From owner-freebsd-acpi@FreeBSD.ORG Thu Apr 30 21:41:23 2009 Return-Path: Delivered-To: freebsd-acpi@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0CF60106567A for ; Thu, 30 Apr 2009 21:41:23 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id BB5758FC2B for ; Thu, 30 Apr 2009 21:41:22 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 50EFB46B7F; Thu, 30 Apr 2009 17:41:22 -0400 (EDT) Received: from jhbbsd.hudson-trading.com (unknown [209.249.190.8]) by bigwig.baldwin.cx (Postfix) with ESMTPA id 10EC58A022; Thu, 30 Apr 2009 17:41:21 -0400 (EDT) From: John Baldwin To: freebsd-acpi@freebsd.org Date: Thu, 30 Apr 2009 08:44:24 -0400 User-Agent: KMail/1.9.7 References: <20090425190801.GA1150@venon.lostgarden> In-Reply-To: <20090425190801.GA1150@venon.lostgarden> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200904300844.24710.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Thu, 30 Apr 2009 17:41:21 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-0.6 required=4.2 tests=AWL,BAYES_00, DATE_IN_PAST_06_12,RDNS_NONE autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: Subject: Re: pci access question X-BeenThere: freebsd-acpi@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: ACPI and power management development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Apr 2009 21:41:23 -0000 On Saturday 25 April 2009 3:08:01 pm William Grzybowski wrote: > Hi, > > I was reading some code and running some tests in freebsd and some doubts came out. > > I know this is not a school but I would like to ask some questions regarding 8086 architecture and pci access, I really appreciate if someone could answer or point me to some good book. > > As far as I can understund the pci controllers have some registers which the cpu can read and write stuff. > Everythings starts with the host pci bridge bus, this bus is define as _BBN in the acpi and is 0 when it is not set. > Then for every pci controller attached to this bus the interrupt routing table is set so this bridge can control them properly. If any of them is a pci controller of the type pci bridge this process is repeated. > > This is how I would describe in a very simple way how the process works with my limited knowledge. > > My questions would be: > > Does ACPI directly inteferes in how pci regs are accesses somehow or a pci_cfgregread is 100% inpendent just with proper locks and asm inb, inl, inw instructions after setting the bus and slot/func? ACPI does not interfere with PCI config access. It is all done by using I/O port access to 0xcf8 and 0xcfc. Newer PCI express systems do support an alternative method of PCI config access using a memory-mapped I/O window. (That is what pcie_cfgreg* implement.) ACPI does provide a table ('MCFG') that describes the available memory windows, but the BIOS does not provide any public AML methods to manage PCI config access. > How does the bridge discovers the pci controllers attached to the bus? Is there some kind of signal or all possible addresses are tested? When scanning a PCI bus, all possible addresses are tested. Look at pci_add_children() in sys/dev/pci/pci.c. When a PCI-PCI bridge driver attaches to a PCI-PCI bridge it scans its child bus during its attach routine. This is all using methods defined in the PCI standard which are true for all PCI implementations. One thing PCI does not define is how to enumerate the list of Host-PCI bridges. ACPI provides this by giving each top-level PCI bus a separate device node with a _BBN method in the ACPI namespace. Other architectures and firmwares provide this info via different methods. > Does the pci bridges need to be initialized by the OS (by initialized i mean set some registers in the controller or something)? Well, the firmware often does some of the setup, but it is not required to. There are all sorts of setup an OS may need to do. It may need to assign bus numbers to PCI-PCI bridges. It may need to assign resources to BARs on devices and to I/O windows on PCI-PCI bridges to provide resources to BARs on devices behind the bridges. > Again, sorry for asking this here, probably not the right place, but I would love any kind of "light", specially a good book about it. For PCI stuff, the Mindshare 'PCI System Architecture' book is what I use. -- John Baldwin