numa.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/alpha/mm/numa.c
  4. *
  5. * DISCONTIGMEM NUMA alpha support.
  6. *
  7. * Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE
  8. */
  9. #include <linux/types.h>
  10. #include <linux/kernel.h>
  11. #include <linux/mm.h>
  12. #include <linux/memblock.h>
  13. #include <linux/swap.h>
  14. #include <linux/initrd.h>
  15. #include <linux/pfn.h>
  16. #include <linux/module.h>
  17. #include <asm/hwrpb.h>
  18. #include <asm/pgalloc.h>
  19. #include <asm/sections.h>
  20. pg_data_t node_data[MAX_NUMNODES];
  21. EXPORT_SYMBOL(node_data);
  22. #undef DEBUG_DISCONTIG
  23. #ifdef DEBUG_DISCONTIG
  24. #define DBGDCONT(args...) printk(args)
  25. #else
  26. #define DBGDCONT(args...)
  27. #endif
  28. #define for_each_mem_cluster(memdesc, _cluster, i) \
  29. for ((_cluster) = (memdesc)->cluster, (i) = 0; \
  30. (i) < (memdesc)->numclusters; (i)++, (_cluster)++)
  31. static void __init show_mem_layout(void)
  32. {
  33. struct memclust_struct * cluster;
  34. struct memdesc_struct * memdesc;
  35. int i;
  36. /* Find free clusters, and init and free the bootmem accordingly. */
  37. memdesc = (struct memdesc_struct *)
  38. (hwrpb->mddt_offset + (unsigned long) hwrpb);
  39. printk("Raw memory layout:\n");
  40. for_each_mem_cluster(memdesc, cluster, i) {
  41. printk(" memcluster %2d, usage %1lx, start %8lu, end %8lu\n",
  42. i, cluster->usage, cluster->start_pfn,
  43. cluster->start_pfn + cluster->numpages);
  44. }
  45. }
  46. static void __init
  47. setup_memory_node(int nid, void *kernel_end)
  48. {
  49. extern unsigned long mem_size_limit;
  50. struct memclust_struct * cluster;
  51. struct memdesc_struct * memdesc;
  52. unsigned long start_kernel_pfn, end_kernel_pfn;
  53. unsigned long start, end;
  54. unsigned long node_pfn_start, node_pfn_end;
  55. unsigned long node_min_pfn, node_max_pfn;
  56. int i;
  57. int show_init = 0;
  58. /* Find the bounds of current node */
  59. node_pfn_start = (node_mem_start(nid)) >> PAGE_SHIFT;
  60. node_pfn_end = node_pfn_start + (node_mem_size(nid) >> PAGE_SHIFT);
  61. /* Find free clusters, and init and free the bootmem accordingly. */
  62. memdesc = (struct memdesc_struct *)
  63. (hwrpb->mddt_offset + (unsigned long) hwrpb);
  64. /* find the bounds of this node (node_min_pfn/node_max_pfn) */
  65. node_min_pfn = ~0UL;
  66. node_max_pfn = 0UL;
  67. for_each_mem_cluster(memdesc, cluster, i) {
  68. /* Bit 0 is console/PALcode reserved. Bit 1 is
  69. non-volatile memory -- we might want to mark
  70. this for later. */
  71. if (cluster->usage & 3)
  72. continue;
  73. start = cluster->start_pfn;
  74. end = start + cluster->numpages;
  75. if (start >= node_pfn_end || end <= node_pfn_start)
  76. continue;
  77. if (!show_init) {
  78. show_init = 1;
  79. printk("Initializing bootmem allocator on Node ID %d\n", nid);
  80. }
  81. printk(" memcluster %2d, usage %1lx, start %8lu, end %8lu\n",
  82. i, cluster->usage, cluster->start_pfn,
  83. cluster->start_pfn + cluster->numpages);
  84. if (start < node_pfn_start)
  85. start = node_pfn_start;
  86. if (end > node_pfn_end)
  87. end = node_pfn_end;
  88. if (start < node_min_pfn)
  89. node_min_pfn = start;
  90. if (end > node_max_pfn)
  91. node_max_pfn = end;
  92. }
  93. if (mem_size_limit && node_max_pfn > mem_size_limit) {
  94. static int msg_shown = 0;
  95. if (!msg_shown) {
  96. msg_shown = 1;
  97. printk("setup: forcing memory size to %ldK (from %ldK).\n",
  98. mem_size_limit << (PAGE_SHIFT - 10),
  99. node_max_pfn << (PAGE_SHIFT - 10));
  100. }
  101. node_max_pfn = mem_size_limit;
  102. }
  103. if (node_min_pfn >= node_max_pfn)
  104. return;
  105. /* Update global {min,max}_low_pfn from node information. */
  106. if (node_min_pfn < min_low_pfn)
  107. min_low_pfn = node_min_pfn;
  108. if (node_max_pfn > max_low_pfn)
  109. max_pfn = max_low_pfn = node_max_pfn;
  110. #if 0 /* we'll try this one again in a little while */
  111. /* Cute trick to make sure our local node data is on local memory */
  112. node_data[nid] = (pg_data_t *)(__va(node_min_pfn << PAGE_SHIFT));
  113. #endif
  114. printk(" Detected node memory: start %8lu, end %8lu\n",
  115. node_min_pfn, node_max_pfn);
  116. DBGDCONT(" DISCONTIG: node_data[%d] is at 0x%p\n", nid, NODE_DATA(nid));
  117. /* Find the bounds of kernel memory. */
  118. start_kernel_pfn = PFN_DOWN(KERNEL_START_PHYS);
  119. end_kernel_pfn = PFN_UP(virt_to_phys(kernel_end));
  120. if (!nid && (node_max_pfn < end_kernel_pfn || node_min_pfn > start_kernel_pfn))
  121. panic("kernel loaded out of ram");
  122. memblock_add(PFN_PHYS(node_min_pfn),
  123. (node_max_pfn - node_min_pfn) << PAGE_SHIFT);
  124. /* Zone start phys-addr must be 2^(MAX_ORDER-1) aligned.
  125. Note that we round this down, not up - node memory
  126. has much larger alignment than 8Mb, so it's safe. */
  127. node_min_pfn &= ~((1UL << (MAX_ORDER-1))-1);
  128. NODE_DATA(nid)->node_start_pfn = node_min_pfn;
  129. NODE_DATA(nid)->node_present_pages = node_max_pfn - node_min_pfn;
  130. node_set_online(nid);
  131. }
  132. void __init
  133. setup_memory(void *kernel_end)
  134. {
  135. unsigned long kernel_size;
  136. int nid;
  137. show_mem_layout();
  138. nodes_clear(node_online_map);
  139. min_low_pfn = ~0UL;
  140. max_low_pfn = 0UL;
  141. for (nid = 0; nid < MAX_NUMNODES; nid++)
  142. setup_memory_node(nid, kernel_end);
  143. kernel_size = virt_to_phys(kernel_end) - KERNEL_START_PHYS;
  144. memblock_reserve(KERNEL_START_PHYS, kernel_size);
  145. #ifdef CONFIG_BLK_DEV_INITRD
  146. initrd_start = INITRD_START;
  147. if (initrd_start) {
  148. extern void *move_initrd(unsigned long);
  149. initrd_end = initrd_start+INITRD_SIZE;
  150. printk("Initial ramdisk at: 0x%p (%lu bytes)\n",
  151. (void *) initrd_start, INITRD_SIZE);
  152. if ((void *)initrd_end > phys_to_virt(PFN_PHYS(max_low_pfn))) {
  153. if (!move_initrd(PFN_PHYS(max_low_pfn)))
  154. printk("initrd extends beyond end of memory "
  155. "(0x%08lx > 0x%p)\ndisabling initrd\n",
  156. initrd_end,
  157. phys_to_virt(PFN_PHYS(max_low_pfn)));
  158. } else {
  159. nid = kvaddr_to_nid(initrd_start);
  160. memblock_reserve(virt_to_phys((void *)initrd_start),
  161. INITRD_SIZE);
  162. }
  163. }
  164. #endif /* CONFIG_BLK_DEV_INITRD */
  165. }
  166. void __init paging_init(void)
  167. {
  168. unsigned int nid;
  169. unsigned long zones_size[MAX_NR_ZONES] = {0, };
  170. unsigned long dma_local_pfn;
  171. /*
  172. * The old global MAX_DMA_ADDRESS per-arch API doesn't fit
  173. * in the NUMA model, for now we convert it to a pfn and
  174. * we interpret this pfn as a local per-node information.
  175. * This issue isn't very important since none of these machines
  176. * have legacy ISA slots anyways.
  177. */
  178. dma_local_pfn = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
  179. for_each_online_node(nid) {
  180. unsigned long start_pfn = NODE_DATA(nid)->node_start_pfn;
  181. unsigned long end_pfn = start_pfn + NODE_DATA(nid)->node_present_pages;
  182. if (dma_local_pfn >= end_pfn - start_pfn)
  183. zones_size[ZONE_DMA] = end_pfn - start_pfn;
  184. else {
  185. zones_size[ZONE_DMA] = dma_local_pfn;
  186. zones_size[ZONE_NORMAL] = (end_pfn - start_pfn) - dma_local_pfn;
  187. }
  188. node_set_state(nid, N_NORMAL_MEMORY);
  189. free_area_init_node(nid, zones_size, start_pfn, NULL);
  190. }
  191. /* Initialize the kernel's ZERO_PGE. */
  192. memset((void *)ZERO_PGE, 0, PAGE_SIZE);
  193. }