Skip to content

Commit a8c84df

Browse files
keith-packardairlied
authored andcommitted
intel/agp: rewrite GTT on resume
On my Intel chipset (965GM), the GTT is entirely erased across suspend/resume. This patch simply re-plays the current mapping at resume time to restore the table.=20 I noticed this once I started relying on persistent GTT mappings across VT switch in our GEM work -- the old X server and DRM code carefully unbind all memory from the GTT on VT switch, but GEM does not bother. I placed the list management and rewrite code in the generic layer on the assumption that it will be needed on other hardware, but I did not add the rewrite call to anything other than the Intel resume function. Keep a list of current GATT mappings. At resume time, rewrite them into the GATT. This is needed on Intel (at least) as the entire GATT is cleared across suspend/resume. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Keith Packard <keithp@keithp.com> Cc: Dave Jones <davej@codemonkey.org.uk> Cc: Andi Kleen <andi@firstfloor.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent e3cf695 commit a8c84df

5 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎drivers/char/agp/agp.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ struct agp_bridge_data {
148148
char minor_version;
149149
struct list_head list;
150150
u32 apbase_config;
151+
/* list of agp_memory mapped to the aperture */
152+
struct list_head mapped_list;
153+
spinlock_t mapped_lock;
151154
};
152155

153156
#define KB(x) ((x) * 1024)

‎drivers/char/agp/backend.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ static int agp_backend_initialize(struct agp_bridge_data *bridge)
185185
rc = -EINVAL;
186186
goto err_out;
187187
}
188+
INIT_LIST_HEAD(&bridge->mapped_list);
189+
spin_lock_init(&bridge->mapped_lock);
188190

189191
return 0;
190192

‎drivers/char/agp/generic.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ int agp_bind_memory(struct agp_memory *curr, off_t pg_start)
429429

430430
curr->is_bound = true;
431431
curr->pg_start = pg_start;
432+
spin_lock(&agp_bridge->mapped_lock);
433+
list_add(&curr->mapped_list, &agp_bridge->mapped_list);
434+
spin_unlock(&agp_bridge->mapped_lock);
435+
432436
return 0;
433437
}
434438
EXPORT_SYMBOL(agp_bind_memory);
@@ -461,10 +465,34 @@ int agp_unbind_memory(struct agp_memory *curr)
461465

462466
curr->is_bound = false;
463467
curr->pg_start = 0;
468+
spin_lock(&curr->bridge->mapped_lock);
469+
list_del(&curr->mapped_list);
470+
spin_unlock(&curr->bridge->mapped_lock);
464471
return 0;
465472
}
466473
EXPORT_SYMBOL(agp_unbind_memory);
467474

475+
/**
476+
* agp_rebind_emmory - Rewrite the entire GATT, useful on resume
477+
*/
478+
int agp_rebind_memory(void)
479+
{
480+
struct agp_memory *curr;
481+
int ret_val = 0;
482+
483+
spin_lock(&agp_bridge->mapped_lock);
484+
list_for_each_entry(curr, &agp_bridge->mapped_list, mapped_list) {
485+
ret_val = curr->bridge->driver->insert_memory(curr,
486+
curr->pg_start,
487+
curr->type);
488+
if (ret_val != 0)
489+
break;
490+
}
491+
spin_unlock(&agp_bridge->mapped_lock);
492+
return ret_val;
493+
}
494+
EXPORT_SYMBOL(agp_rebind_memory);
495+
468496
/* End - Routines for handling swapping of agp_memory into the GATT */
469497

470498

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,6 +2244,7 @@ static void __devexit agp_intel_remove(struct pci_dev *pdev)
22442244
static int agp_intel_resume(struct pci_dev *pdev)
22452245
{
22462246
struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
2247+
int ret_val;
22472248

22482249
pci_restore_state(pdev);
22492250

@@ -2271,6 +2272,10 @@ static int agp_intel_resume(struct pci_dev *pdev)
22712272
else if (bridge->driver == &intel_i965_driver)
22722273
intel_i915_configure();
22732274

2275+
ret_val = agp_rebind_memory();
2276+
if (ret_val != 0)
2277+
return ret_val;
2278+
22742279
return 0;
22752280
}
22762281
#endif

‎include/linux/agp_backend.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#ifndef _AGP_BACKEND_H
3131
#define _AGP_BACKEND_H 1
3232

33+
#include <linux/list.h>
34+
3335
enum chipset_type {
3436
NOT_SUPPORTED,
3537
SUPPORTED,
@@ -78,6 +80,8 @@ struct agp_memory {
7880
bool is_bound;
7981
bool is_flushed;
8082
bool vmalloc_flag;
83+
/* list of agp_memory mapped to the aperture */
84+
struct list_head mapped_list;
8185
};
8286

8387
#define AGP_NORMAL_MEMORY 0
@@ -96,6 +100,7 @@ extern struct agp_memory *agp_allocate_memory(struct agp_bridge_data *, size_t,
96100
extern int agp_copy_info(struct agp_bridge_data *, struct agp_kern_info *);
97101
extern int agp_bind_memory(struct agp_memory *, off_t);
98102
extern int agp_unbind_memory(struct agp_memory *);
103+
extern int agp_rebind_memory(void);
99104
extern void agp_enable(struct agp_bridge_data *, u32);
100105
extern struct agp_bridge_data *agp_backend_acquire(struct pci_dev *);
101106
extern void agp_backend_release(struct agp_bridge_data *);

0 commit comments

Comments
 (0)