Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[MIPS] IP27: Fix bootmem memory setup

Changes in the generic bootmem code broke memory setup for IP27. This
patch fixes this by replacing lots of special IP27 code with generic
bootmon code. This has been tested only on a single node.

Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Thomas Bogendoerfer and committed by
Ralf Baechle
2bf8ec2d c2719d93

+22 -95
+22 -95
arch/mips/sgi-ip27/ip27-memory.c
··· 33 33 #define SLOT_PFNSHIFT (SLOT_SHIFT - PAGE_SHIFT) 34 34 #define PFN_NASIDSHFT (NASID_SHFT - PAGE_SHIFT) 35 35 36 - #define SLOT_IGNORED 0xffff 37 - 38 - static short __initdata slot_lastfilled_cache[MAX_COMPACT_NODES]; 39 - static unsigned short __initdata slot_psize_cache[MAX_COMPACT_NODES][MAX_MEM_SLOTS]; 40 36 static struct bootmem_data __initdata plat_node_bdata[MAX_COMPACT_NODES]; 41 37 42 38 struct node_data *__node_data[MAX_COMPACT_NODES]; ··· 263 267 return ((pfn_t)nasid << PFN_NASIDSHFT) | (slot << SLOT_PFNSHIFT); 264 268 } 265 269 266 - /* 267 - * Return the number of pages of memory provided by the given slot 268 - * on the specified node. 269 - */ 270 - static pfn_t __init slot_getsize(cnodeid_t node, int slot) 271 - { 272 - return (pfn_t) slot_psize_cache[node][slot]; 273 - } 274 - 275 - /* 276 - * Return highest slot filled 277 - */ 278 - static int __init node_getlastslot(cnodeid_t node) 279 - { 280 - return (int) slot_lastfilled_cache[node]; 281 - } 282 - 283 - /* 284 - * Return the pfn of the last free page of memory on a node. 285 - */ 286 - static pfn_t __init node_getmaxclick(cnodeid_t node) 287 - { 288 - pfn_t slot_psize; 289 - int slot; 290 - 291 - /* 292 - * Start at the top slot. When we find a slot with memory in it, 293 - * that's the winner. 294 - */ 295 - for (slot = (MAX_MEM_SLOTS - 1); slot >= 0; slot--) { 296 - if ((slot_psize = slot_getsize(node, slot))) { 297 - if (slot_psize == SLOT_IGNORED) 298 - continue; 299 - /* Return the basepfn + the slot size, minus 1. */ 300 - return slot_getbasepfn(node, slot) + slot_psize - 1; 301 - } 302 - } 303 - 304 - /* 305 - * If there's no memory on the node, return 0. This is likely 306 - * to cause problems. 307 - */ 308 - return 0; 309 - } 310 - 311 270 static pfn_t __init slot_psize_compute(cnodeid_t node, int slot) 312 271 { 313 272 nasid_t nasid; ··· 355 404 static void __init szmem(void) 356 405 { 357 406 pfn_t slot_psize, slot0sz = 0, nodebytes; /* Hack to detect problem configs */ 358 - int slot, ignore; 407 + int slot; 359 408 cnodeid_t node; 360 409 361 410 num_physpages = 0; 362 411 363 412 for_each_online_node(node) { 364 - ignore = nodebytes = 0; 413 + nodebytes = 0; 365 414 for (slot = 0; slot < MAX_MEM_SLOTS; slot++) { 366 415 slot_psize = slot_psize_compute(node, slot); 367 416 if (slot == 0) ··· 371 420 * kernel text. 372 421 */ 373 422 nodebytes += (1LL << SLOT_SHIFT); 423 + 424 + if (!slot_psize) 425 + continue; 426 + 374 427 if ((nodebytes >> PAGE_SHIFT) * (sizeof(struct page)) > 375 - (slot0sz << PAGE_SHIFT)) 376 - ignore = 1; 377 - if (ignore && slot_psize) { 428 + (slot0sz << PAGE_SHIFT)) { 378 429 printk("Ignoring slot %d onwards on node %d\n", 379 430 slot, node); 380 - slot_psize_cache[node][slot] = SLOT_IGNORED; 381 431 slot = MAX_MEM_SLOTS; 382 432 continue; 383 433 } 384 434 num_physpages += slot_psize; 385 - slot_psize_cache[node][slot] = 386 - (unsigned short) slot_psize; 387 - if (slot_psize) 388 - slot_lastfilled_cache[node] = slot; 435 + add_active_range(node, slot_getbasepfn(node, slot), 436 + slot_getbasepfn(node, slot) + slot_psize); 389 437 } 390 438 } 391 439 } ··· 392 442 static void __init node_mem_init(cnodeid_t node) 393 443 { 394 444 pfn_t slot_firstpfn = slot_getbasepfn(node, 0); 395 - pfn_t slot_lastpfn = slot_firstpfn + slot_getsize(node, 0); 396 445 pfn_t slot_freepfn = node_getfirstfree(node); 397 - struct pglist_data *pd; 398 446 unsigned long bootmap_size; 447 + pfn_t start_pfn, end_pfn; 448 + 449 + get_pfn_range_for_nid(node, &start_pfn, &end_pfn); 399 450 400 451 /* 401 452 * Allocate the node data structures on the node first. 402 453 */ 403 454 __node_data[node] = __va(slot_freepfn << PAGE_SHIFT); 404 455 405 - pd = NODE_DATA(node); 406 - pd->bdata = &plat_node_bdata[node]; 456 + NODE_DATA(node)->bdata = &plat_node_bdata[node]; 457 + NODE_DATA(node)->node_start_pfn = start_pfn; 458 + NODE_DATA(node)->node_spanned_pages = end_pfn - start_pfn; 407 459 408 460 cpus_clear(hub_data(node)->h_cpus); 409 461 ··· 413 461 sizeof(struct hub_data)); 414 462 415 463 bootmap_size = init_bootmem_node(NODE_DATA(node), slot_freepfn, 416 - slot_firstpfn, slot_lastpfn); 417 - free_bootmem_node(NODE_DATA(node), slot_firstpfn << PAGE_SHIFT, 418 - (slot_lastpfn - slot_firstpfn) << PAGE_SHIFT); 464 + start_pfn, end_pfn); 465 + free_bootmem_with_active_regions(node, end_pfn); 419 466 reserve_bootmem_node(NODE_DATA(node), slot_firstpfn << PAGE_SHIFT, 420 467 ((slot_freepfn - slot_firstpfn) << PAGE_SHIFT) + bootmap_size, 421 468 BOOTMEM_DEFAULT); 469 + sparse_memory_present_with_active_regions(node); 422 470 } 423 471 424 472 /* ··· 467 515 pagetable_init(); 468 516 469 517 for_each_online_node(node) { 470 - pfn_t start_pfn = slot_getbasepfn(node, 0); 471 - pfn_t end_pfn = node_getmaxclick(node) + 1; 518 + pfn_t start_pfn, end_pfn; 472 519 473 - zones_size[ZONE_NORMAL] = end_pfn - start_pfn; 474 - free_area_init_node(node, NODE_DATA(node), 475 - zones_size, start_pfn, NULL); 520 + get_pfn_range_for_nid(node, &start_pfn, &end_pfn); 476 521 477 522 if (end_pfn > max_low_pfn) 478 523 max_low_pfn = end_pfn; 479 524 } 525 + zones_size[ZONE_NORMAL] = max_low_pfn; 526 + free_area_init_nodes(zones_size); 480 527 } 481 528 482 529 void __init mem_init(void) ··· 486 535 high_memory = (void *) __va(num_physpages << PAGE_SHIFT); 487 536 488 537 for_each_online_node(node) { 489 - unsigned slot, numslots; 490 - struct page *end, *p; 491 - 492 538 /* 493 539 * This will free up the bootmem, ie, slot 0 memory. 494 540 */ 495 541 totalram_pages += free_all_bootmem_node(NODE_DATA(node)); 496 - 497 - /* 498 - * We need to manually do the other slots. 499 - */ 500 - numslots = node_getlastslot(node); 501 - for (slot = 1; slot <= numslots; slot++) { 502 - p = nid_page_nr(node, slot_getbasepfn(node, slot) - 503 - slot_getbasepfn(node, 0)); 504 - 505 - /* 506 - * Free valid memory in current slot. 507 - */ 508 - for (end = p + slot_getsize(node, slot); p < end; p++) { 509 - /* if (!page_is_ram(pgnr)) continue; */ 510 - /* commented out until page_is_ram works */ 511 - ClearPageReserved(p); 512 - init_page_count(p); 513 - __free_page(p); 514 - totalram_pages++; 515 - } 516 - } 517 542 } 518 543 519 544 totalram_pages -= setup_zero_pages(); /* This comes from node 0 */