Skip to content

Commit 0e87d2b

Browse files
danvetickle
authored andcommitted
intel-gtt: initialize our own scratch page
The intel gtt fake agp driver is the only agp driver to use dma address remapping. So it makes sense to fold this code back into the only user (and thus reduce the reliance on the agp code). This patch does the first step by initializing (and remapping) the scratch page in a new function intel_gtt_setup_scratch_page. Unfortunately intel_gtt_cleanup had to move to avoid a forward declaration. The new scratch page is not yet used, though. v2: Refactor out scratch page teardown. Suggested by Chris Wilson on irc. This makes it clear what's going on and results in a nice symmetry between setup and teardown. Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
1 parent f13d3f7 commit 0e87d2b

1 file changed

Lines changed: 64 additions & 17 deletions

File tree

‎drivers/char/agp/intel-gtt.c‎

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
*/
3636
#ifdef CONFIG_DMAR
3737
#define USE_PCI_DMA_API 1
38+
#else
39+
#define USE_PCI_DMA_API 0
3840
#endif
3941

4042
/* Max amount of stolen space, anything above will be returned to Linux */
@@ -108,14 +110,16 @@ static struct _intel_private {
108110
struct page *i8xx_page;
109111
struct resource ifp_resource;
110112
int resource_valid;
113+
struct page *scratch_page;
114+
dma_addr_t scratch_page_dma;
111115
} intel_private;
112116

113117
#define INTEL_GTT_GEN intel_private.driver->gen
114118
#define IS_G33 intel_private.driver->is_g33
115119
#define IS_PINEVIEW intel_private.driver->is_pineview
116120
#define IS_IRONLAKE intel_private.driver->is_ironlake
117121

