ttm_bo_api.h 21 KB

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