Looking for a WDM DMA Sample

I have a busmaster radar video device. Each time the device gives me a
“I’ve got data” interrupt, I need to build a chain of DMA descriptors
telling it from whence and to where I want the data. I allocated the
descriptors from non-paged pool. I need to get the DMA chain’s address in
such a form that, when I put that 32-bit address into a register on my
board, it can read the chain from memory and execute it.

What I’m doing now is trying to calculate the PHYSICAL_ADDRESS of the
chain. Maybe this works; I’m not sure. What I do know is that I’m
stepping all over memory and bugchecking W2k. What fun!

I’d like to find a sample WDM driver that does DMA. (Also one that does
scatter/gather would be nice.) The OSR sample doesn’t (seem to me) to
help me. And Mr Oney’s book leaves out that final step.

Any help would be appreciated. Thanks.

john.

> What I’m doing now is trying to calculate the

PHYSICAL_ADDRESS of the

Well, there has to be a Api call to get that.
MmGetPhysicalAddress will do that, but for some reason
MS warns against using it with DMA.

Asher


Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

Peter Viscarola of OSR gives a very good class in Windows 2000 Device
Drivers. They offer a lab where you have a computer with a board that
presents itself on both the ISA and PCI bus. The PCI side uses DMA. I
remember, but haven’t needed to do it myself, that there are specific calls
using map registers to handle DMA. It just works. It helps if the device
follows the PCI specs.

----- Original Message -----
From: “John Reilly”
To: “NT Developers Interest List”
Sent: Thursday, September 26, 2002 2:26 PM
Subject: [ntdev] Looking for a WDM DMA Sample

> I have a busmaster radar video device. Each time the device gives me a
> “I’ve got data” interrupt, I need to build a chain of DMA descriptors
> telling it from whence and to where I want the data. I allocated the
> descriptors from non-paged pool. I need to get the DMA chain’s address in
> such a form that, when I put that 32-bit address into a register on my
> board, it can read the chain from memory and execute it.
>
> What I’m doing now is trying to calculate the PHYSICAL_ADDRESS of the
> chain. Maybe this works; I’m not sure. What I do know is that I’m
> stepping all over memory and bugchecking W2k. What fun!
>
> I’d like to find a sample WDM driver that does DMA. (Also one that does
> scatter/gather would be nice.) The OSR sample doesn’t (seem to me) to
> help me. And Mr Oney’s book leaves out that final step.
>
> Any help would be appreciated. Thanks.
>
> john.
>
> —
> You are currently subscribed to ntdev as: xxxxx@yoshimuni.com
> To unsubscribe send a blank email to %%email.unsub%%

MmGetPhysicalAddress doesn’t know how to take into account which device
the DMA transfer is directed to. If the device or the bus it’s on can’t
access that memory address for some reason (like it’s above the 4GB
mark) and you hand the address to the controller then bad things can
happen.

you’d probably want to look at the DMA API routines like IoGetDmaAdapter
and the routines in the DMA_OPERATIONS structure that it (indirectly)
returns such as AllocateCommonBuffer (to get shared memory blocks in
which to build your descriptors) and/or [Get|Put]ScatterGatherList in
order to build SG lists of physical addreses for arbitrary (locked-down)
MDLs.

-p

-----Original Message-----
From: Asher Hoodin [mailto:xxxxx@yahoo.com]
Sent: Thursday, September 26, 2002 12:05 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

What I’m doing now is trying to calculate the PHYSICAL_ADDRESS of the

Well, there has to be a Api call to get that. MmGetPhysicalAddress will
do that, but for some reason MS warns against using it with DMA.

Asher


Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com


You are currently subscribed to ntdev as: xxxxx@microsoft.com To
unsubscribe send a blank email to %%email.unsub%%

John:

If you hardware DMA engine reads directly from system memory for
scatter-gather-list descriptor, what you need is to use
MmAllocateContiguousMemorySpecifyCache for this memory instead of allocate
it from a nonpaged pool. Then you can use MmGetPhysicalAddress to get what
you want. The reason is that when you allocate the memory from nonpaged
pool, it many not be physically contiguous. But you hardware does not know
that, it keeps reading scatter-gather-list descriptor which may be garbage
if it is cross the page boundary of what you allocated from nonpaged pool.
When it DMA, it writes to arbitary memory. Most bus master DMA use
scatter-gather-list descriptor will see a null descriptor before it stops.

This will help you.

Bi

-----Original Message-----
From: John Reilly [mailto:xxxxx@nexet.net]
Sent: Thursday, September 26, 2002 11:26 AM
To: NT Developers Interest List
Subject: [ntdev] Looking for a WDM DMA Sample

