pcimt.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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 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 sni_mem_resource = {
  119. .start = 0x18000000UL,
  120. .end = 0x1fbfffffUL,
  121. .name = "PCIMT PCI MEM",
  122. .flags = IORESOURCE_MEM
  123. };
  124. static void __init sni_pcimt_resource_init(void)
  125. {
  126. int i;
  127. /* request I/O space for devices used on all i[345]86 PCs */
  128. for (i = 0; i < ARRAY_SIZE(pcimt_io_resources); i++)
  129. request_resource(&sni_io_resource, pcimt_io_resources + i);
  130. }
  131. extern struct pci_ops sni_pcimt_ops;
  132. static struct pci_controller sni_controller = {
  133. .pci_ops = &sni_pcimt_ops,
  134. .mem_resource = &sni_mem_resource,
  135. .mem_offset = 0x00000000UL,
  136. .io_resource = &sni_io_resource,
  137. .io_offset = 0x00000000UL,
  138. .io_map_base = SNI_PORT_BASE
  139. };
  140. static void enable_pcimt_irq(unsigned int irq)
  141. {
  142. unsigned int mask = 1 << (irq - PCIMT_IRQ_INT2);
  143. *(volatile u8 *) PCIMT_IRQSEL |= mask;
  144. }
  145. void disable_pcimt_irq(unsigned int irq)
  146. {
  147. unsigned int mask = ~(1 << (irq - PCIMT_IRQ_INT2));
  148. *(volatile u8 *) PCIMT_IRQSEL &= mask;
  149. }
  150. static void end_pcimt_irq(unsigned int irq)
  151. {
  152. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  153. enable_pcimt_irq(irq);
  154. }
  155. static struct irq_chip pcimt_irq_type = {
  156. .typename = "PCIMT",
  157. .ack = disable_pcimt_irq,
  158. .mask = disable_pcimt_irq,
  159. .mask_ack = disable_pcimt_irq,
  160. .unmask = enable_pcimt_irq,
  161. .end = end_pcimt_irq,
  162. };
  163. /*
  164. * hwint0 should deal with MP agent, ASIC PCI, EISA NMI and debug
  165. * button interrupts. Later ...
  166. */
  167. static void pcimt_hwint0(void)
  168. {
  169. panic("Received int0 but no handler yet ...");
  170. }
  171. /*
  172. * hwint 1 deals with EISA and SCSI interrupts,
  173. *
  174. * The EISA_INT bit in CSITPEND is high active, all others are low active.
  175. */
  176. static void pcimt_hwint1(void)
  177. {
  178. u8 pend = *(volatile char *)PCIMT_CSITPEND;
  179. unsigned long flags;
  180. if (pend & IT_EISA) {
  181. int irq;
  182. /*
  183. * Note: ASIC PCI's builtin interrupt achknowledge feature is
  184. * broken. Using it may result in loss of some or all i8259
  185. * interupts, so don't use PCIMT_INT_ACKNOWLEDGE ...
  186. */
  187. irq = i8259_irq();
  188. if (unlikely(irq < 0))
  189. return;
  190. do_IRQ(irq);
  191. }
  192. if (!(pend & IT_SCSI)) {
  193. flags = read_c0_status();
  194. clear_c0_status(ST0_IM);
  195. do_IRQ(PCIMT_IRQ_SCSI);
  196. write_c0_status(flags);
  197. }
  198. }
  199. /*
  200. * hwint 3 should deal with the PCI A - D interrupts,
  201. */
  202. static void pcimt_hwint3(void)
  203. {
  204. u8 pend = *(volatile char *)PCIMT_CSITPEND;
  205. int irq;
  206. pend &= (IT_INTA | IT_INTB | IT_INTC | IT_INTD);
  207. pend ^= (IT_INTA | IT_INTB | IT_INTC | IT_INTD);
  208. clear_c0_status(IE_IRQ3);
  209. irq = PCIMT_IRQ_INT2 + ffs(pend) - 1;
  210. do_IRQ(irq);
  211. set_c0_status(IE_IRQ3);
  212. }
  213. static void sni_pcimt_hwint(void)
  214. {
  215. u32 pending = read_c0_cause() & read_c0_status();
  216. if (pending & C_IRQ5)
  217. do_IRQ (MIPS_CPU_IRQ_BASE + 7);
  218. else if (pending & C_IRQ4)
  219. do_IRQ (MIPS_CPU_IRQ_BASE + 6);
  220. else if (pending & C_IRQ3)
  221. pcimt_hwint3();
  222. else if (pending & C_IRQ1)
  223. pcimt_hwint1();
  224. else if (pending & C_IRQ0) {
  225. pcimt_hwint0();
  226. }
  227. }
  228. void __init sni_pcimt_irq_init(void)
  229. {
  230. int i;
  231. *(volatile u8 *) PCIMT_IRQSEL = IT_ETH | IT_EISA;
  232. mips_cpu_irq_init();
  233. /* Actually we've got more interrupts to handle ... */
  234. for (i = PCIMT_IRQ_INT2; i <= PCIMT_IRQ_SCSI; i++)
  235. set_irq_chip(i, &pcimt_irq_type);
  236. sni_hwint = sni_pcimt_hwint;
  237. change_c0_status(ST0_IM, IE_IRQ1|IE_IRQ3);
  238. }
  239. void sni_pcimt_init(void)
  240. {
  241. sni_pcimt_detect();
  242. sni_pcimt_sc_init();
  243. rtc_mips_get_time = mc146818_get_cmos_time;
  244. rtc_mips_set_time = mc146818_set_rtc_mmss;
  245. board_time_init = sni_cpu_time_init;
  246. ioport_resource.end = sni_io_resource.end;
  247. #ifdef CONFIG_PCI
  248. PCIBIOS_MIN_IO = 0x9000;
  249. register_pci_controller(&sni_controller);
  250. #endif
  251. sni_pcimt_resource_init();
  252. }
  253. static int __init snirm_pcimt_setup_devinit(void)
  254. {
  255. switch (sni_brd_type) {
  256. case SNI_BRD_PCI_MTOWER:
  257. case SNI_BRD_PCI_DESKTOP:
  258. case SNI_BRD_PCI_MTOWER_CPLUS:
  259. platform_device_register(&pcimt_serial8250_device);
  260. break;
  261. }
  262. return 0;
  263. }
  264. device_initcall(snirm_pcimt_setup_devinit);