Linux-2.6.12-rc2
[linux-2.6/kvm.git] / arch / v850 / kernel / setup.c
blobc41d72b01b8806cf07ddbc5a664240f0597a84b6
1 /*
2 * arch/v850/kernel/setup.c -- Arch-dependent initialization functions
4 * Copyright (C) 2001,02,03 NEC Electronics Corporation
5 * Copyright (C) 2001,02,03 Miles Bader <miles@gnu.org>
7 * This file is subject to the terms and conditions of the GNU General
8 * Public License. See the file COPYING in the main directory of this
9 * archive for more details.
11 * Written by Miles Bader <miles@gnu.org>
14 #include <linux/mm.h>
15 #include <linux/bootmem.h>
16 #include <linux/swap.h> /* we don't have swap, but for nr_free_pages */
17 #include <linux/irq.h>
18 #include <linux/reboot.h>
19 #include <linux/personality.h>
20 #include <linux/major.h>
21 #include <linux/root_dev.h>
22 #include <linux/mtd/mtd.h>
23 #include <linux/init.h>
25 #include <asm/irq.h>
26 #include <asm/setup.h>
28 #include "mach.h"
30 /* These symbols are all defined in the linker map to delineate various
31 statically allocated regions of memory. */
33 extern char _intv_start, _intv_end;
34 /* `kram' is only used if the kernel uses part of normal user RAM. */
35 extern char _kram_start __attribute__ ((__weak__));
36 extern char _kram_end __attribute__ ((__weak__));
37 extern char _init_start, _init_end;
38 extern char _bootmap;
39 extern char _stext, _etext, _sdata, _edata, _sbss, _ebss;
40 /* Many platforms use an embedded root image. */
41 extern char _root_fs_image_start __attribute__ ((__weak__));
42 extern char _root_fs_image_end __attribute__ ((__weak__));
45 char command_line[COMMAND_LINE_SIZE];
47 /* Memory not used by the kernel. */
48 static unsigned long total_ram_pages;
50 /* System RAM. */
51 static unsigned long ram_start = 0, ram_len = 0;
54 #define ADDR_TO_PAGE_UP(x) ((((unsigned long)x) + PAGE_SIZE-1) >> PAGE_SHIFT)
55 #define ADDR_TO_PAGE(x) (((unsigned long)x) >> PAGE_SHIFT)
56 #define PAGE_TO_ADDR(x) (((unsigned long)x) << PAGE_SHIFT)
58 static void init_mem_alloc (unsigned long ram_start, unsigned long ram_len);
60 void set_mem_root (void *addr, size_t len, char *cmd_line);
63 void __init setup_arch (char **cmdline)
65 /* Keep a copy of command line */
66 *cmdline = command_line;
67 memcpy (saved_command_line, command_line, COMMAND_LINE_SIZE);
68 saved_command_line[COMMAND_LINE_SIZE - 1] = '\0';
70 console_verbose ();
72 init_mm.start_code = (unsigned long) &_stext;
73 init_mm.end_code = (unsigned long) &_etext;
74 init_mm.end_data = (unsigned long) &_edata;
75 init_mm.brk = (unsigned long) &_kram_end;
77 /* Find out what mem this machine has. */
78 mach_get_physical_ram (&ram_start, &ram_len);
79 /* ... and tell the kernel about it. */
80 init_mem_alloc (ram_start, ram_len);
82 printk (KERN_INFO "CPU: %s\nPlatform: %s\n",
83 CPU_MODEL_LONG, PLATFORM_LONG);
85 /* do machine-specific setups. */
86 mach_setup (cmdline);
88 #ifdef CONFIG_MTD
89 if (!ROOT_DEV && &_root_fs_image_end > &_root_fs_image_start)
90 set_mem_root (&_root_fs_image_start,
91 &_root_fs_image_end - &_root_fs_image_start,
92 *cmdline);
93 #endif
96 void __init trap_init (void)
100 #ifdef CONFIG_MTD
101 /* Set the root filesystem to be the given memory region.
102 Some parameter may be appended to CMD_LINE. */
103 void set_mem_root (void *addr, size_t len, char *cmd_line)
105 /* The only way to pass info to the MTD slram driver is via
106 the command line. */
107 if (*cmd_line) {
108 cmd_line += strlen (cmd_line);
109 *cmd_line++ = ' ';
111 sprintf (cmd_line, "slram=root,0x%x,+0x%x", (u32)addr, (u32)len);
113 ROOT_DEV = MKDEV (MTD_BLOCK_MAJOR, 0);
115 #endif
118 static void irq_nop (unsigned irq) { }
119 static unsigned irq_zero (unsigned irq) { return 0; }
121 static void nmi_end (unsigned irq)
123 if (irq != IRQ_NMI (0)) {
124 printk (KERN_CRIT "NMI %d is unrecoverable; restarting...",
125 irq - IRQ_NMI (0));
126 machine_restart (0);
130 static struct hw_interrupt_type nmi_irq_type = {
131 "NMI",
132 irq_zero, /* startup */
133 irq_nop, /* shutdown */
134 irq_nop, /* enable */
135 irq_nop, /* disable */
136 irq_nop, /* ack */
137 nmi_end, /* end */
140 void __init init_IRQ (void)
142 init_irq_handlers (0, NUM_MACH_IRQS, 1, 0);
143 init_irq_handlers (IRQ_NMI (0), NUM_NMIS, 1, &nmi_irq_type);
144 mach_init_irqs ();
148 void __init mem_init (void)
150 max_mapnr = MAP_NR (ram_start + ram_len);
152 num_physpages = ADDR_TO_PAGE (ram_len);
154 total_ram_pages = free_all_bootmem ();
156 printk (KERN_INFO
157 "Memory: %luK/%luK available"
158 " (%luK kernel code, %luK data)\n",
159 PAGE_TO_ADDR (nr_free_pages()) / 1024,
160 ram_len / 1024,
161 ((unsigned long)&_etext - (unsigned long)&_stext) / 1024,
162 ((unsigned long)&_ebss - (unsigned long)&_sdata) / 1024);
165 void free_initmem (void)
167 unsigned long ram_end = ram_start + ram_len;
168 unsigned long start = PAGE_ALIGN ((unsigned long)(&_init_start));
170 if (start >= ram_start && start < ram_end) {
171 unsigned long addr;
172 unsigned long end = PAGE_ALIGN ((unsigned long)(&_init_end));
174 if (end > ram_end)
175 end = ram_end;
177 printk("Freeing unused kernel memory: %ldK freed\n",
178 (end - start) / 1024);
180 for (addr = start; addr < end; addr += PAGE_SIZE) {
181 struct page *page = virt_to_page (addr);
182 ClearPageReserved (page);
183 set_page_count (page, 1);
184 __free_page (page);
185 total_ram_pages++;
191 /* Initialize the `bootmem allocator'. RAM_START and RAM_LEN identify
192 what RAM may be used. */
193 static void __init
194 init_bootmem_alloc (unsigned long ram_start, unsigned long ram_len)
196 /* The part of the kernel that's in the same managed RAM space
197 used for general allocation. */
198 unsigned long kram_start = (unsigned long)&_kram_start;
199 unsigned long kram_end = (unsigned long)&_kram_end;
200 /* End of the managed RAM space. */
201 unsigned long ram_end = ram_start + ram_len;
202 /* Address range of the interrupt vector table. */
203 unsigned long intv_start = (unsigned long)&_intv_start;
204 unsigned long intv_end = (unsigned long)&_intv_end;
205 /* True if the interrupt vectors are in the managed RAM area. */
206 int intv_in_ram = (intv_end > ram_start && intv_start < ram_end);
207 /* True if the interrupt vectors are inside the kernel's RAM. */
208 int intv_in_kram = (intv_end > kram_start && intv_start < kram_end);
209 /* A pointer to an optional function that reserves platform-specific
210 memory regions. We declare the pointer `volatile' to avoid gcc
211 turning the call into a static call (the problem is that since
212 it's a weak symbol, a static call may end up trying to reference
213 the location 0x0, which is not always reachable). */
214 void (*volatile mrb) (void) = mach_reserve_bootmem;
215 /* The bootmem allocator's allocation bitmap. */
216 unsigned long bootmap = (unsigned long)&_bootmap;
217 unsigned long bootmap_len;
219 /* Round bootmap location up to next page. */
220 bootmap = PAGE_TO_ADDR (ADDR_TO_PAGE_UP (bootmap));
222 /* Initialize bootmem allocator. */
223 bootmap_len = init_bootmem_node (NODE_DATA (0),
224 ADDR_TO_PAGE (bootmap),
225 ADDR_TO_PAGE (PAGE_OFFSET),
226 ADDR_TO_PAGE (ram_end));
228 /* Now make the RAM actually allocatable (it starts out `reserved'). */
229 free_bootmem (ram_start, ram_len);
231 if (kram_end > kram_start)
232 /* Reserve the RAM part of the kernel's address space, so it
233 doesn't get allocated. */
234 reserve_bootmem (kram_start, kram_end - kram_start);
236 if (intv_in_ram && !intv_in_kram)
237 /* Reserve the interrupt vector space. */
238 reserve_bootmem (intv_start, intv_end - intv_start);
240 if (bootmap >= ram_start && bootmap < ram_end)
241 /* Reserve the bootmap space. */
242 reserve_bootmem (bootmap, bootmap_len);
244 /* Reserve the memory used by the root filesystem image if it's
245 in RAM. */
246 if (&_root_fs_image_end > &_root_fs_image_start
247 && (unsigned long)&_root_fs_image_start >= ram_start
248 && (unsigned long)&_root_fs_image_start < ram_end)
249 reserve_bootmem ((unsigned long)&_root_fs_image_start,
250 &_root_fs_image_end - &_root_fs_image_start);
252 /* Let the platform-dependent code reserve some too. */
253 if (mrb)
254 (*mrb) ();
257 /* Tell the kernel about what RAM it may use for memory allocation. */
258 static void __init
259 init_mem_alloc (unsigned long ram_start, unsigned long ram_len)
261 unsigned i;
262 unsigned long zones_size[MAX_NR_ZONES];
264 init_bootmem_alloc (ram_start, ram_len);
266 for (i = 0; i < MAX_NR_ZONES; i++)
267 zones_size[i] = 0;
269 /* We stuff all the memory into one area, which includes the
270 initial gap from PAGE_OFFSET to ram_start. */
271 zones_size[ZONE_DMA]
272 = ADDR_TO_PAGE (ram_len + (ram_start - PAGE_OFFSET));
274 /* The allocator is very picky about the address of the first
275 allocatable page -- it must be at least as aligned as the
276 maximum allocation -- so try to detect cases where it will get
277 confused and signal them at compile time (this is a common
278 problem when porting to a new platform with ). There is a
279 similar runtime check in free_area_init_core. */
280 #if ((PAGE_OFFSET >> PAGE_SHIFT) & ((1UL << (MAX_ORDER - 1)) - 1))
281 #error MAX_ORDER is too large for given PAGE_OFFSET (use CONFIG_FORCE_MAX_ZONEORDER to change it)
282 #endif
283 NODE_DATA(0)->node_mem_map = NULL;
284 free_area_init_node (0, NODE_DATA(0), zones_size,
285 ADDR_TO_PAGE (PAGE_OFFSET), 0);