setup.c 5.8 KB

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