Skip to contentSkip to conversation

agpgart - allow user-populated memory types.

PATCH In review Thomas Hellström 2 participants 18 messages Dec 8, 2006 – Jan 23, 2007 Agpgart driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 agpgart - allow user-populated memory types.

This patch allows drm to populate an agpgart structure with pages of its own. It's needed for the new drm memory manager which dynamically flips pages in and out of AGP.

The patch modifies the generic functions as well as the intel agp driver. The intel drm driver is currently the only one supporting the new memory manager.

Other agp drivers may need some minor fixing up once they have a corresponding memory manager enabled drm driver.

AGP memory types >= AGP_USER_TYPES are not populated by the agpgart driver, but the drm is expected to do that, as well as taking care of cache- and tlb flushing when needed.

It's not possible to request these types from user space using agpgart ioctls.

The intel driver also gets a new memory type for pages that can be bound cached to the intel GTT.

Patch against davej's agpgart.git

/Thomas Hellström

drivers/char/agp/agp.h +8 -0
index 8b3317f..8abbbda 100644
@@ -114,6 +114,7 @@ struct agp_bridge_driver {
 	void (*free_by_type)(struct agp_memory *);
 	void *(*agp_alloc_page)(struct agp_bridge_data *);
 	void (*agp_destroy_page)(void *);
+        int (*agp_type_to_mask_type) (struct agp_bridge_data *, int);
 };
 
 struct agp_bridge_data {
@@ -218,6 +219,7 @@ #define I810_PTE_BASE		0x10000
 #define I810_PTE_MAIN_UNCACHED	0x00000000
 #define I810_PTE_LOCAL		0x00000002
 #define I810_PTE_VALID		0x00000001
+#define I830_PTE_SYSTEM_CACHED  0x00000006
 #define I810_SMRAM_MISCC	0x70
 #define I810_GFX_MEM_WIN_SIZE	0x00010000
 #define I810_GFX_MEM_WIN_32M	0x00010000
@@ -266,8 +268,14 @@ void global_cache_flush(void);
 void get_agp_version(struct agp_bridge_data *bridge);
 unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge,
 	unsigned long addr, int type);
+int agp_generic_type_to_mask_type(struct agp_bridge_data *bridge,
+				  int type);
 struct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev);
 
+/* generic functions for user-populated AGP memory types */
+struct agp_memory *agp_generic_alloc_user(size_t page_count, int type);
+void agp_generic_free_user(struct agp_memory *curr);
+
 /* generic routines for agp>=3 */
 int agp3_generic_fetch_size(void);
 void agp3_generic_tlbflush(struct agp_memory *mem);
