Skip to content

Commit 07613ba

Browse files
committed
agp: switch AGP to use page array instead of unsigned long array
This switches AGP to use an array of pages for tracking the pages allocated to the GART. This should enable GEM on PAE to work a lot better as we can pass highmem pages to the PAT code and it will do the right thing with them. Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent 2908826 commit 07613ba

21 files changed

Lines changed: 152 additions & 146 deletions

‎drivers/char/agp/agp.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,17 @@ struct agp_bridge_driver {
107107
void (*agp_enable)(struct agp_bridge_data *, u32);
108108
void (*cleanup)(void);
109109
void (*tlb_flush)(struct agp_memory *);
110-
unsigned long (*mask_memory)(struct agp_bridge_data *, unsigned long, int);
110+
unsigned long (*mask_memory)(struct agp_bridge_data *, struct page *, int);
111111
void (*cache_flush)(void);
112112
int (*create_gatt_table)(struct agp_bridge_data *);
113113
int (*free_gatt_table)(struct agp_bridge_data *);
114114
int (*insert_memory)(struct agp_memory *, off_t, int);
115115
int (*remove_memory)(struct agp_memory *, off_t, int);
116116
struct agp_memory *(*alloc_by_type) (size_t, int);
117117
void (*free_by_type)(struct agp_memory *);
118-
void *(*agp_alloc_page)(struct agp_bridge_data *);
118+
struct page *(*agp_alloc_page)(struct agp_bridge_data *);
119119
int (*agp_alloc_pages)(struct agp_bridge_data *, struct agp_memory *, size_t);
120-
void (*agp_destroy_page)(void *, int flags);
120+
void (*agp_destroy_page)(struct page *, int flags);
121121
void (*agp_destroy_pages)(struct agp_memory *);
122122
int (*agp_type_to_mask_type) (struct agp_bridge_data *, int);
123123
void (*chipset_flush)(struct agp_bridge_data *);
@@ -278,10 +278,10 @@ int agp_generic_insert_memory(struct agp_memory *mem, off_t pg_start, int type);
278278
int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type);
279279
struct agp_memory *agp_generic_alloc_by_type(size_t page_count, int type);
280280
void agp_generic_free_by_type(struct agp_memory *curr);
281-
void *agp_generic_alloc_page(struct agp_bridge_data *bridge);
281+
struct page *agp_generic_alloc_page(struct agp_bridge_data *bridge);
282282
int agp_generic_alloc_pages(struct agp_bridge_data *agp_bridge,
283283
struct agp_memory *memory, size_t page_count);
284-
void agp_generic_destroy_page(void *addr, int flags);
284+
void agp_generic_destroy_page(struct page *page, int flags);
285285
void agp_generic_destroy_pages(struct agp_memory *memory);
286286
void agp_free_key(int key);
287287
int agp_num_entries(void);
@@ -291,7 +291,7 @@ int agp_3_5_enable(struct agp_bridge_data *bridge);
291291
void global_cache_flush(void);
292292
void get_agp_version(struct agp_bridge_data *bridge);
293293
unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge,
294-
unsigned long addr, int type);
294+
struct page *page, int type);
295295
int agp_generic_type_to_mask_type(struct agp_bridge_data *bridge,
296296
int type);
297297
struct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev);

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,37 +141,37 @@ static void m1541_cache_flush(void)
141141
}
142142
}
143143

144-
static void *m1541_alloc_page(struct agp_bridge_data *bridge)
144+
static struct page *m1541_alloc_page(struct agp_bridge_data *bridge)
145145
{
146-
void *addr = agp_generic_alloc_page(agp_bridge);
146+
struct page *page = agp_generic_alloc_page(agp_bridge);
147147
u32 temp;
148148

149-
if (!addr)
149+
if (!page)
150150
return NULL;
151151

152152
pci_read_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, &temp);
153153
pci_write_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL,
154154
(((temp & ALI_CACHE_FLUSH_ADDR_MASK) |
155-
virt_to_gart(addr)) | ALI_CACHE_FLUSH_EN ));
156-
return addr;
155+
phys_to_gart(page_to_phys(page))) | ALI_CACHE_FLUSH_EN ));
156+
return page;
157157
}
158158

