1 /*- 2 * (MPSAFE) 3 * 4 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer as 12 * the first lines of this file unmodified. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $FreeBSD: src/sys/isa/atkbd_isa.c,v 1.7.2.3 2001/08/01 10:42:28 yokota Exp $ 29 */ 30 31 #include "opt_kbd.h" 32 33 #include <sys/param.h> 34 #include <sys/systm.h> 35 #include <sys/kernel.h> 36 #include <sys/bus.h> 37 #include <sys/rman.h> 38 #include <sys/thread.h> 39 40 #include <sys/kbio.h> 41 #include <dev/misc/kbd/kbdreg.h> 42 #include <dev/misc/kbd/atkbdreg.h> 43 #include <dev/misc/kbd/atkbdcreg.h> 44 45 #include <bus/isa/isareg.h> 46 #include <bus/isa/isavar.h> 47 48 #if 0 49 #define lwkt_gettoken(x) 50 #define lwkt_reltoken(x) 51 #endif 52 53 typedef struct { 54 struct resource *intr; 55 void *ih; 56 } atkbd_softc_t; 57 58 devclass_t atkbd_devclass; 59 60 static int atkbdprobe(device_t dev); 61 static int atkbdattach(device_t dev); 62 static int atkbdresume(device_t dev); 63 static void atkbd_isa_intr(void *arg); 64 65 static device_method_t atkbd_methods[] = { 66 DEVMETHOD(device_probe, atkbdprobe), 67 DEVMETHOD(device_attach, atkbdattach), 68 DEVMETHOD(device_resume, atkbdresume), 69 { 0, 0 } 70 }; 71 72 static driver_t atkbd_driver = { 73 ATKBD_DRIVER_NAME, 74 atkbd_methods, 75 sizeof(atkbd_softc_t), 76 }; 77 78 static int 79 atkbdprobe(device_t dev) 80 { 81 uintptr_t irq; 82 uintptr_t flags; 83 84 device_set_desc(dev, "AT Keyboard"); 85 86 /* obtain parameters */ 87 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_IRQ, &irq); 88 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_FLAGS, &flags); 89 90 /* probe the device */ 91 return atkbd_probe_unit(device_get_unit(dev), 92 device_get_unit(device_get_parent(dev)), 93 irq, flags); 94 } 95 96 static int 97 atkbdattach(device_t dev) 98 { 99 atkbd_softc_t *sc; 100 keyboard_t *kbd; 101 uintptr_t irq; 102 uintptr_t flags; 103 int rid; 104 int error; 105 106 sc = device_get_softc(dev); 107 108 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_IRQ, &irq); 109 BUS_READ_IVAR(device_get_parent(dev), dev, KBDC_IVAR_FLAGS, &flags); 110 111 error = atkbd_attach_unit(device_get_unit(dev), &kbd, 112 device_get_unit(device_get_parent(dev)), 113 irq, flags); 114 if (error) 115 return error; 116 117 /* declare our interrupt handler */ 118 rid = 0; 119 sc->intr = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, irq, irq, 1, 120 RF_SHAREABLE | RF_ACTIVE); 121 BUS_SETUP_INTR(device_get_parent(dev), dev, sc->intr, INTR_MPSAFE, 122 atkbd_isa_intr, kbd, &sc->ih, NULL); 123 124 return 0; 125 } 126 127 static int 128 atkbdresume(device_t dev) 129 { 130 atkbd_softc_t *sc; 131 keyboard_t *kbd; 132 int args[2]; 133 134 lwkt_gettoken(&tty_token); 135 sc = device_get_softc(dev); 136 kbd = kbd_get_keyboard(kbd_find_keyboard(ATKBD_DRIVER_NAME, 137 device_get_unit(dev))); 138 if (kbd) { 139 kbd->kb_flags &= ~KB_INITIALIZED; 140 args[0] = device_get_unit(device_get_parent(dev)); 141 args[1] = rman_get_start(sc->intr); 142 sw_init(kbdsw[kbd->kb_index], device_get_unit(dev), &kbd, 143 args, device_get_flags(dev)); 144 kbd_clear_state(kbd); 145 146 } 147 lwkt_reltoken(&tty_token); 148 return 0; 149 } 150 151 static void 152 atkbd_isa_intr(void *arg) 153 { 154 keyboard_t *kbd; 155 156 lwkt_gettoken(&tty_token); 157 kbd = (keyboard_t *)arg; 158 kbd_intr(kbd, NULL); 159 lwkt_reltoken(&tty_token); 160 } 161 162 DRIVER_MODULE(atkbd, atkbdc, atkbd_driver, atkbd_devclass, NULL, NULL); 163