discontig.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * linux/arch/m32r/mm/discontig.c
  3. *
  4. * Discontig memory support
  5. *
  6. * Copyright (c) 2003 Hitoshi Yamamoto
  7. */
  8. #include <linux/mm.h>
  9. #include <linux/bootmem.h>
  10. #include <linux/mmzone.h>
  11. #include <linux/initrd.h>
  12. #include <linux/nodemask.h>
  13. #include <linux/module.h>
  14. #include <linux/pfn.h>
  15. #include <asm/setup.h>
  16. extern char _end[];
  17. struct pglist_data *node_data[MAX_NUMNODES];
  18. EXPORT_SYMBOL(node_data);
  19. pg_data_t m32r_node_data[MAX_NUMNODES];
  20. /* Memory profile */
  21. typedef struct {
  22. unsigned long start_pfn;
  23. unsigned long pages;
  24. unsigned long holes;
  25. unsigned long free_pfn;
  26. } mem_prof_t;
  27. static mem_prof_t mem_prof[MAX_NUMNODES];
  28. extern unsigned long memory_start;
  29. extern unsigned long memory_end;
  30. static void __init mem_prof_init(void)
  31. {
  32. unsigned long start_pfn, holes, free_pfn;
  33. const unsigned long zone_alignment = 1UL << (MAX_ORDER - 1);
  34. unsigned long ul;
  35. mem_prof_t *mp;
  36. /* Node#0 SDRAM */
  37. mp = &mem_prof[0];
  38. mp->start_pfn = PFN_UP(CONFIG_MEMORY_START);
  39. mp->pages = PFN_DOWN(memory_end - memory_start);
  40. mp->holes = 0;
  41. mp->free_pfn = PFN_UP(__pa(_end));
  42. /* Node#1 internal SRAM */
  43. mp = &mem_prof[1];
  44. start_pfn = free_pfn = PFN_UP(CONFIG_IRAM_START);
  45. holes = 0;
  46. if (start_pfn & (zone_alignment - 1)) {
  47. ul = zone_alignment;
  48. while (start_pfn >= ul)
  49. ul += zone_alignment;
  50. start_pfn = ul - zone_alignment;
  51. holes = free_pfn - start_pfn;
  52. }
  53. mp->start_pfn = start_pfn;
  54. mp->pages = PFN_DOWN(CONFIG_IRAM_SIZE) + holes;
  55. mp->holes = holes;
  56. mp->free_pfn = PFN_UP(CONFIG_IRAM_START);
  57. }
  58. unsigned long __init setup_memory(void)
  59. {
  60. unsigned long bootmap_size;
  61. unsigned long min_pfn;
  62. int nid;
  63. mem_prof_t *mp;
  64. max_low_pfn = 0;
  65. min_low_pfn = -1;
  66. mem_prof_init();
  67. for_each_online_node(nid) {
  68. mp = &mem_prof[nid];
  69. NODE_DATA(nid)=(pg_data_t *)&m32r_node_data[nid];
  70. NODE_DATA(nid)->bdata = &bootmem_node_data[nid];
  71. min_pfn = mp->start_pfn;
  72. max_pfn = mp->start_pfn + mp->pages;
  73. bootmap_size = init_bootmem_node(NODE_DATA(nid), mp->free_pfn,
  74. mp->start_pfn, max_pfn);
  75. free_bootmem_node(NODE_DATA(nid), PFN_PHYS(mp->start_pfn),
  76. PFN_PHYS(mp->pages));
  77. reserve_bootmem_node(NODE_DATA(nid), PFN_PHYS(mp->start_pfn),
  78. PFN_PHYS(mp->free_pfn - mp->start_pfn) + bootmap_size,
  79. BOOTMEM_DEFAULT);
  80. if (max_low_pfn < max_pfn)
  81. max_low_pfn = max_pfn;
  82. if (min_low_pfn > min_pfn)
  83. min_low_pfn = min_pfn;
  84. }
  85. #ifdef CONFIG_BLK_DEV_INITRD
  86. if (LOADER_TYPE && INITRD_START) {
  87. if (INITRD_START + INITRD_SIZE <= PFN_PHYS(max_low_pfn)) {
  88. reserve_bootmem_node(NODE_DATA(0), INITRD_START,
  89. INITRD_SIZE, BOOTMEM_DEFAULT);
  90. initrd_start = INITRD_START + PAGE_OFFSET;
  91. initrd_end = initrd_start + INITRD_SIZE;
  92. printk("initrd:start[%08lx],size[%08lx]\n",
  93. initrd_start, INITRD_SIZE);
  94. } else {
  95. printk("initrd extends beyond end of memory "
  96. "(0x%08lx > 0x%08llx)\ndisabling initrd\n",
  97. INITRD_START + INITRD_SIZE,
  98. (unsigned long long)PFN_PHYS(max_low_pfn));
  99. initrd_start = 0;
  100. }
  101. }
  102. #endif /* CONFIG_BLK_DEV_INITRD */
  103. return max_low_pfn;
  104. }
  105. #define START_PFN(nid) (NODE_DATA(nid)->bdata->node_min_pfn)
  106. #define MAX_LOW_PFN(nid) (NODE_DATA(nid)->bdata->node_low_pfn)
  107. void __init zone_sizes_init(void)
  108. {
  109. unsigned long zones_size[MAX_NR_ZONES], zholes_size[MAX_NR_ZONES];
  110. unsigned long low, start_pfn;
  111. int nid, i;
  112. mem_prof_t *mp;
  113. for_each_online_node(nid) {
  114. mp = &mem_prof[nid];
  115. for (i = 0 ; i < MAX_NR_ZONES ; i++) {
  116. zones_size[i] = 0;
  117. zholes_size[i] = 0;
  118. }
  119. start_pfn = START_PFN(nid);
  120. low = MAX_LOW_PFN(nid);
  121. zones_size[ZONE_DMA] = low - start_pfn;
  122. zholes_size[ZONE_DMA] = mp->holes;
  123. node_set_state(nid, N_NORMAL_MEMORY);
  124. free_area_init_node(nid, zones_size, start_pfn, zholes_size);
  125. }
  126. /*
  127. * For test
  128. * Use all area of internal RAM.
  129. * see __alloc_pages()
  130. */
  131. NODE_DATA(1)->node_zones->watermark[WMARK_MIN] = 0;
  132. NODE_DATA(1)->node_zones->watermark[WMARK_LOW] = 0;
  133. NODE_DATA(1)->node_zones->watermark[WMARK_HIGH] = 0;
  134. }