aboutsummaryrefslogtreecommitdiffstats
path: root/include/drm/ttm
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
commit8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch)
treea8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /include/drm/ttm
parent406089d01562f1e2bf9f089fd7637009ebaad589 (diff)
Patched in Tegra support.
Diffstat (limited to 'include/drm/ttm')
-rw-r--r--include/drm/ttm/ttm_bo_api.h68
-rw-r--r--include/drm/ttm/ttm_bo_driver.h269
-rw-r--r--include/drm/ttm/ttm_execbuf_util.h5
-rw-r--r--include/drm/ttm/ttm_lock.h2
-rw-r--r--include/drm/ttm/ttm_memory.h3
-rw-r--r--include/drm/ttm/ttm_object.h6
-rw-r--r--include/drm/ttm/ttm_page_alloc.h81
7 files changed, 219 insertions, 215 deletions
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 3cb5d848fb6..42e34698518 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -31,7 +31,7 @@
31#ifndef _TTM_BO_API_H_ 31#ifndef _TTM_BO_API_H_
32#define _TTM_BO_API_H_ 32#define _TTM_BO_API_H_
33 33
34#include <drm/drm_hashtab.h> 34#include "drm_hashtab.h"
35#include <linux/kref.h> 35#include <linux/kref.h>
36#include <linux/list.h> 36#include <linux/list.h>
37#include <linux/wait.h> 37#include <linux/wait.h>
@@ -122,17 +122,18 @@ struct ttm_mem_reg {
122 * be mmapped by user space. Each of these bos occupy a slot in the 122 * be mmapped by user space. Each of these bos occupy a slot in the
123 * device address space, that can be used for normal vm operations. 123 * device address space, that can be used for normal vm operations.
124 * 124 *
125 * @ttm_bo_type_user: These are user-space memory areas that are made
126 * available to the GPU by mapping the buffer pages into the GPU aperture
127 * space. These buffers cannot be mmaped from the device address space.
128 *
125 * @ttm_bo_type_kernel: These buffers are like ttm_bo_type_device buffers, 129 * @ttm_bo_type_kernel: These buffers are like ttm_bo_type_device buffers,
126 * but they cannot be accessed from user-space. For kernel-only use. 130 * but they cannot be accessed from user-space. For kernel-only use.
127 *
128 * @ttm_bo_type_sg: Buffer made from dmabuf sg table shared with another
129 * driver.
130 */ 131 */
131 132
132enum ttm_bo_type { 133enum ttm_bo_type {
133 ttm_bo_type_device, 134 ttm_bo_type_device,
134 ttm_bo_type_kernel, 135 ttm_bo_type_user,
135 ttm_bo_type_sg 136 ttm_bo_type_kernel
136}; 137};
137 138
138struct ttm_tt; 139struct ttm_tt;
@@ -141,6 +142,8 @@ struct ttm_tt;
141 * struct ttm_buffer_object 142 * struct ttm_buffer_object
142 * 143 *
143 * @bdev: Pointer to the buffer object device structure. 144 * @bdev: Pointer to the buffer object device structure.
145 * @buffer_start: The virtual user-space start address of ttm_bo_type_user
146 * buffers.
144 * @type: The bo type. 147 * @type: The bo type.
145 * @destroy: Destruction function. If NULL, kfree is used. 148 * @destroy: Destruction function. If NULL, kfree is used.
146 * @num_pages: Actual number of pages. 149 * @num_pages: Actual number of pages.
@@ -170,6 +173,7 @@ struct ttm_tt;
170 * @seq_valid: The value of @val_seq is valid. This value is protected by 173 * @seq_valid: The value of @val_seq is valid. This value is protected by
171 * the bo_device::lru_lock. 174 * the bo_device::lru_lock.
172 * @reserved: Deadlock-free lock used for synchronization state transitions. 175 * @reserved: Deadlock-free lock used for synchronization state transitions.
176 * @sync_obj_arg: Opaque argument to synchronization object function.
173 * @sync_obj: Pointer to a synchronization object. 177 * @sync_obj: Pointer to a synchronization object.
174 * @priv_flags: Flags describing buffer object internal state. 178 * @priv_flags: Flags describing buffer object internal state.
175 * @vm_rb: Rb node for the vm rb tree. 179 * @vm_rb: Rb node for the vm rb tree.
@@ -197,6 +201,7 @@ struct ttm_buffer_object {
197 201
198 struct ttm_bo_global *glob; 202 struct ttm_bo_global *glob;
199 struct ttm_bo_device *bdev; 203 struct ttm_bo_device *bdev;
204 unsigned long buffer_start;
200 enum ttm_bo_type type; 205 enum ttm_bo_type type;
201 void (*destroy) (struct ttm_buffer_object *); 206 void (*destroy) (struct ttm_buffer_object *);
202 unsigned long num_pages; 207 unsigned long num_pages;
@@ -251,6 +256,7 @@ struct ttm_buffer_object {
251 * checking NULL while reserved but not holding the mentioned lock. 256 * checking NULL while reserved but not holding the mentioned lock.
252 */ 257 */
253 258
259 void *sync_obj_arg;
254 void *sync_obj; 260 void *sync_obj;
255 unsigned long priv_flags; 261 unsigned long priv_flags;
256 262
@@ -270,8 +276,6 @@ struct ttm_buffer_object {
270 276
271 unsigned long offset; 277 unsigned long offset;
272 uint32_t cur_placement; 278 uint32_t cur_placement;
273
274 struct sg_table *sg;
275}; 279};
276 280
277/** 281/**
@@ -337,6 +341,7 @@ extern int ttm_bo_wait(struct ttm_buffer_object *bo, bool lazy,
337 * @bo: The buffer object. 341 * @bo: The buffer object.
338 * @placement: Proposed placement for the buffer object. 342 * @placement: Proposed placement for the buffer object.
339 * @interruptible: Sleep interruptible if sleeping. 343 * @interruptible: Sleep interruptible if sleeping.
344 * @no_wait_reserve: Return immediately if other buffers are busy.
340 * @no_wait_gpu: Return immediately if the GPU is busy. 345 * @no_wait_gpu: Return immediately if the GPU is busy.
341 * 346 *
342 * Changes placement and caching policy of the buffer object 347 * Changes placement and caching policy of the buffer object
@@ -349,7 +354,7 @@ extern int ttm_bo_wait(struct ttm_buffer_object *bo, bool lazy,
349 */ 354 */
350extern int ttm_bo_validate(struct ttm_buffer_object *bo, 355extern int ttm_bo_validate(struct ttm_buffer_object *bo,
351 struct ttm_placement *placement, 356 struct ttm_placement *placement,
352 bool interruptible, 357 bool interruptible, bool no_wait_reserve,
353 bool no_wait_gpu); 358 bool no_wait_gpu);
354 359
355/** 360/**
@@ -423,16 +428,15 @@ extern void ttm_bo_unlock_delayed_workqueue(struct ttm_bo_device *bdev,
423 * @no_wait: Return immediately if buffer is busy. 428 * @no_wait: Return immediately if buffer is busy.
424 * 429 *
425 * Synchronizes a buffer object for CPU RW access. This means 430 * Synchronizes a buffer object for CPU RW access. This means
426 * command submission that affects the buffer will return -EBUSY 431 * blocking command submission that affects the buffer and
427 * until ttm_bo_synccpu_write_release is called. 432 * waiting for buffer idle. This lock is recursive.
428 *
429 * Returns 433 * Returns
430 * -EBUSY if the buffer is busy and no_wait is true. 434 * -EBUSY if the buffer is busy and no_wait is true.
431 * -ERESTARTSYS if interrupted by a signal. 435 * -ERESTARTSYS if interrupted by a signal.
432 */ 436 */
437
433extern int 438extern int
434ttm_bo_synccpu_write_grab(struct ttm_buffer_object *bo, bool no_wait); 439ttm_bo_synccpu_write_grab(struct ttm_buffer_object *bo, bool no_wait);
435
436/** 440/**
437 * ttm_bo_synccpu_write_release: 441 * ttm_bo_synccpu_write_release:
438 * 442 *
@@ -443,22 +447,6 @@ ttm_bo_synccpu_write_grab(struct ttm_buffer_object *bo, bool no_wait);
443extern void ttm_bo_synccpu_write_release(struct ttm_buffer_object *bo); 447extern void ttm_bo_synccpu_write_release(struct ttm_buffer_object *bo);
444 448
445/** 449/**
446 * ttm_bo_acc_size
447 *
448 * @bdev: Pointer to a ttm_bo_device struct.
449 * @bo_size: size of the buffer object in byte.
450 * @struct_size: size of the structure holding buffer object datas
451 *
452 * Returns size to account for a buffer object
453 */
454size_t ttm_bo_acc_size(struct ttm_bo_device *bdev,
455 unsigned long bo_size,
456 unsigned struct_size);
457size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev,
458 unsigned long bo_size,
459 unsigned struct_size);
460
461/**
462 * ttm_bo_init 450 * ttm_bo_init
463 * 451 *
464 * @bdev: Pointer to a ttm_bo_device struct. 452 * @bdev: Pointer to a ttm_bo_device struct.
@@ -467,6 +455,8 @@ size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev,
467 * @type: Requested type of buffer object. 455 * @type: Requested type of buffer object.
468 * @flags: Initial placement flags. 456 * @flags: Initial placement flags.
469 * @page_alignment: Data alignment in pages. 457 * @page_alignment: Data alignment in pages.
458 * @buffer_start: Virtual address of user space data backing a
459 * user buffer object.
470 * @interruptible: If needing to sleep to wait for GPU resources, 460 * @interruptible: If needing to sleep to wait for GPU resources,
471 * sleep interruptible. 461 * sleep interruptible.
472 * @persistent_swap_storage: Usually the swap storage is deleted for buffers 462 * @persistent_swap_storage: Usually the swap storage is deleted for buffers
@@ -498,12 +488,11 @@ extern int ttm_bo_init(struct ttm_bo_device *bdev,
498 enum ttm_bo_type type, 488 enum ttm_bo_type type,
499 struct ttm_placement *placement, 489 struct ttm_placement *placement,
500 uint32_t page_alignment, 490 uint32_t page_alignment,
491 unsigned long buffer_start,
501 bool interrubtible, 492 bool interrubtible,
502 struct file *persistent_swap_storage, 493 struct file *persistent_swap_storage,
503 size_t acc_size, 494 size_t acc_size,
504 struct sg_table *sg,
505 void (*destroy) (struct ttm_buffer_object *)); 495 void (*destroy) (struct ttm_buffer_object *));
506
507/** 496/**
508 * ttm_bo_synccpu_object_init 497 * ttm_bo_synccpu_object_init
509 * 498 *
@@ -513,6 +502,8 @@ extern int ttm_bo_init(struct ttm_bo_device *bdev,
513 * @type: Requested type of buffer object. 502 * @type: Requested type of buffer object.
514 * @flags: Initial placement flags. 503 * @flags: Initial placement flags.
515 * @page_alignment: Data alignment in pages. 504 * @page_alignment: Data alignment in pages.
505 * @buffer_start: Virtual address of user space data backing a
506 * user buffer object.
516 * @interruptible: If needing to sleep while waiting for GPU resources, 507 * @interruptible: If needing to sleep while waiting for GPU resources,
517 * sleep interruptible. 508 * sleep interruptible.
518 * @persistent_swap_storage: Usually the swap storage is deleted for buffers 509 * @persistent_swap_storage: Usually the swap storage is deleted for buffers
@@ -535,6 +526,7 @@ extern int ttm_bo_create(struct ttm_bo_device *bdev,
535 enum ttm_bo_type type, 526 enum ttm_bo_type type,
536 struct ttm_placement *placement, 527 struct ttm_placement *placement,
537 uint32_t page_alignment, 528 uint32_t page_alignment,
529 unsigned long buffer_start,
538 bool interruptible, 530 bool interruptible,
539 struct file *persistent_swap_storage, 531 struct file *persistent_swap_storage,
540 struct ttm_buffer_object **p_bo); 532 struct ttm_buffer_object **p_bo);
@@ -725,18 +717,4 @@ extern ssize_t ttm_bo_io(struct ttm_bo_device *bdev, struct file *filp,
725 717
726extern void ttm_bo_swapout_all(struct ttm_bo_device *bdev); 718extern void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
727 719
728/**
729 * ttm_bo_is_reserved - return an indication if a ttm buffer object is reserved
730 *
731 * @bo: The buffer object to check.
732 *
733 * This function returns an indication if a bo is reserved or not, and should
734 * only be used to print an error when it is not from incorrect api usage, since
735 * there's no guarantee that it is the caller that is holding the reservation.
736 */
737static inline bool ttm_bo_is_reserved(struct ttm_buffer_object *bo)
738{
739 return atomic_read(&bo->reserved);
740}
741
742#endif 720#endif
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index e3a43a47d78..94eb1434316 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -30,20 +30,49 @@
30#ifndef _TTM_BO_DRIVER_H_ 30#ifndef _TTM_BO_DRIVER_H_
31#define _TTM_BO_DRIVER_H_ 31#define _TTM_BO_DRIVER_H_
32 32
33#include <ttm/ttm_bo_api.h> 33#include "ttm/ttm_bo_api.h"
34#include <ttm/ttm_memory.h> 34#include "ttm/ttm_memory.h"
35#include <ttm/ttm_module.h> 35#include "ttm/ttm_module.h"
36#include <drm/drm_mm.h> 36#include "drm_mm.h"
37#include <drm/drm_global.h> 37#include "drm_global.h"
38#include <linux/workqueue.h> 38#include "linux/workqueue.h"
39#include <linux/fs.h> 39#include "linux/fs.h"
40#include <linux/spinlock.h> 40#include "linux/spinlock.h"
41
42struct ttm_backend;
41 43
42struct ttm_backend_func { 44struct ttm_backend_func {
43 /** 45 /**
46 * struct ttm_backend_func member populate
47 *
48 * @backend: Pointer to a struct ttm_backend.
49 * @num_pages: Number of pages to populate.
50 * @pages: Array of pointers to ttm pages.
51 * @dummy_read_page: Page to be used instead of NULL pages in the
52 * array @pages.
53 * @dma_addrs: Array of DMA (bus) address of the ttm pages.
54 *
55 * Populate the backend with ttm pages. Depending on the backend,
56 * it may or may not copy the @pages array.
57 */
58 int (*populate) (struct ttm_backend *backend,
59 unsigned long num_pages, struct page **pages,
60 struct page *dummy_read_page,
61 dma_addr_t *dma_addrs);
62 /**
63 * struct ttm_backend_func member clear
64 *
65 * @backend: Pointer to a struct ttm_backend.
66 *
67 * This is an "unpopulate" function. Release all resources
68 * allocated with populate.
69 */
70 void (*clear) (struct ttm_backend *backend);
71
72 /**
44 * struct ttm_backend_func member bind 73 * struct ttm_backend_func member bind
45 * 74 *
46 * @ttm: Pointer to a struct ttm_tt. 75 * @backend: Pointer to a struct ttm_backend.
47 * @bo_mem: Pointer to a struct ttm_mem_reg describing the 76 * @bo_mem: Pointer to a struct ttm_mem_reg describing the
48 * memory type and location for binding. 77 * memory type and location for binding.
49 * 78 *
@@ -51,35 +80,51 @@ struct ttm_backend_func {
51 * indicated by @bo_mem. This function should be able to handle 80 * indicated by @bo_mem. This function should be able to handle
52 * differences between aperture and system page sizes. 81 * differences between aperture and system page sizes.
53 */ 82 */
54 int (*bind) (struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem); 83 int (*bind) (struct ttm_backend *backend, struct ttm_mem_reg *bo_mem);
55 84
56 /** 85 /**
57 * struct ttm_backend_func member unbind 86 * struct ttm_backend_func member unbind
58 * 87 *
59 * @ttm: Pointer to a struct ttm_tt. 88 * @backend: Pointer to a struct ttm_backend.
60 * 89 *
61 * Unbind previously bound backend pages. This function should be 90 * Unbind previously bound backend pages. This function should be
62 * able to handle differences between aperture and system page sizes. 91 * able to handle differences between aperture and system page sizes.
63 */ 92 */
64 int (*unbind) (struct ttm_tt *ttm); 93 int (*unbind) (struct ttm_backend *backend);
65 94
66 /** 95 /**
67 * struct ttm_backend_func member destroy 96 * struct ttm_backend_func member destroy
68 * 97 *
69 * @ttm: Pointer to a struct ttm_tt. 98 * @backend: Pointer to a struct ttm_backend.
70 * 99 *
71 * Destroy the backend. This will be call back from ttm_tt_destroy so 100 * Destroy the backend.
72 * don't call ttm_tt_destroy from the callback or infinite loop.
73 */ 101 */
74 void (*destroy) (struct ttm_tt *ttm); 102 void (*destroy) (struct ttm_backend *backend);
75}; 103};
76 104
105/**
106 * struct ttm_backend
107 *
108 * @bdev: Pointer to a struct ttm_bo_device.
109 * @flags: For driver use.
110 * @func: Pointer to a struct ttm_backend_func that describes
111 * the backend methods.
112 *
113 */
114
115struct ttm_backend {
116 struct ttm_bo_device *bdev;
117 uint32_t flags;
118 struct ttm_backend_func *func;
119};
120
121#define TTM_PAGE_FLAG_USER (1 << 1)
122#define TTM_PAGE_FLAG_USER_DIRTY (1 << 2)
77#define TTM_PAGE_FLAG_WRITE (1 << 3) 123#define TTM_PAGE_FLAG_WRITE (1 << 3)
78#define TTM_PAGE_FLAG_SWAPPED (1 << 4) 124#define TTM_PAGE_FLAG_SWAPPED (1 << 4)
79#define TTM_PAGE_FLAG_PERSISTENT_SWAP (1 << 5) 125#define TTM_PAGE_FLAG_PERSISTENT_SWAP (1 << 5)
80#define TTM_PAGE_FLAG_ZERO_ALLOC (1 << 6) 126#define TTM_PAGE_FLAG_ZERO_ALLOC (1 << 6)
81#define TTM_PAGE_FLAG_DMA32 (1 << 7) 127#define TTM_PAGE_FLAG_DMA32 (1 << 7)
82#define TTM_PAGE_FLAG_SG (1 << 8)
83 128
84enum ttm_caching_state { 129enum ttm_caching_state {
85 tt_uncached, 130 tt_uncached,
@@ -90,18 +135,23 @@ enum ttm_caching_state {
90/** 135/**
91 * struct ttm_tt 136 * struct ttm_tt
92 * 137 *
93 * @bdev: Pointer to a struct ttm_bo_device.
94 * @func: Pointer to a struct ttm_backend_func that describes
95 * the backend methods.
96 * @dummy_read_page: Page to map where the ttm_tt page array contains a NULL 138 * @dummy_read_page: Page to map where the ttm_tt page array contains a NULL
97 * pointer. 139 * pointer.
98 * @pages: Array of pages backing the data. 140 * @pages: Array of pages backing the data.
141 * @first_himem_page: Himem pages are put last in the page array, which
142 * enables us to run caching attribute changes on only the first part
143 * of the page array containing lomem pages. This is the index of the
144 * first himem page.
145 * @last_lomem_page: Index of the last lomem page in the page array.
99 * @num_pages: Number of pages in the page array. 146 * @num_pages: Number of pages in the page array.
100 * @bdev: Pointer to the current struct ttm_bo_device. 147 * @bdev: Pointer to the current struct ttm_bo_device.
101 * @be: Pointer to the ttm backend. 148 * @be: Pointer to the ttm backend.
149 * @tsk: The task for user ttm.
150 * @start: virtual address for user ttm.
102 * @swap_storage: Pointer to shmem struct file for swap storage. 151 * @swap_storage: Pointer to shmem struct file for swap storage.
103 * @caching_state: The current caching state of the pages. 152 * @caching_state: The current caching state of the pages.
104 * @state: The current binding state of the pages. 153 * @state: The current binding state of the pages.
154 * @dma_address: The DMA (bus) addresses of the pages (if TTM_PAGE_FLAG_DMA32)
105 * 155 *
106 * This is a structure holding the pages, caching- and aperture binding 156 * This is a structure holding the pages, caching- and aperture binding
107 * status for a buffer object that isn't backed by fixed (VRAM / AGP) 157 * status for a buffer object that isn't backed by fixed (VRAM / AGP)
@@ -109,14 +159,16 @@ enum ttm_caching_state {
109 */ 159 */
110 160
111struct ttm_tt { 161struct ttm_tt {
112 struct ttm_bo_device *bdev;
113 struct ttm_backend_func *func;
114 struct page *dummy_read_page; 162 struct page *dummy_read_page;
115 struct page **pages; 163 struct page **pages;
164 long first_himem_page;
165 long last_lomem_page;
116 uint32_t page_flags; 166 uint32_t page_flags;
117 unsigned long num_pages; 167 unsigned long num_pages;
118 struct sg_table *sg; /* for SG objects via dma-buf */
119 struct ttm_bo_global *glob; 168 struct ttm_bo_global *glob;
169 struct ttm_backend *be;
170 struct task_struct *tsk;
171 unsigned long start;
120 struct file *swap_storage; 172 struct file *swap_storage;
121 enum ttm_caching_state caching_state; 173 enum ttm_caching_state caching_state;
122 enum { 174 enum {
@@ -124,23 +176,7 @@ struct ttm_tt {
124 tt_unbound, 176 tt_unbound,
125 tt_unpopulated, 177 tt_unpopulated,
126 } state; 178 } state;
127};
128
129/**
130 * struct ttm_dma_tt
131 *
132 * @ttm: Base ttm_tt struct.
133 * @dma_address: The DMA (bus) addresses of the pages
134 * @pages_list: used by some page allocation backend
135 *
136 * This is a structure holding the pages, caching- and aperture binding
137 * status for a buffer object that isn't backed by fixed (VRAM / AGP)
138 * memory.
139 */
140struct ttm_dma_tt {
141 struct ttm_tt ttm;
142 dma_addr_t *dma_address; 179 dma_addr_t *dma_address;
143 struct list_head pages_list;
144}; 180};
145 181
146#define TTM_MEMTYPE_FLAG_FIXED (1 << 0) /* Fixed (on-card) PCI memory */ 182#define TTM_MEMTYPE_FLAG_FIXED (1 << 0) /* Fixed (on-card) PCI memory */
@@ -315,42 +351,15 @@ struct ttm_mem_type_manager {
315 351
316struct ttm_bo_driver { 352struct ttm_bo_driver {
317 /** 353 /**
318 * ttm_tt_create 354 * struct ttm_bo_driver member create_ttm_backend_entry
319 * 355 *
320 * @bdev: pointer to a struct ttm_bo_device: 356 * @bdev: The buffer object device.
321 * @size: Size of the data needed backing.
322 * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags.
323 * @dummy_read_page: See struct ttm_bo_device.
324 * 357 *
325 * Create a struct ttm_tt to back data with system memory pages. 358 * Create a driver specific struct ttm_backend.
326 * No pages are actually allocated.
327 * Returns:
328 * NULL: Out of memory.
329 */ 359 */
330 struct ttm_tt *(*ttm_tt_create)(struct ttm_bo_device *bdev,
331 unsigned long size,
332 uint32_t page_flags,
333 struct page *dummy_read_page);
334 360
335 /** 361 struct ttm_backend *(*create_ttm_backend_entry)
336 * ttm_tt_populate 362 (struct ttm_bo_device *bdev);
337 *
338 * @ttm: The struct ttm_tt to contain the backing pages.
339 *
340 * Allocate all backing pages
341 * Returns:
342 * -ENOMEM: Out of memory.
343 */
344 int (*ttm_tt_populate)(struct ttm_tt *ttm);
345
346 /**
347 * ttm_tt_unpopulate
348 *
349 * @ttm: The struct ttm_tt to contain the backing pages.
350 *
351 * Free all backing page
352 */
353 void (*ttm_tt_unpopulate)(struct ttm_tt *ttm);
354 363
355 /** 364 /**
356 * struct ttm_bo_driver member invalidate_caches 365 * struct ttm_bo_driver member invalidate_caches
@@ -394,7 +403,7 @@ struct ttm_bo_driver {
394 */ 403 */
395 int (*move) (struct ttm_buffer_object *bo, 404 int (*move) (struct ttm_buffer_object *bo,
396 bool evict, bool interruptible, 405 bool evict, bool interruptible,
397 bool no_wait_gpu, 406 bool no_wait_reserve, bool no_wait_gpu,
398 struct ttm_mem_reg *new_mem); 407 struct ttm_mem_reg *new_mem);
399 408
400 /** 409 /**
@@ -422,10 +431,10 @@ struct ttm_bo_driver {
422 * documentation. 431 * documentation.
423 */ 432 */
424 433
425 bool (*sync_obj_signaled) (void *sync_obj); 434 bool (*sync_obj_signaled) (void *sync_obj, void *sync_arg);
426 int (*sync_obj_wait) (void *sync_obj, 435 int (*sync_obj_wait) (void *sync_obj, void *sync_arg,
427 bool lazy, bool interruptible); 436 bool lazy, bool interruptible);
428 int (*sync_obj_flush) (void *sync_obj); 437 int (*sync_obj_flush) (void *sync_obj, void *sync_arg);
429 void (*sync_obj_unref) (void **sync_obj); 438 void (*sync_obj_unref) (void **sync_obj);
430 void *(*sync_obj_ref) (void *sync_obj); 439 void *(*sync_obj_ref) (void *sync_obj);
431 440
@@ -468,6 +477,9 @@ struct ttm_bo_global_ref {
468 * @dummy_read_page: Pointer to a dummy page used for mapping requests 477 * @dummy_read_page: Pointer to a dummy page used for mapping requests
469 * of unpopulated pages. 478 * of unpopulated pages.
470 * @shrink: A shrink callback object used for buffer object swap. 479 * @shrink: A shrink callback object used for buffer object swap.
480 * @ttm_bo_extra_size: Extra size (sizeof(struct ttm_buffer_object) excluded)
481 * used by a buffer object. This is excluding page arrays and backing pages.
482 * @ttm_bo_size: This is @ttm_bo_extra_size + sizeof(struct ttm_buffer_object).
471 * @device_list_mutex: Mutex protecting the device list. 483 * @device_list_mutex: Mutex protecting the device list.
472 * This mutex is held while traversing the device list for pm options. 484 * This mutex is held while traversing the device list for pm options.
473 * @lru_lock: Spinlock protecting the bo subsystem lru lists. 485 * @lru_lock: Spinlock protecting the bo subsystem lru lists.
@@ -485,6 +497,8 @@ struct ttm_bo_global {
485 struct ttm_mem_global *mem_glob; 497 struct ttm_mem_global *mem_glob;
486 struct page *dummy_read_page; 498 struct page *dummy_read_page;
487 struct ttm_mem_shrink shrink; 499 struct ttm_mem_shrink shrink;
500 size_t ttm_bo_extra_size;
501 size_t ttm_bo_size;
488 struct mutex device_list_mutex; 502 struct mutex device_list_mutex;
489 spinlock_t lru_lock; 503 spinlock_t lru_lock;
490 504
@@ -521,6 +535,8 @@ struct ttm_bo_global {
521 * lru_lock: Spinlock that protects the buffer+device lru lists and 535 * lru_lock: Spinlock that protects the buffer+device lru lists and
522 * ddestroy lists. 536 * ddestroy lists.
523 * @val_seq: Current validation sequence. 537 * @val_seq: Current validation sequence.
538 * @nice_mode: Try nicely to wait for buffer idle when cleaning a manager.
539 * If a GPU lockup has been detected, this is forced to 0.
524 * @dev_mapping: A pointer to the struct address_space representing the 540 * @dev_mapping: A pointer to the struct address_space representing the
525 * device address space. 541 * device address space.
526 * @wq: Work queue structure for the delayed delete workqueue. 542 * @wq: Work queue structure for the delayed delete workqueue.
@@ -554,6 +570,7 @@ struct ttm_bo_device {
554 * Protected by load / firstopen / lastclose /unload sync. 570 * Protected by load / firstopen / lastclose /unload sync.
555 */ 571 */
556 572
573 bool nice_mode;
557 struct address_space *dev_mapping; 574 struct address_space *dev_mapping;
558 575
559 /* 576 /*
@@ -583,9 +600,8 @@ ttm_flag_masked(uint32_t *old, uint32_t new, uint32_t mask)
583} 600}
584 601
585/** 602/**
586 * ttm_tt_init 603 * ttm_tt_create
587 * 604 *
588 * @ttm: The struct ttm_tt.
589 * @bdev: pointer to a struct ttm_bo_device: 605 * @bdev: pointer to a struct ttm_bo_device:
590 * @size: Size of the data needed backing. 606 * @size: Size of the data needed backing.
591 * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags. 607 * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags.
@@ -596,22 +612,28 @@ ttm_flag_masked(uint32_t *old, uint32_t new, uint32_t mask)
596 * Returns: 612 * Returns:
597 * NULL: Out of memory. 613 * NULL: Out of memory.
598 */ 614 */
599extern int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev, 615extern struct ttm_tt *ttm_tt_create(struct ttm_bo_device *bdev,
600 unsigned long size, uint32_t page_flags, 616 unsigned long size,
601 struct page *dummy_read_page); 617 uint32_t page_flags,
602extern int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev, 618 struct page *dummy_read_page);
603 unsigned long size, uint32_t page_flags,
604 struct page *dummy_read_page);
605 619
606/** 620/**
607 * ttm_tt_fini 621 * ttm_tt_set_user:
608 * 622 *
609 * @ttm: the ttm_tt structure. 623 * @ttm: The struct ttm_tt to populate.
624 * @tsk: A struct task_struct for which @start is a valid user-space address.
625 * @start: A valid user-space address.
626 * @num_pages: Size in pages of the user memory area.
610 * 627 *
611 * Free memory of ttm_tt structure 628 * Populate a struct ttm_tt with a user-space memory area after first pinning
629 * the pages backing it.
630 * Returns:
631 * !0: Error.
612 */ 632 */
613extern void ttm_tt_fini(struct ttm_tt *ttm); 633
614extern void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma); 634extern int ttm_tt_set_user(struct ttm_tt *ttm,
635 struct task_struct *tsk,
636 unsigned long start, unsigned long num_pages);
615 637
616/** 638/**
617 * ttm_ttm_bind: 639 * ttm_ttm_bind:
@@ -624,11 +646,20 @@ extern void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma);
624extern int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem); 646extern int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem);
625 647
626/** 648/**
649 * ttm_tt_populate:
650 *
651 * @ttm: The struct ttm_tt to contain the backing pages.
652 *
653 * Add backing pages to all of @ttm
654 */
655extern int ttm_tt_populate(struct ttm_tt *ttm);
656
657/**
627 * ttm_ttm_destroy: 658 * ttm_ttm_destroy:
628 * 659 *
629 * @ttm: The struct ttm_tt. 660 * @ttm: The struct ttm_tt.
630 * 661 *
631 * Unbind, unpopulate and destroy common struct ttm_tt. 662 * Unbind, unpopulate and destroy a struct ttm_tt.
632 */ 663 */
633extern void ttm_tt_destroy(struct ttm_tt *ttm); 664extern void ttm_tt_destroy(struct ttm_tt *ttm);
634 665
@@ -642,13 +673,19 @@ extern void ttm_tt_destroy(struct ttm_tt *ttm);
642extern void ttm_tt_unbind(struct ttm_tt *ttm); 673extern void ttm_tt_unbind(struct ttm_tt *ttm);
643 674
644/** 675/**
645 * ttm_tt_swapin: 676 * ttm_ttm_destroy:
646 * 677 *
647 * @ttm: The struct ttm_tt. 678 * @ttm: The struct ttm_tt.
679 * @index: Index of the desired page.
648 * 680 *
649 * Swap in a previously swap out ttm_tt. 681 * Return a pointer to the struct page backing @ttm at page
682 * index @index. If the page is unpopulated, one will be allocated to
683 * populate that index.
684 *
685 * Returns:
686 * NULL on OOM.
650 */ 687 */
651extern int ttm_tt_swapin(struct ttm_tt *ttm); 688extern struct page *ttm_tt_get_page(struct ttm_tt *ttm, int index);
652 689
653/** 690/**
654 * ttm_tt_cache_flush: 691 * ttm_tt_cache_flush:
@@ -703,6 +740,7 @@ extern bool ttm_mem_reg_is_pci(struct ttm_bo_device *bdev,
703 * @proposed_placement: Proposed new placement for the buffer object. 740 * @proposed_placement: Proposed new placement for the buffer object.
704 * @mem: A struct ttm_mem_reg. 741 * @mem: A struct ttm_mem_reg.
705 * @interruptible: Sleep interruptible when sliping. 742 * @interruptible: Sleep interruptible when sliping.
743 * @no_wait_reserve: Return immediately if other buffers are busy.
706 * @no_wait_gpu: Return immediately if the GPU is busy. 744 * @no_wait_gpu: Return immediately if the GPU is busy.
707 * 745 *
708 * Allocate memory space for the buffer object pointed to by @bo, using 746 * Allocate memory space for the buffer object pointed to by @bo, using
@@ -718,13 +756,27 @@ extern int ttm_bo_mem_space(struct ttm_buffer_object *bo,
718 struct ttm_placement *placement, 756 struct ttm_placement *placement,
719 struct ttm_mem_reg *mem, 757 struct ttm_mem_reg *mem,
720 bool interruptible, 758 bool interruptible,
721 bool no_wait_gpu); 759 bool no_wait_reserve, bool no_wait_gpu);
722 760
723extern void ttm_bo_mem_put(struct ttm_buffer_object *bo, 761extern void ttm_bo_mem_put(struct ttm_buffer_object *bo,
724 struct ttm_mem_reg *mem); 762 struct ttm_mem_reg *mem);
725extern void ttm_bo_mem_put_locked(struct ttm_buffer_object *bo, 763extern void ttm_bo_mem_put_locked(struct ttm_buffer_object *bo,
726 struct ttm_mem_reg *mem); 764 struct ttm_mem_reg *mem);
727 765
766/**
767 * ttm_bo_wait_for_cpu
768 *
769 * @bo: Pointer to a struct ttm_buffer_object.
770 * @no_wait: Don't sleep while waiting.
771 *
772 * Wait until a buffer object is no longer sync'ed for CPU access.
773 * Returns:
774 * -EBUSY: Buffer object was sync'ed for CPU access. (only if no_wait == 1).
775 * -ERESTARTSYS: An interruptible sleep was interrupted by a signal.
776 */
777
778extern int ttm_bo_wait_cpu(struct ttm_buffer_object *bo, bool no_wait);
779
728extern void ttm_bo_global_release(struct drm_global_reference *ref); 780extern void ttm_bo_global_release(struct drm_global_reference *ref);
729extern int ttm_bo_global_init(struct drm_global_reference *ref); 781extern int ttm_bo_global_init(struct drm_global_reference *ref);
730 782
@@ -900,6 +952,7 @@ extern int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo,
900 * 952 *
901 * @bo: A pointer to a struct ttm_buffer_object. 953 * @bo: A pointer to a struct ttm_buffer_object.
902 * @evict: 1: This is an eviction. Don't try to pipeline. 954 * @evict: 1: This is an eviction. Don't try to pipeline.
955 * @no_wait_reserve: Return immediately if other buffers are busy.
903 * @no_wait_gpu: Return immediately if the GPU is busy. 956 * @no_wait_gpu: Return immediately if the GPU is busy.
904 * @new_mem: struct ttm_mem_reg indicating where to move. 957 * @new_mem: struct ttm_mem_reg indicating where to move.
905 * 958 *
@@ -914,14 +967,15 @@ extern int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo,
914 */ 967 */
915 968
916extern int ttm_bo_move_ttm(struct ttm_buffer_object *bo, 969extern int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
917 bool evict, bool no_wait_gpu, 970 bool evict, bool no_wait_reserve,
918 struct ttm_mem_reg *new_mem); 971 bool no_wait_gpu, struct ttm_mem_reg *new_mem);
919 972
920/** 973/**
921 * ttm_bo_move_memcpy 974 * ttm_bo_move_memcpy
922 * 975 *
923 * @bo: A pointer to a struct ttm_buffer_object. 976 * @bo: A pointer to a struct ttm_buffer_object.
924 * @evict: 1: This is an eviction. Don't try to pipeline. 977 * @evict: 1: This is an eviction. Don't try to pipeline.
978 * @no_wait_reserve: Return immediately if other buffers are busy.
925 * @no_wait_gpu: Return immediately if the GPU is busy. 979 * @no_wait_gpu: Return immediately if the GPU is busy.
926 * @new_mem: struct ttm_mem_reg indicating where to move. 980 * @new_mem: struct ttm_mem_reg indicating where to move.
927 * 981 *
@@ -936,8 +990,8 @@ extern int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
936 */ 990 */
937 991
938extern int ttm_bo_move_memcpy(struct ttm_buffer_object *bo, 992extern int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
939 bool evict, bool no_wait_gpu, 993 bool evict, bool no_wait_reserve,
940 struct ttm_mem_reg *new_mem); 994 bool no_wait_gpu, struct ttm_mem_reg *new_mem);
941 995
942/** 996/**
943 * ttm_bo_free_old_node 997 * ttm_bo_free_old_node
@@ -953,7 +1007,10 @@ extern void ttm_bo_free_old_node(struct ttm_buffer_object *bo);
953 * 1007 *
954 * @bo: A pointer to a struct ttm_buffer_object. 1008 * @bo: A pointer to a struct ttm_buffer_object.
955 * @sync_obj: A sync object that signals when moving is complete. 1009 * @sync_obj: A sync object that signals when moving is complete.
1010 * @sync_obj_arg: An argument to pass to the sync object idle / wait
1011 * functions.
956 * @evict: This is an evict move. Don't return until the buffer is idle. 1012 * @evict: This is an evict move. Don't return until the buffer is idle.
1013 * @no_wait_reserve: Return immediately if other buffers are busy.
957 * @no_wait_gpu: Return immediately if the GPU is busy. 1014 * @no_wait_gpu: Return immediately if the GPU is busy.
958 * @new_mem: struct ttm_mem_reg indicating where to move. 1015 * @new_mem: struct ttm_mem_reg indicating where to move.
959 * 1016 *
@@ -967,7 +1024,9 @@ extern void ttm_bo_free_old_node(struct ttm_buffer_object *bo);
967 1024
968extern int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo, 1025extern int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
969 void *sync_obj, 1026 void *sync_obj,
970 bool evict, bool no_wait_gpu, 1027 void *sync_obj_arg,
1028 bool evict, bool no_wait_reserve,
1029 bool no_wait_gpu,
971 struct ttm_mem_reg *new_mem); 1030 struct ttm_mem_reg *new_mem);
972/** 1031/**
973 * ttm_io_prot 1032 * ttm_io_prot
@@ -987,25 +1046,17 @@ extern const struct ttm_mem_type_manager_func ttm_bo_manager_func;
987#include <linux/agp_backend.h> 1046#include <linux/agp_backend.h>
988 1047
989/** 1048/**
990 * ttm_agp_tt_create 1049 * ttm_agp_backend_init
991 * 1050 *
992 * @bdev: Pointer to a struct ttm_bo_device. 1051 * @bdev: Pointer to a struct ttm_bo_device.
993 * @bridge: The agp bridge this device is sitting on. 1052 * @bridge: The agp bridge this device is sitting on.
994 * @size: Size of the data needed backing.
995 * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags.
996 * @dummy_read_page: See struct ttm_bo_device.
997 *
998 * 1053 *
999 * Create a TTM backend that uses the indicated AGP bridge as an aperture 1054 * Create a TTM backend that uses the indicated AGP bridge as an aperture
1000 * for TT memory. This function uses the linux agpgart interface to 1055 * for TT memory. This function uses the linux agpgart interface to
1001 * bind and unbind memory backing a ttm_tt. 1056 * bind and unbind memory backing a ttm_tt.
1002 */ 1057 */
1003extern struct ttm_tt *ttm_agp_tt_create(struct ttm_bo_device *bdev, 1058extern struct ttm_backend *ttm_agp_backend_init(struct ttm_bo_device *bdev,
1004 struct agp_bridge_data *bridge, 1059 struct agp_bridge_data *bridge);
1005 unsigned long size, uint32_t page_flags,
1006 struct page *dummy_read_page);
1007int ttm_agp_tt_populate(struct ttm_tt *ttm);
1008void ttm_agp_tt_unpopulate(struct ttm_tt *ttm);
1009#endif 1060#endif
1010 1061
1011#endif 1062#endif
diff --git a/include/drm/ttm/ttm_execbuf_util.h b/include/drm/ttm/ttm_execbuf_util.h
index 547e19f06e5..26cc7f9ffa4 100644
--- a/include/drm/ttm/ttm_execbuf_util.h
+++ b/include/drm/ttm/ttm_execbuf_util.h
@@ -31,7 +31,7 @@
31#ifndef _TTM_EXECBUF_UTIL_H_ 31#ifndef _TTM_EXECBUF_UTIL_H_
32#define _TTM_EXECBUF_UTIL_H_ 32#define _TTM_EXECBUF_UTIL_H_
33 33
34#include <ttm/ttm_bo_api.h> 34#include "ttm/ttm_bo_api.h"
35#include <linux/list.h> 35#include <linux/list.h>
36 36
37/** 37/**
@@ -39,6 +39,8 @@
39 * 39 *
40 * @head: list head for thread-private list. 40 * @head: list head for thread-private list.
41 * @bo: refcounted buffer object pointer. 41 * @bo: refcounted buffer object pointer.
42 * @new_sync_obj_arg: New sync_obj_arg for @bo, to be used once
43 * adding a new sync object.
42 * @reserved: Indicates whether @bo has been reserved for validation. 44 * @reserved: Indicates whether @bo has been reserved for validation.
43 * @removed: Indicates whether @bo has been removed from lru lists. 45 * @removed: Indicates whether @bo has been removed from lru lists.
44 * @put_count: Number of outstanding references on bo::list_kref. 46 * @put_count: Number of outstanding references on bo::list_kref.
@@ -48,6 +50,7 @@
48struct ttm_validate_buffer { 50struct ttm_validate_buffer {
49 struct list_head head; 51 struct list_head head;
50 struct ttm_buffer_object *bo; 52 struct ttm_buffer_object *bo;
53 void *new_sync_obj_arg;
51 bool reserved; 54 bool reserved;
52 bool removed; 55 bool removed;
53 int put_count; 56 int put_count;
diff --git a/include/drm/ttm/ttm_lock.h b/include/drm/ttm/ttm_lock.h
index 2902beb5f68..2e7f0c941b5 100644
--- a/include/drm/ttm/ttm_lock.h
+++ b/include/drm/ttm/ttm_lock.h
@@ -49,7 +49,7 @@
49#ifndef _TTM_LOCK_H_ 49#ifndef _TTM_LOCK_H_
50#define _TTM_LOCK_H_ 50#define _TTM_LOCK_H_
51 51
52#include <ttm/ttm_object.h> 52#include "ttm/ttm_object.h"
53#include <linux/wait.h> 53#include <linux/wait.h>
54#include <linux/atomic.h> 54#include <linux/atomic.h>
55 55
diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
index 72dcbe81dd0..26c1f78d136 100644
--- a/include/drm/ttm/ttm_memory.h
+++ b/include/drm/ttm/ttm_memory.h
@@ -30,7 +30,6 @@
30 30
31#include <linux/workqueue.h> 31#include <linux/workqueue.h>
32#include <linux/spinlock.h> 32#include <linux/spinlock.h>
33#include <linux/bug.h>
34#include <linux/wait.h> 33#include <linux/wait.h>
35#include <linux/errno.h> 34#include <linux/errno.h>
36#include <linux/kobject.h> 35#include <linux/kobject.h>
@@ -60,6 +59,7 @@ struct ttm_mem_shrink {
60 * for the GPU, and this will otherwise block other workqueue tasks(?) 59 * for the GPU, and this will otherwise block other workqueue tasks(?)
61 * At this point we use only a single-threaded workqueue. 60 * At this point we use only a single-threaded workqueue.
62 * @work: The workqueue callback for the shrink queue. 61 * @work: The workqueue callback for the shrink queue.
62 * @queue: Wait queue for processes suspended waiting for memory.
63 * @lock: Lock to protect the @shrink - and the memory accounting members, 63 * @lock: Lock to protect the @shrink - and the memory accounting members,
64 * that is, essentially the whole structure with some exceptions. 64 * that is, essentially the whole structure with some exceptions.
65 * @zones: Array of pointers to accounting zones. 65 * @zones: Array of pointers to accounting zones.
@@ -79,6 +79,7 @@ struct ttm_mem_global {
79 struct ttm_mem_shrink *shrink; 79 struct ttm_mem_shrink *shrink;
80 struct workqueue_struct *swap_queue; 80 struct workqueue_struct *swap_queue;
81 struct work_struct work; 81 struct work_struct work;
82 wait_queue_head_t queue;
82 spinlock_t lock; 83 spinlock_t lock;
83 struct ttm_mem_zone *zones[TTM_MEM_MAX_ZONES]; 84 struct ttm_mem_zone *zones[TTM_MEM_MAX_ZONES];
84 unsigned int num_zones; 85 unsigned int num_zones;
diff --git a/include/drm/ttm/ttm_object.h b/include/drm/ttm/ttm_object.h
index fc0cf064990..e46054e5255 100644
--- a/include/drm/ttm/ttm_object.h
+++ b/include/drm/ttm/ttm_object.h
@@ -38,9 +38,8 @@
38#define _TTM_OBJECT_H_ 38#define _TTM_OBJECT_H_
39 39
40#include <linux/list.h> 40#include <linux/list.h>
41#include <drm/drm_hashtab.h> 41#include "drm_hashtab.h"
42#include <linux/kref.h> 42#include <linux/kref.h>
43#include <linux/rcupdate.h>
44#include <ttm/ttm_memory.h> 43#include <ttm/ttm_memory.h>
45 44
46/** 45/**
@@ -121,7 +120,6 @@ struct ttm_object_device;
121 */ 120 */
122 121
123struct ttm_base_object { 122struct ttm_base_object {
124 struct rcu_head rhead;
125 struct drm_hash_item hash; 123 struct drm_hash_item hash;
126 enum ttm_object_type object_type; 124 enum ttm_object_type object_type;
127 bool shareable; 125 bool shareable;
@@ -270,6 +268,4 @@ extern struct ttm_object_device *ttm_object_device_init
270 268
271extern void ttm_object_device_release(struct ttm_object_device **p_tdev); 269extern void ttm_object_device_release(struct ttm_object_device **p_tdev);
272 270
273#define ttm_base_object_kfree(__object, __base)\
274 kfree_rcu(__object, __base.rhead)
275#endif 271#endif
diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
index 706b962c646..129de12353f 100644
--- a/include/drm/ttm/ttm_page_alloc.h
+++ b/include/drm/ttm/ttm_page_alloc.h
@@ -26,74 +26,49 @@
26#ifndef TTM_PAGE_ALLOC 26#ifndef TTM_PAGE_ALLOC
27#define TTM_PAGE_ALLOC 27#define TTM_PAGE_ALLOC
28 28
29#include <drm/ttm/ttm_bo_driver.h> 29#include "ttm_bo_driver.h"
30#include <drm/ttm/ttm_memory.h> 30#include "ttm_memory.h"
31 31
32/** 32/**
33 * Initialize pool allocator. 33 * Get count number of pages from pool to pages list.
34 */
35int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages);
36/**
37 * Free pool allocator.
38 */
39void ttm_page_alloc_fini(void);
40
41/**
42 * ttm_pool_populate:
43 *
44 * @ttm: The struct ttm_tt to contain the backing pages.
45 * 34 *
46 * Add backing pages to all of @ttm 35 * @pages: head of empty linked list where pages are filled.
36 * @flags: ttm flags for page allocation.
37 * @cstate: ttm caching state for the page.
38 * @count: number of pages to allocate.
39 * @dma_address: The DMA (bus) address of pages (if TTM_PAGE_FLAG_DMA32 set).
47 */ 40 */
48extern int ttm_pool_populate(struct ttm_tt *ttm); 41int ttm_get_pages(struct list_head *pages,
49 42 int flags,
43 enum ttm_caching_state cstate,
44 unsigned count,
45 dma_addr_t *dma_address);
50/** 46/**
51 * ttm_pool_unpopulate: 47 * Put linked list of pages to pool.
52 *
53 * @ttm: The struct ttm_tt which to free backing pages.
54 * 48 *
55 * Free all pages of @ttm 49 * @pages: list of pages to free.
50 * @page_count: number of pages in the list. Zero can be passed for unknown
51 * count.
52 * @flags: ttm flags for page allocation.
53 * @cstate: ttm caching state.
54 * @dma_address: The DMA (bus) address of pages (if TTM_PAGE_FLAG_DMA32 set).
56 */ 55 */
57extern void ttm_pool_unpopulate(struct ttm_tt *ttm); 56void ttm_put_pages(struct list_head *pages,
58 57 unsigned page_count,
59/** 58 int flags,
60 * Output the state of pools to debugfs file 59 enum ttm_caching_state cstate,
61 */ 60 dma_addr_t *dma_address);
62extern int ttm_page_alloc_debugfs(struct seq_file *m, void *data);
63
64
65#ifdef CONFIG_SWIOTLB
66/** 61/**
67 * Initialize pool allocator. 62 * Initialize pool allocator.
68 */ 63 */
69int ttm_dma_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages); 64int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages);
70
71/** 65/**
72 * Free pool allocator. 66 * Free pool allocator.
73 */ 67 */
74void ttm_dma_page_alloc_fini(void); 68void ttm_page_alloc_fini(void);
75 69
76/** 70/**
77 * Output the state of pools to debugfs file 71 * Output the state of pools to debugfs file
78 */ 72 */
79extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data); 73extern int ttm_page_alloc_debugfs(struct seq_file *m, void *data);
80
81extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
82extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
83
84#else
85static inline int ttm_dma_page_alloc_init(struct ttm_mem_global *glob,
86 unsigned max_pages)
87{
88 return -ENODEV;
89}
90
91static inline void ttm_dma_page_alloc_fini(void) { return; }
92
93static inline int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data)
94{
95 return 0;
96}
97#endif
98
99#endif 74#endif