core_tsunami.c 13 KB

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