159-
static void ali_destroy_page(void * addr, int flags)
159+
static void ali_destroy_page(struct page *page, int flags)
160160
{
161-
if (addr) {
161+
if (page) {
162162
if (flags & AGP_PAGE_DESTROY_UNMAP) {
163163
global_cache_flush(); /* is this really needed? --hch */
164-
agp_generic_destroy_page(addr, flags);
164+
agp_generic_destroy_page(page, flags);
165165
} else
166-
agp_generic_destroy_page(addr, flags);
166+
agp_generic_destroy_page(page, flags);
167167
}
168168
}
169169

170-
static void m1541_destroy_page(void * addr, int flags)
170+
static void m1541_destroy_page(struct page *page, int flags)
171171
{
172172
u32 temp;
173173

174-
if (addr == NULL)
174+
if (page == NULL)
175175
return;
176176

177177
if (flags & AGP_PAGE_DESTROY_UNMAP) {
@@ -180,9 +180,9 @@ static void m1541_destroy_page(void * addr, int flags)
180180
pci_read_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, &temp);
181181
pci_write_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL,
182182
(((temp & ALI_CACHE_FLUSH_ADDR_MASK) |
183-
virt_to_gart(addr)) | ALI_CACHE_FLUSH_EN));
183+
phys_to_gart(page_to_phys(page))) | ALI_CACHE_FLUSH_EN));
184184
}
185-
agp_generic_destroy_page(addr, flags);
185+
agp_generic_destroy_page(page, flags);
186186
}
187187

188188

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ static int amd_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
325325
addr = (j * PAGE_SIZE) + agp_bridge->gart_bus_addr;
326326
cur_gatt = GET_GATT(addr);
327327
writel(agp_generic_mask_memory(agp_bridge,
328-
mem->memory[i], mem->type), cur_gatt+GET_GATT_OFF(addr));
328+
mem->pages[i], mem->type), cur_gatt+GET_GATT_OFF(addr));
329329
readl(cur_gatt+GET_GATT_OFF(addr)); /* PCI Posting. */
330330
}
331331
amd_irongate_tlbflush(mem);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static int amd64_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
7979

8080
for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
8181
tmp = agp_bridge->driver->mask_memory(agp_bridge,
82-
mem->memory[i], mask_type);
82+
mem->pages[i], mask_type);
8383

8484
BUG_ON(tmp & 0xffffff0000000ffcULL);
8585
pte = (tmp & 0x000000ff00000000ULL) >> 28;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,9 @@ static int ati_insert_memory(struct agp_memory * mem,
296296
for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
297297
addr = (j * PAGE_SIZE) + agp_bridge->gart_bus_addr;
298298
cur_gatt = GET_GATT(addr);
299-
writel(agp_bridge->driver->mask_memory(agp_bridge,
300-
mem->memory[i], mem->type), cur_gatt+GET_GATT_OFF(addr));
299+
writel(agp_bridge->driver->mask_memory(agp_bridge,
300+
mem->pages[i], mem->type),
301+
cur_gatt+GET_GATT_OFF(addr));
301302
readl(cur_gatt+GET_GATT_OFF(addr)); /* PCI Posting. */
302303
}
303304
agp_bridge->driver->tlb_flush(mem);

‎drivers/char/agp/backend.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,17 @@ static int agp_backend_initialize(struct agp_bridge_data *bridge)
141141
bridge->version = &agp_current_version;
142142

143143
if (bridge->driver->needs_scratch_page) {
144-
void *addr = bridge->driver->agp_alloc_page(bridge);
144+
struct page *page = bridge->driver->agp_alloc_page(bridge);
145145

146-
if (!addr) {
146+
if (!page) {
147147
dev_err(&bridge->dev->dev,
148148
"can't get memory for scratch page\n");
149149
return -ENOMEM;
150150
}
151151

152-
bridge->scratch_page_real = virt_to_gart(addr);
152+
bridge->scratch_page_real = phys_to_gart(page_to_phys(page));
153153
bridge->scratch_page =
154-
bridge->driver->mask_memory(bridge, bridge->scratch_page_real, 0);
154+
bridge->driver->mask_memory(bridge, page, 0);
155155
}
156156

157157
size_value = bridge->driver->fetch_size();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ static const struct gatt_mask efficeon_generic_masks[] =
6565
};
6666

6767
/* This function does the same thing as mask_memory() for this chipset... */
68-
static inline unsigned long efficeon_mask_memory(unsigned long addr)
68+
static inline unsigned long efficeon_mask_memory(struct page *page)
6969
{
70+
unsigned long addr = phys_to_gart(page_to_phys(page));
7071
return addr | 0x00000001;
7172
}
7273

