core_titan.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:13k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * linux/arch/alpha/kernel/core_titan.c
  3.  *
  4.  * Code common to all TITAN core logic chips.
  5.  */
  6. #include <linux/config.h>
  7. #include <linux/kernel.h>
  8. #include <linux/types.h>
  9. #include <linux/pci.h>
  10. #include <linux/sched.h>
  11. #include <linux/init.h>
  12. #include <asm/ptrace.h>
  13. #include <asm/system.h>
  14. #include <asm/smp.h>
  15. #define __EXTERN_INLINE inline
  16. #include <asm/io.h>
  17. #include <asm/core_titan.h>
  18. #undef __EXTERN_INLINE
  19. #include <linux/bootmem.h>
  20. #include "proto.h"
  21. #include "pci_impl.h"
  22. unsigned TITAN_agp = 0;
  23. static struct
  24. {
  25. unsigned long wsba[4];
  26. unsigned long wsm[4];
  27. unsigned long tba[4];
  28. } saved_pachip_port[4];
  29. /*
  30.  * BIOS32-style PCI interface:
  31.  */
  32. #define DEBUG_MCHECK 0  /* 0 = minimum, 1 = debug, 2 = dump+dump */
  33. #define DEBUG_CONFIG 0
  34. #if DEBUG_CONFIG
  35. # define DBG_CFG(args) printk args
  36. #else
  37. # define DBG_CFG(args)
  38. #endif
  39. /*
  40.  * Given a bus, device, and function number, compute resulting
  41.  * configuration space address
  42.  * accordingly.  It is therefore not safe to have concurrent
  43.  * invocations to configuration space access routines, but there
  44.  * really shouldn't be any need for this.
  45.  *
  46.  * Note that all config space accesses use Type 1 address format.
  47.  *
  48.  * Note also that type 1 is determined by non-zero bus number.
  49.  *
  50.  * Type 1:
  51.  *
  52.  *  3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1 
  53.  *  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
  54.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  55.  * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
  56.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  57.  *
  58.  * 31:24 reserved
  59.  * 23:16 bus number (8 bits = 128 possible buses)
  60.  * 15:11 Device number (5 bits)
  61.  * 10:8 function number
  62.  *  7:2 register number
  63.  *  
  64.  * Notes:
  65.  * The function number selects which function of a multi-function device 
  66.  * (e.g., SCSI and Ethernet).
  67.  * 
  68.  * The register selects a DWORD (32 bit) register offset.  Hence it
  69.  * doesn't get shifted by 2 bits as we want to "drop" the bottom two
  70.  * bits.
  71.  */
  72. static int
  73. mk_conf_addr(struct pci_dev *dev, int where, unsigned long *pci_addr,
  74.      unsigned char *type1)
  75. {
  76. struct pci_controller *hose = dev->sysdata;
  77. unsigned long addr;
  78. u8 bus = dev->bus->number;
  79. u8 device_fn = dev->devfn;
  80. DBG_CFG(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x, "
  81.  "pci_addr=0x%p, type1=0x%p)n",
  82.  bus, device_fn, where, pci_addr, type1));
  83.         if (hose->first_busno == dev->bus->number)
  84. bus = 0;
  85.         *type1 = (bus != 0);
  86.         addr = (bus << 16) | (device_fn << 8) | where;
  87. addr |= hose->config_space_base;
  88. *pci_addr = addr;
  89. DBG_CFG(("mk_conf_addr: returning pci_addr 0x%lxn", addr));
  90. return 0;
  91. }
  92. static int 
  93. titan_read_config_byte(struct pci_dev *dev, int where, u8 *value)
  94. {
  95. unsigned long addr;
  96. unsigned char type1;
  97. if (mk_conf_addr(dev, where, &addr, &type1))
  98. return PCIBIOS_DEVICE_NOT_FOUND;
  99. *value = __kernel_ldbu(*(vucp)addr);
  100. return PCIBIOS_SUCCESSFUL;
  101. }
  102. static int
  103. titan_read_config_word(struct pci_dev *dev, int where, u16 *value)
  104. {
  105. unsigned long addr;
  106. unsigned char type1;
  107. if (mk_conf_addr(dev, where, &addr, &type1))
  108. return PCIBIOS_DEVICE_NOT_FOUND;
  109. *value = __kernel_ldwu(*(vusp)addr);
  110. return PCIBIOS_SUCCESSFUL;
  111. }
  112. static int
  113. titan_read_config_dword(struct pci_dev *dev, int where, u32 *value)
  114. {
  115. unsigned long addr;
  116. unsigned char type1;
  117. if (mk_conf_addr(dev, where, &addr, &type1))
  118. return PCIBIOS_DEVICE_NOT_FOUND;
  119. *value = *(vuip)addr;
  120. return PCIBIOS_SUCCESSFUL;
  121. }
  122. static int 
  123. titan_write_config_byte(struct pci_dev *dev, int where, u8 value)
  124. {
  125. unsigned long addr;
  126. unsigned char type1;
  127. if (mk_conf_addr(dev, where, &addr, &type1))
  128. return PCIBIOS_DEVICE_NOT_FOUND;
  129. __kernel_stb(value, *(vucp)addr);
  130. mb();
  131. __kernel_ldbu(*(vucp)addr);
  132. return PCIBIOS_SUCCESSFUL;
  133. }
  134. static int 
  135. titan_write_config_word(struct pci_dev *dev, int where, u16 value)
  136. {
  137. unsigned long addr;
  138. unsigned char type1;
  139. if (mk_conf_addr(dev, where, &addr, &type1))
  140. return PCIBIOS_DEVICE_NOT_FOUND;
  141. __kernel_stw(value, *(vusp)addr);
  142. mb();
  143. __kernel_ldwu(*(vusp)addr);
  144. return PCIBIOS_SUCCESSFUL;
  145. }
  146. static int
  147. titan_write_config_dword(struct pci_dev *dev, int where, u32 value)
  148. {
  149. unsigned long addr;
  150. unsigned char type1;
  151. if (mk_conf_addr(dev, where, &addr, &type1))
  152. return PCIBIOS_DEVICE_NOT_FOUND;
  153. *(vuip)addr = value;
  154. mb();
  155. *(vuip)addr;
  156. return PCIBIOS_SUCCESSFUL;
  157. }
  158. struct pci_ops titan_pci_ops = 
  159. {
  160. read_byte: titan_read_config_byte,
  161. read_word: titan_read_config_word,
  162. read_dword: titan_read_config_dword,
  163. write_byte: titan_write_config_byte,
  164. write_word: titan_write_config_word,
  165. write_dword: titan_write_config_dword
  166. };
  167. void
  168. titan_pci_tbi(struct pci_controller *hose, dma_addr_t start, dma_addr_t end)
  169. {
  170. titan_pachip *pachip = 
  171.   (hose->index & 1) ? TITAN_pachip1 : TITAN_pachip0;
  172. titan_pachip_port *port;
  173. volatile unsigned long *csr;
  174. unsigned long value;
  175. /* Get the right hose */
  176. port = &pachip->g_port;
  177. if (hose->index & 2) 
  178. port = &pachip->a_port;
  179. /* We can invalidate up to 8 tlb entries in a go.  The flush
  180.    matches against <31:16> in the pci address.  */
  181. csr = &port->port_specific.g.gtlbia.csr;
  182. if (((start ^ end) & 0xffff0000) == 0)
  183. csr = &port->port_specific.g.gtlbiv.csr;
  184. /* For TBIA, it doesn't matter what value we write.  For TBI, 
  185.    it's the shifted tag bits.  */
  186. value = (start & 0xffff0000) >> 12;
  187. wmb();
  188. *csr = value;
  189. mb();
  190. *csr;
  191. }
  192. #define FN __FUNCTION__
  193. static int __init
  194. titan_query_agp(titan_pachip_port *port)
  195. {
  196. union TPAchipPCTL pctl;
  197. /* set up APCTL */
  198. pctl.pctl_q_whole = port->pctl.csr;
  199. return pctl.pctl_r_bits.apctl_v_agp_present;
  200. }
  201. static void __init
  202. titan_init_agp(titan_pachip_port *port, struct pci_controller *hose)
  203. {
  204. union TPAchipPCTL pctl;
  205. if (!titan_query_agp(port))
  206. return;
  207. printk("AGP present on hose %dn", hose->index);
  208. /* get APCTL */
  209. pctl.pctl_q_whole = port->pctl.csr;
  210. pctl.pctl_r_bits.apctl_v_agp_en = 1; /* enable AGP */
  211. pctl.pctl_r_bits.apctl_v_agp_lp_rd = 0;
  212. pctl.pctl_r_bits.apctl_v_agp_hp_rd = 0;
  213. port->pctl.csr = pctl.pctl_q_whole;
  214. TITAN_agp |= 1 << hose->index;
  215. #ifdef CONFIG_VGA_HOSE
  216. /* is a graphics card on the AGP? (always device 5) */
  217. if (hose != NULL &&
  218.     __kernel_ldwu(*(vusp)(hose->config_space_base + 0x280a)) == 
  219.     PCI_CLASS_DISPLAY_VGA)
  220. set_vga_hose(hose);
  221. #endif
  222. }
  223. static void __init
  224. titan_init_one_pachip_port(titan_pachip_port *port, int index)
  225. {
  226. struct pci_controller *hose;
  227. unsigned long sg_size;
  228. hose = alloc_pci_controller();
  229. if (index == 0)
  230. pci_isa_hose = hose;
  231. hose->io_space = alloc_resource();
  232. hose->mem_space = alloc_resource();
  233. /* This is for userland consumption.  For some reason, the 40-bit
  234.    PIO bias that we use in the kernel through KSEG didn't work for
  235.    the page table based user mappings.  So make sure we get the
  236.    43-bit PIO bias.  */
  237. hose->sparse_mem_base = 0;
  238. hose->sparse_io_base = 0;
  239. hose->dense_mem_base
  240.   = (TITAN_MEM(index) & 0xffffffffff) | 0x80000000000;
  241. hose->dense_io_base
  242.   = (TITAN_IO(index) & 0xffffffffff) | 0x80000000000;
  243. hose->config_space_base = TITAN_CONF(index);
  244. hose->index = index;
  245. hose->io_space->start = TITAN_IO(index) - TITAN_IO_BIAS;
  246. hose->io_space->end = hose->io_space->start + TITAN_IO_SPACE - 1;
  247. hose->io_space->name = pci_io_names[index];
  248. hose->io_space->flags = IORESOURCE_IO;
  249. hose->mem_space->start = TITAN_MEM(index) - TITAN_MEM_BIAS;
  250. hose->mem_space->end = hose->mem_space->start + 0xffffffff;
  251. hose->mem_space->name = pci_mem_names[index];
  252. hose->mem_space->flags = IORESOURCE_MEM;
  253. if (request_resource(&ioport_resource, hose->io_space) < 0)
  254. printk(KERN_ERR "Failed to request IO on hose %dn", index);
  255. if (request_resource(&iomem_resource, hose->mem_space) < 0)
  256. printk(KERN_ERR "Failed to request MEM on hose %dn", index);
  257. /* It's safe to call this for both G-Ports and A-Ports */
  258. titan_init_agp(port, hose);
  259. /*
  260.  * Save the existing PCI window translations.  SRM will 
  261.  * need them when we go to reboot.
  262.  */
  263. saved_pachip_port[index].wsba[0] = port->wsba[0].csr;
  264. saved_pachip_port[index].wsm[0]  = port->wsm[0].csr;
  265. saved_pachip_port[index].tba[0]  = port->tba[0].csr;
  266. saved_pachip_port[index].wsba[1] = port->wsba[1].csr;
  267. saved_pachip_port[index].wsm[1]  = port->wsm[1].csr;
  268. saved_pachip_port[index].tba[1]  = port->tba[1].csr;
  269. saved_pachip_port[index].wsba[2] = port->wsba[2].csr;
  270. saved_pachip_port[index].wsm[2]  = port->wsm[2].csr;
  271. saved_pachip_port[index].tba[2]  = port->tba[2].csr;
  272. saved_pachip_port[index].wsba[3] = port->wsba[3].csr;
  273. saved_pachip_port[index].wsm[3]  = port->wsm[3].csr;
  274. saved_pachip_port[index].tba[3]  = port->tba[3].csr;
  275. /*
  276.  * Set up the PCI to main memory translation windows.
  277.  *
  278.  * Note: Window 3 on Titan is Scatter-Gather ONLY
  279.  *
  280.  * Window 0 is scatter-gather 8MB at 8MB (for isa)
  281.  * Window 1 is scatter-gather (up to) 1GB at 1GB
  282.  * Window 2 is direct access 2GB at 2GB
  283.  */
  284. hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
  285. hose->sg_isa->align_entry = 8; /* 64KB for ISA */
  286. hose->sg_pci = iommu_arena_new(hose, 0x40000000,
  287.        size_for_memory(0x40000000), 0);
  288. hose->sg_pci->align_entry = 4; /* Titan caches 4 PTEs at a time */
  289. __direct_map_base = 0x80000000;
  290. __direct_map_size = 0x80000000;
  291. port->wsba[0].csr = hose->sg_isa->dma_base | 3;
  292. port->wsm[0].csr  = (hose->sg_isa->size - 1) & 0xfff00000;
  293. port->tba[0].csr  = virt_to_phys(hose->sg_isa->ptes);
  294. port->wsba[1].csr = hose->sg_pci->dma_base | 3;
  295. port->wsm[1].csr  = (hose->sg_pci->size - 1) & 0xfff00000;
  296. port->tba[1].csr  = virt_to_phys(hose->sg_pci->ptes);
  297. port->wsba[2].csr = 0x80000000 | 1;
  298. port->wsm[2].csr  = (0x80000000 - 1) & 0xfff00000;
  299. port->tba[2].csr  = 0;
  300. port->wsba[3].csr = 0;
  301. /* Enable the Monster Window to make DAC pci64 possible. */
  302. port->pctl.csr |= pctl_m_mwin;
  303. titan_pci_tbi(hose, 0, -1);
  304. }
  305. static void __init
  306. titan_init_pachips(titan_pachip *pachip0, titan_pachip *pachip1)
  307. {
  308. int pchip1_present = TITAN_cchip->csc.csr & 1L<<14;
  309. /* Init the ports in hose order... */
  310. titan_init_one_pachip_port(&pachip0->g_port, 0); /* hose 0 */
  311. if (pchip1_present)
  312. titan_init_one_pachip_port(&pachip1->g_port, 1);/* hose 1 */
  313. titan_init_one_pachip_port(&pachip0->a_port, 2); /* hose 2 */
  314. if (pchip1_present)
  315. titan_init_one_pachip_port(&pachip1->a_port, 3);/* hose 3 */
  316. }
  317. void __init
  318. titan_init_arch(void)
  319. {
  320. #if 0
  321. printk("%s: titan_init_arch()n", FN);
  322. printk("%s: CChip registers:n", FN);
  323. printk("%s: CSR_CSC 0x%lxn", FN, TITAN_cchip->csc.csr);
  324. printk("%s: CSR_MTR 0x%lxn", FN, TITAN_cchip->mtr.csr);
  325. printk("%s: CSR_MISC 0x%lxn", FN, TITAN_cchip->misc.csr);
  326. printk("%s: CSR_DIM0 0x%lxn", FN, TITAN_cchip->dim0.csr);
  327. printk("%s: CSR_DIM1 0x%lxn", FN, TITAN_cchip->dim1.csr);
  328. printk("%s: CSR_DIR0 0x%lxn", FN, TITAN_cchip->dir0.csr);
  329. printk("%s: CSR_DIR1 0x%lxn", FN, TITAN_cchip->dir1.csr);
  330. printk("%s: CSR_DRIR 0x%lxn", FN, TITAN_cchip->drir.csr);
  331. printk("%s: DChip registers:n", FN);
  332. printk("%s: CSR_DSC 0x%lxn", FN, TITAN_dchip->dsc.csr);
  333. printk("%s: CSR_STR 0x%lxn", FN, TITAN_dchip->str.csr);
  334. printk("%s: CSR_DREV 0x%lxn", FN, TITAN_dchip->drev.csr);
  335. #endif
  336. boot_cpuid = __hard_smp_processor_id();
  337. /* With multiple PCI busses, we play with I/O as physical addrs.  */
  338. ioport_resource.end = ~0UL;
  339. iomem_resource.end = ~0UL;
  340. /* Init the PA chip(s) */
  341. titan_init_pachips(TITAN_pachip0, TITAN_pachip1);
  342. }
  343. static void
  344. titan_kill_one_pachip_port(titan_pachip_port *port, int index)
  345. {
  346. port->wsba[0].csr = saved_pachip_port[index].wsba[0];
  347. port->wsm[0].csr  = saved_pachip_port[index].wsm[0];
  348. port->tba[0].csr  = saved_pachip_port[index].tba[0];
  349. port->wsba[1].csr = saved_pachip_port[index].wsba[1];
  350. port->wsm[1].csr  = saved_pachip_port[index].wsm[1];
  351. port->tba[1].csr  = saved_pachip_port[index].tba[1];
  352. port->wsba[2].csr = saved_pachip_port[index].wsba[2];
  353. port->wsm[2].csr  = saved_pachip_port[index].wsm[2];
  354. port->tba[2].csr  = saved_pachip_port[index].tba[2];
  355. port->wsba[3].csr = saved_pachip_port[index].wsba[3];
  356. port->wsm[3].csr  = saved_pachip_port[index].wsm[3];
  357. port->tba[3].csr  = saved_pachip_port[index].tba[3];
  358. }
  359. static void
  360. titan_kill_pachips(titan_pachip *pachip0, titan_pachip *pachip1)
  361. {
  362. int pchip1_present = TITAN_cchip->csc.csr & 1L<<14;
  363. if (pchip1_present) {
  364. titan_kill_one_pachip_port(&pachip0->g_port, 1);
  365. titan_kill_one_pachip_port(&pachip0->a_port, 3);
  366. }
  367. titan_kill_one_pachip_port(&pachip0->g_port, 0);
  368. titan_kill_one_pachip_port(&pachip0->a_port, 2);
  369. }
  370. void
  371. titan_kill_arch(int mode)
  372. {
  373. titan_kill_pachips(TITAN_pachip0, TITAN_pachip1);
  374. }
  375. static inline void
  376. titan_pci_clr_err_1(titan_pachip *pachip)
  377. {
  378. unsigned int jd;
  379. jd = pachip->g_port.port_specific.g.gperror.csr;
  380. pachip->g_port.port_specific.g.gperror.csr = jd;
  381. mb();
  382. pachip->g_port.port_specific.g.gperror.csr;
  383. }
  384. static inline void
  385. titan_pci_clr_err(void)
  386. {
  387. titan_pci_clr_err_1(TITAN_pachip0);
  388. if (TITAN_cchip->csc.csr & 1L<<14)
  389.     titan_pci_clr_err_1(TITAN_pachip1);
  390. }
  391. void
  392. titan_machine_check(unsigned long vector, unsigned long la_ptr,
  393.       struct pt_regs * regs)
  394. {
  395. /* clear error before any reporting. */
  396. mb();
  397. draina();
  398. titan_pci_clr_err();
  399. wrmces(0x7);
  400. mb();
  401. process_mcheck_info(vector, la_ptr, regs, "TITAN",
  402.     mcheck_expected(smp_processor_id()));
  403. }