118-
#ifdef USE_PCI_DMA_API
122+
#if USE_PCI_DMA_API
119123
static int intel_agp_map_page(struct page *page, dma_addr_t *ret)
120124
{
121125
*ret = pci_map_page(intel_private.pcidev, page, 0,
@@ -540,6 +544,32 @@ static unsigned long intel_i810_mask_memory(struct agp_bridge_data *bridge,
540544
return addr | bridge->driver->masks[type].mask;
541545
}
542546

547+
static int intel_gtt_setup_scratch_page(void)
548+
{
549+
struct page *page;
550+
dma_addr_t dma_addr;
551+
552+
page = alloc_page(GFP_KERNEL | GFP_DMA32 | __GFP_ZERO);
553+
if (page == NULL)
554+
return -ENOMEM;
555+
get_page(page);
556+
set_pages_uc(page, 1);
557+
558+
if (USE_PCI_DMA_API && INTEL_GTT_GEN > 2) {
559+
dma_addr = pci_map_page(intel_private.pcidev, page, 0,
560+
PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
561+
if (pci_dma_mapping_error(intel_private.pcidev, dma_addr))
562+
return -EINVAL;
563+
564+
intel_private.scratch_page_dma = dma_addr;
565+
} else
566+
intel_private.scratch_page_dma = page_to_phys(page);
567+
568+
intel_private.scratch_page = page;
569+
570+
return 0;
571+
}
572+
543573
static const struct aper_size_info_fixed const intel_fake_agp_sizes[] = {
544574
{128, 32768, 5},
545575
/* The 64M mode still requires a 128k gatt */
@@ -794,6 +824,29 @@ static unsigned int intel_gtt_mappable_entries(void)
794824
return aperture_size >> PAGE_SHIFT;
795825
}
796826

827+
static void intel_gtt_teardown_scratch_page(void)
828+
{
829+
set_pages_wb(intel_private.scratch_page, 1);
830+
pci_unmap_page(intel_private.pcidev, intel_private.scratch_page_dma,
831+
PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
832+
put_page(intel_private.scratch_page);
833+
__free_page(intel_private.scratch_page);
834+
}
835+
836+
static void intel_gtt_cleanup(void)
837+
{
838+
if (intel_private.i9xx_flush_page)
839+
iounmap(intel_private.i9xx_flush_page);
840+
if (intel_private.resource_valid)
841+
release_resource(&intel_private.ifp_resource);
842+
intel_private.ifp_resource.start = 0;
843+
intel_private.resource_valid = 0;
844+
iounmap(intel_private.gtt);
845+
iounmap(intel_private.registers);
846+
847+
intel_gtt_teardown_scratch_page();
848+
}
849+
797850
static int intel_gtt_init(void)
798851
{
799852
u32 gtt_map_size;
@@ -825,6 +878,12 @@ static int intel_gtt_init(void)
825878
return -ENOMEM;
826879
}
827880

881+
ret = intel_gtt_setup_scratch_page();
882+
if (ret != 0) {
883+
intel_gtt_cleanup();
884+
return ret;
885+
}
886+
828887
return 0;
829888
}
830889

@@ -1174,18 +1233,6 @@ static int intel_i9xx_configure(void)
11741233
return 0;
11751234
}
11761235

1177-
static void intel_gtt_cleanup(void)
1178-
{
1179-
if (intel_private.i9xx_flush_page)
1180-
iounmap(intel_private.i9xx_flush_page);
1181-
if (intel_private.resource_valid)
1182-
release_resource(&intel_private.ifp_resource);
1183-
intel_private.ifp_resource.start = 0;
1184-
intel_private.resource_valid = 0;
1185-
iounmap(intel_private.gtt);
1186-
iounmap(intel_private.registers);
1187-
}
1188-
11891236
static void intel_i915_chipset_flush(struct agp_bridge_data *bridge)
11901237
{
11911238
if (intel_private.i9xx_flush_page)
@@ -1416,7 +1463,7 @@ static const struct agp_bridge_driver intel_915_driver = {
14161463
.agp_destroy_pages = agp_generic_destroy_pages,
14171464
.agp_type_to_mask_type = intel_i830_type_to_mask_type,
14181465
.chipset_flush = intel_i915_chipset_flush,
1419-
#ifdef USE_PCI_DMA_API
1466+
#if USE_PCI_DMA_API
14201467
.agp_map_page = intel_agp_map_page,
14211468
.agp_unmap_page = intel_agp_unmap_page,
14221469
.agp_map_memory = intel_agp_map_memory,
@@ -1449,7 +1496,7 @@ static const struct agp_bridge_driver intel_i965_driver = {
14491496
.agp_destroy_pages = agp_generic_destroy_pages,
14501497
.agp_type_to_mask_type = intel_i830_type_to_mask_type,
14511498
.chipset_flush = intel_i915_chipset_flush,
1452-
#ifdef USE_PCI_DMA_API
1499+
#if USE_PCI_DMA_API
14531500
.agp_map_page = intel_agp_map_page,
14541501
.agp_unmap_page = intel_agp_unmap_page,
14551502
.agp_map_memory = intel_agp_map_memory,
@@ -1482,7 +1529,7 @@ static const struct agp_bridge_driver intel_gen6_driver = {
14821529
.agp_destroy_pages = agp_generic_destroy_pages,
14831530
.agp_type_to_mask_type = intel_gen6_type_to_mask_type,
14841531
.chipset_flush = intel_i915_chipset_flush,
1485-
#ifdef USE_PCI_DMA_API
1532+
#if USE_PCI_DMA_API
14861533
.agp_map_page = intel_agp_map_page,
14871534
.agp_unmap_page = intel_agp_unmap_page,
14881535
.agp_map_memory = intel_agp_map_memory,
@@ -1515,7 +1562,7 @@ static const struct agp_bridge_driver intel_g33_driver = {
15151562
.agp_destroy_pages = agp_generic_destroy_pages,
15161563
.agp_type_to_mask_type = intel_i830_type_to_mask_type,
15171564
.chipset_flush = intel_i915_chipset_flush,
1518-
#ifdef USE_PCI_DMA_API
1565+
#if USE_PCI_DMA_API
15191566
.agp_map_page = intel_agp_map_page,
15201567
.agp_unmap_page = intel_agp_unmap_page,
15211568
.agp_map_memory = intel_agp_map_memory,

0 commit comments

Comments
 (0)