I’ve inherited a WDM driver which maps memory resources from a PCI device using MmMapIoSpace and then casts the memory to a structure which is held by an object as a volatile pointer.
Is read/write access to to the DWORDS contained within the structure semantically equivalent to using READ_REGISTER_ULONG and WRITE_REGISTER_ULONG? That is, when I assign values to a member of the structure does the OS perform IO, writing data to the device immediately or could the data remain in a cache?
Something like :
struct tHardware
{
/* 0x00 */
DWORD reg0;
DWORD reg1;
DWORD reg2;
DWORD reg3;
};
volatile tHardware * hardware = MmMapIoSpace(pBar0P, cBar0P, MmNonCached);
hardware->reg0 = 0x1;
Many thanks,
Mike D
Short answer: no.
Longer answer: writes can be ‘posted’ which is different than cached. It is
more like deferred, with rules. The macros implement the correct operations
per platform to convince the CPU to obey the rules for that processor to
push the writes out.
volatile does not do this.
Mark Roddy
On Wed, May 5, 2010 at 6:12 AM, wrote:
> I’ve inherited a WDM driver which maps memory resources from a PCI device
> using MmMapIoSpace and then casts the memory to a structure which is held by
> an object as a volatile pointer.
>
> Is read/write access to to the DWORDS contained within the structure
> semantically equivalent to using READ_REGISTER_ULONG and
> WRITE_REGISTER_ULONG? That is, when I assign values to a member of the
> structure does the OS perform IO, writing data to the device immediately or
> could the data remain in a cache?
>
> Something like :
>
> struct tHardware
> {
> /* 0x00 */
> DWORD reg0;
> DWORD reg1;
> DWORD reg2;
> DWORD reg3;
> };
>
> volatile tHardware * hardware = MmMapIoSpace(pBar0P, cBar0P, MmNonCached);
> hardware->reg0 = 0x1;
>
> Many thanks,
>
> Mike D
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
xxxxx@incadigital.com wrote:
I’ve inherited a WDM driver which maps memory resources from a PCI device using MmMapIoSpace and then casts the memory to a structure which is held by an object as a volatile pointer.
Is read/write access to to the DWORDS contained within the structure semantically equivalent to using READ_REGISTER_ULONG and WRITE_REGISTER_ULONG? That is, when I assign values to a member of the structure does the OS perform IO, writing data to the device immediately or could the data remain in a cache?
Something like :
struct tHardware
{
/* 0x00 */
DWORD reg0;
DWORD reg1;
DWORD reg2;
DWORD reg3;
};
volatile tHardware * hardware = MmMapIoSpace(pBar0P, cBar0P, MmNonCached);
hardware->reg0 = 0x1;
On most of the hardware you are likely to encounter, this works just
fine. However, Windows runs in environments where this is not entirely
equivalent. It’s just better to get in the slightly more verbose habit of:
WRITE_REGISTER_ULONG( &hardware->reg0, 0x1 );
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.