aboutsummaryrefslogtreecommitdiffstats
path: root/include/drm/ttm/ttm_bo_driver.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/drm/ttm/ttm_bo_driver.h')
-rw-r--r--include/drm/ttm/ttm_bo_driver.h203
1 files changed, 89 insertions, 114 deletions
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 94eb1434316e..d43e892307ff 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -43,36 +43,9 @@ struct ttm_backend;
43 43
44struct ttm_backend_func { 44struct ttm_backend_func {
45 /** 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 /**
73 * struct ttm_backend_func member bind 46 * struct ttm_backend_func member bind
74 * 47 *
75 * @backend: Pointer to a struct ttm_backend. 48 * @ttm: Pointer to a struct ttm_tt.
76 * @bo_mem: Pointer to a struct ttm_mem_reg describing the 49 * @bo_mem: Pointer to a struct ttm_mem_reg describing the
77 * memory type and location for binding. 50 * memory type and location for binding.
78 * 51 *
@@ -80,46 +53,29 @@ struct ttm_backend_func {
80 * indicated by @bo_mem. This function should be able to handle 53 * indicated by @bo_mem. This function should be able to handle
81 * differences between aperture and system page sizes. 54 * differences between aperture and system page sizes.
82 */ 55 */
83 int (*bind) (struct ttm_backend *backend, struct ttm_mem_reg *bo_mem); 56 int (*bind) (struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem);
84 57
85 /** 58 /**
86 * struct ttm_backend_func member unbind 59 * struct ttm_backend_func member unbind
87 * 60 *
88 * @backend: Pointer to a struct ttm_backend. 61 * @ttm: Pointer to a struct ttm_tt.
89 * 62 *
90 * Unbind previously bound backend pages. This function should be 63 * Unbind previously bound backend pages. This function should be
91 * able to handle differences between aperture and system page sizes. 64 * able to handle differences between aperture and system page sizes.
92 */ 65 */
93 int (*unbind) (struct ttm_backend *backend); 66 int (*unbind) (struct ttm_tt *ttm);
94 67
95 /** 68 /**
96 * struct ttm_backend_func member destroy 69 * struct ttm_backend_func member destroy
97 * 70 *
98 * @backend: Pointer to a struct ttm_backend. 71 * @ttm: Pointer to a struct ttm_tt.
99 * 72 *
100 * Destroy the backend. 73 * Destroy the backend. This will be call back from ttm_tt_destroy so
74 * don't call ttm_tt_destroy from the callback or infinite loop.
101 */ 75 */
102 void (*destroy) (struct ttm_backend *backend); 76 void (*destroy) (struct ttm_tt *ttm);
103};
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}; 77};
120 78
121#define TTM_PAGE_FLAG_USER (1 << 1)
122#define TTM_PAGE_FLAG_USER_DIRTY (1 << 2)
123#define TTM_PAGE_FLAG_WRITE (1 << 3) 79#define TTM_PAGE_FLAG_WRITE (1 << 3)
124#define TTM_PAGE_FLAG_SWAPPED (1 << 4) 80#define TTM_PAGE_FLAG_SWAPPED (1 << 4)
125#define TTM_PAGE_FLAG_PERSISTENT_SWAP (1 << 5) 81#define TTM_PAGE_FLAG_PERSISTENT_SWAP (1 << 5)
@@ -135,23 +91,18 @@ enum ttm_caching_state {
135/** 91/**
136 * struct ttm_tt 92 * struct ttm_tt
137 * 93 *
94 * @bdev: Pointer to a struct ttm_bo_device.
95 * @func: Pointer to a struct ttm_backend_func that describes
96 * the backend methods.
138 * @dummy_read_page: Page to map where the ttm_tt page array contains a NULL 97 * @dummy_read_page: Page to map where the ttm_tt page array contains a NULL
139 * pointer. 98 * pointer.
140 * @pages: Array of pages backing the data. 99 * @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.
146 * @num_pages: Number of pages in the page array. 100 * @num_pages: Number of pages in the page array.
147 * @bdev: Pointer to the current struct ttm_bo_device. 101 * @bdev: Pointer to the current struct ttm_bo_device.
148 * @be: Pointer to the ttm backend. 102 * @be: Pointer to the ttm backend.
149 * @tsk: The task for user ttm.
150 * @start: virtual address for user ttm.
151 * @swap_storage: Pointer to shmem struct file for swap storage. 103 * @swap_storage: Pointer to shmem struct file for swap storage.
152 * @caching_state: The current caching state of the pages. 104 * @caching_state: The current caching state of the pages.
153 * @state: The current binding state of the pages. 105 * @state: The current binding state of the pages.
154 * @dma_address: The DMA (bus) addresses of the pages (if TTM_PAGE_FLAG_DMA32)
155 * 106 *
156 * This is a structure holding the pages, caching- and aperture binding 107 * This is a structure holding the pages, caching- and aperture binding
157 * status for a buffer object that isn't backed by fixed (VRAM / AGP) 108 * status for a buffer object that isn't backed by fixed (VRAM / AGP)
@@ -159,16 +110,14 @@ enum ttm_caching_state {
159 */ 110 */
160 111
161struct ttm_tt { 112struct ttm_tt {
113 struct ttm_bo_device *bdev;
114 struct ttm_backend_func *func;
162 struct page *dummy_read_page; 115 struct page *dummy_read_page;
163 struct page **pages; 116 struct page **pages;
164 long first_himem_page;
165 long last_lomem_page;
166 uint32_t page_flags; 117 uint32_t page_flags;
167 unsigned long num_pages; 118 unsigned long num_pages;
168 struct ttm_bo_global *glob; 119 struct ttm_bo_global *glob;
169 struct ttm_backend *be; 120 struct ttm_backend *be;
170 struct task_struct *tsk;
171 unsigned long start;
172 struct file *swap_storage; 121 struct file *swap_storage;
173 enum ttm_caching_state caching_state; 122 enum ttm_caching_state caching_state;
174 enum { 123 enum {
@@ -176,7 +125,23 @@ struct ttm_tt {
176 tt_unbound, 125 tt_unbound,
177 tt_unpopulated, 126 tt_unpopulated,
178 } state; 127 } state;
128};
129
130/**
131 * struct ttm_dma_tt
132 *
133 * @ttm: Base ttm_tt struct.
134 * @dma_address: The DMA (bus) addresses of the pages
135 * @pages_list: used by some page allocation backend
136 *
137 * This is a structure holding the pages, caching- and aperture binding
138 * status for a buffer object that isn't backed by fixed (VRAM / AGP)
139 * memory.
140 */
141struct ttm_dma_tt {
142 struct ttm_tt ttm;
179 dma_addr_t *dma_address; 143 dma_addr_t *dma_address;
144 struct list_head pages_list;
180}; 145};
181 146
182#define TTM_MEMTYPE_FLAG_FIXED (1 << 0) /* Fixed (on-card) PCI memory */ 147#define TTM_MEMTYPE_FLAG_FIXED (1 << 0) /* Fixed (on-card) PCI memory */
@@ -351,15 +316,42 @@ struct ttm_mem_type_manager {
351 316
352struct ttm_bo_driver { 317struct ttm_bo_driver {
353 /** 318 /**
354 * struct ttm_bo_driver member create_ttm_backend_entry 319 * ttm_tt_create
355 * 320 *
356 * @bdev: The buffer object device. 321 * @bdev: pointer to a struct ttm_bo_device:
322 * @size: Size of the data needed backing.
323 * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags.
324 * @dummy_read_page: See struct ttm_bo_device.
357 * 325 *
358 * Create a driver specific struct ttm_backend. 326 * Create a struct ttm_tt to back data with system memory pages.
327 * No pages are actually allocated.
328 * Returns:
329 * NULL: Out of memory.
359 */ 330 */
331 struct ttm_tt *(*ttm_tt_create)(struct ttm_bo_device *bdev,
332 unsigned long size,
333 uint32_t page_flags,
334 struct page *dummy_read_page);
360 335
361 struct ttm_backend *(*create_ttm_backend_entry) 336 /**
362 (struct ttm_bo_device *bdev); 337 * ttm_tt_populate
338 *
339 * @ttm: The struct ttm_tt to contain the backing pages.
340 *
341 * Allocate all backing pages
342 * Returns:
343 * -ENOMEM: Out of memory.
344 */
345 int (*ttm_tt_populate)(struct ttm_tt *ttm);
346
347 /**
348 * ttm_tt_unpopulate
349 *
350 * @ttm: The struct ttm_tt to contain the backing pages.
351 *
352 * Free all backing page
353 */
354 void (*ttm_tt_unpopulate)(struct ttm_tt *ttm);
363 355
364 /** 356 /**
365 * struct ttm_bo_driver member invalidate_caches 357 * struct ttm_bo_driver member invalidate_caches
@@ -477,9 +469,6 @@ struct ttm_bo_global_ref {
477 * @dummy_read_page: Pointer to a dummy page used for mapping requests 469 * @dummy_read_page: Pointer to a dummy page used for mapping requests
478 * of unpopulated pages. 470 * of unpopulated pages.
479 * @shrink: A shrink callback object used for buffer object swap. 471 * @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).
483 * @device_list_mutex: Mutex protecting the device list. 472 * @device_list_mutex: Mutex protecting the device list.
484 * This mutex is held while traversing the device list for pm options. 473 * This mutex is held while traversing the device list for pm options.
485 * @lru_lock: Spinlock protecting the bo subsystem lru lists. 474 * @lru_lock: Spinlock protecting the bo subsystem lru lists.
@@ -497,8 +486,6 @@ struct ttm_bo_global {
497 struct ttm_mem_global *mem_glob; 486 struct ttm_mem_global *mem_glob;
498 struct page *dummy_read_page; 487 struct page *dummy_read_page;
499 struct ttm_mem_shrink shrink; 488 struct ttm_mem_shrink shrink;
500 size_t ttm_bo_extra_size;
501 size_t ttm_bo_size;
502 struct mutex device_list_mutex; 489 struct mutex device_list_mutex;
503 spinlock_t lru_lock; 490 spinlock_t lru_lock;
504 491
@@ -600,8 +587,9 @@ ttm_flag_masked(uint32_t *old, uint32_t new, uint32_t mask)
600} 587}
601 588
602/** 589/**
603 * ttm_tt_create 590 * ttm_tt_init
604 * 591 *
592 * @ttm: The struct ttm_tt.
605 * @bdev: pointer to a struct ttm_bo_device: 593 * @bdev: pointer to a struct ttm_bo_device:
606 * @size: Size of the data needed backing. 594 * @size: Size of the data needed backing.
607 * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags. 595 * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags.
@@ -612,28 +600,22 @@ ttm_flag_masked(uint32_t *old, uint32_t new, uint32_t mask)
612 * Returns: 600 * Returns:
613 * NULL: Out of memory. 601 * NULL: Out of memory.
614 */ 602 */
615extern struct ttm_tt *ttm_tt_create(struct ttm_bo_device *bdev, 603extern int ttm_tt_init(struct ttm_tt *ttm, struct ttm_bo_device *bdev,
616 unsigned long size, 604 unsigned long size, uint32_t page_flags,
617 uint32_t page_flags, 605 struct page *dummy_read_page);
618 struct page *dummy_read_page); 606extern int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_bo_device *bdev,
607 unsigned long size, uint32_t page_flags,
608 struct page *dummy_read_page);
619 609
620/** 610/**
621 * ttm_tt_set_user: 611 * ttm_tt_fini
622 * 612 *
623 * @ttm: The struct ttm_tt to populate. 613 * @ttm: the ttm_tt structure.
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.
627 * 614 *
628 * Populate a struct ttm_tt with a user-space memory area after first pinning 615 * Free memory of ttm_tt structure
629 * the pages backing it.
630 * Returns:
631 * !0: Error.
632 */ 616 */
633 617extern void ttm_tt_fini(struct ttm_tt *ttm);
634extern int ttm_tt_set_user(struct ttm_tt *ttm, 618extern void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma);
635 struct task_struct *tsk,
636 unsigned long start, unsigned long num_pages);
637 619
638/** 620/**
639 * ttm_ttm_bind: 621 * ttm_ttm_bind:
@@ -646,20 +628,11 @@ extern int ttm_tt_set_user(struct ttm_tt *ttm,
646extern int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem); 628extern int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem);
647 629
648/** 630/**
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/**
658 * ttm_ttm_destroy: 631 * ttm_ttm_destroy:
659 * 632 *
660 * @ttm: The struct ttm_tt. 633 * @ttm: The struct ttm_tt.
661 * 634 *
662 * Unbind, unpopulate and destroy a struct ttm_tt. 635 * Unbind, unpopulate and destroy common struct ttm_tt.
663 */ 636 */
664extern void ttm_tt_destroy(struct ttm_tt *ttm); 637extern void ttm_tt_destroy(struct ttm_tt *ttm);
665 638
@@ -673,19 +646,13 @@ extern void ttm_tt_destroy(struct ttm_tt *ttm);
673extern void ttm_tt_unbind(struct ttm_tt *ttm); 646extern void ttm_tt_unbind(struct ttm_tt *ttm);
674 647
675/** 648/**
676 * ttm_ttm_destroy: 649 * ttm_tt_swapin:
677 * 650 *
678 * @ttm: The struct ttm_tt. 651 * @ttm: The struct ttm_tt.
679 * @index: Index of the desired page.
680 *
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 * 652 *
685 * Returns: 653 * Swap in a previously swap out ttm_tt.
686 * NULL on OOM.
687 */ 654 */
688extern struct page *ttm_tt_get_page(struct ttm_tt *ttm, int index); 655extern int ttm_tt_swapin(struct ttm_tt *ttm);
689 656
690/** 657/**
691 * ttm_tt_cache_flush: 658 * ttm_tt_cache_flush:
@@ -1046,17 +1013,25 @@ extern const struct ttm_mem_type_manager_func ttm_bo_manager_func;
1046#include <linux/agp_backend.h> 1013#include <linux/agp_backend.h>
1047 1014
1048/** 1015/**
1049 * ttm_agp_backend_init 1016 * ttm_agp_tt_create
1050 * 1017 *
1051 * @bdev: Pointer to a struct ttm_bo_device. 1018 * @bdev: Pointer to a struct ttm_bo_device.
1052 * @bridge: The agp bridge this device is sitting on. 1019 * @bridge: The agp bridge this device is sitting on.
1020 * @size: Size of the data needed backing.
1021 * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags.
1022 * @dummy_read_page: See struct ttm_bo_device.
1023 *
1053 * 1024 *
1054 * Create a TTM backend that uses the indicated AGP bridge as an aperture 1025 * Create a TTM backend that uses the indicated AGP bridge as an aperture
1055 * for TT memory. This function uses the linux agpgart interface to 1026 * for TT memory. This function uses the linux agpgart interface to
1056 * bind and unbind memory backing a ttm_tt. 1027 * bind and unbind memory backing a ttm_tt.
1057 */ 1028 */
1058extern struct ttm_backend *ttm_agp_backend_init(struct ttm_bo_device *bdev, 1029extern struct ttm_tt *ttm_agp_tt_create(struct ttm_bo_device *bdev,
1059 struct agp_bridge_data *bridge); 1030 struct agp_bridge_data *bridge,
1031 unsigned long size, uint32_t page_flags,
1032 struct page *dummy_read_page);
1033int ttm_agp_tt_populate(struct ttm_tt *ttm);
1034void ttm_agp_tt_unpopulate(struct ttm_tt *ttm);
1060#endif 1035#endif
1061 1036
1062#endif 1037#endif