aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2017-01-28 12:35:24 -0500
committerIngo Molnar <mingo@kernel.org>2017-01-28 16:55:24 -0500
commit9a02fd0f1efbace5939bc34c4080a175e8112e8c (patch)
tree49f94ae019f3e3ae82595984d1d92a99de1b29b4
parentf9748fa045851041ba69a1d2899971746f29c9d5 (diff)
x86/boot/e820: Clean up __e820__update_table() et al
The __e820__update_table() function has various weirdly named variables, such as 'pbios', 'biosmap' and 'pnr_map' which are pretty confusing and actively misleading at times. This weird naming found its way into other functions as well, such as __append_e820_table() and append_e820_table(). Standardize the naming to make it all much easier to read: biosmap -> entries pbios -> entry nr_map -> nr_entries pnr_map -> nr_entries ... Also clean up the types used: entry indices routinely mixed u32 and int, standardize on u32 thoughout. Update the comments as well, while at it. No change in functionality. Cc: Alex Thorlton <athorlton@sgi.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Huang, Ying <ying.huang@intel.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Juergen Gross <jgross@suse.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul Jackson <pj@sgi.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rafael J. Wysocki <rjw@sisk.pl> Cc: Tejun Heo <tj@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Wei Yang <richard.weiyang@gmail.com> Cc: Yinghai Lu <yinghai@kernel.org> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/kernel/e820.c120
1 files changed, 61 insertions, 59 deletions
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 49823e0a7aea..7dc430c03acb 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -175,23 +175,23 @@ void __init e820__print_table(char *who)
175} 175}
176 176
177/* 177/*
178 * Sanitize the BIOS E820 map. 178 * Sanitize an E820 map.
179 * 179 *
180 * Some E820 responses include overlapping entries. The following 180 * Some E820 layouts include overlapping entries. The following
181 * replaces the original E820 map with a new one, removing overlaps, 181 * replaces the original E820 map with a new one, removing overlaps,
182 * and resolving conflicting memory types in favor of highest 182 * and resolving conflicting memory types in favor of highest
183 * numbered type. 183 * numbered type.
184 * 184 *
185 * The input parameter biosmap points to an array of 'struct 185 * The input parameter 'entries' points to an array of 'struct
186 * e820_entry' which on entry has elements in the range [0, *pnr_map) 186 * e820_entry' which on entry has elements in the range [0, *nr_entries)
187 * valid, and which has space for up to max_nr_map entries. 187 * valid, and which has space for up to max_nr_entries entries.
188 * On return, the resulting sanitized E820 map entries will be in 188 * On return, the resulting sanitized E820 map entries will be in
189 * overwritten in the same location, starting at biosmap. 189 * overwritten in the same location, starting at 'entries'.
190 * 190 *
191 * The integer pointed to by pnr_map must be valid on entry (the 191 * The integer pointed to by nr_entries must be valid on entry (the
192 * current number of valid entries located at biosmap). If the 192 * current number of valid entries located at 'entries'). If the
193 * sanitizing succeeds the *pnr_map will be updated with the new 193 * sanitizing succeeds the *nr_entries will be updated with the new
194 * number of valid entries (something no more than max_nr_map). 194 * number of valid entries (something no more than max_nr_entries).
195 * 195 *
196 * The return value from e820__update_table() is zero if it 196 * The return value from e820__update_table() is zero if it
197 * successfully 'sanitized' the map entries passed in, and is -1 197 * successfully 'sanitized' the map entries passed in, and is -1
@@ -236,8 +236,8 @@ void __init e820__print_table(char *who)
236 * ______________________4_ 236 * ______________________4_
237 */ 237 */
238struct change_member { 238struct change_member {
239 /* Pointer to the original BIOS entry: */ 239 /* Pointer to the original entry: */
240 struct e820_entry *pbios; 240 struct e820_entry *entry;
241 /* Address for this change point: */ 241 /* Address for this change point: */
242 unsigned long long addr; 242 unsigned long long addr;
243}; 243};
@@ -256,33 +256,33 @@ static int __init cpcompare(const void *a, const void *b)
256 if (ap->addr != bp->addr) 256 if (ap->addr != bp->addr)
257 return ap->addr > bp->addr ? 1 : -1; 257 return ap->addr > bp->addr ? 1 : -1;
258 258
259 return (ap->addr != ap->pbios->addr) - (bp->addr != bp->pbios->addr); 259 return (ap->addr != ap->entry->addr) - (bp->addr != bp->entry->addr);
260} 260}
261 261
262static int __init __e820__update_table(struct e820_entry *biosmap, int max_nr_map, u32 *pnr_map) 262static int __init __e820__update_table(struct e820_entry *entries, u32 max_nr_entries, u32 *nr_entries)
263{ 263{
264 static struct change_member change_point_list[2*E820_MAX_ENTRIES] __initdata; 264 static struct change_member change_point_list[2*E820_MAX_ENTRIES] __initdata;
265 static struct change_member *change_point[2*E820_MAX_ENTRIES] __initdata; 265 static struct change_member *change_point[2*E820_MAX_ENTRIES] __initdata;
266 static struct e820_entry *overlap_list[E820_MAX_ENTRIES] __initdata; 266 static struct e820_entry *overlap_list[E820_MAX_ENTRIES] __initdata;
267 static struct e820_entry new_bios[E820_MAX_ENTRIES] __initdata; 267 static struct e820_entry new_entries[E820_MAX_ENTRIES] __initdata;
268 enum e820_type current_type, last_type; 268 enum e820_type current_type, last_type;
269 unsigned long long last_addr; 269 unsigned long long last_addr;
270 int chgidx; 270 u32 chgidx;
271 int overlap_entries; 271 u32 overlap_entries;
272 int new_bios_entry; 272 u32 new_nr_entries;
273 int old_nr, new_nr, chg_nr; 273 u32 old_nr, new_nr, chg_nr;
274 int i; 274 u32 i;
275 275
276 /* If there's only one memory region, don't bother: */ 276 /* If there's only one memory region, don't bother: */
277 if (*pnr_map < 2) 277 if (*nr_entries < 2)
278 return -1; 278 return -1;
279 279
280 old_nr = *pnr_map; 280 old_nr = *nr_entries;
281 BUG_ON(old_nr > max_nr_map); 281 BUG_ON(old_nr > max_nr_entries);
282 282
283 /* Bail out if we find any unreasonable addresses in the BIOS map: */ 283 /* Bail out if we find any unreasonable addresses in the map: */
284 for (i = 0; i < old_nr; i++) { 284 for (i = 0; i < old_nr; i++) {
285 if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr) 285 if (entries[i].addr + entries[i].size < entries[i].addr)
286 return -1; 286 return -1;
287 } 287 }
288 288
@@ -296,11 +296,11 @@ static int __init __e820__update_table(struct e820_entry *biosmap, int max_nr_ma
296 */ 296 */
297 chgidx = 0; 297 chgidx = 0;
298 for (i = 0; i < old_nr; i++) { 298 for (i = 0; i < old_nr; i++) {
299 if (biosmap[i].size != 0) { 299 if (entries[i].size != 0) {
300 change_point[chgidx]->addr = biosmap[i].addr; 300 change_point[chgidx]->addr = entries[i].addr;
301 change_point[chgidx++]->pbios = &biosmap[i]; 301 change_point[chgidx++]->entry = &entries[i];
302 change_point[chgidx]->addr = biosmap[i].addr + biosmap[i].size; 302 change_point[chgidx]->addr = entries[i].addr + entries[i].size;
303 change_point[chgidx++]->pbios = &biosmap[i]; 303 change_point[chgidx++]->entry = &entries[i];
304 } 304 }
305 } 305 }
306 chg_nr = chgidx; 306 chg_nr = chgidx;
@@ -308,22 +308,22 @@ static int __init __e820__update_table(struct e820_entry *biosmap, int max_nr_ma
308 /* Sort change-point list by memory addresses (low -> high): */ 308 /* Sort change-point list by memory addresses (low -> high): */
309 sort(change_point, chg_nr, sizeof(*change_point), cpcompare, NULL); 309 sort(change_point, chg_nr, sizeof(*change_point), cpcompare, NULL);
310 310
311 /* Create a new BIOS memory map, removing overlaps: */ 311 /* Create a new memory map, removing overlaps: */
312 overlap_entries = 0; /* Number of entries in the overlap table */ 312 overlap_entries = 0; /* Number of entries in the overlap table */
313 new_bios_entry = 0; /* Index for creating new bios map entries */ 313 new_nr_entries = 0; /* Index for creating new map entries */
314 last_type = 0; /* Start with undefined memory type */ 314 last_type = 0; /* Start with undefined memory type */
315 last_addr = 0; /* Start with 0 as last starting address */ 315 last_addr = 0; /* Start with 0 as last starting address */
316 316
317 /* Loop through change-points, determining effect on the new BIOS map: */ 317 /* Loop through change-points, determining effect on the new map: */
318 for (chgidx = 0; chgidx < chg_nr; chgidx++) { 318 for (chgidx = 0; chgidx < chg_nr; chgidx++) {
319 /* Keep track of all overlapping BIOS entries */ 319 /* Keep track of all overlapping entries */
320 if (change_point[chgidx]->addr == change_point[chgidx]->pbios->addr) { 320 if (change_point[chgidx]->addr == change_point[chgidx]->entry->addr) {
321 /* Add map entry to overlap list (> 1 entry implies an overlap) */ 321 /* Add map entry to overlap list (> 1 entry implies an overlap) */
322 overlap_list[overlap_entries++] = change_point[chgidx]->pbios; 322 overlap_list[overlap_entries++] = change_point[chgidx]->entry;
323 } else { 323 } else {
324 /* Remove entry from list (order independent, so swap with last): */ 324 /* Remove entry from list (order independent, so swap with last): */
325 for (i = 0; i < overlap_entries; i++) { 325 for (i = 0; i < overlap_entries; i++) {
326 if (overlap_list[i] == change_point[chgidx]->pbios) 326 if (overlap_list[i] == change_point[chgidx]->entry)
327 overlap_list[i] = overlap_list[overlap_entries-1]; 327 overlap_list[i] = overlap_list[overlap_entries-1];
328 } 328 }
329 overlap_entries--; 329 overlap_entries--;
@@ -339,31 +339,31 @@ static int __init __e820__update_table(struct e820_entry *biosmap, int max_nr_ma
339 current_type = overlap_list[i]->type; 339 current_type = overlap_list[i]->type;
340 } 340 }
341 341
342 /* Continue building up new BIOS map based on this information: */ 342 /* Continue building up new map based on this information: */
343 if (current_type != last_type || current_type == E820_TYPE_PRAM) { 343 if (current_type != last_type || current_type == E820_TYPE_PRAM) {
344 if (last_type != 0) { 344 if (last_type != 0) {
345 new_bios[new_bios_entry].size = change_point[chgidx]->addr - last_addr; 345 new_entries[new_nr_entries].size = change_point[chgidx]->addr - last_addr;
346 /* Move forward only if the new size was non-zero: */ 346 /* Move forward only if the new size was non-zero: */
347 if (new_bios[new_bios_entry].size != 0) 347 if (new_entries[new_nr_entries].size != 0)
348 /* No more space left for new BIOS entries? */ 348 /* No more space left for new entries? */
349 if (++new_bios_entry >= max_nr_map) 349 if (++new_nr_entries >= max_nr_entries)
350 break; 350 break;
351 } 351 }
352 if (current_type != 0) { 352 if (current_type != 0) {
353 new_bios[new_bios_entry].addr = change_point[chgidx]->addr; 353 new_entries[new_nr_entries].addr = change_point[chgidx]->addr;
354 new_bios[new_bios_entry].type = current_type; 354 new_entries[new_nr_entries].type = current_type;
355 last_addr = change_point[chgidx]->addr; 355 last_addr = change_point[chgidx]->addr;
356 } 356 }
357 last_type = current_type; 357 last_type = current_type;
358 } 358 }
359 } 359 }
360 360
361 /* Retain count for new BIOS entries: */ 361 /* Retain count for the new entries: */
362 new_nr = new_bios_entry; 362 new_nr = new_nr_entries;
363 363
364 /* Copy new BIOS mapping into the original location: */ 364 /* Copy the new entries into the original location: */
365 memcpy(biosmap, new_bios, new_nr*sizeof(*biosmap)); 365 memcpy(entries, new_entries, new_nr*sizeof(*entries));
366 *pnr_map = new_nr; 366 *nr_entries = new_nr;
367 367
368 return 0; 368 return 0;
369} 369}
@@ -373,13 +373,15 @@ int __init e820__update_table(struct e820_table *table)
373 return __e820__update_table(table->entries, ARRAY_SIZE(table->entries), &table->nr_entries); 373 return __e820__update_table(table->entries, ARRAY_SIZE(table->entries), &table->nr_entries);
374} 374}
375 375
376static int __init __append_e820_table(struct e820_entry *biosmap, int nr_map) 376static int __init __append_e820_table(struct e820_entry *entries, u32 nr_entries)
377{ 377{
378 while (nr_map) { 378 struct e820_entry *entry = entries;
379 u64 start = biosmap->addr; 379
380 u64 size = biosmap->size; 380 while (nr_entries) {
381 u64 start = entry->addr;
382 u64 size = entry->size;
381 u64 end = start + size - 1; 383 u64 end = start + size - 1;
382 u32 type = biosmap->type; 384 u32 type = entry->type;
383 385
384 /* Ignore the entry on 64-bit overflow: */ 386 /* Ignore the entry on 64-bit overflow: */
385 if (start > end && likely(size)) 387 if (start > end && likely(size))
@@ -387,8 +389,8 @@ static int __init __append_e820_table(struct e820_entry *biosmap, int nr_map)
387 389
388 e820__range_add(start, size, type); 390 e820__range_add(start, size, type);
389 391
390 biosmap++; 392 entry++;
391 nr_map--; 393 nr_entries--;
392 } 394 }
393 return 0; 395 return 0;
394} 396}
@@ -402,13 +404,13 @@ static int __init __append_e820_table(struct e820_entry *biosmap, int nr_map)
402 * will have given us a memory map that we can use to properly 404 * will have given us a memory map that we can use to properly
403 * set up memory. If we aren't, we'll fake a memory map. 405 * set up memory. If we aren't, we'll fake a memory map.
404 */ 406 */
405static int __init append_e820_table(struct e820_entry *biosmap, int nr_map) 407static int __init append_e820_table(struct e820_entry *entries, u32 nr_entries)
406{ 408{
407 /* Only one memory region (or negative)? Ignore it */ 409 /* Only one memory region (or negative)? Ignore it */
408 if (nr_map < 2) 410 if (nr_entries < 2)
409 return -1; 411 return -1;
410 412
411 return __append_e820_table(biosmap, nr_map); 413 return __append_e820_table(entries, nr_entries);
412} 414}
413 415
414static u64 __init 416static u64 __init