aboutsummaryrefslogtreecommitdiffstats
path: root/include/drm
diff options
context:
space:
mode:
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2011-11-03 16:46:34 -0400
committerDave Airlie <airlied@redhat.com>2011-12-06 05:39:33 -0500
commit2334b75ffbef6b8932f09ec4418b65ddb764ae99 (patch)
tree3b1ebfbd1714adf1ac1595ca16303d2303c8c959 /include/drm
parentb1e5f172325547270f35e7d1e42416a606e1dbd2 (diff)
drm/ttm: provide dma aware ttm page pool code V9
In TTM world the pages for the graphic drivers are kept in three different pools: write combined, uncached, and cached (write-back). When the pages are used by the graphic driver the graphic adapter via its built in MMU (or AGP) programs these pages in. The programming requires the virtual address (from the graphic adapter perspective) and the physical address (either System RAM or the memory on the card) which is obtained using the pci_map_* calls (which does the virtual to physical - or bus address translation). During the graphic application's "life" those pages can be shuffled around, swapped out to disk, moved from the VRAM to System RAM or vice-versa. This all works with the existing TTM pool code - except when we want to use the software IOTLB (SWIOTLB) code to "map" the physical addresses to the graphic adapter MMU. We end up programming the bounce buffer's physical address instead of the TTM pool memory's and get a non-worky driver. There are two solutions: 1) using the DMA API to allocate pages that are screened by the DMA API, or 2) using the pci_sync_* calls to copy the pages from the bounce-buffer and back. This patch fixes the issue by allocating pages using the DMA API. The second is a viable option - but it has performance drawbacks and potential correctness issues - think of the write cache page being bounced (SWIOTLB->TTM), the WC is set on the TTM page and the copy from SWIOTLB not making it to the TTM page until the page has been recycled in the pool (and used by another application). The bounce buffer does not get activated often - only in cases where we have a 32-bit capable card and we want to use a page that is allocated above the 4GB limit. The bounce buffer offers the solution of copying the contents of that 4GB page to an location below 4GB and then back when the operation has been completed (or vice-versa). This is done by using the 'pci_sync_*' calls. Note: If you look carefully enough in the existing TTM page pool code you will notice the GFP_DMA32 flag is used - which should guarantee that the provided page is under 4GB. It certainly is the case, except this gets ignored in two cases: - If user specifies 'swiotlb=force' which bounces _every_ page. - If user is using a Xen's PV Linux guest (which uses the SWIOTLB and the underlaying PFN's aren't necessarily under 4GB). To not have this extra copying done the other option is to allocate the pages using the DMA API so that there is not need to map the page and perform the expensive 'pci_sync_*' calls. This DMA API capable TTM pool requires for this the 'struct device' to properly call the DMA API. It also has to track the virtual and bus address of the page being handed out in case it ends up being swapped out or de-allocated - to make sure it is de-allocated using the proper's 'struct device'. Implementation wise the code keeps two lists: one that is attached to the 'struct device' (via the dev->dma_pools list) and a global one to be used when the 'struct device' is unavailable (think shrinker code). The global list can iterate over all of the 'struct device' and its associated dma_pool. The list in dev->dma_pools can only iterate the device's dma_pool. /[struct device_pool]\ /---------------------------------------------------| dev | / +-------| dma_pool | /-----+------\ / \--------------------/ |struct device| /-->[struct dma_pool for WC]</ /[struct device_pool]\ | dma_pools +----+ /-| dev | | ... | \--->[struct dma_pool for uncached]<-/--| dma_pool | \-----+------/ / \--------------------/ \----------------------------------------------/ [Two pools associated with the device (WC and UC), and the parallel list containing the 'struct dev' and 'struct dma_pool' entries] The maximum amount of dma pools a device can have is six: write-combined, uncached, and cached; then there are the DMA32 variants which are: write-combined dma32, uncached dma32, and cached dma32. Currently this code only gets activated when any variant of the SWIOTLB IOMMU code is running (Intel without VT-d, AMD without GART, IBM Calgary and Xen PV with PCI devices). Tested-by: Michel Dänzer <michel@daenzer.net> [v1: Using swiotlb_nr_tbl instead of swiotlb_enabled] [v2: Major overhaul - added 'inuse_list' to seperate used from inuse and reorder the order of lists to get better performance.] [v3: Added comments/and some logic based on review, Added Jerome tag] [v4: rebase on top of ttm_tt & ttm_backend merge] [v5: rebase on top of ttm memory accounting overhaul] [v6: New rebase on top of more memory accouting changes] [v7: well rebase on top of no memory accounting changes] [v8: make sure pages list is initialized empty] [v9: calll ttm_mem_global_free_page in unpopulate for accurate accountg] Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Reviewed-by: Jerome Glisse <jglisse@redhat.com> Acked-by: Thomas Hellstrom <thellstrom@vmware.com>
Diffstat (limited to 'include/drm')
-rw-r--r--include/drm/ttm/ttm_bo_driver.h2
-rw-r--r--include/drm/ttm/ttm_page_alloc.h36
2 files changed, 38 insertions, 0 deletions
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index ae06e421cf90..beef9abaaefd 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -104,6 +104,7 @@ enum ttm_caching_state {
104 * @caching_state: The current caching state of the pages. 104 * @caching_state: The current caching state of the pages.
105 * @state: The current binding state of the pages. 105 * @state: The current binding state of the pages.
106 * @dma_address: The DMA (bus) addresses of the pages (if TTM_PAGE_FLAG_DMA32) 106 * @dma_address: The DMA (bus) addresses of the pages (if TTM_PAGE_FLAG_DMA32)
107 * @alloc_list: used by some page allocation backend
107 * 108 *
108 * This is a structure holding the pages, caching- and aperture binding 109 * This is a structure holding the pages, caching- and aperture binding
109 * status for a buffer object that isn't backed by fixed (VRAM / AGP) 110 * status for a buffer object that isn't backed by fixed (VRAM / AGP)
@@ -127,6 +128,7 @@ struct ttm_tt {
127 tt_unpopulated, 128 tt_unpopulated,
128 } state; 129 } state;
129 dma_addr_t *dma_address; 130 dma_addr_t *dma_address;
131 struct list_head alloc_list;
130}; 132};
131 133
132#define TTM_MEMTYPE_FLAG_FIXED (1 << 0) /* Fixed (on-card) PCI memory */ 134#define TTM_MEMTYPE_FLAG_FIXED (1 << 0) /* Fixed (on-card) PCI memory */
diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
index 18deeee23494..1e1337e81f31 100644
--- a/include/drm/ttm/ttm_page_alloc.h
+++ b/include/drm/ttm/ttm_page_alloc.h
@@ -89,4 +89,40 @@ extern void ttm_pool_unpopulate(struct ttm_tt *ttm);
89 * Output the state of pools to debugfs file 89 * Output the state of pools to debugfs file
90 */ 90 */
91extern int ttm_page_alloc_debugfs(struct seq_file *m, void *data); 91extern int ttm_page_alloc_debugfs(struct seq_file *m, void *data);
92
93
94#ifdef CONFIG_SWIOTLB
95/**
96 * Initialize pool allocator.
97 */
98int ttm_dma_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages);
99
100/**
101 * Free pool allocator.
102 */
103void ttm_dma_page_alloc_fini(void);
104
105/**
106 * Output the state of pools to debugfs file
107 */
108extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
109
110int ttm_dma_populate(struct ttm_tt *ttm, struct device *dev);
111extern void ttm_dma_unpopulate(struct ttm_tt *ttm, struct device *dev);
112
113#else
114static inline int ttm_dma_page_alloc_init(struct ttm_mem_global *glob,
115 unsigned max_pages)
116{
117 return -ENODEV;
118}
119
120static inline void ttm_dma_page_alloc_fini(void) { return; }
121
122static inline int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data)
123{
124 return 0;
125}
126#endif
127
92#endif 128#endif