numa.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Multiple memory node support for Meta machines
  3. *
  4. * Copyright (C) 2007 Paul Mundt
  5. * Copyright (C) 2010 Imagination Technologies Ltd.
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #include <linux/export.h>
  12. #include <linux/bootmem.h>
  13. #include <linux/memblock.h>
  14. #include <linux/mm.h>
  15. #include <linux/numa.h>
  16. #include <linux/pfn.h>
  17. #include <asm/sections.h>
  18. struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
  19. EXPORT_SYMBOL_GPL(node_data);
  20. extern char _heap_start[];
  21. /*
  22. * On Meta machines the conventional approach is to stash system RAM
  23. * in node 0, and other memory blocks in to node 1 and up, ordered by
  24. * latency. Each node's pgdat is node-local at the beginning of the node,
  25. * immediately followed by the node mem map.
  26. */
  27. void __init setup_bootmem_node(int nid, unsigned long start, unsigned long end)
  28. {
  29. unsigned long bootmap_pages, bootmem_paddr;
  30. unsigned long start_pfn, end_pfn;
  31. unsigned long pgdat_paddr;
  32. /* Don't allow bogus node assignment */
  33. BUG_ON(nid >= MAX_NUMNODES || nid <= 0);
  34. start_pfn = start >> PAGE_SHIFT;
  35. end_pfn = end >> PAGE_SHIFT;
  36. memblock_add(start, end - start);
  37. memblock_set_node(PFN_PHYS(start_pfn),
  38. PFN_PHYS(end_pfn - start_pfn),
  39. &memblock.memory, nid);
  40. /* Node-local pgdat */
  41. pgdat_paddr = memblock_alloc_base(sizeof(struct pglist_data),
  42. SMP_CACHE_BYTES, end);
  43. NODE_DATA(nid) = __va(pgdat_paddr);
  44. memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
  45. NODE_DATA(nid)->bdata = &bootmem_node_data[nid];
  46. NODE_DATA(nid)->node_start_pfn = start_pfn;
  47. NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
  48. /* Node-local bootmap */
  49. bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
  50. bootmem_paddr = memblock_alloc_base(bootmap_pages << PAGE_SHIFT,
  51. PAGE_SIZE, end);
  52. init_bootmem_node(NODE_DATA(nid), bootmem_paddr >> PAGE_SHIFT,
  53. start_pfn, end_pfn);
  54. free_bootmem_with_active_regions(nid, end_pfn);
  55. /* Reserve the pgdat and bootmap space with the bootmem allocator */
  56. reserve_bootmem_node(NODE_DATA(nid), pgdat_paddr & PAGE_MASK,
  57. sizeof(struct pglist_data), BOOTMEM_DEFAULT);
  58. reserve_bootmem_node(NODE_DATA(nid), bootmem_paddr,
  59. bootmap_pages << PAGE_SHIFT, BOOTMEM_DEFAULT);
  60. /* It's up */
  61. node_set_online(nid);
  62. /* Kick sparsemem */
  63. sparse_memory_present_with_active_regions(nid);
  64. }
  65. void __init __weak soc_mem_setup(void)
  66. {
  67. }