A few newby questions and a desparate plea for help

  1. PCI latency timer. After a ton of web surfing and some review of PC
    books, I think I got to the root of what the PCI timer is and how it is
    implemented, but I still have two questions. a) I have seen two different
    explanations of the timer which determines when the PCI arbiter removes the
    grant to a device. It is either the number of cycles after another device
    requests the bus, or it is the number of cycles in total. I have seen both
    defintions–anybody know which it is? Is this in the PCI spec?–which does
    not appear to be available for free on the internet.

  2. DeviceIoControl “The parameter is incorrect”. This has been killing me
    for a couple of days now. First question is whether the driver is even
    touched when this error is returned. Viewing of debug output appears to
    show that the driver did not get invoked–I just want to be sure. My guess
    would be inconsistent parameters between the createfile and the iocontrol,
    but I can’t see what the problem would be.

  3. I am getting the above message when opening and then trying to invoke a
    deviceiocontrol on a driver. I have spent over 10 hours on this and I
    cannot find or think of anything to help narrow this down–this is pretty
    bread and butter stuff. The driver is a xxx.sys file in a directory, and
    the createfile seems to be opening it ok.

#define IOCTL_PCIDUMPR_DUMP_PCI_DATA \
CTL_CODE( FILE_DEVICE_UNKNOWN, 0xD00, METHOD_BUFFERED, FILE_ANY_ACCESS )

driverHandle = CreateFile(DriverFileName,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);

if (driverHandle == INVALID_HANDLE_VALUE)
ThrowLastError();

…handle is not equal to invalid here…

if(!DeviceIoControl(driverHandle, // handle to driver
IOCTL_PCIDUMPR_DUMP_PCI_DATA, // IOCTL to dump PCI data
NULL, // input (control) buffer pointer
0, // input (control) buffer size
dataBuf, // output (data) buffer pointer
BIG_BUFFER_SIZE, // output (data) buffer size
&dwBytesReturned, // pointer to returned data count
NULL // not overlapped I/O
))
DisplayLastError();

…“The parameter is incorrect”…

PCI latency setting at 1d into the config block that is.

> From: Mark Knutson [mailto:xxxxx@mark-knutson.com]

Sent: Wednesday, June 23, 2004 7:18 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] A few newby questions and a desparate plea for help

  1. PCI latency timer. After a ton of web surfing and some
    review of PC
    books, I think I got to the root of what the PCI timer is and
    how it is
    implemented, but I still have two questions. a) I have seen
    two different
    explanations of the timer which determines when the PCI
    arbiter removes the
    grant to a device. It is either the number of cycles after
    another device
    requests the bus, or it is the number of cycles in total. I
    have seen both
    defintions–anybody know which it is? Is this in the PCI
    spec?–which does
    not appear to be available for free on the internet.

From the PCI spec:
*************************************************************
The master Latency Timer is a programmable timer in each master’s
Configuration Space
(refer to Section 6.2.4.). It is required for each master that is capable of
bursting more
than two data phases. Each master’s Latency Timer is cleared and suspended
whenever it
is not asserting FRAME#. When a master asserts FRAME#, it enables its Latency
Timer to count.

