Home | History | Annotate | Line # | Download | only in pci
apecs.c revision 1.39
      1  1.39   thorpej /* $NetBSD: apecs.c,v 1.39 2002/05/16 01:01:31 thorpej Exp $ */
      2  1.37   thorpej 
      3  1.37   thorpej /*-
      4  1.37   thorpej  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  1.37   thorpej  * All rights reserved.
      6  1.37   thorpej  *
      7  1.37   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.37   thorpej  * by Jason R. Thorpe.
      9  1.37   thorpej  *
     10  1.37   thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.37   thorpej  * modification, are permitted provided that the following conditions
     12  1.37   thorpej  * are met:
     13  1.37   thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.37   thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.37   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.37   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.37   thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.37   thorpej  * 3. All advertising materials mentioning features or use of this software
     19  1.37   thorpej  *    must display the following acknowledgement:
     20  1.37   thorpej  *	This product includes software developed by the NetBSD
     21  1.37   thorpej  *	Foundation, Inc. and its contributors.
     22  1.37   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.37   thorpej  *    contributors may be used to endorse or promote products derived
     24  1.37   thorpej  *    from this software without specific prior written permission.
     25  1.37   thorpej  *
     26  1.37   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.37   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.37   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.37   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.37   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.37   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.37   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.37   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.37   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.37   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.37   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.37   thorpej  */
     38   1.1       cgd 
     39   1.1       cgd /*
     40   1.7       cgd  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
     41   1.1       cgd  * All rights reserved.
     42   1.1       cgd  *
     43   1.1       cgd  * Author: Chris G. Demetriou
     44   1.1       cgd  *
     45   1.1       cgd  * Permission to use, copy, modify and distribute this software and
     46   1.1       cgd  * its documentation is hereby granted, provided that both the copyright
     47   1.1       cgd  * notice and this permission notice appear in all copies of the
     48   1.1       cgd  * software, derivative works or modified versions, and any portions
     49   1.1       cgd  * thereof, and that both notices appear in supporting documentation.
     50   1.1       cgd  *
     51   1.1       cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     52   1.1       cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     53   1.1       cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     54   1.1       cgd  *
     55   1.1       cgd  * Carnegie Mellon requests users of this software to return to
     56   1.1       cgd  *
     57   1.1       cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     58   1.1       cgd  *  School of Computer Science
     59   1.1       cgd  *  Carnegie Mellon University
     60   1.1       cgd  *  Pittsburgh PA 15213-3890
     61   1.1       cgd  *
     62   1.1       cgd  * any improvements or extensions that they make and grant Carnegie the
     63   1.1       cgd  * rights to redistribute these changes.
     64   1.1       cgd  */
     65  1.20       cgd 
     66  1.27   thorpej #include "opt_dec_2100_a50.h"
     67  1.27   thorpej #include "opt_dec_eb64plus.h"
     68  1.34      ross #include "opt_dec_1000a.h"
     69  1.34      ross #include "opt_dec_1000.h"
     70  1.27   thorpej 
     71  1.21       cgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     72  1.21       cgd 
     73  1.39   thorpej __KERNEL_RCSID(0, "$NetBSD: apecs.c,v 1.39 2002/05/16 01:01:31 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.38       mrg 
     81  1.38       mrg #include <uvm/uvm_extern.h>
     82   1.1       cgd 
     83   1.1       cgd #include <machine/autoconf.h>
     84   1.1       cgd #include <machine/rpb.h>
     85  1.37   thorpej #include <machine/sysarch.h>
     86   1.1       cgd 
     87   1.1       cgd #include <dev/isa/isareg.h>
     88   1.1       cgd #include <dev/isa/isavar.h>
     89   1.1       cgd 
     90   1.1       cgd #include <dev/pci/pcireg.h>
     91   1.1       cgd #include <dev/pci/pcivar.h>
     92   1.1       cgd #include <alpha/pci/apecsreg.h>
     93   1.4       cgd #include <alpha/pci/apecsvar.h>
     94  1.18       cgd #ifdef DEC_2100_A50
     95   1.6       cgd #include <alpha/pci/pci_2100_a50.h>
     96   1.9       cgd #endif
     97  1.30   thorpej #ifdef DEC_EB64PLUS
     98  1.30   thorpej #include <alpha/pci/pci_eb64plus.h>
     99  1.30   thorpej #endif
    100  1.33      ross #ifdef DEC_1000A
    101  1.33      ross #include <alpha/pci/pci_1000a.h>
    102  1.33      ross #endif
    103  1.34      ross #ifdef DEC_1000
    104  1.34      ross #include <alpha/pci/pci_1000.h>
    105  1.34      ross #endif
    106   1.1       cgd 
    107  1.16       cgd int	apecsmatch __P((struct device *, struct cfdata *, void *));
    108   1.1       cgd void	apecsattach __P((struct device *, struct device *, void *));
    109   1.1       cgd 
    110   1.5   thorpej struct cfattach apecs_ca = {
    111   1.6       cgd 	sizeof(struct apecs_softc), apecsmatch, apecsattach,
    112   1.5   thorpej };
    113   1.5   thorpej 
    114  1.28   thorpej extern struct cfdriver apecs_cd;
    115   1.1       cgd 
    116  1.10       cgd static int	apecsprint __P((void *, const char *pnp));
    117   1.1       cgd 
    118  1.37   thorpej int	apecs_bus_get_window __P((int, int,
    119  1.37   thorpej 	    struct alpha_bus_space_translation *));
    120  1.37   thorpej 
    121   1.4       cgd /* There can be only one. */
    122   1.4       cgd int apecsfound;
    123   1.4       cgd struct apecs_config apecs_configuration;
    124   1.1       cgd 
    125   1.1       cgd int
    126   1.1       cgd apecsmatch(parent, match, aux)
    127   1.1       cgd 	struct device *parent;
    128  1.16       cgd 	struct cfdata *match;
    129  1.16       cgd 	void *aux;
    130   1.1       cgd {
    131  1.31   thorpej 	struct mainbus_attach_args *ma = aux;
    132   1.1       cgd 
    133   1.4       cgd 	/* Make sure that we're looking for an APECS. */
    134  1.31   thorpej 	if (strcmp(ma->ma_name, apecs_cd.cd_name) != 0)
    135   1.4       cgd 		return (0);
    136   1.4       cgd 
    137   1.4       cgd 	if (apecsfound)
    138   1.4       cgd 		return (0);
    139   1.1       cgd 
    140   1.1       cgd 	return (1);
    141   1.1       cgd }
    142   1.1       cgd 
    143   1.2       cgd /*
    144   1.2       cgd  * Set up the chipset's function pointers.
    145   1.2       cgd  */
    146   1.2       cgd void
    147  1.15       cgd apecs_init(acp, mallocsafe)
    148   1.4       cgd 	struct apecs_config *acp;
    149  1.15       cgd 	int mallocsafe;
    150   1.2       cgd {
    151   1.4       cgd 	acp->ac_comanche_pass2 =
    152   1.4       cgd 	    (REGVAL(COMANCHE_ED) & COMANCHE_ED_PASS2) != 0;
    153   1.4       cgd 	acp->ac_memwidth =
    154   1.4       cgd 	    (REGVAL(COMANCHE_GCR) & COMANCHE_GCR_WIDEMEM) != 0 ? 128 : 64;
    155   1.4       cgd 	acp->ac_epic_pass2 =
    156   1.4       cgd 	    (REGVAL(EPIC_DCSR) & EPIC_DCSR_PASS2) != 0;
    157   1.4       cgd 
    158  1.15       cgd 	acp->ac_haxr1 = REGVAL(EPIC_HAXR1);
    159  1.15       cgd 	acp->ac_haxr2 = REGVAL(EPIC_HAXR2);
    160  1.15       cgd 
    161  1.15       cgd 	if (!acp->ac_initted) {
    162  1.15       cgd 		/* don't do these twice since they set up extents */
    163  1.23   thorpej 		apecs_bus_io_init(&acp->ac_iot, acp);
    164  1.23   thorpej 		apecs_bus_mem_init(&acp->ac_memt, acp);
    165  1.37   thorpej 
    166  1.37   thorpej 		/*
    167  1.37   thorpej 		 * We have two I/O windows and 3 MEM windows.
    168  1.37   thorpej 		 */
    169  1.37   thorpej 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 2;
    170  1.37   thorpej 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 3;
    171  1.37   thorpej 		alpha_bus_get_window = apecs_bus_get_window;
    172  1.15       cgd 	}
    173  1.15       cgd 	acp->ac_mallocsafe = mallocsafe;
    174  1.15       cgd 
    175   1.6       cgd 	apecs_pci_init(&acp->ac_pc, acp);
    176  1.37   thorpej 	alpha_pci_chipset = &acp->ac_pc;
    177   1.4       cgd 
    178  1.15       cgd 	acp->ac_initted = 1;
    179   1.2       cgd }
    180   1.2       cgd 
    181   1.1       cgd void
    182   1.1       cgd apecsattach(parent, self, aux)
    183   1.1       cgd 	struct device *parent, *self;
    184   1.1       cgd 	void *aux;
    185   1.1       cgd {
    186   1.4       cgd 	struct apecs_softc *sc = (struct apecs_softc *)self;
    187   1.4       cgd 	struct apecs_config *acp;
    188   1.6       cgd 	struct pcibus_attach_args pba;
    189   1.4       cgd 
    190   1.4       cgd 	/* note that we've attached the chipset; can't have 2 APECSes. */
    191   1.4       cgd 	apecsfound = 1;
    192   1.4       cgd 
    193   1.4       cgd 	/*
    194   1.4       cgd 	 * set up the chipset's info; done once at console init time
    195   1.4       cgd 	 * (maybe), but doesn't hurt to do twice.
    196   1.4       cgd 	 */
    197   1.4       cgd 	acp = sc->sc_acp = &apecs_configuration;
    198  1.15       cgd 	apecs_init(acp, 1);
    199   1.1       cgd 
    200  1.32   thorpej 	apecs_dma_init(acp);
    201   1.1       cgd 
    202  1.12  christos 	printf(": DECchip %s Core Logic chipset\n",
    203   1.4       cgd 	    acp->ac_memwidth == 128 ? "21072" : "21071");
    204  1.12  christos 	printf("%s: DC21071-CA pass %d, %d-bit memory bus\n",
    205   1.4       cgd 	    self->dv_xname, acp->ac_comanche_pass2 ? 2 : 1, acp->ac_memwidth);
    206  1.12  christos 	printf("%s: DC21071-DA pass %d\n", self->dv_xname,
    207   1.4       cgd 	    acp->ac_epic_pass2 ? 2 : 1);
    208   1.1       cgd 	/* XXX print bcache size */
    209   1.1       cgd 
    210   1.4       cgd 	if (!acp->ac_epic_pass2)
    211  1.12  christos 		printf("WARNING: 21071-DA NOT PASS2... NO BETS...\n");
    212   1.1       cgd 
    213  1.35       cgd 	switch (cputype) {
    214  1.18       cgd #ifdef DEC_2100_A50
    215   1.1       cgd 	case ST_DEC_2100_A50:
    216   1.6       cgd 		pci_2100_a50_pickintr(acp);
    217  1.30   thorpej 		break;
    218  1.30   thorpej #endif
    219  1.30   thorpej 
    220  1.30   thorpej #ifdef DEC_EB64PLUS
    221  1.30   thorpej 	case ST_EB64P:
    222  1.30   thorpej 		pci_eb64plus_pickintr(acp);
    223  1.33      ross 		break;
    224  1.33      ross #endif
    225  1.33      ross 
    226  1.33      ross #ifdef DEC_1000A
    227  1.33      ross 	case ST_DEC_1000A:
    228  1.33      ross 		pci_1000a_pickintr(acp, &acp->ac_iot, &acp->ac_memt,
    229  1.34      ross 			&acp->ac_pc);
    230  1.34      ross 		break;
    231  1.34      ross #endif
    232  1.34      ross 
    233  1.34      ross #ifdef DEC_1000
    234  1.34      ross 	case ST_DEC_1000:
    235  1.34      ross 		pci_1000_pickintr(acp, &acp->ac_iot, &acp->ac_memt,
    236  1.33      ross 			&acp->ac_pc);
    237   1.1       cgd 		break;
    238   1.1       cgd #endif
    239  1.14       cgd 
    240   1.1       cgd 	default:
    241   1.1       cgd 		panic("apecsattach: shouldn't be here, really...");
    242   1.1       cgd 	}
    243   1.1       cgd 
    244   1.6       cgd 	pba.pba_busname = "pci";
    245  1.25   thorpej 	pba.pba_iot = &acp->ac_iot;
    246  1.25   thorpej 	pba.pba_memt = &acp->ac_memt;
    247  1.29   thorpej 	pba.pba_dmat =
    248  1.29   thorpej 	    alphabus_dma_get_tag(&acp->ac_dmat_direct, ALPHA_BUS_PCI);
    249   1.6       cgd 	pba.pba_pc = &acp->ac_pc;
    250   1.6       cgd 	pba.pba_bus = 0;
    251  1.39   thorpej 	pba.pba_bridgetag = NULL;
    252  1.36   thorpej 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
    253  1.36   thorpej 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
    254   1.6       cgd 	config_found(self, &pba, apecsprint);
    255   1.1       cgd }
    256   1.1       cgd 
    257   1.1       cgd static int
    258   1.1       cgd apecsprint(aux, pnp)
    259   1.1       cgd 	void *aux;
    260  1.10       cgd 	const char *pnp;
    261   1.1       cgd {
    262  1.15       cgd 	register struct pcibus_attach_args *pba = aux;
    263   1.1       cgd 
    264   1.4       cgd 	/* only PCIs can attach to APECSes; easy. */
    265   1.4       cgd 	if (pnp)
    266  1.12  christos 		printf("%s at %s", pba->pba_busname, pnp);
    267  1.12  christos 	printf(" bus %d", pba->pba_bus);
    268   1.4       cgd 	return (UNCONF);
    269  1.37   thorpej }
    270  1.37   thorpej 
    271  1.37   thorpej int
    272  1.37   thorpej apecs_bus_get_window(type, window, abst)
    273  1.37   thorpej 	int type, window;
    274  1.37   thorpej 	struct alpha_bus_space_translation *abst;
    275  1.37   thorpej {
    276  1.37   thorpej 	struct apecs_config *acp = &apecs_configuration;
    277  1.37   thorpej 	bus_space_tag_t st;
    278  1.37   thorpej 
    279  1.37   thorpej 	switch (type) {
    280  1.37   thorpej 	case ALPHA_BUS_TYPE_PCI_IO:
    281  1.37   thorpej 		st = &acp->ac_iot;
    282  1.37   thorpej 		break;
    283  1.37   thorpej 
    284  1.37   thorpej 	case ALPHA_BUS_TYPE_PCI_MEM:
    285  1.37   thorpej 		st = &acp->ac_memt;
    286  1.37   thorpej 		break;
    287  1.37   thorpej 
    288  1.37   thorpej 	default:
    289  1.37   thorpej 		panic("apecs_bus_get_window");
    290  1.37   thorpej 	}
    291  1.37   thorpej 
    292  1.37   thorpej 	return (alpha_bus_space_get_window(st, window, abst));
    293   1.1       cgd }
    294