pcimt.c 7.1 KB

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