drivers/char/agp/ali-agp.c +2 -0
index 5a31ec7..98177a9 100644
@@ -214,6 +214,7 @@ static struct agp_bridge_driver ali_gene
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= ali_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static struct agp_bridge_driver ali_m1541_bridge = {
@@ -237,6 +238,7 @@ static struct agp_bridge_driver ali_m154
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= m1541_alloc_page,
 	.agp_destroy_page	= m1541_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 
drivers/char/agp/alpha-agp.c +4 -0
index b4e00a3..b0acf41 100644
@@ -91,6 +91,9 @@ static int alpha_core_agp_insert_memory(
 	int num_entries, status;
 	void *temp;
 
+	if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES)
+		return -EINVAL;
+
 	temp = agp_bridge->current_size;
 	num_entries = A_SIZE_FIX(temp)->num_entries;
 	if ((pg_start + mem->page_count) > num_entries)
@@ -142,6 +145,7 @@ struct agp_bridge_driver alpha_core_agp_
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 struct agp_bridge_data *alpha_bridge;
drivers/char/agp/amd-k7-agp.c +1 -0
index 51d0d56..9c129bd 100644
@@ -376,6 +376,7 @@ static struct agp_bridge_driver amd_iron
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static struct agp_device_ids amd_agp_device_ids[] __devinitdata =
drivers/char/agp/amd64-agp.c +9 -2
index 00b17ae..ac24340 100644
@@ -62,12 +62,18 @@ static int amd64_insert_memory(struct ag
 {
 	int i, j, num_entries;
 	long long tmp;
+	int mask_type;
+	struct agp_bridge_data *bridge = mem->bridge;
 	u32 pte;
 
 	num_entries = agp_num_entries();
 
-	if (type != 0 || mem->type != 0)
+	if (type != mem->type)
 		return -EINVAL;
+	mask_type = bridge->driver->agp_type_to_mask_type(bridge, type);
+	if (mask_type != 0)
+		return -EINVAL;
+	
 
 	/* Make sure we can fit the range in the gatt table. */
 	/* FIXME: could wrap */
@@ -90,7 +96,7 @@ static int amd64_insert_memory(struct ag
 
 	for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
 		tmp = agp_bridge->driver->mask_memory(agp_bridge,
-			mem->memory[i], mem->type);
+			mem->memory[i], mask_type);
 
 		BUG_ON(tmp & 0xffffff0000000ffcULL);
 		pte = (tmp & 0x000000ff00000000ULL) >> 28;
@@ -247,6 +253,7 @@ static struct agp_bridge_driver amd_8151
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 /* Some basic sanity checks for the aperture. */
drivers/char/agp/ati-agp.c +1 -0
index f244c66..d4f7b75 100644
@@ -431,6 +431,7 @@ static struct agp_bridge_driver ati_gene
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 
drivers/char/agp/efficeon-agp.c +1 -0
index 30f730f..658cb1a 100644
@@ -335,6 +335,7 @@ static struct agp_bridge_driver efficeon
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static int __devinit agp_efficeon_probe(struct pci_dev *pdev,
drivers/char/agp/frontend.c +3 -0
index 0f2ed2a..e21a319 100644
@@ -892,6 +892,9 @@ static int agpioc_allocate_wrap(struct a
 	if (copy_from_user(&alloc, arg, sizeof(struct agp_allocate)))
 		return -EFAULT;
 
+	if (alloc.type >= AGP_USER_TYPES)
+		return -EINVAL;
+
 	memory = agp_allocate_memory_wrap(alloc.pg_count, alloc.type);
 
 	if (memory == NULL)
drivers/char/agp/generic.c +117 -3

185 lines not on this page · raw message

drivers/char/agp/hp-agp.c +1 -0
index 907fb66..847deab 100644
@@ -438,6 +438,7 @@ struct agp_bridge_driver hp_zx1_driver =
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 	.cant_use_aperture	= 1,
 };
 
drivers/char/agp/i460-agp.c +7 -0
index 9176944..3e76186 100644
@@ -293,6 +293,9 @@ static int i460_insert_memory_small_io_p
 	pr_debug("i460_insert_memory_small_io_page(mem=%p, pg_start=%ld, type=%d, paddr0=0x%lx)\n",
 		 mem, pg_start, type, mem->memory[0]);
 
+	if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES)
+		return -EINVAL;
+
 	io_pg_start = I460_IOPAGES_PER_KPAGE * pg_start;
 
 	temp = agp_bridge->current_size;
@@ -396,6 +399,9 @@ static int i460_insert_memory_large_io_p
 	struct lp_desc *start, *end, *lp;
 	void *temp;
 
+	if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES)
+		return -EINVAL;
+
 	temp = agp_bridge->current_size;
 	num_entries = A_SIZE_8(temp)->num_entries;
 
@@ -572,6 +578,7 @@ #else
 #endif
 	.alloc_by_type		= agp_generic_alloc_by_type,
 	.free_by_type		= agp_generic_free_by_type,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 	.cant_use_aperture	= 1,
 };
 
drivers/char/agp/intel-agp.c +133 -55

399 lines not on this page · raw message

drivers/char/agp/nvidia-agp.c +1 -0
index df7f37b..2563286 100644
@@ -310,6 +310,7 @@ static struct agp_bridge_driver nvidia_d
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static int __devinit agp_nvidia_probe(struct pci_dev *pdev,
drivers/char/agp/sgi-agp.c +1 -0
index d73be4c..e191d2b 100644
@@ -265,6 +265,7 @@ struct agp_bridge_driver sgi_tioca_drive
 	.free_by_type = agp_generic_free_by_type,
 	.agp_alloc_page = sgi_tioca_alloc_page,
 	.agp_destroy_page = agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 	.cant_use_aperture = 1,
 	.needs_scratch_page = 0,
 	.num_aperture_sizes = 1,
drivers/char/agp/sworks-agp.c +1 -0
index 4f2d7d9..9f5ae77 100644
@@ -444,6 +444,7 @@ static struct agp_bridge_driver sworks_d
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static int __devinit agp_serverworks_probe(struct pci_dev *pdev,
drivers/char/agp/uninorth-agp.c +2 -0
index dffc193..6c45702 100644
@@ -510,6 +510,7 @@ struct agp_bridge_driver uninorth_agp_dr
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 	.cant_use_aperture	= 1,
 };
 
@@ -534,6 +535,7 @@ struct agp_bridge_driver u3_agp_driver =
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 	.cant_use_aperture	= 1,
 	.needs_scratch_page	= 1,
 };
drivers/char/agp/via-agp.c +2 -0
index c149ac9..143d3fa 100644
@@ -191,6 +191,7 @@ static struct agp_bridge_driver via_agp3
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static struct agp_bridge_driver via_driver = {
@@ -214,6 +215,7 @@ static struct agp_bridge_driver via_driv
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static struct agp_device_ids via_agp_device_ids[] __devinitdata =
include/linux/agp_backend.h +4 -0
index a5c8bb5..89868be 100644
@@ -91,6 +91,10 @@ struct agp_memory {
 
 #define AGP_NORMAL_MEMORY 0
 
+#define AGP_USER_TYPES (1 << 16)
+#define AGP_USER_MEMORY (AGP_USER_TYPES)
+#define AGP_USER_CACHED_MEMORY (AGP_USER_TYPES + 1)
+
 extern struct agp_bridge_data *agp_bridge;
 extern struct list_head agp_bridges;
 
#1 lore raw

drivers/char/agp/generic.c void agp_generic_free_by_type(struct agp · line 1171

Quoted 11 lines · Thomas Hellström
drivers/char/agp/generic.c +10 -0
+void agp_generic_free_user(struct agp_memory *curr)
+{
+       if ((unsigned long) curr->memory >= VMALLOC_START 
+           && (unsigned long) curr->memory < VMALLOC_END) {
+               vfree(curr->memory);
+       } else {
+               kfree(curr->memory);
+       }
+       agp_free_key(curr->key);
+       kfree(curr);

why? this really is almost too ugly to live ;(

Quoted 3 lines
drivers/char/agp/generic.c +3 -0
+}
+EXPORT_SYMBOL(agp_generic_free_user);
+ 
Signature · 2 lines
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
Test the interaction between Linux and your BIOS via http://www.linuxfirmwarekit.org
#2 lore raw
In reply to Thomas Hellström

drivers/char/agp/generic.c static int agp_get_key(void) · line 132

Quoted 8 lines · Thomas Hellström
drivers/char/agp/generic.c +7 -0
+       }
+
+       if (alloc_size <= PAGE_SIZE) {
+               new->memory = kmalloc(alloc_size, GFP_KERNEL);
+       }
+       if (new->memory == NULL) {
+               new->memory = vmalloc(alloc_size); 

this bit is more or less evil as well...

1) vmalloc is expensive all the way, higher tlb use etc etc
2) mixing allocation types is just a recipe for disaster
3) if this isn't a frequent operation, kmalloc is fine upto at least 2 pages; I doubt you'll ever want more

Signature · 2 lines
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
Test the interaction between Linux and your BIOS via http://www.linuxfirmwarekit.org
#3 lore raw
Quoted 10 lines · Thomas Hellström

drivers/char/agp/generic.c static int agp_get_key(void) · line 132

Quoted 8 lines
drivers/char/agp/generic.c +7 -0
+       }
+
+       if (alloc_size <= PAGE_SIZE) {
+               new->memory = kmalloc(alloc_size, GFP_KERNEL);
+       }
+       if (new->memory == NULL) {
+               new->memory = vmalloc(alloc_size);
Quoted 6 lines

this bit is more or less evil as well...

1) vmalloc is expensive all the way, higher tlb use etc etc
2) mixing allocation types is just a recipe for disaster
3) if this isn't a frequent operation, kmalloc is fine upto at least 2 pages; I doubt you'll ever want more

I understand your feelings about this, and as you probably understand, the kfree / vfree thingy is a result of the above allocation scheme.

The allocated memory holds an array of struct page pointers. The number of struct page pointers will range from 1 to about 8192, so the alloc size will range from 4bytes to 64K, but could go higher depending on architecture. I figured that kmalloc could fail, and, according to "linux device drivers" (IIRC), vmalloc is faster when allocation size exceeds 1 page. Using only vmalloc waists far too much memory if the number of small buffers is high.

