Home | History | Annotate | Line # | Download | only in pci
irongate.c revision 1.6
      1 /* $NetBSD: irongate.c,v 1.6 2001/10/06 02:51:42 thorpej Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2000, 2001 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 of Wasabi Systems, Inc.
      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  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include "opt_api_up1000.h"
     40 
     41 #include <sys/cdefs.h>
     42 
     43 __KERNEL_RCSID(0, "$NetBSD: irongate.c,v 1.6 2001/10/06 02:51:42 thorpej Exp $");
     44 
     45 #include <sys/param.h>
     46 #include <sys/systm.h>
     47 #include <sys/device.h>
     48 #include <sys/malloc.h>
     49 
     50 #include <machine/autoconf.h>
     51 #include <machine/rpb.h>
     52 #include <machine/sysarch.h>
     53 
     54 #include <dev/isa/isareg.h>
     55 #include <dev/isa/isavar.h>
     56 #include <dev/pci/pcireg.h>
     57 #include <dev/pci/pcivar.h>
     58 #include <dev/pci/agpvar.h>
     59 
     60 #include <alpha/pci/irongatereg.h>
     61 #include <alpha/pci/irongatevar.h>
     62 
     63 #ifdef API_UP1000
     64 #include <alpha/pci/pci_up1000.h>
     65 #endif
     66 
     67 int	irongate_match(struct device *, struct cfdata *, void *);
     68 void	irongate_attach(struct device *, struct device *, void *);
     69 
     70 struct cfattach irongate_ca = {
     71 	sizeof(struct irongate_softc), irongate_match, irongate_attach,
     72 };
     73 
     74 int	irongate_print(void *, const char *pnp);
     75 
     76 extern struct cfdriver irongate_cd;
     77 
     78 /* There can be only one. */
     79 struct irongate_config irongate_configuration;
     80 int	irongate_found;
     81 
     82 int	irongate_bus_get_window(int, int,
     83 	    struct alpha_bus_space_translation *);
     84 
     85 /*
     86  * Set up the chipset's function pointers.
     87  */
     88 void
     89 irongate_init(struct irongate_config *icp, int mallocsafe)
     90 {
     91 	pcitag_t tag;
     92 	pcireg_t reg;
     93 
     94 	icp->ic_mallocsafe = mallocsafe;
     95 
     96 	/*
     97 	 * Set up PCI configuration space; we can only read the
     98 	 * revision info through configuration space.
     99 	 */
    100 	irongate_pci_init(&icp->ic_pc, icp);
    101 	alpha_pci_chipset = &icp->ic_pc;
    102 
    103 	tag = pci_make_tag(&icp->ic_pc, 0, IRONGATE_PCIHOST_DEV, 0);
    104 
    105 	/* Read the revision. */
    106 	reg = irongate_conf_read0(icp, tag, PCI_CLASS_REG);
    107 	icp->ic_rev = PCI_REVISION(reg);
    108 
    109 	if (icp->ic_initted == 0) {
    110 		/* Don't do these twice, since they set up extents. */
    111 		irongate_bus_io_init(&icp->ic_iot, icp);
    112 		irongate_bus_mem_init(&icp->ic_memt, icp);
    113 
    114 		/* Only one each PCI I/O and MEM window. */
    115 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1;
    116 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 1;
    117 
    118 		alpha_bus_get_window = irongate_bus_get_window;
    119 	}
    120 
    121 	icp->ic_initted = 1;
    122 }
    123 
    124 int
    125 irongate_match(struct device *parent, struct cfdata *match, void *aux)
    126 {
    127 	struct mainbus_attach_args *ma = aux;
    128 
    129 	/* Make sure we're looking for an Irongate. */
    130 	if (strcmp(ma->ma_name, irongate_cd.cd_name) != 0)
    131 		return (0);
    132 
    133 	if (irongate_found)
    134 		return (0);
    135 
    136 	return (1);
    137 }
    138 
    139 void
    140 irongate_attach(struct device *parent, struct device *self, void *aux)
    141 {
    142 	struct irongate_softc *sc = (void *) self;
    143 	struct irongate_config *icp;
    144 	struct pcibus_attach_args pba;
    145 	struct agpbus_attach_args apa;
    146 	pcitag_t tag;
    147 
    148 	/* Note that we've attached the chipset; can't have 2 Irongates. */
    149 	irongate_found = 1;
    150 
    151 	/*
    152 	 * Set up the chipset's info; done once at console init time
    153 	 * (maybe), but we must do it here as well to take care of things
    154 	 * that need to use memory allocation.
    155 	 */
    156 	icp = sc->sc_icp = &irongate_configuration;
    157 	irongate_init(icp, 1);
    158 
    159 	printf(": AMD 751 Core Logic + AGP Chipset, rev. %d\n", icp->ic_rev);
    160 
    161 	irongate_dma_init(icp);
    162 
    163 	/*
    164 	 * Do PCI memory initialization that needs to be deferred until
    165 	 * malloc is safe.
    166 	 */
    167 	irongate_bus_mem_init2(&icp->ic_memt, icp);
    168 
    169 	switch (cputype) {
    170 #ifdef API_UP1000
    171 	case ST_API_NAUTILUS:
    172 		pci_up1000_pickintr(icp);
    173 		break;
    174 #endif
    175 
    176 	default:
    177 		panic("irongate_attach: shouldn't be here, really...");
    178 	}
    179 
    180 	tag = pci_make_tag(&icp->ic_pc, 0, IRONGATE_PCIHOST_DEV, 0);
    181 
    182 	pba.pba_busname = "pci";
    183 	pba.pba_iot = &icp->ic_iot;
    184 	pba.pba_memt = &icp->ic_memt;
    185 	pba.pba_dmat =
    186 	    alphabus_dma_get_tag(&icp->ic_dmat_pci, ALPHA_BUS_PCI);
    187 	pba.pba_pc = &icp->ic_pc;
    188 	pba.pba_bus = 0;
    189 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
    190 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
    191 
    192 	if (pci_get_capability(&icp->ic_pc, tag, PCI_CAP_AGP,
    193 	    NULL, NULL) != 0) {
    194 		apa.apa_busname = "agp";
    195 		apa.apa_pci_args.pa_iot = pba.pba_iot;
    196 		apa.apa_pci_args.pa_memt = pba.pba_memt;
    197 		apa.apa_pci_args.pa_dmat = pba.pba_dmat;
    198 		apa.apa_pci_args.pa_pc = pba.pba_pc;
    199 		apa.apa_pci_args.pa_bus = pba.pba_bus;
    200 		apa.apa_pci_args.pa_device = IRONGATE_PCIHOST_DEV;
    201 		apa.apa_pci_args.pa_function = 0;
    202 		apa.apa_pci_args.pa_tag = tag;
    203 		apa.apa_pci_args.pa_id =
    204 		    irongate_conf_read0(icp, tag, PCI_ID_REG);
    205 		apa.apa_pci_args.pa_class =
    206 		    irongate_conf_read0(icp, tag, PCI_CLASS_REG);
    207 		apa.apa_pci_args.pa_flags = pba.pba_flags;
    208 
    209 		(void) config_found(self, &apa, irongate_print);
    210 	}
    211 
    212 	(void) config_found(self, &pba, irongate_print);
    213 }
    214 
    215 int
    216 irongate_print(void *aux, const char *pnp)
    217 {
    218 	struct pcibus_attach_args *pba = aux;
    219 
    220 	/* Only PCIs can attach to Irongates; easy. */
    221 	if (pnp != NULL)
    222 		printf("%s at %s", pba->pba_busname, pnp);
    223 	if (strcmp(pba->pba_busname, "pci") == 0)
    224 		printf(" bus %d", pba->pba_bus);
    225 	return (UNCONF);
    226 }
    227 
    228 int
    229 irongate_bus_get_window(int type, int window,
    230     struct alpha_bus_space_translation *abst)
    231 {
    232 	struct irongate_config *icp = &irongate_configuration;
    233 	bus_space_tag_t st;
    234 	int error;
    235 
    236 	switch (type) {
    237 	case ALPHA_BUS_TYPE_PCI_IO:
    238 		st = &icp->ic_iot;
    239 		break;
    240 
    241 	case ALPHA_BUS_TYPE_PCI_MEM:
    242 		st = &icp->ic_memt;
    243 		break;
    244 
    245 	default:
    246 		panic("irongate_bus_get_window");
    247 	}
    248 
    249 	error = alpha_bus_space_get_window(st, window, abst);
    250 	if (error)
    251 		return (error);
    252 
    253 	abst->abst_sys_start = IRONGATE_PHYSADDR(abst->abst_sys_start);
    254 	abst->abst_sys_end = IRONGATE_PHYSADDR(abst->abst_sys_end);
    255 
    256 	return (0);
    257 }
    258