Home | History | Annotate | Line # | Download | only in pci
cia.c revision 1.1
      1 /*	$NetBSD: cia.c,v 1.1 1995/11/23 02:37:24 cgd Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Author: Chris G. Demetriou
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include <sys/param.h>
     31 #include <sys/systm.h>
     32 #include <sys/kernel.h>
     33 #include <sys/malloc.h>
     34 #include <sys/device.h>
     35 #include <vm/vm.h>
     36 
     37 #include <machine/autoconf.h>
     38 #include <machine/rpb.h>
     39 
     40 #include <dev/isa/isareg.h>
     41 #include <dev/isa/isavar.h>
     42 
     43 #include <dev/pci/pcireg.h>
     44 #include <dev/pci/pcivar.h>
     45 #include <alpha/pci/ciareg.h>
     46 #include <alpha/pci/ciavar.h>
     47 #if defined(DEC_KN20AA)
     48 #include <alpha/pci/pci_kn20aa.h>
     49 #endif
     50 
     51 int	ciamatch __P((struct device *, void *, void *));
     52 void	ciaattach __P((struct device *, struct device *, void *));
     53 
     54 struct cfdriver ciacd = {
     55 	NULL, "cia", ciamatch, ciaattach, DV_DULL,
     56 	    sizeof(struct cia_softc)
     57 };
     58 
     59 static int	ciaprint __P((void *, char *pnp));
     60 
     61 #define	REGVAL(r)	(*(int32_t *)phystok0seg(r))
     62 
     63 /* There can be only one. */
     64 int ciafound;
     65 struct cia_config cia_configuration;
     66 
     67 int
     68 ciamatch(parent, match, aux)
     69 	struct device *parent;
     70 	void *match, *aux;
     71 {
     72 	struct cfdata *cf = match;
     73 	struct confargs *ca = aux;
     74 
     75 	/* Make sure that we're looking for a CIA. */
     76 	if (strcmp(ca->ca_name, ciacd.cd_name) != 0)
     77 		return (0);
     78 
     79 	if (ciafound)
     80 		return (0);
     81 
     82 	return (1);
     83 }
     84 
     85 /*
     86  * Set up the chipset's function pointers.
     87  */
     88 void
     89 cia_init(ccp)
     90 	struct cia_config *ccp;
     91 {
     92 
     93 	/*
     94 	 * Can't set up SGMAP data here; can be called before malloc().
     95 	 */
     96 
     97 	ccp->cc_conffns = &cia_conf_fns;
     98 	ccp->cc_confarg = ccp;
     99 	ccp->cc_dmafns = &cia_dma_fns;
    100 	ccp->cc_dmaarg = ccp;
    101 	/* Interrupt routines set up in 'attach' */
    102 	ccp->cc_memfns = &cia_mem_fns;
    103 	ccp->cc_memarg = ccp;
    104 	ccp->cc_piofns = &cia_pio_fns;
    105 	ccp->cc_pioarg = ccp;
    106 }
    107 
    108 void
    109 ciaattach(parent, self, aux)
    110 	struct device *parent, *self;
    111 	void *aux;
    112 {
    113 	struct confargs *ca = aux;
    114 	struct cia_softc *sc = (struct cia_softc *)self;
    115 	struct cia_config *ccp;
    116 	struct pci_attach_args pa;
    117 
    118 	/* note that we've attached the chipset; can't have 2 CIAs. */
    119 	ciafound = 1;
    120 
    121 	/*
    122 	 * set up the chipset's info; done once at console init time
    123 	 * (maybe), but doesn't hurt to do twice.
    124 	 */
    125 	ccp = sc->sc_ccp = &cia_configuration;
    126 	cia_init(ccp);
    127 
    128 	/* XXX print chipset information */
    129 	printf("\n");
    130 
    131 	switch (hwrpb->rpb_type) {
    132 #if defined(DEC_KN20AA)
    133 	case ST_DEC_KN20AA:
    134 		pci_kn20aa_pickintr(ccp->cc_conffns, ccp->cc_confarg,
    135 		    ccp->cc_piofns, ccp->cc_pioarg,
    136 		    &ccp->cc_intrfns, &ccp->cc_intrarg);
    137 #ifdef EVCNT_COUNTERS
    138 		evcnt_attach(self, "intr", &kn20aa_intr_evcnt);
    139 #endif
    140 		break;
    141 #endif
    142 	default:
    143 		panic("ciaattach: shouldn't be here, really...");
    144 	}
    145 
    146 	pa.pa_bus = 0;
    147 	pa.pa_maxdev = 32;
    148 	pa.pa_burstlog2 = 8;
    149 
    150 	pa.pa_conffns = ccp->cc_conffns;
    151 	pa.pa_confarg = ccp->cc_confarg;
    152 	pa.pa_dmafns = ccp->cc_dmafns;
    153 	pa.pa_dmaarg = ccp->cc_dmaarg;
    154 	pa.pa_intrfns = ccp->cc_intrfns;
    155 	pa.pa_intrarg = ccp->cc_intrarg;
    156 	pa.pa_memfns = ccp->cc_memfns;
    157 	pa.pa_memarg = ccp->cc_memarg;
    158 	pa.pa_piofns = ccp->cc_piofns;
    159 	pa.pa_pioarg = ccp->cc_pioarg;
    160 
    161 	config_found(self, &pa, ciaprint);
    162 }
    163 
    164 static int
    165 ciaprint(aux, pnp)
    166 	void *aux;
    167 	char *pnp;
    168 {
    169 	register struct pci_attach_args *pa = aux;
    170 
    171 	/* only PCIs can attach to CIAs; easy. */
    172 	if (pnp)
    173 		printf("pci at %s", pnp);
    174 	printf(" bus %d", pa->pa_bus);
    175 	return (UNCONF);
    176 }
    177