Reading/Writing shared memory atomically over PCIe

Guys,

I’m having issues with being able to read registers, located in shared memory, for our PCIe card.

I’m running into issues where while I’m doing a read of a 32bit value, the PPC is doing a write to the same location, and my pointers to going into the weeds.

I *thought* that by using READ_REGISTER_ULONG() and WRITE_REGISTER_ULONG() that they were supposed to read values over the PCI bus atomically. But, they’re not.

Also, when I map the memory, I have ensured that it’s non-cached:

pdx->bar0VirtualAddress =
(PULONG)MmMapIoSpace(desc->u.Memory.Start, desc->u.Memory.Length, MmNonCached);
pdx->bar0MemorySize = desc->u.Memory.Length;

Anyone have any slick ways to read 32bit values atomically over PCIe?

Here’s the snippet of code that’s reading the shared memory I mapped above (usq->next_wr points to this shared memory, btw):

head = SwapEndianness32(READ_REGISTER_ULONG((PULONG)&(usq->next_wr)));

Other than this, I’m making great progress on my KMDF driver. :slight_smile: So, I need to get past this to move on…

Thanks gusy!

Jason

xxxxx@gmail.com wrote:

Here’s the snippet of code that’s reading the shared memory I mapped above (usq->next_wr points to this shared memory, btw):

head = SwapEndianness32(READ_REGISTER_ULONG((PULONG)&(usq->next_wr)));

Other than this, I’m making great progress on my KMDF driver. :slight_smile: So, I need to get past this to move on…

Is SwapEndianness32 a macro or a function? If it’s a macro, it’s quite
possible you are actually reading the value several times.


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

Actually, it’s a macro…

#define SwapEndianness32(x) \
( (((x) & 0xff000000) >> 24) | \
(((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | \
(((x) & 0x000000ff) << 24) )

Ahh…now that you mention it, I can see how that would be the case. Very good point!

Thanks Tim, a WHOLE BUNCH! I’ll give it a try, and let you know!

You might replace that macro with RtlUlongByteSwap that will do it in one
instruction.


Don Burn (MVP, Windows DDK)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

wrote in message news:xxxxx@ntdev…
> Actually, it’s a macro…
>
> #define SwapEndianness32(x) <br>> ( (((x) & 0xff000000) >> 24) | <br>> (((x) & 0x00ff0000) >> 8) | <br>> (((x) & 0x0000ff00) << 8) | <br>> (((x) & 0x000000ff) << 24) )
>
> Ahh…now that you mention it, I can see how that would be the case.
> Very good point!
>
> Thanks Tim, a WHOLE BUNCH! I’ll give it a try, and let you know!
>
>
> Information from ESET NOD32 Antivirus, version of virus
> signature database 4025 (20090421)

>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>

Information from ESET NOD32 Antivirus, version of virus signature database 4025 (20090421)

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Awesome…Thanks Don! Will do! :slight_smile:

Jason

That was it! Thanks guys…You guys are always awesome!