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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *      linux/arch/alpha/kernel/core_polaris.c
  3.  *
  4.  * POLARIS chip-specific code
  5.  */
  6. #include <linux/kernel.h>
  7. #include <linux/types.h>
  8. #include <linux/pci.h>
  9. #include <linux/sched.h>
  10. #include <linux/init.h>
  11. #include <asm/system.h>
  12. #include <asm/ptrace.h>
  13. #define __EXTERN_INLINE inline
  14. #include <asm/io.h>
  15. #include <asm/core_polaris.h>
  16. #undef __EXTERN_INLINE
  17. #include "proto.h"
  18. #include "pci_impl.h"
  19. /*
  20.  * BIOS32-style PCI interface:
  21.  */
  22. #define DEBUG_CONFIG 0
  23. #if DEBUG_CONFIG
  24. # define DBG_CFG(args) printk args
  25. #else
  26. # define DBG_CFG(args)
  27. #endif
  28. /*
  29.  * Given a bus, device, and function number, compute resulting
  30.  * configuration space address.  This is fairly straightforward
  31.  * on POLARIS, since the chip itself generates Type 0 or Type 1
  32.  * cycles automatically depending on the bus number (Bus 0 is
  33.  * hardwired to Type 0, all others are Type 1.  Peer bridges
  34.  * are not supported).
  35.  *
  36.  * All types:
  37.  *
  38.  *  3 3 3 3|3 3 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1 
  39.  *  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 9 8|7 6 5 4|3 2 1 0
  40.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  41.  * |1|1|1|1|1|0|0|1|1|1|1|1|1|1|1|0|B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|x|x|
  42.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  43.  *
  44.  * 23:16 bus number (8 bits = 128 possible buses)
  45.  * 15:11 Device number (5 bits)
  46.  * 10:8 function number
  47.  *  7:2 register number
  48.  *  
  49.  * Notes:
  50.  * The function number selects which function of a multi-function device 
  51.  * (e.g., scsi and ethernet).
  52.  * 
  53.  * The register selects a DWORD (32 bit) register offset.  Hence it
  54.  * doesn't get shifted by 2 bits as we want to "drop" the bottom two
  55.  * bits.
  56.  */
  57. static int
  58. mk_conf_addr(struct pci_dev *dev, int where, unsigned long *pci_addr, u8 *type1)
  59. {
  60. u8 bus = dev->bus->number;
  61. u8 device_fn = dev->devfn;
  62. *type1 = (bus == 0) ? 0 : 1;
  63. *pci_addr = (bus << 16) | (device_fn << 8) | (where) |
  64.     POLARIS_DENSE_CONFIG_BASE;
  65.         DBG_CFG(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x,"
  66.                  " returning address 0x%pn"
  67.                  bus, device_fn, where, *pci_addr));
  68. return 0;
  69. }
  70. static int
  71. polaris_read_config_byte(struct pci_dev *dev, int where, u8 *value)
  72. {
  73. unsigned long pci_addr;
  74. unsigned char type1;
  75. if (mk_conf_addr(dev, where, &pci_addr, &type1))
  76.                 return PCIBIOS_DEVICE_NOT_FOUND;
  77. *value = __kernel_ldbu(*(vucp)pci_addr);
  78. return PCIBIOS_SUCCESSFUL;
  79. }
  80. static int
  81. polaris_read_config_word(struct pci_dev *dev, int where, u16 *value)
  82. {
  83. unsigned long pci_addr;
  84. unsigned char type1;
  85. if (mk_conf_addr(dev, where, &pci_addr, &type1))
  86.                 return PCIBIOS_DEVICE_NOT_FOUND;
  87. *value = __kernel_ldwu(*(vusp)pci_addr);
  88. return PCIBIOS_SUCCESSFUL;
  89. }
  90. int
  91. polaris_read_config_dword(struct pci_dev *dev, int where, u32 *value)
  92. {
  93. unsigned long pci_addr;
  94. unsigned char type1;
  95. if (mk_conf_addr(dev, where, &pci_addr, &type1))
  96.                 return PCIBIOS_DEVICE_NOT_FOUND;
  97. *value = *(vuip)pci_addr;
  98. return PCIBIOS_SUCCESSFUL;
  99. }
  100. static int 
  101. polaris_write_config_byte(struct pci_dev *dev, int where, u8 value)
  102. {
  103. unsigned long pci_addr;
  104. unsigned char type1;
  105. if (mk_conf_addr(dev, where, &pci_addr, &type1))
  106.                 return PCIBIOS_DEVICE_NOT_FOUND;
  107.         __kernel_stb(value, *(vucp)pci_addr);
  108. mb();
  109. __kernel_ldbu(*(vucp)pci_addr);
  110. return PCIBIOS_SUCCESSFUL;
  111. }
  112. static int 
  113. polaris_write_config_word(struct pci_dev *dev, int where, u16 value)
  114. {
  115. unsigned long pci_addr;
  116. unsigned char type1;
  117. if (mk_conf_addr(dev, where, &pci_addr, &type1))
  118.                 return PCIBIOS_DEVICE_NOT_FOUND;
  119.         __kernel_stw(value, *(vusp)pci_addr);
  120. mb();
  121. __kernel_ldwu(*(vusp)pci_addr);
  122. return PCIBIOS_SUCCESSFUL;
  123. }
  124. int 
  125. polaris_write_config_dword(struct pci_dev *dev, int where, u32 value)
  126. {
  127. unsigned long pci_addr;
  128. unsigned char type1;
  129. if (mk_conf_addr(dev, where, &pci_addr, &type1))
  130.                 return PCIBIOS_DEVICE_NOT_FOUND;
  131. *(vuip)pci_addr = value;
  132. mb();
  133. *(vuip)pci_addr;
  134. return PCIBIOS_SUCCESSFUL;
  135. }
  136. struct pci_ops polaris_pci_ops = 
  137. {
  138. read_byte: polaris_read_config_byte,
  139. read_word: polaris_read_config_word,
  140. read_dword: polaris_read_config_dword,
  141. write_byte: polaris_write_config_byte,
  142. write_word: polaris_write_config_word,
  143. write_dword: polaris_write_config_dword
  144. };
  145. void __init
  146. polaris_init_arch(void)
  147. {
  148. struct pci_controller *hose;
  149. /* May need to initialize error reporting (see PCICTL0/1), but
  150.  * for now assume that the firmware has done the right thing
  151.  * already.
  152.  */
  153. #if 0
  154. printk("polaris_init_arch(): trusting firmware for setupn");
  155. #endif
  156. /*
  157.  * Create our single hose.
  158.  */
  159. pci_isa_hose = hose = alloc_pci_controller();
  160. hose->io_space = &ioport_resource;
  161. hose->mem_space = &iomem_resource;
  162. hose->index = 0;
  163. hose->sparse_mem_base = 0;
  164. hose->dense_mem_base = POLARIS_DENSE_MEM_BASE - IDENT_ADDR;
  165. hose->sparse_io_base = 0;
  166. hose->dense_io_base = POLARIS_DENSE_IO_BASE - IDENT_ADDR;
  167. hose->sg_isa = hose->sg_pci = NULL;
  168. /* The I/O window is fixed at 2G @ 2G.  */
  169. __direct_map_base = 0x80000000;
  170. __direct_map_size = 0x80000000;
  171. }
  172. static inline void
  173. polaris_pci_clr_err(void)
  174. {
  175. *(vusp)POLARIS_W_STATUS;
  176. /* Write 1's to settable bits to clear errors */
  177. *(vusp)POLARIS_W_STATUS = 0x7800;
  178. mb();
  179. *(vusp)POLARIS_W_STATUS;
  180. }
  181. void
  182. polaris_machine_check(unsigned long vector, unsigned long la_ptr,
  183.       struct pt_regs * regs)
  184. {
  185. /* Clear the error before any reporting.  */
  186. mb();
  187. mb();
  188. draina();
  189. polaris_pci_clr_err();
  190. wrmces(0x7);
  191. mb();
  192. process_mcheck_info(vector, la_ptr, regs, "POLARIS",
  193.     mcheck_expected(0));
  194. }