1 /* $OpenBSD: com_isa.c,v 1.6 2010/08/06 21:08:26 deraadt Exp $ */ 2 /* 3 * Copyright (c) 1997 - 1999, Jason Downs. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name(s) of the author(s) nor the name OpenBSD 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS 18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, 21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 /*- 30 * Copyright (c) 1993, 1994, 1995, 1996 31 * Charles M. Hannum. All rights reserved. 32 * Copyright (c) 1991 The Regents of the University of California. 33 * All rights reserved. 34 * 35 * Redistribution and use in source and binary forms, with or without 36 * modification, are permitted provided that the following conditions 37 * are met: 38 * 1. Redistributions of source code must retain the above copyright 39 * notice, this list of conditions and the following disclaimer. 40 * 2. Redistributions in binary form must reproduce the above copyright 41 * notice, this list of conditions and the following disclaimer in the 42 * documentation and/or other materials provided with the distribution. 43 * 3. Neither the name of the University nor the names of its contributors 44 * may be used to endorse or promote products derived from this software 45 * without specific prior written permission. 46 * 47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 * SUCH DAMAGE. 58 * 59 * @(#)com.c 7.5 (Berkeley) 5/16/91 60 */ 61 62 #include <sys/param.h> 63 #include <sys/systm.h> 64 #include <sys/tty.h> 65 #include <sys/device.h> 66 67 #include <machine/intr.h> 68 #include <machine/bus.h> 69 70 #include <dev/ic/comreg.h> 71 #include <dev/ic/comvar.h> 72 73 #include <dev/isa/isavar.h> 74 75 int com_isa_probe(struct device *, void *, void *); 76 void com_isa_attach(struct device *, struct device *, void *); 77 int com_isa_activate(struct device *, int); 78 79 struct cfattach com_isa_ca = { 80 sizeof(struct com_softc), com_isa_probe, com_isa_attach, NULL, 81 com_isa_activate 82 }; 83 84 int 85 com_isa_probe(struct device *parent, void *match, void *aux) 86 { 87 struct isa_attach_args *ia = aux; 88 bus_space_handle_t ioh; 89 bus_space_tag_t iot; 90 int iobase; 91 int rv; 92 93 iot = ia->ia_iot; 94 iobase = ia->ia_iobase; 95 96 #ifdef KGDB 97 if (iobase == com_kgdb_addr) 98 goto out; 99 #endif 100 if (iobase == comconsaddr && !comconsattached) 101 goto out; 102 103 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) 104 return (0); 105 106 rv = comprobe1(iot, ioh); 107 108 bus_space_unmap(iot, ioh, COM_NPORTS); 109 110 if (rv == 0) 111 return (0); 112 113 out: 114 ia->ia_iosize = COM_NPORTS; 115 ia->ia_msize = 0; 116 return (1); 117 } 118 119 void 120 com_isa_attach(struct device *parent, struct device *self, void *aux) 121 { 122 struct com_softc *sc = (struct com_softc *)self; 123 struct isa_attach_args *ia = aux; 124 bus_space_handle_t ioh; 125 bus_space_tag_t iot; 126 int iobase, irq; 127 128 sc->sc_hwflags = 0; 129 sc->sc_swflags = 0; 130 131 iobase = ia->ia_iobase; 132 iot = ia->ia_iot; 133 134 #ifdef KGDB 135 if ((iobase != comconsaddr) && 136 (iobase != com_kgdb_addr)) { 137 #else 138 if (iobase != comconsaddr) { 139 #endif 140 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) 141 panic("com_isa_attach: mapping failed"); 142 } else { 143 #ifdef KGDB 144 if (iobase == comconsaddr) 145 ioh = comconsioh; 146 else 147 ioh = com_kgdb_ioh; 148 #else 149 ioh = comconsioh; 150 #endif 151 } 152 153 sc->sc_iot = iot; 154 sc->sc_ioh = ioh; 155 sc->sc_iobase = iobase; 156 sc->sc_frequency = COM_FREQ; 157 158 com_attach_subr(sc); 159 160 irq = ia->ia_irq; 161 if (irq != IRQUNK) { 162 #ifdef KGDB 163 if (iobase == com_kgdb_addr) { 164 sc->sc_ih = isa_intr_establish(ia->ia_ic, irq, 165 IST_EDGE, IPL_HIGH, kgdbintr, sc, 166 sc->sc_dev.dv_xname); 167 } else { 168 sc->sc_ih = isa_intr_establish(ia->ia_ic, irq, 169 IST_EDGE, IPL_TTY, comintr, sc, 170 sc->sc_dev.dv_xname); 171 } 172 #else 173 sc->sc_ih = isa_intr_establish(ia->ia_ic, irq, 174 IST_EDGE, IPL_TTY, comintr, sc, 175 sc->sc_dev.dv_xname); 176 #endif /* KGDB */ 177 } 178 } 179 180 int 181 com_isa_activate(struct device *self, int act) 182 { 183 struct com_softc *sc = (struct com_softc *)self; 184 185 switch (act) { 186 case DVACT_SUSPEND: 187 break; 188 case DVACT_RESUME: 189 com_resume(sc); 190 break; 191 } 192 193 return (0); 194 } 195