pcimt.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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 = 0x00001000UL,
  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 = 0x10000000UL,
  120. .end = 0xffffffffUL,
  121. .name = "PCIMT PCI MEM",
  122. .flags = IORESOURCE_MEM
  123. };
  124. /*
  125. * The RM200/RM300 has a few holes in it's PCI/EISA memory address space used
  126. * for other purposes. Be paranoid and allocate all of the before the PCI
  127. * code gets a chance to to map anything else there ...
  128. *
  129. * This leaves the following areas available:
  130. *
  131. * 0x10000000 - 0x1009ffff (640kB) PCI/EISA/ISA Bus Memory
  132. * 0x10100000 - 0x13ffffff ( 15MB) PCI/EISA/ISA Bus Memory
  133. * 0x18000000 - 0x1fbfffff (124MB) PCI/EISA Bus Memory
  134. * 0x1ff08000 - 0x1ffeffff (816kB) PCI/EISA Bus Memory
  135. * 0xa0000000 - 0xffffffff (1.5GB) PCI/EISA Bus Memory
  136. */
  137. static struct resource pcimt_mem_resources[] = {
  138. {
  139. .start = 0x100a0000,
  140. .end = 0x100bffff,
  141. .name = "Video RAM area",
  142. .flags = IORESOURCE_BUSY
  143. }, {
  144. .start = 0x100c0000,
  145. .end = 0x100fffff,
  146. .name = "ISA Reserved",
  147. .flags = IORESOURCE_BUSY
  148. }, {
  149. .start = 0x14000000,
  150. .end = 0x17bfffff,
  151. .name = "PCI IO",
  152. .flags = IORESOURCE_BUSY
  153. }, {
  154. .start = 0x17c00000,
  155. .end = 0x17ffffff,
  156. .name = "Cache Replacement Area",
  157. .flags = IORESOURCE_BUSY
  158. }, {
  159. .start = 0x1a000000,
  160. .end = 0x1a000003,
  161. .name = "PCI INT Acknowledge",
  162. .flags = IORESOURCE_BUSY
  163. }, {
  164. .start = 0x1fc00000,
  165. .end = 0x1fc7ffff,
  166. .name = "Boot PROM",
  167. .flags = IORESOURCE_BUSY
  168. }, {
  169. .start = 0x1fc80000,
  170. .end = 0x1fcfffff,
  171. .name = "Diag PROM",
  172. .flags = IORESOURCE_BUSY
  173. }, {
  174. .start = 0x1fd00000,
  175. .end = 0x1fdfffff,
  176. .name = "X-Bus",
  177. .flags = IORESOURCE_BUSY
  178. }, {
  179. .start = 0x1fe00000,
  180. .end = 0x1fefffff,
  181. .name = "BIOS map",
  182. .flags = IORESOURCE_BUSY
  183. }, {
  184. .start = 0x1ff00000,
  185. .end = 0x1ff7ffff,
  186. .name = "NVRAM / EEPROM",
  187. .flags = IORESOURCE_BUSY
  188. }, {
  189. .start = 0x1fff0000,
  190. .end = 0x1fffefff,
  191. .name = "ASIC PCI",
  192. .flags = IORESOURCE_BUSY
  193. }, {
  194. .start = 0x1ffff000,
  195. .end = 0x1fffffff,
  196. .name = "MP Agent",
  197. .flags = IORESOURCE_BUSY
  198. }, {
  199. .start = 0x20000000,
  200. .end = 0x9fffffff,
  201. .name = "Main Memory",
  202. .flags = IORESOURCE_BUSY
  203. }
  204. };
  205. static void __init sni_pcimt_resource_init(void)
  206. {
  207. int i;
  208. /* request I/O space for devices used on all i[345]86 PCs */
  209. for (i = 0; i < ARRAY_SIZE(pcimt_io_resources); i++)
  210. request_resource(&ioport_resource, pcimt_io_resources + i);
  211. /* request mem space for pcimt-specific devices */
  212. for (i = 0; i < ARRAY_SIZE(pcimt_mem_resources); i++)
  213. request_resource(&sni_mem_resource, pcimt_mem_resources + i);
  214. ioport_resource.end = sni_io_resource.end;
  215. }
  216. extern struct pci_ops sni_pcimt_ops;
  217. static struct pci_controller sni_controller = {
  218. .pci_ops = &sni_pcimt_ops,
  219. .mem_resource = &sni_mem_resource,
  220. .mem_offset = 0x10000000UL,
  221. .io_resource = &sni_io_resource,
  222. .io_offset = 0x00000000UL
  223. };
  224. static void enable_pcimt_irq(unsigned int irq)
  225. {
  226. unsigned int mask = 1 << (irq - PCIMT_IRQ_INT2);
  227. *(volatile u8 *) PCIMT_IRQSEL |= mask;
  228. }
  229. void disable_pcimt_irq(unsigned int irq)
  230. {
  231. unsigned int mask = ~(1 << (irq - PCIMT_IRQ_INT2));
  232. *(volatile u8 *) PCIMT_IRQSEL &= mask;
  233. }
  234. static void end_pcimt_irq(unsigned int irq)
  235. {
  236. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  237. enable_pcimt_irq(irq);
  238. }
  239. static struct irq_chip pcimt_irq_type = {
  240. .typename = "PCIMT",
  241. .ack = disable_pcimt_irq,
  242. .mask = disable_pcimt_irq,
  243. .mask_ack = disable_pcimt_irq,
  244. .unmask = enable_pcimt_irq,
  245. .end = end_pcimt_irq,
  246. };
  247. /*
  248. * hwint0 should deal with MP agent, ASIC PCI, EISA NMI and debug
  249. * button interrupts. Later ...
  250. */
  251. static void pcimt_hwint0(void)
  252. {
  253. panic("Received int0 but no handler yet ...");
  254. }
  255. /*
  256. * hwint 1 deals with EISA and SCSI interrupts,
  257. *
  258. * The EISA_INT bit in CSITPEND is high active, all others are low active.
  259. */
  260. static void pcimt_hwint1(void)
  261. {
  262. u8 pend = *(volatile char *)PCIMT_CSITPEND;
  263. unsigned long flags;
  264. if (pend & IT_EISA) {
  265. int irq;
  266. /*
  267. * Note: ASIC PCI's builtin interrupt achknowledge feature is
  268. * broken. Using it may result in loss of some or all i8259
  269. * interupts, so don't use PCIMT_INT_ACKNOWLEDGE ...
  270. */
  271. irq = i8259_irq();
  272. if (unlikely(irq < 0))
  273. return;
  274. do_IRQ(irq);
  275. }
  276. if (!(pend & IT_SCSI)) {
  277. flags = read_c0_status();
  278. clear_c0_status(ST0_IM);
  279. do_IRQ(PCIMT_IRQ_SCSI);
  280. write_c0_status(flags);
  281. }
  282. }
  283. /*
  284. * hwint 3 should deal with the PCI A - D interrupts,
  285. */
  286. static void pcimt_hwint3(void)
  287. {
  288. u8 pend = *(volatile char *)PCIMT_CSITPEND;
  289. int irq;
  290. pend &= (IT_INTA | IT_INTB | IT_INTC | IT_INTD);
  291. pend ^= (IT_INTA | IT_INTB | IT_INTC | IT_INTD);
  292. clear_c0_status(IE_IRQ3);
  293. irq = PCIMT_IRQ_INT2 + ffs(pend) - 1;
  294. do_IRQ(irq);
  295. set_c0_status(IE_IRQ3);
  296. }
  297. static void sni_pcimt_hwint(void)
  298. {
  299. u32 pending = (read_c0_cause() & read_c0_status());
  300. if (pending & C_IRQ5)
  301. do_IRQ (SNI_MIPS_IRQ_CPU_BASE + 7);
  302. else if (pending & C_IRQ4)
  303. do_IRQ (SNI_MIPS_IRQ_CPU_BASE + 6);
  304. else if (pending & C_IRQ3)
  305. pcimt_hwint3();
  306. else if (pending & C_IRQ1)
  307. pcimt_hwint1();
  308. else if (pending & C_IRQ0) {
  309. pcimt_hwint0();
  310. }
  311. }
  312. void __init sni_pcimt_irq_init(void)
  313. {
  314. int i;
  315. *(volatile u8 *) PCIMT_IRQSEL = IT_ETH | IT_EISA;
  316. mips_cpu_irq_init();
  317. /* Actually we've got more interrupts to handle ... */
  318. for (i = PCIMT_IRQ_INT2; i <= PCIMT_IRQ_SCSI; i++)
  319. set_irq_chip(i, &pcimt_irq_type);
  320. sni_hwint = sni_pcimt_hwint;
  321. change_c0_status(ST0_IM, IE_IRQ1|IE_IRQ3);
  322. }
  323. void sni_pcimt_init(void)
  324. {
  325. sni_pcimt_resource_init();
  326. sni_pcimt_detect();
  327. sni_pcimt_sc_init();
  328. rtc_mips_get_time = mc146818_get_cmos_time;
  329. rtc_mips_set_time = mc146818_set_rtc_mmss;
  330. board_time_init = sni_cpu_time_init;
  331. #ifdef CONFIG_PCI
  332. register_pci_controller(&sni_controller);
  333. #endif
  334. }
  335. static int __init snirm_pcimt_setup_devinit(void)
  336. {
  337. switch (sni_brd_type) {
  338. case SNI_BRD_PCI_MTOWER:
  339. case SNI_BRD_PCI_DESKTOP:
  340. case SNI_BRD_PCI_MTOWER_CPLUS:
  341. platform_device_register(&pcimt_serial8250_device);
  342. break;
  343. }
  344. return 0;
  345. }
  346. device_initcall(snirm_pcimt_setup_devinit);