Home | History | Annotate | Line # | Download | only in pci
mcpcia.c revision 1.1
      1 /* $NetBSD: mcpcia.c,v 1.1 1998/04/15 00:50:14 mjacob Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1998 by Matthew Jacob
      5  * NASA AMES Research Center.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice immediately at the beginning of the file, without modification,
     13  *    this list of conditions, and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     24  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30  * SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * MCPCIA mcbus to PCI bus adapter
     35  * found on AlphaServer 4100 systems.
     36  */
     37 
     38 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     39 
     40 __KERNEL_RCSID(0, "$NetBSD: mcpcia.c,v 1.1 1998/04/15 00:50:14 mjacob Exp $");
     41 
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 #include <sys/device.h>
     45 #include <sys/malloc.h>
     46 
     47 #include <machine/autoconf.h>
     48 #include <machine/rpb.h>
     49 #include <machine/pte.h>
     50 
     51 #include <alpha/mcbus/mcbusreg.h>
     52 #include <alpha/mcbus/mcbusvar.h>
     53 #include <alpha/pci/mcpciareg.h>
     54 #include <alpha/pci/mcpciavar.h>
     55 #include <alpha/pci/pci_kn300.h>
     56 
     57 struct mcpcia_softc *mcpcias = NULL;
     58 static struct mcpcia_softc *mcpcia_lt = NULL;
     59 
     60 #define KV(_addr)	((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
     61 #define	MCPCIA_SYSBASE(sc)	\
     62 	((((unsigned long) (sc)->mcpcia_gid) << MCBUS_GID_SHIFT) | \
     63 	 (((unsigned long) (sc)->mcpcia_mid) << MCBUS_MID_SHIFT) | \
     64 	 (MCBUS_IOSPACE))
     65 
     66 static int	mcpciamatch __P((struct device *, struct cfdata *, void *));
     67 static void	mcpciaattach __P((struct device *, struct device *, void *));
     68 struct cfattach mcpcia_ca = {
     69 	sizeof(struct mcpcia_softc), mcpciamatch, mcpciaattach
     70 };
     71 
     72 static int	mcpciaprint __P((void *, const char *));
     73 void	mcpcia_intr_establish __P((struct confargs *, int (*)(void *), void *));
     74 void	mcpcia_intr_disestablish __P((struct confargs *));
     75 caddr_t	mcpcia_cvtaddr __P((struct confargs *));
     76 int	mcpcia_matchname __P((struct confargs *, char *));
     77 
     78 static int
     79 mcpciaprint(aux, pnp)
     80 	void *aux;
     81 	const char *pnp;
     82 {
     83 	register struct pcibus_attach_args *pba = aux;
     84 	/* only PCIs can attach to MCPCIA for now */
     85 	if (pnp)
     86 		printf("%s at %s", pba->pba_busname, pnp);
     87 	printf(" bus %d", pba->pba_bus);
     88 	return (UNCONF);
     89 }
     90 
     91 static int
     92 mcpciamatch(parent, cf, aux)
     93 	struct device *parent;
     94 	struct cfdata *cf;
     95 	void *aux;
     96 {
     97 	struct mcbus_dev_attach_args *ma = aux;
     98 	if (ma->ma_type == MCBUS_TYPE_PCI)
     99 		return (1);
    100 	return (0);
    101 }
    102 
    103 static void
    104 mcpciaattach(parent, self, aux)
    105 	struct device *parent;
    106 	struct device *self;
    107 	void *aux;
    108 {
    109 	static int first = 1;
    110 	struct mcbus_dev_attach_args *ma = aux;
    111 	struct mcpcia_softc *mcp = (struct mcpcia_softc *)self;
    112 	struct pcibus_attach_args pba;
    113 
    114 	mcp->mcpcia_dev = *self;
    115 	mcp->mcpcia_mid = ma->ma_mid;
    116 	mcp->mcpcia_gid = ma->ma_gid;
    117 
    118 	printf("\n");
    119 
    120 	mcpcia_init(mcp);
    121 
    122 
    123 	mcp->mcpcia_next = NULL;
    124 	if (mcpcia_lt == NULL) {
    125 		mcpcias = mcp;
    126 	} else {
    127 		mcpcia_lt->mcpcia_next = mcp;
    128 	}
    129 	mcpcia_lt = mcp;
    130 
    131 	/*
    132 	 * Set up interrupts
    133 	 */
    134 	pci_kn300_pickintr(&mcp->mcpcia_cc, first);
    135 #ifdef	EVCNT_COUNTERS
    136 	if (first == 1) {
    137 		evcnt_attach(self, "intr", kn300_intr_evcnt);
    138 		first = 0;
    139 	}
    140 #else
    141 	first = 0;
    142 #endif
    143 
    144 	/*
    145 	 * Attach PCI bus
    146 	 */
    147 	pba.pba_busname = "pci";
    148 	pba.pba_iot = &mcp->mcpcia_cc.cc_iot;
    149 	pba.pba_memt = &mcp->mcpcia_cc.cc_memt;
    150 	pba.pba_dmat =	/* start with direct, may change... */
    151 	    alphabus_dma_get_tag(&mcp->mcpcia_cc.cc_dmat_direct, ALPHA_BUS_PCI);
    152 	pba.pba_pc = &mcp->mcpcia_cc.cc_pc;
    153 	pba.pba_bus = 0;
    154 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
    155 	config_found(self, &pba, mcpciaprint);
    156 }
    157 
    158 void
    159 mcpcia_init(mcp)
    160 	struct mcpcia_softc *mcp;
    161 {
    162 	u_int32_t ctl;
    163 	struct mcpcia_config *ccp = &mcp->mcpcia_cc;
    164 
    165 	if (ccp->cc_initted == 0) {
    166 		mcpcia_bus_io_init(&ccp->cc_iot, ccp);
    167 		mcpcia_bus_mem_init(&ccp->cc_memt, ccp);
    168 	}
    169 	mcpcia_pci_init(&ccp->cc_pc, ccp);
    170 	ccp->cc_sc = mcp;
    171 
    172 	/*
    173 	 * Establish a precalculated base for convenience's sake.
    174 	 */
    175 	ccp->cc_sysbase = MCPCIA_SYSBASE(mcp);
    176 
    177 
    178 	ctl = REGVAL(MCPCIA_PCI_REV(mcp));
    179 	printf("%s: Horse Revision %d, %s Handed Saddle Revision %d,"
    180 	    " CAP Revision %d\n", mcp->mcpcia_dev.dv_xname, HORSE_REV(ctl),
    181 	    (SADDLE_TYPE(ctl) & 1)? "Right": "Left", SADDLE_REV(ctl),
    182 	    CAP_REV(ctl));
    183 
    184 	/*
    185  	 * Disable interrupts and clear errors prior to probing
    186 	 */
    187 	REGVAL(MCPCIA_INT_MASK0(mcp)) = 0;
    188 	REGVAL(MCPCIA_INT_MASK1(mcp)) = 0;
    189 	REGVAL(MCPCIA_CAP_ERR(mcp)) = 0xFFFFFFFF;
    190 	alpha_mb();
    191 
    192 	/*
    193 	 * Set up DMA stuff for this MCPCIA.
    194 	 */
    195 	mcpcia_dma_init(ccp);
    196 
    197 	/*
    198 	 * Clean up any post probe errors (W1TC).
    199 	 */
    200 	REGVAL(MCPCIA_CAP_ERR(mcp)) = 0xFFFFFFFF;
    201 	alpha_mb();
    202 
    203 	/*
    204 	 * Use this opportunity to also find out the MID and CPU
    205 	 * type of the currently running CPU (that's us, billybob....)
    206 	 */
    207 	ctl = REGVAL(MCPCIA_WHOAMI(mcp));
    208 	mcbus_primary.mcbus_cpu_mid = MCBUS_CPU_MID(ctl);
    209 	if ((ctl & CPU_Fill_Err) == 0 && mcbus_primary.mcbus_valid == 0) {
    210 		mcbus_primary.mcbus_bcache =
    211 		    MCBUS_CPU_INFO(ctl) & CPU_BCacheMask;
    212 		mcbus_primary.mcbus_valid = 1;
    213 	}
    214 	alpha_mb();
    215 	ccp->cc_initted = 1;
    216 }
    217 
    218 void
    219 mcpcia_config_cleanup()
    220 {
    221 	volatile u_int32_t ctl;
    222 	struct mcpcia_softc *mcp;
    223 
    224 	/*
    225 	 * Turn on Hard, Soft error interrupts. Maybe i2c too.
    226 	 */
    227 	for (mcp = mcpcias; mcp; mcp = mcp->mcpcia_next) {
    228 		ctl =  REGVAL(MCPCIA_INT_MASK0(mcp));
    229 		ctl |= MCPCIA_GEN_IENABL;
    230 		REGVAL(MCPCIA_INT_MASK0(mcp)) = ctl;
    231 		alpha_mb();
    232 		/* force stall while write completes */
    233 		ctl =  REGVAL(MCPCIA_INT_MASK0(mcp));
    234 	}
    235 }
    236