Home | History | Annotate | Line # | Download | only in dev
sgc.c revision 1.2.74.1
      1  1.2.74.1  thorpej /*	$NetBSD: sgc.c,v 1.2.74.1 2021/03/21 21:09:00 thorpej Exp $	*/
      2       1.1  tsutsui /*	$OpenBSD: sgc.c,v 1.6 2010/04/15 20:35:21 miod Exp $	*/
      3       1.1  tsutsui 
      4       1.1  tsutsui /*
      5       1.1  tsutsui  * Copyright (c) 2005, Miodrag Vallat
      6       1.1  tsutsui  *
      7       1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
      8       1.1  tsutsui  * modification, are permitted provided that the following conditions
      9       1.1  tsutsui  * are met:
     10       1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     11       1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     12       1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     14       1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     15       1.1  tsutsui  *
     16       1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17       1.1  tsutsui  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     18       1.1  tsutsui  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     19       1.1  tsutsui  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     20       1.1  tsutsui  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     21       1.1  tsutsui  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22       1.1  tsutsui  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23       1.1  tsutsui  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     24       1.1  tsutsui  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     25       1.1  tsutsui  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26       1.1  tsutsui  * POSSIBILITY OF SUCH DAMAGE.
     27       1.1  tsutsui  *
     28       1.1  tsutsui  */
     29       1.1  tsutsui 
     30       1.1  tsutsui /*
     31       1.1  tsutsui  * SGC bus attachment and mapping glue.
     32       1.1  tsutsui  */
     33       1.1  tsutsui 
     34       1.1  tsutsui #include <sys/param.h>
     35       1.1  tsutsui #include <sys/systm.h>
     36       1.1  tsutsui #include <sys/device.h>
     37       1.1  tsutsui #include <sys/kernel.h>
     38       1.1  tsutsui #include <sys/bus.h>
     39       1.1  tsutsui #include <sys/cpu.h>
     40       1.1  tsutsui 
     41       1.1  tsutsui #include <machine/autoconf.h>
     42       1.1  tsutsui #include <machine/hp300spu.h>
     43       1.1  tsutsui 
     44       1.1  tsutsui #include <hp300/dev/sgcreg.h>
     45       1.1  tsutsui #include <hp300/dev/sgcvar.h>
     46       1.1  tsutsui 
     47       1.1  tsutsui #ifdef SGC_DEBUG
     48       1.1  tsutsui #define DPRINTF(x)	printf x
     49       1.1  tsutsui #else
     50       1.1  tsutsui #define DPRINTF(x)	do {} while (/* CONSTCOND */ 0)
     51       1.1  tsutsui #endif
     52       1.1  tsutsui 
     53       1.1  tsutsui struct sgc_softc {
     54       1.1  tsutsui 	device_t sc_dev;
     55       1.1  tsutsui 	struct bus_space_tag sc_tag;
     56       1.1  tsutsui };
     57       1.1  tsutsui 
     58       1.2  tsutsui static int	sgcmatch(device_t, cfdata_t, void *);
     59       1.2  tsutsui static void	sgcattach(device_t, device_t, void *);
     60       1.2  tsutsui static int	sgcprint(void *, const char *);
     61       1.1  tsutsui 
     62       1.1  tsutsui CFATTACH_DECL_NEW(sgc, sizeof(struct sgc_softc),
     63       1.1  tsutsui     sgcmatch, sgcattach, NULL, NULL);
     64       1.1  tsutsui 
     65       1.1  tsutsui int
     66       1.1  tsutsui sgcmatch(device_t parent, cfdata_t cf, void *aux)
     67       1.1  tsutsui {
     68       1.1  tsutsui 	static int sgc_matched = 0;
     69       1.1  tsutsui 
     70       1.1  tsutsui 	/* Allow only one instance. */
     71       1.1  tsutsui 	if (sgc_matched)
     72       1.1  tsutsui 		return 0;
     73       1.1  tsutsui 
     74       1.1  tsutsui 	/*
     75       1.1  tsutsui 	 * Leave out machines which can not have an SGC bus.
     76       1.1  tsutsui 	 */
     77       1.1  tsutsui 
     78       1.1  tsutsui 	switch (machineid) {
     79       1.1  tsutsui #if 0
     80       1.1  tsutsui 	case HP_362:
     81       1.1  tsutsui 	case HP_382:
     82       1.1  tsutsui #endif
     83       1.1  tsutsui 	case HP_400:
     84       1.1  tsutsui 	case HP_425:
     85       1.1  tsutsui 	case HP_433:
     86       1.1  tsutsui 		return sgc_matched = 1;
     87       1.1  tsutsui 	default:
     88       1.1  tsutsui 		return 0;
     89       1.1  tsutsui 	}
     90       1.1  tsutsui }
     91       1.1  tsutsui 
     92       1.1  tsutsui void
     93       1.1  tsutsui sgcattach(device_t parent, device_t self, void *aux)
     94       1.1  tsutsui {
     95       1.1  tsutsui 	struct sgc_softc *sc;
     96       1.1  tsutsui 	struct sgc_attach_args saa;
     97       1.1  tsutsui 	paddr_t pa;
     98       1.1  tsutsui 	void *va;
     99       1.1  tsutsui 	int slot, rv;
    100       1.1  tsutsui 	bus_space_tag_t bst;
    101       1.1  tsutsui 	bus_space_handle_t bsh;
    102       1.1  tsutsui 
    103       1.1  tsutsui 	sc = device_private(self);
    104       1.1  tsutsui 	sc->sc_dev = self;
    105       1.1  tsutsui 	aprint_normal("\n");
    106       1.1  tsutsui 
    107       1.1  tsutsui 	bst = &sc->sc_tag;
    108       1.1  tsutsui 	memset(bst, 0, sizeof(struct bus_space_tag));
    109       1.1  tsutsui 	bst->bustype = HP300_BUS_SPACE_SGC;
    110       1.1  tsutsui 
    111       1.1  tsutsui 	for (slot = 0; slot < SGC_NSLOTS; slot++) {
    112       1.1  tsutsui 		pa = sgc_slottopa(slot);
    113       1.1  tsutsui 		if (bus_space_map(bst, pa, PAGE_SIZE, 0, &bsh) != 0) {
    114       1.1  tsutsui 			aprint_error_dev(self, "can't map slot %d\n", slot);
    115       1.1  tsutsui 			continue;
    116       1.1  tsutsui 		}
    117       1.1  tsutsui 		va = bus_space_vaddr(bst, bsh);
    118       1.1  tsutsui 
    119       1.1  tsutsui 		/* Check for hardware. */
    120       1.1  tsutsui 		rv = badaddr(va);
    121       1.1  tsutsui 		bus_space_unmap(bst, bsh, PAGE_SIZE);
    122       1.1  tsutsui 
    123       1.1  tsutsui 		if (rv != 0) {
    124       1.1  tsutsui 			DPRINTF(("%s: no valid device at slot %d\n",
    125       1.1  tsutsui 			    device_xname(self), slot));
    126       1.1  tsutsui 			continue;
    127       1.1  tsutsui 		}
    128       1.1  tsutsui 
    129       1.1  tsutsui 		memset(&saa, 0, sizeof(saa));
    130       1.1  tsutsui 		saa.saa_iot = bst;
    131       1.1  tsutsui 		saa.saa_slot = slot;
    132       1.1  tsutsui 
    133       1.1  tsutsui 		/* Attach matching device. */
    134  1.2.74.1  thorpej 		config_found(self, &saa, sgcprint, CFARG_EOL);
    135       1.1  tsutsui 	}
    136       1.1  tsutsui }
    137       1.1  tsutsui 
    138       1.1  tsutsui int
    139       1.1  tsutsui sgcprint(void *aux, const char *pnp)
    140       1.1  tsutsui {
    141       1.1  tsutsui 	struct sgc_attach_args *saa = aux;
    142       1.1  tsutsui 
    143       1.1  tsutsui 	if (pnp)
    144       1.1  tsutsui 		aprint_normal("unknown SGC card at %s", pnp);
    145       1.1  tsutsui 	aprint_normal(" slot %d", saa->saa_slot);
    146       1.1  tsutsui 	return UNCONF;
    147       1.1  tsutsui }
    148       1.1  tsutsui 
    149       1.1  tsutsui /*
    150       1.1  tsutsui  * Convert a slot number to a system physical address.
    151       1.1  tsutsui  * This is needed for bus_space.
    152       1.1  tsutsui  */
    153       1.1  tsutsui paddr_t
    154       1.1  tsutsui sgc_slottopa(int slot)
    155       1.1  tsutsui {
    156       1.1  tsutsui 	paddr_t rval;
    157       1.1  tsutsui 
    158       1.1  tsutsui 	if (slot < 0 || slot >= SGC_NSLOTS)
    159       1.1  tsutsui 		rval = 0;
    160       1.1  tsutsui 	else
    161       1.1  tsutsui 		rval = SGC_BASE + (slot * SGC_DEVSIZE);
    162       1.1  tsutsui 
    163       1.1  tsutsui 	return rval;
    164       1.1  tsutsui }
    165