ttm_bo_api.h 22 KB

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