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