Home | History | Annotate | Line # | Download | only in pci
pci_eb164.c revision 1.2
      1  1.2  cgd /*	$NetBSD: pci_eb164.c,v 1.2 1996/11/13 21:13:30 cgd Exp $	*/
      2  1.1  cgd 
      3  1.1  cgd /*
      4  1.1  cgd  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  1.1  cgd  * All rights reserved.
      6  1.1  cgd  *
      7  1.1  cgd  * Author: Chris G. Demetriou
      8  1.1  cgd  *
      9  1.1  cgd  * Permission to use, copy, modify and distribute this software and
     10  1.1  cgd  * its documentation is hereby granted, provided that both the copyright
     11  1.1  cgd  * notice and this permission notice appear in all copies of the
     12  1.1  cgd  * software, derivative works or modified versions, and any portions
     13  1.1  cgd  * thereof, and that both notices appear in supporting documentation.
     14  1.1  cgd  *
     15  1.1  cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  1.1  cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  1.1  cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  1.1  cgd  *
     19  1.1  cgd  * Carnegie Mellon requests users of this software to return to
     20  1.1  cgd  *
     21  1.1  cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  1.1  cgd  *  School of Computer Science
     23  1.1  cgd  *  Carnegie Mellon University
     24  1.1  cgd  *  Pittsburgh PA 15213-3890
     25  1.1  cgd  *
     26  1.1  cgd  * any improvements or extensions that they make and grant Carnegie the
     27  1.1  cgd  * rights to redistribute these changes.
     28  1.1  cgd  */
     29  1.1  cgd 
     30  1.1  cgd #include <sys/types.h>
     31  1.1  cgd #include <sys/param.h>
     32  1.1  cgd #include <sys/time.h>
     33  1.1  cgd #include <sys/systm.h>
     34  1.1  cgd #include <sys/errno.h>
     35  1.1  cgd #include <sys/malloc.h>
     36  1.1  cgd #include <sys/device.h>
     37  1.1  cgd #include <sys/syslog.h>
     38  1.1  cgd 
     39  1.1  cgd #include <vm/vm.h>
     40  1.1  cgd 
     41  1.1  cgd #include <machine/autoconf.h>
     42  1.1  cgd 
     43  1.1  cgd #include <dev/pci/pcireg.h>
     44  1.1  cgd #include <dev/pci/pcivar.h>
     45  1.1  cgd 
     46  1.1  cgd #include <alpha/pci/ciareg.h>
     47  1.1  cgd #include <alpha/pci/ciavar.h>
     48  1.1  cgd 
     49  1.1  cgd #include <alpha/pci/pci_eb164.h>
     50  1.1  cgd 
     51  1.1  cgd #ifndef EVCNT_COUNTERS
     52  1.1  cgd #include <machine/intrcnt.h>
     53  1.1  cgd #endif
     54  1.1  cgd 
     55  1.1  cgd #include "sio.h"
     56  1.1  cgd #if NSIO
     57  1.1  cgd #include <alpha/pci/siovar.h>
     58  1.1  cgd #endif
     59  1.1  cgd 
     60  1.1  cgd int	dec_eb164_intr_map __P((void *, pcitag_t, int, int,
     61  1.1  cgd 	    pci_intr_handle_t *));
     62  1.1  cgd const char *dec_eb164_intr_string __P((void *, pci_intr_handle_t));
     63  1.1  cgd void	*dec_eb164_intr_establish __P((void *, pci_intr_handle_t,
     64  1.1  cgd 	    int, int (*func)(void *), void *));
     65  1.1  cgd void	dec_eb164_intr_disestablish __P((void *, void *));
     66  1.1  cgd 
     67  1.1  cgd void	eb164_pci_strayintr __P((int irq));
     68  1.1  cgd void	eb164_iointr __P((void *framep, unsigned long vec));
     69  1.1  cgd 
     70  1.1  cgd void
     71  1.1  cgd pci_eb164_pickintr(ccp)
     72  1.1  cgd 	struct cia_config *ccp;
     73  1.1  cgd {
     74  1.1  cgd 	bus_space_tag_t iot = ccp->cc_iot;
     75  1.1  cgd 	pci_chipset_tag_t pc = &ccp->cc_pc;
     76  1.1  cgd 
     77  1.1  cgd         pc->pc_intr_v = ccp;
     78  1.1  cgd         pc->pc_intr_map = dec_eb164_intr_map;
     79  1.1  cgd         pc->pc_intr_string = dec_eb164_intr_string;
     80  1.1  cgd         pc->pc_intr_establish = dec_eb164_intr_establish;
     81  1.1  cgd         pc->pc_intr_disestablish = dec_eb164_intr_disestablish;
     82  1.1  cgd 
     83  1.1  cgd #if NSIO
     84  1.1  cgd 	sio_intr_setup(iot);
     85  1.1  cgd #endif
     86  1.1  cgd 
     87  1.1  cgd 	set_iointr(eb164_iointr);
     88  1.1  cgd 
     89  1.1  cgd #if 0 /* XXX */
     90  1.1  cgd #if NSIO
     91  1.1  cgd 	eb164_enable_intr(KN20AA_PCEB_IRQ);
     92  1.1  cgd #if 0 /* XXX init PCEB interrupt handler? */
     93  1.1  cgd 	eb164_attach_intr(&eb164_pci_intrs[KN20AA_PCEB_IRQ], ???, ???, ???);
     94  1.1  cgd #endif
     95  1.1  cgd #endif
     96  1.1  cgd #endif /* 0 XXX */
     97  1.1  cgd }
     98  1.1  cgd 
     99  1.1  cgd int
    100  1.1  cgd dec_eb164_intr_map(ccv, bustag, buspin, line, ihp)
    101  1.1  cgd         void *ccv;
    102  1.1  cgd         pcitag_t bustag;
    103  1.1  cgd         int buspin, line;
    104  1.1  cgd         pci_intr_handle_t *ihp;
    105  1.1  cgd {
    106  1.1  cgd 
    107  1.1  cgd 	printf("dec_eb164_intr_map(0x%lx, %d, %d)\n", bustag, buspin, line);
    108  1.1  cgd 	return 0;
    109  1.1  cgd 
    110  1.1  cgd #if 0
    111  1.1  cgd 	struct cia_config *ccp = ccv;
    112  1.1  cgd 	pci_chipset_tag_t pc = &ccp->cc_pc;
    113  1.1  cgd 	int device;
    114  1.1  cgd 	int eb164_irq;
    115  1.1  cgd 	void *ih;
    116  1.1  cgd 
    117  1.1  cgd         if (buspin == 0) {
    118  1.1  cgd                 /* No IRQ used. */
    119  1.1  cgd                 return 1;
    120  1.1  cgd         }
    121  1.1  cgd         if (buspin > 4) {
    122  1.1  cgd                 printf("pci_map_int: bad interrupt pin %d\n", buspin);
    123  1.1  cgd                 return 1;
    124  1.1  cgd         }
    125  1.1  cgd 
    126  1.1  cgd 	/*
    127  1.1  cgd 	 * Slot->interrupt translation.  Appears to work, though it
    128  1.1  cgd 	 * may not hold up forever.
    129  1.1  cgd 	 *
    130  1.1  cgd 	 * The DEC engineers who did this hardware obviously engaged
    131  1.1  cgd 	 * in random drug testing.
    132  1.1  cgd 	 */
    133  1.1  cgd 	pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    134  1.1  cgd 	switch (device) {
    135  1.1  cgd 	case 11:
    136  1.1  cgd 	case 12:
    137  1.1  cgd 		eb164_irq = ((device - 11) + 0) * 4;
    138  1.1  cgd 		break;
    139  1.1  cgd 
    140  1.1  cgd 	case 7:
    141  1.1  cgd 		eb164_irq = 8;
    142  1.1  cgd 		break;
    143  1.1  cgd 
    144  1.1  cgd 	case 9:
    145  1.1  cgd 		eb164_irq = 12;
    146  1.1  cgd 		break;
    147  1.1  cgd 
    148  1.1  cgd 	case 6:					/* 21040 on AlphaStation 500 */
    149  1.1  cgd 		eb164_irq = 13;
    150  1.1  cgd 		break;
    151  1.1  cgd 
    152  1.1  cgd 	case 8:
    153  1.1  cgd 		eb164_irq = 16;
    154  1.1  cgd 		break;
    155  1.1  cgd 
    156  1.1  cgd 	default:
    157  1.1  cgd #ifdef KN20AA_BOGUS_IRQ_FROB
    158  1.1  cgd 		*ihp = 0xdeadbeef;
    159  1.1  cgd 		printf("\n\n BOGUS INTERRUPT MAPPING: dev %d, pin %d\n",
    160  1.1  cgd 		    device, buspin);
    161  1.1  cgd 		return (0);
    162  1.1  cgd #endif
    163  1.1  cgd 		panic("pci_eb164_map_int: invalid device number %d\n",
    164  1.1  cgd 		    device);
    165  1.1  cgd 	}
    166  1.1  cgd 
    167  1.1  cgd 	eb164_irq += buspin - 1;
    168  1.1  cgd 	if (eb164_irq > KN20AA_MAX_IRQ)
    169  1.1  cgd 		panic("pci_eb164_map_int: eb164_irq too large (%d)\n",
    170  1.1  cgd 		    eb164_irq);
    171  1.1  cgd 
    172  1.1  cgd 	*ihp = eb164_irq;
    173  1.1  cgd 	return (0);
    174  1.1  cgd #endif
    175  1.1  cgd }
    176  1.1  cgd 
    177  1.1  cgd const char *
    178  1.1  cgd dec_eb164_intr_string(ccv, ih)
    179  1.1  cgd 	void *ccv;
    180  1.1  cgd 	pci_intr_handle_t ih;
    181  1.1  cgd {
    182  1.2  cgd #if 0
    183  1.1  cgd 	struct cia_config *ccp = ccv;
    184  1.2  cgd #endif
    185  1.1  cgd         static char irqstr[15];          /* 11 + 2 + NULL + sanity */
    186  1.1  cgd 
    187  1.1  cgd 	sprintf(irqstr, "BOGUS");
    188  1.1  cgd 	return (irqstr);
    189  1.1  cgd 
    190  1.1  cgd #if 0 /* XXX */
    191  1.1  cgd #ifdef KN20AA_BOGUS_IRQ_FROB
    192  1.1  cgd 	if (ih == 0xdeadbeef) {
    193  1.1  cgd 		sprintf(irqstr, "BOGUS");
    194  1.1  cgd 		return (irqstr);
    195  1.1  cgd 	}
    196  1.1  cgd #endif
    197  1.1  cgd         if (ih > KN20AA_MAX_IRQ)
    198  1.1  cgd                 panic("dec_eb164_a50_intr_string: bogus eb164 IRQ 0x%x\n",
    199  1.1  cgd 		    ih);
    200  1.1  cgd 
    201  1.1  cgd         sprintf(irqstr, "eb164 irq %d", ih);
    202  1.1  cgd         return (irqstr);
    203  1.1  cgd #endif /* 0 XXX */
    204  1.1  cgd }
    205  1.1  cgd 
    206  1.1  cgd void *
    207  1.1  cgd dec_eb164_intr_establish(ccv, ih, level, func, arg)
    208  1.1  cgd         void *ccv, *arg;
    209  1.1  cgd         pci_intr_handle_t ih;
    210  1.1  cgd         int level;
    211  1.1  cgd         int (*func) __P((void *));
    212  1.1  cgd {
    213  1.1  cgd 
    214  1.1  cgd 	printf("dec_eb164_intr_establish(0x%lx, %d, %p, %p)\n", ih, level, func, arg);
    215  1.1  cgd 	return ((void *)0xbabefacedeadbeef);
    216  1.1  cgd 
    217  1.1  cgd #if 0 /* XXX */
    218  1.1  cgd         struct cia_config *ccp = ccv;
    219  1.1  cgd 	void *cookie;
    220  1.1  cgd 
    221  1.1  cgd #ifdef KN20AA_BOGUS_IRQ_FROB
    222  1.1  cgd 	if (ih == 0xdeadbeef) {
    223  1.1  cgd 		int i;
    224  1.1  cgd 		char chars[10];
    225  1.1  cgd 
    226  1.1  cgd 		printf("dec_eb164_intr_establish: BOGUS IRQ\n");
    227  1.1  cgd 		do {
    228  1.1  cgd 			printf("IRQ to enable? ");
    229  1.1  cgd 			getstr(chars, 10);
    230  1.1  cgd 			i = atoi(chars);
    231  1.1  cgd 		} while (i < 0 || i > 32);
    232  1.1  cgd 		printf("ENABLING IRQ %d\n", i);
    233  1.1  cgd 		eb164_enable_intr(i);
    234  1.1  cgd 		return ((void *)0xbabefacedeadbeef);
    235  1.1  cgd 	}
    236  1.1  cgd #endif
    237  1.1  cgd         if (ih > KN20AA_MAX_IRQ)
    238  1.1  cgd                 panic("dec_eb164_intr_establish: bogus eb164 IRQ 0x%x\n",
    239  1.1  cgd 		    ih);
    240  1.1  cgd 
    241  1.1  cgd 	cookie = eb164_attach_intr(&eb164_pci_intrs[ih], level, func, arg);
    242  1.1  cgd 	eb164_enable_intr(ih);
    243  1.1  cgd 	return (cookie);
    244  1.1  cgd #endif /* XXX */
    245  1.1  cgd }
    246  1.1  cgd 
    247  1.1  cgd void
    248  1.1  cgd dec_eb164_intr_disestablish(ccv, cookie)
    249  1.1  cgd         void *ccv, *cookie;
    250  1.1  cgd {
    251  1.1  cgd 
    252  1.1  cgd 	panic("dec_eb164_intr_disestablish not implemented"); /* XXX */
    253  1.1  cgd }
    254  1.1  cgd 
    255  1.1  cgd void
    256  1.1  cgd eb164_iointr(framep, vec)
    257  1.1  cgd 	void *framep;
    258  1.1  cgd 	unsigned long vec;
    259  1.1  cgd {
    260  1.1  cgd 
    261  1.1  cgd 	panic("eb164_iointr: weird vec 0x%x\n", vec);
    262  1.1  cgd }
    263