Home | History | Annotate | Line # | Download | only in pci
lca.c revision 1.7
      1 /*	$NetBSD: lca.c,v 1.7 1996/07/11 03:30:14 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 #if defined(DEC_AXPPCI_33)
     48 #include <alpha/pci/pci_axppci_33.h>
     49 #endif
     50 
     51 int	lcamatch __P((struct device *, void *, 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 *, 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 	void *match, *aux;
     72 {
     73 	struct confargs *ca = aux;
     74 
     75 	/* Make sure that we're looking for a LCA. */
     76 	if (strcmp(ca->ca_name, lca_cd.cd_name) != 0)
     77 		return (0);
     78 
     79 	if (lcafound)
     80 		return (0);
     81 
     82 	return (1);
     83 }
     84 
     85 /*
     86  * Set up the chipset's function pointers.
     87  */
     88 void
     89 lca_init(lcp)
     90 	struct lca_config *lcp;
     91 {
     92 
     93 	/*
     94 	 * Can't set up SGMAP data here; can be called before malloc().
     95 	 */
     96 
     97 	apecs_lca_bus_io_init(&lcp->lc_bc, lcp);
     98 	apecs_lca_bus_mem_init(&lcp->lc_bc, lcp);
     99 	lca_pci_init(&lcp->lc_pc, lcp);
    100 
    101 	/*
    102 	 * Refer to ``DECchip 21066 and DECchip 21068 Alpha AXP Microprocessors
    103 	 * Hardware Reference Manual''.
    104 	 * ...
    105 	 */
    106 
    107 	/*
    108 	 * According to section 6.4.1, all bits of the IOC_HAE register are
    109 	 * undefined after reset.  Bits <31:27> are write-only.  However, we
    110 	 * cannot blindly set it to zero.  The serial ROM code that initializes
    111 	 * the PCI devices' address spaces, allocates sparse memory blocks in
    112 	 * the range that must use the IOC_HAE register for address translation,
    113 	 * and sets this register accordingly (see section 6.4.14).
    114 	 *
    115 	 *	IOC_HAE left AS IS.
    116 	 */
    117 
    118 	/* According to section 6.4.2, all bits of the IOC_CONF register are
    119 	 * undefined after reset.  Bits <1:0> are write-only.  Set them to
    120 	 * 0x00 for PCI Type 0 configuration access.
    121 	 *
    122 	 *	IOC_CONF set to ZERO.
    123 	 */
    124 	REGVAL(LCA_IOC_CONF) = 0;
    125 
    126 	/* Turn off DMA window enables in Window Base Registers */
    127 /*	REGVAL(LCA_IOC_W_BASE0) = 0;
    128 	REGVAL(LCA_IOC_W_BASE1) = 0; */
    129 	alpha_mb();
    130 }
    131 
    132 #ifdef notdef
    133 void
    134 lca_init_sgmap(lcp)
    135 	struct lca_config *lcp;
    136 {
    137 
    138 	/* XXX */
    139 	lcp->lc_sgmap = malloc(1024 * 8, M_DEVBUF, M_WAITOK);
    140 	bzero(lcp->lc_sgmap, 1024 * 8);		/* clear all entries. */
    141 
    142 	REGVAL(LCA_IOC_W_BASE0) = 0;
    143 	alpha_mb();
    144 
    145 	/* Set up Translated Base Register 1; translate to sybBus addr 0. */
    146 	/* check size against APEC XXX JH */
    147         REGVAL(LCA_IOC_T_BASE_0) = vtophys(lcp->lc_sgmap) >> 1;
    148 
    149         /* Set up PCI mask register 1; map 8MB space. */
    150         REGVAL(LCA_IOC_W_MASK0) = 0x00700000;
    151 
    152         /* Enable window 1; from PCI address 8MB, direct mapped. */
    153         REGVAL(LCA_IOC_W_BASE0) = 0x300800000;
    154         alpha_mb();
    155 }
    156 #endif
    157 
    158 void
    159 lcaattach(parent, self, aux)
    160 	struct device *parent, *self;
    161 	void *aux;
    162 {
    163 	struct lca_softc *sc = (struct lca_softc *)self;
    164 	struct lca_config *lcp;
    165 	struct pcibus_attach_args pba;
    166 
    167 	/* note that we've attached the chipset; can't have 2 LCAs. */
    168 	/* Um, not sure about this.  XXX JH */
    169 	lcafound = 1;
    170 
    171 	/*
    172 	 * set up the chipset's info; done once at console init time
    173 	 * (maybe), but doesn't hurt to do twice.
    174 	 */
    175 	lcp = sc->sc_lcp = &lca_configuration;
    176 	lca_init(lcp);
    177 #ifdef notdef
    178 	lca_init_sgmap(lcp);
    179 #endif
    180 
    181 	/* XXX print chipset information */
    182 	printf("\n");
    183 
    184 	switch (hwrpb->rpb_type) {
    185 #if defined(DEC_AXPPCI_33)
    186 	case ST_DEC_AXPPCI_33:
    187 		pci_axppci_33_pickintr(lcp);
    188 		break;
    189 #endif
    190 	default:
    191 		panic("lcaattach: shouldn't be here, really...");
    192 	}
    193 
    194 	pba.pba_busname = "pci";
    195 	pba.pba_bc = &lcp->lc_bc;
    196 	pba.pba_pc = &lcp->lc_pc;
    197 	pba.pba_bus = 0;
    198 	config_found(self, &pba, lcaprint);
    199 }
    200 
    201 static int
    202 lcaprint(aux, pnp)
    203 	void *aux;
    204 	char *pnp;
    205 {
    206         register struct pcibus_attach_args *pba = aux;
    207 
    208 	/* only PCIs can attach to LCAes; easy. */
    209 	if (pnp)
    210 		printf("%s at %s", pba->pba_busname, pnp);
    211 	printf(" bus %d", pba->pba_bus);
    212 	return (UNCONF);
    213 }
    214