numa.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/memblock.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_bootmem_node(int nid, unsigned long start, unsigned long end)
  26. {
  27. unsigned long bootmap_pages;
  28. unsigned long start_pfn, end_pfn;
  29. unsigned long bootmem_paddr;
  30. /* Don't allow bogus node assignment */
  31. BUG_ON(nid >= MAX_NUMNODES || nid <= 0);
  32. start_pfn = PFN_DOWN(start);
  33. end_pfn = PFN_DOWN(end);
  34. pmb_bolt_mapping((unsigned long)__va(start), start, end - start,
  35. PAGE_KERNEL);
  36. memblock_add(start, end - start);
  37. __add_active_range(nid, start_pfn, end_pfn);
  38. /* Node-local pgdat */
  39. NODE_DATA(nid) = __va(memblock_alloc_base(sizeof(struct pglist_data),
  40. SMP_CACHE_BYTES, end));
  41. memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
  42. NODE_DATA(nid)->bdata = &bootmem_node_data[nid];
  43. NODE_DATA(nid)->node_start_pfn = start_pfn;
  44. NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
  45. /* Node-local bootmap */
  46. bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
  47. bootmem_paddr = memblock_alloc_base(bootmap_pages << PAGE_SHIFT,
  48. PAGE_SIZE, end);
  49. init_bootmem_node(NODE_DATA(nid), bootmem_paddr >> PAGE_SHIFT,
  50. start_pfn, end_pfn);
  51. free_bootmem_with_active_regions(nid, end_pfn);
  52. /* Reserve the pgdat and bootmap space with the bootmem allocator */
  53. reserve_bootmem_node(NODE_DATA(nid), start_pfn << PAGE_SHIFT,
  54. sizeof(struct pglist_data), BOOTMEM_DEFAULT);
  55. reserve_bootmem_node(NODE_DATA(nid), bootmem_paddr,
  56. bootmap_pages << PAGE_SHIFT, BOOTMEM_DEFAULT);
  57. /* It's up */
  58. node_set_online(nid);
  59. /* Kick sparsemem */
  60. sparse_memory_present_with_active_regions(nid);
  61. }