Home | History | Annotate | Line # | Download | only in pci
irongate.c revision 1.2
      1 /* $NetBSD: irongate.c,v 1.2 2000/06/26 18:19:26 thorpej 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  * 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.2 2000/06/26 18:19:26 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 
     59 #include <alpha/pci/irongatereg.h>
     60 #include <alpha/pci/irongatevar.h>
     61 
     62 #ifdef API_UP1000
     63 #include <alpha/pci/pci_up1000.h>
     64 #endif
     65 
     66 int	irongate_match(struct device *, struct cfdata *, void *);
     67 void	irongate_attach(struct device *, struct device *, void *);
     68 
     69 struct cfattach irongate_ca = {
     70 	sizeof(struct irongate_softc), irongate_match, irongate_attach,
     71 };
     72 
     73 int	irongate_print(void *, const char *pnp);
     74 
     75 extern struct cfdriver irongate_cd;
     76 
     77 /* There can be only one. */
     78 struct irongate_config irongate_configuration;
     79 int	irongate_found;
     80 
     81 int	irongate_bus_get_window(int, int,
     82 	    struct alpha_bus_space_translation *);
     83 
     84 /*
     85  * Set up the chipset's function pointers.
     86  */
     87 void
     88 irongate_init(struct irongate_config *icp, int mallocsafe)
     89 {
     90 	pcitag_t tag;
     91 	pcireg_t reg;
     92 
     93 	icp->ic_mallocsafe = mallocsafe;
     94 
     95 	/*
     96 	 * Set up PCI configuration space; we can only read the
     97 	 * revision info through configuration space.
     98 	 */
     99 	irongate_pci_init(&icp->ic_pc, icp);
    100 	alpha_pci_chipset = &icp->ic_pc;
    101 
    102 	tag = pci_make_tag(&icp->ic_pc, 0, IRONGATE_PCIHOST_DEV, 0);
    103 
    104 	/* Read the revision. */
    105 	reg = irongate_conf_read0(icp, tag, PCI_CLASS_REG);
    106 	icp->ic_rev = PCI_REVISION(reg);
    107 
    108 	if (icp->ic_initted == 0) {
    109 		/* Don't do these twice, since they set up extents. */
    110 		irongate_bus_io_init(&icp->ic_iot, icp);
    111 		irongate_bus_mem_init(&icp->ic_memt, icp);
    112 
    113 		/* Only one each PCI I/O and MEM window. */
    114 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1;
    115 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 1;
    116 
    117 		alpha_bus_get_window = irongate_bus_get_window;
    118 	}
    119 
    120 	icp->ic_initted = 1;
    121 }
    122 
    123 int
    124 irongate_match(struct device *parent, struct cfdata *match, void *aux)
    125 {
    126 	struct mainbus_attach_args *ma = aux;
    127 
    128 	/* Make sure we're looking for an Irongate. */
    129 	if (strcmp(ma->ma_name, irongate_cd.cd_name) != 0)
    130 		return (0);
    131 
    132 	if (irongate_found)
    133 		return (0);
    134 
    135 	return (1);
    136 }
    137 
    138 void
    139 irongate_attach(struct device *parent, struct device *self, void *aux)
    140 {
    141 	struct irongate_softc *sc = (void *) self;
    142 	struct irongate_config *icp;
    143 	struct pcibus_attach_args pba;
    144 
    145 	/* Note that we've attached the chipset; can't have 2 Irongates. */
    146 	irongate_found = 1;
    147 
    148 	/*
    149 	 * Set up the chipset's info; done once at console init time
    150 	 * (maybe), but we must do it here as well to take care of things
    151 	 * that need to use memory allocation.
    152 	 */
    153 	icp = sc->sc_icp = &irongate_configuration;
    154 	irongate_init(icp, 1);
    155 
    156 	printf(": AMD 751 Core Logic + AGP Chipset, rev. %d\n", icp->ic_rev);
    157 
    158 	irongate_dma_init(icp);
    159 
    160 	switch (cputype) {
    161 #ifdef API_UP1000
    162 	case ST_API_NAUTILUS:
    163 		pci_up1000_pickintr(icp);
    164 		break;
    165 #endif
    166 
    167 	default:
    168 		panic("irongate_attach: shouldn't be here, really...");
    169 	}
    170 
    171 	pba.pba_busname = "pci";
    172 	pba.pba_iot = &icp->ic_iot;
    173 	pba.pba_memt = &icp->ic_memt;
    174 	pba.pba_dmat =
    175 	    alphabus_dma_get_tag(&icp->ic_dmat_pci, ALPHA_BUS_PCI);
    176 	pba.pba_pc = &icp->ic_pc;
    177 	pba.pba_bus = 0;
    178 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
    179 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
    180 	(void) config_found(self, &pba, irongate_print);
    181 }
    182 
    183 int
    184 irongate_print(void *aux, const char *pnp)
    185 {
    186 	struct pcibus_attach_args *pba = aux;
    187 
    188 	/* Only PCIs can attach to Irongates; easy. */
    189 	if (pnp != NULL)
    190 		printf("%s at %s", pba->pba_busname, pnp);
    191 	printf(" bus %d", pba->pba_bus);
    192 	return (UNCONF);
    193 }
    194 
    195 int
    196 irongate_bus_get_window(int type, int window,
    197     struct alpha_bus_space_translation *abst)
    198 {
    199 	struct irongate_config *icp = &irongate_configuration;
    200 	bus_space_tag_t st;
    201 	int error;
    202 
    203 	switch (type) {
    204 	case ALPHA_BUS_TYPE_PCI_IO:
    205 		st = &icp->ic_iot;
    206 		break;
    207 
    208 	case ALPHA_BUS_TYPE_PCI_MEM:
    209 		st = &icp->ic_memt;
    210 		break;
    211 
    212 	default:
    213 		panic("irongate_bus_get_window");
    214 	}
    215 
    216 	error = alpha_bus_space_get_window(st, window, abst);
    217 	if (error)
    218 		return (error);
    219 
    220 	abst->abst_sys_start = IRONGATE_PHYSADDR(abst->abst_sys_start);
    221 	abst->abst_sys_end = IRONGATE_PHYSADDR(abst->abst_sys_end);
    222 
    223 	return (0);
    224 }
    225