Home | History | Annotate | Line # | Download | only in pci
cia.c revision 1.21.4.1
      1 /* $NetBSD: cia.c,v 1.21.4.1 1997/08/23 07:06:58 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright Notice:
      5  *
      6  * Copyright (c) 1997 Christopher G. Demetriou.  All rights reserved.
      7  *
      8  * License:
      9  *
     10  * This License applies to this software ("Software"), created
     11  * by Christopher G. Demetriou ("Author").
     12  *
     13  * You may use, copy, modify and redistribute this Software without
     14  * charge, in either source code form, binary form, or both, on the
     15  * following conditions:
     16  *
     17  * 1.  (a) Binary code: (i) a complete copy of the above copyright notice
     18  * must be included within each copy of the Software in binary code form,
     19  * and (ii) a complete copy of the above copyright notice and all terms
     20  * of this License as presented here must be included within each copy of
     21  * all documentation accompanying or associated with binary code, in any
     22  * medium, along with a list of the software modules to which the license
     23  * applies.
     24  *
     25  * (b) Source Code: A complete copy of the above copyright notice and all
     26  * terms of this License as presented here must be included within: (i)
     27  * each copy of the Software in source code form, and (ii) each copy of
     28  * all accompanying or associated documentation, in any medium.
     29  *
     30  * 2. The following Acknowledgment must be used in communications
     31  * involving the Software as described below:
     32  *
     33  *      This product includes software developed by
     34  *      Christopher G. Demetriou for the NetBSD Project.
     35  *
     36  * The Acknowledgment must be conspicuously and completely displayed
     37  * whenever the Software, or any software, products or systems containing
     38  * the Software, are mentioned in advertising, marketing, informational
     39  * or publicity materials of any kind, whether in print, electronic or
     40  * other media (except for information provided to support use of
     41  * products containing the Software by existing users or customers).
     42  *
     43  * 3. The name of the Author may not be used to endorse or promote
     44  * products derived from this Software without specific prior written
     45  * permission (conditions (1) and (2) above are not considered
     46  * endorsement or promotion).
     47  *
     48  * 4.  This license applies to: (a) all copies of the Software, whether
     49  * partial or whole, original or modified, and (b) your actions, and the
     50  * actions of all those who may act on your behalf.  All uses not
     51  * expressly permitted are reserved to the Author.
     52  *
     53  * 5.  Disclaimer.  THIS SOFTWARE IS MADE AVAILABLE BY THE AUTHOR TO THE
     54  * PUBLIC FOR FREE AND "AS IS.''  ALL USERS OF THIS FREE SOFTWARE ARE
     55  * SOLELY AND ENTIRELY RESPONSIBLE FOR THEIR OWN CHOICE AND USE OF THIS
     56  * SOFTWARE FOR THEIR OWN PURPOSES.  BY USING THIS SOFTWARE, EACH USER
     57  * AGREES THAT THE AUTHOR SHALL NOT BE LIABLE FOR DAMAGES OF ANY KIND IN
     58  * RELATION TO ITS USE OR PERFORMANCE.
     59  *
     60  * 6.  If you have a special need for a change in one or more of these
     61  * license conditions, please contact the Author via electronic mail to
     62  *
     63  *     cgd (at) NetBSD.ORG
     64  *
     65  * or via the contact information on
     66  *
     67  *     http://www.NetBSD.ORG/People/Pages/cgd.html
     68  */
     69 
     70 /*
     71  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
     72  * All rights reserved.
     73  *
     74  * Author: Chris G. Demetriou
     75  *
     76  * Permission to use, copy, modify and distribute this software and
     77  * its documentation is hereby granted, provided that both the copyright
     78  * notice and this permission notice appear in all copies of the
     79  * software, derivative works or modified versions, and any portions
     80  * thereof, and that both notices appear in supporting documentation.
     81  *
     82  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     83  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     84  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     85  *
     86  * Carnegie Mellon requests users of this software to return to
     87  *
     88  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     89  *  School of Computer Science
     90  *  Carnegie Mellon University
     91  *  Pittsburgh PA 15213-3890
     92  *
     93  * any improvements or extensions that they make and grant Carnegie the
     94  * rights to redistribute these changes.
     95  */
     96 
     97 #include <machine/options.h>		/* Config options headers */
     98 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     99 
    100 __KERNEL_RCSID(0, "$NetBSD: cia.c,v 1.21.4.1 1997/08/23 07:06:58 thorpej Exp $");
    101 __KERNEL_COPYRIGHT(0,
    102     "Copyright (c) 1997 Christopher G. Demetriou.  All rights reserved.");
    103 
    104 #include <sys/param.h>
    105 #include <sys/systm.h>
    106 #include <sys/kernel.h>
    107 #include <sys/malloc.h>
    108 #include <sys/device.h>
    109 #include <vm/vm.h>
    110 
    111 #include <machine/autoconf.h>
    112 #include <machine/rpb.h>
    113 
    114 #include <dev/isa/isareg.h>
    115 #include <dev/isa/isavar.h>
    116 
    117 #include <dev/pci/pcireg.h>
    118 #include <dev/pci/pcivar.h>
    119 #include <alpha/pci/ciareg.h>
    120 #include <alpha/pci/ciavar.h>
    121 #ifdef DEC_KN20AA
    122 #include <alpha/pci/pci_kn20aa.h>
    123 #endif
    124 #ifdef DEC_EB164
    125 #include <alpha/pci/pci_eb164.h>
    126 #endif
    127 
    128 int	ciamatch __P((struct device *, struct cfdata *, void *));
    129 void	ciaattach __P((struct device *, struct device *, void *));
    130 
    131 struct cfattach cia_ca = {
    132 	sizeof(struct cia_softc), ciamatch, ciaattach,
    133 };
    134 
    135 struct cfdriver cia_cd = {
    136 	NULL, "cia", DV_DULL,
    137 };
    138 
    139 static int	ciaprint __P((void *, const char *pnp));
    140 
    141 /* There can be only one. */
    142 int ciafound;
    143 struct cia_config cia_configuration;
    144 
    145 int
    146 ciamatch(parent, match, aux)
    147 	struct device *parent;
    148 	struct cfdata *match;
    149 	void *aux;
    150 {
    151 	struct confargs *ca = aux;
    152 
    153 	/* Make sure that we're looking for a CIA. */
    154 	if (strcmp(ca->ca_name, cia_cd.cd_name) != 0)
    155 		return (0);
    156 
    157 	if (ciafound)
    158 		return (0);
    159 
    160 	return (1);
    161 }
    162 
    163 /*
    164  * Set up the chipset's function pointers.
    165  */
    166 void
    167 cia_init(ccp, mallocsafe)
    168 	struct cia_config *ccp;
    169 	int mallocsafe;
    170 {
    171 
    172 	ccp->cc_pass =
    173 	    (REGVAL(CIA_CSR_CIA_REV) & CIA_REV_REV_MASK) >> CIA_REV_REV_SHIFT;
    174 	ccp->cc_is21172 = (ccp->cc_pass >= 3);
    175 	ccp->cc_bwx_enabled = ccp->cc_is21172 &&
    176 	    (REGVAL(CIA_CSR_CIA_CNFG) & CIA_CNFG_IOA_BWEN);
    177 
    178 	ccp->cc_hae_mem = REGVAL(CIA_CSR_HAE_MEM);
    179 	ccp->cc_hae_io = REGVAL(CIA_CSR_HAE_IO);
    180 
    181 	if (!ccp->cc_initted) {
    182 		/* don't do these twice since they set up extents */
    183 		ccp->cc_iot = cia_swiz_bus_io_init(ccp);
    184 		ccp->cc_memt = cia_swiz_bus_mem_init(ccp);
    185 		cia_swiz_pci_init(&ccp->cc_pc, ccp); /* no ext. yet */
    186 	}
    187 	ccp->cc_mallocsafe = mallocsafe;
    188 
    189 	cia_dma_init(ccp);
    190 
    191 	ccp->cc_initted = 1;
    192 }
    193 
    194 void
    195 ciaattach(parent, self, aux)
    196 	struct device *parent, *self;
    197 	void *aux;
    198 {
    199 	struct cia_softc *sc = (struct cia_softc *)self;
    200 	struct cia_config *ccp;
    201 	struct pcibus_attach_args pba;
    202 
    203 	/* note that we've attached the chipset; can't have 2 CIAs. */
    204 	ciafound = 1;
    205 
    206 	/*
    207 	 * set up the chipset's info; done once at console init time
    208 	 * (maybe), but we must do it here as well to take care of things
    209 	 * that need to use memory allocation.
    210 	 */
    211 	ccp = sc->sc_ccp = &cia_configuration;
    212 	cia_init(ccp, 1);
    213 
    214 	printf(": CIA pass %d (%s)", ccp->cc_pass,
    215 	    ccp->cc_is21172 ? "21172" : "21171");
    216 	if (ccp->cc_is21172)
    217 	    printf(", BWX %sabled", ccp->cc_bwx_enabled ? "en" : "dis");
    218         printf("\n");
    219 
    220 	switch (hwrpb->rpb_type) {
    221 #ifdef DEC_KN20AA
    222 	case ST_DEC_KN20AA:
    223 		pci_kn20aa_pickintr(ccp);
    224 #ifdef EVCNT_COUNTERS
    225 		evcnt_attach(self, "intr", &kn20aa_intr_evcnt);
    226 #endif
    227 		break;
    228 #endif
    229 
    230 #ifdef DEC_EB164
    231 	case ST_EB164:
    232 		pci_eb164_pickintr(ccp);
    233 #ifdef EVCNT_COUNTERS
    234 		evcnt_attach(self, "intr", &eb164_intr_evcnt);
    235 #endif
    236 		break;
    237 #endif
    238 
    239 	default:
    240 		panic("ciaattach: shouldn't be here, really...");
    241 	}
    242 
    243 	pba.pba_busname = "pci";
    244 	pba.pba_iot = ccp->cc_iot;
    245 	pba.pba_memt = ccp->cc_memt;
    246 	pba.pba_dmat = &ccp->cc_dmat_direct;
    247 	pba.pba_pc = &ccp->cc_pc;
    248 	pba.pba_bus = 0;
    249 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
    250 	config_found(self, &pba, ciaprint);
    251 }
    252 
    253 static int
    254 ciaprint(aux, pnp)
    255 	void *aux;
    256 	const char *pnp;
    257 {
    258 	register struct pcibus_attach_args *pba = aux;
    259 
    260 	/* only PCIs can attach to CIAs; easy. */
    261 	if (pnp)
    262 		printf("%s at %s", pba->pba_busname, pnp);
    263 	printf(" bus %d", pba->pba_bus);
    264 	return (UNCONF);
    265 }
    266