Home | History | Annotate | Line # | Download | only in dev
asp.c revision 1.2.4.1
      1  1.2.4.1  thorpej /*	$NetBSD: asp.c,v 1.2.4.1 2021/03/21 21:09:01 thorpej Exp $	*/
      2      1.1    skrll 
      3      1.1    skrll /*	$OpenBSD: asp.c,v 1.5 2000/02/09 05:04:22 mickey Exp $	*/
      4      1.1    skrll 
      5      1.1    skrll /*
      6      1.1    skrll  * Copyright (c) 1998-2003 Michael Shalayeff
      7      1.1    skrll  * All rights reserved.
      8      1.1    skrll  *
      9      1.1    skrll  * Redistribution and use in source and binary forms, with or without
     10      1.1    skrll  * modification, are permitted provided that the following conditions
     11      1.1    skrll  * are met:
     12      1.1    skrll  * 1. Redistributions of source code must retain the above copyright
     13      1.1    skrll  *    notice, this list of conditions and the following disclaimer.
     14      1.1    skrll  * 2. Redistributions in binary form must reproduce the above copyright
     15      1.1    skrll  *    notice, this list of conditions and the following disclaimer in the
     16      1.1    skrll  *    documentation and/or other materials provided with the distribution.
     17      1.1    skrll  *
     18      1.1    skrll  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19      1.1    skrll  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20      1.1    skrll  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21      1.1    skrll  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
     22      1.1    skrll  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23      1.1    skrll  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24      1.1    skrll  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25      1.1    skrll  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     26      1.1    skrll  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     27      1.1    skrll  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     28      1.1    skrll  * THE POSSIBILITY OF SUCH DAMAGE.
     29      1.1    skrll  */
     30      1.1    skrll 
     31      1.1    skrll /*
     32      1.1    skrll  * References:
     33      1.1    skrll  *
     34      1.1    skrll  * 1. Cobra/Coral I/O Subsystem External Reference Specification
     35      1.1    skrll  *    Hewlett-Packard
     36      1.1    skrll  *
     37      1.1    skrll  */
     38      1.1    skrll 
     39      1.1    skrll #include <sys/cdefs.h>
     40  1.2.4.1  thorpej __KERNEL_RCSID(0, "$NetBSD: asp.c,v 1.2.4.1 2021/03/21 21:09:01 thorpej Exp $");
     41      1.1    skrll 
     42      1.1    skrll #include <sys/param.h>
     43      1.1    skrll #include <sys/systm.h>
     44      1.1    skrll #include <sys/device.h>
     45      1.1    skrll #include <sys/reboot.h>
     46      1.1    skrll 
     47      1.1    skrll #include <sys/bus.h>
     48      1.1    skrll #include <machine/iomod.h>
     49      1.1    skrll #include <machine/autoconf.h>
     50      1.1    skrll #include <machine/cpufunc.h>
     51      1.1    skrll 
     52      1.1    skrll #include <hppa/hppa/machdep.h>
     53      1.1    skrll #include <hppa/dev/cpudevs.h>
     54      1.1    skrll #include <hppa/dev/viper.h>
     55      1.1    skrll 
     56      1.1    skrll #include <hppa/gsc/gscbusvar.h>
     57      1.1    skrll 
     58      1.1    skrll struct asp_hwr {
     59      1.1    skrll 	uint8_t asp_reset;
     60      1.1    skrll 	uint8_t asp_resv[31];
     61      1.1    skrll 	uint8_t asp_version;
     62      1.1    skrll 	uint8_t asp_resv1[15];
     63      1.1    skrll 	uint8_t asp_scsidsync;
     64      1.1    skrll 	uint8_t asp_resv2[15];
     65      1.1    skrll 	uint8_t asp_error;
     66      1.1    skrll };
     67      1.1    skrll 
     68      1.1    skrll struct asp_trs {
     69      1.1    skrll 	uint32_t asp_irr;
     70      1.1    skrll 	uint32_t asp_imr;
     71      1.1    skrll 	uint32_t asp_ipr;
     72      1.1    skrll 	uint32_t asp_icr;
     73      1.1    skrll 	uint32_t asp_iar;
     74      1.1    skrll 	uint32_t asp_resv[3];
     75      1.1    skrll 	uint8_t  asp_cled;
     76      1.1    skrll 	uint8_t  asp_resv1[3];
     77      1.1    skrll 	struct {
     78      1.1    skrll 		u_int		:20,
     79      1.1    skrll 			asp_spu	: 3,	/* SPU ID board jumper */
     80      1.1    skrll #define	ASP_SPUCOBRA	0
     81      1.1    skrll #define	ASP_SPUCORAL	1
     82      1.1    skrll #define	ASP_SPUBUSH	2
     83      1.1    skrll #define	ASP_SPUHARDBALL	3
     84      1.1    skrll #define	ASP_SPUSCORPIO	4
     85      1.1    skrll #define	ASP_SPUCORAL2	5
     86      1.1    skrll 			asp_sw	: 1,	/* front switch is normal */
     87      1.1    skrll 			asp_clk : 1,	/* SCSI clock is doubled */
     88      1.1    skrll 			asp_lan : 2,	/* LAN iface selector */
     89      1.1    skrll #define	ASP_LANINVAL	0
     90      1.1    skrll #define	ASP_LANAUI	1
     91      1.1    skrll #define	ASP_LANTHIN	2
     92      1.1    skrll #define	ASP_LANMISS	3
     93      1.1    skrll 			asp_lanf: 1,	/* LAN AUI fuse is ok */
     94      1.1    skrll 			asp_spwr: 1,	/* SCSI power ok */
     95      1.1    skrll 			asp_scsi: 3;	/* SCSI ctrl ID */
     96      1.1    skrll 	} _asp_ios;
     97      1.1    skrll #define	asp_spu		_asp_ios.asp_spu
     98      1.1    skrll #define	asp_sw		_asp_ios.asp_sw
     99      1.1    skrll #define	asp_clk		_asp_ios.asp_clk
    100      1.1    skrll #define	asp_lan		_asp_ios.asp_lan
    101      1.1    skrll #define	asp_lanf	_asp_ios.asp_lanf
    102      1.1    skrll #define	asp_spwr	_asp_ios.asp_spwr
    103      1.1    skrll #define	asp_scsi	_asp_ios.asp_scsi
    104      1.1    skrll };
    105      1.1    skrll 
    106      1.1    skrll #define	ASP_BANK_SZ	0x02000000
    107      1.1    skrll #define	ASP_REG_INT	0x00800000
    108      1.1    skrll #define	ASP_ETHER_ADDR	0x00810000
    109      1.1    skrll #define	ASP_REG_MISC	0x0082f000
    110      1.1    skrll 
    111      1.1    skrll const struct asp_spus_tag {
    112      1.1    skrll 	char	name[12];
    113      1.1    skrll 	int	ledword;
    114      1.1    skrll } asp_spus[] = {
    115      1.1    skrll 	{ "Cobra", 0 },
    116      1.1    skrll 	{ "Coral", 0 },
    117      1.1    skrll 	{ "Bushmaster", 0 },
    118      1.1    skrll 	{ "Hardball", 1 },
    119      1.1    skrll 	{ "Scorpio", 0 },
    120      1.1    skrll 	{ "Coral II", 1 },
    121      1.1    skrll 	{ "#6", 0 },
    122      1.1    skrll 	{ "#7", 0 }
    123      1.1    skrll };
    124      1.1    skrll 
    125      1.1    skrll struct asp_softc {
    126      1.1    skrll 	device_t sc_dev;
    127      1.1    skrll 
    128      1.1    skrll 	struct hppa_interrupt_register sc_ir;
    129      1.1    skrll 
    130      1.1    skrll 	volatile struct asp_hwr *sc_hw;
    131      1.1    skrll 	volatile struct asp_trs *sc_trs;
    132      1.1    skrll };
    133      1.1    skrll 
    134      1.1    skrll int	aspmatch(device_t, cfdata_t, void *);
    135      1.1    skrll void	aspattach(device_t, device_t, void *);
    136      1.1    skrll 
    137      1.1    skrll CFATTACH_DECL_NEW(asp, sizeof(struct asp_softc),
    138      1.1    skrll     aspmatch, aspattach, NULL, NULL);
    139      1.1    skrll 
    140      1.1    skrll /*
    141      1.1    skrll  * Before a module is matched, this fixes up its gsc_attach_args.
    142      1.1    skrll  */
    143      1.1    skrll static void asp_fix_args(void *, struct gsc_attach_args *);
    144      1.1    skrll static void
    145      1.1    skrll asp_fix_args(void *_sc, struct gsc_attach_args *ga)
    146      1.1    skrll {
    147      1.1    skrll 	hppa_hpa_t module_offset;
    148      1.1    skrll 	struct asp_softc *sc = _sc;
    149      1.1    skrll 
    150      1.1    skrll 	/*
    151      1.1    skrll 	 * Determine this module's interrupt bit.
    152      1.1    skrll 	 */
    153      1.1    skrll 	module_offset = ga->ga_hpa - (hppa_hpa_t) sc->sc_trs;
    154      1.1    skrll 	ga->ga_irq = HPPACF_IRQ_UNDEF;
    155      1.1    skrll #define ASP_IRQ(off, irq) if (module_offset == off) ga->ga_irq = irq
    156      1.1    skrll 	ASP_IRQ(0x22000, 6);	/* com1 */
    157      1.1    skrll 	ASP_IRQ(0x23000, 5);	/* com0 */
    158      1.1    skrll 	ASP_IRQ(0x24000, 7);	/* lpt */
    159      1.1    skrll 	ASP_IRQ(0x25000, 9);	/* osiop */
    160      1.1    skrll 	ASP_IRQ(0x26000, 8);	/* ie */
    161      1.1    skrll 	ASP_IRQ(0x30000, 3);	/* siop */
    162      1.1    skrll 	ASP_IRQ(0x800000, 13);	/* harmony */
    163      1.1    skrll #undef ASP_IRQ
    164      1.1    skrll }
    165      1.1    skrll 
    166      1.1    skrll int
    167      1.1    skrll aspmatch(device_t parent, cfdata_t cf, void *aux)
    168      1.1    skrll {
    169      1.1    skrll 	struct confargs *ca = aux;
    170      1.1    skrll 
    171      1.1    skrll 	if (ca->ca_type.iodc_type != HPPA_TYPE_BHA ||
    172      1.1    skrll 	    ca->ca_type.iodc_sv_model != HPPA_BHA_ASP)
    173      1.1    skrll 		return 0;
    174      1.1    skrll 
    175      1.1    skrll 	/*
    176      1.1    skrll 	 * Forcibly mask the HPA down to the start of the ASP
    177      1.1    skrll 	 * chip address space.
    178      1.1    skrll 	 */
    179      1.1    skrll 	ca->ca_hpa &= ~(ASP_BANK_SZ - 1);
    180      1.1    skrll 
    181      1.1    skrll 	return 1;
    182      1.1    skrll }
    183      1.1    skrll 
    184      1.1    skrll void
    185      1.1    skrll aspattach(device_t parent, device_t self, void *aux)
    186      1.1    skrll {
    187      1.1    skrll 	struct confargs *ca = aux;
    188      1.1    skrll 	struct asp_softc *sc = device_private(self);
    189      1.1    skrll 	struct gsc_attach_args ga;
    190      1.1    skrll 	struct cpu_info *ci = &cpus[0];
    191      1.1    skrll 	bus_space_handle_t ioh;
    192      1.1    skrll 	int s;
    193      1.1    skrll 
    194      1.1    skrll 	sc->sc_dev = self;
    195      1.1    skrll 
    196      1.1    skrll 	ca->ca_irq = hppa_intr_allocate_bit(&ci->ci_ir, ca->ca_irq);
    197      1.1    skrll 	if (ca->ca_irq == HPPACF_IRQ_UNDEF) {
    198      1.1    skrll 		aprint_error_dev(self, ": can't allocate interrupt");
    199      1.1    skrll 		return;
    200      1.1    skrll 	}
    201      1.1    skrll 
    202      1.1    skrll 	/*
    203      1.1    skrll 	 * Map the ASP interrupt registers.
    204      1.1    skrll 	 */
    205      1.1    skrll 	if (bus_space_map(ca->ca_iot, ca->ca_hpa + ASP_REG_INT,
    206      1.1    skrll 	    sizeof(struct asp_trs), 0, &ioh)) {
    207      1.1    skrll 		aprint_error(": can't map interrupt registers.\n");
    208      1.1    skrll 		return;
    209      1.1    skrll 	}
    210      1.1    skrll 	sc->sc_trs = (struct asp_trs *)ioh;
    211      1.1    skrll 
    212      1.1    skrll 	/*
    213      1.1    skrll 	 * Map the ASP miscellaneous registers.
    214      1.1    skrll 	 */
    215      1.1    skrll 	if (bus_space_map(ca->ca_iot, ca->ca_hpa + ASP_REG_MISC,
    216      1.1    skrll 			  sizeof(struct asp_hwr), 0, &ioh)) {
    217      1.1    skrll 		aprint_error(": can't map miscellaneous registers.\n");
    218      1.1    skrll 		return;
    219      1.1    skrll 	}
    220      1.1    skrll 	sc->sc_hw = (struct asp_hwr *)ioh;
    221      1.1    skrll 
    222      1.1    skrll 	/*
    223      1.1    skrll 	 * Map the Ethernet address and read it out.
    224      1.1    skrll 	 */
    225      1.1    skrll 	if (bus_space_map(ca->ca_iot, ca->ca_hpa + ASP_ETHER_ADDR,
    226      1.1    skrll 			  sizeof(ga.ga_ether_address), 0, &ioh)) {
    227      1.1    skrll 		aprint_error(": can't map EEPROM.\n");
    228      1.1    skrll 		return;
    229      1.1    skrll 	}
    230      1.1    skrll 	bus_space_read_region_1(ca->ca_iot, ioh, 0,
    231      1.1    skrll 		ga.ga_ether_address, sizeof(ga.ga_ether_address));
    232      1.1    skrll 	bus_space_unmap(ca->ca_iot, ioh, sizeof(ga.ga_ether_address));
    233      1.1    skrll 
    234      1.1    skrll #ifdef USELEDS
    235      1.1    skrll 	machine_ledaddr = &sc->sc_trs->asp_cled;
    236      1.1    skrll 	machine_ledword = asp_spus[sc->sc_trs->asp_spu].ledword;
    237      1.1    skrll #endif
    238      1.1    skrll 
    239      1.1    skrll 	/* reset ASP */
    240      1.1    skrll 	/* sc->sc_hw->asp_reset = 1; */
    241      1.1    skrll 	/* delay(400000); */
    242      1.1    skrll 
    243      1.1    skrll 	s = splhigh();
    244      1.1    skrll 	viper_setintrwnd(1 << ca->ca_irq);
    245      1.1    skrll 
    246      1.2    skrll 	sc->sc_trs->asp_imr = 0;
    247      1.1    skrll 	(void)sc->sc_trs->asp_irr;
    248      1.1    skrll 
    249      1.1    skrll 	/* Establish the interrupt register. */
    250      1.1    skrll 	hppa_interrupt_register_establish(ci, &sc->sc_ir);
    251      1.1    skrll 	sc->sc_ir.ir_name = device_xname(self);
    252      1.1    skrll 	sc->sc_ir.ir_mask = &sc->sc_trs->asp_imr;
    253      1.1    skrll 	sc->sc_ir.ir_req = &sc->sc_trs->asp_irr;
    254      1.1    skrll 
    255      1.1    skrll 	splx(s);
    256      1.1    skrll 
    257      1.1    skrll 	aprint_normal(": %s rev %d, lan %d scsi %d\n",
    258      1.1    skrll 	    asp_spus[sc->sc_trs->asp_spu].name, sc->sc_hw->asp_version,
    259      1.1    skrll 	    sc->sc_trs->asp_lan, sc->sc_trs->asp_scsi);
    260      1.1    skrll 
    261      1.1    skrll 	/* Attach the GSC bus. */
    262      1.1    skrll 	ga.ga_ca = *ca;	/* clone from us */
    263      1.1    skrll 	if (strcmp(device_xname(parent), "mainbus0") == 0) {
    264      1.1    skrll 		ga.ga_dp.dp_bc[0] = ga.ga_dp.dp_bc[1];
    265      1.1    skrll 		ga.ga_dp.dp_bc[1] = ga.ga_dp.dp_bc[2];
    266      1.1    skrll 		ga.ga_dp.dp_bc[2] = ga.ga_dp.dp_bc[3];
    267      1.1    skrll 		ga.ga_dp.dp_bc[3] = ga.ga_dp.dp_bc[4];
    268      1.1    skrll 		ga.ga_dp.dp_bc[4] = ga.ga_dp.dp_bc[5];
    269      1.1    skrll 		ga.ga_dp.dp_bc[5] = ga.ga_dp.dp_mod;
    270      1.1    skrll 		ga.ga_dp.dp_mod = 0;
    271      1.1    skrll 	}
    272      1.1    skrll 
    273      1.1    skrll 	ga.ga_name = "gsc";
    274      1.1    skrll 	ga.ga_ir = &sc->sc_ir;
    275      1.1    skrll 	ga.ga_fix_args = asp_fix_args;
    276      1.1    skrll 	ga.ga_fix_args_cookie = sc;
    277      1.1    skrll 	ga.ga_scsi_target = sc->sc_trs->asp_scsi;
    278  1.2.4.1  thorpej 	config_found(self, &ga, gscprint, CFARG_EOL);
    279      1.1    skrll }
    280