Nothing wrong with intellectual curiosity, but you’d be surprised how many
times I find people asking me about this in class with the *intention* of
going out there and fiddling with them. I always ask, “You’re a hardware
designer, aren’t you?” and the answer is always “yes”. And it is also the
case that they sometimes were working on bare machines without even a decent
PCI BIOS (in their past) and think that they actually *have* to do this
stuff. Some are even offended that they can’t.
joe
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Madhusudan Narayan
Sent: Tuesday, November 25, 2008 2:00 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Question on MMIO for a PCI device
Joe,
I agree that driver programmers do not need to worry about these.
I was(am) just curious to know the little magic done by the OS, and BIOS.
Thanks a lot for mentioning the sources of more information.
regards,
Madhu
On Wed, Nov 26, 2008 at 12:21 AM, Joseph M. Newcomer
wrote:
If you are trying to program PCI and do not have a copy of the Mindshare bok
“PCI System Architecture” (Tom Shanley and Don Anderson, Addison Wesley; I
have the Third Edition, up to PCI 2.1, published in 1995. They also have
PCIe and PCIx books), then stop right now and go get them.
The Hub Controller Interface (nee North Bridge) only knows a window of
address values. It drops the address onto the address lines of the PCI bus.
After that, it is up to the devices to respond. If a device does not
acknowledge the address within a specified time, an access fault is
triggered. The HCI does not “remember” any BAR values at all; it only
handles the idea that some block of addresses are rumored to be on the bus,
and it is up to the individual devices to confirm (or implicitly deny) those
rumors.
Because each bridge chip does have an address range (a base register and a
limit register, see p.419 of the above-cited work), if you were to change
the BAR value, you would have to program EACH bridge chip along the path to
have a different limit.
Why do you think this is even a concept that anyone should care about? The
whole point of the OS is to mask this nonsense so you never need to worry
about it. The mechanisms for handling this are built deep into the BIOS and
OS, and are of no concern to you; all you care about is what VIRTUAL address
you have to access the MMIO values on the card, and that’s already handed to
you! There is absolutely no reason you need to write the BAR registers or
reprogram the bridges. You are approaching this problem from the wrong
direction. Stop thinking grubby-and-irrelevant-low-level hardware details
and think only of the OS interface presented to you.
Look at some PCI examples in the DDK, for example, search for
CM_RESOURCE_LIST in the toaster.c example to see where you get the virtual
address (in my copy, it is around line 1346). This would give you an
address/length pair for one of the addresses mapped from the BAR.
joe
_____
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Madhusudan Narayan
Sent: Tuesday, November 25, 2008 12:39 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Question on MMIO for a PCI device
Thanks a lot Tim.
Some clarification required(questions inline)
On Tue, Nov 25, 2008 at 10:45 PM, Tim Roberts wrote:
Madhusudan Narayan wrote:
>
> I have a few questions about Memory mapped IO.
> 1. where does that intelligence of mapping physical address space to
> device address lie?
The responsibility is somewhat spread out. The device embeds in the BAR
the size of the region it needs. The BIOS then assigns a chunk of the
physical address space by writing to the BAR. Depending on the version,
the operating system might assign a new address by rewriting the BAR.
The driver has the job of mapping this physical address region into
virtual address space so that it can be used.
Finally, it is the job of
the hardware to recognize and handle bus cycles that are within its BARs.
Here, hardware in the sense, the bus controller/Northbridge? Does this
remember what values were written into BARs?
> 2. What operations are involved (from a programmer’s perspective)in
> accomplishing this on a PCI device?
See previous paragraph. The samples show how to map the BAR into
virtual address space.
> 3. if I just modify the MMIO BAR of the PCI register, does it cause a
> different block physical address space to be mapped to device IO?
Only in the sense that the device will start looking for a different
region. The BIOS and the operating system will not know of the changes,
so they might think that the address space was usable for other
devices.
Plus, if your device sits behind a PCI bridge, the bridge also
has to be notified of the new BAR.
How do we(rather OS/BIOS) notify the bridge? what is this bridge enumerated
as?
General advice: DO NOT change your
device’s BAR. Let the operating system handle it.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by http:</http:> MailScanner, and is
believed to be clean.
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and
dangerous content by http:</http:> MailScanner, and is
believed to be clean.