Physical Address From VirtualMemory in WEC7 RRS feed

  • Question

  • Hi,

    I am trying to port a miniport driver from Windows 7 to WEC7. As part of the porting, we found there is no support for API "MmGetPhysicalAddress" (It returns the physical address for non-paged virtual address) in WEC7. 

    After looking into msdn doc'n,  found one API i.e., LockPages can be used to get the physical address from virtual address. But couldn't find any examples on how to use it ?

    I would like to know whether this (
    LockPages ) API is correct and if so , any examples on usage of it ?


    • Edited by SPmishra Thursday, May 18, 2017 10:08 AM
    Wednesday, May 17, 2017 2:10 PM

All replies

  • Hi SPmishra,

    I think I would suggest looking at the miniport sample in WEC.  Do you have a WINCEROOT that looks something like this? C:\WINCE700\public\common\oak\drivers\netsamp\passthru\miniport.c

    Also, a previous poster claims they had little issue porting their driver...

    Also, in a previous post with a similar question, MVP Valter Minute gave the following response:

    HALAllocateCommonBuffer already returns a valid virtual pointer. You don't need to use VirtualAlloc/Copy to remap the physical address.



    Saturday, June 3, 2017 5:52 AM
  • Hi

    Thanks for your help. 
    But am doing below implementation for getting physical address from virtual address. Is this correct. ?


    NdisQueryMdl(pmdl, &data, &length, PagePriority);

    addr = MmGetPhysicalAddress(data);


    NdisQueryMdl(pmdl, &data, &length, PagePriority);

    if(LockPages(data, length, &pfn, (LOCKFLAG_WRITE | LOCKFLAG_READ)))
    ( (pfn) << UserKInfo[KINX_PFN_SHIFT] )


    • Edited by SPmishra Thursday, June 29, 2017 10:23 AM
    Thursday, June 29, 2017 10:22 AM
  • Yes, that would be correct.  I am doing the equivalent code sequence in one of my drivers:

    LockPages(pVirtualAddress, UserKInfo[KINX_PAGESIZE], &pfn, LOCKFLAG_QUERY_ONLY);

    physAddr = pfn << UserKInfo[KINX_PFN_SHIFT];

    Thursday, July 6, 2017 3:36 PM
  • Thanks for this conformation.
    Can you explain why you are using UserKInfo[KINX_PAGESIZE] as the length what size it gives.  But in my case the length value is always set to ZERO. Is that correct to make length value ZERO. ?

    Why can't we use below API. And what difference it gives from LockPages().


    Any idea ??


    • Edited by SPmishra Friday, July 7, 2017 12:12 PM
    Friday, July 7, 2017 12:04 PM
  • HALAllocateCommonBuffer actually allocates some memory, LockPages just return the physical addresses.

    On the other side HalAllocateCommonBuffer grants that the memory is contiguous in both physical and virtual space and this may be required if you need to use DMA. LockPages may return non-contiguous addresses for the page pool and so just translating the address of first page may not work. Will work only if you know for sure that the memory has been allocated to be DMA-compatible (and this requires HalAllocateCommonBuffer).

    Valter Minute<br/> Windows Embedded MVP<br/><br/>

    Monday, July 10, 2017 6:05 AM
  • Thanks man.

    I am doubtful whether I will be able to use HalAllocateCommonBuffer(). This is because the
    parameters this API need. I cant find any DMA_ADAPTER_OBJECT AdapterObject HANDLE in my driver.
    Do u have any idea how and where to derive this. And also the parameters such as..

        AdapterObject.ObjectSize = ; ?
        AdapterObject.InterfaceType = ;?
        AdapterObject.BusNumber = ;?


    Tuesday, July 11, 2017 2:31 PM