@@ -257,7 +258,7 @@ static int efficeon_insert_memory(struct agp_memory * mem, off_t pg_start, int t
257258
last_page = NULL;
258259
for (i = 0; i < count; i++) {
259260
int index = pg_start + i;
260-
unsigned long insert = efficeon_mask_memory(mem->memory[i]);
261+
unsigned long insert = efficeon_mask_memory(mem->pages[i]);
261262

262263
page = (unsigned int *) efficeon_private.l1_table[index >> 10];
263264

‎drivers/char/agp/generic.c‎

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ EXPORT_SYMBOL(agp_flush_chipset);
9595

9696
void agp_alloc_page_array(size_t size, struct agp_memory *mem)
9797
{
98-
mem->memory = NULL;
98+
mem->pages = NULL;
9999
mem->vmalloc_flag = false;
100100

101101
if (size <= 2*PAGE_SIZE)
102-
mem->memory = kmalloc(size, GFP_KERNEL | __GFP_NORETRY);
103-
if (mem->memory == NULL) {
104-
mem->memory = vmalloc(size);
102+
mem->pages = kmalloc(size, GFP_KERNEL | __GFP_NORETRY);
103+
if (mem->pages == NULL) {
104+
mem->pages = vmalloc(size);
105105
mem->vmalloc_flag = true;
106106
}
107107
}
@@ -110,9 +110,9 @@ EXPORT_SYMBOL(agp_alloc_page_array);
110110
void agp_free_page_array(struct agp_memory *mem)
111111
{
112112
if (mem->vmalloc_flag) {
113-
vfree(mem->memory);
113+
vfree(mem->pages);
114114
} else {
115-
kfree(mem->memory);
115+
kfree(mem->pages);
116116
}
117117
}
118118
EXPORT_SYMBOL(agp_free_page_array);
@@ -136,7 +136,7 @@ static struct agp_memory *agp_create_user_memory(unsigned long num_agp_pages)
136136

137137
agp_alloc_page_array(alloc_size, new);
138138

139-
if (new->memory == NULL) {
139+
if (new->pages == NULL) {
140140
agp_free_key(new->key);
141141
kfree(new);
142142
return NULL;
@@ -162,7 +162,7 @@ struct agp_memory *agp_create_memory(int scratch_pages)
162162

163163
agp_alloc_page_array(PAGE_SIZE * scratch_pages, new);
164164

165-
if (new->memory == NULL) {
165+
if (new->pages == NULL) {
166166
agp_free_key(new->key);
167167
kfree(new);
168168
return NULL;
@@ -206,15 +206,13 @@ void agp_free_memory(struct agp_memory *curr)
206206
} else {
207207

208208
for (i = 0; i < curr->page_count; i++) {
209-
curr->memory[i] = (unsigned long)gart_to_virt(
210-
curr->memory[i]);
211209
curr->bridge->driver->agp_destroy_page(
212-
(void *)curr->memory[i],
210+
curr->pages[i],
213211
AGP_PAGE_DESTROY_UNMAP);
214212
}
215213
for (i = 0; i < curr->page_count; i++) {
216214
curr->bridge->driver->agp_destroy_page(
217-
(void *)curr->memory[i],
215+
curr->pages[i],
218216
AGP_PAGE_DESTROY_FREE);
219217
}
220218
}
@@ -282,13 +280,13 @@ struct agp_memory *agp_allocate_memory(struct agp_bridge_data *bridge,
282280
}
283281

284282
for (i = 0; i < page_count; i++) {
285-
void *addr = bridge->driver->agp_alloc_page(bridge);
283+
struct page *page = bridge->driver->agp_alloc_page(bridge);
286284

287-
if (addr == NULL) {
285+
if (page == NULL) {
288286
agp_free_memory(new);
289287
return NULL;
290288
}
291-
new->memory[i] = virt_to_gart(addr);
289+
new->pages[i] = page;
292290
new->page_count++;
293291
}
294292
new->bridge = bridge;
@@ -1134,7 +1132,7 @@ int agp_generic_insert_memory(struct agp_memory * mem, off_t pg_start, int type)
11341132
}
11351133

11361134
for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
1137-
writel(bridge->driver->mask_memory(bridge, mem->memory[i], mask_type),
1135+
writel(bridge->driver->mask_memory(bridge, mem->pages[i], mask_type),
11381136
bridge->gatt_table+j);
11391137
}
11401138
readl(bridge->gatt_table+j-1); /* PCI Posting. */
@@ -1204,7 +1202,7 @@ struct agp_memory *agp_generic_alloc_user(size_t page_count, int type)
12041202
return NULL;
12051203

12061204
for (i = 0; i < page_count; i++)
1207-
new->memory[i] = 0;
1205+
new->pages[i] = 0;
12081206
new->page_count = 0;
12091207
new->type = type;
12101208
new->num_scratch_pages = pages;
@@ -1237,23 +1235,20 @@ int agp_generic_alloc_pages(struct agp_bridge_data *bridge, struct agp_memory *m
12371235
get_page(page);
12381236
atomic_inc(&agp_bridge->current_memory_agp);
12391237

1240-
/* set_memory_array_uc() needs virtual address */
1241-
mem->memory[i] = (unsigned long)page_address(page);
1238+
mem->pages[i] = page;
12421239
mem->page_count++;
12431240
}
12441241

12451242
#ifdef CONFIG_X86
1246-
set_memory_array_uc(mem->memory, num_pages);
1243+
set_pages_array_uc(mem->pages, num_pages);
12471244
#endif
12481245
ret = 0;
12491246
out:
1250-
for (i = 0; i < mem->page_count; i++)
1251-
mem->memory[i] = virt_to_gart((void *)mem->memory[i]);
12521247
return ret;
12531248
}
12541249
EXPORT_SYMBOL(agp_generic_alloc_pages);
12551250

1256-
void *agp_generic_alloc_page(struct agp_bridge_data *bridge)
1251+
struct page *agp_generic_alloc_page(struct agp_bridge_data *bridge)
12571252
{
12581253
struct page * page;
12591254

@@ -1265,56 +1260,47 @@ void *agp_generic_alloc_page(struct agp_bridge_data *bridge)
12651260

12661261
get_page(page);
12671262
atomic_inc(&agp_bridge->current_memory_agp);
1268-
return page_address(page);
1263+
return page;
12691264
}
12701265
EXPORT_SYMBOL(agp_generic_alloc_page);
12711266

12721267
void agp_generic_destroy_pages(struct agp_memory *mem)
12731268
{
12741269
int i;
1275-
void *addr;
12761270
struct page *page;
12771271

12781272
if (!mem)
12791273
return;
12801274

1281-
for (i = 0; i < mem->page_count; i++)
1282-
mem->memory[i] = (unsigned long)gart_to_virt(mem->memory[i]);
1283-
12841275
#ifdef CONFIG_X86
1285-
set_memory_array_wb(mem->memory, mem->page_count);
1276+
set_pages_array_wb(mem->pages, mem->page_count);
12861277
#endif
12871278

12881279
for (i = 0; i < mem->page_count; i++) {
1289-
addr = (void *)mem->memory[i];
1290-
page = virt_to_page(addr);
1280+
page = mem->pages[i];
12911281

12921282
#ifndef CONFIG_X86
12931283
unmap_page_from_agp(page);
12941284
#endif
1295-
12961285
put_page(page);
1297-
free_page((unsigned long)addr);
1286+
__free_page(page);
12981287
atomic_dec(&agp_bridge->current_memory_agp);
1299-
mem->memory[i] = 0;
1288+
mem->pages[i] = NULL;
13001289
}
13011290
}
13021291
EXPORT_SYMBOL(agp_generic_destroy_pages);
13031292

1304-
void agp_generic_destroy_page(void *addr, int flags)
1293+
void agp_generic_destroy_page(struct page *page, int flags)
13051294
{
1306-
struct page *page;
1307-
1308-
if (addr == NULL)
1295+
if (page == NULL)
13091296
return;
13101297

1311-
page = virt_to_page(addr);
13121298
if (flags & AGP_PAGE_DESTROY_UNMAP)
13131299
unmap_page_from_agp(page);
13141300

13151301
if (flags & AGP_PAGE_DESTROY_FREE) {
13161302
put_page(page);
1317-
free_page((unsigned long)addr);
1303+
__free_page(page);
13181304
atomic_dec(&agp_bridge->current_memory_agp);
13191305
}
13201306
}
@@ -1361,8 +1347,9 @@ void global_cache_flush(void)
13611347
EXPORT_SYMBOL(global_cache_flush);
13621348

13631349
unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge,
1364-
unsigned long addr, int type)
1350+
struct page *page, int type)
13651351
{
1352+
unsigned long addr = phys_to_gart(page_to_phys(page));
13661353
/* memory type is ignored in the generic routine */
13671354
if (bridge->driver->masks)
13681355
return addr | bridge->driver->masks[0].mask;

0 commit comments

Comments
 (0)