Re: [intel-agp] Rewrite GTT on resume

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Keith Packard
Date: Friday, June 6, 2008 - 2:17 pm

On Fri, 2008-06-06 at 13:50 -0700, Andrew Morton wrote:


See below.


I don't know. There is a mutex in the agp frontend exposed to user mode,
but that is not used by the internal kernel interfaces used by drm. This
scares me a bit, but the agp code doesn't appear to have any kind of
internal data structures that might be messed up, so it 'should' be OK.

This version adds a spinlock around all of the mapped_list manipulation.

=46rom 26b58f13ecbe95a7eaca7434aeb885def057b835 Mon Sep 17 00:00:00 2001
From: Keith Packard <keithp@keithp.com>
Date: Tue, 3 Jun 2008 20:34:54 -0700
Subject: [PATCH] [INTEL-AGP] Re-write GATT on resume

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. The list is protected by a spinlock.

Signed-off-by: Keith Packard <keithp@keithp.com>

diff --git a/drivers/char/agp/agp.h b/drivers/char/agp/agp.h
index c69f795..5fdbbd7 100644
--- a/drivers/char/agp/agp.h
+++ b/drivers/char/agp/agp.h
@@ -148,6 +148,9 @@ struct agp_bridge_data {
 	char minor_version;
 	struct list_head list;
 	u32 apbase_config;
+	/* list of agp_memory mapped to the aperture */
+	struct list_head mapped_list;
+	spinlock_t mapped_lock;
 };
=20
 #define KB(x)	((x) * 1024)
diff --git a/drivers/char/agp/backend.c b/drivers/char/agp/backend.c
index b1bdd01..463f04b 100644
--- a/drivers/char/agp/backend.c
+++ b/drivers/char/agp/backend.c
@@ -183,6 +183,8 @@ static int agp_backend_initialize(struct agp_bridge_dat=
a *bridge)
 		rc =3D -EINVAL;
 		goto err_out;
 	}
+	INIT_LIST_HEAD(&bridge->mapped_list);
+	spin_lock_init(&bridge->mapped_lock);
=20
 	return 0;
=20
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index 7fc0c99..4741438 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -426,6 +426,10 @@ int agp_bind_memory(struct agp_memory *curr, off_t pg_=
start)
=20
 	curr->is_bound =3D TRUE;
 	curr->pg_start =3D pg_start;
+	spin_lock(&agp_bridge->mapped_lock);
+	list_add (&curr->mapped_list, &agp_bridge->mapped_list);
+	spin_unlock(&agp_bridge->mapped_lock);
+=09
 	return 0;
 }
 EXPORT_SYMBOL(agp_bind_memory);
@@ -458,10 +462,34 @@ int agp_unbind_memory(struct agp_memory *curr)
=20
 	curr->is_bound =3D FALSE;
 	curr->pg_start =3D 0;
+	spin_lock(&curr->bridge->mapped_lock);
+	list_del (&curr->mapped_list);
+	spin_unlock(&curr->bridge->mapped_lock);
 	return 0;
 }
 EXPORT_SYMBOL(agp_unbind_memory);
=20
+/**
+ *	agp_rebind_emmory  -  Rewrite the entire GATT, useful on resume
+ */
+int agp_rebind_memory (void)
+{
+	struct agp_memory *curr;
+	int ret_val;
+=09
+	spin_lock(&agp_bridge->mapped_lock);
+	list_for_each_entry(curr, &agp_bridge->mapped_list, mapped_list) {
+		ret_val =3D curr->bridge->driver->insert_memory(curr,
+							      curr->pg_start,
+							      curr->type);
+		if (ret_val !=3D 0)
+			return ret_val;
+	}
+	spin_unlock(&agp_bridge->mapped_lock);
+	return 0;
+}
+EXPORT_SYMBOL(agp_rebind_memory);
+
 /* End - Routines for handling swapping of agp_memory into the GATT */
=20
=20
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index eeea50a..7f1a96e 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -2176,6 +2176,7 @@ static void __devexit agp_intel_remove(struct pci_dev=
 *pdev)
 static int agp_intel_resume(struct pci_dev *pdev)
 {
 	struct agp_bridge_data *bridge =3D pci_get_drvdata(pdev);
+	int ret_val;
=20
 	pci_restore_state(pdev);
=20
@@ -2203,6 +2204,10 @@ static int agp_intel_resume(struct pci_dev *pdev)
 	else if (bridge->driver =3D=3D &intel_i965_driver)
 		intel_i915_configure();
=20
+	ret_val =3D agp_rebind_memory();
+	if (ret_val !=3D 0)
+		return ret_val;
+
 	return 0;
 }
 #endif
diff --git a/include/linux/agp_backend.h b/include/linux/agp_backend.h
index 03e3454..2fbfe4d 100644
--- a/include/linux/agp_backend.h
+++ b/include/linux/agp_backend.h
@@ -32,6 +32,8 @@
=20
 #ifdef __KERNEL__
=20
+#include <linux/list.h>
+
 #ifndef TRUE
 #define TRUE 1
 #endif
@@ -88,6 +90,8 @@ struct agp_memory {
 	u8 is_bound;
 	u8 is_flushed;
         u8 vmalloc_flag;
+	/* list of agp_memory mapped to the aperture */
+	struct list_head mapped_list;
 };
=20
 #define AGP_NORMAL_MEMORY 0
@@ -106,6 +110,7 @@ extern struct agp_memory *agp_allocate_memory(struct ag=
p_bridge_data *, size_t,
 extern int agp_copy_info(struct agp_bridge_data *, struct agp_kern_info *)=
;
 extern int agp_bind_memory(struct agp_memory *, off_t);
 extern int agp_unbind_memory(struct agp_memory *);
+extern int agp_rebind_memory (void);
 extern void agp_enable(struct agp_bridge_data *, u32);
 extern struct agp_bridge_data *agp_backend_acquire(struct pci_dev *);
 extern void agp_backend_release(struct agp_bridge_data *);

--=20
keith.packard@intel.com
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[intel-agp] Rewrite GTT on resume, Keith Packard, (Tue Jun 3, 8:41 pm)
Re: [intel-agp] Rewrite GTT on resume, Andrew Morton, (Fri Jun 6, 1:50 pm)
Re: [intel-agp] Rewrite GTT on resume, Keith Packard, (Fri Jun 6, 2:17 pm)
Re: [intel-agp] Rewrite GTT on resume, Pavel Machek, (Sun Jun 8, 12:13 am)
Re: [intel-agp] Rewrite GTT on resume, Keith Packard, (Sun Jun 8, 8:02 pm)