Home | History | Annotate | Line # | Download | only in dev
pcc.c revision 1.29
      1  1.29   tsutsui /*	$NetBSD: pcc.c,v 1.29 2008/01/12 09:54:23 tsutsui Exp $	*/
      2  1.10   thorpej 
      3  1.10   thorpej /*-
      4  1.10   thorpej  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
      5  1.10   thorpej  * All rights reserved.
      6  1.10   thorpej  *
      7  1.10   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.13       scw  * by Jason R. Thorpe and Steve C. Woodford.
      9  1.10   thorpej  *
     10  1.10   thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.10   thorpej  * modification, are permitted provided that the following conditions
     12  1.10   thorpej  * are met:
     13  1.10   thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.10   thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.10   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.10   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.10   thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.10   thorpej  * 3. All advertising materials mentioning features or use of this software
     19  1.10   thorpej  *    must display the following acknowledgement:
     20  1.10   thorpej  *	This product includes software developed by the NetBSD
     21  1.10   thorpej  *	Foundation, Inc. and its contributors.
     22  1.10   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.10   thorpej  *    contributors may be used to endorse or promote products derived
     24  1.10   thorpej  *    from this software without specific prior written permission.
     25  1.10   thorpej  *
     26  1.10   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.10   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.10   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.10   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.10   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.10   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.10   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.10   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.10   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.10   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.10   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.10   thorpej  */
     38   1.1     chuck 
     39   1.1     chuck /*
     40   1.1     chuck  * Copyright (c) 1995 Charles D. Cranor
     41   1.1     chuck  * All rights reserved.
     42   1.1     chuck  *
     43   1.1     chuck  * Redistribution and use in source and binary forms, with or without
     44   1.1     chuck  * modification, are permitted provided that the following conditions
     45   1.1     chuck  * are met:
     46   1.1     chuck  * 1. Redistributions of source code must retain the above copyright
     47   1.1     chuck  *    notice, this list of conditions and the following disclaimer.
     48   1.1     chuck  * 2. Redistributions in binary form must reproduce the above copyright
     49   1.1     chuck  *    notice, this list of conditions and the following disclaimer in the
     50   1.1     chuck  *    documentation and/or other materials provided with the distribution.
     51   1.1     chuck  * 3. All advertising materials mentioning features or use of this software
     52   1.1     chuck  *    must display the following acknowledgement:
     53   1.1     chuck  *      This product includes software developed by Charles D. Cranor.
     54   1.1     chuck  * 4. The name of the author may not be used to endorse or promote products
     55   1.1     chuck  *    derived from this software without specific prior written permission.
     56   1.1     chuck  *
     57   1.1     chuck  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     58   1.1     chuck  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     59   1.1     chuck  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     60   1.1     chuck  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     61   1.1     chuck  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     62   1.1     chuck  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     63   1.1     chuck  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     64   1.1     chuck  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     65   1.1     chuck  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     66   1.1     chuck  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     67   1.1     chuck  */
     68   1.1     chuck 
     69   1.1     chuck /*
     70   1.1     chuck  * peripheral channel controller
     71   1.1     chuck  */
     72  1.25     lukem 
     73  1.25     lukem #include <sys/cdefs.h>
     74  1.29   tsutsui __KERNEL_RCSID(0, "$NetBSD: pcc.c,v 1.29 2008/01/12 09:54:23 tsutsui Exp $");
     75  1.12       scw 
     76   1.1     chuck #include <sys/param.h>
     77  1.13       scw #include <sys/kernel.h>
     78   1.1     chuck #include <sys/systm.h>
     79   1.1     chuck #include <sys/device.h>
     80  1.14       scw #include <sys/kcore.h>
     81  1.13       scw 
     82   1.1     chuck #include <machine/cpu.h>
     83  1.13       scw #include <machine/bus.h>
     84   1.3     chuck 
     85  1.13       scw #include <mvme68k/dev/mainbus.h>
     86   1.1     chuck #include <mvme68k/dev/pccreg.h>
     87   1.3     chuck #include <mvme68k/dev/pccvar.h>
     88   1.1     chuck 
     89  1.29   tsutsui #include "ioconf.h"
     90  1.29   tsutsui 
     91   1.1     chuck /*
     92  1.13       scw  * Autoconfiguration stuff for the PCC chip on mvme147
     93   1.1     chuck  */
     94   1.1     chuck 
     95  1.29   tsutsui void pccattach(struct device *, struct device *, void *);
     96  1.29   tsutsui int pccmatch(struct device *, struct cfdata *, void *);
     97  1.29   tsutsui int pccprint(void *, const char *);
     98   1.1     chuck 
     99  1.22   thorpej CFATTACH_DECL(pcc, sizeof(struct pcc_softc),
    100  1.22   thorpej     pccmatch, pccattach, NULL, NULL);
    101   1.2   thorpej 
    102  1.29   tsutsui static int pccintr(void *);
    103  1.29   tsutsui static int pccsoftintr(void *);
    104  1.28        ad #ifdef notyet
    105  1.29   tsutsui static void pccsoftintrassert(void);
    106  1.28        ad #endif
    107   1.3     chuck 
    108   1.1     chuck /*
    109  1.13       scw  * Structure used to describe a device for autoconfiguration purposes.
    110   1.1     chuck  */
    111  1.13       scw struct pcc_device {
    112  1.26       scw 	const char *pcc_name;	/* name of device (e.g. "clock") */
    113  1.13       scw 	bus_addr_t pcc_offset;	/* offset from PCC base */
    114  1.13       scw };
    115   1.1     chuck 
    116   1.3     chuck /*
    117   1.3     chuck  * Devices that live on the PCC, attached in this order.
    118   1.3     chuck  */
    119  1.26       scw static const struct pcc_device pcc_devices[] = {
    120  1.20       scw 	{"clock", 0},
    121  1.13       scw 	{"zsc", PCC_ZS0_OFF},
    122  1.13       scw 	{"zsc", PCC_ZS1_OFF},
    123  1.13       scw 	{"le", PCC_LE_OFF},
    124  1.13       scw 	{"wdsc", PCC_WDSC_OFF},
    125  1.13       scw 	{"lpt", PCC_LPT_OFF},
    126  1.13       scw 	{"vmepcc", PCC_VME_OFF},
    127  1.13       scw 	{NULL, 0},
    128  1.13       scw };
    129  1.13       scw 
    130  1.13       scw static int pcc_vec2intctrl[] = {
    131  1.13       scw 	PCCREG_ACFAIL_INTR_CTRL,/* PCCV_ACFAIL */
    132  1.13       scw 	PCCREG_BUSERR_INTR_CTRL,/* PCCV_BERR */
    133  1.13       scw 	PCCREG_ABORT_INTR_CTRL,	/* PCCV_ABORT */
    134  1.13       scw 	PCCREG_SERIAL_INTR_CTRL,/* PCCV_ZS */
    135  1.13       scw 	PCCREG_LANCE_INTR_CTRL,	/* PCCV_LE */
    136  1.13       scw 	PCCREG_SCSI_INTR_CTRL,	/* PCCV_SCSI */
    137  1.13       scw 	PCCREG_DMA_INTR_CTRL,	/* PCCV_DMA */
    138  1.13       scw 	PCCREG_PRNT_INTR_CTRL,	/* PCCV_PRINTER */
    139  1.13       scw 	PCCREG_TMR1_INTR_CTRL,	/* PCCV_TIMER1 */
    140  1.13       scw 	PCCREG_TMR2_INTR_CTRL,	/* PCCV_TIMER2 */
    141  1.13       scw 	PCCREG_SOFT1_INTR_CTRL,	/* PCCV_SOFT1 */
    142  1.13       scw 	PCCREG_SOFT2_INTR_CTRL	/* PCCV_SOFT2 */
    143   1.3     chuck };
    144   1.1     chuck 
    145  1.14       scw extern phys_ram_seg_t mem_clusters[];
    146  1.13       scw struct pcc_softc *sys_pcc;
    147  1.13       scw 
    148  1.14       scw /* The base address of the MVME147 from the VMEbus */
    149  1.14       scw bus_addr_t pcc_slave_base_addr;
    150  1.14       scw 
    151  1.14       scw 
    152  1.13       scw /* ARGSUSED */
    153   1.1     chuck int
    154  1.29   tsutsui pccmatch(struct device *parent, struct cfdata *cf, void *args)
    155   1.1     chuck {
    156  1.13       scw 	struct mainbus_attach_args *ma;
    157  1.13       scw 
    158  1.13       scw 	ma = args;
    159   1.3     chuck 
    160   1.3     chuck 	/* Only attach one PCC. */
    161   1.3     chuck 	if (sys_pcc)
    162  1.29   tsutsui 		return 0;
    163   1.1     chuck 
    164  1.29   tsutsui 	return strcmp(ma->ma_name, pcc_cd.cd_name) == 0;
    165   1.1     chuck }
    166   1.1     chuck 
    167  1.13       scw /* ARGSUSED */
    168   1.1     chuck void
    169  1.29   tsutsui pccattach(struct device *parent, struct device *self, void *args)
    170   1.1     chuck {
    171  1.13       scw 	struct mainbus_attach_args *ma;
    172   1.3     chuck 	struct pcc_attach_args npa;
    173  1.13       scw 	struct pcc_softc *sc;
    174  1.29   tsutsui 	uint8_t reg;
    175   1.6   thorpej 	int i;
    176   1.1     chuck 
    177  1.13       scw 	ma = args;
    178  1.29   tsutsui 	sc = sys_pcc = (struct pcc_softc *)self;
    179   1.1     chuck 
    180  1.13       scw 	/* Get a handle to the PCC's registers. */
    181  1.13       scw 	sc->sc_bust = ma->ma_bust;
    182  1.20       scw 	bus_space_map(sc->sc_bust, ma->ma_offset, PCCREG_SIZE, 0, &sc->sc_bush);
    183   1.1     chuck 
    184  1.13       scw 	/* Tell the chip the base interrupt vector */
    185  1.13       scw 	pcc_reg_write(sc, PCCREG_VECTOR_BASE, PCC_VECBASE);
    186   1.1     chuck 
    187   1.8  christos 	printf(": Peripheral Channel Controller, "
    188  1.13       scw 	    "rev %d, vecbase 0x%x\n", pcc_reg_read(sc, PCCREG_REVISION),
    189  1.13       scw 	    pcc_reg_read(sc, PCCREG_VECTOR_BASE));
    190   1.3     chuck 
    191  1.18       scw 	evcnt_attach_dynamic(&sc->sc_evcnt, EVCNT_TYPE_INTR,
    192  1.18       scw 	    isrlink_evcnt(7), "nmi", "abort sw");
    193  1.18       scw 
    194  1.13       scw 	/* Hook up interrupt handler for abort button, and enable it */
    195  1.18       scw 	pccintr_establish(PCCV_ABORT, pccintr, 7, NULL, &sc->sc_evcnt);
    196  1.13       scw 	pcc_reg_write(sc, PCCREG_ABORT_INTR_CTRL,
    197  1.13       scw 	    PCC_ABORT_IEN | PCC_ABORT_ACK);
    198   1.3     chuck 
    199  1.19       scw 	/*
    200  1.19       scw 	 * Install a handler for Software Interrupt 1
    201  1.19       scw 	 * and arrange to schedule soft interrupts on demand.
    202  1.19       scw 	 */
    203  1.19       scw 	pccintr_establish(PCCV_SOFT1, pccsoftintr, 1, sc, &sc->sc_evcnt);
    204  1.28        ad #ifdef notyet
    205  1.19       scw 	_softintr_chipset_assert = pccsoftintrassert;
    206  1.28        ad #endif
    207  1.19       scw 
    208   1.3     chuck 	/* Make sure the global interrupt line is hot. */
    209  1.13       scw 	reg = pcc_reg_read(sc, PCCREG_GENERAL_CONTROL) | PCC_GENCR_IEN;
    210  1.13       scw 	pcc_reg_write(sc, PCCREG_GENERAL_CONTROL, reg);
    211  1.14       scw 
    212  1.14       scw 	/*
    213  1.14       scw 	 * Calculate the board's VMEbus slave base address, for the
    214  1.14       scw 	 * benefit of the VMEchip driver.
    215  1.14       scw 	 * (Weird that this register is in the PCC ...)
    216  1.14       scw 	 */
    217  1.14       scw 	reg = pcc_reg_read(sc, PCCREG_SLAVE_BASE_ADDR) & PCC_SLAVE_BASE_MASK;
    218  1.14       scw 	pcc_slave_base_addr = (bus_addr_t)reg * mem_clusters[0].size;
    219   1.3     chuck 
    220   1.3     chuck 	/*
    221   1.3     chuck 	 * Attach configured children.
    222   1.3     chuck 	 */
    223  1.15       scw 	npa._pa_base = ma->ma_offset;
    224   1.3     chuck 	for (i = 0; pcc_devices[i].pcc_name != NULL; ++i) {
    225   1.3     chuck 		/*
    226   1.3     chuck 		 * Note that IPL is filled in by match function.
    227   1.3     chuck 		 */
    228   1.3     chuck 		npa.pa_name = pcc_devices[i].pcc_name;
    229   1.3     chuck 		npa.pa_ipl = -1;
    230  1.13       scw 		npa.pa_dmat = ma->ma_dmat;
    231  1.13       scw 		npa.pa_bust = ma->ma_bust;
    232  1.13       scw 		npa.pa_offset = pcc_devices[i].pcc_offset + ma->ma_offset;
    233   1.3     chuck 
    234   1.3     chuck 		/* Attach the device if configured. */
    235  1.29   tsutsui 		(void)config_found(self, &npa, pccprint);
    236   1.3     chuck 	}
    237   1.1     chuck }
    238   1.1     chuck 
    239   1.1     chuck int
    240  1.29   tsutsui pccprint(void *aux, const char *cp)
    241   1.1     chuck {
    242  1.13       scw 	struct pcc_attach_args *pa;
    243  1.13       scw 
    244  1.13       scw 	pa = aux;
    245   1.3     chuck 
    246   1.3     chuck 	if (cp)
    247  1.23   thorpej 		aprint_normal("%s at %s", pa->pa_name, cp);
    248   1.3     chuck 
    249  1.23   thorpej 	aprint_normal(" offset 0x%lx", pa->pa_offset - pa->_pa_base);
    250   1.3     chuck 	if (pa->pa_ipl != -1)
    251  1.23   thorpej 		aprint_normal(" ipl %d", pa->pa_ipl);
    252   1.1     chuck 
    253  1.29   tsutsui 	return UNCONF;
    254   1.1     chuck }
    255   1.1     chuck 
    256   1.1     chuck /*
    257   1.1     chuck  * pccintr_establish: establish pcc interrupt
    258   1.1     chuck  */
    259   1.3     chuck void
    260  1.29   tsutsui pccintr_establish(int pccvec, int (*hand)(void *), int lvl, void *arg,
    261  1.29   tsutsui     struct evcnt *evcnt)
    262   1.1     chuck {
    263   1.3     chuck 
    264  1.13       scw #ifdef DEBUG
    265  1.13       scw 	if (pccvec < 0 || pccvec >= PCC_NVEC) {
    266   1.8  christos 		printf("pcc: illegal vector offset: 0x%x\n", pccvec);
    267   1.1     chuck 		panic("pccintr_establish");
    268   1.1     chuck 	}
    269  1.13       scw 	if (lvl < 1 || lvl > 7) {
    270   1.8  christos 		printf("pcc: illegal interrupt level: %d\n", lvl);
    271   1.1     chuck 		panic("pccintr_establish");
    272   1.1     chuck 	}
    273  1.13       scw #endif
    274   1.1     chuck 
    275  1.18       scw 	isrlink_vectored(hand, arg, lvl, pccvec + PCC_VECBASE, evcnt);
    276   1.3     chuck }
    277   1.3     chuck 
    278   1.3     chuck void
    279  1.29   tsutsui pccintr_disestablish(int pccvec)
    280   1.3     chuck {
    281   1.3     chuck 
    282  1.13       scw #ifdef DEBUG
    283  1.13       scw 	if (pccvec < 0 || pccvec >= PCC_NVEC) {
    284   1.8  christos 		printf("pcc: illegal vector offset: 0x%x\n", pccvec);
    285  1.13       scw 		panic("pccintr_disestablish");
    286   1.3     chuck 	}
    287  1.13       scw #endif
    288   1.3     chuck 
    289  1.13       scw 	/* Disable the interrupt */
    290  1.13       scw 	pcc_reg_write(sys_pcc, pcc_vec2intctrl[pccvec], PCC_ICLEAR);
    291   1.3     chuck 	isrunlink_vectored(pccvec + PCC_VECBASE);
    292   1.3     chuck }
    293   1.3     chuck 
    294   1.3     chuck /*
    295   1.3     chuck  * Handle NMI from abort switch.
    296   1.3     chuck  */
    297  1.13       scw static int
    298  1.29   tsutsui pccintr(void *frame)
    299   1.3     chuck {
    300   1.3     chuck 
    301   1.3     chuck 	/* XXX wait until button pops out */
    302  1.13       scw 	pcc_reg_write(sys_pcc, PCCREG_ABORT_INTR_CTRL,
    303  1.13       scw 	    PCC_ABORT_IEN | PCC_ABORT_ACK);
    304  1.13       scw 
    305  1.29   tsutsui 	return nmihand(frame);
    306  1.19       scw }
    307  1.19       scw 
    308  1.28        ad #ifdef notyet
    309  1.19       scw static void
    310  1.19       scw pccsoftintrassert(void)
    311  1.19       scw {
    312  1.19       scw 
    313  1.19       scw 	/* Request a software interrupt at ipl 1 */
    314  1.19       scw 	pcc_reg_write(sys_pcc, PCCREG_SOFT1_INTR_CTRL, 1 | PCC_IENABLE);
    315  1.19       scw }
    316  1.28        ad #endif
    317  1.19       scw 
    318  1.19       scw /*
    319  1.24       wiz  * Handle PCC soft interrupt #1
    320  1.19       scw  */
    321  1.19       scw static int
    322  1.29   tsutsui pccsoftintr(void *arg)
    323  1.19       scw {
    324  1.19       scw 	struct pcc_softc *sc = arg;
    325  1.19       scw 
    326  1.19       scw 	/* Clear the interrupt */
    327  1.19       scw 	pcc_reg_write(sc, PCCREG_SOFT1_INTR_CTRL, 0);
    328  1.19       scw 
    329  1.28        ad #ifdef notyet
    330  1.19       scw 	/* Call the soft interrupt dispatcher */
    331  1.19       scw 	softintr_dispatch();
    332  1.28        ad #endif
    333  1.19       scw 
    334  1.29   tsutsui 	return 1;
    335   1.1     chuck }
    336