x86: clean up arch/x86/kernel/e820_64.c
White space and coding style cleanup. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
committed by
Ingo Molnar
parent
05fccb0e38
commit
2f36fa13ce
@@ -109,8 +109,10 @@ int
|
|||||||
e820_any_mapped(unsigned long start, unsigned long end, unsigned type)
|
e820_any_mapped(unsigned long start, unsigned long end, unsigned type)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < e820.nr_map; i++) {
|
for (i = 0; i < e820.nr_map; i++) {
|
||||||
struct e820entry *ei = &e820.map[i];
|
struct e820entry *ei = &e820.map[i];
|
||||||
|
|
||||||
if (type && ei->type != type)
|
if (type && ei->type != type)
|
||||||
continue;
|
continue;
|
||||||
if (ei->addr >= end || ei->addr + ei->size <= start)
|
if (ei->addr >= end || ei->addr + ei->size <= start)
|
||||||
@@ -127,11 +129,14 @@ EXPORT_SYMBOL_GPL(e820_any_mapped);
|
|||||||
* Note: this function only works correct if the e820 table is sorted and
|
* Note: this function only works correct if the e820 table is sorted and
|
||||||
* not-overlapping, which is the case
|
* not-overlapping, which is the case
|
||||||
*/
|
*/
|
||||||
int __init e820_all_mapped(unsigned long start, unsigned long end, unsigned type)
|
int __init e820_all_mapped(unsigned long start, unsigned long end,
|
||||||
|
unsigned type)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < e820.nr_map; i++) {
|
for (i = 0; i < e820.nr_map; i++) {
|
||||||
struct e820entry *ei = &e820.map[i];
|
struct e820entry *ei = &e820.map[i];
|
||||||
|
|
||||||
if (type && ei->type != type)
|
if (type && ei->type != type)
|
||||||
continue;
|
continue;
|
||||||
/* is the region (part) in overlap with the current region ?*/
|
/* is the region (part) in overlap with the current region ?*/
|
||||||
@@ -143,9 +148,12 @@ int __init e820_all_mapped(unsigned long start, unsigned long end, unsigned type
|
|||||||
*/
|
*/
|
||||||
if (ei->addr <= start)
|
if (ei->addr <= start)
|
||||||
start = ei->addr + ei->size;
|
start = ei->addr + ei->size;
|
||||||
/* if start is now at or beyond end, we're done, full coverage */
|
/*
|
||||||
|
* if start is now at or beyond end, we're done, full
|
||||||
|
* coverage
|
||||||
|
*/
|
||||||
if (start >= end)
|
if (start >= end)
|
||||||
return 1; /* we're done */
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -153,12 +161,15 @@ int __init e820_all_mapped(unsigned long start, unsigned long end, unsigned type
|
|||||||
/*
|
/*
|
||||||
* Find a free area in a specific range.
|
* Find a free area in a specific range.
|
||||||
*/
|
*/
|
||||||
unsigned long __init find_e820_area(unsigned long start, unsigned long end, unsigned size)
|
unsigned long __init find_e820_area(unsigned long start, unsigned long end,
|
||||||
|
unsigned size)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < e820.nr_map; i++) {
|
for (i = 0; i < e820.nr_map; i++) {
|
||||||
struct e820entry *ei = &e820.map[i];
|
struct e820entry *ei = &e820.map[i];
|
||||||
unsigned long addr = ei->addr, last;
|
unsigned long addr = ei->addr, last;
|
||||||
|
|
||||||
if (ei->type != E820_RAM)
|
if (ei->type != E820_RAM)
|
||||||
continue;
|
continue;
|
||||||
if (addr < start)
|
if (addr < start)
|
||||||
@@ -182,7 +193,8 @@ unsigned long __init find_e820_area(unsigned long start, unsigned long end, unsi
|
|||||||
*/
|
*/
|
||||||
unsigned long __init e820_end_of_ram(void)
|
unsigned long __init e820_end_of_ram(void)
|
||||||
{
|
{
|
||||||
unsigned long end_pfn = 0;
|
unsigned long end_pfn;
|
||||||
|
|
||||||
end_pfn = find_max_pfn_with_active_regions();
|
end_pfn = find_max_pfn_with_active_regions();
|
||||||
|
|
||||||
if (end_pfn > end_pfn_map)
|
if (end_pfn > end_pfn_map)
|
||||||
@@ -194,7 +206,7 @@ unsigned long __init e820_end_of_ram(void)
|
|||||||
if (end_pfn > end_pfn_map)
|
if (end_pfn > end_pfn_map)
|
||||||
end_pfn = end_pfn_map;
|
end_pfn = end_pfn_map;
|
||||||
|
|
||||||
printk("end_pfn_map = %lu\n", end_pfn_map);
|
printk(KERN_INFO "end_pfn_map = %lu\n", end_pfn_map);
|
||||||
return end_pfn;
|
return end_pfn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,9 +231,9 @@ void __init e820_reserve_resources(void)
|
|||||||
request_resource(&iomem_resource, res);
|
request_resource(&iomem_resource, res);
|
||||||
if (e820.map[i].type == E820_RAM) {
|
if (e820.map[i].type == E820_RAM) {
|
||||||
/*
|
/*
|
||||||
* We don't know which RAM region contains kernel data,
|
* We don't know which RAM region contains kernel data,
|
||||||
* so we try it repeatedly and let the resource manager
|
* so we try it repeatedly and let the resource manager
|
||||||
* test it.
|
* test it.
|
||||||
*/
|
*/
|
||||||
request_resource(res, &code_resource);
|
request_resource(res, &code_resource);
|
||||||
request_resource(res, &data_resource);
|
request_resource(res, &data_resource);
|
||||||
@@ -349,9 +361,7 @@ unsigned long __init e820_hole_size(unsigned long start, unsigned long end)
|
|||||||
{
|
{
|
||||||
unsigned long start_pfn = start >> PAGE_SHIFT;
|
unsigned long start_pfn = start >> PAGE_SHIFT;
|
||||||
unsigned long end_pfn = end >> PAGE_SHIFT;
|
unsigned long end_pfn = end >> PAGE_SHIFT;
|
||||||
unsigned long ei_startpfn;
|
unsigned long ei_startpfn, ei_endpfn, ram = 0;
|
||||||
unsigned long ei_endpfn;
|
|
||||||
unsigned long ram = 0;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < e820.nr_map; i++) {
|
for (i = 0; i < e820.nr_map; i++) {
|
||||||
@@ -369,22 +379,25 @@ void __init e820_print_map(char *who)
|
|||||||
|
|
||||||
for (i = 0; i < e820.nr_map; i++) {
|
for (i = 0; i < e820.nr_map; i++) {
|
||||||
printk(KERN_INFO " %s: %016Lx - %016Lx ", who,
|
printk(KERN_INFO " %s: %016Lx - %016Lx ", who,
|
||||||
(unsigned long long) e820.map[i].addr,
|
(unsigned long long) e820.map[i].addr,
|
||||||
(unsigned long long) (e820.map[i].addr + e820.map[i].size));
|
(unsigned long long)
|
||||||
|
(e820.map[i].addr + e820.map[i].size));
|
||||||
switch (e820.map[i].type) {
|
switch (e820.map[i].type) {
|
||||||
case E820_RAM: printk("(usable)\n");
|
case E820_RAM:
|
||||||
break;
|
printk(KERN_CONT "(usable)\n");
|
||||||
|
break;
|
||||||
case E820_RESERVED:
|
case E820_RESERVED:
|
||||||
printk("(reserved)\n");
|
printk(KERN_CONT "(reserved)\n");
|
||||||
break;
|
break;
|
||||||
case E820_ACPI:
|
case E820_ACPI:
|
||||||
printk("(ACPI data)\n");
|
printk(KERN_CONT "(ACPI data)\n");
|
||||||
break;
|
break;
|
||||||
case E820_NVS:
|
case E820_NVS:
|
||||||
printk("(ACPI NVS)\n");
|
printk(KERN_CONT "(ACPI NVS)\n");
|
||||||
break;
|
break;
|
||||||
default: printk("type %u\n", e820.map[i].type);
|
default:
|
||||||
break;
|
printk(KERN_CONT "type %u\n", e820.map[i].type);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -392,11 +405,11 @@ void __init e820_print_map(char *who)
|
|||||||
/*
|
/*
|
||||||
* Sanitize the BIOS e820 map.
|
* Sanitize the BIOS e820 map.
|
||||||
*
|
*
|
||||||
* Some e820 responses include overlapping entries. The following
|
* Some e820 responses include overlapping entries. The following
|
||||||
* replaces the original e820 map with a new one, removing overlaps.
|
* replaces the original e820 map with a new one, removing overlaps.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static int __init sanitize_e820_map(struct e820entry * biosmap, char * pnr_map)
|
static int __init sanitize_e820_map(struct e820entry *biosmap, char *pnr_map)
|
||||||
{
|
{
|
||||||
struct change_member {
|
struct change_member {
|
||||||
struct e820entry *pbios; /* pointer to original bios entry */
|
struct e820entry *pbios; /* pointer to original bios entry */
|
||||||
@@ -416,7 +429,8 @@ static int __init sanitize_e820_map(struct e820entry * biosmap, char * pnr_map)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Visually we're performing the following (1,2,3,4 = memory types)...
|
Visually we're performing the following
|
||||||
|
(1,2,3,4 = memory types)...
|
||||||
|
|
||||||
Sample memory map (w/overlaps):
|
Sample memory map (w/overlaps):
|
||||||
____22__________________
|
____22__________________
|
||||||
@@ -458,22 +472,23 @@ static int __init sanitize_e820_map(struct e820entry * biosmap, char * pnr_map)
|
|||||||
old_nr = *pnr_map;
|
old_nr = *pnr_map;
|
||||||
|
|
||||||
/* bail out if we find any unreasonable addresses in bios map */
|
/* bail out if we find any unreasonable addresses in bios map */
|
||||||
for (i=0; i<old_nr; i++)
|
for (i = 0; i < old_nr; i++)
|
||||||
if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
|
if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* create pointers for initial change-point information (for sorting) */
|
/* create pointers for initial change-point information (for sorting) */
|
||||||
for (i=0; i < 2*old_nr; i++)
|
for (i = 0; i < 2 * old_nr; i++)
|
||||||
change_point[i] = &change_point_list[i];
|
change_point[i] = &change_point_list[i];
|
||||||
|
|
||||||
/* record all known change-points (starting and ending addresses),
|
/* record all known change-points (starting and ending addresses),
|
||||||
omitting those that are for empty memory regions */
|
omitting those that are for empty memory regions */
|
||||||
chgidx = 0;
|
chgidx = 0;
|
||||||
for (i=0; i < old_nr; i++) {
|
for (i = 0; i < old_nr; i++) {
|
||||||
if (biosmap[i].size != 0) {
|
if (biosmap[i].size != 0) {
|
||||||
change_point[chgidx]->addr = biosmap[i].addr;
|
change_point[chgidx]->addr = biosmap[i].addr;
|
||||||
change_point[chgidx++]->pbios = &biosmap[i];
|
change_point[chgidx++]->pbios = &biosmap[i];
|
||||||
change_point[chgidx]->addr = biosmap[i].addr + biosmap[i].size;
|
change_point[chgidx]->addr = biosmap[i].addr +
|
||||||
|
biosmap[i].size;
|
||||||
change_point[chgidx++]->pbios = &biosmap[i];
|
change_point[chgidx++]->pbios = &biosmap[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -483,75 +498,106 @@ static int __init sanitize_e820_map(struct e820entry * biosmap, char * pnr_map)
|
|||||||
still_changing = 1;
|
still_changing = 1;
|
||||||
while (still_changing) {
|
while (still_changing) {
|
||||||
still_changing = 0;
|
still_changing = 0;
|
||||||
for (i=1; i < chg_nr; i++) {
|
for (i = 1; i < chg_nr; i++) {
|
||||||
/* if <current_addr> > <last_addr>, swap */
|
unsigned long long curaddr, lastaddr;
|
||||||
/* or, if current=<start_addr> & last=<end_addr>, swap */
|
unsigned long long curpbaddr, lastpbaddr;
|
||||||
if ((change_point[i]->addr < change_point[i-1]->addr) ||
|
|
||||||
((change_point[i]->addr == change_point[i-1]->addr) &&
|
curaddr = change_point[i]->addr;
|
||||||
(change_point[i]->addr == change_point[i]->pbios->addr) &&
|
lastaddr = change_point[i - 1]->addr;
|
||||||
(change_point[i-1]->addr != change_point[i-1]->pbios->addr))
|
curpbaddr = change_point[i]->pbios->addr;
|
||||||
)
|
lastpbaddr = change_point[i - 1]->pbios->addr;
|
||||||
{
|
|
||||||
|
/*
|
||||||
|
* swap entries, when:
|
||||||
|
*
|
||||||
|
* curaddr > lastaddr or
|
||||||
|
* curaddr == lastaddr and curaddr == curpbaddr and
|
||||||
|
* lastaddr != lastpbaddr
|
||||||
|
*/
|
||||||
|
if (curaddr < lastaddr ||
|
||||||
|
(curaddr == lastaddr && curaddr == curpbaddr &&
|
||||||
|
lastaddr != lastpbaddr)) {
|
||||||
change_tmp = change_point[i];
|
change_tmp = change_point[i];
|
||||||
change_point[i] = change_point[i-1];
|
change_point[i] = change_point[i-1];
|
||||||
change_point[i-1] = change_tmp;
|
change_point[i-1] = change_tmp;
|
||||||
still_changing=1;
|
still_changing = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create a new bios memory map, removing overlaps */
|
/* create a new bios memory map, removing overlaps */
|
||||||
overlap_entries=0; /* number of entries in the overlap table */
|
overlap_entries = 0; /* number of entries in the overlap table */
|
||||||
new_bios_entry=0; /* index for creating new bios map entries */
|
new_bios_entry = 0; /* index for creating new bios map entries */
|
||||||
last_type = 0; /* start with undefined memory type */
|
last_type = 0; /* start with undefined memory type */
|
||||||
last_addr = 0; /* start with 0 as last starting address */
|
last_addr = 0; /* start with 0 as last starting address */
|
||||||
|
|
||||||
/* loop through change-points, determining affect on the new bios map */
|
/* loop through change-points, determining affect on the new bios map */
|
||||||
for (chgidx=0; chgidx < chg_nr; chgidx++)
|
for (chgidx = 0; chgidx < chg_nr; chgidx++) {
|
||||||
{
|
|
||||||
/* keep track of all overlapping bios entries */
|
/* keep track of all overlapping bios entries */
|
||||||
if (change_point[chgidx]->addr == change_point[chgidx]->pbios->addr)
|
if (change_point[chgidx]->addr ==
|
||||||
{
|
change_point[chgidx]->pbios->addr) {
|
||||||
/* add map entry to overlap list (> 1 entry implies an overlap) */
|
/*
|
||||||
overlap_list[overlap_entries++]=change_point[chgidx]->pbios;
|
* add map entry to overlap list (> 1 entry
|
||||||
}
|
* implies an overlap)
|
||||||
else
|
*/
|
||||||
{
|
overlap_list[overlap_entries++] =
|
||||||
/* remove entry from list (order independent, so swap with last) */
|
change_point[chgidx]->pbios;
|
||||||
for (i=0; i<overlap_entries; i++)
|
} else {
|
||||||
{
|
/*
|
||||||
if (overlap_list[i] == change_point[chgidx]->pbios)
|
* remove entry from list (order independent,
|
||||||
overlap_list[i] = overlap_list[overlap_entries-1];
|
* so swap with last)
|
||||||
|
*/
|
||||||
|
for (i = 0; i < overlap_entries; i++) {
|
||||||
|
if (overlap_list[i] ==
|
||||||
|
change_point[chgidx]->pbios)
|
||||||
|
overlap_list[i] =
|
||||||
|
overlap_list[overlap_entries-1];
|
||||||
}
|
}
|
||||||
overlap_entries--;
|
overlap_entries--;
|
||||||
}
|
}
|
||||||
/* if there are overlapping entries, decide which "type" to use */
|
/*
|
||||||
/* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
|
* if there are overlapping entries, decide which
|
||||||
|
* "type" to use (larger value takes precedence --
|
||||||
|
* 1=usable, 2,3,4,4+=unusable)
|
||||||
|
*/
|
||||||
current_type = 0;
|
current_type = 0;
|
||||||
for (i=0; i<overlap_entries; i++)
|
for (i = 0; i < overlap_entries; i++)
|
||||||
if (overlap_list[i]->type > current_type)
|
if (overlap_list[i]->type > current_type)
|
||||||
current_type = overlap_list[i]->type;
|
current_type = overlap_list[i]->type;
|
||||||
/* continue building up new bios map based on this information */
|
/*
|
||||||
|
* continue building up new bios map based on this
|
||||||
|
* information
|
||||||
|
*/
|
||||||
if (current_type != last_type) {
|
if (current_type != last_type) {
|
||||||
if (last_type != 0) {
|
if (last_type != 0) {
|
||||||
new_bios[new_bios_entry].size =
|
new_bios[new_bios_entry].size =
|
||||||
change_point[chgidx]->addr - last_addr;
|
change_point[chgidx]->addr - last_addr;
|
||||||
/* move forward only if the new size was non-zero */
|
/*
|
||||||
|
* move forward only if the new size
|
||||||
|
* was non-zero
|
||||||
|
*/
|
||||||
if (new_bios[new_bios_entry].size != 0)
|
if (new_bios[new_bios_entry].size != 0)
|
||||||
|
/*
|
||||||
|
* no more space left for new
|
||||||
|
* bios entries ?
|
||||||
|
*/
|
||||||
if (++new_bios_entry >= E820MAX)
|
if (++new_bios_entry >= E820MAX)
|
||||||
break; /* no more space left for new bios entries */
|
break;
|
||||||
}
|
}
|
||||||
if (current_type != 0) {
|
if (current_type != 0) {
|
||||||
new_bios[new_bios_entry].addr = change_point[chgidx]->addr;
|
new_bios[new_bios_entry].addr =
|
||||||
|
change_point[chgidx]->addr;
|
||||||
new_bios[new_bios_entry].type = current_type;
|
new_bios[new_bios_entry].type = current_type;
|
||||||
last_addr=change_point[chgidx]->addr;
|
last_addr = change_point[chgidx]->addr;
|
||||||
}
|
}
|
||||||
last_type = current_type;
|
last_type = current_type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
new_nr = new_bios_entry; /* retain count for new bios entries */
|
/* retain count for new bios entries */
|
||||||
|
new_nr = new_bios_entry;
|
||||||
|
|
||||||
/* copy new bios mapping into original location */
|
/* copy new bios mapping into original location */
|
||||||
memcpy(biosmap, new_bios, new_nr*sizeof(struct e820entry));
|
memcpy(biosmap, new_bios, new_nr * sizeof(struct e820entry));
|
||||||
*pnr_map = new_nr;
|
*pnr_map = new_nr;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -566,7 +612,7 @@ static int __init sanitize_e820_map(struct e820entry * biosmap, char * pnr_map)
|
|||||||
* will have given us a memory map that we can use to properly
|
* will have given us a memory map that we can use to properly
|
||||||
* set up memory. If we aren't, we'll fake a memory map.
|
* set up memory. If we aren't, we'll fake a memory map.
|
||||||
*/
|
*/
|
||||||
static int __init copy_e820_map(struct e820entry * biosmap, int nr_map)
|
static int __init copy_e820_map(struct e820entry *biosmap, int nr_map)
|
||||||
{
|
{
|
||||||
/* Only one memory region (or negative)? Ignore it */
|
/* Only one memory region (or negative)? Ignore it */
|
||||||
if (nr_map < 2)
|
if (nr_map < 2)
|
||||||
@@ -583,7 +629,7 @@ static int __init copy_e820_map(struct e820entry * biosmap, int nr_map)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
add_memory_region(start, size, type);
|
add_memory_region(start, size, type);
|
||||||
} while (biosmap++,--nr_map);
|
} while (biosmap++, --nr_map);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -627,9 +673,9 @@ static int __init parse_memmap_opt(char *p)
|
|||||||
|
|
||||||
if (!strcmp(p, "exactmap")) {
|
if (!strcmp(p, "exactmap")) {
|
||||||
#ifdef CONFIG_CRASH_DUMP
|
#ifdef CONFIG_CRASH_DUMP
|
||||||
/* If we are doing a crash dump, we
|
/*
|
||||||
* still need to know the real mem
|
* If we are doing a crash dump, we still need to know
|
||||||
* size before original memory map is
|
* the real mem size before original memory map is
|
||||||
* reset.
|
* reset.
|
||||||
*/
|
*/
|
||||||
e820_register_active_regions(0, 0, -1UL);
|
e820_register_active_regions(0, 0, -1UL);
|
||||||
@@ -713,8 +759,10 @@ __init void e820_setup_gap(void)
|
|||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
gapstart = (end_pfn << PAGE_SHIFT) + 1024*1024;
|
gapstart = (end_pfn << PAGE_SHIFT) + 1024*1024;
|
||||||
printk(KERN_ERR "PCI: Warning: Cannot find a gap in the 32bit address range\n"
|
printk(KERN_ERR "PCI: Warning: Cannot find a gap in the 32bit "
|
||||||
KERN_ERR "PCI: Unassigned devices with 32bit resource registers may break!\n");
|
"address range\n"
|
||||||
|
KERN_ERR "PCI: Unassigned devices with 32bit resource "
|
||||||
|
"registers may break!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -727,8 +775,9 @@ __init void e820_setup_gap(void)
|
|||||||
/* Fun with two's complement */
|
/* Fun with two's complement */
|
||||||
pci_mem_start = (gapstart + round) & -round;
|
pci_mem_start = (gapstart + round) & -round;
|
||||||
|
|
||||||
printk(KERN_INFO "Allocating PCI resources starting at %lx (gap: %lx:%lx)\n",
|
printk(KERN_INFO
|
||||||
pci_mem_start, gapstart, gapsize);
|
"Allocating PCI resources starting at %lx (gap: %lx:%lx)\n",
|
||||||
|
pci_mem_start, gapstart, gapsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
int __init arch_get_ram_range(int slot, u64 *addr, u64 *size)
|
int __init arch_get_ram_range(int slot, u64 *addr, u64 *size)
|
||||||
|
Reference in New Issue
Block a user