ttm_bo_api.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. #ifndef _TTM_BO_API_H_
  31. #define _TTM_BO_API_H_
  32. #include "drm_hashtab.h"
  33. #include <linux/kref.h>
  34. #include <linux/list.h>
  35. #include <linux/wait.h>
  36. #include <linux/mutex.h>
  37. #include <linux/mm.h>
  38. #include <linux/rbtree.h>
  39. #include <linux/bitmap.h>
  40. struct ttm_bo_device;
  41. struct drm_mm_node;
  42. /**
  43. * struct ttm_placement
  44. *
  45. * @fpfn: first valid page frame number to put the object
  46. * @lpfn: last valid page frame number to put the object
  47. * @num_placement: number of preferred placements
  48. * @placement: preferred placements
  49. * @num_busy_placement: number of preferred placements when need to evict buffer
  50. * @busy_placement: preferred placements when need to evict buffer
  51. *
  52. * Structure indicating the placement you request for an object.
  53. */
  54. struct ttm_placement {
  55. unsigned fpfn;
  56. unsigned lpfn;
  57. unsigned num_placement;
  58. const uint32_t *placement;
  59. unsigned num_busy_placement;
  60. const uint32_t *busy_placement;
  61. };
  62. /**
  63. * struct ttm_bus_placement
  64. *
  65. * @addr: mapped virtual address
  66. * @base: bus base address
  67. * @is_iomem: is this io memory ?
  68. * @size: size in byte
  69. * @offset: offset from the base address
  70. * @io_reserved_vm: The VM system has a refcount in @io_reserved_count
  71. * @io_reserved_count: Refcounting the numbers of callers to ttm_mem_io_reserve
  72. *
  73. * Structure indicating the bus placement of an object.
  74. */
  75. struct ttm_bus_placement {
  76. void *addr;
  77. unsigned long base;
  78. unsigned long size;
  79. unsigned long offset;
  80. bool is_iomem;
  81. bool io_reserved_vm;
  82. uint64_t io_reserved_count;
  83. };
  84. /**
  85. * struct ttm_mem_reg
  86. *
  87. * @mm_node: Memory manager node.
  88. * @size: Requested size of memory region.
  89. * @num_pages: Actual size of memory region in pages.
  90. * @page_alignment: Page alignment.
  91. * @placement: Placement flags.
  92. * @bus: Placement on io bus accessible to the CPU
  93. *
  94. * Structure indicating the placement and space resources used by a
  95. * buffer object.
  96. */
  97. struct ttm_mem_reg {
  98. void *mm_node;
  99. unsigned long start;
  100. unsigned long size;
  101. unsigned long num_pages;
  102. uint32_t page_alignment;
  103. uint32_t mem_type;
  104. uint32_t placement;
  105. struct ttm_bus_placement bus;
  106. };
  107. /**
  108. * enum ttm_bo_type
  109. *
  110. * @ttm_bo_type_device: These are 'normal' buffers that can
  111. * be mmapped by user space. Each of these bos occupy a slot in the
  112. * device address space, that can be used for normal vm operations.
  113. *
  114. * @ttm_bo_type_kernel: These buffers are like ttm_bo_type_device buffers,
  115. * but they cannot be accessed from user-space. For kernel-only use.
  116. */
  117. enum ttm_bo_type {
  118. ttm_bo_type_device,
  119. ttm_bo_type_kernel
  120. };
  121. struct ttm_tt;
  122. /**
  123. * struct ttm_buffer_object
  124. *
  125. * @bdev: Pointer to the buffer object device structure.
  126. * @buffer_start: The virtual user-space start address of ttm_bo_type_user
  127. * buffers.
  128. * @type: The bo type.
  129. * @destroy: Destruction function. If NULL, kfree is used.
  130. * @num_pages: Actual number of pages.
  131. * @addr_space_offset: Address space offset.
  132. * @acc_size: Accounted size for this object.
  133. * @kref: Reference count of this buffer object. When this refcount reaches
  134. * zero, the object is put on the delayed delete list.
  135. * @list_kref: List reference count of this buffer object. This member is
  136. * used to avoid destruction while the buffer object is still on a list.
  137. * Lru lists may keep one refcount, the delayed delete list, and kref != 0
  138. * keeps one refcount. When this refcount reaches zero,
  139. * the object is destroyed.
  140. * @event_queue: Queue for processes waiting on buffer object status change.
  141. * @mem: structure describing current placement.
  142. * @persistent_swap_storage: Usually the swap storage is deleted for buffers
  143. * pinned in physical memory. If this behaviour is not desired, this member
  144. * holds a pointer to a persistent shmem object.
  145. * @ttm: TTM structure holding system pages.
  146. * @evicted: Whether the object was evicted without user-space knowing.
  147. * @cpu_writes: For synchronization. Number of cpu writers.
  148. * @lru: List head for the lru list.
  149. * @ddestroy: List head for the delayed destroy list.
  150. * @swap: List head for swap LRU list.
  151. * @val_seq: Sequence of the validation holding the @reserved lock.
  152. * Used to avoid starvation when many processes compete to validate the
  153. * buffer. This member is protected by the bo_device::lru_lock.
  154. * @seq_valid: The value of @val_seq is valid. This value is protected by
  155. * the bo_device::lru_lock.
  156. * @reserved: Deadlock-free lock used for synchronization state transitions.
  157. * @sync_obj_arg: Opaque argument to synchronization object function.
  158. * @sync_obj: Pointer to a synchronization object.
  159. * @priv_flags: Flags describing buffer object internal state.
  160. * @vm_rb: Rb node for the vm rb tree.
  161. * @vm_node: Address space manager node.
  162. * @offset: The current GPU offset, which can have different meanings
  163. * depending on the memory type. For SYSTEM type memory, it should be 0.
  164. * @cur_placement: Hint of current placement.
  165. *
  166. * Base class for TTM buffer object, that deals with data placement and CPU
  167. * mappings. GPU mappings are really up to the driver, but for simpler GPUs
  168. * the driver can usually use the placement offset @offset directly as the
  169. * GPU virtual address. For drivers implementing multiple
  170. * GPU memory manager contexts, the driver should manage the address space
  171. * in these contexts separately and use these objects to get the correct
  172. * placement and caching for these GPU maps. This makes it possible to use
  173. * these objects for even quite elaborate memory management schemes.
  174. * The destroy member, the API visibility of this object makes it possible
  175. * to derive driver specific types.
  176. */
  177. struct ttm_buffer_object {
  178. /**
  179. * Members constant at init.
  180. */
  181. struct ttm_bo_global *glob;
  182. struct ttm_bo_device *bdev;
  183. unsigned long buffer_start;
  184. enum ttm_bo_type type;
  185. void (*destroy) (struct ttm_buffer_object *);
  186. unsigned long num_pages;
  187. uint64_t addr_space_offset;
  188. size_t acc_size;
  189. /**
  190. * Members not needing protection.
  191. */
  192. struct kref kref;
  193. struct kref list_kref;
  194. wait_queue_head_t event_queue;
  195. /**
  196. * Members protected by the bo::reserved lock.
  197. */
  198. struct ttm_mem_reg mem;
  199. struct file *persistent_swap_storage;
  200. struct ttm_tt *ttm;
  201. bool evicted;
  202. /**
  203. * Members protected by the bo::reserved lock only when written to.
  204. */
  205. atomic_t cpu_writers;
  206. /**
  207. * Members protected by the bdev::lru_lock.
  208. */
  209. struct list_head lru;
  210. struct list_head ddestroy;
  211. struct list_head swap;
  212. struct list_head io_reserve_lru;
  213. uint32_t val_seq;
  214. bool seq_valid;
  215. /**
  216. * Members protected by the bdev::lru_lock
  217. * only when written to.
  218. */
  219. atomic_t reserved;
  220. /**
  221. * Members protected by struct buffer_object_device::fence_lock
  222. * In addition, setting sync_obj to anything else
  223. * than NULL requires bo::reserved to be held. This allows for
  224. * checking NULL while reserved but not holding the mentioned lock.
  225. */
  226. void *sync_obj_arg;
  227. void *sync_obj;
  228. unsigned long priv_flags;
  229. /**
  230. * Members protected by the bdev::vm_lock
  231. */
  232. struct rb_node vm_rb;
  233. struct drm_mm_node *vm_node;
  234. /**
  235. * Special members that are protected by the reserve lock
  236. * and the bo::lock when written to. Can be read with
  237. * either of these locks held.
  238. */
  239. unsigned long offset;
  240. uint32_t cur_placement;
  241. };
  242. /**
  243. * struct ttm_bo_kmap_obj
  244. *
  245. * @virtual: The current kernel virtual address.
  246. * @page: The page when kmap'ing a single page.
  247. * @bo_kmap_type: Type of bo_kmap.
  248. *
  249. * Object describing a kernel mapping. Since a TTM bo may be located
  250. * in various memory types with various caching policies, the
  251. * mapping can either be an ioremap, a vmap, a kmap or part of a
  252. * premapped region.
  253. */
  254. #define TTM_BO_MAP_IOMEM_MASK 0x80
  255. struct ttm_bo_kmap_obj {
  256. void *virtual;
  257. struct page *page;
  258. enum {
  259. ttm_bo_map_iomap = 1 | TTM_BO_MAP_IOMEM_MASK,
  260. ttm_bo_map_vmap = 2,
  261. ttm_bo_map_kmap = 3,
  262. ttm_bo_map_premapped = 4 | TTM_BO_MAP_IOMEM_MASK,
  263. } bo_kmap_type;
  264. struct ttm_buffer_object *bo;
  265. };
  266. /**
  267. * ttm_bo_reference - reference a struct ttm_buffer_object
  268. *
  269. * @bo: The buffer object.
  270. *
  271. * Returns a refcounted pointer to a buffer object.
  272. */
  273. static inline struct ttm_buffer_object *
  274. ttm_bo_reference(struct ttm_buffer_object *bo)
  275. {
  276. kref_get(&bo->kref);
  277. return bo;
  278. }
  279. /**
  280. * ttm_bo_wait - wait for buffer idle.
  281. *
  282. * @bo: The buffer object.
  283. * @interruptible: Use interruptible wait.
  284. * @no_wait: Return immediately if buffer is busy.
  285. *
  286. * This function must be called with the bo::mutex held, and makes
  287. * sure any previous rendering to the buffer is completed.
  288. * Note: It might be necessary to block validations before the
  289. * wait by reserving the buffer.
  290. * Returns -EBUSY if no_wait is true and the buffer is busy.
  291. * Returns -ERESTARTSYS if interrupted by a signal.
  292. */
  293. extern int ttm_bo_wait(struct ttm_buffer_object *bo, bool lazy,
  294. bool interruptible, bool no_wait);
  295. /**
  296. * ttm_bo_validate
  297. *
  298. * @bo: The buffer object.
  299. * @placement: Proposed placement for the buffer object.
  300. * @interruptible: Sleep interruptible if sleeping.
  301. * @no_wait_reserve: Return immediately if other buffers are busy.
  302. * @no_wait_gpu: Return immediately if the GPU is busy.
  303. *
  304. * Changes placement and caching policy of the buffer object
  305. * according proposed placement.
  306. * Returns
  307. * -EINVAL on invalid proposed placement.
  308. * -ENOMEM on out-of-memory condition.
  309. * -EBUSY if no_wait is true and buffer busy.
  310. * -ERESTARTSYS if interrupted by a signal.
  311. */
  312. extern int ttm_bo_validate(struct ttm_buffer_object *bo,
  313. struct ttm_placement *placement,
  314. bool interruptible, bool no_wait_reserve,
  315. bool no_wait_gpu);
  316. /**
  317. * ttm_bo_unref
  318. *
  319. * @bo: The buffer object.
  320. *
  321. * Unreference and clear a pointer to a buffer object.
  322. */
  323. extern void ttm_bo_unref(struct ttm_buffer_object **bo);
  324. /**
  325. * ttm_bo_list_ref_sub
  326. *
  327. * @bo: The buffer object.
  328. * @count: The number of references with which to decrease @bo::list_kref;
  329. * @never_free: The refcount should not reach zero with this operation.
  330. *
  331. * Release @count lru list references to this buffer object.
  332. */
  333. extern void ttm_bo_list_ref_sub(struct ttm_buffer_object *bo, int count,
  334. bool never_free);
  335. /**
  336. * ttm_bo_add_to_lru
  337. *
  338. * @bo: The buffer object.
  339. *
  340. * Add this bo to the relevant mem type lru and, if it's backed by
  341. * system pages (ttms) to the swap list.
  342. * This function must be called with struct ttm_bo_global::lru_lock held, and
  343. * is typically called immediately prior to unreserving a bo.
  344. */
  345. extern void ttm_bo_add_to_lru(struct ttm_buffer_object *bo);
  346. /**
  347. * ttm_bo_del_from_lru
  348. *
  349. * @bo: The buffer object.
  350. *
  351. * Remove this bo from all lru lists used to lookup and reserve an object.
  352. * This function must be called with struct ttm_bo_global::lru_lock held,
  353. * and is usually called just immediately after the bo has been reserved to
  354. * avoid recursive reservation from lru lists.
  355. */
  356. extern int ttm_bo_del_from_lru(struct ttm_buffer_object *bo);
  357. /**
  358. * ttm_bo_lock_delayed_workqueue
  359. *
  360. * Prevent the delayed workqueue from running.
  361. * Returns
  362. * True if the workqueue was queued at the time
  363. */
  364. extern int ttm_bo_lock_delayed_workqueue(struct ttm_bo_device *bdev);
  365. /**
  366. * ttm_bo_unlock_delayed_workqueue
  367. *
  368. * Allows the delayed workqueue to run.
  369. */
  370. extern void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev,
  371. int resched);
  372. /**
  373. * ttm_bo_synccpu_write_grab
  374. *
  375. * @bo: The buffer object:
  376. * @no_wait: Return immediately if buffer is busy.
  377. *
  378. * Synchronizes a buffer object for CPU RW access. This means
  379. * blocking command submission that affects the buffer and
  380. * waiting for buffer idle. This lock is recursive.
  381. * Returns
  382. * -EBUSY if the buffer is busy and no_wait is true.
  383. * -ERESTARTSYS if interrupted by a signal.
  384. */
  385. extern int
  386. ttm_bo_synccpu_write_grab(struct ttm_buffer_object *bo, bool no_wait);
  387. /**
  388. * ttm_bo_synccpu_write_release:
  389. *
  390. * @bo : The buffer object.
  391. *
  392. * Releases a synccpu lock.
  393. */
  394. extern void ttm_bo_synccpu_write_release(struct ttm_buffer_object *bo);
  395. /**
  396. * ttm_bo_acc_size
  397. *
  398. * @bdev: Pointer to a ttm_bo_device struct.
  399. * @bo_size: size of the buffer object in byte.
  400. * @struct_size: size of the structure holding buffer object datas
  401. *
  402. * Returns size to account for a buffer object
  403. */
  404. size_t ttm_bo_acc_size(struct ttm_bo_device *bdev,
  405. unsigned long bo_size,
  406. unsigned struct_size);
  407. size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev,
  408. unsigned long bo_size,
  409. unsigned struct_size);
  410. /**
  411. * ttm_bo_init
  412. *
  413. * @bdev: Pointer to a ttm_bo_device struct.
  414. * @bo: Pointer to a ttm_buffer_object to be initialized.
  415. * @size: Requested size of buffer object.
  416. * @type: Requested type of buffer object.
  417. * @flags: Initial placement flags.
  418. * @page_alignment: Data alignment in pages.
  419. * @buffer_start: Virtual address of user space data backing a
  420. * user buffer object.
  421. * @interruptible: If needing to sleep to wait for GPU resources,
  422. * sleep interruptible.
  423. * @persistent_swap_storage: Usually the swap storage is deleted for buffers
  424. * pinned in physical memory. If this behaviour is not desired, this member
  425. * holds a pointer to a persistent shmem object. Typically, this would
  426. * point to the shmem object backing a GEM object if TTM is used to back a
  427. * GEM user interface.
  428. * @acc_size: Accounted size for this object.
  429. * @destroy: Destroy function. Use NULL for kfree().
  430. *
  431. * This function initializes a pre-allocated struct ttm_buffer_object.
  432. * As this object may be part of a larger structure, this function,
  433. * together with the @destroy function,
  434. * enables driver-specific objects derived from a ttm_buffer_object.
  435. * On successful return, the object kref and list_kref are set to 1.
  436. * If a failure occurs, the function will call the @destroy function, or
  437. * kfree() if @destroy is NULL. Thus, after a failure, dereferencing @bo is
  438. * illegal and will likely cause memory corruption.
  439. *
  440. * Returns
  441. * -ENOMEM: Out of memory.
  442. * -EINVAL: Invalid placement flags.
  443. * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
  444. */
  445. extern int ttm_bo_init(struct ttm_bo_device *bdev,
  446. struct ttm_buffer_object *bo,
  447. unsigned long size,
  448. enum ttm_bo_type type,
  449. struct ttm_placement *placement,
  450. uint32_t page_alignment,
  451. unsigned long buffer_start,
  452. bool interrubtible,
  453. struct file *persistent_swap_storage,
  454. size_t acc_size,
  455. void (*destroy) (struct ttm_buffer_object *));
  456. /**
  457. * ttm_bo_synccpu_object_init
  458. *
  459. * @bdev: Pointer to a ttm_bo_device struct.
  460. * @bo: Pointer to a ttm_buffer_object to be initialized.
  461. * @size: Requested size of buffer object.
  462. * @type: Requested type of buffer object.
  463. * @flags: Initial placement flags.
  464. * @page_alignment: Data alignment in pages.
  465. * @buffer_start: Virtual address of user space data backing a
  466. * user buffer object.
  467. * @interruptible: If needing to sleep while waiting for GPU resources,
  468. * sleep interruptible.
  469. * @persistent_swap_storage: Usually the swap storage is deleted for buffers
  470. * pinned in physical memory. If this behaviour is not desired, this member
  471. * holds a pointer to a persistent shmem object. Typically, this would
  472. * point to the shmem object backing a GEM object if TTM is used to back a
  473. * GEM user interface.
  474. * @p_bo: On successful completion *p_bo points to the created object.
  475. *
  476. * This function allocates a ttm_buffer_object, and then calls ttm_bo_init
  477. * on that object. The destroy function is set to kfree().
  478. * Returns
  479. * -ENOMEM: Out of memory.
  480. * -EINVAL: Invalid placement flags.
  481. * -ERESTARTSYS: Interrupted by signal while waiting for resources.
  482. */
  483. extern int ttm_bo_create(struct ttm_bo_device *bdev,
  484. unsigned long size,
  485. enum ttm_bo_type type,
  486. struct ttm_placement *placement,
  487. uint32_t page_alignment,
  488. unsigned long buffer_start,
  489. bool interruptible,
  490. struct file *persistent_swap_storage,
  491. struct ttm_buffer_object **p_bo);
  492. /**
  493. * ttm_bo_check_placement
  494. *
  495. * @bo: the buffer object.
  496. * @placement: placements
  497. *
  498. * Performs minimal validity checking on an intended change of
  499. * placement flags.
  500. * Returns
  501. * -EINVAL: Intended change is invalid or not allowed.
  502. */
  503. extern int ttm_bo_check_placement(struct ttm_buffer_object *bo,
  504. struct ttm_placement *placement);
  505. /**
  506. * ttm_bo_init_mm
  507. *
  508. * @bdev: Pointer to a ttm_bo_device struct.
  509. * @mem_type: The memory type.
  510. * @p_size: size managed area in pages.
  511. *
  512. * Initialize a manager for a given memory type.
  513. * Note: if part of driver firstopen, it must be protected from a
  514. * potentially racing lastclose.
  515. * Returns:
  516. * -EINVAL: invalid size or memory type.
  517. * -ENOMEM: Not enough memory.
  518. * May also return driver-specified errors.
  519. */
  520. extern int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
  521. unsigned long p_size);
  522. /**
  523. * ttm_bo_clean_mm
  524. *
  525. * @bdev: Pointer to a ttm_bo_device struct.
  526. * @mem_type: The memory type.
  527. *
  528. * Take down a manager for a given memory type after first walking
  529. * the LRU list to evict any buffers left alive.
  530. *
  531. * Normally, this function is part of lastclose() or unload(), and at that
  532. * point there shouldn't be any buffers left created by user-space, since
  533. * there should've been removed by the file descriptor release() method.
  534. * However, before this function is run, make sure to signal all sync objects,
  535. * and verify that the delayed delete queue is empty. The driver must also
  536. * make sure that there are no NO_EVICT buffers present in this memory type
  537. * when the call is made.
  538. *
  539. * If this function is part of a VT switch, the caller must make sure that
  540. * there are no appications currently validating buffers before this
  541. * function is called. The caller can do that by first taking the
  542. * struct ttm_bo_device::ttm_lock in write mode.
  543. *
  544. * Returns:
  545. * -EINVAL: invalid or uninitialized memory type.
  546. * -EBUSY: There are still buffers left in this memory type.
  547. */
  548. extern int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type);
  549. /**
  550. * ttm_bo_evict_mm
  551. *
  552. * @bdev: Pointer to a ttm_bo_device struct.
  553. * @mem_type: The memory type.
  554. *
  555. * Evicts all buffers on the lru list of the memory type.
  556. * This is normally part of a VT switch or an
  557. * out-of-memory-space-due-to-fragmentation handler.
  558. * The caller must make sure that there are no other processes
  559. * currently validating buffers, and can do that by taking the
  560. * struct ttm_bo_device::ttm_lock in write mode.
  561. *
  562. * Returns:
  563. * -EINVAL: Invalid or uninitialized memory type.
  564. * -ERESTARTSYS: The call was interrupted by a signal while waiting to
  565. * evict a buffer.
  566. */
  567. extern int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type);
  568. /**
  569. * ttm_kmap_obj_virtual
  570. *
  571. * @map: A struct ttm_bo_kmap_obj returned from ttm_bo_kmap.
  572. * @is_iomem: Pointer to an integer that on return indicates 1 if the
  573. * virtual map is io memory, 0 if normal memory.
  574. *
  575. * Returns the virtual address of a buffer object area mapped by ttm_bo_kmap.
  576. * If *is_iomem is 1 on return, the virtual address points to an io memory area,
  577. * that should strictly be accessed by the iowriteXX() and similar functions.
  578. */
  579. static inline void *ttm_kmap_obj_virtual(struct ttm_bo_kmap_obj *map,
  580. bool *is_iomem)
  581. {
  582. *is_iomem = !!(map->bo_kmap_type & TTM_BO_MAP_IOMEM_MASK);
  583. return map->virtual;
  584. }
  585. /**
  586. * ttm_bo_kmap
  587. *
  588. * @bo: The buffer object.
  589. * @start_page: The first page to map.
  590. * @num_pages: Number of pages to map.
  591. * @map: pointer to a struct ttm_bo_kmap_obj representing the map.
  592. *
  593. * Sets up a kernel virtual mapping, using ioremap, vmap or kmap to the
  594. * data in the buffer object. The ttm_kmap_obj_virtual function can then be
  595. * used to obtain a virtual address to the data.
  596. *
  597. * Returns
  598. * -ENOMEM: Out of memory.
  599. * -EINVAL: Invalid range.
  600. */
  601. extern int ttm_bo_kmap(struct ttm_buffer_object *bo, unsigned long start_page,
  602. unsigned long num_pages, struct ttm_bo_kmap_obj *map);
  603. /**
  604. * ttm_bo_kunmap
  605. *
  606. * @map: Object describing the map to unmap.
  607. *
  608. * Unmaps a kernel map set up by ttm_bo_kmap.
  609. */
  610. extern void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map);
  611. /**
  612. * ttm_fbdev_mmap - mmap fbdev memory backed by a ttm buffer object.
  613. *
  614. * @vma: vma as input from the fbdev mmap method.
  615. * @bo: The bo backing the address space. The address space will
  616. * have the same size as the bo, and start at offset 0.
  617. *
  618. * This function is intended to be called by the fbdev mmap method
  619. * if the fbdev address space is to be backed by a bo.
  620. */
  621. extern int ttm_fbdev_mmap(struct vm_area_struct *vma,
  622. struct ttm_buffer_object *bo);
  623. /**
  624. * ttm_bo_mmap - mmap out of the ttm device address space.
  625. *
  626. * @filp: filp as input from the mmap method.
  627. * @vma: vma as input from the mmap method.
  628. * @bdev: Pointer to the ttm_bo_device with the address space manager.
  629. *
  630. * This function is intended to be called by the device mmap method.
  631. * if the device address space is to be backed by the bo manager.
  632. */
  633. extern int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma,
  634. struct ttm_bo_device *bdev);
  635. /**
  636. * ttm_bo_io
  637. *
  638. * @bdev: Pointer to the struct ttm_bo_device.
  639. * @filp: Pointer to the struct file attempting to read / write.
  640. * @wbuf: User-space pointer to address of buffer to write. NULL on read.
  641. * @rbuf: User-space pointer to address of buffer to read into.
  642. * Null on write.
  643. * @count: Number of bytes to read / write.
  644. * @f_pos: Pointer to current file position.
  645. * @write: 1 for read, 0 for write.
  646. *
  647. * This function implements read / write into ttm buffer objects, and is
  648. * intended to
  649. * be called from the fops::read and fops::write method.
  650. * Returns:
  651. * See man (2) write, man(2) read. In particular,
  652. * the function may return -ERESTARTSYS if
  653. * interrupted by a signal.
  654. */
  655. extern ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
  656. const char __user *wbuf, char __user *rbuf,
  657. size_t count, loff_t *f_pos, bool write);
  658. extern void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
  659. #endif