So we can't use only vmalloc, and we can't fail so we can't use only kmalloc. I'm open to suggestions on how to improve this.

Regards,
Thomas

Quoted 9 lines

--
if you want to mail me at work (you don't), use arjan (at) linux.intel.com Test the interaction between Linux and your BIOS via
http://www.linuxfirmwarekit.org

#4 lore raw
Quoted 12 lines · Thomas Hellström
Quoted 12 lines · Thomas Hellström

drivers/char/agp/generic.c static int agp_get_key(void) · line 132

Quoted 8 lines
drivers/char/agp/generic.c +7 -0
+       }
+
+       if (alloc_size <= PAGE_SIZE) {
+               new->memory = kmalloc(alloc_size, GFP_KERNEL);
+       }
+       if (new->memory == NULL) {
+               new->memory = vmalloc(alloc_size);

this bit is more or less evil as well...

Quoted 7 lines
Quoted 4 lines

1) vmalloc is expensive all the way, higher tlb use etc etc
2) mixing allocation types is just a recipe for disaster
3) if this isn't a frequent operation, kmalloc is fine upto at least 2 pages; I doubt you'll ever want more

I understand your feelings about this, and as you probably understand, the kfree / vfree thingy is a result of the above allocation scheme.

the kfree/vfree thing at MINIMUM should be changed though. Even if you need both kfree and vfree, you should key it off of a flag that you store, not off the address of the memory, that's just unportable and highly fragile. You *know* which allocator you used, so store it and use THAT info.

Quoted 4 lines

The allocated memory holds an array of struct page pointers. The number of struct page pointers will range from 1 to about 8192, so the alloc size will range from 4bytes to 64K, but could go higher depending on architecture.

hmm 64Kb is a bit much indeed. You can't do an array of upto 16 entries with one page in each array entry?

Quoted 3 lines

I figured that kmalloc could fail, and, according to "linux
device drivers" (IIRC), vmalloc is faster when allocation size exceeds 1 page.

that is just plain incorrect. Vmalloc is really really slow, both in allocating and in use. During use you trash the 4Kb tlbs all the time for example, and that's just cost that accumulates.

Quoted 2 lines

So we can't use only vmalloc, and we can't fail so we can't use only kmalloc. I'm open to suggestions on how to improve this.

cleanest is probably the array of pages thing. to index it then you first calculate which entry to use (that's half a cycle since it's a power of 2) and then you index inside that page... that's going to be faster than the tlb miss no doubt.

Signature · 2 lines
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
Test the interaction between Linux and your BIOS via http://www.linuxfirmwarekit.org
#5 lore raw
Quoted 45 lines · Arjan van de Ven
Quoted 14 lines · Thomas Hellström
Quoted 14 lines · Thomas Hellström

drivers/char/agp/generic.c static int agp_get_key(void) · line 132

Quoted 11 lines
drivers/char/agp/generic.c +7 -0
+       }
+
+       if (alloc_size <= PAGE_SIZE) {
+               new->memory = kmalloc(alloc_size, GFP_KERNEL);
+       }
+       if (new->memory == NULL) {
+               new->memory = vmalloc(alloc_size);

this bit is more or less evil as well...

Quoted 10 lines
Quoted 6 lines

1) vmalloc is expensive all the way, higher tlb use etc etc
2) mixing allocation types is just a recipe for disaster
3) if this isn't a frequent operation, kmalloc is fine upto at least 2 pages; I doubt you'll ever want more

I understand your feelings about this, and as you probably understand, the kfree / vfree thingy is a result of the above allocation scheme.

the kfree/vfree thing at MINIMUM should be changed though. Even if you need both kfree and vfree, you should key it off of a flag that you store, not off the address of the memory, that's just unportable and highly fragile. You *know* which allocator you used, so store it and use THAT info.

Quoted 6 lines

The allocated memory holds an array of struct page pointers. The number of struct page pointers will range from 1 to about 8192, so the alloc size will range from 4bytes to 64K, but could go higher depending on architecture.

Quoted 5 lines

hmm 64Kb is a bit much indeed. You can't do an array of upto 16 entries with one page in each array entry?

Arjan,
Thanks for taking time to review this.

A short background:
The current code uses vmalloc only. The potential use of kmalloc was introduced
to save memory and cpu-speed.
All agp drivers expect to see a single memory chunk, so I'm not sure we want to have an array of pages. That may require rewriting a lot of code.

If it's acceptable I'd like to go for the vmalloc / kmalloc flag, or at worst keep the current vmalloc only but that's such a _huge_ memory waste for small buffers. The flag was the original idea, but unfortunately the agp_memory struct is part of the drm interface, and I wasn't sure we could add a variable to it.

DaveJ, is it possible to extend struct agp_memory with a flags field?

Regards,
Thomas

#6 lore raw
Quoted 7 lines

A short background:
The current code uses vmalloc only. The potential use of kmalloc was introduced
to save memory and cpu-speed.
All agp drivers expect to see a single memory chunk, so I'm not sure we want to have an array of pages. That may require rewriting a lot of code.

but if it's clearly the right thing.....
How hard can it be? there are what.. 5 or 6 AGP drivers in the kernel?

Quoted 5 lines

If it's acceptable I'd like to go for the vmalloc / kmalloc flag, or at worst keep the current vmalloc only but that's such a _huge_ memory waste for small buffers. The flag was the original idea, but unfortunately the agp_memory struct is part of the drm interface, and I wasn't sure we could add a variable to it.

I doubt this is part of the userspace interface so for sure we can change it to be right.

Signature · 2 lines
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
Test the interaction between Linux and your BIOS via http://www.linuxfirmwarekit.org
#7 lore raw
Quoted 7 lines · Arjan van de Ven
Quoted 6 lines

A short background:
The current code uses vmalloc only. The potential use of kmalloc was introduced
to save memory and cpu-speed.
All agp drivers expect to see a single memory chunk, so I'm not sure we want to have an array of pages. That may require rewriting a lot of code.

Quoted 6 lines

but if it's clearly the right thing.....
How hard can it be? there are what.. 5 or 6 AGP drivers in the kernel?

Hmm,
but we would still waste a lot of memory compared to kmalloc, when the amount of memory needed is much less than one page, which tends to be a very common case.

Unless we allow the first entry in the array to be the virtual adress to an arbitrary-sized (max one page) kmalloc() area, the rest of the entries can be pointers to pages allocated with __get_free_page().

