ops-bridge.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1999, 2000, 04, 06 Ralf Baechle (ralf@linux-mips.org)
  7. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  8. */
  9. #include <linux/pci.h>
  10. #include <asm/paccess.h>
  11. #include <asm/pci/bridge.h>
  12. #include <asm/sn/arch.h>
  13. #include <asm/sn/intr.h>
  14. #include <asm/sn/sn0/hub.h>
  15. /*
  16. * The Bridge ASIC supports both type 0 and type 1 access. Type 1 is
  17. * not really documented, so right now I can't write code which uses it.
  18. * Therefore we use type 0 accesses for now even though they won't work
  19. * correcly for PCI-to-PCI bridges.
  20. *
  21. * The function is complicated by the ultimate brokeness of the IOC3 chip
  22. * which is used in SGI systems. The IOC3 can only handle 32-bit PCI
  23. * accesses and does only decode parts of it's address space.
  24. */
  25. static int pci_conf0_read_config(struct pci_bus *bus, unsigned int devfn,
  26. int where, int size, u32 * value)
  27. {
  28. struct bridge_controller *bc = BRIDGE_CONTROLLER(bus);
  29. bridge_t *bridge = bc->base;
  30. int slot = PCI_SLOT(devfn);
  31. int fn = PCI_FUNC(devfn);
  32. volatile void *addr;
  33. u32 cf, shift, mask;
  34. int res;
  35. addr = &bridge->b_type0_cfg_dev[slot].f[fn].c[PCI_VENDOR_ID];
  36. if (get_dbe(cf, (u32 *) addr))
  37. return PCIBIOS_DEVICE_NOT_FOUND;
  38. /*
  39. * IOC3 is fucked fucked beyond believe ... Don't even give the
  40. * generic PCI code a chance to look at it for real ...
  41. */
  42. if (cf == (PCI_VENDOR_ID_SGI | (PCI_DEVICE_ID_SGI_IOC3 << 16)))
  43. goto oh_my_gawd;
  44. addr = &bridge->b_type0_cfg_dev[slot].f[fn].c[where ^ (4 - size)];
  45. if (size == 1)
  46. res = get_dbe(*value, (u8 *) addr);
  47. else if (size == 2)
  48. res = get_dbe(*value, (u16 *) addr);
  49. else
  50. res = get_dbe(*value, (u32 *) addr);
  51. return res ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
  52. oh_my_gawd:
  53. /*
  54. * IOC3 is fucked fucked beyond believe ... Don't even give the
  55. * generic PCI code a chance to look at the wrong register.
  56. */
  57. if ((where >= 0x14 && where < 0x40) || (where >= 0x48)) {
  58. *value = 0;
  59. return PCIBIOS_SUCCESSFUL;
  60. }
  61. /*
  62. * IOC3 is fucked fucked beyond believe ... Don't try to access
  63. * anything but 32-bit words ...
  64. */
  65. addr = &bridge->b_type0_cfg_dev[slot].f[fn].l[where >> 2];
  66. if (get_dbe(cf, (u32 *) addr))
  67. return PCIBIOS_DEVICE_NOT_FOUND;
  68. shift = ((where & 3) << 3);
  69. mask = (0xffffffffU >> ((4 - size) << 3));
  70. *value = (cf >> shift) & mask;
  71. return PCIBIOS_SUCCESSFUL;
  72. }
  73. static int pci_conf1_read_config(struct pci_bus *bus, unsigned int devfn,
  74. int where, int size, u32 * value)
  75. {
  76. struct bridge_controller *bc = BRIDGE_CONTROLLER(bus);
  77. bridge_t *bridge = bc->base;
  78. int busno = bus->number;
  79. int slot = PCI_SLOT(devfn);
  80. int fn = PCI_FUNC(devfn);
  81. volatile void *addr;
  82. u32 cf, shift, mask;
  83. int res;
  84. bridge->b_pci_cfg = (busno << 16) | (slot << 11);
  85. addr = &bridge->b_type1_cfg.c[(fn << 8) | PCI_VENDOR_ID];
  86. if (get_dbe(cf, (u32 *) addr))
  87. return PCIBIOS_DEVICE_NOT_FOUND;
  88. /*
  89. * IOC3 is fucked fucked beyond believe ... Don't even give the
  90. * generic PCI code a chance to look at it for real ...
  91. */
  92. if (cf == (PCI_VENDOR_ID_SGI | (PCI_DEVICE_ID_SGI_IOC3 << 16)))
  93. goto oh_my_gawd;
  94. bridge->b_pci_cfg = (busno << 16) | (slot << 11);
  95. addr = &bridge->b_type1_cfg.c[(fn << 8) | (where ^ (4 - size))];
  96. if (size == 1)
  97. res = get_dbe(*value, (u8 *) addr);
  98. else if (size == 2)
  99. res = get_dbe(*value, (u16 *) addr);
  100. else
  101. res = get_dbe(*value, (u32 *) addr);
  102. return res ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
  103. oh_my_gawd:
  104. /*
  105. * IOC3 is fucked fucked beyond believe ... Don't even give the
  106. * generic PCI code a chance to look at the wrong register.
  107. */
  108. if ((where >= 0x14 && where < 0x40) || (where >= 0x48)) {
  109. *value = 0;
  110. return PCIBIOS_SUCCESSFUL;
  111. }
  112. /*
  113. * IOC3 is fucked fucked beyond believe ... Don't try to access
  114. * anything but 32-bit words ...
  115. */
  116. bridge->b_pci_cfg = (busno << 16) | (slot << 11);
  117. addr = &bridge->b_type1_cfg.c[(fn << 8) | where];
  118. if (get_dbe(cf, (u32 *) addr))
  119. return PCIBIOS_DEVICE_NOT_FOUND;
  120. shift = ((where & 3) << 3);
  121. mask = (0xffffffffU >> ((4 - size) << 3));
  122. *value = (cf >> shift) & mask;
  123. return PCIBIOS_SUCCESSFUL;
  124. }
  125. static int pci_read_config(struct pci_bus *bus, unsigned int devfn,
  126. int where, int size, u32 * value)
  127. {
  128. if (bus->number > 0)
  129. return pci_conf1_read_config(bus, devfn, where, size, value);
  130. return pci_conf0_read_config(bus, devfn, where, size, value);
  131. }
  132. static int pci_conf0_write_config(struct pci_bus *bus, unsigned int devfn,
  133. int where, int size, u32 value)
  134. {
  135. struct bridge_controller *bc = BRIDGE_CONTROLLER(bus);
  136. bridge_t *bridge = bc->base;
  137. int slot = PCI_SLOT(devfn);
  138. int fn = PCI_FUNC(devfn);
  139. volatile void *addr;
  140. u32 cf, shift, mask, smask;
  141. int res;
  142. addr = &bridge->b_type0_cfg_dev[slot].f[fn].c[PCI_VENDOR_ID];
  143. if (get_dbe(cf, (u32 *) addr))
  144. return PCIBIOS_DEVICE_NOT_FOUND;
  145. /*
  146. * IOC3 is fucked fucked beyond believe ... Don't even give the
  147. * generic PCI code a chance to look at it for real ...
  148. */
  149. if (cf == (PCI_VENDOR_ID_SGI | (PCI_DEVICE_ID_SGI_IOC3 << 16)))
  150. goto oh_my_gawd;
  151. addr = &bridge->b_type0_cfg_dev[slot].f[fn].c[where ^ (4 - size)];
  152. if (size == 1) {
  153. res = put_dbe(value, (u8 *) addr);
  154. } else if (size == 2) {
  155. res = put_dbe(value, (u16 *) addr);
  156. } else {
  157. res = put_dbe(value, (u32 *) addr);
  158. }
  159. if (res)
  160. return PCIBIOS_DEVICE_NOT_FOUND;
  161. return PCIBIOS_SUCCESSFUL;
  162. oh_my_gawd:
  163. /*
  164. * IOC3 is fucked fucked beyond believe ... Don't even give the
  165. * generic PCI code a chance to touch the wrong register.
  166. */
  167. if ((where >= 0x14 && where < 0x40) || (where >= 0x48))
  168. return PCIBIOS_SUCCESSFUL;
  169. /*
  170. * IOC3 is fucked fucked beyond believe ... Don't try to access
  171. * anything but 32-bit words ...
  172. */
  173. addr = &bridge->b_type0_cfg_dev[slot].f[fn].l[where >> 2];
  174. if (get_dbe(cf, (u32 *) addr))
  175. return PCIBIOS_DEVICE_NOT_FOUND;
  176. shift = ((where & 3) << 3);
  177. mask = (0xffffffffU >> ((4 - size) << 3));
  178. smask = mask << shift;
  179. cf = (cf & ~smask) | ((value & mask) << shift);
  180. if (put_dbe(cf, (u32 *) addr))
  181. return PCIBIOS_DEVICE_NOT_FOUND;
  182. return PCIBIOS_SUCCESSFUL;
  183. }
  184. static int pci_conf1_write_config(struct pci_bus *bus, unsigned int devfn,
  185. int where, int size, u32 value)
  186. {
  187. struct bridge_controller *bc = BRIDGE_CONTROLLER(bus);
  188. bridge_t *bridge = bc->base;
  189. int slot = PCI_SLOT(devfn);
  190. int fn = PCI_FUNC(devfn);
  191. int busno = bus->number;
  192. volatile void *addr;
  193. u32 cf, shift, mask, smask;
  194. int res;
  195. bridge->b_pci_cfg = (busno << 16) | (slot << 11);
  196. addr = &bridge->b_type1_cfg.c[(fn << 8) | PCI_VENDOR_ID];
  197. if (get_dbe(cf, (u32 *) addr))
  198. return PCIBIOS_DEVICE_NOT_FOUND;
  199. /*
  200. * IOC3 is fucked fucked beyond believe ... Don't even give the
  201. * generic PCI code a chance to look at it for real ...
  202. */
  203. if (cf == (PCI_VENDOR_ID_SGI | (PCI_DEVICE_ID_SGI_IOC3 << 16)))
  204. goto oh_my_gawd;
  205. addr = &bridge->b_type1_cfg.c[(fn << 8) | (where ^ (4 - size))];
  206. if (size == 1) {
  207. res = put_dbe(value, (u8 *) addr);
  208. } else if (size == 2) {
  209. res = put_dbe(value, (u16 *) addr);
  210. } else {
  211. res = put_dbe(value, (u32 *) addr);
  212. }
  213. if (res)
  214. return PCIBIOS_DEVICE_NOT_FOUND;
  215. return PCIBIOS_SUCCESSFUL;
  216. oh_my_gawd:
  217. /*
  218. * IOC3 is fucked fucked beyond believe ... Don't even give the
  219. * generic PCI code a chance to touch the wrong register.
  220. */
  221. if ((where >= 0x14 && where < 0x40) || (where >= 0x48))
  222. return PCIBIOS_SUCCESSFUL;
  223. /*
  224. * IOC3 is fucked fucked beyond believe ... Don't try to access
  225. * anything but 32-bit words ...
  226. */
  227. addr = &bridge->b_type0_cfg_dev[slot].f[fn].l[where >> 2];
  228. if (get_dbe(cf, (u32 *) addr))
  229. return PCIBIOS_DEVICE_NOT_FOUND;
  230. shift = ((where & 3) << 3);
  231. mask = (0xffffffffU >> ((4 - size) << 3));
  232. smask = mask << shift;
  233. cf = (cf & ~smask) | ((value & mask) << shift);
  234. if (put_dbe(cf, (u32 *) addr))
  235. return PCIBIOS_DEVICE_NOT_FOUND;
  236. return PCIBIOS_SUCCESSFUL;
  237. }
  238. static int pci_write_config(struct pci_bus *bus, unsigned int devfn,
  239. int where, int size, u32 value)
  240. {
  241. if (bus->number > 0)
  242. return pci_conf1_write_config(bus, devfn, where, size, value);
  243. return pci_conf0_write_config(bus, devfn, where, size, value);
  244. }
  245. struct pci_ops bridge_pci_ops = {
  246. .read = pci_read_config,
  247. .write = pci_write_config,
  248. };