NetBSD/sys/arch/alpha/pci/pci_kn300.c

288 lines
7.8 KiB
C
Raw Normal View History

/* $NetBSD: pci_kn300.c,v 1.36 2014/03/21 16:39:29 christos Exp $ */
1998-04-15 04:50:14 +04:00
/*
* Copyright (c) 1998 by Matthew Jacob
* NASA AMES Research Center.
* 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 immediately at the beginning of the file, without modification,
* 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 author 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 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> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: pci_kn300.c,v 1.36 2014/03/21 16:39:29 christos Exp $");
1998-04-15 04:50:14 +04:00
#include <sys/types.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/malloc.h>
#include <sys/device.h>
#include <sys/syslog.h>
#include <machine/autoconf.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <alpha/mcbus/mcbusvar.h>
#include <alpha/mcbus/mcbusreg.h>
#include <alpha/pci/mcpciareg.h>
#include <alpha/pci/mcpciavar.h>
#include <alpha/pci/pci_kn300.h>
#include "sio.h"
#if NSIO > 0 || NPCEB > 0
1998-04-15 04:50:14 +04:00
#include <alpha/pci/siovar.h>
#endif
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-05 00:37:44 +04:00
int dec_kn300_intr_map(const struct pci_attach_args *,
pci_intr_handle_t *);
const char *dec_kn300_intr_string(void *, pci_intr_handle_t, char *, size_t);
const struct evcnt *dec_kn300_intr_evcnt(void *, pci_intr_handle_t);
void *dec_kn300_intr_establish(void *, pci_intr_handle_t,
int, int (*func)(void *), void *);
void dec_kn300_intr_disestablish(void *, void *);
1998-04-15 04:50:14 +04:00
#define KN300_PCEB_IRQ 16
#define NPIN 4
1998-04-15 04:50:14 +04:00
#define NIRQ (MAX_MC_BUS * MCPCIA_PER_MCBUS * MCPCIA_MAXSLOT * NPIN)
static int savirqs[NIRQ];
1998-04-15 04:50:14 +04:00
static struct alpha_shared_intr *kn300_pci_intr;
static struct mcpcia_config *mcpcia_eisaccp = NULL;
void kn300_iointr(void *, unsigned long);
void kn300_enable_intr(struct mcpcia_config *, int);
void kn300_disable_intr(struct mcpcia_config *, int);
1998-04-15 04:50:14 +04:00
void
pci_kn300_pickintr(struct mcpcia_config *ccp, int first)
1998-04-15 04:50:14 +04:00
{
char *cp;
1998-04-15 04:50:14 +04:00
pci_chipset_tag_t pc = &ccp->cc_pc;
if (first) {
int g;
#define PCI_KN300_IRQ_STR 16
kn300_pci_intr = alpha_shared_intr_alloc(NIRQ,
PCI_KN300_IRQ_STR);
for (g = 0; g < NIRQ; g++) {
alpha_shared_intr_set_maxstrays(kn300_pci_intr, g, 25);
cp = alpha_shared_intr_string(kn300_pci_intr, g);
snprintf(cp, PCI_KN300_IRQ_STR, "irq %d", g);
evcnt_attach_dynamic(alpha_shared_intr_evcnt(
kn300_pci_intr, g), EVCNT_TYPE_INTR, NULL,
"kn300", cp);
savirqs[g] = (char) -1;
1998-04-15 04:50:14 +04:00
}
}
pc->pc_intr_v = ccp;
pc->pc_intr_map = dec_kn300_intr_map;
pc->pc_intr_string = dec_kn300_intr_string;
pc->pc_intr_evcnt = dec_kn300_intr_evcnt;
1998-04-15 04:50:14 +04:00
pc->pc_intr_establish = dec_kn300_intr_establish;
pc->pc_intr_disestablish = dec_kn300_intr_disestablish;
1998-04-24 05:25:18 +04:00
/* Not supported on KN300. */
pc->pc_pciide_compat_intr_establish = NULL;
if (EISA_PRESENT(REGVAL(MCPCIA_PCI_REV(ccp)))) {
mcpcia_eisaccp = ccp;
#if NSIO > 0 || NPCEB > 0
sio_intr_setup(pc, &ccp->cc_iot);
1998-04-15 04:50:14 +04:00
kn300_enable_intr(ccp, KN300_PCEB_IRQ);
#endif
}
1998-04-15 04:50:14 +04:00
}
int
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-05 00:37:44 +04:00
dec_kn300_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
1998-04-15 04:50:14 +04:00
{
pcitag_t bustag = pa->pa_intrtag;
int buspin = pa->pa_intrpin;
pci_chipset_tag_t pc = pa->pa_pc;
struct mcpcia_config *ccp = (struct mcpcia_config *)pc->pc_intr_v;
1998-04-15 04:50:14 +04:00
int device;
int mcpcia_irq;
1998-04-15 04:50:14 +04:00
1998-04-25 04:12:44 +04:00
if (buspin == 0) {
/* No IRQ used. */
return 1;
}
if (buspin > 4 || buspin < 0) {
printf("dec_kn300_intr_map: bad interrupt pin %d\n", buspin);
return 1;
}
1998-04-15 04:50:14 +04:00
pci_decompose_tag(pc, bustag, NULL, &device, NULL);
1998-04-15 04:50:14 +04:00
/*
* On MID 5 device 1 is the internal NCR 53c810.
*/
if (ccp->cc_mid == 5 && device == 1) {
mcpcia_irq = 16;
1998-04-15 04:50:14 +04:00
} else if (device >= 2 && device <= 5) {
2004-07-06 17:36:19 +04:00
mcpcia_irq = (device - 2) * 4 + buspin - 1;
1998-04-15 04:50:14 +04:00
} else {
printf("dec_kn300_intr_map: weird device number %d\n", device);
return(1);
1998-04-15 04:50:14 +04:00
}
1998-04-15 04:50:14 +04:00
/*
* handle layout:
*
* Determine kn300 IRQ (encoded in SCB vector):
* bits 0..1 buspin-1
* bits 2..4 PCI Slot (0..7- yes, some don't exist)
* bits 5..7 MID-4
* bits 8..10 7-GID
*
* Software only:
* bits 11-15 MCPCIA IRQ
1998-04-15 04:50:14 +04:00
*/
*ihp = (pci_intr_handle_t)
(buspin - 1 ) |
((device & 0x7) << 2) |
((ccp->cc_mid - 4) << 5) |
((7 - ccp->cc_gid) << 8) |
(mcpcia_irq << 11);
1998-04-15 04:50:14 +04:00
return (0);
}
const char *
dec_kn300_intr_string(void *ccv, pci_intr_handle_t ih, char *buf, size_t len)
1998-04-15 04:50:14 +04:00
{
snprintf(buf, len, "kn300 irq %ld", ih & 0x3ff);
return buf;
1998-04-15 04:50:14 +04:00
}
const struct evcnt *
dec_kn300_intr_evcnt(void *ccv, pci_intr_handle_t ih)
{
return (alpha_shared_intr_evcnt(kn300_pci_intr, ih & 0x3ff));
}
1998-04-15 04:50:14 +04:00
void *
dec_kn300_intr_establish(
void *ccv,
pci_intr_handle_t ih,
int level,
int (*func)(void *),
void *arg)
{
struct mcpcia_config *ccp = ccv;
void *cookie;
int irq;
irq = ih & 0x3ff;
cookie = alpha_shared_intr_establish(kn300_pci_intr, irq, IST_LEVEL,
level, func, arg, "kn300 irq");
if (cookie != NULL &&
alpha_shared_intr_firstactive(kn300_pci_intr, irq)) {
scb_set(MCPCIA_VEC_PCI + SCB_IDXTOVEC(irq),
kn300_iointr, NULL, level);
alpha_shared_intr_set_private(kn300_pci_intr, irq, ccp);
savirqs[irq] = (ih >> 11) & 0x1f;
kn300_enable_intr(ccp, savirqs[irq]);
alpha_mb();
1998-04-15 04:50:14 +04:00
}
return (cookie);
}
void
dec_kn300_intr_disestablish(void *ccv, void *cookie)
1998-04-15 04:50:14 +04:00
{
panic("dec_kn300_intr_disestablish not implemented");
1998-04-15 04:50:14 +04:00
}
void
kn300_iointr(void *arg, unsigned long vec)
1998-04-15 04:50:14 +04:00
{
struct mcpcia_softc *mcp;
u_long irq;
1998-04-15 04:50:14 +04:00
irq = SCB_VECTOIDX(vec - MCPCIA_VEC_PCI);
1998-04-15 04:50:14 +04:00
if (alpha_shared_intr_dispatch(kn300_pci_intr, irq)) {
/*
* Any claim of an interrupt at this level is a hint to
* reset the stray interrupt count- elsewise a slow leak
* over time will cause this level to be shutdown.
*/
alpha_shared_intr_reset_strays(kn300_pci_intr, irq);
return;
}
/*
* If we haven't finished configuring yet, or there is no mcp
* registered for this level yet, just return.
*/
mcp = alpha_shared_intr_get_private(kn300_pci_intr, irq);
if (mcp == NULL || mcp->mcpcia_cc == NULL)
return;
/*
* We're getting an interrupt for a device we haven't enabled.
* We had better not try and use -1 to find the right bit to disable.
*/
if (savirqs[irq] == -1) {
printf("kn300_iointr: stray interrupt vector 0x%lx\n", vec);
return;
}
/*
* Stray interrupt; disable the IRQ on the appropriate MCPCIA
* if we've reached the limit.
*/
alpha_shared_intr_stray(kn300_pci_intr, irq, "kn300 irq");
if (ALPHA_SHARED_INTR_DISABLE(kn300_pci_intr, irq) == 0)
return;
kn300_disable_intr(mcp->mcpcia_cc, savirqs[irq]);
1998-04-15 04:50:14 +04:00
}
void
kn300_enable_intr(struct mcpcia_config *ccp, int irq)
1998-04-15 04:50:14 +04:00
{
alpha_mb();
REGVAL(MCPCIA_INT_MASK0(ccp)) |= (1 << irq);
1998-04-15 04:50:14 +04:00
alpha_mb();
}
void
kn300_disable_intr(struct mcpcia_config *ccp, int irq)
1998-04-15 04:50:14 +04:00
{
alpha_mb();
REGVAL(MCPCIA_INT_MASK0(ccp)) &= ~(1 << irq);
1998-04-15 04:50:14 +04:00
alpha_mb();
}