1/*- 2 * Copyright (c) 1996-1999 3 * Kazutaka YOKOTA (yokota@zodiac.mech.utsunomiya-u.ac.jp) 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 13 unchanged lines hidden (view full) --- 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * |
30 * $FreeBSD: head/sys/dev/atkbdc/atkbdc.c 93279 2002-03-27 13:16:11Z murray $ |
31 * from kbdio.c,v 1.13 1998/09/25 11:55:46 yokota Exp 32 */ 33 34#include "atkbdc.h" 35#include "opt_kbd.h" 36 37#include <sys/param.h> 38#include <sys/systm.h> --- 175 unchanged lines hidden (view full) --- 214 215/* 216 * I/O access arbitration in `kbdio' 217 * 218 * The `kbdio' module uses a simplistic convention to arbitrate 219 * I/O access to the controller/keyboard/mouse. The convention requires 220 * close cooperation of the calling device driver. 221 * |
222 * The device drivers which utilize the `kbdio' module are assumed to |
223 * have the following set of routines. 224 * a. An interrupt handler (the bottom half of the driver). |
225 * b. Timeout routines which may briefly poll the keyboard controller. |
226 * c. Routines outside interrupt context (the top half of the driver). 227 * They should follow the rules below: 228 * 1. The interrupt handler may assume that it always has full access 229 * to the controller/keyboard/mouse. 230 * 2. The other routines must issue `spltty()' if they wish to 231 * prevent the interrupt handler from accessing 232 * the controller/keyboard/mouse. 233 * 3. The timeout routines and the top half routines of the device driver 234 * arbitrate I/O access by observing the lock flag in `kbdio'. 235 * The flag is manipulated via `kbdc_lock()'; when one wants to 236 * perform I/O, call `kbdc_lock(kbdc, TRUE)' and proceed only if 237 * the call returns with TRUE. Otherwise the caller must back off. 238 * Call `kbdc_lock(kbdc, FALSE)' when necessary I/O operaion 239 * is finished. This mechanism does not prevent the interrupt 240 * handler from being invoked at any time and carrying out I/O. 241 * Therefore, `spltty()' must be strategically placed in the device 242 * driver code. Also note that the timeout routine may interrupt 243 * `kbdc_lock()' called by the top half of the driver, but this |
244 * interruption is OK so long as the timeout routine observes 245 * rule 4 below. |
246 * 4. The interrupt and timeout routines should not extend I/O operation |
247 * across more than one interrupt or timeout; they must complete any 248 * necessary I/O operation within one invocation of the routine. 249 * This means that if the timeout routine acquires the lock flag, |
250 * it must reset the flag to FALSE before it returns. 251 */ 252 253/* set/reset polling lock */ 254int 255kbdc_lock(KBDC p, int lock) 256{ 257 int prevlock; --- 783 unchanged lines hidden --- |