Home | History | Annotate | Line # | Download | only in pci
lca.c revision 1.17
      1 /* $NetBSD: lca.c,v 1.17 1997/04/07 02:01:19 cgd Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Authors: Jeffrey Hsu and Chris G. Demetriou
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include <machine/options.h>		/* Pull in config options headers */
     31 
     32 #include <sys/param.h>
     33 #include <sys/systm.h>
     34 #include <sys/kernel.h>
     35 #include <sys/malloc.h>
     36 #include <sys/device.h>
     37 #include <vm/vm.h>
     38 
     39 #include <machine/autoconf.h>
     40 #include <machine/rpb.h>
     41 
     42 #include <dev/isa/isareg.h>
     43 #include <dev/isa/isavar.h>
     44 
     45 #include <dev/pci/pcireg.h>
     46 #include <dev/pci/pcivar.h>
     47 #include <alpha/pci/lcareg.h>
     48 #include <alpha/pci/lcavar.h>
     49 #ifdef DEC_AXPPCI_33
     50 #include <alpha/pci/pci_axppci_33.h>
     51 #endif
     52 
     53 int	lcamatch __P((struct device *, struct cfdata *, void *));
     54 void	lcaattach __P((struct device *, struct device *, void *));
     55 
     56 struct cfattach lca_ca = {
     57 	sizeof(struct lca_softc), lcamatch, lcaattach,
     58 };
     59 
     60 struct cfdriver lca_cd = {
     61 	NULL, "lca", DV_DULL,
     62 };
     63 
     64 static int	lcaprint __P((void *, const char *pnp));
     65 
     66 /* There can be only one. */
     67 int lcafound;
     68 struct lca_config lca_configuration;
     69 
     70 int
     71 lcamatch(parent, match, aux)
     72 	struct device *parent;
     73 	struct cfdata *match;
     74 	void *aux;
     75 {
     76 	struct confargs *ca = aux;
     77 
     78 	/* Make sure that we're looking for a LCA. */
     79 	if (strcmp(ca->ca_name, lca_cd.cd_name) != 0)
     80 		return (0);
     81 
     82 	if (lcafound)
     83 		return (0);
     84 
     85 	return (1);
     86 }
     87 
     88 /*
     89  * Set up the chipset's function pointers.
     90  */
     91 void
     92 lca_init(lcp, mallocsafe)
     93 	struct lca_config *lcp;
     94 	int mallocsafe;
     95 {
     96 
     97 	/*
     98 	 * Can't set up SGMAP data here; can be called before malloc().
     99 	 */
    100 
    101 	/*
    102 	 * The LCA HAE register is WRITE-ONLY, so we can't tell where
    103 	 * the second sparse window is actually mapped.  Therefore,
    104 	 * we have to guess where it is.  This seems to be the normal
    105 	 * address.
    106 	 */
    107 	lcp->lc_s_mem_w2_masked_base = 0x80000000;
    108 
    109 	if (!lcp->lc_initted) {
    110 		/* don't do these twice since they set up extents */
    111 		lcp->lc_iot = lca_bus_io_init(lcp);
    112 		lcp->lc_memt = lca_bus_mem_init(lcp);
    113 	}
    114 	lcp->lc_mallocsafe = mallocsafe;
    115 
    116 	lca_pci_init(&lcp->lc_pc, lcp);
    117 
    118 	/*
    119 	 * Refer to ``DECchip 21066 and DECchip 21068 Alpha AXP Microprocessors
    120 	 * Hardware Reference Manual''.
    121 	 * ...
    122 	 */
    123 
    124 	/*
    125 	 * According to section 6.4.1, all bits of the IOC_HAE register are
    126 	 * undefined after reset.  Bits <31:27> are write-only.  However, we
    127 	 * cannot blindly set it to zero.  The serial ROM code that initializes
    128 	 * the PCI devices' address spaces, allocates sparse memory blocks in
    129 	 * the range that must use the IOC_HAE register for address translation,
    130 	 * and sets this register accordingly (see section 6.4.14).
    131 	 *
    132 	 *	IOC_HAE left AS IS.
    133 	 */
    134 
    135 	/* According to section 6.4.2, all bits of the IOC_CONF register are
    136 	 * undefined after reset.  Bits <1:0> are write-only.  Set them to
    137 	 * 0x00 for PCI Type 0 configuration access.
    138 	 *
    139 	 *	IOC_CONF set to ZERO.
    140 	 */
    141 	REGVAL(LCA_IOC_CONF) = 0;
    142 
    143 	/* Turn off DMA window enables in Window Base Registers */
    144 /*	REGVAL(LCA_IOC_W_BASE0) = 0;
    145 	REGVAL(LCA_IOC_W_BASE1) = 0; */
    146 	alpha_mb();
    147 
    148 	/* XXX XXX BEGIN XXX XXX */
    149 	{							/* XXX */
    150 		extern vm_offset_t alpha_XXX_dmamap_or;		/* XXX */
    151 		alpha_XXX_dmamap_or = 0x40000000;		/* XXX */
    152 	}							/* XXX */
    153 	/* XXX XXX END XXX XXX */
    154 
    155 	lcp->lc_initted = 1;
    156 }
    157 
    158 #ifdef notdef
    159 void
    160 lca_init_sgmap(lcp)
    161 	struct lca_config *lcp;
    162 {
    163 
    164 	/* XXX */
    165 	lcp->lc_sgmap = malloc(1024 * 8, M_DEVBUF, M_WAITOK);
    166 	bzero(lcp->lc_sgmap, 1024 * 8);		/* clear all entries. */
    167 
    168 	REGVAL(LCA_IOC_W_BASE0) = 0;
    169 	alpha_mb();
    170 
    171 	/* Set up Translated Base Register 1; translate to sybBus addr 0. */
    172 	/* check size against APEC XXX JH */
    173 	REGVAL(LCA_IOC_T_BASE_0) = vtophys(lcp->lc_sgmap) >> 1;
    174 
    175 	/* Set up PCI mask register 1; map 8MB space. */
    176 	REGVAL(LCA_IOC_W_MASK0) = 0x00700000;
    177 
    178 	/* Enable window 1; from PCI address 8MB, direct mapped. */
    179 	REGVAL(LCA_IOC_W_BASE0) = 0x300800000;
    180 	alpha_mb();
    181 }
    182 #endif
    183 
    184 void
    185 lcaattach(parent, self, aux)
    186 	struct device *parent, *self;
    187 	void *aux;
    188 {
    189 	struct lca_softc *sc = (struct lca_softc *)self;
    190 	struct lca_config *lcp;
    191 	struct pcibus_attach_args pba;
    192 
    193 	/* note that we've attached the chipset; can't have 2 LCAs. */
    194 	/* Um, not sure about this.  XXX JH */
    195 	lcafound = 1;
    196 
    197 	/*
    198 	 * set up the chipset's info; done once at console init time
    199 	 * (maybe), but doesn't hurt to do twice.
    200 	 */
    201 	lcp = sc->sc_lcp = &lca_configuration;
    202 	lca_init(lcp, 1);
    203 #ifdef notdef
    204 	lca_init_sgmap(lcp);
    205 #endif
    206 
    207 	/* XXX print chipset information */
    208 	printf("\n");
    209 
    210 	switch (hwrpb->rpb_type) {
    211 #ifdef DEC_AXPPCI_33
    212 	case ST_DEC_AXPPCI_33:
    213 		pci_axppci_33_pickintr(lcp);
    214 		break;
    215 #endif
    216 
    217 	default:
    218 		panic("lcaattach: shouldn't be here, really...");
    219 	}
    220 
    221 	pba.pba_busname = "pci";
    222 	pba.pba_iot = lcp->lc_iot;
    223 	pba.pba_memt = lcp->lc_memt;
    224 	pba.pba_pc = &lcp->lc_pc;
    225 	pba.pba_bus = 0;
    226 	config_found(self, &pba, lcaprint);
    227 }
    228 
    229 static int
    230 lcaprint(aux, pnp)
    231 	void *aux;
    232 	const char *pnp;
    233 {
    234 	register struct pcibus_attach_args *pba = aux;
    235 
    236 	/* only PCIs can attach to LCAes; easy. */
    237 	if (pnp)
    238 		printf("%s at %s", pba->pba_busname, pnp);
    239 	printf(" bus %d", pba->pba_bus);
    240 	return (UNCONF);
    241 }
    242