diff options
author | Pavel Machek <pavel@ucw.cz> | 2008-05-20 10:27:17 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2008-05-22 05:35:14 -0400 |
commit | 0abbc78a0137fee60ef092f0b20a3d3d7e7e0cc2 (patch) | |
tree | 861c8de86a39a9c3235f949dcad01ba96cfb18c6 | |
parent | 538f0fd0f210c2ce5c585799f18d0e5c7cf6155e (diff) |
x86, aperture_64: use symbolic constants
Factor-out common aperture_valid code.
Signed-off-by: Pavel Machek <pavel@suse.cz>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
-rw-r--r-- | arch/x86/kernel/aperture_64.c | 23 | ||||
-rw-r--r-- | drivers/char/agp/amd64-agp.c | 22 | ||||
-rw-r--r-- | include/asm-x86/gart.h | 24 |
3 files changed, 29 insertions, 40 deletions
diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c index 02f4dbaa4df4..5373f7834d8a 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) | |||
109 | return (u32)__pa(p); | 109 | return (u32)__pa(p); |
110 | } | 110 | } |
111 | 111 | ||
112 | static int __init aperture_valid(u64 aper_base, u32 aper_size, u32 min_size) | ||
113 | { | ||
114 | if (!aper_base) | ||
115 | return 0; | ||
116 | |||
117 | if (aper_base + aper_size > 0x100000000UL) { | ||
118 | printk(KERN_ERR "Aperture beyond 4GB. Ignoring.\n"); | ||
119 | return 0; | ||
120 | } | ||
121 | if (e820_any_mapped(aper_base, aper_base + aper_size, E820_RAM)) { | ||
122 | printk(KERN_ERR "Aperture pointing to e820 RAM. Ignoring.\n"); | ||
123 | return 0; | ||
124 | } | ||
125 | if (aper_size < min_size) { | ||
126 | printk(KERN_ERR "Aperture too small (%d MB) than (%d MB)\n", | ||
127 | aper_size>>20, min_size>>20); | ||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | return 1; | ||
132 | } | ||
133 | 112 | ||
134 | /* Find a PCI capability */ | 113 | /* Find a PCI capability */ |
135 | static __u32 __init find_cap(int bus, int slot, int func, int cap) | 114 | static __u32 __init find_cap(int bus, int slot, int func, int cap) |
@@ -344,7 +323,7 @@ out: | |||
344 | if (gart_fix_e820 && !fix && aper_enabled) { | 323 | if (gart_fix_e820 && !fix && aper_enabled) { |
345 | if (!e820_all_mapped(aper_base, aper_base + aper_size, | 324 | if (!e820_all_mapped(aper_base, aper_base + aper_size, |
346 | E820_RESERVED)) { | 325 | E820_RESERVED)) { |
347 | /* reserved it, so we can resuse it in second kernel */ | 326 | /* reserve it, so we can reuse it in second kernel */ |
348 | printk(KERN_INFO "update e820 for GART\n"); | 327 | printk(KERN_INFO "update e820 for GART\n"); |
349 | add_memory_region(aper_base, aper_size, E820_RESERVED); | 328 | add_memory_region(aper_base, aper_size, E820_RESERVED); |
350 | update_e820(); | 329 | update_e820(); |
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c index e3c7ea07f57c..f5af65ac8c78 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 amd_8151_driver = { | |||
228 | }; | 228 | }; |
229 | 229 | ||
230 | /* Some basic sanity checks for the aperture. */ | 230 | /* Some basic sanity checks for the aperture. */ |
231 | static int __devinit aperture_valid(u64 aper, u32 size) | 231 | static int __devinit agp_aperture_valid(u64 aper, u32 size) |
232 | { | 232 | { |
233 | if (aper == 0) { | 233 | if (!aperture_valid(aper, size, 32*1024*1024)) |
234 | printk(KERN_ERR PFX "No aperture\n"); | ||
235 | return 0; | 234 | return 0; |
236 | } | ||
237 | if ((u64)aper + size > 0x100000000ULL) { | ||
238 | printk(KERN_ERR PFX "Aperture out of bounds\n"); | ||
239 | return 0; | ||
240 | } | ||
241 | if (e820_any_mapped(aper, aper + size, E820_RAM)) { | ||
242 | printk(KERN_ERR PFX "Aperture pointing to RAM\n"); | ||
243 | return 0; | ||
244 | } | ||
245 | if (size < 32*1024*1024) { | ||
246 | printk(KERN_ERR PFX "Aperture too small (%d MB)\n", size>>20); | ||
247 | return 0; | ||
248 | } | ||
249 | 235 | ||
250 | /* Request the Aperture. This catches cases when someone else | 236 | /* Request the Aperture. This catches cases when someone else |
251 | already put a mapping in there - happens with some very broken BIOS | 237 | already put a mapping in there - happens with some very broken BIOS |
@@ -282,7 +268,7 @@ static __devinit int fix_northbridge(struct pci_dev *nb, struct pci_dev *agp, | |||
282 | nb_order = (nb_order >> 1) & 7; | 268 | nb_order = (nb_order >> 1) & 7; |
283 | pci_read_config_dword(nb, AMD64_GARTAPERTUREBASE, &nb_base); | 269 | pci_read_config_dword(nb, AMD64_GARTAPERTUREBASE, &nb_base); |
284 | nb_aper = nb_base << 25; | 270 | nb_aper = nb_base << 25; |
285 | if (aperture_valid(nb_aper, (32*1024*1024)<<nb_order)) { | 271 | if (agp_aperture_valid(nb_aper, (32*1024*1024)<<nb_order)) { |
286 | return 0; | 272 | return 0; |
287 | } | 273 | } |
288 | 274 | ||
@@ -313,7 +299,7 @@ static __devinit int fix_northbridge(struct pci_dev *nb, struct pci_dev *agp, | |||
313 | } | 299 | } |
314 | 300 | ||
315 | printk(KERN_INFO PFX "Aperture from AGP @ %Lx size %u MB\n", aper, 32 << order); | 301 | printk(KERN_INFO PFX "Aperture from AGP @ %Lx size %u MB\n", aper, 32 << order); |
316 | if (order < 0 || !aperture_valid(aper, (32*1024*1024)<<order)) | 302 | if (order < 0 || !agp_aperture_valid(aper, (32*1024*1024)<<order)) |
317 | return -1; | 303 | return -1; |
318 | 304 | ||
319 | pci_write_config_dword(nb, AMD64_GARTAPERTURECTL, order << 1); | 305 | pci_write_config_dword(nb, AMD64_GARTAPERTURECTL, order << 1); |
diff --git a/include/asm-x86/gart.h b/include/asm-x86/gart.h index 6f22786d2f0c..c818b96f936b 100644 --- a/include/asm-x86/gart.h +++ b/include/asm-x86/gart.h | |||
@@ -1,6 +1,8 @@ | |||
1 | #ifndef _ASM_X8664_IOMMU_H | 1 | #ifndef _ASM_X8664_IOMMU_H |
2 | #define _ASM_X8664_IOMMU_H 1 | 2 | #define _ASM_X8664_IOMMU_H 1 |
3 | 3 | ||
4 | #include <asm/e820.h> | ||
5 | |||
4 | extern void pci_iommu_shutdown(void); | 6 | extern void pci_iommu_shutdown(void); |
5 | extern void no_iommu_init(void); | 7 | extern void no_iommu_init(void); |
6 | extern int force_iommu, no_iommu; | 8 | extern int force_iommu, no_iommu; |
@@ -69,4 +71,26 @@ static inline void enable_gart_translation(struct pci_dev *dev, u64 addr) | |||
69 | pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, ctl); | 71 | pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, ctl); |
70 | } | 72 | } |
71 | 73 | ||
74 | static inline int aperture_valid(u64 aper_base, u32 aper_size, u32 min_size) | ||
75 | { | ||
76 | if (!aper_base) | ||
77 | return 0; | ||
78 | |||
79 | if (aper_base + aper_size > 0x100000000ULL) { | ||
80 | printk(KERN_ERR "Aperture beyond 4GB. Ignoring.\n"); | ||
81 | return 0; | ||
82 | } | ||
83 | if (e820_any_mapped(aper_base, aper_base + aper_size, E820_RAM)) { | ||
84 | printk(KERN_ERR "Aperture pointing to e820 RAM. Ignoring.\n"); | ||
85 | return 0; | ||
86 | } | ||
87 | if (aper_size < min_size) { | ||
88 | printk(KERN_ERR "Aperture too small (%d MB) than (%d MB)\n", | ||
89 | aper_size>>20, min_size>>20); | ||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | return 1; | ||
94 | } | ||
95 | |||
72 | #endif | 96 | #endif |