RE: Problem with Virtual to Physical address conversi- on

Indira,

You need to go look at classpnp and disk in the ddk src directory. There you
will find all the details about how to build a request for scsi targets. You
have made a lot of assumptions about how an SRB is constructed, and those
assumptions are not correct. To start with - Srb.DataBuffer does NOT point
to an MDL, it points to the user’s original data buffer (hence the name
‘DataBuffer’.) Scsi miniport drivers do not even know what an MDL is. By the
way, you should be able to use classpnp directly in your driver to
send/receive requests to scsiport targets. Read the code.

Second, perhaps I should have been more explicit: DO NOT USE INTERNAL MDL
FIELDS, EVER, UNLESS YOU REALLY KNOW WHAT YOU ARE DOING, AND YOU DON’T. BAD
BAD BAD. Sorry if that was a little harsh.

Mdl.MappedSystemVa is way up at the top of the list of internal MDL fields
that you should never access directly. Instead use the function
MmGetSystemAddressForMdl, that is why it is there.

-----Original Message-----
From: Indira [mailto:xxxxx@uiscpl.com]
Sent: Wednesday, August 22, 2001 2:02 AM
To: NT Developers Interest List
Subject: [ntdev] RE: Problem with Virtual to Physical address conversion

Hi All,
Thanks for the reply,
With respect to 2nd question/answer,
In NDIS driver, the complete packet is sent down to the SCSI Driver by
getting the
Buffer = NdisGetFirstBufer() ;
pMdl = (PMDL) Buffer ;
and this pMdl is sent down to SCSI driver through
SRB->DataBuffer = pMdl;
Therefore, in SCSI driver we get MDL and which is the first buffer and has
pointers to next NDIS_BUFFER, so each buffer has to be converted to the
physical address and that we are doing it by converting MDL->MappedSystemVa
to physical address by calling
ScsiPortGetPhysicalAddress(
IN PVOID HwDeviceExtension,
IN PSCSI_REQUEST_BLOCK Srb OPTIONAL,
IN PVOID VirtualAddress,
OUT ULONG *Length
);
If this is the source of the problem then what may be the right way of
achiving the same?
For our clarification we also called the routine, MmGetPhysicalAddress(),
but this sometimes returns the physical address which is different from the
address of ScsiPortGetPhysicalAddress(), what may be the reason? and which
one should we use?
Thanks again,
Indira

Subject: RE: Problem with Virtual to Physical address conversion

From: “Roddy, Mark”
Date: Tue, 9 Oct 2001 09:34:10 -0400
X-Message-Number: 17
1) In general you should never be using the internal virtual or physical
address pointers in an MDL. MappedSystemVa is frequently not going to be the

same as StartVa+ByteOffset, as StartVa is likely to be a process-specific
usermode virtual address, while MappedSystemVa, if it is valid, is a process

independent kernel mode virtual address. If nobody has ever called
MmGetSystemAddressForMdl, MappedSystemVa is garbage.
2) No, if I understand you correctly, it is not fine at all to attempt to
convert Mdl->MappedSystemVa directly to a physical address. In general you
should not be trying to convert virtual addresses to physical except through

the defined scsiport mechanism:
ScsiPortGetPhysicalAddress(
IN PVOID HwDeviceExtension,
IN PSCSI_REQUEST_BLOCK Srb OPTIONAL,
IN PVOID VirtualAddress,
OUT ULONG *Length
);
Where VirtualAddress is the value supplied in Srb.DataBuffer (perhaps offset

by some value.) You can convert other virtual addresses to physical using
this interface as well (when the address is not related to the
Srb.DataBuffer.)
But specifically in your case, scsiport has done all the work for you and
you should not ever have to look at mdls. Everything you need is in the SRB.

If you have done things correctly in your ndis driver then the scsiport side

should just work like any other miniport driver without your having to go
through all sorts of gyrations.
I have no explanation for why you appear to be getting invalid virtual
addresses. I would look at the ndis side.
-----Original Message-----
>From: Indira [mailto:xxxxx@uiscpl.com]
Sent: Tuesday, August 21, 2001 7:58 AM
To: NT Developers Interest List
Subject: [ntdev] Problem with Virtual to Physical address conversion

Hi All,
We are developing a layered driver, upper one being NDIS miniport driver and

the lower one is SCSI miniport driver. We are passing the NDIS_BUFFERs (the

MDL) of NDIS_PACKET down to the scsi driver where it’s converted to physical

address.
We arefacing some problems with this:
1. Sometimes the Mdl->MappedSystemVa & (Mdl->StartVa + Mdl->ByteOffset) are

different addresses, and the
routine MmIsAddressValid() returns FALSE for both the address. Even the
address from MmGetSystemAddressForSafe() returns an invalid address (Tested
with MmIsAddressValid), so what could be the reason & the soultuion?
2. Is it fine to convert the Mdl->MappedSystemVa to phsyical address
directly or is it required to copy
the content to other loaction before converting to physical address?
Thanks in advance,
Indira

“When you move beyond your fear, you feel free”

You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com