ttm_bo_api.h 23 KB

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