ops-bridge.c 8.5 KB

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