I have a busmaster radar video device. Each time the device gives me a
“I’ve got data” interrupt, I need to build a chain of DMA descriptors
telling it from whence and to where I want the data. I allocated the
descriptors from non-paged pool. I need to get the DMA chain’s address in
such a form that, when I put that 32-bit address into a register on my
board, it can read the chain from memory and execute it.

What I’m doing now is trying to calculate the PHYSICAL_ADDRESS of the
chain. Maybe this works; I’m not sure. What I do know is that I’m
stepping all over memory and bugchecking W2k. What fun!

I’d like to find a sample WDM driver that does DMA. (Also one that does
scatter/gather would be nice.) The OSR sample doesn’t (seem to me) to
help me. And Mr Oney’s book leaves out that final step.

Any help would be appreciated. Thanks.

john.


You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%

RE: [ntdev] Looking for a WDM DMA SampleSorry Bi, but you missed the boat.

John, go back and re-read Peter Wielands comment very carefully.

Bus Mastering Scatter-Gather DMA has been greatly simplifed in 2000 and above. After filling in the DMA descriptor and creating a DMA adapter object you then use the functions within that DMA adapter object to process an MDL describing the buffer. If the kernel hands you that buffer from user request such as a Read/WriteFile, it has been set for system memory and all you have to do is pass each page of the buffer through IoMapTransfer, or simply call DmaObject->GetScatterGatherList with an MDL describing a system buffer.

Gary G. Little
909-551-2105
909-698-3191
“Bi Chen” wrote in message news:xxxxx@ntdev…
John:

If you hardware DMA engine reads directly from system memory for scatter-gather-list descriptor, what you need is to use MmAllocateContiguousMemorySpecifyCache for this memory instead of allocate it from a nonpaged pool. Then you can use MmGetPhysicalAddress to get what you want. The reason is that when you allocate the memory from nonpaged pool, it many not be physically contiguous. But you hardware does not know that, it keeps reading scatter-gather-list descriptor which may be garbage if it is cross the page boundary of what you allocated from nonpaged pool. When it DMA, it writes to arbitary memory. Most bus master DMA use scatter-gather-list descriptor will see a null descriptor before it stops.

This will help you.

Bi

-----Original Message-----
From: John Reilly [mailto:xxxxx@nexet.net]
Sent: Thursday, September 26, 2002 11:26 AM
To: NT Developers Interest List
Subject: [ntdev] Looking for a WDM DMA Sample

I have a busmaster radar video device. Each time the device gives me a
“I’ve got data” interrupt, I need to build a chain of DMA descriptors
telling it from whence and to where I want the data. I allocated the
descriptors from non-paged pool. I need to get the DMA chain’s address in
such a form that, when I put that 32-bit address into a register on my
board, it can read the chain from memory and execute it.

What I’m doing now is trying to calculate the PHYSICAL_ADDRESS of the
chain. Maybe this works; I’m not sure. What I do know is that I’m
stepping all over memory and bugchecking W2k. What fun!

I’d like to find a sample WDM driver that does DMA. (Also one that does
scatter/gather would be nice.) The OSR sample doesn’t (seem to me) to
help me. And Mr Oney’s book leaves out that final step.

Any help would be appreciated. Thanks.

john.


You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%

Gary.

I don’t think you understand John’s problem. I think John knows how to use
DMA Adpater object. I have written many PCI bus master device drivers to
know his problem. If you read his post carefully, what he needs to know is
not how to get scatter gather list, but where to put the descriptor that
hardware understand and need to read to perform the hardware DMA operation.

Bi

-----Original Message-----
From: Gary G. Little [mailto:xxxxx@inland.net]
Sent: Thursday, September 26, 2002 1:40 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

Sorry Bi, but you missed the boat.

John, go back and re-read Peter Wielands comment very carefully.

Bus Mastering Scatter-Gather DMA has been greatly simplifed in 2000 and
above. After filling in the DMA descriptor and creating a DMA adapter object
you then use the functions within that DMA adapter object to process an MDL
describing the buffer. If the kernel hands you that buffer from user request
such as a Read/WriteFile, it has been set for system memory and all you have
to do is pass each page of the buffer through IoMapTransfer, or simply call
DmaObject->GetScatterGatherList with an MDL describing a system buffer.

Gary G. Little
909-551-2105
909-698-3191

“Bi Chen” < xxxxx@AppStream.com mailto:xxxxx > wrote in
message news:xxxxx@ntdev news:xxxxx

