Module Name: src Committed By: riastradh Date: Sun Feb 27 21:21:51 UTC 2022
Modified Files: src/sys/dev/acpi: acpi_display.c Added Files: src/sys/dev/acpi: acpi_display.h Log Message: acpivga(4): Provide hooks for ACPI display notifications. The Intel i915 graphics driver needs to receive ACPI VGA 0x80 notifications, but with NetBSD's ACPI API, each ACPI node -- such as the VGA node -- can only have one notifier attached, and acpivga(4) already uses it. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/sys/dev/acpi/acpi_display.c cvs rdiff -u -r0 -r1.1 src/sys/dev/acpi/acpi_display.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/acpi/acpi_display.c diff -u src/sys/dev/acpi/acpi_display.c:1.21 src/sys/dev/acpi/acpi_display.c:1.22 --- src/sys/dev/acpi/acpi_display.c:1.21 Thu Dec 30 14:40:06 2021 +++ src/sys/dev/acpi/acpi_display.c Sun Feb 27 21:21:51 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_display.c,v 1.21 2021/12/30 14:40:06 riastradh Exp $ */ +/* $NetBSD: acpi_display.c,v 1.22 2022/02/27 21:21:51 riastradh Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -66,19 +66,23 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: acpi_display.c,v 1.21 2021/12/30 14:40:06 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_display.c,v 1.22 2022/02/27 21:21:51 riastradh Exp $"); #include <sys/param.h> #include <sys/device.h> #include <sys/kmem.h> #include <sys/module.h> #include <sys/mutex.h> +#include <sys/pserialize.h> +#include <sys/pslist.h> #include <sys/sysctl.h> #include <sys/systm.h> +#include <sys/xcall.h> #include <dev/pci/pcireg.h> #include <dev/pci/pcidevs.h> +#include <dev/acpi/acpi_display.h> #include <dev/acpi/acpireg.h> #include <dev/acpi/acpivar.h> @@ -386,6 +390,65 @@ static void acpidisp_array_search(const uint8_t *); /* + * Display notification callbacks -- used by i915 + */ + +struct acpidisp_notifier { + void (*adn_func)(ACPI_HANDLE, uint32_t, void *); + void *adn_cookie; + struct pslist_entry adn_entry; +}; + +static struct { + kmutex_t lock; + struct pslist_head list; +} acpidisp_notifiers; + +struct acpidisp_notifier * +acpidisp_register_notify(void (*func)(ACPI_HANDLE, uint32_t, void *), + void *cookie) +{ + struct acpidisp_notifier *adn; + + adn = kmem_zalloc(sizeof(*adn), KM_SLEEP); + adn->adn_func = func; + adn->adn_cookie = cookie; + PSLIST_ENTRY_INIT(adn, adn_entry); + + mutex_enter(&acpidisp_notifiers.lock); + PSLIST_WRITER_INSERT_HEAD(&acpidisp_notifiers.list, adn, adn_entry); + mutex_exit(&acpidisp_notifiers.lock); + + return adn; +} + +void +acpidisp_deregister_notify(struct acpidisp_notifier *adn) +{ + + mutex_enter(&acpidisp_notifiers.lock); + PSLIST_WRITER_REMOVE(adn, adn_entry); + mutex_exit(&acpidisp_notifiers.lock); + + xc_barrier(0); + kmem_free(adn, sizeof(*adn)); +} + +static void +acpidisp_notify(ACPI_HANDLE handle, uint32_t notify) +{ + struct acpidisp_notifier *adn; + int s; + + s = pserialize_read_enter(); + PSLIST_READER_FOREACH(adn, &acpidisp_notifiers.list, + struct acpidisp_notifier, adn_entry) { + (*adn->adn_func)(handle, notify, adn->adn_cookie); + } + pserialize_read_exit(s); +} + +/* * Autoconfiguration for the acpivga driver. */ @@ -863,6 +926,8 @@ acpidisp_vga_notify_handler(ACPI_HANDLE KASSERT(callback != NULL); (void)AcpiOsExecute(OSL_NOTIFY_HANDLER, callback, asc); + + acpidisp_notify(handle, notify); } static void @@ -2081,7 +2146,9 @@ acpivga_modcmd(modcmd_t cmd, void *aux) switch (cmd) { case MODULE_CMD_INIT: - + KASSERT(PSLIST_READER_FIRST(&acpidisp_notifiers.list, + struct acpidisp_notifier, adn_entry) == NULL); + mutex_init(&acpidisp_notifiers.lock, MUTEX_DEFAULT, IPL_NONE); #ifdef _MODULE rv = config_init_component(cfdriver_ioconf_acpivga, cfattach_ioconf_acpivga, cfdata_ioconf_acpivga); @@ -2093,7 +2160,10 @@ acpivga_modcmd(modcmd_t cmd, void *aux) #ifdef _MODULE rv = config_fini_component(cfdriver_ioconf_acpivga, cfattach_ioconf_acpivga, cfdata_ioconf_acpivga); + if (rv) + break; #endif + mutex_destroy(&acpidisp_notifiers.lock); break; default: Added files: Index: src/sys/dev/acpi/acpi_display.h diff -u /dev/null src/sys/dev/acpi/acpi_display.h:1.1 --- /dev/null Sun Feb 27 21:21:51 2022 +++ src/sys/dev/acpi/acpi_display.h Sun Feb 27 21:21:51 2022 @@ -0,0 +1,42 @@ +/* $NetBSD: acpi_display.h,v 1.1 2022/02/27 21:21:51 riastradh Exp $ */ + +/*- + * Copyright (c) 2022 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _DEV_ACPI_ACPI_DISPLAY_H_ +#define _DEV_ACPI_ACPI_DISPLAY_H_ + +#include <sys/types.h> + +#include <dev/acpi/acpica.h> + +struct acpidisp_notifier; + +struct acpidisp_notifier *acpidisp_register_notify(void (*func)(ACPI_HANDLE, + uint32_t, void *), void *); +void acpidisp_deregister_notify(struct acpidisp_notifier *); + +#endif /* _DEV_ACPI_ACPI_DISPLAY_H_ */