ttm_bo_api.h 22 KB

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