This would almost introduce the same level of confusion as the original proposal, and effectively we'd be doing virtual address translation in software for each access.

Quoted 10 lines
Quoted 3 lines

If it's acceptable I'd like to go for the vmalloc / kmalloc flag, or at worst keep the current vmalloc only but that's such a _huge_ memory waste for small buffers. The flag was the original idea, but unfortunately the agp_memory struct is part of the drm interface, and I wasn't sure we could add a variable to it.

I doubt this is part of the userspace interface so for sure we can change it to be right.

/Thomas

#8 lore raw
Quoted 11 lines · Thomas Hellström
Quoted 9 lines · Arjan van de Ven
Quoted 8 lines

A short background:
The current code uses vmalloc only. The potential use of kmalloc was introduced
to save memory and cpu-speed.
All agp drivers expect to see a single memory chunk, so I'm not sure we want to have an array of pages. That may require rewriting a lot of code.

Quoted 8 lines
Quoted 6 lines

but if it's clearly the right thing.....
How hard can it be? there are what.. 5 or 6 AGP drivers in the kernel?

Hmm,
but we would still waste a lot of memory compared to kmalloc,

surely it's at most 4Kb for the entire system?

(if agp allows the non-root user to pin a lot more than that in kernel memory there is a different problem of rlimits ;)

Signature · 2 lines
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
Test the interaction between Linux and your BIOS via http://www.linuxfirmwarekit.org
#9 lore raw
Quoted 19 lines · Arjan van de Ven
Quoted 17 lines · Thomas Hellström
Quoted 14 lines · Arjan van de Ven
Quoted 7 lines

A short background:
The current code uses vmalloc only. The potential use of kmalloc was introduced
to save memory and cpu-speed.
All agp drivers expect to see a single memory chunk, so I'm not sure we want to have an array of pages. That may require rewriting a lot of code.

but if it's clearly the right thing.....
How hard can it be? there are what.. 5 or 6 AGP drivers in the kernel?

Quoted 7 lines
Quoted 3 lines

Hmm,
but we would still waste a lot of memory compared to kmalloc,

surely it's at most 4Kb for the entire system?

Nope. These structures get allocated once per display memory buffer, and a display memory buffer may be as large as
the AGP aperture size, (usually up to 512MB) or as small as one page.
The latter could be a user allocating a texture buffer for each character in a font, and they can be quite numerous, so we would waste almost 4Kb per buffer, which is not acceptable.

Quoted 4 lines

(if agp allows the non-root user to pin a lot more than that in kernel memory there is a different problem of rlimits ;)

The drm memory manager sets aside and keeps track of a preset amount of memory that can be pinned in the kernel for video use, which is shared by all users running direct rendering clients. Currently this is a hard limit, but the idea is to unlock memory and make it swappable if resources become scarce. The memory we're discussing above is included in the bookkeeping.

/Thomas

#10 lore raw

agpgart: drm-populated memory types

In reply to Arjan van de Ven

Dave and Arjan,

I'm resending a slightly reworked version of the apgart patch for drm-populated memory types.

The address- based vmalloc / vfree has been replaced and encapsulated in agp-vkmalloc / agp vkfree which both takes a flag argument to indicate whether to use vmalloc or kmalloc. This, at least, gets rid of the portability problem, and the chances of running into trouble in the future will be small if all allocs / frees of these memory areas are done using these functions.

A short recap why I belive the kmalloc / vmalloc construct is necessary:

0) The current code uses vmalloc only.
1) The allocated area ranges from 4 bytes possibly up to 512 kB, depending on on the size of the AGP buffer allocated.
2) Large buffers are very few. Small buffers tend to be quite many. If we continue to use vmalloc only or another page-based scheme we will waste approx one page per buffer, together with the added slowness of vmalloc. This will severely hurt applications with a lot of small texture buffers.

Please let me know if you still consider this unacceptable. In that case I suggest sticking with vmalloc for now.

Also please let me know if there are other parths of the patch that should be reworked.

The patch that follows is against Dave's agpgart repo.

Regards,

Thomas

#11 lore raw

Re: agpgart: drm-populated memory types

Quoted 13 lines

A short recap why I belive the kmalloc / vmalloc construct is necessary:

0) The current code uses vmalloc only.
1) The allocated area ranges from 4 bytes possibly up to 512 kB, depending on on the size of the AGP buffer allocated.
2) Large buffers are very few. Small buffers tend to be quite many. If we continue to use vmalloc only or another page-based scheme we will waste approx one page per buffer, together with the added slowness of vmalloc. This will severely hurt applications with a lot of small texture buffers.

Quoted 1 line

Please let me know if you still consider this unacceptable.

explicit use of either kmalloc/vmalloc is fine with me; I would suggest an 2*PAGE_SIZE cutoff for this decision

Quoted 8 lines

In that case I suggest sticking with vmalloc for now.

Also please let me know if there are other parths of the patch that should be reworked.

The patch that follows is against Dave's agpgart repo.

<you forgot the patch>

Signature · 2 lines
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
Test the interaction between Linux and your BIOS via http://www.linuxfirmwarekit.org
#13 lore raw

PATCH 1/1 agpgart: Allow drm-populated agp memory types

In reply to [email protected]

From: Thomas Hellstrom <[email protected]>

This patch allows drm to populate an agpgart structure with pages of its own. It's needed for the new drm memory manager which dynamically flips pages in and out of AGP.

The patch modifies the generic functions as well as the intel agp driver. The intel drm driver is currently the only one supporting the new memory manager.

Other agp drivers may need some minor fixing up once they have a corresponding memory manager enabled drm driver.

AGP memory types >= AGP_USER_TYPES are not populated by the agpgart driver, but the drm is expected to do that, as well as taking care of cache- and tlb flushing when needed.

It's not possible to request these types from user space using agpgart ioctls.

The Intel driver also gets a new memory type for pages that can be bound cached to the intel GTT.

