1 /* $NetBSD: isa_machdep.c,v 1.14 2009/08/19 15:11:53 dyoung 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.14 2009/08/19 15:11:53 dyoung 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(struct device *pdp, struct cfdata *cfp, void *aux) 73 { 74 struct confargs *ca = aux; 75 76 if (strcmp(ca->ca_name, isabus_cd.cd_name) != 0) 77 return 0; 78 return 1; 79 } 80 81 static void 82 isa_bus_space_init(struct mipsco_bus_space *bst, const char *type, paddr_t paddr, size_t len) 83 { 84 vaddr_t vaddr = MIPS_PHYS_TO_KSEG1(paddr); /* XXX */ 85 86 /* Setup default bus_space */ 87 mipsco_bus_space_init(bst, type, paddr, vaddr, 0x0, len); 88 89 /* ISA bus maps 1 word for every byte, therefore stride = 2 */ 90 mipsco_bus_space_set_aligned_stride(bst, 2); 91 92 /* 93 * ISA bus will do an automatic byte swap, but when accessing 94 * memory using bus_space_stream functions we need to byte swap 95 * to reverse the one performed in hardware 96 */ 97 bst->bs_bswap = 1; 98 99 bst->bs_intr_establish = (void *)isa_intr_establish; 100 101 printf(" %s %p", type, (void *)vaddr); 102 } 103 104 105 void 106 isabusattach(struct device *pdp, struct device *dp, void *aux) 107 { 108 struct isabus_softc *sc = (struct isabus_softc *)dp; 109 struct mipsco_isa_chipset *ic = &sc->sc_isa_ic; 110 struct isabus_attach_args iba; 111 112 printf(":"); 113 114 iba.iba_iot = &isa_io_bst; 115 iba.iba_memt = &isa_mem_bst; 116 iba.iba_dmat = &isa_dmatag; 117 iba.iba_ic = ic; 118 119 isa_bus_space_init(&isa_io_bst, "isa_io", PIZAZZ_ISA_IOBASE, 120 PIZAZZ_ISA_IOSIZE); 121 122 isa_bus_space_init(&isa_mem_bst, "isa_mem", PIZAZZ_ISA_MEMBASE, 123 PIZAZZ_ISA_MEMSIZE); 124 125 isa_bus_space_init(&isa_ctl_bst, "isa_intr", PIZAZZ_ISA_INTRLATCH, 126 sizeof(u_int32_t)); 127 128 _bus_dma_tag_init(&isa_dmatag); 129 130 ic->ic_bst = &isa_ctl_bst; 131 132 if (bus_space_map(ic->ic_bst, 0x00000, sizeof(u_int32_t), 133 BUS_SPACE_MAP_LINEAR, &ic->ic_bsh) != 0) { 134 printf(": can't map intrreg\n"); 135 return; 136 } 137 138 /* Clear ISA interrupt latch */ 139 bus_space_write_4(ic->ic_bst, ic->ic_bsh, 0, 0); 140 141 evcnt_attach_dynamic(&ic->ic_intrcnt, EVCNT_TYPE_INTR, NULL, 142 dp->dv_xname, "intr"); 143 144 LIST_INIT(&ic->intr_q); 145 (*platform.intr_establish)(SYS_INTR_ATBUS, isa_intr, ic); 146 147 printf("\n"); 148 config_found_ia(dp, "isabus", &iba, mipscoisabusprint); 149 } 150 151 int 152 mipscoisabusprint(void *auxp, const char *name) 153 { 154 if(name == NULL) 155 return(UNCONF); 156 return(QUIET); 157 } 158 159 void 160 isa_attach_hook(struct device *parent, struct device *self, struct isabus_attach_args *iba) 161 { 162 } 163 164 void 165 isa_detach_hook(isa_chipset_tag_t ic, device_t self) 166 { 167 } 168 169 const struct evcnt * 170 isa_intr_evcnt(isa_chipset_tag_t ic, int irq) 171 { 172 /* XXX for now, no evcnt parent reported */ 173 return NULL; 174 } 175 176 void * 177 isa_intr_establish(isa_chipset_tag_t ic, int intr, int type, int level, int (*ih_fun)(void*), void *ih_arg) 178 /* type: XXX not yet */ 179 /* level: XXX not yet */ 180 { 181 struct mipsco_intrhand *ih; 182 183 ih = malloc(sizeof *ih, M_DEVBUF, M_NOWAIT); 184 if (ih == NULL) 185 panic("isa_intr_establish: malloc failed"); 186 187 ih->ih_fun = ih_fun; 188 ih->ih_arg = ih_arg; 189 LIST_INSERT_HEAD(&ic->intr_q, ih, ih_q); 190 return ih; 191 } 192 193 void 194 isa_intr_disestablish(isa_chipset_tag_t ic, void *cookie) 195 { 196 struct mipsco_intrhand *ih = cookie; 197 198 LIST_REMOVE(ih, ih_q); 199 free(ih, M_DEVBUF); 200 } 201 202 int 203 isa_intr_alloc(isa_chipset_tag_t ic, int mask, int type, int *irq) 204 { 205 return 0; 206 } 207 208 int 209 isa_intr(void *arg) 210 { 211 struct mipsco_isa_chipset *ic = (struct mipsco_isa_chipset *)arg; 212 struct mipsco_intrhand *ih; 213 int rv, handled; 214 215 ic->ic_intrcnt.ev_count++; 216 217 handled = 0; 218 LIST_FOREACH(ih, &ic->intr_q, ih_q) { 219 /* 220 * The handler returns one of three values: 221 * 0: This interrupt wasn't for me. 222 * 1: This interrupt was for me. 223 * -1: This interrupt might have been for me, but I can't say 224 * for sure. 225 */ 226 rv = (*ih->ih_fun)(ih->ih_arg); 227 handled |= (rv != 0); 228 } 229 230 /* Clear ISA interrupt latch */ 231 bus_space_write_4(ic->ic_bst, ic->ic_bsh, 0, 0); 232 233 return handled; 234 } 235