holly.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Board setup routines for the IBM 750GX/CL platform w/ TSI10x bridge
  4. *
  5. * Copyright 2007 IBM Corporation
  6. *
  7. * Stephen Winiecki <[email protected]>
  8. * Josh Boyer <[email protected]>
  9. *
  10. * Based on code from mpc7448_hpc2.c
  11. */
  12. #include <linux/stddef.h>
  13. #include <linux/kernel.h>
  14. #include <linux/pci.h>
  15. #include <linux/kdev_t.h>
  16. #include <linux/console.h>
  17. #include <linux/delay.h>
  18. #include <linux/irq.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/root_dev.h>
  21. #include <linux/serial.h>
  22. #include <linux/tty.h>
  23. #include <linux/serial_core.h>
  24. #include <linux/of_address.h>
  25. #include <linux/of_irq.h>
  26. #include <linux/of_platform.h>
  27. #include <linux/extable.h>
  28. #include <asm/time.h>
  29. #include <asm/machdep.h>
  30. #include <asm/udbg.h>
  31. #include <asm/tsi108.h>
  32. #include <asm/pci-bridge.h>
  33. #include <asm/reg.h>
  34. #include <mm/mmu_decl.h>
  35. #include <asm/tsi108_irq.h>
  36. #include <asm/tsi108_pci.h>
  37. #include <asm/mpic.h>
  38. #undef DEBUG
  39. #define HOLLY_PCI_CFG_PHYS 0x7c000000
  40. static int holly_exclude_device(struct pci_controller *hose, u_char bus,
  41. u_char devfn)
  42. {
  43. if (bus == 0 && PCI_SLOT(devfn) == 0)
  44. return PCIBIOS_DEVICE_NOT_FOUND;
  45. else
  46. return PCIBIOS_SUCCESSFUL;
  47. }
  48. static void __init holly_remap_bridge(void)
  49. {
  50. u32 lut_val, lut_addr;
  51. int i;
  52. printk(KERN_INFO "Remapping PCI bridge\n");
  53. /* Re-init the PCI bridge and LUT registers to have mappings that don't
  54. * rely on PIBS
  55. */
  56. lut_addr = 0x900;
  57. for (i = 0; i < 31; i++) {
  58. tsi108_write_reg(TSI108_PB_OFFSET + lut_addr, 0x00000201);
  59. lut_addr += 4;
  60. tsi108_write_reg(TSI108_PB_OFFSET + lut_addr, 0x0);
  61. lut_addr += 4;
  62. }
  63. /* Reserve the last LUT entry for PCI I/O space */
  64. tsi108_write_reg(TSI108_PB_OFFSET + lut_addr, 0x00000241);
  65. lut_addr += 4;
  66. tsi108_write_reg(TSI108_PB_OFFSET + lut_addr, 0x0);
  67. /* Map PCI I/O space */
  68. tsi108_write_reg(TSI108_PCI_PFAB_IO_UPPER, 0x0);
  69. tsi108_write_reg(TSI108_PCI_PFAB_IO, 0x1);
  70. /* Map PCI CFG space */
  71. tsi108_write_reg(TSI108_PCI_PFAB_BAR0_UPPER, 0x0);
  72. tsi108_write_reg(TSI108_PCI_PFAB_BAR0, 0x7c000000 | 0x01);
  73. /* We don't need MEM32 and PRM remapping so disable them */
  74. tsi108_write_reg(TSI108_PCI_PFAB_MEM32, 0x0);
  75. tsi108_write_reg(TSI108_PCI_PFAB_PFM3, 0x0);
  76. tsi108_write_reg(TSI108_PCI_PFAB_PFM4, 0x0);
  77. /* Set P2O_BAR0 */
  78. tsi108_write_reg(TSI108_PCI_P2O_BAR0_UPPER, 0x0);
  79. tsi108_write_reg(TSI108_PCI_P2O_BAR0, 0xc0000000);
  80. /* Init the PCI LUTs to do no remapping */
  81. lut_addr = 0x500;
  82. lut_val = 0x00000002;
  83. for (i = 0; i < 32; i++) {
  84. tsi108_write_reg(TSI108_PCI_OFFSET + lut_addr, lut_val);
  85. lut_addr += 4;
  86. tsi108_write_reg(TSI108_PCI_OFFSET + lut_addr, 0x40000000);
  87. lut_addr += 4;
  88. lut_val += 0x02000000;
  89. }
  90. tsi108_write_reg(TSI108_PCI_P2O_PAGE_SIZES, 0x00007900);
  91. /* Set 64-bit PCI bus address for system memory */
  92. tsi108_write_reg(TSI108_PCI_P2O_BAR2_UPPER, 0x0);
  93. tsi108_write_reg(TSI108_PCI_P2O_BAR2, 0x0);
  94. }
  95. static void __init holly_init_pci(void)
  96. {
  97. struct device_node *np;
  98. if (ppc_md.progress)
  99. ppc_md.progress("holly_setup_arch():set_bridge", 0);
  100. /* setup PCI host bridge */
  101. holly_remap_bridge();
  102. np = of_find_node_by_type(NULL, "pci");
  103. if (np)
  104. tsi108_setup_pci(np, HOLLY_PCI_CFG_PHYS, 1);
  105. of_node_put(np);
  106. ppc_md.pci_exclude_device = holly_exclude_device;
  107. if (ppc_md.progress)
  108. ppc_md.progress("tsi108: resources set", 0x100);
  109. }
  110. static void __init holly_setup_arch(void)
  111. {
  112. tsi108_csr_vir_base = get_vir_csrbase();
  113. printk(KERN_INFO "PPC750GX/CL Platform\n");
  114. }
  115. /*
  116. * Interrupt setup and service. Interrupts on the holly come
  117. * from the four external INT pins, PCI interrupts are routed via
  118. * PCI interrupt control registers, it generates internal IRQ23
  119. *
  120. * Interrupt routing on the Holly Board:
  121. * TSI108:PB_INT[0] -> CPU0:INT#
  122. * TSI108:PB_INT[1] -> CPU0:MCP#
  123. * TSI108:PB_INT[2] -> N/C
  124. * TSI108:PB_INT[3] -> N/C
  125. */
  126. static void __init holly_init_IRQ(void)
  127. {
  128. struct mpic *mpic;
  129. #ifdef CONFIG_PCI
  130. unsigned int cascade_pci_irq;
  131. struct device_node *tsi_pci;
  132. struct device_node *cascade_node = NULL;
  133. #endif
  134. mpic = mpic_alloc(NULL, 0, MPIC_BIG_ENDIAN |
  135. MPIC_SPV_EOI | MPIC_NO_PTHROU_DIS | MPIC_REGSET_TSI108,
  136. 24, 0,
  137. "Tsi108_PIC");
  138. BUG_ON(mpic == NULL);
  139. mpic_assign_isu(mpic, 0, mpic->paddr + 0x100);
  140. mpic_init(mpic);
  141. #ifdef CONFIG_PCI
  142. tsi_pci = of_find_node_by_type(NULL, "pci");
  143. if (tsi_pci == NULL) {
  144. printk(KERN_ERR "%s: No tsi108 pci node found !\n", __func__);
  145. return;
  146. }
  147. cascade_node = of_find_node_by_type(NULL, "pic-router");
  148. if (cascade_node == NULL) {
  149. printk(KERN_ERR "%s: No tsi108 pci cascade node found !\n", __func__);
  150. return;
  151. }
  152. cascade_pci_irq = irq_of_parse_and_map(tsi_pci, 0);
  153. pr_debug("%s: tsi108 cascade_pci_irq = 0x%x\n", __func__, (u32) cascade_pci_irq);
  154. tsi108_pci_int_init(cascade_node);
  155. irq_set_handler_data(cascade_pci_irq, mpic);
  156. irq_set_chained_handler(cascade_pci_irq, tsi108_irq_cascade);
  157. of_node_put(tsi_pci);
  158. of_node_put(cascade_node);
  159. #endif
  160. /* Configure MPIC outputs to CPU0 */
  161. tsi108_write_reg(TSI108_MPIC_OFFSET + 0x30c, 0);
  162. }
  163. static void holly_show_cpuinfo(struct seq_file *m)
  164. {
  165. seq_printf(m, "vendor\t\t: IBM\n");
  166. seq_printf(m, "machine\t\t: PPC750 GX/CL\n");
  167. }
  168. static void __noreturn holly_restart(char *cmd)
  169. {
  170. __be32 __iomem *ocn_bar1 = NULL;
  171. unsigned long bar;
  172. struct device_node *bridge = NULL;
  173. const void *prop;
  174. int size;
  175. phys_addr_t addr = 0xc0000000;
  176. local_irq_disable();
  177. bridge = of_find_node_by_type(NULL, "tsi-bridge");
  178. if (bridge) {
  179. prop = of_get_property(bridge, "reg", &size);
  180. addr = of_translate_address(bridge, prop);
  181. of_node_put(bridge);
  182. }
  183. addr += (TSI108_PB_OFFSET + 0x414);
  184. ocn_bar1 = ioremap(addr, 0x4);
  185. /* Turn on the BOOT bit so the addresses are correctly
  186. * routed to the HLP interface */
  187. bar = ioread32be(ocn_bar1);
  188. bar |= 2;
  189. iowrite32be(bar, ocn_bar1);
  190. iosync();
  191. /* Set SRR0 to the reset vector and turn on MSR_IP */
  192. mtspr(SPRN_SRR0, 0xfff00100);
  193. mtspr(SPRN_SRR1, MSR_IP);
  194. /* Do an rfi to jump back to firmware. Somewhat evil,
  195. * but it works
  196. */
  197. __asm__ __volatile__("rfi" : : : "memory");
  198. /* Spin until reset happens. Shouldn't really get here */
  199. for (;;) ;
  200. }
  201. /*
  202. * Called very early, device-tree isn't unflattened
  203. */
  204. static int __init holly_probe(void)
  205. {
  206. if (!of_machine_is_compatible("ibm,holly"))
  207. return 0;
  208. return 1;
  209. }
  210. static int ppc750_machine_check_exception(struct pt_regs *regs)
  211. {
  212. const struct exception_table_entry *entry;
  213. /* Are we prepared to handle this fault */
  214. if ((entry = search_exception_tables(regs->nip)) != NULL) {
  215. tsi108_clear_pci_cfg_error();
  216. regs_set_recoverable(regs);
  217. regs_set_return_ip(regs, extable_fixup(entry));
  218. return 1;
  219. }
  220. return 0;
  221. }
  222. define_machine(holly){
  223. .name = "PPC750 GX/CL TSI",
  224. .probe = holly_probe,
  225. .setup_arch = holly_setup_arch,
  226. .discover_phbs = holly_init_pci,
  227. .init_IRQ = holly_init_IRQ,
  228. .show_cpuinfo = holly_show_cpuinfo,
  229. .get_irq = mpic_get_irq,
  230. .restart = holly_restart,
  231. .calibrate_decr = generic_calibrate_decr,
  232. .machine_check_exception = ppc750_machine_check_exception,
  233. .progress = udbg_progress,
  234. };