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.

285 lines
6.9 KiB

  1. #if 1 // The following includes are used when building with the microsoft internal build tree.
  2. #include <nt.h>
  3. #include <ntrtl.h>
  4. #include <nturtl.h>
  5. #include <windows.h>
  6. #else // These headers are used when building with the microsoft DDK.
  7. #include <ntddk.h>
  8. #include <windef.h>
  9. #include <winerror.h>
  10. #endif
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <ntddnetd.h>
  15. #include <ncnet.h>
  16. #include <netdet.h>
  17. BOOLEAN
  18. R81wDetInit(
  19. IN HANDLE hModule,
  20. IN DWORD dwReason,
  21. IN DWORD dwReserved
  22. )
  23. /*++
  24. Routine Description:
  25. This routine is the entry point into the detection dll.
  26. This routine only return "TRUE".
  27. ++*/
  28. {
  29. return (TRUE);
  30. }
  31. ULONG
  32. R81wNextIoAddress(
  33. IN ULONG IoBaseAddress
  34. )
  35. /*++
  36. Routine Description:
  37. This routine provide next I/O address for detect PC-9801-111.
  38. ++*/
  39. {
  40. switch(IoBaseAddress){
  41. case 0x0888:
  42. return (0x1888);
  43. case 0x1888:
  44. return (0x2888);
  45. case 0x2888:
  46. return (0x3888);
  47. default:
  48. return (0xffff);
  49. }
  50. }
  51. NTSTATUS
  52. FindR81wAdapter(
  53. OUT PMND_ADAPTER_INFO *pDetectedAdapter,
  54. IN INTERFACE_TYPE InterfaceType,
  55. IN ULONG BusNumber,
  56. IN ULONG IoBaseAddress,
  57. IN PWSTR pPnpId
  58. )
  59. {
  60. NTSTATUS NtStatus;
  61. UCHAR Data;
  62. USHORT CheckSum = 0;
  63. USHORT StoredCheckSum;
  64. UINT Place;
  65. UCHAR Interrupt = 0;
  66. HANDLE TrapHandle;
  67. UCHAR InterruptList[8];
  68. UCHAR ResultList[8] = {0};
  69. UINT cResources;
  70. UINT c;
  71. UCHAR Value;
  72. ULONG MemoryBaseAddress = 0;
  73. do{
  74. // check I/O port range.
  75. NtStatus = NDetCheckPortUsage(InterfaceType,
  76. BusNumber,
  77. IoBaseAddress,
  78. 0x4);
  79. if(!NT_SUCCESS(NtStatus)){
  80. #if DBG
  81. DbgPrint("FindR81wAdapter : Port range in use. IoBaseAddress = %x\n", IoBaseAddress);
  82. #endif
  83. break;
  84. }
  85. // check board ID.
  86. // 111's ID is 0x67.
  87. NDetWritePortUchar(InterfaceType,
  88. BusNumber,
  89. IoBaseAddress + 0x003,
  90. 0x88);
  91. NDetReadPortUchar(InterfaceType,
  92. BusNumber,
  93. IoBaseAddress + 0x001,
  94. &Value);
  95. if(Value != 0x67){
  96. NtStatus = STATUS_NOT_FOUND;
  97. #if DBG
  98. DbgPrint("R81WDET : Board ID is invalid.\n");
  99. DbgPrint("R81WDET : I/O port is %x.\n",IoBaseAddress);
  100. #endif
  101. break;
  102. }
  103. // check interrupt.
  104. InterruptList[0] = 3;
  105. InterruptList[1] = 5;
  106. InterruptList[2] = 6;
  107. InterruptList[3] = 9;
  108. InterruptList[4] = 10;
  109. InterruptList[5] = 12;
  110. InterruptList[6] = 13;
  111. NtStatus = NDetSetInterruptTrap(InterfaceType,
  112. BusNumber,
  113. &TrapHandle,
  114. InterruptList,
  115. 7);
  116. if(NT_SUCCESS(NtStatus)){
  117. NtStatus = NDetQueryInterruptTrap(TrapHandle, ResultList, 7);
  118. NtStatus = NDetRemoveInterruptTrap(TrapHandle);
  119. if(!NT_SUCCESS(NtStatus)){
  120. #if DBG
  121. DbgPrint("R81WDET : RemoveInterrupt failed.");
  122. #endif
  123. break;
  124. }
  125. for(c=0 ; c<7 ; c++){
  126. if((ResultList[c] == 1) || (ResultList[c] == 2)){
  127. Interrupt = InterruptList[c];
  128. break;
  129. }
  130. }
  131. }else{
  132. #if DBG
  133. DbgPrint("R81WDET : SetInterrupt failed\n");
  134. #endif
  135. }
  136. for(c=0 ; c<16 ; c++){
  137. MemoryBaseAddress = 0xc0000 + (0x2000 * c);
  138. if(MemoryBaseAddress == 0xd0000){
  139. continue;
  140. }
  141. NtStatus = NDetCheckMemoryUsage(
  142. InterfaceType,
  143. BusNumber,
  144. MemoryBaseAddress,
  145. 0x2000);
  146. if (NT_SUCCESS(NtStatus))
  147. {
  148. break;
  149. }
  150. }
  151. // Allocate the adapter information.
  152. NtStatus = NetDetectAllocAdapterInfo(pDetectedAdapter,
  153. InterfaceType,
  154. BusNumber,
  155. pPnpId,
  156. 0,
  157. 0,
  158. 0,
  159. 2);
  160. if (!NT_SUCCESS(NtStatus)){
  161. #if DBG
  162. DbgPrint("FindR81wAdapter: Unable to allocate adapter info\n");
  163. #endif
  164. break;
  165. }
  166. #if DBG
  167. DbgPrint("I/O port is %x\n",IoBaseAddress);
  168. DbgPrint("IRQ is %x\n",Interrupt);
  169. DbgPrint("Memory address is %x\n",MemoryBaseAddress);
  170. #endif
  171. // Initialize the resources.
  172. NetDetectInitializeResource(*pDetectedAdapter,
  173. 0,
  174. MndResourcePort,
  175. IoBaseAddress,
  176. 0x4);
  177. if(Interrupt != 0){
  178. NetDetectInitializeResource(*pDetectedAdapter,
  179. 1,
  180. MndResourceInterrupt,
  181. Interrupt,
  182. MND_RESOURCE_INTERRUPT_LATCHED);
  183. }
  184. if(MemoryBaseAddress != 0){
  185. NetDetectInitializeResource(*pDetectedAdapter,
  186. 1,
  187. MndResourceMemory,
  188. MemoryBaseAddress,
  189. 0x2000);
  190. }
  191. NtStatus = STATUS_SUCCESS;
  192. }while(FALSE);
  193. return (NtStatus);
  194. }
  195. NTSTATUS
  196. WINAPI
  197. FindAdapterHandler(
  198. IN OUT PMND_ADAPTER_INFO *pDetectedAdapter,
  199. IN INTERFACE_TYPE InterfaceType,
  200. IN ULONG BusNumber,
  201. IN PDET_ADAPTER_INFO pAdapterInfo,
  202. IN PDET_CONTEXT pDetContext
  203. )
  204. /*++
  205. Routine Description:
  206. Arguments:
  207. Return Value:
  208. --*/
  209. {
  210. NTSTATUS NtStatus;
  211. ULONG IoBaseAddress;
  212. if(InterfaceType != Isa){
  213. return(STATUS_INVALID_PARAMETER);
  214. }
  215. // Are we looking for the first adapter?
  216. if (fDET_CONTEXT_FIND_FIRST == (pDetContext->Flags & fDET_CONTEXT_FIND_FIRST)){
  217. // Initialize the context information so that we start detecting
  218. // at the initialize port range.
  219. pDetContext->ISA.IoBaseAddress = 0x0888;
  220. }
  221. for (IoBaseAddress = pDetContext->ISA.IoBaseAddress;
  222. IoBaseAddress <= 0x3888;
  223. IoBaseAddress = R81wNextIoAddress(IoBaseAddress)){
  224. // Look for the PC-9801-111 adapter at the current port.
  225. NtStatus = FindR81wAdapter(pDetectedAdapter,
  226. InterfaceType,
  227. BusNumber,
  228. IoBaseAddress,
  229. pAdapterInfo->PnPId);
  230. if (NT_SUCCESS(NtStatus)){
  231. // We found an adapter. Save the next IO address to check.
  232. #if DBG
  233. DbgPrint("R81WDET : We found an PC-9801-111\n");
  234. #endif
  235. pDetContext->ISA.IoBaseAddress = R81wNextIoAddress(IoBaseAddress);
  236. break;
  237. }
  238. }
  239. if (0xffff == IoBaseAddress){
  240. NtStatus = STATUS_NO_MORE_ENTRIES;
  241. }
  242. return(NtStatus);
  243. }