setup.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /*
  2. * Copyright (C) 2006-2007 PA Semi, Inc
  3. *
  4. * Authors: Kip Walker, PA Semi
  5. * Olof Johansson, PA Semi
  6. *
  7. * Maintained by: Olof Johansson <olof@lixom.net>
  8. *
  9. * Based on arch/powerpc/platforms/maple/setup.c
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. #include <linux/errno.h>
  25. #include <linux/kernel.h>
  26. #include <linux/delay.h>
  27. #include <linux/console.h>
  28. #include <linux/pci.h>
  29. #include <asm/prom.h>
  30. #include <asm/system.h>
  31. #include <asm/iommu.h>
  32. #include <asm/machdep.h>
  33. #include <asm/mpic.h>
  34. #include <asm/smp.h>
  35. #include <asm/time.h>
  36. #include <asm/of_platform.h>
  37. #include "pasemi.h"
  38. /* SDC reset register, must be pre-mapped at reset time */
  39. static void __iomem *reset_reg;
  40. /* Various error status registers, must be pre-mapped at MCE time */
  41. #define MAX_MCE_REGS 32
  42. struct mce_regs {
  43. char *name;
  44. void __iomem *addr;
  45. };
  46. static struct mce_regs mce_regs[MAX_MCE_REGS];
  47. static int num_mce_regs;
  48. static void pas_restart(char *cmd)
  49. {
  50. printk("Restarting...\n");
  51. while (1)
  52. out_le32(reset_reg, 0x6000000);
  53. }
  54. #ifdef CONFIG_SMP
  55. static DEFINE_SPINLOCK(timebase_lock);
  56. static unsigned long timebase;
  57. static void __devinit pas_give_timebase(void)
  58. {
  59. spin_lock(&timebase_lock);
  60. mtspr(SPRN_TBCTL, TBCTL_FREEZE);
  61. isync();
  62. timebase = get_tb();
  63. spin_unlock(&timebase_lock);
  64. while (timebase)
  65. barrier();
  66. mtspr(SPRN_TBCTL, TBCTL_RESTART);
  67. }
  68. static void __devinit pas_take_timebase(void)
  69. {
  70. while (!timebase)
  71. smp_rmb();
  72. spin_lock(&timebase_lock);
  73. set_tb(timebase >> 32, timebase & 0xffffffff);
  74. timebase = 0;
  75. spin_unlock(&timebase_lock);
  76. }
  77. struct smp_ops_t pas_smp_ops = {
  78. .probe = smp_mpic_probe,
  79. .message_pass = smp_mpic_message_pass,
  80. .kick_cpu = smp_generic_kick_cpu,
  81. .setup_cpu = smp_mpic_setup_cpu,
  82. .give_timebase = pas_give_timebase,
  83. .take_timebase = pas_take_timebase,
  84. };
  85. #endif /* CONFIG_SMP */
  86. void __init pas_setup_arch(void)
  87. {
  88. #ifdef CONFIG_SMP
  89. /* Setup SMP callback */
  90. smp_ops = &pas_smp_ops;
  91. #endif
  92. /* Lookup PCI hosts */
  93. pas_pci_init();
  94. #ifdef CONFIG_DUMMY_CONSOLE
  95. conswitchp = &dummy_con;
  96. #endif
  97. /* Remap SDC register for doing reset */
  98. /* XXXOJN This should maybe come out of the device tree */
  99. reset_reg = ioremap(0xfc101100, 4);
  100. }
  101. static int __init pas_setup_mce_regs(void)
  102. {
  103. struct pci_dev *dev;
  104. int reg;
  105. if (!machine_is(pasemi))
  106. return -ENODEV;
  107. /* Remap various SoC status registers for use by the MCE handler */
  108. reg = 0;
  109. dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, NULL);
  110. while (dev && reg < MAX_MCE_REGS) {
  111. mce_regs[reg].name = kasprintf(GFP_KERNEL,
  112. "mc%d_mcdebug_errsta", reg);
  113. mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x730);
  114. dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, dev);
  115. reg++;
  116. }
  117. dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
  118. if (dev && reg+4 < MAX_MCE_REGS) {
  119. mce_regs[reg].name = "iobdbg_IntStatus1";
  120. mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x438);
  121. reg++;
  122. mce_regs[reg].name = "iobdbg_IOCTbusIntDbgReg";
  123. mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x454);
  124. reg++;
  125. mce_regs[reg].name = "iobiom_IntStatus";
  126. mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0xc10);
  127. reg++;
  128. mce_regs[reg].name = "iobiom_IntDbgReg";
  129. mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0xc1c);
  130. reg++;
  131. }
  132. dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa009, NULL);
  133. if (dev && reg+2 < MAX_MCE_REGS) {
  134. mce_regs[reg].name = "l2csts_IntStatus";
  135. mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x200);
  136. reg++;
  137. mce_regs[reg].name = "l2csts_Cnt";
  138. mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x214);
  139. reg++;
  140. }
  141. num_mce_regs = reg;
  142. return 0;
  143. }
  144. device_initcall(pas_setup_mce_regs);
  145. static __init void pas_init_IRQ(void)
  146. {
  147. struct device_node *np;
  148. struct device_node *root, *mpic_node;
  149. unsigned long openpic_addr;
  150. const unsigned int *opprop;
  151. int naddr, opplen;
  152. struct mpic *mpic;
  153. mpic_node = NULL;
  154. for_each_node_by_type(np, "interrupt-controller")
  155. if (of_device_is_compatible(np, "open-pic")) {
  156. mpic_node = np;
  157. break;
  158. }
  159. if (!mpic_node)
  160. for_each_node_by_type(np, "open-pic") {
  161. mpic_node = np;
  162. break;
  163. }
  164. if (!mpic_node) {
  165. printk(KERN_ERR
  166. "Failed to locate the MPIC interrupt controller\n");
  167. return;
  168. }
  169. /* Find address list in /platform-open-pic */
  170. root = of_find_node_by_path("/");
  171. naddr = of_n_addr_cells(root);
  172. opprop = of_get_property(root, "platform-open-pic", &opplen);
  173. if (!opprop) {
  174. printk(KERN_ERR "No platform-open-pic property.\n");
  175. of_node_put(root);
  176. return;
  177. }
  178. openpic_addr = of_read_number(opprop, naddr);
  179. printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);
  180. mpic = mpic_alloc(mpic_node, openpic_addr,
  181. MPIC_PRIMARY|MPIC_LARGE_VECTORS|MPIC_WANTS_RESET,
  182. 0, 0, " PAS-OPIC ");
  183. BUG_ON(!mpic);
  184. mpic_assign_isu(mpic, 0, openpic_addr + 0x10000);
  185. mpic_init(mpic);
  186. of_node_put(mpic_node);
  187. of_node_put(root);
  188. }
  189. static void __init pas_progress(char *s, unsigned short hex)
  190. {
  191. printk("[%04x] : %s\n", hex, s ? s : "");
  192. }
  193. static int pas_machine_check_handler(struct pt_regs *regs)
  194. {
  195. int cpu = smp_processor_id();
  196. unsigned long srr0, srr1, dsisr;
  197. int dump_slb = 0;
  198. int i;
  199. srr0 = regs->nip;
  200. srr1 = regs->msr;
  201. dsisr = mfspr(SPRN_DSISR);
  202. printk(KERN_ERR "Machine Check on CPU %d\n", cpu);
  203. printk(KERN_ERR "SRR0 0x%016lx SRR1 0x%016lx\n", srr0, srr1);
  204. printk(KERN_ERR "DSISR 0x%016lx DAR 0x%016lx\n", dsisr, regs->dar);
  205. printk(KERN_ERR "BER 0x%016lx MER 0x%016lx\n", mfspr(SPRN_PA6T_BER),
  206. mfspr(SPRN_PA6T_MER));
  207. printk(KERN_ERR "IER 0x%016lx DER 0x%016lx\n", mfspr(SPRN_PA6T_IER),
  208. mfspr(SPRN_PA6T_DER));
  209. printk(KERN_ERR "Cause:\n");
  210. if (srr1 & 0x200000)
  211. printk(KERN_ERR "Signalled by SDC\n");
  212. if (srr1 & 0x100000) {
  213. printk(KERN_ERR "Load/Store detected error:\n");
  214. if (dsisr & 0x8000)
  215. printk(KERN_ERR "D-cache ECC double-bit error or bus error\n");
  216. if (dsisr & 0x4000)
  217. printk(KERN_ERR "LSU snoop response error\n");
  218. if (dsisr & 0x2000) {
  219. printk(KERN_ERR "MMU SLB multi-hit or invalid B field\n");
  220. dump_slb = 1;
  221. }
  222. if (dsisr & 0x1000)
  223. printk(KERN_ERR "Recoverable Duptags\n");
  224. if (dsisr & 0x800)
  225. printk(KERN_ERR "Recoverable D-cache parity error count overflow\n");
  226. if (dsisr & 0x400)
  227. printk(KERN_ERR "TLB parity error count overflow\n");
  228. }
  229. if (srr1 & 0x80000)
  230. printk(KERN_ERR "Bus Error\n");
  231. if (srr1 & 0x40000) {
  232. printk(KERN_ERR "I-side SLB multiple hit\n");
  233. dump_slb = 1;
  234. }
  235. if (srr1 & 0x20000)
  236. printk(KERN_ERR "I-cache parity error hit\n");
  237. if (num_mce_regs == 0)
  238. printk(KERN_ERR "No MCE registers mapped yet, can't dump\n");
  239. else
  240. printk(KERN_ERR "SoC debug registers:\n");
  241. for (i = 0; i < num_mce_regs; i++)
  242. printk(KERN_ERR "%s: 0x%08x\n", mce_regs[i].name,
  243. in_le32(mce_regs[i].addr));
  244. if (dump_slb) {
  245. unsigned long e, v;
  246. int i;
  247. printk(KERN_ERR "slb contents:\n");
  248. for (i = 0; i < SLB_NUM_ENTRIES; i++) {
  249. asm volatile("slbmfee %0,%1" : "=r" (e) : "r" (i));
  250. asm volatile("slbmfev %0,%1" : "=r" (v) : "r" (i));
  251. printk(KERN_ERR "%02d %016lx %016lx\n", i, e, v);
  252. }
  253. }
  254. /* SRR1[62] is from MSR[62] if recoverable, so pass that back */
  255. return !!(srr1 & 0x2);
  256. }
  257. static void __init pas_init_early(void)
  258. {
  259. iommu_init_early_pasemi();
  260. }
  261. static struct of_device_id pasemi_bus_ids[] = {
  262. { .type = "sdc", },
  263. {},
  264. };
  265. static int __init pasemi_publish_devices(void)
  266. {
  267. if (!machine_is(pasemi))
  268. return 0;
  269. /* Publish OF platform devices for SDC and other non-PCI devices */
  270. of_platform_bus_probe(NULL, pasemi_bus_ids, NULL);
  271. return 0;
  272. }
  273. device_initcall(pasemi_publish_devices);
  274. /*
  275. * Called very early, MMU is off, device-tree isn't unflattened
  276. */
  277. static int __init pas_probe(void)
  278. {
  279. unsigned long root = of_get_flat_dt_root();
  280. if (!of_flat_dt_is_compatible(root, "PA6T-1682M"))
  281. return 0;
  282. hpte_init_native();
  283. alloc_iobmap_l2();
  284. return 1;
  285. }
  286. define_machine(pasemi) {
  287. .name = "PA Semi PA6T-1682M",
  288. .probe = pas_probe,
  289. .setup_arch = pas_setup_arch,
  290. .init_early = pas_init_early,
  291. .init_IRQ = pas_init_IRQ,
  292. .get_irq = mpic_get_irq,
  293. .restart = pas_restart,
  294. .get_boot_time = pas_get_boot_time,
  295. .calibrate_decr = generic_calibrate_decr,
  296. .progress = pas_progress,
  297. .machine_check_exception = pas_machine_check_handler,
  298. };