Home | History | Annotate | Line # | Download | only in pci
pci_2100_a50.c revision 1.32.120.1
      1  1.32.120.1     skrll /* $NetBSD: pci_2100_a50.c,v 1.32.120.1 2009/04/28 07:33:35 skrll Exp $ */
      2         1.1       cgd 
      3         1.1       cgd /*
      4         1.6       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.13       cgd 
     30        1.14       cgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     31        1.14       cgd 
     32  1.32.120.1     skrll __KERNEL_RCSID(0, "$NetBSD: pci_2100_a50.c,v 1.32.120.1 2009/04/28 07:33:35 skrll Exp $");
     33         1.1       cgd 
     34         1.1       cgd #include <sys/types.h>
     35         1.1       cgd #include <sys/param.h>
     36         1.1       cgd #include <sys/time.h>
     37         1.1       cgd #include <sys/systm.h>
     38         1.1       cgd #include <sys/errno.h>
     39         1.1       cgd #include <sys/device.h>
     40        1.28       mrg 
     41        1.28       mrg #include <uvm/uvm_extern.h>
     42         1.1       cgd 
     43         1.8       cgd #include <machine/autoconf.h>
     44         1.5       cgd #include <machine/bus.h>
     45         1.5       cgd #include <machine/intr.h>
     46         1.5       cgd 
     47         1.1       cgd #include <dev/isa/isavar.h>
     48         1.3       cgd #include <dev/pci/pcireg.h>
     49         1.1       cgd #include <dev/pci/pcivar.h>
     50         1.1       cgd 
     51         1.3       cgd #include <alpha/pci/apecsvar.h>
     52         1.1       cgd 
     53         1.3       cgd #include <alpha/pci/pci_2100_a50.h>
     54         1.3       cgd #include <alpha/pci/siovar.h>
     55         1.7       cgd #include <alpha/pci/sioreg.h>
     56         1.1       cgd 
     57         1.3       cgd #include "sio.h"
     58         1.1       cgd 
     59  1.32.120.1     skrll int	dec_2100_a50_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
     60  1.32.120.1     skrll const char *dec_2100_a50_intr_string(void *, pci_intr_handle_t);
     61  1.32.120.1     skrll const struct evcnt *dec_2100_a50_intr_evcnt(void *, pci_intr_handle_t);
     62  1.32.120.1     skrll void    *dec_2100_a50_intr_establish(void *, pci_intr_handle_t,
     63  1.32.120.1     skrll 	    int, int (*func)(void *), void *);
     64  1.32.120.1     skrll void    dec_2100_a50_intr_disestablish(void *, void *);
     65         1.5       cgd 
     66         1.7       cgd #define	APECS_SIO_DEVICE	7	/* XXX */
     67         1.7       cgd 
     68         1.5       cgd void
     69  1.32.120.1     skrll pci_2100_a50_pickintr(struct apecs_config *acp)
     70         1.5       cgd {
     71        1.18   thorpej 	bus_space_tag_t iot = &acp->ac_iot;
     72         1.5       cgd 	pci_chipset_tag_t pc = &acp->ac_pc;
     73         1.5       cgd 	pcireg_t sioclass;
     74         1.5       cgd 	int sioII;
     75         1.5       cgd 
     76         1.5       cgd 	/* XXX MAGIC NUMBER */
     77         1.5       cgd 	sioclass = pci_conf_read(pc, pci_make_tag(pc, 0, 7, 0), PCI_CLASS_REG);
     78         1.5       cgd         sioII = (sioclass & 0xff) >= 3;
     79         1.5       cgd 
     80         1.5       cgd 	if (!sioII)
     81        1.10  christos 		printf("WARNING: SIO NOT SIO II... NO BETS...\n");
     82         1.5       cgd 
     83         1.5       cgd 	pc->pc_intr_v = acp;
     84         1.5       cgd 	pc->pc_intr_map = dec_2100_a50_intr_map;
     85         1.5       cgd 	pc->pc_intr_string = dec_2100_a50_intr_string;
     86        1.26       cgd 	pc->pc_intr_evcnt = dec_2100_a50_intr_evcnt;
     87         1.5       cgd 	pc->pc_intr_establish = dec_2100_a50_intr_establish;
     88         1.5       cgd 	pc->pc_intr_disestablish = dec_2100_a50_intr_disestablish;
     89        1.22   thorpej 
     90        1.23    mjacob 	/* Not supported on 2100 A50. */
     91        1.22   thorpej 	pc->pc_pciide_compat_intr_establish = NULL;
     92         1.1       cgd 
     93         1.5       cgd #if NSIO
     94        1.20   thorpej 	sio_intr_setup(pc, iot);
     95         1.5       cgd #else
     96         1.5       cgd 	panic("pci_2100_a50_pickintr: no I/O interrupt handler (no sio)");
     97         1.5       cgd #endif
     98         1.5       cgd }
     99         1.5       cgd 
    100         1.5       cgd int
    101  1.32.120.1     skrll dec_2100_a50_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    102         1.1       cgd {
    103        1.29  sommerfe         pcitag_t bustag = pa->pa_intrtag;
    104        1.29  sommerfe 	int buspin = pa->pa_intrpin;
    105        1.29  sommerfe 	pci_chipset_tag_t pc = pa->pa_pc;
    106         1.5       cgd 	int device, pirq;
    107         1.5       cgd 	pcireg_t pirqreg;
    108         1.3       cgd 	u_int8_t pirqline;
    109        1.15       cgd 
    110        1.15       cgd #ifndef DIAGNOSTIC
    111        1.15       cgd 	pirq = 0;				/* XXX gcc -Wuninitialized */
    112        1.15       cgd #endif
    113         1.1       cgd 
    114        1.24   thorpej 	if (buspin == 0) {
    115        1.24   thorpej 		/* No IRQ used. */
    116        1.24   thorpej 		return 1;
    117        1.24   thorpej 	}
    118        1.24   thorpej 	if (buspin > 4) {
    119        1.24   thorpej 		printf("dec_2100_a50_intr_map: bad interrupt pin %d\n",
    120        1.12       cgd 		    buspin);
    121        1.24   thorpej 		return 1;
    122        1.24   thorpej 	}
    123         1.1       cgd 
    124        1.31   thorpej 	pci_decompose_tag(pc, bustag, NULL, &device, NULL);
    125         1.1       cgd 
    126         1.1       cgd 	switch (device) {
    127         1.1       cgd 	case 6:					/* NCR SCSI */
    128         1.1       cgd 		pirq = 3;
    129         1.1       cgd 		break;
    130         1.1       cgd 
    131         1.1       cgd 	case 11:				/* slot 1 */
    132         1.5       cgd 	case 14:				/* slot 3 */
    133         1.5       cgd 		switch (buspin) {
    134         1.1       cgd 		case PCI_INTERRUPT_PIN_A:
    135         1.1       cgd 		case PCI_INTERRUPT_PIN_D:
    136         1.1       cgd 			pirq = 0;
    137         1.1       cgd 			break;
    138         1.1       cgd 		case PCI_INTERRUPT_PIN_B:
    139         1.1       cgd 			pirq = 2;
    140         1.1       cgd 			break;
    141         1.1       cgd 		case PCI_INTERRUPT_PIN_C:
    142         1.1       cgd 			pirq = 1;
    143         1.1       cgd 			break;
    144        1.12       cgd #ifdef DIAGNOSTIC
    145        1.12       cgd 		default:			/* XXX gcc -Wuninitialized */
    146        1.32    provos 			panic("dec_2100_a50_intr_map bogus PCI pin %d",
    147        1.12       cgd 			    buspin);
    148        1.12       cgd #endif
    149         1.1       cgd 		};
    150         1.1       cgd 		break;
    151         1.1       cgd 
    152         1.1       cgd 	case 12:				/* slot 2 */
    153         1.5       cgd 		switch (buspin) {
    154         1.1       cgd 		case PCI_INTERRUPT_PIN_A:
    155         1.1       cgd 		case PCI_INTERRUPT_PIN_D:
    156         1.1       cgd 			pirq = 1;
    157         1.1       cgd 			break;
    158         1.1       cgd 		case PCI_INTERRUPT_PIN_B:
    159         1.1       cgd 			pirq = 0;
    160         1.1       cgd 			break;
    161         1.1       cgd 		case PCI_INTERRUPT_PIN_C:
    162         1.1       cgd 			pirq = 2;
    163         1.1       cgd 			break;
    164        1.12       cgd #ifdef DIAGNOSTIC
    165        1.12       cgd 		default:			/* XXX gcc -Wuninitialized */
    166        1.32    provos 			panic("dec_2100_a50_intr_map bogus PCI pin %d",
    167        1.12       cgd 			    buspin);
    168        1.12       cgd #endif
    169         1.1       cgd 		};
    170         1.1       cgd 		break;
    171         1.1       cgd 
    172         1.1       cgd 	case 13:				/* slot 3 */
    173         1.5       cgd 		switch (buspin) {
    174         1.1       cgd 		case PCI_INTERRUPT_PIN_A:
    175         1.1       cgd 		case PCI_INTERRUPT_PIN_D:
    176         1.1       cgd 			pirq = 2;
    177         1.1       cgd 			break;
    178         1.1       cgd 		case PCI_INTERRUPT_PIN_B:
    179         1.1       cgd 			pirq = 1;
    180         1.1       cgd 			break;
    181         1.1       cgd 		case PCI_INTERRUPT_PIN_C:
    182         1.1       cgd 			pirq = 0;
    183         1.1       cgd 			break;
    184        1.12       cgd #ifdef DIAGNOSTIC
    185        1.12       cgd 		default:			/* XXX gcc -Wuninitialized */
    186        1.32    provos 			panic("dec_2100_a50_intr_map bogus PCI pin %d",
    187        1.12       cgd 			    buspin);
    188        1.12       cgd #endif
    189         1.1       cgd 		};
    190         1.1       cgd 		break;
    191        1.12       cgd 
    192        1.12       cgd 	default:
    193        1.12       cgd                 printf("dec_2100_a50_intr_map: weird device number %d\n",
    194        1.12       cgd 		    device);
    195        1.12       cgd                 return 1;
    196         1.1       cgd 	}
    197         1.1       cgd 
    198         1.7       cgd 	pirqreg = pci_conf_read(pc, pci_make_tag(pc, 0, APECS_SIO_DEVICE, 0),
    199         1.7       cgd 	    SIO_PCIREG_PIRQ_RTCTRL);
    200         1.1       cgd #if 0
    201        1.21   thorpej 	printf("pci_2100_a50_intr_map: device %d pin %c: pirq %d, reg = %x\n",
    202         1.5       cgd 		device, '@' + buspin, pirq, pirqreg);
    203         1.1       cgd #endif
    204         1.3       cgd 	pirqline = (pirqreg >> (pirq * 8)) & 0xff;
    205         1.3       cgd 	if ((pirqline & 0x80) != 0)
    206         1.5       cgd 		return 1;
    207         1.3       cgd 	pirqline &= 0xf;
    208         1.1       cgd 
    209         1.1       cgd #if 0
    210        1.21   thorpej 	printf("pci_2100_a50_intr_map: device %d pin %c: mapped to line %d\n",
    211         1.5       cgd 	    device, '@' + buspin, pirqline);
    212         1.1       cgd #endif
    213         1.1       cgd 
    214         1.5       cgd 	*ihp = pirqline;
    215         1.5       cgd 	return (0);
    216         1.3       cgd }
    217         1.3       cgd 
    218         1.5       cgd const char *
    219  1.32.120.1     skrll dec_2100_a50_intr_string(void *acv, pci_intr_handle_t ih)
    220         1.3       cgd {
    221        1.12       cgd #if 0
    222         1.5       cgd 	struct apecs_config *acp = acv;
    223        1.12       cgd #endif
    224         1.3       cgd 
    225         1.5       cgd 	return sio_intr_string(NULL /*XXX*/, ih);
    226        1.26       cgd }
    227        1.26       cgd 
    228        1.26       cgd const struct evcnt *
    229  1.32.120.1     skrll dec_2100_a50_intr_evcnt(void *acv, pci_intr_handle_t ih)
    230        1.26       cgd {
    231        1.26       cgd #if 0
    232        1.26       cgd 	struct apecs_config *acp = acv;
    233        1.26       cgd #endif
    234        1.26       cgd 
    235        1.26       cgd 	return sio_intr_evcnt(NULL /*XXX*/, ih);
    236         1.1       cgd }
    237         1.1       cgd 
    238         1.5       cgd void *
    239  1.32.120.1     skrll dec_2100_a50_intr_establish(void *acv, pci_intr_handle_t ih, int level, int (*func)(void *), void *arg)
    240         1.1       cgd {
    241        1.12       cgd #if 0
    242         1.5       cgd 	struct apecs_config *acp = acv;
    243        1.12       cgd #endif
    244         1.1       cgd 
    245         1.5       cgd 	return sio_intr_establish(NULL /*XXX*/, ih, IST_LEVEL, level, func,
    246         1.5       cgd 	    arg);
    247         1.5       cgd }
    248         1.3       cgd 
    249         1.5       cgd void
    250  1.32.120.1     skrll dec_2100_a50_intr_disestablish(void *acv, void *cookie)
    251         1.5       cgd {
    252        1.12       cgd #if 0
    253         1.5       cgd 	struct apecs_config *acp = acv;
    254        1.12       cgd #endif
    255         1.1       cgd 
    256         1.5       cgd 	sio_intr_disestablish(NULL /*XXX*/, cookie);
    257         1.1       cgd }
    258