setup.c 10 KB

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