Re: aperture_64: use symbolic constants

Previous thread: 2.6.25.4-rt2 compile errors on ARM due to cmpxchg() problems. by Remy Bohmer on Tuesday, May 20, 2008 - 7:21 am. (4 messages)

Next thread: Re: [PATCH 1/8] Scaling msgmni to the amount of lowmem by Michael Kerrisk on Tuesday, May 20, 2008 - 7:28 am. (4 messages)
From: Pavel Machek
Date: Tuesday, May 20, 2008 - 7:27 am

Thanks, I have a copy now. And this one is relative to it:

--- 

Factor-out common aperture_valid code.

Signed-off-by: Pavel Machek <pavel@suse.cz>

diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
index 02f4dba..5373f78 100644
--- a/arch/x86/kernel/aperture_64.c
+++ b/arch/x86/kernel/aperture_64.c
@@ -109,27 +109,6 @@ static u32 __init allocate_aperture(void
 	return (u32)__pa(p);
 }
 
-static int __init aperture_valid(u64 aper_base, u32 aper_size, u32 min_size)
-{
-	if (!aper_base)
-		return 0;
-
-	if (aper_base + aper_size > 0x100000000UL) {
-		printk(KERN_ERR "Aperture beyond 4GB. Ignoring.\n");
-		return 0;
-	}
-	if (e820_any_mapped(aper_base, aper_base + aper_size, E820_RAM)) {
-		printk(KERN_ERR "Aperture pointing to e820 RAM. Ignoring.\n");
-		return 0;
-	}
-	if (aper_size < min_size) {
-		printk(KERN_ERR "Aperture too small (%d MB) than (%d MB)\n",
-				 aper_size>>20, min_size>>20);
-		return 0;
-	}
-
-	return 1;
-}
 
 /* Find a PCI capability */
 static __u32 __init find_cap(int bus, int slot, int func, int cap)
@@ -344,7 +323,7 @@ out:
 	if (gart_fix_e820 && !fix && aper_enabled) {
 		if (!e820_all_mapped(aper_base, aper_base + aper_size,
 				    E820_RESERVED)) {
-			/* reserved it, so we can resuse it in second kernel */
+			/* reserve it, so we can reuse it in second kernel */
 			printk(KERN_INFO "update e820 for GART\n");
 			add_memory_region(aper_base, aper_size, E820_RESERVED);
 			update_e820();
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index fea1313..3b53ea0 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -228,24 +228,10 @@ static const struct agp_bridge_driver am
 };
 
 /* Some basic sanity checks for the aperture. */
-static int __devinit aperture_valid(u64 aper, u32 size)
+static int __devinit agp_aperture_valid(u64 aper, u32 size)
 {
-	if (aper == 0) {
-		printk(KERN_ERR PFX "No aperture\n");
+	if (!aperture_valid(aper, size, ...
From: Dave Jones
Date: Tuesday, May 20, 2008 - 8:06 am

On Tue, May 20, 2008 at 04:27:17PM +0200, Pavel Machek wrote:


 > +static inline int aperture_valid(u64 aper_base, u32 aper_size, u32 min_size)
 > +{
 > +	if (!aper_base)
 > +		return 0;
 > +
 > +	if (aper_base + aper_size > 0x100000000ULL) {
 > +		printk(KERN_ERR "Aperture beyond 4GB. Ignoring.\n");
 > +		return 0;
 > +	}
 > +	if (e820_any_mapped(aper_base, aper_base + aper_size, E820_RAM)) {
 > +		printk(KERN_ERR "Aperture pointing to e820 RAM. Ignoring.\n");
 > +		return 0;
 > +	}
 > +	if (aper_size < min_size) {
 > +		printk(KERN_ERR "Aperture too small (%d MB) than (%d MB)\n",
 > +				 aper_size>>20, min_size>>20);
 > +		return 0;
 > +	}
 > +
 > +	return 1;
 > +}

Instead of making this an inline, we could add it to the agpgart code
and export it, and have the gart-iommu code call it.
You can't build the IOMMU code without agpgart anyway, and having this inlined
in both places seems a bit wasteful.
Additionally, it would mean not having a function in a header file,
which always strikes me as a wrong thing to do.

	Dave

-- 
http://www.codemonkey.org.uk
--

From: Pavel Machek
Date: Tuesday, May 20, 2008 - 8:32 am

Can you elaborate? Yes, it would be nicer if this went to .c
somewhere, but aperture_64.c seems unsuitable (we need it on 32-bit,
too, right?)... plus it was __init in one place, and __devinit in the
other, so I figured out "inline it so that it works automagically".

Plus, I don't think it should go into drivers/agp, as iommu code in
arch/x86/kernel seems to be able to work without that...?

								Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--

From: Dave Jones
Date: Tuesday, May 20, 2008 - 8:42 am

On Tue, May 20, 2008 at 05:32:15PM +0200, Pavel Machek wrote:

 > > Instead of making this an inline, we could add it to the agpgart code
 > > and export it, and have the gart-iommu code call it.
 > > You can't build the IOMMU code without agpgart anyway, and having this inlined
 > > in both places seems a bit wasteful.
 > > Additionally, it would mean not having a function in a header file,
 > > which always strikes me as a wrong thing to do.
 > 
 > Can you elaborate? Yes, it would be nicer if this went to .c
 > somewhere, but aperture_64.c seems unsuitable (we need it on 32-bit,
 > too, right?)... plus it was __init in one place, and __devinit in the
 > other, so I figured out "inline it so that it works automagically".
 > 
 > Plus, I don't think it should go into drivers/agp, as iommu code in
 > arch/x86/kernel seems to be able to work without that...?

If you enable IOMMU, you _have_ to enable AGP.  (well, you don't have to,
it does a 'select AGP' for you when you enable it :-)

It does this because the agpgart driver needs to know how much of the
aperture has been stolen for IOMMU use, and I think it already uses some
functions from that driver already.

	Dave

-- 
http://www.codemonkey.org.uk
--

From: Andi Kleen
Date: Tuesday, May 20, 2008 - 6:23 pm

That's actually not needed. The IOMMU code was carefully
written to not require AGP. The only requirement it has is that
if AGP is enabled it has to be built in.

-Andi
--

From: Ingo Molnar
Date: Tuesday, May 20, 2008 - 8:42 am

applied, thanks Pavel.

	Ingo
--

From: Yinghai Lu
Date: Tuesday, May 20, 2008 - 6:59 pm

can you change the titile?

YH
--

Previous thread: 2.6.25.4-rt2 compile errors on ARM due to cmpxchg() problems. by Remy Bohmer on Tuesday, May 20, 2008 - 7:21 am. (4 messages)

Next thread: Re: [PATCH 1/8] Scaling msgmni to the amount of lowmem by Michael Kerrisk on Tuesday, May 20, 2008 - 7:28 am. (4 messages)