Skip to content

Commit 07eee78

Browse files
Keir FraserDave Jones
authored andcommitted
[PATCH] AGP fix for Xen VMM
When Linux is running on the Xen virtual machine monitor, physical addresses are virtualised and cannot be directly referenced by the AGP GART. This patch fixes the GART driver for Xen by adding a layer of abstraction between physical addresses and 'GART addresses'. Architecture-specific functions are also defined for allocating and freeing the GATT. Xen requires this to ensure that table really is contiguous from the point of view of the GART. These extra interface functions are defined as 'no-ops' for all existing architectures that use the GART driver. Signed-off-by: Keir Fraser <keir@xensource.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Dave Jones <davej@redhat.com>
1 parent e29b545 commit 07eee78

20 files changed

Lines changed: 106 additions & 35 deletions

File tree

‎drivers/char/agp/agp.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ void agp3_generic_cleanup(void);
278278
#define AGP_GENERIC_SIZES_ENTRIES 11
279279
extern struct aper_size_info_16 agp3_generic_sizes[];
280280

281+
#define virt_to_gart(x) (phys_to_gart(virt_to_phys(x)))
282+
#define gart_to_virt(x) (phys_to_virt(gart_to_phys(x)))
281283

282284
extern int agp_off;
283285
extern int agp_try_unsupported_boot;

‎drivers/char/agp/ali-agp.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static void *m1541_alloc_page(struct agp_bridge_data *bridge)
150150
pci_read_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, &temp);
151151
pci_write_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL,
152152
(((temp & ALI_CACHE_FLUSH_ADDR_MASK) |
153-
virt_to_phys(addr)) | ALI_CACHE_FLUSH_EN ));
153+
virt_to_gart(addr)) | ALI_CACHE_FLUSH_EN ));
154154
return addr;
155155
}
156156

@@ -174,7 +174,7 @@ static void m1541_destroy_page(void * addr)
174174
pci_read_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, &temp);
175175
pci_write_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL,
176176
(((temp & ALI_CACHE_FLUSH_ADDR_MASK) |
177-
virt_to_phys(addr)) | ALI_CACHE_FLUSH_EN));
177+
virt_to_gart(addr)) | ALI_CACHE_FLUSH_EN));
178178
agp_generic_destroy_page(addr);
179179
}
180180

‎drivers/char/agp/amd-k7-agp.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static int amd_create_page_map(struct amd_page_map *page_map)
4343

