2000-12-29 01:59:06 +03:00
|
|
|
/* $NetBSD: pci_kn20aa.c,v 1.41 2000/12/28 22:59:07 sommerfeld Exp $ */
|
1995-11-23 05:33:17 +03:00
|
|
|
|
|
|
|
/*
|
1996-06-13 22:31:49 +04:00
|
|
|
* Copyright (c) 1995, 1996 Carnegie-Mellon University.
|
1995-11-23 05:33:17 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: Chris G. Demetriou
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute this software and
|
|
|
|
* its documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
|
|
|
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
|
1997-04-08 03:39:37 +04:00
|
|
|
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
|
|
|
|
|
2000-12-29 01:59:06 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: pci_kn20aa.c,v 1.41 2000/12/28 22:59:07 sommerfeld Exp $");
|
1997-04-07 06:01:16 +04:00
|
|
|
|
1995-11-23 05:33:17 +03: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>
|
|
|
|
|
2000-06-29 12:58:45 +04:00
|
|
|
#include <uvm/uvm_extern.h>
|
1995-11-23 05:33:17 +03:00
|
|
|
|
1996-07-14 08:08:56 +04:00
|
|
|
#include <machine/autoconf.h>
|
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
|
|
|
|
#include <alpha/pci/ciareg.h>
|
|
|
|
#include <alpha/pci/ciavar.h>
|
|
|
|
|
|
|
|
#include <alpha/pci/pci_kn20aa.h>
|
|
|
|
|
|
|
|
#include "sio.h"
|
1999-12-16 01:28:15 +03:00
|
|
|
#if NSIO > 0 || NPCEB > 0
|
1995-11-23 05:33:17 +03:00
|
|
|
#include <alpha/pci/siovar.h>
|
|
|
|
#endif
|
|
|
|
|
2000-12-29 01:59:06 +03:00
|
|
|
int dec_kn20aa_intr_map __P((struct pci_attach_args *,
|
1996-04-13 04:24:30 +04:00
|
|
|
pci_intr_handle_t *));
|
|
|
|
const char *dec_kn20aa_intr_string __P((void *, pci_intr_handle_t));
|
2000-06-04 23:14:14 +04:00
|
|
|
const struct evcnt *dec_kn20aa_intr_evcnt __P((void *, pci_intr_handle_t));
|
1996-04-13 04:24:30 +04:00
|
|
|
void *dec_kn20aa_intr_establish __P((void *, pci_intr_handle_t,
|
|
|
|
int, int (*func)(void *), void *));
|
|
|
|
void dec_kn20aa_intr_disestablish __P((void *, void *));
|
1995-11-23 05:33:17 +03:00
|
|
|
|
|
|
|
#define KN20AA_PCEB_IRQ 31
|
|
|
|
#define KN20AA_MAX_IRQ 32
|
|
|
|
#define PCI_STRAY_MAX 5
|
|
|
|
|
1996-11-17 05:05:26 +03:00
|
|
|
struct alpha_shared_intr *kn20aa_pci_intr;
|
1995-11-23 05:33:17 +03:00
|
|
|
|
1996-07-14 08:08:56 +04:00
|
|
|
void kn20aa_iointr __P((void *framep, unsigned long vec));
|
1995-11-23 05:33:17 +03:00
|
|
|
void kn20aa_enable_intr __P((int irq));
|
1996-08-16 02:17:44 +04:00
|
|
|
void kn20aa_disable_intr __P((int irq));
|
1995-11-23 05:33:17 +03:00
|
|
|
|
|
|
|
void
|
1996-04-13 04:24:30 +04:00
|
|
|
pci_kn20aa_pickintr(ccp)
|
|
|
|
struct cia_config *ccp;
|
1995-11-23 05:33:17 +03:00
|
|
|
{
|
|
|
|
int i;
|
1999-12-16 01:28:15 +03:00
|
|
|
#if NSIO > 0 || NPCEB > 0
|
1997-09-03 00:10:28 +04:00
|
|
|
bus_space_tag_t iot = &ccp->cc_iot;
|
1998-11-01 02:51:05 +03:00
|
|
|
#endif
|
1996-04-13 04:24:30 +04:00
|
|
|
pci_chipset_tag_t pc = &ccp->cc_pc;
|
2000-06-06 01:47:26 +04:00
|
|
|
char *cp;
|
1995-11-23 05:33:17 +03:00
|
|
|
|
1996-04-13 04:24:30 +04:00
|
|
|
pc->pc_intr_v = ccp;
|
|
|
|
pc->pc_intr_map = dec_kn20aa_intr_map;
|
|
|
|
pc->pc_intr_string = dec_kn20aa_intr_string;
|
2000-06-04 23:14:14 +04:00
|
|
|
pc->pc_intr_evcnt = dec_kn20aa_intr_evcnt;
|
1996-04-13 04:24:30 +04:00
|
|
|
pc->pc_intr_establish = dec_kn20aa_intr_establish;
|
|
|
|
pc->pc_intr_disestablish = dec_kn20aa_intr_disestablish;
|
1995-11-23 05:33:17 +03:00
|
|
|
|
1998-04-24 05:25:18 +04:00
|
|
|
/* Not supported on KN20AA. */
|
1998-04-18 05:12:23 +04:00
|
|
|
pc->pc_pciide_compat_intr_establish = NULL;
|
|
|
|
|
2000-06-06 01:47:26 +04:00
|
|
|
kn20aa_pci_intr = alpha_shared_intr_alloc(KN20AA_MAX_IRQ, 8);
|
|
|
|
for (i = 0; i < KN20AA_MAX_IRQ; i++) {
|
1996-11-17 05:05:26 +03:00
|
|
|
alpha_shared_intr_set_maxstrays(kn20aa_pci_intr, i,
|
|
|
|
PCI_STRAY_MAX);
|
|
|
|
|
2000-06-06 01:47:26 +04:00
|
|
|
cp = alpha_shared_intr_string(kn20aa_pci_intr, i);
|
|
|
|
sprintf(cp, "irq %d", i);
|
|
|
|
evcnt_attach_dynamic(alpha_shared_intr_evcnt(
|
|
|
|
kn20aa_pci_intr, i), EVCNT_TYPE_INTR, NULL,
|
|
|
|
"kn20aa", cp);
|
|
|
|
}
|
|
|
|
|
1999-12-16 01:28:15 +03:00
|
|
|
#if NSIO > 0 || NPCEB > 0
|
1998-04-15 02:20:59 +04:00
|
|
|
sio_intr_setup(pc, iot);
|
1996-11-17 05:05:26 +03:00
|
|
|
kn20aa_enable_intr(KN20AA_PCEB_IRQ);
|
1995-11-23 05:33:17 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
set_iointr(kn20aa_iointr);
|
|
|
|
}
|
|
|
|
|
1996-04-13 04:24:30 +04:00
|
|
|
int
|
2000-12-29 01:59:06 +03:00
|
|
|
dec_kn20aa_intr_map(pa, ihp)
|
|
|
|
struct pci_attach_args *pa;
|
1996-04-13 04:24:30 +04:00
|
|
|
pci_intr_handle_t *ihp;
|
1995-11-23 05:33:17 +03:00
|
|
|
{
|
2000-12-29 01:59:06 +03:00
|
|
|
pcitag_t bustag = pa->pa_intrtag;
|
|
|
|
int buspin = pa->pa_intrpin;
|
|
|
|
pci_chipset_tag_t pc = pa->pa_pc;
|
1995-11-23 05:33:17 +03:00
|
|
|
int device;
|
1996-08-07 08:33:21 +04:00
|
|
|
int kn20aa_irq;
|
1995-11-23 05:33:17 +03:00
|
|
|
|
1998-04-25 04:12:44 +04:00
|
|
|
if (buspin == 0) {
|
|
|
|
/* No IRQ used. */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (buspin > 4) {
|
|
|
|
printf("dec_kn20aa_intr_map: bad interrupt pin %d\n", buspin);
|
|
|
|
return 1;
|
|
|
|
}
|
1995-11-23 05:33:17 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Slot->interrupt translation. Appears to work, though it
|
|
|
|
* may not hold up forever.
|
|
|
|
*
|
|
|
|
* The DEC engineers who did this hardware obviously engaged
|
|
|
|
* in random drug testing.
|
|
|
|
*/
|
1997-07-19 13:49:39 +04:00
|
|
|
alpha_pci_decompose_tag(pc, bustag, NULL, &device, NULL);
|
1996-04-13 04:24:30 +04:00
|
|
|
switch (device) {
|
1995-11-23 05:33:17 +03:00
|
|
|
case 11:
|
|
|
|
case 12:
|
1996-08-07 08:33:21 +04:00
|
|
|
kn20aa_irq = ((device - 11) + 0) * 4;
|
1995-11-23 05:33:17 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
1996-08-07 08:33:21 +04:00
|
|
|
kn20aa_irq = 8;
|
1995-11-23 05:33:17 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 9:
|
1996-08-07 08:33:21 +04:00
|
|
|
kn20aa_irq = 12;
|
1995-11-23 05:33:17 +03:00
|
|
|
break;
|
|
|
|
|
1996-08-19 08:19:01 +04:00
|
|
|
case 6: /* 21040 on AlphaStation 500 */
|
1996-08-19 08:14:58 +04:00
|
|
|
kn20aa_irq = 13;
|
|
|
|
break;
|
|
|
|
|
1996-08-14 09:44:31 +04:00
|
|
|
case 8:
|
|
|
|
kn20aa_irq = 16;
|
|
|
|
break;
|
|
|
|
|
1995-11-23 05:33:17 +03:00
|
|
|
default:
|
1996-11-14 00:13:04 +03:00
|
|
|
printf("dec_kn20aa_intr_map: weird device number %d\n",
|
1995-11-23 05:33:17 +03:00
|
|
|
device);
|
1996-11-14 00:13:04 +03:00
|
|
|
return 1;
|
1995-11-23 05:33:17 +03:00
|
|
|
}
|
|
|
|
|
1996-08-07 08:33:21 +04:00
|
|
|
kn20aa_irq += buspin - 1;
|
1995-11-23 05:33:17 +03:00
|
|
|
if (kn20aa_irq > KN20AA_MAX_IRQ)
|
1998-04-16 23:50:55 +04:00
|
|
|
panic("dec_kn20aa_intr_map: kn20aa_irq too large (%d)\n",
|
1995-11-23 05:33:17 +03:00
|
|
|
kn20aa_irq);
|
|
|
|
|
1996-04-13 04:24:30 +04:00
|
|
|
*ihp = kn20aa_irq;
|
1996-08-07 08:33:21 +04:00
|
|
|
return (0);
|
1996-04-13 04:24:30 +04:00
|
|
|
}
|
1995-11-23 05:33:17 +03:00
|
|
|
|
1996-04-13 04:24:30 +04:00
|
|
|
const char *
|
|
|
|
dec_kn20aa_intr_string(ccv, ih)
|
|
|
|
void *ccv;
|
|
|
|
pci_intr_handle_t ih;
|
|
|
|
{
|
1996-11-14 00:13:04 +03:00
|
|
|
#if 0
|
1996-04-13 04:24:30 +04:00
|
|
|
struct cia_config *ccp = ccv;
|
1996-11-14 00:13:04 +03:00
|
|
|
#endif
|
1996-04-13 04:24:30 +04:00
|
|
|
static char irqstr[15]; /* 11 + 2 + NULL + sanity */
|
|
|
|
|
|
|
|
if (ih > KN20AA_MAX_IRQ)
|
1999-02-12 09:25:13 +03:00
|
|
|
panic("dec_kn20aa_intr_string: bogus kn20aa IRQ 0x%lx\n",
|
1996-04-13 04:24:30 +04:00
|
|
|
ih);
|
|
|
|
|
1996-11-14 00:13:04 +03:00
|
|
|
sprintf(irqstr, "kn20aa irq %ld", ih);
|
1996-04-13 04:24:30 +04:00
|
|
|
return (irqstr);
|
1995-11-23 05:33:17 +03:00
|
|
|
}
|
|
|
|
|
2000-06-04 23:14:14 +04:00
|
|
|
const struct evcnt *
|
|
|
|
dec_kn20aa_intr_evcnt(ccv, ih)
|
|
|
|
void *ccv;
|
|
|
|
pci_intr_handle_t ih;
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
struct cia_config *ccp = ccv;
|
|
|
|
#endif
|
|
|
|
|
2000-06-06 01:47:26 +04:00
|
|
|
if (ih > KN20AA_MAX_IRQ)
|
|
|
|
panic("dec_kn20aa_intr_string: bogus kn20aa IRQ 0x%lx\n", ih);
|
|
|
|
return (alpha_shared_intr_evcnt(kn20aa_pci_intr, ih));
|
2000-06-04 23:14:14 +04:00
|
|
|
}
|
|
|
|
|
1996-04-13 04:24:30 +04:00
|
|
|
void *
|
|
|
|
dec_kn20aa_intr_establish(ccv, ih, level, func, arg)
|
|
|
|
void *ccv, *arg;
|
|
|
|
pci_intr_handle_t ih;
|
|
|
|
int level;
|
|
|
|
int (*func) __P((void *));
|
|
|
|
{
|
1996-11-14 00:13:04 +03:00
|
|
|
#if 0
|
1996-04-13 04:24:30 +04:00
|
|
|
struct cia_config *ccp = ccv;
|
1996-11-14 00:13:04 +03:00
|
|
|
#endif
|
1995-11-23 05:33:17 +03:00
|
|
|
void *cookie;
|
1996-04-13 04:24:30 +04:00
|
|
|
|
|
|
|
if (ih > KN20AA_MAX_IRQ)
|
1999-02-12 09:25:13 +03:00
|
|
|
panic("dec_kn20aa_intr_establish: bogus kn20aa IRQ 0x%lx\n",
|
1996-04-13 04:24:30 +04:00
|
|
|
ih);
|
|
|
|
|
1996-11-17 05:05:26 +03:00
|
|
|
cookie = alpha_shared_intr_establish(kn20aa_pci_intr, ih, IST_LEVEL,
|
|
|
|
level, func, arg, "kn20aa irq");
|
|
|
|
|
|
|
|
if (cookie != NULL &&
|
|
|
|
alpha_shared_intr_isactive(kn20aa_pci_intr, ih))
|
|
|
|
kn20aa_enable_intr(ih);
|
1996-04-13 04:24:30 +04:00
|
|
|
return (cookie);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dec_kn20aa_intr_disestablish(ccv, cookie)
|
|
|
|
void *ccv, *cookie;
|
1995-11-23 05:33:17 +03:00
|
|
|
{
|
1996-11-14 00:13:04 +03:00
|
|
|
#if 0
|
1996-04-13 04:24:30 +04:00
|
|
|
struct cia_config *ccp = ccv;
|
1996-11-14 00:13:04 +03:00
|
|
|
#endif
|
1998-08-02 00:25:12 +04:00
|
|
|
struct alpha_shared_intrhand *ih = cookie;
|
|
|
|
unsigned int irq = ih->ih_num;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splhigh();
|
|
|
|
|
|
|
|
alpha_shared_intr_disestablish(kn20aa_pci_intr, cookie,
|
|
|
|
"kn20aa irq");
|
|
|
|
if (alpha_shared_intr_isactive(kn20aa_pci_intr, irq) == 0) {
|
|
|
|
kn20aa_disable_intr(irq);
|
|
|
|
alpha_shared_intr_set_dfltsharetype(kn20aa_pci_intr, irq,
|
|
|
|
IST_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
1995-11-23 05:33:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
kn20aa_iointr(framep, vec)
|
|
|
|
void *framep;
|
1996-07-14 08:08:56 +04:00
|
|
|
unsigned long vec;
|
1995-11-23 05:33:17 +03:00
|
|
|
{
|
1996-11-17 05:05:26 +03:00
|
|
|
int irq;
|
1995-11-23 05:33:17 +03:00
|
|
|
|
|
|
|
if (vec >= 0x900) {
|
|
|
|
if (vec >= 0x900 + (KN20AA_MAX_IRQ << 4))
|
1999-02-12 09:25:13 +03:00
|
|
|
panic("kn20aa_iointr: vec 0x%lx out of range\n", vec);
|
1995-11-23 05:33:17 +03:00
|
|
|
irq = (vec - 0x900) >> 4;
|
|
|
|
|
1996-11-17 05:05:26 +03:00
|
|
|
if (!alpha_shared_intr_dispatch(kn20aa_pci_intr, irq)) {
|
|
|
|
alpha_shared_intr_stray(kn20aa_pci_intr, irq,
|
|
|
|
"kn20aa irq");
|
1998-07-08 02:24:38 +04:00
|
|
|
if (ALPHA_SHARED_INTR_DISABLE(kn20aa_pci_intr, irq))
|
1996-11-17 05:05:26 +03:00
|
|
|
kn20aa_disable_intr(irq);
|
1995-11-23 05:33:17 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
1999-12-16 01:28:15 +03:00
|
|
|
#if NSIO > 0 || NPCEB > 0
|
1996-11-17 05:05:26 +03:00
|
|
|
if (vec >= 0x800) {
|
1995-11-23 05:33:17 +03:00
|
|
|
sio_iointr(framep, vec);
|
|
|
|
return;
|
|
|
|
}
|
1996-11-17 05:05:26 +03:00
|
|
|
#endif
|
1999-02-12 09:25:13 +03:00
|
|
|
panic("kn20aa_iointr: weird vec 0x%lx\n", vec);
|
1995-11-23 05:33:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
kn20aa_enable_intr(irq)
|
|
|
|
int irq;
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
1996-08-07 08:22:40 +04:00
|
|
|
* From disassembling small bits of the OSF/1 kernel:
|
1995-11-23 05:33:17 +03:00
|
|
|
* the following appears to enable a given interrupt request.
|
|
|
|
* "blech." I'd give valuable body parts for better docs or
|
|
|
|
* for a good decompiler.
|
|
|
|
*/
|
1996-07-09 04:53:48 +04:00
|
|
|
alpha_mb();
|
1995-11-23 05:33:17 +03:00
|
|
|
REGVAL(0x8780000000L + 0x40L) |= (1 << irq); /* XXX */
|
1996-07-09 04:53:48 +04:00
|
|
|
alpha_mb();
|
1995-11-23 05:33:17 +03:00
|
|
|
}
|
|
|
|
|
1996-08-07 08:22:40 +04:00
|
|
|
void
|
|
|
|
kn20aa_disable_intr(irq)
|
|
|
|
int irq;
|
|
|
|
{
|
|
|
|
|
|
|
|
alpha_mb();
|
|
|
|
REGVAL(0x8780000000L + 0x40L) &= ~(1 << irq); /* XXX */
|
|
|
|
alpha_mb();
|
|
|
|
}
|