Leaked source code of windows server 2003
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.

286 lines
7.3 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. NibcDetInit(
  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. NibcNextIoAddress(
  33. IN ULONG IoBaseAddress
  34. )
  35. /*++
  36. Routine Description:
  37. This routine provide next I/O address for detect PC-9801-83/84/103/104.
  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. FindNibcAdapter(
  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("FindNibcAdapter : Port range in use. IoBaseAddress = %x\n", IoBaseAddress);
  82. #endif
  83. break;
  84. }
  85. // check board ID.
  86. // 83/84's ID is 0x05.
  87. NDetWritePortUchar(InterfaceType,
  88. BusNumber,
  89. IoBaseAddress + 0x003,
  90. 0x88);
  91. NDetReadPortUchar(InterfaceType,
  92. BusNumber,
  93. IoBaseAddress + 0x001,
  94. &Value);
  95. if(Value != 0x05){
  96. NtStatus = STATUS_NOT_FOUND;
  97. #if DBG
  98. DbgPrint("ID is invalid. ID = %x\n",Value);
  99. #endif
  100. break;
  101. }
  102. // check interrupt.
  103. InterruptList[0] = 3;
  104. InterruptList[1] = 5;
  105. InterruptList[2] = 6;
  106. InterruptList[3] = 9;
  107. InterruptList[4] = 10;
  108. InterruptList[5] = 12;
  109. InterruptList[6] = 13;
  110. NtStatus = NDetSetInterruptTrap(InterfaceType,
  111. BusNumber,
  112. &TrapHandle,
  113. InterruptList,
  114. 7);
  115. if(NT_SUCCESS(NtStatus)){
  116. NtStatus = NDetQueryInterruptTrap(TrapHandle, ResultList, 7);
  117. NtStatus = NDetRemoveInterruptTrap(TrapHandle);
  118. if(!NT_SUCCESS(NtStatus)){
  119. #if DBG
  120. DbgPrint("NDetRemoveInterruptTrap failed. Status = %x\n",NtStatus);
  121. #endif
  122. break;
  123. }
  124. for(c=0 ; c<7 ; c++){
  125. if((ResultList[c] == 1) || (ResultList[c] == 2)){
  126. Interrupt = InterruptList[c];
  127. break;
  128. }
  129. }
  130. }else{
  131. #if DBG
  132. DbgPrint("NDetSetInterruptTrap failed. Status = %x\n",NtStatus);
  133. #endif
  134. }
  135. for(c=0 ; c<16 ; c++){
  136. MemoryBaseAddress = 0xc0000 + (0x2000 * c);
  137. if(MemoryBaseAddress == 0xd0000){
  138. continue;
  139. }
  140. NtStatus = NDetCheckMemoryUsage(
  141. InterfaceType,
  142. BusNumber,
  143. MemoryBaseAddress,
  144. 0x2000);
  145. if (NT_SUCCESS(NtStatus))
  146. {
  147. #if DBG
  148. DbgPrint("NDetCheckMemoryUsage success. Address = %x\n",MemoryBaseAddress);
  149. #endif
  150. break;
  151. }
  152. }
  153. // Allocate the adapter information.
  154. NtStatus = NetDetectAllocAdapterInfo(pDetectedAdapter,
  155. InterfaceType,
  156. BusNumber,
  157. pPnpId,
  158. 0,
  159. 0,
  160. 0,
  161. 2);
  162. if (!NT_SUCCESS(NtStatus)){
  163. #if DBG
  164. DbgPrint("NetDetectAllocAdapterInfo failed. Status = %x\n",NtStatus);
  165. #endif
  166. break;
  167. }
  168. #if DBG
  169. DbgPrint("IoBaseAddress = %x\n",IoBaseAddress);
  170. DbgPrint("Interrupt = %x\n",Interrupt);
  171. DbgPrint("MemoryAddress = %x\n",MemoryBaseAddress);
  172. #endif
  173. // Initialize the resources.
  174. NetDetectInitializeResource(*pDetectedAdapter,
  175. 0,
  176. MndResourcePort,
  177. IoBaseAddress,
  178. 0x4);
  179. if(Interrupt != 0){
  180. NetDetectInitializeResource(*pDetectedAdapter,
  181. 1,
  182. MndResourceInterrupt,
  183. Interrupt,
  184. MND_RESOURCE_INTERRUPT_LATCHED);
  185. }
  186. if(MemoryBaseAddress != 0){
  187. NetDetectInitializeResource(*pDetectedAdapter,
  188. 1,
  189. MndResourceMemory,
  190. MemoryBaseAddress,
  191. 0x2000);
  192. }
  193. NtStatus = STATUS_SUCCESS;
  194. }while(FALSE);
  195. return (NtStatus);
  196. }
  197. NTSTATUS
  198. WINAPI
  199. FindAdapterHandler(
  200. IN OUT PMND_ADAPTER_INFO *pDetectedAdapter,
  201. IN INTERFACE_TYPE InterfaceType,
  202. IN ULONG BusNumber,
  203. IN PDET_ADAPTER_INFO pAdapterInfo,
  204. IN PDET_CONTEXT pDetContext
  205. )
  206. /*++
  207. Routine Description:
  208. Arguments:
  209. Return Value:
  210. --*/
  211. {
  212. NTSTATUS NtStatus;
  213. ULONG IoBaseAddress;
  214. if(InterfaceType != Isa){
  215. return(STATUS_INVALID_PARAMETER);
  216. }
  217. // Are we looking for the first adapter?
  218. if (fDET_CONTEXT_FIND_FIRST == (pDetContext->Flags & fDET_CONTEXT_FIND_FIRST)){
  219. // Initialize the context information so that we start detecting
  220. // at the initialize port range.
  221. pDetContext->ISA.IoBaseAddress = 0x0888;
  222. }
  223. for (IoBaseAddress = pDetContext->ISA.IoBaseAddress;
  224. IoBaseAddress <= 0x3888;
  225. IoBaseAddress = NibcNextIoAddress(IoBaseAddress)){
  226. // Look for the PC-9801-83/84/103/104 adapter at the current port.
  227. NtStatus = FindNibcAdapter(pDetectedAdapter,
  228. InterfaceType,
  229. BusNumber,
  230. IoBaseAddress,
  231. pAdapterInfo->PnPId);
  232. if (NT_SUCCESS(NtStatus)){
  233. // We found an adapter. Save the next IO address to check.
  234. #if DBG
  235. DbgPrint("Found an adapter. I/O port is %x\n",IoBaseAddress);
  236. #endif
  237. pDetContext->ISA.IoBaseAddress = NibcNextIoAddress(IoBaseAddress);
  238. break;
  239. }
  240. }
  241. if (0xffff == IoBaseAddress){
  242. NtStatus = STATUS_NO_MORE_ENTRIES;
  243. }
  244. return(NtStatus);
  245. }