ttm_bo_api.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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. * Returns
  392. * -ENOMEM: Out of memory.
  393. * -EINVAL: Invalid placement flags.
  394. * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources.
  395. */
  396. extern int ttm_bo_init(struct ttm_bo_device *bdev,
  397. struct ttm_buffer_object *bo,
  398. unsigned long size,
  399. enum ttm_bo_type type,
  400. struct ttm_placement *placement,
  401. uint32_t page_alignment,
  402. unsigned long buffer_start,
  403. bool interrubtible,
  404. struct file *persistant_swap_storage,
  405. size_t acc_size,
  406. void (*destroy) (struct ttm_buffer_object *));
  407. /**
  408. * ttm_bo_synccpu_object_init
  409. *
  410. * @bdev: Pointer to a ttm_bo_device struct.
  411. * @bo: Pointer to a ttm_buffer_object to be initialized.
  412. * @size: Requested size of buffer object.
  413. * @type: Requested type of buffer object.
  414. * @flags: Initial placement flags.
  415. * @page_alignment: Data alignment in pages.
  416. * @buffer_start: Virtual address of user space data backing a
  417. * user buffer object.
  418. * @interruptible: If needing to sleep while waiting for GPU resources,
  419. * sleep interruptible.
  420. * @persistant_swap_storage: Usually the swap storage is deleted for buffers
  421. * pinned in physical memory. If this behaviour is not desired, this member
  422. * holds a pointer to a persistant shmem object. Typically, this would
  423. * point to the shmem object backing a GEM object if TTM is used to back a
  424. * GEM user interface.
  425. * @p_bo: On successful completion *p_bo points to the created object.
  426. *
  427. * This function allocates a ttm_buffer_object, and then calls ttm_bo_init
  428. * on that object. The destroy function is set to kfree().
  429. * Returns
  430. * -ENOMEM: Out of memory.
  431. * -EINVAL: Invalid placement flags.
  432. * -ERESTARTSYS: Interrupted by signal while waiting for resources.
  433. */
  434. extern int ttm_bo_create(struct ttm_bo_device *bdev,
  435. unsigned long size,
  436. enum ttm_bo_type type,
  437. struct ttm_placement *placement,
  438. uint32_t page_alignment,
  439. unsigned long buffer_start,
  440. bool interruptible,
  441. struct file *persistant_swap_storage,
  442. struct ttm_buffer_object **p_bo);
  443. /**
  444. * ttm_bo_check_placement
  445. *
  446. * @bo: the buffer object.
  447. * @placement: placements
  448. *
  449. * Performs minimal validity checking on an intended change of
  450. * placement flags.
  451. * Returns
  452. * -EINVAL: Intended change is invalid or not allowed.
  453. */
  454. extern int ttm_bo_check_placement(struct ttm_buffer_object *bo,
  455. struct ttm_placement *placement);
  456. /**
  457. * ttm_bo_init_mm
  458. *
  459. * @bdev: Pointer to a ttm_bo_device struct.
  460. * @mem_type: The memory type.
  461. * @p_size: size managed area in pages.
  462. *
  463. * Initialize a manager for a given memory type.
  464. * Note: if part of driver firstopen, it must be protected from a
  465. * potentially racing lastclose.
  466. * Returns:
  467. * -EINVAL: invalid size or memory type.
  468. * -ENOMEM: Not enough memory.
  469. * May also return driver-specified errors.
  470. */
  471. extern int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
  472. unsigned long p_size);
  473. /**
  474. * ttm_bo_clean_mm
  475. *
  476. * @bdev: Pointer to a ttm_bo_device struct.
  477. * @mem_type: The memory type.
  478. *
  479. * Take down a manager for a given memory type after first walking
  480. * the LRU list to evict any buffers left alive.
  481. *
  482. * Normally, this function is part of lastclose() or unload(), and at that
  483. * point there shouldn't be any buffers left created by user-space, since
  484. * there should've been removed by the file descriptor release() method.
  485. * However, before this function is run, make sure to signal all sync objects,
  486. * and verify that the delayed delete queue is empty. The driver must also
  487. * make sure that there are no NO_EVICT buffers present in this memory type
  488. * when the call is made.
  489. *
  490. * If this function is part of a VT switch, the caller must make sure that
  491. * there are no appications currently validating buffers before this
  492. * function is called. The caller can do that by first taking the
  493. * struct ttm_bo_device::ttm_lock in write mode.
  494. *
  495. * Returns:
  496. * -EINVAL: invalid or uninitialized memory type.
  497. * -EBUSY: There are still buffers left in this memory type.
  498. */
  499. extern int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type);
  500. /**
  501. * ttm_bo_evict_mm
  502. *
  503. * @bdev: Pointer to a ttm_bo_device struct.
  504. * @mem_type: The memory type.
  505. *
  506. * Evicts all buffers on the lru list of the memory type.
  507. * This is normally part of a VT switch or an
  508. * out-of-memory-space-due-to-fragmentation handler.
  509. * The caller must make sure that there are no other processes
  510. * currently validating buffers, and can do that by taking the
  511. * struct ttm_bo_device::ttm_lock in write mode.
  512. *
  513. * Returns:
  514. * -EINVAL: Invalid or uninitialized memory type.
  515. * -ERESTARTSYS: The call was interrupted by a signal while waiting to
  516. * evict a buffer.
  517. */
  518. extern int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type);
  519. /**
  520. * ttm_kmap_obj_virtual
  521. *
  522. * @map: A struct ttm_bo_kmap_obj returned from ttm_bo_kmap.
  523. * @is_iomem: Pointer to an integer that on return indicates 1 if the
  524. * virtual map is io memory, 0 if normal memory.
  525. *
  526. * Returns the virtual address of a buffer object area mapped by ttm_bo_kmap.
  527. * If *is_iomem is 1 on return, the virtual address points to an io memory area,
  528. * that should strictly be accessed by the iowriteXX() and similar functions.
  529. */
  530. static inline void *ttm_kmap_obj_virtual(struct ttm_bo_kmap_obj *map,
  531. bool *is_iomem)
  532. {
  533. *is_iomem = !!(map->bo_kmap_type & TTM_BO_MAP_IOMEM_MASK);
  534. return map->virtual;
  535. }
  536. /**
  537. * ttm_bo_kmap
  538. *
  539. * @bo: The buffer object.
  540. * @start_page: The first page to map.
  541. * @num_pages: Number of pages to map.
  542. * @map: pointer to a struct ttm_bo_kmap_obj representing the map.
  543. *
  544. * Sets up a kernel virtual mapping, using ioremap, vmap or kmap to the
  545. * data in the buffer object. The ttm_kmap_obj_virtual function can then be
  546. * used to obtain a virtual address to the data.
  547. *
  548. * Returns
  549. * -ENOMEM: Out of memory.
  550. * -EINVAL: Invalid range.
  551. */
  552. extern int ttm_bo_kmap(struct ttm_buffer_object *bo, unsigned long start_page,
  553. unsigned long num_pages, struct ttm_bo_kmap_obj *map);
  554. /**
  555. * ttm_bo_kunmap
  556. *
  557. * @map: Object describing the map to unmap.
  558. *
  559. * Unmaps a kernel map set up by ttm_bo_kmap.
  560. */
  561. extern void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map);
  562. #if 0
  563. #endif
  564. /**
  565. * ttm_fbdev_mmap - mmap fbdev memory backed by a ttm buffer object.
  566. *
  567. * @vma: vma as input from the fbdev mmap method.
  568. * @bo: The bo backing the address space. The address space will
  569. * have the same size as the bo, and start at offset 0.
  570. *
  571. * This function is intended to be called by the fbdev mmap method
  572. * if the fbdev address space is to be backed by a bo.
  573. */
  574. extern int ttm_fbdev_mmap(struct vm_area_struct *vma,
  575. struct ttm_buffer_object *bo);
  576. /**
  577. * ttm_bo_mmap - mmap out of the ttm device address space.
  578. *
  579. * @filp: filp as input from the mmap method.
  580. * @vma: vma as input from the mmap method.
  581. * @bdev: Pointer to the ttm_bo_device with the address space manager.
  582. *
  583. * This function is intended to be called by the device mmap method.
  584. * if the device address space is to be backed by the bo manager.
  585. */
  586. extern int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma,
  587. struct ttm_bo_device *bdev);
  588. /**
  589. * ttm_bo_io
  590. *
  591. * @bdev: Pointer to the struct ttm_bo_device.
  592. * @filp: Pointer to the struct file attempting to read / write.
  593. * @wbuf: User-space pointer to address of buffer to write. NULL on read.
  594. * @rbuf: User-space pointer to address of buffer to read into.
  595. * Null on write.
  596. * @count: Number of bytes to read / write.
  597. * @f_pos: Pointer to current file position.
  598. * @write: 1 for read, 0 for write.
  599. *
  600. * This function implements read / write into ttm buffer objects, and is
  601. * intended to
  602. * be called from the fops::read and fops::write method.
  603. * Returns:
  604. * See man (2) write, man(2) read. In particular,
  605. * the function may return -ERESTARTSYS if
  606. * interrupted by a signal.
  607. */
  608. extern ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
  609. const char __user *wbuf, char __user *rbuf,
  610. size_t count, loff_t *f_pos, bool write);
  611. extern void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
  612. #endif