core_tsunami.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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 "proto.h"
  20. #include "pci_impl.h"
  21. /* Save Tsunami configuration data as the console had it set up. */
  22. struct
  23. {
  24. unsigned long wsba[4];
  25. unsigned long wsm[4];
  26. unsigned long tba[4];
  27. } saved_config[2] __attribute__((common));
  28. /*
  29. * NOTE: Herein lie back-to-back mb instructions. They are magic.
  30. * One plausible explanation is that the I/O controller does not properly
  31. * handle the system transaction. Another involves timing. Ho hum.
  32. */
  33. /*
  34. * BIOS32-style PCI interface:
  35. */
  36. #define DEBUG_CONFIG 0
  37. #if DEBUG_CONFIG
  38. # define DBG_CFG(args) printk args
  39. #else
  40. # define DBG_CFG(args)
  41. #endif
  42. /*
  43. * Given a bus, device, and function number, compute resulting
  44. * configuration space address
  45. * accordingly. It is therefore not safe to have concurrent
  46. * invocations to configuration space access routines, but there
  47. * really shouldn't be any need for this.
  48. *
  49. * Note that all config space accesses use Type 1 address format.
  50. *
  51. * Note also that type 1 is determined by non-zero bus number.
  52. *
  53. * Type 1:
  54. *
  55. * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
  56. * 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
  57. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  58. * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
  59. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  60. *
  61. * 31:24 reserved
  62. * 23:16 bus number (8 bits = 128 possible buses)
  63. * 15:11 Device number (5 bits)
  64. * 10:8 function number
  65. * 7:2 register number
  66. *
  67. * Notes:
  68. * The function number selects which function of a multi-function device
  69. * (e.g., SCSI and Ethernet).
  70. *
  71. * The register selects a DWORD (32 bit) register offset. Hence it
  72. * doesn't get shifted by 2 bits as we want to "drop" the bottom two
  73. * bits.
  74. */
  75. static int
  76. mk_conf_addr(struct pci_bus *pbus, unsigned int device_fn, int where,
  77. unsigned long *pci_addr, unsigned char *type1)
  78. {
  79. struct pci_controller *hose = pbus->sysdata;
  80. unsigned long addr;
  81. u8 bus = pbus->number;
  82. DBG_CFG(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x, "
  83. "pci_addr=0x%p, type1=0x%p)\n",
  84. bus, device_fn, where, pci_addr, type1));
  85. if (!pbus->parent) /* No parent means peer PCI bus. */
  86. bus = 0;
  87. *type1 = (bus != 0);
  88. addr = (bus << 16) | (device_fn << 8) | where;
  89. addr |= hose->config_space_base;
  90. *pci_addr = addr;
  91. DBG_CFG(("mk_conf_addr: returning pci_addr 0x%lx\n", addr));
  92. return 0;
  93. }
  94. static int
  95. tsunami_read_config(struct pci_bus *bus, unsigned int devfn, int where,
  96. int size, u32 *value)
  97. {
  98. unsigned long addr;
  99. unsigned char type1;
  100. if (mk_conf_addr(bus, devfn, where, &addr, &type1))
  101. return PCIBIOS_DEVICE_NOT_FOUND;
  102. switch (size) {
  103. case 1:
  104. *value = __kernel_ldbu(*(vucp)addr);
  105. break;
  106. case 2:
  107. *value = __kernel_ldwu(*(vusp)addr);
  108. break;
  109. case 4:
  110. *value = *(vuip)addr;
  111. break;
  112. }
  113. return PCIBIOS_SUCCESSFUL;
  114. }
  115. static int
  116. tsunami_write_config(struct pci_bus *bus, unsigned int devfn, int where,
  117. int size, u32 value)
  118. {
  119. unsigned long addr;
  120. unsigned char type1;
  121. if (mk_conf_addr(bus, devfn, where, &addr, &type1))
  122. return PCIBIOS_DEVICE_NOT_FOUND;
  123. switch (size) {
  124. case 1:
  125. __kernel_stb(value, *(vucp)addr);
  126. mb();
  127. __kernel_ldbu(*(vucp)addr);
  128. break;
  129. case 2:
  130. __kernel_stw(value, *(vusp)addr);
  131. mb();
  132. __kernel_ldwu(*(vusp)addr);
  133. break;
  134. case 4:
  135. *(vuip)addr = value;
  136. mb();
  137. *(vuip)addr;
  138. break;
  139. }
  140. return PCIBIOS_SUCCESSFUL;
  141. }
  142. struct pci_ops tsunami_pci_ops =
  143. {
  144. .read = tsunami_read_config,
  145. .write = tsunami_write_config,
  146. };
  147. void
  148. tsunami_pci_tbi(struct pci_controller *hose, dma_addr_t start, dma_addr_t end)
  149. {
  150. tsunami_pchip *pchip = hose->index ? TSUNAMI_pchip1 : TSUNAMI_pchip0;
  151. volatile unsigned long *csr;
  152. unsigned long value;
  153. /* We can invalidate up to 8 tlb entries in a go. The flush
  154. matches against <31:16> in the pci address. */
  155. csr = &pchip->tlbia.csr;
  156. if (((start ^ end) & 0xffff0000) == 0)
  157. csr = &pchip->tlbiv.csr;
  158. /* For TBIA, it doesn't matter what value we write. For TBI,
  159. it's the shifted tag bits. */
  160. value = (start & 0xffff0000) >> 12;
  161. *csr = value;
  162. mb();
  163. *csr;
  164. }
  165. #ifdef NXM_MACHINE_CHECKS_ON_TSUNAMI
  166. static long __init
  167. tsunami_probe_read(volatile unsigned long *vaddr)
  168. {
  169. long dont_care, probe_result;
  170. int cpu = smp_processor_id();
  171. int s = swpipl(IPL_MCHECK - 1);
  172. mcheck_taken(cpu) = 0;
  173. mcheck_expected(cpu) = 1;
  174. mb();
  175. dont_care = *vaddr;
  176. draina();
  177. mcheck_expected(cpu) = 0;
  178. probe_result = !mcheck_taken(cpu);
  179. mcheck_taken(cpu) = 0;
  180. setipl(s);
  181. printk("dont_care == 0x%lx\n", dont_care);
  182. return probe_result;
  183. }
  184. static long __init
  185. tsunami_probe_write(volatile unsigned long *vaddr)
  186. {
  187. long true_contents, probe_result = 1;
  188. TSUNAMI_cchip->misc.csr |= (1L << 28); /* clear NXM... */
  189. true_contents = *vaddr;
  190. *vaddr = 0;
  191. draina();
  192. if (TSUNAMI_cchip->misc.csr & (1L << 28)) {
  193. int source = (TSUNAMI_cchip->misc.csr >> 29) & 7;
  194. TSUNAMI_cchip->misc.csr |= (1L << 28); /* ...and unlock NXS. */
  195. probe_result = 0;
  196. printk("tsunami_probe_write: unit %d at 0x%016lx\n", source,
  197. (unsigned long)vaddr);
  198. }
  199. if (probe_result)
  200. *vaddr = true_contents;
  201. return probe_result;
  202. }
  203. #else
  204. #define tsunami_probe_read(ADDR) 1
  205. #endif /* NXM_MACHINE_CHECKS_ON_TSUNAMI */
  206. #define FN __FUNCTION__
  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 __init
  293. tsunami_init_arch(void)
  294. {
  295. #ifdef NXM_MACHINE_CHECKS_ON_TSUNAMI
  296. unsigned long tmp;
  297. /* Ho hum.. init_arch is called before init_IRQ, but we need to be
  298. able to handle machine checks. So install the handler now. */
  299. wrent(entInt, 0);
  300. /* NXMs just don't matter to Tsunami--unless they make it
  301. choke completely. */
  302. tmp = (unsigned long)(TSUNAMI_cchip - 1);
  303. printk("%s: probing bogus address: 0x%016lx\n", FN, bogus_addr);
  304. printk("\tprobe %s\n",
  305. tsunami_probe_write((unsigned long *)bogus_addr)
  306. ? "succeeded" : "failed");
  307. #endif /* NXM_MACHINE_CHECKS_ON_TSUNAMI */
  308. #if 0
  309. printk("%s: CChip registers:\n", FN);
  310. printk("%s: CSR_CSC 0x%lx\n", FN, TSUNAMI_cchip->csc.csr);
  311. printk("%s: CSR_MTR 0x%lx\n", FN, TSUNAMI_cchip.mtr.csr);
  312. printk("%s: CSR_MISC 0x%lx\n", FN, TSUNAMI_cchip->misc.csr);
  313. printk("%s: CSR_DIM0 0x%lx\n", FN, TSUNAMI_cchip->dim0.csr);
  314. printk("%s: CSR_DIM1 0x%lx\n", FN, TSUNAMI_cchip->dim1.csr);
  315. printk("%s: CSR_DIR0 0x%lx\n", FN, TSUNAMI_cchip->dir0.csr);
  316. printk("%s: CSR_DIR1 0x%lx\n", FN, TSUNAMI_cchip->dir1.csr);
  317. printk("%s: CSR_DRIR 0x%lx\n", FN, TSUNAMI_cchip->drir.csr);
  318. printk("%s: DChip registers:\n");
  319. printk("%s: CSR_DSC 0x%lx\n", FN, TSUNAMI_dchip->dsc.csr);
  320. printk("%s: CSR_STR 0x%lx\n", FN, TSUNAMI_dchip->str.csr);
  321. printk("%s: CSR_DREV 0x%lx\n", FN, TSUNAMI_dchip->drev.csr);
  322. #endif
  323. /* With multiple PCI busses, we play with I/O as physical addrs. */
  324. ioport_resource.end = ~0UL;
  325. /* Find how many hoses we have, and initialize them. TSUNAMI
  326. and TYPHOON can have 2, but might only have 1 (DS10). */
  327. tsunami_init_one_pchip(TSUNAMI_pchip0, 0);
  328. if (TSUNAMI_cchip->csc.csr & 1L<<14)
  329. tsunami_init_one_pchip(TSUNAMI_pchip1, 1);
  330. }
  331. static void
  332. tsunami_kill_one_pchip(tsunami_pchip *pchip, int index)
  333. {
  334. pchip->wsba[0].csr = saved_config[index].wsba[0];
  335. pchip->wsm[0].csr = saved_config[index].wsm[0];
  336. pchip->tba[0].csr = saved_config[index].tba[0];
  337. pchip->wsba[1].csr = saved_config[index].wsba[1];
  338. pchip->wsm[1].csr = saved_config[index].wsm[1];
  339. pchip->tba[1].csr = saved_config[index].tba[1];
  340. pchip->wsba[2].csr = saved_config[index].wsba[2];
  341. pchip->wsm[2].csr = saved_config[index].wsm[2];
  342. pchip->tba[2].csr = saved_config[index].tba[2];
  343. pchip->wsba[3].csr = saved_config[index].wsba[3];
  344. pchip->wsm[3].csr = saved_config[index].wsm[3];
  345. pchip->tba[3].csr = saved_config[index].tba[3];
  346. }
  347. void
  348. tsunami_kill_arch(int mode)
  349. {
  350. tsunami_kill_one_pchip(TSUNAMI_pchip0, 0);
  351. if (TSUNAMI_cchip->csc.csr & 1L<<14)
  352. tsunami_kill_one_pchip(TSUNAMI_pchip1, 1);
  353. }
  354. static inline void
  355. tsunami_pci_clr_err_1(tsunami_pchip *pchip)
  356. {
  357. pchip->perror.csr;
  358. pchip->perror.csr = 0x040;
  359. mb();
  360. pchip->perror.csr;
  361. }
  362. static inline void
  363. tsunami_pci_clr_err(void)
  364. {
  365. tsunami_pci_clr_err_1(TSUNAMI_pchip0);
  366. /* TSUNAMI and TYPHOON can have 2, but might only have 1 (DS10) */
  367. if (TSUNAMI_cchip->csc.csr & 1L<<14)
  368. tsunami_pci_clr_err_1(TSUNAMI_pchip1);
  369. }
  370. void
  371. tsunami_machine_check(unsigned long vector, unsigned long la_ptr,
  372. struct pt_regs * regs)
  373. {
  374. /* Clear error before any reporting. */
  375. mb();
  376. mb(); /* magic */
  377. draina();
  378. tsunami_pci_clr_err();
  379. wrmces(0x7);
  380. mb();
  381. process_mcheck_info(vector, la_ptr, regs, "TSUNAMI",
  382. mcheck_expected(smp_processor_id()));
  383. }