Home | History | Annotate | Line # | Download | only in dev
vme_pcc.c revision 1.14.2.2
      1  1.14.2.2  jdolecek /*	$NetBSD: vme_pcc.c,v 1.14.2.2 2002/10/10 18:34:18 jdolecek Exp $	*/
      2       1.1     chuck 
      3       1.1     chuck /*-
      4       1.7       scw  * Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
      5       1.1     chuck  * All rights reserved.
      6       1.1     chuck  *
      7       1.1     chuck  * This code is derived from software contributed to The NetBSD Foundation
      8       1.7       scw  * by Jason R. Thorpe and Steve C. Woodford.
      9       1.1     chuck  *
     10       1.1     chuck  * Redistribution and use in source and binary forms, with or without
     11       1.1     chuck  * modification, are permitted provided that the following conditions
     12       1.1     chuck  * are met:
     13       1.1     chuck  * 1. Redistributions of source code must retain the above copyright
     14       1.1     chuck  *    notice, this list of conditions and the following disclaimer.
     15       1.1     chuck  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1     chuck  *    notice, this list of conditions and the following disclaimer in the
     17       1.1     chuck  *    documentation and/or other materials provided with the distribution.
     18       1.1     chuck  * 3. All advertising materials mentioning features or use of this software
     19       1.1     chuck  *    must display the following acknowledgement:
     20       1.1     chuck  *        This product includes software developed by the NetBSD
     21       1.1     chuck  *        Foundation, Inc. and its contributors.
     22       1.1     chuck  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1     chuck  *    contributors may be used to endorse or promote products derived
     24       1.1     chuck  *    from this software without specific prior written permission.
     25       1.1     chuck  *
     26       1.1     chuck  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1     chuck  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1     chuck  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.5       jtc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.5       jtc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1     chuck  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1     chuck  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1     chuck  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1     chuck  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1     chuck  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1     chuck  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1     chuck  */
     38       1.1     chuck 
     39       1.1     chuck /*
     40       1.1     chuck  * VME support specific to the Type 1 VMEchip found on the
     41       1.1     chuck  * MVME-147.
     42       1.1     chuck  *
     43       1.1     chuck  * For a manual on the MVME-147, call: 408.991.8634.  (Yes, this
     44       1.1     chuck  * is the Sunnyvale sales office.)
     45       1.1     chuck  */
     46       1.1     chuck 
     47       1.1     chuck #include <sys/param.h>
     48       1.1     chuck #include <sys/kernel.h>
     49       1.1     chuck #include <sys/systm.h>
     50       1.1     chuck #include <sys/device.h>
     51       1.7       scw #include <sys/malloc.h>
     52       1.7       scw #include <sys/kcore.h>
     53       1.1     chuck 
     54       1.1     chuck #include <machine/cpu.h>
     55       1.7       scw #include <machine/bus.h>
     56       1.7       scw 
     57       1.7       scw #include <dev/vme/vmereg.h>
     58       1.7       scw #include <dev/vme/vmevar.h>
     59       1.7       scw 
     60       1.1     chuck #include <mvme68k/dev/pccreg.h>
     61       1.1     chuck #include <mvme68k/dev/pccvar.h>
     62  1.14.2.1  jdolecek 
     63  1.14.2.1  jdolecek #include <dev/mvme/mvmebus.h>
     64       1.1     chuck #include <mvme68k/dev/vme_pccreg.h>
     65       1.7       scw #include <mvme68k/dev/vme_pccvar.h>
     66       1.7       scw 
     67       1.1     chuck 
     68      1.10       scw int vme_pcc_match(struct device *, struct cfdata *, void *);
     69      1.10       scw void vme_pcc_attach(struct device *, struct device *, void *);
     70       1.1     chuck 
     71  1.14.2.2  jdolecek CFATTACH_DECL(vmepcc, sizeof(struct vme_pcc_softc),
     72  1.14.2.2  jdolecek     vme_pcc_match, vme_pcc_attach, NULL, NULL);
     73       1.6   thorpej 
     74       1.7       scw extern struct cfdriver vmepcc_cd;
     75       1.7       scw 
     76       1.7       scw extern phys_ram_seg_t mem_clusters[];
     77       1.7       scw static int vme_pcc_attached;
     78       1.7       scw 
     79      1.12       scw void vme_pcc_intr_establish(void *, int, int, int, int,
     80      1.14       scw     int (*)(void *), void *, struct evcnt *);
     81      1.14       scw void vme_pcc_intr_disestablish(void *, int, int, int, struct evcnt *);
     82       1.7       scw 
     83       1.1     chuck 
     84      1.10       scw static struct mvmebus_range vme_pcc_masters[] = {
     85      1.11       scw 	{VME_AM_A24 |
     86      1.11       scw 	    MVMEBUS_AM_CAP_DATA  | MVMEBUS_AM_CAP_PROG |
     87      1.11       scw 	    MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
     88      1.11       scw 		VME_D32 | VME_D16 | VME_D8,
     89       1.7       scw 		VME1_A24D32_LOC_START,
     90      1.10       scw 		VME1_A24_MASK,
     91       1.7       scw 		VME1_A24D32_START,
     92       1.7       scw 		VME1_A24D32_END},
     93       1.7       scw 
     94      1.11       scw 	{VME_AM_A32 |
     95      1.11       scw 	    MVMEBUS_AM_CAP_DATA  | MVMEBUS_AM_CAP_PROG |
     96      1.11       scw 	    MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
     97      1.11       scw 		VME_D32 | VME_D16 | VME_D8,
     98       1.7       scw 		VME1_A32D32_LOC_START,
     99      1.10       scw 		VME1_A32_MASK,
    100       1.7       scw 		VME1_A32D32_START,
    101       1.7       scw 		VME1_A32D32_END},
    102       1.7       scw 
    103      1.11       scw 	{VME_AM_A24 |
    104      1.11       scw 	    MVMEBUS_AM_CAP_DATA  | MVMEBUS_AM_CAP_PROG |
    105      1.11       scw 	    MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
    106      1.11       scw 		VME_D16 | VME_D8,
    107       1.7       scw 		VME1_A24D16_LOC_START,
    108      1.10       scw 		VME1_A24_MASK,
    109       1.7       scw 		VME1_A24D16_START,
    110       1.7       scw 		VME1_A24D16_END},
    111       1.7       scw 
    112      1.11       scw 	{VME_AM_A32 |
    113      1.11       scw 	    MVMEBUS_AM_CAP_DATA  | MVMEBUS_AM_CAP_PROG |
    114      1.11       scw 	    MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
    115       1.7       scw 		VME_D16 | VME_D8,
    116       1.7       scw 		VME1_A32D16_LOC_START,
    117      1.10       scw 		VME1_A32_MASK,
    118       1.7       scw 		VME1_A32D16_START,
    119       1.7       scw 		VME1_A32D16_END},
    120       1.7       scw 
    121      1.11       scw 	{VME_AM_A16 |
    122      1.11       scw 	    MVMEBUS_AM_CAP_DATA  |
    123      1.11       scw 	    MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
    124       1.7       scw 		VME_D16 | VME_D8,
    125       1.7       scw 		VME1_A16D16_LOC_START,
    126      1.10       scw 		VME1_A16_MASK,
    127       1.7       scw 		VME1_A16D16_START,
    128       1.7       scw 		VME1_A16D16_END}
    129       1.7       scw };
    130      1.10       scw #define VME1_NMASTERS	(sizeof(vme_pcc_masters)/sizeof(struct mvmebus_range))
    131       1.1     chuck 
    132       1.1     chuck 
    133       1.7       scw /* ARGSUSED */
    134       1.1     chuck int
    135       1.7       scw vme_pcc_match(parent, cf, aux)
    136       1.1     chuck 	struct device *parent;
    137       1.4       gwr 	struct cfdata *cf;
    138       1.4       gwr 	void *aux;
    139       1.1     chuck {
    140       1.7       scw 	struct pcc_attach_args *pa;
    141       1.7       scw 
    142       1.7       scw 	pa = aux;
    143       1.1     chuck 
    144       1.1     chuck 	/* Only one VME chip, please. */
    145       1.7       scw 	if (vme_pcc_attached)
    146       1.1     chuck 		return (0);
    147       1.1     chuck 
    148       1.7       scw 	if (strcmp(pa->pa_name, vmepcc_cd.cd_name))
    149       1.1     chuck 		return (0);
    150       1.1     chuck 
    151       1.1     chuck 	return (1);
    152       1.1     chuck }
    153       1.1     chuck 
    154       1.1     chuck void
    155       1.7       scw vme_pcc_attach(parent, self, aux)
    156       1.7       scw 	struct device *parent;
    157       1.7       scw 	struct device *self;
    158       1.1     chuck 	void *aux;
    159       1.1     chuck {
    160       1.7       scw 	struct pcc_attach_args *pa;
    161       1.7       scw 	struct vme_pcc_softc *sc;
    162      1.11       scw 	vme_am_t am;
    163       1.7       scw 	u_int8_t reg;
    164       1.7       scw 
    165       1.7       scw 	sc = (struct vme_pcc_softc *) self;
    166       1.7       scw 	pa = aux;
    167       1.7       scw 
    168      1.10       scw 	/* Map the VMEchip's registers */
    169      1.13       scw 	bus_space_map(pa->pa_bust, pa->pa_offset, VME1REG_SIZE, 0,
    170       1.7       scw 	    &sc->sc_bush);
    171       1.1     chuck 
    172      1.13       scw 	/* Initialise stuff used by the mvme68k common VMEbus front-end */
    173      1.13       scw 	sc->sc_mvmebus.sc_bust = pa->pa_bust;
    174      1.13       scw 	sc->sc_mvmebus.sc_dmat = pa->pa_dmat;
    175      1.13       scw 	sc->sc_mvmebus.sc_chip = sc;
    176      1.13       scw 	sc->sc_mvmebus.sc_nmasters = VME1_NMASTERS;
    177      1.13       scw 	sc->sc_mvmebus.sc_masters = &vme_pcc_masters[0];
    178      1.13       scw 	sc->sc_mvmebus.sc_nslaves = VME1_NSLAVES;
    179      1.13       scw 	sc->sc_mvmebus.sc_slaves = &sc->sc_slave[0];
    180      1.13       scw 	sc->sc_mvmebus.sc_intr_establish = vme_pcc_intr_establish;
    181      1.13       scw 	sc->sc_mvmebus.sc_intr_disestablish = vme_pcc_intr_disestablish;
    182      1.13       scw 
    183       1.1     chuck 	/* Initialize the chip. */
    184       1.7       scw 	reg = vme1_reg_read(sc, VME1REG_SCON) & ~VME1_SCON_SYSFAIL;
    185       1.7       scw 	vme1_reg_write(sc, VME1REG_SCON, reg);
    186       1.1     chuck 
    187       1.3  christos 	printf(": Type 1 VMEchip, scon jumper %s\n",
    188       1.7       scw 	    (reg & VME1_SCON_SWITCH) ? "enabled" : "disabled");
    189       1.1     chuck 
    190       1.7       scw 	/*
    191      1.10       scw 	 * Adjust the start address of the first range in vme_pcc_masters[]
    192       1.7       scw 	 * according to how much onboard memory exists. Disable the first
    193       1.7       scw 	 * range if onboard memory >= 16Mb, and adjust the start of the
    194       1.7       scw 	 * second range (A32D32).
    195       1.7       scw 	 */
    196      1.10       scw 	vme_pcc_masters[0].vr_vmestart = (vme_addr_t) mem_clusters[0].size;
    197       1.7       scw 	if (mem_clusters[0].size >= 0x01000000) {
    198      1.10       scw 		vme_pcc_masters[0].vr_am = MVMEBUS_AM_DISABLED;
    199      1.10       scw 		vme_pcc_masters[1].vr_vmestart +=
    200       1.7       scw 		    (vme_addr_t) (mem_clusters[0].size - 0x01000000);
    201       1.7       scw 	}
    202       1.1     chuck 
    203      1.11       scw 	am = 0;
    204      1.11       scw 	reg = vme1_reg_read(sc, VME1REG_SLADDRMOD);
    205      1.11       scw 	if ((reg & VME1_SLMOD_DATA) != 0)
    206      1.11       scw 		am |= MVMEBUS_AM_CAP_DATA;
    207      1.11       scw 	if ((reg & VME1_SLMOD_PRGRM) != 0)
    208      1.11       scw 		am |= MVMEBUS_AM_CAP_PROG;
    209      1.11       scw 	if ((reg & VME1_SLMOD_SUPER) != 0)
    210      1.11       scw 		am |= MVMEBUS_AM_CAP_SUPER;
    211      1.11       scw 	if ((reg & VME1_SLMOD_USER) != 0)
    212      1.11       scw 		am |= MVMEBUS_AM_CAP_USER;
    213      1.11       scw 	if ((reg & VME1_SLMOD_BLOCK) != 0)
    214      1.11       scw 		am |= MVMEBUS_AM_CAP_BLK;
    215      1.11       scw 
    216      1.11       scw #ifdef notyet
    217      1.11       scw 	if ((reg & VME1_SLMOD_SHORT) != 0) {
    218      1.11       scw 		sc->sc_slave[VME1_SLAVE_A16].vr_am = am | VME_AM_A16;
    219      1.11       scw 		sc->sc_slave[VME1_SLAVE_A16].vr_mask = 0xffffu;
    220      1.11       scw 	} else
    221      1.11       scw #endif
    222      1.11       scw 		sc->sc_slave[VME1_SLAVE_A16].vr_am = MVMEBUS_AM_DISABLED;
    223      1.11       scw 
    224      1.11       scw 	if (pcc_slave_base_addr < 0x01000000u && (reg & VME1_SLMOD_STND) != 0) {
    225      1.11       scw 		sc->sc_slave[VME1_SLAVE_A24].vr_am = am | VME_AM_A24;
    226      1.11       scw 		sc->sc_slave[VME1_SLAVE_A24].vr_datasize = VME_D32 |
    227      1.11       scw 		    VME_D16 | VME_D8;
    228      1.11       scw 		sc->sc_slave[VME1_SLAVE_A24].vr_mask = 0xffffffu;
    229      1.11       scw 		sc->sc_slave[VME1_SLAVE_A24].vr_locstart = 0;
    230      1.11       scw 		sc->sc_slave[VME1_SLAVE_A24].vr_vmestart = pcc_slave_base_addr;
    231      1.11       scw 		sc->sc_slave[VME1_SLAVE_A24].vr_vmeend = (pcc_slave_base_addr +
    232      1.11       scw 		    mem_clusters[0].size - 1) & 0x00ffffffu;
    233      1.11       scw 	} else
    234      1.11       scw 		sc->sc_slave[VME1_SLAVE_A24].vr_am = MVMEBUS_AM_DISABLED;
    235      1.11       scw 
    236      1.11       scw 	if ((reg & VME1_SLMOD_EXTED) != 0) {
    237      1.11       scw 		sc->sc_slave[VME1_SLAVE_A32].vr_am = am | VME_AM_A32;
    238      1.11       scw 		sc->sc_slave[VME1_SLAVE_A32].vr_datasize = VME_D32 |
    239      1.11       scw 		    VME_D16 | VME_D8;
    240      1.11       scw 		sc->sc_slave[VME1_SLAVE_A32].vr_mask = 0xffffffffu;
    241      1.11       scw 		sc->sc_slave[VME1_SLAVE_A32].vr_locstart = 0;
    242      1.11       scw 		sc->sc_slave[VME1_SLAVE_A32].vr_vmestart = pcc_slave_base_addr;
    243      1.11       scw 		sc->sc_slave[VME1_SLAVE_A32].vr_vmeend =
    244      1.11       scw 		    pcc_slave_base_addr + mem_clusters[0].size - 1;
    245      1.11       scw 	} else
    246      1.11       scw 		sc->sc_slave[VME1_SLAVE_A32].vr_am = MVMEBUS_AM_DISABLED;
    247      1.11       scw 
    248      1.11       scw 	vme_pcc_attached = 1;
    249       1.1     chuck 
    250      1.10       scw 	mvmebus_attach(&sc->sc_mvmebus);
    251       1.7       scw }
    252       1.7       scw 
    253       1.7       scw void
    254      1.14       scw vme_pcc_intr_establish(csc, prior, level, vector, first, func, arg, evcnt)
    255      1.10       scw 	void *csc;
    256      1.12       scw 	int prior, level, vector, first;
    257      1.10       scw 	int (*func)(void *);
    258      1.10       scw 	void *arg;
    259      1.14       scw 	struct evcnt *evcnt;
    260       1.7       scw {
    261      1.10       scw 	struct vme_pcc_softc *sc = csc;
    262       1.7       scw 
    263      1.12       scw 	if (prior != level)
    264      1.12       scw 		panic("vme_pcc_intr_establish: cpu priority != VMEbus irq level");
    265      1.12       scw 
    266      1.14       scw 	isrlink_vectored(func, arg, prior, vector, evcnt);
    267       1.7       scw 
    268      1.10       scw 	if (first) {
    269      1.14       scw 		evcnt_attach_dynamic(evcnt, EVCNT_TYPE_INTR,
    270      1.14       scw 		    isrlink_evcnt(prior), sc->sc_mvmebus.sc_dev.dv_xname,
    271      1.14       scw 		    mvmebus_irq_name[level]);
    272      1.14       scw 
    273       1.7       scw 		/*
    274      1.10       scw 		 * There had better not be another VMEbus master responding
    275      1.10       scw 		 * to this interrupt level...
    276       1.7       scw 		 */
    277      1.10       scw 		vme1_reg_write(sc, VME1REG_IRQEN,
    278      1.10       scw 		    vme1_reg_read(sc, VME1REG_IRQEN) | VME1_IRQ_VME(level));
    279       1.7       scw 	}
    280       1.7       scw }
    281       1.1     chuck 
    282       1.7       scw void
    283      1.14       scw vme_pcc_intr_disestablish(csc, level, vector, last, evcnt)
    284      1.10       scw 	void *csc;
    285      1.10       scw 	int level, vector, last;
    286      1.14       scw 	struct evcnt *evcnt;
    287       1.7       scw {
    288      1.10       scw 	struct vme_pcc_softc *sc = csc;
    289       1.7       scw 
    290       1.7       scw 	isrunlink_vectored(vector);
    291       1.7       scw 
    292      1.10       scw 	if (last) {
    293       1.7       scw 		vme1_reg_write(sc, VME1REG_IRQEN,
    294       1.7       scw 		    vme1_reg_read(sc, VME1REG_IRQEN) & ~VME1_IRQ_VME(level));
    295      1.14       scw 		evcnt_detach(evcnt);
    296       1.1     chuck 	}
    297       1.7       scw }
    298