pcimt.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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/mc146818-time.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 deactived.\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 sni_io_resource = {
  80. .start = 0x00000000UL,
  81. .end = 0x03bfffffUL,
  82. .name = "PCIMT IO MEM",
  83. .flags = IORESOURCE_IO,
  84. };
  85. static struct resource pcimt_io_resources[] = {
  86. {
  87. .start = 0x00,
  88. .end = 0x1f,
  89. .name = "dma1",
  90. .flags = IORESOURCE_BUSY
  91. }, {
  92. .start = 0x40,
  93. .end = 0x5f,
  94. .name = "timer",
  95. .flags = IORESOURCE_BUSY
  96. }, {
  97. .start = 0x60,
  98. .end = 0x6f,
  99. .name = "keyboard",
  100. .flags = IORESOURCE_BUSY
  101. }, {
  102. .start = 0x80,
  103. .end = 0x8f,
  104. .name = "dma page reg",
  105. .flags = IORESOURCE_BUSY
  106. }, {
  107. .start = 0xc0,
  108. .end = 0xdf,
  109. .name = "dma2",
  110. .flags = IORESOURCE_BUSY
  111. }, {
  112. .start = 0xcfc,
  113. .end = 0xcff,
  114. .name = "PCI config data",
  115. .flags = IORESOURCE_BUSY
  116. }
  117. };
  118. static struct resource pcimt_mem_resources[] = {
  119. {
  120. /*
  121. * this region should only be 4 bytes long,
  122. * but it's 16MB on all RM300C I've checked
  123. */
  124. .start = 0x1a000000,
  125. .end = 0x1affffff,
  126. .name = "PCI INT ACK",
  127. .flags = IORESOURCE_BUSY
  128. }
  129. };
  130. static struct resource sni_mem_resource = {
  131. .start = 0x18000000UL,
  132. .end = 0x1fbfffffUL,
  133. .name = "PCIMT PCI MEM",
  134. .flags = IORESOURCE_MEM
  135. };
  136. static void __init sni_pcimt_resource_init(void)
  137. {
  138. int i;
  139. /* request I/O space for devices used on all i[345]86 PCs */
  140. for (i = 0; i < ARRAY_SIZE(pcimt_io_resources); i++)
  141. request_resource(&sni_io_resource, pcimt_io_resources + i);
  142. /* request MEM space for devices used on all i[345]86 PCs */
  143. for (i = 0; i < ARRAY_SIZE(pcimt_mem_resources); i++)
  144. request_resource(&sni_mem_resource, pcimt_mem_resources + i);
  145. }
  146. extern struct pci_ops sni_pcimt_ops;
  147. static struct pci_controller sni_controller = {
  148. .pci_ops = &sni_pcimt_ops,
  149. .mem_resource = &sni_mem_resource,
  150. .mem_offset = 0x00000000UL,
  151. .io_resource = &sni_io_resource,
  152. .io_offset = 0x00000000UL,
  153. .io_map_base = SNI_PORT_BASE
  154. };
  155. static void enable_pcimt_irq(unsigned int irq)
  156. {
  157. unsigned int mask = 1 << (irq - PCIMT_IRQ_INT2);
  158. *(volatile u8 *) PCIMT_IRQSEL |= mask;
  159. }
  160. void disable_pcimt_irq(unsigned int irq)
  161. {
  162. unsigned int mask = ~(1 << (irq - PCIMT_IRQ_INT2));
  163. *(volatile u8 *) PCIMT_IRQSEL &= mask;
  164. }
  165. static void end_pcimt_irq(unsigned int irq)
  166. {
  167. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  168. enable_pcimt_irq(irq);
  169. }
  170. static struct irq_chip pcimt_irq_type = {
  171. .typename = "PCIMT",
  172. .ack = disable_pcimt_irq,
  173. .mask = disable_pcimt_irq,
  174. .mask_ack = disable_pcimt_irq,
  175. .unmask = enable_pcimt_irq,
  176. .end = end_pcimt_irq,
  177. };
  178. /*
  179. * hwint0 should deal with MP agent, ASIC PCI, EISA NMI and debug
  180. * button interrupts. Later ...
  181. */
  182. static void pcimt_hwint0(void)
  183. {
  184. panic("Received int0 but no handler yet ...");
  185. }
  186. /*
  187. * hwint 1 deals with EISA and SCSI interrupts,
  188. *
  189. * The EISA_INT bit in CSITPEND is high active, all others are low active.
  190. */
  191. static void pcimt_hwint1(void)
  192. {
  193. u8 pend = *(volatile char *)PCIMT_CSITPEND;
  194. unsigned long flags;
  195. if (pend & IT_EISA) {
  196. int irq;
  197. /*
  198. * Note: ASIC PCI's builtin interrupt achknowledge feature is
  199. * broken. Using it may result in loss of some or all i8259
  200. * interupts, so don't use PCIMT_INT_ACKNOWLEDGE ...
  201. */
  202. irq = i8259_irq();
  203. if (unlikely(irq < 0))
  204. return;
  205. do_IRQ(irq);
  206. }
  207. if (!(pend & IT_SCSI)) {
  208. flags = read_c0_status();
  209. clear_c0_status(ST0_IM);
  210. do_IRQ(PCIMT_IRQ_SCSI);
  211. write_c0_status(flags);
  212. }
  213. }
  214. /*
  215. * hwint 3 should deal with the PCI A - D interrupts,
  216. */
  217. static void pcimt_hwint3(void)
  218. {
  219. u8 pend = *(volatile char *)PCIMT_CSITPEND;
  220. int irq;
  221. pend &= (IT_INTA | IT_INTB | IT_INTC | IT_INTD);
  222. pend ^= (IT_INTA | IT_INTB | IT_INTC | IT_INTD);
  223. clear_c0_status(IE_IRQ3);
  224. irq = PCIMT_IRQ_INT2 + ffs(pend) - 1;
  225. do_IRQ(irq);
  226. set_c0_status(IE_IRQ3);
  227. }
  228. static void sni_pcimt_hwint(void)
  229. {
  230. u32 pending = read_c0_cause() & read_c0_status();
  231. if (pending & C_IRQ5)
  232. do_IRQ (MIPS_CPU_IRQ_BASE + 7);
  233. else if (pending & C_IRQ4)
  234. do_IRQ (MIPS_CPU_IRQ_BASE + 6);
  235. else if (pending & C_IRQ3)
  236. pcimt_hwint3();
  237. else if (pending & C_IRQ1)
  238. pcimt_hwint1();
  239. else if (pending & C_IRQ0) {
  240. pcimt_hwint0();
  241. }
  242. }
  243. void __init sni_pcimt_irq_init(void)
  244. {
  245. int i;
  246. *(volatile u8 *) PCIMT_IRQSEL = IT_ETH | IT_EISA;
  247. mips_cpu_irq_init();
  248. /* Actually we've got more interrupts to handle ... */
  249. for (i = PCIMT_IRQ_INT2; i <= PCIMT_IRQ_SCSI; i++)
  250. set_irq_chip(i, &pcimt_irq_type);
  251. sni_hwint = sni_pcimt_hwint;
  252. change_c0_status(ST0_IM, IE_IRQ1|IE_IRQ3);
  253. }
  254. void sni_pcimt_init(void)
  255. {
  256. sni_pcimt_detect();
  257. sni_pcimt_sc_init();
  258. rtc_mips_get_time = mc146818_get_cmos_time;
  259. rtc_mips_set_time = mc146818_set_rtc_mmss;
  260. board_time_init = sni_cpu_time_init;
  261. ioport_resource.end = sni_io_resource.end;
  262. #ifdef CONFIG_PCI
  263. PCIBIOS_MIN_IO = 0x9000;
  264. register_pci_controller(&sni_controller);
  265. #endif
  266. sni_pcimt_resource_init();
  267. }
  268. static int __init snirm_pcimt_setup_devinit(void)
  269. {
  270. switch (sni_brd_type) {
  271. case SNI_BRD_PCI_MTOWER:
  272. case SNI_BRD_PCI_DESKTOP:
  273. case SNI_BRD_PCI_MTOWER_CPLUS:
  274. platform_device_register(&pcimt_serial8250_device);
  275. break;
  276. }
  277. return 0;
  278. }
  279. device_initcall(snirm_pcimt_setup_devinit);