NetBSD/sys/arch/evbarm/ifpga/ifpga_pci.c
dyoung a184f1f486 Neither pci_dma64_available(), pci_probe_device(), pci_mapreg_map(9),
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'
2011-04-04 20:37:44 +00:00

376 lines
11 KiB
C

/* $NetBSD: ifpga_pci.c,v 1.14 2011/04/04 20:37:48 dyoung Exp $ */
/*
* Copyright (c) 2001 ARM Ltd
* 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.
* 3. The name of the company may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
*
* Copyright (c) 1997,1998 Mark Brinicombe.
* Copyright (c) 1997,1998 Causality Limited
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Mark Brinicombe
* for the NetBSD Project.
* 4. The name of the company nor the name of the author may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
*/
#define _ARM32_BUS_DMA_PRIVATE
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ifpga_pci.c,v 1.14 2011/04/04 20:37:48 dyoung Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/malloc.h>
#include <sys/device.h>
#include <evbarm/integrator/int_bus_dma.h>
#include <machine/intr.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <evbarm/ifpga/ifpgareg.h>
#include <evbarm/ifpga/ifpgamem.h>
#include <evbarm/ifpga/ifpga_pcivar.h>
#include <evbarm/dev/v360reg.h>
void ifpga_pci_attach_hook (device_t, device_t,
struct pcibus_attach_args *);
int ifpga_pci_bus_maxdevs (void *, int);
pcitag_t ifpga_pci_make_tag (void *, int, int, int);
void ifpga_pci_decompose_tag (void *, pcitag_t, int *, int *,
int *);
pcireg_t ifpga_pci_conf_read (void *, pcitag_t, int);
void ifpga_pci_conf_write (void *, pcitag_t, int, pcireg_t);
int ifpga_pci_intr_map (const struct pci_attach_args *,
pci_intr_handle_t *);
const char *ifpga_pci_intr_string (void *, pci_intr_handle_t);
const struct evcnt *ifpga_pci_intr_evcnt (void *, pci_intr_handle_t);
void *ifpga_pci_intr_establish (void *, pci_intr_handle_t, int,
int (*)(void *), void *);
void ifpga_pci_intr_disestablish (void *, void *);
struct arm32_pci_chipset ifpga_pci_chipset = {
NULL, /* conf_v */
ifpga_pci_attach_hook,
ifpga_pci_bus_maxdevs,
ifpga_pci_make_tag,
ifpga_pci_decompose_tag,
ifpga_pci_conf_read,
ifpga_pci_conf_write,
NULL, /* intr_v */
ifpga_pci_intr_map,
ifpga_pci_intr_string,
ifpga_pci_intr_evcnt,
ifpga_pci_intr_establish,
ifpga_pci_intr_disestablish
};
/*
* Use the integrator-specific bus_dma routines.
*/
struct arm32_bus_dma_tag ifpga_pci_bus_dma_tag = {
0,
0,
NULL,
_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, /* pre */
NULL, /* post */
_bus_dmamem_alloc,
_bus_dmamem_free,
_bus_dmamem_map,
_bus_dmamem_unmap,
_bus_dmamem_mmap,
};
/*
* Currently we only support 12 devices as we select directly in the
* type 0 config cycle
* (See conf_{read,write} for more detail
*/
#define MAX_PCI_DEVICES 21
/*static int
pci_intr(void *arg)
{
printf("pci int %x\n", (int)arg);
return 0;
}*/
void
ifpga_pci_attach_hook(device_t parent, device_t self,
struct pcibus_attach_args *pba)
{
#ifdef PCI_DEBUG
printf("ifpga_pci_attach_hook()\n");
#endif
}
int
ifpga_pci_bus_maxdevs(void *pcv, int busno)
{
#ifdef PCI_DEBUG
printf("ifpga_pci_bus_maxdevs(pcv=%p, busno=%d)\n", pcv, busno);
#endif
return MAX_PCI_DEVICES;
}
pcitag_t
ifpga_pci_make_tag(void *pcv, int bus, int device, int function)
{
#ifdef PCI_DEBUG
printf("ifpga_pci_make_tag(pcv=%p, bus=%d, device=%d, function=%d)\n",
pcv, bus, device, function);
#endif
return (bus << 16) | (device << 11) | (function << 8);
}
void
ifpga_pci_decompose_tag(void *pcv, pcitag_t tag, int *busp, int *devicep,
int *functionp)
{
#ifdef PCI_DEBUG
printf("ifpga_pci_decompose_tag(pcv=%p, tag=0x%08lx, bp=%p, dp=%p, "
"fp=%p)\n", pcv, tag, busp, devicep, functionp);
#endif
if (busp != NULL)
*busp = (tag >> 16) & 0xff;
if (devicep != NULL)
*devicep = (tag >> 11) & 0x1f;
if (functionp != NULL)
*functionp = (tag >> 8) & 0x7;
}
pcireg_t
ifpga_pci_conf_read(void *pcv, pcitag_t tag, int reg)
{
pcireg_t data;
struct ifpga_pci_softc *sc = (struct ifpga_pci_softc *)pcv;
int bus, device, function;
u_int address;
ifpga_pci_decompose_tag(pcv, tag, &bus, &device, &function);
/* Reset the appertures so that we can talk to the register space. */
bus_space_write_4(sc->sc_memt, sc->sc_reg_ioh, V360_LB_BASE0,
IFPGA_PCI_APP0_512MB_BASE);
bus_space_write_4(sc->sc_memt, sc->sc_reg_ioh, V360_LB_BASE1,
IFPGA_PCI_APP1_CONF_BASE);
if (bus == 0) {
address = (1 << (device + 11)) | reg;
bus_space_write_2(sc->sc_memt, sc->sc_reg_ioh, V360_LB_MAP1,
IFPGA_PCI_APP1_CONF_T0_MAP | ((address >> 16) & 0xff00));
/* Read the value from the bus... */
data = bus_space_read_4(sc->sc_iot, sc->sc_conf_ioh,
address & 0x00ffffff);
} else {
bus_space_write_2(sc->sc_memt, sc->sc_reg_ioh, V360_LB_MAP1,
IFPGA_PCI_APP1_CONF_T1_MAP);
/* Read the value from the bus... */
data = bus_space_read_4(sc->sc_iot, sc->sc_conf_ioh,
tag | reg);
}
/* ... and put the memory spaces back again. */
bus_space_write_4(sc->sc_memt, sc->sc_reg_ioh, V360_LB_BASE1,
IFPGA_PCI_APP1_256MB_BASE);
bus_space_write_2(sc->sc_memt, sc->sc_reg_ioh, V360_LB_MAP1,
IFPGA_PCI_APP1_256MB_MAP);
bus_space_write_4(sc->sc_memt, sc->sc_reg_ioh, V360_LB_BASE0,
IFPGA_PCI_APP0_256MB_BASE);
#ifdef PCI_DEBUG
printf("ifpga_pci_conf_read(pcv=%p tag=0x%08lx reg=0x%02x)=0x%08x\n",
pcv, tag, reg, data);
#endif
return data;
}
void
ifpga_pci_conf_write(void *pcv, pcitag_t tag, int reg, pcireg_t data)
{
struct ifpga_pci_softc *sc = (struct ifpga_pci_softc *)pcv;
int bus, device, function;
u_int address;
#ifdef PCI_DEBUG
printf("ifpga_pci_conf_write(pcv=%p tag=0x%08lx reg=0x%02x, 0x%08x)\n",
pcv, tag, reg, data);
#endif
ifpga_pci_decompose_tag(pcv, tag, &bus, &device, &function);
/* Reset the appertures so that we can talk to the register space. */
bus_space_write_4(sc->sc_memt, sc->sc_reg_ioh, V360_LB_BASE0,
IFPGA_PCI_APP0_512MB_BASE);
bus_space_write_4(sc->sc_memt, sc->sc_reg_ioh, V360_LB_BASE1,
IFPGA_PCI_APP1_CONF_BASE);
if (bus == 0) {
address = (1 << (device + 11)) | reg;
bus_space_write_2(sc->sc_memt, sc->sc_reg_ioh, V360_LB_MAP1,
IFPGA_PCI_APP1_CONF_T0_MAP | ((address >> 16) & 0xff00));
/* Write the value to the bus... */
bus_space_write_4(sc->sc_iot, sc->sc_conf_ioh,
address & 0x00ffffff, data);
} else {
bus_space_write_2(sc->sc_memt, sc->sc_reg_ioh, V360_LB_MAP1,
IFPGA_PCI_APP1_CONF_T1_MAP);
/* Write the value to the bus... */
bus_space_write_4(sc->sc_iot, sc->sc_conf_ioh, tag | reg,
data);
}
/* ... and put the memory spaces back again. */
bus_space_write_4(sc->sc_memt, sc->sc_reg_ioh, V360_LB_BASE1,
IFPGA_PCI_APP1_256MB_BASE);
bus_space_write_2(sc->sc_memt, sc->sc_reg_ioh, V360_LB_MAP1,
IFPGA_PCI_APP1_256MB_MAP);
bus_space_write_4(sc->sc_memt, sc->sc_reg_ioh, V360_LB_BASE0,
IFPGA_PCI_APP0_256MB_BASE);
}
int
ifpga_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
{
int line = pa->pa_intrline;
#ifdef PCI_DEBUG
int pin = pa->pa_intrpin;
void *pcv = pa->pa_pc;
pcitag_t intrtag = pa->pa_intrtag;
int bus, device, function;
ifpga_pci_decompose_tag(pcv, intrtag, &bus, &device, &function);
printf("ifpga_pci_intr_map: pcv=%p, tag=%08lx pin=%d line=%d "
"dev=%d\n", pcv, intrtag, pin, line, device);
#endif
#ifdef PCI_DEBUG
printf("pin %d, line %d mapped to int %d\n", pin, line, line);
#endif
*ihp = line;
return 0;
}
const char *
ifpga_pci_intr_string(void *pcv, pci_intr_handle_t ih)
{
static char irqstr[12]; /* 6 + 1 + NULL + sanity */
#ifdef PCI_DEBUG
printf("ifpga_pci_intr_string(pcv=%p, ih=0x%lx)\n", pcv, ih);
#endif
if (ih == 0)
panic("ifpga_pci_intr_string: bogus handle 0x%lx", ih);
sprintf(irqstr, "pciint%ld", ih - IFPGA_INTRNUM_PCIINT0);
return irqstr;
}
const struct evcnt *
ifpga_pci_intr_evcnt(void *pcv, pci_intr_handle_t ih)
{
/* XXX for now, no evcnt parent reported */
return NULL;
}
void *
ifpga_pci_intr_establish(void *pcv, pci_intr_handle_t ih, int level,
int (*func) (void *), void *arg)
{
void *intr;
int length;
#ifdef PCI_DEBUG
printf("ifpga_pci_intr_establish(pcv=%p, ih=0x%lx, level=%d, "
"func=%p, arg=%p)\n", pcv, ih, level, func, arg);
#endif
/* Copy the interrupt string to a private buffer */
length = strlen(ifpga_pci_intr_string(pcv, ih));
intr = ifpga_intr_establish(ih, level, func, arg);
return intr;
}
void
ifpga_pci_intr_disestablish(void *pcv, void *cookie)
{
#ifdef PCI_DEBUG
printf("ifpga_pci_intr_disestablish(pcv=%p, cookie=%p)\n",
pcv, cookie);
#endif
/* XXXX Need to free the string */
ifpga_intr_disestablish(cookie);
}