Home | History | Annotate | Line # | Download | only in isa
isa_machdep.c revision 1.6
      1  1.6  drochner /*	$NetBSD: isa_machdep.c,v 1.6 2004/08/30 15:05:18 drochner Exp $	*/
      2  1.1       wdk 
      3  1.1       wdk /*
      4  1.1       wdk  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.1       wdk  * All rights reserved.
      6  1.1       wdk  *
      7  1.1       wdk  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1       wdk  * by Wayne Knowles
      9  1.1       wdk  *
     10  1.1       wdk  * Redistribution and use in source and binary forms, with or without
     11  1.1       wdk  * modification, are permitted provided that the following conditions
     12  1.1       wdk  * are met:
     13  1.1       wdk  * 1. Redistributions of source code must retain the above copyright
     14  1.1       wdk  *    notice, this list of conditions and the following disclaimer.
     15  1.1       wdk  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1       wdk  *    notice, this list of conditions and the following disclaimer in the
     17  1.1       wdk  *    documentation and/or other materials provided with the distribution.
     18  1.1       wdk  * 3. All advertising materials mentioning features or use of this software
     19  1.1       wdk  *    must display the following acknowledgement:
     20  1.1       wdk  *        This product includes software developed by the NetBSD
     21  1.1       wdk  *        Foundation, Inc. and its contributors.
     22  1.1       wdk  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1       wdk  *    contributors may be used to endorse or promote products derived
     24  1.1       wdk  *    from this software without specific prior written permission.
     25  1.1       wdk  *
     26  1.1       wdk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1       wdk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1       wdk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1       wdk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1       wdk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1       wdk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1       wdk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1       wdk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1       wdk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1       wdk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1       wdk  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1       wdk  */
     38  1.5     lukem 
     39  1.5     lukem #include <sys/cdefs.h>
     40  1.6  drochner __KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.6 2004/08/30 15:05:18 drochner Exp $");
     41  1.1       wdk 
     42  1.1       wdk #include <sys/param.h>
     43  1.1       wdk #include <sys/systm.h>
     44  1.1       wdk #include <sys/device.h>
     45  1.1       wdk #include <sys/malloc.h>
     46  1.1       wdk #include <sys/queue.h>
     47  1.1       wdk 
     48  1.1       wdk #include <machine/sysconf.h>
     49  1.1       wdk #include <machine/autoconf.h>
     50  1.1       wdk #include <machine/mainboard.h>
     51  1.1       wdk #include <machine/bus.h>
     52  1.1       wdk 
     53  1.1       wdk #include <dev/isa/isavar.h>
     54  1.1       wdk #include <dev/isa/isareg.h>
     55  1.1       wdk 
     56  1.6  drochner static int	mipscoisabusprint __P((void *auxp, const char *));
     57  1.1       wdk static int	isabusmatch __P((struct device *, struct cfdata *, void *));
     58  1.1       wdk static void	isabusattach __P((struct device *, struct device *, void *));
     59  1.1       wdk 
     60  1.1       wdk struct isabus_softc {
     61  1.1       wdk 	struct device		sc_dev;
     62  1.1       wdk 	struct mipsco_isa_chipset sc_isa_ic;
     63  1.1       wdk };
     64  1.1       wdk 
     65  1.4   thorpej CFATTACH_DECL(isabus, sizeof(struct isabus_softc),
     66  1.4   thorpej     isabusmatch, isabusattach, NULL, NULL);
     67  1.1       wdk 
     68  1.1       wdk extern struct cfdriver isabus_cd;
     69  1.1       wdk 
     70  1.1       wdk static struct mipsco_bus_space	isa_io_bst, isa_mem_bst, isa_ctl_bst;
     71  1.1       wdk static struct mipsco_bus_dma_tag isa_dmatag;
     72  1.1       wdk 
     73  1.1       wdk static void isa_bus_space_init __P((struct mipsco_bus_space *, const char *,
     74  1.1       wdk 				     paddr_t, size_t));
     75  1.1       wdk int    isa_intr __P((void *));
     76  1.1       wdk 
     77  1.1       wdk 
     78  1.1       wdk int
     79  1.1       wdk isabusmatch(pdp, cfp, aux)
     80  1.1       wdk struct device	*pdp;
     81  1.1       wdk struct cfdata	*cfp;
     82  1.1       wdk void		*aux;
     83  1.1       wdk {
     84  1.1       wdk 	struct confargs *ca = aux;
     85  1.1       wdk 
     86  1.1       wdk 	if (strcmp(ca->ca_name, isabus_cd.cd_name) != 0)
     87  1.1       wdk 		return 0;
     88  1.1       wdk 	return 1;
     89  1.1       wdk }
     90  1.1       wdk 
     91  1.1       wdk static void
     92  1.1       wdk isa_bus_space_init(bst, type, paddr, len)
     93  1.1       wdk     struct mipsco_bus_space *bst;
     94  1.1       wdk     const char *type;
     95  1.1       wdk     paddr_t paddr;
     96  1.1       wdk     size_t len;
     97  1.1       wdk {
     98  1.1       wdk 	vaddr_t vaddr = MIPS_PHYS_TO_KSEG1(paddr); /* XXX */
     99  1.1       wdk 
    100  1.1       wdk 	/* Setup default bus_space */
    101  1.1       wdk 	mipsco_bus_space_init(bst, type, paddr, vaddr, 0x0, len);
    102  1.1       wdk 
    103  1.1       wdk 	/* ISA bus maps 1 word for every byte, therefore stride = 2 */
    104  1.1       wdk 	mipsco_bus_space_set_aligned_stride(bst, 2);
    105  1.1       wdk 
    106  1.1       wdk 	/*
    107  1.1       wdk 	 * ISA bus will do an automatic byte swap, but when accessing
    108  1.1       wdk 	 * memory using bus_space_stream functions we need to byte swap
    109  1.1       wdk 	 * to reverse the one performed in hardware
    110  1.1       wdk 	 */
    111  1.1       wdk 	bst->bs_bswap = 1;
    112  1.1       wdk 
    113  1.1       wdk 	bst->bs_intr_establish = (void *)isa_intr_establish;
    114  1.1       wdk 
    115  1.1       wdk 	printf(" %s %p", type, (void *)vaddr);
    116  1.1       wdk }
    117  1.1       wdk 
    118  1.1       wdk 
    119  1.1       wdk void
    120  1.1       wdk isabusattach(pdp, dp, aux)
    121  1.1       wdk struct device	*pdp, *dp;
    122  1.1       wdk void		*aux;
    123  1.1       wdk {
    124  1.1       wdk 	struct isabus_softc *sc = (struct isabus_softc *)dp;
    125  1.1       wdk 	struct mipsco_isa_chipset *ic = &sc->sc_isa_ic;
    126  1.1       wdk 	struct isabus_attach_args iba;
    127  1.1       wdk 
    128  1.1       wdk 	printf(":");
    129  1.1       wdk 
    130  1.1       wdk 	iba.iba_iot	= &isa_io_bst;
    131  1.1       wdk 	iba.iba_memt	= &isa_mem_bst;
    132  1.1       wdk 	iba.iba_dmat	= &isa_dmatag;
    133  1.1       wdk 	iba.iba_ic	= ic;
    134  1.1       wdk 
    135  1.1       wdk 	isa_bus_space_init(&isa_io_bst,  "isa_io",   PIZAZZ_ISA_IOBASE,
    136  1.1       wdk 	  	PIZAZZ_ISA_IOSIZE);
    137  1.1       wdk 
    138  1.1       wdk 	isa_bus_space_init(&isa_mem_bst, "isa_mem",  PIZAZZ_ISA_MEMBASE,
    139  1.1       wdk 		PIZAZZ_ISA_MEMSIZE);
    140  1.1       wdk 
    141  1.1       wdk 	isa_bus_space_init(&isa_ctl_bst, "isa_intr", PIZAZZ_ISA_INTRLATCH,
    142  1.1       wdk 	  	sizeof(u_int32_t));
    143  1.1       wdk 
    144  1.1       wdk 	_bus_dma_tag_init(&isa_dmatag);
    145  1.1       wdk 
    146  1.1       wdk 	ic->ic_bst = &isa_ctl_bst;
    147  1.1       wdk 
    148  1.1       wdk 	if (bus_space_map(ic->ic_bst, 0x00000, sizeof(u_int32_t),
    149  1.1       wdk 			  BUS_SPACE_MAP_LINEAR, &ic->ic_bsh) != 0) {
    150  1.1       wdk 		printf(": can't map intrreg\n");
    151  1.1       wdk 		return;
    152  1.1       wdk 	}
    153  1.1       wdk 
    154  1.1       wdk 	/* Clear ISA interrupt latch */
    155  1.1       wdk 	bus_space_write_4(ic->ic_bst, ic->ic_bsh, 0, 0);
    156  1.1       wdk 
    157  1.1       wdk 	evcnt_attach_dynamic(&ic->ic_intrcnt, EVCNT_TYPE_INTR, NULL,
    158  1.1       wdk 			     dp->dv_xname, "intr");
    159  1.1       wdk 
    160  1.1       wdk 	LIST_INIT(&ic->intr_q);
    161  1.1       wdk 	(*platform.intr_establish)(SYS_INTR_ATBUS, isa_intr, ic);
    162  1.1       wdk 
    163  1.1       wdk 	printf("\n");
    164  1.6  drochner 	config_found_ia(dp, "isabus", &iba, mipscoisabusprint);
    165  1.1       wdk }
    166  1.1       wdk 
    167  1.1       wdk int
    168  1.6  drochner mipscoisabusprint(auxp, name)
    169  1.1       wdk void		*auxp;
    170  1.1       wdk const char	*name;
    171  1.1       wdk {
    172  1.1       wdk 	if(name == NULL)
    173  1.1       wdk 		return(UNCONF);
    174  1.1       wdk 	return(QUIET);
    175  1.1       wdk }
    176  1.1       wdk 
    177  1.1       wdk void
    178  1.1       wdk isa_attach_hook(parent, self, iba)
    179  1.1       wdk 	struct device *parent, *self;
    180  1.1       wdk 	struct isabus_attach_args *iba;
    181  1.1       wdk {
    182  1.1       wdk }
    183  1.1       wdk 
    184  1.1       wdk const struct evcnt *
    185  1.1       wdk isa_intr_evcnt(isa_chipset_tag_t ic, int irq)
    186  1.1       wdk {
    187  1.1       wdk 	/* XXX for now, no evcnt parent reported */
    188  1.1       wdk 	return NULL;
    189  1.1       wdk }
    190  1.1       wdk 
    191  1.1       wdk void *
    192  1.1       wdk isa_intr_establish(ic, intr, type, level, ih_fun, ih_arg)
    193  1.1       wdk 	isa_chipset_tag_t ic;
    194  1.1       wdk 	int intr;
    195  1.1       wdk 	int type;  /* XXX not yet */
    196  1.1       wdk 	int level;  /* XXX not yet */
    197  1.1       wdk 	int (*ih_fun) __P((void*));
    198  1.1       wdk 	void *ih_arg;
    199  1.1       wdk {
    200  1.1       wdk 	struct mipsco_intrhand *ih;
    201  1.1       wdk 
    202  1.1       wdk 	ih = malloc(sizeof *ih, M_DEVBUF, M_NOWAIT);
    203  1.1       wdk 	if (ih == NULL)
    204  1.1       wdk 		panic("isa_intr_establish: malloc failed");
    205  1.1       wdk 
    206  1.1       wdk 	ih->ih_fun = ih_fun;
    207  1.1       wdk 	ih->ih_arg  = ih_arg;
    208  1.1       wdk 	LIST_INSERT_HEAD(&ic->intr_q, ih, ih_q);
    209  1.1       wdk 	return ih;
    210  1.1       wdk }
    211  1.1       wdk 
    212  1.1       wdk void
    213  1.1       wdk isa_intr_disestablish(ic, cookie)
    214  1.1       wdk 	isa_chipset_tag_t ic;
    215  1.1       wdk 	void *cookie;
    216  1.1       wdk {
    217  1.1       wdk 	struct mipsco_intrhand *ih = cookie;
    218  1.1       wdk 
    219  1.1       wdk 	LIST_REMOVE(ih, ih_q);
    220  1.1       wdk 	free(ih, M_DEVBUF);
    221  1.1       wdk }
    222  1.1       wdk 
    223  1.1       wdk int
    224  1.1       wdk isa_intr_alloc(ic, mask, type, irq)
    225  1.1       wdk 	isa_chipset_tag_t ic;
    226  1.1       wdk 	int mask;
    227  1.1       wdk 	int type;
    228  1.1       wdk 	int *irq;
    229  1.1       wdk {
    230  1.1       wdk 	return 0;
    231  1.1       wdk }
    232  1.1       wdk 
    233  1.1       wdk int
    234  1.1       wdk isa_intr(arg)
    235  1.1       wdk 	void *arg;
    236  1.1       wdk {
    237  1.1       wdk 	struct mipsco_isa_chipset *ic = (struct mipsco_isa_chipset *)arg;
    238  1.1       wdk 	struct mipsco_intrhand *ih;
    239  1.1       wdk 	int rv, handled;
    240  1.1       wdk 
    241  1.1       wdk 	ic->ic_intrcnt.ev_count++;
    242  1.1       wdk 
    243  1.1       wdk 	handled = 0;
    244  1.1       wdk 	LIST_FOREACH(ih, &ic->intr_q, ih_q) {
    245  1.1       wdk 		/*
    246  1.1       wdk 		 * The handler returns one of three values:
    247  1.1       wdk 		 *   0:	This interrupt wasn't for me.
    248  1.1       wdk 		 *   1: This interrupt was for me.
    249  1.1       wdk 		 *  -1: This interrupt might have been for me, but I can't say
    250  1.1       wdk 		 *      for sure.
    251  1.1       wdk 		 */
    252  1.1       wdk 		rv = (*ih->ih_fun)(ih->ih_arg);
    253  1.1       wdk 		handled |= (rv != 0);
    254  1.1       wdk 	}
    255  1.2       wdk 
    256  1.2       wdk 	/* Clear ISA interrupt latch */
    257  1.2       wdk 	bus_space_write_4(ic->ic_bst, ic->ic_bsh, 0, 0);
    258  1.1       wdk 
    259  1.1       wdk 	return handled;
    260  1.1       wdk }
    261