John:

If you hardware DMA engine reads directly from system memory for
scatter-gather-list descriptor, what you need is to use
MmAllocateContiguousMemorySpecifyCache for this memory instead of allocate
it from a nonpaged pool. Then you can use MmGetPhysicalAddress to get what
you want. The reason is that when you allocate the memory from nonpaged
pool, it many not be physically contiguous. But you hardware does not know
that, it keeps reading scatter-gather-list descriptor which may be garbage
if it is cross the page boundary of what you allocated from nonpaged pool.
When it DMA, it writes to arbitary memory. Most bus master DMA use
scatter-gather-list descriptor will see a null descriptor before it stops.

This will help you.

Bi

-----Original Message-----
From: John Reilly [mailto:xxxxx@nexet.net
mailto:xxxxx]
Sent: Thursday, September 26, 2002 11:26 AM
To: NT Developers Interest List
Subject: [ntdev] Looking for a WDM DMA Sample

I have a busmaster radar video device. Each time the device gives me a
“I’ve got data” interrupt, I need to build a chain of DMA descriptors
telling it from whence and to where I want the data. I allocated the
descriptors from non-paged pool. I need to get the DMA chain’s address in
such a form that, when I put that 32-bit address into a register on my
board, it can read the chain from memory and execute it.

What I’m doing now is trying to calculate the PHYSICAL_ADDRESS of the
chain. Maybe this works; I’m not sure. What I do know is that I’m
stepping all over memory and bugchecking W2k. What fun!

I’d like to find a sample WDM driver that does DMA. (Also one that does
scatter/gather would be nice.) The OSR sample doesn’t (seem to me) to
help me. And Mr Oney’s book leaves out that final step.

Any help would be appreciated. Thanks.

john.


You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%</mailto:xxxxx></news:xxxxx></mailto:xxxxx>

Well, the answer here is to use AllocateCommonBuffer (or
HalAllocateCommonBuffer for NT4) - this allocates main memory in a way that
it can be shared with the device easily AND it returns the physical address
to hand to the device (it’s in the LogicalAddress output parameter).
Typically, one would do this allocation once (in startdevice processing for
example) and then hand the physical address to the hw.

/simgr

-----Original Message-----
From: Bi Chen [mailto:xxxxx@AppStream.com]
Sent: Thursday, September 26, 2002 4:48 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

Gary.

I don’t think you understand John’s problem. I think John knows how to use
DMA Adpater object. I have written many PCI bus master device drivers to
know his problem. If you read his post carefully, what he needs to know is
not how to get scatter gather list, but where to put the descriptor that
hardware understand and need to read to perform the hardware DMA operation.

Bi

-----Original Message-----
From: Gary G. Little [mailto:xxxxx@inland.net]
Sent: Thursday, September 26, 2002 1:40 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

Sorry Bi, but you missed the boat.

John, go back and re-read Peter Wielands comment very carefully.

Bus Mastering Scatter-Gather DMA has been greatly simplifed in 2000 and
above. After filling in the DMA descriptor and creating a DMA adapter object
you then use the functions within that DMA adapter object to process an MDL
describing the buffer. If the kernel hands you that buffer from user request
such as a Read/WriteFile, it has been set for system memory and all you have
to do is pass each page of the buffer through IoMapTransfer, or simply call
DmaObject->GetScatterGatherList with an MDL describing a system buffer.

Gary G. Little
909-551-2105
909-698-3191

“Bi Chen” > wrote in
message news:xxxxx@ntdev news:xxxxx

John:

If you hardware DMA engine reads directly from system memory for
scatter-gather-list descriptor, what you need is to use
MmAllocateContiguousMemorySpecifyCache for this memory instead of allocate
it from a nonpaged pool. Then you can use MmGetPhysicalAddress to get what
you want. The reason is that when you allocate the memory from nonpaged
pool, it many not be physically contiguous. But you hardware does not know
that, it keeps reading scatter-gather-list descriptor which may be garbage
if it is cross the page boundary of what you allocated from nonpaged pool.
When it DMA, it writes to arbitary memory. Most bus master DMA use
scatter-gather-list descriptor will see a null descriptor before it stops.

This will help you.

Bi

-----Original Message-----
From: John Reilly [mailto:xxxxx@nexet.net
mailto:xxxxx]
Sent: Thursday, September 26, 2002 11:26 AM
To: NT Developers Interest List
Subject: [ntdev] Looking for a WDM DMA Sample

