2 * Copyright (c) 1997, Stefan Esser <se@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: src/sys/pci/pci_compat.c,v 1.35.2.1 2001/10/14 21:14:14 luigi Exp $
27 * $DragonFly: src/sys/bus/pci/pci_compat.c,v 1.2 2003/06/17 04:28:57 dillon Exp $
33 /* for compatibility to FreeBSD-2.2 version of PCI code */
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/malloc.h>
41 #include <sys/interrupt.h>
44 #include <machine/bus.h>
46 #include <machine/resource.h>
48 #include <pci/pcireg.h>
49 #include <pci/pcivar.h>
52 #include <machine/smp.h>
57 /* ------------------------------------------------------------------------- */
60 pci_conf_read(pcici_t cfg, u_long reg)
62 return (pci_read_config(cfg->dev, reg, 4));
66 pci_conf_write(pcici_t cfg, u_long reg, u_long data)
68 pci_write_config(cfg->dev, reg, data, 4);
72 pci_map_port(pcici_t cfg, u_long reg, pci_port_t* pa)
78 res = bus_alloc_resource(cfg->dev, SYS_RES_IOPORT, &rid,
81 *pa = rman_get_start(res);
88 pci_map_mem(pcici_t cfg, u_long reg, vm_offset_t* va, vm_offset_t* pa)
94 res = bus_alloc_resource(cfg->dev, SYS_RES_MEMORY, &rid,
97 *pa = rman_get_start(res);
98 *va = (vm_offset_t) rman_get_virtual(res);
105 pci_map_int(pcici_t cfg, pci_inthand_t *handler, void *arg, intrmask_t *maskptr)
107 return (pci_map_int_right(cfg, handler, arg, maskptr, 0));
111 pci_map_int_right(pcici_t cfg, pci_inthand_t *handler, void *arg,
112 intrmask_t *maskptr, u_int intflags)
118 if (cfg->intpin != 0) {
119 int irq = cfg->intline;
121 struct resource *res;
123 int resflags = RF_SHAREABLE|RF_ACTIVE;
127 if (intflags & INTR_FAST)
128 flags |= INTR_TYPE_FAST;
129 if (intflags & INTR_EXCL)
130 resflags &= ~RF_SHAREABLE;
133 res = bus_alloc_resource(cfg->dev, SYS_RES_IRQ, &rid,
134 irq, irq, 1, resflags);
136 printf("pci_map_int: can't allocate interrupt\n");
141 * This is ugly. Translate the mask into an interrupt type.
143 if (maskptr == &tty_imask)
144 flags |= INTR_TYPE_TTY;
145 else if (maskptr == &bio_imask)
146 flags |= INTR_TYPE_BIO;
147 else if (maskptr == &net_imask)
148 flags |= INTR_TYPE_NET;
149 else if (maskptr == &cam_imask)
150 flags |= INTR_TYPE_CAM;
152 error = BUS_SETUP_INTR(device_get_parent(cfg->dev), cfg->dev,
153 res, flags, handler, arg, &ih);
159 * XXX this apic stuff looks totally busted. It should
160 * move to the nexus code which actually registers the
166 nextpin = next_apic_irq(irq);
172 * Attempt handling of some broken mp tables.
174 * It's OK to yell (since the mp tables are broken).
176 * Hanging in the boot is not OK
180 nextpin = next_apic_irq(nextpin);
181 while (muxcnt < 5 && nextpin >= 0) {
183 nextpin = next_apic_irq(nextpin);
186 printf("bogus MP table, more than 4 IO APIC pins connected to the same PCI device or ISA/EISA interrupt\n");
190 printf("bogus MP table, %d IO APIC pins connected to the same PCI device or ISA/EISA interrupt\n", muxcnt);
192 nextpin = next_apic_irq(irq);
193 while (nextpin >= 0) {
195 res = bus_alloc_resource(cfg->dev, SYS_RES_IRQ, &rid,
199 printf("pci_map_int: can't allocate extra interrupt\n");
202 error = BUS_SETUP_INTR(device_get_parent(cfg->dev),
203 cfg->dev, res, flags,
206 printf("pci_map_int: BUS_SETUP_INTR failed\n");
209 printf("Registered extra interrupt handler for int %d (in addition to int %d)\n", nextpin, irq);
210 nextpin = next_apic_irq(nextpin);
218 pci_unmap_int(pcici_t cfg)
220 return (0); /* not supported, yet, since cfg doesn't know about idesc */
224 pci_get_parent_from_tag(pcici_t tag)
226 return (pcici_t)pci_devlist_get_parent(tag);
230 pci_get_bus_from_tag(pcici_t tag)
235 #endif /* PCI_COMPAT */