1ad8b1aafSjsg /*
2ad8b1aafSjsg  * Copyright 2020 Advanced Micro Devices, Inc.
3ad8b1aafSjsg  *
4ad8b1aafSjsg  * Permission is hereby granted, free of charge, to any person obtaining a
5ad8b1aafSjsg  * copy of this software and associated documentation files (the "Software"),
6ad8b1aafSjsg  * to deal in the Software without restriction, including without limitation
7ad8b1aafSjsg  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8ad8b1aafSjsg  * and/or sell copies of the Software, and to permit persons to whom the
9ad8b1aafSjsg  * Software is furnished to do so, subject to the following conditions:
10ad8b1aafSjsg  *
11ad8b1aafSjsg  * The above copyright notice and this permission notice shall be included in
12ad8b1aafSjsg  * all copies or substantial portions of the Software.
13ad8b1aafSjsg  *
14ad8b1aafSjsg  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15ad8b1aafSjsg  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16ad8b1aafSjsg  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17ad8b1aafSjsg  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18ad8b1aafSjsg  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19ad8b1aafSjsg  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20ad8b1aafSjsg  * OTHER DEALINGS IN THE SOFTWARE.
21ad8b1aafSjsg  *
22ad8b1aafSjsg  * Authors: Christian König
23ad8b1aafSjsg  */
24ad8b1aafSjsg 
25ad8b1aafSjsg #ifndef _TTM_RESOURCE_H_
26ad8b1aafSjsg #define _TTM_RESOURCE_H_
27ad8b1aafSjsg 
28ad8b1aafSjsg #include <linux/types.h>
291bb76ff1Sjsg #include <linux/list.h>
30ad8b1aafSjsg #include <linux/mutex.h>
311bb76ff1Sjsg #include <linux/iosys-map.h>
32ad8b1aafSjsg #include <linux/dma-fence.h>
331bb76ff1Sjsg 
34ad8b1aafSjsg #include <drm/drm_print.h>
355ca02815Sjsg #include <drm/ttm/ttm_caching.h>
365ca02815Sjsg #include <drm/ttm/ttm_kmap_iter.h>
37ad8b1aafSjsg 
38ad8b1aafSjsg #define TTM_MAX_BO_PRIORITY	4U
391bb76ff1Sjsg #define TTM_NUM_MEM_TYPES 8
40ad8b1aafSjsg 
415ca02815Sjsg struct ttm_device;
42ad8b1aafSjsg struct ttm_resource_manager;
43ad8b1aafSjsg struct ttm_resource;
44ad8b1aafSjsg struct ttm_place;
45ad8b1aafSjsg struct ttm_buffer_object;
461bb76ff1Sjsg struct ttm_placement;
471bb76ff1Sjsg struct iosys_map;
485ca02815Sjsg struct io_mapping;
495ca02815Sjsg struct sg_table;
505ca02815Sjsg struct scatterlist;
51ad8b1aafSjsg 
52ad8b1aafSjsg struct ttm_resource_manager_func {
53ad8b1aafSjsg 	/**
54ad8b1aafSjsg 	 * struct ttm_resource_manager_func member alloc
55ad8b1aafSjsg 	 *
56ad8b1aafSjsg 	 * @man: Pointer to a memory type manager.
57ad8b1aafSjsg 	 * @bo: Pointer to the buffer object we're allocating space for.
585ca02815Sjsg 	 * @place: Placement details.
595ca02815Sjsg 	 * @res: Resulting pointer to the ttm_resource.
60ad8b1aafSjsg 	 *
61ad8b1aafSjsg 	 * This function should allocate space in the memory type managed
625ca02815Sjsg 	 * by @man. Placement details if applicable are given by @place. If
635ca02815Sjsg 	 * successful, a filled in ttm_resource object should be returned in
645ca02815Sjsg 	 * @res. @res::start should be set to a value identifying the beginning
65ad8b1aafSjsg 	 * of the range allocated, and the function should return zero.
665ca02815Sjsg 	 * If the manager can't fulfill the request -ENOSPC should be returned.
67ad8b1aafSjsg 	 * If a system error occurred, preventing the request to be fulfilled,
68ad8b1aafSjsg 	 * the function should return a negative error code.
69ad8b1aafSjsg 	 *
705ca02815Sjsg 	 * This function may not be called from within atomic context and needs
715ca02815Sjsg 	 * to take care of its own locking to protect any data structures
725ca02815Sjsg 	 * managing the space.
73ad8b1aafSjsg 	 */
74ad8b1aafSjsg 	int  (*alloc)(struct ttm_resource_manager *man,
75ad8b1aafSjsg 		      struct ttm_buffer_object *bo,
76ad8b1aafSjsg 		      const struct ttm_place *place,
775ca02815Sjsg 		      struct ttm_resource **res);
78ad8b1aafSjsg 
79ad8b1aafSjsg 	/**
80ad8b1aafSjsg 	 * struct ttm_resource_manager_func member free
81ad8b1aafSjsg 	 *
82ad8b1aafSjsg 	 * @man: Pointer to a memory type manager.
835ca02815Sjsg 	 * @res: Pointer to a struct ttm_resource to be freed.
84ad8b1aafSjsg 	 *
855ca02815Sjsg 	 * This function frees memory type resources previously allocated.
865ca02815Sjsg 	 * May not be called from within atomic context.
87ad8b1aafSjsg 	 */
88ad8b1aafSjsg 	void (*free)(struct ttm_resource_manager *man,
895ca02815Sjsg 		     struct ttm_resource *res);
90ad8b1aafSjsg 
91ad8b1aafSjsg 	/**
921bb76ff1Sjsg 	 * struct ttm_resource_manager_func member intersects
931bb76ff1Sjsg 	 *
941bb76ff1Sjsg 	 * @man: Pointer to a memory type manager.
951bb76ff1Sjsg 	 * @res: Pointer to a struct ttm_resource to be checked.
961bb76ff1Sjsg 	 * @place: Placement to check against.
971bb76ff1Sjsg 	 * @size: Size of the check.
981bb76ff1Sjsg 	 *
991bb76ff1Sjsg 	 * Test if @res intersects with @place + @size. Used to judge if
1001bb76ff1Sjsg 	 * evictions are valueable or not.
1011bb76ff1Sjsg 	 */
1021bb76ff1Sjsg 	bool (*intersects)(struct ttm_resource_manager *man,
1031bb76ff1Sjsg 			   struct ttm_resource *res,
1041bb76ff1Sjsg 			   const struct ttm_place *place,
1051bb76ff1Sjsg 			   size_t size);
1061bb76ff1Sjsg 
1071bb76ff1Sjsg 	/**
1081bb76ff1Sjsg 	 * struct ttm_resource_manager_func member compatible
1091bb76ff1Sjsg 	 *
1101bb76ff1Sjsg 	 * @man: Pointer to a memory type manager.
1111bb76ff1Sjsg 	 * @res: Pointer to a struct ttm_resource to be checked.
1121bb76ff1Sjsg 	 * @place: Placement to check against.
1131bb76ff1Sjsg 	 * @size: Size of the check.
1141bb76ff1Sjsg 	 *
1151bb76ff1Sjsg 	 * Test if @res compatible with @place + @size. Used to check of
1161bb76ff1Sjsg 	 * the need to move the backing store or not.
1171bb76ff1Sjsg 	 */
1181bb76ff1Sjsg 	bool (*compatible)(struct ttm_resource_manager *man,
1191bb76ff1Sjsg 			   struct ttm_resource *res,
1201bb76ff1Sjsg 			   const struct ttm_place *place,
1211bb76ff1Sjsg 			   size_t size);
1221bb76ff1Sjsg 
1231bb76ff1Sjsg 	/**
124ad8b1aafSjsg 	 * struct ttm_resource_manager_func member debug
125ad8b1aafSjsg 	 *
126ad8b1aafSjsg 	 * @man: Pointer to a memory type manager.
127ad8b1aafSjsg 	 * @printer: Prefix to be used in printout to identify the caller.
128ad8b1aafSjsg 	 *
129ad8b1aafSjsg 	 * This function is called to print out the state of the memory
130ad8b1aafSjsg 	 * type manager to aid debugging of out-of-memory conditions.
131ad8b1aafSjsg 	 * It may not be called from within atomic context.
132ad8b1aafSjsg 	 */
133ad8b1aafSjsg 	void (*debug)(struct ttm_resource_manager *man,
134ad8b1aafSjsg 		      struct drm_printer *printer);
135ad8b1aafSjsg };
136ad8b1aafSjsg 
137ad8b1aafSjsg /**
138ad8b1aafSjsg  * struct ttm_resource_manager
139ad8b1aafSjsg  *
140ad8b1aafSjsg  * @use_type: The memory type is enabled.
1411bb76ff1Sjsg  * @use_tt: If a TT object should be used for the backing store.
142ad8b1aafSjsg  * @size: Size of the managed region.
1431bb76ff1Sjsg  * @bdev: ttm device this manager belongs to
144ad8b1aafSjsg  * @func: structure pointer implementing the range manager. See above
145ad8b1aafSjsg  * @move_lock: lock for move fence
146ad8b1aafSjsg  * @move: The fence of the last pipelined move operation.
1471bb76ff1Sjsg  * @lru: The lru list for this memory type.
148ad8b1aafSjsg  *
149ad8b1aafSjsg  * This structure is used to identify and manage memory types for a device.
150ad8b1aafSjsg  */
151ad8b1aafSjsg struct ttm_resource_manager {
152ad8b1aafSjsg 	/*
153ad8b1aafSjsg 	 * No protection. Constant from start.
154ad8b1aafSjsg 	 */
155ad8b1aafSjsg 	bool use_type;
156ad8b1aafSjsg 	bool use_tt;
1571bb76ff1Sjsg 	struct ttm_device *bdev;
158ad8b1aafSjsg 	uint64_t size;
159ad8b1aafSjsg 	const struct ttm_resource_manager_func *func;
160ad8b1aafSjsg 	spinlock_t move_lock;
161ad8b1aafSjsg 
162ad8b1aafSjsg 	/*
163ad8b1aafSjsg 	 * Protected by @move_lock.
164ad8b1aafSjsg 	 */
165ad8b1aafSjsg 	struct dma_fence *move;
1661bb76ff1Sjsg 
1671bb76ff1Sjsg 	/*
1681bb76ff1Sjsg 	 * Protected by the bdev->lru_lock.
1691bb76ff1Sjsg 	 */
1701bb76ff1Sjsg 	struct list_head lru[TTM_MAX_BO_PRIORITY];
1711bb76ff1Sjsg 
1721bb76ff1Sjsg 	/**
1731bb76ff1Sjsg 	 * @usage: How much of the resources are used, protected by the
1741bb76ff1Sjsg 	 * bdev->lru_lock.
1751bb76ff1Sjsg 	 */
1761bb76ff1Sjsg 	uint64_t usage;
177ad8b1aafSjsg };
178ad8b1aafSjsg 
179ad8b1aafSjsg /**
180ad8b1aafSjsg  * struct ttm_bus_placement
181ad8b1aafSjsg  *
182ad8b1aafSjsg  * @addr:		mapped virtual address
183ad8b1aafSjsg  * @offset:		physical addr
184ad8b1aafSjsg  * @is_iomem:		is this io memory ?
1851bb76ff1Sjsg  * @caching:		See enum ttm_caching
186ad8b1aafSjsg  *
187ad8b1aafSjsg  * Structure indicating the bus placement of an object.
188ad8b1aafSjsg  */
189ad8b1aafSjsg struct ttm_bus_placement {
190ad8b1aafSjsg 	void			*addr;
191ad8b1aafSjsg 	phys_addr_t		offset;
192ad8b1aafSjsg 	bool			is_iomem;
1935ca02815Sjsg 	enum ttm_caching	caching;
194ad8b1aafSjsg 	bus_space_handle_t	bsh;
195ad8b1aafSjsg };
196ad8b1aafSjsg 
197ad8b1aafSjsg /**
198ad8b1aafSjsg  * struct ttm_resource
199ad8b1aafSjsg  *
2005ca02815Sjsg  * @start: Start of the allocation.
201*f005ef32Sjsg  * @size: Actual size of resource in bytes.
2025ca02815Sjsg  * @mem_type: Resource type of the allocation.
203ad8b1aafSjsg  * @placement: Placement flags.
204ad8b1aafSjsg  * @bus: Placement on io bus accessible to the CPU
2051bb76ff1Sjsg  * @bo: weak reference to the BO, protected by ttm_device::lru_lock
206ad8b1aafSjsg  *
207ad8b1aafSjsg  * Structure indicating the placement and space resources used by a
208ad8b1aafSjsg  * buffer object.
209ad8b1aafSjsg  */
210ad8b1aafSjsg struct ttm_resource {
211ad8b1aafSjsg 	unsigned long start;
212*f005ef32Sjsg 	size_t size;
213ad8b1aafSjsg 	uint32_t mem_type;
214ad8b1aafSjsg 	uint32_t placement;
215ad8b1aafSjsg 	struct ttm_bus_placement bus;
2161bb76ff1Sjsg 	struct ttm_buffer_object *bo;
2171bb76ff1Sjsg 
2181bb76ff1Sjsg 	/**
2191bb76ff1Sjsg 	 * @lru: Least recently used list, see &ttm_resource_manager.lru
2201bb76ff1Sjsg 	 */
2211bb76ff1Sjsg 	struct list_head lru;
2221bb76ff1Sjsg };
2231bb76ff1Sjsg 
2241bb76ff1Sjsg /**
2251bb76ff1Sjsg  * struct ttm_resource_cursor
2261bb76ff1Sjsg  *
2271bb76ff1Sjsg  * @priority: the current priority
2281bb76ff1Sjsg  *
2291bb76ff1Sjsg  * Cursor to iterate over the resources in a manager.
2301bb76ff1Sjsg  */
2311bb76ff1Sjsg struct ttm_resource_cursor {
2321bb76ff1Sjsg 	unsigned int priority;
2331bb76ff1Sjsg };
2341bb76ff1Sjsg 
2351bb76ff1Sjsg /**
2361bb76ff1Sjsg  * struct ttm_lru_bulk_move_pos
2371bb76ff1Sjsg  *
2381bb76ff1Sjsg  * @first: first res in the bulk move range
2391bb76ff1Sjsg  * @last: last res in the bulk move range
2401bb76ff1Sjsg  *
2411bb76ff1Sjsg  * Range of resources for a lru bulk move.
2421bb76ff1Sjsg  */
2431bb76ff1Sjsg struct ttm_lru_bulk_move_pos {
2441bb76ff1Sjsg 	struct ttm_resource *first;
2451bb76ff1Sjsg 	struct ttm_resource *last;
2461bb76ff1Sjsg };
2471bb76ff1Sjsg 
2481bb76ff1Sjsg /**
2491bb76ff1Sjsg  * struct ttm_lru_bulk_move
2501bb76ff1Sjsg  *
2511bb76ff1Sjsg  * @pos: first/last lru entry for resources in the each domain/priority
2521bb76ff1Sjsg  *
2531bb76ff1Sjsg  * Container for the current bulk move state. Should be used with
2541bb76ff1Sjsg  * ttm_lru_bulk_move_init() and ttm_bo_set_bulk_move().
2551bb76ff1Sjsg  */
2561bb76ff1Sjsg struct ttm_lru_bulk_move {
2571bb76ff1Sjsg 	struct ttm_lru_bulk_move_pos pos[TTM_NUM_MEM_TYPES][TTM_MAX_BO_PRIORITY];
258ad8b1aafSjsg };
259ad8b1aafSjsg 
260ad8b1aafSjsg /**
2615ca02815Sjsg  * struct ttm_kmap_iter_iomap - Specialization for a struct io_mapping +
2625ca02815Sjsg  * struct sg_table backed struct ttm_resource.
2635ca02815Sjsg  * @base: Embedded struct ttm_kmap_iter providing the usage interface.
2645ca02815Sjsg  * @iomap: struct io_mapping representing the underlying linear io_memory.
2655ca02815Sjsg  * @st: sg_table into @iomap, representing the memory of the struct ttm_resource.
2665ca02815Sjsg  * @start: Offset that needs to be subtracted from @st to make
2675ca02815Sjsg  * sg_dma_address(st->sgl) - @start == 0 for @iomap start.
2685ca02815Sjsg  * @cache: Scatterlist traversal cache for fast lookups.
2695ca02815Sjsg  * @cache.sg: Pointer to the currently cached scatterlist segment.
2705ca02815Sjsg  * @cache.i: First index of @sg. PAGE_SIZE granularity.
2715ca02815Sjsg  * @cache.end: Last index + 1 of @sg. PAGE_SIZE granularity.
2725ca02815Sjsg  * @cache.offs: First offset into @iomap of @sg. PAGE_SIZE granularity.
2735ca02815Sjsg  */
2745ca02815Sjsg struct ttm_kmap_iter_iomap {
2755ca02815Sjsg 	struct ttm_kmap_iter base;
2765ca02815Sjsg 	struct io_mapping *iomap;
2775ca02815Sjsg 	struct sg_table *st;
2785ca02815Sjsg 	resource_size_t start;
2795ca02815Sjsg 	struct {
2805ca02815Sjsg 		struct scatterlist *sg;
2815ca02815Sjsg 		pgoff_t i;
2825ca02815Sjsg 		pgoff_t end;
2835ca02815Sjsg 		pgoff_t offs;
2845ca02815Sjsg 	} cache;
2855ca02815Sjsg };
2865ca02815Sjsg 
2875ca02815Sjsg /**
2885ca02815Sjsg  * struct ttm_kmap_iter_linear_io - Iterator specialization for linear io
2895ca02815Sjsg  * @base: The base iterator
2905ca02815Sjsg  * @dmap: Points to the starting address of the region
2915ca02815Sjsg  * @needs_unmap: Whether we need to unmap on fini
2925ca02815Sjsg  */
2935ca02815Sjsg struct ttm_kmap_iter_linear_io {
2945ca02815Sjsg 	struct ttm_kmap_iter base;
2951bb76ff1Sjsg 	struct iosys_map dmap;
2965ca02815Sjsg 	bool needs_unmap;
2975ca02815Sjsg };
2985ca02815Sjsg 
2995ca02815Sjsg /**
300ad8b1aafSjsg  * ttm_resource_manager_set_used
301ad8b1aafSjsg  *
302ad8b1aafSjsg  * @man: A memory manager object.
303ad8b1aafSjsg  * @used: usage state to set.
304ad8b1aafSjsg  *
305ad8b1aafSjsg  * Set the manager in use flag. If disabled the manager is no longer
306ad8b1aafSjsg  * used for object placement.
307ad8b1aafSjsg  */
308ad8b1aafSjsg static inline void
ttm_resource_manager_set_used(struct ttm_resource_manager * man,bool used)309ad8b1aafSjsg ttm_resource_manager_set_used(struct ttm_resource_manager *man, bool used)
310ad8b1aafSjsg {
3115ca02815Sjsg 	int i;
3125ca02815Sjsg 
3135ca02815Sjsg 	for (i = 0; i < TTM_MAX_BO_PRIORITY; i++)
3145ca02815Sjsg 		WARN_ON(!list_empty(&man->lru[i]));
315ad8b1aafSjsg 	man->use_type = used;
316ad8b1aafSjsg }
317ad8b1aafSjsg 
318ad8b1aafSjsg /**
319ad8b1aafSjsg  * ttm_resource_manager_used
320ad8b1aafSjsg  *
321ad8b1aafSjsg  * @man: Manager to get used state for
322ad8b1aafSjsg  *
323ad8b1aafSjsg  * Get the in use flag for a manager.
324ad8b1aafSjsg  * Returns:
325ad8b1aafSjsg  * true is used, false if not.
326ad8b1aafSjsg  */
ttm_resource_manager_used(struct ttm_resource_manager * man)327ad8b1aafSjsg static inline bool ttm_resource_manager_used(struct ttm_resource_manager *man)
328ad8b1aafSjsg {
329ad8b1aafSjsg 	return man->use_type;
330ad8b1aafSjsg }
331ad8b1aafSjsg 
332ad8b1aafSjsg /**
333ad8b1aafSjsg  * ttm_resource_manager_cleanup
334ad8b1aafSjsg  *
335ad8b1aafSjsg  * @man: A memory manager object.
336ad8b1aafSjsg  *
337ad8b1aafSjsg  * Cleanup the move fences from the memory manager object.
338ad8b1aafSjsg  */
339ad8b1aafSjsg static inline void
ttm_resource_manager_cleanup(struct ttm_resource_manager * man)340ad8b1aafSjsg ttm_resource_manager_cleanup(struct ttm_resource_manager *man)
341ad8b1aafSjsg {
342ad8b1aafSjsg 	dma_fence_put(man->move);
343ad8b1aafSjsg 	man->move = NULL;
344ad8b1aafSjsg }
345ad8b1aafSjsg 
3461bb76ff1Sjsg void ttm_lru_bulk_move_init(struct ttm_lru_bulk_move *bulk);
3471bb76ff1Sjsg void ttm_lru_bulk_move_tail(struct ttm_lru_bulk_move *bulk);
3481bb76ff1Sjsg 
3491bb76ff1Sjsg void ttm_resource_add_bulk_move(struct ttm_resource *res,
3501bb76ff1Sjsg 				struct ttm_buffer_object *bo);
3511bb76ff1Sjsg void ttm_resource_del_bulk_move(struct ttm_resource *res,
3521bb76ff1Sjsg 				struct ttm_buffer_object *bo);
3531bb76ff1Sjsg void ttm_resource_move_to_lru_tail(struct ttm_resource *res);
3541bb76ff1Sjsg 
3555ca02815Sjsg void ttm_resource_init(struct ttm_buffer_object *bo,
356ad8b1aafSjsg                        const struct ttm_place *place,
357ad8b1aafSjsg                        struct ttm_resource *res);
3581bb76ff1Sjsg void ttm_resource_fini(struct ttm_resource_manager *man,
3591bb76ff1Sjsg 		       struct ttm_resource *res);
3601bb76ff1Sjsg 
3615ca02815Sjsg int ttm_resource_alloc(struct ttm_buffer_object *bo,
3625ca02815Sjsg 		       const struct ttm_place *place,
3635ca02815Sjsg 		       struct ttm_resource **res);
3645ca02815Sjsg void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res);
3651bb76ff1Sjsg bool ttm_resource_intersects(struct ttm_device *bdev,
3661bb76ff1Sjsg 			     struct ttm_resource *res,
3671bb76ff1Sjsg 			     const struct ttm_place *place,
3681bb76ff1Sjsg 			     size_t size);
3691bb76ff1Sjsg bool ttm_resource_compatible(struct ttm_device *bdev,
3701bb76ff1Sjsg 			     struct ttm_resource *res,
3711bb76ff1Sjsg 			     const struct ttm_place *place,
3721bb76ff1Sjsg 			     size_t size);
3731bb76ff1Sjsg bool ttm_resource_compat(struct ttm_resource *res,
3741bb76ff1Sjsg 			 struct ttm_placement *placement);
3751bb76ff1Sjsg void ttm_resource_set_bo(struct ttm_resource *res,
3761bb76ff1Sjsg 			 struct ttm_buffer_object *bo);
377ad8b1aafSjsg 
378ad8b1aafSjsg void ttm_resource_manager_init(struct ttm_resource_manager *man,
3791bb76ff1Sjsg 			       struct ttm_device *bdev,
3801bb76ff1Sjsg 			       uint64_t size);
381ad8b1aafSjsg 
3825ca02815Sjsg int ttm_resource_manager_evict_all(struct ttm_device *bdev,
383ad8b1aafSjsg 				   struct ttm_resource_manager *man);
384ad8b1aafSjsg 
3851bb76ff1Sjsg uint64_t ttm_resource_manager_usage(struct ttm_resource_manager *man);
386ad8b1aafSjsg void ttm_resource_manager_debug(struct ttm_resource_manager *man,
387ad8b1aafSjsg 				struct drm_printer *p);
388ad8b1aafSjsg 
3891bb76ff1Sjsg struct ttm_resource *
3901bb76ff1Sjsg ttm_resource_manager_first(struct ttm_resource_manager *man,
3911bb76ff1Sjsg 			   struct ttm_resource_cursor *cursor);
3921bb76ff1Sjsg struct ttm_resource *
3931bb76ff1Sjsg ttm_resource_manager_next(struct ttm_resource_manager *man,
3941bb76ff1Sjsg 			  struct ttm_resource_cursor *cursor,
3951bb76ff1Sjsg 			  struct ttm_resource *res);
3961bb76ff1Sjsg 
3971bb76ff1Sjsg /**
3981bb76ff1Sjsg  * ttm_resource_manager_for_each_res - iterate over all resources
3991bb76ff1Sjsg  * @man: the resource manager
4001bb76ff1Sjsg  * @cursor: struct ttm_resource_cursor for the current position
4011bb76ff1Sjsg  * @res: the current resource
4021bb76ff1Sjsg  *
4031bb76ff1Sjsg  * Iterate over all the evictable resources in a resource manager.
4041bb76ff1Sjsg  */
4051bb76ff1Sjsg #define ttm_resource_manager_for_each_res(man, cursor, res)		\
4061bb76ff1Sjsg 	for (res = ttm_resource_manager_first(man, cursor); res;	\
4071bb76ff1Sjsg 	     res = ttm_resource_manager_next(man, cursor, res))
4081bb76ff1Sjsg 
4095ca02815Sjsg struct ttm_kmap_iter *
4105ca02815Sjsg ttm_kmap_iter_iomap_init(struct ttm_kmap_iter_iomap *iter_io,
4115ca02815Sjsg 			 struct io_mapping *iomap,
4125ca02815Sjsg 			 struct sg_table *st,
4135ca02815Sjsg 			 resource_size_t start);
4145ca02815Sjsg 
4155ca02815Sjsg struct ttm_kmap_iter_linear_io;
4165ca02815Sjsg 
4175ca02815Sjsg struct ttm_kmap_iter *
4185ca02815Sjsg ttm_kmap_iter_linear_io_init(struct ttm_kmap_iter_linear_io *iter_io,
4195ca02815Sjsg 			     struct ttm_device *bdev,
4205ca02815Sjsg 			     struct ttm_resource *mem);
4215ca02815Sjsg 
4225ca02815Sjsg void ttm_kmap_iter_linear_io_fini(struct ttm_kmap_iter_linear_io *iter_io,
4235ca02815Sjsg 				  struct ttm_device *bdev,
4245ca02815Sjsg 				  struct ttm_resource *mem);
4251bb76ff1Sjsg 
4261bb76ff1Sjsg #ifdef __linux__
4271bb76ff1Sjsg void ttm_resource_manager_create_debugfs(struct ttm_resource_manager *man,
4281bb76ff1Sjsg 					 struct dentry * parent,
4291bb76ff1Sjsg 					 const char *name);
4301bb76ff1Sjsg #endif
431ad8b1aafSjsg #endif
432