I have a busmaster radar video device. Each time the device gives me a
“I’ve got data” interrupt, I need to build a chain of DMA descriptors
telling it from whence and to where I want the data. I allocated the
descriptors from non-paged pool. I need to get the DMA chain’s address in
such a form that, when I put that 32-bit address into a register on my
board, it can read the chain from memory and execute it.

What I’m doing now is trying to calculate the PHYSICAL_ADDRESS of the
chain. Maybe this works; I’m not sure. What I do know is that I’m
stepping all over memory and bugchecking W2k. What fun!

I’d like to find a sample WDM driver that does DMA. (Also one that does
scatter/gather would be nice.) The OSR sample doesn’t (seem to me) to
help me. And Mr Oney’s book leaves out that final step.

Any help would be appreciated. Thanks.

john.


You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to %%email.unsub%%</mailto:xxxxx></news:xxxxx>

Graham:

You are right. AllocateCommonBuffer will do the job.
MmAllocateContiguousMemorySpecifyCache will do the same job to any PCI
device because of PCI devices including PCI to host bridge use positive
decoding. It does have some platform dependence on the bus.
AllocateCommBuffer from DMA adapter object is based on the bus driver to
remove that dependence.

Bi

-----Original Message-----
From: Graham, Simon [mailto:xxxxx@stratus.com]
Sent: Thursday, September 26, 2002 1:57 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

Well, the answer here is to use AllocateCommonBuffer (or
HalAllocateCommonBuffer for NT4) - this allocates main memory in a way that
it can be shared with the device easily AND it returns the physical address
to hand to the device (it’s in the LogicalAddress output parameter).
Typically, one would do this allocation once (in startdevice processing for
example) and then hand the physical address to the hw.

/simgr

-----Original Message-----
From: Bi Chen [mailto:xxxxx@AppStream.com]
Sent: Thursday, September 26, 2002 4:48 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

Gary.

I don’t think you understand John’s problem. I think John knows how to use
DMA Adpater object. I have written many PCI bus master device drivers to
know his problem. If you read his post carefully, what he needs to know is
not how to get scatter gather list, but where to put the descriptor that
hardware understand and need to read to perform the hardware DMA operation.

Bi

-----Original Message-----
From: Gary G. Little [mailto:xxxxx@inland.net]
Sent: Thursday, September 26, 2002 1:40 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

Sorry Bi, but you missed the boat.

John, go back and re-read Peter Wielands comment very carefully.

Bus Mastering Scatter-Gather DMA has been greatly simplifed in 2000 and
above. After filling in the DMA descriptor and creating a DMA adapter object
you then use the functions within that DMA adapter object to process an MDL
describing the buffer. If the kernel hands you that buffer from user request
such as a Read/WriteFile, it has been set for system memory and all you have
to do is pass each page of the buffer through IoMapTransfer, or simply call
DmaObject->GetScatterGatherList with an MDL describing a system buffer.

Gary G. Little
909-551-2105
909-698-3191

“Bi Chen” < xxxxx@AppStream.com mailto:xxxxx > wrote in
message news:xxxxx@ntdev news:xxxxx

John:

If you hardware DMA engine reads directly from system memory for
scatter-gather-list descriptor, what you need is to use
MmAllocateContiguousMemorySpecifyCache for this memory instead of allocate
it from a nonpaged pool. Then you can use MmGetPhysicalAddress to get what
you want. The reason is that when you allocate the memory from nonpaged
pool, it many not be physically contiguous. But you hardware does not know
that, it keeps reading scatter-gather-list descriptor which may be garbage
if it is cross the page boundary of what you allocated from nonpaged pool.
When it DMA, it writes to arbitary memory. Most bus master DMA use
scatter-gather-list descriptor will see a null descriptor before it stops.

This will help you.

Bi

-----Original Message-----
From: John Reilly [mailto:xxxxx@nexet.net
mailto:xxxxx]
Sent: Thursday, September 26, 2002 11:26 AM
To: NT Developers Interest List
Subject: [ntdev] Looking for a WDM DMA Sample

I have a busmaster radar video device. Each time the device gives me a
“I’ve got data” interrupt, I need to build a chain of DMA descriptors
telling it from whence and to where I want the data. I allocated the
descriptors from non-paged pool. I need to get the DMA chain’s address in
such a form that, when I put that 32-bit address into a register on my
board, it can read the chain from memory and execute it.

What I’m doing now is trying to calculate the PHYSICAL_ADDRESS of the
chain. Maybe this works; I’m not sure. What I do know is that I’m
stepping all over memory and bugchecking W2k. What fun!

