1.\" $NetBSD: pci_configure_bus.9,v 1.2 2001/06/21 11:59:01 wiz Exp $ 2.\" 3.\" Copyright 2001 Wasabi Systems, Inc. 4.\" All rights reserved. 5.\" 6.\" Written by Allen Briggs for Wasabi Systems, Inc. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. All advertising materials mentioning features or use of this software 17.\" must display the following acknowledgement: 18.\" This product includes software developed for the NetBSD Project by 19.\" Wasabi Systems, Inc. 20.\" 4. The name of Wasabi Systems, Inc. may not be used to endorse 21.\" or promote products derived from this software without specific prior 22.\" written permission. 23.\" 24.\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 28.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34.\" POSSIBILITY OF SUCH DAMAGE. 35.\" 36.Dd February 9, 2001 37.Dt PCI_CONFIGURE_BUS 9 38.Os 39.Sh NAME 40.Nm pci_configure_bus 41.Nm pci_conf_interrupt 42.Nd perform PCI bus configuration 43.Sh SYNOPSIS 44.Fd #include <dev/pci/pciconf.h> 45.Ft int 46.Fo pci_configure_bus 47.Fa "pci_chipset_tag_t pc" 48.Fa "struct extent *ioext" 49.Fa "struct extent *memext" 50.Fa "struct extent *pmemext" 51.Fc 52.Sh DESCRIPTION 53.Pp 54The 55.Fn pci_configure_bus 56function configures a PCI bus for use. This involves: 57.Bl -bullet 58.It 59Defining bus numbers for all busses on the system, 60.It 61Setting the Base Address Registers for all devices, 62.It 63Setting up the interrupt line register for all devices, and 64.It 65Configuring bus latency timers for all devices. 66.El 67.Pp 68In traditional PCs and Alpha systems, the BIOS or firmware takes care 69of this task, but that is not the case for all systems. 70.Fn pci_configure_bus 71should be called prior to the auto-configuration of the bus. 72.Pp 73The 74.Fa pc 75argument is a machine-dependent tag used to specify the PCI chipset to the 76system. This should be the same value used with 77.Fn pci_make_tag . 78The extent arguments 79define memory extents from which the address space for the cards will be 80taken. These addresses should be in the PCI address space. The 81.Fa ioext 82extent is for PCI I/O accesses. The 83.Fa memext 84extent is for PCI memory accesses that might have side effects. I.e., 85that can not be cached. The 86.Fa pmemext 87extent is for PCI memory accesses that can be cached. The 88.Fa pmemext 89extent will be used for any ROMs and any memory regions that are marked as 90.Dq prefetchable 91in their BAR. If an implementation does not distinguish between 92prefetchable and non-prefetchable memory, it may pass NULL for 93.Fa pmemext . 94In this case, prefetchable memory allocations will be made from the 95non-prefetchable region. 96.Pp 97One of the functions of 98.Fn pci_configure_bus 99is to configure interrupt 100.Dq line 101information. This must be done on a machine-dependent basis, so a 102machine-dependent function 103.Fn pci_conf_interrupt 104must be defined. The prototype for this function is 105.Pp 106.Fn "void pci_conf_interrupt" "pci_chipset_tag_t pc" "int bus" \ 107 "int device" "int function" "int swiz" "int *iline" 108.Pp 109In this function, 110.Fa bus , 111.Fa device , 112and 113.Fa function , 114uniquely identify the item being configured. The 115.Fa swiz 116argument is a 117.Dq swizzle , 118a sum of the device numbers of the primary interface of the bridges between 119the host bridge and the current device. The function is responsible for 120setting the value of 121.Fa iline . 122See chapter 9 of the 123.Dq PCI-to-PCI Bridge Architecture Specification 124for more information on swizzling (also known as interrupt routing). 125.Sh EXAMPLES 126The 127.Fn pci_conf_interrupt 128function in the sandpoint implementation looks like: 129.Pp 130.Bd -literal -compact 131void 132pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int func, 133 int swiz, int *iline) 134{ 135 if (bus == 0) { 136 *iline = dev; 137 } else { 138 *iline = 13 + ((swiz + dev + 3) & 3); 139 } 140} 141.Ed 142.Pp 143The BeBox has nearly 1GB of PCI I/O memory starting at processor address 1440x81000000 (PCI I/O address 0x01000000), and nearly 1GB of PCI memory 145starting at 0xC0000000 (PCI memory address 0x00000000). 146The 147.Fn pci_configure_bus 148function might be called as follows: 149.Pp 150.Bd -literal -compact 151 struct extent *ioext, *memext; 152 ... 153 ioext = extent_create("pciio", 0x01000000, 0x0fffffff, M_DEVBUF, 154 NULL, 0, EX_NOWAIT); 155 memext = extent_create("pcimem", 0x00000000, 0x0fffffff, M_DEVBUF, 156 NULL, 0, EX_NOWAIT); 157 ... 158 pci_configure_bus(0, ioext, memext, NULL); 159 ... 160 extent_destroy(ioext); 161 extent_destroy(memext); 162 ... 163.Ed 164.Pp 165Note that this must be called before the PCI bus is attached during 166autoconfiguration. 167.Sh ENVIRONMENT 168The 169.Fn pci_configure_bus 170function is only included in the kernel if the kernel is compiled with 171the 172.Dv PCI_NETBSD_CONFIGURE 173option enabled. 174.Sh RETURN VALUES 175If successful 176.Fn pci_configure_bus 177returns 0. A non-zero return value means that the bus was not completely 178configured for some reason. A description of the failure will be displayed 179on the console. 180.Pp 181.Sh SEE ALSO 182.Xr pci 4 , 183.Xr extent 9 184.Sh HISTORY 185.Fn pci_configure_bus 186was added in 187.Nx 1.6 . 188