1 /* $OpenBSD: pcibiosvar.h,v 1.19 2024/05/13 01:15:50 jsg Exp $ */ 2 /* $NetBSD: pcibios.h,v 1.2 2000/04/28 17:15:16 uch Exp $ */ 3 4 /* 5 * Copyright (c) 1999, by UCHIYAMA Yasushi 6 * 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. The name of the developer may NOT be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 /* 30 * Data structure definitions for the PCI BIOS interface. 31 */ 32 33 #define PCIBIOS_ADDR_FIXUP 0x001 34 #define PCIBIOS_BUS_FIXUP 0x002 35 #define PCIBIOS_INTR_FIXUP 0x004 36 #define PCIBIOS_INTR_GUESS 0x008 37 #define PCIBIOS_VERBOSE 0x010 38 #define PCIBIOS_INTRDEBUG 0x020 39 #define PCIBIOS_FIXUP_FORCE 0x040 40 41 /* 42 * PCI BIOS return codes. 43 */ 44 #define PCIBIOS_SUCCESS 0x00 45 #define PCIBIOS_SERVICE_NOT_PRESENT 0x80 46 #define PCIBIOS_FUNCTION_NOT_SUPPORTED 0x81 47 #define PCIBIOS_BAD_VENDOR_ID 0x83 48 #define PCIBIOS_DEVICE_NOT_FOUND 0x86 49 #define PCIBIOS_BAD_REGISTER_NUMBER 0x87 50 #define PCIBIOS_SET_FAILED 0x88 51 #define PCIBIOS_BUFFER_TOO_SMALL 0x89 52 53 struct pcibios_softc { 54 struct device sc_dev; 55 56 int max_bus; 57 58 /* address fixup guts */ 59 struct extent *extent_mem; 60 struct extent *extent_port; 61 bus_addr_t mem_alloc_start; 62 bus_addr_t port_alloc_start; 63 int nbogus; 64 }; 65 66 /* 67 * PCI IRQ Routing Table definitions. 68 */ 69 70 /* 71 * Slot entry (per PCI 2.1) 72 */ 73 struct pcibios_linkmap { 74 u_int8_t link; 75 u_int16_t bitmap; 76 } __packed; 77 78 struct pcibios_intr_routing { 79 u_int8_t bus; 80 u_int8_t device; 81 struct pcibios_linkmap linkmap[4]; /* INT[A:D]# */ 82 u_int8_t slot; 83 u_int8_t reserved; 84 } __packed; 85 86 /* 87 * $PIR header. Reference: 88 * 89 * http://www.microsoft.com/whdc/archive/pciirq.mspx 90 */ 91 struct pcibios_pir_header { 92 u_int32_t signature; /* $PIR */ 93 u_int16_t version; 94 u_int16_t tablesize; 95 u_int8_t router_bus; 96 u_int8_t router_devfunc; 97 u_int16_t exclusive_irq; 98 u_int32_t compat_router; /* PCI vendor/product */ 99 u_int32_t miniport; 100 u_int8_t reserved[11]; 101 u_int8_t checksum; 102 } __packed; 103 104 #define PIR_DEVFUNC_DEVICE(devfunc) (((devfunc) >> 3) & 0x1f) 105 #define PIR_DEVFUNC_FUNCTION(devfunc) ((devfunc) & 7) 106 #define PIR_DEVFUNC_COMPOSE(dev,func) ((((dev) &0x1f) << 3) | ((func) & 7)) 107 108 extern struct pcibios_pir_header pcibios_pir_header; 109 extern struct pcibios_intr_routing *pcibios_pir_table; 110 extern int pcibios_pir_table_nentries; 111 112 extern int pcibios_flags; 113 114 typedef void *pciintr_icu_handle_t; 115 116 struct pciintr_icu { 117 int (*pi_getclink)(pciintr_icu_handle_t, int, int *); 118 int (*pi_get_intr)(pciintr_icu_handle_t, int, int *); 119 int (*pi_set_intr)(pciintr_icu_handle_t, int, int); 120 int (*pi_get_trigger)(pciintr_icu_handle_t, int, int *); 121 int (*pi_set_trigger)(pciintr_icu_handle_t, int, int); 122 }; 123 124 typedef const struct pciintr_icu *pciintr_icu_tag_t; 125 126 #define pciintr_icu_getclink(t, h, link, pirqp) \ 127 (*(t)->pi_getclink)((h), (link), (pirqp)) 128 #define pciintr_icu_get_intr(t, h, pirq, irqp) \ 129 (*(t)->pi_get_intr)((h), (pirq), (irqp)) 130 #define pciintr_icu_set_intr(t, h, pirq, irq) \ 131 (*(t)->pi_set_intr)((h), (pirq), (irq)) 132 #define pciintr_icu_get_trigger(t, h, irq, triggerp) \ 133 (*(t)->pi_get_trigger)((h), (irq), (triggerp)) 134 #define pciintr_icu_set_trigger(t, h, irq, trigger) \ 135 (*(t)->pi_set_trigger)((h), (irq), (trigger)) 136 137 #define PCIBIOS_PRINTV(arg) \ 138 do { \ 139 if (pcibios_flags & PCIBIOS_VERBOSE) \ 140 printf arg; \ 141 } while (0) 142 143 #define PCIADDR_SEARCH_IO 0 144 #define PCIADDR_SEARCH_MEM 1 145 146 #define PCI_INT_VIA_ISA 0x20000000 /* XXX see APIC_INT_VIA_APIC */ 147 148 int pci_intr_fixup(struct pcibios_softc *, pci_chipset_tag_t, bus_space_tag_t); 149 int pci_bus_fixup(pci_chipset_tag_t, int); 150 void pci_addr_fixup(struct pcibios_softc *, pci_chipset_tag_t, int); 151 void pci_device_foreach(struct pcibios_softc *, pci_chipset_tag_t, int, 152 void (*)(struct pcibios_softc *, pci_chipset_tag_t, pcitag_t)); 153 int pci_intr_header_fixup(pci_chipset_tag_t, pcitag_t, pci_intr_handle_t *); 154 int pci_intr_route_link(pci_chipset_tag_t, pci_intr_handle_t *); 155 int pci_intr_post_fixup(void); 156 157 /* 158 * Init functions for our known PCI ICUs. 159 */ 160 int piix_init(pci_chipset_tag_t, bus_space_tag_t, pcitag_t, 161 pciintr_icu_tag_t *, pciintr_icu_handle_t *); 162 int opti82c558_init(pci_chipset_tag_t, bus_space_tag_t, pcitag_t, 163 pciintr_icu_tag_t *, pciintr_icu_handle_t *); 164 int opti82c700_init(pci_chipset_tag_t, bus_space_tag_t, pcitag_t, 165 pciintr_icu_tag_t *, pciintr_icu_handle_t *); 166 int via82c586_init(pci_chipset_tag_t, bus_space_tag_t, pcitag_t, 167 pciintr_icu_tag_t *, pciintr_icu_handle_t *); 168 int via8231_init(pci_chipset_tag_t, bus_space_tag_t, pcitag_t, 169 pciintr_icu_tag_t *, pciintr_icu_handle_t *); 170 int sis85c503_init(pci_chipset_tag_t, bus_space_tag_t, pcitag_t, 171 pciintr_icu_tag_t *, pciintr_icu_handle_t *); 172 int amd756_init(pci_chipset_tag_t, bus_space_tag_t, pcitag_t, 173 pciintr_icu_tag_t *, pciintr_icu_handle_t *); 174 int ali1543_init(pci_chipset_tag_t, bus_space_tag_t, pcitag_t, 175 pciintr_icu_tag_t *, pciintr_icu_handle_t *); 176 int osb4_init(pci_chipset_tag_t, bus_space_tag_t, pcitag_t, 177 pciintr_icu_tag_t *, pciintr_icu_handle_t *); 178 179