---
 drivers/char/agp/agp.h          |   10 ++
 drivers/char/agp/ali-agp.c      |    2 
 drivers/char/agp/alpha-agp.c    |    4 +
 drivers/char/agp/amd-k7-agp.c   |    1 
 drivers/char/agp/amd64-agp.c    |   11 ++
 drivers/char/agp/ati-agp.c      |    1 
 drivers/char/agp/backend.c      |    2 
 drivers/char/agp/efficeon-agp.c |    1 
 drivers/char/agp/frontend.c     |    3 +
 drivers/char/agp/generic.c      |  133 +++++++++++++++++++++++++++-
 drivers/char/agp/hp-agp.c       |    1 
 drivers/char/agp/i460-agp.c     |    7 +
 drivers/char/agp/intel-agp.c    |  185 +++++++++++++++++++++++++--------------
 drivers/char/agp/nvidia-agp.c   |    1 
 drivers/char/agp/sgi-agp.c      |    1 
 drivers/char/agp/sworks-agp.c   |    1 
 drivers/char/agp/uninorth-agp.c |    2 
 drivers/char/agp/via-agp.c      |    2 
 include/linux/agp_backend.h     |    5 +
 19 files changed, 298 insertions(+), 75 deletions(-)
drivers/char/agp/agp.h +10 -0
index 1d59e2a..7c75389 100644
@@ -114,6 +114,7 @@ struct agp_bridge_driver {
 	void (*free_by_type)(struct agp_memory *);
 	void *(*agp_alloc_page)(struct agp_bridge_data *);
 	void (*agp_destroy_page)(void *);
+        int (*agp_type_to_mask_type) (struct agp_bridge_data *, int);
 };
 
 struct agp_bridge_data {
@@ -218,6 +219,7 @@ #define I810_PTE_BASE		0x10000
 #define I810_PTE_MAIN_UNCACHED	0x00000000
 #define I810_PTE_LOCAL		0x00000002
 #define I810_PTE_VALID		0x00000001
+#define I830_PTE_SYSTEM_CACHED  0x00000006
 #define I810_SMRAM_MISCC	0x70
 #define I810_GFX_MEM_WIN_SIZE	0x00010000
 #define I810_GFX_MEM_WIN_32M	0x00010000
@@ -270,8 +272,16 @@ void global_cache_flush(void);
 void get_agp_version(struct agp_bridge_data *bridge);
 unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge,
 	unsigned long addr, int type);
+int agp_generic_type_to_mask_type(struct agp_bridge_data *bridge,
+				  int type);
 struct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev);
 
+/* generic functions for user-populated AGP memory types */
+struct agp_memory *agp_generic_alloc_user(size_t page_count, int type);
+void agp_vkmalloc(size_t size, unsigned long **addr, u8 *vmalloc_flag);
+void agp_vkfree(unsigned long *addr, u8 vmalloc_flag);
+
+
 /* generic routines for agp>=3 */
 int agp3_generic_fetch_size(void);
 void agp3_generic_tlbflush(struct agp_memory *mem);
