sys_titan.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /*
  2. * linux/arch/alpha/kernel/sys_titan.c
  3. *
  4. * Copyright (C) 1995 David A Rusling
  5. * Copyright (C) 1996, 1999 Jay A Estabrook
  6. * Copyright (C) 1998, 1999 Richard Henderson
  7. * Copyright (C) 1999, 2000 Jeff Wiedemeier
  8. *
  9. * Code supporting TITAN systems (EV6+TITAN), currently:
  10. * Privateer
  11. * Falcon
  12. * Granite
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/types.h>
  16. #include <linux/mm.h>
  17. #include <linux/sched.h>
  18. #include <linux/pci.h>
  19. #include <linux/init.h>
  20. #include <linux/bitops.h>
  21. #include <asm/ptrace.h>
  22. #include <asm/system.h>
  23. #include <asm/dma.h>
  24. #include <asm/irq.h>
  25. #include <asm/mmu_context.h>
  26. #include <asm/io.h>
  27. #include <asm/pgtable.h>
  28. #include <asm/core_titan.h>
  29. #include <asm/hwrpb.h>
  30. #include <asm/tlbflush.h>
  31. #include "proto.h"
  32. #include "irq_impl.h"
  33. #include "pci_impl.h"
  34. #include "machvec_impl.h"
  35. #include "err_impl.h"
  36. /*
  37. * Titan generic
  38. */
  39. /*
  40. * Titan supports up to 4 CPUs
  41. */
  42. static unsigned long titan_cpu_irq_affinity[4] = { ~0UL, ~0UL, ~0UL, ~0UL };
  43. /*
  44. * Mask is set (1) if enabled
  45. */
  46. static unsigned long titan_cached_irq_mask;
  47. /*
  48. * Need SMP-safe access to interrupt CSRs
  49. */
  50. DEFINE_SPINLOCK(titan_irq_lock);
  51. static void
  52. titan_update_irq_hw(unsigned long mask)
  53. {
  54. register titan_cchip *cchip = TITAN_cchip;
  55. unsigned long isa_enable = 1UL << 55;
  56. register int bcpu = boot_cpuid;
  57. #ifdef CONFIG_SMP
  58. cpumask_t cpm = cpu_present_map;
  59. volatile unsigned long *dim0, *dim1, *dim2, *dim3;
  60. unsigned long mask0, mask1, mask2, mask3, dummy;
  61. mask &= ~isa_enable;
  62. mask0 = mask & titan_cpu_irq_affinity[0];
  63. mask1 = mask & titan_cpu_irq_affinity[1];
  64. mask2 = mask & titan_cpu_irq_affinity[2];
  65. mask3 = mask & titan_cpu_irq_affinity[3];
  66. if (bcpu == 0) mask0 |= isa_enable;
  67. else if (bcpu == 1) mask1 |= isa_enable;
  68. else if (bcpu == 2) mask2 |= isa_enable;
  69. else mask3 |= isa_enable;
  70. dim0 = &cchip->dim0.csr;
  71. dim1 = &cchip->dim1.csr;
  72. dim2 = &cchip->dim2.csr;
  73. dim3 = &cchip->dim3.csr;
  74. if (!cpu_isset(0, cpm)) dim0 = &dummy;
  75. if (!cpu_isset(1, cpm)) dim1 = &dummy;
  76. if (!cpu_isset(2, cpm)) dim2 = &dummy;
  77. if (!cpu_isset(3, cpm)) dim3 = &dummy;
  78. *dim0 = mask0;
  79. *dim1 = mask1;
  80. *dim2 = mask2;
  81. *dim3 = mask3;
  82. mb();
  83. *dim0;
  84. *dim1;
  85. *dim2;
  86. *dim3;
  87. #else
  88. volatile unsigned long *dimB;
  89. dimB = &cchip->dim0.csr;
  90. if (bcpu == 1) dimB = &cchip->dim1.csr;
  91. else if (bcpu == 2) dimB = &cchip->dim2.csr;
  92. else if (bcpu == 3) dimB = &cchip->dim3.csr;
  93. *dimB = mask | isa_enable;
  94. mb();
  95. *dimB;
  96. #endif
  97. }
  98. static inline void
  99. titan_enable_irq(unsigned int irq)
  100. {
  101. spin_lock(&titan_irq_lock);
  102. titan_cached_irq_mask |= 1UL << (irq - 16);
  103. titan_update_irq_hw(titan_cached_irq_mask);
  104. spin_unlock(&titan_irq_lock);
  105. }
  106. static inline void
  107. titan_disable_irq(unsigned int irq)
  108. {
  109. spin_lock(&titan_irq_lock);
  110. titan_cached_irq_mask &= ~(1UL << (irq - 16));
  111. titan_update_irq_hw(titan_cached_irq_mask);
  112. spin_unlock(&titan_irq_lock);
  113. }
  114. static unsigned int
  115. titan_startup_irq(unsigned int irq)
  116. {
  117. titan_enable_irq(irq);
  118. return 0; /* never anything pending */
  119. }
  120. static void
  121. titan_end_irq(unsigned int irq)
  122. {
  123. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  124. titan_enable_irq(irq);
  125. }
  126. static void
  127. titan_cpu_set_irq_affinity(unsigned int irq, cpumask_t affinity)
  128. {
  129. int cpu;
  130. for (cpu = 0; cpu < 4; cpu++) {
  131. if (cpu_isset(cpu, affinity))
  132. titan_cpu_irq_affinity[cpu] |= 1UL << irq;
  133. else
  134. titan_cpu_irq_affinity[cpu] &= ~(1UL << irq);
  135. }
  136. }
  137. static int
  138. titan_set_irq_affinity(unsigned int irq, const struct cpumask *affinity)
  139. {
  140. spin_lock(&titan_irq_lock);
  141. titan_cpu_set_irq_affinity(irq - 16, *affinity);
  142. titan_update_irq_hw(titan_cached_irq_mask);
  143. spin_unlock(&titan_irq_lock);
  144. return 0;
  145. }
  146. static void
  147. titan_device_interrupt(unsigned long vector)
  148. {
  149. printk("titan_device_interrupt: NOT IMPLEMENTED YET!! \n");
  150. }
  151. static void
  152. titan_srm_device_interrupt(unsigned long vector)
  153. {
  154. int irq;
  155. irq = (vector - 0x800) >> 4;
  156. handle_irq(irq);
  157. }
  158. static void __init
  159. init_titan_irqs(struct irq_chip * ops, int imin, int imax)
  160. {
  161. long i;
  162. for (i = imin; i <= imax; ++i) {
  163. irq_desc[i].status = IRQ_DISABLED | IRQ_LEVEL;
  164. irq_desc[i].chip = ops;
  165. }
  166. }
  167. static struct irq_chip titan_irq_type = {
  168. .typename = "TITAN",
  169. .startup = titan_startup_irq,
  170. .shutdown = titan_disable_irq,
  171. .enable = titan_enable_irq,
  172. .disable = titan_disable_irq,
  173. .ack = titan_disable_irq,
  174. .end = titan_end_irq,
  175. .set_affinity = titan_set_irq_affinity,
  176. };
  177. static irqreturn_t
  178. titan_intr_nop(int irq, void *dev_id)
  179. {
  180. /*
  181. * This is a NOP interrupt handler for the purposes of
  182. * event counting -- just return.
  183. */
  184. return IRQ_HANDLED;
  185. }
  186. static void __init
  187. titan_init_irq(void)
  188. {
  189. if (alpha_using_srm && !alpha_mv.device_interrupt)
  190. alpha_mv.device_interrupt = titan_srm_device_interrupt;
  191. if (!alpha_mv.device_interrupt)
  192. alpha_mv.device_interrupt = titan_device_interrupt;
  193. titan_update_irq_hw(0);
  194. init_titan_irqs(&titan_irq_type, 16, 63 + 16);
  195. }
  196. static void __init
  197. titan_legacy_init_irq(void)
  198. {
  199. /* init the legacy dma controller */
  200. outb(0, DMA1_RESET_REG);
  201. outb(0, DMA2_RESET_REG);
  202. outb(DMA_MODE_CASCADE, DMA2_MODE_REG);
  203. outb(0, DMA2_MASK_REG);
  204. /* init the legacy irq controller */
  205. init_i8259a_irqs();
  206. /* init the titan irqs */
  207. titan_init_irq();
  208. }
  209. void
  210. titan_dispatch_irqs(u64 mask)
  211. {
  212. unsigned long vector;
  213. /*
  214. * Mask down to those interrupts which are enable on this processor
  215. */
  216. mask &= titan_cpu_irq_affinity[smp_processor_id()];
  217. /*
  218. * Dispatch all requested interrupts
  219. */
  220. while (mask) {
  221. /* convert to SRM vector... priority is <63> -> <0> */
  222. vector = 63 - __kernel_ctlz(mask);
  223. mask &= ~(1UL << vector); /* clear it out */
  224. vector = 0x900 + (vector << 4); /* convert to SRM vector */
  225. /* dispatch it */
  226. alpha_mv.device_interrupt(vector);
  227. }
  228. }
  229. /*
  230. * Titan Family
  231. */
  232. static void __init
  233. titan_request_irq(unsigned int irq, irq_handler_t handler,
  234. unsigned long irqflags, const char *devname,
  235. void *dev_id)
  236. {
  237. int err;
  238. err = request_irq(irq, handler, irqflags, devname, dev_id);
  239. if (err) {
  240. printk("titan_request_irq for IRQ %d returned %d; ignoring\n",
  241. irq, err);
  242. }
  243. }
  244. static void __init
  245. titan_late_init(void)
  246. {
  247. /*
  248. * Enable the system error interrupts. These interrupts are
  249. * all reported to the kernel as machine checks, so the handler
  250. * is a nop so it can be called to count the individual events.
  251. */
  252. titan_request_irq(63+16, titan_intr_nop, IRQF_DISABLED,
  253. "CChip Error", NULL);
  254. titan_request_irq(62+16, titan_intr_nop, IRQF_DISABLED,
  255. "PChip 0 H_Error", NULL);
  256. titan_request_irq(61+16, titan_intr_nop, IRQF_DISABLED,
  257. "PChip 1 H_Error", NULL);
  258. titan_request_irq(60+16, titan_intr_nop, IRQF_DISABLED,
  259. "PChip 0 C_Error", NULL);
  260. titan_request_irq(59+16, titan_intr_nop, IRQF_DISABLED,
  261. "PChip 1 C_Error", NULL);
  262. /*
  263. * Register our error handlers.
  264. */
  265. titan_register_error_handlers();
  266. /*
  267. * Check if the console left us any error logs.
  268. */
  269. cdl_check_console_data_log();
  270. }
  271. static int __devinit
  272. titan_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  273. {
  274. u8 intline;
  275. int irq;
  276. /* Get the current intline. */
  277. pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &intline);
  278. irq = intline;
  279. /* Is it explicitly routed through ISA? */
  280. if ((irq & 0xF0) == 0xE0)
  281. return irq;
  282. /* Offset by 16 to make room for ISA interrupts 0 - 15. */
  283. return irq + 16;
  284. }
  285. static void __init
  286. titan_init_pci(void)
  287. {
  288. /*
  289. * This isn't really the right place, but there's some init
  290. * that needs to be done after everything is basically up.
  291. */
  292. titan_late_init();
  293. pci_probe_only = 1;
  294. common_init_pci();
  295. SMC669_Init(0);
  296. locate_and_init_vga(NULL);
  297. }
  298. /*
  299. * Privateer
  300. */
  301. static void __init
  302. privateer_init_pci(void)
  303. {
  304. /*
  305. * Hook a couple of extra err interrupts that the
  306. * common titan code won't.
  307. */
  308. titan_request_irq(53+16, titan_intr_nop, IRQF_DISABLED,
  309. "NMI", NULL);
  310. titan_request_irq(50+16, titan_intr_nop, IRQF_DISABLED,
  311. "Temperature Warning", NULL);
  312. /*
  313. * Finish with the common version.
  314. */
  315. return titan_init_pci();
  316. }
  317. /*
  318. * The System Vectors.
  319. */
  320. struct alpha_machine_vector titan_mv __initmv = {
  321. .vector_name = "TITAN",
  322. DO_EV6_MMU,
  323. DO_DEFAULT_RTC,
  324. DO_TITAN_IO,
  325. .machine_check = titan_machine_check,
  326. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  327. .min_io_address = DEFAULT_IO_BASE,
  328. .min_mem_address = DEFAULT_MEM_BASE,
  329. .pci_dac_offset = TITAN_DAC_OFFSET,
  330. .nr_irqs = 80, /* 64 + 16 */
  331. /* device_interrupt will be filled in by titan_init_irq */
  332. .agp_info = titan_agp_info,
  333. .init_arch = titan_init_arch,
  334. .init_irq = titan_legacy_init_irq,
  335. .init_rtc = common_init_rtc,
  336. .init_pci = titan_init_pci,
  337. .kill_arch = titan_kill_arch,
  338. .pci_map_irq = titan_map_irq,
  339. .pci_swizzle = common_swizzle,
  340. };
  341. ALIAS_MV(titan)
  342. struct alpha_machine_vector privateer_mv __initmv = {
  343. .vector_name = "PRIVATEER",
  344. DO_EV6_MMU,
  345. DO_DEFAULT_RTC,
  346. DO_TITAN_IO,
  347. .machine_check = privateer_machine_check,
  348. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  349. .min_io_address = DEFAULT_IO_BASE,
  350. .min_mem_address = DEFAULT_MEM_BASE,
  351. .pci_dac_offset = TITAN_DAC_OFFSET,
  352. .nr_irqs = 80, /* 64 + 16 */
  353. /* device_interrupt will be filled in by titan_init_irq */
  354. .agp_info = titan_agp_info,
  355. .init_arch = titan_init_arch,
  356. .init_irq = titan_legacy_init_irq,
  357. .init_rtc = common_init_rtc,
  358. .init_pci = privateer_init_pci,
  359. .kill_arch = titan_kill_arch,
  360. .pci_map_irq = titan_map_irq,
  361. .pci_swizzle = common_swizzle,
  362. };
  363. /* No alpha_mv alias for privateer since we compile it
  364. in unconditionally with titan; setup_arch knows how to cope. */