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