read/write data>1MB size to pci device memory

Hi,

I have to read/write data of size > 1 MB to my PCIExpress endpoint
device from a wdm function driver. I am thinking of using WRITE/
READ_REGISTER_BUFFER_UCHAR for the same. I could not find any mention
about maximum size of the buffer, which these APIs can handle.

I have following questions.

1.a. Can I use READ/ WRITE_REGISTER_BUFFER_UCHAR APIs for data transfers
of size > 1MB?

1.b. These APIs do not return any status. How will I know whether the
transfer was successful?

1.c. If I use these APIs then I need not worry about the synchronization
mechanism because HAL takes care for the same. Is this correct?

  1. There can be another alternative of taking the help of PCI bus
    driver. Does pci bus driver handle IRP_MJ_READ/ WRITE sent by function
    drivers?

If yes, then I can create an IRP with IRP_MJ_READ/ WRITE, pass on to
lower driver and wait for completion.

  1. Which approach is better?

Regards,

Aparna

Aparna Argade wrote:

Hi,

I have to read/write data of size > 1 MB to my PCIExpress endpoint
device from a wdm function driver. I am thinking of using WRITE/
READ_REGISTER_BUFFER_UCHAR for the same. I could not find any mention
about maximum size of the buffer, which these APIs can handle.

Note that you almost CERTAINLY do not want to use
READ_REGISTER_BUFFER_UCHAR. You want READ_REGISTER_BUFFER_ULONG.
Otherwise, you’re just wasting cycles.

These aren’t really APIs. They are essentially macros that generate the
“rep movs” instruction. Now, that necessarily implies that it writes to
consecutive addressses. Thus, you need to make sure you have a
megabyte’s worth of address space mapped on your device. For example,
if you copy a megabyte to address 0 in your device’s address space, it
will write dwords to 0, 4, 8, C, 10, etc., on through FFFF0, FFFF4,
FFFF8, and FFFFC.

All of these functions are basically synonyms for RtlMoveMemory or
memmove. That’s what I’d use for this function.

I have following questions.

1.a. Can I use READ/ WRITE_REGISTER_BUFFER_UCHAR APIs for data
transfers of size > 1MB?

Yes. You can write as much data as you have address space.

1.b. These APIs do not return any status. How will I know whether the
transfer was successful?

The only way it can fail is if one of the addresses touches an unmapped
page, in which case you’ll get a blue screen. Other than that, they
cannot fail.

1.c. If I use these APIs then I need not worry about the
synchronization mechanism because HAL takes care for the same. Is this
correct?

Synchronization of what? It’s just moving a block of memory from here
to there. There is nothing to synchronize.

  1. There can be another alternative of taking the help of PCI bus
    driver. Does pci bus driver handle IRP_MJ_READ/ WRITE sent by function
    drivers?

If yes, then I can create an IRP with IRP_MJ_READ/ WRITE, pass on to
lower driver and wait for completion.

I doubt that the PCI bus driver has any read/write functionality, but
even if it did, you wouldn’t want to use it.

  1. Which approach is better?

Just write the bytes yourself. RtlMoveMemory,
READ_REGISTER_BUFFER_ULONG, or *pBuffer = 0.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

On Intel architecture platforms write operations are not guaranteed to
actually be available on external devices when the write completes. (The
infamous write post buffer problem.) Using the HAL APIs issues the
appropriate write posts buffer flush-causing instruction to arrive at a
platform independent guarantee that the device actually has the data when
the api returns.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Thursday, February 23, 2006 12:52 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] read/write data>1MB size to pci device memory

Aparna Argade wrote:

> Hi,
>
> I have to read/write data of size > 1 MB to my PCIExpress endpoint
> device from a wdm function driver. I am thinking of using WRITE/
> READ_REGISTER_BUFFER_UCHAR for the same. I could not find
any mention
> about maximum size of the buffer, which these APIs can handle.
>

Note that you almost CERTAINLY do not want to use
READ_REGISTER_BUFFER_UCHAR. You want READ_REGISTER_BUFFER_ULONG.
Otherwise, you’re just wasting cycles.

These aren’t really APIs. They are essentially macros that
generate the “rep movs” instruction. Now, that necessarily
implies that it writes to consecutive addressses. Thus, you
need to make sure you have a megabyte’s worth of address
space mapped on your device. For example, if you copy a
megabyte to address 0 in your device’s address space, it will
write dwords to 0, 4, 8, C, 10, etc., on through FFFF0,
FFFF4, FFFF8, and FFFFC.

All of these functions are basically synonyms for
RtlMoveMemory or memmove. That’s what I’d use for this function.

> I have following questions.
>
> 1.a. Can I use READ/ WRITE_REGISTER_BUFFER_UCHAR APIs for data
> transfers of size > 1MB?
>

Yes. You can write as much data as you have address space.

> 1.b. These APIs do not return any status. How will I know
whether the
> transfer was successful?
>

The only way it can fail is if one of the addresses touches
an unmapped page, in which case you’ll get a blue screen.
Other than that, they cannot fail.

> 1.c. If I use these APIs then I need not worry about the
> synchronization mechanism because HAL takes care for the
same. Is this
> correct?
>

Synchronization of what? It’s just moving a block of memory
from here to there. There is nothing to synchronize.

> 2. There can be another alternative of taking the help of PCI bus
> driver. Does pci bus driver handle IRP_MJ_READ/ WRITE sent
by function
> drivers?
>
> If yes, then I can create an IRP with IRP_MJ_READ/ WRITE,
pass on to
> lower driver and wait for completion.
>

I doubt that the PCI bus driver has any read/write
functionality, but even if it did, you wouldn’t want to use it.

> 3. Which approach is better?
>

Just write the bytes yourself. RtlMoveMemory,
READ_REGISTER_BUFFER_ULONG, or *pBuffer = 0.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


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