On 4/25/07, <b class="gmail_sendername">Peter Stuge</b> <<a href="mailto:stuge-linuxbios@cdy.org">stuge-linuxbios@cdy.org</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Tue, Apr 24, 2007 at 11:15:24PM +0700, Darmawan Salihun wrote:<br>> >Do we need a wrapper for those "map-physical-memory" functions?<br>><br>> I think we don't need it because it has an "equivalent" in Windows'
<br>> kernel mode driver, i.e.<br>><br>> PVOID MmGetSystemAddressForMdlSafe(IN PMDL  Mdl, IN<br>> MM_PAGE_PRIORITY Priority);<br><br>Is MmMapIoSpace() strictly for io? Otherwise it may also be a<br>candidate.<br>
</blockquote>...ah, you're right Peter. It was in the midnight back then when I wrote mail. It should've been <br>MmMapIoSpace(..), not MmGetSystemAddressForMdlSafe(..) function. I have something in the works right now for the porting of flashrom to Windows. Below is the snippet (in case you are curious about it ;)
<br>----------<br>    //<br>    // We have obtained a free mapZone, map the physical address range.<br>    //    <br>    pUsermodeMem =  (MMIO_MAP*) MmGetSystemAddressForMdlSafe( pIrp->MdlAddress, NormalPagePriority );
<br>    if( NULL == pUsermodeMem) {<br>    return STATUS_INVALID_USER_BUFFER;<br>    } <br>    <br>    phyAddr.HighPart = 0;<br>    phyAddr.LowPart = pUsermodeMem->phyAddrStart;<br><br>    pDevExt->mapZone[free_idx].sysAddrBase = MmMapIoSpace( phyAddr, pUsermodeMem->size, MmNonCached);
<br>    if(NULL == pDevExt->mapZone[free_idx].sysAddrBase)<br>    {<br>    return STATUS_BUFFER_TOO_SMALL;<br>    }<br>    <br>    pDevExt->mapZone[free_idx].pMdl = IoAllocateMdl(pDevExt->mapZone[free_idx].sysAddrBase, 
<br>                            pUsermodeMem->size, FALSE, FALSE, NULL);<br>    if(NULL == pDevExt->mapZone[free_idx].pMdl)         <br>    {<br>    MmUnmapIoSpace(pDevExt->mapZone[free_idx].sysAddrBase, pUsermodeMem->size);
<br>    pDevExt->mapZone[free_idx].sysAddrBase = NULL;<br>    return STATUS_BUFFER_TOO_SMALL;<br>    }<br><br>    pDevExt->mapZone[free_idx].size = pUsermodeMem->size;<br><br>    //<br>    // Map the system virtual address to usermode virtual address
<br>    // <br>    MmBuildMdlForNonPagedPool(pDevExt->mapZone[free_idx].pMdl);<br>    pDevExt->mapZone[free_idx].usermodeAddrBase = MmMapLockedPagesSpecifyCache(    pDevExt->mapZone[free_idx].pMdl, <br>                                        UserMode, MmNonCached, 
<br>                                        NULL, FALSE,  <br>                                        NormalPagePriority);<br>    if(NULL ==  pDevExt->mapZone[free_idx].usermodeAddrBase)<br>    {<br>    IoFreeMdl(pDevExt->mapZone[free_idx].pMdl);
<br>    MmUnmapIoSpace(pDevExt->mapZone[free_idx].sysAddrBase, pDevExt->mapZone[free_idx].size);<br>    pDevExt->mapZone[free_idx].sysAddrBase = NULL;<br>    pDevExt->mapZone[free_idx].size = 0;<br>    return STATUS_BUFFER_TOO_SMALL;
<br>    } <br>----------------- <br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"></blockquote><br><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
It seems an MDL is always specified with a virtual address but I<br>can't find a phystovirt() in the Mm functions. Admittedly I didn't<br>look very hard so you may already have found it. :)<br></blockquote>Basically, the conversion to User mode virtual address is in the code snippet above ;-)
<br><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>> The main problem is the mechanism will be a bit different because<br>> flashrom will be divided into kernel mode driver and user mode
<br>> application in Windows.<br><br>I think I like having more of the logic in the kernel driver for<br>once, this is because the algorithms can benefit in speed, and<br>because the system will be more stable as long as the kernel driver
<br>is bug free. ;)<br><br>Letting the app drive everything is less intrusive of course, but<br>could also put the system into an unknown state if the app is aborted<br>halfway through something.<br></blockquote>I'll look forward this issue. Thanks.
<br><br>--Darmawan</div>--------------------------------------------------------------------<br>-= Human knowledge belongs to the world =-