[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reading BAR0 under WindowsNT

Paul Slade wrote:
> I have written some code that tries to determine the PCI memory
> usage. It does this by going through all the devices and reading each
> BAR, then writing 0xffffffff to each bar and reading it again to
> determine the size. Finally the original BAR value read is written
> back.
Yikes! and DOUBLE Yikes!

<other craziness with the configuration registers snipped>

I'm surprised that the system doesn't go out to lunch the minute
you start tweaking those registers.  After NT (or Windows) is
booted and running, they belong (for all practical purposes)
to the operating system.  It is considered very bad form to
twiddle with those registers, except through the interfaces
that are exposed to the programmer by the operating system.

For NT, the key call is:

    IN BUS_DATA_TYPE BusDataType,
    IN ULONG BusNumber,
    IN ULONG SlotNumber,
    IN PVOID Buffer,
    IN ULONG Length

Typically, you just loop through all the available busses and slots,
and Buffer is returned chock-full of interesting data, like
the vendor and device ID, the BAR's, etc.  See the NT DDK
documentation (you do have an MSDN subscription, don't you --
if you are writing code for the Wintel platform, I wouldn't leave
home without it 8-).

Any other approach is dangerous -- even just reading the 'extended'
configuration space (the bytes past the first 64) could have
unintended side affects (although a pox on any hardware designer
that does something like this 8-).


-- DaveN
Dave New, den@aisinc.com    | Machine vision?
Applied Intelligent Systems |      I'm glad *they* can see the future...
3980 Ranchero Drive         | 
Ann Arbor, MI  48108        |        Opinions expressed are mine.    | PGP 2.6
(313) 332-7010              | 08 12 9F AF 5B 3E B2 9B  6F DC 66 5A 41 0B AB 29
(313) 332-7077 FAX