aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorbibo,mao <bibo.mao@intel.com>2006-12-06 20:14:06 -0500
committerAndi Kleen <andi@basil.nowhere.org>2006-12-06 20:14:06 -0500
commit269c2d81ed66af7c09a1619ffe165f03e7470a5b (patch)
treed613830e37d539f41582a213544c70c26d9a5fb1 /arch
parent8e3de538eec95b57a5b86038988451c38ba83f7e (diff)
[PATCH] i386: i386 create e820.c to handle standard io/mem resources
This patch creates new file named e820.c to hanle standard io/mem resources, moving request_standard_resources function from setup.c to e820.c. Also this patch modifies Makfile to compile file e820.c. Signed-off-by: bibo,mao <bibo.mao@intel.com> Signed-off-by: Andi Kleen <ak@suse.de> Makefile | 2 arch/i386/kernel/Makefile | 2 arch/i386/kernel/e820.c | 289 ++++++++++++++++++++++++++++++++++++++++++++++ arch/i386/kernel/setup.c | 276 ------------------------------------------- 3 files changed, 293 insertions(+), 274 deletions(-)
Diffstat (limited to 'arch')
-rw-r--r--arch/i386/kernel/Makefile2
-rw-r--r--arch/i386/kernel/e820.c289
-rw-r--r--arch/i386/kernel/setup.c276
3 files changed, 293 insertions, 274 deletions
diff --git a/arch/i386/kernel/Makefile b/arch/i386/kernel/Makefile
index 1a884b6e6e5c..f614854bd71f 100644
--- a/arch/i386/kernel/Makefile
+++ b/arch/i386/kernel/Makefile
@@ -6,7 +6,7 @@ extra-y := head.o init_task.o vmlinux.lds
6 6
7obj-y := process.o signal.o entry.o traps.o irq.o \ 7obj-y := process.o signal.o entry.o traps.o irq.o \
8 ptrace.o time.o ioport.o ldt.o setup.o i8259.o sys_i386.o \ 8 ptrace.o time.o ioport.o ldt.o setup.o i8259.o sys_i386.o \
9 pci-dma.o i386_ksyms.o i387.o bootflag.o \ 9 pci-dma.o i386_ksyms.o i387.o bootflag.o e820.o\
10 quirks.o i8237.o topology.o alternative.o i8253.o tsc.o 10 quirks.o i8237.o topology.o alternative.o i8253.o tsc.o
11 11
12obj-$(CONFIG_STACKTRACE) += stacktrace.o 12obj-$(CONFIG_STACKTRACE) += stacktrace.o
diff --git a/arch/i386/kernel/e820.c b/arch/i386/kernel/e820.c
new file mode 100644
index 000000000000..cce706049488
--- /dev/null
+++ b/arch/i386/kernel/e820.c
@@ -0,0 +1,289 @@
1#include <linux/kernel.h>
2#include <linux/types.h>
3#include <linux/init.h>
4#include <linux/bootmem.h>
5#include <linux/ioport.h>
6#include <linux/string.h>
7#include <linux/kexec.h>
8#include <linux/module.h>
9#include <linux/mm.h>
10#include <linux/efi.h>
11
12#include <asm/pgtable.h>
13#include <asm/page.h>
14#include <asm/e820.h>
15
16#ifdef CONFIG_EFI
17int efi_enabled = 0;
18EXPORT_SYMBOL(efi_enabled);
19#endif
20
21struct e820map e820;
22struct resource data_resource = {
23 .name = "Kernel data",
24 .start = 0,
25 .end = 0,
26 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
27};
28
29struct resource code_resource = {
30 .name = "Kernel code",
31 .start = 0,
32 .end = 0,
33 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
34};
35
36static struct resource system_rom_resource = {
37 .name = "System ROM",
38 .start = 0xf0000,
39 .end = 0xfffff,
40 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
41};
42
43static struct resource extension_rom_resource = {
44 .name = "Extension ROM",
45 .start = 0xe0000,
46 .end = 0xeffff,
47 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
48};
49
50static struct resource adapter_rom_resources[] = { {
51 .name = "Adapter ROM",
52 .start = 0xc8000,
53 .end = 0,
54 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
55}, {
56 .name = "Adapter ROM",
57 .start = 0,
58 .end = 0,
59 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
60}, {
61 .name = "Adapter ROM",
62 .start = 0,
63 .end = 0,
64 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
65}, {
66 .name = "Adapter ROM",
67 .start = 0,
68 .end = 0,
69 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
70}, {
71 .name = "Adapter ROM",
72 .start = 0,
73 .end = 0,
74 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
75}, {
76 .name = "Adapter ROM",
77 .start = 0,
78 .end = 0,
79 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
80} };
81
82static struct resource video_rom_resource = {
83 .name = "Video ROM",
84 .start = 0xc0000,
85 .end = 0xc7fff,
86 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
87};
88
89static struct resource video_ram_resource = {
90 .name = "Video RAM area",
91 .start = 0xa0000,
92 .end = 0xbffff,
93 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
94};
95
96static struct resource standard_io_resources[] = { {
97 .name = "dma1",
98 .start = 0x0000,
99 .end = 0x001f,
100 .flags = IORESOURCE_BUSY | IORESOURCE_IO
101}, {
102 .name = "pic1",
103 .start = 0x0020,
104 .end = 0x0021,
105 .flags = IORESOURCE_BUSY | IORESOURCE_IO
106}, {
107 .name = "timer0",
108 .start = 0x0040,
109 .end = 0x0043,
110 .flags = IORESOURCE_BUSY | IORESOURCE_IO
111}, {
112 .name = "timer1",
113 .start = 0x0050,
114 .end = 0x0053,
115 .flags = IORESOURCE_BUSY | IORESOURCE_IO
116}, {
117 .name = "keyboard",
118 .start = 0x0060,
119 .end = 0x006f,
120 .flags = IORESOURCE_BUSY | IORESOURCE_IO
121}, {
122 .name = "dma page reg",
123 .start = 0x0080,
124 .end = 0x008f,
125 .flags = IORESOURCE_BUSY | IORESOURCE_IO
126}, {
127 .name = "pic2",
128 .start = 0x00a0,
129 .end = 0x00a1,
130 .flags = IORESOURCE_BUSY | IORESOURCE_IO
131}, {
132 .name = "dma2",
133 .start = 0x00c0,
134 .end = 0x00df,
135 .flags = IORESOURCE_BUSY | IORESOURCE_IO
136}, {
137 .name = "fpu",
138 .start = 0x00f0,
139 .end = 0x00ff,
140 .flags = IORESOURCE_BUSY | IORESOURCE_IO
141} };
142
143#define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
144
145static int __init romchecksum(unsigned char *rom, unsigned long length)
146{
147 unsigned char *p, sum = 0;
148
149 for (p = rom; p < rom + length; p++)
150 sum += *p;
151 return sum == 0;
152}
153
154static void __init probe_roms(void)
155{
156 unsigned long start, length, upper;
157 unsigned char *rom;
158 int i;
159
160 /* video rom */
161 upper = adapter_rom_resources[0].start;
162 for (start = video_rom_resource.start; start < upper; start += 2048) {
163 rom = isa_bus_to_virt(start);
164 if (!romsignature(rom))
165 continue;
166
167 video_rom_resource.start = start;
168
169 /* 0 < length <= 0x7f * 512, historically */
170 length = rom[2] * 512;
171
172 /* if checksum okay, trust length byte */
173 if (length && romchecksum(rom, length))
174 video_rom_resource.end = start + length - 1;
175
176 request_resource(&iomem_resource, &video_rom_resource);
177 break;
178 }
179
180 start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
181 if (start < upper)
182 start = upper;
183
184 /* system rom */
185 request_resource(&iomem_resource, &system_rom_resource);
186 upper = system_rom_resource.start;
187
188 /* check for extension rom (ignore length byte!) */
189 rom = isa_bus_to_virt(extension_rom_resource.start);
190 if (romsignature(rom)) {
191 length = extension_rom_resource.end - extension_rom_resource.start + 1;
192 if (romchecksum(rom, length)) {
193 request_resource(&iomem_resource, &extension_rom_resource);
194 upper = extension_rom_resource.start;
195 }
196 }
197
198 /* check for adapter roms on 2k boundaries */
199 for (i = 0; i < ARRAY_SIZE(adapter_rom_resources) && start < upper; start += 2048) {
200 rom = isa_bus_to_virt(start);
201 if (!romsignature(rom))
202 continue;
203
204 /* 0 < length <= 0x7f * 512, historically */
205 length = rom[2] * 512;
206
207 /* but accept any length that fits if checksum okay */
208 if (!length || start + length > upper || !romchecksum(rom, length))
209 continue;
210
211 adapter_rom_resources[i].start = start;
212 adapter_rom_resources[i].end = start + length - 1;
213 request_resource(&iomem_resource, &adapter_rom_resources[i]);
214
215 start = adapter_rom_resources[i++].end & ~2047UL;
216 }
217}
218
219/*
220 * Request address space for all standard RAM and ROM resources
221 * and also for regions reported as reserved by the e820.
222 */
223static void __init
224legacy_init_iomem_resources(struct resource *code_resource, struct resource *data_resource)
225{
226 int i;
227
228 probe_roms();
229 for (i = 0; i < e820.nr_map; i++) {
230 struct resource *res;
231#ifndef CONFIG_RESOURCES_64BIT
232 if (e820.map[i].addr + e820.map[i].size > 0x100000000ULL)
233 continue;
234#endif
235 res = kzalloc(sizeof(struct resource), GFP_ATOMIC);
236 switch (e820.map[i].type) {
237 case E820_RAM: res->name = "System RAM"; break;
238 case E820_ACPI: res->name = "ACPI Tables"; break;
239 case E820_NVS: res->name = "ACPI Non-volatile Storage"; break;
240 default: res->name = "reserved";
241 }
242 res->start = e820.map[i].addr;
243 res->end = res->start + e820.map[i].size - 1;
244 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
245 if (request_resource(&iomem_resource, res)) {
246 kfree(res);
247 continue;
248 }
249 if (e820.map[i].type == E820_RAM) {
250 /*
251 * We don't know which RAM region contains kernel data,
252 * so we try it repeatedly and let the resource manager
253 * test it.
254 */
255 request_resource(res, code_resource);
256 request_resource(res, data_resource);
257#ifdef CONFIG_KEXEC
258 request_resource(res, &crashk_res);
259#endif
260 }
261 }
262}
263
264/*
265 * Request address space for all standard resources
266 *
267 * This is called just before pcibios_init(), which is also a
268 * subsys_initcall, but is linked in later (in arch/i386/pci/common.c).
269 */
270static int __init request_standard_resources(void)
271{
272 int i;
273
274 printk("Setting up standard PCI resources\n");
275 if (efi_enabled)
276 efi_initialize_iomem_resources(&code_resource, &data_resource);
277 else
278 legacy_init_iomem_resources(&code_resource, &data_resource);
279
280 /* EFI systems may still have VGA */
281 request_resource(&iomem_resource, &video_ram_resource);
282
283 /* request I/O space for devices used on all i[345]86 PCs */
284 for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
285 request_resource(&ioport_resource, &standard_io_resources[i]);
286 return 0;
287}
288
289subsys_initcall(request_standard_resources);
diff --git a/arch/i386/kernel/setup.c b/arch/i386/kernel/setup.c
index 61539afbdf23..acd2d9392abb 100644
--- a/arch/i386/kernel/setup.c
+++ b/arch/i386/kernel/setup.c
@@ -76,11 +76,9 @@ int disable_pse __devinitdata = 0;
76/* 76/*
77 * Machine setup.. 77 * Machine setup..
78 */ 78 */
79 79extern struct e820map e820;
80#ifdef CONFIG_EFI 80extern struct resource code_resource;
81int efi_enabled = 0; 81extern struct resource data_resource;
82EXPORT_SYMBOL(efi_enabled);
83#endif
84 82
85/* cpu data as detected by the assembly code in head.S */ 83/* cpu data as detected by the assembly code in head.S */
86struct cpuinfo_x86 new_cpu_data __initdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 }; 84struct cpuinfo_x86 new_cpu_data __initdata = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
@@ -134,7 +132,6 @@ struct ist_info ist_info;
134 defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE) 132 defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
135EXPORT_SYMBOL(ist_info); 133EXPORT_SYMBOL(ist_info);
136#endif 134#endif
137struct e820map e820;
138 135
139extern void early_cpu_init(void); 136extern void early_cpu_init(void);
140extern int root_mountflags; 137extern int root_mountflags;
@@ -149,203 +146,6 @@ static char command_line[COMMAND_LINE_SIZE];
149 146
150unsigned char __initdata boot_params[PARAM_SIZE]; 147unsigned char __initdata boot_params[PARAM_SIZE];
151 148
152static struct resource data_resource = {
153 .name = "Kernel data",
154 .start = 0,
155 .end = 0,
156 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
157};
158
159static struct resource code_resource = {
160 .name = "Kernel code",
161 .start = 0,
162 .end = 0,
163 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
164};
165
166static struct resource system_rom_resource = {
167 .name = "System ROM",
168 .start = 0xf0000,
169 .end = 0xfffff,
170 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
171};
172
173static struct resource extension_rom_resource = {
174 .name = "Extension ROM",
175 .start = 0xe0000,
176 .end = 0xeffff,
177 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
178};
179
180static struct resource adapter_rom_resources[] = { {
181 .name = "Adapter ROM",
182 .start = 0xc8000,
183 .end = 0,
184 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
185}, {
186 .name = "Adapter ROM",
187 .start = 0,
188 .end = 0,
189 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
190}, {
191 .name = "Adapter ROM",
192 .start = 0,
193 .end = 0,
194 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
195}, {
196 .name = "Adapter ROM",
197 .start = 0,
198 .end = 0,
199 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
200}, {
201 .name = "Adapter ROM",
202 .start = 0,
203 .end = 0,
204 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
205}, {
206 .name = "Adapter ROM",
207 .start = 0,
208 .end = 0,
209 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
210} };
211
212static struct resource video_rom_resource = {
213 .name = "Video ROM",
214 .start = 0xc0000,
215 .end = 0xc7fff,
216 .flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
217};
218
219static struct resource video_ram_resource = {
220 .name = "Video RAM area",
221 .start = 0xa0000,
222 .end = 0xbffff,
223 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
224};
225
226static struct resource standard_io_resources[] = { {
227 .name = "dma1",
228 .start = 0x0000,
229 .end = 0x001f,
230 .flags = IORESOURCE_BUSY | IORESOURCE_IO
231}, {
232 .name = "pic1",
233 .start = 0x0020,
234 .end = 0x0021,
235 .flags = IORESOURCE_BUSY | IORESOURCE_IO
236}, {
237 .name = "timer0",
238 .start = 0x0040,
239 .end = 0x0043,
240 .flags = IORESOURCE_BUSY | IORESOURCE_IO
241}, {
242 .name = "timer1",
243 .start = 0x0050,
244 .end = 0x0053,
245 .flags = IORESOURCE_BUSY | IORESOURCE_IO
246}, {
247 .name = "keyboard",
248 .start = 0x0060,
249 .end = 0x006f,
250 .flags = IORESOURCE_BUSY | IORESOURCE_IO
251}, {
252 .name = "dma page reg",
253 .start = 0x0080,
254 .end = 0x008f,
255 .flags = IORESOURCE_BUSY | IORESOURCE_IO
256}, {
257 .name = "pic2",
258 .start = 0x00a0,
259 .end = 0x00a1,
260 .flags = IORESOURCE_BUSY | IORESOURCE_IO
261}, {
262 .name = "dma2",
263 .start = 0x00c0,
264 .end = 0x00df,
265 .flags = IORESOURCE_BUSY | IORESOURCE_IO
266}, {
267 .name = "fpu",
268 .start = 0x00f0,
269 .end = 0x00ff,
270 .flags = IORESOURCE_BUSY | IORESOURCE_IO
271} };
272
273#define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
274
275static int __init romchecksum(unsigned char *rom, unsigned long length)
276{
277 unsigned char *p, sum = 0;
278
279 for (p = rom; p < rom + length; p++)
280 sum += *p;
281 return sum == 0;
282}
283
284static void __init probe_roms(void)
285{
286 unsigned long start, length, upper;
287 unsigned char *rom;
288 int i;
289
290 /* video rom */
291 upper = adapter_rom_resources[0].start;
292 for (start = video_rom_resource.start; start < upper; start += 2048) {
293 rom = isa_bus_to_virt(start);
294 if (!romsignature(rom))
295 continue;
296
297 video_rom_resource.start = start;
298
299 /* 0 < length <= 0x7f * 512, historically */
300 length = rom[2] * 512;
301
302 /* if checksum okay, trust length byte */
303 if (length && romchecksum(rom, length))
304 video_rom_resource.end = start + length - 1;
305
306 request_resource(&iomem_resource, &video_rom_resource);
307 break;
308 }
309
310 start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
311 if (start < upper)
312 start = upper;
313
314 /* system rom */
315 request_resource(&iomem_resource, &system_rom_resource);
316 upper = system_rom_resource.start;
317
318 /* check for extension rom (ignore length byte!) */
319 rom = isa_bus_to_virt(extension_rom_resource.start);
320 if (romsignature(rom)) {
321 length = extension_rom_resource.end - extension_rom_resource.start + 1;
322 if (romchecksum(rom, length)) {
323 request_resource(&iomem_resource, &extension_rom_resource);
324 upper = extension_rom_resource.start;
325 }
326 }
327
328 /* check for adapter roms on 2k boundaries */
329 for (i = 0; i < ARRAY_SIZE(adapter_rom_resources) && start < upper; start += 2048) {
330 rom = isa_bus_to_virt(start);
331 if (!romsignature(rom))
332 continue;
333
334 /* 0 < length <= 0x7f * 512, historically */
335 length = rom[2] * 512;
336
337 /* but accept any length that fits if checksum okay */
338 if (!length || start + length > upper || !romchecksum(rom, length))
339 continue;
340
341 adapter_rom_resources[i].start = start;
342 adapter_rom_resources[i].end = start + length - 1;
343 request_resource(&iomem_resource, &adapter_rom_resources[i]);
344
345 start = adapter_rom_resources[i++].end & ~2047UL;
346 }
347}
348
349static void __init limit_regions(unsigned long long size) 149static void __init limit_regions(unsigned long long size)
350{ 150{
351 unsigned long long current_addr = 0; 151 unsigned long long current_addr = 0;
@@ -1200,77 +1000,7 @@ void __init remapped_pgdat_init(void)
1200 } 1000 }
1201} 1001}
1202 1002
1203/*
1204 * Request address space for all standard RAM and ROM resources
1205 * and also for regions reported as reserved by the e820.
1206 */
1207static void __init
1208legacy_init_iomem_resources(struct resource *code_resource, struct resource *data_resource)
1209{
1210 int i;
1211
1212 probe_roms();
1213 for (i = 0; i < e820.nr_map; i++) {
1214 struct resource *res;
1215#ifndef CONFIG_RESOURCES_64BIT
1216 if (e820.map[i].addr + e820.map[i].size > 0x100000000ULL)
1217 continue;
1218#endif
1219 res = kzalloc(sizeof(struct resource), GFP_ATOMIC);
1220 switch (e820.map[i].type) {
1221 case E820_RAM: res->name = "System RAM"; break;
1222 case E820_ACPI: res->name = "ACPI Tables"; break;
1223 case E820_NVS: res->name = "ACPI Non-volatile Storage"; break;
1224 default: res->name = "reserved";
1225 }
1226 res->start = e820.map[i].addr;
1227 res->end = res->start + e820.map[i].size - 1;
1228 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
1229 if (request_resource(&iomem_resource, res)) {
1230 kfree(res);
1231 continue;
1232 }
1233 if (e820.map[i].type == E820_RAM) {
1234 /*
1235 * We don't know which RAM region contains kernel data,
1236 * so we try it repeatedly and let the resource manager
1237 * test it.
1238 */
1239 request_resource(res, code_resource);
1240 request_resource(res, data_resource);
1241#ifdef CONFIG_KEXEC
1242 request_resource(res, &crashk_res);
1243#endif
1244 }
1245 }
1246}
1247
1248/*
1249 * Request address space for all standard resources
1250 *
1251 * This is called just before pcibios_init(), which is also a
1252 * subsys_initcall, but is linked in later (in arch/i386/pci/common.c).
1253 */
1254static int __init request_standard_resources(void)
1255{
1256 int i;
1257
1258 printk("Setting up standard PCI resources\n");
1259 if (efi_enabled)
1260 efi_initialize_iomem_resources(&code_resource, &data_resource);
1261 else
1262 legacy_init_iomem_resources(&code_resource, &data_resource);
1263
1264 /* EFI systems may still have VGA */
1265 request_resource(&iomem_resource, &video_ram_resource);
1266
1267 /* request I/O space for devices used on all i[345]86 PCs */
1268 for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
1269 request_resource(&ioport_resource, &standard_io_resources[i]);
1270 return 0;
1271}
1272 1003
1273subsys_initcall(request_standard_resources);
1274 1004
1275static void __init register_memory(void) 1005static void __init register_memory(void)
1276{ 1006{