I’d like to find a sample WDM driver that does DMA. (Also one that does
scatter/gather would be nice.) The OSR sample doesn’t (seem to me) to
help me. And Mr Oney’s book leaves out that final step.

Any help would be appreciated. Thanks.

john.


You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%</mailto:xxxxx></news:xxxxx></mailto:xxxxx>

MmAllocateContiguousMemorySpecifyCache will NOT do the same job.

MM is not aware of the limitations of the device or the device’s bus.
For example, on a system where one of the PCI busses is busted and
cannot be used to access data physically located above 4GB (and such
machines exist) only the HAL knows that the buffer for a device on that
bus must be located below 4GB.

if you want to do DMA then please use the DMA API.

-p

-----Original Message-----
From: Bi Chen [mailto:xxxxx@AppStream.com]
Sent: Thursday, September 26, 2002 2:14 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

Graham:

You are right. AllocateCommonBuffer will do the job.
MmAllocateContiguousMemorySpecifyCache will do the same job to any PCI
device because of PCI devices including PCI to host bridge use positive
decoding. It does have some platform dependence on the bus.
AllocateCommBuffer from DMA adapter object is based on the bus driver to
remove that dependence.

Bi

-----Original Message-----
From: Graham, Simon [mailto:xxxxx@stratus.com]
Sent: Thursday, September 26, 2002 1:57 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

Well, the answer here is to use AllocateCommonBuffer (or
HalAllocateCommonBuffer for NT4) - this allocates main memory in a way
that it can be shared with the device easily AND it returns the physical
address to hand to the device (it’s in the LogicalAddress output
parameter). Typically, one would do this allocation once (in startdevice
processing for example) and then hand the physical address to the hw.

/simgr
-----Original Message-----
From: Bi Chen [mailto:xxxxx@AppStream.com]
Sent: Thursday, September 26, 2002 4:48 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

Gary.

I don’t think you understand John’s problem. I think John knows how to
use DMA Adpater object. I have written many PCI bus master device
drivers to know his problem. If you read his post carefully, what he
needs to know is not how to get scatter gather list, but where to put
the descriptor that hardware understand and need to read to perform the
hardware DMA operation.

Bi
-----Original Message-----
From: Gary G. Little [mailto:xxxxx@inland.net]
Sent: Thursday, September 26, 2002 1:40 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

Sorry Bi, but you missed the boat.

John, go back and re-read Peter Wielands comment very carefully.

Bus Mastering Scatter-Gather DMA has been greatly simplifed in 2000 and
above. After filling in the DMA descriptor and creating a DMA adapter
object you then use the functions within that DMA adapter object to
process an MDL describing the buffer. If the kernel hands you that
buffer from user request such as a Read/WriteFile, it has been set for
system memory and all you have to do is pass each page of the buffer
through IoMapTransfer, or simply call DmaObject->GetScatterGatherList
with an MDL describing a system buffer.

Gary G. Little
909-551-2105
909-698-3191
“Bi Chen” wrote in message news:xxxxx@ntdev…
John:
If you hardware DMA engine reads directly from system memory for
scatter-gather-list descriptor, what you need is to use
MmAllocateContiguousMemorySpecifyCache for this memory instead of
allocate it from a nonpaged pool. Then you can use MmGetPhysicalAddress
to get what you want. The reason is that when you allocate the memory
from nonpaged pool, it many not be physically contiguous. But you
hardware does not know that, it keeps reading scatter-gather-list
descriptor which may be garbage if it is cross the page boundary of what
you allocated from nonpaged pool. When it DMA, it writes to arbitary
memory. Most bus master DMA use scatter-gather-list descriptor will see
a null descriptor before it stops.
This will help you.
Bi

-----Original Message-----
From: John Reilly [mailto:xxxxx@nexet.net]
Sent: Thursday, September 26, 2002 11:26 AM
To: NT Developers Interest List
Subject: [ntdev] Looking for a WDM DMA Sample

I have a busmaster radar video device. Each time the device gives me a
“I’ve got data” interrupt, I need to build a chain of DMA descriptors
telling it from whence and to where I want the data. I allocated the
descriptors from non-paged pool. I need to get the DMA chain’s address
in
such a form that, when I put that 32-bit address into a register on my
board, it can read the chain from memory and execute it.
What I’m doing now is trying to calculate the PHYSICAL_ADDRESS of the
chain. Maybe this works; I’m not sure. What I do know is that I’m
stepping all over memory and bugchecking W2k. What fun!
I’d like to find a sample WDM driver that does DMA. (Also one that does

scatter/gather would be nice.) The OSR sample doesn’t (seem to me) to
help me. And Mr Oney’s book leaves out that final step.
Any help would be appreciated. Thanks.
john.

