memoryOperation.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * linux/arch/alpha/kernel/core_mcpcia.c
  3. *
  4. * Based on code written by David A Rusling (david.rusling@reo.mts.dec.com).
  5. *
  6. * Code common to all MCbus-PCI Adaptor core logic chipsets
  7. */
  8. #define __EXTERN_INLINE inline
  9. #include <asm/io.h>
  10. #include <asm/core_mcpcia.h>
  11. #undef __EXTERN_INLINE
  12. #include <linux/types.h>
  13. #include <linux/pci.h>
  14. #include <linux/sched.h>
  15. #include <linux/init.h>
  16. #include <linux/delay.h>
  17. #include <asm/ptrace.h>
  18. #include "proto.h"
  19. #include "pci_impl.h"
  20. /*
  21. * NOTE: Herein lie back-to-back mb instructions. They are magic.
  22. * One plausible explanation is that the i/o controller does not properly
  23. * handle the system transaction. Another involves timing. Ho hum.
  24. */
  25. /*
  26. * BIOS32-style PCI interface:
  27. */
  28. #define DEBUG_CFG 0
  29. #if DEBUG_CFG
  30. # define DBG_CFG(args) printk args
  31. #else
  32. # define DBG_CFG(args)
  33. #endif
  34. /*
  35. * Given a bus, device, and function number, compute resulting
  36. * configuration space address and setup the MCPCIA_HAXR2 register
  37. * accordingly. It is therefore not safe to have concurrent
  38. * invocations to configuration space access routines, but there
  39. * really shouldn't be any need for this.
  40. *
  41. * Type 0:
  42. *
  43. * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
  44. * 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
  45. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  46. * | | |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|
  47. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  48. *
  49. * 31:11 Device select bit.
  50. * 10:8 Function number
  51. * 7:2 Register number
  52. *
  53. * Type 1:
  54. *
  55. * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
  56. * 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
  57. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  58. * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
  59. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  60. *
  61. * 31:24 reserved
  62. * 23:16 bus number (8 bits = 128 possible buses)
  63. * 15:11 Device number (5 bits)
  64. * 10:8 function number
  65. * 7:2 register number
  66. *
  67. * Notes:
  68. * The function number selects which function of a multi-function device
  69. * (e.g., SCSI and Ethernet).
  70. *
  71. * The register selects a DWORD (32 bit) register offset. Hence it
  72. * doesn't get shifted by 2 bits as we want to "drop" the bottom two
  73. * bits.
  74. */
  75. static unsigned int
  76. conf_read(unsigned long addr, unsigned char type1,
  77. struct pci_controller *hose)
  78. {
  79. unsigned long flags;
  80. unsigned long mid = MCPCIA_HOSE2MID(hose->index);
  81. unsigned int stat0, value, cpu;
  82. cpu = smp_processor_id();
  83. local_irq_save(flags);
  84. DBG_CFG(("conf_read(addr=0x%lx, type1=%d, hose=%d)\n",
  85. addr, type1, mid));
  86. /* Reset status register to avoid losing errors. */
  87. stat0 = *(vuip)MCPCIA_CAP_ERR(mid);
  88. *(vuip)MCPCIA_CAP_ERR(mid) = stat0;
  89. mb();
  90. *(vuip)MCPCIA_CAP_ERR(mid);
  91. DBG_CFG(("conf_read: MCPCIA_CAP_ERR(%d) was 0x%x\n", mid, stat0));
  92. mb();
  93. draina();
  94. mcheck_expected(cpu) = 1;
  95. mcheck_taken(cpu) = 0;
  96. mcheck_extra(cpu) = mid;
  97. mb();
  98. /* Access configuration space. */
  99. value = *((vuip)addr);
  100. mb();
  101. mb(); /* magic */
  102. if (mcheck_taken(cpu)) {
  103. mcheck_taken(cpu) = 0;
  104. value = 0xffffffffU;
  105. mb();
  106. }
  107. mcheck_expected(cpu) = 0;
  108. mb();
  109. DBG_CFG(("conf_read(): finished\n"));
  110. local_irq_restore(flags);
  111. return value;
  112. }
  113. static void
  114. conf_write(unsigned long addr, unsigned int value, unsigned char type1,
  115. struct pci_controller *hose)
  116. {
  117. unsigned long flags;
  118. unsigned long mid = MCPCIA_HOSE2MID(hose->index);
  119. unsigned int stat0, cpu;
  120. cpu = smp_processor_id();
  121. local_irq_save(flags); /* avoid getting hit by machine check */
  122. /* Reset status register to avoid losing errors. */
  123. stat0 = *(vuip)MCPCIA_CAP_ERR(mid);
  124. *(vuip)MCPCIA_CAP_ERR(mid) = stat0; mb();
  125. *(vuip)MCPCIA_CAP_ERR(mid);
  126. DBG_CFG(("conf_write: MCPCIA CAP_ERR(%d) was 0x%x\n", mid, stat0));
  127. draina();
  128. mcheck_expected(cpu) = 1;
  129. mcheck_extra(cpu) = mid;
  130. mb();
  131. /* Access configuration space. */
  132. *((vuip)addr) = value;
  133. mb();
  134. mb(); /* magic */
  135. *(vuip)MCPCIA_CAP_ERR(mid); /* read to force the write */
  136. mcheck_expected(cpu) = 0;
  137. mb();
  138. DBG_CFG(("conf_write(): finished\n"));
  139. local_irq_restore(flags);
  140. }
  141. static int
  142. mk_conf_addr(struct pci_bus *pbus, unsigned int devfn, int where,
  143. struct pci_controller *hose, unsigned long *pci_addr,
  144. unsigned char *type1)
  145. {
  146. u8 bus = pbus->number;
  147. unsigned long addr;
  148. DBG_CFG(("mk_conf_addr(bus=%d,devfn=0x%x,hose=%d,where=0x%x,"
  149. " pci_addr=0x%p, type1=0x%p)\n",
  150. bus, devfn, hose->index, where, pci_addr, type1));
  151. /* Type 1 configuration cycle for *ALL* busses. */
  152. *type1 = 1;
  153. if (!pbus->parent) /* No parent means peer PCI bus. */
  154. bus = 0;
  155. addr = (bus << 16) | (devfn << 8) | (where);
  156. addr <<= 5; /* swizzle for SPARSE */
  157. addr |= hose->config_space_base;
  158. *pci_addr = addr;
  159. DBG_CFG(("mk_conf_addr: returning pci_addr 0x%lx\n", addr));
  160. return 0;
  161. }
  162. static int
  163. mcpcia_read_config(struct pci_bus *bus, unsigned int devfn, int where,
  164. int size, u32 *value)
  165. {
  166. struct pci_controller *hose = bus->sysdata;
  167. unsigned long addr, w;
  168. unsigned char type1;
  169. if (mk_conf_addr(bus, devfn, where, hose, &addr, &type1))
  170. return PCIBIOS_DEVICE_NOT_FOUND;
  171. addr |= (size - 1) * 8;
  172. w = conf_read(addr, type1, hose);
  173. switch (size) {
  174. case 1:
  175. *value = __kernel_extbl(w, where & 3);
  176. break;