drivers/char/agp/ali-agp.c +2 -0
index 5a31ec7..98177a9 100644
@@ -214,6 +214,7 @@ static struct agp_bridge_driver ali_gene
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= ali_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static struct agp_bridge_driver ali_m1541_bridge = {
@@ -237,6 +238,7 @@ static struct agp_bridge_driver ali_m154
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= m1541_alloc_page,
 	.agp_destroy_page	= m1541_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 
drivers/char/agp/alpha-agp.c +4 -0
index b4e00a3..b0acf41 100644
@@ -91,6 +91,9 @@ static int alpha_core_agp_insert_memory(
 	int num_entries, status;
 	void *temp;
 
+	if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES)
+		return -EINVAL;
+
 	temp = agp_bridge->current_size;
 	num_entries = A_SIZE_FIX(temp)->num_entries;
 	if ((pg_start + mem->page_count) > num_entries)
@@ -142,6 +145,7 @@ struct agp_bridge_driver alpha_core_agp_
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 struct agp_bridge_data *alpha_bridge;
drivers/char/agp/amd-k7-agp.c +1 -0
index 51d0d56..9c129bd 100644
@@ -376,6 +376,7 @@ static struct agp_bridge_driver amd_iron
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static struct agp_device_ids amd_agp_device_ids[] __devinitdata =
drivers/char/agp/amd64-agp.c +9 -2
index 9793004..0e749f6 100644
@@ -62,12 +62,18 @@ static int amd64_insert_memory(struct ag
 {
 	int i, j, num_entries;
 	long long tmp;
+	int mask_type;
+	struct agp_bridge_data *bridge = mem->bridge;
 	u32 pte;
 
 	num_entries = agp_num_entries();
 
-	if (type != 0 || mem->type != 0)
+	if (type != mem->type)
 		return -EINVAL;
+	mask_type = bridge->driver->agp_type_to_mask_type(bridge, type);
+	if (mask_type != 0)
+		return -EINVAL;
+
 
 	/* Make sure we can fit the range in the gatt table. */
 	/* FIXME: could wrap */
@@ -90,7 +96,7 @@ static int amd64_insert_memory(struct ag
 
 	for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
 		tmp = agp_bridge->driver->mask_memory(agp_bridge,
-			mem->memory[i], mem->type);
+			mem->memory[i], mask_type);
 
 		BUG_ON(tmp & 0xffffff0000000ffcULL);
 		pte = (tmp & 0x000000ff00000000ULL) >> 28;
@@ -247,6 +253,7 @@ static struct agp_bridge_driver amd_8151
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 /* Some basic sanity checks for the aperture. */
drivers/char/agp/ati-agp.c +1 -0
index f244c66..d4f7b75 100644
@@ -431,6 +431,7 @@ static struct agp_bridge_driver ati_gene
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 
drivers/char/agp/backend.c +1 -1
index d59e037..ebdd6dd 100644
@@ -43,7 +43,7 @@ #include "agp.h"
  * fix some real stupidity. It's only by chance we can bump
  * past 0.99 at all due to some boolean logic error. */
 #define AGPGART_VERSION_MAJOR 0
-#define AGPGART_VERSION_MINOR 101
+#define AGPGART_VERSION_MINOR 102
 static const struct agp_version agp_current_version =
 {
 	.major = AGPGART_VERSION_MAJOR,
drivers/char/agp/efficeon-agp.c +1 -0
index 30f730f..658cb1a 100644
@@ -335,6 +335,7 @@ static struct agp_bridge_driver efficeon
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static int __devinit agp_efficeon_probe(struct pci_dev *pdev,
drivers/char/agp/frontend.c +3 -0
index 0f2ed2a..e21a319 100644
@@ -892,6 +892,9 @@ static int agpioc_allocate_wrap(struct a
 	if (copy_from_user(&alloc, arg, sizeof(struct agp_allocate)))
 		return -EFAULT;
 
+	if (alloc.type >= AGP_USER_TYPES)
+		return -EINVAL;
+
 	memory = agp_allocate_memory_wrap(alloc.pg_count, alloc.type);
 
 	if (memory == NULL)
drivers/char/agp/generic.c +127 -6

210 lines not on this page · raw message

drivers/char/agp/hp-agp.c +1 -0
index 907fb66..847deab 100644
@@ -438,6 +438,7 @@ struct agp_bridge_driver hp_zx1_driver =
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 	.cant_use_aperture	= 1,
 };
 
drivers/char/agp/i460-agp.c +7 -0
index 9176944..3e76186 100644
@@ -293,6 +293,9 @@ static int i460_insert_memory_small_io_p
 	pr_debug("i460_insert_memory_small_io_page(mem=%p, pg_start=%ld, type=%d, paddr0=0x%lx)\n",
 		 mem, pg_start, type, mem->memory[0]);
 
+	if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES)
+		return -EINVAL;
+
 	io_pg_start = I460_IOPAGES_PER_KPAGE * pg_start;
 
 	temp = agp_bridge->current_size;
@@ -396,6 +399,9 @@ static int i460_insert_memory_large_io_p
 	struct lp_desc *start, *end, *lp;
 	void *temp;
 
+	if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES)
+		return -EINVAL;
+
 	temp = agp_bridge->current_size;
 	num_entries = A_SIZE_8(temp)->num_entries;
 
@@ -572,6 +578,7 @@ #else
 #endif
 	.alloc_by_type		= agp_generic_alloc_by_type,
 	.free_by_type		= agp_generic_free_by_type,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 	.cant_use_aperture	= 1,
 };
 
drivers/char/agp/intel-agp.c +119 -66

394 lines not on this page · raw message

drivers/char/agp/nvidia-agp.c +1 -0
index df7f37b..2563286 100644
@@ -310,6 +310,7 @@ static struct agp_bridge_driver nvidia_d
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static int __devinit agp_nvidia_probe(struct pci_dev *pdev,
drivers/char/agp/sgi-agp.c +1 -0
index 902648d..92d1dc4 100644
@@ -265,6 +265,7 @@ struct agp_bridge_driver sgi_tioca_drive
 	.free_by_type = agp_generic_free_by_type,
 	.agp_alloc_page = sgi_tioca_alloc_page,
 	.agp_destroy_page = agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 	.cant_use_aperture = 1,
 	.needs_scratch_page = 0,
 	.num_aperture_sizes = 1,
drivers/char/agp/sworks-agp.c +1 -0
index 4f2d7d9..9f5ae77 100644
@@ -444,6 +444,7 @@ static struct agp_bridge_driver sworks_d
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static int __devinit agp_serverworks_probe(struct pci_dev *pdev,
drivers/char/agp/uninorth-agp.c +2 -0
index dffc193..6c45702 100644
@@ -510,6 +510,7 @@ struct agp_bridge_driver uninorth_agp_dr
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 	.cant_use_aperture	= 1,
 };
 
@@ -534,6 +535,7 @@ struct agp_bridge_driver u3_agp_driver =
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 	.cant_use_aperture	= 1,
 	.needs_scratch_page	= 1,
 };
drivers/char/agp/via-agp.c +2 -0
index c149ac9..143d3fa 100644
@@ -191,6 +191,7 @@ static struct agp_bridge_driver via_agp3
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static struct agp_bridge_driver via_driver = {
@@ -214,6 +215,7 @@ static struct agp_bridge_driver via_driv
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static struct agp_device_ids via_agp_device_ids[] __devinitdata =
include/linux/agp_backend.h +5 -0
index a5c8bb5..abc521c 100644
@@ -87,10 +87,15 @@ struct agp_memory {
 	u32 physical;
 	u8 is_bound;
 	u8 is_flushed;
+        u8 vmalloc_flag;
 };
 
 #define AGP_NORMAL_MEMORY 0
 
+#define AGP_USER_TYPES (1 << 16)
+#define AGP_USER_MEMORY (AGP_USER_TYPES)
+#define AGP_USER_CACHED_MEMORY (AGP_USER_TYPES + 1)
+
 extern struct agp_bridge_data *agp_bridge;
 extern struct list_head agp_bridges;
 
Signature · 1 line
1.4.1
#12 lore raw

Re: agpgart: drm-populated memory types

In reply to Arjan van de Ven
Quoted 21 lines · Arjan van de Ven
Quoted 11 lines

A short recap why I belive the kmalloc / vmalloc construct is necessary:

0) The current code uses vmalloc only.
1) The allocated area ranges from 4 bytes possibly up to 512 kB, depending on on the size of the AGP buffer allocated.
2) Large buffers are very few. Small buffers tend to be quite many. If we continue to use vmalloc only or another page-based scheme we will waste approx one page per buffer, together with the added slowness of vmalloc. This will severely hurt applications with a lot of small texture buffers.

Quoted 2 lines

Please let me know if you still consider this unacceptable.

explicit use of either kmalloc/vmalloc is fine with me; I would suggest an 2*PAGE_SIZE cutoff for this decision

Quoted 3 lines

In that case I suggest sticking with vmalloc for now.

Quoted 9 lines
Quoted 6 lines

Also please let me know if there are other parths of the patch that should be reworked.

The patch that follows is against Dave's agpgart repo.

<you forgot the patch>

Hmm.
Still struggling with git-send-email.
Now it should have arrived.

Thanks,
Thomas

#14 lore raw

Re: [PATCH] agpgart: Allow drm-populated agp memory types

In reply to [email protected]
Quoted 8 lines · On Tue, 2007-01-09 at 09:23 +0100, [email protected] wrote:
drivers/char/agp/generic.c +8 -0
+
+void agp_vkmalloc(size_t size, unsigned long **addr, u8 *vmalloc_flag)
+{
+	void *tmp = NULL;
+
+	*vmalloc_flag = 0;
+
+	if (size <= 2*PAGE_SIZE) {

drivers/char/agp/generic.c static int agp_get_key(void) · line 126

Quoted 10 lines
drivers/char/agp/generic.c +10 -0
+		tmp = kmalloc(size, GFP_KERNEL);
+	}
+	if (tmp == NULL) {
+		tmp = vmalloc(size);
+		*vmalloc_flag = 1;
+	}
+
+	*addr = tmp;
+}
+EXPORT_SYMBOL(agp_vkmalloc);

if you don't do this "fallback" thing the caller can just know it is vmalloc due to the size... (and a 2 page kmalloc isn't going to fail on you with GFP_KERNEL; also if you really want to deal with this failure also tell the VM you're ok with failure (__GFP_NORETRY and such)... but unless you do, things get a lot simpler by not doing this "fall back" thing.