You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@microsoft.com
To unsubscribe send a blank email to %%email.unsub%%

“John Reilly” wrote in message news:xxxxx@ntdev…
>
> I have a busmaster radar video device. Each time the device gives me a
> “I’ve got data” interrupt, I need to build a chain of DMA descriptors
> telling it from whence and to where I want the data. I allocated the
> descriptors from non-paged pool. I need to get the DMA chain’s address in
> such a form that, when I put that 32-bit address into a register on my
> board, it can read the chain from memory and execute it.
>
> What I’m doing now is trying to calculate the PHYSICAL_ADDRESS of the
> chain. Maybe this works; I’m not sure. What I do know is that I’m
> stepping all over memory and bugchecking W2k. What fun!
>

Just to make sure I follow what you’re asking: You have an DMA device (like
that supported by the PLX 905x), and you want to support scatter/gather.
The s/g descriptors are built in “shared memory” (that is, host memory that
is shared between the device (doing continuous DMA) and your driver). Is
that right?

Assuming this is the case, you need to allocate the memory where you’re
building your descriptors by calling AllocateCommonBuffer. This’ll return
you a hunk of memory that is both virtually and logically (from the DMA
viewpoint) contiguous. It’ll also return you the base “Physical Address”
(in quotes because this is really a device bus logical address… but, yes,
it’s an address that you can give to your DMA controller), and a kernel
virtual address (that’ll enable your driver to talk to it).

You can then build the actual SG list with BuildScatterGatherList (qv,
providing this function a pointer to where you want the system to put the SG
list in your shared memory area). Alternatively, you call
GetScatterGatherList and copy the SG list that’s pass to you to your shared
memory area.

Does that help any?

Peter
OSR

Hi Peter:

I agree with you guys on that. In the past I used MmXXX and it worked. But
it may not be compatible with new system. I have a couple of questions.

I wonder if one of the PCI bus is busted, all the devices including
possible the bridge node on that bus are not usable and probably removed by
PnP Manager if it detects such catastrophic event, how does it affect other
PCI devices on the PCI buses that are still accessible to the system. Will
Win2k and XP remaping the BAR for still live PCI bridges, resulting a
chained PnP events for device to get its new translated resources? I am not
sure it will do that.

Also, I don’t understand the 64-bit issue. We are not talking about 64-bit
OS. I know even 32-bit PCI bus device can be addressed in 64-bit through
dual address cycle. But the system memory cannot be addressed in 64-bit. I
think John wants to use system memory to store his scatter-gather-list
descriptor, not the hardware MMIO memory. If he writes the 32-bit system
physical address to the device register, the device will generate the
address which will be passed by PCI-to-host bridge to system memory. If he
uses hardware MMIO memory, he will use (HalTranslateBusAddress, NT 4.0)
translated address and MmMapIoSpace on the memory so the driver can write
descriptors directly to the hardware memory.

I hope you can clarify it further.

Thanks.

Bi

-----Original Message-----
From: Peter Wieland [mailto:xxxxx@windows.microsoft.com]
Sent: Thursday, September 26, 2002 2:43 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

MmAllocateContiguousMemorySpecifyCache will NOT do the same job.

MM is not aware of the limitations of the device or the device’s bus.
For example, on a system where one of the PCI busses is busted and
cannot be used to access data physically located above 4GB (and such
machines exist) only the HAL knows that the buffer for a device on that
bus must be located below 4GB.

if you want to do DMA then please use the DMA API.

-p

-----Original Message-----
From: Bi Chen [mailto:xxxxx@AppStream.com]
Sent: Thursday, September 26, 2002 2:14 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

Graham:

You are right. AllocateCommonBuffer will do the job.
MmAllocateContiguousMemorySpecifyCache will do the same job to any PCI
device because of PCI devices including PCI to host bridge use positive
decoding. It does have some platform dependence on the bus.
AllocateCommBuffer from DMA adapter object is based on the bus driver to
remove that dependence.

Bi

-----Original Message-----
From: Graham, Simon [mailto:xxxxx@stratus.com]
Sent: Thursday, September 26, 2002 1:57 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

Well, the answer here is to use AllocateCommonBuffer (or
HalAllocateCommonBuffer for NT4) - this allocates main memory in a way
that it can be shared with the device easily AND it returns the physical
address to hand to the device (it’s in the LogicalAddress output
parameter). Typically, one would do this allocation once (in startdevice
processing for example) and then hand the physical address to the hw.

