numa.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/mm.h>
  13. #include <linux/numa.h>
  14. #include <linux/pfn.h>
  15. #include <asm/sections.h>
  16. struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
  17. EXPORT_SYMBOL_GPL(node_data);
  18. /*
  19. * On SH machines the conventional approach is to stash system RAM
  20. * in node 0, and other memory blocks in to node 1 and up, ordered by
  21. * latency. Each node's pgdat is node-local at the beginning of the node,
  22. * immediately followed by the node mem map.
  23. */
  24. void __init setup_memory(void)
  25. {
  26. unsigned long free_pfn = PFN_UP(__pa(_end));
  27. /*
  28. * Node 0 sets up its pgdat at the first available pfn,
  29. * and bumps it up before setting up the bootmem allocator.
  30. */
  31. NODE_DATA(0) = pfn_to_kaddr(free_pfn);
  32. memset(NODE_DATA(0), 0, sizeof(struct pglist_data));
  33. free_pfn += PFN_UP(sizeof(struct pglist_data));
  34. NODE_DATA(0)->bdata = &bootmem_node_data[0];
  35. /* Set up node 0 */
  36. setup_bootmem_allocator(free_pfn);
  37. /* Give the platforms a chance to hook up their nodes */
  38. plat_mem_setup();
  39. }
  40. void __init setup_bootmem_node(int nid, unsigned long start, unsigned long end)
  41. {
  42. unsigned long bootmap_pages, bootmap_start, bootmap_size;
  43. unsigned long start_pfn, free_pfn, end_pfn;
  44. /* Don't allow bogus node assignment */
  45. BUG_ON(nid > MAX_NUMNODES || nid == 0);
  46. /*
  47. * The free pfn starts at the beginning of the range, and is
  48. * advanced as necessary for pgdat and node map allocations.
  49. */
  50. free_pfn = start_pfn = start >> PAGE_SHIFT;
  51. end_pfn = end >> PAGE_SHIFT;
  52. __add_active_range(nid, start_pfn, end_pfn);
  53. /* Node-local pgdat */
  54. NODE_DATA(nid) = pfn_to_kaddr(free_pfn);
  55. free_pfn += PFN_UP(sizeof(struct pglist_data));
  56. memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
  57. NODE_DATA(nid)->bdata = &bootmem_node_data[nid];
  58. NODE_DATA(nid)->node_start_pfn = start_pfn;
  59. NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
  60. /* Node-local bootmap */
  61. bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
  62. bootmap_start = (unsigned long)pfn_to_kaddr(free_pfn);
  63. bootmap_size = init_bootmem_node(NODE_DATA(nid), free_pfn, start_pfn,
  64. end_pfn);
  65. free_bootmem_with_active_regions(nid, end_pfn);
  66. /* Reserve the pgdat and bootmap space with the bootmem allocator */
  67. reserve_bootmem_node(NODE_DATA(nid), start_pfn << PAGE_SHIFT,
  68. sizeof(struct pglist_data), BOOTMEM_DEFAULT);
  69. reserve_bootmem_node(NODE_DATA(nid), free_pfn << PAGE_SHIFT,
  70. bootmap_pages << PAGE_SHIFT, BOOTMEM_DEFAULT);
  71. /* It's up */
  72. node_set_online(nid);
  73. /* Kick sparsemem */
  74. sparse_memory_present_with_active_regions(nid);
  75. }