Home | History | Annotate | Line # | Download | only in pci
cia.c revision 1.42
      1  1.42   thorpej /* $NetBSD: cia.c,v 1.42 1998/06/05 19:25:19 thorpej Exp $ */
      2  1.42   thorpej 
      3  1.42   thorpej /*-
      4  1.42   thorpej  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.42   thorpej  * All rights reserved.
      6  1.42   thorpej  *
      7  1.42   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.42   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.42   thorpej  * NASA Ames Research Center.
     10  1.42   thorpej  *
     11  1.42   thorpej  * Redistribution and use in source and binary forms, with or without
     12  1.42   thorpej  * modification, are permitted provided that the following conditions
     13  1.42   thorpej  * are met:
     14  1.42   thorpej  * 1. Redistributions of source code must retain the above copyright
     15  1.42   thorpej  *    notice, this list of conditions and the following disclaimer.
     16  1.42   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.42   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18  1.42   thorpej  *    documentation and/or other materials provided with the distribution.
     19  1.42   thorpej  * 3. All advertising materials mentioning features or use of this software
     20  1.42   thorpej  *    must display the following acknowledgement:
     21  1.42   thorpej  *	This product includes software developed by the NetBSD
     22  1.42   thorpej  *	Foundation, Inc. and its contributors.
     23  1.42   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.42   thorpej  *    contributors may be used to endorse or promote products derived
     25  1.42   thorpej  *    from this software without specific prior written permission.
     26  1.42   thorpej  *
     27  1.42   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.42   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.42   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.42   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.42   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.42   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.42   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.42   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.42   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.42   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.42   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38  1.42   thorpej  */
     39   1.1       cgd 
     40   1.1       cgd /*
     41   1.4       cgd  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
     42   1.1       cgd  * All rights reserved.
     43   1.1       cgd  *
     44   1.1       cgd  * Author: Chris G. Demetriou
     45   1.1       cgd  *
     46   1.1       cgd  * Permission to use, copy, modify and distribute this software and
     47   1.1       cgd  * its documentation is hereby granted, provided that both the copyright
     48   1.1       cgd  * notice and this permission notice appear in all copies of the
     49   1.1       cgd  * software, derivative works or modified versions, and any portions
     50   1.1       cgd  * thereof, and that both notices appear in supporting documentation.
     51   1.1       cgd  *
     52   1.1       cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     53   1.1       cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     54   1.1       cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     55   1.1       cgd  *
     56   1.1       cgd  * Carnegie Mellon requests users of this software to return to
     57   1.1       cgd  *
     58   1.1       cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     59   1.1       cgd  *  School of Computer Science
     60   1.1       cgd  *  Carnegie Mellon University
     61   1.1       cgd  *  Pittsburgh PA 15213-3890
     62   1.1       cgd  *
     63   1.1       cgd  * any improvements or extensions that they make and grant Carnegie the
     64   1.1       cgd  * rights to redistribute these changes.
     65   1.1       cgd  */
     66  1.18       cgd 
     67  1.25   thorpej #include "opt_dec_eb164.h"
     68  1.25   thorpej #include "opt_dec_kn20aa.h"
     69  1.39   thorpej #include "opt_dec_550.h"
     70  1.25   thorpej 
     71  1.19       cgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     72  1.19       cgd 
     73  1.42   thorpej __KERNEL_RCSID(0, "$NetBSD: cia.c,v 1.42 1998/06/05 19:25:19 thorpej Exp $");
     74   1.1       cgd 
     75   1.1       cgd #include <sys/param.h>
     76   1.1       cgd #include <sys/systm.h>
     77   1.1       cgd #include <sys/kernel.h>
     78   1.1       cgd #include <sys/malloc.h>
     79   1.1       cgd #include <sys/device.h>
     80   1.1       cgd #include <vm/vm.h>
     81   1.1       cgd 
     82   1.1       cgd #include <machine/autoconf.h>
     83   1.1       cgd #include <machine/rpb.h>
     84   1.1       cgd 
     85   1.1       cgd #include <dev/isa/isareg.h>
     86   1.1       cgd #include <dev/isa/isavar.h>
     87   1.1       cgd 
     88   1.1       cgd #include <dev/pci/pcireg.h>
     89   1.1       cgd #include <dev/pci/pcivar.h>
     90   1.1       cgd #include <alpha/pci/ciareg.h>
     91   1.1       cgd #include <alpha/pci/ciavar.h>
     92  1.17       cgd #ifdef DEC_KN20AA
     93   1.1       cgd #include <alpha/pci/pci_kn20aa.h>
     94   1.1       cgd #endif
     95  1.17       cgd #ifdef DEC_EB164
     96  1.13       cgd #include <alpha/pci/pci_eb164.h>
     97  1.13       cgd #endif
     98  1.39   thorpej #ifdef DEC_550
     99  1.39   thorpej #include <alpha/pci/pci_550.h>
    100  1.39   thorpej #endif
    101   1.1       cgd 
    102  1.15       cgd int	ciamatch __P((struct device *, struct cfdata *, void *));
    103   1.1       cgd void	ciaattach __P((struct device *, struct device *, void *));
    104   1.1       cgd 
    105   1.5       cgd struct cfattach cia_ca = {
    106   1.5       cgd 	sizeof(struct cia_softc), ciamatch, ciaattach,
    107   1.5       cgd };
    108   1.5       cgd 
    109  1.29   thorpej extern struct cfdriver cia_cd;
    110   1.1       cgd 
    111   1.9       cgd static int	ciaprint __P((void *, const char *pnp));
    112   1.1       cgd 
    113   1.1       cgd /* There can be only one. */
    114   1.1       cgd int ciafound;
    115   1.1       cgd struct cia_config cia_configuration;
    116   1.1       cgd 
    117  1.37   thorpej /*
    118  1.37   thorpej  * This determines if we attempt to use BWX for PCI bus and config space
    119  1.37   thorpej  * access.  Some systems, notably with Pyxis, don't fare so well unless
    120  1.37   thorpej  * BWX is used.
    121  1.37   thorpej  */
    122  1.37   thorpej #ifndef CIA_USE_BWX
    123  1.37   thorpej #define	CIA_USE_BWX	1
    124  1.37   thorpej #endif
    125  1.37   thorpej 
    126  1.37   thorpej int	cia_use_bwx = CIA_USE_BWX;
    127  1.37   thorpej 
    128   1.1       cgd int
    129   1.1       cgd ciamatch(parent, match, aux)
    130   1.1       cgd 	struct device *parent;
    131  1.15       cgd 	struct cfdata *match;
    132  1.15       cgd 	void *aux;
    133   1.1       cgd {
    134  1.35   thorpej 	struct mainbus_attach_args *ma = aux;
    135   1.1       cgd 
    136   1.1       cgd 	/* Make sure that we're looking for a CIA. */
    137  1.35   thorpej 	if (strcmp(ma->ma_name, cia_cd.cd_name) != 0)
    138   1.1       cgd 		return (0);
    139   1.1       cgd 
    140   1.1       cgd 	if (ciafound)
    141   1.1       cgd 		return (0);
    142   1.1       cgd 
    143   1.1       cgd 	return (1);
    144   1.1       cgd }
    145   1.1       cgd 
    146   1.1       cgd /*
    147   1.1       cgd  * Set up the chipset's function pointers.
    148   1.1       cgd  */
    149   1.1       cgd void
    150  1.14       cgd cia_init(ccp, mallocsafe)
    151   1.1       cgd 	struct cia_config *ccp;
    152  1.14       cgd 	int mallocsafe;
    153   1.1       cgd {
    154   1.1       cgd 
    155   1.6       cgd 	ccp->cc_hae_mem = REGVAL(CIA_CSR_HAE_MEM);
    156   1.6       cgd 	ccp->cc_hae_io = REGVAL(CIA_CSR_HAE_IO);
    157  1.36   thorpej 	ccp->cc_rev = REGVAL(CIA_CSR_REV) & REV_MASK;
    158  1.36   thorpej 
    159  1.36   thorpej 	/*
    160  1.36   thorpej 	 * Determine if we have a Pyxis.  Only two systypes can
    161  1.36   thorpej 	 * have this: the EB164 systype (AlphaPC164LX and AlphaPC164SX)
    162  1.36   thorpej 	 * and the DEC_550 systype (Miata).
    163  1.36   thorpej 	 */
    164  1.36   thorpej 	if ((hwrpb->rpb_type == ST_EB164 &&
    165  1.36   thorpej 	     (hwrpb->rpb_variation & SV_ST_MASK) >= SV_ST_ALPHAPC164LX_400) ||
    166  1.36   thorpej 	    hwrpb->rpb_type == ST_DEC_550)
    167  1.36   thorpej 		ccp->cc_flags |= CCF_ISPYXIS;
    168  1.27   thorpej 
    169  1.27   thorpej 	/*
    170  1.40   thorpej 	 * ALCOR/ALCOR2 Revisions >= 2 and Pyxis have the CNFG register.
    171  1.27   thorpej 	 */
    172  1.40   thorpej 	if (ccp->cc_rev >= 2 || (ccp->cc_flags & CCF_ISPYXIS) != 0)
    173  1.27   thorpej 		ccp->cc_cnfg = REGVAL(CIA_CSR_CNFG);
    174  1.27   thorpej 	else
    175  1.27   thorpej 		ccp->cc_cnfg = 0;
    176  1.12       cgd 
    177  1.37   thorpej 	/*
    178  1.37   thorpej 	 * Use BWX iff:
    179  1.37   thorpej 	 *
    180  1.37   thorpej 	 *	- It hasn't been disbled by the user,
    181  1.37   thorpej 	 *	- it's enabled in CNFG,
    182  1.37   thorpej 	 *	- we're implementation version ev5,
    183  1.37   thorpej 	 *	- BWX is enabled in the CPU's capabilities mask (yes,
    184  1.37   thorpej 	 *	  the bit is really cleared if the capability exists...)
    185  1.37   thorpej 	 */
    186  1.37   thorpej 	if (cia_use_bwx != 0 &&
    187  1.37   thorpej 	    (ccp->cc_cnfg & CNFG_BWEN) != 0 &&
    188  1.37   thorpej 	    alpha_implver() == ALPHA_IMPLVER_EV5 &&
    189  1.38   thorpej 	    alpha_amask(ALPHA_AMASK_BWX) == 0) {
    190  1.38   thorpej 		u_int32_t ctrl;
    191  1.38   thorpej 
    192  1.37   thorpej 		ccp->cc_flags |= CCF_USEBWX;
    193  1.38   thorpej 
    194  1.38   thorpej 		/*
    195  1.38   thorpej 		 * For whatever reason, the firmware seems to enable PCI
    196  1.38   thorpej 		 * loopback mode if it also enables BWX.  Make sure it's
    197  1.38   thorpej 		 * enabled if we have an old, buggy firmware rev.
    198  1.38   thorpej 		 */
    199  1.38   thorpej 		alpha_mb();
    200  1.38   thorpej 		ctrl = REGVAL(CIA_CSR_CTRL);
    201  1.38   thorpej 		if ((ctrl & CTRL_PCI_LOOP_EN) == 0) {
    202  1.38   thorpej 			REGVAL(CIA_CSR_CTRL) = ctrl | CTRL_PCI_LOOP_EN;
    203  1.38   thorpej 			alpha_mb();
    204  1.38   thorpej 		}
    205  1.38   thorpej 	}
    206  1.37   thorpej 
    207  1.14       cgd 	if (!ccp->cc_initted) {
    208  1.14       cgd 		/* don't do these twice since they set up extents */
    209  1.37   thorpej 		if (ccp->cc_flags & CCF_USEBWX) {
    210  1.37   thorpej 			cia_bwx_bus_io_init(&ccp->cc_iot, ccp);
    211  1.37   thorpej 			cia_bwx_bus_mem_init(&ccp->cc_memt, ccp);
    212  1.37   thorpej 		} else {
    213  1.37   thorpej 			cia_swiz_bus_io_init(&ccp->cc_iot, ccp);
    214  1.37   thorpej 			cia_swiz_bus_mem_init(&ccp->cc_memt, ccp);
    215  1.37   thorpej 		}
    216  1.14       cgd 	}
    217  1.14       cgd 	ccp->cc_mallocsafe = mallocsafe;
    218  1.14       cgd 
    219  1.14       cgd 	cia_pci_init(&ccp->cc_pc, ccp);
    220  1.14       cgd 
    221  1.21   thorpej 	cia_dma_init(ccp);
    222  1.14       cgd 
    223  1.14       cgd 	ccp->cc_initted = 1;
    224   1.1       cgd }
    225   1.1       cgd 
    226   1.1       cgd void
    227   1.1       cgd ciaattach(parent, self, aux)
    228   1.1       cgd 	struct device *parent, *self;
    229   1.1       cgd 	void *aux;
    230   1.1       cgd {
    231   1.1       cgd 	struct cia_softc *sc = (struct cia_softc *)self;
    232   1.1       cgd 	struct cia_config *ccp;
    233   1.5       cgd 	struct pcibus_attach_args pba;
    234  1.28   thorpej 	char bits[64];
    235   1.1       cgd 
    236   1.1       cgd 	/* note that we've attached the chipset; can't have 2 CIAs. */
    237   1.1       cgd 	ciafound = 1;
    238   1.1       cgd 
    239   1.1       cgd 	/*
    240   1.1       cgd 	 * set up the chipset's info; done once at console init time
    241  1.21   thorpej 	 * (maybe), but we must do it here as well to take care of things
    242  1.21   thorpej 	 * that need to use memory allocation.
    243   1.1       cgd 	 */
    244   1.1       cgd 	ccp = sc->sc_ccp = &cia_configuration;
    245  1.14       cgd 	cia_init(ccp, 1);
    246   1.1       cgd 
    247  1.36   thorpej 	printf(": DECchip 2117x Core Logic Chipset (%s), pass %d\n",
    248  1.36   thorpej 	    (ccp->cc_flags & CCF_ISPYXIS) ? "Pyxis" : "ALCOR/ALCOR2",
    249  1.36   thorpej 	    ccp->cc_rev + 1);
    250  1.28   thorpej 	if (ccp->cc_cnfg)
    251  1.28   thorpej 		printf("%s: extended capabilities: %s\n", self->dv_xname,
    252  1.28   thorpej 		    bitmask_snprintf(ccp->cc_cnfg, CIA_CSR_CNFG_BITS,
    253  1.28   thorpej 		    bits, sizeof(bits)));
    254  1.37   thorpej #if 1
    255  1.37   thorpej 	if (ccp->cc_flags & CCF_USEBWX)
    256  1.37   thorpej 		printf("%s: using BWX for PCI config and device access\n",
    257  1.37   thorpej 		    self->dv_xname);
    258  1.37   thorpej #endif
    259  1.41   thorpej 
    260  1.42   thorpej #ifdef DEC_550
    261  1.42   thorpej 	if (hwrpb->rpb_type == ST_DEC_550 &&
    262  1.42   thorpej 	    (hwrpb->rpb_variation & SV_ST_MASK) < SV_ST_MIATA_1_5) {
    263  1.41   thorpej 		/*
    264  1.42   thorpej 		 * Miata 1 systems have a bug: DMA cannot cross
    265  1.41   thorpej 		 * an 8k boundary!  Make sure PCI read prefetching
    266  1.41   thorpej 		 * is disabled on these chips.  Note that secondary
    267  1.41   thorpej 		 * PCI busses don't have this problem, because of
    268  1.41   thorpej 		 * the way PPBs handle PCI read requests.
    269  1.41   thorpej 		 *
    270  1.42   thorpej 		 * In the 21174 Technical Reference Manual, this is
    271  1.42   thorpej 		 * actually documented as "Pyxis Pass 1", but apparently
    272  1.42   thorpej 		 * there are chips that report themselves as "Pass 1"
    273  1.42   thorpej 		 * which do not have the bug!  Miatas with the Cypress
    274  1.42   thorpej 		 * PCI-ISA bridge (i.e. Miata 1.5 and Miata 2) do not
    275  1.42   thorpej 		 * have the bug, so we use this check.
    276  1.42   thorpej 		 *
    277  1.41   thorpej 		 * XXX We also need to deal with this boundary constraint
    278  1.41   thorpej 		 * XXX in the PCI bus 0 (and ISA) DMA tags, but some
    279  1.41   thorpej 		 * XXX drivers are going to need to be changed first.
    280  1.41   thorpej 		 */
    281  1.41   thorpej 		u_int32_t ctrl;
    282  1.41   thorpej 
    283  1.41   thorpej 		/* XXX no bets... */
    284  1.41   thorpej 		printf("%s: WARNING: Pyxis pass 1 DMA bug; no bets...\n",
    285  1.41   thorpej 		    self->dv_xname);
    286  1.41   thorpej 
    287  1.41   thorpej 		alpha_mb();
    288  1.41   thorpej 		ctrl = REGVAL(CIA_CSR_CTRL);
    289  1.41   thorpej 		ctrl &= ~(CTRL_RD_TYPE|CTRL_RL_TYPE|CTRL_RM_TYPE);
    290  1.41   thorpej 		REGVAL(CIA_CSR_CTRL) = ctrl;
    291  1.41   thorpej 		alpha_mb();
    292  1.41   thorpej 	}
    293  1.42   thorpej #endif /* DEC_550 */
    294   1.1       cgd 
    295   1.1       cgd 	switch (hwrpb->rpb_type) {
    296  1.17       cgd #ifdef DEC_KN20AA
    297   1.1       cgd 	case ST_DEC_KN20AA:
    298   1.5       cgd 		pci_kn20aa_pickintr(ccp);
    299   1.1       cgd #ifdef EVCNT_COUNTERS
    300   1.1       cgd 		evcnt_attach(self, "intr", &kn20aa_intr_evcnt);
    301   1.1       cgd #endif
    302   1.1       cgd 		break;
    303   1.1       cgd #endif
    304  1.13       cgd 
    305  1.17       cgd #ifdef DEC_EB164
    306  1.13       cgd 	case ST_EB164:
    307  1.13       cgd 		pci_eb164_pickintr(ccp);
    308  1.13       cgd #ifdef EVCNT_COUNTERS
    309  1.13       cgd 		evcnt_attach(self, "intr", &eb164_intr_evcnt);
    310  1.39   thorpej #endif
    311  1.39   thorpej 		break;
    312  1.39   thorpej #endif
    313  1.39   thorpej 
    314  1.39   thorpej #ifdef DEC_550
    315  1.39   thorpej 	case ST_DEC_550:
    316  1.39   thorpej 		pci_550_pickintr(ccp);
    317  1.39   thorpej #ifdef EVCNT_COUNTERS
    318  1.39   thorpej 		evcnt_attach(self, "intr", &dec_550_intr_evcnt);
    319  1.13       cgd #endif
    320  1.13       cgd 		break;
    321  1.13       cgd #endif
    322  1.13       cgd 
    323   1.1       cgd 	default:
    324   1.1       cgd 		panic("ciaattach: shouldn't be here, really...");
    325   1.1       cgd 	}
    326   1.1       cgd 
    327   1.5       cgd 	pba.pba_busname = "pci";
    328  1.23   thorpej 	pba.pba_iot = &ccp->cc_iot;
    329  1.23   thorpej 	pba.pba_memt = &ccp->cc_memt;
    330  1.30   thorpej 	pba.pba_dmat =
    331  1.30   thorpej 	    alphabus_dma_get_tag(&ccp->cc_dmat_direct, ALPHA_BUS_PCI);
    332   1.5       cgd 	pba.pba_pc = &ccp->cc_pc;
    333   1.5       cgd 	pba.pba_bus = 0;
    334  1.20       cgd 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
    335   1.5       cgd 	config_found(self, &pba, ciaprint);
    336   1.1       cgd }
    337   1.1       cgd 
    338   1.1       cgd static int
    339   1.1       cgd ciaprint(aux, pnp)
    340   1.1       cgd 	void *aux;
    341   1.9       cgd 	const char *pnp;
    342   1.1       cgd {
    343   1.5       cgd 	register struct pcibus_attach_args *pba = aux;
    344   1.1       cgd 
    345   1.1       cgd 	/* only PCIs can attach to CIAs; easy. */
    346   1.1       cgd 	if (pnp)
    347  1.11  christos 		printf("%s at %s", pba->pba_busname, pnp);
    348  1.11  christos 	printf(" bus %d", pba->pba_bus);
    349   1.1       cgd 	return (UNCONF);
    350   1.1       cgd }
    351