/simgr
-----Original Message-----
From: Bi Chen [mailto:xxxxx@AppStream.com]
Sent: Thursday, September 26, 2002 4:48 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

Gary.

I don’t think you understand John’s problem. I think John knows how to
use DMA Adpater object. I have written many PCI bus master device
drivers to know his problem. If you read his post carefully, what he
needs to know is not how to get scatter gather list, but where to put
the descriptor that hardware understand and need to read to perform the
hardware DMA operation.

Bi
-----Original Message-----
From: Gary G. Little [mailto:xxxxx@inland.net]
Sent: Thursday, September 26, 2002 1:40 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

Sorry Bi, but you missed the boat.

John, go back and re-read Peter Wielands comment very carefully.

Bus Mastering Scatter-Gather DMA has been greatly simplifed in 2000 and
above. After filling in the DMA descriptor and creating a DMA adapter
object you then use the functions within that DMA adapter object to
process an MDL describing the buffer. If the kernel hands you that
buffer from user request such as a Read/WriteFile, it has been set for
system memory and all you have to do is pass each page of the buffer
through IoMapTransfer, or simply call DmaObject->GetScatterGatherList
with an MDL describing a system buffer.

Gary G. Little
909-551-2105
909-698-3191
“Bi Chen” wrote in message news:xxxxx@ntdev…
John:
If you hardware DMA engine reads directly from system memory for
scatter-gather-list descriptor, what you need is to use
MmAllocateContiguousMemorySpecifyCache for this memory instead of
allocate it from a nonpaged pool. Then you can use MmGetPhysicalAddress
to get what you want. The reason is that when you allocate the memory
from nonpaged pool, it many not be physically contiguous. But you
hardware does not know that, it keeps reading scatter-gather-list
descriptor which may be garbage if it is cross the page boundary of what
you allocated from nonpaged pool. When it DMA, it writes to arbitary
memory. Most bus master DMA use scatter-gather-list descriptor will see
a null descriptor before it stops.
This will help you.
Bi

-----Original Message-----
From: John Reilly [mailto:xxxxx@nexet.net]
Sent: Thursday, September 26, 2002 11:26 AM
To: NT Developers Interest List
Subject: [ntdev] Looking for a WDM DMA Sample

I have a busmaster radar video device. Each time the device gives me a
“I’ve got data” interrupt, I need to build a chain of DMA descriptors
telling it from whence and to where I want the data. I allocated the
descriptors from non-paged pool. I need to get the DMA chain’s address
in
such a form that, when I put that 32-bit address into a register on my
board, it can read the chain from memory and execute it.
What I’m doing now is trying to calculate the PHYSICAL_ADDRESS of the
chain. Maybe this works; I’m not sure. What I do know is that I’m
stepping all over memory and bugchecking W2k. What fun!
I’d like to find a sample WDM driver that does DMA. (Also one that does

scatter/gather would be nice.) The OSR sample doesn’t (seem to me) to
help me. And Mr Oney’s book leaves out that final step.
Any help would be appreciated. Thanks.
john.

You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@microsoft.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%

“Bi Chen” wrote in message news:xxxxx@ntdev…
> Hi Peter:
>
>
> Also, I don’t understand the 64-bit issue. We are not talking about 64-bit
> OS. I know even 32-bit PCI bus device can be addressed in 64-bit through
> dual address cycle. But the system memory cannot be addressed in 64-bit. I
> think John wants to use system memory to store his scatter-gather-list
> descriptor, not the hardware MMIO memory. If he writes the 32-bit system
> physical address to the device register, the device will generate the
> address which will be passed by PCI-to-host bridge to system memory. If he
> uses hardware MMIO memory, he will use (HalTranslateBusAddress, NT 4.0)
> translated address and MmMapIoSpace on the memory so the driver can write
> descriptors directly to the hardware memory.
>

Bi… Suppose there’s more than 4GB of physical memory installed on the
system? Physical addresses can be 36 bits long on Pentium Pro and later,
through the use of PAE.

In short, everybody should listen to Peter Wieland: Do NOT attempt to
substitute a physical address for a Device Bug Logical Address (provided to
you via the bus driver/HAL). In other words, you MUST NOT use
MmGetPhysicalAddress(…) to get the address of host memory that you want to
use for DMA. I don’t know how many times I’ve said this in The NT Insider
or in class. In this operating system Main Memory Physical Address IS NOT
necessarily EQUAL TO the Device Bus Logical Address which is necessary
address for DMA. This is NOT just some esoteric architectural issue about
correctness.

