setup.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 nlm_linux_exit(void)
  57. {
  58. uint64_t gpiobase;
  59. gpiobase = nlm_mmio_base(NETLOGIC_IO_GPIO_OFFSET);
  60. /* trigger a chip reset by writing 1 to GPIO_SWRESET_REG */
  61. nlm_write_reg(gpiobase, GPIO_SWRESET_REG, 1);
  62. for ( ; ; )
  63. cpu_wait();
  64. }
  65. void __init plat_mem_setup(void)
  66. {
  67. _machine_restart = (void (*)(char *))nlm_linux_exit;
  68. _machine_halt = nlm_linux_exit;
  69. pm_power_off = nlm_linux_exit;
  70. }
  71. const char *get_system_type(void)
  72. {
  73. return "Netlogic XLR/XLS Series";
  74. }
  75. unsigned int nlm_get_cpu_frequency(void)
  76. {
  77. return (unsigned int)nlm_prom_info.cpu_frequency;
  78. }
  79. void __init prom_free_prom_memory(void)
  80. {
  81. /* Nothing yet */
  82. }
  83. void nlm_percpu_init(int hwcpuid)
  84. {
  85. if (hwcpuid % 4 == 0)
  86. xlr_percpu_fmn_init();
  87. }
  88. static void __init build_arcs_cmdline(int *argv)
  89. {
  90. int i, remain, len;
  91. char *arg;
  92. remain = sizeof(arcs_cmdline) - 1;
  93. arcs_cmdline[0] = '\0';
  94. for (i = 0; argv[i] != 0; i++) {
  95. arg = (char *)(long)argv[i];
  96. len = strlen(arg);
  97. if (len + 1 > remain)
  98. break;
  99. strcat(arcs_cmdline, arg);
  100. strcat(arcs_cmdline, " ");
  101. remain -= len + 1;
  102. }
  103. /* Add the default options here */
  104. if ((strstr(arcs_cmdline, "console=")) == NULL) {
  105. arg = "console=ttyS0,38400 ";
  106. len = strlen(arg);
  107. if (len > remain)
  108. goto fail;
  109. strcat(arcs_cmdline, arg);
  110. remain -= len;
  111. }
  112. #ifdef CONFIG_BLK_DEV_INITRD
  113. if ((strstr(arcs_cmdline, "rdinit=")) == NULL) {
  114. arg = "rdinit=/sbin/init ";
  115. len = strlen(arg);
  116. if (len > remain)
  117. goto fail;
  118. strcat(arcs_cmdline, arg);
  119. remain -= len;
  120. }
  121. #endif
  122. return;
  123. fail:
  124. panic("Cannot add %s, command line too big!", arg);
  125. }
  126. static void prom_add_memory(void)
  127. {
  128. struct nlm_boot_mem_map *bootm;
  129. u64 start, size;
  130. u64 pref_backup = 512; /* avoid pref walking beyond end */
  131. int i;
  132. bootm = (void *)(long)nlm_prom_info.psb_mem_map;
  133. for (i = 0; i < bootm->nr_map; i++) {
  134. if (bootm->map[i].type != BOOT_MEM_RAM)
  135. continue;
  136. start = bootm->map[i].addr;
  137. size = bootm->map[i].size;
  138. /* Work around for using bootloader mem */
  139. if (i == 0 && start == 0 && size == 0x0c000000)
  140. size = 0x0ff00000;
  141. add_memory_region(start, size - pref_backup, BOOT_MEM_RAM);
  142. }
  143. }
  144. static void nlm_init_node(void)
  145. {
  146. struct nlm_soc_info *nodep;
  147. nodep = nlm_current_node();
  148. nodep->picbase = nlm_mmio_base(NETLOGIC_IO_PIC_OFFSET);
  149. nodep->ebase = read_c0_ebase() & (~((1 << 12) - 1));
  150. spin_lock_init(&nodep->piclock);
  151. }
  152. void __init prom_init(void)
  153. {
  154. int *argv, *envp; /* passed as 32 bit ptrs */
  155. struct psb_info *prom_infop;
  156. void *reset_vec;
  157. #ifdef CONFIG_SMP
  158. int i;
  159. #endif
  160. /* truncate to 32 bit and sign extend all args */
  161. argv = (int *)(long)(int)fw_arg1;
  162. envp = (int *)(long)(int)fw_arg2;
  163. prom_infop = (struct psb_info *)(long)(int)fw_arg3;
  164. nlm_prom_info = *prom_infop;
  165. nlm_init_node();
  166. /* Update reset entry point with CPU init code */
  167. reset_vec = (void *)CKSEG1ADDR(RESET_VEC_PHYS);
  168. memset(reset_vec, 0, RESET_VEC_SIZE);
  169. memcpy(reset_vec, (void *)nlm_reset_entry,
  170. (nlm_reset_entry_end - nlm_reset_entry));
  171. build_arcs_cmdline(argv);
  172. prom_add_memory();
  173. #ifdef CONFIG_SMP
  174. for (i = 0; i < 32; i++)
  175. if (nlm_prom_info.online_cpu_map & (1 << i))
  176. cpumask_set_cpu(i, &nlm_cpumask);
  177. nlm_wakeup_secondary_cpus();
  178. register_smp_ops(&nlm_smp_ops);
  179. #endif
  180. xlr_board_info_setup();
  181. xlr_percpu_fmn_init();
  182. }