Home | History | Annotate | Line # | Download | only in dev
frodo.c revision 1.27.40.1
      1  1.27.40.1       mjf /*	$NetBSD: frodo.c,v 1.27.40.1 2008/04/03 12:42:15 mjf Exp $	*/
      2        1.2   thorpej 
      3        1.2   thorpej /*-
      4        1.5   thorpej  * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
      5        1.2   thorpej  * All rights reserved.
      6        1.2   thorpej  *
      7        1.2   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8        1.2   thorpej  * by Jason R. Thorpe.
      9        1.2   thorpej  *
     10        1.2   thorpej  * Redistribution and use in source and binary forms, with or without
     11        1.2   thorpej  * modification, are permitted provided that the following conditions
     12        1.2   thorpej  * are met:
     13        1.2   thorpej  * 1. Redistributions of source code must retain the above copyright
     14        1.2   thorpej  *    notice, this list of conditions and the following disclaimer.
     15        1.2   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.2   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17        1.2   thorpej  *    documentation and/or other materials provided with the distribution.
     18        1.2   thorpej  * 3. All advertising materials mentioning features or use of this software
     19        1.2   thorpej  *    must display the following acknowledgement:
     20        1.2   thorpej  *	This product includes software developed by the NetBSD
     21        1.2   thorpej  *	Foundation, Inc. and its contributors.
     22        1.2   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23        1.2   thorpej  *    contributors may be used to endorse or promote products derived
     24        1.2   thorpej  *    from this software without specific prior written permission.
     25        1.2   thorpej  *
     26        1.2   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27        1.2   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28        1.2   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29        1.2   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30        1.2   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31        1.2   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32        1.2   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33        1.2   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34        1.2   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35        1.2   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36        1.2   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37        1.2   thorpej  */
     38        1.1   thorpej 
     39        1.1   thorpej /*
     40        1.1   thorpej  * Copyright (c) 1997 Michael Smith.  All rights reserved.
     41        1.1   thorpej  *
     42        1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     43        1.1   thorpej  * modification, are permitted provided that the following conditions
     44        1.1   thorpej  * are met:
     45        1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     46        1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     47        1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     48        1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     49        1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     50        1.1   thorpej  *
     51        1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     52        1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     53        1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     54        1.1   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     55        1.1   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     56        1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     57        1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     58        1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     59        1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     60        1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     61        1.1   thorpej  * SUCH DAMAGE.
     62        1.1   thorpej  */
     63        1.1   thorpej 
     64        1.1   thorpej /*
     65        1.1   thorpej  * Support for the "Frodo" (a.k.a. "Apollo Utility") chip found
     66       1.26   tsutsui  * in HP Apollo 9000/4xx workstations, as well as
     67       1.26   tsutsui  * HP 9000/362 and 9000/382 controllers.
     68        1.1   thorpej  */
     69        1.9  gmcgarry 
     70        1.9  gmcgarry #include <sys/cdefs.h>
     71  1.27.40.1       mjf __KERNEL_RCSID(0, "$NetBSD: frodo.c,v 1.27.40.1 2008/04/03 12:42:15 mjf Exp $");
     72        1.1   thorpej 
     73        1.1   thorpej #define	_HP300_INTR_H_PRIVATE
     74        1.1   thorpej 
     75        1.1   thorpej #include <sys/param.h>
     76        1.1   thorpej #include <sys/systm.h>
     77        1.1   thorpej #include <sys/kernel.h>
     78        1.1   thorpej #include <sys/syslog.h>
     79        1.1   thorpej #include <sys/device.h>
     80        1.1   thorpej 
     81       1.15   tsutsui #include <machine/bus.h>
     82        1.1   thorpej #include <machine/cpu.h>
     83        1.1   thorpej #include <machine/intr.h>
     84        1.1   thorpej #include <machine/hp300spu.h>
     85        1.1   thorpej 
     86        1.1   thorpej #include <hp300/dev/intiovar.h>
     87        1.1   thorpej 
     88        1.1   thorpej #include <hp300/dev/frodoreg.h>
     89        1.1   thorpej #include <hp300/dev/frodovar.h>
     90        1.1   thorpej 
     91        1.1   thorpej /*
     92        1.1   thorpej  * Description of a Frodo interrupt handler.
     93        1.1   thorpej  */
     94        1.8  gmcgarry struct frodo_interhand {
     95       1.18   thorpej 	int	(*ih_fn)(void *);
     96        1.8  gmcgarry 	void	*ih_arg;
     97        1.8  gmcgarry 	int	ih_priority;
     98        1.1   thorpej };
     99        1.1   thorpej 
    100        1.1   thorpej struct frodo_softc {
    101  1.27.40.1       mjf 	device_t	sc_dev;		/* generic device glue */
    102       1.19   tsutsui 	volatile uint8_t *sc_regs;	/* register base */
    103        1.8  gmcgarry 	struct frodo_interhand sc_intr[FRODO_NINTR]; /* interrupt handlers */
    104        1.6  gmcgarry 	int		sc_ipl;
    105        1.1   thorpej 	void		*sc_ih;		/* out interrupt cookie */
    106        1.1   thorpej 	int		sc_refcnt;	/* number of interrupt refs */
    107       1.15   tsutsui 	struct bus_space_tag sc_tag;	/* bus space tag */
    108        1.1   thorpej };
    109        1.1   thorpej 
    110  1.27.40.1       mjf static int	frodomatch(device_t, cfdata_t, void *);
    111  1.27.40.1       mjf static void	frodoattach(device_t, device_t, void *);
    112        1.1   thorpej 
    113       1.18   thorpej static int	frodoprint(void *, const char *);
    114  1.27.40.1       mjf static int	frodosubmatch(device_t, cfdata_t, const int *, void *);
    115        1.1   thorpej 
    116       1.18   thorpej static int	frodointr(void *);
    117        1.1   thorpej 
    118       1.19   tsutsui static void	frodo_imask(struct frodo_softc *, uint16_t, uint16_t);
    119        1.1   thorpej 
    120  1.27.40.1       mjf CFATTACH_DECL_NEW(frodo, sizeof(struct frodo_softc),
    121       1.13   thorpej     frodomatch, frodoattach, NULL, NULL);
    122        1.1   thorpej 
    123       1.18   thorpej static const struct frodo_device frodo_subdevs[] = {
    124        1.1   thorpej 	{ "dnkbd",	FRODO_APCI_OFFSET(0),	FRODO_INTR_APCI0 },
    125       1.17   tsutsui 	{ "com",	FRODO_APCI_OFFSET(1),	FRODO_INTR_APCI1 },
    126       1.17   tsutsui 	{ "com",	FRODO_APCI_OFFSET(2),	FRODO_INTR_APCI2 },
    127       1.17   tsutsui 	{ "com",	FRODO_APCI_OFFSET(3),	FRODO_INTR_APCI3 },
    128       1.25   tsutsui 	{ NULL,		0,			0 }
    129        1.1   thorpej };
    130        1.1   thorpej 
    131       1.18   thorpej static int
    132  1.27.40.1       mjf frodomatch(device_t parent, cfdata_t cf, void *aux)
    133        1.1   thorpej {
    134        1.1   thorpej 	struct intio_attach_args *ia = aux;
    135        1.1   thorpej 	static int frodo_matched = 0;
    136        1.1   thorpej 
    137        1.1   thorpej 	/* only allow one instance */
    138        1.1   thorpej 	if (frodo_matched)
    139       1.25   tsutsui 		return 0;
    140        1.1   thorpej 
    141       1.10  gmcgarry 	if (strcmp(ia->ia_modname, "frodo") != 0)
    142       1.25   tsutsui 		return 0;
    143        1.1   thorpej 
    144       1.27  christos 	if (badaddr((void *)ia->ia_addr))
    145       1.25   tsutsui 		return 0;
    146        1.1   thorpej 
    147        1.1   thorpej 	frodo_matched = 1;
    148       1.25   tsutsui 	return 1;
    149        1.1   thorpej }
    150        1.1   thorpej 
    151       1.18   thorpej static void
    152  1.27.40.1       mjf frodoattach(device_t parent, device_t self, void *aux)
    153        1.1   thorpej {
    154  1.27.40.1       mjf 	struct frodo_softc *sc = device_private(self);
    155        1.1   thorpej 	struct intio_attach_args *ia = aux;
    156       1.15   tsutsui 	bus_space_tag_t bst = &sc->sc_tag;
    157       1.18   thorpej 	const struct frodo_device *fd;
    158       1.15   tsutsui 	struct frodo_attach_args fa;
    159        1.1   thorpej 
    160  1.27.40.1       mjf 	sc->sc_dev = self;
    161       1.19   tsutsui 	sc->sc_regs = (volatile uint8_t *)ia->ia_addr;
    162        1.6  gmcgarry 	sc->sc_ipl = ia->ia_ipl;
    163        1.1   thorpej 
    164        1.1   thorpej 	if ((FRODO_READ(sc, FRODO_IISR) & FRODO_IISR_SERVICE) == 0)
    165  1.27.40.1       mjf 		aprint_error(": service mode enabled");
    166  1.27.40.1       mjf 	aprint_normal("\n");
    167        1.1   thorpej 
    168       1.15   tsutsui 	/* Initialize bus_space_tag_t for frodo */
    169       1.15   tsutsui 	frodo_init_bus_space(bst);
    170       1.15   tsutsui 
    171        1.1   thorpej 	/* Clear all of the interrupt handlers. */
    172        1.7  gmcgarry 	memset(sc->sc_intr, 0, sizeof(sc->sc_intr));
    173        1.1   thorpej 	sc->sc_refcnt = 0;
    174        1.1   thorpej 
    175        1.1   thorpej 	/*
    176        1.1   thorpej 	 * Disable all of the interrupt lines; we reenable them
    177        1.1   thorpej 	 * as subdevices attach.
    178        1.1   thorpej 	 */
    179        1.1   thorpej 	frodo_imask(sc, 0, 0xffff);
    180        1.1   thorpej 
    181        1.1   thorpej 	/* Clear any pending interrupts. */
    182        1.1   thorpej 	FRODO_WRITE(sc, FRODO_PIC_PU, 0xff);
    183        1.1   thorpej 	FRODO_WRITE(sc, FRODO_PIC_PL, 0xff);
    184        1.1   thorpej 
    185        1.1   thorpej 	/* Set interrupt polarities. */
    186        1.1   thorpej 	FRODO_WRITE(sc, FRODO_PIO_IPR, 0x10);
    187        1.1   thorpej 
    188        1.1   thorpej 	/* ...and configure for edge triggering. */
    189        1.1   thorpej 	FRODO_WRITE(sc, FRODO_PIO_IELR, 0xcf);
    190        1.1   thorpej 
    191        1.1   thorpej 	/*
    192        1.1   thorpej 	 * We defer hooking up our interrupt handler until
    193        1.1   thorpej 	 * a subdevice hooks up theirs.
    194        1.1   thorpej 	 */
    195        1.1   thorpej 	sc->sc_ih = NULL;
    196        1.1   thorpej 
    197        1.1   thorpej 	/* ... and attach subdevices. */
    198       1.15   tsutsui 	for (fd = frodo_subdevs; fd->fd_name != NULL; fd++) {
    199        1.5   thorpej 		/*
    200        1.5   thorpej 		 * Skip the first serial port if we're not a 425e;
    201        1.5   thorpej 		 * it's mapped to the DCA at select code 9 on all
    202        1.5   thorpej 		 * other models.
    203        1.5   thorpej 		 */
    204       1.15   tsutsui 		if (fd->fd_offset == FRODO_APCI_OFFSET(1) &&
    205        1.5   thorpej 		    mmuid != MMUID_425_E)
    206        1.5   thorpej 			continue;
    207       1.15   tsutsui 		fa.fa_name = fd->fd_name;
    208       1.15   tsutsui 		fa.fa_bst = bst;
    209       1.24   tsutsui 		fa.fa_base = ia->ia_iobase;
    210       1.15   tsutsui 		fa.fa_offset = fd->fd_offset;
    211       1.15   tsutsui 		fa.fa_line = fd->fd_line;
    212       1.20  drochner 		config_found_sm_loc(self, "frodo", NULL, &fa, frodoprint,
    213       1.25   tsutsui 		    frodosubmatch);
    214        1.5   thorpej 	}
    215        1.1   thorpej }
    216        1.1   thorpej 
    217       1.18   thorpej static int
    218  1.27.40.1       mjf frodosubmatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    219        1.1   thorpej {
    220        1.1   thorpej 	struct frodo_attach_args *fa = aux;
    221        1.1   thorpej 
    222        1.1   thorpej 	if (cf->frodocf_offset != FRODO_UNKNOWN_OFFSET &&
    223        1.1   thorpej 	    cf->frodocf_offset != fa->fa_offset)
    224       1.25   tsutsui 		return 0;
    225        1.1   thorpej 
    226       1.25   tsutsui 	return config_match(parent, cf, aux);
    227        1.1   thorpej }
    228        1.1   thorpej 
    229       1.18   thorpej static int
    230       1.18   thorpej frodoprint(void *aux, const char *pnp)
    231        1.1   thorpej {
    232        1.1   thorpej 	struct frodo_attach_args *fa = aux;
    233        1.1   thorpej 
    234        1.1   thorpej 	if (pnp)
    235       1.14   thorpej 		aprint_normal("%s at %s", fa->fa_name, pnp);
    236       1.14   thorpej 	aprint_normal(" offset 0x%x", fa->fa_offset);
    237       1.25   tsutsui 	return UNCONF;
    238        1.1   thorpej }
    239        1.1   thorpej 
    240        1.1   thorpej void
    241  1.27.40.1       mjf frodo_intr_establish(device_t frdev, int (*func)(void *), void *arg,
    242       1.18   thorpej     int line, int priority)
    243        1.1   thorpej {
    244  1.27.40.1       mjf 	struct frodo_softc *sc = device_private(frdev);
    245        1.8  gmcgarry 	struct hp300_intrhand *ih = sc->sc_ih;
    246        1.1   thorpej 
    247        1.1   thorpej 	if (line < 0 || line >= FRODO_NINTR) {
    248  1.27.40.1       mjf 		aprint_error_dev(frdev, "bad interrupt line %d\n", line);
    249        1.1   thorpej 		goto lose;
    250        1.1   thorpej 	}
    251        1.8  gmcgarry 	if (sc->sc_intr[line].ih_fn != NULL) {
    252  1.27.40.1       mjf 		aprint_error_dev(frdev, "interrupt line %d already used\n",
    253  1.27.40.1       mjf 		    line);
    254        1.1   thorpej 		goto lose;
    255        1.1   thorpej 	}
    256        1.1   thorpej 
    257        1.1   thorpej 	/* Install the handler. */
    258        1.8  gmcgarry 	sc->sc_intr[line].ih_fn = func;
    259        1.8  gmcgarry 	sc->sc_intr[line].ih_arg = arg;
    260        1.8  gmcgarry 	sc->sc_intr[line].ih_priority = priority;
    261        1.1   thorpej 
    262        1.1   thorpej 	/*
    263        1.1   thorpej 	 * If this is the first one, establish the frodo
    264        1.1   thorpej 	 * interrupt handler.  If not, reestablish at a
    265        1.1   thorpej 	 * higher priority if necessary.
    266        1.1   thorpej 	 */
    267        1.8  gmcgarry 	if (ih == NULL || ih->ih_priority < priority) {
    268        1.8  gmcgarry 		if (ih != NULL)
    269        1.8  gmcgarry 			intr_disestablish(ih);
    270        1.6  gmcgarry 		sc->sc_ih = intr_establish(frodointr, sc, sc->sc_ipl, priority);
    271        1.1   thorpej 	}
    272        1.1   thorpej 
    273        1.1   thorpej 	sc->sc_refcnt++;
    274        1.1   thorpej 
    275        1.1   thorpej 	/* Enable the interrupt line. */
    276        1.1   thorpej 	frodo_imask(sc, (1 << line), 0);
    277        1.1   thorpej 	return;
    278        1.1   thorpej  lose:
    279        1.1   thorpej 	panic("frodo_intr_establish");
    280        1.1   thorpej }
    281        1.1   thorpej 
    282        1.1   thorpej void
    283  1.27.40.1       mjf frodo_intr_disestablish(device_t frdev, int line)
    284        1.1   thorpej {
    285  1.27.40.1       mjf 	struct frodo_softc *sc = device_private(frdev);
    286        1.8  gmcgarry 	struct hp300_intrhand *ih = sc->sc_ih;
    287        1.1   thorpej 	int newpri;
    288        1.1   thorpej 
    289        1.8  gmcgarry 	if (sc->sc_intr[line].ih_fn == NULL) {
    290        1.1   thorpej 		printf("%s: no handler for line %d\n",
    291  1.27.40.1       mjf 		    device_xname(sc->sc_dev), line);
    292        1.1   thorpej 		panic("frodo_intr_disestablish");
    293        1.1   thorpej 	}
    294        1.1   thorpej 
    295        1.8  gmcgarry 	sc->sc_intr[line].ih_fn = NULL;
    296        1.1   thorpej 	frodo_imask(sc, 0, (1 << line));
    297        1.1   thorpej 
    298        1.1   thorpej 	/* If this was the last, unhook ourselves. */
    299        1.1   thorpej 	if (sc->sc_refcnt-- == 1) {
    300        1.8  gmcgarry 		intr_disestablish(ih);
    301        1.1   thorpej 		return;
    302        1.1   thorpej 	}
    303        1.1   thorpej 
    304        1.1   thorpej 	/* Lower our priority, if appropriate. */
    305        1.1   thorpej 	for (newpri = 0, line = 0; line < FRODO_NINTR; line++)
    306        1.8  gmcgarry 		if (sc->sc_intr[line].ih_fn != NULL &&
    307        1.8  gmcgarry 		    sc->sc_intr[line].ih_priority > newpri)
    308        1.8  gmcgarry 			newpri = sc->sc_intr[line].ih_priority;
    309        1.1   thorpej 
    310        1.8  gmcgarry 	if (newpri != ih->ih_priority) {
    311        1.8  gmcgarry 		intr_disestablish(ih);
    312        1.6  gmcgarry 		sc->sc_ih = intr_establish(frodointr, sc, sc->sc_ipl, newpri);
    313        1.1   thorpej 	}
    314        1.1   thorpej }
    315        1.1   thorpej 
    316       1.18   thorpej static int
    317       1.18   thorpej frodointr(void *arg)
    318        1.1   thorpej {
    319        1.1   thorpej 	struct frodo_softc *sc = arg;
    320        1.8  gmcgarry 	struct frodo_interhand *fih;
    321        1.1   thorpej 	int line, taken = 0;
    322        1.1   thorpej 
    323        1.1   thorpej 	/* Any interrupts pending? */
    324        1.1   thorpej 	if (FRODO_GETPEND(sc) == 0)
    325       1.25   tsutsui 		return 0;
    326        1.1   thorpej 
    327        1.1   thorpej 	do {
    328        1.1   thorpej 		/*
    329        1.1   thorpej 		 * Get pending interrupt; this also clears it for us.
    330        1.1   thorpej 		 */
    331        1.1   thorpej 		line = FRODO_IPEND(sc);
    332        1.8  gmcgarry 		fih = &sc->sc_intr[line];
    333        1.8  gmcgarry 		if (fih->ih_fn == NULL ||
    334        1.8  gmcgarry 		    (*fih->ih_fn)(fih->ih_arg) == 0)
    335        1.1   thorpej 			printf("%s: spurious interrupt on line %d\n",
    336  1.27.40.1       mjf 			    device_xname(sc->sc_dev), line);
    337        1.1   thorpej 		if (taken++ > 100)
    338        1.1   thorpej 			panic("frodointr: looping!");
    339        1.1   thorpej 	} while (FRODO_GETPEND(sc) != 0);
    340        1.1   thorpej 
    341       1.25   tsutsui 	return 1;
    342        1.1   thorpej }
    343        1.1   thorpej 
    344       1.18   thorpej static void
    345       1.19   tsutsui frodo_imask(struct frodo_softc *sc, uint16_t set, uint16_t clear)
    346        1.1   thorpej {
    347       1.19   tsutsui 	uint16_t imask;
    348        1.1   thorpej 
    349        1.1   thorpej 	imask = FRODO_GETMASK(sc);
    350        1.1   thorpej 
    351        1.1   thorpej 	imask |= set;
    352        1.1   thorpej 	imask &= ~clear;
    353        1.1   thorpej 
    354        1.1   thorpej 	FRODO_SETMASK(sc, imask);
    355       1.15   tsutsui }
    356       1.15   tsutsui 
    357       1.15   tsutsui /*
    358       1.15   tsutsui  * frodo chip specific bus_space(9) support functions.
    359       1.15   tsutsui  */
    360       1.19   tsutsui static uint8_t frodo_bus_space_read_sparse_1(bus_space_tag_t,
    361       1.18   thorpej     bus_space_handle_t, bus_size_t);
    362       1.18   thorpej static void frodo_bus_space_write_sparse_1(bus_space_tag_t,
    363       1.19   tsutsui     bus_space_handle_t, bus_size_t, uint8_t);
    364       1.18   thorpej 
    365       1.18   thorpej static void frodo_bus_space_read_multi_sparse_1(bus_space_tag_t,
    366       1.19   tsutsui     bus_space_handle_t, bus_size_t, uint8_t *, bus_size_t);
    367       1.18   thorpej static void frodo_bus_space_write_multi_sparse_1(bus_space_tag_t,
    368       1.19   tsutsui     bus_space_handle_t, bus_size_t, const uint8_t *, bus_size_t);
    369       1.18   thorpej 
    370       1.18   thorpej static void frodo_bus_space_read_region_sparse_1(bus_space_tag_t,
    371       1.19   tsutsui     bus_space_handle_t, bus_size_t, uint8_t *, bus_size_t);
    372       1.18   thorpej static void frodo_bus_space_write_region_sparse_1(bus_space_tag_t,
    373       1.19   tsutsui     bus_space_handle_t, bus_size_t, const uint8_t *, bus_size_t);
    374       1.15   tsutsui 
    375       1.18   thorpej static void frodo_bus_space_set_multi_sparse_1(bus_space_tag_t,
    376       1.19   tsutsui     bus_space_handle_t, bus_size_t, uint8_t, bus_size_t);
    377       1.15   tsutsui 
    378       1.18   thorpej static void frodo_bus_space_set_region_sparse_1(bus_space_tag_t,
    379       1.19   tsutsui     bus_space_handle_t, bus_size_t, uint8_t, bus_size_t);
    380       1.15   tsutsui 
    381       1.15   tsutsui /*
    382       1.15   tsutsui  * frodo_init_bus_space():
    383       1.15   tsutsui  *	Initialize bus_space functions in bus_space_tag_t
    384       1.15   tsutsui  *	for frodo devices which have sparse address space.
    385       1.15   tsutsui  */
    386       1.15   tsutsui void
    387       1.18   thorpej frodo_init_bus_space(bus_space_tag_t bst)
    388       1.15   tsutsui {
    389       1.15   tsutsui 
    390       1.15   tsutsui 	memset(bst, 0, sizeof(struct bus_space_tag));
    391       1.15   tsutsui 	bst->bustype = HP300_BUS_SPACE_INTIO;
    392       1.15   tsutsui 
    393       1.15   tsutsui 	bst->bsr1 = frodo_bus_space_read_sparse_1;
    394       1.15   tsutsui 	bst->bsw1 = frodo_bus_space_write_sparse_1;
    395       1.15   tsutsui 
    396       1.15   tsutsui 	bst->bsrm1 = frodo_bus_space_read_multi_sparse_1;
    397       1.15   tsutsui 	bst->bswm1 = frodo_bus_space_write_multi_sparse_1;
    398       1.15   tsutsui 
    399       1.15   tsutsui 	bst->bsrr1 = frodo_bus_space_read_region_sparse_1;
    400       1.15   tsutsui 	bst->bswr1 = frodo_bus_space_write_region_sparse_1;
    401       1.15   tsutsui 
    402       1.15   tsutsui 	bst->bssm1 = frodo_bus_space_set_multi_sparse_1;
    403       1.15   tsutsui 
    404       1.15   tsutsui 	bst->bssr1 = frodo_bus_space_set_region_sparse_1;
    405       1.15   tsutsui }
    406       1.15   tsutsui 
    407       1.19   tsutsui static uint8_t
    408       1.18   thorpej frodo_bus_space_read_sparse_1(bus_space_tag_t bst, bus_space_handle_t bsh,
    409       1.18   thorpej     bus_size_t offset)
    410       1.15   tsutsui {
    411       1.15   tsutsui 
    412       1.19   tsutsui 	return *(volatile uint8_t *)(bsh + (offset << 2));
    413       1.15   tsutsui }
    414       1.15   tsutsui 
    415       1.18   thorpej static void
    416       1.18   thorpej frodo_bus_space_write_sparse_1(bus_space_tag_t bst, bus_space_handle_t bsh,
    417       1.19   tsutsui     bus_size_t offset, uint8_t val)
    418       1.15   tsutsui {
    419       1.15   tsutsui 
    420       1.19   tsutsui 	*(volatile uint8_t *)(bsh + (offset << 2)) = val;
    421       1.15   tsutsui }
    422       1.15   tsutsui 
    423       1.15   tsutsui static void
    424       1.18   thorpej frodo_bus_space_read_multi_sparse_1(bus_space_tag_t bst, bus_space_handle_t bsh,
    425       1.19   tsutsui     bus_size_t offset, uint8_t *addr, bus_size_t len)
    426       1.15   tsutsui {
    427       1.15   tsutsui 
    428       1.23     perry 	__asm volatile (
    429       1.15   tsutsui 	"	movl	%0,%%a0		;\n"
    430       1.15   tsutsui 	"	movl	%1,%%a1		;\n"
    431       1.15   tsutsui 	"	movl	%2,%%d0		;\n"
    432       1.15   tsutsui 	"1:	movb	%%a0@,%%a1@+	;\n"
    433       1.15   tsutsui 	"	subql	#1,%%d0		;\n"
    434       1.15   tsutsui 	"	jne	1b"
    435       1.15   tsutsui 	    :
    436       1.15   tsutsui 	    : "r" (bsh + (offset << 2)), "g" (addr), "g" (len)
    437       1.15   tsutsui 	    : "%a0","%a1","%d0");
    438       1.15   tsutsui }
    439       1.15   tsutsui 
    440       1.15   tsutsui static void
    441       1.18   thorpej frodo_bus_space_write_multi_sparse_1(bus_space_tag_t bst,
    442       1.19   tsutsui     bus_space_handle_t bsh, bus_size_t offset, const uint8_t *addr,
    443       1.18   thorpej     bus_size_t len)
    444       1.15   tsutsui {
    445       1.15   tsutsui 
    446       1.23     perry 	__asm volatile (
    447       1.15   tsutsui 	"	movl	%0,%%a0		;\n"
    448       1.15   tsutsui 	"	movl	%1,%%a1		;\n"
    449       1.15   tsutsui 	"	movl	%2,%%d0		;\n"
    450       1.15   tsutsui 	"1:	movb	%%a1@+,%%a0@	;\n"
    451       1.15   tsutsui 	"	subql	#1,%%d0		;\n"
    452       1.15   tsutsui 	"	jne	1b"
    453       1.15   tsutsui 	    :
    454       1.15   tsutsui 	    : "r" (bsh + (offset << 2)), "g" (addr), "g" (len)
    455       1.15   tsutsui 	    : "%a0","%a1","%d0");
    456       1.15   tsutsui }
    457       1.15   tsutsui 
    458       1.15   tsutsui static void
    459       1.18   thorpej frodo_bus_space_read_region_sparse_1(bus_space_tag_t bst,
    460       1.19   tsutsui     bus_space_handle_t bsh, bus_size_t offset, uint8_t *addr, bus_size_t len)
    461       1.15   tsutsui {
    462       1.23     perry 	__asm volatile (
    463       1.15   tsutsui 	"	movl	%0,%%a0		;\n"
    464       1.15   tsutsui 	"	movl	%1,%%a1		;\n"
    465       1.15   tsutsui 	"	movl	%2,%%d0		;\n"
    466       1.15   tsutsui 	"1:	movb	%%a0@,%%a1@+	;\n"
    467       1.15   tsutsui 	"	addql	#4,%%a0		;\n"
    468       1.15   tsutsui 	"	subql	#1,%%d0		;\n"
    469       1.15   tsutsui 	"	jne	1b"
    470       1.15   tsutsui 	    :
    471       1.15   tsutsui 	    : "r" (bsh + (offset << 2)), "g" (addr), "g" (len)
    472       1.15   tsutsui 	    : "%a0","%a1","%d0");
    473       1.15   tsutsui }
    474       1.15   tsutsui 
    475       1.15   tsutsui static void
    476       1.18   thorpej frodo_bus_space_write_region_sparse_1(bus_space_tag_t bst,
    477       1.19   tsutsui     bus_space_handle_t bsh, bus_size_t offset, const uint8_t *addr,
    478       1.18   thorpej     bus_size_t len)
    479       1.15   tsutsui {
    480       1.15   tsutsui 
    481       1.23     perry 	__asm volatile (
    482       1.15   tsutsui 	"	movl	%0,%%a0		;\n"
    483       1.15   tsutsui 	"	movl	%1,%%a1		;\n"
    484       1.15   tsutsui 	"	movl	%2,%%d0		;\n"
    485       1.15   tsutsui 	"1:	movb	%%a1@+,%%a0@	;\n"
    486       1.15   tsutsui 	"	addql	#4,%%a0		;\n"
    487       1.15   tsutsui 	"	subql	#1,%%d0		;\n"
    488       1.15   tsutsui 	"	jne	1b"
    489       1.15   tsutsui 	    :
    490       1.15   tsutsui 	    : "r" (bsh + (offset << 2)), "g" (addr), "g" (len)
    491       1.15   tsutsui 	    : "%a0","%a1","%d0");
    492       1.15   tsutsui }
    493       1.15   tsutsui 
    494       1.15   tsutsui static void
    495       1.18   thorpej frodo_bus_space_set_multi_sparse_1(bus_space_tag_t bst, bus_space_handle_t bsh,
    496       1.19   tsutsui     bus_size_t offset, uint8_t val, bus_size_t count)
    497       1.15   tsutsui {
    498       1.23     perry 	__asm volatile (
    499       1.15   tsutsui 	"	movl	%0,%%a0		;\n"
    500       1.15   tsutsui 	"	movl	%1,%%d1		;\n"
    501       1.15   tsutsui 	"	movl	%2,%%d0		;\n"
    502       1.15   tsutsui 	"1:	movb	%%d1,%%a0@	;\n"
    503       1.15   tsutsui 	"	subql	#1,%%d0		;\n"
    504       1.15   tsutsui 	"	jne	1b"
    505       1.15   tsutsui 	    :
    506       1.15   tsutsui 	    : "r" (bsh + (offset << 2)), "g" (val), "g" (count)
    507       1.15   tsutsui 	    : "%a0","%d0","%d1");
    508       1.15   tsutsui }
    509       1.15   tsutsui 
    510       1.15   tsutsui static void
    511       1.18   thorpej frodo_bus_space_set_region_sparse_1(bus_space_tag_t bst, bus_space_handle_t bsh,
    512       1.19   tsutsui     bus_size_t offset, uint8_t val, bus_size_t count)
    513       1.15   tsutsui {
    514       1.15   tsutsui 
    515       1.23     perry 	__asm volatile (
    516       1.15   tsutsui 	"	movl	%0,%%a0		;\n"
    517       1.15   tsutsui 	"	movl	%1,%%d1		;\n"
    518       1.15   tsutsui 	"	movl	%2,%%d0		;\n"
    519       1.15   tsutsui 	"1:	movb	%%d1,%%a0@	;\n"
    520       1.15   tsutsui 	"	addql	#4,%%a0		;\n"
    521       1.15   tsutsui 	"	subql	#1,%%d0		;\n"
    522       1.15   tsutsui 	"	jne	1b"
    523       1.15   tsutsui 	    :
    524       1.15   tsutsui 	    : "r" (bsh + (offset << 2)), "g" (val), "g" (count)
    525       1.15   tsutsui 	    : "%a0","%d0","%d1");
    526        1.1   thorpej }
    527