• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24  * USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 /*
28  * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
29  */
30 
31 #ifndef _TTM_BO_API_H_
32 #define _TTM_BO_API_H_
33 
34 #include <drm/drm_gem.h>
35 #include <drm/drm_hashtab.h>
36 #include <drm/drm_vma_manager.h>
37 #include <linux/kref.h>
38 #include <linux/list.h>
39 #include <linux/wait.h>
40 #include <linux/mutex.h>
41 #include <linux/mm.h>
42 #include <linux/bitmap.h>
43 #include <linux/dma-resv.h>
44 
45 #include "ttm_resource.h"
46 
47 struct ttm_bo_global;
48 
49 struct ttm_bo_device;
50 
51 struct drm_mm_node;
52 
53 struct ttm_placement;
54 
55 struct ttm_place;
56 
57 struct ttm_lru_bulk_move;
58 
59 /**
60  * enum ttm_bo_type
61  *
62  * @ttm_bo_type_device:	These are 'normal' buffers that can
63  * be mmapped by user space. Each of these bos occupy a slot in the
64  * device address space, that can be used for normal vm operations.
65  *
66  * @ttm_bo_type_kernel: These buffers are like ttm_bo_type_device buffers,
67  * but they cannot be accessed from user-space. For kernel-only use.
68  *
69  * @ttm_bo_type_sg: Buffer made from dmabuf sg table shared with another
70  * driver.
71  */
72 
73 enum ttm_bo_type {
74 	ttm_bo_type_device,
75 	ttm_bo_type_kernel,
76 	ttm_bo_type_sg
77 };
78 
79 struct ttm_tt;
80 
81 /**
82  * struct ttm_buffer_object
83  *
84  * @base: drm_gem_object superclass data.
85  * @bdev: Pointer to the buffer object device structure.
86  * @type: The bo type.
87  * @destroy: Destruction function. If NULL, kfree is used.
88  * @num_pages: Actual number of pages.
89  * @acc_size: Accounted size for this object.
90  * @kref: Reference count of this buffer object. When this refcount reaches
91  * zero, the object is destroyed or put on the delayed delete list.
92  * @mem: structure describing current placement.
93  * @persistent_swap_storage: Usually the swap storage is deleted for buffers
94  * pinned in physical memory. If this behaviour is not desired, this member
95  * holds a pointer to a persistent shmem object.
96  * @ttm: TTM structure holding system pages.
97  * @evicted: Whether the object was evicted without user-space knowing.
98  * @deleted: True if the object is only a zombie and already deleted.
99  * @lru: List head for the lru list.
100  * @ddestroy: List head for the delayed destroy list.
101  * @swap: List head for swap LRU list.
102  * @moving: Fence set when BO is moving
103  * @offset: The current GPU offset, which can have different meanings
104  * depending on the memory type. For SYSTEM type memory, it should be 0.
105  * @cur_placement: Hint of current placement.
106  *
107  * Base class for TTM buffer object, that deals with data placement and CPU
108  * mappings. GPU mappings are really up to the driver, but for simpler GPUs
109  * the driver can usually use the placement offset @offset directly as the
110  * GPU virtual address. For drivers implementing multiple
111  * GPU memory manager contexts, the driver should manage the address space
112  * in these contexts separately and use these objects to get the correct
113  * placement and caching for these GPU maps. This makes it possible to use
114  * these objects for even quite elaborate memory management schemes.
115  * The destroy member, the API visibility of this object makes it possible
116  * to derive driver specific types.
117  */
118 
119 struct ttm_buffer_object {
120 	struct drm_gem_object base;
121 
122 	/**
123 	 * Members constant at init.
124 	 */
125 
126 	struct ttm_bo_device *bdev;
127 	enum ttm_bo_type type;
128 	void (*destroy) (struct ttm_buffer_object *);
129 	unsigned long num_pages;
130 	size_t acc_size;
131 
132 	/**
133 	* Members not needing protection.
134 	*/
135 	struct kref kref;
136 
137 	/**
138 	 * Members protected by the bo::resv::reserved lock.
139 	 */
140 
141 	struct ttm_resource mem;
142 	struct file *persistent_swap_storage;
143 	struct ttm_tt *ttm;
144 	bool deleted;
145 
146 	/**
147 	 * Members protected by the bdev::lru_lock.
148 	 */
149 
150 	struct list_head lru;
151 	struct list_head ddestroy;
152 	struct list_head swap;
153 
154 	/**
155 	 * Members protected by a bo reservation.
156 	 */
157 
158 	struct dma_fence *moving;
159 	unsigned priority;
160 	unsigned pin_count;
161 
162 	/**
163 	 * Special members that are protected by the reserve lock
164 	 * and the bo::lock when written to. Can be read with
165 	 * either of these locks held.
166 	 */
167 
168 	struct sg_table *sg;
169 };
170 
171 /**
172  * struct ttm_bo_kmap_obj
173  *
174  * @virtual: The current kernel virtual address.
175  * @page: The page when kmap'ing a single page.
176  * @bo_kmap_type: Type of bo_kmap.
177  *
178  * Object describing a kernel mapping. Since a TTM bo may be located
179  * in various memory types with various caching policies, the
180  * mapping can either be an ioremap, a vmap, a kmap or part of a
181  * premapped region.
182  */
183 
184 #define TTM_BO_MAP_IOMEM_MASK 0x80
185 struct ttm_bo_kmap_obj {
186 	void *virtual;
187 	struct page *page;
188 	enum {
189 		ttm_bo_map_iomap        = 1 | TTM_BO_MAP_IOMEM_MASK,
190 		ttm_bo_map_vmap         = 2,
191 		ttm_bo_map_kmap         = 3,
192 		ttm_bo_map_premapped    = 4 | TTM_BO_MAP_IOMEM_MASK,
193 	} bo_kmap_type;
194 	struct ttm_buffer_object *bo;
195 };
196 
197 /**
198  * struct ttm_operation_ctx
199  *
200  * @interruptible: Sleep interruptible if sleeping.
201  * @no_wait_gpu: Return immediately if the GPU is busy.
202  * @resv: Reservation object to allow reserved evictions with.
203  * @flags: Including the following flags
204  *
205  * Context for TTM operations like changing buffer placement or general memory
206  * allocation.
207  */
208 struct ttm_operation_ctx {
209 	bool interruptible;
210 	bool no_wait_gpu;
211 	struct dma_resv *resv;
212 	uint64_t bytes_moved;
213 	uint32_t flags;
214 };
215 
216 /* Allow eviction of reserved BOs */
217 #define TTM_OPT_FLAG_ALLOW_RES_EVICT		0x1
218 /* when serving page fault or suspend, allow alloc anyway */
219 #define TTM_OPT_FLAG_FORCE_ALLOC		0x2
220 
221 /**
222  * ttm_bo_get - reference a struct ttm_buffer_object
223  *
224  * @bo: The buffer object.
225  */
ttm_bo_get(struct ttm_buffer_object * bo)226 static inline void ttm_bo_get(struct ttm_buffer_object *bo)
227 {
228 	kref_get(&bo->kref);
229 }
230 
231 /**
232  * ttm_bo_get_unless_zero - reference a struct ttm_buffer_object unless
233  * its refcount has already reached zero.
234  * @bo: The buffer object.
235  *
236  * Used to reference a TTM buffer object in lookups where the object is removed
237  * from the lookup structure during the destructor and for RCU lookups.
238  *
239  * Returns: @bo if the referencing was successful, NULL otherwise.
240  */
241 static inline __must_check struct ttm_buffer_object *
ttm_bo_get_unless_zero(struct ttm_buffer_object * bo)242 ttm_bo_get_unless_zero(struct ttm_buffer_object *bo)
243 {
244 	if (!kref_get_unless_zero(&bo->kref))
245 		return NULL;
246 	return bo;
247 }
248 
249 /**
250  * ttm_bo_wait - wait for buffer idle.
251  *
252  * @bo:  The buffer object.
253  * @interruptible:  Use interruptible wait.
254  * @no_wait:  Return immediately if buffer is busy.
255  *
256  * This function must be called with the bo::mutex held, and makes
257  * sure any previous rendering to the buffer is completed.
258  * Note: It might be necessary to block validations before the
259  * wait by reserving the buffer.
260  * Returns -EBUSY if no_wait is true and the buffer is busy.
261  * Returns -ERESTARTSYS if interrupted by a signal.
262  */
263 int ttm_bo_wait(struct ttm_buffer_object *bo, bool interruptible, bool no_wait);
264 
265 /**
266  * ttm_bo_mem_compat - Check if proposed placement is compatible with a bo
267  *
268  * @placement:  Return immediately if buffer is busy.
269  * @mem:  The struct ttm_resource indicating the region where the bo resides
270  * @new_flags: Describes compatible placement found
271  *
272  * Returns true if the placement is compatible
273  */
274 bool ttm_bo_mem_compat(struct ttm_placement *placement, struct ttm_resource *mem,
275 		       uint32_t *new_flags);
276 
277 /**
278  * ttm_bo_validate
279  *
280  * @bo: The buffer object.
281  * @placement: Proposed placement for the buffer object.
282  * @ctx: validation parameters.
283  *
284  * Changes placement and caching policy of the buffer object
285  * according proposed placement.
286  * Returns
287  * -EINVAL on invalid proposed placement.
288  * -ENOMEM on out-of-memory condition.
289  * -EBUSY if no_wait is true and buffer busy.
290  * -ERESTARTSYS if interrupted by a signal.
291  */
292 int ttm_bo_validate(struct ttm_buffer_object *bo,
293 		    struct ttm_placement *placement,
294 		    struct ttm_operation_ctx *ctx);
295 
296 /**
297  * ttm_bo_put
298  *
299  * @bo: The buffer object.
300  *
301  * Unreference a buffer object.
302  */
303 void ttm_bo_put(struct ttm_buffer_object *bo);
304 
305 /**
306  * ttm_bo_move_to_lru_tail
307  *
308  * @bo: The buffer object.
309  * @bulk: optional bulk move structure to remember BO positions
310  *
311  * Move this BO to the tail of all lru lists used to lookup and reserve an
312  * object. This function must be called with struct ttm_bo_global::lru_lock
313  * held, and is used to make a BO less likely to be considered for eviction.
314  */
315 void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo,
316 			     struct ttm_lru_bulk_move *bulk);
317 
318 /**
319  * ttm_bo_bulk_move_lru_tail
320  *
321  * @bulk: bulk move structure
322  *
323  * Bulk move BOs to the LRU tail, only valid to use when driver makes sure that
324  * BO order never changes. Should be called with ttm_bo_global::lru_lock held.
325  */
326 void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk);
327 
328 /**
329  * ttm_bo_lock_delayed_workqueue
330  *
331  * Prevent the delayed workqueue from running.
332  * Returns
333  * True if the workqueue was queued at the time
334  */
335 int ttm_bo_lock_delayed_workqueue(struct ttm_bo_device *bdev);
336 
337 /**
338  * ttm_bo_unlock_delayed_workqueue
339  *
340  * Allows the delayed workqueue to run.
341  */
342 void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev, int resched);
343 
344 /**
345  * ttm_bo_eviction_valuable
346  *
347  * @bo: The buffer object to evict
348  * @place: the placement we need to make room for
349  *
350  * Check if it is valuable to evict the BO to make room for the given placement.
351  */
352 bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
353 			      const struct ttm_place *place);
354 
355 size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev,
356 			   unsigned long bo_size,
357 			   unsigned struct_size);
358 
359 /**
360  * ttm_bo_init_reserved
361  *
362  * @bdev: Pointer to a ttm_bo_device struct.
363  * @bo: Pointer to a ttm_buffer_object to be initialized.
364  * @size: Requested size of buffer object.
365  * @type: Requested type of buffer object.
366  * @flags: Initial placement flags.
367  * @page_alignment: Data alignment in pages.
368  * @ctx: TTM operation context for memory allocation.
369  * @acc_size: Accounted size for this object.
370  * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
371  * @destroy: Destroy function. Use NULL for kfree().
372  *
373  * This function initializes a pre-allocated struct ttm_buffer_object.
374  * As this object may be part of a larger structure, this function,
375  * together with the @destroy function,
376  * enables driver-specific objects derived from a ttm_buffer_object.
377  *
378  * On successful return, the caller owns an object kref to @bo. The kref and
379  * list_kref are usually set to 1, but note that in some situations, other
380  * tasks may already be holding references to @bo as well.
381  * Furthermore, if resv == NULL, the buffer's reservation lock will be held,
382  * and it is the caller's responsibility to call ttm_bo_unreserve.
383  *
384  * If a failure occurs, the function will call the @destroy function, or
385  * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is
386  * illegal and will likely cause memory corruption.
387  *
388  * Returns
389  * -ENOMEM: Out of memory.
390  * -EINVAL: Invalid placement flags.
391  * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
392  */
393 
394 int ttm_bo_init_reserved(struct ttm_bo_device *bdev,
395 			 struct ttm_buffer_object *bo,
396 			 unsigned long size,
397 			 enum ttm_bo_type type,
398 			 struct ttm_placement *placement,
399 			 uint32_t page_alignment,
400 			 struct ttm_operation_ctx *ctx,
401 			 size_t acc_size,
402 			 struct sg_table *sg,
403 			 struct dma_resv *resv,
404 			 void (*destroy) (struct ttm_buffer_object *));
405 
406 /**
407  * ttm_bo_init
408  *
409  * @bdev: Pointer to a ttm_bo_device struct.
410  * @bo: Pointer to a ttm_buffer_object to be initialized.
411  * @size: Requested size of buffer object.
412  * @type: Requested type of buffer object.
413  * @flags: Initial placement flags.
414  * @page_alignment: Data alignment in pages.
415  * @interruptible: If needing to sleep to wait for GPU resources,
416  * sleep interruptible.
417  * pinned in physical memory. If this behaviour is not desired, this member
418  * holds a pointer to a persistent shmem object. Typically, this would
419  * point to the shmem object backing a GEM object if TTM is used to back a
420  * GEM user interface.
421  * @acc_size: Accounted size for this object.
422  * @resv: Pointer to a dma_resv, or NULL to let ttm allocate one.
423  * @destroy: Destroy function. Use NULL for kfree().
424  *
425  * This function initializes a pre-allocated struct ttm_buffer_object.
426  * As this object may be part of a larger structure, this function,
427  * together with the @destroy function,
428  * enables driver-specific objects derived from a ttm_buffer_object.
429  *
430  * On successful return, the caller owns an object kref to @bo. The kref and
431  * list_kref are usually set to 1, but note that in some situations, other
432  * tasks may already be holding references to @bo as well.
433  *
434  * If a failure occurs, the function will call the @destroy function, or
435  * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is
436  * illegal and will likely cause memory corruption.
437  *
438  * Returns
439  * -ENOMEM: Out of memory.
440  * -EINVAL: Invalid placement flags.
441  * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
442  */
443 int ttm_bo_init(struct ttm_bo_device *bdev, struct ttm_buffer_object *bo,
444 		unsigned long size, enum ttm_bo_type type,
445 		struct ttm_placement *placement,
446 		uint32_t page_alignment, bool interrubtible, size_t acc_size,
447 		struct sg_table *sg, struct dma_resv *resv,
448 		void (*destroy) (struct ttm_buffer_object *));
449 
450 /**
451  * ttm_bo_create
452  *
453  * @bdev: Pointer to a ttm_bo_device struct.
454  * @size: Requested size of buffer object.
455  * @type: Requested type of buffer object.
456  * @placement: Initial placement.
457  * @page_alignment: Data alignment in pages.
458  * @interruptible: If needing to sleep while waiting for GPU resources,
459  * sleep interruptible.
460  * @p_bo: On successful completion *p_bo points to the created object.
461  *
462  * This function allocates a ttm_buffer_object, and then calls ttm_bo_init
463  * on that object. The destroy function is set to kfree().
464  * Returns
465  * -ENOMEM: Out of memory.
466  * -EINVAL: Invalid placement flags.
467  * -ERESTARTSYS: Interrupted by signal while waiting for resources.
468  */
469 int ttm_bo_create(struct ttm_bo_device *bdev, unsigned long size,
470 		  enum ttm_bo_type type, struct ttm_placement *placement,
471 		  uint32_t page_alignment, bool interruptible,
472 		  struct ttm_buffer_object **p_bo);
473 
474 /**
475  * ttm_bo_evict_mm
476  *
477  * @bdev: Pointer to a ttm_bo_device struct.
478  * @mem_type: The memory type.
479  *
480  * Evicts all buffers on the lru list of the memory type.
481  * This is normally part of a VT switch or an
482  * out-of-memory-space-due-to-fragmentation handler.
483  * The caller must make sure that there are no other processes
484  * currently validating buffers, and can do that by taking the
485  * struct ttm_bo_device::ttm_lock in write mode.
486  *
487  * Returns:
488  * -EINVAL: Invalid or uninitialized memory type.
489  * -ERESTARTSYS: The call was interrupted by a signal while waiting to
490  * evict a buffer.
491  */
492 int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type);
493 
494 /**
495  * ttm_kmap_obj_virtual
496  *
497  * @map: A struct ttm_bo_kmap_obj returned from ttm_bo_kmap.
498  * @is_iomem: Pointer to an integer that on return indicates 1 if the
499  * virtual map is io memory, 0 if normal memory.
500  *
501  * Returns the virtual address of a buffer object area mapped by ttm_bo_kmap.
502  * If *is_iomem is 1 on return, the virtual address points to an io memory area,
503  * that should strictly be accessed by the iowriteXX() and similar functions.
504  */
ttm_kmap_obj_virtual(struct ttm_bo_kmap_obj * map,bool * is_iomem)505 static inline void *ttm_kmap_obj_virtual(struct ttm_bo_kmap_obj *map,
506 					 bool *is_iomem)
507 {
508 	*is_iomem = !!(map->bo_kmap_type & TTM_BO_MAP_IOMEM_MASK);
509 	return map->virtual;
510 }
511 
512 /**
513  * ttm_bo_kmap
514  *
515  * @bo: The buffer object.
516  * @start_page: The first page to map.
517  * @num_pages: Number of pages to map.
518  * @map: pointer to a struct ttm_bo_kmap_obj representing the map.
519  *
520  * Sets up a kernel virtual mapping, using ioremap, vmap or kmap to the
521  * data in the buffer object. The ttm_kmap_obj_virtual function can then be
522  * used to obtain a virtual address to the data.
523  *
524  * Returns
525  * -ENOMEM: Out of memory.
526  * -EINVAL: Invalid range.
527  */
528 int ttm_bo_kmap(struct ttm_buffer_object *bo, unsigned long start_page,
529 		unsigned long num_pages, struct ttm_bo_kmap_obj *map);
530 
531 /**
532  * ttm_bo_kunmap
533  *
534  * @map: Object describing the map to unmap.
535  *
536  * Unmaps a kernel map set up by ttm_bo_kmap.
537  */
538 void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map);
539 
540 /**
541  * ttm_bo_mmap_obj - mmap memory backed by a ttm buffer object.
542  *
543  * @vma:       vma as input from the fbdev mmap method.
544  * @bo:        The bo backing the address space.
545  *
546  * Maps a buffer object.
547  */
548 int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo);
549 
550 /**
551  * ttm_bo_mmap - mmap out of the ttm device address space.
552  *
553  * @filp:      filp as input from the mmap method.
554  * @vma:       vma as input from the mmap method.
555  * @bdev:      Pointer to the ttm_bo_device with the address space manager.
556  *
557  * This function is intended to be called by the device mmap method.
558  * if the device address space is to be backed by the bo manager.
559  */
560 int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma,
561 		struct ttm_bo_device *bdev);
562 
563 /**
564  * ttm_bo_io
565  *
566  * @bdev:      Pointer to the struct ttm_bo_device.
567  * @filp:      Pointer to the struct file attempting to read / write.
568  * @wbuf:      User-space pointer to address of buffer to write. NULL on read.
569  * @rbuf:      User-space pointer to address of buffer to read into.
570  * Null on write.
571  * @count:     Number of bytes to read / write.
572  * @f_pos:     Pointer to current file position.
573  * @write:     1 for read, 0 for write.
574  *
575  * This function implements read / write into ttm buffer objects, and is
576  * intended to
577  * be called from the fops::read and fops::write method.
578  * Returns:
579  * See man (2) write, man(2) read. In particular,
580  * the function may return -ERESTARTSYS if
581  * interrupted by a signal.
582  */
583 ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
584 		  const char __user *wbuf, char __user *rbuf,
585 		  size_t count, loff_t *f_pos, bool write);
586 
587 int ttm_bo_swapout(struct ttm_bo_global *glob,
588 			struct ttm_operation_ctx *ctx);
589 void ttm_bo_swapout_all(void);
590 
591 /**
592  * ttm_bo_uses_embedded_gem_object - check if the given bo uses the
593  * embedded drm_gem_object.
594  *
595  * Most ttm drivers are using gem too, so the embedded
596  * ttm_buffer_object.base will be initialized by the driver (before
597  * calling ttm_bo_init).  It is also possible to use ttm without gem
598  * though (vmwgfx does that).
599  *
600  * This helper will figure whenever a given ttm bo is a gem object too
601  * or not.
602  *
603  * @bo: The bo to check.
604  */
ttm_bo_uses_embedded_gem_object(struct ttm_buffer_object * bo)605 static inline bool ttm_bo_uses_embedded_gem_object(struct ttm_buffer_object *bo)
606 {
607 	return bo->base.dev != NULL;
608 }
609 
610 /**
611  * ttm_bo_pin - Pin the buffer object.
612  * @bo: The buffer object to pin
613  *
614  * Make sure the buffer is not evicted any more during memory pressure.
615  */
ttm_bo_pin(struct ttm_buffer_object * bo)616 static inline void ttm_bo_pin(struct ttm_buffer_object *bo)
617 {
618 	dma_resv_assert_held(bo->base.resv);
619 	++bo->pin_count;
620 }
621 
622 /**
623  * ttm_bo_unpin - Unpin the buffer object.
624  * @bo: The buffer object to unpin
625  *
626  * Allows the buffer object to be evicted again during memory pressure.
627  */
ttm_bo_unpin(struct ttm_buffer_object * bo)628 static inline void ttm_bo_unpin(struct ttm_buffer_object *bo)
629 {
630 	dma_resv_assert_held(bo->base.resv);
631 	if (bo->pin_count)
632 		--bo->pin_count;
633 	else
634 		WARN_ON_ONCE(true);
635 }
636 
637 int ttm_mem_evict_first(struct ttm_bo_device *bdev,
638 			struct ttm_resource_manager *man,
639 			const struct ttm_place *place,
640 			struct ttm_operation_ctx *ctx,
641 			struct ww_acquire_ctx *ticket);
642 
643 /* Default number of pre-faulted pages in the TTM fault handler */
644 #define TTM_BO_VM_NUM_PREFAULT 16
645 
646 vm_fault_t ttm_bo_vm_reserve(struct ttm_buffer_object *bo,
647 			     struct vm_fault *vmf);
648 
649 vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,
650 				    pgprot_t prot,
651 				    pgoff_t num_prefault,
652 				    pgoff_t fault_page_size);
653 
654 vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf);
655 
656 void ttm_bo_vm_open(struct vm_area_struct *vma);
657 
658 void ttm_bo_vm_close(struct vm_area_struct *vma);
659 
660 int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr,
661 		     void *buf, int len, int write);
662 
663 #endif
664