core_tsunami.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /*
  2. * linux/arch/alpha/kernel/core_tsunami.c
  3. *
  4. * Based on code written by David A. Rusling (david.rusling@reo.mts.dec.com).
  5. *
  6. * Code common to all TSUNAMI core logic chips.
  7. */
  8. #define __EXTERN_INLINE inline
  9. #include <asm/io.h>
  10. #include <asm/core_tsunami.h>
  11. #undef __EXTERN_INLINE
  12. #include <linux/module.h>
  13. #include <linux/types.h>
  14. #include <linux/pci.h>
  15. #include <linux/sched.h>
  16. #include <linux/init.h>
  17. #include <linux/bootmem.h>
  18. #include <asm/ptrace.h>
  19. #include <asm/smp.h>
  20. #include <asm/vga.h>
  21. #include "proto.h"
  22. #include "pci_impl.h"
  23. /* Save Tsunami configuration data as the console had it set up. */
  24. struct
  25. {
  26. unsigned long wsba[4];
  27. unsigned long wsm[4];
  28. unsigned long tba[4];
  29. } saved_config[2] __attribute__((common));
  30. /*
  31. * NOTE: Herein lie back-to-back mb instructions. They are magic.
  32. * One plausible explanation is that the I/O controller does not properly
  33. * handle the system transaction. Another involves timing. Ho hum.
  34. */
  35. /*
  36. * BIOS32-style PCI interface:
  37. */
  38. #define DEBUG_CONFIG 0
  39. #if DEBUG_CONFIG
  40. # define DBG_CFG(args) printk args
  41. #else
  42. # define DBG_CFG(args)
  43. #endif
  44. /*
  45. * Given a bus, device, and function number, compute resulting
  46. * configuration space address
  47. * accordingly. It is therefore not safe to have concurrent
  48. * invocations to configuration space access routines, but there
  49. * really shouldn't be any need for this.
  50. *
  51. * Note that all config space accesses use Type 1 address format.
  52. *
  53. * Note also that type 1 is determined by non-zero bus number.
  54. *
  55. * Type 1:
  56. *
  57. * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
  58. * 3 2|1 0 9 8|7 6 5 4|3 2 1 0|9 8 7 6|5 4 3 2|1 0 9 8|7 6 5 4|3 2 1 0
  59. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  60. * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
  61. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  62. *
  63. * 31:24 reserved
  64. * 23:16 bus number (8 bits = 128 possible buses)
  65. * 15:11 Device number (5 bits)
  66. * 10:8 function number
  67. * 7:2 register number
  68. *
  69. * Notes:
  70. * The function number selects which function of a multi-function device
  71. * (e.g., SCSI and Ethernet).
  72. *
  73. * The register selects a DWORD (32 bit) register offset. Hence it
  74. * doesn't get shifted by 2 bits as we want to "drop" the bottom two
  75. * bits.
  76. */
  77. static int
  78. mk_conf_addr(struct pci_bus *pbus, unsigned int device_fn, int where,
  79. unsigned long *pci_addr, unsigned char *type1)
  80. {
  81. struct pci_controller *hose = pbus->sysdata;
  82. unsigned long addr;
  83. u8 bus = pbus->number;
  84. DBG_CFG(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x, "
  85. "pci_addr=0x%p, type1=0x%p)\n",
  86. bus, device_fn, where, pci_addr, type1));
  87. if (!pbus->parent) /* No parent means peer PCI bus. */
  88. bus = 0;
  89. *type1 = (bus != 0);
  90. addr = (bus << 16) | (device_fn << 8) | where;
  91. addr |= hose->config_space_base;
  92. *pci_addr = addr;
  93. DBG_CFG(("mk_conf_addr: returning pci_addr 0x%lx\n", addr));
  94. return 0;
  95. }
  96. static int
  97. tsunami_read_config(struct pci_bus *bus, unsigned int devfn, int where,
  98. int size, u32 *value)
  99. {
  100. unsigned long addr;
  101. unsigned char type1;
  102. if (mk_conf_addr(bus, devfn, where, &addr, &type1))
  103. return PCIBIOS_DEVICE_NOT_FOUND;
  104. switch (size) {
  105. case 1:
  106. *value = __kernel_ldbu(*(vucp)addr);
  107. break;
  108. case 2:
  109. *value = __kernel_ldwu(*(vusp)addr);
  110. break;
  111. case 4:
  112. *value = *(vuip)addr;
  113. break;
  114. }
  115. return PCIBIOS_SUCCESSFUL;
  116. }
  117. static int
  118. tsunami_write_config(struct pci_bus *bus, unsigned int devfn, int where,
  119. int size, u32 value)
  120. {
  121. unsigned long addr;
  122. unsigned char type1;
  123. if (mk_conf_addr(bus, devfn, where, &addr, &type1))
  124. return PCIBIOS_DEVICE_NOT_FOUND;
  125. switch (size) {
  126. case 1:
  127. __kernel_stb(value, *(vucp)addr);
  128. mb();
  129. __kernel_ldbu(*(vucp)addr);
  130. break;
  131. case 2:
  132. __kernel_stw(value, *(vusp)addr);
  133. mb();
  134. __kernel_ldwu(*(vusp)addr);
  135. break;
  136. case 4:
  137. *(vuip)addr = value;
  138. mb();
  139. *(vuip)addr;
  140. break;
  141. }
  142. return PCIBIOS_SUCCESSFUL;
  143. }
  144. struct pci_ops tsunami_pci_ops =
  145. {
  146. .read = tsunami_read_config,
  147. .write = tsunami_write_config,
  148. };
  149. void
  150. tsunami_pci_tbi(struct pci_controller *hose, dma_addr_t start, dma_addr_t end)
  151. {
  152. tsunami_pchip *pchip = hose->index ? TSUNAMI_pchip1 : TSUNAMI_pchip0;
  153. volatile unsigned long *csr;
  154. unsigned long value;
  155. /* We can invalidate up to 8 tlb entries in a go. The flush
  156. matches against <31:16> in the pci address. */
  157. csr = &pchip->tlbia.csr;
  158. if (((start ^ end) & 0xffff0000) == 0)
  159. csr = &pchip->tlbiv.csr;
  160. /* For TBIA, it doesn't matter what value we write. For TBI,
  161. it's the shifted tag bits. */
  162. value = (start & 0xffff0000) >> 12;
  163. *csr = value;
  164. mb();
  165. *csr;
  166. }
  167. #ifdef NXM_MACHINE_CHECKS_ON_TSUNAMI
  168. static long __init
  169. tsunami_probe_read(volatile unsigned long *vaddr)
  170. {
  171. long dont_care, probe_result;
  172. int cpu = smp_processor_id();
  173. int s = swpipl(IPL_MCHECK - 1);
  174. mcheck_taken(cpu) = 0;
  175. mcheck_expected(cpu) = 1;
  176. mb();
  177. dont_care = *vaddr;
  178. draina();
  179. mcheck_expected(cpu) = 0;
  180. probe_result = !mcheck_taken(cpu);
  181. mcheck_taken(cpu) = 0;
  182. setipl(s);
  183. printk("dont_care == 0x%lx\n", dont_care);
  184. return probe_result;
  185. }
  186. static long __init
  187. tsunami_probe_write(volatile unsigned long *vaddr)
  188. {
  189. long true_contents, probe_result = 1;
  190. TSUNAMI_cchip->misc.csr |= (1L << 28); /* clear NXM... */
  191. true_contents = *vaddr;
  192. *vaddr = 0;
  193. draina();
  194. if (TSUNAMI_cchip->misc.csr & (1L << 28)) {
  195. int source = (TSUNAMI_cchip->misc.csr >> 29) & 7;
  196. TSUNAMI_cchip->misc.csr |= (1L << 28); /* ...and unlock NXS. */
  197. probe_result = 0;
  198. printk("tsunami_probe_write: unit %d at 0x%016lx\n", source,
  199. (unsigned long)vaddr);
  200. }
  201. if (probe_result)
  202. *vaddr = true_contents;
  203. return probe_result;
  204. }
  205. #else
  206. #define tsunami_probe_read(ADDR) 1
  207. #endif /* NXM_MACHINE_CHECKS_ON_TSUNAMI */
  208. static void __init
  209. tsunami_init_one_pchip(tsunami_pchip *pchip, int index)
  210. {
  211. struct pci_controller *hose;
  212. if (tsunami_probe_read(&pchip->pctl.csr) == 0)
  213. return;
  214. hose = alloc_pci_controller();
  215. if (index == 0)
  216. pci_isa_hose = hose;
  217. hose->io_space = alloc_resource();
  218. hose->mem_space = alloc_resource();
  219. /* This is for userland consumption. For some reason, the 40-bit
  220. PIO bias that we use in the kernel through KSEG didn't work for
  221. the page table based user mappings. So make sure we get the
  222. 43-bit PIO bias. */
  223. hose->sparse_mem_base = 0;
  224. hose->sparse_io_base = 0;
  225. hose->dense_mem_base
  226. = (TSUNAMI_MEM(index) & 0xffffffffffL) | 0x80000000000L;
  227. hose->dense_io_base
  228. = (TSUNAMI_IO(index) & 0xffffffffffL) | 0x80000000000L;
  229. hose->config_space_base = TSUNAMI_CONF(index);
  230. hose->index = index;
  231. hose->io_space->start = TSUNAMI_IO(index) - TSUNAMI_IO_BIAS;
  232. hose->io_space->end = hose->io_space->start + TSUNAMI_IO_SPACE - 1;
  233. hose->io_space->name = pci_io_names[index];
  234. hose->io_space->flags = IORESOURCE_IO;
  235. hose->mem_space->start = TSUNAMI_MEM(index) - TSUNAMI_MEM_BIAS;
  236. hose->mem_space->end = hose->mem_space->start + 0xffffffff;
  237. hose->mem_space->name = pci_mem_names[index];
  238. hose->mem_space->flags = IORESOURCE_MEM;
  239. if (request_resource(&ioport_resource, hose->io_space) < 0)
  240. printk(KERN_ERR "Failed to request IO on hose %d\n", index);
  241. if (request_resource(&iomem_resource, hose->mem_space) < 0)
  242. printk(KERN_ERR "Failed to request MEM on hose %d\n", index);
  243. /*
  244. * Save the existing PCI window translations. SRM will
  245. * need them when we go to reboot.
  246. */
  247. saved_config[index].wsba[0] = pchip->wsba[0].csr;
  248. saved_config[index].wsm[0] = pchip->wsm[0].csr;
  249. saved_config[index].tba[0] = pchip->tba[0].csr;
  250. saved_config[index].wsba[1] = pchip->wsba[1].csr;
  251. saved_config[index].wsm[1] = pchip->wsm[1].csr;
  252. saved_config[index].tba[1] = pchip->tba[1].csr;
  253. saved_config[index].wsba[2] = pchip->wsba[2].csr;
  254. saved_config[index].wsm[2] = pchip->wsm[2].csr;
  255. saved_config[index].tba[2] = pchip->tba[2].csr;
  256. saved_config[index].wsba[3] = pchip->wsba[3].csr;
  257. saved_config[index].wsm[3] = pchip->wsm[3].csr;
  258. saved_config[index].tba[3] = pchip->tba[3].csr;
  259. /*
  260. * Set up the PCI to main memory translation windows.
  261. *
  262. * Note: Window 3 is scatter-gather only
  263. *
  264. * Window 0 is scatter-gather 8MB at 8MB (for isa)
  265. * Window 1 is scatter-gather (up to) 1GB at 1GB
  266. * Window 2 is direct access 2GB at 2GB
  267. *
  268. * NOTE: we need the align_entry settings for Acer devices on ES40,
  269. * specifically floppy and IDE when memory is larger than 2GB.
  270. */
  271. hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
  272. /* Initially set for 4 PTEs, but will be overridden to 64K for ISA. */
  273. hose->sg_isa->align_entry = 4;
  274. hose->sg_pci = iommu_arena_new(hose, 0x40000000,
  275. size_for_memory(0x40000000), 0);
  276. hose->sg_pci->align_entry = 4; /* Tsunami caches 4 PTEs at a time */
  277. __direct_map_base = 0x80000000;
  278. __direct_map_size = 0x80000000;
  279. pchip->wsba[0].csr = hose->sg_isa->dma_base | 3;
  280. pchip->wsm[0].csr = (hose->sg_isa->size - 1) & 0xfff00000;
  281. pchip->tba[0].csr = virt_to_phys(hose->sg_isa->ptes);
  282. pchip->wsba[1].csr = hose->sg_pci->dma_base | 3;
  283. pchip->wsm[1].csr = (hose->sg_pci->size - 1) & 0xfff00000;
  284. pchip->tba[1].csr = virt_to_phys(hose->sg_pci->ptes);
  285. pchip->wsba[2].csr = 0x80000000 | 1;
  286. pchip->wsm[2].csr = (0x80000000 - 1) & 0xfff00000;
  287. pchip->tba[2].csr = 0;
  288. pchip->wsba[3].csr = 0;
  289. /* Enable the Monster Window to make DAC pci64 possible. */
  290. pchip->pctl.csr |= pctl_m_mwin;
  291. tsunami_pci_tbi(hose, 0, -1);
  292. }
  293. void __iomem *
  294. tsunami_ioportmap(unsigned long addr)
  295. {
  296. FIXUP_IOADDR_VGA(addr);
  297. return (void __iomem *)(addr + TSUNAMI_IO_BIAS);
  298. }
  299. void __iomem *
  300. tsunami_ioremap(unsigned long addr, unsigned long size)
  301. {
  302. FIXUP_MEMADDR_VGA(addr);
  303. return (void __iomem *)(addr + TSUNAMI_MEM_BIAS);
  304. }
  305. #ifndef CONFIG_ALPHA_GENERIC
  306. EXPORT_SYMBOL(tsunami_ioportmap);
  307. EXPORT_SYMBOL(tsunami_ioremap);
  308. #endif
  309. void __init
  310. tsunami_init_arch(void)
  311. {
  312. #ifdef NXM_MACHINE_CHECKS_ON_TSUNAMI
  313. unsigned long tmp;
  314. /* Ho hum.. init_arch is called before init_IRQ, but we need to be
  315. able to handle machine checks. So install the handler now. */
  316. wrent(entInt, 0);
  317. /* NXMs just don't matter to Tsunami--unless they make it
  318. choke completely. */
  319. tmp = (unsigned long)(TSUNAMI_cchip - 1);
  320. printk("%s: probing bogus address: 0x%016lx\n", __func__, bogus_addr);
  321. printk("\tprobe %s\n",
  322. tsunami_probe_write((unsigned long *)bogus_addr)
  323. ? "succeeded" : "failed");
  324. #endif /* NXM_MACHINE_CHECKS_ON_TSUNAMI */
  325. #if 0
  326. printk("%s: CChip registers:\n", __func__);
  327. printk("%s: CSR_CSC 0x%lx\n", __func__, TSUNAMI_cchip->csc.csr);
  328. printk("%s: CSR_MTR 0x%lx\n", __func__, TSUNAMI_cchip.mtr.csr);
  329. printk("%s: CSR_MISC 0x%lx\n", __func__, TSUNAMI_cchip->misc.csr);
  330. printk("%s: CSR_DIM0 0x%lx\n", __func__, TSUNAMI_cchip->dim0.csr);
  331. printk("%s: CSR_DIM1 0x%lx\n", __func__, TSUNAMI_cchip->dim1.csr);
  332. printk("%s: CSR_DIR0 0x%lx\n", __func__, TSUNAMI_cchip->dir0.csr);
  333. printk("%s: CSR_DIR1 0x%lx\n", __func__, TSUNAMI_cchip->dir1.csr);
  334. printk("%s: CSR_DRIR 0x%lx\n", __func__, TSUNAMI_cchip->drir.csr);
  335. printk("%s: DChip registers:\n");
  336. printk("%s: CSR_DSC 0x%lx\n", __func__, TSUNAMI_dchip->dsc.csr);
  337. printk("%s: CSR_STR 0x%lx\n", __func__, TSUNAMI_dchip->str.csr);
  338. printk("%s: CSR_DREV 0x%lx\n", __func__, TSUNAMI_dchip->drev.csr);
  339. #endif
  340. /* With multiple PCI busses, we play with I/O as physical addrs. */
  341. ioport_resource.end = ~0UL;
  342. /* Find how many hoses we have, and initialize them. TSUNAMI
  343. and TYPHOON can have 2, but might only have 1 (DS10). */
  344. tsunami_init_one_pchip(TSUNAMI_pchip0, 0);
  345. if (TSUNAMI_cchip->csc.csr & 1L<<14)
  346. tsunami_init_one_pchip(TSUNAMI_pchip1, 1);
  347. /* Check for graphic console location (if any). */
  348. find_console_vga_hose();
  349. }
  350. static void
  351. tsunami_kill_one_pchip(tsunami_pchip *pchip, int index)
  352. {
  353. pchip->wsba[0].csr = saved_config[index].wsba[0];
  354. pchip->wsm[0].csr = saved_config[index].wsm[0];
  355. pchip->tba[0].csr = saved_config[index].tba[0];
  356. pchip->wsba[1].csr = saved_config[index].wsba[1];
  357. pchip->wsm[1].csr = saved_config[index].wsm[1];
  358. pchip->tba[1].csr = saved_config[index].tba[1];
  359. pchip->wsba[2].csr = saved_config[index].wsba[2];
  360. pchip->wsm[2].csr = saved_config[index].wsm[2];
  361. pchip->tba[2].csr = saved_config[index].tba[2];
  362. pchip->wsba[3].csr = saved_config[index].wsba[3];
  363. pchip->wsm[3].csr = saved_config[index].wsm[3];
  364. pchip->tba[3].csr = saved_config[index].tba[3];
  365. }
  366. void
  367. tsunami_kill_arch(int mode)
  368. {
  369. tsunami_kill_one_pchip(TSUNAMI_pchip0, 0);
  370. if (TSUNAMI_cchip->csc.csr & 1L<<14)
  371. tsunami_kill_one_pchip(TSUNAMI_pchip1, 1);
  372. }
  373. static inline void
  374. tsunami_pci_clr_err_1(tsunami_pchip *pchip)
  375. {
  376. pchip->perror.csr;
  377. pchip->perror.csr = 0x040;
  378. mb();
  379. pchip->perror.csr;
  380. }
  381. static inline void
  382. tsunami_pci_clr_err(void)
  383. {
  384. tsunami_pci_clr_err_1(TSUNAMI_pchip0);
  385. /* TSUNAMI and TYPHOON can have 2, but might only have 1 (DS10) */
  386. if (TSUNAMI_cchip->csc.csr & 1L<<14)
  387. tsunami_pci_clr_err_1(TSUNAMI_pchip1);
  388. }
  389. void
  390. tsunami_machine_check(unsigned long vector, unsigned long la_ptr)
  391. {
  392. /* Clear error before any reporting. */
  393. mb();
  394. mb(); /* magic */
  395. draina();
  396. tsunami_pci_clr_err();
  397. wrmces(0x7);
  398. mb();
  399. process_mcheck_info(vector, la_ptr, "TSUNAMI",
  400. mcheck_expected(smp_processor_id()));
  401. }