1999-12-16 01:25:21 +03:00
|
|
|
/* $NetBSD: pci_kn300.c,v 1.16 1999/12/15 22:25:21 thorpej 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 */
|
|
|
|
|
1999-12-16 01:25:21 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: pci_kn300.c,v 1.16 1999/12/15 22:25:21 thorpej 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 <vm/vm.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>
|
|
|
|
|
|
|
|
#ifndef EVCNT_COUNTERS
|
|
|
|
#include <machine/intrcnt.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "sio.h"
|
1999-12-16 01:25:21 +03:00
|
|
|
#if NSIO > 0 || NPCEB > 0
|
1998-04-15 04:50:14 +04:00
|
|
|
#include <alpha/pci/siovar.h>
|
|
|
|
#endif
|
|
|
|
|
1999-04-17 01:29:47 +04:00
|
|
|
int dec_kn300_intr_map __P((void *, pcitag_t, int, int,
|
|
|
|
pci_intr_handle_t *));
|
1998-04-15 04:50:14 +04:00
|
|
|
const char *dec_kn300_intr_string __P((void *, pci_intr_handle_t));
|
1999-04-17 01:29:47 +04:00
|
|
|
void *dec_kn300_intr_establish __P((void *, pci_intr_handle_t,
|
1998-04-15 04:50:14 +04:00
|
|
|
int, int (*func)(void *), void *));
|
|
|
|
void dec_kn300_intr_disestablish __P((void *, void *));
|
|
|
|
|
|
|
|
#define KN300_PCEB_IRQ 16
|
1998-04-30 08:31:19 +04:00
|
|
|
#define NPIN 4
|
1998-04-15 04:50:14 +04:00
|
|
|
|
1999-04-17 01:29:47 +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
|
|
|
|
1998-04-30 08:31:19 +04:00
|
|
|
static struct alpha_shared_intr *kn300_pci_intr;
|
|
|
|
|
1999-12-04 23:29:02 +03:00
|
|
|
static struct mcpcia_config *mcpcia_eisaccp = NULL;
|
|
|
|
|
1998-04-15 04:50:14 +04:00
|
|
|
#ifdef EVCNT_COUNTERS
|
|
|
|
struct evcnt kn300_intr_evcnt;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void kn300_iointr __P((void *, unsigned long));
|
|
|
|
void kn300_enable_intr __P((struct mcpcia_config *, int));
|
|
|
|
void kn300_disable_intr __P((struct mcpcia_config *, int));
|
|
|
|
|
|
|
|
void
|
|
|
|
pci_kn300_pickintr(ccp, first)
|
|
|
|
struct mcpcia_config *ccp;
|
|
|
|
int first;
|
|
|
|
{
|
|
|
|
pci_chipset_tag_t pc = &ccp->cc_pc;
|
|
|
|
|
|
|
|
if (first) {
|
|
|
|
int g;
|
1998-04-30 08:31:19 +04:00
|
|
|
|
1999-04-17 01:29:47 +04:00
|
|
|
kn300_pci_intr = alpha_shared_intr_alloc(NIRQ);
|
|
|
|
for (g = 0; g < NIRQ; g++) {
|
1998-04-30 08:31:19 +04:00
|
|
|
alpha_shared_intr_set_maxstrays(kn300_pci_intr, g, 25);
|
|
|
|
savirqs[g] = (char) -1;
|
1998-04-15 04:50:14 +04:00
|
|
|
}
|
|
|
|
set_iointr(kn300_iointr);
|
|
|
|
}
|
|
|
|
|
|
|
|
pc->pc_intr_v = ccp;
|
|
|
|
pc->pc_intr_map = dec_kn300_intr_map;
|
|
|
|
pc->pc_intr_string = dec_kn300_intr_string;
|
|
|
|
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. */
|
1998-04-18 05:12:23 +04:00
|
|
|
pc->pc_pciide_compat_intr_establish = NULL;
|
|
|
|
|
1999-04-16 02:37:25 +04:00
|
|
|
if (EISA_PRESENT(REGVAL(MCPCIA_PCI_REV(ccp)))) {
|
1999-12-04 23:29:02 +03:00
|
|
|
mcpcia_eisaccp = ccp;
|
1999-12-16 01:25:21 +03:00
|
|
|
#if NSIO > 0 || NPCEB > 0
|
1999-04-16 02:37:25 +04:00
|
|
|
sio_intr_setup(pc, &ccp->cc_iot);
|
1998-04-15 04:50:14 +04:00
|
|
|
kn300_enable_intr(ccp, KN300_PCEB_IRQ);
|
|
|
|
#endif
|
1999-12-04 23:29:02 +03:00
|
|
|
}
|
1998-04-15 04:50:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dec_kn300_intr_map(ccv, bustag, buspin, line, ihp)
|
1999-12-16 01:21:45 +03:00
|
|
|
void *ccv;
|
|
|
|
pcitag_t bustag;
|
|
|
|
int buspin, line;
|
|
|
|
pci_intr_handle_t *ihp;
|
1998-04-15 04:50:14 +04:00
|
|
|
{
|
|
|
|
struct mcpcia_config *ccp = ccv;
|
|
|
|
pci_chipset_tag_t pc = &ccp->cc_pc;
|
|
|
|
int device;
|
1999-04-17 01:29:47 +04:00
|
|
|
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
|
|
|
|
|
|
|
alpha_pci_decompose_tag(pc, bustag, NULL, &device, NULL);
|
|
|
|
|
1999-04-16 02:37:25 +04:00
|
|
|
/*
|
|
|
|
* On MID 5 device 1 is the internal NCR 53c810.
|
|
|
|
*/
|
|
|
|
if (ccp->cc_mid == 5 && device == 1) {
|
1999-04-17 01:29:47 +04:00
|
|
|
mcpcia_irq = 16;
|
1998-04-15 04:50:14 +04:00
|
|
|
} else if (device >= 2 && device <= 5) {
|
1999-04-17 01:29:47 +04:00
|
|
|
mcpcia_irq = (device - 2) * 4;
|
1998-04-15 04:50:14 +04:00
|
|
|
} else {
|
1999-12-16 01:21:45 +03:00
|
|
|
printf("dec_kn300_intr_map: weird device number %d\n", device);
|
|
|
|
return(1);
|
1998-04-15 04:50:14 +04:00
|
|
|
}
|
1999-04-16 02:37:25 +04:00
|
|
|
|
1998-04-15 04:50:14 +04:00
|
|
|
/*
|
|
|
|
* handle layout:
|
|
|
|
*
|
1999-12-16 01:21:45 +03:00
|
|
|
* Determine kn300 IRQ (encoded in SCB vector):
|
1998-04-30 08:31:19 +04:00
|
|
|
* 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
|
1999-04-17 01:29:47 +04:00
|
|
|
*
|
|
|
|
* Software only:
|
|
|
|
* bits 11-15 MCPCIA IRQ
|
1998-04-15 04:50:14 +04:00
|
|
|
*/
|
|
|
|
*ihp = (pci_intr_handle_t)
|
1998-04-30 08:31:19 +04:00
|
|
|
(buspin - 1 ) |
|
|
|
|
((device & 0x7) << 2) |
|
1999-04-16 02:37:25 +04:00
|
|
|
((ccp->cc_mid - 4) << 5) |
|
|
|
|
((7 - ccp->cc_gid) << 8) |
|
1999-12-16 01:21:45 +03:00
|
|
|
(mcpcia_irq << 11);
|
1998-04-15 04:50:14 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
dec_kn300_intr_string(ccv, ih)
|
|
|
|
void *ccv;
|
|
|
|
pci_intr_handle_t ih;
|
|
|
|
{
|
1999-12-16 01:21:45 +03:00
|
|
|
static char irqstr[64];
|
1999-04-17 01:29:47 +04:00
|
|
|
|
|
|
|
sprintf(irqstr, "kn300 irq %ld", ih & 0x3ff);
|
1998-04-15 04:50:14 +04:00
|
|
|
return (irqstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
dec_kn300_intr_establish(ccv, ih, level, func, arg)
|
|
|
|
void *ccv;
|
|
|
|
pci_intr_handle_t ih;
|
|
|
|
int level;
|
|
|
|
int (*func) __P((void *));
|
|
|
|
void *arg;
|
|
|
|
{
|
1999-12-16 01:21:45 +03:00
|
|
|
struct mcpcia_config *ccp = ccv;
|
1998-04-30 08:31:19 +04:00
|
|
|
void *cookie;
|
1999-04-17 01:29:47 +04:00
|
|
|
int irq;
|
1998-04-30 08:31:19 +04:00
|
|
|
|
1999-04-17 01:29:47 +04:00
|
|
|
irq = ih & 0x3ff;
|
|
|
|
cookie = alpha_shared_intr_establish(kn300_pci_intr, irq, IST_LEVEL,
|
|
|
|
level, func, arg, "kn300 irq");
|
1998-04-30 08:31:19 +04:00
|
|
|
|
1999-04-17 01:29:47 +04:00
|
|
|
if (cookie != NULL && alpha_shared_intr_isactive(kn300_pci_intr, irq)) {
|
1999-12-16 01:21:45 +03:00
|
|
|
alpha_shared_intr_set_private(kn300_pci_intr, irq, ccp);
|
1999-04-17 01:29:47 +04:00
|
|
|
savirqs[irq] = (ih >> 11) & 0x1f;
|
1999-12-16 01:21:45 +03:00
|
|
|
kn300_enable_intr(ccp, savirqs[irq]);
|
1998-04-30 08:31:19 +04:00
|
|
|
alpha_mb();
|
1998-04-15 04:50:14 +04:00
|
|
|
}
|
|
|
|
return (cookie);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dec_kn300_intr_disestablish(ccv, cookie)
|
1999-12-16 01:21:45 +03:00
|
|
|
void *ccv, *cookie;
|
1998-04-15 04:50:14 +04:00
|
|
|
{
|
1999-12-16 01:21:45 +03:00
|
|
|
|
1998-04-30 08:31:19 +04:00
|
|
|
panic("dec_kn300_intr_disestablish not implemented");
|
1998-04-15 04:50:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
kn300_iointr(framep, vec)
|
|
|
|
void *framep;
|
|
|
|
unsigned long vec;
|
|
|
|
{
|
1998-04-30 08:31:19 +04:00
|
|
|
struct mcpcia_softc *mcp;
|
1999-04-17 01:29:47 +04:00
|
|
|
u_long irq;
|
1998-04-15 04:50:14 +04:00
|
|
|
|
|
|
|
if (vec >= MCPCIA_VEC_EISA && vec < MCPCIA_VEC_PCI) {
|
1999-12-16 01:25:21 +03:00
|
|
|
#if NSIO > 0 || NPCEB > 0
|
1998-04-15 04:50:14 +04:00
|
|
|
sio_iointr(framep, vec);
|
|
|
|
return;
|
|
|
|
#else
|
1999-12-16 01:21:45 +03:00
|
|
|
static const char *plaint = "kn300_iointr: (E)ISA interrupt "
|
|
|
|
"support not configured for vector 0x%x";
|
1999-12-04 23:29:02 +03:00
|
|
|
if (mcpcia_eisaccp) {
|
|
|
|
kn300_disable_intr(mcpcia_eisaccp, KN300_PCEB_IRQ);
|
|
|
|
printf(plaint, vec);
|
|
|
|
} else {
|
|
|
|
panic(plaint, vec);
|
|
|
|
}
|
1998-04-15 04:50:14 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef EVCNT_COUNTERS
|
|
|
|
kn300_intr_evcnt.ev_count++;
|
|
|
|
#endif
|
1999-04-17 01:29:47 +04:00
|
|
|
|
|
|
|
irq = (vec - MCPCIA_VEC_PCI) >> 4;
|
|
|
|
|
1998-04-15 04:50:14 +04:00
|
|
|
/*
|
1999-04-17 01:29:47 +04:00
|
|
|
* Check for I2C interrupts. These are technically within
|
|
|
|
* the PCI vector range, but no PCI device should ever map
|
|
|
|
* to them.
|
1998-04-15 04:50:14 +04:00
|
|
|
*/
|
1999-04-17 01:29:47 +04:00
|
|
|
if (vec == MCPCIA_I2C_CVEC) {
|
1998-04-15 04:50:14 +04:00
|
|
|
#ifndef EVCNT_COUNTERS
|
|
|
|
intrcnt[INTRCNT_KN300_I2C_CTRL]++;
|
|
|
|
#endif
|
|
|
|
printf("i2c: controller interrupt\n");
|
|
|
|
return;
|
|
|
|
}
|
1999-04-17 01:29:47 +04:00
|
|
|
if (vec == MCPCIA_I2C_BVEC) {
|
1998-04-15 04:50:14 +04:00
|
|
|
#ifndef EVCNT_COUNTERS
|
|
|
|
intrcnt[INTRCNT_KN300_I2C_BUS]++;
|
|
|
|
#endif
|
|
|
|
printf("i2c: bus interrupt\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef EVCNT_COUNTERS
|
1999-04-17 01:29:47 +04:00
|
|
|
if (savirqs[irq] >= 0 && savirqs[irq] <= INTRCNT_KN300_NCR810) {
|
|
|
|
intrcnt[INTRCNT_KN300_IRQ + savirqs[irq]]++;
|
1998-04-15 04:50:14 +04:00
|
|
|
}
|
|
|
|
#endif
|
1998-04-30 08:31:19 +04:00
|
|
|
|
1999-04-17 01:29:47 +04:00
|
|
|
if (alpha_shared_intr_dispatch(kn300_pci_intr, irq))
|
1998-04-30 08:31:19 +04:00
|
|
|
return;
|
1999-04-16 02:37:25 +04:00
|
|
|
|
1998-04-30 08:31:19 +04:00
|
|
|
/*
|
1999-04-16 02:37:25 +04:00
|
|
|
* Stray interrupt; disable the IRQ on the appropriate MCPCIA
|
|
|
|
* if we've reached the limit.
|
1998-04-30 08:31:19 +04:00
|
|
|
*/
|
1999-12-15 23:10:04 +03:00
|
|
|
alpha_shared_intr_stray(kn300_pci_intr, irq, "kn300 irq");
|
1999-04-17 01:29:47 +04:00
|
|
|
if (ALPHA_SHARED_INTR_DISABLE(kn300_pci_intr, irq) == 0)
|
1998-04-30 08:31:19 +04:00
|
|
|
return;
|
1999-04-16 02:37:25 +04:00
|
|
|
|
1999-12-16 01:21:45 +03:00
|
|
|
mcp = alpha_shared_intr_get_private(kn300_pci_intr, irq);
|
1999-04-17 01:29:47 +04:00
|
|
|
kn300_disable_intr(mcp->mcpcia_cc, savirqs[irq]);
|
1998-04-15 04:50:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
kn300_enable_intr(ccp, irq)
|
|
|
|
struct mcpcia_config *ccp;
|
|
|
|
int irq;
|
|
|
|
{
|
|
|
|
alpha_mb();
|
1999-04-16 02:37:25 +04:00
|
|
|
REGVAL(MCPCIA_INT_MASK0(ccp)) |= (1 << irq);
|
1998-04-15 04:50:14 +04:00
|
|
|
alpha_mb();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
kn300_disable_intr(ccp, irq)
|
|
|
|
struct mcpcia_config *ccp;
|
|
|
|
int irq;
|
|
|
|
{
|
|
|
|
alpha_mb();
|
1999-04-16 02:37:25 +04:00
|
|
|
REGVAL(MCPCIA_INT_MASK0(ccp)) &= ~(1 << irq);
|
1998-04-15 04:50:14 +04:00
|
|
|
alpha_mb();
|
|
|
|
}
|