Home | History | Annotate | Line # | Download | only in device
      1 /*	$NetBSD: nouveau_nvkm_engine_device_acpi.c,v 1.4 2024/04/16 14:34:02 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2014 Red Hat Inc.
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the "Software"),
      8  * to deal in the Software without restriction, including without limitation
      9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  * and/or sell copies of the Software, and to permit persons to whom the
     11  * Software is furnished to do so, subject to the following conditions:
     12  *
     13  * The above copyright notice and this permission notice shall be included in
     14  * all copies or substantial portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  * OTHER DEALINGS IN THE SOFTWARE.
     23  *
     24  * Authors: Ben Skeggs
     25  */
     26 #include <sys/cdefs.h>
     27 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_device_acpi.c,v 1.4 2024/04/16 14:34:02 riastradh Exp $");
     28 
     29 #include "acpi.h"
     30 
     31 #include <core/device.h>
     32 
     33 #ifdef __NetBSD__
     34 /* This should be a PMF hook, not an ACPI notifier.  */
     35 #undef	CONFIG_ACPI
     36 #endif
     37 
     38 #ifdef CONFIG_ACPI
     39 static int
     40 nvkm_acpi_ntfy(struct notifier_block *nb, unsigned long val, void *data)
     41 {
     42 	struct nvkm_device *device =
     43 		container_of(nb, typeof(*device), acpi.nb);
     44 	struct acpi_bus_event *info = data;
     45 
     46 	if (!strcmp(info->device_class, "ac_adapter"))
     47 		nvkm_event_send(&device->event, 1, 0, NULL, 0);
     48 
     49 	return NOTIFY_DONE;
     50 }
     51 #endif
     52 
     53 void
     54 nvkm_acpi_fini(struct nvkm_device *device)
     55 {
     56 #ifdef CONFIG_ACPI
     57 	unregister_acpi_notifier(&device->acpi.nb);
     58 #endif
     59 }
     60 
     61 void
     62 nvkm_acpi_init(struct nvkm_device *device)
     63 {
     64 #ifdef CONFIG_ACPI
     65 	device->acpi.nb.notifier_call = nvkm_acpi_ntfy;
     66 	register_acpi_notifier(&device->acpi.nb);
     67 #endif
     68 }
     69