4444
SetPageReserved(virt_to_page(page_map->real));
4545
global_cache_flush();
46-
page_map->remapped = ioremap_nocache(virt_to_phys(page_map->real),
46+
page_map->remapped = ioremap_nocache(virt_to_gart(page_map->real),
4747
PAGE_SIZE);
4848
if (page_map->remapped == NULL) {
4949
ClearPageReserved(virt_to_page(page_map->real));
@@ -154,7 +154,7 @@ static int amd_create_gatt_table(struct agp_bridge_data *bridge)
154154

155155
agp_bridge->gatt_table_real = (u32 *)page_dir.real;
156156
agp_bridge->gatt_table = (u32 __iomem *)page_dir.remapped;
157-
agp_bridge->gatt_bus_addr = virt_to_phys(page_dir.real);
157+
agp_bridge->gatt_bus_addr = virt_to_gart(page_dir.real);
158158

159159
/* Get the address for the gart region.
160160
* This is a bus address even on the alpha, b/c its
@@ -167,7 +167,7 @@ static int amd_create_gatt_table(struct agp_bridge_data *bridge)
167167

168168
/* Calculate the agp offset */
169169
for (i = 0; i < value->num_entries / 1024; i++, addr += 0x00400000) {
170-
writel(virt_to_phys(amd_irongate_private.gatt_pages[i]->real) | 1,
170+
writel(virt_to_gart(amd_irongate_private.gatt_pages[i]->real) | 1,
171171
page_dir.remapped+GET_PAGE_DIR_OFF(addr));
172172
readl(page_dir.remapped+GET_PAGE_DIR_OFF(addr)); /* PCI Posting. */
173173
}

‎drivers/char/agp/amd64-agp.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static struct aper_size_info_32 amd_8151_sizes[7] =
219219

220220
static int amd_8151_configure(void)
221221
{
222-
unsigned long gatt_bus = virt_to_phys(agp_bridge->gatt_table_real);
222+
unsigned long gatt_bus = virt_to_gart(agp_bridge->gatt_table_real);
223223

224224
/* Configure AGP regs in each x86-64 host bridge. */
225225
for_each_nb() {
@@ -591,7 +591,7 @@ static void __devexit agp_amd64_remove(struct pci_dev *pdev)
591591
{
592592
struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
593593

594-
release_mem_region(virt_to_phys(bridge->gatt_table_real),
594+
release_mem_region(virt_to_gart(bridge->gatt_table_real),
595595
amd64_aperture_sizes[bridge->aperture_size_idx].size);
596596
agp_remove_bridge(bridge);
597597
agp_put_bridge(bridge);

‎drivers/char/agp/ati-agp.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static int ati_create_page_map(ati_page_map *page_map)
6161

6262
SetPageReserved(virt_to_page(page_map->real));
6363
err = map_page_into_agp(virt_to_page(page_map->real));
64-
page_map->remapped = ioremap_nocache(virt_to_phys(page_map->real),
64+
page_map->remapped = ioremap_nocache(virt_to_gart(page_map->real),
6565
PAGE_SIZE);
6666
if (page_map->remapped == NULL || err) {
6767
ClearPageReserved(virt_to_page(page_map->real));
@@ -343,7 +343,7 @@ static int ati_create_gatt_table(struct agp_bridge_data *bridge)
343343

344344
agp_bridge->gatt_table_real = (u32 *)page_dir.real;
345345
agp_bridge->gatt_table = (u32 __iomem *) page_dir.remapped;
346-
agp_bridge->gatt_bus_addr = virt_to_bus(page_dir.real);
346+
agp_bridge->gatt_bus_addr = virt_to_gart(page_dir.real);
347347

348348
/* Write out the size register */
349349
current_size = A_SIZE_LVL2(agp_bridge->current_size);
@@ -373,7 +373,7 @@ static int ati_create_gatt_table(struct agp_bridge_data *bridge)
373373

374374
/* Calculate the agp offset */
375375
for(i = 0; i < value->num_entries / 1024; i++, addr += 0x00400000) {
376-
writel(virt_to_bus(ati_generic_private.gatt_pages[i]->real) | 1,
376+
writel(virt_to_gart(ati_generic_private.gatt_pages[i]->real) | 1,
377377
page_dir.remapped+GET_PAGE_DIR_OFF(addr));
378378
readl(page_dir.remapped+GET_PAGE_DIR_OFF(addr)); /* PCI Posting. */
379379
}

‎drivers/char/agp/backend.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static int agp_backend_initialize(struct agp_bridge_data *bridge)
148148
return -ENOMEM;
149149
}
150150

151-
bridge->scratch_page_real = virt_to_phys(addr);
151+
bridge->scratch_page_real = virt_to_gart(addr);
152152
bridge->scratch_page =
153153
bridge->driver->mask_memory(bridge, bridge->scratch_page_real, 0);
154154
}
@@ -189,7 +189,7 @@ static int agp_backend_initialize(struct agp_bridge_data *bridge)
189189
err_out:
190190
if (bridge->driver->needs_scratch_page)
191191
bridge->driver->agp_destroy_page(
192-
phys_to_virt(bridge->scratch_page_real));
192+
gart_to_virt(bridge->scratch_page_real));
193193
if (got_gatt)
194194
bridge->driver->free_gatt_table(bridge);
195195
if (got_keylist) {
@@ -214,7 +214,7 @@ static void agp_backend_cleanup(struct agp_bridge_data *bridge)
214214
if (bridge->driver->agp_destroy_page &&
215215
bridge->driver->needs_scratch_page)
216216
bridge->driver->agp_destroy_page(
217-
phys_to_virt(bridge->scratch_page_real));
217+
gart_to_virt(bridge->scratch_page_real));
218218
}
219219

220220
/* When we remove the global variable agp_bridge from all drivers

‎drivers/char/agp/efficeon-agp.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static int efficeon_create_gatt_table(struct agp_bridge_data *bridge)
219219

220220
efficeon_private.l1_table[index] = page;
221221

222-
value = __pa(page) | pati | present | index;
222+
value = virt_to_gart(page) | pati | present | index;
223223

224224
pci_write_config_dword(agp_bridge->dev,
225225
EFFICEON_ATTPAGE, value);

‎drivers/char/agp/generic.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void agp_free_memory(struct agp_memory *curr)
153153
}
154154
if (curr->page_count != 0) {
155155
for (i = 0; i < curr->page_count; i++) {
156-
curr->bridge->driver->agp_destroy_page(phys_to_virt(curr->memory[i]));
156+
curr->bridge->driver->agp_destroy_page(gart_to_virt(curr->memory[i]));
157157
}
158158
}
159159
agp_free_key(curr->key);
@@ -209,7 +209,7 @@ struct agp_memory *agp_allocate_memory(struct agp_bridge_data *bridge,
209209
agp_free_memory(new);
210210
return NULL;
211211
}
212-
new->memory[i] = virt_to_phys(addr);
212+
new->memory[i] = virt_to_gart(addr);
213213
new->page_count++;
214214
}
215215
new->bridge = bridge;
@@ -806,8 +806,7 @@ int agp_generic_create_gatt_table(struct agp_bridge_data *bridge)
806806
break;
807807
}
808808

809-
table = (char *) __get_free_pages(GFP_KERNEL,
810-
page_order);
809+
table = alloc_gatt_pages(page_order);
811810

812811
if (table == NULL) {
813812
i++;
@@ -838,7 +837,7 @@ int agp_generic_create_gatt_table(struct agp_bridge_data *bridge)
838837
size = ((struct aper_size_info_fixed *) temp)->size;
839838
page_order = ((struct aper_size_info_fixed *) temp)->page_order;
840839
num_entries = ((struct aper_size_info_fixed *) temp)->num_entries;
841-
table = (char *) __get_free_pages(GFP_KERNEL, page_order);
840+
table = alloc_gatt_pages(page_order);
842841
}
843842

844843
if (table == NULL)
@@ -853,19 +852,19 @@ int agp_generic_create_gatt_table(struct agp_bridge_data *bridge)
853852
agp_gatt_table = (void *)table;
854853

855854
bridge->driver->cache_flush();
856-
bridge->gatt_table = ioremap_nocache(virt_to_phys(table),
855+
bridge->gatt_table = ioremap_nocache(virt_to_gart(table),
857856
(PAGE_SIZE * (1 << page_order)));
858857
bridge->driver->cache_flush();
859858

860859
if (bridge->gatt_table == NULL) {
861860
for (page = virt_to_page(table); page <= virt_to_page(table_end); page++)
862861
ClearPageReserved(page);
863862

864-
free_pages((unsigned long) table, page_order);
863+
free_gatt_pages(table, page_order);
865864

866865
return -ENOMEM;
867866
}
868-
bridge->gatt_bus_addr = virt_to_phys(bridge->gatt_table_real);
867+
bridge->gatt_bus_addr = virt_to_gart(bridge->gatt_table_real);
869868

870869
/* AK: bogus, should encode addresses > 4GB */
871870
for (i = 0; i < num_entries; i++) {
@@ -919,7 +918,7 @@ int agp_generic_free_gatt_table(struct agp_bridge_data *bridge)
919918
for (page = virt_to_page(table); page <= virt_to_page(table_end); page++)
920919
ClearPageReserved(page);
921920

922-
free_pages((unsigned long) bridge->gatt_table_real, page_order);
921+
free_gatt_pages(bridge->gatt_table_real, page_order);
923922

924923
agp_gatt_table = NULL;
925924
bridge->gatt_table = NULL;

‎drivers/char/agp/hp-agp.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static int __init hp_zx1_ioc_shared(void)
110110
hp->gart_size = HP_ZX1_GART_SIZE;
111111
hp->gatt_entries = hp->gart_size / hp->io_page_size;
112112

113-
hp->io_pdir = phys_to_virt(readq(hp->ioc_regs+HP_ZX1_PDIR_BASE));
113+
hp->io_pdir = gart_to_virt(readq(hp->ioc_regs+HP_ZX1_PDIR_BASE));
114114
hp->gatt = &hp->io_pdir[HP_ZX1_IOVA_TO_PDIR(hp->gart_base)];
115115

116116
if (hp->gatt[0] != HP_ZX1_SBA_IOMMU_COOKIE) {
@@ -248,7 +248,7 @@ hp_zx1_configure (void)
248248
agp_bridge->mode = readl(hp->lba_regs+hp->lba_cap_offset+PCI_AGP_STATUS);
249249

250250
if (hp->io_pdir_owner) {
251-
writel(virt_to_phys(hp->io_pdir), hp->ioc_regs+HP_ZX1_PDIR_BASE);
251+
writel(virt_to_gart(hp->io_pdir), hp->ioc_regs+HP_ZX1_PDIR_BASE);
252252
readl(hp->ioc_regs+HP_ZX1_PDIR_BASE);
253253
writel(hp->io_tlb_ps, hp->ioc_regs+HP_ZX1_TCNFG);
254254
readl(hp->ioc_regs+HP_ZX1_TCNFG);

‎drivers/char/agp/i460-agp.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ static int i460_alloc_large_page (struct lp_desc *lp)
372372
}
373373
memset(lp->alloced_map, 0, map_size);
374374

375-
lp->paddr = virt_to_phys(lpage);
375+
lp->paddr = virt_to_gart(lpage);
376376
lp->refcount = 0;
377377
atomic_add(I460_KPAGES_PER_IOPAGE, &agp_bridge->current_memory_agp);
378378
return 0;
@@ -383,7 +383,7 @@ static void i460_free_large_page (struct lp_desc *lp)
383383
kfree(lp->alloced_map);
384384
lp->alloced_map = NULL;
385385

386-
free_pages((unsigned long) phys_to_virt(lp->paddr), I460_IO_PAGE_SHIFT - PAGE_SHIFT);
386+
free_pages((unsigned long) gart_to_virt(lp->paddr), I460_IO_PAGE_SHIFT - PAGE_SHIFT);
387387
atomic_sub(I460_KPAGES_PER_IOPAGE, &agp_bridge->current_memory_agp);
388388
}
389389

0 commit comments

Comments
 (0)