prom.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2011 Zhang, Keguang <keguang.zhang@gmail.com>
  3. *
  4. * Modified from arch/mips/pnx833x/common/prom.c.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <linux/serial_reg.h>
  12. #include <asm/bootinfo.h>
  13. #include <loongson1.h>
  14. #include <prom.h>
  15. int prom_argc;
  16. char **prom_argv, **prom_envp;
  17. unsigned long memsize, highmemsize;
  18. char *prom_getenv(char *envname)
  19. {
  20. char **env = prom_envp;
  21. int i;
  22. i = strlen(envname);
  23. while (*env) {
  24. if (strncmp(envname, *env, i) == 0 && *(*env + i) == '=')
  25. return *env + i + 1;
  26. env++;
  27. }
  28. return 0;
  29. }
  30. static inline unsigned long env_or_default(char *env, unsigned long dfl)
  31. {
  32. char *str = prom_getenv(env);
  33. return str ? simple_strtol(str, 0, 0) : dfl;
  34. }
  35. void __init prom_init_cmdline(void)
  36. {
  37. char *c = &(arcs_cmdline[0]);
  38. int i;
  39. for (i = 1; i < prom_argc; i++) {
  40. strcpy(c, prom_argv[i]);
  41. c += strlen(prom_argv[i]);
  42. if (i < prom_argc - 1)
  43. *c++ = ' ';
  44. }
  45. *c = 0;
  46. }
  47. void __init prom_init(void)
  48. {
  49. void __iomem *uart_base;
  50. prom_argc = fw_arg0;
  51. prom_argv = (char **)fw_arg1;
  52. prom_envp = (char **)fw_arg2;
  53. prom_init_cmdline();
  54. memsize = env_or_default("memsize", DEFAULT_MEMSIZE);
  55. highmemsize = env_or_default("highmemsize", 0x0);
  56. if (strstr(arcs_cmdline, "console=ttyS3"))
  57. uart_base = ioremap_nocache(LS1X_UART3_BASE, 0x0f);
  58. else if (strstr(arcs_cmdline, "console=ttyS2"))
  59. uart_base = ioremap_nocache(LS1X_UART2_BASE, 0x0f);
  60. else if (strstr(arcs_cmdline, "console=ttyS1"))
  61. uart_base = ioremap_nocache(LS1X_UART1_BASE, 0x0f);
  62. else
  63. uart_base = ioremap_nocache(LS1X_UART0_BASE, 0x0f);
  64. setup_8250_early_printk_port((unsigned long)uart_base, 0, 0);
  65. }
  66. void __init prom_free_prom_memory(void)
  67. {
  68. }