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