pcimt.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /*
  2. * PCIMT specific code
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 1996, 97, 98, 2000, 03, 04, 06 Ralf Baechle (ralf@linux-mips.org)
  9. * Copyright (C) 2006,2007 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
  10. */
  11. #include <linux/init.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/pci.h>
  14. #include <linux/serial_8250.h>
  15. #include <asm/sni.h>
  16. #include <asm/time.h>
  17. #include <asm/i8259.h>
  18. #include <asm/irq_cpu.h>
  19. #define cacheconf (*(volatile unsigned int *)PCIMT_CACHECONF)
  20. #define invspace (*(volatile unsigned int *)PCIMT_INVSPACE)
  21. static void __init sni_pcimt_sc_init(void)
  22. {
  23. unsigned int scsiz, sc_size;
  24. scsiz = cacheconf & 7;
  25. if (scsiz == 0) {
  26. printk("Second level cache is deactived.\n");
  27. return;
  28. }
  29. if (scsiz >= 6) {
  30. printk("Invalid second level cache size configured, "
  31. "deactivating second level cache.\n");
  32. cacheconf = 0;
  33. return;
  34. }
  35. sc_size = 128 << scsiz;
  36. printk("%dkb second level cache detected, deactivating.\n", sc_size);
  37. cacheconf = 0;
  38. }
  39. /*
  40. * A bit more gossip about the iron we're running on ...
  41. */
  42. static inline void sni_pcimt_detect(void)
  43. {
  44. char boardtype[80];
  45. unsigned char csmsr;
  46. char *p = boardtype;
  47. unsigned int asic;
  48. csmsr = *(volatile unsigned char *)PCIMT_CSMSR;
  49. p += sprintf(p, "%s PCI", (csmsr & 0x80) ? "RM200" : "RM300");
  50. if ((csmsr & 0x80) == 0)
  51. p += sprintf(p, ", board revision %s",
  52. (csmsr & 0x20) ? "D" : "C");
  53. asic = csmsr & 0x80;
  54. asic = (csmsr & 0x08) ? asic : !asic;
  55. p += sprintf(p, ", ASIC PCI Rev %s", asic ? "1.0" : "1.1");
  56. printk("%s.\n", boardtype);
  57. }
  58. #define PORT(_base,_irq) \
  59. { \
  60. .iobase = _base, \
  61. .irq = _irq, \
  62. .uartclk = 1843200, \
  63. .iotype = UPIO_PORT, \
  64. .flags = UPF_BOOT_AUTOCONF, \
  65. }
  66. static struct plat_serial8250_port pcimt_data[] = {
  67. PORT(0x3f8, 4),
  68. PORT(0x2f8, 3),
  69. { },
  70. };
  71. static struct platform_device pcimt_serial8250_device = {
  72. .name = "serial8250",
  73. .id = PLAT8250_DEV_PLATFORM,
  74. .dev = {
  75. .platform_data = pcimt_data,
  76. },
  77. };
  78. static struct resource pcimt_cmos_rsrc[] = {
  79. {
  80. .start = 0x70,
  81. .end = 0x71,
  82. .flags = IORESOURCE_IO
  83. },
  84. {
  85. .start = 8,
  86. .end = 8,
  87. .flags = IORESOURCE_IRQ
  88. }
  89. };
  90. static struct platform_device pcimt_cmos_device = {
  91. .name = "rtc_cmos",
  92. .num_resources = ARRAY_SIZE(pcimt_cmos_rsrc),
  93. .resource = pcimt_cmos_rsrc
  94. };
  95. static struct resource sni_io_resource = {
  96. .start = 0x00000000UL,
  97. .end = 0x03bfffffUL,
  98. .name = "PCIMT IO MEM",
  99. .flags = IORESOURCE_IO,
  100. };
  101. static struct resource pcimt_io_resources[] = {
  102. {
  103. .start = 0x00,
  104. .end = 0x1f,
  105. .name = "dma1",
  106. .flags = IORESOURCE_BUSY
  107. }, {
  108. .start = 0x40,
  109. .end = 0x5f,
  110. .name = "timer",
  111. .flags = IORESOURCE_BUSY
  112. }, {
  113. .start = 0x60,
  114. .end = 0x6f,
  115. .name = "keyboard",
  116. .flags = IORESOURCE_BUSY
  117. }, {
  118. .start = 0x80,
  119. .end = 0x8f,
  120. .name = "dma page reg",
  121. .flags = IORESOURCE_BUSY
  122. }, {
  123. .start = 0xc0,
  124. .end = 0xdf,
  125. .name = "dma2",
  126. .flags = IORESOURCE_BUSY
  127. }, {
  128. .start = 0xcfc,
  129. .end = 0xcff,
  130. .name = "PCI config data",
  131. .flags = IORESOURCE_BUSY
  132. }
  133. };
  134. static struct resource pcimt_mem_resources[] = {
  135. {
  136. /*
  137. * this region should only be 4 bytes long,
  138. * but it's 16MB on all RM300C I've checked
  139. */
  140. .start = 0x1a000000,
  141. .end = 0x1affffff,
  142. .name = "PCI INT ACK",
  143. .flags = IORESOURCE_BUSY
  144. }
  145. };
  146. static struct resource sni_mem_resource = {
  147. .start = 0x18000000UL,
  148. .end = 0x1fbfffffUL,
  149. .name = "PCIMT PCI MEM",
  150. .flags = IORESOURCE_MEM
  151. };
  152. static void __init sni_pcimt_resource_init(void)
  153. {
  154. int i;
  155. /* request I/O space for devices used on all i[345]86 PCs */
  156. for (i = 0; i < ARRAY_SIZE(pcimt_io_resources); i++)
  157. request_resource(&sni_io_resource, pcimt_io_resources + i);
  158. /* request MEM space for devices used on all i[345]86 PCs */
  159. for (i = 0; i < ARRAY_SIZE(pcimt_mem_resources); i++)
  160. request_resource(&sni_mem_resource, pcimt_mem_resources + i);
  161. }
  162. extern struct pci_ops sni_pcimt_ops;
  163. static struct pci_controller sni_controller = {
  164. .pci_ops = &sni_pcimt_ops,
  165. .mem_resource = &sni_mem_resource,
  166. .mem_offset = 0x00000000UL,
  167. .io_resource = &sni_io_resource,
  168. .io_offset = 0x00000000UL,
  169. .io_map_base = SNI_PORT_BASE
  170. };
  171. static void enable_pcimt_irq(unsigned int irq)
  172. {
  173. unsigned int mask = 1 << (irq - PCIMT_IRQ_INT2);
  174. *(volatile u8 *) PCIMT_IRQSEL |= mask;
  175. }
  176. void disable_pcimt_irq(unsigned int irq)
  177. {
  178. unsigned int mask = ~(1 << (irq - PCIMT_IRQ_INT2));
  179. *(volatile u8 *) PCIMT_IRQSEL &= mask;
  180. }
  181. static void end_pcimt_irq(unsigned int irq)
  182. {
  183. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  184. enable_pcimt_irq(irq);
  185. }
  186. static struct irq_chip pcimt_irq_type = {
  187. .typename = "PCIMT",
  188. .ack = disable_pcimt_irq,
  189. .mask = disable_pcimt_irq,
  190. .mask_ack = disable_pcimt_irq,
  191. .unmask = enable_pcimt_irq,
  192. .end = end_pcimt_irq,
  193. };
  194. /*
  195. * hwint0 should deal with MP agent, ASIC PCI, EISA NMI and debug
  196. * button interrupts. Later ...
  197. */
  198. static void pcimt_hwint0(void)
  199. {
  200. panic("Received int0 but no handler yet ...");
  201. }
  202. /*
  203. * hwint 1 deals with EISA and SCSI interrupts,
  204. *
  205. * The EISA_INT bit in CSITPEND is high active, all others are low active.
  206. */
  207. static void pcimt_hwint1(void)
  208. {
  209. u8 pend = *(volatile char *)PCIMT_CSITPEND;
  210. unsigned long flags;
  211. if (pend & IT_EISA) {
  212. int irq;
  213. /*
  214. * Note: ASIC PCI's builtin interrupt acknowledge feature is
  215. * broken. Using it may result in loss of some or all i8259
  216. * interrupts, so don't use PCIMT_INT_ACKNOWLEDGE ...
  217. */
  218. irq = i8259_irq();
  219. if (unlikely(irq < 0))
  220. return;
  221. do_IRQ(irq);
  222. }
  223. if (!(pend & IT_SCSI)) {
  224. flags = read_c0_status();
  225. clear_c0_status(ST0_IM);
  226. do_IRQ(PCIMT_IRQ_SCSI);
  227. write_c0_status(flags);
  228. }
  229. }
  230. /*
  231. * hwint 3 should deal with the PCI A - D interrupts,
  232. */
  233. static void pcimt_hwint3(void)
  234. {
  235. u8 pend = *(volatile char *)PCIMT_CSITPEND;
  236. int irq;
  237. pend &= (IT_INTA | IT_INTB | IT_INTC | IT_INTD);
  238. pend ^= (IT_INTA | IT_INTB | IT_INTC | IT_INTD);
  239. clear_c0_status(IE_IRQ3);
  240. irq = PCIMT_IRQ_INT2 + ffs(pend) - 1;
  241. do_IRQ(irq);
  242. set_c0_status(IE_IRQ3);
  243. }
  244. static void sni_pcimt_hwint(void)
  245. {
  246. u32 pending = read_c0_cause() & read_c0_status();
  247. if (pending & C_IRQ5)
  248. do_IRQ(MIPS_CPU_IRQ_BASE + 7);
  249. else if (pending & C_IRQ4)
  250. do_IRQ(MIPS_CPU_IRQ_BASE + 6);
  251. else if (pending & C_IRQ3)
  252. pcimt_hwint3();
  253. else if (pending & C_IRQ1)
  254. pcimt_hwint1();
  255. else if (pending & C_IRQ0) {
  256. pcimt_hwint0();
  257. }
  258. }
  259. void __init sni_pcimt_irq_init(void)
  260. {
  261. int i;
  262. *(volatile u8 *) PCIMT_IRQSEL = IT_ETH | IT_EISA;
  263. mips_cpu_irq_init();
  264. /* Actually we've got more interrupts to handle ... */
  265. for (i = PCIMT_IRQ_INT2; i <= PCIMT_IRQ_SCSI; i++)
  266. set_irq_chip_and_handler(i, &pcimt_irq_type, handle_level_irq);
  267. sni_hwint = sni_pcimt_hwint;
  268. change_c0_status(ST0_IM, IE_IRQ1|IE_IRQ3);
  269. }
  270. void __init sni_pcimt_init(void)
  271. {
  272. sni_pcimt_detect();
  273. sni_pcimt_sc_init();
  274. ioport_resource.end = sni_io_resource.end;
  275. #ifdef CONFIG_PCI
  276. PCIBIOS_MIN_IO = 0x9000;
  277. register_pci_controller(&sni_controller);
  278. #endif
  279. sni_pcimt_resource_init();
  280. }
  281. static int __init snirm_pcimt_setup_devinit(void)
  282. {
  283. switch (sni_brd_type) {
  284. case SNI_BRD_PCI_MTOWER:
  285. case SNI_BRD_PCI_DESKTOP:
  286. case SNI_BRD_PCI_MTOWER_CPLUS:
  287. platform_device_register(&pcimt_serial8250_device);
  288. platform_device_register(&pcimt_cmos_device);
  289. break;
  290. }
  291. return 0;
  292. }
  293. device_initcall(snirm_pcimt_setup_devinit);