setup.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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/idle.h>
  38. #include <asm/reboot.h>
  39. #include <asm/time.h>
  40. #include <asm/bootinfo.h>
  41. #include <asm/netlogic/interrupt.h>
  42. #include <asm/netlogic/psb-bootinfo.h>
  43. #include <asm/netlogic/haldefs.h>
  44. #include <asm/netlogic/common.h>
  45. #include <asm/netlogic/xlr/xlr.h>
  46. #include <asm/netlogic/xlr/iomap.h>
  47. #include <asm/netlogic/xlr/pic.h>
  48. #include <asm/netlogic/xlr/gpio.h>
  49. #include <asm/netlogic/xlr/fmn.h>
  50. uint64_t nlm_io_base = DEFAULT_NETLOGIC_IO_BASE;
  51. struct psb_info nlm_prom_info;
  52. /* default to uniprocessor */
  53. unsigned int nlm_threads_per_core = 1;
  54. struct nlm_soc_info nlm_nodes[NLM_NR_NODES];
  55. cpumask_t nlm_cpumask = CPU_MASK_CPU0;
  56. static void __init nlm_early_serial_setup(void)
  57. {
  58. struct uart_port s;
  59. unsigned long uart_base;
  60. uart_base = (unsigned long)nlm_mmio_base(NETLOGIC_IO_UART_0_OFFSET);
  61. memset(&s, 0, sizeof(s));
  62. s.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
  63. s.iotype = UPIO_MEM32;
  64. s.regshift = 2;
  65. s.irq = PIC_UART_0_IRQ;
  66. s.uartclk = PIC_CLK_HZ;
  67. s.serial_in = nlm_xlr_uart_in;
  68. s.serial_out = nlm_xlr_uart_out;
  69. s.mapbase = uart_base;
  70. s.membase = (unsigned char __iomem *)uart_base;
  71. early_serial_setup(&s);
  72. }
  73. static void nlm_linux_exit(void)
  74. {
  75. uint64_t gpiobase;
  76. gpiobase = nlm_mmio_base(NETLOGIC_IO_GPIO_OFFSET);
  77. /* trigger a chip reset by writing 1 to GPIO_SWRESET_REG */
  78. nlm_write_reg(gpiobase, GPIO_SWRESET_REG, 1);
  79. for ( ; ; )
  80. cpu_wait();
  81. }
  82. void __init plat_mem_setup(void)
  83. {
  84. panic_timeout = 5;
  85. _machine_restart = (void (*)(char *))nlm_linux_exit;
  86. _machine_halt = nlm_linux_exit;
  87. pm_power_off = nlm_linux_exit;
  88. }
  89. const char *get_system_type(void)
  90. {
  91. return "Netlogic XLR/XLS Series";
  92. }
  93. unsigned int nlm_get_cpu_frequency(void)
  94. {
  95. return (unsigned int)nlm_prom_info.cpu_frequency;
  96. }
  97. void __init prom_free_prom_memory(void)
  98. {
  99. /* Nothing yet */
  100. }
  101. void nlm_percpu_init(int hwcpuid)
  102. {
  103. if (hwcpuid % 4 == 0)
  104. xlr_percpu_fmn_init();
  105. }
  106. static void __init build_arcs_cmdline(int *argv)
  107. {
  108. int i, remain, len;
  109. char *arg;
  110. remain = sizeof(arcs_cmdline) - 1;
  111. arcs_cmdline[0] = '\0';
  112. for (i = 0; argv[i] != 0; i++) {
  113. arg = (char *)(long)argv[i];
  114. len = strlen(arg);
  115. if (len + 1 > remain)
  116. break;
  117. strcat(arcs_cmdline, arg);
  118. strcat(arcs_cmdline, " ");
  119. remain -= len + 1;
  120. }
  121. /* Add the default options here */
  122. if ((strstr(arcs_cmdline, "console=")) == NULL) {
  123. arg = "console=ttyS0,38400 ";
  124. len = strlen(arg);
  125. if (len > remain)
  126. goto fail;
  127. strcat(arcs_cmdline, arg);
  128. remain -= len;
  129. }
  130. #ifdef CONFIG_BLK_DEV_INITRD
  131. if ((strstr(arcs_cmdline, "rdinit=")) == NULL) {
  132. arg = "rdinit=/sbin/init ";
  133. len = strlen(arg);
  134. if (len > remain)
  135. goto fail;
  136. strcat(arcs_cmdline, arg);
  137. remain -= len;
  138. }
  139. #endif
  140. return;
  141. fail:
  142. panic("Cannot add %s, command line too big!", arg);
  143. }
  144. static void prom_add_memory(void)
  145. {
  146. struct nlm_boot_mem_map *bootm;
  147. u64 start, size;
  148. u64 pref_backup = 512; /* avoid pref walking beyond end */
  149. int i;
  150. bootm = (void *)(long)nlm_prom_info.psb_mem_map;
  151. for (i = 0; i < bootm->nr_map; i++) {
  152. if (bootm->map[i].type != BOOT_MEM_RAM)
  153. continue;
  154. start = bootm->map[i].addr;
  155. size = bootm->map[i].size;
  156. /* Work around for using bootloader mem */
  157. if (i == 0 && start == 0 && size == 0x0c000000)
  158. size = 0x0ff00000;
  159. add_memory_region(start, size - pref_backup, BOOT_MEM_RAM);
  160. }
  161. }
  162. static void nlm_init_node(void)
  163. {
  164. struct nlm_soc_info *nodep;
  165. nodep = nlm_current_node();
  166. nodep->picbase = nlm_mmio_base(NETLOGIC_IO_PIC_OFFSET);
  167. nodep->ebase = read_c0_ebase() & (~((1 << 12) - 1));
  168. spin_lock_init(&nodep->piclock);
  169. }
  170. void __init prom_init(void)
  171. {
  172. int *argv, *envp; /* passed as 32 bit ptrs */
  173. struct psb_info *prom_infop;
  174. void *reset_vec;
  175. #ifdef CONFIG_SMP
  176. int i;
  177. #endif
  178. /* truncate to 32 bit and sign extend all args */
  179. argv = (int *)(long)(int)fw_arg1;
  180. envp = (int *)(long)(int)fw_arg2;
  181. prom_infop = (struct psb_info *)(long)(int)fw_arg3;
  182. nlm_prom_info = *prom_infop;
  183. nlm_init_node();
  184. /* Update reset entry point with CPU init code */
  185. reset_vec = (void *)CKSEG1ADDR(RESET_VEC_PHYS);
  186. memset(reset_vec, 0, RESET_VEC_SIZE);
  187. memcpy(reset_vec, (void *)nlm_reset_entry,
  188. (nlm_reset_entry_end - nlm_reset_entry));
  189. nlm_early_serial_setup();
  190. build_arcs_cmdline(argv);
  191. prom_add_memory();
  192. #ifdef CONFIG_SMP
  193. for (i = 0; i < 32; i++)
  194. if (nlm_prom_info.online_cpu_map & (1 << i))
  195. cpumask_set_cpu(i, &nlm_cpumask);
  196. nlm_wakeup_secondary_cpus();
  197. register_smp_ops(&nlm_smp_ops);
  198. #endif
  199. xlr_board_info_setup();
  200. xlr_percpu_fmn_init();
  201. }