Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[MIPS] setup.c: use early_param() for early command line parsing

There's no point to rewrite some logic to parse command line
to pass initrd parameters or to declare a user memory area.
We could use instead parse_early_param() that does the same
thing.

Signed-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Franck Bui-Huu and committed by
Ralf Baechle
a09fc446 1c6fd44d

+60 -112
+60 -112
arch/mips/kernel/setup.c
··· 135 135 } 136 136 } 137 137 138 - static void __init parse_cmdline_early(void) 139 - { 140 - char c = ' ', *to = command_line, *from = saved_command_line; 141 - unsigned long start_at, mem_size; 142 - int len = 0; 143 - int usermem = 0; 144 - 145 - printk("Determined physical RAM map:\n"); 146 - print_memory_map(); 147 - 148 - for (;;) { 149 - /* 150 - * "mem=XXX[kKmM]" defines a memory region from 151 - * 0 to <XXX>, overriding the determined size. 152 - * "mem=XXX[KkmM]@YYY[KkmM]" defines a memory region from 153 - * <YYY> to <YYY>+<XXX>, overriding the determined size. 154 - */ 155 - if (c == ' ' && !memcmp(from, "mem=", 4)) { 156 - if (to != command_line) 157 - to--; 158 - /* 159 - * If a user specifies memory size, we 160 - * blow away any automatically generated 161 - * size. 162 - */ 163 - if (usermem == 0) { 164 - boot_mem_map.nr_map = 0; 165 - usermem = 1; 166 - } 167 - mem_size = memparse(from + 4, &from); 168 - if (*from == '@') 169 - start_at = memparse(from + 1, &from); 170 - else 171 - start_at = 0; 172 - add_memory_region(start_at, mem_size, BOOT_MEM_RAM); 173 - } 174 - c = *(from++); 175 - if (!c) 176 - break; 177 - if (CL_SIZE <= ++len) 178 - break; 179 - *(to++) = c; 180 - } 181 - *to = '\0'; 182 - 183 - if (usermem) { 184 - printk("User-defined physical RAM map:\n"); 185 - print_memory_map(); 186 - } 187 - } 188 - 189 138 /* 190 139 * Manage initrd 191 140 */ 192 141 #ifdef CONFIG_BLK_DEV_INITRD 193 142 194 - static int __init parse_rd_cmdline(unsigned long *rd_start, unsigned long *rd_end) 143 + static int __init rd_start_early(char *p) 195 144 { 196 - /* 197 - * "rd_start=0xNNNNNNNN" defines the memory address of an initrd 198 - * "rd_size=0xNN" it's size 199 - */ 200 - unsigned long start = 0; 201 - unsigned long size = 0; 202 - unsigned long end; 203 - char cmd_line[CL_SIZE]; 204 - char *start_str; 205 - char *size_str; 206 - char *tmp; 207 - 208 - strcpy(cmd_line, command_line); 209 - *command_line = 0; 210 - tmp = cmd_line; 211 - /* Ignore "rd_start=" strings in other parameters. */ 212 - start_str = strstr(cmd_line, "rd_start="); 213 - if (start_str && start_str != cmd_line && *(start_str - 1) != ' ') 214 - start_str = strstr(start_str, " rd_start="); 215 - while (start_str) { 216 - if (start_str != cmd_line) 217 - strncat(command_line, tmp, start_str - tmp); 218 - start = memparse(start_str + 9, &start_str); 219 - tmp = start_str + 1; 220 - start_str = strstr(start_str, " rd_start="); 221 - } 222 - if (*tmp) 223 - strcat(command_line, tmp); 224 - 225 - strcpy(cmd_line, command_line); 226 - *command_line = 0; 227 - tmp = cmd_line; 228 - /* Ignore "rd_size" strings in other parameters. */ 229 - size_str = strstr(cmd_line, "rd_size="); 230 - if (size_str && size_str != cmd_line && *(size_str - 1) != ' ') 231 - size_str = strstr(size_str, " rd_size="); 232 - while (size_str) { 233 - if (size_str != cmd_line) 234 - strncat(command_line, tmp, size_str - tmp); 235 - size = memparse(size_str + 8, &size_str); 236 - tmp = size_str + 1; 237 - size_str = strstr(size_str, " rd_size="); 238 - } 239 - if (*tmp) 240 - strcat(command_line, tmp); 145 + unsigned long start = memparse(p, &p); 241 146 242 147 #ifdef CONFIG_64BIT 243 148 /* HACK: Guess if the sign extension was forgotten */ 244 149 if (start > 0x0000000080000000 && start < 0x00000000ffffffff) 245 150 start |= 0xffffffff00000000UL; 246 151 #endif 152 + initrd_start = start; 153 + initrd_end += start; 247 154 248 - end = start + size; 249 - if (start && end) { 250 - *rd_start = start; 251 - *rd_end = end; 252 - return 1; 253 - } 254 155 return 0; 255 156 } 157 + early_param("rd_start", rd_start_early); 158 + 159 + static int __init rd_size_early(char *p) 160 + { 161 + initrd_end += memparse(p, &p); 162 + 163 + return 0; 164 + } 165 + early_param("rd_size", rd_size_early); 256 166 257 167 static unsigned long __init init_initrd(void) 258 168 { 259 - unsigned long tmp, end; 169 + unsigned long tmp, end, size; 260 170 u32 *initrd_header; 261 171 262 172 ROOT_DEV = Root_RAM0; 263 173 264 - if (parse_rd_cmdline(&initrd_start, &initrd_end)) 265 - return initrd_end; 266 174 /* 267 - * Board specific code should have set up initrd_start 268 - * and initrd_end... 175 + * Board specific code or command line parser should have 176 + * already set up initrd_start and initrd_end. In these cases 177 + * perfom sanity checks and use them if all looks good. 269 178 */ 179 + size = initrd_end - initrd_start; 180 + if (initrd_end == 0 || size == 0) { 181 + initrd_start = 0; 182 + initrd_end = 0; 183 + } else 184 + return initrd_end; 185 + 270 186 end = (unsigned long)&_end; 271 187 tmp = PAGE_ALIGN(end) - sizeof(u32) * 2; 272 188 if (tmp < end) ··· 352 436 * 353 437 * o plat_mem_setup() detects the memory configuration and will record detected 354 438 * memory areas using add_memory_region. 355 - * o parse_cmdline_early() parses the command line for mem= options which, 356 - * iff detected, will override the results of the automatic detection. 357 439 * 358 440 * At this stage the memory configuration of the system is known to the 359 441 * kernel but generic memory managment system is still entirely uninitialized. ··· 369 455 * initialization hook for anything else was introduced. 370 456 */ 371 457 372 - extern void plat_mem_setup(void); 458 + static int usermem __initdata = 0; 459 + 460 + static int __init early_parse_mem(char *p) 461 + { 462 + unsigned long start, size; 463 + 464 + /* 465 + * If a user specifies memory size, we 466 + * blow away any automatically generated 467 + * size. 468 + */ 469 + if (usermem == 0) { 470 + boot_mem_map.nr_map = 0; 471 + usermem = 1; 472 + } 473 + start = 0; 474 + size = memparse(p, &p); 475 + if (*p == '@') 476 + start = memparse(p + 1, &p); 477 + 478 + add_memory_region(start, size, BOOT_MEM_RAM); 479 + return 0; 480 + } 481 + early_param("mem", early_parse_mem); 373 482 374 483 static void __init arch_mem_init(char **cmdline_p) 375 484 { 485 + extern void plat_mem_setup(void); 486 + 376 487 /* call board setup routine */ 377 488 plat_mem_setup(); 489 + 490 + printk("Determined physical RAM map:\n"); 491 + print_memory_map(); 378 492 379 493 strlcpy(command_line, arcs_cmdline, sizeof(command_line)); 380 494 strlcpy(saved_command_line, command_line, COMMAND_LINE_SIZE); 381 495 382 496 *cmdline_p = command_line; 383 497 384 - parse_cmdline_early(); 498 + parse_early_param(); 499 + 500 + if (usermem) { 501 + printk("User-defined physical RAM map:\n"); 502 + print_memory_map(); 503 + } 504 + 385 505 bootmem_init(); 386 506 sparse_init(); 387 507 paging_init();