1 /* $OpenBSD: pcivar.h,v 1.42 2005/06/29 03:53:28 brad Exp $ */ 2 /* $NetBSD: pcivar.h,v 1.23 1997/06/06 23:48:05 thorpej Exp $ */ 3 4 /* 5 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. 6 * Copyright (c) 1994 Charles Hannum. All rights reserved. 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 by Charles Hannum. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #ifndef _DEV_PCI_PCIVAR_H_ 35 #define _DEV_PCI_PCIVAR_H_ 36 37 /* 38 * Definitions for PCI autoconfiguration. 39 * 40 * This file describes types and functions which are used for PCI 41 * configuration. Some of this information is machine-specific, and is 42 * provided by pci_machdep.h. 43 */ 44 45 #include <machine/bus.h> 46 #include <dev/pci/pcireg.h> 47 48 /* 49 * Structures and definitions needed by the machine-dependent header. 50 */ 51 typedef u_int32_t pcireg_t; /* configuration space register XXX */ 52 struct pcibus_attach_args; 53 54 /* 55 * Machine-dependent definitions. 56 */ 57 #if defined(__alpha__) 58 #include <alpha/pci/pci_machdep.h> 59 #elif defined(__i386__) 60 #include <i386/pci/pci_machdep.h> 61 #elif defined(__cats__) 62 #include <cats/pci/pci_machdep.h> 63 #elif defined(__powerpc__) 64 #include <powerpc/pci/pci_machdep.h> 65 #elif defined(__sgi__) 66 #include <sgi/pci/pci_machdep.h> 67 #else 68 #include <machine/pci_machdep.h> 69 #endif 70 71 /* 72 * PCI bus attach arguments. 73 */ 74 struct pcibus_attach_args { 75 char *pba_busname; /* XXX should be common */ 76 bus_space_tag_t pba_iot; /* pci i/o space tag */ 77 bus_space_tag_t pba_memt; /* pci mem space tag */ 78 bus_dma_tag_t pba_dmat; /* DMA tag */ 79 pci_chipset_tag_t pba_pc; 80 81 int pba_bus; /* PCI bus number */ 82 83 /* 84 * Interrupt swizzling information. These fields 85 * are only used by secondary busses. 86 */ 87 u_int pba_intrswiz; /* how to swizzle pins */ 88 pcitag_t pba_intrtag; /* intr. appears to come from here */ 89 }; 90 91 /* 92 * PCI device attach arguments. 93 */ 94 struct pci_attach_args { 95 bus_space_tag_t pa_iot; /* pci i/o space tag */ 96 bus_space_tag_t pa_memt; /* pci mem space tag */ 97 bus_dma_tag_t pa_dmat; /* DMA tag */ 98 pci_chipset_tag_t pa_pc; 99 int pa_flags; /* flags; see below */ 100 101 u_int pa_device; 102 u_int pa_bus; 103 u_int pa_function; 104 pcitag_t pa_tag; 105 pcireg_t pa_id, pa_class; 106 107 /* 108 * Interrupt information. 109 * 110 * "Intrline" is used on systems whose firmware puts 111 * the right routing data into the line register in 112 * configuration space. The rest are used on systems 113 * that do not. 114 */ 115 u_int pa_intrswiz; /* how to swizzle pins if ppb */ 116 pcitag_t pa_intrtag; /* intr. appears to come from here */ 117 pci_intr_pin_t pa_intrpin; /* intr. appears on this pin */ 118 pci_intr_line_t pa_intrline; /* intr. routing information */ 119 pci_intr_pin_t pa_rawintrpin; /* unswizzled pin */ 120 }; 121 122 /* 123 * Flags given in the bus and device attachment args. 124 * 125 * OpenBSD doesn't actually use them yet -- csapuntz@cvs.openbsd.org 126 */ 127 #define PCI_FLAGS_IO_ENABLED 0x01 /* I/O space is enabled */ 128 #define PCI_FLAGS_MEM_ENABLED 0x02 /* memory space is enabled */ 129 #define PCI_FLAGS_MRL_OKAY 0x04 /* Memory Read Line okay */ 130 #define PCI_FLAGS_MRM_OKAY 0x08 /* Memory Read Multiple okay */ 131 #define PCI_FLAGS_MWI_OKAY 0x10 /* Memory Write and Invalidate 132 okay */ 133 134 /* 135 * 136 */ 137 struct pci_quirkdata { 138 pci_vendor_id_t vendor; /* Vendor ID */ 139 pci_product_id_t product; /* Product ID */ 140 int quirks; /* quirks; see below */ 141 }; 142 #define PCI_QUIRK_MULTIFUNCTION 0x00000001 143 144 /* 145 * Locators devices that attach to 'pcibus', as specified to config. 146 */ 147 #define pcibuscf_bus cf_loc[0] 148 #define PCIBUS_UNK_BUS -1 /* wildcarded 'bus' */ 149 150 /* 151 * Locators for PCI devices, as specified to config. 152 */ 153 #define pcicf_dev cf_loc[0] 154 #define PCI_UNK_DEV -1 /* wildcarded 'dev' */ 155 156 #define pcicf_function cf_loc[1] 157 #define PCI_UNK_FUNCTION -1 /* wildcarded 'function' */ 158 159 /* 160 * Configuration space access and utility functions. (Note that most, 161 * e.g. make_tag, conf_read, conf_write are declared by pci_machdep.h.) 162 */ 163 pcireg_t pci_mapreg_type(pci_chipset_tag_t, pcitag_t, int); 164 int pci_mapreg_info(pci_chipset_tag_t, pcitag_t, int, pcireg_t, 165 bus_addr_t *, bus_size_t *, int *); 166 int pci_mapreg_map(struct pci_attach_args *, int, pcireg_t, int, 167 bus_space_tag_t *, bus_space_handle_t *, bus_addr_t *, 168 bus_size_t *, bus_size_t); 169 170 171 int pci_io_find(pci_chipset_tag_t, pcitag_t, int, bus_addr_t *, 172 bus_size_t *); 173 int pci_mem_find(pci_chipset_tag_t, pcitag_t, int, bus_addr_t *, 174 bus_size_t *, int *); 175 176 int pci_get_capability(pci_chipset_tag_t, pcitag_t, int, 177 int *, pcireg_t *); 178 179 struct pci_matchid { 180 pci_vendor_id_t pm_vid; 181 pci_product_id_t pm_pid; 182 }; 183 184 int pci_matchbyid(struct pci_attach_args *, const struct pci_matchid *, int); 185 186 /* 187 * Helper functions for autoconfiguration. 188 */ 189 const char *pci_findvendor(pcireg_t); 190 void pci_devinfo(pcireg_t, pcireg_t, int, char *, size_t); 191 const struct pci_quirkdata * 192 pci_lookup_quirkdata(pci_vendor_id_t, pci_product_id_t); 193 void pciagp_set_pchb(struct pci_attach_args *); 194 195 /* 196 * Power Management (PCI 2.2) 197 */ 198 #define PCI_PWR_D0 0 199 #define PCI_PWR_D1 1 200 #define PCI_PWR_D2 2 201 #define PCI_PWR_D3 3 202 203 #endif /* _DEV_PCI_PCIVAR_H_ */ 204