Trouble with initialization of PCI card under Win Vista and above

During porting of my driver to KMDF I encountered with the following trouble under Windows Vista and 7 compare to XP.

When PNP initialize the PCI card by writing to PCI command register 04h in its configuration area, there are generated two pulses on bit 0 - IO Space while on Win XP there is only one puls. This causes malfunction of our card under Win Vista, 7.

Is threre any way how to suppress second puls on HW or SW level?
By the PCI specification there should be only one puls on bit 0 - IO Space…

Yes of course same driver compiled for each target platform.

Thanks so much for any help.

Why that’s causing a problem for you? Does your hardware actually counting the pulses?

xxxxx@seznam.cz wrote:

When PNP initialize the PCI card by writing to PCI command register 04h in its configuration area, there are generated two pulses on bit 0 - IO Space while on Win XP there is only one puls. This causes malfunction of our card under Win Vista, 7.

Is threre any way how to suppress second puls on HW or SW level?
By the PCI specification there should be only one puls on bit 0 - IO Space…

Where do you see that? I just looked through my copy of the PCI spec,
and I find no such restriction. Does your card actually have any I/O
BARs? If not, the spec recommends that you simply make that bit
non-writable.

It is VERY hard for me to imagine a hardware architecture that failed
because the I/O bit happened to be set twice.


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

More detail info taken from HW specialist:

Our card is mapped into I/O space - port resources are used.
The card is initialized by write of log.1 to bit.0 into its COMMAND REGISTER (addr. offset 04h in configuration space).
When PNP system of Win XP initialize card, this bit is set to log.0 and then to log.1 and stays in this state.
The problem is on Win 7 where about 2us later is generated another entry into configuration area. This second entry causes that the bit.0 is set to log.0 what causes blocking of I/O space and malfunctioning of card.

Thanks so much for any help,
Radim

On 28-Feb-2012 12:31, xxxxx@seznam.cz wrote:

More detail info taken from HW specialist:

Our card is mapped into I/O space - port resources are used.
The card is initialized by write of log.1 to bit.0 into its COMMAND REGISTER (addr. offset 04h in configuration space).
When PNP system of Win XP initialize card, this bit is set to log.0 and then to log.1 and stays in this state.
The problem is on Win 7 where about 2us later is generated another entry into configuration area. This second entry causes that the bit.0 is set to log.0 what causes blocking of I/O space and malfunctioning of card.

Thanks so much for any help,
Radim

When you look at the card’s resources in device manager, do you still
see I/O ports there? If not, are the ports replaced by a memory resource?

– pa

Hello Pavel,
thanks for answer.

If I check card’s resources in device manager -> driver properties, there is everything OK and looks same for Win XP and 7. Base address and IO range is assigned and driver is working properly.

While functionality of driver under Win XP is like we expected, under Win 7 not. It happen because of second entry into card’s configuration area where bit.0 is set back from log.1 to log.0. Since this moment card stops working and don’t listen writes & reads from driver… checked by scope.

Thanks so much for any help,
Radim

On 28-Feb-2012 17:10, xxxxx@seznam.cz wrote:

Hello Pavel,
thanks for answer.

If I check card’s resources in device manager -> driver properties, there is everything OK and looks same for Win XP and 7. Base address and IO range is assigned and driver is working properly.

While functionality of driver under Win XP is like we expected, under Win 7 not. It happen because of second entry into card’s configuration area where bit.0 is set back from log.1 to log.0. Since this moment card stops working and don’t listen writes& reads from driver… checked by scope.

Thanks so much for any help,
Radim

Now this is very strange. Basically you say that
win7 just resets the i/o enable bit in the command register.

What dump of the config space (!pci) shows?
– pa

xxxxx@seznam.cz wrote:

If I check card’s resources in device manager -> driver properties, there is everything OK and looks same for Win XP and 7. Base address and IO range is assigned and driver is working properly.

It is a very poor design decision to use I/O ports. Unless you are a
graphics card that needs to emulate a VGA, there is NO justification for
using I/O ports. The I/O port instructions are tens to hundreds of
times slower than memory instructions, and you gain nothing in return.

While functionality of driver under Win XP is like we expected, under Win 7 not. It happen because of second entry into card’s configuration area where bit.0 is set back from log.1 to log.0. Since this moment card stops working and don’t listen writes & reads from driver… checked by scope.

