From 4c2c8a2fcdcc06c278b5034355bc1f5aead103b7 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Fri, 16 Jan 2026 19:15:17 +0100 Subject: [PATCH] xfree86: os-support: bsd: factor out bell ring into driver functions factor it out into per console-driver functions. Signed-off-by: Enrico Weigelt, metux IT consult --- hw/xfree86/os-support/bsd/bsd_bell.c | 66 --------------------- hw/xfree86/os-support/bsd/console.c | 14 +++++ hw/xfree86/os-support/bsd/console_pcvt.c | 10 ++++ hw/xfree86/os-support/bsd/console_syscons.c | 10 ++++ hw/xfree86/os-support/bsd/console_wscons.c | 14 +++++ hw/xfree86/os-support/meson.build | 2 +- 6 files changed, 49 insertions(+), 67 deletions(-) delete mode 100644 hw/xfree86/os-support/bsd/bsd_bell.c create mode 100644 hw/xfree86/os-support/bsd/console.c diff --git a/hw/xfree86/os-support/bsd/bsd_bell.c b/hw/xfree86/os-support/bsd/bsd_bell.c deleted file mode 100644 index aaa73ef06a..0000000000 --- a/hw/xfree86/os-support/bsd/bsd_bell.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 1992 by Rich Murphey - * Copyright 1993 by David Dawes - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the names of Rich Murphey and David Dawes - * not be used in advertising or publicity pertaining to distribution of - * the software without specific, written prior permission. Rich Murphey and - * David Dawes make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * RICH MURPHEY AND DAVID DAWES DISCLAIM ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID DAWES BE LIABLE FOR - * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -#include - -#if defined (SYSCONS_SUPPORT) -#include -#endif - -#include - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_os_support.h" -#include "xf86_OSlib.h" - -void -xf86OSRingBell(int loudness, int pitch, int duration) -{ -#ifdef WSCONS_SUPPORT - struct wskbd_bell_data wsb; -#endif - - if (loudness && pitch) { - switch (xf86Info.consType) { -#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - case SYSCONS: - case PCVT: - ioctl(xf86Info.consoleFd, KDMKTONE, - ((1193190 / pitch) & 0xffff) | - (((unsigned long) duration * loudness / 50) << 16)); - break; -#endif -#if defined (WSCONS_SUPPORT) - case WSCONS: - wsb.which = WSKBD_BELL_DOALL; - wsb.pitch = pitch; - wsb.period = duration; - wsb.volume = loudness; - ioctl(xf86Info.consoleFd, WSKBDIO_COMPLEXBELL, &wsb); - break; -#endif - } - } -} diff --git a/hw/xfree86/os-support/bsd/console.c b/hw/xfree86/os-support/bsd/console.c new file mode 100644 index 0000000000..0631986d4a --- /dev/null +++ b/hw/xfree86/os-support/bsd/console.c @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: MIT OR X11 + * + * Copyright © 2024 Enrico Weigelt, metux IT consult + */ +#include + +#include "xf86_console_priv.h" +#include "xf86_os_support.h" + +void xf86OSRingBell(int loudness, int pitch, int duration) +{ + if (xf86_console_proc_bell) + xf86_console_proc_bell(loudness, pitch, duration); +} diff --git a/hw/xfree86/os-support/bsd/console_pcvt.c b/hw/xfree86/os-support/bsd/console_pcvt.c index a14eea13f5..f15685033b 100644 --- a/hw/xfree86/os-support/bsd/console_pcvt.c +++ b/hw/xfree86/os-support/bsd/console_pcvt.c @@ -59,6 +59,15 @@ void xf86_console_pcvt_reactivate(void) LogMessageVerb(X_WARNING, 1, "xf86_console_pcvt_reactivate: VT_ACTIVATE failed\n"); } +static void xf86_console_pcvt_bell(int loudness, int pitch, int duration) +{ + if (loudness && pitch) { + ioctl(xf86Info.consoleFd, KDMKTONE, + ((1193190 / pitch) & 0xffff) | + (((unsigned long) duration * loudness / 50) << 16)); + } +} + bool xf86_console_pcvt_open(void) { /* This looks much like syscons, since pcvt is API compatible */ @@ -173,6 +182,7 @@ bool xf86_console_pcvt_open(void) goto out; out: xf86_bsd_acquire_vt(); + xf86_console_proc_bell = xf86_console_pcvt_bell; xf86_console_proc_close = xf86_console_pcvt_close; xf86_console_proc_reactivate = xf86_console_pcvt_reactivate; return (fd > 0); diff --git a/hw/xfree86/os-support/bsd/console_syscons.c b/hw/xfree86/os-support/bsd/console_syscons.c index 10eeb2f3fc..25932ff047 100644 --- a/hw/xfree86/os-support/bsd/console_syscons.c +++ b/hw/xfree86/os-support/bsd/console_syscons.c @@ -44,6 +44,15 @@ void xf86_console_syscons_reactivate(void) LogMessageVerb(X_WARNING, 1, "xf86_console_syscons_reactivate: VT_ACTIVATE failed\n"); } +static void xf86_console_syscons_bell(int loudness, int pitch, int duration) +{ + if (loudness && pitch) { + ioctl(xf86Info.consoleFd, KDMKTONE, + ((1193190 / pitch) & 0xffff) | + (((unsigned long) duration * loudness / 50) << 16)); + } +} + /* The FreeBSD 1.1 version syscons driver uses /dev/ttyv0 */ #define SYSCONS_CONSOLE_DEV1 "/dev/ttyv0" #define SYSCONS_CONSOLE_DEV2 "/dev/vga" @@ -145,6 +154,7 @@ bool xf86_console_syscons_open(void) } xf86Info.consoleFd = fd; xf86_bsd_acquire_vt(); + xf86_console_proc_bell = xf86_console_syscons_bell; xf86_console_proc_close = xf86_console_syscons_close; xf86_console_proc_reactivate = xf86_console_syscons_reactivate; return (fd > 0); diff --git a/hw/xfree86/os-support/bsd/console_wscons.c b/hw/xfree86/os-support/bsd/console_wscons.c index 30875d4d74..bea4fcfeea 100644 --- a/hw/xfree86/os-support/bsd/console_wscons.c +++ b/hw/xfree86/os-support/bsd/console_wscons.c @@ -25,6 +25,19 @@ void xf86_console_wscons_close(void) xf86Info.consoleFd = -1; } +static void xf86_console_wscons_bell(int loudness, int pitch, int duration) +{ + if (loudness && pitch) { + struct wskbd_bell_data wsb = { + .which = WSKBD_BELL_DOALL, + .pitch = pitch, + .period = duration, + .volume = loudness, + }; + ioctl(xf86Info.consoleFd, WSKBDIO_COMPLEXBELL, &wsb); + } +} + bool xf86_console_wscons_open(void) { int fd = -1; @@ -52,6 +65,7 @@ bool xf86_console_wscons_open(void) } xf86Info.consoleFd = fd; + xf86_console_proc_bell = xf86_console_wscons_bell; xf86_console_proc_close = xf86_console_wscons_close; /* nothing special to do for acquiring the VT */ diff --git a/hw/xfree86/os-support/meson.build b/hw/xfree86/os-support/meson.build index dfd6ce1aba..20138bb116 100644 --- a/hw/xfree86/os-support/meson.build +++ b/hw/xfree86/os-support/meson.build @@ -96,8 +96,8 @@ elif host_machine.system() == 'sunos' elif host_machine.system().endswith('bsd') or host_machine.system() == 'dragonfly' srcs_xorg_os_support += [ 'bsd/bsd_VTsw.c', - 'bsd/bsd_bell.c', 'bsd/bsd_init.c', + 'bsd/console.c', 'bsd/console_pcvt.c', 'bsd/console_syscons.c', 'bsd/console_wscons.c',