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