temperatureMemoryDefinition.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * linux/arch/alpha/kernel/core_cia.c
  3. *
  4. * Written by David A Rusling (david.rusling@reo.mts.dec.com).
  5. * December 1995.
  6. *
  7. * Copyright (C) 1995 David A Rusling
  8. * Copyright (C) 1997, 1998 Jay Estabrook
  9. * Copyright (C) 1998, 1999, 2000 Richard Henderson
  10. *
  11. * Code common to all CIA core logic chips.
  12. */
  13. #define __EXTERN_INLINE inline
  14. #include <asm/io.h>
  15. #include <asm/core_cia.h>
  16. #undef __EXTERN_INLINE
  17. #include <linux/types.h>
  18. #include <linux/pci.h>
  19. #include <linux/sched.h>
  20. #include <linux/init.h>
  21. #include <linux/bootmem.h>
  22. #include <asm/ptrace.h>
  23. #include <asm/mce.h>
  24. #include "proto.h"
  25. #include "pci_impl.h"
  26. /*
  27. * NOTE: Herein lie back-to-back mb instructions. They are magic.
  28. * One plausible explanation is that the i/o controller does not properly
  29. * handle the system transaction. Another involves timing. Ho hum.
  30. */
  31. #define DEBUG_CONFIG 0
  32. #if DEBUG_CONFIG
  33. # define DBGC(args) printk args
  34. #else
  35. # define DBGC(args)
  36. #endif
  37. #define vip volatile int *
  38. /*
  39. * Given a bus, device, and function number, compute resulting
  40. * configuration space address. It is therefore not safe to have
  41. * concurrent invocations to configuration space access routines, but
  42. * there really shouldn't be any need for this.
  43. *
  44. * Type 0:
  45. *
  46. * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
  47. * 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
  48. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  49. * | | |D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|0|
  50. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  51. *
  52. * 31:11 Device select bit.
  53. * 10:8 Function number
  54. * 7:2 Register number
  55. *
  56. * Type 1:
  57. *
  58. * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
  59. * 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
  60. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  61. * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
  62. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  63. *
  64. * 31:24 reserved
  65. * 23:16 bus number (8 bits = 128 possible buses)
  66. * 15:11 Device number (5 bits)
  67. * 10:8 function number
  68. * 7:2 register number
  69. *
  70. * Notes:
  71. * The function number selects which function of a multi-function device
  72. * (e.g., SCSI and Ethernet).
  73. *
  74. * The register selects a DWORD (32 bit) register offset. Hence it
  75. * doesn't get shifted by 2 bits as we want to "drop" the bottom two
  76. * bits.
  77. */
  78. static int
  79. mk_conf_addr(struct pci_bus *bus_dev, unsigned int device_fn, int where,
  80. unsigned long *pci_addr, unsigned char *type1)
  81. {
  82. u8 bus = bus_dev->number;
  83. *type1 = (bus != 0);
  84. *pci_addr = (bus << 16) | (device_fn << 8) | where;
  85. DBGC(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x,"
  86. " returning address 0x%p\n"
  87. bus, device_fn, where, *pci_addr));
  88. return 0;
  89. }
  90. static unsigned int
  91. conf_read(unsigned long addr, unsigned char type1)
  92. {
  93. unsigned long flags;
  94. int stat0, value;
  95. int cia_cfg = 0;
  96. DBGC(("conf_read(addr=0x%lx, type1=%d) ", addr, type1));
  97. local_irq_save(flags);
  98. /* Reset status register to avoid losing errors. */
  99. stat0 = *(vip)CIA_IOC_CIA_ERR;
  100. *(vip)CIA_IOC_CIA_ERR = stat0;
  101. mb();
  102. *(vip)CIA_IOC_CIA_ERR; /* re-read to force write */
  103. /* If Type1 access, must set CIA CFG. */
  104. if (type1) {
  105. cia_cfg = *(vip)CIA_IOC_CFG;
  106. *(vip)CIA_IOC_CFG = (cia_cfg & ~3) | 1;
  107. mb();
  108. *(vip)CIA_IOC_CFG;
  109. }
  110. mb();
  111. draina();
  112. mcheck_expected(0) = 1;
  113. mcheck_taken(0) = 0;
  114. mb();
  115. /* Access configuration space. */
  116. value = *(vip)addr;
  117. mb();
  118. mb(); /* magic */
  119. if (mcheck_taken(0)) {
  120. mcheck_taken(0) = 0;
  121. value = 0xffffffff;
  122. mb();
  123. }
  124. mcheck_expected(0) = 0;
  125. mb();
  126. /* If Type1 access, must reset IOC CFG so normal IO space ops work. */
  127. if (type1) {
  128. *(vip)CIA_IOC_CFG = cia_cfg;
  129. mb();
  130. *(vip)CIA_IOC_CFG;
  131. }
  132. local_irq_restore(flags);
  133. DBGC(("done\n"));
  134. return value;
  135. }
  136. static void
  137. conf_write(unsigned long addr, unsigned int value, unsigned char type1)
  138. {
  139. unsigned long flags;
  140. int stat0, cia_cfg = 0;
  141. DBGC(("conf_write(addr=0x%lx, type1=%d) ", addr, type1));
  142. local_irq_save(flags);
  143. /* Reset status register to avoid losing errors. */
  144. stat0 = *(vip)CIA_IOC_CIA_ERR;
  145. *(vip)CIA_IOC_CIA_ERR = stat0;
  146. mb();
  147. *(vip)CIA_IOC_CIA_ERR; /* re-read to force write */
  148. /* If Type1 access, must set CIA CFG. */
  149. if (type1) {
  150. cia_cfg = *(vip)CIA_IOC_CFG;
  151. *(vip)CIA_IOC_CFG = (cia_cfg & ~3) | 1;
  152. mb();
  153. *(vip)CIA_IOC_CFG;
  154. }
  155. mb();
  156. draina();
  157. mcheck_expected(0) = 1;
  158. mcheck_taken(0) = 0;
  159. mb();
  160. /* Access configuration space. */
  161. *(vip)addr = value;
  162. mb();
  163. *(vip)addr; /* read back to force the write */
  164. mcheck_expected(0) = 0;
  165. mb();
  166. /* If Type1 access, must reset IOC CFG so normal IO space ops work. */
  167. if (type1) {
  168. *(vip)CIA_IOC_CFG = cia_cfg;
  169. mb();
  170. *(vip)CIA_IOC_CFG;
  171. }
  172. local_irq_restore(flags);
  173. DBGC(("done\n"));
  174. }
  175. static int
  176. cia_read_config(struct pci_bus *bus, unsigned int devfn, int where, int size,
  177. u32 *value)
  178. {
  179. unsigned long addr, pci_addr;
  180. long mask;
  181. unsigned char type1;
  182. int shift;
  183. if (mk_conf_addr(bus, devfn, where, &pci_addr, &type1))
  184. return PCIBIOS_DEVICE_NOT_FOUND;
  185. mask = (size - 1) * 8;
  186. shift = (where & 3) * 8;
  187. addr = (pci_addr << 5) + mask + CIA_CONF;
  188. *value = conf_read(addr, type1) >> (shift);
  189. return PCIBIOS_SUCCESSFUL;
  190. }
  191. static int
  192. cia_write_config(struct pci_bus *bus, unsigned int devfn, int where, int size,
  193. u32 value)
  194. {
  195. unsigned long addr, pci_addr;
  196. long mask;
  197. unsigned char type1;
  198. if (mk_conf_addr(bus, devfn, where, &pci_addr, &type1))
  199. return PCIBIOS_DEVICE_NOT_FOUND;
  200. mask = (size - 1) * 8;
  201. addr = (pci_addr << 5) + mask + CIA_CONF;
  202. conf_write(addr, value << ((where & 3) * 8), type1);
  203. return PCIBIOS_SUCCESSFUL;
  204. }
  205. struct pci_ops cia_pci_ops =
  206. {
  207. .read = cia_read_config,
  208. .write = cia_write_config,
  209. };
  210. /*
  211. * CIA Pass 1 and PYXIS Pass 1 and 2 have a broken scatter-gather tlb.
  212. * It cannot be invalidated. Rather than hard code the pass numbers,
  213. * actually try the tbia to see if it works.
  214. */
  215. void
  216. cia_pci_tbi(struct pci_controller *hose, dma_addr_t start, dma_addr_t end)
  217. {