Mercurial > illumos > illumos-gate
changeset 5129:5dc46a0fd425
PSARC 2007/019 KIOCMKTONE (keyboard make tone) ioctl
6425775 Xsun is blocked when a program rings keyboard- or audio-bell
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/deleted_files/usr/src/uts/sun4/os/beep.c Tue Sep 25 13:11:35 2007 -0700 @@ -0,0 +1,347 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * This is the Beep module for supporting keyboard beep for keyboards + * that do not have the beeping feature within themselves + * + */ + +#include <sys/types.h> +#include <sys/conf.h> + +#include <sys/ddi.h> +#include <sys/sunddi.h> +#include <sys/modctl.h> +#include <sys/ddi_impldefs.h> +#include <sys/kmem.h> + +#include <sys/devops.h> + +#include <sys/beep.h> +#include <sys/errno.h> +#include <sys/inttypes.h> + +/* + * Debug stuff + * BEEP_DEBUG used for errors + * BEEP_DEBUG1 prints when beep_debug > 1 and used for normal messages + */ +#ifdef DEBUG +int beep_debug = 0; +#define BEEP_DEBUG(args) if (beep_debug) cmn_err args +#define BEEP_DEBUG1(args) if (beep_debug > 1) cmn_err args +#else +#define BEEP_DEBUG(args) +#define BEEP_DEBUG1(args) +#endif + + +/* Prototypes */ + +static void beep_timeout(); + + +struct beep_params { + enum beep_type type; + int frequency; /* Hz */ + int duration; /* milliseconds */ +}; + + +struct beep_params beep_params[] = { + BEEP_CONSOLE, 900, 200, + BEEP_TYPE4, 2000, 0, + BEEP_DEFAULT, 1000, 200, /* Must be last */ +}; + + +/* beep_state structure */ + +typedef struct beep_state { + + dev_info_t *beep_state_beep_dip; /* device pointer */ + + /* Indicates if a beep command is already in progress */ + enum {BEEP_OFF, BEEP_TIMED, BEEP_ON} beep_state_mode; + + /* Address of the hw-dependent beep_freq function */ + void (*beep_state_beep_freq) (dev_info_t *, int); + + /* Address of the hw-dependent beep_on function */ + void (*beep_state_beep_on) (dev_info_t *); + + /* Address of the hw-dependent beep_off function */ + void (*beep_state_beep_off) (dev_info_t *); + + /* Timeout id for the beep() timeout function */ + timeout_id_t beep_state_timeout_id; + + /* Mutex */ + kmutex_t beep_state_mutex; + +} beep_state_t; + + +static beep_state_t *beep_statep = NULL; + + +/* + * beep_init : + * Alloc beep_state structure + * called from the beep driver attach routine + */ +int +beep_init(dev_info_t *dip, void (*hwbeep_beep_on)(dev_info_t *), + void (*hwbeep_beep_off)(dev_info_t *), + void (*hwbeep_beep_freq)(dev_info_t *, int)) +{ + BEEP_DEBUG1((CE_CONT, "beep_init : start")); + + if (dip == NULL) { + return (DDI_FAILURE); + } + + if ((hwbeep_beep_on == NULL) || (hwbeep_beep_off == NULL) || + (hwbeep_beep_freq == NULL)) { + + BEEP_DEBUG((CE_WARN, + "beep_init : Null routines passed for registration.")); + return (DDI_FAILURE); + } + + beep_statep = kmem_zalloc(sizeof (beep_state_t), KM_SLEEP); + if (beep_statep == NULL) { + BEEP_DEBUG((CE_WARN, + "beep_init : kmem_zalloc failed.")); + return (DDI_FAILURE); + } + + beep_statep->beep_state_beep_dip = dip; + beep_statep->beep_state_beep_on = hwbeep_beep_on; + beep_statep->beep_state_beep_off = hwbeep_beep_off; + beep_statep->beep_state_beep_freq = hwbeep_beep_freq; + beep_statep->beep_state_mode = BEEP_OFF; + + mutex_init(&beep_statep->beep_state_mutex, NULL, MUTEX_DRIVER, NULL); + + BEEP_DEBUG1((CE_CONT, "beep_init : Done.")); + return (DDI_SUCCESS); + +} + + +/* + * beep : + * Start beeping for period specified by 'time' (in microsecond) + */ +void +beep(enum beep_type type) +{ + + struct beep_params *bp; + + BEEP_DEBUG1((CE_CONT, "beep : Start")); + + if (beep_statep == NULL) { + return; + } + + for (bp = beep_params; bp->type != BEEP_DEFAULT; bp++) { + if (bp->type == type) + break; + } + + if (bp->type != type) { + + /* If type doesn't match, return silently without beeping */ + return; + } + + mutex_enter(&beep_statep->beep_state_mutex); + + /* Beep only when no previous beep is in progress */ + if (beep_statep->beep_state_mode == BEEP_OFF && bp->frequency != 0) { + + beep_statep->beep_state_mode = BEEP_TIMED; + + (*beep_statep->beep_state_beep_freq)(beep_statep-> + beep_state_beep_dip, bp->frequency); + (*beep_statep->beep_state_beep_on)(beep_statep-> + beep_state_beep_dip); + + /* Set timeout for ending the beep after the specified time */ + beep_statep->beep_state_timeout_id = timeout(beep_timeout, + NULL, + drv_usectohz(bp->duration*1000)); + } + + mutex_exit(&beep_statep->beep_state_mutex); + + BEEP_DEBUG1((CE_CONT, "beep : Done")); + +} + + +/*ARGSUSED*/ +void +beep_polled(enum beep_type type) +{ + /* No-op at this time */ +} + + +/* + * beeper_on : + * Turn the beeper on + */ +void +beeper_on(enum beep_type type) +{ + + struct beep_params *bp; + + BEEP_DEBUG1((CE_CONT, "beeper_on : Start")); + + if (beep_statep == NULL) { + return; + } + + for (bp = beep_params; bp->type != BEEP_DEFAULT; bp++) { + if (bp->type == type) + break; + } + + if (bp->type != type) { + + /* If type doesn't match, return silently */ + return; + } + + mutex_enter(&beep_statep->beep_state_mutex); + + /* Start another beep only if the previous one is over */ + if (beep_statep->beep_state_mode == BEEP_OFF) { + + beep_statep->beep_state_mode = BEEP_ON; + + if (bp->frequency != 0) { + (*beep_statep->beep_state_beep_freq)(beep_statep-> + beep_state_beep_dip, bp->frequency); + (*beep_statep->beep_state_beep_on)(beep_statep-> + beep_state_beep_dip); + } + } + mutex_exit(&beep_statep->beep_state_mutex); + + BEEP_DEBUG1((CE_CONT, "beeper_on : Done")); + +} + + +/* + * beeper_off : + * Turn the beeper off + */ +void +beeper_off() +{ + + BEEP_DEBUG1((CE_CONT, "beeper_off : Start")); + + if (beep_statep == NULL) { + return; + } + + mutex_enter(&beep_statep->beep_state_mutex); + + if (beep_statep->beep_state_mode == BEEP_ON) { + + beep_statep->beep_state_mode = BEEP_OFF; + (*beep_statep->beep_state_beep_off)(beep_statep-> + beep_state_beep_dip); + } + mutex_exit(&beep_statep->beep_state_mutex); + + BEEP_DEBUG1((CE_CONT, "beeper_off : Done")); + +} + + +/* + * Turn the beeper off which had been turned on from beep() + * for a specified period of time + */ +void +beep_timeout() +{ + BEEP_DEBUG1((CE_CONT, "beeper_timeout : Start")); + + beep_statep->beep_state_timeout_id = 0; + mutex_enter(&beep_statep->beep_state_mutex); + + if ((beep_statep->beep_state_mode == BEEP_ON) || + (beep_statep->beep_state_mode == BEEP_TIMED)) { + + beep_statep->beep_state_mode = BEEP_OFF; + (*beep_statep->beep_state_beep_off)(beep_statep-> + beep_state_beep_dip); + } + mutex_exit(&beep_statep->beep_state_mutex); + + BEEP_DEBUG1((CE_CONT, "beeper_timeout : Done")); + +} + +/* + * Beeper_freq: + * Set beeper frequency + */ +int +beeper_freq(enum beep_type type, int freq) +{ + struct beep_params *bp; + + BEEP_DEBUG1((CE_CONT, "beeper_freq : Start")); + + /* + * The frequency value is limited to the range of [0 - 32767] + */ + if ((type != BEEP_CONSOLE && type != BEEP_TYPE4) || freq < 0 || + freq > INT16_MAX) + return (EINVAL); + + for (bp = beep_params; bp->type != BEEP_DEFAULT; bp++) { + if (bp->type == type) + break; + } + + bp->frequency = freq; + + BEEP_DEBUG1((CE_CONT, "beeper_freq : Done")); + + return (0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/deleted_files/usr/src/uts/sun4/sys/beep_driver.h Tue Sep 25 13:11:35 2007 -0700 @@ -0,0 +1,56 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1999,2003 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _SYS_BEEP_DRIVER_H +#define _SYS_BEEP_DRIVER_H + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * beep_driver.h : Registration functions of beep driver to beeper module + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_KERNEL) + +/* + * Registration mechanism of the hardware dependent + * beep driver to the beeper module for sun4 platforms. + */ +int beep_init(dev_info_t *, void (*)(dev_info_t *), + void (*)(dev_info_t *), void (*)(dev_info_t *, int)); + + +#endif /* _KERNEL */ + +#ifdef __cplusplus +} +#endif + +#endif /* _SYS_BEEP_DRIVER_H */
--- a/usr/src/cmd/truss/codes.c Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/cmd/truss/codes.c Tue Sep 25 13:11:35 2007 -0700 @@ -819,6 +819,7 @@ { (uint_t)KIOCGRPTRATE, "KIOCGRPTRATE", NULL }, { (uint_t)KIOCSRPTRATE, "KIOCSRPTRATE", NULL }, { (uint_t)KIOCSETFREQ, "KIOCSETFREQ", NULL }, + { (uint_t)KIOCMKTONE, "KIOCMKTONE", NULL }, /* ptm/pts driver I_STR ioctls */ { (uint_t)ISPTM, "ISPTM", NULL},
--- a/usr/src/pkgdefs/SUNWcakr.i/prototype_com Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/pkgdefs/SUNWcakr.i/prototype_com Tue Sep 25 13:11:35 2007 -0700 @@ -77,6 +77,7 @@ f none platform/i86pc/kernel/drv/amd64/mc-amd 755 root sys f none platform/i86pc/kernel/drv/amd64/npe 755 root sys f none platform/i86pc/kernel/drv/amd64/pci 755 root sys +f none platform/i86pc/kernel/drv/amd64/pit_beep 755 root sys f none platform/i86pc/kernel/drv/amd64/rootnex 755 root sys f none platform/i86pc/kernel/drv/cpudrv 755 root sys f none platform/i86pc/kernel/drv/isa 755 root sys @@ -84,6 +85,8 @@ f none platform/i86pc/kernel/drv/mc-amd.conf 644 root sys f none platform/i86pc/kernel/drv/npe 755 root sys f none platform/i86pc/kernel/drv/pci 755 root sys +f none platform/i86pc/kernel/drv/pit_beep 755 root sys +f none platform/i86pc/kernel/drv/pit_beep.conf 644 root sys f none platform/i86pc/kernel/drv/ppm 755 root sys f none platform/i86pc/kernel/drv/ppm.conf 644 root sys f none platform/i86pc/kernel/drv/rootnex 755 root sys
--- a/usr/src/uts/common/Makefile.files Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/common/Makefile.files Tue Sep 25 13:11:35 2007 -0700 @@ -37,6 +37,7 @@ sparc_CORE_OBJS += COMMON_CORE_OBJS += \ + beep.o \ bitset.o \ bp_map.o \ brand.o \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usr/src/uts/common/io/beep.c Tue Sep 25 13:11:35 2007 -0700 @@ -0,0 +1,517 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * This is the Beep module for supporting keyboard beep for keyboards + * that do not have the beeping feature within themselves + * + */ + +#include <sys/types.h> +#include <sys/conf.h> + +#include <sys/ddi.h> +#include <sys/sunddi.h> +#include <sys/modctl.h> +#include <sys/ddi_impldefs.h> +#include <sys/kmem.h> + +#include <sys/beep.h> +#include <sys/inttypes.h> + +/* + * Debug stuff + * BEEP_DEBUG used for errors + * BEEP_DEBUG1 prints when beep_debug > 1 and used for normal messages + */ +#ifdef DEBUG +int beep_debug = 0; +#define BEEP_DEBUG(args) if (beep_debug) cmn_err args +#define BEEP_DEBUG1(args) if (beep_debug > 1) cmn_err args +#else +#define BEEP_DEBUG(args) +#define BEEP_DEBUG1(args) +#endif + +int beep_queue_size = BEEP_QUEUE_SIZE; + +/* + * Note that mutex_init is not called on the mutex in beep_state, + * But assumes that zeroed memory does not need to call mutex_init, + * as documented in mutex.c + */ + +beep_state_t beep_state; + +beep_params_t beep_params[] = { + {BEEP_CONSOLE, 900, 200}, + {BEEP_TYPE4, 2000, 0}, + {BEEP_DEFAULT, 1000, 200}, /* Must be last */ +}; + + +/* + * beep_init: + * Allocate the beep_queue structure + * Initialize beep_state structure + * Called from beep driver attach routine + */ + +int +beep_init(void *arg, + beep_on_func_t beep_on_func, + beep_off_func_t beep_off_func, + beep_freq_func_t beep_freq_func) +{ + beep_entry_t *queue; + + BEEP_DEBUG1((CE_CONT, + "beep_init(0x%lx, 0x%lx, 0x%lx, 0x%lx) : start.", + (unsigned long) arg, + (unsigned long) beep_on_func, + (unsigned long) beep_off_func, + (unsigned long) beep_freq_func)); + + mutex_enter(&beep_state.mutex); + + if (beep_state.mode != BEEP_UNINIT) { + mutex_exit(&beep_state.mutex); + BEEP_DEBUG((CE_WARN, + "beep_init : beep_state already initialized.")); + return (DDI_SUCCESS); + } + + queue = kmem_zalloc(sizeof (beep_entry_t) * beep_queue_size, + KM_SLEEP); + + BEEP_DEBUG1((CE_CONT, + "beep_init : beep_queue kmem_zalloc(%d) = 0x%lx.", + (int)sizeof (beep_entry_t) * beep_queue_size, + (unsigned long)queue)); + + if (queue == NULL) { + BEEP_DEBUG((CE_WARN, + "beep_init : kmem_zalloc of beep_queue failed.")); + return (DDI_FAILURE); + } + + beep_state.arg = arg; + beep_state.mode = BEEP_OFF; + beep_state.beep_freq = beep_freq_func; + beep_state.beep_on = beep_on_func; + beep_state.beep_off = beep_off_func; + beep_state.timeout_id = 0; + + beep_state.queue_head = 0; + beep_state.queue_tail = 0; + beep_state.queue_size = beep_queue_size; + beep_state.queue = queue; + + mutex_exit(&beep_state.mutex); + + BEEP_DEBUG1((CE_CONT, "beep_init : done.")); + return (DDI_SUCCESS); +} + + +int +beep_fini(void) +{ + BEEP_DEBUG1((CE_CONT, "beep_fini() : start.")); + + (void) beeper_off(); + + mutex_enter(&beep_state.mutex); + + if (beep_state.mode == BEEP_UNINIT) { + mutex_exit(&beep_state.mutex); + BEEP_DEBUG((CE_WARN, + "beep_fini : beep_state already uninitialized.")); + return (0); + } + + if (beep_state.queue != NULL) + kmem_free(beep_state.queue, + sizeof (beep_entry_t) * beep_state.queue_size); + + beep_state.arg = (void *)NULL; + beep_state.mode = BEEP_UNINIT; + beep_state.beep_freq = (beep_freq_func_t)NULL; + beep_state.beep_on = (beep_on_func_t)NULL; + beep_state.beep_off = (beep_off_func_t)NULL; + beep_state.timeout_id = 0; + + beep_state.queue_head = 0; + beep_state.queue_tail = 0; + beep_state.queue_size = 0; + beep_state.queue = (beep_entry_t *)NULL; + + mutex_exit(&beep_state.mutex); + + BEEP_DEBUG1((CE_CONT, "beep_fini() : done.")); + + return (0); +} + + +int +beeper_off(void) +{ + BEEP_DEBUG1((CE_CONT, "beeper_off : start.")); + + mutex_enter(&beep_state.mutex); + + if (beep_state.mode == BEEP_UNINIT) { + mutex_exit(&beep_state.mutex); + return (ENXIO); + } + + if (beep_state.mode == BEEP_TIMED) { + (void) untimeout(beep_state.timeout_id); + beep_state.timeout_id = 0; + } + + if (beep_state.mode != BEEP_OFF) { + beep_state.mode = BEEP_OFF; + + if (beep_state.beep_off != NULL) + (*beep_state.beep_off)(beep_state.arg); + } + + beep_state.queue_head = 0; + beep_state.queue_tail = 0; + + mutex_exit(&beep_state.mutex); + + BEEP_DEBUG1((CE_CONT, "beeper_off : done.")); + + return (0); +} + +int +beeper_freq(enum beep_type type, int freq) +{ + beep_params_t *bp; + + BEEP_DEBUG1((CE_CONT, "beeper_freq(%d, %d) : start", type, freq)); + + /* + * The frequency value is limited to the range of [0 - 32767] + */ + if (freq < 0 || freq > INT16_MAX) + return (EINVAL); + + for (bp = beep_params; bp->type != BEEP_DEFAULT; bp++) { + if (bp->type == type) + break; + } + + if (bp->type != type) { + BEEP_DEBUG((CE_WARN, "beeper_freq : invalid type.")); + + return (EINVAL); + } + + bp->frequency = freq; + + BEEP_DEBUG1((CE_CONT, "beeper_freq : done.")); + return (0); +} + +/* + * beep : + * Start beeping for period specified by the type value, + * from the value in the beep_param structure in milliseconds. + */ +int +beep(enum beep_type type) +{ + + beep_params_t *bp; + + BEEP_DEBUG1((CE_CONT, "beep(%d) : start.", type)); + + for (bp = beep_params; bp->type != BEEP_DEFAULT; bp++) { + if (bp->type == type) + break; + } + + if (bp->type != type) { + + BEEP_DEBUG((CE_WARN, "beep : invalid type.")); + + /* If type doesn't match, return silently without beeping */ + return (EINVAL); + } + + return (beep_mktone(bp->frequency, bp->duration)); +} + + +/*ARGSUSED*/ +int +beep_polled(enum beep_type type) +{ + /* + * No-op at this time. + * + * Don't think we can make this work in general, as tem_safe + * has a requirement of no mutexes, but kbd sends messages + * through streams. + */ + + BEEP_DEBUG1((CE_CONT, "beep_polled(%d)", type)); + + return (0); +} + +/* + * beeper_on : + * Turn the beeper on + */ +int +beeper_on(enum beep_type type) +{ + beep_params_t *bp; + int status = 0; + + BEEP_DEBUG1((CE_CONT, "beeper_on(%d) : start.", type)); + + for (bp = beep_params; bp->type != BEEP_DEFAULT; bp++) { + if (bp->type == type) + break; + } + + if (bp->type != type) { + + BEEP_DEBUG((CE_WARN, "beeper_on : invalid type.")); + + /* If type doesn't match, return silently without beeping */ + return (EINVAL); + } + + mutex_enter(&beep_state.mutex); + + if (beep_state.mode == BEEP_UNINIT) { + status = ENXIO; + + /* Start another beep only if the previous one is over */ + } else if (beep_state.mode == BEEP_OFF) { + if (bp->frequency != 0) { + beep_state.mode = BEEP_ON; + + if (beep_state.beep_freq != NULL) + (*beep_state.beep_freq)(beep_state.arg, + bp->frequency); + + if (beep_state.beep_on != NULL) + (*beep_state.beep_on)(beep_state.arg); + } + } else { + status = EBUSY; + } + + mutex_exit(&beep_state.mutex); + + BEEP_DEBUG1((CE_CONT, "beeper_on : done, status %d.", status)); + + return (status); +} + + +int +beep_mktone(int frequency, int duration) +{ + int next; + int status = 0; + + BEEP_DEBUG1((CE_CONT, "beep_mktone(%d, %d) : start.", frequency, + duration)); + + /* + * The frequency value is limited to the range of [0 - 32767] + */ + if (frequency < 0 || frequency > INT16_MAX) + return (EINVAL); + + mutex_enter(&beep_state.mutex); + + if (beep_state.mode == BEEP_UNINIT) { + status = ENXIO; + + } else if (beep_state.mode == BEEP_TIMED) { + + /* If already processing a beep, queue this one */ + + if (frequency != 0) { + next = beep_state.queue_tail + 1; + if (next == beep_state.queue_size) + next = 0; + + if (next != beep_state.queue_head) { + /* + * If there is room in the queue, + * add this entry + */ + + beep_state.queue[beep_state.queue_tail]. + frequency = (unsigned short)frequency; + + beep_state.queue[beep_state.queue_tail]. + duration = (unsigned short)duration; + + beep_state.queue_tail = next; + } else { + status = EAGAIN; + } + } + + } else if (beep_state.mode == BEEP_OFF) { + + /* Start another beep only if the previous one is over */ + + if (frequency != 0) { + beep_state.mode = BEEP_TIMED; + + if (beep_state.beep_freq != NULL) + (*beep_state.beep_freq)(beep_state.arg, + frequency); + + if (beep_state.beep_on != NULL) + (*beep_state.beep_on)(beep_state.arg); + + /* + * Set timeout for ending the beep after the + * specified time + */ + + beep_state.timeout_id = timeout(beep_timeout, NULL, + drv_usectohz(duration * 1000)); + } + } else { + status = EBUSY; + } + + mutex_exit(&beep_state.mutex); + + BEEP_DEBUG1((CE_CONT, "beep_mktone : done, status %d.", status)); + + return (status); +} + + +/* + * Turn the beeper off which had been turned on from beep() + * for a specified period of time + */ +/*ARGSUSED*/ +void +beep_timeout(void *arg) +{ + int frequency; + int duration; + int next; + + BEEP_DEBUG1((CE_CONT, "beeper_timeout : start.")); + + mutex_enter(&beep_state.mutex); + + beep_state.timeout_id = 0; + + if (beep_state.mode == BEEP_UNINIT) { + mutex_exit(&beep_state.mutex); + BEEP_DEBUG1((CE_CONT, "beep_timeout : uninitialized.")); + return; + } + + if ((beep_state.mode == BEEP_ON) || + (beep_state.mode == BEEP_TIMED)) { + + beep_state.mode = BEEP_OFF; + + if (beep_state.beep_off != NULL) + (*beep_state.beep_off)(beep_state.arg); + } + + if (beep_state.queue_head != beep_state.queue_tail) { + + next = beep_state.queue_head; + + frequency = beep_state.queue[next].frequency; + + duration = beep_state.queue[next].duration; + + next++; + if (next == beep_state.queue_size) + next = 0; + + beep_state.queue_head = next; + + beep_state.mode = BEEP_TIMED; + + if (frequency != 0) { + if (beep_state.beep_freq != NULL) + (*beep_state.beep_freq)(beep_state.arg, + frequency); + + if (beep_state.beep_on != NULL) + (*beep_state.beep_on)(beep_state.arg); + } + + /* Set timeout for ending the beep after the specified time */ + + beep_state.timeout_id = timeout(beep_timeout, NULL, + drv_usectohz(duration * 1000)); + } + + mutex_exit(&beep_state.mutex); + + BEEP_DEBUG1((CE_CONT, "beep_timeout : done.")); +} + + +/* + * Return true (1) if we are sounding a tone. + */ +int +beep_busy(void) +{ + int status; + + BEEP_DEBUG1((CE_CONT, "beep_busy : start.")); + + mutex_enter(&beep_state.mutex); + + status = beep_state.mode != BEEP_UNINIT && + beep_state.mode != BEEP_OFF; + + mutex_exit(&beep_state.mutex); + + BEEP_DEBUG1((CE_CONT, "beep_busy : status %d.", status)); + + return (status); +}
--- a/usr/src/uts/common/io/conskbd.c Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/common/io/conskbd.c Tue Sep 25 13:11:35 2007 -0700 @@ -983,6 +983,7 @@ break; case KIOCCMD: + case KIOCMKTONE: if (conskbd.conskbd_lqueue_list == NULL || mp->b_cont == NULL) { miocnak(q, mp, 0, EINVAL); @@ -1275,7 +1276,8 @@ ASSERT(iocp->ioc_cmd == CONSOPENPOLLEDIO || iocp->ioc_cmd == CONSCLOSEPOLLEDIO || - iocp->ioc_cmd == KIOCCMD); + iocp->ioc_cmd == KIOCCMD || + iocp->ioc_cmd == KIOCMKTONE); msg->kpm_upper_queue = q; msg->kpm_req_msg = mp; @@ -1963,6 +1965,7 @@ break; case KIOCCMD: + case KIOCMKTONE: for (mp = msg->kpm_resp_list; mp; ) { msg->kpm_resp_list = mp->b_next;
--- a/usr/src/uts/common/io/kb8042/kb8042.c Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/common/io/kb8042/kb8042.c Tue Sep 25 13:11:35 2007 -0700 @@ -23,7 +23,7 @@ /* All Rights Reserved */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -54,6 +54,7 @@ #include "sys/reboot.h" #include <sys/promif.h> #include <sys/beep.h> +#include <sys/inttypes.h> /* * For any keyboard, there is a unique code describing the position @@ -385,8 +386,8 @@ * just for fun, so blow past those to get the keyboard scan code. */ while (kb8042_is_input_avail(kb8042, MAX_WAIT_USECS, B_TRUE) && - (scanset = ddi_get8(kb8042->handle, kb8042->addr + port)) - == KB_ACK) + (scanset = ddi_get8(kb8042->handle, kb8042->addr + port)) + == KB_ACK) ; #ifdef KD_DEBUG @@ -455,14 +456,14 @@ kb8042->polled_synthetic_release_pending = B_FALSE; if (ddi_create_minor_node(devi, module_name, S_IFCHR, 0, - DDI_NT_KEYBOARD, 0) == DDI_FAILURE) { + DDI_NT_KEYBOARD, 0) == DDI_FAILURE) { goto failure; } kb8042->init_state |= KB8042_MINOR_NODE_CREATED; rc = ddi_regs_map_setup(devi, 0, (caddr_t *)&kb8042->addr, - (offset_t)0, (offset_t)0, &attr, &kb8042->handle); + (offset_t)0, (offset_t)0, &attr, &kb8042->handle); if (rc != DDI_SUCCESS) { #if defined(KD_DEBUG) cmn_err(CE_WARN, "kb8042_attach: can't map registers"); @@ -473,7 +474,7 @@ kb8042->init_state |= KB8042_REGS_MAPPED; if (ddi_get_iblock_cookie(devi, 0, &kb8042->w_iblock) != - DDI_SUCCESS) { + DDI_SUCCESS) { cmn_err(CE_WARN, "kb8042_attach: Can't get iblock cookie"); goto failure; } @@ -522,8 +523,8 @@ * Turn on interrupts... */ if (ddi_add_intr(devi, 0, - &kb8042->w_iblock, (ddi_idevice_cookie_t *)NULL, - kb8042_intr, (caddr_t)kb8042) != DDI_SUCCESS) { + &kb8042->w_iblock, (ddi_idevice_cookie_t *)NULL, + kb8042_intr, (caddr_t)kb8042) != DDI_SUCCESS) { cmn_err(CE_WARN, "kb8042_attach: cannot add interrupt"); goto failure; } @@ -671,9 +672,9 @@ kb8042_get_initial_leds(kb8042, &initial_leds, &initial_led_mask); err = kbtrans_streams_init(qp, sflag, credp, - (struct kbtrans_hardware *)kb8042, &kb8042_callbacks, - &kb8042->hw_kbtrans, - initial_leds, initial_led_mask); + (struct kbtrans_hardware *)kb8042, &kb8042_callbacks, + &kb8042->hw_kbtrans, + initial_leds, initial_led_mask); if (err != 0) return (err); @@ -681,19 +682,19 @@ kb8042->polledio.cons_polledio_version = CONSPOLLEDIO_V1; kb8042->polledio.cons_polledio_argument = - (cons_polledio_arg_t)kb8042; + (cons_polledio_arg_t)kb8042; kb8042->polledio.cons_polledio_putchar = NULL; kb8042->polledio.cons_polledio_getchar = - (int (*)(cons_polledio_arg_t))kb8042_polled_getchar; + (int (*)(cons_polledio_arg_t))kb8042_polled_getchar; kb8042->polledio.cons_polledio_ischar = - (boolean_t (*)(cons_polledio_arg_t))kb8042_polled_ischar; + (boolean_t (*)(cons_polledio_arg_t))kb8042_polled_ischar; kb8042->polledio.cons_polledio_enter = NULL; kb8042->polledio.cons_polledio_exit = NULL; kb8042->polledio.cons_polledio_setled = - (void (*)(cons_polledio_arg_t, int))kb8042_polled_setled; + (void (*)(cons_polledio_arg_t, int))kb8042_polled_setled; kb8042->polledio.cons_polledio_keycheck = - (boolean_t (*)(cons_polledio_arg_t, int *, - enum keystate *))kb8042_polled_keycheck; + (boolean_t (*)(cons_polledio_arg_t, int *, + enum keystate *))kb8042_polled_keycheck; qprocson(qp); @@ -708,6 +709,9 @@ { struct kb8042 *kb8042; + /* If a beep is in progress, stop that */ + (void) beeper_off(); + kb8042 = (struct kb8042 *)qp->q_ptr; (void) kbtrans_streams_fini(kb8042->hw_kbtrans); @@ -756,7 +760,7 @@ continue; default: cmn_err(CE_NOTE, "kb8042_wsrv: bad msg %x", - mp->b_datap->db_type); + mp->b_datap->db_type); freemsg(mp); continue; } @@ -771,6 +775,9 @@ mblk_t *datap; int error; int tmp; + int cycles; + int frequency; + int msecs; iocp = (struct iocblk *)mp->b_rptr; @@ -873,6 +880,33 @@ miocack(qp, mp, 0, 0); break; + case KIOCMKTONE: + if (iocp->ioc_count != TRANSPARENT) { + miocnak(qp, mp, 0, EINVAL); + return; + } + + tmp = (int)(*(intptr_t *)mp->b_cont->b_rptr); + cycles = tmp & 0xffff; + msecs = (tmp >> 16) & 0xffff; + + if (cycles == 0) + frequency = UINT16_MAX; + else if (cycles == UINT16_MAX) + frequency = 0; + else { + frequency = (PIT_HZ + cycles / 2) / cycles; + if (frequency > UINT16_MAX) + frequency = UINT16_MAX; + } + + error = beep_mktone(frequency, msecs); + if (error != 0) + miocnak(qp, mp, 0, error); + else + miocack(qp, mp, 0, 0); + break; + default: #ifdef DEBUG1 cmn_err(CE_NOTE, "!kb8042_ioctlmsg %x", iocp->ioc_cmd); @@ -903,7 +937,7 @@ return; legit = KeyboardConvertScan(kb8042, scancode, &key_pos, &state, - &synthetic_release_needed); + &synthetic_release_needed); if (legit == 0) { /* Eaten by translation */ @@ -917,9 +951,9 @@ #ifdef KD_DEBUG if (kb8042_debug) { prom_printf("kb8042_intr: 0x%x -> %s %d", - scancode, - state == KEY_RELEASED ? "released" : "pressed", - key_pos); + scancode, + state == KEY_RELEASED ? "released" : "pressed", + key_pos); } #endif @@ -994,8 +1028,8 @@ #if defined(KD_DEBUG) if (kb8042_pressrelease_debug) { prom_printf(" %s%d ", - state == KEY_PRESSED ? "+" : "-", - key_pos); + state == KEY_PRESSED ? "+" : "-", + key_pos); } #endif @@ -1059,7 +1093,7 @@ rc = DDI_INTR_CLAIMED; scancode = ddi_get8(kb8042->handle, - kb8042->addr + I8042_INT_INPUT_DATA); + kb8042->addr + I8042_INT_INPUT_DATA); #if defined(KD_DEBUG) if (kb8042_low_level_debug) @@ -1131,7 +1165,7 @@ } scancode = ddi_get8(kb8042->handle, - kb8042->addr + I8042_POLL_INPUT_DATA); + kb8042->addr + I8042_POLL_INPUT_DATA); #if defined(KD_DEBUG) if (kb8042_low_level_debug) @@ -1150,7 +1184,7 @@ #endif legit = KeyboardConvertScan(kb8042, scancode, key, state, - &synthetic_release_needed); + &synthetic_release_needed); if (!legit) { #ifdef KD_DEBUG if (kb8042_getchar_debug) @@ -1161,8 +1195,8 @@ #ifdef KD_DEBUG if (kb8042_getchar_debug) { prom_printf(" -> %s %d\n", - *state == KEY_PRESSED ? "pressed" : "released", - *key); + *state == KEY_PRESSED ? "pressed" : "released", + *key); } #endif /* @@ -1256,7 +1290,7 @@ /* wait for up to 250 ms for a response */ for (cnt = 0; cnt < 250; cnt++) { ready = ddi_get8(kb8042->handle, - kb8042->addr + I8042_INT_INPUT_AVAIL); + kb8042->addr + I8042_INT_INPUT_AVAIL); if (ready != 0) break; drv_usecwait(1000); @@ -1269,7 +1303,7 @@ */ if (ready != 0) { byt = ddi_get8(kb8042->handle, - kb8042->addr + I8042_INT_INPUT_DATA); + kb8042->addr + I8042_INT_INPUT_DATA); #if defined(KD_DEBUG) if (kb8042_low_level_debug) prom_printf(" <K:%x ", byt); @@ -1298,8 +1332,8 @@ case KB_COMMAND_STATE_LED: if (scancode == KB_ACK) { kb8042_send_to_keyboard(kb8042, - kb8042_xlate_leds(kb8042->leds.desired), - polled); + kb8042_xlate_leds(kb8042->leds.desired), + polled); kb8042->leds.commanded = kb8042->leds.desired; kb8042->command_state = KB_COMMAND_STATE_WAIT; return (STATE_INTERNAL); @@ -1436,10 +1470,10 @@ { switch (cmd) { case KBD_CMD_BELL: - beeper_on(BEEP_TYPE4); + (void) beeper_on(BEEP_TYPE4); break; case KBD_CMD_NOBELL: - beeper_off(); + (void) beeper_off(); break; } }
--- a/usr/src/uts/common/io/kbd.c Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/common/io/kbd.c Tue Sep 25 13:11:35 2007 -0700 @@ -56,6 +56,8 @@ #include <sys/policy.h> #include <sys/modctl.h> +#include <sys/beep.h> +#include <sys/int_limits.h> static struct streamtab kbd_info; @@ -231,6 +233,8 @@ static void kbdflush(struct kbddata *); static void kbduse(struct kbddata *, unsigned); static void kbdsetled(struct kbddata *); +static void kbd_beep_off(void *arg); +static void kbd_beep_on(void *arg); static void kbdcmd(queue_t *, char); static void kbdreset(struct kbddata *, uint_t); static int kbdsetkey(struct kbddata *, struct kiockey *, cred_t *); @@ -342,7 +346,7 @@ } } while ((datap = allocb(sizeof (struct termios), BPRI_HI)) == - NULL) { + NULL) { timeout_id_t id = qbufcall(q, sizeof (struct termios), BPRI_HI, dummy_callback, NULL); if (!qwait_sig(q)) { @@ -407,6 +411,8 @@ */ kbdreset(kbdd, HARD_RESET); + (void) beep_init((void *)WR(q), kbd_beep_on, kbd_beep_off, NULL); + return (0); error: @@ -426,6 +432,7 @@ register mblk_t *mp; qprocsoff(q); + (void) beep_fini(); /* * Since we're about to destroy our private data, turn off * our open flag first, so we don't accept any more input @@ -510,6 +517,10 @@ mblk_t *datap; size_t ioctlrespsize; int err = 0; + int tmp; + int cycles; + int frequency; + int msecs; iocp = (struct iocblk *)mp->b_rptr; @@ -543,7 +554,39 @@ if (err != 0) break; - kbdcmd(q, (char)(*(int *)mp->b_cont->b_rptr)); + tmp = (char)(*(int *)mp->b_cont->b_rptr); + if (tmp == KBD_CMD_BELL) + (void) beeper_on(BEEP_TYPE4); + else if (tmp == KBD_CMD_NOBELL) + (void) beeper_off(); + else + kbdcmd(q, tmp); + break; + + case KIOCMKTONE: + if (iocp->ioc_count != TRANSPARENT) { + /* + * We don't support non-transparent ioctls, + * i.e. I_STR ioctls + */ + err = EINVAL; + break; + } + tmp = (int)(*(intptr_t *)mp->b_cont->b_rptr); + cycles = tmp & 0xffff; + msecs = (tmp >> 16) & 0xffff; + + if (cycles == 0) + frequency = UINT16_MAX; + else if (cycles == UINT16_MAX) + frequency = 0; + else { + frequency = (PIT_HZ + cycles / 2) / cycles; + if (frequency > UINT16_MAX) + frequency = UINT16_MAX; + } + + err = beep_mktone(frequency, msecs); break; case KIOCSLED: @@ -576,7 +619,7 @@ *(int *)datap->b_wptr = (kbdd->kbdd_translate == TR_EVENT || kbdd->kbdd_translate == TR_UNTRANS_EVENT) ? - VUID_FIRM_EVENT: VUID_NATIVE; + VUID_FIRM_EVENT: VUID_NATIVE; datap->b_wptr += sizeof (int); if (mp->b_cont) /* free msg to prevent memory leak */ freemsg(mp->b_cont); @@ -955,6 +998,20 @@ kbdtranslate(kbdd, keycode, readq); } +static void +kbd_beep_on(void *arg) +{ + kbdcmd((queue_t *)arg, KBD_CMD_BELL); +} + + +static void +kbd_beep_off(void *arg) +{ + kbdcmd((queue_t *)arg, KBD_CMD_NOBELL); +} + + /* * kbdclick is used to remember the current click value of the * Sun-3 keyboard. This brain damaged keyboard will reset the @@ -980,7 +1037,7 @@ if (canput(q)) { if ((bp = allocb(1, BPRI_MED)) == NULL) cmn_err(CE_WARN, - "kbdcmd: Can't allocate block for command"); + "kbdcmd: Can't allocate block for command"); else { *bp->b_wptr++ = cmd; putnext(q, bp); @@ -1417,7 +1474,7 @@ len > 0 && len < 8) { if (strcmp(wrkbuf, "true") == 0) { kbdcmd(kbdd->kbdd_writeq, - KBD_CMD_CLICK); + KBD_CMD_CLICK); } } } @@ -1604,7 +1661,7 @@ k->k_id = keytables[0].id; k->k_curkeyboard = keytables[0].table; cmn_err(CE_WARN, "kbd: Unknown keyboard type, " - "Type %d assumed", k->k_id); + "Type %d assumed", k->k_id); } } @@ -1780,32 +1837,33 @@ if (kb_compose_map[entry] >= 0) { if (kbdd->compose_key <= entry) { ret_val = kbd_do_compose( - kbdd->compose_key, - entry, - &result_iso); + kbdd->compose_key, + entry, + &result_iso); } else { ret_val = kbd_do_compose( - entry, - kbdd->compose_key, - &result_iso); + entry, + kbdd->compose_key, + &result_iso); } if (ret_val == 1) { if (kbdd->kbdd_translate == - TR_EVENT) { + TR_EVENT) { fe.id = - (kbdd->kbdd_compat ? - ISO_FIRST : EUC_FIRST) - + result_iso; + (kbdd->kbdd_compat ? + ISO_FIRST : + EUC_FIRST) + + result_iso; fe.value = 1; kbdqueueevent( - kbdd, - &fe); + kbdd, + &fe); } else if ( - kbdd->kbdd_translate == - TR_ASCII) + kbdd->kbdd_translate == + TR_ASCII) kbdputcode( - result_iso, - q); + result_iso, + q); } } } @@ -1816,7 +1874,7 @@ k->k_state = NORMAL; /* next state is "normal" */ for (i = 0; (kb_fltaccent_table[i].fa_entry - != kbdd->fltaccent_entry) || + != kbdd->fltaccent_entry) || (kb_fltaccent_table[i].ascii != entry); i++) { if (kb_fltaccent_table[i].fa_entry == 0) @@ -1825,8 +1883,8 @@ } if (kbdd->kbdd_translate == TR_EVENT) { fe.id = (kbdd->kbdd_compat ? - ISO_FIRST : EUC_FIRST) - + kb_fltaccent_table[i].iso; + ISO_FIRST : EUC_FIRST) + + kb_fltaccent_table[i].iso; fe.value = 1; kbdqueueevent(kbdd, &fe); } else if (kbdd->kbdd_translate == TR_ASCII) @@ -2008,8 +2066,8 @@ case TR_ASCII: bufp = buf; cp = strsetwithdecimal(bufp + 2, - (uint_t)((entry & 0x003F) + 192), - sizeof (buf) - 5); + (uint_t)((entry & 0x003F) + 192), + sizeof (buf) - 5); *bufp++ = '\033'; /* Escape */ *bufp++ = '['; while (*cp != '\0') @@ -2327,7 +2385,7 @@ else { if ((bp = allocb((int)strlen(buf), BPRI_HI)) == NULL) cmn_err(CE_WARN, - "kbdputbuf: Can't allocate block for keycode"); + "kbdputbuf: Can't allocate block for keycode"); else { while (*buf) { *bp->b_wptr++ = *buf; @@ -2352,7 +2410,7 @@ if (!canput(q)) { if (kbd_overflow_msg) cmn_err(CE_WARN, - "kbd: Buffer flushed when overflowed"); + "kbd: Buffer flushed when overflowed"); kbdflush(kbdd); kbd_overflow_cnt++; } else {
--- a/usr/src/uts/common/io/tem_safe.c Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/common/io/tem_safe.c Tue Sep 25 13:11:35 2007 -0700 @@ -611,15 +611,15 @@ /* erase cursor to end of screen */ /* FIRST erase cursor to end of line */ tem_clear_chars(tem, - tems->a_c_dimension.width - - tems->a_c_cursor.col, - tems->a_c_cursor.row, - tems->a_c_cursor.col, credp, called_from); + tems->a_c_dimension.width - + tems->a_c_cursor.col, + tems->a_c_cursor.row, + tems->a_c_cursor.col, credp, called_from); /* THEN erase lines below the cursor */ for (row = tems->a_c_cursor.row + 1; - row < tems->a_c_dimension.height; - row++) { + row < tems->a_c_dimension.height; + row++) { tem_clear_chars(tem, tems->a_c_dimension.width, row, 0, credp, called_from); @@ -630,17 +630,17 @@ /* erase beginning of screen to cursor */ /* FIRST erase lines above the cursor */ for (row = 0; - row < tems->a_c_cursor.row; - row++) { + row < tems->a_c_cursor.row; + row++) { tem_clear_chars(tem, tems->a_c_dimension.width, row, 0, credp, called_from); } /* THEN erase beginning of line to cursor */ tem_clear_chars(tem, - tems->a_c_cursor.col + 1, - tems->a_c_cursor.row, - 0, credp, called_from); + tems->a_c_cursor.col + 1, + tems->a_c_cursor.row, + 0, credp, called_from); break; case 2: @@ -649,8 +649,8 @@ row < tems->a_c_dimension.height; row++) { tem_clear_chars(tem, - tems->a_c_dimension.width, - row, 0, credp, called_from); + tems->a_c_dimension.width, + row, 0, credp, called_from); } break; } @@ -692,20 +692,20 @@ tem_send_data(tem, credp, called_from); tem_setparam(tem, 1, 1); tem_scroll(tem, - tems->a_c_cursor.row, - tems->a_c_dimension.height - 1, - tems->a_params[0], TEM_SCROLL_DOWN, - credp, called_from); + tems->a_c_cursor.row, + tems->a_c_dimension.height - 1, + tems->a_params[0], TEM_SCROLL_DOWN, + credp, called_from); break; case 'M': /* delete line */ tem_send_data(tem, credp, called_from); tem_setparam(tem, 1, 1); tem_scroll(tem, - tems->a_c_cursor.row, - tems->a_c_dimension.height - 1, - tems->a_params[0], TEM_SCROLL_UP, - credp, called_from); + tems->a_c_cursor.row, + tems->a_c_dimension.height - 1, + tems->a_params[0], TEM_SCROLL_UP, + credp, called_from); break; case 'P': /* DCH - delete char */ @@ -718,27 +718,27 @@ tem_send_data(tem, credp, called_from); tem_setparam(tem, 1, 1); tem_scroll(tem, 0, - tems->a_c_dimension.height - 1, - tems->a_params[0], TEM_SCROLL_UP, - credp, called_from); + tems->a_c_dimension.height - 1, + tems->a_params[0], TEM_SCROLL_UP, + credp, called_from); break; case 'T': /* scroll down */ tem_send_data(tem, credp, called_from); tem_setparam(tem, 1, 1); tem_scroll(tem, 0, - tems->a_c_dimension.height - 1, - tems->a_params[0], TEM_SCROLL_DOWN, - credp, called_from); + tems->a_c_dimension.height - 1, + tems->a_params[0], TEM_SCROLL_DOWN, + credp, called_from); break; case 'X': /* erase char */ tem_setparam(tem, 1, 1); tem_clear_chars(tem, - tems->a_params[0], - tems->a_c_cursor.row, - tems->a_c_cursor.col, - credp, called_from); + tems->a_params[0], + tems->a_c_cursor.row, + tems->a_c_cursor.col, + credp, called_from); break; case 'Z': /* cursor backward tabulation */ @@ -779,14 +779,14 @@ tems->a_gotparam = B_TRUE; /* Remember got parameter */ return; /* Return immediately */ } else if (tems->a_state == A_STATE_CSI_EQUAL || - tems->a_state == A_STATE_CSI_QMARK) { + tems->a_state == A_STATE_CSI_QMARK) { tems->a_state = A_STATE_START; } else { if (tems->a_curparam < TEM_MAXPARAMS) { if (tems->a_gotparam) { /* get the parameter value */ tems->a_params[tems->a_curparam] = - tems->a_paramval; + tems->a_paramval; } tems->a_curparam++; } @@ -877,7 +877,7 @@ } tem_mv_cursor(tem, row, tems->a_c_cursor.col, - credp, called_from); + credp, called_from); if (tems->a_nscroll == 0) { /* erase rest of cursor line */ @@ -922,12 +922,12 @@ * Call the primitive to render this data. */ (*tems->in_fp.f_display)(tem, - tems->a_outbuf, - tems->a_outindex, - tems->a_s_cursor.row, - tems->a_s_cursor.col, - fg_color, bg_color, - credp, called_from); + tems->a_outbuf, + tems->a_outindex, + tems->a_s_cursor.row, + tems->a_s_cursor.col, + fg_color, bg_color, + credp, called_from); tems->a_outindex = 0; } tem_align_cursor(tem); @@ -1119,9 +1119,9 @@ tem_bell(struct tem *tem, enum called_from called_from) { if (called_from == CALLED_FROM_STANDALONE) - beep_polled(BEEP_CONSOLE); + (void) beep_polled(BEEP_CONSOLE); else - beep(BEEP_CONSOLE); + (void) beep(BEEP_CONSOLE); } @@ -1205,7 +1205,7 @@ return; (*tems->in_fp.f_copy)(tem, s_col, s_row, - e_col, e_row, t_col, t_row, credp, called_from); + e_col, e_row, t_col, t_row, credp, called_from); } static void @@ -1516,7 +1516,7 @@ if (tems->display_mode == VIS_TEXT) { for (row = 0; row < tems->a_c_dimension.height; row++) { tem_clear_chars(tem, tems->a_c_dimension.width, - row, 0, credp, called_from); + row, 0, credp, called_from); } tems->a_c_cursor.row = 0; tems->a_c_cursor.col = 0; @@ -1550,7 +1550,7 @@ } tem_mv_cursor(tem, tems->a_c_cursor.row, - tabstop, credp, called_from); + tabstop, credp, called_from); } static void @@ -1587,9 +1587,9 @@ if (tems->a_ntabs == TEM_MAXTAB) return; if (tems->a_ntabs == 0 || - tems->a_tabs[tems->a_ntabs] < tems->a_c_cursor.col) { - tems->a_tabs[tems->a_ntabs++] = tems->a_c_cursor.col; - return; + tems->a_tabs[tems->a_ntabs] < tems->a_c_cursor.col) { + tems->a_tabs[tems->a_ntabs++] = tems->a_c_cursor.col; + return; } for (i = 0; i < tems->a_ntabs; i++) { if (tems->a_tabs[i] == tems->a_c_cursor.col) @@ -1758,33 +1758,33 @@ case TEM_SHIFT_LEFT: if (count < rest_of_line) { tem_copy_area(tem, - tems->a_c_cursor.col + count, - tems->a_c_cursor.row, - tems->a_c_dimension.width - 1, - tems->a_c_cursor.row, - tems->a_c_cursor.col, - tems->a_c_cursor.row, - credp, called_from); + tems->a_c_cursor.col + count, + tems->a_c_cursor.row, + tems->a_c_dimension.width - 1, + tems->a_c_cursor.row, + tems->a_c_cursor.col, + tems->a_c_cursor.row, + credp, called_from); } tem_clear_chars(tem, count, tems->a_c_cursor.row, - (tems->a_c_dimension.width - count), credp, - called_from); + (tems->a_c_dimension.width - count), credp, + called_from); break; case TEM_SHIFT_RIGHT: if (count < rest_of_line) { tem_copy_area(tem, - tems->a_c_cursor.col, - tems->a_c_cursor.row, - tems->a_c_dimension.width - count - 1, - tems->a_c_cursor.row, - tems->a_c_cursor.col + count, - tems->a_c_cursor.row, - credp, called_from); + tems->a_c_cursor.col, + tems->a_c_cursor.row, + tems->a_c_dimension.width - count - 1, + tems->a_c_cursor.row, + tems->a_c_cursor.col + count, + tems->a_c_cursor.row, + credp, called_from); } tem_clear_chars(tem, count, tems->a_c_cursor.row, - tems->a_c_cursor.col, credp, called_from); + tems->a_c_cursor.col, credp, called_from); break; } } @@ -1823,9 +1823,9 @@ MUTEX_HELD(&tem->lock)); ca.row = tems->a_c_cursor.row * tems->a_font.height + - tems->a_p_offset.y; + tems->a_p_offset.y; ca.col = tems->a_c_cursor.col * tems->a_font.width + - tems->a_p_offset.x; + tems->a_p_offset.x; ca.width = tems->a_font.width; ca.height = tems->a_font.height; if (tems->a_pdepth == 8 || tems->a_pdepth == 4) { @@ -1901,7 +1901,7 @@ f->width = font_selected->width; f->height = font_selected->height; bcopy((caddr_t)font_selected->encoding, (caddr_t)f->char_ptr, - sizeof (f->char_ptr)); + sizeof (f->char_ptr)); f->image_data = font_selected->image; } @@ -2067,8 +2067,8 @@ nbits = MIN(8, bitsleft); bitsleft -= nbits; for (i = 0; i < nbits; i++) { - *destp++ = ((data << i) & 0x80 ? - fg_color32 : bg_color32); + *destp++ = ((data << i) & 0x80 ? + fg_color32 : bg_color32); } } } @@ -2085,9 +2085,9 @@ ansi_fg_to_solaris(struct tem *tem, int ansi) { if (tem->state->a_flags & TEM_ATTR_BOLD) - return (fg_brt_xlate[ansi]); + return (fg_brt_xlate[ansi]); else - return (fg_dim_xlate[ansi]); + return (fg_dim_xlate[ansi]); } static void
--- a/usr/src/uts/common/io/usb/clients/usbkbm/usbkbm.c Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/common/io/usb/clients/usbkbm/usbkbm.c Tue Sep 25 13:11:35 2007 -0700 @@ -48,6 +48,7 @@ #include <sys/usb/clients/usbkbm/usbkbm.h> #include <sys/beep.h> #include <sys/policy.h> +#include <sys/inttypes.h> /* debugging information */ uint_t usbkbm_errmask = (uint_t)PRINT_MASK_ALL; @@ -164,7 +165,7 @@ usbkbm_keyindex = kbtrans_usbkb_maptab_init(); usbkbm_log_handle = usb_alloc_log_hdl(NULL, "usbkbm", - &usbkbm_errlevel, &usbkbm_errmask, NULL, 0); + &usbkbm_errlevel, &usbkbm_errmask, NULL, 0); sp = (usbkbm_save_state_t *)space_fetch("SUNW,usbkbm_state"); @@ -181,16 +182,16 @@ /* Restore abort information */ usbkbm_keyindex->k_abort1 = - sp->usbkbm_save_keyindex.k_abort1; + sp->usbkbm_save_keyindex.k_abort1; usbkbm_keyindex->k_abort2 = - sp->usbkbm_save_keyindex.k_abort2; + sp->usbkbm_save_keyindex.k_abort2; usbkbm_keyindex->k_newabort1 = - sp->usbkbm_save_keyindex.k_newabort1; + sp->usbkbm_save_keyindex.k_newabort1; usbkbm_keyindex->k_newabort2 = - sp->usbkbm_save_keyindex.k_newabort2; + sp->usbkbm_save_keyindex.k_newabort2; /* Restore keytables */ bcopy(sp->usbkbm_save_keyindex.k_normal, @@ -215,19 +216,19 @@ usbkbm_keyindex->k_up, USB_KEYTABLE_SIZE); kmem_free(sp->usbkbm_save_keyindex.k_normal, - USB_KEYTABLE_SIZE); + USB_KEYTABLE_SIZE); kmem_free(sp->usbkbm_save_keyindex.k_shifted, - USB_KEYTABLE_SIZE); + USB_KEYTABLE_SIZE); kmem_free(sp->usbkbm_save_keyindex.k_caps, - USB_KEYTABLE_SIZE); + USB_KEYTABLE_SIZE); kmem_free(sp->usbkbm_save_keyindex.k_altgraph, - USB_KEYTABLE_SIZE); + USB_KEYTABLE_SIZE); kmem_free(sp->usbkbm_save_keyindex.k_numlock, - USB_KEYTABLE_SIZE); + USB_KEYTABLE_SIZE); kmem_free(sp->usbkbm_save_keyindex.k_control, - USB_KEYTABLE_SIZE); + USB_KEYTABLE_SIZE); kmem_free(sp->usbkbm_save_keyindex.k_up, - USB_KEYTABLE_SIZE); + USB_KEYTABLE_SIZE); kmem_free(sp, sizeof (usbkbm_save_state_t)); space_free("SUNW,usbkbm_state"); @@ -284,19 +285,19 @@ /* Allocate space for keytables to be stored */ sp->usbkbm_save_keyindex.k_normal = - kmem_alloc(USB_KEYTABLE_SIZE, KM_SLEEP); + kmem_alloc(USB_KEYTABLE_SIZE, KM_SLEEP); sp->usbkbm_save_keyindex.k_shifted = - kmem_alloc(USB_KEYTABLE_SIZE, KM_SLEEP); + kmem_alloc(USB_KEYTABLE_SIZE, KM_SLEEP); sp->usbkbm_save_keyindex.k_caps = - kmem_alloc(USB_KEYTABLE_SIZE, KM_SLEEP); + kmem_alloc(USB_KEYTABLE_SIZE, KM_SLEEP); sp->usbkbm_save_keyindex.k_altgraph = - kmem_alloc(USB_KEYTABLE_SIZE, KM_SLEEP); + kmem_alloc(USB_KEYTABLE_SIZE, KM_SLEEP); sp->usbkbm_save_keyindex.k_numlock = - kmem_alloc(USB_KEYTABLE_SIZE, KM_SLEEP); + kmem_alloc(USB_KEYTABLE_SIZE, KM_SLEEP); sp->usbkbm_save_keyindex.k_control = - kmem_alloc(USB_KEYTABLE_SIZE, KM_SLEEP); + kmem_alloc(USB_KEYTABLE_SIZE, KM_SLEEP); sp->usbkbm_save_keyindex.k_up = - kmem_alloc(USB_KEYTABLE_SIZE, KM_SLEEP); + kmem_alloc(USB_KEYTABLE_SIZE, KM_SLEEP); /* Copy over the keytables */ bcopy(usbkbm_keyindex->k_normal, @@ -388,10 +389,10 @@ packet_size = 0; if (q->q_ptr) { - USB_DPRINTF_L3(PRINT_MASK_OPEN, usbkbm_log_handle, - "usbkbm_open already opened"); + USB_DPRINTF_L3(PRINT_MASK_OPEN, usbkbm_log_handle, + "usbkbm_open already opened"); - return (0); /* already opened */ + return (0); /* already opened */ } /* @@ -409,7 +410,7 @@ case CLONEOPEN: USB_DPRINTF_L3(PRINT_MASK_OPEN, usbkbm_log_handle, - "usbkbm_open: Clone open not supported"); + "usbkbm_open: Clone open not supported"); /* FALLTHRU */ default: @@ -422,7 +423,7 @@ usbkbmd = kmem_zalloc(sizeof (usbkbm_state_t), KM_SLEEP); USB_DPRINTF_L3(PRINT_MASK_OPEN, usbkbm_log_handle, - "usbkbm_state= %p", (void *)usbkbmd); + "usbkbm_state= %p", (void *)usbkbmd); /* * Set up private data. @@ -439,12 +440,12 @@ WR(q)->q_ptr = (caddr_t)usbkbmd; error = kbtrans_streams_init(q, sflag, crp, - (struct kbtrans_hardware *)usbkbmd, &kbd_usb_callbacks, - &usbkbmd->usbkbm_kbtrans, usbkbm_led_state, 0); + (struct kbtrans_hardware *)usbkbmd, &kbd_usb_callbacks, + &usbkbmd->usbkbm_kbtrans, usbkbm_led_state, 0); if (error != 0) { USB_DPRINTF_L3(PRINT_MASK_OPEN, usbkbm_log_handle, - "kbdopen: kbtrans_streams_init failed\n"); + "kbdopen: kbtrans_streams_init failed\n"); kmem_free(usbkbmd, sizeof (*usbkbmd)); return (error); @@ -455,40 +456,40 @@ * This information is set once, and doesn't change */ usbkbmd->usbkbm_polled_info.cons_polledio_version = - CONSPOLLEDIO_V1; + CONSPOLLEDIO_V1; usbkbmd->usbkbm_polled_info.cons_polledio_argument = - (cons_polledio_arg_t)usbkbmd; + (cons_polledio_arg_t)usbkbmd; usbkbmd->usbkbm_polled_info.cons_polledio_putchar = NULL; usbkbmd->usbkbm_polled_info.cons_polledio_getchar = - usbkbm_polled_getchar; + usbkbm_polled_getchar; usbkbmd->usbkbm_polled_info.cons_polledio_ischar = - usbkbm_polled_ischar; + usbkbm_polled_ischar; usbkbmd->usbkbm_polled_info.cons_polledio_enter = - usbkbm_polled_enter; + usbkbm_polled_enter; usbkbmd->usbkbm_polled_info.cons_polledio_exit = - usbkbm_polled_exit; + usbkbm_polled_exit; usbkbmd->usbkbm_polled_info.cons_polledio_setled = - (void (*)(cons_polledio_arg_t, int))usbkbm_polled_setled; + (void (*)(cons_polledio_arg_t, int))usbkbm_polled_setled; usbkbmd->usbkbm_polled_info.cons_polledio_keycheck = - (boolean_t (*)(cons_polledio_arg_t, int *, - enum keystate *))usbkbm_polled_keycheck; + (boolean_t (*)(cons_polledio_arg_t, int *, + enum keystate *))usbkbm_polled_keycheck; /* * The head and the tail pointing at the same byte means empty or * full. usbkbm_polled_buffer_num_characters is used to * tell the difference. */ usbkbmd->usbkbm_polled_buffer_head = - usbkbmd->usbkbm_polled_scancode_buffer; + usbkbmd->usbkbm_polled_scancode_buffer; usbkbmd->usbkbm_polled_buffer_tail = - usbkbmd->usbkbm_polled_scancode_buffer; + usbkbmd->usbkbm_polled_scancode_buffer; usbkbmd->usbkbm_polled_buffer_num_characters = 0; qprocson(q); @@ -534,8 +535,8 @@ if (usbkbmd->usbkbm_report_descr != NULL) { if (hidparser_get_country_code(usbkbmd->usbkbm_report_descr, - (uint16_t *)&usbkbmd->usbkbm_layout) == - HIDPARSER_FAILURE) { + (uint16_t *)&usbkbmd->usbkbm_layout) == + HIDPARSER_FAILURE) { USB_DPRINTF_L3(PRINT_MASK_OPEN, usbkbm_log_handle, "get_country_code failed" @@ -545,16 +546,16 @@ } if (hidparser_get_packet_size(usbkbmd->usbkbm_report_descr, - 0, HIDPARSER_ITEM_INPUT, (uint32_t *)&packet_size) == - HIDPARSER_FAILURE) { + 0, HIDPARSER_ITEM_INPUT, (uint32_t *)&packet_size) == + HIDPARSER_FAILURE) { USB_DPRINTF_L3(PRINT_MASK_OPEN, - usbkbm_log_handle, "get_packet_size failed" - "setting default packet size(8)"); + usbkbm_log_handle, "get_packet_size failed" + "setting default packet size(8)"); /* Setting to default packet size = 8 */ usbkbmd->usbkbm_packet_size = - USB_KBD_DEFAULT_PACKET_SIZE; + USB_KBD_DEFAULT_PACKET_SIZE; } else { usbkbmd->usbkbm_packet_size = packet_size/8; } @@ -565,7 +566,7 @@ usbkbmd->usbkbm_layout = usbkbm_layout; usbkbmd->usbkbm_packet_size = - USB_KBD_DEFAULT_PACKET_SIZE; + USB_KBD_DEFAULT_PACKET_SIZE; } /* @@ -585,22 +586,22 @@ } if ((usbkbmd->usbkbm_vid_pid.VendorId == - HID_SUN_JAPANESE_TYPE6_KBD_VID) && - (usbkbmd->usbkbm_vid_pid.ProductId == - HID_SUN_JAPANESE_TYPE6_KBD_PID)) { + HID_SUN_JAPANESE_TYPE6_KBD_VID) && + (usbkbmd->usbkbm_vid_pid.ProductId == + HID_SUN_JAPANESE_TYPE6_KBD_PID)) { usbkbmd->usbkbm_layout = SUN_JAPANESE_TYPE6; } } kbtrans_streams_set_keyboard(usbkbmd->usbkbm_kbtrans, KB_USB, - usbkbm_keyindex); + usbkbm_keyindex); usbkbmd->usbkbm_flags = USBKBM_OPEN; kbtrans_streams_enable(usbkbmd->usbkbm_kbtrans); USB_DPRINTF_L3(PRINT_MASK_OPEN, usbkbm_log_handle, - "usbkbm_open exiting"); + "usbkbm_open exiting"); return (0); } @@ -616,7 +617,7 @@ usbkbm_state_t *usbkbmd = (usbkbm_state_t *)q->q_ptr; /* If a beep is in progress, stop that */ - beeper_off(); + (void) beeper_off(); (void) kbtrans_streams_fini(usbkbmd->usbkbm_kbtrans); @@ -631,7 +632,7 @@ kmem_free(usbkbmd, sizeof (usbkbm_state_t)); USB_DPRINTF_L3(PRINT_MASK_CLOSE, usbkbm_log_handle, - "usbkbm_close exiting"); + "usbkbm_close exiting"); return (0); } @@ -649,7 +650,7 @@ enum kbtrans_message_response ret; USB_DPRINTF_L3(PRINT_MASK_ALL, usbkbm_log_handle, - "usbkbm_wput entering"); + "usbkbm_wput entering"); usbkbmd = (usbkbm_state_t *)q->q_ptr; @@ -659,7 +660,7 @@ if (ret == KBTRANS_MESSAGE_HANDLED) { USB_DPRINTF_L3(PRINT_MASK_ALL, usbkbm_log_handle, - "usbkbm_wput exiting:2"); + "usbkbm_wput exiting:2"); return; } @@ -685,7 +686,7 @@ if (ret == KBTRANS_MESSAGE_HANDLED) { USB_DPRINTF_L3(PRINT_MASK_ALL, usbkbm_log_handle, - "usbkbm_wput exiting:1"); + "usbkbm_wput exiting:1"); return; } @@ -700,7 +701,7 @@ putnext(q, mp); USB_DPRINTF_L3(PRINT_MASK_ALL, usbkbm_log_handle, - "usbkbm_wput exiting:3"); + "usbkbm_wput exiting:3"); } /* @@ -718,6 +719,9 @@ size_t ioctlrespsize; int err; int tmp; + int cycles; + int frequency; + int msecs; char command; err = 0; @@ -799,7 +803,7 @@ */ if (usbkbmd->usbkbm_setled_second_byte) { usbkbm_streams_setled((struct kbtrans_hardware *) - usbkbmd, command); + usbkbmd, command); usbkbmd->usbkbm_setled_second_byte = 0; break; } @@ -823,7 +827,7 @@ case CONSOPENPOLLEDIO: USB_DPRINTF_L3(PRINT_MASK_ALL, usbkbm_log_handle, - "usbkbm_ioctl CONSOPENPOLLEDIO"); + "usbkbm_ioctl CONSOPENPOLLEDIO"); err = miocpullup(mp, sizeof (struct cons_polledio *)); if (err != 0) { @@ -857,7 +861,7 @@ case CONSCLOSEPOLLEDIO: USB_DPRINTF_L3(PRINT_MASK_ALL, usbkbm_log_handle, - "usbkbm_ioctl CONSCLOSEPOLLEDIO mp = 0x%p", (void *)mp); + "usbkbm_ioctl CONSCLOSEPOLLEDIO mp = 0x%p", (void *)mp); usbkbmd->usbkbm_pending_link = mp; @@ -889,6 +893,29 @@ break; + case KIOCMKTONE: + if (iocp->ioc_count != TRANSPARENT) { + err = EINVAL; + break; + } + + tmp = (int)(*(intptr_t *)mp->b_cont->b_rptr); + cycles = tmp & 0xffff; + msecs = (tmp >> 16) & 0xffff; + + if (cycles == 0) + frequency = UINT16_MAX; + else if (cycles == UINT16_MAX) + frequency = 0; + else { + frequency = (PIT_HZ + cycles / 2) / cycles; + if (frequency > UINT16_MAX) + frequency = UINT16_MAX; + } + + err = beep_mktone(frequency, msecs); + break; + default: return (KBTRANS_MESSAGE_NOT_HANDLED); @@ -927,11 +954,11 @@ if (usbkbmd->usbkbm_streams_bufcallid) { qunbufcall(usbkbmd->usbkbm_readq, - usbkbmd->usbkbm_streams_bufcallid); + usbkbmd->usbkbm_streams_bufcallid); } usbkbmd->usbkbm_streams_bufcallid = - qbufcall(usbkbmd->usbkbm_readq, ioctlrespsize, BPRI_HI, - usbkbm_reioctl, usbkbmd); + qbufcall(usbkbmd->usbkbm_readq, ioctlrespsize, BPRI_HI, + usbkbm_reioctl, usbkbmd); return (KBTRANS_MESSAGE_HANDLED); } @@ -991,7 +1018,7 @@ * in it, the generic beeper interface * is used. Turn the beeper on. */ - beeper_on(BEEP_TYPE4); + (void) beeper_on(BEEP_TYPE4); break; case KBD_CMD_NOBELL: @@ -1000,7 +1027,7 @@ * in it, the generic beeper interface * is used. Turn the beeper off. */ - beeper_off(); + (void) beeper_off(); break; case KBD_CMD_CLICK: @@ -1030,7 +1057,7 @@ usbkbmd = (usbkbm_state_t *)q->q_ptr; USB_DPRINTF_L3(PRINT_MASK_ALL, usbkbm_log_handle, - "usbkbm_rput"); + "usbkbm_rput"); if (usbkbmd == 0) { freemsg(mp); /* nobody's listening */ @@ -1126,7 +1153,7 @@ case HID_SET_REPORT: USB_DPRINTF_L3(PRINT_MASK_ALL, usbkbm_log_handle, - "usbkbm_mctl_receive HID_SET mctl"); + "usbkbm_mctl_receive HID_SET mctl"); freemsg(mp); /* Setting of the LED is not waiting for this message */ @@ -1163,7 +1190,7 @@ break; case HID_OPEN_POLLED_INPUT: USB_DPRINTF_L3(PRINT_MASK_ALL, usbkbm_log_handle, - "usbkbm_mctl_receive HID_OPEN_POLLED_INPUT"); + "usbkbm_mctl_receive HID_OPEN_POLLED_INPUT"); size = sizeof (hid_polled_input_callback_t); reply_mp = usbkbmd->usbkbm_pending_link; @@ -1183,7 +1210,7 @@ * The structure is saved in the states structure */ *(cons_polledio_t **)reply_mp->b_cont->b_rptr = - &usbkbmd->usbkbm_polled_info; + &usbkbmd->usbkbm_polled_info; } else { reply_mp->b_datap->db_type = M_IOCNAK; @@ -1197,11 +1224,11 @@ break; case HID_CLOSE_POLLED_INPUT: USB_DPRINTF_L3(PRINT_MASK_ALL, usbkbm_log_handle, - "usbkbm_mctl_receive HID_CLOSE_POLLED_INPUT"); + "usbkbm_mctl_receive HID_CLOSE_POLLED_INPUT"); bzero(&usbkbmd->usbkbm_hid_callback, - sizeof (hid_polled_input_callback_t)); + sizeof (hid_polled_input_callback_t)); freemsg(mp); @@ -1210,8 +1237,8 @@ iocp = (struct iocblk *)reply_mp->b_rptr; USB_DPRINTF_L3(PRINT_MASK_ALL, usbkbm_log_handle, - "usbkbm_mctl_receive reply reply_mp 0x%p cmd 0x%x", - (void *)reply_mp, iocp->ioc_cmd); + "usbkbm_mctl_receive reply reply_mp 0x%p cmd 0x%x", + (void *)reply_mp, iocp->ioc_cmd); reply_mp->b_datap->db_type = M_IOCACK; @@ -1252,11 +1279,11 @@ /* FALLTHRU */ case HID_FULL_POWER : USB_DPRINTF_L3(PRINT_MASK_ALL, usbkbm_log_handle, - "usbkbm_mctl_receive restore LEDs"); + "usbkbm_mctl_receive restore LEDs"); /* send setled command down to restore LED states */ usbkbm_streams_setled((struct kbtrans_hardware *)usbkbmd, - usbkbm_led_state); + usbkbm_led_state); freemsg(mp); @@ -1373,10 +1400,10 @@ } hid_polled_handle = - usbkbmd->usbkbm_hid_callback.hid_polled_input_handle; + usbkbmd->usbkbm_hid_callback.hid_polled_input_handle; num_keys = (usbkbmd->usbkbm_hid_callback.hid_polled_read) - (hid_polled_handle, &buffer); + (hid_polled_handle, &buffer); /* * If we don't get any characters back then indicate that, and we @@ -1393,7 +1420,7 @@ * individual key/state values. */ usbkbm_unpack_usb_packet(usbkbmd, usbkbm_poll_callback, - buffer, num_keys); + buffer, num_keys); /* * If a scancode was returned as a result of this packet, @@ -1478,7 +1505,7 @@ * Check to make sure that the buffer isn't already full */ if (usbkbmd->usbkbm_polled_buffer_num_characters == - USB_POLLED_BUFFER_SIZE) { + USB_POLLED_BUFFER_SIZE) { /* * The buffer is full, we will drop this character. @@ -1506,11 +1533,11 @@ * Check to see if the tail has wrapped. */ if (usbkbmd->usbkbm_polled_buffer_head - - usbkbmd->usbkbm_polled_scancode_buffer == - USB_POLLED_BUFFER_SIZE) { + usbkbmd->usbkbm_polled_scancode_buffer == + USB_POLLED_BUFFER_SIZE) { usbkbmd->usbkbm_polled_buffer_head = - usbkbmd->usbkbm_polled_scancode_buffer; + usbkbmd->usbkbm_polled_scancode_buffer; } } @@ -1539,11 +1566,11 @@ * Check to see if the tail has wrapped. */ if (usbkbmd->usbkbm_polled_buffer_tail - - usbkbmd->usbkbm_polled_scancode_buffer == - USB_POLLED_BUFFER_SIZE) { + usbkbmd->usbkbm_polled_scancode_buffer == + USB_POLLED_BUFFER_SIZE) { usbkbmd->usbkbm_polled_buffer_tail = - usbkbmd->usbkbm_polled_scancode_buffer; + usbkbmd->usbkbm_polled_scancode_buffer; } /* @@ -1613,16 +1640,16 @@ */ for (uindex = 2; uindex < USBKBM_MAXPKTSIZE; uindex ++) { usbkbmd->usbkbm_lastusbpacket[uindex] = - usbkbmd->usbkbm_pendingusbpacket[uindex]; + usbkbmd->usbkbm_pendingusbpacket[uindex]; usbkbmd->usbkbm_pendingusbpacket[uindex] = 0; } hid_polled_handle = - usbkbmd->usbkbm_hid_callback.hid_polled_input_handle; + usbkbmd->usbkbm_hid_callback.hid_polled_input_handle; (void) (usbkbmd->usbkbm_hid_callback.hid_polled_input_enter) - (hid_polled_handle); + (hid_polled_handle); } /* @@ -1648,16 +1675,16 @@ */ for (uindex = 2; uindex < USBKBM_MAXPKTSIZE; uindex ++) { usbkbmd->usbkbm_pendingusbpacket[uindex] = - usbkbmd->usbkbm_lastusbpacket[uindex]; + usbkbmd->usbkbm_lastusbpacket[uindex]; usbkbmd->usbkbm_lastusbpacket[uindex] = 0; } hid_polled_handle = - usbkbmd->usbkbm_hid_callback.hid_polled_input_handle; + usbkbmd->usbkbm_hid_callback.hid_polled_input_handle; (void) (usbkbmd->usbkbm_hid_callback.hid_polled_input_exit) - (hid_polled_handle); + (hid_polled_handle); } /* @@ -1687,57 +1714,57 @@ for (uindex = 0; uindex < packet_size; uindex++) { USB_DPRINTF_L3(PRINT_MASK_PACKET, usbkbm_log_handle, - " %x ", usbpacket[uindex]); + " %x ", usbpacket[uindex]); } USB_DPRINTF_L3(PRINT_MASK_PACKET, usbkbm_log_handle, - " is the usbkeypacket"); + " is the usbkeypacket"); /* check to see if modifier keys are different */ if (mkb != lastmkb) { if ((mkb & USB_LSHIFTBIT) != (lastmkb & USB_LSHIFTBIT)) { (*func)(usbkbmd, USB_LSHIFTKEY, (mkb&USB_LSHIFTBIT) ? - KEY_PRESSED : KEY_RELEASED); + KEY_PRESSED : KEY_RELEASED); USB_DPRINTF_L3(PRINT_MASK_ALL, usbkbm_log_handle, - "unpack: sending USB_LSHIFTKEY"); + "unpack: sending USB_LSHIFTKEY"); } if ((mkb & USB_LCTLBIT) != (lastmkb & USB_LCTLBIT)) { (*func)(usbkbmd, USB_LCTLCKEY, mkb&USB_LCTLBIT ? - KEY_PRESSED : KEY_RELEASED); + KEY_PRESSED : KEY_RELEASED); } if ((mkb & USB_LALTBIT) != (lastmkb & USB_LALTBIT)) { (*func)(usbkbmd, USB_LALTKEY, mkb&USB_LALTBIT ? - KEY_PRESSED : KEY_RELEASED); + KEY_PRESSED : KEY_RELEASED); } if ((mkb & USB_LMETABIT) != (lastmkb & USB_LMETABIT)) { (*func)(usbkbmd, USB_LMETAKEY, mkb&USB_LMETABIT ? - KEY_PRESSED : KEY_RELEASED); + KEY_PRESSED : KEY_RELEASED); } if ((mkb & USB_RMETABIT) != (lastmkb & USB_RMETABIT)) { (*func)(usbkbmd, USB_RMETAKEY, mkb&USB_RMETABIT ? - KEY_PRESSED : KEY_RELEASED); + KEY_PRESSED : KEY_RELEASED); } if ((mkb & USB_RALTBIT) != (lastmkb & USB_RALTBIT)) { (*func)(usbkbmd, USB_RALTKEY, mkb&USB_RALTBIT ? - KEY_PRESSED : KEY_RELEASED); + KEY_PRESSED : KEY_RELEASED); } if ((mkb & USB_RCTLBIT) != (lastmkb & USB_RCTLBIT)) { (*func)(usbkbmd, USB_RCTLCKEY, mkb&USB_RCTLBIT ? - KEY_PRESSED : KEY_RELEASED); + KEY_PRESSED : KEY_RELEASED); } if ((mkb & USB_RSHIFTBIT) != (lastmkb & USB_RSHIFTBIT)) { (*func)(usbkbmd, USB_RSHIFTKEY, mkb&USB_RSHIFTBIT ? - KEY_PRESSED : KEY_RELEASED); + KEY_PRESSED : KEY_RELEASED); USB_DPRINTF_L3(PRINT_MASK_ALL, usbkbm_log_handle, - "unpack: sending USB_RSHIFTKEY"); + "unpack: sending USB_RSHIFTKEY"); } } @@ -1748,7 +1775,7 @@ if (usbpacket[2] == USB_ERRORROLLOVER) { rollover = 1; for (uindex = 3; uindex < packet_size; - uindex++) { + uindex++) { if (usbpacket[uindex] != USB_ERRORROLLOVER) { rollover = 0; break; @@ -1756,7 +1783,7 @@ } if (rollover) { USB_DPRINTF_L3(PRINT_MASK_ALL, usbkbm_log_handle, - "unpack: errorrollover"); + "unpack: errorrollover"); return; } } @@ -1804,7 +1831,7 @@ if (!usbkbm_is_modkey(usbpacket[uindex])) { (*func)(usbkbmd, usbpacket[uindex], - KEY_PRESSED); + KEY_PRESSED); } else { usbkbmd->usbkbm_pendingusbpacket[uindex] = 0; @@ -1820,7 +1847,7 @@ */ for (uindex = 2; uindex < USBKBM_MAXPKTSIZE; uindex++) { lastusbpacket[uindex] = - usbkbmd->usbkbm_pendingusbpacket[uindex]; + usbkbmd->usbkbm_pendingusbpacket[uindex]; usbkbmd->usbkbm_pendingusbpacket[uindex] = 0; } }
--- a/usr/src/uts/common/sys/beep.h Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/common/sys/beep.h Tue Sep 25 13:11:35 2007 -0700 @@ -28,6 +28,8 @@ #pragma ident "%Z%%M% %I% %E% SMI" +#include <sys/mutex.h> + /* * Interface to the system beeper. * @@ -39,13 +41,94 @@ #endif #if defined(_KERNEL) + +/* beep_entry structure */ + +typedef struct beep_entry { + unsigned short frequency; + unsigned short duration; +} beep_entry_t; + +typedef void (*beep_on_func_t)(void *arg); + +typedef void (*beep_off_func_t)(void *arg); + +typedef void (*beep_freq_func_t)(void *arg, int freq); + +/* beep_state structure */ + +typedef struct beep_state { + + /* Private data for beep_freq, beep_on, and beep_off functions */ + void *arg; + + /* Indicates if a beep command is already in progress */ + enum {BEEP_UNINIT = 0, BEEP_OFF = 1, + BEEP_TIMED = 2, BEEP_ON = 3} mode; + + /* Address of the hw-dependent beep_freq function */ + beep_freq_func_t beep_freq; + + /* Address of the hw-dependent beep_on function */ + beep_on_func_t beep_on; + + /* Address of the hw-dependent beep_off function */ + beep_off_func_t beep_off; + + /* Timeout id for the beep_timeout() function */ + timeout_id_t timeout_id; + + /* Mutex protecting mode, timeout_id, queue_head, queue_tail, */ + /* and queue */ + kmutex_t mutex; + + /* Index of head of queue */ + int queue_head; + + /* Index of tail of queue */ + int queue_tail; + + /* Max queue size */ + int queue_size; + + /* Circular ring buffer */ + beep_entry_t *queue; +} beep_state_t; + +#define BEEP_QUEUE_SIZE 1000 + +/* BEEP_DEFAULT is a sentinel for the beep_param table. */ enum beep_type { BEEP_DEFAULT = 0, BEEP_CONSOLE = 1, BEEP_TYPE4 = 2 }; -void beep(enum beep_type); -void beep_polled(enum beep_type); -void beeper_on(enum beep_type); -void beeper_off(void); -int beeper_freq(enum beep_type, int); +typedef struct beep_params { + enum beep_type type; + int frequency; /* Hz */ + int duration; /* milliseconds */ +} beep_params_t; + + +extern int beep_init(void *arg, + beep_on_func_t beep_on_func, + beep_off_func_t beep_off_func, + beep_freq_func_t beep_freq_func); + +extern int beep_fini(void); + +extern int beeper_off(void); + +extern int beeper_freq(enum beep_type type, int freq); + +extern int beep(enum beep_type type); + +extern int beep_polled(enum beep_type type); + +extern int beeper_on(enum beep_type type); + +extern int beep_mktone(int frequency, int duration); + +extern void beep_timeout(void *arg); + +extern int beep_busy(void); #endif /* _KERNEL */
--- a/usr/src/uts/common/sys/kbio.h Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/common/sys/kbio.h Tue Sep 25 13:11:35 2007 -0700 @@ -224,6 +224,17 @@ int16_t freq; /* Frequency */ }; +#define KIOCMKTONE (KIOC|27) + +/* + * For historical reasons, the frequency argument to KIOCMKTONE is + * in i8254 clock cycles. + */ + +#define PIT_HZ 1193182 /* 8254's cycles per second */ + +#define KDMKTONE KIOCMKTONE + /* Used to control the AutoRepeat Min-delay and Min-Rate */ #define KIOCRPTDELAY_MIN (100) #define KIOCRPTRATE_MIN (1)
--- a/usr/src/uts/common/sys/pit.h Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/common/sys/pit.h Tue Sep 25 13:11:35 2007 -0700 @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -24,7 +23,7 @@ /* All Rights Reserved */ /* - * Copyright 2003 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -74,6 +73,7 @@ /* byte followed by most significant */ #define PIT_RATEMODE 0x06 /* square-wave mode for USART */ +#define PIT_C2 0x80 /* select counter 2 */ #define SANITY_NUM 0xFFFF /* Sanity timer fires every .2 secs */ /* bits used in auxiliary control port for timer 2 */
--- a/usr/src/uts/i86pc/Makefile.files Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/i86pc/Makefile.files Tue Sep 25 13:11:35 2007 -0700 @@ -34,7 +34,6 @@ # object lists # CORE_OBJS += \ - beeper.o \ biosdisk.o \ bios_call.o \ cbe.o \
--- a/usr/src/uts/i86pc/os/startup.c Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/i86pc/os/startup.c Tue Sep 25 13:11:35 2007 -0700 @@ -2051,6 +2051,8 @@ */ (void) modload("fs", "procfs"); + (void) i_ddi_attach_hw_nodes("pit_beep"); + #if defined(__i386) /* * Check for required functional Floating Point hardware,
--- a/usr/src/uts/i86xpv/Makefile.files Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/i86xpv/Makefile.files Tue Sep 25 13:11:35 2007 -0700 @@ -35,7 +35,6 @@ # CORE_OBJS += \ balloon.o \ - beeper.o \ biosdisk.o \ cbe.o \ cmi.o \
--- a/usr/src/uts/intel/Makefile.files Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/intel/Makefile.files Tue Sep 25 13:11:35 2007 -0700 @@ -146,6 +146,7 @@ PCI_PCINEXUS_OBJS += pci_pci.o PCIEHPCNEXUS_OBJS += pciehpc_x86.o pciehpc_acpi.o PCN_OBJS += mii.o +PIT_BEEP_OBJS += pit_beep.o POWER_OBJS += power.o PCI_AUTOCONFIG_OBJS += pci_autoconfig.o pci_boot.o pcie_nvidia.o \ pci_memlist.o pci_resource.o
--- a/usr/src/uts/intel/Makefile.intel.shared Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/intel/Makefile.intel.shared Tue Sep 25 13:11:35 2007 -0700 @@ -275,6 +275,7 @@ DRV_KMODS += physmem DRV_KMODS += pcan DRV_KMODS += pcwl +DRV_KMODS += pit_beep DRV_KMODS += pm DRV_KMODS += poll DRV_KMODS += pool
--- a/usr/src/uts/intel/io/beeper.c Tue Sep 25 11:12:45 2007 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,200 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * Simple beeper support for PC platform, using standard timer 2 beeper. - * Eventually this should probably be in a driver. - */ - -#include <sys/types.h> -#include <sys/conf.h> -#include <sys/beep.h> -#include <sys/ksynch.h> -#include <sys/ddi.h> -#include <sys/sunddi.h> -#include <sys/errno.h> -#include <sys/inttypes.h> - -#define NELEM(a) (sizeof (a) / sizeof ((a)[0])) - -#define TIMER 0x40 -#define TIMERCR (TIMER+3) -#define TIMER2 (TIMER+2) - -#define TONE_CTL 0x61 -#define T_CTLWORD 0xB6 -#define TONE_ON 0x03 - -static struct beep_state { - enum {BEEP_OFF, BEEP_TIMED, BEEP_ON} state; - kmutex_t mutex; -} beep_state; - -static void beep_end(void *); -static void beep_on(void); -static void beep_off(void); -static void beep_frequency(int frequency); - -struct beep_params { - enum beep_type type; - int frequency; /* Hz */ - int duration; /* milliseconds */ -}; - -struct beep_params beep_params[] = { - { BEEP_CONSOLE, 900, 200 }, - { BEEP_TYPE4, 2000, 0 }, - { BEEP_DEFAULT, 1000, 200 } /* Must be last */ -}; - -/* ARGSUSED */ -void -beep(enum beep_type type) -{ - struct beep_params *bp; - - /* - * In the fullness of time, we would use the "type" argument - * to determine frequency, volume, duration, waveform, sample - * to be played, ... - */ - - for (bp = beep_params; bp->type != BEEP_DEFAULT; bp++) { - if (bp->type == type) - break; - } - - mutex_enter(&beep_state.mutex); - if (beep_state.state == BEEP_OFF && bp->frequency != 0) { - beep_state.state = BEEP_TIMED; - beep_frequency(bp->frequency); - beep_on(); - (void) timeout(beep_end, &beep_state, - drv_usectohz(bp->duration*1000)); - } - mutex_exit(&beep_state.mutex); -} - -/* ARGSUSED */ -void -beep_polled(enum beep_type type) -{ - /* No-op at this time */ -} - -static void -beep_end(void *arg) -{ - struct beep_state *state = arg; - - /* Perhaps we should enforce a small "quiet" period between beeps. */ - mutex_enter(&state->mutex); - state->state = BEEP_OFF; - beep_off(); - mutex_exit(&state->mutex); -} - -static void -beep_frequency(int frequency) -{ - int counter; - - counter = 1193180 / frequency; - if (counter > 65535) - counter = 65535; - else if (counter < 1) - counter = 1; - - outb(TIMERCR, T_CTLWORD); - outb(TIMER2, counter & 0xff); - outb(TIMER2, counter >> 8); -} - -static void -beep_on(void) -{ - outb(TONE_CTL, inb(TONE_CTL) | TONE_ON); -} - -static void -beep_off(void) -{ - outb(TONE_CTL, inb(TONE_CTL) & ~TONE_ON); -} - -void -beeper_on(enum beep_type type) -{ - struct beep_params *bp; - - for (bp = beep_params; bp->type != BEEP_DEFAULT; bp++) { - if (bp->type == type) - break; - } - - mutex_enter(&beep_state.mutex); - if (beep_state.state == BEEP_OFF) { - beep_state.state = BEEP_ON; - if (bp->frequency != 0) { - beep_frequency(bp->frequency); - beep_on(); - } - } - mutex_exit(&beep_state.mutex); -} - -void -beeper_off() -{ - mutex_enter(&beep_state.mutex); - if (beep_state.state == BEEP_ON) { - beep_state.state = BEEP_OFF; - beep_off(); - } - mutex_exit(&beep_state.mutex); -} - -int -beeper_freq(enum beep_type type, int freq) -{ - struct beep_params *bp; - - /* - * The frequency value is limited to the range of [0 - 32767] - */ - if ((type != BEEP_CONSOLE && type != BEEP_TYPE4) || freq < 0 || - freq > INT16_MAX) - return (EINVAL); - - for (bp = beep_params; bp->type != BEEP_DEFAULT; bp++) { - if (bp->type == type) - break; - } - - bp->frequency = freq; - return (0); -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usr/src/uts/intel/io/pit_beep.c Tue Sep 25 13:11:35 2007 -0700 @@ -0,0 +1,288 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Simple beeper support for PC platform, using standard timer 2 beeper. + */ + +#include <sys/types.h> +#include <sys/conf.h> +#include <sys/beep.h> +#include <sys/ksynch.h> +#include <sys/ddi.h> +#include <sys/sunddi.h> +#include <sys/modctl.h> +#include <sys/pit.h> +#include <sys/inttypes.h> + +#define PIT_BEEP_UNIT(dev) (getminor((dev))) + +typedef struct pit_beep_state { + /* Dip of pit_beep device */ + dev_info_t *dip; + +} pit_beep_state_t; + +#define PIT_BEEP_ON 1 +#define PIT_BEEP_OFF 0 + +/* Pointer to the state structure */ +static void *pit_beep_statep; + +static int pit_beep_attach(dev_info_t *dip, ddi_attach_cmd_t cmd); +static int pit_beep_detach(dev_info_t *dip, ddi_detach_cmd_t cmd); +static int pit_beep_info(dev_info_t *dip, ddi_info_cmd_t infocmd, + void *arg, void **result); +static void pit_beep_freq(void *arg, int freq); +static void pit_beep_on(void *arg); +static void pit_beep_off(void *arg); + +struct cb_ops pit_beep_cb_ops = { + nulldev, /* open */ + nulldev, /* close */ + nulldev, /* strategy */ + nulldev, /* print */ + nulldev, /* dump */ + nulldev, /* read */ + nulldev, /* write */ + nulldev, /* ioctl */ + nulldev, /* devmap */ + nulldev, /* mmap */ + nulldev, /* segmap */ + nochpoll, /* poll */ + ddi_prop_op, /* cb_prop_op */ + NULL, /* streamtab */ + D_MP | D_NEW +}; + + +static struct dev_ops pit_beep_ops = { + DEVO_REV, /* Devo_rev */ + 0, /* Refcnt */ + pit_beep_info, /* Info */ + nulldev, /* Identify */ + nulldev, /* Probe */ + pit_beep_attach, /* Attach */ + pit_beep_detach, /* Detach */ + nodev, /* Reset */ + &pit_beep_cb_ops, /* Driver operations */ + 0, /* Bus operations */ + NULL /* Power */ +}; + + +static struct modldrv modldrv = { + &mod_driverops, /* This one is a driver */ + "Intel Pit_beep Driver %I%", /* Name of the module. */ + &pit_beep_ops, /* Driver ops */ +}; + + +static struct modlinkage modlinkage = { + MODREV_1, (void *)&modldrv, NULL +}; + + + +int +_init(void) +{ + int error; + + /* Initialize the soft state structures */ + if ((error = ddi_soft_state_init(&pit_beep_statep, + sizeof (pit_beep_state_t), 1)) != 0) { + + return (error); + } + + /* Install the loadable module */ + if ((error = mod_install(&modlinkage)) != 0) { + ddi_soft_state_fini(&pit_beep_statep); + } + + return (error); +} + + +int +_info(struct modinfo *modinfop) +{ + return (mod_info(&modlinkage, modinfop)); +} + +int +_fini(void) +{ + int error; + + error = mod_remove(&modlinkage); + + if (error == 0) { + /* Release per module resources */ + ddi_soft_state_fini(&pit_beep_statep); + } + + return (error); +} + +/* + * pit_beep_attach: + */ +static int +pit_beep_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) +{ + switch (cmd) { + case DDI_ATTACH: + break; + case DDI_RESUME: + + return (DDI_SUCCESS); + default: + + return (DDI_FAILURE); + } + + pit_beep_off(dip); + + (void) beep_init((void *)dip, pit_beep_on, pit_beep_off, + pit_beep_freq); + + /* Display information in the banner */ + ddi_report_dev(dip); + + return (DDI_SUCCESS); +} + + +/* + * pit_beep_detach: + */ +/* ARGSUSED */ +static int +pit_beep_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) +{ + switch (cmd) { + case DDI_SUSPEND: + + /* + * If a beep is in progress; fail suspend + */ + if (!beep_busy()) { + + return (DDI_SUCCESS); + } else { + + return (DDI_FAILURE); + } + default: + + return (DDI_FAILURE); + } +} + + +/* + * pit_beep_info: + */ +/* ARGSUSED */ +static int +pit_beep_info(dev_info_t *dip, ddi_info_cmd_t infocmd, + void *arg, void **result) +{ + dev_t dev; + pit_beep_state_t *statep; + int instance, error; + + switch (infocmd) { + case DDI_INFO_DEVT2DEVINFO: + dev = (dev_t)arg; + instance = PIT_BEEP_UNIT(dev); + + if ((statep = ddi_get_soft_state(pit_beep_statep, + instance)) == NULL) { + + return (DDI_FAILURE); + } + + *result = (void *)statep->dip; + + error = DDI_SUCCESS; + break; + case DDI_INFO_DEVT2INSTANCE: + dev = (dev_t)arg; + instance = PIT_BEEP_UNIT(dev); + + *result = (void *)(uintptr_t)instance; + + error = DDI_SUCCESS; + break; + default: + error = DDI_FAILURE; + + } + + return (error); +} + + +/* ARGSUSED */ +static void +pit_beep_freq(void *arg, int freq) +{ + int counter; + + if (freq == 0) + counter = 0; + else { + counter = PIT_HZ / freq; + if (counter > UINT16_MAX) + counter = UINT16_MAX; + else if (counter < 1) + counter = 1; + } + + outb(PITCTL_PORT, PIT_C2 | PIT_READMODE | PIT_RATEMODE); + outb(PITCTR2_PORT, counter & 0xff); + outb(PITCTR2_PORT, counter >> 8); +} + + +/* ARGSUSED */ +static void +pit_beep_on(void *arg) +{ + outb(PITAUX_PORT, inb(PITAUX_PORT) | (PITAUX_OUT2 | PITAUX_GATE2)); +} + + +/* ARGSUSED */ +static void +pit_beep_off(void *arg) +{ + outb(PITAUX_PORT, inb(PITAUX_PORT) & ~(PITAUX_OUT2 | PITAUX_GATE2)); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usr/src/uts/intel/io/pit_beep.conf Tue Sep 25 13:11:35 2007 -0700 @@ -0,0 +1,29 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "%Z%%M% %I% %E% SMI" +# +# Configuration file for pit_beep driver + +name="pit_beep" parent="isa" instance=0;
--- a/usr/src/uts/intel/os/driver_aliases Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/intel/os/driver_aliases Tue Sep 25 13:11:35 2007 -0700 @@ -33,3 +33,4 @@ xnbe "xnb,ioemu" xnbo "xnb,SUNW_mac" xnbu "xnb,netfront" +pit_beep "SUNW,pit_beep"
--- a/usr/src/uts/intel/os/name_to_major Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/intel/os/name_to_major Tue Sep 25 13:11:35 2007 -0700 @@ -140,3 +140,4 @@ xnbo 250 xnbu 251 vnic 252 +pit_beep 253
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usr/src/uts/intel/pit_beep/Makefile Tue Sep 25 13:11:35 2007 -0700 @@ -0,0 +1,86 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "%Z%%M% %I% %E% SMI" +# +# uts/intel/pit_beep/Makefile +# +# This makefile drives the production of the pit_beep driver. +# +# Path to the base of the uts directory tree (usually /usr/src/uts). + +UTSBASE = ../.. + +# +# Define the module and object file sets. +# +MODULE = pit_beep +OBJECTS = $(PIT_BEEP_OBJS:%=$(OBJS_DIR)/%) +LINTS = $(PIT_BEEP_OBJS:%.o=$(LINTS_DIR)/%.ln) +ROOTMODULE = $(ROOT_PSM_DRV_DIR)/$(MODULE) +CONF_SRCDIR = $(UTSBASE)/intel/io + +# +# Include common rules. +# +include $(UTSBASE)/intel/Makefile.intel + +# +# lint pass one enforcement +# +CFLAGS += $(CCVERBOSE) + +# +# Define targets +# +ALL_TARGET = $(BINARY) $(CONFMOD) +LINT_TARGET = $(MODULE).lint +INSTALL_TARGET = $(BINARY) $(ROOTMODULE) $(ROOT_CONFFILE) + +.KEEP_STATE: + +all: $(ALL_DEPS) + +def: $(DEF_DEPS) + +clean: $(CLEAN_DEPS) + +clobber: $(CLOBBER_DEPS) + +lint: $(LINT_DEPS) + +modlintlib: $(MODLINTLIB_DEPS) + +clean.lint: $(CLEAN_LINT_DEPS) + +install: $(INSTALL_DEPS) + +# +# Include common targets +# +include $(UTSBASE)/intel/Makefile.targ + + +
--- a/usr/src/uts/sun4/Makefile.files Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/sun4/Makefile.files Tue Sep 25 13:11:35 2007 -0700 @@ -20,7 +20,7 @@ # # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -34,7 +34,6 @@ # object lists # CORE_OBJS += bcmp.o -CORE_OBJS += beep.o CORE_OBJS += bus_func.o CORE_OBJS += cbe.o CORE_OBJS += confunix.o
--- a/usr/src/uts/sun4/os/beep.c Tue Sep 25 11:12:45 2007 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,347 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * This is the Beep module for supporting keyboard beep for keyboards - * that do not have the beeping feature within themselves - * - */ - -#include <sys/types.h> -#include <sys/conf.h> - -#include <sys/ddi.h> -#include <sys/sunddi.h> -#include <sys/modctl.h> -#include <sys/ddi_impldefs.h> -#include <sys/kmem.h> - -#include <sys/devops.h> - -#include <sys/beep.h> -#include <sys/errno.h> -#include <sys/inttypes.h> - -/* - * Debug stuff - * BEEP_DEBUG used for errors - * BEEP_DEBUG1 prints when beep_debug > 1 and used for normal messages - */ -#ifdef DEBUG -int beep_debug = 0; -#define BEEP_DEBUG(args) if (beep_debug) cmn_err args -#define BEEP_DEBUG1(args) if (beep_debug > 1) cmn_err args -#else -#define BEEP_DEBUG(args) -#define BEEP_DEBUG1(args) -#endif - - -/* Prototypes */ - -static void beep_timeout(); - - -struct beep_params { - enum beep_type type; - int frequency; /* Hz */ - int duration; /* milliseconds */ -}; - - -struct beep_params beep_params[] = { - BEEP_CONSOLE, 900, 200, - BEEP_TYPE4, 2000, 0, - BEEP_DEFAULT, 1000, 200, /* Must be last */ -}; - - -/* beep_state structure */ - -typedef struct beep_state { - - dev_info_t *beep_state_beep_dip; /* device pointer */ - - /* Indicates if a beep command is already in progress */ - enum {BEEP_OFF, BEEP_TIMED, BEEP_ON} beep_state_mode; - - /* Address of the hw-dependent beep_freq function */ - void (*beep_state_beep_freq) (dev_info_t *, int); - - /* Address of the hw-dependent beep_on function */ - void (*beep_state_beep_on) (dev_info_t *); - - /* Address of the hw-dependent beep_off function */ - void (*beep_state_beep_off) (dev_info_t *); - - /* Timeout id for the beep() timeout function */ - timeout_id_t beep_state_timeout_id; - - /* Mutex */ - kmutex_t beep_state_mutex; - -} beep_state_t; - - -static beep_state_t *beep_statep = NULL; - - -/* - * beep_init : - * Alloc beep_state structure - * called from the beep driver attach routine - */ -int -beep_init(dev_info_t *dip, void (*hwbeep_beep_on)(dev_info_t *), - void (*hwbeep_beep_off)(dev_info_t *), - void (*hwbeep_beep_freq)(dev_info_t *, int)) -{ - BEEP_DEBUG1((CE_CONT, "beep_init : start")); - - if (dip == NULL) { - return (DDI_FAILURE); - } - - if ((hwbeep_beep_on == NULL) || (hwbeep_beep_off == NULL) || - (hwbeep_beep_freq == NULL)) { - - BEEP_DEBUG((CE_WARN, - "beep_init : Null routines passed for registration.")); - return (DDI_FAILURE); - } - - beep_statep = kmem_zalloc(sizeof (beep_state_t), KM_SLEEP); - if (beep_statep == NULL) { - BEEP_DEBUG((CE_WARN, - "beep_init : kmem_zalloc failed.")); - return (DDI_FAILURE); - } - - beep_statep->beep_state_beep_dip = dip; - beep_statep->beep_state_beep_on = hwbeep_beep_on; - beep_statep->beep_state_beep_off = hwbeep_beep_off; - beep_statep->beep_state_beep_freq = hwbeep_beep_freq; - beep_statep->beep_state_mode = BEEP_OFF; - - mutex_init(&beep_statep->beep_state_mutex, NULL, MUTEX_DRIVER, NULL); - - BEEP_DEBUG1((CE_CONT, "beep_init : Done.")); - return (DDI_SUCCESS); - -} - - -/* - * beep : - * Start beeping for period specified by 'time' (in microsecond) - */ -void -beep(enum beep_type type) -{ - - struct beep_params *bp; - - BEEP_DEBUG1((CE_CONT, "beep : Start")); - - if (beep_statep == NULL) { - return; - } - - for (bp = beep_params; bp->type != BEEP_DEFAULT; bp++) { - if (bp->type == type) - break; - } - - if (bp->type != type) { - - /* If type doesn't match, return silently without beeping */ - return; - } - - mutex_enter(&beep_statep->beep_state_mutex); - - /* Beep only when no previous beep is in progress */ - if (beep_statep->beep_state_mode == BEEP_OFF && bp->frequency != 0) { - - beep_statep->beep_state_mode = BEEP_TIMED; - - (*beep_statep->beep_state_beep_freq)(beep_statep-> - beep_state_beep_dip, bp->frequency); - (*beep_statep->beep_state_beep_on)(beep_statep-> - beep_state_beep_dip); - - /* Set timeout for ending the beep after the specified time */ - beep_statep->beep_state_timeout_id = timeout(beep_timeout, - NULL, - drv_usectohz(bp->duration*1000)); - } - - mutex_exit(&beep_statep->beep_state_mutex); - - BEEP_DEBUG1((CE_CONT, "beep : Done")); - -} - - -/*ARGSUSED*/ -void -beep_polled(enum beep_type type) -{ - /* No-op at this time */ -} - - -/* - * beeper_on : - * Turn the beeper on - */ -void -beeper_on(enum beep_type type) -{ - - struct beep_params *bp; - - BEEP_DEBUG1((CE_CONT, "beeper_on : Start")); - - if (beep_statep == NULL) { - return; - } - - for (bp = beep_params; bp->type != BEEP_DEFAULT; bp++) { - if (bp->type == type) - break; - } - - if (bp->type != type) { - - /* If type doesn't match, return silently */ - return; - } - - mutex_enter(&beep_statep->beep_state_mutex); - - /* Start another beep only if the previous one is over */ - if (beep_statep->beep_state_mode == BEEP_OFF) { - - beep_statep->beep_state_mode = BEEP_ON; - - if (bp->frequency != 0) { - (*beep_statep->beep_state_beep_freq)(beep_statep-> - beep_state_beep_dip, bp->frequency); - (*beep_statep->beep_state_beep_on)(beep_statep-> - beep_state_beep_dip); - } - } - mutex_exit(&beep_statep->beep_state_mutex); - - BEEP_DEBUG1((CE_CONT, "beeper_on : Done")); - -} - - -/* - * beeper_off : - * Turn the beeper off - */ -void -beeper_off() -{ - - BEEP_DEBUG1((CE_CONT, "beeper_off : Start")); - - if (beep_statep == NULL) { - return; - } - - mutex_enter(&beep_statep->beep_state_mutex); - - if (beep_statep->beep_state_mode == BEEP_ON) { - - beep_statep->beep_state_mode = BEEP_OFF; - (*beep_statep->beep_state_beep_off)(beep_statep-> - beep_state_beep_dip); - } - mutex_exit(&beep_statep->beep_state_mutex); - - BEEP_DEBUG1((CE_CONT, "beeper_off : Done")); - -} - - -/* - * Turn the beeper off which had been turned on from beep() - * for a specified period of time - */ -void -beep_timeout() -{ - BEEP_DEBUG1((CE_CONT, "beeper_timeout : Start")); - - beep_statep->beep_state_timeout_id = 0; - mutex_enter(&beep_statep->beep_state_mutex); - - if ((beep_statep->beep_state_mode == BEEP_ON) || - (beep_statep->beep_state_mode == BEEP_TIMED)) { - - beep_statep->beep_state_mode = BEEP_OFF; - (*beep_statep->beep_state_beep_off)(beep_statep-> - beep_state_beep_dip); - } - mutex_exit(&beep_statep->beep_state_mutex); - - BEEP_DEBUG1((CE_CONT, "beeper_timeout : Done")); - -} - -/* - * Beeper_freq: - * Set beeper frequency - */ -int -beeper_freq(enum beep_type type, int freq) -{ - struct beep_params *bp; - - BEEP_DEBUG1((CE_CONT, "beeper_freq : Start")); - - /* - * The frequency value is limited to the range of [0 - 32767] - */ - if ((type != BEEP_CONSOLE && type != BEEP_TYPE4) || freq < 0 || - freq > INT16_MAX) - return (EINVAL); - - for (bp = beep_params; bp->type != BEEP_DEFAULT; bp++) { - if (bp->type == type) - break; - } - - bp->frequency = freq; - - BEEP_DEBUG1((CE_CONT, "beeper_freq : Done")); - - return (0); -}
--- a/usr/src/uts/sun4/sys/beep_driver.h Tue Sep 25 11:12:45 2007 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 1999,2003 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#ifndef _SYS_BEEP_DRIVER_H -#define _SYS_BEEP_DRIVER_H - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * beep_driver.h : Registration functions of beep driver to beeper module - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(_KERNEL) - -/* - * Registration mechanism of the hardware dependent - * beep driver to the beeper module for sun4 platforms. - */ -int beep_init(dev_info_t *, void (*)(dev_info_t *), - void (*)(dev_info_t *), void (*)(dev_info_t *, int)); - - -#endif /* _KERNEL */ - -#ifdef __cplusplus -} -#endif - -#endif /* _SYS_BEEP_DRIVER_H */
--- a/usr/src/uts/sun4u/io/bbc_beep.c Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/sun4u/io/bbc_beep.c Tue Sep 25 13:11:35 2007 -0700 @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 1999-2000, 2002 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -39,7 +38,7 @@ #include <sys/kmem.h> #include <sys/devops.h> #include <sys/bbc_beep.h> -#include <sys/beep_driver.h> +#include <sys/beep.h> /* Pointer to the state structure */ @@ -66,9 +65,9 @@ static int bbc_beep_detach(dev_info_t *dip, ddi_detach_cmd_t cmd); static int bbc_beep_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result); -static void bbc_beep_freq(dev_info_t *, int); -static void bbc_beep_on(dev_info_t *); -static void bbc_beep_off(dev_info_t *); +static void bbc_beep_freq(void *arg, int freq); +static void bbc_beep_on(void *arg); +static void bbc_beep_off(void *arg); static void bbc_beep_cleanup(bbc_beep_state_t *); static int bbc_beep_map_regs(dev_info_t *, bbc_beep_state_t *); static bbc_beep_state_t *bbc_beep_obtain_state(dev_info_t *); @@ -128,7 +127,7 @@ /* Initialize the soft state structures */ if ((error = ddi_soft_state_init(&bbc_beep_statep, - sizeof (bbc_beep_state_t), 1)) != 0) { + sizeof (bbc_beep_state_t), 1)) != 0) { return (error); } @@ -219,14 +218,14 @@ if (bbc_beep_map_regs(dip, bbc_beeptr) != DDI_SUCCESS) { BBC_BEEP_DEBUG((CE_WARN, \ - "bbc_beep_attach: Mapping of bbc registers failed.")); + "bbc_beep_attach: Mapping of bbc registers failed.")); bbc_beep_cleanup(bbc_beeptr); return (DDI_FAILURE); } - (void) beep_init(dip, bbc_beep_on, bbc_beep_off, bbc_beep_freq); + (void) beep_init((void *)dip, bbc_beep_on, bbc_beep_off, bbc_beep_freq); /* Display information in the banner */ ddi_report_dev(dip); @@ -241,7 +240,6 @@ /* * bbc_beep_detach: */ -/* ARGSUSED */ static int bbc_beep_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) { @@ -324,8 +322,9 @@ * Set the frequency */ static void -bbc_beep_freq(dev_info_t *dip, int freq) +bbc_beep_freq(void *arg, int freq) { + dev_info_t *dip = (dev_info_t *)arg; unsigned long counter; int8_t beep_c2 = 0; int8_t beep_c3 = 0; @@ -362,8 +361,9 @@ * Turn the beeper on */ static void -bbc_beep_on(dev_info_t *dip) +bbc_beep_on(void *arg) { + dev_info_t *dip = (dev_info_t *)arg; bbc_beep_state_t *bbc_beeptr = bbc_beep_obtain_state(dip); BEEP_WRITE_CTRL_REG(BBC_BEEP_ON); @@ -380,8 +380,9 @@ * Turn the beeper off */ static void -bbc_beep_off(dev_info_t *dip) +bbc_beep_off(void *arg) { + dev_info_t *dip = (dev_info_t *)arg; bbc_beep_state_t *bbc_beeptr = bbc_beep_obtain_state(dip); BEEP_WRITE_CTRL_REG(BBC_BEEP_OFF); @@ -414,11 +415,11 @@ /* Map in operational registers */ if (ddi_regs_map_setup(dip, 0, - (caddr_t *)&bbc_beeptr->bbc_beep_regsp, - 0, - sizeof (bbc_beep_regs_t), - &attr, - &bbc_beeptr->bbc_beep_regs_handle) != DDI_SUCCESS) { + (caddr_t *)&bbc_beeptr->bbc_beep_regsp, + 0, + sizeof (bbc_beep_regs_t), + &attr, + &bbc_beeptr->bbc_beep_regs_handle) != DDI_SUCCESS) { return (DDI_FAILURE); } @@ -489,7 +490,7 @@ * Get system frequency for the root dev_info properties */ system_freq = ddi_prop_get_int(DDI_DEV_T_ANY, ddi_root_node(), - 0, "clock-frequency", 0); + 0, "clock-frequency", 0); oldfreq = 0;
--- a/usr/src/uts/sun4u/io/grbeep.c Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/sun4u/io/grbeep.c Tue Sep 25 13:11:35 2007 -0700 @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2000-2002 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -43,7 +42,7 @@ #include <sys/kmem.h> #include <sys/devops.h> #include <sys/grbeep.h> -#include <sys/beep_driver.h> +#include <sys/beep.h> /* Pointer to the state structure */ @@ -70,9 +69,9 @@ static int grbeep_detach(dev_info_t *dip, ddi_detach_cmd_t cmd); static int grbeep_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result); -static void grbeep_freq(dev_info_t *, int); -static void grbeep_on(dev_info_t *); -static void grbeep_off(dev_info_t *); +static void grbeep_freq(void *arg, int freq); +static void grbeep_on(void *arg); +static void grbeep_off(void *arg); static void grbeep_cleanup(grbeep_state_t *); static int grbeep_map_regs(dev_info_t *, grbeep_state_t *); static grbeep_state_t *grbeep_obtain_state(dev_info_t *); @@ -131,7 +130,7 @@ /* Initialize the soft state structures */ if ((error = ddi_soft_state_init(&grbeep_statep, - sizeof (grbeep_state_t), 1)) != 0) { + sizeof (grbeep_state_t), 1)) != 0) { return (error); } @@ -224,19 +223,18 @@ if (grbeep_map_regs(dip, grbeeptr) != DDI_SUCCESS) { GRBEEP_DEBUG((CE_WARN, - "grbeep_attach: Mapping of beep registers failed.")); + "grbeep_attach: Mapping of beep registers failed.")); grbeep_cleanup(grbeeptr); return (DDI_FAILURE); } - (void) beep_init(dip, grbeep_on, grbeep_off, grbeep_freq); + (void) beep_init((void *)dip, grbeep_on, grbeep_off, grbeep_freq); /* Display information in the banner */ ddi_report_dev(dip); - mutex_init(&grbeeptr->grbeep_mutex, NULL, MUTEX_DRIVER, NULL); GRBEEP_DEBUG1((CE_CONT, "grbeep_attach: dip = 0x%p done", (void *)dip)); @@ -247,7 +245,6 @@ /* * grbeep_detach: */ -/* ARGSUSED */ static int grbeep_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) { @@ -330,16 +327,15 @@ * grbeep_freq() : * Set beep frequency */ -/*ARGSUSED*/ static void -grbeep_freq(dev_info_t *dip, int freq) +grbeep_freq(void *arg, int freq) { + dev_info_t *dip = (dev_info_t *)arg; grbeep_state_t *grbeeptr = grbeep_obtain_state(dip); int divisor = 0; ASSERT(freq != 0); - mutex_enter(&grbeeptr->grbeep_mutex); GRBEEP_DEBUG1((CE_CONT, "grbeep_freq: dip=0x%p freq=%d mode=%d", (void *)dip, freq, grbeeptr->grbeep_mode)); @@ -354,12 +350,10 @@ } GRBEEP_DEBUG1((CE_CONT, "grbeep_freq: first=0x%x second=0x%x", - (divisor & 0xff), ((divisor & 0xff00) >> 8))); + (divisor & 0xff), ((divisor & 0xff00) >> 8))); GRBEEP_WRITE_FREQ_DIVISOR_REG(divisor & 0xff); GRBEEP_WRITE_FREQ_DIVISOR_REG((divisor & 0xff00) >> 8); - - mutex_exit(&grbeeptr->grbeep_mutex); } @@ -368,11 +362,11 @@ * Turn the beeper on */ static void -grbeep_on(dev_info_t *dip) +grbeep_on(void *arg) { + dev_info_t *dip = (dev_info_t *)arg; grbeep_state_t *grbeeptr = grbeep_obtain_state(dip); - mutex_enter(&grbeeptr->grbeep_mutex); GRBEEP_DEBUG1((CE_CONT, "grbeep_on: dip = 0x%p mode=%d", (void *)dip, grbeeptr->grbeep_mode)); @@ -384,7 +378,6 @@ } - mutex_exit(&grbeeptr->grbeep_mutex); GRBEEP_DEBUG1((CE_CONT, "grbeep_on: dip = 0x%p done", (void *)dip)); } @@ -393,13 +386,12 @@ * grbeep_off() : * Turn the beeper off */ -/*ARGSUSED*/ static void -grbeep_off(dev_info_t *dip) +grbeep_off(void *arg) { + dev_info_t *dip = (dev_info_t *)arg; grbeep_state_t *grbeeptr = grbeep_obtain_state(dip); - mutex_enter(&grbeeptr->grbeep_mutex); GRBEEP_DEBUG1((CE_CONT, "grbeep_off: dip = 0x%p mode=%d", (void *)dip, grbeeptr->grbeep_mode)); @@ -411,7 +403,6 @@ } - mutex_exit(&grbeeptr->grbeep_mutex); GRBEEP_DEBUG1((CE_CONT, "grbeep_off: dip = 0x%p done", (void *)dip)); } @@ -441,7 +432,7 @@ sizeof (grbeep_freq_regs_t), &attr, &grbeeptr->grbeep_freq_regs_handle) - != DDI_SUCCESS) { + != DDI_SUCCESS) { GRBEEP_DEBUG((CE_CONT, "grbeep_map_regs: Failed to map")); return (DDI_FAILURE); @@ -454,7 +445,7 @@ 1, &attr, &grbeeptr->grbeep_start_stop_reg_handle) - != DDI_SUCCESS) { + != DDI_SUCCESS) { GRBEEP_DEBUG((CE_CONT, "grbeep_map_regs: Failed to map")); ddi_regs_map_free((void *)&grbeeptr->grbeep_freq_regs_handle); @@ -495,7 +486,6 @@ { int instance = ddi_get_instance(grbeeptr->grbeep_dip); - mutex_destroy(&grbeeptr->grbeep_mutex); ddi_soft_state_free(grbeep_statep, instance); GRBEEP_DEBUG1((CE_CONT, "grbeep_cleanup: done"));
--- a/usr/src/uts/sun4u/sys/grbeep.h Tue Sep 25 11:12:45 2007 -0700 +++ b/usr/src/uts/sun4u/sys/grbeep.h Tue Sep 25 13:11:35 2007 -0700 @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2000-2002 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -99,9 +98,6 @@ /* If beeper is active or not */ int grbeep_mode; - /* Mutex for fields that are mutually exclusively accessible */ - kmutex_t grbeep_mutex; - } grbeep_state_t; #define GRBEEP_WRITE_FREQ_CONTROL_REG(val) \