Oh, I’m ranting again…

Peter
OSR

Thanks to all you guys! It is working.

To Peter W: I had forgotten about AllocateCommonBuffer() function. I was
allocating memory from non-paged pool. To quote Homer Simpson, “DOH!”

To Peter V: I took your classes about 18 months ago, both the WDM class
and the Advanced. After the second or third day, it is a miracle that
ANYTHING you said stuck; my brain was full. (I did manage to catch it
when you said that the driver routine no longer owns the IRP after you
pass it down the stack.)

So, let me follow up with a question about scatter/gather. I’d really
like to use it. But the device I’m using (PLX 9080-based), can’t transfer
more than 1024 bytes at a time. I need to grab a full radar sector of
2000 bytes at each interrupt. So I’m looping over MapTransfer(), making
sure that no map request is greater than 1024, until the 2000 bytes is
transferred.

Given my 1024 limitation, which I hope I’ve adequately explained, can I
use scatter/gather?

Thanks again. I really appreciate your help. (Sorry, Peter, I’ll listen
better in class next time; I really need to convince my company to spring
for the debugging course.)

john.

GetScatterGather gives you the scatter gather list for the request
(there’s some new functions in XP which let you provide the buffer into
which the list is built … it makes working in low memory situations
possible). How you translate that into your DMA descriptor is up to
you.

so you can take that list and transfer 1024 bytes at a time if you want.
Until you call PutScatterGather the scatter gather list (and any
associated bounce buffers, etc…) remain for you to use.

It seems like it should work okay.

-p

-----Original Message-----
From: John Reilly [mailto:xxxxx@nexet.net]
Sent: Thursday, September 26, 2002 5:30 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Looking for a WDM DMA Sample

Thanks to all you guys! It is working.

To Peter W: I had forgotten about AllocateCommonBuffer() function. I
was allocating memory from non-paged pool. To quote Homer Simpson,
“DOH!”

To Peter V: I took your classes about 18 months ago, both the WDM class
and the Advanced. After the second or third day, it is a miracle that
ANYTHING you said stuck; my brain was full. (I did manage to catch it
when you said that the driver routine no longer owns the IRP after you
pass it down the stack.)

So, let me follow up with a question about scatter/gather. I’d really
like to use it. But the device I’m using (PLX 9080-based), can’t
transfer more than 1024 bytes at a time. I need to grab a full radar
sector of 2000 bytes at each interrupt. So I’m looping over
MapTransfer(), making sure that no map request is greater than 1024,
until the 2000 bytes is transferred.

Given my 1024 limitation, which I hope I’ve adequately explained, can I
use scatter/gather?

Thanks again. I really appreciate your help. (Sorry, Peter, I’ll
listen better in class next time; I really need to convince my company
to spring for the debugging course.)

john.


You are currently subscribed to ntdev as: xxxxx@microsoft.com To
unsubscribe send a blank email to %%email.unsub%%

Does this mean that you can write a WDM driver for an ISA board?

I have been told that WDM is only for PNP PCI devices. (not that I
believe them but I have no other sources that i actually physically
socialize with.)

Asher

Peter Viscarola of OSR gives a very good class in Windows 2000 Device
Drivers. They offer a lab where you have a computer with a board that
presents itself on both the ISA and PCI bus. The PCI side uses DMA. I
remember, but haven’t needed to do it myself, that there are specific
calls using map registers to handle DMA. It just works. It helps if the
device follows the PCI specs.

“Asher Hoodin” wrote in message news:xxxxx@ntdev…
>
> Does this mean that you can write a WDM driver for an ISA board?
>

Yes, indeed you can (thought I s’pose it depends on what you mean by “WDM
driver” – one of my favorite terms). This is even described in the DDK…
check out IoReportResourceForDetection(…) IIRC.

Peter
OSR

Well,

“Writing Windows WDM Device Drivers” by Chris Cant
title would be wrong?

Asher

“Asher Hoodin” wrote in message
> news:xxxxx@ntdev…
> >
> > Does this mean that you can write a WDM driver for
> an ISA board?
> >
>
> Yes, indeed you can (thought I s’pose it depends on
> what you mean by “WDM
> driver” – one of my favorite terms). This is even
> described in the DDK…
> check out IoReportResourceForDetection(…) IIRC.
>
> Peter
> OSR

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

> > described in the DDK…

> check out IoReportResourceForDetection(…) IIRC.
ty very much,
Asher


Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

> substitute a physical address for a Device Bug Logical Address
(provided to

Sorry, “Device Bus Logical Address”. A great typo :slight_smile:

Max