sys_marvel.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. /*
  2. * linux/arch/alpha/kernel/sys_marvel.c
  3. *
  4. * Marvel / IO7 support
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/types.h>
  8. #include <linux/mm.h>
  9. #include <linux/sched.h>
  10. #include <linux/pci.h>
  11. #include <linux/init.h>
  12. #include <linux/bitops.h>
  13. #include <asm/ptrace.h>
  14. #include <asm/system.h>
  15. #include <asm/dma.h>
  16. #include <asm/irq.h>
  17. #include <asm/mmu_context.h>
  18. #include <asm/io.h>
  19. #include <asm/pgtable.h>
  20. #include <asm/core_marvel.h>
  21. #include <asm/hwrpb.h>
  22. #include <asm/tlbflush.h>
  23. #include "proto.h"
  24. #include "err_impl.h"
  25. #include "irq_impl.h"
  26. #include "pci_impl.h"
  27. #include "machvec_impl.h"
  28. #if NR_IRQS < MARVEL_NR_IRQS
  29. # error NR_IRQS < MARVEL_NR_IRQS !!!
  30. #endif
  31. /*
  32. * Interrupt handling.
  33. */
  34. static void
  35. io7_device_interrupt(unsigned long vector, struct pt_regs * regs)
  36. {
  37. unsigned int pid;
  38. unsigned int irq;
  39. /*
  40. * Vector is 0x800 + (interrupt)
  41. *
  42. * where (interrupt) is:
  43. *
  44. * ...16|15 14|13 4|3 0
  45. * -----+-----+--------+---
  46. * PE | 0 | irq | 0
  47. *
  48. * where (irq) is
  49. *
  50. * 0x0800 - 0x0ff0 - 0x0800 + (LSI id << 4)
  51. * 0x1000 - 0x2ff0 - 0x1000 + (MSI_DAT<8:0> << 4)
  52. */
  53. pid = vector >> 16;
  54. irq = ((vector & 0xffff) - 0x800) >> 4;
  55. irq += 16; /* offset for legacy */
  56. irq &= MARVEL_IRQ_VEC_IRQ_MASK; /* not too many bits */
  57. irq |= pid << MARVEL_IRQ_VEC_PE_SHIFT; /* merge the pid */
  58. handle_irq(irq, regs);
  59. }
  60. static volatile unsigned long *
  61. io7_get_irq_ctl(unsigned int irq, struct io7 **pio7)
  62. {
  63. volatile unsigned long *ctl;
  64. unsigned int pid;
  65. struct io7 *io7;
  66. pid = irq >> MARVEL_IRQ_VEC_PE_SHIFT;
  67. if (!(io7 = marvel_find_io7(pid))) {
  68. printk(KERN_ERR
  69. "%s for nonexistent io7 -- vec %x, pid %d\n",
  70. __FUNCTION__, irq, pid);
  71. return NULL;
  72. }
  73. irq &= MARVEL_IRQ_VEC_IRQ_MASK; /* isolate the vector */
  74. irq -= 16; /* subtract legacy bias */
  75. if (irq >= 0x180) {
  76. printk(KERN_ERR
  77. "%s for invalid irq -- pid %d adjusted irq %x\n",
  78. __FUNCTION__, pid, irq);
  79. return NULL;
  80. }
  81. ctl = &io7->csrs->PO7_LSI_CTL[irq & 0xff].csr; /* assume LSI */
  82. if (irq >= 0x80) /* MSI */
  83. ctl = &io7->csrs->PO7_MSI_CTL[((irq - 0x80) >> 5) & 0x0f].csr;
  84. if (pio7) *pio7 = io7;
  85. return ctl;
  86. }
  87. static void
  88. io7_enable_irq(unsigned int irq)
  89. {
  90. volatile unsigned long *ctl;
  91. struct io7 *io7;
  92. ctl = io7_get_irq_ctl(irq, &io7);
  93. if (!ctl || !io7) {
  94. printk(KERN_ERR "%s: get_ctl failed for irq %x\n",
  95. __FUNCTION__, irq);
  96. return;
  97. }
  98. spin_lock(&io7->irq_lock);
  99. *ctl |= 1UL << 24;
  100. mb();
  101. *ctl;
  102. spin_unlock(&io7->irq_lock);
  103. }
  104. static void
  105. io7_disable_irq(unsigned int irq)
  106. {
  107. volatile unsigned long *ctl;
  108. struct io7 *io7;
  109. ctl = io7_get_irq_ctl(irq, &io7);
  110. if (!ctl || !io7) {
  111. printk(KERN_ERR "%s: get_ctl failed for irq %x\n",
  112. __FUNCTION__, irq);
  113. return;
  114. }
  115. spin_lock(&io7->irq_lock);
  116. *ctl &= ~(1UL << 24);
  117. mb();
  118. *ctl;
  119. spin_unlock(&io7->irq_lock);
  120. }
  121. static unsigned int
  122. io7_startup_irq(unsigned int irq)
  123. {
  124. io7_enable_irq(irq);
  125. return 0; /* never anything pending */
  126. }
  127. static void
  128. io7_end_irq(unsigned int irq)
  129. {
  130. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  131. io7_enable_irq(irq);
  132. }
  133. static void
  134. marvel_irq_noop(unsigned int irq)
  135. {
  136. return;
  137. }
  138. static unsigned int
  139. marvel_irq_noop_return(unsigned int irq)
  140. {
  141. return 0;
  142. }
  143. static struct hw_interrupt_type marvel_legacy_irq_type = {
  144. .typename = "LEGACY",
  145. .startup = marvel_irq_noop_return,
  146. .shutdown = marvel_irq_noop,
  147. .enable = marvel_irq_noop,
  148. .disable = marvel_irq_noop,
  149. .ack = marvel_irq_noop,
  150. .end = marvel_irq_noop,
  151. };
  152. static struct hw_interrupt_type io7_lsi_irq_type = {
  153. .typename = "LSI",
  154. .startup = io7_startup_irq,
  155. .shutdown = io7_disable_irq,
  156. .enable = io7_enable_irq,
  157. .disable = io7_disable_irq,
  158. .ack = io7_disable_irq,
  159. .end = io7_end_irq,
  160. };
  161. static struct hw_interrupt_type io7_msi_irq_type = {
  162. .typename = "MSI",
  163. .startup = io7_startup_irq,
  164. .shutdown = io7_disable_irq,
  165. .enable = io7_enable_irq,
  166. .disable = io7_disable_irq,
  167. .ack = marvel_irq_noop,
  168. .end = io7_end_irq,
  169. };
  170. static void
  171. io7_redirect_irq(struct io7 *io7,
  172. volatile unsigned long *csr,
  173. unsigned int where)
  174. {
  175. unsigned long val;
  176. val = *csr;
  177. val &= ~(0x1ffUL << 24); /* clear the target pid */
  178. val |= ((unsigned long)where << 24); /* set the new target pid */
  179. *csr = val;
  180. mb();
  181. *csr;
  182. }
  183. static void
  184. io7_redirect_one_lsi(struct io7 *io7, unsigned int which, unsigned int where)
  185. {
  186. unsigned long val;
  187. /*
  188. * LSI_CTL has target PID @ 14
  189. */
  190. val = io7->csrs->PO7_LSI_CTL[which].csr;
  191. val &= ~(0x1ffUL << 14); /* clear the target pid */
  192. val |= ((unsigned long)where << 14); /* set the new target pid */
  193. io7->csrs->PO7_LSI_CTL[which].csr = val;
  194. mb();
  195. io7->csrs->PO7_LSI_CTL[which].csr;
  196. }
  197. static void
  198. io7_redirect_one_msi(struct io7 *io7, unsigned int which, unsigned int where)
  199. {
  200. unsigned long val;
  201. /*
  202. * MSI_CTL has target PID @ 14
  203. */
  204. val = io7->csrs->PO7_MSI_CTL[which].csr;
  205. val &= ~(0x1ffUL << 14); /* clear the target pid */
  206. val |= ((unsigned long)where << 14); /* set the new target pid */
  207. io7->csrs->PO7_MSI_CTL[which].csr = val;
  208. mb();
  209. io7->csrs->PO7_MSI_CTL[which].csr;
  210. }
  211. static void __init
  212. init_one_io7_lsi(struct io7 *io7, unsigned int which, unsigned int where)
  213. {
  214. /*
  215. * LSI_CTL has target PID @ 14
  216. */
  217. io7->csrs->PO7_LSI_CTL[which].csr = ((unsigned long)where << 14);
  218. mb();
  219. io7->csrs->PO7_LSI_CTL[which].csr;
  220. }
  221. static void __init
  222. init_one_io7_msi(struct io7 *io7, unsigned int which, unsigned int where)
  223. {
  224. /*
  225. * MSI_CTL has target PID @ 14
  226. */
  227. io7->csrs->PO7_MSI_CTL[which].csr = ((unsigned long)where << 14);
  228. mb();
  229. io7->csrs->PO7_MSI_CTL[which].csr;
  230. }
  231. static void __init
  232. init_io7_irqs(struct io7 *io7,
  233. struct hw_interrupt_type *lsi_ops,
  234. struct hw_interrupt_type *msi_ops)
  235. {
  236. long base = (io7->pe << MARVEL_IRQ_VEC_PE_SHIFT) + 16;
  237. long i;
  238. printk("Initializing interrupts for IO7 at PE %u - base %lx\n",
  239. io7->pe, base);
  240. /*
  241. * Where should interrupts from this IO7 go?
  242. *
  243. * They really should be sent to the local CPU to avoid having to
  244. * traverse the mesh, but if it's not an SMP kernel, they have to
  245. * go to the boot CPU. Send them all to the boot CPU for now,
  246. * as each secondary starts, it can redirect it's local device
  247. * interrupts.
  248. */
  249. printk(" Interrupts reported to CPU at PE %u\n", boot_cpuid);
  250. spin_lock(&io7->irq_lock);
  251. /* set up the error irqs */
  252. io7_redirect_irq(io7, &io7->csrs->HLT_CTL.csr, boot_cpuid);
  253. io7_redirect_irq(io7, &io7->csrs->HPI_CTL.csr, boot_cpuid);
  254. io7_redirect_irq(io7, &io7->csrs->CRD_CTL.csr, boot_cpuid);
  255. io7_redirect_irq(io7, &io7->csrs->STV_CTL.csr, boot_cpuid);
  256. io7_redirect_irq(io7, &io7->csrs->HEI_CTL.csr, boot_cpuid);
  257. /* Set up the lsi irqs. */
  258. for (i = 0; i < 128; ++i) {
  259. irq_desc[base + i].status = IRQ_DISABLED | IRQ_LEVEL;
  260. irq_desc[base + i].handler = lsi_ops;
  261. }
  262. /* Disable the implemented irqs in hardware. */
  263. for (i = 0; i < 0x60; ++i)
  264. init_one_io7_lsi(io7, i, boot_cpuid);
  265. init_one_io7_lsi(io7, 0x74, boot_cpuid);
  266. init_one_io7_lsi(io7, 0x75, boot_cpuid);
  267. /* Set up the msi irqs. */
  268. for (i = 128; i < (128 + 512); ++i) {
  269. irq_desc[base + i].status = IRQ_DISABLED | IRQ_LEVEL;
  270. irq_desc[base + i].handler = msi_ops;
  271. }
  272. for (i = 0; i < 16; ++i)
  273. init_one_io7_msi(io7, i, boot_cpuid);
  274. spin_unlock(&io7->irq_lock);
  275. }
  276. static void __init
  277. marvel_init_irq(void)
  278. {
  279. int i;
  280. struct io7 *io7 = NULL;
  281. /* Reserve the legacy irqs. */
  282. for (i = 0; i < 16; ++i) {
  283. irq_desc[i].status = IRQ_DISABLED;
  284. irq_desc[i].handler = &marvel_legacy_irq_type;
  285. }
  286. /* Init the io7 irqs. */
  287. for (io7 = NULL; (io7 = marvel_next_io7(io7)) != NULL; )
  288. init_io7_irqs(io7, &io7_lsi_irq_type, &io7_msi_irq_type);
  289. }
  290. static int
  291. marvel_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  292. {
  293. struct pci_controller *hose = dev->sysdata;
  294. struct io7_port *io7_port = hose->sysdata;
  295. struct io7 *io7 = io7_port->io7;
  296. int msi_loc, msi_data_off;
  297. u16 msg_ctl;
  298. u16 msg_dat;
  299. u8 intline;
  300. int irq;
  301. pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &intline);
  302. irq = intline;
  303. msi_loc = pci_find_capability(dev, PCI_CAP_ID_MSI);
  304. msg_ctl = 0;
  305. if (msi_loc)
  306. pci_read_config_word(dev, msi_loc + PCI_MSI_FLAGS, &msg_ctl);
  307. if (msg_ctl & PCI_MSI_FLAGS_ENABLE) {
  308. msi_data_off = PCI_MSI_DATA_32;
  309. if (msg_ctl & PCI_MSI_FLAGS_64BIT)
  310. msi_data_off = PCI_MSI_DATA_64;
  311. pci_read_config_word(dev, msi_loc + msi_data_off, &msg_dat);
  312. irq = msg_dat & 0x1ff; /* we use msg_data<8:0> */
  313. irq += 0x80; /* offset for lsi */
  314. #if 1
  315. printk("PCI:%d:%d:%d (hose %d) is using MSI\n",
  316. dev->bus->number,
  317. PCI_SLOT(dev->devfn),
  318. PCI_FUNC(dev->devfn),
  319. hose->index);
  320. printk(" %d message(s) from 0x%04x\n",
  321. 1 << ((msg_ctl & PCI_MSI_FLAGS_QSIZE) >> 4),
  322. msg_dat);
  323. printk(" reporting on %d IRQ(s) from %d (0x%x)\n",
  324. 1 << ((msg_ctl & PCI_MSI_FLAGS_QSIZE) >> 4),
  325. (irq + 16) | (io7->pe << MARVEL_IRQ_VEC_PE_SHIFT),
  326. (irq + 16) | (io7->pe << MARVEL_IRQ_VEC_PE_SHIFT));
  327. #endif
  328. #if 0
  329. pci_write_config_word(dev, msi_loc + PCI_MSI_FLAGS,
  330. msg_ctl & ~PCI_MSI_FLAGS_ENABLE);
  331. pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &intline);
  332. irq = intline;
  333. printk(" forcing LSI interrupt on irq %d [0x%x]\n", irq, irq);
  334. #endif
  335. }
  336. irq += 16; /* offset for legacy */
  337. irq |= io7->pe << MARVEL_IRQ_VEC_PE_SHIFT; /* merge the pid */
  338. return irq;
  339. }
  340. static void __init
  341. marvel_init_pci(void)
  342. {
  343. struct io7 *io7;
  344. marvel_register_error_handlers();
  345. pci_probe_only = 1;
  346. common_init_pci();
  347. #ifdef CONFIG_VGA_HOSE
  348. locate_and_init_vga(NULL);
  349. #endif
  350. /* Clear any io7 errors. */
  351. for (io7 = NULL; (io7 = marvel_next_io7(io7)) != NULL; )
  352. io7_clear_errors(io7);
  353. }
  354. static void
  355. marvel_init_rtc(void)
  356. {
  357. init_rtc_irq();
  358. }
  359. static void
  360. marvel_smp_callin(void)
  361. {
  362. int cpuid = hard_smp_processor_id();
  363. struct io7 *io7 = marvel_find_io7(cpuid);
  364. unsigned int i;
  365. if (!io7)
  366. return;
  367. /*
  368. * There is a local IO7 - redirect all of its interrupts here.
  369. */
  370. printk("Redirecting IO7 interrupts to local CPU at PE %u\n", cpuid);
  371. /* Redirect the error IRQS here. */
  372. io7_redirect_irq(io7, &io7->csrs->HLT_CTL.csr, cpuid);
  373. io7_redirect_irq(io7, &io7->csrs->HPI_CTL.csr, cpuid);
  374. io7_redirect_irq(io7, &io7->csrs->CRD_CTL.csr, cpuid);
  375. io7_redirect_irq(io7, &io7->csrs->STV_CTL.csr, cpuid);
  376. io7_redirect_irq(io7, &io7->csrs->HEI_CTL.csr, cpuid);
  377. /* Redirect the implemented LSIs here. */
  378. for (i = 0; i < 0x60; ++i)
  379. io7_redirect_one_lsi(io7, i, cpuid);
  380. io7_redirect_one_lsi(io7, 0x74, cpuid);
  381. io7_redirect_one_lsi(io7, 0x75, cpuid);
  382. /* Redirect the MSIs here. */
  383. for (i = 0; i < 16; ++i)
  384. io7_redirect_one_msi(io7, i, cpuid);
  385. }
  386. /*
  387. * System Vectors
  388. */
  389. struct alpha_machine_vector marvel_ev7_mv __initmv = {
  390. .vector_name = "MARVEL/EV7",
  391. DO_EV7_MMU,
  392. DO_DEFAULT_RTC,
  393. DO_MARVEL_IO,
  394. .machine_check = marvel_machine_check,
  395. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  396. .min_io_address = DEFAULT_IO_BASE,
  397. .min_mem_address = DEFAULT_MEM_BASE,
  398. .pci_dac_offset = IO7_DAC_OFFSET,
  399. .nr_irqs = MARVEL_NR_IRQS,
  400. .device_interrupt = io7_device_interrupt,
  401. .agp_info = marvel_agp_info,
  402. .smp_callin = marvel_smp_callin,
  403. .init_arch = marvel_init_arch,
  404. .init_irq = marvel_init_irq,
  405. .init_rtc = marvel_init_rtc,
  406. .init_pci = marvel_init_pci,
  407. .kill_arch = marvel_kill_arch,
  408. .pci_map_irq = marvel_map_irq,
  409. .pci_swizzle = common_swizzle,
  410. .pa_to_nid = marvel_pa_to_nid,
  411. .cpuid_to_nid = marvel_cpuid_to_nid,
  412. .node_mem_start = marvel_node_mem_start,
  413. .node_mem_size = marvel_node_mem_size,
  414. };
  415. ALIAS_MV(marvel_ev7)