sys_titan.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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;
  59. volatile unsigned long *dim0, *dim1, *dim2, *dim3;
  60. unsigned long mask0, mask1, mask2, mask3, dummy;
  61. cpumask_copy(&cpm, cpu_present_mask);
  62. mask &= ~isa_enable;
  63. mask0 = mask & titan_cpu_irq_affinity[0];
  64. mask1 = mask & titan_cpu_irq_affinity[1];
  65. mask2 = mask & titan_cpu_irq_affinity[2];
  66. mask3 = mask & titan_cpu_irq_affinity[3];
  67. if (bcpu == 0) mask0 |= isa_enable;
  68. else if (bcpu == 1) mask1 |= isa_enable;
  69. else if (bcpu == 2) mask2 |= isa_enable;
  70. else mask3 |= isa_enable;
  71. dim0 = &cchip->dim0.csr;
  72. dim1 = &cchip->dim1.csr;
  73. dim2 = &cchip->dim2.csr;
  74. dim3 = &cchip->dim3.csr;
  75. if (!cpumask_test_cpu(0, &cpm)) dim0 = &dummy;
  76. if (!cpumask_test_cpu(1, &cpm)) dim1 = &dummy;
  77. if (!cpumask_test_cpu(2, &cpm)) dim2 = &dummy;
  78. if (!cpumask_test_cpu(3, &cpm)) dim3 = &dummy;
  79. *dim0 = mask0;
  80. *dim1 = mask1;
  81. *dim2 = mask2;
  82. *dim3 = mask3;
  83. mb();
  84. *dim0;
  85. *dim1;
  86. *dim2;
  87. *dim3;
  88. #else
  89. volatile unsigned long *dimB;
  90. dimB = &cchip->dim0.csr;
  91. if (bcpu == 1) dimB = &cchip->dim1.csr;
  92. else if (bcpu == 2) dimB = &cchip->dim2.csr;
  93. else if (bcpu == 3) dimB = &cchip->dim3.csr;
  94. *dimB = mask | isa_enable;
  95. mb();
  96. *dimB;
  97. #endif
  98. }
  99. static inline void
  100. titan_enable_irq(struct irq_data *d)
  101. {
  102. unsigned int irq = d->irq;
  103. spin_lock(&titan_irq_lock);
  104. titan_cached_irq_mask |= 1UL << (irq - 16);
  105. titan_update_irq_hw(titan_cached_irq_mask);
  106. spin_unlock(&titan_irq_lock);
  107. }
  108. static inline void
  109. titan_disable_irq(struct irq_data *d)
  110. {
  111. unsigned int irq = d->irq;
  112. spin_lock(&titan_irq_lock);
  113. titan_cached_irq_mask &= ~(1UL << (irq - 16));
  114. titan_update_irq_hw(titan_cached_irq_mask);
  115. spin_unlock(&titan_irq_lock);
  116. }
  117. static void
  118. titan_cpu_set_irq_affinity(unsigned int irq, cpumask_t affinity)
  119. {
  120. int cpu;
  121. for (cpu = 0; cpu < 4; cpu++) {
  122. if (cpumask_test_cpu(cpu, &affinity))
  123. titan_cpu_irq_affinity[cpu] |= 1UL << irq;
  124. else
  125. titan_cpu_irq_affinity[cpu] &= ~(1UL << irq);
  126. }
  127. }
  128. static int
  129. titan_set_irq_affinity(struct irq_data *d, const struct cpumask *affinity,
  130. bool force)
  131. {
  132. unsigned int irq = d->irq;
  133. spin_lock(&titan_irq_lock);
  134. titan_cpu_set_irq_affinity(irq - 16, *affinity);
  135. titan_update_irq_hw(titan_cached_irq_mask);
  136. spin_unlock(&titan_irq_lock);
  137. return 0;
  138. }
  139. static void
  140. titan_device_interrupt(unsigned long vector)
  141. {
  142. printk("titan_device_interrupt: NOT IMPLEMENTED YET!!\n");
  143. }
  144. static void
  145. titan_srm_device_interrupt(unsigned long vector)
  146. {
  147. int irq;
  148. irq = (vector - 0x800) >> 4;
  149. handle_irq(irq);
  150. }
  151. static void __init
  152. init_titan_irqs(struct irq_chip * ops, int imin, int imax)
  153. {
  154. long i;
  155. for (i = imin; i <= imax; ++i) {
  156. irq_set_chip_and_handler(i, ops, handle_level_irq);
  157. irq_set_status_flags(i, IRQ_LEVEL);
  158. }
  159. }
  160. static struct irq_chip titan_irq_type = {
  161. .name = "TITAN",
  162. .irq_unmask = titan_enable_irq,
  163. .irq_mask = titan_disable_irq,
  164. .irq_mask_ack = titan_disable_irq,
  165. .irq_set_affinity = titan_set_irq_affinity,
  166. };
  167. static irqreturn_t
  168. titan_intr_nop(int irq, void *dev_id)
  169. {
  170. /*
  171. * This is a NOP interrupt handler for the purposes of
  172. * event counting -- just return.
  173. */
  174. return IRQ_HANDLED;
  175. }
  176. static void __init
  177. titan_init_irq(void)
  178. {
  179. if (alpha_using_srm && !alpha_mv.device_interrupt)
  180. alpha_mv.device_interrupt = titan_srm_device_interrupt;
  181. if (!alpha_mv.device_interrupt)
  182. alpha_mv.device_interrupt = titan_device_interrupt;
  183. titan_update_irq_hw(0);
  184. init_titan_irqs(&titan_irq_type, 16, 63 + 16);
  185. }
  186. static void __init
  187. titan_legacy_init_irq(void)
  188. {
  189. /* init the legacy dma controller */
  190. outb(0, DMA1_RESET_REG);
  191. outb(0, DMA2_RESET_REG);
  192. outb(DMA_MODE_CASCADE, DMA2_MODE_REG);
  193. outb(0, DMA2_MASK_REG);
  194. /* init the legacy irq controller */
  195. init_i8259a_irqs();
  196. /* init the titan irqs */
  197. titan_init_irq();
  198. }
  199. void
  200. titan_dispatch_irqs(u64 mask)
  201. {
  202. unsigned long vector;
  203. /*
  204. * Mask down to those interrupts which are enable on this processor
  205. */
  206. mask &= titan_cpu_irq_affinity[smp_processor_id()];
  207. /*
  208. * Dispatch all requested interrupts
  209. */
  210. while (mask) {
  211. /* convert to SRM vector... priority is <63> -> <0> */
  212. vector = 63 - __kernel_ctlz(mask);
  213. mask &= ~(1UL << vector); /* clear it out */
  214. vector = 0x900 + (vector << 4); /* convert to SRM vector */
  215. /* dispatch it */
  216. alpha_mv.device_interrupt(vector);
  217. }
  218. }
  219. /*
  220. * Titan Family
  221. */
  222. static void __init
  223. titan_request_irq(unsigned int irq, irq_handler_t handler,
  224. unsigned long irqflags, const char *devname,
  225. void *dev_id)
  226. {
  227. int err;
  228. err = request_irq(irq, handler, irqflags, devname, dev_id);
  229. if (err) {
  230. printk("titan_request_irq for IRQ %d returned %d; ignoring\n",
  231. irq, err);
  232. }
  233. }
  234. static void __init
  235. titan_late_init(void)
  236. {
  237. /*
  238. * Enable the system error interrupts. These interrupts are
  239. * all reported to the kernel as machine checks, so the handler
  240. * is a nop so it can be called to count the individual events.
  241. */
  242. titan_request_irq(63+16, titan_intr_nop, IRQF_DISABLED,
  243. "CChip Error", NULL);
  244. titan_request_irq(62+16, titan_intr_nop, IRQF_DISABLED,
  245. "PChip 0 H_Error", NULL);
  246. titan_request_irq(61+16, titan_intr_nop, IRQF_DISABLED,
  247. "PChip 1 H_Error", NULL);
  248. titan_request_irq(60+16, titan_intr_nop, IRQF_DISABLED,
  249. "PChip 0 C_Error", NULL);
  250. titan_request_irq(59+16, titan_intr_nop, IRQF_DISABLED,
  251. "PChip 1 C_Error", NULL);
  252. /*
  253. * Register our error handlers.
  254. */
  255. titan_register_error_handlers();
  256. /*
  257. * Check if the console left us any error logs.
  258. */
  259. cdl_check_console_data_log();
  260. }
  261. static int __devinit
  262. titan_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  263. {
  264. u8 intline;
  265. int irq;
  266. /* Get the current intline. */
  267. pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &intline);
  268. irq = intline;
  269. /* Is it explicitly routed through ISA? */
  270. if ((irq & 0xF0) == 0xE0)
  271. return irq;
  272. /* Offset by 16 to make room for ISA interrupts 0 - 15. */
  273. return irq + 16;
  274. }
  275. static void __init
  276. titan_init_pci(void)
  277. {
  278. /*
  279. * This isn't really the right place, but there's some init
  280. * that needs to be done after everything is basically up.
  281. */
  282. titan_late_init();
  283. pci_probe_only = 1;
  284. common_init_pci();
  285. SMC669_Init(0);
  286. locate_and_init_vga(NULL);
  287. }
  288. /*
  289. * Privateer
  290. */
  291. static void __init
  292. privateer_init_pci(void)
  293. {
  294. /*
  295. * Hook a couple of extra err interrupts that the
  296. * common titan code won't.
  297. */
  298. titan_request_irq(53+16, titan_intr_nop, IRQF_DISABLED,
  299. "NMI", NULL);
  300. titan_request_irq(50+16, titan_intr_nop, IRQF_DISABLED,
  301. "Temperature Warning", NULL);
  302. /*
  303. * Finish with the common version.
  304. */
  305. return titan_init_pci();
  306. }
  307. /*
  308. * The System Vectors.
  309. */
  310. struct alpha_machine_vector titan_mv __initmv = {
  311. .vector_name = "TITAN",
  312. DO_EV6_MMU,
  313. DO_DEFAULT_RTC,
  314. DO_TITAN_IO,
  315. .machine_check = titan_machine_check,
  316. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  317. .min_io_address = DEFAULT_IO_BASE,
  318. .min_mem_address = DEFAULT_MEM_BASE,
  319. .pci_dac_offset = TITAN_DAC_OFFSET,
  320. .nr_irqs = 80, /* 64 + 16 */
  321. /* device_interrupt will be filled in by titan_init_irq */
  322. .agp_info = titan_agp_info,
  323. .init_arch = titan_init_arch,
  324. .init_irq = titan_legacy_init_irq,
  325. .init_rtc = common_init_rtc,
  326. .init_pci = titan_init_pci,
  327. .kill_arch = titan_kill_arch,
  328. .pci_map_irq = titan_map_irq,
  329. .pci_swizzle = common_swizzle,
  330. };
  331. ALIAS_MV(titan)
  332. struct alpha_machine_vector privateer_mv __initmv = {
  333. .vector_name = "PRIVATEER",
  334. DO_EV6_MMU,
  335. DO_DEFAULT_RTC,
  336. DO_TITAN_IO,
  337. .machine_check = privateer_machine_check,
  338. .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
  339. .min_io_address = DEFAULT_IO_BASE,
  340. .min_mem_address = DEFAULT_MEM_BASE,
  341. .pci_dac_offset = TITAN_DAC_OFFSET,
  342. .nr_irqs = 80, /* 64 + 16 */
  343. /* device_interrupt will be filled in by titan_init_irq */
  344. .agp_info = titan_agp_info,
  345. .init_arch = titan_init_arch,
  346. .init_irq = titan_legacy_init_irq,
  347. .init_rtc = common_init_rtc,
  348. .init_pci = privateer_init_pci,
  349. .kill_arch = titan_kill_arch,
  350. .pci_map_irq = titan_map_irq,
  351. .pci_swizzle = common_swizzle,
  352. };
  353. /* No alpha_mv alias for privateer since we compile it
  354. in unconditionally with titan; setup_arch knows how to cope. */