2006-12-06 18:14:06 -07:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/bootmem.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/kexec.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mm.h>
|
2006-12-06 18:14:06 -07:00
|
|
|
#include <linux/pfn.h>
|
2006-12-06 18:14:08 -07:00
|
|
|
#include <linux/uaccess.h>
|
2007-07-21 09:11:09 -06:00
|
|
|
#include <linux/suspend.h>
|
2006-12-06 18:14:06 -07:00
|
|
|
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/e820.h>
|
2007-02-13 05:26:21 -07:00
|
|
|
#include <asm/setup.h>
|
2006-12-06 18:14:06 -07:00
|
|
|
|
|
|
|
static struct resource system_rom_resource = {
|
|
|
|
.name = "System ROM",
|
|
|
|
.start = 0xf0000,
|
|
|
|
.end = 0xfffff,
|
|
|
|
.flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct resource extension_rom_resource = {
|
|
|
|
.name = "Extension ROM",
|
|
|
|
.start = 0xe0000,
|
|
|
|
.end = 0xeffff,
|
|
|
|
.flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct resource adapter_rom_resources[] = { {
|
|
|
|
.name = "Adapter ROM",
|
|
|
|
.start = 0xc8000,
|
|
|
|
.end = 0,
|
|
|
|
.flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
|
|
|
|
}, {
|
|
|
|
.name = "Adapter ROM",
|
|
|
|
.start = 0,
|
|
|
|
.end = 0,
|
|
|
|
.flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
|
|
|
|
}, {
|
|
|
|
.name = "Adapter ROM",
|
|
|
|
.start = 0,
|
|
|
|
.end = 0,
|
|
|
|
.flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
|
|
|
|
}, {
|
|
|
|
.name = "Adapter ROM",
|
|
|
|
.start = 0,
|
|
|
|
.end = 0,
|
|
|
|
.flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
|
|
|
|
}, {
|
|
|
|
.name = "Adapter ROM",
|
|
|
|
.start = 0,
|
|
|
|
.end = 0,
|
|
|
|
.flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
|
|
|
|
}, {
|
|
|
|
.name = "Adapter ROM",
|
|
|
|
.start = 0,
|
|
|
|
.end = 0,
|
|
|
|
.flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
|
|
|
|
} };
|
|
|
|
|
|
|
|
static struct resource video_rom_resource = {
|
|
|
|
.name = "Video ROM",
|
|
|
|
.start = 0xc0000,
|
|
|
|
.end = 0xc7fff,
|
|
|
|
.flags = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
|
|
|
|
};
|
|
|
|
|
2007-02-13 05:26:22 -07:00
|
|
|
#define ROMSIGNATURE 0xaa55
|
|
|
|
|
|
|
|
static int __init romsignature(const unsigned char *rom)
|
2006-12-06 18:14:08 -07:00
|
|
|
{
|
2007-05-02 11:27:05 -06:00
|
|
|
const unsigned short * const ptr = (const unsigned short *)rom;
|
2006-12-06 18:14:08 -07:00
|
|
|
unsigned short sig;
|
2007-02-13 05:26:22 -07:00
|
|
|
|
2007-05-02 11:27:05 -06:00
|
|
|
return probe_kernel_address(ptr, sig) == 0 && sig == ROMSIGNATURE;
|
2006-12-06 18:14:08 -07:00
|
|
|
}
|
2006-12-06 18:14:06 -07:00
|
|
|
|
2007-05-02 11:27:05 -06:00
|
|
|
static int __init romchecksum(const unsigned char *rom, unsigned long length)
|
2006-12-06 18:14:06 -07:00
|
|
|
{
|
2007-05-02 11:27:05 -06:00
|
|
|
unsigned char sum, c;
|
2006-12-06 18:14:06 -07:00
|
|
|
|
2007-05-02 11:27:05 -06:00
|
|
|
for (sum = 0; length && probe_kernel_address(rom++, c) == 0; length--)
|
|
|
|
sum += c;
|
|
|
|
return !length && !sum;
|
2006-12-06 18:14:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __init probe_roms(void)
|
|
|
|
{
|
2007-05-02 11:27:05 -06:00
|
|
|
const unsigned char *rom;
|
2006-12-06 18:14:06 -07:00
|
|
|
unsigned long start, length, upper;
|
2007-05-02 11:27:05 -06:00
|
|
|
unsigned char c;
|
|
|
|
int i;
|
2006-12-06 18:14:06 -07:00
|
|
|
|
|
|
|
/* video rom */
|
|
|
|
upper = adapter_rom_resources[0].start;
|
|
|
|
for (start = video_rom_resource.start; start < upper; start += 2048) {
|
|
|
|
rom = isa_bus_to_virt(start);
|
|
|
|
if (!romsignature(rom))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
video_rom_resource.start = start;
|
|
|
|
|
2007-05-02 11:27:05 -06:00
|
|
|
if (probe_kernel_address(rom + 2, c) != 0)
|
|
|
|
continue;
|
|
|
|
|
2006-12-06 18:14:06 -07:00
|
|
|
/* 0 < length <= 0x7f * 512, historically */
|
2007-05-02 11:27:05 -06:00
|
|
|
length = c * 512;
|
2006-12-06 18:14:06 -07:00
|
|
|
|
|
|
|
/* if checksum okay, trust length byte */
|
|
|
|
if (length && romchecksum(rom, length))
|
|
|
|
video_rom_resource.end = start + length - 1;
|
|
|
|
|
|
|
|
request_resource(&iomem_resource, &video_rom_resource);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
|
|
|
|
if (start < upper)
|
|
|
|
start = upper;
|
|
|
|
|
|
|
|
/* system rom */
|
|
|
|
request_resource(&iomem_resource, &system_rom_resource);
|
|
|
|
upper = system_rom_resource.start;
|
|
|
|
|
|
|
|
/* check for extension rom (ignore length byte!) */
|
|
|
|
rom = isa_bus_to_virt(extension_rom_resource.start);
|
|
|
|
if (romsignature(rom)) {
|
|
|
|
length = extension_rom_resource.end - extension_rom_resource.start + 1;
|
|
|
|
if (romchecksum(rom, length)) {
|
|
|
|
request_resource(&iomem_resource, &extension_rom_resource);
|
|
|
|
upper = extension_rom_resource.start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for adapter roms on 2k boundaries */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(adapter_rom_resources) && start < upper; start += 2048) {
|
|
|
|
rom = isa_bus_to_virt(start);
|
|
|
|
if (!romsignature(rom))
|
|
|
|
continue;
|
|
|
|
|
2007-05-02 11:27:05 -06:00
|
|
|
if (probe_kernel_address(rom + 2, c) != 0)
|
|
|
|
continue;
|
|
|
|
|
2006-12-06 18:14:06 -07:00
|
|
|
/* 0 < length <= 0x7f * 512, historically */
|
2007-05-02 11:27:05 -06:00
|
|
|
length = c * 512;
|
2006-12-06 18:14:06 -07:00
|
|
|
|
|
|
|
/* but accept any length that fits if checksum okay */
|
|
|
|
if (!length || start + length > upper || !romchecksum(rom, length))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
adapter_rom_resources[i].start = start;
|
|
|
|
adapter_rom_resources[i].end = start + length - 1;
|
|
|
|
request_resource(&iomem_resource, &adapter_rom_resources[i]);
|
|
|
|
|
|
|
|
start = adapter_rom_resources[i++].end & ~2047UL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Request address space for all standard RAM and ROM resources
|
|
|
|
* and also for regions reported as reserved by the e820.
|
|
|
|
*/
|
2008-01-30 05:31:19 -07:00
|
|
|
void __init init_iomem_resources(struct resource *code_resource,
|
2008-01-30 05:30:32 -07:00
|
|
|
struct resource *data_resource,
|
|
|
|
struct resource *bss_resource)
|
2006-12-06 18:14:06 -07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
probe_roms();
|
|
|
|
for (i = 0; i < e820.nr_map; i++) {
|
|
|
|
struct resource *res;
|
|
|
|
#ifndef CONFIG_RESOURCES_64BIT
|
|
|
|
if (e820.map[i].addr + e820.map[i].size > 0x100000000ULL)
|
|
|
|
continue;
|
|
|
|
#endif
|
|
|
|
res = kzalloc(sizeof(struct resource), GFP_ATOMIC);
|
|
|
|
switch (e820.map[i].type) {
|
|
|
|
case E820_RAM: res->name = "System RAM"; break;
|
|
|
|
case E820_ACPI: res->name = "ACPI Tables"; break;
|
|
|
|
case E820_NVS: res->name = "ACPI Non-volatile Storage"; break;
|
|
|
|
default: res->name = "reserved";
|
|
|
|
}
|
|
|
|
res->start = e820.map[i].addr;
|
|
|
|
res->end = res->start + e820.map[i].size - 1;
|
|
|
|
res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
|
|
|
|
if (request_resource(&iomem_resource, res)) {
|
|
|
|
kfree(res);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (e820.map[i].type == E820_RAM) {
|
|
|
|
/*
|
|
|
|
* We don't know which RAM region contains kernel data,
|
|
|
|
* so we try it repeatedly and let the resource manager
|
|
|
|
* test it.
|
|
|
|
*/
|
|
|
|
request_resource(res, code_resource);
|
|
|
|
request_resource(res, data_resource);
|
2007-10-21 17:42:01 -06:00
|
|
|
request_resource(res, bss_resource);
|
2006-12-06 18:14:06 -07:00
|
|
|
#ifdef CONFIG_KEXEC
|
2007-10-19 00:40:59 -06:00
|
|
|
if (crashk_res.start != crashk_res.end)
|
|
|
|
request_resource(res, &crashk_res);
|
2006-12-06 18:14:06 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-29 15:24:36 -06:00
|
|
|
#if defined(CONFIG_PM) && defined(CONFIG_HIBERNATION)
|
2007-07-21 09:11:09 -06:00
|
|
|
/**
|
|
|
|
* e820_mark_nosave_regions - Find the ranges of physical addresses that do not
|
|
|
|
* correspond to e820 RAM areas and mark the corresponding pages as nosave for
|
|
|
|
* hibernation.
|
|
|
|
*
|
|
|
|
* This function requires the e820 map to be sorted and without any
|
|
|
|
* overlapping entries and assumes the first e820 area to be RAM.
|
|
|
|
*/
|
|
|
|
void __init e820_mark_nosave_regions(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned long pfn;
|
|
|
|
|
|
|
|
pfn = PFN_DOWN(e820.map[0].addr + e820.map[0].size);
|
|
|
|
for (i = 1; i < e820.nr_map; i++) {
|
|
|
|
struct e820entry *ei = &e820.map[i];
|
|
|
|
|
|
|
|
if (pfn < PFN_UP(ei->addr))
|
|
|
|
register_nosave_region(pfn, PFN_UP(ei->addr));
|
|
|
|
|
|
|
|
pfn = PFN_DOWN(ei->addr + ei->size);
|
|
|
|
if (ei->type != E820_RAM)
|
|
|
|
register_nosave_region(PFN_UP(ei->addr), pfn);
|
|
|
|
|
|
|
|
if (pfn >= max_low_pfn)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-12-06 18:14:06 -07:00
|
|
|
/*
|
|
|
|
* Find the highest page frame number we have available
|
|
|
|
*/
|
2008-04-15 18:29:42 -06:00
|
|
|
void __init propagate_e820_map(void)
|
2006-12-06 18:14:06 -07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
max_pfn = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < e820.nr_map; i++) {
|
|
|
|
unsigned long start, end;
|
|
|
|
/* RAM? */
|
|
|
|
if (e820.map[i].type != E820_RAM)
|
|
|
|
continue;
|
|
|
|
start = PFN_UP(e820.map[i].addr);
|
|
|
|
end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
|
|
|
|
if (start >= end)
|
|
|
|
continue;
|
|
|
|
if (end > max_pfn)
|
|
|
|
max_pfn = end;
|
|
|
|
memory_present(0, start, end);
|
|
|
|
}
|
|
|
|
}
|
2006-12-06 18:14:06 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register fully available low RAM pages with the bootmem allocator.
|
|
|
|
*/
|
|
|
|
void __init register_bootmem_low_pages(unsigned long max_low_pfn)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < e820.nr_map; i++) {
|
|
|
|
unsigned long curr_pfn, last_pfn, size;
|
|
|
|
/*
|
|
|
|
* Reserve usable low memory
|
|
|
|
*/
|
|
|
|
if (e820.map[i].type != E820_RAM)
|
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* We are rounding up the start address of usable memory:
|
|
|
|
*/
|
|
|
|
curr_pfn = PFN_UP(e820.map[i].addr);
|
|
|
|
if (curr_pfn >= max_low_pfn)
|
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* ... and at the end of the usable range downwards:
|
|
|
|
*/
|
|
|
|
last_pfn = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
|
|
|
|
|
|
|
|
if (last_pfn > max_low_pfn)
|
|
|
|
last_pfn = max_low_pfn;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* .. finally, did all the rounding and playing
|
|
|
|
* around just make the area go away?
|
|
|
|
*/
|
|
|
|
if (last_pfn <= curr_pfn)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
size = last_pfn - curr_pfn;
|
|
|
|
free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-06 18:14:11 -07:00
|
|
|
void __init limit_regions(unsigned long long size)
|
|
|
|
{
|
|
|
|
unsigned long long current_addr;
|
2006-12-06 18:14:06 -07:00
|
|
|
int i;
|
|
|
|
|
2008-05-11 01:30:15 -06:00
|
|
|
e820_print_map("limit_regions start");
|
2006-12-06 18:14:06 -07:00
|
|
|
for (i = 0; i < e820.nr_map; i++) {
|
|
|
|
current_addr = e820.map[i].addr + e820.map[i].size;
|
|
|
|
if (current_addr < size)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (e820.map[i].type != E820_RAM)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (e820.map[i].addr >= size) {
|
|
|
|
/*
|
|
|
|
* This region starts past the end of the
|
|
|
|
* requested size, skip it completely.
|
|
|
|
*/
|
|
|
|
e820.nr_map = i;
|
|
|
|
} else {
|
|
|
|
e820.nr_map = i + 1;
|
|
|
|
e820.map[i].size -= current_addr - size;
|
|
|
|
}
|
2008-05-11 01:30:15 -06:00
|
|
|
e820_print_map("limit_regions endfor");
|
2006-12-06 18:14:06 -07:00
|
|
|
return;
|
|
|
|
}
|
2008-05-11 01:30:15 -06:00
|
|
|
e820_print_map("limit_regions endfunc");
|
2006-12-06 18:14:06 -07:00
|
|
|
}
|
|
|
|
|
2008-04-23 07:09:05 -06:00
|
|
|
/* Overridden in paravirt.c if CONFIG_PARAVIRT */
|
|
|
|
char * __init __attribute__((weak)) memory_setup(void)
|
|
|
|
{
|
|
|
|
return machine_specific_memory_setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init setup_memory_map(void)
|
|
|
|
{
|
|
|
|
printk(KERN_INFO "BIOS-provided physical RAM map:\n");
|
2008-05-11 01:30:15 -06:00
|
|
|
e820_print_map(memory_setup());
|
2008-04-23 07:09:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __initdata user_defined_memmap;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "mem=nopentium" disables the 4MB page tables.
|
|
|
|
* "mem=XXX[kKmM]" defines a memory region from HIGH_MEM
|
|
|
|
* to <mem>, overriding the bios size.
|
|
|
|
* "memmap=XXX[KkmM]@XXX[KkmM]" defines a memory region from
|
|
|
|
* <start> to <start>+<mem>, overriding the bios size.
|
|
|
|
*
|
|
|
|
* HPA tells me bootloaders need to parse mem=, so no new
|
|
|
|
* option should be mem= [also see Documentation/i386/boot.txt]
|
|
|
|
*/
|
|
|
|
static int __init parse_mem(char *arg)
|
|
|
|
{
|
|
|
|
if (!arg)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (strcmp(arg, "nopentium") == 0) {
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_PSE);
|
|
|
|
} else {
|
|
|
|
/* If the user specifies memory size, we
|
|
|
|
* limit the BIOS-provided memory map to
|
|
|
|
* that size. exactmap can be used to specify
|
|
|
|
* the exact map. mem=number can be used to
|
|
|
|
* trim the existing memory map.
|
|
|
|
*/
|
|
|
|
unsigned long long mem_size;
|
|
|
|
|
|
|
|
mem_size = memparse(arg, &arg);
|
|
|
|
limit_regions(mem_size);
|
|
|
|
user_defined_memmap = 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_param("mem", parse_mem);
|
|
|
|
|
2006-12-06 18:14:06 -07:00
|
|
|
static int __init parse_memmap(char *arg)
|
|
|
|
{
|
|
|
|
if (!arg)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (strcmp(arg, "exactmap") == 0) {
|
|
|
|
#ifdef CONFIG_CRASH_DUMP
|
|
|
|
/* If we are doing a crash dump, we
|
|
|
|
* still need to know the real mem
|
|
|
|
* size before original memory map is
|
|
|
|
* reset.
|
|
|
|
*/
|
2008-04-15 18:29:42 -06:00
|
|
|
propagate_e820_map();
|
2006-12-06 18:14:06 -07:00
|
|
|
saved_max_pfn = max_pfn;
|
|
|
|
#endif
|
|
|
|
e820.nr_map = 0;
|
|
|
|
user_defined_memmap = 1;
|
|
|
|
} else {
|
|
|
|
/* If the user specifies memory size, we
|
|
|
|
* limit the BIOS-provided memory map to
|
|
|
|
* that size. exactmap can be used to specify
|
|
|
|
* the exact map. mem=number can be used to
|
|
|
|
* trim the existing memory map.
|
|
|
|
*/
|
|
|
|
unsigned long long start_at, mem_size;
|
|
|
|
|
|
|
|
mem_size = memparse(arg, &arg);
|
|
|
|
if (*arg == '@') {
|
|
|
|
start_at = memparse(arg+1, &arg);
|
|
|
|
add_memory_region(start_at, mem_size, E820_RAM);
|
|
|
|
} else if (*arg == '#') {
|
|
|
|
start_at = memparse(arg+1, &arg);
|
|
|
|
add_memory_region(start_at, mem_size, E820_ACPI);
|
|
|
|
} else if (*arg == '$') {
|
|
|
|
start_at = memparse(arg+1, &arg);
|
|
|
|
add_memory_region(start_at, mem_size, E820_RESERVED);
|
|
|
|
} else {
|
|
|
|
limit_regions(mem_size);
|
|
|
|
user_defined_memmap = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_param("memmap", parse_memmap);
|
2008-04-23 07:09:05 -06:00
|
|
|
|
|
|
|
void __init finish_e820_parsing(void)
|
|
|
|
{
|
|
|
|
if (user_defined_memmap) {
|
|
|
|
printk(KERN_INFO "user-defined physical RAM map:\n");
|
2008-05-11 01:30:15 -06:00
|
|
|
e820_print_map("user");
|
2008-04-23 07:09:05 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|