BOOL DumpDeviceResourcesOfType(_In_ DEVINST DevInst, _In_ HMACHINE MachineHandle, _In_ LOG_CONF Config, _In_ RESOURCEID ReqResId) { RES_DES prevResDes = (RES_DES)Config; RES_DES resDes = 0; RESOURCEID resId = ReqResId; ULONG dataSize; PBYTE resDesData; BOOL retval = FALSE; UNREFERENCED_PARAMETER(DevInst); while(CM_Get_Next_Res_Des_Ex(&resDes,prevResDes,ReqResId,&resId,0,MachineHandle)==CR_SUCCESS) { if(prevResDes != Config) { CM_Free_Res_Des_Handle(prevResDes); } prevResDes = resDes; if(CM_Get_Res_Des_Data_Size_Ex(&dataSize,resDes,0,MachineHandle)!=CR_SUCCESS) { continue; } resDesData = new BYTE[dataSize]; if(!resDesData) { continue; } if(CM_Get_Res_Des_Data_Ex(resDes,resDesData,dataSize,0,MachineHandle)!=CR_SUCCESS) { delete [] resDesData; continue; } switch(resId) { case ResType_Mem: { PMEM_RESOURCE pMemData = (PMEM_RESOURCE)resDesData; if(pMemData->MEM_Header.MD_Alloc_End-pMemData->MEM_Header.MD_Alloc_Base+1) { Padding(2); _tprintf(TEXT("MEM : %08I64x-%08I64x\n"),pMemData->MEM_Header.MD_Alloc_Base,pMemData->MEM_Header.MD_Alloc_End); retval = TRUE; } break; } case ResType_IO: { PIO_RESOURCE pIoData = (PIO_RESOURCE)resDesData; if(pIoData->IO_Header.IOD_Alloc_End-pIoData->IO_Header.IOD_Alloc_Base+1) { Padding(2); _tprintf(TEXT("IO : %04I64x-%04I64x\n"),pIoData->IO_Header.IOD_Alloc_Base,pIoData->IO_Header.IOD_Alloc_End); retval = TRUE; } break; } case ResType_DMA: { PDMA_RESOURCE pDmaData = (PDMA_RESOURCE)resDesData; Padding(2); _tprintf(TEXT("DMA : %u\n"),pDmaData->DMA_Header.DD_Alloc_Chan); retval = TRUE; break; } case ResType_IRQ: { PIRQ_RESOURCE pIrqData = (PIRQ_RESOURCE)resDesData; Padding(2); _tprintf(TEXT("IRQ : %u\n"),pIrqData->IRQ_Header.IRQD_Alloc_Num); retval = TRUE; break; } } delete [] resDesData; } if(prevResDes != Config) { CM_Free_Res_Des_Handle(prevResDes); } return retval; }
/** * Find IO port range for the parallel port and return the lower address. * * @returns parallel port IO address. * @param DevInst Device Instance for parallel port. */ static uint32_t drvHostWinFindIORangeResource(const DEVINST DevInst) { uint8_t *pBuf = NULL; short wHeaderSize; uint32_t u32Size; CONFIGRET cmRet; LOG_CONF firstLogConf; LOG_CONF nextLogConf; RES_DES rdPrevResDes; uint32_t u32ParportAddr = 0; wHeaderSize = sizeof(IO_DES); cmRet = CM_Get_First_Log_Conf(&firstLogConf, DevInst, ALLOC_LOG_CONF); if (cmRet != CR_SUCCESS) { cmRet = CM_Get_First_Log_Conf(&firstLogConf, DevInst, BOOT_LOG_CONF); if (cmRet != CR_SUCCESS) return 0; } cmRet = CM_Get_Next_Res_Des(&nextLogConf, firstLogConf, 2, 0L, 0L); if (cmRet != CR_SUCCESS) { CM_Free_Res_Des_Handle(firstLogConf); return 0; } /* This loop is based on the fact that only one resourece is assigned to * the LPT port. If multiple resources (address range) are assigned to * to LPT port, it will pick and return the last one */ for (;;) { u32Size = 0; cmRet = CM_Get_Res_Des_Data_Size((PULONG)(&u32Size), nextLogConf, 0L); if (cmRet != CR_SUCCESS) { LogFlowFunc(("Failed to get Size \n")); CM_Free_Res_Des_Handle(nextLogConf); break; } pBuf = (uint8_t *)RTMemAlloc(u32Size + 1); if (!pBuf) { LogFlowFunc(("Failed to get Buf %d\n", u32Size)); CM_Free_Res_Des_Handle(nextLogConf); break; } cmRet = CM_Get_Res_Des_Data(nextLogConf, pBuf, u32Size, 0L); if (cmRet != CR_SUCCESS) { LogFlowFunc(("Failed to get Des Data \n")); CM_Free_Res_Des_Handle(nextLogConf); if (pBuf) RTMemFree(pBuf); break; } LogFlowFunc(("call GetIOResource\n")); if (pBuf) u32ParportAddr = ((IO_DES *)pBuf)->IOD_Alloc_Base; LogFlowFunc(("called GetIOResource, ret=%#x\n", u32ParportAddr)); rdPrevResDes = 0; cmRet = CM_Get_Next_Res_Des(&rdPrevResDes, nextLogConf, 2, 0L, 0L); if (pBuf) RTMemFree(pBuf); if (cmRet != CR_SUCCESS) break; CM_Free_Res_Des_Handle(nextLogConf); nextLogConf = rdPrevResDes; } CM_Free_Res_Des_Handle(nextLogConf); LogFlowFunc(("return u32ParportAddr=%#x", u32ParportAddr)); return u32ParportAddr; }
/** * Find IO port range for the parallel port and return the lower address. * * @returns parallel port IO address. * @param DevInst Device Instance for parallel port. */ static uint32_t drvHostWinFindIORangeResource(const DEVINST DevInst) { uint8_t *pBuf = NULL; short wHeaderSize; uint32_t u32Size; CONFIGRET cmRet; LOG_CONF firstLogConf; LOG_CONF nextLogConf; RES_DES rdPrevResDes; uint32_t u32ParportAddr; wHeaderSize = sizeof(IO_DES); cmRet = CM_Get_First_Log_Conf(&firstLogConf, DevInst, ALLOC_LOG_CONF); if (cmRet != CR_SUCCESS) { cmRet = CM_Get_First_Log_Conf(&firstLogConf, DevInst, BOOT_LOG_CONF); if (cmRet != CR_SUCCESS) return 0; } cmRet = CM_Get_Next_Res_Des(&nextLogConf, firstLogConf, 2, 0L, 0L); if (cmRet != CR_SUCCESS) { CM_Free_Res_Des_Handle(firstLogConf); return 0; } for (;;) { u32Size = 0; cmRet = CM_Get_Res_Des_Data_Size((PULONG)(&u32Size), nextLogConf, 0L); if (cmRet != CR_SUCCESS) { CM_Free_Res_Des_Handle(nextLogConf); /** @todo r=bird: Why are you doing this twice in this code path? */ break; } pBuf = (uint8_t *)RTMemAlloc(u32Size + 1); if (!pBuf) { CM_Free_Res_Des_Handle(nextLogConf); /** @todo r=bird: Ditto above. */ break; } cmRet = CM_Get_Res_Des_Data(nextLogConf, pBuf, u32Size, 0L); if (cmRet != CR_SUCCESS) { CM_Free_Res_Des_Handle(nextLogConf); RTMemFree(pBuf); break; } LogFlowFunc(("call GetIOResource\n")); u32ParportAddr = ((IO_DES *)pBuf)->IOD_Alloc_Base; LogFlowFunc(("called GetIOResource, ret=%#x\n", u32ParportAddr)); rdPrevResDes = 0; cmRet = CM_Get_Next_Res_Des(&rdPrevResDes, nextLogConf, 2, 0L, 0L); RTMemFree(pBuf); if (cmRet != CR_SUCCESS) break; CM_Free_Res_Des_Handle(nextLogConf); nextLogConf = rdPrevResDes; } CM_Free_Res_Des_Handle(nextLogConf); LogFlowFunc(("return u32ParportAddr=%#x", u32ParportAddr)); return u32ParportAddr; }