1.\" $NetBSD: pci_configure_bus.9,v 1.1 2001/02/10 02:50:37 briggs 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-dependant 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 function in the sandpoint implementation looks like: 128.Pp 129.Bd -literal -compact 130void 131pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int func, 132 int swiz, int *iline) 133{ 134 if (bus == 0) { 135 *iline = dev; 136 } else { 137 *iline = 13 + ((swiz + dev + 3) & 3); 138 } 139} 140.Ed 141.Pp 142The BeBox has nearly 1GB of PCI I/O memory starting at processor address 1430x81000000 (PCI I/O address 0x01000000), and nearly 1GB of PCI memory 144starting at 0xC0000000 (PCI memory address 0x00000000). 145The 146.Fn pci_configure_bus 147function might be called as follows: 148.Pp 149.Bd -literal -compact 150 struct extent *ioext, *memext; 151 ... 152 ioext = extent_create("pciio", 0x01000000, 0x0fffffff, M_DEVBUF, 153 NULL, 0, EX_NOWAIT); 154 memext = extent_create("pcimem", 0x00000000, 0x0fffffff, M_DEVBUF, 155 NULL, 0, EX_NOWAIT); 156 ... 157 pci_configure_bus(0, ioext, memext, NULL); 158 ... 159 extent_destroy(ioext); 160 extent_destroy(memext); 161 ... 162.Ed 163.Pp 164Note that this must be called before the PCI bus is attached during 165autoconfiguration. 166.Sh ENVIRONMENT 167The 168.Fn pci_configure_bus 169function is only included in the kernel if the kernel is compiled with 170the 171.Dv PCI_NETBSD_CONFIGURE 172option enabled. 173.Sh RETURN VALUES 174If successful 175.Fn pci_configure_bus 176returns 0. A non-zero return value means that the bus was not completely 177configured for some reason. A description of the failure will be displayed 178on the console. 179.Pp 180.Sh SEE ALSO 181.Xr pci 4 , 182.Xr extent 9 183.Sh HISTORY 184.Fn pci_configure_bus 185was added in 186.Nx 1.6 . 187