Signature · 2 lines
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
Test the interaction between Linux and your BIOS via http://www.linuxfirmwarekit.org
#15 lore raw

Re: [PATCH] agpgart: Allow drm-populated agp memory types

In reply to [email protected]

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	agp_vkmalloc(alloc_size, &new->memory, &new->vmalloc_flag);

ok why wouldn't agp_vkmalloc take a size and just only "new" as argument here? Just pass it a pointer to the struct it fills in anyway...

Signature · 2 lines
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
Test the interaction between Linux and your BIOS via http://www.linuxfirmwarekit.org
#16 lore raw

New patch: drm-populated memory types

This one incorporates some of Arjan's suggestions and a fix for the i810 problem introduced with the previous patch.

/Thomas

#17 lore raw

PATCH 1/1 agpgart: Allow drm-populated agp memory types

From: Thomas Hellstrom <[email protected]>

This patch allows drm to populate an agpgart structure with pages of its own. It's needed for the new drm memory manager which dynamically flips pages in and out of AGP.

The patch modifies the generic functions as well as the intel agp driver. The intel drm driver is currently the only one supporting the new memory manager.

Other agp drivers may need some minor fixing up once they have a corresponding memory manager enabled drm driver.

AGP memory types >= AGP_USER_TYPES are not populated by the agpgart driver, but the drm is expected to do that, as well as taking care of cache- and tlb flushing when needed.

It's not possible to request these types from user space using agpgart ioctls.

The Intel driver also gets a new memory type for pages that can be bound cached to the intel GTT.

---
 drivers/char/agp/agp.h          |   10 ++
 drivers/char/agp/ali-agp.c      |    2 
 drivers/char/agp/alpha-agp.c    |    4 +
 drivers/char/agp/amd-k7-agp.c   |    1 
 drivers/char/agp/amd64-agp.c    |   11 ++
 drivers/char/agp/ati-agp.c      |    1 
 drivers/char/agp/backend.c      |    2 
 drivers/char/agp/efficeon-agp.c |    1 
 drivers/char/agp/frontend.c     |    3 +
 drivers/char/agp/generic.c      |  130 ++++++++++++++++++++++++++-
 drivers/char/agp/hp-agp.c       |    1 
 drivers/char/agp/i460-agp.c     |    7 +
 drivers/char/agp/intel-agp.c    |  186 +++++++++++++++++++++++++--------------
 drivers/char/agp/nvidia-agp.c   |    1 
 drivers/char/agp/sgi-agp.c      |    1 
 drivers/char/agp/sworks-agp.c   |    1 
 drivers/char/agp/uninorth-agp.c |    2 
 drivers/char/agp/via-agp.c      |    2 
 include/linux/agp_backend.h     |    5 +
 19 files changed, 296 insertions(+), 75 deletions(-)
drivers/char/agp/agp.h +10 -0
index 1d59e2a..f821243 100644
@@ -114,6 +114,7 @@ struct agp_bridge_driver {
 	void (*free_by_type)(struct agp_memory *);
 	void *(*agp_alloc_page)(struct agp_bridge_data *);
 	void (*agp_destroy_page)(void *);
+        int (*agp_type_to_mask_type) (struct agp_bridge_data *, int);
 };
 
 struct agp_bridge_data {
@@ -218,6 +219,7 @@ #define I810_PTE_BASE		0x10000
 #define I810_PTE_MAIN_UNCACHED	0x00000000
 #define I810_PTE_LOCAL		0x00000002
 #define I810_PTE_VALID		0x00000001
+#define I830_PTE_SYSTEM_CACHED  0x00000006
 #define I810_SMRAM_MISCC	0x70
 #define I810_GFX_MEM_WIN_SIZE	0x00010000
 #define I810_GFX_MEM_WIN_32M	0x00010000
@@ -270,8 +272,16 @@ void global_cache_flush(void);
 void get_agp_version(struct agp_bridge_data *bridge);
 unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge,
 	unsigned long addr, int type);
+int agp_generic_type_to_mask_type(struct agp_bridge_data *bridge,
+				  int type);
 struct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev);
 
+/* generic functions for user-populated AGP memory types */
+struct agp_memory *agp_generic_alloc_user(size_t page_count, int type);
+void agp_alloc_page_array(size_t size, struct agp_memory *mem);
+void agp_free_page_array(struct agp_memory *mem);
+
+
 /* generic routines for agp>=3 */
 int agp3_generic_fetch_size(void);
 void agp3_generic_tlbflush(struct agp_memory *mem);
