[PATCH] unify PFN_* macros
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / m32r / mm / discontig.c
blobcf610a7c5ff0541f8dc051e99fa4825f69a73e31
1 /*
2 * linux/arch/m32r/mm/discontig.c
4 * Discontig memory support
6 * Copyright (c) 2003 Hitoshi Yamamoto
7 */
9 #include <linux/config.h>
10 #include <linux/mm.h>
11 #include <linux/bootmem.h>
12 #include <linux/mmzone.h>
13 #include <linux/initrd.h>
14 #include <linux/nodemask.h>
15 #include <linux/module.h>
16 #include <linux/pfn.h>
18 #include <asm/setup.h>
20 extern char _end[];
22 struct pglist_data *node_data[MAX_NUMNODES];
23 EXPORT_SYMBOL(node_data);
24 static bootmem_data_t node_bdata[MAX_NUMNODES] __initdata;
26 pg_data_t m32r_node_data[MAX_NUMNODES];
28 /* Memory profile */
29 typedef struct {
30 unsigned long start_pfn;
31 unsigned long pages;
32 unsigned long holes;
33 unsigned long free_pfn;
34 } mem_prof_t;
35 static mem_prof_t mem_prof[MAX_NUMNODES];
37 static void __init mem_prof_init(void)
39 unsigned long start_pfn, holes, free_pfn;
40 const unsigned long zone_alignment = 1UL << (MAX_ORDER - 1);
41 unsigned long ul;
42 mem_prof_t *mp;
44 /* Node#0 SDRAM */
45 mp = &mem_prof[0];
46 mp->start_pfn = PFN_UP(CONFIG_MEMORY_START);
47 mp->pages = PFN_DOWN(CONFIG_MEMORY_SIZE);
48 mp->holes = 0;
49 mp->free_pfn = PFN_UP(__pa(_end));
51 /* Node#1 internal SRAM */
52 mp = &mem_prof[1];
53 start_pfn = free_pfn = PFN_UP(CONFIG_IRAM_START);
54 holes = 0;
55 if (start_pfn & (zone_alignment - 1)) {
56 ul = zone_alignment;
57 while (start_pfn >= ul)
58 ul += zone_alignment;
60 start_pfn = ul - zone_alignment;
61 holes = free_pfn - start_pfn;
64 mp->start_pfn = start_pfn;
65 mp->pages = PFN_DOWN(CONFIG_IRAM_SIZE) + holes;
66 mp->holes = holes;
67 mp->free_pfn = PFN_UP(CONFIG_IRAM_START);
70 unsigned long __init setup_memory(void)
72 unsigned long bootmap_size;
73 unsigned long min_pfn;
74 int nid;
75 mem_prof_t *mp;
77 max_low_pfn = 0;
78 min_low_pfn = -1;
80 mem_prof_init();
82 for_each_online_node(nid) {
83 mp = &mem_prof[nid];
84 NODE_DATA(nid)=(pg_data_t *)&m32r_node_data[nid];
85 NODE_DATA(nid)->bdata = &node_bdata[nid];
86 min_pfn = mp->start_pfn;
87 max_pfn = mp->start_pfn + mp->pages;
88 bootmap_size = init_bootmem_node(NODE_DATA(nid), mp->free_pfn,
89 mp->start_pfn, max_pfn);
91 free_bootmem_node(NODE_DATA(nid), PFN_PHYS(mp->start_pfn),
92 PFN_PHYS(mp->pages));
94 reserve_bootmem_node(NODE_DATA(nid), PFN_PHYS(mp->start_pfn),
95 PFN_PHYS(mp->free_pfn - mp->start_pfn) + bootmap_size);
97 if (max_low_pfn < max_pfn)
98 max_low_pfn = max_pfn;
100 if (min_low_pfn > min_pfn)
101 min_low_pfn = min_pfn;
104 #ifdef CONFIG_BLK_DEV_INITRD
105 if (LOADER_TYPE && INITRD_START) {
106 if (INITRD_START + INITRD_SIZE <= PFN_PHYS(max_low_pfn)) {
107 reserve_bootmem_node(NODE_DATA(0), INITRD_START,
108 INITRD_SIZE);
109 initrd_start = INITRD_START ?
110 INITRD_START + PAGE_OFFSET : 0;
112 initrd_end = initrd_start + INITRD_SIZE;
113 printk("initrd:start[%08lx],size[%08lx]\n",
114 initrd_start, INITRD_SIZE);
115 } else {
116 printk("initrd extends beyond end of memory "
117 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
118 INITRD_START + INITRD_SIZE,
119 PFN_PHYS(max_low_pfn));
121 initrd_start = 0;
124 #endif /* CONFIG_BLK_DEV_INITRD */
126 return max_low_pfn;
129 #define START_PFN(nid) \
130 (NODE_DATA(nid)->bdata->node_boot_start >> PAGE_SHIFT)
131 #define MAX_LOW_PFN(nid) (NODE_DATA(nid)->bdata->node_low_pfn)
133 unsigned long __init zone_sizes_init(void)
135 unsigned long zones_size[MAX_NR_ZONES], zholes_size[MAX_NR_ZONES];
136 unsigned long low, start_pfn;
137 unsigned long holes = 0;
138 int nid, i;
139 mem_prof_t *mp;
141 for_each_online_node(nid) {
142 mp = &mem_prof[nid];
143 for (i = 0 ; i < MAX_NR_ZONES ; i++) {
144 zones_size[i] = 0;
145 zholes_size[i] = 0;
147 start_pfn = START_PFN(nid);
148 low = MAX_LOW_PFN(nid);
149 zones_size[ZONE_DMA] = low - start_pfn;
150 zholes_size[ZONE_DMA] = mp->holes;
151 holes += zholes_size[ZONE_DMA];
153 free_area_init_node(nid, NODE_DATA(nid), zones_size,
154 start_pfn, zholes_size);
158 * For test
159 * Use all area of internal RAM.
160 * see __alloc_pages()
162 NODE_DATA(1)->node_zones->pages_min = 0;
163 NODE_DATA(1)->node_zones->pages_low = 0;
164 NODE_DATA(1)->node_zones->pages_high = 0;
166 return holes;