1

I am porting Windows 7 Network driver code to WEC7. I got stuck with the API MmGetPhysicalAddress. I didn't find equivalent API to this in WEC7. Can anyone help to proceed further..

Thanks.

2 Answers2

0

MmGetPhysicalAddress is not available in Windows CE, but you probably don't need it anyway.

Somewhere in the InitializeHandlerEx callback, the driver should be calling NdisMAllocateSharedMemory to allocate RX/TX buffers.

NdisMAllocateSharedMemory returns both the virtual and physical address of the allocated buffer, so you can keep the physical address around, and then there won't be any need to request it from the OS.

Normally the physical address would be kept in a driver-specific, per-buffer structure along with the virtual buffer address.

You can find a sample implementation of this in C:\WINCE700\public\COMMON\oak\drivers\netcard\e100bex\60. In mp_init.c, notice how NICAllocAdapterMemory calls NdisMAllocateSharedMemory and stores the physical address of each buffer in pMpTxbuf->BufferPa.

Carsten Hansen
  • 1,508
  • 2
  • 21
  • 27
  • My requirement is to send some command to firmware, to do this I am allocating a buffer at lower layer. I am not using the buffers(tx/rx) allocated in InitializeHandlerEx to send commands to FW. As my network adapter is PCI, I need to map the virtual address to physical address of MDL. How can I get physical address of allocated MDL? – sathish reddy s Jul 27 '17 at 13:12
  • You could probably get away with using `LockPages` as suggested by Valter, but if the buffer was allocated using a non-NDIS function you would need to ensure that it is physically contiguous, assuming you are going to do a DMA transfer – Carsten Hansen Jul 28 '17 at 02:24
0

You may have a look at LockPages: https://msdn.microsoft.com/en-us/library/ee482989.aspx But if the buffer was not allocated using NDIS functions it may not be fully contiguous in physical memory, so you may need to check that.

Valter Minute
  • 2,177
  • 1
  • 11
  • 13
  • I used the below code to replace the Windows 7 code: DWORD pfn, offset_addr; if(!LockPages(data, length, &pfn, (LOCKFLAG_READ | LOCKFLAG_WRITE))){ printk("LockPages failed for block buffer\r\n");} offset_addr = pfn << UserKInfo[KINX_PFN_SHIFT]; skb->wb_mapped_paddr_lo[0] = offset_addr + ((DWORD)NET_BUFFER_DATA_OFFSET(os_buf)); I am not sure whether it is correct or not? Could you check this? – sathish reddy s Jul 27 '17 at 13:14
  • I don't understand your code, missing meaning of some vars and not well formatted. Do you get an error calling LockPages? – Valter Minute Jul 28 '17 at 15:13