drivers/char/agp/ali-agp.c +2 -0
index 5a31ec7..98177a9 100644
@@ -214,6 +214,7 @@ static struct agp_bridge_driver ali_gene
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= ali_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static struct agp_bridge_driver ali_m1541_bridge = {
@@ -237,6 +238,7 @@ static struct agp_bridge_driver ali_m154
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= m1541_alloc_page,
 	.agp_destroy_page	= m1541_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 
drivers/char/agp/alpha-agp.c +4 -0
index b4e00a3..b0acf41 100644
@@ -91,6 +91,9 @@ static int alpha_core_agp_insert_memory(
 	int num_entries, status;
 	void *temp;
 
+	if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES)
+		return -EINVAL;
+
 	temp = agp_bridge->current_size;
 	num_entries = A_SIZE_FIX(temp)->num_entries;
 	if ((pg_start + mem->page_count) > num_entries)
@@ -142,6 +145,7 @@ struct agp_bridge_driver alpha_core_agp_
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 struct agp_bridge_data *alpha_bridge;
drivers/char/agp/amd-k7-agp.c +1 -0
index 51d0d56..9c129bd 100644
@@ -376,6 +376,7 @@ static struct agp_bridge_driver amd_iron
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static struct agp_device_ids amd_agp_device_ids[] __devinitdata =
drivers/char/agp/amd64-agp.c +9 -2
index 9793004..0e749f6 100644
@@ -62,12 +62,18 @@ static int amd64_insert_memory(struct ag
 {
 	int i, j, num_entries;
 	long long tmp;
+	int mask_type;
+	struct agp_bridge_data *bridge = mem->bridge;
 	u32 pte;
 
 	num_entries = agp_num_entries();
 
-	if (type != 0 || mem->type != 0)
+	if (type != mem->type)
 		return -EINVAL;
+	mask_type = bridge->driver->agp_type_to_mask_type(bridge, type);
+	if (mask_type != 0)
+		return -EINVAL;
+
 
 	/* Make sure we can fit the range in the gatt table. */
 	/* FIXME: could wrap */
@@ -90,7 +96,7 @@ static int amd64_insert_memory(struct ag
 
 	for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
 		tmp = agp_bridge->driver->mask_memory(agp_bridge,
-			mem->memory[i], mem->type);
+			mem->memory[i], mask_type);
 
 		BUG_ON(tmp & 0xffffff0000000ffcULL);
 		pte = (tmp & 0x000000ff00000000ULL) >> 28;
@@ -247,6 +253,7 @@ static struct agp_bridge_driver amd_8151
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 /* Some basic sanity checks for the aperture. */
drivers/char/agp/ati-agp.c +1 -0
index f244c66..d4f7b75 100644
@@ -431,6 +431,7 @@ static struct agp_bridge_driver ati_gene
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 
drivers/char/agp/backend.c +1 -1
index d59e037..ebdd6dd 100644
@@ -43,7 +43,7 @@ #include "agp.h"
  * fix some real stupidity. It's only by chance we can bump
  * past 0.99 at all due to some boolean logic error. */
 #define AGPGART_VERSION_MAJOR 0
-#define AGPGART_VERSION_MINOR 101
+#define AGPGART_VERSION_MINOR 102
 static const struct agp_version agp_current_version =
 {
 	.major = AGPGART_VERSION_MAJOR,
drivers/char/agp/efficeon-agp.c +1 -0
index 30f730f..658cb1a 100644
@@ -335,6 +335,7 @@ static struct agp_bridge_driver efficeon
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static int __devinit agp_efficeon_probe(struct pci_dev *pdev,
drivers/char/agp/frontend.c +3 -0
index 0f2ed2a..e21a319 100644
@@ -892,6 +892,9 @@ static int agpioc_allocate_wrap(struct a
 	if (copy_from_user(&alloc, arg, sizeof(struct agp_allocate)))
 		return -EFAULT;
 
+	if (alloc.type >= AGP_USER_TYPES)
+		return -EINVAL;
+
 	memory = agp_allocate_memory_wrap(alloc.pg_count, alloc.type);
 
 	if (memory == NULL)
drivers/char/agp/generic.c +124 -6

213 lines not on this page · raw message

drivers/char/agp/hp-agp.c +1 -0
index 907fb66..847deab 100644
@@ -438,6 +438,7 @@ struct agp_bridge_driver hp_zx1_driver =
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 	.cant_use_aperture	= 1,
 };
 
drivers/char/agp/i460-agp.c +7 -0
index 9176944..3e76186 100644
@@ -293,6 +293,9 @@ static int i460_insert_memory_small_io_p
 	pr_debug("i460_insert_memory_small_io_page(mem=%p, pg_start=%ld, type=%d, paddr0=0x%lx)\n",
 		 mem, pg_start, type, mem->memory[0]);
 
+	if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES)
+		return -EINVAL;
+
 	io_pg_start = I460_IOPAGES_PER_KPAGE * pg_start;
 
 	temp = agp_bridge->current_size;
@@ -396,6 +399,9 @@ static int i460_insert_memory_large_io_p
 	struct lp_desc *start, *end, *lp;
 	void *temp;
 
+	if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES)
+		return -EINVAL;
+
 	temp = agp_bridge->current_size;
 	num_entries = A_SIZE_8(temp)->num_entries;
 
@@ -572,6 +578,7 @@ #else
 #endif
 	.alloc_by_type		= agp_generic_alloc_by_type,
 	.free_by_type		= agp_generic_free_by_type,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 	.cant_use_aperture	= 1,
 };
 
drivers/char/agp/intel-agp.c +120 -66

395 lines not on this page · raw message

drivers/char/agp/nvidia-agp.c +1 -0
index df7f37b..2563286 100644
@@ -310,6 +310,7 @@ static struct agp_bridge_driver nvidia_d
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static int __devinit agp_nvidia_probe(struct pci_dev *pdev,
drivers/char/agp/sgi-agp.c +1 -0
index 902648d..92d1dc4 100644
@@ -265,6 +265,7 @@ struct agp_bridge_driver sgi_tioca_drive
 	.free_by_type = agp_generic_free_by_type,
 	.agp_alloc_page = sgi_tioca_alloc_page,
 	.agp_destroy_page = agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 	.cant_use_aperture = 1,
 	.needs_scratch_page = 0,
 	.num_aperture_sizes = 1,
drivers/char/agp/sworks-agp.c +1 -0
index 4f2d7d9..9f5ae77 100644
@@ -444,6 +444,7 @@ static struct agp_bridge_driver sworks_d
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static int __devinit agp_serverworks_probe(struct pci_dev *pdev,
drivers/char/agp/uninorth-agp.c +2 -0
index dffc193..6c45702 100644
@@ -510,6 +510,7 @@ struct agp_bridge_driver uninorth_agp_dr
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 	.cant_use_aperture	= 1,
 };
 
@@ -534,6 +535,7 @@ struct agp_bridge_driver u3_agp_driver =
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 	.cant_use_aperture	= 1,
 	.needs_scratch_page	= 1,
 };
drivers/char/agp/via-agp.c +2 -0
index c149ac9..143d3fa 100644
@@ -191,6 +191,7 @@ static struct agp_bridge_driver via_agp3
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static struct agp_bridge_driver via_driver = {
@@ -214,6 +215,7 @@ static struct agp_bridge_driver via_driv
 	.free_by_type		= agp_generic_free_by_type,
 	.agp_alloc_page		= agp_generic_alloc_page,
 	.agp_destroy_page	= agp_generic_destroy_page,
+	.agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static struct agp_device_ids via_agp_device_ids[] __devinitdata =
include/linux/agp_backend.h +5 -0
index a5c8bb5..abc521c 100644
@@ -87,10 +87,15 @@ struct agp_memory {
 	u32 physical;
 	u8 is_bound;
 	u8 is_flushed;
+        u8 vmalloc_flag;
 };
 
 #define AGP_NORMAL_MEMORY 0
 
+#define AGP_USER_TYPES (1 << 16)
+#define AGP_USER_MEMORY (AGP_USER_TYPES)
+#define AGP_USER_CACHED_MEMORY (AGP_USER_TYPES + 1)
+
 extern struct agp_bridge_data *agp_bridge;
 extern struct list_head agp_bridges;
 
Signature · 1 line
1.4.1