READ_REGISTER_XXXX

I have a fundamental doubt about implementing mechanism to access MMIO Space Pointed by Device BAR’s

Is it Ok of I map my Device MMIO Space to equivalent Stucture , What are the consequences if I dont use READ_REGISTER_XXX

Example 1 : Using READ_REGISTER_XXXX

mappedaddress = MMmapIoSpace(BARMMIOAddress,range);
READ_REGISTER_XXX(mappedaddress,offset,outvalue);

EXample 2: Using structure to read MMIO

typedef struct _DEVICE
{
ULONG some register1;
ULONG some register2;

} DEVICE,*PDEVICE;

PDEVICE pdevice = MmapIoSpace(BARMMIOAddress,range); //assing and map

pDevice.register1 = value; //access

What are the pro’s and con’s

Thanks,
Manohara

}

There’s an ancient article from The NT INsider that provides some background on this that you might find useful: http://www.osronline.com/article.cfm?id=80

Also, you might wanna try searching the archives for additional information.

Peter
OSR

Read access from device memory on current platforms will work correctly.
Write access to device memory on current platforms will appear to work
correctly 99% or so of the time. See PGV’s reference to some ancient
NtInsider article about the x86 write post buffer and why it matters for
device memory write access.

The simple answer is use the HAL.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Thursday, August 03, 2006 6:41 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] READ_REGISTER_XXXX

I have a fundamental doubt about implementing mechanism to access MMIO
Space Pointed by Device BAR’s

Is it Ok of I map my Device MMIO Space to equivalent Stucture , What are
the consequences if I dont use READ_REGISTER_XXX

Example 1 : Using READ_REGISTER_XXXX

mappedaddress = MMmapIoSpace(BARMMIOAddress,range);
READ_REGISTER_XXX(mappedaddress,offset,outvalue);

EXample 2: Using structure to read MMIO

typedef struct _DEVICE
{
ULONG some register1;
ULONG some register2;

} DEVICE,*PDEVICE;

PDEVICE pdevice = MmapIoSpace(BARMMIOAddress,range); //assing and map

pDevice.register1 = value; //access

What are the pro’s and con’s

Thanks,
Manohara

}


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

> READ_REGISTER_XXX(mappedaddress,offset,outvalue);

READ_REGISTER_XXX is correct, it applies all necessary memory barriers.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

xxxxx@hotmail.com wrote:

I have a fundamental doubt about implementing mechanism to access MMIO Space Pointed by Device BAR’s

Is it Ok of I map my Device MMIO Space to equivalent Stucture , What are the consequences if I dont use READ_REGISTER_XXX

Example 1 : Using READ_REGISTER_XXXX

mappedaddress = MMmapIoSpace(BARMMIOAddress,range);
READ_REGISTER_XXX(mappedaddress,offset,outvalue);

Note, however, that the WRITE/READ_REGISTER routines only take one
address, so the code actually looks like:
WRITE_REGISTER_XXX(mappedaddress+offset, outvalue);
invalue = READ_REGISTER_XXXX(mappedaddress+offset);

EXample 2: Using structure to read MMIO

typedef struct _DEVICE
{
ULONG some register1;
ULONG some register2;

} DEVICE,*PDEVICE;

PDEVICE pdevice = MmapIoSpace(BARMMIOAddress,range); //assing and map

pDevice.register1 = value; //access

It’s also possible to mix the two. You can use Example 2 and replace
the last line by:
WRITE_REGISTER_ULONG( &pDevice.register1, value );

That’s usually the approach I take.


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

You can do it both ways.

The mapping of IO space to a structure would allow easier access from
your driver, as opposed to always doing the READ/WRITE_REGISTER_XXX.

I used the mapping to a structure in one of my NDIS drivers and have
never had a problem and access are generally pretty fast.

One thing to note, if you are planning on using the structure method on
multiple platforms, big and little endian, you will need to make sure
you define your structure accordingly.

Michael Smith
Senior Software Engineer, SMTS

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-258186-
xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Thursday, August 03, 2006 6:41 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] READ_REGISTER_XXXX

I have a fundamental doubt about implementing mechanism to access MMIO
Space Pointed by Device BAR’s

Is it Ok of I map my Device MMIO Space to equivalent Stucture , What
are
the consequences if I dont use READ_REGISTER_XXX

Example 1 : Using READ_REGISTER_XXXX

mappedaddress = MMmapIoSpace(BARMMIOAddress,range);
READ_REGISTER_XXX(mappedaddress,offset,outvalue);

EXample 2: Using structure to read MMIO

typedef struct _DEVICE
{
ULONG some register1;
ULONG some register2;

} DEVICE,*PDEVICE;

PDEVICE pdevice = MmapIoSpace(BARMMIOAddress,range); //assing and map

pDevice.register1 = value; //access

What are the pro’s and con’s

Thanks,
Manohara

}


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

>

You can do it both ways.

The mapping of IO space to a structure would allow easier access from your driver,
as opposed to always doing the READ/WRITE_REGISTER_XXX.

The point is that you CAN do it both ways, but just using the structure deref won’t necessarily always work correctly. And the problems/delays can be very subtle.

Please read the aforereferenced article.

Peter
OSR

Also note that the op asked about read access and then provided an example
that does write access:

pDevice.register1 = value; //access

So while you *might* get away with a correct program that only reads device
memory this way on current platforms, the meaning of ‘read’ appears to be
problematic, and it is a fact that on x86 architecture platforms write
access without flushing the write post buffer may eventually cause you
grief. Read the stupid cited article.

=====================
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 xxxxx@osr.com
Sent: Friday, August 04, 2006 11:46 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] READ_REGISTER_XXXX

>
>You can do it both ways.
>
>The mapping of IO space to a structure would allow easier
access from
>your driver, as opposed to always doing the READ/WRITE_REGISTER_XXX.
>

The point is that you CAN do it both ways, but just using the
structure deref won’t necessarily always work correctly. And
the problems/delays can be very subtle.

Please read the aforereferenced article.

Peter
OSR


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online
at http://www.osronline.com/page.cfm?name=ListServer