Paul Mundt | 711fa80 | 2006-10-03 13:14:04 +0900 | [diff] [blame] | 1 | /* |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 2 | * arch/sh/kernel/setup.c |
| 3 | * |
| 4 | * This file handles the architecture-dependent parts of initialization |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * Copyright (C) 1999 Niibe Yutaka |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 7 | * Copyright (C) 2002 - 2006 Paul Mundt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
Jon Smirl | 894673e | 2006-07-10 04:44:13 -0700 | [diff] [blame] | 9 | #include <linux/screen_info.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/ioport.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/initrd.h> |
| 13 | #include <linux/bootmem.h> |
| 14 | #include <linux/console.h> |
| 15 | #include <linux/seq_file.h> |
| 16 | #include <linux/root_dev.h> |
| 17 | #include <linux/utsname.h> |
| 18 | #include <linux/cpu.h> |
Dave Hansen | 22a9835 | 2006-03-27 01:16:04 -0800 | [diff] [blame] | 19 | #include <linux/pfn.h> |
Paul Mundt | 711fa80 | 2006-10-03 13:14:04 +0900 | [diff] [blame] | 20 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/uaccess.h> |
| 22 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/sections.h> |
| 24 | #include <asm/irq.h> |
| 25 | #include <asm/setup.h> |
Paul Mundt | de02797 | 2006-02-01 03:06:02 -0800 | [diff] [blame] | 26 | #include <asm/clock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | extern void * __rd_start, * __rd_end; |
Paul Mundt | fa5da2f | 2007-03-08 17:27:37 +0900 | [diff] [blame^] | 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | /* |
| 31 | * Machine setup.. |
| 32 | */ |
| 33 | |
| 34 | /* |
| 35 | * Initialize loops_per_jiffy as 10000000 (1000MIPS). |
| 36 | * This value will be used at the very early stage of serial setup. |
| 37 | * The bigger value means no problem. |
| 38 | */ |
Paul Mundt | de02797 | 2006-02-01 03:06:02 -0800 | [diff] [blame] | 39 | struct sh_cpuinfo boot_cpu_data = { CPU_SH_NONE, 10000000, }; |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 40 | #ifdef CONFIG_VT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | struct screen_info screen_info; |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 42 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | #if defined(CONFIG_SH_UNKNOWN) |
| 45 | struct sh_machine_vector sh_mv; |
| 46 | #endif |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | extern int root_mountflags; |
| 49 | |
| 50 | #define MV_NAME_SIZE 32 |
| 51 | |
| 52 | static struct sh_machine_vector* __init get_mv_byname(const char* name); |
| 53 | |
| 54 | /* |
| 55 | * This is set up by the setup-routine at boot-time |
| 56 | */ |
| 57 | #define PARAM ((unsigned char *)empty_zero_page) |
| 58 | |
| 59 | #define MOUNT_ROOT_RDONLY (*(unsigned long *) (PARAM+0x000)) |
| 60 | #define RAMDISK_FLAGS (*(unsigned long *) (PARAM+0x004)) |
| 61 | #define ORIG_ROOT_DEV (*(unsigned long *) (PARAM+0x008)) |
| 62 | #define LOADER_TYPE (*(unsigned long *) (PARAM+0x00c)) |
| 63 | #define INITRD_START (*(unsigned long *) (PARAM+0x010)) |
| 64 | #define INITRD_SIZE (*(unsigned long *) (PARAM+0x014)) |
| 65 | /* ... */ |
| 66 | #define COMMAND_LINE ((char *) (PARAM+0x100)) |
| 67 | |
Paul Mundt | 65463b7 | 2005-11-07 00:58:24 -0800 | [diff] [blame] | 68 | #define RAMDISK_IMAGE_START_MASK 0x07FF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #define RAMDISK_PROMPT_FLAG 0x8000 |
Paul Mundt | 65463b7 | 2005-11-07 00:58:24 -0800 | [diff] [blame] | 70 | #define RAMDISK_LOAD_FLAG 0x4000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Alon Bar-Lev | 53c8262 | 2007-02-12 00:54:19 -0800 | [diff] [blame] | 72 | static char __initdata command_line[COMMAND_LINE_SIZE] = { 0, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 74 | static struct resource code_resource = { .name = "Kernel code", }; |
| 75 | static struct resource data_resource = { .name = "Kernel data", }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | unsigned long memory_start, memory_end; |
| 78 | |
| 79 | static inline void parse_cmdline (char ** cmdline_p, char mv_name[MV_NAME_SIZE], |
| 80 | struct sh_machine_vector** mvp, |
Paul Mundt | b641fe0 | 2006-12-12 09:00:47 +0900 | [diff] [blame] | 81 | unsigned long *mv_io_base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
| 83 | char c = ' ', *to = command_line, *from = COMMAND_LINE; |
| 84 | int len = 0; |
| 85 | |
| 86 | /* Save unparsed command line copy for /proc/cmdline */ |
Alon Bar-Lev | 53c8262 | 2007-02-12 00:54:19 -0800 | [diff] [blame] | 87 | memcpy(boot_command_line, COMMAND_LINE, COMMAND_LINE_SIZE); |
| 88 | boot_command_line[COMMAND_LINE_SIZE-1] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | memory_start = (unsigned long)PAGE_OFFSET+__MEMORY_START; |
| 91 | memory_end = memory_start + __MEMORY_SIZE; |
| 92 | |
| 93 | for (;;) { |
| 94 | /* |
| 95 | * "mem=XXX[kKmM]" defines a size of memory. |
| 96 | */ |
| 97 | if (c == ' ' && !memcmp(from, "mem=", 4)) { |
| 98 | if (to != command_line) |
| 99 | to--; |
| 100 | { |
| 101 | unsigned long mem_size; |
| 102 | |
| 103 | mem_size = memparse(from+4, &from); |
| 104 | memory_end = memory_start + mem_size; |
| 105 | } |
| 106 | } |
Paul Mundt | a80fd21 | 2006-09-27 14:26:53 +0900 | [diff] [blame] | 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | if (c == ' ' && !memcmp(from, "sh_mv=", 6)) { |
| 109 | char* mv_end; |
| 110 | char* mv_comma; |
| 111 | int mv_len; |
| 112 | if (to != command_line) |
| 113 | to--; |
| 114 | from += 6; |
| 115 | mv_end = strchr(from, ' '); |
| 116 | if (mv_end == NULL) |
| 117 | mv_end = from + strlen(from); |
| 118 | |
| 119 | mv_comma = strchr(from, ','); |
| 120 | if ((mv_comma != NULL) && (mv_comma < mv_end)) { |
| 121 | int ints[3]; |
| 122 | get_options(mv_comma+1, ARRAY_SIZE(ints), ints); |
| 123 | *mv_io_base = ints[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | mv_len = mv_comma - from; |
| 125 | } else { |
| 126 | mv_len = mv_end - from; |
| 127 | } |
| 128 | if (mv_len > (MV_NAME_SIZE-1)) |
| 129 | mv_len = MV_NAME_SIZE-1; |
| 130 | memcpy(mv_name, from, mv_len); |
| 131 | mv_name[mv_len] = '\0'; |
| 132 | from = mv_end; |
| 133 | |
| 134 | *mvp = get_mv_byname(mv_name); |
| 135 | } |
Paul Mundt | b641fe0 | 2006-12-12 09:00:47 +0900 | [diff] [blame] | 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | c = *(from++); |
| 138 | if (!c) |
| 139 | break; |
| 140 | if (COMMAND_LINE_SIZE <= ++len) |
| 141 | break; |
| 142 | *(to++) = c; |
| 143 | } |
| 144 | *to = '\0'; |
| 145 | *cmdline_p = command_line; |
| 146 | } |
| 147 | |
| 148 | static int __init sh_mv_setup(char **cmdline_p) |
| 149 | { |
Paul Mundt | 50373c1 | 2006-02-01 03:06:03 -0800 | [diff] [blame] | 150 | #ifdef CONFIG_SH_UNKNOWN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | extern struct sh_machine_vector mv_unknown; |
| 152 | #endif |
| 153 | struct sh_machine_vector *mv = NULL; |
| 154 | char mv_name[MV_NAME_SIZE] = ""; |
| 155 | unsigned long mv_io_base = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Paul Mundt | b641fe0 | 2006-12-12 09:00:47 +0900 | [diff] [blame] | 157 | parse_cmdline(cmdline_p, mv_name, &mv, &mv_io_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Paul Mundt | 50373c1 | 2006-02-01 03:06:03 -0800 | [diff] [blame] | 159 | #ifdef CONFIG_SH_UNKNOWN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | if (mv == NULL) { |
| 161 | mv = &mv_unknown; |
| 162 | if (*mv_name != '\0') { |
| 163 | printk("Warning: Unsupported machine %s, using unknown\n", |
| 164 | mv_name); |
| 165 | } |
| 166 | } |
| 167 | sh_mv = *mv; |
| 168 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | /* |
| 171 | * Manually walk the vec, fill in anything that the board hasn't yet |
| 172 | * by hand, wrapping to the generic implementation. |
| 173 | */ |
| 174 | #define mv_set(elem) do { \ |
| 175 | if (!sh_mv.mv_##elem) \ |
| 176 | sh_mv.mv_##elem = generic_##elem; \ |
| 177 | } while (0) |
| 178 | |
| 179 | mv_set(inb); mv_set(inw); mv_set(inl); |
| 180 | mv_set(outb); mv_set(outw); mv_set(outl); |
| 181 | |
| 182 | mv_set(inb_p); mv_set(inw_p); mv_set(inl_p); |
| 183 | mv_set(outb_p); mv_set(outw_p); mv_set(outl_p); |
| 184 | |
| 185 | mv_set(insb); mv_set(insw); mv_set(insl); |
| 186 | mv_set(outsb); mv_set(outsw); mv_set(outsl); |
| 187 | |
| 188 | mv_set(readb); mv_set(readw); mv_set(readl); |
| 189 | mv_set(writeb); mv_set(writew); mv_set(writel); |
| 190 | |
Paul Mundt | 50373c1 | 2006-02-01 03:06:03 -0800 | [diff] [blame] | 191 | mv_set(ioport_map); |
| 192 | mv_set(ioport_unmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | mv_set(irq_demux); |
| 194 | |
| 195 | #ifdef CONFIG_SH_UNKNOWN |
| 196 | __set_io_port_base(mv_io_base); |
| 197 | #endif |
| 198 | |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 199 | if (!sh_mv.mv_nr_irqs) |
| 200 | sh_mv.mv_nr_irqs = NR_IRQS; |
| 201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | void __init setup_arch(char **cmdline_p) |
| 206 | { |
| 207 | unsigned long bootmap_size; |
| 208 | unsigned long start_pfn, max_pfn, max_low_pfn; |
| 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | #ifdef CONFIG_CMDLINE_BOOL |
| 211 | strcpy(COMMAND_LINE, CONFIG_CMDLINE); |
| 212 | #endif |
| 213 | |
| 214 | ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV); |
| 215 | |
| 216 | #ifdef CONFIG_BLK_DEV_RAM |
| 217 | rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK; |
| 218 | rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0); |
| 219 | rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0); |
| 220 | #endif |
| 221 | |
| 222 | if (!MOUNT_ROOT_RDONLY) |
| 223 | root_mountflags &= ~MS_RDONLY; |
| 224 | init_mm.start_code = (unsigned long) _text; |
| 225 | init_mm.end_code = (unsigned long) _etext; |
| 226 | init_mm.end_data = (unsigned long) _edata; |
| 227 | init_mm.brk = (unsigned long) _end; |
| 228 | |
Paul Mundt | de02797 | 2006-02-01 03:06:02 -0800 | [diff] [blame] | 229 | code_resource.start = (unsigned long)virt_to_phys(_text); |
| 230 | code_resource.end = (unsigned long)virt_to_phys(_etext)-1; |
| 231 | data_resource.start = (unsigned long)virt_to_phys(_etext); |
| 232 | data_resource.end = (unsigned long)virt_to_phys(_edata)-1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | sh_mv_setup(cmdline_p); |
| 235 | |
Paul Mundt | b641fe0 | 2006-12-12 09:00:47 +0900 | [diff] [blame] | 236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | /* |
| 238 | * Find the highest page frame number we have available |
| 239 | */ |
| 240 | max_pfn = PFN_DOWN(__pa(memory_end)); |
| 241 | |
| 242 | /* |
| 243 | * Determine low and high memory ranges: |
| 244 | */ |
| 245 | max_low_pfn = max_pfn; |
| 246 | |
Paul Mundt | 65463b7 | 2005-11-07 00:58:24 -0800 | [diff] [blame] | 247 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | * Partially used pages are not usable - thus |
| 249 | * we are rounding upwards: |
Paul Mundt | 65463b7 | 2005-11-07 00:58:24 -0800 | [diff] [blame] | 250 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | start_pfn = PFN_UP(__pa(_end)); |
| 252 | |
| 253 | /* |
| 254 | * Find a proper area for the bootmem bitmap. After this |
| 255 | * bootstrap step all allocations (until the page allocator |
| 256 | * is intact) must be done via bootmem_alloc(). |
| 257 | */ |
| 258 | bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn, |
| 259 | __MEMORY_START>>PAGE_SHIFT, |
| 260 | max_low_pfn); |
| 261 | /* |
| 262 | * Register fully available low RAM pages with the bootmem allocator. |
| 263 | */ |
| 264 | { |
| 265 | unsigned long curr_pfn, last_pfn, pages; |
| 266 | |
| 267 | /* |
| 268 | * We are rounding up the start address of usable memory: |
| 269 | */ |
| 270 | curr_pfn = PFN_UP(__MEMORY_START); |
| 271 | /* |
| 272 | * ... and at the end of the usable range downwards: |
| 273 | */ |
| 274 | last_pfn = PFN_DOWN(__pa(memory_end)); |
| 275 | |
| 276 | if (last_pfn > max_low_pfn) |
| 277 | last_pfn = max_low_pfn; |
| 278 | |
| 279 | pages = last_pfn - curr_pfn; |
| 280 | free_bootmem_node(NODE_DATA(0), PFN_PHYS(curr_pfn), |
| 281 | PFN_PHYS(pages)); |
| 282 | } |
| 283 | |
Paul Mundt | b641fe0 | 2006-12-12 09:00:47 +0900 | [diff] [blame] | 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | /* |
| 286 | * Reserve the kernel text and |
| 287 | * Reserve the bootmem bitmap. We do this in two steps (first step |
| 288 | * was init_bootmem()), because this catches the (definitely buggy) |
| 289 | * case of us accidentally initializing the bootmem allocator with |
| 290 | * an invalid RAM area. |
| 291 | */ |
| 292 | reserve_bootmem_node(NODE_DATA(0), __MEMORY_START+PAGE_SIZE, |
| 293 | (PFN_PHYS(start_pfn)+bootmap_size+PAGE_SIZE-1)-__MEMORY_START); |
| 294 | |
| 295 | /* |
| 296 | * reserve physical page 0 - it's a special BIOS page on many boxes, |
| 297 | * enabling clean reboots, SMP operation, laptop functions. |
| 298 | */ |
| 299 | reserve_bootmem_node(NODE_DATA(0), __MEMORY_START, PAGE_SIZE); |
| 300 | |
| 301 | #ifdef CONFIG_BLK_DEV_INITRD |
Paul Mundt | 65463b7 | 2005-11-07 00:58:24 -0800 | [diff] [blame] | 302 | ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0); |
| 303 | if (&__rd_start != &__rd_end) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | LOADER_TYPE = 1; |
Paul Mundt | 41504c3 | 2006-12-11 20:28:03 +0900 | [diff] [blame] | 305 | INITRD_START = PHYSADDR((unsigned long)&__rd_start) - |
| 306 | __MEMORY_START; |
| 307 | INITRD_SIZE = (unsigned long)&__rd_end - |
| 308 | (unsigned long)&__rd_start; |
Paul Mundt | 65463b7 | 2005-11-07 00:58:24 -0800 | [diff] [blame] | 309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
| 311 | if (LOADER_TYPE && INITRD_START) { |
| 312 | if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) { |
Paul Mundt | 41504c3 | 2006-12-11 20:28:03 +0900 | [diff] [blame] | 313 | reserve_bootmem_node(NODE_DATA(0), INITRD_START + |
| 314 | __MEMORY_START, INITRD_SIZE); |
| 315 | initrd_start = INITRD_START + PAGE_OFFSET + |
| 316 | __MEMORY_START; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | initrd_end = initrd_start + INITRD_SIZE; |
| 318 | } else { |
| 319 | printk("initrd extends beyond end of memory " |
| 320 | "(0x%08lx > 0x%08lx)\ndisabling initrd\n", |
| 321 | INITRD_START + INITRD_SIZE, |
| 322 | max_low_pfn << PAGE_SHIFT); |
| 323 | initrd_start = 0; |
| 324 | } |
| 325 | } |
| 326 | #endif |
| 327 | |
| 328 | #ifdef CONFIG_DUMMY_CONSOLE |
| 329 | conswitchp = &dummy_con; |
| 330 | #endif |
| 331 | |
| 332 | /* Perform the machine specific initialisation */ |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 333 | if (likely(sh_mv.mv_setup)) |
| 334 | sh_mv.mv_setup(cmdline_p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
| 336 | paging_init(); |
| 337 | } |
| 338 | |
| 339 | struct sh_machine_vector* __init get_mv_byname(const char* name) |
| 340 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | extern long __machvec_start, __machvec_end; |
| 342 | struct sh_machine_vector *all_vecs = |
| 343 | (struct sh_machine_vector *)&__machvec_start; |
| 344 | |
| 345 | int i, n = ((unsigned long)&__machvec_end |
| 346 | - (unsigned long)&__machvec_start)/ |
| 347 | sizeof(struct sh_machine_vector); |
| 348 | |
| 349 | for (i = 0; i < n; ++i) { |
| 350 | struct sh_machine_vector *mv = &all_vecs[i]; |
| 351 | if (mv == NULL) |
| 352 | continue; |
| 353 | if (strcasecmp(name, get_system_type()) == 0) { |
| 354 | return mv; |
| 355 | } |
| 356 | } |
| 357 | return NULL; |
| 358 | } |
| 359 | |
| 360 | static struct cpu cpu[NR_CPUS]; |
| 361 | |
| 362 | static int __init topology_init(void) |
| 363 | { |
| 364 | int cpu_id; |
| 365 | |
KAMEZAWA Hiroyuki | bc83db4 | 2006-03-31 02:30:02 -0800 | [diff] [blame] | 366 | for_each_possible_cpu(cpu_id) |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 367 | register_cpu(&cpu[cpu_id], cpu_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | subsys_initcall(topology_init); |
| 373 | |
| 374 | static const char *cpu_name[] = { |
Paul Mundt | b552c7e | 2006-11-20 14:14:29 +0900 | [diff] [blame] | 375 | [CPU_SH7206] = "SH7206", [CPU_SH7619] = "SH7619", |
Paul Mundt | e5723e0 | 2006-09-27 17:38:11 +0900 | [diff] [blame] | 376 | [CPU_SH7604] = "SH7604", [CPU_SH7300] = "SH7300", |
| 377 | [CPU_SH7705] = "SH7705", [CPU_SH7706] = "SH7706", |
| 378 | [CPU_SH7707] = "SH7707", [CPU_SH7708] = "SH7708", |
| 379 | [CPU_SH7709] = "SH7709", [CPU_SH7710] = "SH7710", |
| 380 | [CPU_SH7729] = "SH7729", [CPU_SH7750] = "SH7750", |
| 381 | [CPU_SH7750S] = "SH7750S", [CPU_SH7750R] = "SH7750R", |
| 382 | [CPU_SH7751] = "SH7751", [CPU_SH7751R] = "SH7751R", |
| 383 | [CPU_SH7760] = "SH7760", [CPU_SH73180] = "SH73180", |
| 384 | [CPU_ST40RA] = "ST40RA", [CPU_ST40GX1] = "ST40GX1", |
| 385 | [CPU_SH4_202] = "SH4-202", [CPU_SH4_501] = "SH4-501", |
| 386 | [CPU_SH7770] = "SH7770", [CPU_SH7780] = "SH7780", |
| 387 | [CPU_SH7781] = "SH7781", [CPU_SH7343] = "SH7343", |
Paul Mundt | 41504c3 | 2006-12-11 20:28:03 +0900 | [diff] [blame] | 388 | [CPU_SH7785] = "SH7785", [CPU_SH7722] = "SH7722", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | [CPU_SH_NONE] = "Unknown" |
| 390 | }; |
| 391 | |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 392 | const char *get_cpu_subtype(struct sh_cpuinfo *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | { |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 394 | return cpu_name[c->type]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | #ifdef CONFIG_PROC_FS |
Paul Mundt | 2220d16 | 2006-09-27 18:24:28 +0900 | [diff] [blame] | 398 | /* Symbolic CPU flags, keep in sync with asm/cpu-features.h */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | static const char *cpu_flags[] = { |
Paul Mundt | 2220d16 | 2006-09-27 18:24:28 +0900 | [diff] [blame] | 400 | "none", "fpu", "p2flush", "mmuassoc", "dsp", "perfctr", |
Paul Mundt | 72c3554 | 2006-09-27 18:27:43 +0900 | [diff] [blame] | 401 | "ptea", "llsc", "l2", NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | }; |
| 403 | |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 404 | static void show_cpuflags(struct seq_file *m, struct sh_cpuinfo *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | { |
| 406 | unsigned long i; |
| 407 | |
| 408 | seq_printf(m, "cpu flags\t:"); |
| 409 | |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 410 | if (!c->flags) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | seq_printf(m, " %s\n", cpu_flags[0]); |
| 412 | return; |
| 413 | } |
| 414 | |
Paul Mundt | de02797 | 2006-02-01 03:06:02 -0800 | [diff] [blame] | 415 | for (i = 0; cpu_flags[i]; i++) |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 416 | if ((c->flags & (1 << i))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | seq_printf(m, " %s", cpu_flags[i+1]); |
| 418 | |
| 419 | seq_printf(m, "\n"); |
| 420 | } |
| 421 | |
Paul Mundt | 2c7834a | 2006-09-27 18:17:31 +0900 | [diff] [blame] | 422 | static void show_cacheinfo(struct seq_file *m, const char *type, |
| 423 | struct cache_info info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | { |
| 425 | unsigned int cache_size; |
| 426 | |
| 427 | cache_size = info.ways * info.sets * info.linesz; |
| 428 | |
Paul Mundt | de02797 | 2006-02-01 03:06:02 -0800 | [diff] [blame] | 429 | seq_printf(m, "%s size\t: %2dKiB (%d-way)\n", |
| 430 | type, cache_size >> 10, info.ways); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /* |
| 434 | * Get CPU information for use by the procfs. |
| 435 | */ |
| 436 | static int show_cpuinfo(struct seq_file *m, void *v) |
| 437 | { |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 438 | struct sh_cpuinfo *c = v; |
| 439 | unsigned int cpu = c - cpu_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 441 | if (!cpu_online(cpu)) |
| 442 | return 0; |
| 443 | |
| 444 | if (cpu == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | seq_printf(m, "machine\t\t: %s\n", get_system_type()); |
| 446 | |
| 447 | seq_printf(m, "processor\t: %d\n", cpu); |
Serge E. Hallyn | 96b644b | 2006-10-02 02:18:13 -0700 | [diff] [blame] | 448 | seq_printf(m, "cpu family\t: %s\n", init_utsname()->machine); |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 449 | seq_printf(m, "cpu type\t: %s\n", get_cpu_subtype(c)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 451 | show_cpuflags(m, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
| 453 | seq_printf(m, "cache type\t: "); |
| 454 | |
| 455 | /* |
| 456 | * Check for what type of cache we have, we support both the |
| 457 | * unified cache on the SH-2 and SH-3, as well as the harvard |
| 458 | * style cache on the SH-4. |
| 459 | */ |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 460 | if (c->icache.flags & SH_CACHE_COMBINED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | seq_printf(m, "unified\n"); |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 462 | show_cacheinfo(m, "cache", c->icache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | } else { |
| 464 | seq_printf(m, "split (harvard)\n"); |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 465 | show_cacheinfo(m, "icache", c->icache); |
| 466 | show_cacheinfo(m, "dcache", c->dcache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Paul Mundt | 72c3554 | 2006-09-27 18:27:43 +0900 | [diff] [blame] | 469 | /* Optional secondary cache */ |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 470 | if (c->flags & CPU_HAS_L2_CACHE) |
| 471 | show_cacheinfo(m, "scache", c->scache); |
Paul Mundt | 72c3554 | 2006-09-27 18:27:43 +0900 | [diff] [blame] | 472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | seq_printf(m, "bogomips\t: %lu.%02lu\n", |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 474 | c->loops_per_jiffy/(500000/HZ), |
| 475 | (c->loops_per_jiffy/(5000/HZ)) % 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
Paul Mundt | de02797 | 2006-02-01 03:06:02 -0800 | [diff] [blame] | 477 | return show_clocks(m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | static void *c_start(struct seq_file *m, loff_t *pos) |
| 481 | { |
| 482 | return *pos < NR_CPUS ? cpu_data + *pos : NULL; |
| 483 | } |
| 484 | static void *c_next(struct seq_file *m, void *v, loff_t *pos) |
| 485 | { |
| 486 | ++*pos; |
| 487 | return c_start(m, pos); |
| 488 | } |
| 489 | static void c_stop(struct seq_file *m, void *v) |
| 490 | { |
| 491 | } |
| 492 | struct seq_operations cpuinfo_op = { |
| 493 | .start = c_start, |
| 494 | .next = c_next, |
| 495 | .stop = c_stop, |
| 496 | .show = show_cpuinfo, |
| 497 | }; |
| 498 | #endif /* CONFIG_PROC_FS */ |