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.

232 lines
5.2 KiB

  1. //
  2. // MODULE : PNP.C
  3. // PURPOSE : Plug&Play Specific PCI Bios code
  4. // AUTHOR : JBS Yadawa
  5. // CREATED : 7/20/96
  6. //
  7. //
  8. // Copyright (C) 1996 SGS-THOMSON Microelectronics
  9. //
  10. //
  11. // REVISION HISTORY :
  12. //
  13. // DATE :
  14. //
  15. // COMMENTS :
  16. //
  17. #include "stdefs.h"
  18. #include "pnp.h"
  19. //---- PCI BIOS functions
  20. #define PCI_FUNCTION_ID 0xB1
  21. #define PCI_BIOS_PRESENT 0x01
  22. #define FIND_PCI_DEVICE 0x02
  23. #define FIND_PCI_CLASS_CODE 0x03
  24. #define GENERATE_SPECIAL_CYCLE 0x06
  25. #define READ_CONFIG_BYTE 0x08
  26. #define READ_CONFIG_WORD 0x09
  27. #define READ_CONFIG_DWORD 0x0A
  28. #define WRITE_CONFIG_BYTE 0x0B
  29. #define WRITE_CONFIG_WORD 0x0C
  30. #define WRITE_CONFIG_DWORD 0x0D
  31. #define GET_IRQ_ROUTING_OPTIONS 0x0E
  32. #define SET_PCI_IRQ 0x0F
  33. //---- PCI BIOS return codes
  34. #define SUCCESSFUL 0x00
  35. #define NOT_SUCCESSFUL 0x01
  36. #define FUNC_NOT_SUPPORTED 0x81
  37. #define BAD_VENDOR_ID 0x83
  38. #define DEVICE_NOT_FOUND 0x86
  39. #define BAD_REGISTER_NUMBER 0x87
  40. #define SET_FAILED 0x88
  41. #define BUFFER_TOO_SMALL 0x89
  42. static BOOL NEARAPI PCIBIOSPresent(LPBYTE pHardwareMechanism,LPWORD pBIOSVersion, LPBYTE pLastPCIBusNumber);
  43. static int NEARAPI ReadConfigByte(BYTE BusNumber,BYTE DeviceAndFunction,WORD RegNumber,LPBYTE pVal);
  44. static int NEARAPI FindPCIDevice(WORD DeviceID,WORD VendorID,WORD Index,LPBYTE pBusNumber,LPBYTE pDeviceAndFunction);
  45. static int NEARAPI ReadConfigDWORD(BYTE BusNumber,BYTE DeviceAndFunction,WORD RegNumber,LPDWORD lpDwVal);
  46. static int NEARAPI WriteConfigByte(BYTE BusNumber,BYTE DeviceAndFunction,WORD RegNumber,BYTE data);
  47. static BOOL NEARAPI PCIBIOSGetBoardConfig(WORD wDeviceID, WORD wVendorID, LPBYTE pIRQ, LPDWORD Base);
  48. static BOOL NEARAPI PCIBIOSPresent(LPBYTE pHardwareMechanism,LPWORD pBIOSVersion, LPBYTE pLastPCIBusNumber)
  49. {
  50. BYTE BIOSPresentStatus = 0;
  51. BYTE HWMechanism = 0;
  52. BYTE LastPCIBus = 0;
  53. WORD Version = 0;
  54. WORD Signature = 0;
  55. _asm {
  56. mov ah, PCI_FUNCTION_ID
  57. mov al, PCI_BIOS_PRESENT
  58. int 0x1A
  59. mov BIOSPresentStatus, ah
  60. mov HWMechanism, al
  61. mov Version, bx
  62. mov LastPCIBus, cl
  63. mov Signature, dx
  64. }
  65. if (BIOSPresentStatus == 0) {
  66. if ( (((Signature >> 0) & 0xFF) == 'P') &&
  67. (((Signature >> 8) & 0xFF) == 'C')) {
  68. *pHardwareMechanism = HWMechanism;
  69. *pBIOSVersion = Version;
  70. *pLastPCIBusNumber = LastPCIBus;
  71. return TRUE;
  72. }
  73. }
  74. return FALSE;
  75. }
  76. static int NEARAPI FindPCIDevice(WORD DeviceID,WORD VendorID,WORD Index,LPBYTE pBusNumber,LPBYTE pDeviceAndFunction)
  77. {
  78. BYTE ReturnCode;
  79. BYTE BusNbr;
  80. BYTE DevAndFunc;
  81. _asm {
  82. mov ah, PCI_FUNCTION_ID
  83. mov al, FIND_PCI_DEVICE
  84. mov cx, DeviceID
  85. mov dx, VendorID
  86. mov si, Index
  87. int 0x1A
  88. mov BusNbr, bh
  89. mov DevAndFunc, bl
  90. mov ReturnCode, ah
  91. }
  92. *pBusNumber = BusNbr;
  93. *pDeviceAndFunction = DevAndFunc;
  94. return ReturnCode;
  95. }
  96. static int NEARAPI ReadConfigByte(BYTE BusNumber,BYTE DeviceAndFunction,WORD RegNumber,LPBYTE pVal)
  97. {
  98. BYTE Val = 0;
  99. BYTE ReturnCode;
  100. _asm {
  101. mov ah, PCI_FUNCTION_ID
  102. mov al, READ_CONFIG_BYTE
  103. mov bh, BusNumber
  104. mov bl, DeviceAndFunction
  105. mov di, RegNumber
  106. int 0x1A
  107. mov ReturnCode, ah
  108. mov Val, cl
  109. }
  110. *pVal = Val;
  111. return ReturnCode;
  112. }
  113. static int NEARAPI ReadConfigDWORD(BYTE BusNumber,BYTE DeviceAndFunction,WORD RegNumber,LPDWORD lpDwVal)
  114. {
  115. BYTE fourByte[4];
  116. ReadConfigByte (BusNumber, DeviceAndFunction, RegNumber, &fourByte[0]);
  117. ReadConfigByte (BusNumber, DeviceAndFunction, RegNumber+1, &fourByte[1]);
  118. ReadConfigByte (BusNumber, DeviceAndFunction, RegNumber+2, &fourByte[2]);
  119. ReadConfigByte (BusNumber, DeviceAndFunction, RegNumber+3, &fourByte[3]);
  120. *lpDwVal = *((DWORD FAR *)fourByte);
  121. return 0;
  122. }
  123. static int NEARAPI WriteConfigByte(BYTE BusNumber,BYTE DeviceAndFunction,WORD RegNumber,BYTE data)
  124. {
  125. BYTE Val = data;
  126. _asm {
  127. mov ah, PCI_FUNCTION_ID
  128. mov al, WRITE_CONFIG_BYTE
  129. mov bh, BusNumber
  130. mov bl, DeviceAndFunction
  131. mov di, RegNumber
  132. mov cl, Val
  133. mov ch, 0
  134. int 0x1A
  135. }
  136. return 0;
  137. }
  138. static BOOL NEARAPI PCIBIOSGetBoardConfig(WORD wDeviceID, WORD wVendorID, LPBYTE pIRQ, LPDWORD Base)
  139. {
  140. BYTE HardwareMechanism;
  141. WORD BIOSVersion;
  142. BYTE LastPCIBusNumber;
  143. BYTE BusNumber;
  144. BYTE DeviceAndFunction;
  145. DWORD ReadValue;
  146. //---- Test PCI BIOS presence
  147. if (!PCIBIOSPresent(&HardwareMechanism, &BIOSVersion, &LastPCIBusNumber)) {
  148. return FALSE;
  149. }
  150. else {
  151. }
  152. //---- Get board information
  153. if (!FindPCIDevice(wDeviceID, wVendorID, 0, &BusNumber, &DeviceAndFunction) == 0) {
  154. return FALSE;
  155. }
  156. //---- Get the base address for PCI9060
  157. if (ReadConfigDWORD(BusNumber, DeviceAndFunction, 0x10, &ReadValue) == 0)
  158. {
  159. if (ReadValue == 0) {
  160. return FALSE;
  161. }
  162. *Base = ReadValue;
  163. }
  164. else {
  165. return FALSE;
  166. }
  167. //---- Get the IRQ line
  168. if (ReadConfigByte(BusNumber, DeviceAndFunction, 0x3C, pIRQ) != 0)
  169. {
  170. return FALSE;
  171. }
  172. // Set the latency
  173. WriteConfigByte(BusNumber, DeviceAndFunction, 0x0D, 0x80);
  174. return TRUE;
  175. }
  176. BOOL FARAPI HostGetBoardConfig(WORD wDeviceID,WORD wVendorID,LPBYTE pIRQ,LPDWORD Base)
  177. {
  178. if (!PCIBIOSGetBoardConfig(wDeviceID,wVendorID,pIRQ,Base))
  179. {
  180. return FALSE;
  181. }
  182. return TRUE;
  183. }
  184. #if 0
  185. int main()
  186. {
  187. BYTE irq;
  188. DWORD base;
  189. if(HostGetBoardConfig(0x6120, 0x11de, &irq, &base))
  190. {
  191. printf("Irq = %d, Base = %lx\n", irq, base);
  192. }
  193. else
  194. {
  195. printf("Board not found!!\n");
  196. }
  197. }
  198. #endif
  199.