alistair23-linux/include/drm
Konrad Rzeszutek Wilk 2334b75ffb 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>
2011-12-06 10:39:33 +00:00
..
i2c drm: Import driver for the sil164 I2C TMDS transmitter. 2010-08-02 10:21:13 +10:00
ttm drm/ttm: provide dma aware ttm page pool code V9 2011-12-06 10:39:33 +00:00
drm.h drm: add an fb creation ioctl that takes a pixel format v5 2011-11-15 19:53:23 +00:00
drm_buffer.h drm: Add generic multipart buffer. 2010-02-23 09:46:20 +10:00
drm_cache.h drm/ttm: consolidate cache flushing code in one place. 2009-08-27 09:53:47 +10:00
drm_core.h drm: Fix support for PCI domains 2010-08-10 08:20:20 +10:00
drm_crtc.h drm: document the drm_mode_config structure 2011-12-06 10:23:35 +00:00
drm_crtc_helper.h drm: move the fb bpp/depth helper into the core. 2011-11-29 20:02:54 +00:00
drm_dp_helper.h drm/radeon/kms: properly set panel mode for eDP 2011-11-01 16:01:58 +00:00
drm_edid.h drm: support routines for HDMI/DP ELD 2011-09-21 14:52:41 -07:00
drm_encoder_slave.h drm/kms: no need to return void value (encoder) 2009-08-19 16:06:49 +10:00
drm_fb_helper.h drm: Take lock around probes for drm_fb_helper_hotplug_event 2011-05-16 12:01:43 +10:00
drm_fixed.h drm: move radeon_fixed.h to shared drm_fixed.h header 2010-05-18 18:21:33 +10:00
drm_fourcc.h drm: Redefine pixel formats 2011-12-01 14:16:10 +00:00
drm_global.h drm: move ttm global code to core drm 2010-08-04 09:46:06 +10:00
drm_hashtab.h drm: Remove unused members from struct drm_open_hash 2011-02-23 11:16:40 +10:00
drm_mem_util.h drm/ttm: use drm calloc large and free large 2010-03-15 10:31:43 +10:00
drm_memory.h includecheck fix: include/drm, drm_memory.h 2009-09-20 16:02:58 +05:30
drm_mm.h drm: mm: fix debug output 2011-05-09 09:14:45 +10:00
drm_mode.h drm: add an fb creation ioctl that takes a pixel format v5 2011-11-15 19:53:23 +00:00
drm_os_linux.h drm/i915: add i915_lp_ring_sync helper 2009-11-05 14:47:07 -08:00
drm_pciids.h drm/radeon/kms: add new NI pci ids 2011-07-15 16:10:55 +01:00
drm_sarea.h drm: move to kref per-master structures. 2008-12-29 17:47:22 +10:00
drm_sman.h drm: reorganise drm tree to be more future proof. 2008-07-14 10:45:01 +10:00
drm_sysfs.h drm: Enable drm drivers to add drm sysfs devices. 2009-08-19 16:08:51 +10:00
drm_usb.h drm: add usb framework 2011-02-07 13:09:42 +10:00
drmP.h drm: Make the per-driver file_operations struct const 2011-11-11 11:14:47 +00:00
exynos_drm.h DRM: add DRM Driver for Samsung SoC EXYNOS4210. 2011-10-05 10:27:31 +01:00
gma_drm.h gma500: Move the API 2011-12-06 09:54:23 +00:00
i810_drm.h drm: reorganise drm tree to be more future proof. 2008-07-14 10:45:01 +10:00
i915_drm.h drm/i915: Fix typo in DRM_I915_OVERLAY_PUT_IMAGE ioctl define 2011-07-22 13:36:44 -07:00
intel-gtt.h drm/i915: ILK + VT-d workaround 2011-10-20 15:26:39 -07:00
Kbuild drm: remove i830 driver 2011-02-07 12:14:18 +10:00
mga_drm.h Fix common misspellings 2011-03-31 11:26:23 -03:00
nouveau_drm.h drm/nv50: support for compression 2011-02-25 06:46:07 +10:00
r128_drm.h drm: reorganise drm tree to be more future proof. 2008-07-14 10:45:01 +10:00
radeon_drm.h Revert "drm/radeon/kms: add a new gem_wait ioctl with read/write flags" 2011-10-27 18:15:10 +02:00
savage_drm.h Fix common misspellings 2011-03-31 11:26:23 -03:00
sis_drm.h drm: reorganise drm tree to be more future proof. 2008-07-14 10:45:01 +10:00
via_drm.h drm: Add compatibility #ifdefs for *BSD 2009-12-04 08:59:28 +10:00
vmwgfx_drm.h vmwgfx: Reinstate the update_layout ioctl 2011-11-02 08:30:31 +00:00