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