Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2006 Atmel Corporation |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/clk.h> |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/sched.h> |
| 12 | #include <linux/console.h> |
| 13 | #include <linux/ioport.h> |
| 14 | #include <linux/bootmem.h> |
| 15 | #include <linux/fs.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/root_dev.h> |
| 18 | #include <linux/cpu.h> |
Ahmed S. Darwish | 10b50b7 | 2007-02-05 04:41:27 +0200 | [diff] [blame] | 19 | #include <linux/kernel.h> |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 20 | |
| 21 | #include <asm/sections.h> |
| 22 | #include <asm/processor.h> |
| 23 | #include <asm/pgtable.h> |
| 24 | #include <asm/setup.h> |
| 25 | #include <asm/sysreg.h> |
| 26 | |
| 27 | #include <asm/arch/board.h> |
| 28 | #include <asm/arch/init.h> |
| 29 | |
| 30 | extern int root_mountflags; |
| 31 | |
| 32 | /* |
| 33 | * Bootloader-provided information about physical memory |
| 34 | */ |
| 35 | struct tag_mem_range *mem_phys; |
| 36 | struct tag_mem_range *mem_reserved; |
| 37 | struct tag_mem_range *mem_ramdisk; |
| 38 | |
| 39 | /* |
| 40 | * Initialize loops_per_jiffy as 5000000 (500MIPS). |
| 41 | * Better make it too large than too small... |
| 42 | */ |
| 43 | struct avr32_cpuinfo boot_cpu_data = { |
| 44 | .loops_per_jiffy = 5000000 |
| 45 | }; |
| 46 | EXPORT_SYMBOL(boot_cpu_data); |
| 47 | |
Alon Bar-Lev | bf4352c | 2007-02-12 00:54:08 -0800 | [diff] [blame^] | 48 | static char __initdata command_line[COMMAND_LINE_SIZE]; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 49 | |
| 50 | /* |
| 51 | * Should be more than enough, but if you have a _really_ complex |
| 52 | * setup, you might need to increase the size of this... |
| 53 | */ |
| 54 | static struct tag_mem_range __initdata mem_range_cache[32]; |
| 55 | static unsigned mem_range_next_free; |
| 56 | |
| 57 | /* |
| 58 | * Standard memory resources |
| 59 | */ |
| 60 | static struct resource mem_res[] = { |
| 61 | { |
| 62 | .name = "Kernel code", |
| 63 | .start = 0, |
| 64 | .end = 0, |
| 65 | .flags = IORESOURCE_MEM |
| 66 | }, |
| 67 | { |
| 68 | .name = "Kernel data", |
| 69 | .start = 0, |
| 70 | .end = 0, |
| 71 | .flags = IORESOURCE_MEM, |
| 72 | }, |
| 73 | }; |
| 74 | |
| 75 | #define kernel_code mem_res[0] |
| 76 | #define kernel_data mem_res[1] |
| 77 | |
| 78 | /* |
| 79 | * Early framebuffer allocation. Works as follows: |
| 80 | * - If fbmem_size is zero, nothing will be allocated or reserved. |
| 81 | * - If fbmem_start is zero when setup_bootmem() is called, |
| 82 | * fbmem_size bytes will be allocated from the bootmem allocator. |
| 83 | * - If fbmem_start is nonzero, an area of size fbmem_size will be |
| 84 | * reserved at the physical address fbmem_start if necessary. If |
| 85 | * the area isn't in a memory region known to the kernel, it will |
| 86 | * be left alone. |
| 87 | * |
| 88 | * Board-specific code may use these variables to set up platform data |
| 89 | * for the framebuffer driver if fbmem_size is nonzero. |
| 90 | */ |
| 91 | static unsigned long __initdata fbmem_start; |
| 92 | static unsigned long __initdata fbmem_size; |
| 93 | |
| 94 | /* |
| 95 | * "fbmem=xxx[kKmM]" allocates the specified amount of boot memory for |
| 96 | * use as framebuffer. |
| 97 | * |
| 98 | * "fbmem=xxx[kKmM]@yyy[kKmM]" defines a memory region of size xxx and |
| 99 | * starting at yyy to be reserved for use as framebuffer. |
| 100 | * |
| 101 | * The kernel won't verify that the memory region starting at yyy |
| 102 | * actually contains usable RAM. |
| 103 | */ |
| 104 | static int __init early_parse_fbmem(char *p) |
| 105 | { |
| 106 | fbmem_size = memparse(p, &p); |
| 107 | if (*p == '@') |
| 108 | fbmem_start = memparse(p, &p); |
| 109 | return 0; |
| 110 | } |
| 111 | early_param("fbmem", early_parse_fbmem); |
| 112 | |
| 113 | static inline void __init resource_init(void) |
| 114 | { |
| 115 | struct tag_mem_range *region; |
| 116 | |
| 117 | kernel_code.start = __pa(init_mm.start_code); |
| 118 | kernel_code.end = __pa(init_mm.end_code - 1); |
| 119 | kernel_data.start = __pa(init_mm.end_code); |
| 120 | kernel_data.end = __pa(init_mm.brk - 1); |
| 121 | |
| 122 | for (region = mem_phys; region; region = region->next) { |
| 123 | struct resource *res; |
| 124 | unsigned long phys_start, phys_end; |
| 125 | |
| 126 | if (region->size == 0) |
| 127 | continue; |
| 128 | |
| 129 | phys_start = region->addr; |
| 130 | phys_end = phys_start + region->size - 1; |
| 131 | |
| 132 | res = alloc_bootmem_low(sizeof(*res)); |
| 133 | res->name = "System RAM"; |
| 134 | res->start = phys_start; |
| 135 | res->end = phys_end; |
| 136 | res->flags = IORESOURCE_MEM | IORESOURCE_BUSY; |
| 137 | |
| 138 | request_resource (&iomem_resource, res); |
| 139 | |
| 140 | if (kernel_code.start >= res->start && |
| 141 | kernel_code.end <= res->end) |
| 142 | request_resource (res, &kernel_code); |
| 143 | if (kernel_data.start >= res->start && |
| 144 | kernel_data.end <= res->end) |
| 145 | request_resource (res, &kernel_data); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | static int __init parse_tag_core(struct tag *tag) |
| 150 | { |
| 151 | if (tag->hdr.size > 2) { |
| 152 | if ((tag->u.core.flags & 1) == 0) |
| 153 | root_mountflags &= ~MS_RDONLY; |
| 154 | ROOT_DEV = new_decode_dev(tag->u.core.rootdev); |
| 155 | } |
| 156 | return 0; |
| 157 | } |
| 158 | __tagtable(ATAG_CORE, parse_tag_core); |
| 159 | |
| 160 | static int __init parse_tag_mem_range(struct tag *tag, |
| 161 | struct tag_mem_range **root) |
| 162 | { |
| 163 | struct tag_mem_range *cur, **pprev; |
| 164 | struct tag_mem_range *new; |
| 165 | |
| 166 | /* |
| 167 | * Ignore zero-sized entries. If we're running standalone, the |
| 168 | * SDRAM code may emit such entries if something goes |
| 169 | * wrong... |
| 170 | */ |
| 171 | if (tag->u.mem_range.size == 0) |
| 172 | return 0; |
| 173 | |
| 174 | /* |
| 175 | * Copy the data so the bootmem init code doesn't need to care |
| 176 | * about it. |
| 177 | */ |
Ahmed S. Darwish | 10b50b7 | 2007-02-05 04:41:27 +0200 | [diff] [blame] | 178 | if (mem_range_next_free >= ARRAY_SIZE(mem_range_cache)) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 179 | panic("Physical memory map too complex!\n"); |
| 180 | |
| 181 | new = &mem_range_cache[mem_range_next_free++]; |
| 182 | *new = tag->u.mem_range; |
| 183 | |
| 184 | pprev = root; |
| 185 | cur = *root; |
| 186 | while (cur) { |
| 187 | pprev = &cur->next; |
| 188 | cur = cur->next; |
| 189 | } |
| 190 | |
| 191 | *pprev = new; |
| 192 | new->next = NULL; |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | static int __init parse_tag_mem(struct tag *tag) |
| 198 | { |
| 199 | return parse_tag_mem_range(tag, &mem_phys); |
| 200 | } |
| 201 | __tagtable(ATAG_MEM, parse_tag_mem); |
| 202 | |
| 203 | static int __init parse_tag_cmdline(struct tag *tag) |
| 204 | { |
Alon Bar-Lev | bf4352c | 2007-02-12 00:54:08 -0800 | [diff] [blame^] | 205 | strlcpy(boot_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 206 | return 0; |
| 207 | } |
| 208 | __tagtable(ATAG_CMDLINE, parse_tag_cmdline); |
| 209 | |
| 210 | static int __init parse_tag_rdimg(struct tag *tag) |
| 211 | { |
| 212 | return parse_tag_mem_range(tag, &mem_ramdisk); |
| 213 | } |
| 214 | __tagtable(ATAG_RDIMG, parse_tag_rdimg); |
| 215 | |
| 216 | static int __init parse_tag_clock(struct tag *tag) |
| 217 | { |
| 218 | /* |
| 219 | * We'll figure out the clocks by peeking at the system |
| 220 | * manager regs directly. |
| 221 | */ |
| 222 | return 0; |
| 223 | } |
| 224 | __tagtable(ATAG_CLOCK, parse_tag_clock); |
| 225 | |
| 226 | static int __init parse_tag_rsvd_mem(struct tag *tag) |
| 227 | { |
| 228 | return parse_tag_mem_range(tag, &mem_reserved); |
| 229 | } |
| 230 | __tagtable(ATAG_RSVD_MEM, parse_tag_rsvd_mem); |
| 231 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 232 | /* |
| 233 | * Scan the tag table for this tag, and call its parse function. The |
| 234 | * tag table is built by the linker from all the __tagtable |
| 235 | * declarations. |
| 236 | */ |
| 237 | static int __init parse_tag(struct tag *tag) |
| 238 | { |
| 239 | extern struct tagtable __tagtable_begin, __tagtable_end; |
| 240 | struct tagtable *t; |
| 241 | |
| 242 | for (t = &__tagtable_begin; t < &__tagtable_end; t++) |
| 243 | if (tag->hdr.tag == t->tag) { |
| 244 | t->parse(tag); |
| 245 | break; |
| 246 | } |
| 247 | |
| 248 | return t < &__tagtable_end; |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | * Parse all tags in the list we got from the boot loader |
| 253 | */ |
| 254 | static void __init parse_tags(struct tag *t) |
| 255 | { |
| 256 | for (; t->hdr.tag != ATAG_NONE; t = tag_next(t)) |
| 257 | if (!parse_tag(t)) |
| 258 | printk(KERN_WARNING |
| 259 | "Ignoring unrecognised tag 0x%08x\n", |
| 260 | t->hdr.tag); |
| 261 | } |
| 262 | |
| 263 | void __init setup_arch (char **cmdline_p) |
| 264 | { |
| 265 | struct clk *cpu_clk; |
| 266 | |
| 267 | parse_tags(bootloader_tags); |
| 268 | |
| 269 | setup_processor(); |
| 270 | setup_platform(); |
Haavard Skinnemoen | c194588 | 2006-10-04 16:02:10 +0200 | [diff] [blame] | 271 | setup_board(); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 272 | |
| 273 | cpu_clk = clk_get(NULL, "cpu"); |
| 274 | if (IS_ERR(cpu_clk)) { |
| 275 | printk(KERN_WARNING "Warning: Unable to get CPU clock\n"); |
| 276 | } else { |
| 277 | unsigned long cpu_hz = clk_get_rate(cpu_clk); |
| 278 | |
| 279 | /* |
| 280 | * Well, duh, but it's probably a good idea to |
| 281 | * increment the use count. |
| 282 | */ |
| 283 | clk_enable(cpu_clk); |
| 284 | |
| 285 | boot_cpu_data.clk = cpu_clk; |
| 286 | boot_cpu_data.loops_per_jiffy = cpu_hz * 4; |
| 287 | printk("CPU: Running at %lu.%03lu MHz\n", |
| 288 | ((cpu_hz + 500) / 1000) / 1000, |
| 289 | ((cpu_hz + 500) / 1000) % 1000); |
| 290 | } |
| 291 | |
| 292 | init_mm.start_code = (unsigned long) &_text; |
| 293 | init_mm.end_code = (unsigned long) &_etext; |
| 294 | init_mm.end_data = (unsigned long) &_edata; |
| 295 | init_mm.brk = (unsigned long) &_end; |
| 296 | |
Alon Bar-Lev | bf4352c | 2007-02-12 00:54:08 -0800 | [diff] [blame^] | 297 | strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 298 | *cmdline_p = command_line; |
| 299 | parse_early_param(); |
| 300 | |
| 301 | setup_bootmem(); |
| 302 | |
| 303 | board_setup_fbmem(fbmem_start, fbmem_size); |
| 304 | |
| 305 | #ifdef CONFIG_VT |
| 306 | conswitchp = &dummy_con; |
| 307 | #endif |
| 308 | |
| 309 | paging_init(); |
| 310 | |
| 311 | resource_init(); |
| 312 | } |