setup.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
  3. * reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the NetLogic
  9. * license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR
  23. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  29. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  30. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  31. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  32. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <linux/kernel.h>
  35. #include <linux/serial_8250.h>
  36. #include <linux/pm.h>
  37. #include <asm/reboot.h>
  38. #include <asm/time.h>
  39. #include <asm/bootinfo.h>
  40. #include <asm/smp-ops.h>
  41. #include <asm/netlogic/interrupt.h>
  42. #include <asm/netlogic/psb-bootinfo.h>
  43. #include <asm/netlogic/xlr/xlr.h>
  44. #include <asm/netlogic/xlr/iomap.h>
  45. #include <asm/netlogic/xlr/pic.h>
  46. #include <asm/netlogic/xlr/gpio.h>
  47. unsigned long netlogic_io_base = (unsigned long)(DEFAULT_NETLOGIC_IO_BASE);
  48. unsigned long nlm_common_ebase = 0x0;
  49. struct psb_info nlm_prom_info;
  50. static void nlm_early_serial_setup(void)
  51. {
  52. struct uart_port s;
  53. nlm_reg_t *uart_base;
  54. uart_base = netlogic_io_mmio(NETLOGIC_IO_UART_0_OFFSET);
  55. memset(&s, 0, sizeof(s));
  56. s.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
  57. s.iotype = UPIO_MEM32;
  58. s.regshift = 2;
  59. s.irq = PIC_UART_0_IRQ;
  60. s.uartclk = PIC_CLKS_PER_SEC;
  61. s.serial_in = nlm_xlr_uart_in;
  62. s.serial_out = nlm_xlr_uart_out;
  63. s.mapbase = (unsigned long)uart_base;
  64. s.membase = (unsigned char __iomem *)uart_base;
  65. early_serial_setup(&s);
  66. }
  67. static void nlm_linux_exit(void)
  68. {
  69. nlm_reg_t *mmio;
  70. mmio = netlogic_io_mmio(NETLOGIC_IO_GPIO_OFFSET);
  71. /* trigger a chip reset by writing 1 to GPIO_SWRESET_REG */
  72. netlogic_write_reg(mmio, NETLOGIC_GPIO_SWRESET_REG, 1);
  73. for ( ; ; )
  74. cpu_wait();
  75. }
  76. void __init plat_mem_setup(void)
  77. {
  78. panic_timeout = 5;
  79. _machine_restart = (void (*)(char *))nlm_linux_exit;
  80. _machine_halt = nlm_linux_exit;
  81. pm_power_off = nlm_linux_exit;
  82. }
  83. const char *get_system_type(void)
  84. {
  85. return "Netlogic XLR/XLS Series";
  86. }
  87. void __init prom_free_prom_memory(void)
  88. {
  89. /* Nothing yet */
  90. }
  91. static void build_arcs_cmdline(int *argv)
  92. {
  93. int i, remain, len;
  94. char *arg;
  95. remain = sizeof(arcs_cmdline) - 1;
  96. arcs_cmdline[0] = '\0';
  97. for (i = 0; argv[i] != 0; i++) {
  98. arg = (char *)(long)argv[i];
  99. len = strlen(arg);
  100. if (len + 1 > remain)
  101. break;
  102. strcat(arcs_cmdline, arg);
  103. strcat(arcs_cmdline, " ");
  104. remain -= len + 1;
  105. }
  106. /* Add the default options here */
  107. if ((strstr(arcs_cmdline, "console=")) == NULL) {
  108. arg = "console=ttyS0,38400 ";
  109. len = strlen(arg);
  110. if (len > remain)
  111. goto fail;
  112. strcat(arcs_cmdline, arg);
  113. remain -= len;
  114. }
  115. #ifdef CONFIG_BLK_DEV_INITRD
  116. if ((strstr(arcs_cmdline, "rdinit=")) == NULL) {
  117. arg = "rdinit=/sbin/init ";
  118. len = strlen(arg);
  119. if (len > remain)
  120. goto fail;
  121. strcat(arcs_cmdline, arg);
  122. remain -= len;
  123. }
  124. #endif
  125. return;
  126. fail:
  127. panic("Cannot add %s, command line too big!", arg);
  128. }
  129. static void prom_add_memory(void)
  130. {
  131. struct nlm_boot_mem_map *bootm;
  132. u64 start, size;
  133. u64 pref_backup = 512; /* avoid pref walking beyond end */
  134. int i;
  135. bootm = (void *)(long)nlm_prom_info.psb_mem_map;
  136. for (i = 0; i < bootm->nr_map; i++) {
  137. if (bootm->map[i].type != BOOT_MEM_RAM)
  138. continue;
  139. start = bootm->map[i].addr;
  140. size = bootm->map[i].size;
  141. /* Work around for using bootloader mem */
  142. if (i == 0 && start == 0 && size == 0x0c000000)
  143. size = 0x0ff00000;
  144. add_memory_region(start, size - pref_backup, BOOT_MEM_RAM);
  145. }
  146. }
  147. void __init prom_init(void)
  148. {
  149. int *argv, *envp; /* passed as 32 bit ptrs */
  150. struct psb_info *prom_infop;
  151. /* truncate to 32 bit and sign extend all args */
  152. argv = (int *)(long)(int)fw_arg1;
  153. envp = (int *)(long)(int)fw_arg2;
  154. prom_infop = (struct psb_info *)(long)(int)fw_arg3;
  155. nlm_prom_info = *prom_infop;
  156. nlm_early_serial_setup();
  157. build_arcs_cmdline(argv);
  158. nlm_common_ebase = read_c0_ebase() & (~((1 << 12) - 1));
  159. prom_add_memory();
  160. #ifdef CONFIG_SMP
  161. nlm_wakeup_secondary_cpus(nlm_prom_info.online_cpu_map);
  162. register_smp_ops(&nlm_smp_ops);
  163. #endif
  164. }