In essence, the value programmed into the Latency Timer represents a minimum
guaranteed number of clocks allotted to the master, after which it must
surrender tenure
as soon as possible after its GNT# is deasserted. The actual duration of a
transaction
(assuming its GNT# is deasserted) can be from a minimum of the Latency Timer
value
plus one clock to a maximum of the Latency Timer value plus the number of
clocks
required to complete an entire cacheline transfer (unless the target asserts
STOP#).
*************************************************************

So the master Latency Timer is “the number of cycles in total”.

Dmitriy Budko, VMware

From the PCI spec:
*************************************************************
The master Latency Timer is a programmable timer in each master’s
Configuration Space
(refer to Section 6.2.4.). It is required for each master that is capable of
bursting more
than two data phases. Each master’s Latency Timer is cleared and suspended
whenever it
is not asserting FRAME#. When a master asserts FRAME#, it enables its
Latency
Timer to count.

In essence, the value programmed into the Latency Timer represents a minimum
guaranteed number of clocks allotted to the master, after which it must
surrender tenure
as soon as possible after its GNT# is deasserted. The actual duration of a
transaction
(assuming its GNT# is deasserted) can be from a minimum of the Latency Timer
value
plus one clock to a maximum of the Latency Timer value plus the number of
clocks
required to complete an entire cacheline transfer (unless the target asserts
STOP#).
*************************************************************

So the master Latency Timer is “the number of cycles in total”.

Dmitriy Budko, VMware

Thanks for the information!

I got it going using the SCM functionality. What I am doing is a small
utility where I want to load the driver under the covers and unload it when
the program exits so there aren’t install programs and so forth.

The thing that puzzles me is that some examples I have seen gave me the
impression that I could simply do a createfile in the xxx.sys driver
executable and I would be able to use it. I got a handle back, but when I
tried the iocntl, it gave me the error.

So, with the scm functions I am creating the registry entries and so forth
and I can see how that works, but just opening the driver executable seemed
like a nice shortcut.

Another thing is it appears that the scm functions do not work with relative
paths to the driver executable, but must have the entire path
specified–took me a few hours to get that figured out.

> ----------

From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Mark Knutson[SMTP:xxxxx@mark-knutson.com]
Reply To: Windows System Software Devs Interest List
Sent: Friday, June 25, 2004 1:31 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] A few newby questions and a desparate plea for help

I got it going using the SCM functionality. What I am doing is a small
utility where I want to load the driver under the covers and unload it when
the program exits so there aren’t install programs and so forth.

See also sc.exe utility which is part of OS installation (XP+, maybe w2k). It allows almost everything what SCM interface and legacy drivers can be installed this way without rebooting. Also, it is possible to change driver or service configuration.

Of course, if you want to control everything from your software, SCM is the way.

The thing that puzzles me is that some examples I have seen gave me the
impression that I could simply do a createfile in the xxx.sys driver
executable and I would be able to use it. I got a handle back, but when I
tried the iocntl, it gave me the error.

So, with the scm functions I am creating the registry entries and so forth
and I can see how that works, but just opening the driver executable seemed
like a nice shortcut.

As far as I know, it was w9x only hack. Obnoxious API abuse, IMHO.

Another thing is it appears that the scm functions do not work with relative
paths to the driver executable, but must have the entire path
specified–took me a few hours to get that figured out.

It may be a good idea to examine registry entries for other drivers to see what is possible. Paths relative to system root are valid.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http:://www.upek.com]

Thanks for the answers. I wrote the scm stuff in a parameterized C++ class
so I won’t need to do any coding for subsequent programs.

“Michal Vodicka” wrote in message
news:xxxxx@ntdev…
> ----------
> From:
xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on
behalf of Mark Knutson[SMTP:xxxxx@mark-knutson.com]
> Reply To: Windows System Software Devs Interest List
> Sent: Friday, June 25, 2004 1:31 AM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] A few newby questions and a desparate plea for help
>
> I got it going using the SCM functionality. What I am doing is a small
> utility where I want to load the driver under the covers and unload it
when
> the program exits so there aren’t install programs and so forth.
>
See also sc.exe utility which is part of OS installation (XP+, maybe w2k).
It allows almost everything what SCM interface and legacy drivers can be
installed this way without rebooting. Also, it is possible to change driver
or service configuration.

Of course, if you want to control everything from your software, SCM is the
way.

> The thing that puzzles me is that some examples I have seen gave me the
> impression that I could simply do a createfile in the xxx.sys driver
> executable and I would be able to use it. I got a handle back, but when I
> tried the iocntl, it gave me the error.
>
> So, with the scm functions I am creating the registry entries and so forth
> and I can see how that works, but just opening the driver executable
seemed
> like a nice shortcut.
>
As far as I know, it was w9x only hack. Obnoxious API abuse, IMHO.

> Another thing is it appears that the scm functions do not work with
relative
> paths to the driver executable, but must have the entire path
> specified–took me a few hours to get that figured out.
>
It may be a good idea to examine registry entries for other drivers to see
what is possible. Paths relative to system root are valid.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http:://www.upek.com]

> 2) DeviceIoControl “The parameter is incorrect”. This has been killing me

for a couple of days now. First question is whether the driver is even
touched when this error is returned. Viewing of debug output appears to

This means that the IOCTL IRP was completed with STATUS_INVALID_PARAMETER in
the kernel. Check the input buffer validity and the output buffer size.

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