numa.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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) - min_low_pfn;
  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. * Node 0 sets up its pgdat at the first available pfn,
  37. * and bumps it up before setting up the bootmem allocator.
  38. */
  39. NODE_DATA(0) = pfn_to_kaddr(free_pfn);
  40. memset(NODE_DATA(0), 0, sizeof(struct pglist_data));
  41. free_pfn += PFN_UP(sizeof(struct pglist_data));
  42. NODE_DATA(0)->bdata = &bootmem_node_data[0];
  43. /* Set up node 0 */
  44. setup_bootmem_allocator(free_pfn);
  45. /* Give the platforms a chance to hook up their nodes */
  46. plat_mem_setup();
  47. }
  48. void __init setup_bootmem_node(int nid, unsigned long start, unsigned long end)
  49. {
  50. unsigned long bootmap_pages;
  51. unsigned long start_pfn, end_pfn;
  52. unsigned long bootmem_paddr;
  53. /* Don't allow bogus node assignment */
  54. BUG_ON(nid > MAX_NUMNODES || nid == 0);
  55. start_pfn = start >> PAGE_SHIFT;
  56. end_pfn = end >> PAGE_SHIFT;
  57. lmb_add(start, end - start);
  58. __add_active_range(nid, start_pfn, end_pfn);
  59. /* Node-local pgdat */
  60. NODE_DATA(nid) = __va(lmb_alloc_base(sizeof(struct pglist_data),
  61. SMP_CACHE_BYTES, end_pfn));
  62. memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
  63. NODE_DATA(nid)->bdata = &bootmem_node_data[nid];
  64. NODE_DATA(nid)->node_start_pfn = start_pfn;
  65. NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
  66. /* Node-local bootmap */
  67. bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
  68. bootmem_paddr = lmb_alloc_base(bootmap_pages << PAGE_SHIFT,
  69. PAGE_SIZE, end_pfn);
  70. init_bootmem_node(NODE_DATA(nid), bootmem_paddr >> PAGE_SHIFT,
  71. start_pfn, end_pfn);
  72. free_bootmem_with_active_regions(nid, end_pfn);
  73. /* Reserve the pgdat and bootmap space with the bootmem allocator */
  74. reserve_bootmem_node(NODE_DATA(nid), start_pfn << PAGE_SHIFT,
  75. sizeof(struct pglist_data), BOOTMEM_DEFAULT);
  76. reserve_bootmem_node(NODE_DATA(nid), bootmem_paddr,
  77. bootmap_pages << PAGE_SHIFT, BOOTMEM_DEFAULT);
  78. /* It's up */
  79. node_set_online(nid);
  80. /* Kick sparsemem */
  81. sparse_memory_present_with_active_regions(nid);
  82. }