a184f1f486
pci_find_rom(), pci_intr_map(9), pci_enumerate_bus(), nor the match predicate passed to pciide_compat_intr_establish() should ever modify their pci_attach_args argument, so make their pci_attach_args arguments const and deal with the fallout throughout the kernel. For the most part, these changes add a 'const' where there was no 'const' before, however, some drivers and MD code used to modify pci_attach_args. Now those drivers either copy their pci_attach_args and modify the copy, or refrain from modifying pci_attach_args: Xen: according to Manuel Bouyer, writing to pci_attach_args in pci_intr_map() was a leftover from Xen 2. Probably a bug. I stopped writing it. I have not tested this change. siside(4): sis_hostbr_match() needlessly wrote to pci_attach_args. Probably a bug. I use a temporary variable. I have not tested this change. slide(4): sl82c105_chip_map() overwrote the caller's pci_attach_args. Probably a bug. Use a local pci_attach_args. I have not tested this change. viaide(4): via_sata_chip_map() and via_sata_chip_map_new() overwrote the caller's pci_attach_args. Probably a bug. Make a local copy of the caller's pci_attach_args and modify the copy. I have not tested this change. While I'm here, make pci_mapreg_submap() static. With these changes in place, I have tested the compilation of these kernels: alpha GENERIC amd64 GENERIC XEN3_DOM0 arc GENERIC atari HADES MILAN-PCIIDE bebox GENERIC cats GENERIC cobalt GENERIC evbarm-eb NSLU2 evbarm-el ADI_BRH ARMADILLO9 CP3100 GEMINI GEMINI_MASTER GEMINI_SLAVE GUMSTIX HDL_G IMX31LITE INTEGRATOR IQ31244 IQ80310 IQ80321 IXDP425 IXM1200 KUROBOX_PRO LUBBOCK MARVELL_NAS NAPPI SHEEVAPLUG SMDK2800 TEAMASA_NPWR TEAMASA_NPWR_FC TS7200 TWINTAIL ZAO425 evbmips-el AP30 DBAU1500 DBAU1550 MALTA MERAKI MTX-1 OMSAL400 RB153 WGT624V3 evbmips64-el XLSATX evbppc EV64260 MPC8536DS MPC8548CDS OPENBLOCKS200 OPENBLOCKS266 OPENBLOCKS266_OPT P2020RDB PMPPC RB800 WALNUT hp700 GENERIC i386 ALL XEN3_DOM0 XEN3_DOMU ibmnws GENERIC macppc GENERIC mvmeppc GENERIC netwinder GENERIC ofppc GENERIC prep GENERIC sandpoint GENERIC sgimips GENERIC32_IP2x sparc GENERIC_SUN4U KRUPS sparc64 GENERIC As of Sun Apr 3 15:26:26 CDT 2011, I could not compile these kernels with or without my patches in place: ### evbmips-el GDIUM nbmake: nbmake: don't know how to make /home/dyoung/pristine-nbsd/src/sys/arch/mips/mips/softintr.c. Stop ### evbarm-el MPCSA_GENERIC src/sys/arch/evbarm/conf/MPCSA_GENERIC:318: ds1672rtc*: unknown device `ds1672rtc' ### ia64 GENERIC /tmp/genassym.28085/assym.c: In function 'f111': /tmp/genassym.28085/assym.c:67: error: invalid application of 'sizeof' to incomplete type 'struct pcb' /tmp/genassym.28085/assym.c:76: error: dereferencing pointer to incomplete type ### sgimips GENERIC32_IP3x crmfb.o: In function `crmfb_attach': crmfb.c:(.text+0x2304): undefined reference to `ddc_read_edid' crmfb.c:(.text+0x2304): relocation truncated to fit: R_MIPS_26 against `ddc_read_edid' crmfb.c:(.text+0x234c): undefined reference to `edid_parse' crmfb.c:(.text+0x234c): relocation truncated to fit: R_MIPS_26 against `edid_parse' crmfb.c:(.text+0x2354): undefined reference to `edid_print' crmfb.c:(.text+0x2354): relocation truncated to fit: R_MIPS_26 against `edid_print'
294 lines
7.1 KiB
C
294 lines
7.1 KiB
C
/* $NetBSD: pci_machdep.c,v 1.29 2011/04/04 20:37:47 dyoung Exp $ */
|
|
|
|
/*
|
|
* Copyright (c) 2000 Soren S. Jorvang. All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions, and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*/
|
|
|
|
#include <sys/cdefs.h>
|
|
__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.29 2011/04/04 20:37:47 dyoung Exp $");
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/param.h>
|
|
#include <sys/time.h>
|
|
#include <sys/systm.h>
|
|
#include <sys/errno.h>
|
|
#include <sys/device.h>
|
|
#include <sys/extent.h>
|
|
|
|
#define _COBALT_BUS_DMA_PRIVATE
|
|
#include <machine/bus.h>
|
|
#include <machine/intr.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
#include <dev/pci/pcireg.h>
|
|
#include <dev/pci/pcidevs.h>
|
|
#include <dev/pci/pciconf.h>
|
|
#include <dev/pci/pciide_apollo_reg.h>
|
|
|
|
#include <cobalt/dev/gtreg.h>
|
|
|
|
/*
|
|
* PCI doesn't have any special needs; just use
|
|
* the generic versions of these functions.
|
|
*/
|
|
struct cobalt_bus_dma_tag pci_bus_dma_tag = {
|
|
_bus_dmamap_create,
|
|
_bus_dmamap_destroy,
|
|
_bus_dmamap_load,
|
|
_bus_dmamap_load_mbuf,
|
|
_bus_dmamap_load_uio,
|
|
_bus_dmamap_load_raw,
|
|
_bus_dmamap_unload,
|
|
_bus_dmamap_sync,
|
|
_bus_dmamem_alloc,
|
|
_bus_dmamem_free,
|
|
_bus_dmamem_map,
|
|
_bus_dmamem_unmap,
|
|
_bus_dmamem_mmap,
|
|
};
|
|
|
|
void
|
|
pci_attach_hook(struct device *parent, struct device *self,
|
|
struct pcibus_attach_args *pba)
|
|
{
|
|
/* XXX */
|
|
|
|
return;
|
|
}
|
|
|
|
int
|
|
pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
|
|
{
|
|
|
|
return 32;
|
|
}
|
|
|
|
pcitag_t
|
|
pci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function)
|
|
{
|
|
|
|
return (bus << 16) | (device << 11) | (function << 8);
|
|
}
|
|
|
|
void
|
|
pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp)
|
|
{
|
|
|
|
if (bp != NULL)
|
|
*bp = (tag >> 16) & 0xff;
|
|
if (dp != NULL)
|
|
*dp = (tag >> 11) & 0x1f;
|
|
if (fp != NULL)
|
|
*fp = (tag >> 8) & 0x07;
|
|
}
|
|
|
|
pcireg_t
|
|
pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
|
|
{
|
|
pcireg_t data;
|
|
int bus, dev, func;
|
|
|
|
KASSERT(pc != NULL);
|
|
|
|
pci_decompose_tag(pc, tag, &bus, &dev, &func);
|
|
|
|
/*
|
|
* 2700 hardware wedges on accesses to device 6.
|
|
*/
|
|
if (bus == 0 && dev == 6)
|
|
return 0;
|
|
/*
|
|
* 2800 hardware wedges on accesses to device 31.
|
|
*/
|
|
if (bus == 0 && dev == 31)
|
|
return 0;
|
|
|
|
bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR,
|
|
PCICFG_ENABLE | tag | reg);
|
|
data = bus_space_read_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_DATA);
|
|
bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 0);
|
|
|
|
return data;
|
|
}
|
|
|
|
void
|
|
pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
|
|
{
|
|
|
|
bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR,
|
|
PCICFG_ENABLE | tag | reg);
|
|
bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_DATA, data);
|
|
bus_space_write_4(pc->pc_bst, pc->pc_bsh, GT_PCICFG_ADDR, 0);
|
|
}
|
|
|
|
int
|
|
pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
|
|
{
|
|
pci_chipset_tag_t pc = pa->pa_pc;
|
|
pcitag_t intrtag = pa->pa_intrtag;
|
|
int pin = pa->pa_intrpin;
|
|
int line = pa->pa_intrline;
|
|
int bus, dev, func;
|
|
|
|
pci_decompose_tag(pc, intrtag, &bus, &dev, &func);
|
|
|
|
/*
|
|
* The interrupt lines of the internal Tulips are connected
|
|
* directly to the CPU.
|
|
*/
|
|
if (cobalt_id == COBALT_ID_QUBE2700) {
|
|
if (bus == 0 && dev == 7 && pin == PCI_INTERRUPT_PIN_A) {
|
|
/* tulip is connected to CPU INT2 on Qube2700 */
|
|
*ihp = NICU_INT + 2;
|
|
return 0;
|
|
}
|
|
} else {
|
|
if (bus == 0 && dev == 7 && pin == PCI_INTERRUPT_PIN_A) {
|
|
/* the primary tulip is connected to CPU INT1 */
|
|
*ihp = NICU_INT + 1;
|
|
return 0;
|
|
}
|
|
if (bus == 0 && dev == 12 && pin == PCI_INTERRUPT_PIN_A) {
|
|
/* the secondary tulip is connected to CPU INT2 */
|
|
*ihp = NICU_INT + 2;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
/* sanity check */
|
|
if (line == 0 || line >= NICU_INT)
|
|
return -1;
|
|
|
|
*ihp = line;
|
|
return 0;
|
|
}
|
|
|
|
const char *
|
|
pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih)
|
|
{
|
|
static char irqstr[8];
|
|
|
|
if (ih >= NICU_INT)
|
|
sprintf(irqstr, "level %d", ih - NICU_INT);
|
|
else
|
|
sprintf(irqstr, "irq %d", ih);
|
|
|
|
return irqstr;
|
|
}
|
|
|
|
const struct evcnt *
|
|
pci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih)
|
|
{
|
|
|
|
/* XXX for now, no evcnt parent reported */
|
|
return NULL;
|
|
}
|
|
|
|
int
|
|
pci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ih,
|
|
int attr, uint64_t data)
|
|
{
|
|
|
|
switch (attr) {
|
|
case PCI_INTR_MPSAFE:
|
|
return 0;
|
|
default:
|
|
return ENODEV;
|
|
}
|
|
}
|
|
|
|
void *
|
|
pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
|
|
int (*func)(void *), void *arg)
|
|
{
|
|
|
|
if (ih >= NICU_INT)
|
|
return cpu_intr_establish(ih - NICU_INT, level, func, arg);
|
|
else
|
|
return icu_intr_establish(ih, IST_LEVEL, level, func, arg);
|
|
}
|
|
|
|
void
|
|
pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
|
|
{
|
|
|
|
/* Try both, only the valid one will disestablish. */
|
|
cpu_intr_disestablish(cookie);
|
|
icu_intr_disestablish(cookie);
|
|
}
|
|
|
|
void
|
|
pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin, int swiz,
|
|
int *iline)
|
|
{
|
|
|
|
/*
|
|
* Use irq 9 on all devices on the Qube's PCI slot.
|
|
* XXX doesn't handle devices over PCI-PCI bridges
|
|
*/
|
|
if (bus == 0 && dev == 10 && pin != PCI_INTERRUPT_PIN_NONE)
|
|
*iline = 9;
|
|
}
|
|
|
|
int
|
|
pci_conf_hook(pci_chipset_tag_t pc, int bus, int dev, int func, pcireg_t id)
|
|
{
|
|
|
|
/* ignore bogus IDs */
|
|
if (PCI_VENDOR(id) == 0)
|
|
return 0;
|
|
|
|
/* 2700 hardware wedges on accesses to device 6. */
|
|
if (bus == 0 && dev == 6)
|
|
return 0;
|
|
|
|
/* 2800 hardware wedges on accesses to device 31. */
|
|
if (bus == 0 && dev == 31)
|
|
return 0;
|
|
|
|
/* Don't configure the bridge and PCI probe. */
|
|
if (PCI_VENDOR(id) == PCI_VENDOR_MARVELL &&
|
|
PCI_PRODUCT(id) == PCI_PRODUCT_MARVELL_GT64011)
|
|
return 0;
|
|
|
|
/* Don't configure on-board VIA VT82C586 (pcib, uhci) */
|
|
if (bus == 0 && dev == 9 && (func == 0 || func == 2))
|
|
return 0;
|
|
|
|
/* Enable viaide secondary port. Some firmware doesn't enable it. */
|
|
if (bus == 0 && dev == 9 && func == 1) {
|
|
pcitag_t tag;
|
|
pcireg_t csr;
|
|
|
|
#define APO_VIAIDECONF (APO_VIA_REGBASE + 0x00)
|
|
|
|
tag = pci_make_tag(pc, bus, dev, func);
|
|
csr = pci_conf_read(pc, tag, APO_VIAIDECONF);
|
|
pci_conf_write(pc, tag, APO_VIAIDECONF,
|
|
csr | APO_IDECONF_EN(1));
|
|
}
|
|
return PCI_CONF_DEFAULT & ~(PCI_COMMAND_SERR_ENABLE |
|
|
PCI_COMMAND_PARITY_ENABLE);
|
|
}
|