You shouldn’t be using that bit as a “board initialize” bit. The card
should be initialized when power is applied. Nowhere does the PCI spec
define that as a one-time-only “board enable” bit. It merely enables or
disables access to any I/O ports. An operating system is free to toggle
that bit back and forth as it chooses.

Having said that, it shouldn’t be leaving the I/O ports disabled,
assuming you were assigned a proper range in the BAR. How large is the
I/O port range? Do you sit behind a bridge? Is there a memory BAR as
well? Does it leave the memory bit enabled?


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

It sounds like you’re trying to debug a software problem by looking at the
hardware. That’s like trying to count the people in the apartment above you
by putting your ear to the ceiling. It might work, but it’s much faster and
more accurate to just go upstairs and look into that apartment.

Hook up a debugger and tell us what state the driver is in. Is it started?
Is it powered on? What happens when you type “!pcitree” and then find your
device and type “!devext ”?

Jake Oshins
Windows Kernel Team

This post implies no warrantees and confers no rights.
------------------------------------------------------------
wrote in message news:xxxxx@ntdev…

More detail info taken from HW specialist:

Our card is mapped into I/O space - port resources are used.
The card is initialized by write of log.1 to bit.0 into its COMMAND
REGISTER (addr. offset 04h in configuration space).
When PNP system of Win XP initialize card, this bit is set to log.0 and
then to log.1 and stays in this state.
The problem is on Win 7 where about 2us later is generated another entry
into configuration area. This second entry causes that the bit.0 is set to
log.0 what causes blocking of I/O space and malfunctioning of card.

Thanks so much for any help,
Radim

xxxxx@windows.microsoft.com wrote:

It sounds like you’re trying to debug a software problem by looking at
the hardware. That’s like trying to count the people in the apartment
above you by putting your ear to the ceiling. It might work, but it’s
much faster and more accurate to just go upstairs and look into that
apartment.

I have seen this before with Win7.

Sequence is as follows:

  1. BIOS enables IO space and sets up an interrupt pin.
  2. Windows detects device and loads driver.
  3. Device driver forwards IRP_MN_START_DEVICE onto pci.sys PDO.
  4. On completion of IRP_MN_START_DEVICE pci.sys has DISABLED IO access
    in PCI configuration space.
  5. Driver then attempts to set up IO space and access registers (which
    fail).

Only thing that was different with this card and other PCI devices with
IO resources in the failing systems was the fact that it didn’t have any
support for the PCI power management features.

In the case I saw we managed to work around this by explicitly
re-enabling IO access by performing a configuration space write after
IRP_MN_START_DEVICE was completed by pci.sys.

Mike


Mike Pumford, Senior Software Engineer
MPC Data Limited
e-mail: xxxxx@mpcdata.com web: www.mpcdata.com
tel: +44 (0) 1225 710600 fax: +44 (0) 1225 710601
ddi: +44 (0) 1225 710635

Hello all,
thanks so much for aswers.

A. Card

  • it is used to control of tester for semiconductor devices
  • HW design is more than 10 years old
  • 3 pcs PLDs (from Lattice) are used for PCI stuff (FW)
  • FW completely implemented by our company
  • mapped I/O ports are used, because it has been easier to implement into FW compare to mapped memory
    Speed of instruction execution is ok for us.
  • PCI: 5.25V, 33MHz
  • no interrupt, DMA used
  • no PCI power management support

B. Driver

  • old orignal driver for Win 2k,XP re-compiled for Vista,7 failed on instalation
  • that for reason for me to transfer to new one - KMDF
  • new KMDF driver developmet platform Win XP, debugged using WinDbg, 100% working properly with our SW

C. Testing PC

  • multiboot of Win XP,Vista,7 on one PC, same PC-HW used for several OSs we would like to support

