core_polaris.c 4.4 KB

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