core_lca.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:14k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  * linux/arch/alpha/kernel/core_lca.c
  3.  *
  4.  * Written by David Mosberger (davidm@cs.arizona.edu) with some code
  5.  * taken from Dave Rusling's (david.rusling@reo.mts.dec.com) 32-bit
  6.  * bios code.
  7.  *
  8.  * Code common to all LCA core logic chips.
  9.  */
  10. #include <linux/kernel.h>
  11. #include <linux/types.h>
  12. #include <linux/pci.h>
  13. #include <linux/init.h>
  14. #include <linux/tty.h>
  15. #include <asm/ptrace.h>
  16. #include <asm/system.h>
  17. #include <asm/smp.h>
  18. #define __EXTERN_INLINE inline
  19. #include <asm/io.h>
  20. #include <asm/core_lca.h>
  21. #undef __EXTERN_INLINE
  22. #include "proto.h"
  23. #include "pci_impl.h"
  24. /*
  25.  * BIOS32-style PCI interface:
  26.  */
  27. /*
  28.  * Machine check reasons.  Defined according to PALcode sources
  29.  * (osf.h and platform.h).
  30.  */
  31. #define MCHK_K_TPERR 0x0080
  32. #define MCHK_K_TCPERR 0x0082
  33. #define MCHK_K_HERR 0x0084
  34. #define MCHK_K_ECC_C 0x0086
  35. #define MCHK_K_ECC_NC 0x0088
  36. #define MCHK_K_UNKNOWN 0x008A
  37. #define MCHK_K_CACKSOFT 0x008C
  38. #define MCHK_K_BUGCHECK 0x008E
  39. #define MCHK_K_OS_BUGCHECK 0x0090
  40. #define MCHK_K_DCPERR 0x0092
  41. #define MCHK_K_ICPERR 0x0094
  42. /*
  43.  * Platform-specific machine-check reasons:
  44.  */
  45. #define MCHK_K_SIO_SERR 0x204 /* all platforms so far */
  46. #define MCHK_K_SIO_IOCHK 0x206 /* all platforms so far */
  47. #define MCHK_K_DCSR 0x208 /* all but Noname */
  48. /*
  49.  * Given a bus, device, and function number, compute resulting
  50.  * configuration space address and setup the LCA_IOC_CONF register
  51.  * accordingly.  It is therefore not safe to have concurrent
  52.  * invocations to configuration space access routines, but there
  53.  * really shouldn't be any need for this.
  54.  *
  55.  * Type 0:
  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.  * | | | | | | | | | | | | | | | | | | | | | | | |F|F|F|R|R|R|R|R|R|0|0|
  61.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  62.  *
  63.  * 31:11 Device select bit.
  64.  *  10:8 Function number
  65.  *   7:2 Register number
  66.  *
  67.  * Type 1:
  68.  *
  69.  *  3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1 
  70.  *  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
  71.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  72.  * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
  73.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  74.  *
  75.  * 31:24 reserved
  76.  * 23:16 bus number (8 bits = 128 possible buses)
  77.  * 15:11 Device number (5 bits)
  78.  * 10:8 function number
  79.  *  7:2 register number
  80.  *  
  81.  * Notes:
  82.  * The function number selects which function of a multi-function device 
  83.  * (e.g., SCSI and Ethernet).
  84.  * 
  85.  * The register selects a DWORD (32 bit) register offset.  Hence it
  86.  * doesn't get shifted by 2 bits as we want to "drop" the bottom two
  87.  * bits.
  88.  */
  89. static int
  90. mk_conf_addr(struct pci_dev *dev, int where, unsigned long *pci_addr)
  91. {
  92. unsigned long addr;
  93. u8 bus = dev->bus->number;
  94. u8 device_fn = dev->devfn;
  95. if (bus == 0) {
  96. int device = device_fn >> 3;
  97. int func = device_fn & 0x7;
  98. /* Type 0 configuration cycle.  */
  99. if (device > 12) {
  100. return -1;
  101. }
  102. *(vulp)LCA_IOC_CONF = 0;
  103. addr = (1 << (11 + device)) | (func << 8) | where;
  104. } else {
  105. /* Type 1 configuration cycle.  */
  106. *(vulp)LCA_IOC_CONF = 1;
  107. addr = (bus << 16) | (device_fn << 8) | where;
  108. }
  109. *pci_addr = addr;
  110. return 0;
  111. }
  112. static unsigned int
  113. conf_read(unsigned long addr)
  114. {
  115. unsigned long flags, code, stat0;
  116. unsigned int value;
  117. __save_and_cli(flags);
  118. /* Reset status register to avoid loosing errors.  */
  119. stat0 = *(vulp)LCA_IOC_STAT0;
  120. *(vulp)LCA_IOC_STAT0 = stat0;
  121. mb();
  122. /* Access configuration space.  */
  123. value = *(vuip)addr;
  124. draina();
  125. stat0 = *(vulp)LCA_IOC_STAT0;
  126. if (stat0 & LCA_IOC_STAT0_ERR) {
  127. code = ((stat0 >> LCA_IOC_STAT0_CODE_SHIFT)
  128. & LCA_IOC_STAT0_CODE_MASK);
  129. if (code != 1) {
  130. printk("lca.c:conf_read: got stat0=%lxn", stat0);
  131. }
  132. /* Reset error status.  */
  133. *(vulp)LCA_IOC_STAT0 = stat0;
  134. mb();
  135. /* Reset machine check.  */
  136. wrmces(0x7);
  137. value = 0xffffffff;
  138. }
  139. __restore_flags(flags);
  140. return value;
  141. }
  142. static void
  143. conf_write(unsigned long addr, unsigned int value)
  144. {
  145. unsigned long flags, code, stat0;
  146. __save_and_cli(flags); /* avoid getting hit by machine check */
  147. /* Reset status register to avoid loosing errors.  */
  148. stat0 = *(vulp)LCA_IOC_STAT0;
  149. *(vulp)LCA_IOC_STAT0 = stat0;
  150. mb();
  151. /* Access configuration space.  */
  152. *(vuip)addr = value;
  153. draina();
  154. stat0 = *(vulp)LCA_IOC_STAT0;
  155. if (stat0 & LCA_IOC_STAT0_ERR) {
  156. code = ((stat0 >> LCA_IOC_STAT0_CODE_SHIFT)
  157. & LCA_IOC_STAT0_CODE_MASK);
  158. if (code != 1) {
  159. printk("lca.c:conf_write: got stat0=%lxn", stat0);
  160. }
  161. /* Reset error status.  */
  162. *(vulp)LCA_IOC_STAT0 = stat0;
  163. mb();
  164. /* Reset machine check. */
  165. wrmces(0x7);
  166. }
  167. __restore_flags(flags);
  168. }
  169. static int
  170. lca_read_config_byte(struct pci_dev *dev, int where, u8 *value)
  171. {
  172. unsigned long addr, pci_addr;
  173. if (mk_conf_addr(dev, where, &pci_addr))
  174. return PCIBIOS_DEVICE_NOT_FOUND;
  175. addr = (pci_addr << 5) + 0x00 + LCA_CONF;
  176. *value = conf_read(addr) >> ((where & 3) * 8);
  177. return PCIBIOS_SUCCESSFUL;
  178. }
  179. static int 
  180. lca_read_config_word(struct pci_dev *dev, int where, u16 *value)
  181. {
  182. unsigned long addr, pci_addr;
  183. if (mk_conf_addr(dev, where, &pci_addr))
  184. return PCIBIOS_DEVICE_NOT_FOUND;
  185. addr = (pci_addr << 5) + 0x08 + LCA_CONF;
  186. *value = conf_read(addr) >> ((where & 3) * 8);
  187. return PCIBIOS_SUCCESSFUL;
  188. }
  189. static int
  190. lca_read_config_dword(struct pci_dev *dev, int where, u32 *value)
  191. {
  192. unsigned long addr, pci_addr;
  193. if (mk_conf_addr(dev, where, &pci_addr))
  194. return PCIBIOS_DEVICE_NOT_FOUND;
  195. addr = (pci_addr << 5) + 0x18 + LCA_CONF;
  196. *value = conf_read(addr);
  197. return PCIBIOS_SUCCESSFUL;
  198. }
  199. static int 
  200. lca_write_config(struct pci_dev *dev, int where, u32 value, long mask)
  201. {
  202. unsigned long addr, pci_addr;
  203. if (mk_conf_addr(dev, where, &pci_addr))
  204. return PCIBIOS_DEVICE_NOT_FOUND;
  205. addr = (pci_addr << 5) + mask + LCA_CONF;
  206. conf_write(addr, value << ((where & 3) * 8));
  207. return PCIBIOS_SUCCESSFUL;
  208. }
  209. static int
  210. lca_write_config_byte(struct pci_dev *dev, int where, u8 value)
  211. {
  212. return lca_write_config(dev, where, value, 0x00);
  213. }
  214. static int
  215. lca_write_config_word(struct pci_dev *dev, int where, u16 value)
  216. {
  217. return lca_write_config(dev, where, value, 0x08);
  218. }
  219. static int
  220. lca_write_config_dword(struct pci_dev *dev, int where, u32 value)
  221. {
  222. return lca_write_config(dev, where, value, 0x18);
  223. }
  224. struct pci_ops lca_pci_ops = 
  225. {
  226. read_byte: lca_read_config_byte,
  227. read_word: lca_read_config_word,
  228. read_dword: lca_read_config_dword,
  229. write_byte: lca_write_config_byte,
  230. write_word: lca_write_config_word,
  231. write_dword: lca_write_config_dword
  232. };
  233. void
  234. lca_pci_tbi(struct pci_controller *hose, dma_addr_t start, dma_addr_t end)
  235. {
  236. wmb();
  237. *(vip)LCA_IOC_TBIA = 0;
  238. mb();
  239. }
  240. void __init
  241. lca_init_arch(void)
  242. {
  243. struct pci_controller *hose;
  244. /*
  245.  * Create our single hose.
  246.  */
  247. pci_isa_hose = hose = alloc_pci_controller();
  248. hose->io_space = &ioport_resource;
  249. hose->mem_space = &iomem_resource;
  250. hose->index = 0;
  251. hose->sparse_mem_base = LCA_SPARSE_MEM - IDENT_ADDR;
  252. hose->dense_mem_base = LCA_DENSE_MEM - IDENT_ADDR;
  253. hose->sparse_io_base = LCA_IO - IDENT_ADDR;
  254. hose->dense_io_base = 0;
  255. /*
  256.  * Set up the PCI to main memory translation windows.
  257.  *
  258.  * Window 0 is direct access 1GB at 1GB
  259.  * Window 1 is scatter-gather 8MB at 8MB (for isa)
  260.  */
  261. hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
  262. hose->sg_pci = NULL;
  263. __direct_map_base = 0x40000000;
  264. __direct_map_size = 0x40000000;
  265. *(vulp)LCA_IOC_W_BASE0 = __direct_map_base | (2UL << 32);
  266. *(vulp)LCA_IOC_W_MASK0 = (__direct_map_size - 1) & 0xfff00000;
  267. *(vulp)LCA_IOC_T_BASE0 = 0;
  268. *(vulp)LCA_IOC_W_BASE1 = hose->sg_isa->dma_base | (3UL << 32);
  269. *(vulp)LCA_IOC_W_MASK1 = (hose->sg_isa->size - 1) & 0xfff00000;
  270. *(vulp)LCA_IOC_T_BASE1 = virt_to_phys(hose->sg_isa->ptes);
  271. *(vulp)LCA_IOC_TB_ENA = 0x80;
  272. lca_pci_tbi(hose, 0, -1);
  273. /*
  274.  * Disable PCI parity for now.  The NCR53c810 chip has
  275.  * troubles meeting the PCI spec which results in
  276.  * data parity errors.
  277.  */
  278. *(vulp)LCA_IOC_PAR_DIS = 1UL<<5;
  279. }
  280. /*
  281.  * Constants used during machine-check handling.  I suppose these
  282.  * could be moved into lca.h but I don't see much reason why anybody
  283.  * else would want to use them.
  284.  */
  285. #define ESR_EAV (1UL<< 0) /* error address valid */
  286. #define ESR_CEE (1UL<< 1) /* correctable error */
  287. #define ESR_UEE (1UL<< 2) /* uncorrectable error */
  288. #define ESR_WRE (1UL<< 3) /* write-error */
  289. #define ESR_SOR (1UL<< 4) /* error source */
  290. #define ESR_CTE (1UL<< 7) /* cache-tag error */
  291. #define ESR_MSE (1UL<< 9) /* multiple soft errors */
  292. #define ESR_MHE (1UL<<10) /* multiple hard errors */
  293. #define ESR_NXM (1UL<<12) /* non-existent memory */
  294. #define IOC_ERR (  1<<4) /* ioc logs an error */
  295. #define IOC_CMD_SHIFT 0
  296. #define IOC_CMD (0xf<<IOC_CMD_SHIFT)
  297. #define IOC_CODE_SHIFT 8
  298. #define IOC_CODE (0xf<<IOC_CODE_SHIFT)
  299. #define IOC_LOST (  1<<5)
  300. #define IOC_P_NBR ((__u32) ~((1<<13) - 1))
  301. static void
  302. mem_error(unsigned long esr, unsigned long ear)
  303. {
  304. printk("    %s %s error to %s occurred at address %xn",
  305.        ((esr & ESR_CEE) ? "Correctable" :
  306. (esr & ESR_UEE) ? "Uncorrectable" : "A"),
  307.        (esr & ESR_WRE) ? "write" : "read",
  308.        (esr & ESR_SOR) ? "memory" : "b-cache",
  309.        (unsigned) (ear & 0x1ffffff8));
  310. if (esr & ESR_CTE) {
  311. printk("    A b-cache tag parity error was detected.n");
  312. }
  313. if (esr & ESR_MSE) {
  314. printk("    Several other correctable errors occurred.n");
  315. }
  316. if (esr & ESR_MHE) {
  317. printk("    Several other uncorrectable errors occurred.n");
  318. }
  319. if (esr & ESR_NXM) {
  320. printk("    Attempted to access non-existent memory.n");
  321. }
  322. }
  323. static void
  324. ioc_error(__u32 stat0, __u32 stat1)
  325. {
  326. static const char * const pci_cmd[] = {
  327. "Interrupt Acknowledge", "Special", "I/O Read", "I/O Write",
  328. "Rsvd 1", "Rsvd 2", "Memory Read", "Memory Write", "Rsvd3",
  329. "Rsvd4", "Configuration Read", "Configuration Write",
  330. "Memory Read Multiple", "Dual Address", "Memory Read Line",
  331. "Memory Write and Invalidate"
  332. };
  333. static const char * const err_name[] = {
  334. "exceeded retry limit", "no device", "bad data parity",
  335. "target abort", "bad address parity", "page table read error",
  336. "invalid page", "data error"
  337. };
  338. unsigned code = (stat0 & IOC_CODE) >> IOC_CODE_SHIFT;
  339. unsigned cmd  = (stat0 & IOC_CMD)  >> IOC_CMD_SHIFT;
  340. printk("    %s initiated PCI %s cycle to address %x"
  341.        " failed due to %s.n",
  342.        code > 3 ? "PCI" : "CPU", pci_cmd[cmd], stat1, err_name[code]);
  343. if (code == 5 || code == 6) {
  344. printk("    (Error occurred at PCI memory address %x.)n",
  345.        (stat0 & ~IOC_P_NBR));
  346. }
  347. if (stat0 & IOC_LOST) {
  348. printk("    Other PCI errors occurred simultaneously.n");
  349. }
  350. }
  351. void
  352. lca_machine_check(unsigned long vector, unsigned long la_ptr,
  353.   struct pt_regs *regs)
  354. {
  355. const char * reason;
  356. union el_lca el;
  357. el.c = (struct el_common *) la_ptr;
  358. wrmces(rdmces()); /* reset machine check pending flag */
  359. printk(KERN_CRIT "LCA machine check: vector=%#lx pc=%#lx code=%#xn",
  360.        vector, regs->pc, (unsigned int) el.c->code);
  361. /*
  362.  * The first quadword after the common header always seems to
  363.  * be the machine check reason---don't know why this isn't
  364.  * part of the common header instead.  In the case of a long
  365.  * logout frame, the upper 32 bits is the machine check
  366.  * revision level, which we ignore for now.
  367.  */
  368. switch ((unsigned int) el.c->code) {
  369. case MCHK_K_TPERR: reason = "tag parity error"; break;
  370. case MCHK_K_TCPERR: reason = "tag control parity error"; break;
  371. case MCHK_K_HERR: reason = "access to non-existent memory"; break;
  372. case MCHK_K_ECC_C: reason = "correctable ECC error"; break;
  373. case MCHK_K_ECC_NC: reason = "non-correctable ECC error"; break;
  374. case MCHK_K_CACKSOFT: reason = "MCHK_K_CACKSOFT"; break;
  375. case MCHK_K_BUGCHECK: reason = "illegal exception in PAL mode"; break;
  376. case MCHK_K_OS_BUGCHECK: reason = "callsys in kernel mode"; break;
  377. case MCHK_K_DCPERR: reason = "d-cache parity error"; break;
  378. case MCHK_K_ICPERR: reason = "i-cache parity error"; break;
  379. case MCHK_K_SIO_SERR: reason = "SIO SERR occurred on PCI bus"; break;
  380. case MCHK_K_SIO_IOCHK: reason = "SIO IOCHK occurred on ISA bus"; break;
  381. case MCHK_K_DCSR: reason = "MCHK_K_DCSR"; break;
  382. case MCHK_K_UNKNOWN:
  383. default: reason = "unknown"; break;
  384. }
  385. switch (el.c->size) {
  386. case sizeof(struct el_lca_mcheck_short):
  387. printk(KERN_CRIT
  388.        "  Reason: %s (short frame%s, dc_stat=%#lx):n",
  389.        reason, el.c->retry ? ", retryable" : "",
  390.        el.s->dc_stat);
  391. if (el.s->esr & ESR_EAV) {
  392. mem_error(el.s->esr, el.s->ear);
  393. }
  394. if (el.s->ioc_stat0 & IOC_ERR) {
  395. ioc_error(el.s->ioc_stat0, el.s->ioc_stat1);
  396. }
  397. break;
  398. case sizeof(struct el_lca_mcheck_long):
  399. printk(KERN_CRIT "  Reason: %s (long frame%s):n",
  400.        reason, el.c->retry ? ", retryable" : "");
  401. printk(KERN_CRIT
  402.        "    reason: %#lx  exc_addr: %#lx  dc_stat: %#lxn", 
  403.        el.l->pt[0], el.l->exc_addr, el.l->dc_stat);
  404. printk(KERN_CRIT "    car: %#lxn", el.l->car);
  405. if (el.l->esr & ESR_EAV) {
  406. mem_error(el.l->esr, el.l->ear);
  407. }
  408. if (el.l->ioc_stat0 & IOC_ERR) {
  409. ioc_error(el.l->ioc_stat0, el.l->ioc_stat1);
  410. }
  411. break;
  412. default:
  413. printk(KERN_CRIT "  Unknown errorlog size %dn", el.c->size);
  414. }
  415. /* Dump the logout area to give all info.  */
  416. #if DEBUG_MCHECK > 1
  417. {
  418. unsigned long * ptr = (unsigned long *) la_ptr;
  419. long i;
  420. for (i = 0; i < el.c->size / sizeof(long); i += 2) {
  421. printk(KERN_CRIT " +%8lx %016lx %016lxn",
  422.        i*sizeof(long), ptr[i], ptr[i+1]);
  423. }
  424. }
  425. #endif
  426. }
  427. /*
  428.  * The following routines are needed to support the SPEED changing
  429.  * necessary to successfully manage the thermal problem on the AlphaBook1.
  430.  */
  431. void
  432. lca_clock_print(void)
  433. {
  434.         long    pmr_reg;
  435.         pmr_reg = LCA_READ_PMR;
  436.         printk("Status of clock control:n");
  437.         printk("tPrimary clock divisort0x%lxn", LCA_GET_PRIMARY(pmr_reg));
  438.         printk("tOverride clock divisort0x%lxn", LCA_GET_OVERRIDE(pmr_reg));
  439.         printk("tInterrupt override is %sn",
  440.        (pmr_reg & LCA_PMR_INTO) ? "on" : "off"); 
  441.         printk("tDMA override is %sn",
  442.        (pmr_reg & LCA_PMR_DMAO) ? "on" : "off"); 
  443. }
  444. int
  445. lca_get_clock(void)
  446. {
  447.         long    pmr_reg;
  448.         pmr_reg = LCA_READ_PMR;
  449.         return(LCA_GET_PRIMARY(pmr_reg));
  450. }
  451. void
  452. lca_clock_fiddle(int divisor)
  453. {
  454.         long    pmr_reg;
  455.         pmr_reg = LCA_READ_PMR;
  456.         LCA_SET_PRIMARY_CLOCK(pmr_reg, divisor);
  457. /* lca_norm_clock = divisor; */
  458.         LCA_WRITE_PMR(pmr_reg);
  459.         mb();
  460. }