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.

859 lines
28 KiB

  1. /*----------------------------------------------------------------------
  2. pnprckt.c - rocketport pnp specific things.
  3. |----------------------------------------------------------------------*/
  4. #include "precomp.h"
  5. #define TraceStr(s) GTrace(D_Pnp, sz_modid, s)
  6. #define TraceStr1(s, p1) GTrace1(D_Pnp, sz_modid, s, p1)
  7. #define TraceStr2(s, p1, p2) GTrace2(D_Pnp, sz_modid, s, p1, p2)
  8. #define DTraceStr(s) DTrace(D_Pnp, sz_modid, s)
  9. #define TraceErr(s) GTrace(D_Error, sz_modid_err, s)
  10. static char *sz_modid = {"pnpadd"};
  11. static char *sz_modid_err = {"Error,pnpadd"};
  12. /*----------------------------------------------------------------------
  13. PrimaryIsaBoard - Search for Primary Isa boards, if found then return
  14. a pointer to the extension.
  15. Return Value:
  16. Return ptr to extension of primary Isa board, if not found, null.
  17. |----------------------------------------------------------------------*/
  18. PSERIAL_DEVICE_EXTENSION FindPrimaryIsaBoard(void)
  19. {
  20. PSERIAL_DEVICE_EXTENSION ext;
  21. ext = Driver.board_ext;
  22. while (ext)
  23. {
  24. if (ext->config->BusType == Isa)
  25. {
  26. // first board must have 4 hex io-defined, 4 bytes for mudback.
  27. // additional isa-boards alias up on original to save space.
  28. if ((ext->config->BaseIoSize == 0x44) &&
  29. (ext->config->ISABrdIndex == 0))
  30. {
  31. return ext;
  32. }
  33. }
  34. ext = ext->board_ext; // next in chain
  35. } // while ext
  36. return NULL;
  37. }
  38. #ifdef NT50
  39. /*----------------------------------------------------------------------
  40. GetPCIRocket - find the pci-card indicated by BaseAddr and fill in
  41. the rest of the info in the config.
  42. |----------------------------------------------------------------------*/
  43. int GetPCIRocket(ULONG BaseAddr, DEVICE_CONFIG *CfCtl)
  44. {
  45. PCI_COMMON_CONFIG *PCIDev;
  46. UCHAR i;
  47. NTSTATUS Status;
  48. int Slot;
  49. int NumPCI;
  50. NumPCI = FindPCIBus();
  51. if (NumPCI == 0)
  52. return 1;
  53. PCIDev = ExAllocatePool(NonPagedPool,sizeof(PCI_COMMON_CONFIG));
  54. if ( PCIDev == NULL ) {
  55. Eprintf("No memory for PCI device.");
  56. return 1;
  57. }
  58. for(i=0;i<NumPCI;++i)
  59. {
  60. for(Slot = 0;Slot < 32;++Slot) /*5 bits for device 32 = 2^5*/
  61. {
  62. // get a few bytes of pci-config space(vendor-id & device-id).
  63. Status = HalGetBusData(PCIConfiguration,i,Slot,PCIDev,0x4);
  64. if (Status == 0)
  65. {
  66. Eprintf("PCI Bus %d does not exist.",i);
  67. }
  68. if (Status > 2) /* Found Device Is it ours? */
  69. {
  70. if (PCIDev->VendorID == PCI_VENDOR_ID)
  71. {
  72. // get 0x40 worth of pci-config space(includes irq, addr, etc.)
  73. Status = HalGetBusData(PCIConfiguration,i,Slot,PCIDev,0x40);
  74. if (BaseAddr == (PCIDev->u.type0.BaseAddresses[0]-1))
  75. {
  76. if (Driver.VerboseLog)
  77. Eprintf("PCI Board found, IO:%xh, Int:%d ID:%d Rev:%d.",
  78. PCIDev->u.type0.BaseAddresses[0]-1,
  79. PCIDev->u.type0.InterruptLine,
  80. PCIDev->DeviceID,
  81. PCIDev->RevisionID);
  82. CfCtl->BusType=PCIBus;
  83. CfCtl->BusNumber = i; //get from previous halquerysysin
  84. CfCtl->PCI_Slot = Slot;
  85. CfCtl->PCI_DevID = PCIDev->DeviceID;
  86. CfCtl->PCI_RevID = PCIDev->RevisionID;
  87. CfCtl->PCI_SVID = PCIDev->u.type0.SubVendorID;
  88. CfCtl->PCI_SID = PCIDev->u.type0.SubSystemID;
  89. CfCtl->BaseIoAddr =
  90. PCIDev->u.type0.BaseAddresses[0]-1;
  91. //if (PCIDev->u.type0.InterruptLine != 255)
  92. //{
  93. //RcktCfg->Irq = PCIDev->u.type0.InterruptLine;
  94. //}
  95. if (Driver.VerboseLog)
  96. Eprintf("Bus:%d,Slt:%x,Dev:%x,Rev:%x,Pin:%x",
  97. i, Slot, PCIDev->DeviceID, PCIDev->RevisionID, PCIDev->u.type0.InterruptPin);
  98. ExFreePool(PCIDev);
  99. return 0; // fail
  100. }
  101. } // if (PCIDev->VendorID == PCI_VENDOR_ID)
  102. } // if (Status > 2)
  103. }
  104. }
  105. ExFreePool(PCIDev);
  106. return 2; // fail
  107. }
  108. /*----------------------------------------------------------------------
  109. RkGetPnpResourceToConfig -
  110. This routine will get the configuration information and put
  111. it and the translated values into CONFIG_DATA structures.
  112. It first sets up with defaults and then queries the registry
  113. to see if the user has overridden these defaults; if this is a legacy
  114. multiport card, it uses the info in PUserData instead of groping the
  115. registry again.
  116. Arguments:
  117. Fdo - Pointer to the functional device object.
  118. pResourceList - Pointer to the untranslated resources requested.
  119. pTrResourceList - Pointer to the translated resources requested.
  120. pConfig - Pointer to configuration info
  121. PUserData - Pointer to data discovered in the registry for legacy devices.
  122. Return Value:
  123. STATUS_SUCCESS if consistant configuration was found - otherwise.
  124. returns STATUS_SERIAL_NO_DEVICE_INITED.
  125. |----------------------------------------------------------------------*/
  126. NTSTATUS
  127. RkGetPnpResourceToConfig(IN PDEVICE_OBJECT Fdo,
  128. IN PCM_RESOURCE_LIST pResourceList,
  129. IN PCM_RESOURCE_LIST pTrResourceList,
  130. OUT DEVICE_CONFIG *pConfig)
  131. {
  132. PSERIAL_DEVICE_EXTENSION fdoExtension = Fdo->DeviceExtension;
  133. PDEVICE_OBJECT pdo = fdoExtension->LowerDeviceObject;
  134. NTSTATUS status = STATUS_NOT_IMPLEMENTED;
  135. ULONG count;
  136. ULONG i;
  137. BOOLEAN MappedFlag;
  138. PCM_FULL_RESOURCE_DESCRIPTOR pFullResourceDesc = NULL,
  139. pFullTrResourceDesc = NULL;
  140. ULONG zero = 0;
  141. pFullResourceDesc = &pResourceList->List[0];
  142. pFullTrResourceDesc = &pTrResourceList->List[0];
  143. // Ok, if we have a full resource descriptor. Let's take it apart.
  144. if (pFullResourceDesc) {
  145. PCM_PARTIAL_RESOURCE_LIST prl;
  146. PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
  147. unsigned int Addr;
  148. prl = &pFullResourceDesc->PartialResourceList;
  149. prd = prl->PartialDescriptors;
  150. count = prl->Count;
  151. // Pull out the stuff that is in the full descriptor.
  152. // for rocketport could be: PCIBus, Isa, MicroChannel
  153. pConfig->BusType = pFullResourceDesc->InterfaceType;
  154. pConfig->BusNumber = pFullResourceDesc->BusNumber;
  155. if ((pConfig->BusType != PCIBus) && (pConfig->BusType != Isa))
  156. {
  157. Eprintf("Err, Unknown Bus");
  158. return STATUS_INSUFFICIENT_RESOURCES;
  159. }
  160. // Now run through the partial resource descriptors looking for the port,
  161. // interrupt, and clock rate.
  162. for (i = 0; i < count; i++, prd++)
  163. {
  164. switch (prd->Type)
  165. {
  166. case CmResourceTypePort:
  167. Addr = (unsigned int) prd->u.Port.Start.LowPart;
  168. #if 0
  169. // we don't handle aliasing here
  170. if (pConfig->BusType == Isa)
  171. {
  172. // only setup if not an isa-bus alias address
  173. if (prd->u.Port.Start.LowPart < 0x400)
  174. pConfig->BaseIoAddr = Addr;
  175. }
  176. else
  177. #endif
  178. pConfig->BaseIoAddr = Addr;
  179. pConfig->BaseIoSize = prd->u.Port.Length;
  180. switch(pConfig->BusType)
  181. {
  182. case Isa:
  183. pConfig->AiopIO[0] = pConfig->BaseIoAddr;
  184. pConfig->AiopIO[1] = pConfig->AiopIO[0] + 0x400;
  185. pConfig->AiopIO[2] = pConfig->AiopIO[0] + 0x800;
  186. pConfig->AiopIO[3] = pConfig->AiopIO[0] + 0xc00;
  187. pConfig->MudbacIO = pConfig->AiopIO[0] + 0x40;
  188. //if (prd->u.Port.Length == 0x40)
  189. //pConfig->AddressSpace = prd->Flags;
  190. //Eprintf("Error, Res 1C");
  191. GTrace1(D_Pnp,sz_modid,"ISA_Addr:%xH", pConfig->BaseIoAddr);
  192. break;
  193. case PCIBus:
  194. pConfig->AiopIO[0] = pConfig->BaseIoAddr;
  195. pConfig->AiopIO[1] = pConfig->AiopIO[0] + 0x40;
  196. pConfig->AiopIO[2] = pConfig->AiopIO[0] + 0x80;
  197. pConfig->AiopIO[3] = pConfig->AiopIO[0] + 0xc0;
  198. GTrace1(D_Pnp,sz_modid,"PCI_Addr:%xH", pConfig->BaseIoAddr);
  199. break;
  200. }
  201. break;
  202. case CmResourceTypeInterrupt:
  203. pConfig->IrqLevel = prd->u.Interrupt.Level;
  204. pConfig->IrqVector = prd->u.Interrupt.Vector;
  205. pConfig->Affinity = prd->u.Interrupt.Affinity;
  206. if (prd->Flags
  207. & CM_RESOURCE_INTERRUPT_LATCHED) {
  208. pConfig->InterruptMode = Latched;
  209. } else {
  210. pConfig->InterruptMode = LevelSensitive; }
  211. GTrace1(D_Pnp,sz_modid, "Res_Int:%xH", pConfig->IrqVector);
  212. break;
  213. case CmResourceTypeMemory:
  214. DTraceStr("PnP:Res,DevSpec");
  215. break;
  216. case CmResourceTypeDeviceSpecific:
  217. DTraceStr("PnP:Res,DevSpec");
  218. break;
  219. default:
  220. if (Driver.VerboseLog)
  221. Eprintf("PnP:Dev. Data 1G:%x",prd->Type);
  222. break;
  223. } // switch (prd->Type)
  224. } // for (i = 0; i < count; i++, prd++)
  225. } // if (pFullResourceDesc)
  226. //---- Do the same for the translated resources
  227. if (pFullTrResourceDesc)
  228. {
  229. PCM_PARTIAL_RESOURCE_LIST prl;
  230. PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
  231. PUCHAR pAddr;
  232. prl = &pFullTrResourceDesc->PartialResourceList;
  233. prd = prl->PartialDescriptors;
  234. count = prl->Count;
  235. for (i = 0; i < count; i++, prd++)
  236. {
  237. switch (prd->Type)
  238. {
  239. case CmResourceTypePort:
  240. pConfig->TrBaseIoAddr = (unsigned int) prd->u.Port.Start.LowPart;
  241. pAddr = SerialGetMappedAddress(
  242. pConfig->BusType,
  243. pConfig->BusNumber,
  244. prd->u.Port.Start,
  245. prd->u.Port.Length,
  246. prd->Flags, // port-io?
  247. //1, // port-io
  248. &MappedFlag, // do we need to unmap on cleanup?
  249. 0); // don't translate
  250. #if 0
  251. // we do not handle the alias io here
  252. //!!!!!!! this is guarenteed to work, since it is mapped
  253. if (pConfig->BusType == Isa)
  254. {
  255. // only setup if not an isa-bus alias address
  256. if (prd->u.Port.Start.LowPart < 0x400)
  257. pConfig->pBaseIoAddr = pAddr;
  258. }
  259. else
  260. #endif
  261. pConfig->pBaseIoAddr = pAddr;
  262. if (pConfig->BaseIoSize == 0)
  263. pConfig->BaseIoSize = prd->u.Port.Length;
  264. switch(pConfig->BusType)
  265. {
  266. case Isa:
  267. pConfig->NumAiop=AIOP_CTL_SIZE; // let init figure it out
  268. pConfig->pAiopIO[0] = pConfig->pBaseIoAddr;
  269. pConfig->pAiopIO[1] = pConfig->pAiopIO[0] + 0x400;
  270. pConfig->pAiopIO[2] = pConfig->pAiopIO[0] + 0x800;
  271. pConfig->pAiopIO[3] = pConfig->pAiopIO[0] + 0xc00;
  272. if (pConfig->BaseIoSize == 0x44)
  273. {
  274. pConfig->pMudbacIO = pConfig->pAiopIO[0] + 0x40;
  275. }
  276. GTrace1(D_Pnp,sz_modid,"ISA TrRes_Addr:%xH", prd->u.Port.Start.LowPart);
  277. GTrace1(D_Pnp,sz_modid,"ISA pAddr:%xH", pAddr);
  278. //Eprintf("ISA TrRes_Addr:%xH", prd->u.Port.Start.LowPart);
  279. break;
  280. case PCIBus:
  281. pConfig->pAiopIO[0] = pConfig->pBaseIoAddr;
  282. pConfig->pAiopIO[1] = pConfig->pAiopIO[0] + 0x40;
  283. pConfig->pAiopIO[2] = pConfig->pAiopIO[0] + 0x80;
  284. pConfig->pAiopIO[3] = pConfig->pAiopIO[0] + 0xc0;
  285. //if (prd->u.Port.Length == 0x40)
  286. //pConfig->AddressSpace = prd->Flags;
  287. //Eprintf("Error, Res 1G");
  288. GTrace1(D_Pnp,sz_modid,"PCI TrRes_Addr:%xH", prd->u.Port.Start.LowPart);
  289. GTrace1(D_Pnp,sz_modid,"PCI pAddr:%xH", pAddr);
  290. break;
  291. }
  292. break;
  293. case CmResourceTypeInterrupt:
  294. pConfig->TrIrqVector = prd->u.Interrupt.Vector;
  295. pConfig->TrIrqLevel = prd->u.Interrupt.Level;
  296. pConfig->TrAffinity = prd->u.Interrupt.Affinity;
  297. GTrace1(D_Pnp,sz_modid,"TrRes_Int:%xH", pConfig->TrIrqVector);
  298. break;
  299. case CmResourceTypeMemory:
  300. DTraceStr("PnP:TransRes,DevSpec");
  301. break;
  302. default:
  303. if (Driver.VerboseLog)
  304. Eprintf("PnP:Dev. Data 1H:%x",prd->Type);
  305. break;
  306. } // switch (prd->Type)
  307. } // for (i = 0; i < count; i++, prd++)
  308. } // if (pFullTrResourceDesc)
  309. if (pConfig->BusType == Isa)
  310. {
  311. // figure out mudbac alias io space stuff.
  312. SetupRocketCfg(1);
  313. } // isa
  314. // if PCI bus, then we need to query for device type, etc.
  315. if (pConfig->BusType == PCIBus)
  316. {
  317. if (GetPCIRocket(pConfig->AiopIO[0], pConfig) != 0)
  318. {
  319. Eprintf("Unknown PCI type");
  320. }
  321. }
  322. ConfigAIOP(pConfig);
  323. status = STATUS_SUCCESS;
  324. return status;
  325. }
  326. #ifdef DO_ISA_BUS_ALIAS_IO
  327. /*-----------------------------------------------------------------------
  328. Report_Alias_IO -
  329. |-----------------------------------------------------------------------*/
  330. int Report_Alias_IO(IN PSERIAL_DEVICE_EXTENSION extension)
  331. {
  332. PCM_RESOURCE_LIST resourceList;
  333. ULONG sizeOfResourceList;
  334. ULONG countOfPartials;
  335. PCM_PARTIAL_RESOURCE_DESCRIPTOR partial;
  336. NTSTATUS status;
  337. PHYSICAL_ADDRESS MyPort;
  338. BOOLEAN ConflictDetected;
  339. BOOLEAN MappedFlag;
  340. int j;
  341. int brd = extension->UniqueId;
  342. DEVICE_CONFIG *Ctl;
  343. char name[70];
  344. int need_alias = 0;
  345. int NumAiop;
  346. DTraceStr("ReportResources");
  347. ConflictDetected=FALSE;
  348. countOfPartials=0;
  349. Ctl = extension->config;
  350. // we got mudback.
  351. if (Ctl->BusType != Isa)
  352. {
  353. DTraceStr("NotISA");
  354. return 0;
  355. }
  356. // if it only has 1 aiopic and has 4 bytes for mudback,
  357. // then no aliasing required.
  358. if (Ctl->BaseIoSize != 0x44)
  359. need_alias = 1;
  360. // rocketport boards need extra aiop space for reset circuitry.
  361. if (extension->config->ModemDevice)
  362. {
  363. need_alias = 1;
  364. }
  365. if (Ctl->NumPorts > 8)
  366. need_alias = 1;
  367. if (need_alias == 0)
  368. {
  369. // no aliasing needed.
  370. DTraceStr("EasyISA");
  371. return 0;
  372. }
  373. // we need to update initcontroller to stall until first controller
  374. // gets a start.
  375. // else it is an additional board which needs to alias its mudback
  376. // ontop of the first ISA(44H) address space, or it is a board
  377. // with more than 1 aiopic chip(which requires aliasing over itself)
  378. if (Ctl->BaseIoSize != 0x44) // must be 2nd, 3rd, or 4th board
  379. {
  380. DTraceStr("HasMdBk");
  381. countOfPartials++; // so mudback is aliased up
  382. }
  383. NumAiop = Ctl->NumAiop;
  384. if (extension->config->ModemDevice)
  385. { // reset circuitry
  386. ++NumAiop;
  387. }
  388. if (NumAiop > 4)
  389. return 15; // error
  390. MyKdPrint(D_Pnp,("Report Resources brd:%d bus:%d\n",brd+1, Ctl->BusType))
  391. // don't report first aiop(we got that from pnp)
  392. for (j=1; j<NumAiop; j++)
  393. {
  394. if (Ctl->AiopIO[j] > 0)
  395. countOfPartials++; // For each Aiop, we will get resources
  396. }
  397. sizeOfResourceList = sizeof(CM_RESOURCE_LIST) +
  398. sizeof(CM_FULL_RESOURCE_DESCRIPTOR) + // add, kpb
  399. (sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)*
  400. countOfPartials);
  401. // add 64 for slop
  402. resourceList = ExAllocatePool(PagedPool, sizeOfResourceList+64);
  403. if (!resourceList)
  404. {
  405. if (Driver.VerboseLog)
  406. Eprintf("No ResourceList");
  407. EventLog(Driver.GlobalDriverObject,
  408. STATUS_SUCCESS,
  409. SERIAL_INSUFFICIENT_RESOURCES,
  410. 0, NULL);
  411. return(9);
  412. }
  413. RtlZeroMemory(resourceList, sizeOfResourceList);
  414. resourceList->Count = 1;
  415. resourceList->List[0].InterfaceType = Ctl->BusType;
  416. resourceList->List[0].BusNumber = Ctl->BusNumber; //change for multibus
  417. resourceList->List[0].PartialResourceList.Count = countOfPartials;
  418. partial = &resourceList->List[0].PartialResourceList.PartialDescriptors[0];
  419. // Account for the space used by the Rocket.
  420. // Report the use of the Mudbacs on Isa boards only
  421. if (Ctl->BaseIoSize != 0x44) // must be 2nd, 3rd, or 4th board
  422. {
  423. MyPort.HighPart=0x0;
  424. MyPort.LowPart=Ctl->MudbacIO;
  425. partial->Type = CmResourceTypePort;
  426. partial->ShareDisposition = CmResourceShareDeviceExclusive;
  427. partial->Flags = CM_RESOURCE_PORT_IO;
  428. partial->u.Port.Start = MyPort;
  429. partial->u.Port.Length = SPANOFMUDBAC;
  430. partial++;
  431. }
  432. for (j=1; j<NumAiop; j++)
  433. {
  434. if (Ctl->AiopIO[j] == 0)
  435. Ctl->AiopIO[j] = Ctl->AiopIO[j-1];
  436. // Report the use of the AIOPs.
  437. if (Ctl->AiopIO[j] > 0)
  438. {
  439. MyPort.HighPart=0x0;
  440. MyPort.LowPart=Ctl->AiopIO[j];
  441. partial->Type = CmResourceTypePort;
  442. partial->ShareDisposition = CmResourceShareDeviceExclusive;
  443. partial->Flags = CM_RESOURCE_PORT_IO;
  444. partial->u.Port.Start = MyPort;
  445. partial->u.Port.Length = SPANOFAIOP;
  446. partial++;
  447. }
  448. else
  449. {
  450. MyKdPrint(D_Pnp,("Aiop Count Wrong, A.\n"))
  451. if (Driver.VerboseLog)
  452. Eprintf("Error RR12");
  453. }
  454. } // end for j
  455. //-------- Report the resources indicated by partial list (resourceList)
  456. strcpy(name, szResourceClassName);
  457. our_ultoa(extension->UniqueId, &name[strlen(name)], 10);
  458. MyKdPrint(D_Pnp,("Reporting Resources To system\n"))
  459. status=IoReportResourceUsage(
  460. CToU1(name), // DriverClassName OPTIONAL,
  461. extension->DeviceObject->DriverObject, // DriverObject,
  462. // Driver.GlobalDriverObject,
  463. NULL, // DriverList OPTIONAL,
  464. 0, // DriverListSize OPTIONAL,
  465. extension->DeviceObject, // DeviceObject
  466. resourceList, // DeviceList OPTIONAL,
  467. sizeOfResourceList, // DeviceListSize OPTIONAL,
  468. FALSE, // OverrideConflict,
  469. &ConflictDetected); // ConflictDetected
  470. if (!NT_SUCCESS(status))
  471. {
  472. if (Driver.VerboseLog)
  473. Eprintf("Error, Resources");
  474. TraceErr("Err5G");
  475. }
  476. if (ConflictDetected)
  477. {
  478. Eprintf("Error, Resource Conflict.");
  479. if (resourceList)
  480. ExFreePool(resourceList);
  481. resourceList = NULL;
  482. EventLog(Driver.GlobalDriverObject,
  483. STATUS_SUCCESS,
  484. SERIAL_INSUFFICIENT_RESOURCES,
  485. 0, NULL);
  486. MyKdPrint(D_Pnp,("Resource Conflict Detected.\n"))
  487. return(10);
  488. }
  489. // OK, even more important than reporting resources is getting
  490. // the pointers to the I/O ports!!
  491. if (Ctl->BusType == Isa)
  492. {
  493. MyPort.HighPart=0x0;
  494. MyPort.LowPart=Ctl->MudbacIO;
  495. if (Ctl->BaseIoSize != 0x44) // must be 2nd, 3rd, or 4th board
  496. {
  497. Ctl->pMudbacIO =
  498. SerialGetMappedAddress(Isa,Ctl->BusNumber,MyPort,SPANOFMUDBAC,1,&MappedFlag,1);
  499. if (Ctl->pMudbacIO == NULL)
  500. {
  501. if (Driver.VerboseLog)
  502. Eprintf("Err RR15");
  503. MyKdPrint(D_Pnp,("Resource Error A.\n"))
  504. return 11;
  505. }
  506. }
  507. }
  508. for (j=1; j<NumAiop; j++)
  509. {
  510. if (Ctl->AiopIO[j] > 0)
  511. {
  512. MyPort.HighPart=0x0;
  513. MyPort.LowPart=Ctl->AiopIO[j];
  514. Ctl->pAiopIO[j] =
  515. SerialGetMappedAddress(Ctl->BusType,
  516. Ctl->BusNumber,MyPort,SPANOFAIOP,1,&MappedFlag,1);
  517. if (Ctl->pAiopIO[j] == NULL)
  518. {
  519. if (Driver.VerboseLog)
  520. Eprintf("Err RR16");
  521. MyKdPrint(D_Pnp,("Resource Error B.\n"))
  522. return 12;
  523. }
  524. }
  525. else
  526. {
  527. if (Driver.VerboseLog)
  528. Eprintf("Err RR17");
  529. MyKdPrint(D_Pnp,("Aiop Count Wrong, B.\n"))
  530. return 13;
  531. }
  532. }
  533. extension->io_reported = 1; // tells that we should deallocate on unload.
  534. // Release the memory used for the resourceList
  535. if (resourceList)
  536. ExFreePool(resourceList);
  537. resourceList = NULL;
  538. MyKdPrint(D_Pnp,("Done Reporting Resources\n"))
  539. return 0;
  540. }
  541. #endif
  542. #if 0
  543. /*----------------------------------------------------------------------
  544. SerialFindInitController -
  545. |----------------------------------------------------------------------*/
  546. NTSTATUS
  547. SerialFindInitController(IN PDEVICE_OBJECT Fdo, IN PCONFIG_DATA PConfig)
  548. {
  549. PSERIAL_DEVICE_EXTENSION fdoExtension = Fdo->DeviceExtension;
  550. PDEVICE_OBJECT pDeviceObject;
  551. PSERIAL_DEVICE_EXTENSION pExtension;
  552. PHYSICAL_ADDRESS serialPhysicalMax;
  553. //SERIAL_LIST_DATA listAddition;
  554. PLIST_ENTRY currentFdo;
  555. NTSTATUS status;
  556. serialPhysicalMax.LowPart = (ULONG)~0;
  557. serialPhysicalMax.HighPart = ~0;
  558. //if (address is hosed,)
  559. // return STATUS_NO_SUCH_DEVICE;
  560. //
  561. // Loop through all of the driver's device objects making
  562. // sure that this new record doesn't overlap with any of them.
  563. //
  564. #ifdef DO_LATER
  565. if (!IsListEmpty(&Driver.AllFdos)) {
  566. currentFdo = Driver.AllFdos.Flink;
  567. pExtension = CONTAINING_RECORD(currentFdo, SERIAL_DEVICE_EXTENSION,
  568. AllFdos);
  569. } else {
  570. currentFdo = NULL;
  571. pExtension = NULL;
  572. }
  573. //
  574. // Loop through all previously attached devices
  575. //
  576. if (!IsListEmpty(&Driver.AllFdos)) {
  577. currentFdo = Driver.AllFdos.Flink;
  578. pExtension = CONTAINING_RECORD(currentFdo, SERIAL_DEVICE_EXTENSION,
  579. AllFdos);
  580. } else {
  581. currentFdo = NULL;
  582. pExtension = NULL;
  583. }
  584. //status = SerialInitOneController(Fdo, PConfig);
  585. //PSERIAL_DEVICE_EXTENSION fdoExtension = Fdo->DeviceExtension;
  586. // init the thing
  587. if (!NT_SUCCESS(status)) {
  588. return status;
  589. }
  590. #endif
  591. return STATUS_SUCCESS;
  592. }
  593. #endif // 0
  594. #ifdef DO_BRD_FILTER_RES_REQ
  595. /*----------------------------------------------------------------------
  596. BoardFilterResReq - handle IRP_MN_FILTER_RESOURCE_REQUIREMENTS: // 0x0D
  597. for our board FDO entity. Test to see if we can adjust requirements
  598. to handle io-aliasing(no, doesn't look too promising).
  599. |----------------------------------------------------------------------*/
  600. NTSTATUS BoardFilterResReq(IN PDEVICE_OBJECT devobj, IN PIRP Irp)
  601. {
  602. PSERIAL_DEVICE_EXTENSION Ext = devobj->DeviceExtension;
  603. PDEVICE_OBJECT pdo = Ext->LowerDeviceObject;
  604. PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp);
  605. NTSTATUS status = STATUS_NOT_SUPPORTED;
  606. //******** see serial driver(changes resource requirements)
  607. HANDLE pnpKey;
  608. //KEVENT resFiltEvent;
  609. //ULONG isMulti = 0;
  610. PIO_RESOURCE_REQUIREMENTS_LIST prrl;
  611. PIO_RESOURCE_LIST prl;
  612. PIO_RESOURCE_DESCRIPTOR prd;
  613. PIO_RESOURCE_REQUIREMENTS_LIST new_prrl;
  614. PIO_RESOURCE_LIST new_prl;
  615. PIO_RESOURCE_DESCRIPTOR new_prd;
  616. ULONG i, j;
  617. ULONG reqCnt;
  618. ULONG rrl_size;
  619. ULONG rl_size;
  620. TraceStr1("Filt Res Req, PDO:%x", do);
  621. status = WaitForLowerPdo(devobj, Irp);
  622. if (Irp->IoStatus.Information == 0)
  623. {
  624. if (irpStack->Parameters.FilterResourceRequirements
  625. .IoResourceRequirementList == 0)
  626. {
  627. DTraceStr("No Resources");
  628. status = Irp->IoStatus.Status;
  629. SerialCompleteRequest(Ext, Irp, IO_NO_INCREMENT);
  630. return status;
  631. }
  632. Irp->IoStatus.Information = (ULONG)irpStack->Parameters
  633. .FilterResourceRequirements
  634. .IoResourceRequirementList;
  635. }
  636. // Add aliases to IO_RES_REQ_LIST.
  637. prrl = (PIO_RESOURCE_REQUIREMENTS_LIST)Irp->IoStatus.Information;
  638. #if 0
  639. new_prrl = (new_prrl) ExAllocatePool(PagedPool,
  640. prrl->ListSize + (sizeof(IO_RESOURCE_DESCRIPTOR)*2));
  641. if (new_prrl == NULL)
  642. {
  643. TraceErr("Bad Buf Z");
  644. //ExFreePool();
  645. }
  646. memcpy(new_prrl, prrl);
  647. #endif
  648. //reqCnt = ((prrl->ListSize - sizeof(IO_RESOURCE_REQUIREMENTS_LIST))
  649. // / sizeof(IO_RESOURCE_DESCRIPTOR)) + 1;
  650. reqCnt = 0;
  651. TraceStr1("RRL Size:%x", sizeof(IO_RESOURCE_REQUIREMENTS_LIST));
  652. TraceStr1("RL Size:%x", sizeof(IO_RESOURCE_LIST));
  653. TraceStr1("RD Size:%x", sizeof(IO_RESOURCE_DESCRIPTOR));
  654. TraceStr1("List Size:%x", prrl->ListSize);
  655. rrl_size = sizeof(IO_RESOURCE_REQUIREMENTS_LIST) -
  656. sizeof(IO_RESOURCE_LIST);
  657. rl_size = sizeof(IO_RESOURCE_LIST) - sizeof(IO_RESOURCE_DESCRIPTOR);
  658. TraceStr1("RRL Base Size:%x", rrl_size);
  659. TraceStr1("RL Base Size:%x", rl_size);
  660. //for (i = 0; i < reqCnt; i++) {
  661. reqCnt = rrl_size; // pass up base of IO_RESOURCE_REQUIREMENTS_LIST
  662. while (reqCnt < prrl->ListSize)
  663. {
  664. prl = (PIO_RESOURCE_LIST) &((BYTE *)prrl)[reqCnt]; // ptr to IO_RESOURCE_LIST
  665. reqCnt += rl_size; // pass up base of IO_RESOURCE_LIST
  666. TraceStr1("Num Res Desc:%d", prl->Count);
  667. for (j = 0; j < prl->Count; j++)
  668. {
  669. reqCnt += sizeof(IO_RESOURCE_DESCRIPTOR);
  670. prd = &prl->Descriptors[j];
  671. TraceStr2("Desc Type:%x, Flags:%x", prd->Type, prd->Flags);
  672. if (prd->Type == CmResourceTypePort)
  673. {
  674. DTraceStr("Type:Port");
  675. TraceStr2("Min:%x Max:%x",
  676. prd->u.Port.MinimumAddress.LowPart,
  677. prd->u.Port.MaximumAddress.LowPart);
  678. TraceStr2("Align:%x Len:%x",
  679. prd->u.Port.Alignment, prd->u.Port.Length);
  680. //Addr = (unsigned int) prd->u.Port.Start.LowPart;
  681. //if (Addr < 0x400)
  682. // pConfig->BaseIoAddr = Addr;
  683. //pConfig->BaseIoSize = prd->u.Port.Length;
  684. }
  685. }
  686. TraceStr1("ByteCnt:%d", reqCnt);
  687. }
  688. Irp->IoStatus.Status = STATUS_SUCCESS;
  689. SerialCompleteRequest(Ext, Irp, IO_NO_INCREMENT);
  690. return STATUS_SUCCESS;
  691. }
  692. #endif // DO_BRD_FILTER_RES_REQ
  693. /*----------------------------------------------------------------------------
  694. | is_isa_cards_pending_start - scan linked list of card devices, see if
  695. any ISA bus cards are not started(delayed or pending a start waiting
  696. for first ISA card.)
  697. |----------------------------------------------------------------------------*/
  698. int is_isa_cards_pending_start(void)
  699. {
  700. PSERIAL_DEVICE_EXTENSION Ext;
  701. Ext = Driver.board_ext;
  702. while (Ext)
  703. {
  704. if (Ext->config->BusType == Isa)
  705. {
  706. if (Ext->config->ISABrdIndex == 0)
  707. {
  708. if (Ext->config->HardwareStarted)
  709. return 1; // true, its pending a start
  710. }
  711. }
  712. Ext = Ext->board_ext; // next in chain
  713. } // while board extension
  714. return 0; // false, not started
  715. }
  716. /*----------------------------------------------------------------------------
  717. | is_first_isa_card_started - scan linked list of card devices, see if
  718. "first" ISA bus card is started.
  719. |----------------------------------------------------------------------------*/
  720. int is_first_isa_card_started(void)
  721. {
  722. PSERIAL_DEVICE_EXTENSION Ext;
  723. Ext = Driver.board_ext;
  724. while (Ext)
  725. {
  726. if (Ext->config->BusType == Isa)
  727. {
  728. if (Ext->config->ISABrdIndex == 0)
  729. {
  730. if (Ext->config->HardwareStarted)
  731. return 1; // true, its started
  732. }
  733. }
  734. Ext = Ext->board_ext; // next in chain
  735. } // while board extension
  736. return 0; // false, not started
  737. }
  738. #endif // NT50