Re: Flushing DMA Buffer Allocated with AllocateCommonBuffer

The documentation does require it. While the page in the DDK help labeled
“Using Common-Buffer Bus-Master DMA” makes no mention of allocating an MDL
and passing it to KeFlushIoBuffers, the page “Flushing Cached Data during
DMA Operations” infers it if you mark the buffers as CacheEnabled.

Problem in the DDK docs?

“Mark Roddy” wrote in message news:xxxxx@ntdev…
> 3) common buffers are ‘special’. They are platform specific designed to
> be used for dma. The documentation in the DDK does not require that you
> flush common buffers.
>
> Note that on x86 platforms KeFlushIoBuffers is a NOP. Draw your own
> conclusions.
>

Hmmm… I find that page more than a little confusing, don’t you? At any
rate, I do stand by my previous point 1): why is he allocating a cached
common buffer? If he would stop doing that everything would work correctly
on all platforms and he would not have to go through the idiocy of
allocating an MDL to describe a common buffer so that he can call the NOP
function KeFlushIoBuffers.

Note also that over in videoport the docs are quite different. All that the
miniport has to do is allocate the common buffer and release it. No flushing
seems to be required. Odd huh? I guess video must just be broken on NT :slight_smile:

Here is some more oddness - on the ndis side NdisUpdateSharedMemory does
nothing on any platform, and NdisFlushBuffer does nothing on current
platforms, except the IA64, where it is KeFlushIoBuffers.

Scsiport avoids this mess by forcing the miniport to use a noncached common
buffer. Hmmmm… Clue?

But if we are going to go by what the DDK docs say, check this out in the
description of KeFlushIoBuffers:

“Drivers call KeFlushIoBuffers to maintain data integrity during DMA or PIO
device transfer operations. Calling this routine affects all processors in
the machine.”

I actually have never met the driver that does a KeFlushIoBuffers every time
it finishes a PIO operation. Have any of you?

You have to call KeFlushIoBuffers on a PIO transfer for some platforms, so
by implication you have to do it on all platforms or your driver is
technically broken.

So here is what I think: x86 and amd64 snoop all memory transactions from
anywhere, and there is no issue on these platforms. IA64, like Alpha and
some of those other older platforms, has ‘issues’ here and consequently you
have to go through the idiocy of building MDLs for common buffers (or for
system buffers if you are doing PIO) so that the OS can handle edge
conditions on some platforms.

Maybe DriverFrameWorks will fix this mess?

Too bad I didn’t think to ask somebody about this at the driver lovefest in
redmond this week.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doug
Sent: Friday, November 14, 2003 11:05 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Re: Flushing DMA Buffer Allocated with
AllocateCommonBuffer

The documentation does require it. While the page in the DDK
help labeled “Using Common-Buffer Bus-Master DMA” makes no
mention of allocating an MDL and passing it to
KeFlushIoBuffers, the page “Flushing Cached Data during DMA
Operations” infers it if you mark the buffers as CacheEnabled.

Problem in the DDK docs?

“Mark Roddy” wrote in message
> news:xxxxx@ntdev…
> > 3) common buffers are ‘special’. They are platform specific
> designed
> > to be used for dma. The documentation in the DDK does not
> require that
> > you flush common buffers.
> >
> > Note that on x86 platforms KeFlushIoBuffers is a NOP. Draw your own
> > conclusions.
> >
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@hollistech.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>

Why? Performance. I see close to a 100% performance improvement using cached
buffers.

Also, since this code will run on ia64, I will do what is described so that
it does not come back to bite me (as it did on other operating
systems/platforms).

“Mark Roddy” wrote in message news:xxxxx@ntdev…
>
> Hmmm… I find that page more than a little confusing, don’t you? At any
> rate, I do stand by my previous point 1): why is he allocating a cached
> common buffer? If he would stop doing that everything would work correctly
> on all platforms and he would not have to go through the idiocy of
> allocating an MDL to describe a common buffer so that he can call the NOP
> function KeFlushIoBuffers.
>
> Note also that over in videoport the docs are quite different. All that
the
> miniport has to do is allocate the common buffer and release it. No
flushing
> seems to be required. Odd huh? I guess video must just be broken on NT :slight_smile:
>
> Here is some more oddness - on the ndis side NdisUpdateSharedMemory does
> nothing on any platform, and NdisFlushBuffer does nothing on current
> platforms, except the IA64, where it is KeFlushIoBuffers.
>
> Scsiport avoids this mess by forcing the miniport to use a noncached
common
> buffer. Hmmmm… Clue?
>
> But if we are going to go by what the DDK docs say, check this out in the
> description of KeFlushIoBuffers:
>
> “Drivers call KeFlushIoBuffers to maintain data integrity during DMA or
PIO
> device transfer operations. Calling this routine affects all processors in
> the machine.”
>
> I actually have never met the driver that does a KeFlushIoBuffers every
time
> it finishes a PIO operation. Have any of you?
>
> You have to call KeFlushIoBuffers on a PIO transfer for some platforms, so
> by implication you have to do it on all platforms or your driver is
> technically broken.
>
> So here is what I think: x86 and amd64 snoop all memory transactions from
> anywhere, and there is no issue on these platforms. IA64, like Alpha and
> some of those other older platforms, has ‘issues’ here and consequently
you
> have to go through the idiocy of building MDLs for common buffers (or for
> system buffers if you are doing PIO) so that the OS can handle edge
> conditions on some platforms.
>
> Maybe DriverFrameWorks will fix this mess?
>
> Too bad I didn’t think to ask somebody about this at the driver lovefest
in
> redmond this week.
>