numa.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * arch/sh/mm/numa.c - Multiple node support for SH machines
  3. *
  4. * Copyright (C) 2007 Paul Mundt
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/bootmem.h>
  12. #include <linux/lmb.h>
  13. #include <linux/mm.h>
  14. #include <linux/numa.h>
  15. #include <linux/pfn.h>
  16. #include <asm/sections.h>
  17. struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
  18. EXPORT_SYMBOL_GPL(node_data);
  19. /*
  20. * On SH machines the conventional approach is to stash system RAM
  21. * in node 0, and other memory blocks in to node 1 and up, ordered by
  22. * latency. Each node's pgdat is node-local at the beginning of the node,
  23. * immediately followed by the node mem map.
  24. */
  25. void __init setup_memory(void)
  26. {
  27. unsigned long free_pfn = PFN_UP(__pa(_end));
  28. u64 base = min_low_pfn << PAGE_SHIFT;
  29. u64 size = (max_low_pfn << PAGE_SHIFT) - base;
  30. lmb_add(base, size);
  31. /* Reserve the LMB regions used by the kernel, initrd, etc.. */
  32. lmb_reserve(__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET,
  33. (PFN_PHYS(free_pfn) + PAGE_SIZE - 1) -
  34. (__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET));
  35. /*
  36. * Reserve physical pages below CONFIG_ZERO_PAGE_OFFSET.
  37. */
  38. if (CONFIG_ZERO_PAGE_OFFSET != 0)
  39. lmb_reserve(__MEMORY_START, CONFIG_ZERO_PAGE_OFFSET);
  40. lmb_analyze();
  41. lmb_dump_all();
  42. /*
  43. * Node 0 sets up its pgdat at the first available pfn,
  44. * and bumps it up before setting up the bootmem allocator.
  45. */
  46. NODE_DATA(0) = pfn_to_kaddr(free_pfn);
  47. memset(NODE_DATA(0), 0, sizeof(struct pglist_data));
  48. free_pfn += PFN_UP(sizeof(struct pglist_data));
  49. NODE_DATA(0)->bdata = &bootmem_node_data[0];
  50. /* Set up node 0 */
  51. setup_bootmem_allocator(free_pfn);
  52. /* Give the platforms a chance to hook up their nodes */
  53. plat_mem_setup();
  54. }
  55. void __init setup_bootmem_node(int nid, unsigned long start, unsigned long end)
  56. {
  57. unsigned long bootmap_pages;
  58. unsigned long start_pfn, end_pfn;
  59. unsigned long bootmem_paddr;
  60. /* Don't allow bogus node assignment */
  61. BUG_ON(nid > MAX_NUMNODES || nid <= 0);
  62. start_pfn = start >> PAGE_SHIFT;
  63. end_pfn = end >> PAGE_SHIFT;
  64. lmb_add(start, end - start);
  65. __add_active_range(nid, start_pfn, end_pfn);
  66. /* Node-local pgdat */
  67. NODE_DATA(nid) = __va(lmb_alloc_base(sizeof(struct pglist_data),
  68. SMP_CACHE_BYTES, end));
  69. memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
  70. NODE_DATA(nid)->bdata = &bootmem_node_data[nid];
  71. NODE_DATA(nid)->node_start_pfn = start_pfn;
  72. NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
  73. /* Node-local bootmap */
  74. bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
  75. bootmem_paddr = lmb_alloc_base(bootmap_pages << PAGE_SHIFT,
  76. PAGE_SIZE, end);
  77. init_bootmem_node(NODE_DATA(nid), bootmem_paddr >> PAGE_SHIFT,
  78. start_pfn, end_pfn);
  79. free_bootmem_with_active_regions(nid, end_pfn);
  80. /* Reserve the pgdat and bootmap space with the bootmem allocator */
  81. reserve_bootmem_node(NODE_DATA(nid), start_pfn << PAGE_SHIFT,
  82. sizeof(struct pglist_data), BOOTMEM_DEFAULT);
  83. reserve_bootmem_node(NODE_DATA(nid), bootmem_paddr,
  84. bootmap_pages << PAGE_SHIFT, BOOTMEM_DEFAULT);
  85. /* It's up */
  86. node_set_online(nid);
  87. /* Kick sparsemem */
  88. sparse_memory_present_with_active_regions(nid);
  89. }