setup.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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 <linux/of_platform.h>
  30. #include <linux/gfp.h>
  31. #include <asm/prom.h>
  32. #include <asm/system.h>
  33. #include <asm/iommu.h>
  34. #include <asm/machdep.h>
  35. #include <asm/mpic.h>
  36. #include <asm/smp.h>
  37. #include <asm/time.h>
  38. #include <asm/mmu.h>
  39. #include <pcmcia/ss.h>
  40. #include <pcmcia/cistpl.h>
  41. #include <pcmcia/ds.h>
  42. #include "pasemi.h"
  43. /* SDC reset register, must be pre-mapped at reset time */
  44. static void __iomem *reset_reg;
  45. /* Various error status registers, must be pre-mapped at MCE time */
  46. #define MAX_MCE_REGS 32
  47. struct mce_regs {
  48. char *name;
  49. void __iomem *addr;
  50. };
  51. static struct mce_regs mce_regs[MAX_MCE_REGS];
  52. static int num_mce_regs;
  53. static int nmi_virq = NO_IRQ;
  54. static void pas_restart(char *cmd)
  55. {
  56. /* Need to put others cpu in hold loop so they're not sleeping */
  57. smp_send_stop();
  58. udelay(10000);
  59. printk("Restarting...\n");
  60. while (1)
  61. out_le32(reset_reg, 0x6000000);
  62. }
  63. #ifdef CONFIG_SMP
  64. static arch_spinlock_t timebase_lock;
  65. static unsigned long timebase;
  66. static void __devinit pas_give_timebase(void)
  67. {
  68. unsigned long flags;
  69. local_irq_save(flags);
  70. hard_irq_disable();
  71. arch_spin_lock(&timebase_lock);
  72. mtspr(SPRN_TBCTL, TBCTL_FREEZE);
  73. isync();
  74. timebase = get_tb();
  75. arch_spin_unlock(&timebase_lock);
  76. while (timebase)
  77. barrier();
  78. mtspr(SPRN_TBCTL, TBCTL_RESTART);
  79. local_irq_restore(flags);
  80. }
  81. static void __devinit pas_take_timebase(void)
  82. {
  83. while (!timebase)
  84. smp_rmb();
  85. arch_spin_lock(&timebase_lock);
  86. set_tb(timebase >> 32, timebase & 0xffffffff);
  87. timebase = 0;
  88. arch_spin_unlock(&timebase_lock);
  89. }
  90. struct smp_ops_t pas_smp_ops = {
  91. .probe = smp_mpic_probe,
  92. .message_pass = smp_mpic_message_pass,
  93. .kick_cpu = smp_generic_kick_cpu,
  94. .setup_cpu = smp_mpic_setup_cpu,
  95. .give_timebase = pas_give_timebase,
  96. .take_timebase = pas_take_timebase,
  97. };
  98. #endif /* CONFIG_SMP */
  99. void __init pas_setup_arch(void)
  100. {
  101. #ifdef CONFIG_SMP
  102. /* Setup SMP callback */
  103. smp_ops = &pas_smp_ops;
  104. #endif
  105. /* Lookup PCI hosts */
  106. pas_pci_init();
  107. #ifdef CONFIG_DUMMY_CONSOLE
  108. conswitchp = &dummy_con;
  109. #endif
  110. /* Remap SDC register for doing reset */
  111. /* XXXOJN This should maybe come out of the device tree */
  112. reset_reg = ioremap(0xfc101100, 4);
  113. }
  114. static int __init pas_setup_mce_regs(void)
  115. {
  116. struct pci_dev *dev;
  117. int reg;
  118. /* Remap various SoC status registers for use by the MCE handler */
  119. reg = 0;
  120. dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, NULL);
  121. while (dev && reg < MAX_MCE_REGS) {
  122. mce_regs[reg].name = kasprintf(GFP_KERNEL,
  123. "mc%d_mcdebug_errsta", reg);
  124. mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x730);
  125. dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, dev);
  126. reg++;
  127. }
  128. dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
  129. if (dev && reg+4 < MAX_MCE_REGS) {
  130. mce_regs[reg].name = "iobdbg_IntStatus1";
  131. mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x438);
  132. reg++;
  133. mce_regs[reg].name = "iobdbg_IOCTbusIntDbgReg";
  134. mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x454);
  135. reg++;
  136. mce_regs[reg].name = "iobiom_IntStatus";
  137. mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0xc10);
  138. reg++;
  139. mce_regs[reg].name = "iobiom_IntDbgReg";
  140. mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0xc1c);
  141. reg++;
  142. }
  143. dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa009, NULL);
  144. if (dev && reg+2 < MAX_MCE_REGS) {
  145. mce_regs[reg].name = "l2csts_IntStatus";
  146. mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x200);
  147. reg++;
  148. mce_regs[reg].name = "l2csts_Cnt";
  149. mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x214);
  150. reg++;
  151. }
  152. num_mce_regs = reg;
  153. return 0;
  154. }
  155. machine_device_initcall(pasemi, pas_setup_mce_regs);
  156. static __init void pas_init_IRQ(void)
  157. {
  158. struct device_node *np;
  159. struct device_node *root, *mpic_node;
  160. unsigned long openpic_addr;
  161. const unsigned int *opprop;
  162. int naddr, opplen;
  163. int mpic_flags;
  164. const unsigned int *nmiprop;
  165. struct mpic *mpic;
  166. mpic_node = NULL;
  167. for_each_node_by_type(np, "interrupt-controller")
  168. if (of_device_is_compatible(np, "open-pic")) {
  169. mpic_node = np;
  170. break;
  171. }
  172. if (!mpic_node)
  173. for_each_node_by_type(np, "open-pic") {
  174. mpic_node = np;
  175. break;
  176. }
  177. if (!mpic_node) {
  178. printk(KERN_ERR
  179. "Failed to locate the MPIC interrupt controller\n");
  180. return;
  181. }
  182. /* Find address list in /platform-open-pic */
  183. root = of_find_node_by_path("/");
  184. naddr = of_n_addr_cells(root);
  185. opprop = of_get_property(root, "platform-open-pic", &opplen);
  186. if (!opprop) {
  187. printk(KERN_ERR "No platform-open-pic property.\n");
  188. of_node_put(root);
  189. return;
  190. }
  191. openpic_addr = of_read_number(opprop, naddr);
  192. printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);
  193. mpic_flags = MPIC_PRIMARY | MPIC_LARGE_VECTORS | MPIC_NO_BIAS;
  194. nmiprop = of_get_property(mpic_node, "nmi-source", NULL);
  195. if (nmiprop)
  196. mpic_flags |= MPIC_ENABLE_MCK;
  197. mpic = mpic_alloc(mpic_node, openpic_addr,
  198. mpic_flags, 0, 0, "PASEMI-OPIC");
  199. BUG_ON(!mpic);
  200. mpic_assign_isu(mpic, 0, openpic_addr + 0x10000);
  201. mpic_init(mpic);
  202. /* The NMI/MCK source needs to be prio 15 */
  203. if (nmiprop) {
  204. nmi_virq = irq_create_mapping(NULL, *nmiprop);
  205. mpic_irq_set_priority(nmi_virq, 15);
  206. irq_set_irq_type(nmi_virq, IRQ_TYPE_EDGE_RISING);
  207. mpic_unmask_irq(irq_get_irq_data(nmi_virq));
  208. }
  209. of_node_put(mpic_node);
  210. of_node_put(root);
  211. }
  212. static void __init pas_progress(char *s, unsigned short hex)
  213. {
  214. printk("[%04x] : %s\n", hex, s ? s : "");
  215. }
  216. static int pas_machine_check_handler(struct pt_regs *regs)
  217. {
  218. int cpu = smp_processor_id();
  219. unsigned long srr0, srr1, dsisr;
  220. int dump_slb = 0;
  221. int i;
  222. srr0 = regs->nip;
  223. srr1 = regs->msr;
  224. if (nmi_virq != NO_IRQ && mpic_get_mcirq() == nmi_virq) {
  225. printk(KERN_ERR "NMI delivered\n");
  226. debugger(regs);
  227. mpic_end_irq(irq_get_irq_data(nmi_virq));
  228. goto out;
  229. }
  230. dsisr = mfspr(SPRN_DSISR);
  231. printk(KERN_ERR "Machine Check on CPU %d\n", cpu);
  232. printk(KERN_ERR "SRR0 0x%016lx SRR1 0x%016lx\n", srr0, srr1);
  233. printk(KERN_ERR "DSISR 0x%016lx DAR 0x%016lx\n", dsisr, regs->dar);
  234. printk(KERN_ERR "BER 0x%016lx MER 0x%016lx\n", mfspr(SPRN_PA6T_BER),
  235. mfspr(SPRN_PA6T_MER));
  236. printk(KERN_ERR "IER 0x%016lx DER 0x%016lx\n", mfspr(SPRN_PA6T_IER),
  237. mfspr(SPRN_PA6T_DER));
  238. printk(KERN_ERR "Cause:\n");
  239. if (srr1 & 0x200000)
  240. printk(KERN_ERR "Signalled by SDC\n");
  241. if (srr1 & 0x100000) {
  242. printk(KERN_ERR "Load/Store detected error:\n");
  243. if (dsisr & 0x8000)
  244. printk(KERN_ERR "D-cache ECC double-bit error or bus error\n");
  245. if (dsisr & 0x4000)
  246. printk(KERN_ERR "LSU snoop response error\n");
  247. if (dsisr & 0x2000) {
  248. printk(KERN_ERR "MMU SLB multi-hit or invalid B field\n");
  249. dump_slb = 1;
  250. }
  251. if (dsisr & 0x1000)
  252. printk(KERN_ERR "Recoverable Duptags\n");
  253. if (dsisr & 0x800)
  254. printk(KERN_ERR "Recoverable D-cache parity error count overflow\n");
  255. if (dsisr & 0x400)
  256. printk(KERN_ERR "TLB parity error count overflow\n");
  257. }
  258. if (srr1 & 0x80000)
  259. printk(KERN_ERR "Bus Error\n");
  260. if (srr1 & 0x40000) {
  261. printk(KERN_ERR "I-side SLB multiple hit\n");
  262. dump_slb = 1;
  263. }
  264. if (srr1 & 0x20000)
  265. printk(KERN_ERR "I-cache parity error hit\n");
  266. if (num_mce_regs == 0)
  267. printk(KERN_ERR "No MCE registers mapped yet, can't dump\n");
  268. else
  269. printk(KERN_ERR "SoC debug registers:\n");
  270. for (i = 0; i < num_mce_regs; i++)
  271. printk(KERN_ERR "%s: 0x%08x\n", mce_regs[i].name,
  272. in_le32(mce_regs[i].addr));
  273. if (dump_slb) {
  274. unsigned long e, v;
  275. int i;
  276. printk(KERN_ERR "slb contents:\n");
  277. for (i = 0; i < mmu_slb_size; i++) {
  278. asm volatile("slbmfee %0,%1" : "=r" (e) : "r" (i));
  279. asm volatile("slbmfev %0,%1" : "=r" (v) : "r" (i));
  280. printk(KERN_ERR "%02d %016lx %016lx\n", i, e, v);
  281. }
  282. }
  283. out:
  284. /* SRR1[62] is from MSR[62] if recoverable, so pass that back */
  285. return !!(srr1 & 0x2);
  286. }
  287. static void __init pas_init_early(void)
  288. {
  289. iommu_init_early_pasemi();
  290. }
  291. #ifdef CONFIG_PCMCIA
  292. static int pcmcia_notify(struct notifier_block *nb, unsigned long action,
  293. void *data)
  294. {
  295. struct device *dev = data;
  296. struct device *parent;
  297. struct pcmcia_device *pdev = to_pcmcia_dev(dev);
  298. /* We are only intereted in device addition */
  299. if (action != BUS_NOTIFY_ADD_DEVICE)
  300. return 0;
  301. parent = pdev->socket->dev.parent;
  302. /* We know electra_cf devices will always have of_node set, since
  303. * electra_cf is an of_platform driver.
  304. */
  305. if (!parent->of_node)
  306. return 0;
  307. if (!of_device_is_compatible(parent->of_node, "electra-cf"))
  308. return 0;
  309. /* We use the direct ops for localbus */
  310. dev->archdata.dma_ops = &dma_direct_ops;
  311. return 0;
  312. }
  313. static struct notifier_block pcmcia_notifier = {
  314. .notifier_call = pcmcia_notify,
  315. };
  316. static inline void pasemi_pcmcia_init(void)
  317. {
  318. extern struct bus_type pcmcia_bus_type;
  319. bus_register_notifier(&pcmcia_bus_type, &pcmcia_notifier);
  320. }
  321. #else
  322. static inline void pasemi_pcmcia_init(void)
  323. {
  324. }
  325. #endif
  326. static struct of_device_id pasemi_bus_ids[] = {
  327. /* Unfortunately needed for legacy firmwares */
  328. { .type = "localbus", },
  329. { .type = "sdc", },
  330. /* These are the proper entries, which newer firmware uses */
  331. { .compatible = "pasemi,localbus", },
  332. { .compatible = "pasemi,sdc", },
  333. {},
  334. };
  335. static int __init pasemi_publish_devices(void)
  336. {
  337. pasemi_pcmcia_init();
  338. /* Publish OF platform devices for SDC and other non-PCI devices */
  339. of_platform_bus_probe(NULL, pasemi_bus_ids, NULL);
  340. return 0;
  341. }
  342. machine_device_initcall(pasemi, pasemi_publish_devices);
  343. /*
  344. * Called very early, MMU is off, device-tree isn't unflattened
  345. */
  346. static int __init pas_probe(void)
  347. {
  348. unsigned long root = of_get_flat_dt_root();
  349. if (!of_flat_dt_is_compatible(root, "PA6T-1682M") &&
  350. !of_flat_dt_is_compatible(root, "pasemi,pwrficient"))
  351. return 0;
  352. hpte_init_native();
  353. alloc_iobmap_l2();
  354. return 1;
  355. }
  356. define_machine(pasemi) {
  357. .name = "PA Semi PWRficient",
  358. .probe = pas_probe,
  359. .setup_arch = pas_setup_arch,
  360. .init_early = pas_init_early,
  361. .init_IRQ = pas_init_IRQ,
  362. .get_irq = mpic_get_irq,
  363. .restart = pas_restart,
  364. .get_boot_time = pas_get_boot_time,
  365. .calibrate_decr = generic_calibrate_decr,
  366. .progress = pas_progress,
  367. .machine_check_exception = pas_machine_check_handler,
  368. };