Home | History | Annotate | Line # | Download | only in dev
pcctwo_68k.c revision 1.10
      1  1.10      chs /*	$NetBSD: pcctwo_68k.c,v 1.10 2012/10/27 17:18:04 chs Exp $	*/
      2   1.1      scw 
      3   1.1      scw /*-
      4   1.1      scw  * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
      5   1.1      scw  * All rights reserved.
      6   1.1      scw  *
      7   1.1      scw  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1      scw  * by Steve C. Woodford.
      9   1.1      scw  *
     10   1.1      scw  * Redistribution and use in source and binary forms, with or without
     11   1.1      scw  * modification, are permitted provided that the following conditions
     12   1.1      scw  * are met:
     13   1.1      scw  * 1. Redistributions of source code must retain the above copyright
     14   1.1      scw  *    notice, this list of conditions and the following disclaimer.
     15   1.1      scw  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1      scw  *    notice, this list of conditions and the following disclaimer in the
     17   1.1      scw  *    documentation and/or other materials provided with the distribution.
     18   1.1      scw  *
     19   1.1      scw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1      scw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1      scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1      scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1      scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1      scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1      scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1      scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1      scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1      scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1      scw  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1      scw  */
     31   1.1      scw 
     32   1.1      scw /*
     33   1.1      scw  * PCCchip2 and MCchip Mvme68k Front End Driver
     34   1.1      scw  */
     35   1.4    lukem 
     36   1.4    lukem #include <sys/cdefs.h>
     37  1.10      chs __KERNEL_RCSID(0, "$NetBSD: pcctwo_68k.c,v 1.10 2012/10/27 17:18:04 chs Exp $");
     38   1.1      scw 
     39   1.1      scw #include <sys/param.h>
     40   1.1      scw #include <sys/kernel.h>
     41   1.1      scw #include <sys/systm.h>
     42   1.1      scw #include <sys/device.h>
     43   1.1      scw 
     44   1.1      scw #include <machine/cpu.h>
     45   1.1      scw #include <machine/bus.h>
     46   1.1      scw 
     47   1.1      scw #include <mvme68k/dev/mainbus.h>
     48   1.1      scw #include <mvme68k/mvme68k/isr.h>
     49   1.1      scw 
     50   1.1      scw #include <dev/mvme/pcctworeg.h>
     51   1.1      scw #include <dev/mvme/pcctwovar.h>
     52   1.1      scw 
     53   1.8  tsutsui #include "ioconf.h"
     54   1.8  tsutsui 
     55   1.1      scw /*
     56   1.1      scw  * Autoconfiguration stuff.
     57   1.1      scw  */
     58  1.10      chs void pcctwoattach(device_t, device_t, void *);
     59  1.10      chs int pcctwomatch(device_t, cfdata_t, void *);
     60   1.1      scw 
     61  1.10      chs CFATTACH_DECL_NEW(pcctwo, sizeof(struct pcctwo_softc),
     62   1.3  thorpej     pcctwomatch, pcctwoattach, NULL, NULL);
     63   1.1      scw 
     64   1.1      scw 
     65   1.1      scw #if defined(MVME167) || defined(MVME177)
     66   1.1      scw /*
     67   1.1      scw  * Devices that live on the PCCchip2, attached in this order.
     68   1.1      scw  */
     69   1.5      scw static const struct pcctwo_device pcctwo_devices[] = {
     70   1.1      scw 	{"clock", 0},
     71   1.1      scw 	{"clmpcc", PCCTWO_SCC_OFF},
     72   1.1      scw 	{"ie", PCCTWO_IE_OFF},
     73   1.1      scw 	{"osiop", PCCTWO_NCRSC_OFF},
     74   1.1      scw 	{"lpt", PCCTWO_LPT_OFF},
     75   1.1      scw 	{NULL, 0}
     76   1.1      scw };
     77   1.1      scw 
     78   1.1      scw static int pcctwo_vec2icsr_1x7[] = {
     79   1.1      scw 	VEC2ICSR(PCC2REG_PRT_BUSY_ICSR,  PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     80   1.1      scw 	VEC2ICSR(PCC2REG_PRT_PE_ICSR,    PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     81   1.1      scw 	VEC2ICSR(PCC2REG_PRT_SEL_ICSR,   PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     82   1.1      scw 	VEC2ICSR(PCC2REG_PRT_FAULT_ICSR, PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     83   1.1      scw 	VEC2ICSR(PCC2REG_PRT_ACK_ICSR,   PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     84   1.1      scw 	VEC2ICSR(PCC2REG_SCSI_ICSR,      0),
     85   1.1      scw 	VEC2ICSR(PCC2REG_ETH_ICSR,       PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     86   1.1      scw 	VEC2ICSR(PCC2REG_ETH_ICSR,       PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     87   1.1      scw 	VEC2ICSR(PCC2REG_TIMER2_ICSR,    PCCTWO_ICR_ICLR),
     88   1.1      scw 	VEC2ICSR(PCC2REG_TIMER1_ICSR,    PCCTWO_ICR_ICLR),
     89   1.1      scw 	VEC2ICSR(PCC2REG_GPIO_ICSR,      PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
     90   1.1      scw 	-1,
     91   1.1      scw 	VEC2ICSR(PCC2REG_SCC_RX_ICSR,    0),
     92   1.1      scw 	VEC2ICSR(PCC2REG_SCC_MODEM_ICSR, 0),
     93   1.1      scw 	VEC2ICSR(PCC2REG_SCC_TX_ICSR,    0),
     94   1.1      scw 	VEC2ICSR(PCC2REG_SCC_RX_ICSR,    0)
     95   1.1      scw };
     96   1.1      scw #endif
     97   1.1      scw 
     98   1.1      scw #if defined(MVME162) || defined(MVME172)
     99   1.1      scw /*
    100   1.1      scw  * Devices that live on the MCchip, attached in this order.
    101   1.1      scw  */
    102   1.5      scw static const struct pcctwo_device mcchip_devices[] = {
    103   1.1      scw 	{"clock", 0},
    104   1.1      scw 	{"zsc", MCCHIP_ZS0_OFF},
    105   1.1      scw 	{"zsc", MCCHIP_ZS1_OFF},
    106   1.1      scw 	{"ie", PCCTWO_IE_OFF},
    107   1.1      scw 	{"osiop", PCCTWO_NCRSC_OFF},
    108   1.1      scw 	{NULL, 0}
    109   1.1      scw };
    110   1.1      scw 
    111   1.1      scw static int pcctwo_vec2icsr_1x2[] = {
    112   1.1      scw 	-1,
    113   1.1      scw 	-1,
    114   1.1      scw 	-1,
    115   1.1      scw 	VEC2ICSR(MCCHIPREG_TIMER4_ICSR, PCCTWO_ICR_ICLR),
    116   1.1      scw 	VEC2ICSR(MCCHIPREG_TIMER3_ICSR, PCCTWO_ICR_ICLR),
    117   1.1      scw 	VEC2ICSR(PCC2REG_SCSI_ICSR,     0),
    118   1.1      scw 	VEC2ICSR(PCC2REG_ETH_ICSR,      PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
    119   1.1      scw 	VEC2ICSR(PCC2REG_ETH_ICSR,      PCCTWO_ICR_EDGE | PCCTWO_ICR_ICLR),
    120   1.1      scw 	VEC2ICSR(PCC2REG_TIMER2_ICSR,   PCCTWO_ICR_ICLR),
    121   1.1      scw 	VEC2ICSR(PCC2REG_TIMER1_ICSR,   PCCTWO_ICR_ICLR),
    122   1.1      scw 	-1,
    123   1.1      scw 	VEC2ICSR(MCCHIPREG_PARERR_ICSR, PCCTWO_ICR_ICLR),
    124   1.1      scw 	VEC2ICSR(MCCHIPREG_SCC_ICSR,    0),
    125   1.1      scw 	VEC2ICSR(MCCHIPREG_SCC_ICSR,    0),
    126   1.1      scw 	VEC2ICSR(MCCHIPREG_ABORT_ICSR,  PCCTWO_ICR_ICLR),
    127   1.1      scw 	-1
    128   1.1      scw };
    129   1.1      scw 
    130   1.1      scw static	int pcctwoabortintr(void *);
    131   1.1      scw void	pcctwosoftintrinit(void);
    132   1.1      scw static	int pcctwosoftintr(void *);
    133   1.7       ad #ifdef notyet
    134   1.1      scw static	void pcctwosoftintrassert(void);
    135   1.1      scw #endif
    136   1.7       ad #endif
    137   1.1      scw 
    138   1.1      scw static void pcctwoisrlink(void *, int (*)(void *), void *,
    139   1.1      scw 		int, int, struct evcnt *);
    140   1.1      scw static void pcctwoisrunlink(void *, int);
    141   1.1      scw static struct evcnt *pcctwoisrevcnt(void *, int);
    142   1.1      scw 
    143   1.1      scw 
    144   1.1      scw /* ARGSUSED */
    145   1.1      scw int
    146  1.10      chs pcctwomatch(device_t parent, cfdata_t cf, void *aux)
    147   1.1      scw {
    148   1.1      scw 	struct mainbus_attach_args *ma;
    149   1.1      scw 	bus_space_handle_t bh;
    150   1.8  tsutsui 	uint8_t cid;
    151   1.1      scw 
    152  1.10      chs 	ma = aux;
    153   1.1      scw 
    154   1.1      scw 	/* There can be only one. */
    155   1.1      scw 	if (sys_pcctwo || strcmp(ma->ma_name, pcctwo_cd.cd_name))
    156   1.8  tsutsui 		return 0;
    157   1.1      scw 
    158   1.1      scw 	/*
    159   1.1      scw 	 * Grab the Chip's ID
    160   1.1      scw 	 */
    161   1.1      scw 	bus_space_map(ma->ma_bust, PCCTWO_REG_OFF + ma->ma_offset,
    162   1.1      scw 	    PCC2REG_SIZE, 0, &bh);
    163   1.1      scw 	cid = bus_space_read_1(ma->ma_bust, bh, PCC2REG_CHIP_ID);
    164   1.1      scw 	bus_space_unmap(ma->ma_bust, bh, PCC2REG_SIZE);
    165   1.1      scw 
    166   1.1      scw #if defined(MVME167) || defined(MVME177)
    167   1.1      scw 	if ((machineid == MVME_167 || machineid == MVME_177) &&
    168   1.1      scw 	    cid == PCCTWO_CHIP_ID_PCC2)
    169   1.8  tsutsui 		return 1;
    170   1.1      scw #endif
    171   1.1      scw #if defined(MVME162) || defined(MVME172)
    172   1.1      scw 	if ((machineid == MVME_162 || machineid == MVME_172) &&
    173   1.1      scw 	    cid == PCCTWO_CHIP_ID_MCCHIP)
    174   1.8  tsutsui 		return 1;
    175   1.1      scw #endif
    176   1.1      scw 
    177   1.8  tsutsui 	return 0;
    178   1.1      scw }
    179   1.1      scw 
    180   1.1      scw /* ARGSUSED */
    181   1.1      scw void
    182  1.10      chs pcctwoattach(device_t parent, device_t self, void *aux)
    183   1.1      scw {
    184   1.1      scw 	struct mainbus_attach_args *ma;
    185   1.1      scw 	struct pcctwo_softc *sc;
    186   1.5      scw 	const struct pcctwo_device *pd = NULL;
    187   1.8  tsutsui 	uint8_t cid;
    188   1.1      scw 
    189  1.10      chs 	sc = sys_pcctwo = device_private(self);
    190  1.10      chs 	ma = aux;
    191   1.1      scw 
    192   1.1      scw 	/* Get a handle to the PCCChip2's registers */
    193   1.1      scw 	sc->sc_bust = ma->ma_bust;
    194   1.1      scw 	sc->sc_dmat = ma->ma_dmat;
    195   1.1      scw 	bus_space_map(sc->sc_bust, PCCTWO_REG_OFF + ma->ma_offset,
    196   1.1      scw 	    PCC2REG_SIZE, 0, &sc->sc_bush);
    197   1.1      scw 
    198   1.1      scw 	sc->sc_vecbase = PCCTWO_VECBASE;
    199   1.1      scw 	sc->sc_isrlink = pcctwoisrlink;
    200   1.1      scw 	sc->sc_isrevcnt = pcctwoisrevcnt;
    201   1.1      scw 	sc->sc_isrunlink = pcctwoisrunlink;
    202   1.1      scw 
    203   1.1      scw 	cid = pcc2_reg_read(sc, PCC2REG_CHIP_ID);
    204   1.1      scw 
    205   1.1      scw #if defined(MVME167) || defined(MVME177)
    206   1.1      scw 	if (cid == PCCTWO_CHIP_ID_PCC2) {
    207   1.1      scw 		pd = pcctwo_devices;
    208   1.1      scw 		sc->sc_vec2icsr = pcctwo_vec2icsr_1x7;
    209   1.1      scw 	}
    210   1.1      scw #endif
    211   1.1      scw #if defined(MVME162) || defined(MVME172)
    212   1.1      scw 	if (cid == PCCTWO_CHIP_ID_MCCHIP) {
    213   1.1      scw 		pd = mcchip_devices;
    214   1.1      scw 		sc->sc_vec2icsr = pcctwo_vec2icsr_1x2;
    215   1.1      scw 	}
    216   1.1      scw #endif
    217   1.1      scw 
    218   1.1      scw 	/* Finish initialisation in common code */
    219   1.1      scw 	pcctwo_init(sc, pd, ma->ma_offset);
    220   1.1      scw 
    221   1.1      scw #if defined(MVME162) || defined(MVME172)
    222   1.1      scw 	if (cid == PCCTWO_CHIP_ID_MCCHIP) {
    223   1.1      scw 		evcnt_attach_dynamic(&sc->sc_evcnt, EVCNT_TYPE_INTR,
    224   1.1      scw 		    isrlink_evcnt(7), "nmi", "abort sw");
    225   1.1      scw 		pcctwointr_establish(MCCHIPV_ABORT, pcctwoabortintr, 7, NULL,
    226   1.1      scw 		    &sc->sc_evcnt);
    227   1.1      scw 	}
    228   1.1      scw #endif
    229   1.1      scw }
    230   1.1      scw 
    231   1.1      scw /* ARGSUSED */
    232   1.1      scw static void
    233   1.8  tsutsui pcctwoisrlink(void *cookie, int (*fn)(void *), void *arg, int ipl, int vec,
    234   1.8  tsutsui     struct evcnt *evcnt)
    235   1.1      scw {
    236   1.1      scw 
    237   1.1      scw 	isrlink_vectored(fn, arg, ipl, vec, evcnt);
    238   1.1      scw }
    239   1.1      scw 
    240   1.1      scw /* ARGSUSED */
    241   1.1      scw static void
    242   1.8  tsutsui pcctwoisrunlink(void *cookie, int vec)
    243   1.1      scw {
    244   1.1      scw 
    245   1.1      scw 	isrunlink_vectored(vec);
    246   1.1      scw }
    247   1.1      scw 
    248   1.1      scw /* ARGSUSED */
    249   1.1      scw static struct evcnt *
    250   1.8  tsutsui pcctwoisrevcnt(void *cookie, int ipl)
    251   1.1      scw {
    252   1.1      scw 
    253   1.8  tsutsui 	return isrlink_evcnt(ipl);
    254   1.1      scw }
    255   1.1      scw 
    256   1.1      scw #if defined(MVME162) || defined(MVME172)
    257   1.1      scw static int
    258   1.1      scw pcctwoabortintr(void *frame)
    259   1.1      scw {
    260   1.1      scw 
    261   1.1      scw 	pcc2_reg_write(sys_pcctwo, MCCHIPREG_ABORT_ICSR, PCCTWO_ICR_ICLR |
    262   1.1      scw 	    pcc2_reg_read(sys_pcctwo, MCCHIPREG_ABORT_ICSR));
    263   1.1      scw 
    264   1.8  tsutsui 	return nmihand(frame);
    265   1.1      scw }
    266   1.1      scw 
    267   1.1      scw void
    268   1.1      scw pcctwosoftintrinit(void)
    269   1.1      scw {
    270   1.1      scw 
    271   1.1      scw 	/*
    272   1.1      scw 	 * Since the VMEChip2 is normally used to generate
    273   1.1      scw 	 * software interrupts to the CPU, we have to deal
    274   1.1      scw 	 * with 162/172 boards which have the "No VMEChip2"
    275   1.1      scw 	 * build option.
    276   1.1      scw 	 *
    277   1.1      scw 	 * When such a board is found, the VMEChip2 probe code
    278   1.1      scw 	 * calls this function to implement software interrupts
    279   1.1      scw 	 * the hard way; using tick timer 4 ...
    280   1.1      scw 	 */
    281   1.1      scw 	pcctwointr_establish(MCCHIPV_TIMER4, pcctwosoftintr,
    282   1.1      scw 	    1, sys_pcctwo, &sys_pcctwo->sc_evcnt);
    283   1.1      scw 	pcc2_reg_write(sys_pcctwo, MCCHIPREG_TIMER4_CTRL, 0);
    284   1.1      scw 	pcc2_reg_write32(sys_pcctwo, MCCHIPREG_TIMER4_COMP, 1);
    285   1.1      scw 	pcc2_reg_write32(sys_pcctwo, MCCHIPREG_TIMER4_CNTR, 0);
    286   1.7       ad #ifdef notyet
    287   1.1      scw 	_softintr_chipset_assert = pcctwosoftintrassert;
    288   1.7       ad #endif
    289   1.1      scw }
    290   1.1      scw 
    291   1.1      scw static int
    292   1.1      scw pcctwosoftintr(void *arg)
    293   1.1      scw {
    294   1.1      scw 	struct pcctwo_softc *sc = arg;
    295   1.1      scw 
    296   1.1      scw 	pcc2_reg_write32(sc, MCCHIPREG_TIMER4_CNTR, 0);
    297   1.1      scw 	pcc2_reg_write(sc, MCCHIPREG_TIMER4_CTRL, 0);
    298   1.1      scw 	pcc2_reg_write(sc, MCCHIPREG_TIMER4_ICSR,
    299   1.1      scw 	    PCCTWO_ICR_ICLR | PCCTWO_ICR_IEN | 1);
    300   1.1      scw 
    301   1.7       ad #ifdef notyet
    302   1.1      scw 	softintr_dispatch();
    303   1.7       ad #endif
    304   1.1      scw 
    305   1.8  tsutsui 	return 1;
    306   1.1      scw }
    307   1.1      scw 
    308   1.7       ad #ifdef notyet
    309   1.1      scw static void
    310   1.1      scw pcctwosoftintrassert(void)
    311   1.1      scw {
    312   1.1      scw 
    313   1.1      scw 	/*
    314   1.1      scw 	 * Schedule a timer interrupt to happen in ~1uS.
    315   1.1      scw 	 * This is more than adequate on any available m68k platform
    316   1.1      scw 	 * for simulating software interrupts.
    317   1.1      scw 	 */
    318   1.1      scw 	pcc2_reg_write(sys_pcctwo, MCCHIPREG_TIMER4_CTRL, PCCTWO_TT_CTRL_CEN);
    319   1.1      scw }
    320   1.1      scw #endif
    321   1.7       ad #endif
    322