init.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (C) 1999, 2000, 2004, 2005 MIPS Technologies, Inc.
  3. * All rights reserved.
  4. * Authors: Carsten Langgaard <carstenl@mips.com>
  5. * Maciej W. Rozycki <macro@mips.com>
  6. * Portions copyright (C) 2009 Cisco Systems, Inc.
  7. *
  8. * This program is free software; you can distribute it and/or modify it
  9. * under the terms of the GNU General Public License (Version 2) as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. * for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  20. *
  21. * PROM library initialisation code.
  22. */
  23. #include <linux/init.h>
  24. #include <linux/string.h>
  25. #include <linux/kernel.h>
  26. #include <asm/bootinfo.h>
  27. #include <linux/io.h>
  28. #include <asm/system.h>
  29. #include <asm/cacheflush.h>
  30. #include <asm/traps.h>
  31. #include <asm/mips-boards/prom.h>
  32. #include <asm/mips-boards/generic.h>
  33. #include <asm/mach-powertv/asic.h>
  34. static int *_prom_envp;
  35. unsigned long _prom_memsize;
  36. /*
  37. * YAMON (32-bit PROM) pass arguments and environment as 32-bit pointer.
  38. * This macro take care of sign extension, if running in 64-bit mode.
  39. */
  40. #define prom_envp(index) ((char *)(long)_prom_envp[(index)])
  41. char *prom_getenv(char *envname)
  42. {
  43. char *result = NULL;
  44. if (_prom_envp != NULL) {
  45. /*
  46. * Return a pointer to the given environment variable.
  47. * In 64-bit mode: we're using 64-bit pointers, but all pointers
  48. * in the PROM structures are only 32-bit, so we need some
  49. * workarounds, if we are running in 64-bit mode.
  50. */
  51. int i, index = 0;
  52. i = strlen(envname);
  53. while (prom_envp(index)) {
  54. if (strncmp(envname, prom_envp(index), i) == 0) {
  55. result = prom_envp(index + 1);
  56. break;
  57. }
  58. index += 2;
  59. }
  60. }
  61. return result;
  62. }
  63. /* TODO: Verify on linux-mips mailing list that the following two */
  64. /* functions are correct */
  65. /* TODO: Copy NMI and EJTAG exception vectors to memory from the */
  66. /* BootROM exception vectors. Flush their cache entries. test it. */
  67. static void __init mips_nmi_setup(void)
  68. {
  69. void *base;
  70. #if defined(CONFIG_CPU_MIPS32_R1)
  71. base = cpu_has_veic ?
  72. (void *)(CAC_BASE + 0xa80) :
  73. (void *)(CAC_BASE + 0x380);
  74. #elif defined(CONFIG_CPU_MIPS32_R2)
  75. base = (void *)0xbfc00000;
  76. #else
  77. #error NMI exception handler address not defined
  78. #endif
  79. }
  80. static void __init mips_ejtag_setup(void)
  81. {
  82. void *base;
  83. #if defined(CONFIG_CPU_MIPS32_R1)
  84. base = cpu_has_veic ?
  85. (void *)(CAC_BASE + 0xa00) :
  86. (void *)(CAC_BASE + 0x300);
  87. #elif defined(CONFIG_CPU_MIPS32_R2)
  88. base = (void *)0xbfc00480;
  89. #else
  90. #error EJTAG exception handler address not defined
  91. #endif
  92. }
  93. void __init prom_init(void)
  94. {
  95. int prom_argc;
  96. char *prom_argv;
  97. prom_argc = fw_arg0;
  98. prom_argv = (char *) fw_arg1;
  99. _prom_envp = (int *) fw_arg2;
  100. _prom_memsize = (unsigned long) fw_arg3;
  101. board_nmi_handler_setup = mips_nmi_setup;
  102. board_ejtag_handler_setup = mips_ejtag_setup;
  103. if (prom_argc == 1) {
  104. strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
  105. strlcat(arcs_cmdline, prom_argv, COMMAND_LINE_SIZE);
  106. }
  107. configure_platform();
  108. prom_meminit();
  109. #ifndef CONFIG_BOOTLOADER_DRIVER
  110. pr_info("\nBootloader driver isn't loaded...\n");
  111. #endif
  112. }