Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

300 lines
7.6 KiB

  1. /*
  2. * OptiFireStar.C - OPTI FIRESTAR PCI chipset routines.
  3. *
  4. * Notes:
  5. * Algorithms from OPTI FIRESTAR Data Sheet
  6. * Opti contact: William@unixgate.opti.com
  7. *
  8. */
  9. #include "local.h"
  10. /****************************************************************************
  11. *
  12. * OptiFireStarSetIRQ - Set a OPTI FIRESTAR PCI link to a specific IRQ
  13. *
  14. * Exported.
  15. *
  16. * ENTRY: bIRQNumber is the new IRQ to be used.
  17. *
  18. * bLink is the Link to be set.
  19. *
  20. * EXIT: Standard PCIMP return value.
  21. *
  22. ***************************************************************************/
  23. PCIMPRET CDECL
  24. OptiFireStarSetIRQ(UCHAR bIRQNumber, UCHAR bLink)
  25. {
  26. UCHAR bData, bOffset;
  27. switch (bLink & 0x07)
  28. {
  29. case 0:
  30. if (bLink == 0)
  31. return (PCIMP_FAILURE);
  32. else
  33. return (PCIMP_INVALID_LINK);
  34. case 1:
  35. //
  36. // FireStar IRQ
  37. //
  38. bLink = (UCHAR)((bLink & 0x70) >> 4);
  39. bData = ReadConfigUchar(bBusPIC, bDevFuncPIC, (UCHAR)(0xB0 + bLink));
  40. bData = (bData & 0xf0) | bIRQNumber;
  41. if (bIRQNumber)
  42. bData |= 0x10;
  43. WriteConfigUchar(bBusPIC, bDevFuncPIC, (UCHAR)(0xB0 + bLink), bData);
  44. return (PCIMP_SUCCESS);
  45. case 2:
  46. //
  47. // FireStar PIO or Serial IRQ
  48. //
  49. case 3:
  50. //
  51. // FireBridge INTs
  52. //
  53. bOffset = (UCHAR)((bLink >> 5) & 1) + 0xB8;
  54. bData = ReadConfigUchar(bBusPIC, bDevFuncPIC, bOffset);
  55. if (bLink & (1<<4)) {
  56. bData &= 0x0f;
  57. bData |= (bIRQNumber<<4);
  58. }
  59. else {
  60. bData &= 0xf0;
  61. bData |= bIRQNumber;
  62. }
  63. WriteConfigUchar(bBusPIC, bDevFuncPIC, bOffset, bData);
  64. return (PCIMP_SUCCESS);
  65. default:
  66. return (PCIMP_INVALID_LINK);
  67. }
  68. return (PCIMP_FAILURE);
  69. }
  70. /****************************************************************************
  71. *
  72. * OptiFireStarGetIRQ - Get the IRQ of a OPTI FIRESTAR PCI link
  73. *
  74. * Exported.
  75. *
  76. * ENTRY: pbIRQNumber is the buffer to fill.
  77. *
  78. * bLink is the Link to be read.
  79. *
  80. * EXIT: Standard PCIMP return value.
  81. *
  82. ***************************************************************************/
  83. PCIMPRET CDECL
  84. OptiFireStarGetIRQ(PUCHAR pbIRQNumber, UCHAR bLink)
  85. {
  86. UCHAR bData, bOffset;
  87. switch (bLink & 0x07)
  88. {
  89. case 0:
  90. //
  91. // Valid link?
  92. //
  93. if (bLink == 0)
  94. return (PCIMP_FAILURE);
  95. else
  96. return (PCIMP_INVALID_LINK);
  97. case 1:
  98. //
  99. // FireStar IRQ
  100. //
  101. bLink = (UCHAR)((bLink & 0x70) >> 4);
  102. bData = ReadConfigUchar(bBusPIC, bDevFuncPIC, (UCHAR)(0xB0 + bLink));
  103. *pbIRQNumber = (bData & 0x0f);
  104. return (PCIMP_SUCCESS);
  105. case 2:
  106. //
  107. // FireStar PIO or Serial IRQ
  108. //
  109. case 3:
  110. //
  111. // FireBridge INTs
  112. //
  113. bOffset = (UCHAR)((bLink >> 5) & 1) + 0xB8;
  114. bData = ReadConfigUchar(bBusPIC, bDevFuncPIC, bOffset);
  115. if (bLink & (1<<4))
  116. bData >>= 4;
  117. *pbIRQNumber = bData & 0x0f;
  118. return (PCIMP_SUCCESS);
  119. default:
  120. return (PCIMP_INVALID_LINK);
  121. }
  122. return (PCIMP_FAILURE);
  123. }
  124. /****************************************************************************
  125. *
  126. * OptiViperSetTrigger - Set the IRQ triggering values for the OptiViper
  127. *
  128. * Exported.
  129. *
  130. * ENTRY: ulTrigger has bits set for Level triggered IRQs.
  131. *
  132. * EXIT: Standard PCIMP return value.
  133. *
  134. ***************************************************************************/
  135. PCIMPRET CDECL
  136. OptiFireStarSetTrigger(ULONG ulTrigger)
  137. {
  138. ULONG i;
  139. UCHAR bData;
  140. for (i = 0; i < 8; i++)
  141. {
  142. UCHAR bTemp;
  143. bData = ReadConfigUchar(bBusPIC, bDevFuncPIC, (UCHAR)(0xB0+i));
  144. bTemp = bData & 0x0F;
  145. if (bTemp && (ulTrigger & (1 << bTemp)))
  146. {
  147. bData |= 0x10;
  148. }
  149. else
  150. {
  151. bData &= ~0x10;
  152. }
  153. WriteConfigUchar(bBusPIC, bDevFuncPIC, (UCHAR)(0xB0+i), bData);
  154. }
  155. return (PCIMP_SUCCESS);
  156. }
  157. /****************************************************************************
  158. *
  159. * OptiViperGetTrigger - Get the IRQ triggering values for the OptiViper
  160. *
  161. * Exported.
  162. *
  163. * ENTRY: pulTrigger will have bits set for Level triggered IRQs.
  164. *
  165. * EXIT: Standard PCIMP return value.
  166. *
  167. ***************************************************************************/
  168. PCIMPRET CDECL
  169. OptiFireStarGetTrigger(PULONG pulTrigger)
  170. {
  171. ULONG i;
  172. UCHAR bData;
  173. //
  174. // Assume all are edge.
  175. //
  176. *pulTrigger = 0;
  177. //
  178. // Check PCIDV1 registers B0-B7.
  179. //
  180. for (i = 0; i < 8; i++)
  181. {
  182. bData = (UCHAR)(ReadConfigUchar(bBusPIC, bDevFuncPIC, (UCHAR)(0xB0 + i)) & 0x1F);
  183. if (bData & 0x10)
  184. *pulTrigger |= (1 << (bData & 0x0f));
  185. }
  186. //
  187. // Check PCIDV1 registers B8-B9.
  188. //
  189. for (i = 0; i < 2; i++)
  190. {
  191. bData = ReadConfigUchar(bBusPIC, bDevFuncPIC, (UCHAR)(0xB8 + i));
  192. *pulTrigger |= (1 << (bData & 0x0F));
  193. bData >>= 4;
  194. *pulTrigger |= (1 << (bData & 0x0F));
  195. }
  196. return (PCIMP_SUCCESS);
  197. }
  198. /****************************************************************************
  199. *
  200. * OptiFireStarValidateTable - Validate an IRQ table
  201. *
  202. * Exported.
  203. *
  204. * ENTRY: piihIRQInfoHeader points to an IRQInfoHeader followed
  205. * by an IRQ Routing Table.
  206. *
  207. * ulFlags are PCIMP_VALIDATE flags.
  208. *
  209. * EXIT: Standard PCIMP return value.
  210. *
  211. ***************************************************************************/
  212. #ifdef ALLOC_PRAGMA
  213. PCIMPRET CDECL
  214. OptiFireStarValidateTable(PIRQINFOHEADER piihIRQInfoHeader, ULONG ulFlags);
  215. #pragma alloc_text(PAGE, OptiFireStarValidateTable)
  216. #endif //ALLOC_PRAGMA
  217. PCIMPRET CDECL
  218. OptiFireStarValidateTable(PIRQINFOHEADER piihIRQInfoHeader, ULONG ulFlags)
  219. {
  220. PIRQINFO pii=(PIRQINFO)(((PUCHAR) piihIRQInfoHeader)+sizeof(IRQINFOHEADER));
  221. ULONG i, j;
  222. ULONG cEntries=(piihIRQInfoHeader->TableSize-sizeof(IRQINFOHEADER))/sizeof(IRQINFO);
  223. PAGED_CODE();
  224. for (i=0; i<cEntries; i++) {
  225. for (j=0; j<4; j++) {
  226. switch (pii->PinInfo[j].Link & 0x07)
  227. {
  228. case 0:
  229. //
  230. // Valid link?
  231. //
  232. if (pii->PinInfo[j].Link & 0x70)
  233. return (PCIMP_FAILURE);
  234. break;
  235. case 1:
  236. //
  237. // FireStar IRQ
  238. //
  239. break;
  240. case 2:
  241. //
  242. // FireStar PIO or Serial IRQ
  243. //
  244. case 3:
  245. //
  246. // FireBridge INTs
  247. //
  248. if ((pii->PinInfo[j].Link & 0x70) > 0x30)
  249. return (PCIMP_FAILURE);
  250. break;
  251. default:
  252. return (PCIMP_FAILURE);
  253. }
  254. }
  255. pii++;
  256. }
  257. return(i? PCIMP_SUCCESS : PCIMP_FAILURE);
  258. }