Hello there, I have, maybe a dumb, problem with writing a PCI driver for specific board on Windows.
I have a little problem. It happend that my device does not support neither PnP not DMA.
So I faced a wall with figuring out how to obtain BAR base addresses for my device
As it is non-pnp driver, I cannot use EvtPrepareHardware to get those addresses.
I have the driver working if I initially plug in the device and watch address ranges from Device Manager in Windows Control Panel, so i can allocate virtual addresses just putting exact values into MmMapIoSpace() in my EvtDeviceAdd routine.
But the problem is, I cant afford to change those numbers for every single machine where my board should work (am I right about BIOS taking care of allocating physicall addresses for device resources?)
I tried to set up an interface with WDF_QUERY_INTERFACE_CONFIG_INIT & WdfDeviceAddQueryInterface using my own defined GUID.
But Im getting a BSOD on GetBusData when trying to read from config space
Where is the problem which Im missing? Thanks for the any help
the code processing what i’ve said is:
GetDeviceContext(device)->busInterface.Version = 1;
GetDeviceContext(device)->busInterface.Context = (PVOID) GetDeviceContext(device);
GetDeviceContext(device)->busInterface.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
GetDeviceContext(device)->busInterface.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
WDF_QUERY_INTERFACE_CONFIG_INIT(&qiConfig,
(PINTERFACE)&GetDeviceContext(device)->busInterface,
&GUID_DEVINTERFACE_IM_BOARD,
NULL);
status = WdfDeviceAddQueryInterface(device, &qiConfig);
if (!NT_SUCCESS(status))
{
KdPrint((__DRIVER_NAME “ERROR CREATING INTERFACE\n”));
}
bytesRead = GetDeviceContext(device)->busInterface.GetBusData(GetDeviceContext(device)->busInterface.Context, PCI_WHICHSPACE_CONFIG, Bar0BaseBuf, 0x10, 4);
if (bytesRead == 0) {
return STATUS_ACCESS_VIOLATION;
}
bytesRead = GetDeviceContext(device)->busInterface.GetBusData(GetDeviceContext(device)->busInterface.Context, PCI_WHICHSPACE_CONFIG, Bar1BaseBuf, 0x14, 4);
if (bytesRead == 0) {
return STATUS_ACCESS_VIOLATION;
}
bytesRead = GetDeviceContext(device)->busInterface.GetBusData(GetDeviceContext(device)->busInterface.Context, PCI_WHICHSPACE_CONFIG, RegsBaseBuf, 0x18, 4);
if (bytesRead == 0) {
return STATUS_ACCESS_VIOLATION;
}
bytesRead = GetDeviceContext(device)->busInterface.GetBusData(GetDeviceContext(device)->busInterface.Context, PCI_WHICHSPACE_CONFIG, IrqBaseBuf, 0x3C, 1);
if (bytesRead == 0) {
return STATUS_ACCESS_VIOLATION;
}
SRAMBase.QuadPart = (int)Bar0BaseBuf;
FlashBase.QuadPart = (int)Bar1BaseBuf;
RegsBase.QuadPart = (int)RegsBaseBuf;
IRQBase.QuadPart = (int)IrqBaseBuf;
GetDeviceContext(device)->BAR0 = (PUCHAR)MmMapIoSpace(SRAMBase, IM_BAR0_SIZE, MmNonCached);
GetDeviceContext(device)->SRAMLength = IM_BAR0_SIZE;
GetDeviceContext(device)->BAR1 = (PUCHAR)MmMapIoSpace(FlashBase, IM_BAR1_SIZE, MmNonCached);
GetDeviceContext(device)->FlashLength = IM_BAR0_SIZE;
GetDeviceContext(device)->BAR2 = (PUCHAR)MmMapIoSpace(RegsBase, IM_BAR2_SIZE, MmNonCached);
GetDeviceContext(device)->RegsLength = IM_BAR0_SIZE;
GetDeviceContext(device)->IRQ = (PUCHAR)MmMapIoSpace(IRQBase, IM_IRQ_SIZE, MmNonCached);
GetDeviceContext(device)->IrqLength = IM_IRQ_SIZE;
> I have a little problem. It happend that my device does not support neither PnP not DMA.
All PCI devices support PnP.
–
Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com
Dear ,
A PCI device has to support standard PCI way to configure its BAR addresses, otherwise it is not a PCI device; the Windows PCI bus driver does not know how to assign resources for it.
Was it designed on some non-Windows platform, and you now port it to Windows?
– pa
> All PCI devices support PnP.
Well, my device is a part of previously-developed PLD firmware with closed sources, so I only can deal with what I have now. It’s sad but I have no choice in this case
> A PCI device has to support standard PCI way to configure its BAR addresses,
otherwise it is not a PCI device; the Windows PCI bus driver does not know how
to assign resources for it.
Call me Alex, i think my name is cracked because of encoding on my mac or whatever.
I can only say that when I plugged in the board for the first time, Windows assigned a “Standard RAM controller” driver for it, and I could already see me 3 BAR addresses ranges plus 1 IRQ
By the way, I have to append, that Jungo WinDriver app somehow getting all the resources for its future template and shows me all the config space structure and BARs. As Jungo’s library sources are also closed, I assume this tool somehow can read from config space but I can’t see how exactly
The Jungo stuff does it by violating the locking of Windows. Your device is
PnP, just because Windows assigns a driver to the device, does not mean that
you cannot create an INF file for it that replaces that driver with the
correct one. Go into Device Manager select your device, choose properties,
and under the details tab look at the hardware ID’s then build an INF for
that ID.
Don Burn
Windows Driver Consulting
Website: http://www.windrvr.com
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Tuesday, February 02, 2016 6:26 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] PCI driver - read BARs from config space (non-pnp, KMDF)
By the way, I have to append, that Jungo WinDriver app somehow getting all
the resources for its future template and shows me all the config space
structure and BARs. As Jungo’s library sources are also closed, I assume
this tool somehow can read from config space but I can’t see how exactly
NTDEV is sponsored by OSR
Visit the list online at:
http:
MONTHLY seminars on crash dump analysis, WDF, Windows internals and software
drivers!
Details at http:
To unsubscribe, visit the List Server section of OSR Online at
http:</http:></http:></http:>
Don Burn, thank you for your answer.
By the way, I thought that if I need to plug in the device (via PCI cabel) before switching on the PC for Windows to see that device, and if I do that after Windows loaded, it doesnt see it, means my device doesn’t support PnP…
Thank you, I know how to build a driver, but the problem is, when I first created a PnP driver for the device, Device Manager said i dont have any resources, even when I implemented EvtPrepareHardware routine
The plug in problem means your system (like most) does not support hot plug
PCI. This has nothing to do whether your device supports PnP it has to do
whether hot plug is supported for the bus.
On the lack of resources, did you try manually unloading the driver Windows
installed?
Don Burn
Windows Driver Consulting
Website: http://www.windrvr.com
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Tuesday, February 02, 2016 7:59 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] PCI driver - read BARs from config space (non-pnp, KMDF)
Don Burn, thank you for your answer.
By the way, I thought that if I need to plug in the device (via PCI cabel)
before switching on the PC for Windows to see that device, and if I do that
after Windows loaded, it doesnt see it, means my device doesn’t support
PnP…
Thank you, I know how to build a driver, but the problem is, when I first
created a PnP driver for the device, Device Manager said i dont have any
resources, even when I implemented EvtPrepareHardware routine
NTDEV is sponsored by OSR
Visit the list online at:
http:
MONTHLY seminars on crash dump analysis, WDF, Windows internals and software
drivers!
Details at http:
To unsubscribe, visit the List Server section of OSR Online at
http:</http:></http:></http:>
Don Burn, I get it about hot-plug now, thank you.
When Windows assignes a default driver for the device, all the resources are correctly allocated and are listed in Properties tab.
I think I didnt try unloading driver manually, because I dont know what that means. Im quite new for this 
I found a topic http://www.osronline.com/showThread.CFM?link=269862
where is a link to MSDN saying that non-pnp devices does not support interrupt objects. If I have IRQ resource listed for my device, does that also prove my device is PnP-suuported?
How did you install your driver? If you used devcon install you created a virtual (root) device, not what you need. You need to call devcon update
Sent from my Windows 10 phone
From: xxxxx@gmail.commailto:xxxxx
Sent: Tuesday, February 2, 2016 4:59 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] PCI driver - read BARs from config space (non-pnp, KMDF)
Don Burn, thank you for your answer.
By the way, I thought that if I need to plug in the device (via PCI cabel) before switching on the PC for Windows to see that device, and if I do that after Windows loaded, it doesnt see it, means my device doesn’t support PnP…
Thank you, I know how to build a driver, but the problem is, when I first created a PnP driver for the device, Device Manager said i dont have any resources, even when I implemented EvtPrepareHardware routine
—
NTDEV is sponsored by OSR
Visit the list online at: https:
MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:
To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:></mailto:xxxxx></mailto:xxxxx>
Don Burn, I install my driver from Device Manager -> driver Properties -> Driver -> Update… -> Select from existing -> Load from disk -> point to my INF located with .sys
> By the way, I thought that if I need to plug in the device (via PCI cabel) before switching on the PC
for Windows to see that device, and if I do that after Windows loaded, it doesnt see it, means my
device doesn’t support PnP…
It does not support PCIe hotplug, and not PnP.
PCIe hotplug can trivially be not supported by the motherboard either.
–
Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com
Hi Alex,
Could you answer these two questions, please?
-
When Windows installs a default driver for your device, what is that driver?
-
Is your driver based on Jungo library?
Thanks,
– pa
xxxxx@gmail.com wrote:
Hello there, I have, maybe a dumb, problem with writing a PCI driver for specific board on Windows.
I have a little problem. It happend that my device does not support neither PnP not DMA.
You’re getting good help from the list, but I want to point out a couple
of thing that might be confusing.
Your hardware is definitely PnP. If it meets the PCI spec, it is
automatically PnP, by definition. If you don’t meet the PCI spec, then
you are screwed; you cannot write a driver that works in every computer.
Now, it is quite possible that the existing DRIVER you have is not PnP.
Many older PCI drivers were not, especially those that have been handed
down since NT 4. That does not mean that you CANNOT write a PnP driver
for them.
So I faced a wall with figuring out how to obtain BAR base addresses for my device
As it is non-pnp driver, I cannot use EvtPrepareHardware to get those addresses.
You should be writing a PnP driver and using EvtPrepareHardware. I’ll
wager real dollars that you will be handed the resources you need.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
> Pavel A
- As I said before, its called “Standard RAM controller”. Thats all I know about this driver. Maybe the next day I would say more when I reach my test machine
- No, my driver has nothing to do with Jungo libs, thats the main point for driver
Tim Roberts
What do you mean by “If you don’t meet the PCI spec”? If I cant meet spec because of my knowledge, or because technically no one can meet the spec for this device?
Okay, I willl try to write PnP driver carefully this time. I will report back the next day
xxxxx@gmail.com wrote:
> Tim Roberts
What do you mean by “If you don’t meet the PCI spec”? If I cant meet spec because of my knowledge, or because technically no one can meet the spec for this device?
I meant “If the hardware doesn’t meet the PCI spec”. I agree that was
ambiguous on my part.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
Since, with at least some driver, the BARs and interrupt are assigned properly to your HW - your HW satisfies the PCI spec (at least to the degree required by Windows).
This means that it is PnP-compatible.
PCI hotplug is really a different another story (which requires motherboard support BTW).
So, just write a KMDF driver for your device, using standard KMDF ways.
–
Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com
wrote in message news:xxxxx@ntdev…
>> Pavel A
> 1. As I said before, its called “Standard RAM controller”. Thats all I know about this driver. Maybe the next day I would say more when I reach my test machine
> 2. No, my driver has nothing to do with Jungo libs, thats the main point for driver
>
>> Tim Roberts
> What do you mean by “If you don’t meet the PCI spec”? If I cant meet spec because of my knowledge, or because technically no one can meet the spec for this device?
>
> Okay, I willl try to write PnP driver carefully this time. I will report back the next day
>
Tim Roberts, Maxim S.
Thank you for the explanation, I will try to fix my driver (or re-write it), and will report back for sure!