uint32 peChecksumExecSections(uint8 *peBaseAddr, void *realBase, PEPROCESS proc, PKAPC_STATE apc, PHYSICAL_ADDRESS *physArr) { uint16 numExecSections = peGetNumExecSections(peBaseAddr); uint32 checksum = 0, k, i, j, numRelocs = peGetNumberOfRelocs(peBaseAddr, realBase, proc, apc), relocDelta = peCalculateRelocDiff(peBaseAddr, realBase); uint8 *dataPtr = NULL; PHYSICAL_ADDRESS phys = {0}; SectionData *execSections = (SectionData *) MmAllocateNonCachedMemory( numExecSections * sizeof(SectionData)); peGetExecSections(peBaseAddr, execSections); //DbgPrint("Found %d relocations, delta of: %x\r\n", numRelocs, relocDelta); for (i = 0; i < numExecSections; i++) { uint32 numpages = execSections[i].Size / 0x1000, size = execSections[i].Size; if (numpages * 0x1000 < execSections[i].Size) numpages++; for (k = 0; k < numpages; k++) { KeStackAttachProcess(proc, apc); dataPtr = (uint8 *) MmMapIoSpace(MmGetPhysicalAddress((void *)(((uint32) realBase) + execSections[i].VirtualAddress + (0x1000 * k))), 0x1000, 0); phys = MmGetPhysicalAddress((void *) dataPtr); for (j = 0; j < min(size, 0x1000); j++) { checksum += dataPtr[j]; } MmUnmapIoSpace((void *) dataPtr, 0x1000); size -= 0x1000; KeUnstackDetachProcess(apc); } } // Subtract the relocations from the checksum // TODO Fix incase of lower load address checksum += numRelocs * (relocDelta & 0x000000FF); checksum += numRelocs * ((relocDelta & 0x0000FF00) >> 8); checksum += numRelocs * ((relocDelta & 0x00FF0000) >> 16); checksum += numRelocs * ((relocDelta & 0xFF000000) >> 24); MmFreeNonCachedMemory((void *) execSections, numExecSections * sizeof(SectionData)); return checksum; }
CRomiDisk::~CRomiDisk( ) { FreeDMABuffers(); if ( m_vpSYSCONRegs) { MmUnmapIoSpace((PVOID)m_vpSYSCONRegs, sizeof(S3C6410_SYSCON_REG)); m_vpSYSCONRegs= NULL; } if ( m_vpIOPORTRegs) { MmUnmapIoSpace((PVOID)m_vpIOPORTRegs, sizeof(S3C6410_GPIO_REG)); m_vpIOPORTRegs= NULL; } if ( m_pDMAVirtualAddress ) { PHYSICAL_ADDRESS PhysicalAddress; PhysicalAddress.LowPart = m_DMAPhyaddress.LowPart; HalFreeCommonBuffer(0, 0, PhysicalAddress, (PVOID)m_pDMAVirtualAddress, FALSE); m_pDMAVirtualAddress = NULL; } InterlockedDecrement(&m_lDeviceCount); DEBUGMSG(ZONE_INIT|ZONE_PCI, (_T( "Atapi!CRomiDisk::~CRomiDisk> device count(%d)\r\n" ), m_lDeviceCount)); }
void CameraDeinit() { RETAILMSG(CAM_INOUT,(TEXT("++++++++++++++++++CameraDeInit\n"))); if(s6410IOP != NULL) { MmUnmapIoSpace((PVOID)s6410IOP, sizeof(S3C6410_GPIO_REG)); s6410IOP = NULL; } if(s6410CAM != NULL) { MmUnmapIoSpace((PVOID)s6410CAM, sizeof(S3C6410_CAMIF_REG)); s6410CAM = NULL; } if(s6410PWR != NULL) { MmUnmapIoSpace((PVOID)s6410PWR, sizeof(S3C6410_SYSCON_REG)); s6410PWR = NULL; } ModuleDeinit(); DeinitializeBuffer(); // CloseHandle(hCaptureThread); // CloseHandle(hPreviewThread); bCaptureThreadExit = TRUE; SetEvent(hCaptureEvent); bPreviewThreadExit = TRUE; SetEvent(hPreviewEvent); CloseHandle(hCaptureEvent); CloseHandle(hPreviewEvent); RETAILMSG(CAM_INOUT,(TEXT("------------------CameraDeInit\n"))); }
/************************************************************************************* // Function: BspBattDeallocResource // Purpose:dellloc resource for battery driver // Returns: N/A //***********************************************************************************/ void BspBattDeallocResource( void) { DPNOK(0); DeinitPinMuxMutex(g_hADCMutex); g_hADCMutex = NULL; g_bLedThreadExit = TRUE; if(g_hevLEDStatus) CloseHandle(g_hevLEDStatus); g_hevLEDStatus = NULL; if(g_hNotifyLedThread) CloseHandle(g_hNotifyLedThread); g_hNotifyLedThread = NULL; if (g_hevBatteryStatus) CloseHandle(g_hevBatteryStatus); g_hevBatteryStatus = NULL; #if 1 DPSTR("MmUnmapIoSpace"); MmUnmapIoSpace(g_pBspArgs, sizeof(BSP_ARGS)); MmUnmapIoSpace(v_p2450IOP, sizeof(S3C2450_IOPORT_REG)); MmUnmapIoSpace(v_pADCregs, sizeof(S3C2450_ADC_REG)); MmUnmapIoSpace(v_pUSBCtrlAddr, sizeof(S3C2450_USBD_REG)); #endif // BspPowerStatesManagerDeInit(); // CspRegUnMap(); }//endof BspBatDeallocResource
//----------------------------------------------------------------------------- // // Function: SMARTREFLEX_DeinitPolicy // // Policy uninitialization // BOOL SMARTREFLEX_DeinitPolicy( HANDLE hPolicyAdapter ) { BOOL rc = FALSE; RETAILMSG(ZONE_FUNCTION, ( L"+SMARTREFLEX_DeinitPolicy(0x%08x)\r\n", hPolicyAdapter )); // validate parameters if (hPolicyAdapter != (HANDLE)&s_SmartReflexLoadPolicyInfo) { RETAILMSG (ZONE_ERROR, (L"ERROR: SMARTREFLEX_DeinitPolicy:" L"Incorrect context parameter\r\n" )); goto cleanUp; } //unmap vdd1 voltage register to virtual memory MmUnmapIoSpace(s_VddOptimizationInfo[0].pPrcmRegistryAddress,sizeof(UINT32)); //unmap vdd2 voltage register to virtual memory MmUnmapIoSpace(s_VddOptimizationInfo[1].pPrcmRegistryAddress,sizeof(UINT32)); //unregisted DVFS change callback function PmxUnregisterConstraintCallback(s_SmartReflexLoadPolicyInfo.hDvfsConstraint, DvfsConstraintCallback ); //release DVFS constraint handler PmxReleaseConstraint(s_SmartReflexLoadPolicyInfo.hDvfsConstraint); //stop thread gracefuly if (s_SmartReflexLoadPolicyInfo.hSmartReflexSensingThread != NULL) { s_SmartReflexLoadPolicyInfo.bExitThread = TRUE; SetEvent(s_SmartReflexLoadPolicyInfo.hSmartReflexSensingEvent); WaitForSingleObject(s_SmartReflexLoadPolicyInfo.hSmartReflexSensingThread, INFINITE); CloseHandle(s_SmartReflexLoadPolicyInfo.hSmartReflexSensingThread); } //close sync event hanle CloseHandle(s_SmartReflexLoadPolicyInfo.hSmartReflexSensingEvent); // clear main policy structure memset(&s_SmartReflexLoadPolicyInfo, 0, sizeof(SmartReflexPolicyInfo_t)); rc = TRUE; cleanUp: RETAILMSG(ZONE_FUNCTION, (L"-SMARTREFLEX_DeinitPolicy()\r\n")); return rc; }
NTSTATUS PLxEvtDeviceReleaseHardware( IN WDFDEVICE Device, IN WDFCMRESLIST ResourcesTranslated ) /*++ Routine Description: Unmap the resources that were mapped in PLxEvtDevicePrepareHardware. This will only be called when the device stopped for resource rebalance, surprise-removed or query-removed. Arguments: Device - A handle to the WDFDEVICE ResourcesTranslated - The translated PnP resources associated with the device. This is what is important to a PCI device. Return Value: NT status code - failure will result in the device stack being torn down --*/ { KdPrint(("Entry PLxEvtDeviceReleaseHardware Routine")); PDEVICE_EXTENSION devExt; NTSTATUS status = STATUS_SUCCESS; UNREFERENCED_PARAMETER(ResourcesTranslated); PAGED_CODE(); TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> PLxEvtDeviceReleaseHardware"); devExt = PLxGetDeviceContext(Device); if (devExt->RegsBase) { MmUnmapIoSpace(devExt->RegsBase, devExt->RegsLength); devExt->RegsBase = NULL; } if(devExt->SRAMBase){ MmUnmapIoSpace(devExt->SRAMBase, devExt->SRAMLength); devExt->SRAMBase = NULL; } TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- PLxEvtDeviceReleaseHardware"); KdPrint(("Leave PLxEvtDeviceReleaseHardware Routine")); return status; }
VOID ScrLoadFontTable(UINT32 CodePage) { PHYSICAL_ADDRESS BaseAddress; PUCHAR Bitplane; PUCHAR FontBitfield = NULL; NTSTATUS Status = STATUS_SUCCESS; FontBitfield = (PUCHAR) ExAllocatePoolWithTag(NonPagedPool, 2048, TAG_BLUE); if(FontBitfield) { /* open bit plane for font table access */ OpenBitPlane(); /* get pointer to video memory */ BaseAddress.QuadPart = BITPLANE_BASE; Bitplane = (PUCHAR)MmMapIoSpace (BaseAddress, 0xFFFF, MmNonCached); Status = ExtractFont(CodePage, FontBitfield); if (NT_SUCCESS(Status)) LoadFont(Bitplane, FontBitfield); MmUnmapIoSpace(Bitplane, 0xFFFF); ExFreePool(FontBitfield); /* close bit plane */ CloseBitPlane(); } }
VOID SynthCleanup( IN PGLOBAL_SYNTH_INFO pGDI ) /*++ Routine Description: Clean up all resources allocated by our initialization Arguments: pGDI - Pointer to global data Return Value: NONE --*/ { // // Owning driver will remove all devices and free global data // if (pGDI->Hw.SynthBase && pGDI->MemType == 0) { ASSERT(pGDI->Key == SYNTH_KEY); MmUnmapIoSpace(pGDI->Hw.SynthBase, NUMBER_OF_SYNTH_PORTS); } pGDI->Hw.SynthBase = NULL; }
// HelpMapMMIOSpace: Map MMIO space bool HelpMapMMIOSpace( uint64 address, // IN size_t size, // IN uint64* mappedAddress, // OUT uint64* mappedSize) // OUT { bool result = false; void* pLinearAddress = NULL; PHYSICAL_ADDRESS physicalAddress; ResetPoolMemory(&physicalAddress, sizeof(PHYSICAL_ADDRESS)); physicalAddress.QuadPart = address; pLinearAddress = static_cast<PUCHAR>(MmMapIoSpace(physicalAddress, size, MmNonCached)); if (NULL != pLinearAddress) { if (MmIsAddressValid(pLinearAddress)) { *mappedAddress = reinterpret_cast<uint64>(pLinearAddress); *mappedSize = size; result = true; } else { MmUnmapIoSpace(pLinearAddress, size); } } return result; }
// The function that initilize the register for HSMMC Control. BOOL CSDHControllerCh1::InitHSMMC() { volatile S3C6410_HSMMC_REG *pHSMMC = NULL; PHYSICAL_ADDRESS ioPhysicalBase = {0,0}; ioPhysicalBase.LowPart = S3C6410_BASE_REG_PA_HSMMC1; pHSMMC = (volatile S3C6410_HSMMC_REG *)MmMapIoSpace(ioPhysicalBase, sizeof(S3C6410_HSMMC_REG), FALSE); if (pHSMMC == NULL) { RETAILMSG(TRUE, (TEXT("[HSMMC1] HSMMC Special Register is *NOT* mapped.\n"))); return FALSE; } #ifdef _SRCCLK_48MHZ_ RETAILMSG(TRUE, (TEXT("[HSMMC1] Setting registers for the USB48MHz (EXTCLK) : HSMMCCon.\n"))); // Set the clock source to USB_PHY for CLKMMC1 pHSMMC->CONTROL2 = (pHSMMC->CONTROL2 & ~(0xffffffff)) | (0x3<<9) | // Debounce Filter Count 0x3=64 iSDCLK (0x1<<8) | // SDCLK Hold Enable (0x3<<4); // Base Clock Source = External Clock #else RETAILMSG(TRUE, (TEXT("[HSMMC1] Setting registers for the EPLL : HSMMCCon.\n"))); // Set the clock source to EPLL out for CLKMMC1 pHSMMC->CONTROL2 = (pHSMMC->CONTROL2 & ~(0xffffffff)) | (0x3<<9) | // Debounce Filter Count 0x3=64 iSDCLK (0x1<<8) | // SDCLK Hold Enable (0x2<<4); // Base Clock Source = EPLL out #endif MmUnmapIoSpace((PVOID)pHSMMC, sizeof(S3C6410_HSMMC_REG)); return TRUE; }
// The function that initilize SYSCON for a clock gating. BOOL CSDHControllerCh1::InitClkPwr() { volatile S3C6410_SYSCON_REG *pCLKPWR = NULL; PHYSICAL_ADDRESS ioPhysicalBase = {0,0}; ioPhysicalBase.LowPart = S3C6410_BASE_REG_PA_SYSCON; pCLKPWR = (volatile S3C6410_SYSCON_REG *)MmMapIoSpace(ioPhysicalBase, sizeof(S3C6410_SYSCON_REG), FALSE); if (pCLKPWR == NULL) { RETAILMSG(TRUE, (TEXT("[HSMMC1] Clock & Power Management Special Register is *NOT* mapped.\n"))); return FALSE; } #ifdef _SRCCLK_48MHZ_ RETAILMSG(TRUE, (TEXT("[HSMMC1] Setting registers for the USB48MHz (EXTCLK for SDCLK) : SYSCon.\n"))); // SCLK_HSMMC#_48 : CLK48M_PHY(OTH PHY 48MHz Clock Source from SYSCON block) // To use the USB clock, must be set the "USB_SIG_MASK" bit in the syscon register. pCLKPWR->OTHERS |= (0x1<<16); // set USB_SIG_MASK pCLKPWR->HCLK_GATE |= (0x1<<18); // Gating HCLK for HSMMC1 pCLKPWR->SCLK_GATE |= (0x1<<28); // Gating special clock for HSMMC1 (SCLK_MMC1_48) #else RETAILMSG(TRUE, (TEXT("[HSMMC1] Setting registers for the EPLL (for SDCLK) : SYSCon.\n"))); // SCLK_HSMMC# : EPLLout, MPLLout, PLL_source_clk or CLK27 clock // (from SYSCON block, can be selected by MMC#_SEL[1:0] fields of the CLK_SRC register in SYSCON block) // Set the clock source to EPLL out for CLKMMC1 pCLKPWR->CLK_SRC = (pCLKPWR->CLK_SRC & ~(0x3<<20) & ~(0x1<<2)) | // Control MUX(MMC1:MOUT EPLL) (0x1<<2); // Control MUX(EPLL:FOUT EPLL) pCLKPWR->HCLK_GATE |= (0x1<<18); // Gating HCLK for HSMMC1 pCLKPWR->SCLK_GATE = (pCLKPWR->SCLK_GATE) | (0x1<<25); // Gating special clock for HSMMC1 (SCLK_MMC1) #endif MmUnmapIoSpace((PVOID)pCLKPWR, sizeof(S3C6410_SYSCON_REG)); return TRUE; }
VOID XenGfxFreeResources(XENGFX_DEVICE_EXTENSION *pXenGfxExtension) { PAGED_CODE(); // T & S Level 3 XenGfxDisableVCrtcs(pXenGfxExtension); if (pXenGfxExtension->pSources != NULL) { ExFreePoolWithTag(pXenGfxExtension->pSources, XENGFX_TAG); pXenGfxExtension->pSources = NULL; } XenGfxFreeVCrtcBanks(pXenGfxExtension); if (pXenGfxExtension->pXgfxRegs != NULL) { MmUnmapIoSpace(pXenGfxExtension->pXgfxRegs, pXenGfxExtension->XgfxRegistersDescriptor.u.Memory.Length); pXenGfxExtension->pXgfxRegs = NULL; pXenGfxExtension->pGartRegs = NULL; pXenGfxExtension->pVCrtcsRegs = NULL; pXenGfxExtension->pGlobalRegs = NULL; pXenGfxExtension->pGartBaseReg = NULL; } RtlZeroMemory(&pXenGfxExtension->GraphicsApertureDescriptor, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)); RtlZeroMemory(&pXenGfxExtension->XgfxRegistersDescriptor, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)); pXenGfxExtension->pPhysicalDeviceObject = NULL; pXenGfxExtension->hDxgkHandle = NULL; }
NTSTATUS fscc_card_delete(struct fscc_card *card, WDFCMRESLIST ResourcesTranslated) { unsigned bar_counter = 0; unsigned i = 0; for (i = 0; i < WdfCmResourceListGetCount(ResourcesTranslated); i++) { PCM_PARTIAL_RESOURCE_DESCRIPTOR descriptor; descriptor = WdfCmResourceListGetDescriptor(ResourcesTranslated, i); if (!descriptor) return STATUS_DEVICE_CONFIGURATION_ERROR; switch (descriptor->Type) { case CmResourceTypePort: bar_counter++; break; case CmResourceTypeMemory: MmUnmapIoSpace(card->bar[bar_counter].address, descriptor->u.Memory.Length); bar_counter++; break; } } return STATUS_SUCCESS; }
~CPdd6410Serial3() { if(m_pSysconRegs) { m_pSysconRegs->PCLK_GATE &= ~PCLK_UART3; // UART3 m_pSysconRegs->SCLK_GATE &= ~SCLK_UART; // UART0~3 } if (m_pIOPregs!=NULL) { MmUnmapIoSpace((PVOID)m_pIOPregs, sizeof(S3C6410_GPIO_REG)); } if (m_pSysconRegs!=NULL) { MmUnmapIoSpace((PVOID)m_pSysconRegs, sizeof(S3C6410_SYSCON_REG)); } }
/* * @implemented */ VOID EXPORT NdisMUnmapIoSpace( IN NDIS_HANDLE MiniportAdapterHandle, IN PVOID VirtualAddress, IN UINT Length) /* * FUNCTION: Un-maps space previously mapped with NdisMMapIoSpace * ARGUMENTS: * MiniportAdapterHandle: handle originally passed into MiniportInitialize * VirtualAddress: Address to un-map * Length: length of the mapped memory space * NOTES: * - Must be called at IRQL = PASSIVE_LEVEL * - Must only be called from MiniportInitialize and MiniportHalt * - See also: NdisMMapIoSpace * BUGS: * - Depends on MmUnmapIoSpace to Do The Right Thing in all cases */ { PAGED_CODE(); ASSERT(MiniportAdapterHandle); MmUnmapIoSpace(VirtualAddress, Length); }
CPdd6410Uart::~CPdd6410Uart() { InitModem(FALSE); if (m_hISTEvent) { m_bTerminated=TRUE; ThreadStart(); SetEvent(m_hISTEvent); ThreadTerminated(1000); InterruptDisable( m_dwSysIntr ); CloseHandle(m_hISTEvent); }; if (m_pReg6410Uart) { delete m_pReg6410Uart; } if (m_XmitFlushDone) { CloseHandle(m_XmitFlushDone); } if (m_pRegVirtualAddr != NULL) { MmUnmapIoSpace((PVOID)m_pRegVirtualAddr,sizeof(S3C6410_UART_REG)); } }
NTSTATUS TpmEvtDeviceReleaseHardware( IN WDFDEVICE Device, IN WDFCMRESLIST ResourcesTranslated ) { PTPM_CONTEXT TpmContext; PAGED_CODE(); TpmContext = GetTpmContext(Device); KdPrintEx((DPFLTR_PNPMEM_ID, DPFLTR_INFO_LEVEL, "TpmEvtDeviceReleaseHardware\n")); #if _NT_TARGET_VERSION >= 0x601 if(TpmContext->hEntropySource) EntropyUnregisterSource(TpmContext->hEntropySource); TpmContext->hEntropySource = NULL; #endif if(TpmContext->MemAddr) MmUnmapIoSpace(TpmContext->MemAddr,TpmContext->MemLen); TpmContext->MemAddr = NULL; TpmContext->MemLen = 0; KdPrintEx((DPFLTR_PNPMEM_ID, DPFLTR_INFO_LEVEL, "TpmEvtDeviceReleaseHardware exited with Status code 0x%x\n",STATUS_SUCCESS)); return STATUS_SUCCESS; }
NTSTATUS BalloonEvtDeviceReleaseHardware ( IN WDFDEVICE Device, IN WDFCMRESLIST ResourcesTranslated ) { PDEVICE_CONTEXT devCtx = NULL; TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s\n", __FUNCTION__); UNREFERENCED_PARAMETER(ResourcesTranslated); PAGED_CODE(); devCtx = GetDeviceContext(Device); if(devCtx->PortBase && devCtx->PortMapped) { MmUnmapIoSpace( devCtx->PortBase, devCtx->PortCount ); } devCtx->PortBase = NULL; TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s\n", __FUNCTION__); return STATUS_SUCCESS; }
RegCtrlG2D::~RegCtrlG2D() { if (m_pG2DReg != NULL) { MmUnmapIoSpace((PVOID)m_pG2DReg, sizeof(G2D_REG)); m_pG2DReg = NULL; } }
VOID NTAPI HalpUnmapVirtualAddress(IN PVOID VirtualAddress, IN ULONG NumberPages) { /* Use kernel memory manager I/O map facilities */ MmUnmapIoSpace(VirtualAddress, NumberPages << PAGE_SHIFT); }
uint32 peGetNumberOfRelocs(uint8 *peBaseAddr, void *realBase, PEPROCESS proc, PKAPC_STATE apc) { ImageDosHeader *dosHeader = NULL; ImageNtHeaders *ntHeaders = NULL; ImageSectionHeader *sectionHeader = NULL; ImageBaseRelocation *relocationPtr = NULL, *bkupRPtr = NULL; uint32 numRelocs = 0; PageTableEntry *pte = NULL; PHYSICAL_ADDRESS phys = {0}; uint16 i, j = 0, execSectionCount = 0, numSections = 0; dosHeader = (ImageDosHeader *) peBaseAddr; ntHeaders = (ImageNtHeaders *) ((uint8 *) peBaseAddr + dosHeader->e_lfanew); numSections = ntHeaders->FileHeader.NumberOfSections; sectionHeader = (ImageSectionHeader *) &ntHeaders[1]; for (i = 0; i < numSections; i++) { if(strncmp(sectionHeader[i].Name, ".reloc", 8) == 0) break; } if(strncmp(sectionHeader[i].Name, ".reloc", 8) != 0) return 0; /*DbgPrint("Found %.08s RVA: %x Characteristics: %x", sectionHeader[i].Name, sectionHeader[i].VirtualAddress, sectionHeader[i].Characteristics);*/ //KeStackAttachProcess(proc, apc); pte = pagingMapInPte(targetCR3, (uint8 *) (((uint32) realBase) + sectionHeader[i].VirtualAddress)); if (pte == NULL) return 0; phys.LowPart = pte->address << 12; pagingMapOutEntry(pte); relocationPtr = (ImageBaseRelocation *) MmMapIoSpace(phys, PAGE_SIZE, 0); bkupRPtr = relocationPtr; /*DbgPrint("%p + %x = %x", realBase, sectionHeader[i].VirtualAddress, (((uint32) realBase) + sectionHeader[i].VirtualAddress));*/ i = 0; do { //DbgPrint("RP: %x %x\r\n", relocationPtr->VirtualAddress, relocationPtr->SizeOfBlock); numRelocs += (relocationPtr->SizeOfBlock - sizeof(*relocationPtr)) / sizeof(uint16); relocationPtr = (ImageBaseRelocation *) ((uint8 *) relocationPtr + relocationPtr->SizeOfBlock); i++; } while(relocationPtr->SizeOfBlock != 0); MmUnmapIoSpace(bkupRPtr, PAGE_SIZE); //KeUnstackDetachProcess(apc); //DbgPrint("I %d\r\n", i); // Size of the table (minus the header) divided by the size of each entry // FIXME Figure out why this is the case return numRelocs - (i); }
VOID PushUnload( DRIVER_OBJECT* DriverObject ) { UNICODE_STRING DeviceLinkU; NTSTATUS ntStatus; PMAPINFO pMapInfo; PSINGLE_LIST_ENTRY pLink; DbgPrint("[Push] => (PushUnload)"); RdUnload(DriverObject); //free resources pLink=PopEntryList(&lstMapInfo); while(pLink) { pMapInfo=CONTAINING_RECORD(pLink, MAPINFO, link); MmUnmapLockedPages(pMapInfo->pvu, pMapInfo->pMdl); IoFreeMdl(pMapInfo->pMdl); MmUnmapIoSpace(pMapInfo->pvk, pMapInfo->memSize); ExFreePool(pMapInfo); pLink=PopEntryList(&lstMapInfo); } // // By default the I/O device is configured incorrectly or the // configuration parameters to the driver are incorrect. // ntStatus = STATUS_DEVICE_CONFIGURATION_ERROR; // // restore the call back routine, thus givinig chance to the // user mode application to unload dynamically the driver // ntStatus = PsSetCreateProcessNotifyRoutine(ProcessCallback, TRUE); IoDeleteDevice(DriverObject->DeviceObject); RtlInitUnicodeString(&DeviceLinkU, PUSH_SYMLINK_NAME); ntStatus=IoDeleteSymbolicLink(&DeviceLinkU); if (NT_SUCCESS(ntStatus)) { IoDeleteDevice(DriverObject->DeviceObject); } else { DbgPrint("Error: IoDeleteSymbolicLink failed"); } DbgPrint("[Push] <= (PushUnload)"); }
_Use_decl_annotations_ NTSTATUS ReleaseHardware( WDFDEVICE Device, WDFCMRESLIST ResourcesTranslated ) /*++ Routine Description: ReleaseHardware releases resources allocated by PrepareHardware. Arguments: Device - Pointer to the device object ResourceListTranslated - Ponter to the translated resource list of the device Return Value: NTSTATUS --*/ { PAGED_CODE(); UNREFERENCED_PARAMETER(ResourcesTranslated); PDEVICE_CONTEXT deviceContext; deviceContext = GetContext(Device); if (deviceContext->dmaChannelRegs) { MmUnmapIoSpace(deviceContext->dmaChannelRegs, sizeof(DMA_CHANNEL_REGS)); } if (deviceContext->pwmRegs) { MmUnmapIoSpace(deviceContext->pwmRegs, sizeof(PWM_REGS)); } if (deviceContext->cmPwmRegs) { MmUnmapIoSpace(deviceContext->cmPwmRegs, sizeof(CM_PWM_REGS)); } return STATUS_SUCCESS; }
/* * @implemented */ VOID NTAPI MmUnmapVideoDisplay(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes) { // // Call the real function // MmUnmapIoSpace(BaseAddress, NumberOfBytes); }
NTSTATUS AmccPciEvtDeviceReleaseHardware ( _In_ WDFDEVICE hDevice, _In_ WDFCMRESLIST ResourcesTranslated ) /*++ Routine Description: EvtDeviceReleaseHardware is called by the framework whenever the PnP manager is revoking ownership of our resources. This may be in response to either IRP_MN_STOP_DEVICE or IRP_MN_REMOVE_DEVICE. The callback is made before passing down the IRP to the lower driver. In this callback, do anything necessary to free those resources. Arguments: Device - Handle to a framework device object. ResourcesTranslated - Handle to a collection of framework resource objects. This collection identifies the translated (system-physical) hardware resources that have been assigned to the device. The resources appear from the CPU's point of view. Use this list of resources to map I/O space and device-accessible memory into virtual address space Return Value: VOID --*/ { PAMCC_DEVICE_EXTENSION devExt = NULL; UNREFERENCED_PARAMETER(ResourcesTranslated); PAGED_CODE(); devExt = AmccPciGetDevExt(hDevice); // // Unmap the IO resource // if (devExt->PortBase) { if (devExt->PortMapped) { MmUnmapIoSpace( devExt->PortBase, devExt->PortCount ); } devExt->PortBase = NULL; } return STATUS_SUCCESS; }
void AcpiOsUnmapMemory ( void *virt, ACPI_SIZE length) { DPRINT("AcpiOsMapMemory(phys 0x%p size 0x%X)\n", virt, length); ASSERT(virt); MmUnmapIoSpace(virt, length); }
VOID NdisMUnmapIoSpace( IN NDIS_HANDLE MiniportAdapterHandle, IN PVOID VirtualAddress, IN UINT Length ) { #ifndef _ALPHA_ MmUnmapIoSpace(VirtualAddress, Length); #endif }
/** * Unmaps the VMMDev I/O range from kernel space. * * @param pDevExt The device extension. */ void vboxguestwinUnmapVMMDevMemory(PVBOXGUESTDEVEXT pDevExt) { Log(("VBoxGuest::vboxguestwinUnmapVMMDevMemory: pVMMDevMemory = 0x%x\n", pDevExt->pVMMDevMemory)); if (pDevExt->pVMMDevMemory) { MmUnmapIoSpace((void*)pDevExt->pVMMDevMemory, pDevExt->win.s.vmmDevPhysMemoryLength); pDevExt->pVMMDevMemory = NULL; } pDevExt->win.s.vmmDevPhysMemoryAddress.QuadPart = 0; pDevExt->win.s.vmmDevPhysMemoryLength = 0; }
//----------------------------------------------------------------------------- void NAND_Uninitialize( HANDLE hNand ) { #ifdef BOOT_MODE UNREFERENCED_PARAMETER(hNand); #else NandDevice_t *pDevice = (NandDevice_t*)hNand; if (pDevice->pGpmcRegs != NULL) { MmUnmapIoSpace((void*)pDevice->pGpmcRegs, pDevice->memLen[0]); } if (pDevice->pFifo != NULL) { MmUnmapIoSpace((void*)pDevice->pFifo, pDevice->memLen[1]); } #endif }
NTSTATUS _write_phys_mem( PHYSICAL_ADDRESS pa, unsigned int len, void * pData ) { void * va = MmMapIoSpace( pa, len, MmCached ); if( !va ) { DbgPrint( "[chipsec] ERROR: no space for mapping\n" ); return STATUS_UNSUCCESSFUL; } DbgPrint( "[chipsec] writing %d bytes to physical address 0x%08x_%08x (virtual = %#010x)", len, pa.HighPart, pa.LowPart, (unsigned int)va ); RtlCopyMemory( va, pData, len ); MmUnmapIoSpace( va, len ); return STATUS_SUCCESS; }