D. Trouble in Win Vista,7

  • driver properties in device manager displays required range 255 ports length

  • the assigned BAR and ports length from driver properties given into driver’s EvtDevicePrepareHardware

  • when I try in EvtDevicePrepareHardware initialize card by write of card’s status word it failed
    //Initialize of statusword
    codeword = 0xC100;
    WRITE_PORT_USHORT((PUSHORT)((ULONG)fdoData->PortBase + STATUS_WORD_TIMES_REG_OFFS), codeword);
    KdPrint((“[SzIfPci] Initialization statusword=0x%X \n”, codeword));
    //Read statusword to check if card is operational
    codeword = READ_PORT_USHORT((PSHORT)((ULONG)fdoData->PortBase + STATUS_WORD_REG_OFFS));
    if (codeword == 0x0100)
    KdPrint((“[SzIfPci] Initialization check - OK :-))), statusword=0x%X \n”, codeword));
    else {
    KdPrint((“[SzIfPci] Initialization check - ERR !!!, statusword=0x%X \n”, codeword));
    return status = STATUS_UNSUCCESSFUL;
    }

  • the reason is that bit.0 (IO Space) of PCI bus - COMMAND REGISTER (offset 04h in configuration space)
    has level log.0 (card is dissabled) instead of expected log.1 (checked by scope).

  • bit IO Space on Win XP - there it is OK and works like in PCI specification


XXXXXXXXXXXXXXXXXXXXXXXXXXXXX____| |_________________
PNP initialization (BAR?) IRP_MN_START_DEVICE EvtReleaseHardware
EvtDevicePrepareHardware IRP_MN_STOP_DEVICE
/* ***** D R I V E R L O A D ***** */ /* ***** D R I V E R U N L O A D ***** */

  • IO Space on Win Vista,7 - failed. The card is enabled by value log.1, but 2us later it is dissabled by log.0

XXXXXXXXXXXXXXXXXXXXXXXXXXXXX____| |____________________________________________________________________
PNP initialization (BAR?) IRP_MN_START_DEVICE EvtReleaseHardware
EvtDevicePrepareHardware IRP_MN_STOP_DEVICE
/* ***** D R I V E R L O A D ***** */ /* ***** D R I V E R U N L O A D ***** */

By my opinion the problem is in behaviour of PCI bus driver (pci.sys ?) which performs IRP_MN_START_DEVICE.
When the framework calls my driver’s EvtDevicePrepareHardware the card is already disabled and read/write from driver failed.
Read always returns FFFF.

Conclusion:
PCI PNP behaviour of IO Space bit in Win XP is different compare to Win Vista,7

So, does anybody knows about how make IO Space bit like in Win XP ? HW or SW way …

Mike please can you advice me, how did you re-enable IO access by performing a configuration space write after
IRP_MN_START_DEVICE was completed by pci.sys in your driver?

Thanks so much for any help,
Radim

My “pictures” again…

or use http://rapidshare.com/files/3875950667/IO_Space.jpg

  • bit IO Space on Win XP - there it is OK and works like in PCI specification

XXXXXXXXXX____| |_________________
PNP init IRP_MN_START_DEVICE EvtReleaseHardware
EvtDevicePrepareHardware IRP_MN_STOP_DEVICE
/* D R I V E R L O A D */ /* D R I V E R U N L O A D */

  • IO Space on Win Vista,7 - failed. The card is enabled by value log.1, but 2us later it is dissabled by log.0

XXXXXXXXXX____| |_______________________________________
PNP init IRP_MN_START_DEVICE EvtReleaseHardware
EvtDevicePrepareHardware IRP_MN_STOP_DEVICE
/* D R I V E R L O A D */ /* D R I V E R U N L O A D */

If we exclude possibilities of a miracle or peculiar hardware bug…
maybe a rebalance occurs and your device is temporarily disabled,
but your driver somehow misses this.
Have you tested the driver with verifier?
– pa

wrote in message news:xxxxx@ntdev…
> My “pictures” again…
>
> or use http://rapidshare.com/files/3875950667/IO_Space.jpg
>
> - bit IO Space on Win XP - there it is OK and works like in PCI
> specification
>
> XXXXXXXXXX
| |
> PNP init IRP_MN_START_DEVICE EvtReleaseHardware
> EvtDevicePrepareHardware IRP_MN_STOP_DEVICE
> /* D R I V E R L O A D / / D R I V E R U N L O A D */
>
>
> - IO Space on Win Vista,7 - failed. The card is enabled by value log.1,
> but 2us later it is dissabled by log.0
>

> XXXXXXXXXX | |

> PNP init IRP_MN_START_DEVICE EvtReleaseHardware
> EvtDevicePrepareHardware IRP_MN_STOP_DEVICE
> /* D R I V E R L O A D / / D R I V E R U N L O A D */
>
>

Install checked build of OS and see if it will issue any warnings/ asserts.