xref: /openbmc/linux/include/drm/ttm/ttm_resource.h (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
1b2458726SChristian König /*
2b2458726SChristian König  * Copyright 2020 Advanced Micro Devices, Inc.
3b2458726SChristian König  *
4b2458726SChristian König  * Permission is hereby granted, free of charge, to any person obtaining a
5b2458726SChristian König  * copy of this software and associated documentation files (the "Software"),
6b2458726SChristian König  * to deal in the Software without restriction, including without limitation
7b2458726SChristian König  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8b2458726SChristian König  * and/or sell copies of the Software, and to permit persons to whom the
9b2458726SChristian König  * Software is furnished to do so, subject to the following conditions:
10b2458726SChristian König  *
11b2458726SChristian König  * The above copyright notice and this permission notice shall be included in
12b2458726SChristian König  * all copies or substantial portions of the Software.
13b2458726SChristian König  *
14b2458726SChristian König  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15b2458726SChristian König  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16b2458726SChristian König  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17b2458726SChristian König  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18b2458726SChristian König  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19b2458726SChristian König  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20b2458726SChristian König  * OTHER DEALINGS IN THE SOFTWARE.
21b2458726SChristian König  *
22b2458726SChristian König  * Authors: Christian König
23b2458726SChristian König  */
24b2458726SChristian König 
25b2458726SChristian König #ifndef _TTM_RESOURCE_H_
26b2458726SChristian König #define _TTM_RESOURCE_H_
27b2458726SChristian König 
28b2458726SChristian König #include <linux/types.h>
296a9b0289SChristian König #include <linux/list.h>
30b2458726SChristian König #include <linux/mutex.h>
317938f421SLucas De Marchi #include <linux/iosys-map.h>
32b2458726SChristian König #include <linux/dma-fence.h>
336a9b0289SChristian König 
34b2458726SChristian König #include <drm/drm_print.h>
351cf65c45SChristian König #include <drm/ttm/ttm_caching.h>
363bf3710eSThomas Hellström #include <drm/ttm/ttm_kmap_iter.h>
37b2458726SChristian König 
38b2458726SChristian König #define TTM_MAX_BO_PRIORITY	4U
39b0e2c9eaSChristian König #define TTM_NUM_MEM_TYPES 8
40b2458726SChristian König 
418af8a109SChristian König struct ttm_device;
42b2458726SChristian König struct ttm_resource_manager;
43b2458726SChristian König struct ttm_resource;
44b2458726SChristian König struct ttm_place;
45b2458726SChristian König struct ttm_buffer_object;
4698cca519SChristian König struct ttm_placement;
477938f421SLucas De Marchi struct iosys_map;
483bf3710eSThomas Hellström struct io_mapping;
493bf3710eSThomas Hellström struct sg_table;
503bf3710eSThomas Hellström struct scatterlist;
51b2458726SChristian König 
52b2458726SChristian König struct ttm_resource_manager_func {
53b2458726SChristian König 	/**
54b2458726SChristian König 	 * struct ttm_resource_manager_func member alloc
55b2458726SChristian König 	 *
56b2458726SChristian König 	 * @man: Pointer to a memory type manager.
57b2458726SChristian König 	 * @bo: Pointer to the buffer object we're allocating space for.
58cb1c8146SChristian König 	 * @place: Placement details.
59cb1c8146SChristian König 	 * @res: Resulting pointer to the ttm_resource.
60b2458726SChristian König 	 *
61b2458726SChristian König 	 * This function should allocate space in the memory type managed
62cb1c8146SChristian König 	 * by @man. Placement details if applicable are given by @place. If
63cb1c8146SChristian König 	 * successful, a filled in ttm_resource object should be returned in
64cb1c8146SChristian König 	 * @res. @res::start should be set to a value identifying the beginning
65b2458726SChristian König 	 * of the range allocated, and the function should return zero.
66cb1c8146SChristian König 	 * If the manager can't fulfill the request -ENOSPC should be returned.
67b2458726SChristian König 	 * If a system error occurred, preventing the request to be fulfilled,
68b2458726SChristian König 	 * the function should return a negative error code.
69b2458726SChristian König 	 *
70cb1c8146SChristian König 	 * This function may not be called from within atomic context and needs
71cb1c8146SChristian König 	 * to take care of its own locking to protect any data structures
72cb1c8146SChristian König 	 * managing the space.
73b2458726SChristian König 	 */
74b2458726SChristian König 	int  (*alloc)(struct ttm_resource_manager *man,
75b2458726SChristian König 		      struct ttm_buffer_object *bo,
76b2458726SChristian König 		      const struct ttm_place *place,
77cb1c8146SChristian König 		      struct ttm_resource **res);
78b2458726SChristian König 
79b2458726SChristian König 	/**
80b2458726SChristian König 	 * struct ttm_resource_manager_func member free
81b2458726SChristian König 	 *
82b2458726SChristian König 	 * @man: Pointer to a memory type manager.
83cb1c8146SChristian König 	 * @res: Pointer to a struct ttm_resource to be freed.
84b2458726SChristian König 	 *
85cb1c8146SChristian König 	 * This function frees memory type resources previously allocated.
86cb1c8146SChristian König 	 * May not be called from within atomic context.
87b2458726SChristian König 	 */
88b2458726SChristian König 	void (*free)(struct ttm_resource_manager *man,
89cb1c8146SChristian König 		     struct ttm_resource *res);
90b2458726SChristian König 
91b2458726SChristian König 	/**
9254443270SArunpravin Paneer Selvam 	 * struct ttm_resource_manager_func member intersects
9354443270SArunpravin Paneer Selvam 	 *
9454443270SArunpravin Paneer Selvam 	 * @man: Pointer to a memory type manager.
9554443270SArunpravin Paneer Selvam 	 * @res: Pointer to a struct ttm_resource to be checked.
9654443270SArunpravin Paneer Selvam 	 * @place: Placement to check against.
9754443270SArunpravin Paneer Selvam 	 * @size: Size of the check.
9854443270SArunpravin Paneer Selvam 	 *
9954443270SArunpravin Paneer Selvam 	 * Test if @res intersects with @place + @size. Used to judge if
10054443270SArunpravin Paneer Selvam 	 * evictions are valueable or not.
10154443270SArunpravin Paneer Selvam 	 */
10254443270SArunpravin Paneer Selvam 	bool (*intersects)(struct ttm_resource_manager *man,
10354443270SArunpravin Paneer Selvam 			   struct ttm_resource *res,
10454443270SArunpravin Paneer Selvam 			   const struct ttm_place *place,
10554443270SArunpravin Paneer Selvam 			   size_t size);
10654443270SArunpravin Paneer Selvam 
10754443270SArunpravin Paneer Selvam 	/**
10854443270SArunpravin Paneer Selvam 	 * struct ttm_resource_manager_func member compatible
10954443270SArunpravin Paneer Selvam 	 *
11054443270SArunpravin Paneer Selvam 	 * @man: Pointer to a memory type manager.
11154443270SArunpravin Paneer Selvam 	 * @res: Pointer to a struct ttm_resource to be checked.
11254443270SArunpravin Paneer Selvam 	 * @place: Placement to check against.
11354443270SArunpravin Paneer Selvam 	 * @size: Size of the check.
11454443270SArunpravin Paneer Selvam 	 *
11554443270SArunpravin Paneer Selvam 	 * Test if @res compatible with @place + @size. Used to check of
11654443270SArunpravin Paneer Selvam 	 * the need to move the backing store or not.
11754443270SArunpravin Paneer Selvam 	 */
11854443270SArunpravin Paneer Selvam 	bool (*compatible)(struct ttm_resource_manager *man,
11954443270SArunpravin Paneer Selvam 			   struct ttm_resource *res,
12054443270SArunpravin Paneer Selvam 			   const struct ttm_place *place,
12154443270SArunpravin Paneer Selvam 			   size_t size);
12254443270SArunpravin Paneer Selvam 
12354443270SArunpravin Paneer Selvam 	/**
124b2458726SChristian König 	 * struct ttm_resource_manager_func member debug
125b2458726SChristian König 	 *
126b2458726SChristian König 	 * @man: Pointer to a memory type manager.
127b2458726SChristian König 	 * @printer: Prefix to be used in printout to identify the caller.
128b2458726SChristian König 	 *
129b2458726SChristian König 	 * This function is called to print out the state of the memory
130b2458726SChristian König 	 * type manager to aid debugging of out-of-memory conditions.
131b2458726SChristian König 	 * It may not be called from within atomic context.
132b2458726SChristian König 	 */
133b2458726SChristian König 	void (*debug)(struct ttm_resource_manager *man,
134b2458726SChristian König 		      struct drm_printer *printer);
135b2458726SChristian König };
136b2458726SChristian König 
137b2458726SChristian König /**
138b2458726SChristian König  * struct ttm_resource_manager
139b2458726SChristian König  *
140b2458726SChristian König  * @use_type: The memory type is enabled.
141324317adSChristian König  * @use_tt: If a TT object should be used for the backing store.
142b2458726SChristian König  * @size: Size of the managed region.
1433f268ef0SChristian König  * @bdev: ttm device this manager belongs to
144b2458726SChristian König  * @func: structure pointer implementing the range manager. See above
145b2458726SChristian König  * @move_lock: lock for move fence
146b2458726SChristian König  * @move: The fence of the last pipelined move operation.
1473f268ef0SChristian König  * @lru: The lru list for this memory type.
148b2458726SChristian König  *
149b2458726SChristian König  * This structure is used to identify and manage memory types for a device.
150b2458726SChristian König  */
151b2458726SChristian König struct ttm_resource_manager {
152b2458726SChristian König 	/*
153b2458726SChristian König 	 * No protection. Constant from start.
154b2458726SChristian König 	 */
155b2458726SChristian König 	bool use_type;
156b2458726SChristian König 	bool use_tt;
1573f268ef0SChristian König 	struct ttm_device *bdev;
158b2458726SChristian König 	uint64_t size;
159b2458726SChristian König 	const struct ttm_resource_manager_func *func;
160b2458726SChristian König 	spinlock_t move_lock;
161b2458726SChristian König 
162b2458726SChristian König 	/*
1633f268ef0SChristian König 	 * Protected by @move_lock.
1643f268ef0SChristian König 	 */
1653f268ef0SChristian König 	struct dma_fence *move;
1663f268ef0SChristian König 
1673f268ef0SChristian König 	/*
1680e05fc49SChristian König 	 * Protected by the bdev->lru_lock.
169b2458726SChristian König 	 */
170b2458726SChristian König 	struct list_head lru[TTM_MAX_BO_PRIORITY];
1710e05fc49SChristian König 
1720e05fc49SChristian König 	/**
1730e05fc49SChristian König 	 * @usage: How much of the resources are used, protected by the
1740e05fc49SChristian König 	 * bdev->lru_lock.
1750e05fc49SChristian König 	 */
1760e05fc49SChristian König 	uint64_t usage;
177b2458726SChristian König };
178b2458726SChristian König 
179b2458726SChristian König /**
180b2458726SChristian König  * struct ttm_bus_placement
181b2458726SChristian König  *
182b2458726SChristian König  * @addr:		mapped virtual address
18354d04ea8SChristian König  * @offset:		physical addr
184b2458726SChristian König  * @is_iomem:		is this io memory ?
185324317adSChristian König  * @caching:		See enum ttm_caching
186b2458726SChristian König  *
187b2458726SChristian König  * Structure indicating the bus placement of an object.
188b2458726SChristian König  */
189b2458726SChristian König struct ttm_bus_placement {
190b2458726SChristian König 	void			*addr;
19154d04ea8SChristian König 	phys_addr_t		offset;
192b2458726SChristian König 	bool			is_iomem;
1931cf65c45SChristian König 	enum ttm_caching	caching;
194b2458726SChristian König };
195b2458726SChristian König 
196b2458726SChristian König /**
197b2458726SChristian König  * struct ttm_resource
198b2458726SChristian König  *
199cb1c8146SChristian König  * @start: Start of the allocation.
200*e3c92eb4SSomalapuram Amaranath  * @size: Actual size of resource in bytes.
201cb1c8146SChristian König  * @mem_type: Resource type of the allocation.
202b2458726SChristian König  * @placement: Placement flags.
203b2458726SChristian König  * @bus: Placement on io bus accessible to the CPU
204fda8d552SChristian König  * @bo: weak reference to the BO, protected by ttm_device::lru_lock
205b2458726SChristian König  *
206b2458726SChristian König  * Structure indicating the placement and space resources used by a
207b2458726SChristian König  * buffer object.
208b2458726SChristian König  */
209b2458726SChristian König struct ttm_resource {
210b2458726SChristian König 	unsigned long start;
211*e3c92eb4SSomalapuram Amaranath 	size_t size;
212b2458726SChristian König 	uint32_t mem_type;
213b2458726SChristian König 	uint32_t placement;
214b2458726SChristian König 	struct ttm_bus_placement bus;
215fda8d552SChristian König 	struct ttm_buffer_object *bo;
2166a9b0289SChristian König 
2176a9b0289SChristian König 	/**
2186a9b0289SChristian König 	 * @lru: Least recently used list, see &ttm_resource_manager.lru
2196a9b0289SChristian König 	 */
2206a9b0289SChristian König 	struct list_head lru;
2216a9b0289SChristian König };
2226a9b0289SChristian König 
2236a9b0289SChristian König /**
2245d05b988SChristian König  * struct ttm_resource_cursor
2255d05b988SChristian König  *
2265d05b988SChristian König  * @priority: the current priority
2275d05b988SChristian König  *
2285d05b988SChristian König  * Cursor to iterate over the resources in a manager.
2295d05b988SChristian König  */
2305d05b988SChristian König struct ttm_resource_cursor {
2315d05b988SChristian König 	unsigned int priority;
2325d05b988SChristian König };
2335d05b988SChristian König 
2345d05b988SChristian König /**
2356a9b0289SChristian König  * struct ttm_lru_bulk_move_pos
2366a9b0289SChristian König  *
2376a9b0289SChristian König  * @first: first res in the bulk move range
2386a9b0289SChristian König  * @last: last res in the bulk move range
2396a9b0289SChristian König  *
240fee2ede1SChristian König  * Range of resources for a lru bulk move.
2416a9b0289SChristian König  */
2426a9b0289SChristian König struct ttm_lru_bulk_move_pos {
2436a9b0289SChristian König 	struct ttm_resource *first;
2446a9b0289SChristian König 	struct ttm_resource *last;
2456a9b0289SChristian König };
2466a9b0289SChristian König 
2476a9b0289SChristian König /**
2486a9b0289SChristian König  * struct ttm_lru_bulk_move
2496a9b0289SChristian König  *
25084ab41dbSChristian König  * @pos: first/last lru entry for resources in the each domain/priority
2516a9b0289SChristian König  *
2526a9b0289SChristian König  * Container for the current bulk move state. Should be used with
253fee2ede1SChristian König  * ttm_lru_bulk_move_init() and ttm_bo_set_bulk_move().
2546a9b0289SChristian König  */
2556a9b0289SChristian König struct ttm_lru_bulk_move {
256b0e2c9eaSChristian König 	struct ttm_lru_bulk_move_pos pos[TTM_NUM_MEM_TYPES][TTM_MAX_BO_PRIORITY];
257b2458726SChristian König };
258b2458726SChristian König 
259b2458726SChristian König /**
2603bf3710eSThomas Hellström  * struct ttm_kmap_iter_iomap - Specialization for a struct io_mapping +
2613bf3710eSThomas Hellström  * struct sg_table backed struct ttm_resource.
2623bf3710eSThomas Hellström  * @base: Embedded struct ttm_kmap_iter providing the usage interface.
2633bf3710eSThomas Hellström  * @iomap: struct io_mapping representing the underlying linear io_memory.
2643bf3710eSThomas Hellström  * @st: sg_table into @iomap, representing the memory of the struct ttm_resource.
2653bf3710eSThomas Hellström  * @start: Offset that needs to be subtracted from @st to make
2663bf3710eSThomas Hellström  * sg_dma_address(st->sgl) - @start == 0 for @iomap start.
2673bf3710eSThomas Hellström  * @cache: Scatterlist traversal cache for fast lookups.
2683bf3710eSThomas Hellström  * @cache.sg: Pointer to the currently cached scatterlist segment.
2693bf3710eSThomas Hellström  * @cache.i: First index of @sg. PAGE_SIZE granularity.
2703bf3710eSThomas Hellström  * @cache.end: Last index + 1 of @sg. PAGE_SIZE granularity.
2713bf3710eSThomas Hellström  * @cache.offs: First offset into @iomap of @sg. PAGE_SIZE granularity.
2723bf3710eSThomas Hellström  */
2733bf3710eSThomas Hellström struct ttm_kmap_iter_iomap {
2743bf3710eSThomas Hellström 	struct ttm_kmap_iter base;
2753bf3710eSThomas Hellström 	struct io_mapping *iomap;
2763bf3710eSThomas Hellström 	struct sg_table *st;
2773bf3710eSThomas Hellström 	resource_size_t start;
2783bf3710eSThomas Hellström 	struct {
2793bf3710eSThomas Hellström 		struct scatterlist *sg;
2803bf3710eSThomas Hellström 		pgoff_t i;
2813bf3710eSThomas Hellström 		pgoff_t end;
2823bf3710eSThomas Hellström 		pgoff_t offs;
2833bf3710eSThomas Hellström 	} cache;
2843bf3710eSThomas Hellström };
2853bf3710eSThomas Hellström 
2863bf3710eSThomas Hellström /**
2873bf3710eSThomas Hellström  * struct ttm_kmap_iter_linear_io - Iterator specialization for linear io
2883bf3710eSThomas Hellström  * @base: The base iterator
2893bf3710eSThomas Hellström  * @dmap: Points to the starting address of the region
2903bf3710eSThomas Hellström  * @needs_unmap: Whether we need to unmap on fini
2913bf3710eSThomas Hellström  */
2923bf3710eSThomas Hellström struct ttm_kmap_iter_linear_io {
2933bf3710eSThomas Hellström 	struct ttm_kmap_iter base;
2947938f421SLucas De Marchi 	struct iosys_map dmap;
2953bf3710eSThomas Hellström 	bool needs_unmap;
2963bf3710eSThomas Hellström };
2973bf3710eSThomas Hellström 
2983bf3710eSThomas Hellström /**
299b2458726SChristian König  * ttm_resource_manager_set_used
300b2458726SChristian König  *
301b2458726SChristian König  * @man: A memory manager object.
302b2458726SChristian König  * @used: usage state to set.
303b2458726SChristian König  *
304b2458726SChristian König  * Set the manager in use flag. If disabled the manager is no longer
305b2458726SChristian König  * used for object placement.
306b2458726SChristian König  */
307b2458726SChristian König static inline void
ttm_resource_manager_set_used(struct ttm_resource_manager * man,bool used)308b2458726SChristian König ttm_resource_manager_set_used(struct ttm_resource_manager *man, bool used)
309b2458726SChristian König {
31072fec10cSDaniel Vetter 	int i;
31172fec10cSDaniel Vetter 
31272fec10cSDaniel Vetter 	for (i = 0; i < TTM_MAX_BO_PRIORITY; i++)
31372fec10cSDaniel Vetter 		WARN_ON(!list_empty(&man->lru[i]));
314b2458726SChristian König 	man->use_type = used;
315b2458726SChristian König }
316b2458726SChristian König 
317b2458726SChristian König /**
318b2458726SChristian König  * ttm_resource_manager_used
319b2458726SChristian König  *
320b2458726SChristian König  * @man: Manager to get used state for
321b2458726SChristian König  *
322b2458726SChristian König  * Get the in use flag for a manager.
323b2458726SChristian König  * Returns:
324b2458726SChristian König  * true is used, false if not.
325b2458726SChristian König  */
ttm_resource_manager_used(struct ttm_resource_manager * man)326b2458726SChristian König static inline bool ttm_resource_manager_used(struct ttm_resource_manager *man)
327b2458726SChristian König {
328b2458726SChristian König 	return man->use_type;
329b2458726SChristian König }
330b2458726SChristian König 
331b2458726SChristian König /**
332b2458726SChristian König  * ttm_resource_manager_cleanup
333b2458726SChristian König  *
334b2458726SChristian König  * @man: A memory manager object.
335b2458726SChristian König  *
336b2458726SChristian König  * Cleanup the move fences from the memory manager object.
337b2458726SChristian König  */
338b2458726SChristian König static inline void
ttm_resource_manager_cleanup(struct ttm_resource_manager * man)339b2458726SChristian König ttm_resource_manager_cleanup(struct ttm_resource_manager *man)
340b2458726SChristian König {
341b2458726SChristian König 	dma_fence_put(man->move);
342b2458726SChristian König 	man->move = NULL;
343b2458726SChristian König }
344b2458726SChristian König 
3456a9b0289SChristian König void ttm_lru_bulk_move_init(struct ttm_lru_bulk_move *bulk);
3466a9b0289SChristian König void ttm_lru_bulk_move_tail(struct ttm_lru_bulk_move *bulk);
3476a9b0289SChristian König 
3480f9cd1eaSChristian König void ttm_resource_add_bulk_move(struct ttm_resource *res,
3490f9cd1eaSChristian König 				struct ttm_buffer_object *bo);
3500f9cd1eaSChristian König void ttm_resource_del_bulk_move(struct ttm_resource *res,
3510f9cd1eaSChristian König 				struct ttm_buffer_object *bo);
352fee2ede1SChristian König void ttm_resource_move_to_lru_tail(struct ttm_resource *res);
3536a9b0289SChristian König 
3543eb7d96eSChristian König void ttm_resource_init(struct ttm_buffer_object *bo,
3553eb7d96eSChristian König                        const struct ttm_place *place,
3563eb7d96eSChristian König                        struct ttm_resource *res);
357de3688e4SChristian König void ttm_resource_fini(struct ttm_resource_manager *man,
358de3688e4SChristian König 		       struct ttm_resource *res);
359de3688e4SChristian König 
360b2458726SChristian König int ttm_resource_alloc(struct ttm_buffer_object *bo,
361b2458726SChristian König 		       const struct ttm_place *place,
362bfa3357eSChristian König 		       struct ttm_resource **res);
363bfa3357eSChristian König void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res);
36454443270SArunpravin Paneer Selvam bool ttm_resource_intersects(struct ttm_device *bdev,
36554443270SArunpravin Paneer Selvam 			     struct ttm_resource *res,
36654443270SArunpravin Paneer Selvam 			     const struct ttm_place *place,
36754443270SArunpravin Paneer Selvam 			     size_t size);
36854443270SArunpravin Paneer Selvam bool ttm_resource_compatible(struct ttm_device *bdev,
36954443270SArunpravin Paneer Selvam 			     struct ttm_resource *res,
37054443270SArunpravin Paneer Selvam 			     const struct ttm_place *place,
37154443270SArunpravin Paneer Selvam 			     size_t size);
37298cca519SChristian König bool ttm_resource_compat(struct ttm_resource *res,
37398cca519SChristian König 			 struct ttm_placement *placement);
374fda8d552SChristian König void ttm_resource_set_bo(struct ttm_resource *res,
375fda8d552SChristian König 			 struct ttm_buffer_object *bo);
376b2458726SChristian König 
377b2458726SChristian König void ttm_resource_manager_init(struct ttm_resource_manager *man,
3783f268ef0SChristian König 			       struct ttm_device *bdev,
37990d4aa20SChristian König 			       uint64_t size);
380b2458726SChristian König 
3818af8a109SChristian König int ttm_resource_manager_evict_all(struct ttm_device *bdev,
382b2458726SChristian König 				   struct ttm_resource_manager *man);
383b2458726SChristian König 
3840e05fc49SChristian König uint64_t ttm_resource_manager_usage(struct ttm_resource_manager *man);
385b2458726SChristian König void ttm_resource_manager_debug(struct ttm_resource_manager *man,
386b2458726SChristian König 				struct drm_printer *p);
387b2458726SChristian König 
3885d05b988SChristian König struct ttm_resource *
3895d05b988SChristian König ttm_resource_manager_first(struct ttm_resource_manager *man,
3905d05b988SChristian König 			   struct ttm_resource_cursor *cursor);
3915d05b988SChristian König struct ttm_resource *
3925d05b988SChristian König ttm_resource_manager_next(struct ttm_resource_manager *man,
3935d05b988SChristian König 			  struct ttm_resource_cursor *cursor,
3945d05b988SChristian König 			  struct ttm_resource *res);
3955d05b988SChristian König 
39677ef271fSChristian König /**
39777ef271fSChristian König  * ttm_resource_manager_for_each_res - iterate over all resources
39877ef271fSChristian König  * @man: the resource manager
39977ef271fSChristian König  * @cursor: struct ttm_resource_cursor for the current position
40077ef271fSChristian König  * @res: the current resource
40177ef271fSChristian König  *
40277ef271fSChristian König  * Iterate over all the evictable resources in a resource manager.
40377ef271fSChristian König  */
4045d05b988SChristian König #define ttm_resource_manager_for_each_res(man, cursor, res)		\
4055d05b988SChristian König 	for (res = ttm_resource_manager_first(man, cursor); res;	\
4065d05b988SChristian König 	     res = ttm_resource_manager_next(man, cursor, res))
4075d05b988SChristian König 
4083bf3710eSThomas Hellström struct ttm_kmap_iter *
4093bf3710eSThomas Hellström ttm_kmap_iter_iomap_init(struct ttm_kmap_iter_iomap *iter_io,
4103bf3710eSThomas Hellström 			 struct io_mapping *iomap,
4113bf3710eSThomas Hellström 			 struct sg_table *st,
4123bf3710eSThomas Hellström 			 resource_size_t start);
4133bf3710eSThomas Hellström 
4143bf3710eSThomas Hellström struct ttm_kmap_iter_linear_io;
4153bf3710eSThomas Hellström 
4163bf3710eSThomas Hellström struct ttm_kmap_iter *
4173bf3710eSThomas Hellström ttm_kmap_iter_linear_io_init(struct ttm_kmap_iter_linear_io *iter_io,
4183bf3710eSThomas Hellström 			     struct ttm_device *bdev,
4193bf3710eSThomas Hellström 			     struct ttm_resource *mem);
4203bf3710eSThomas Hellström 
4213bf3710eSThomas Hellström void ttm_kmap_iter_linear_io_fini(struct ttm_kmap_iter_linear_io *iter_io,
4223bf3710eSThomas Hellström 				  struct ttm_device *bdev,
4233bf3710eSThomas Hellström 				  struct ttm_resource *mem);
4248cd9efd1SZack Rusin 
4258cd9efd1SZack Rusin void ttm_resource_manager_create_debugfs(struct ttm_resource_manager *man,
4268cd9efd1SZack Rusin 					 struct dentry * parent,
4278cd9efd1SZack Rusin 					 const char *name);
428b2458726SChristian König #endif
429