diff options
author | 2019-08-18 13:11:47 +0000 | |
---|---|---|
committer | 2019-08-18 13:11:47 +0000 | |
commit | 6a77e6ad1ad5d153b53aaa6987055f6163280aee (patch) | |
tree | 29692a27662027f6fb8801aee9c9d90eae78c6a1 | |
parent | minor cleanup: (diff) | |
download | wireguard-openbsd-6a77e6ad1ad5d153b53aaa6987055f6163280aee.tar.xz wireguard-openbsd-6a77e6ad1ad5d153b53aaa6987055f6163280aee.zip |
Implement a few Linux compat ACPI interfaces and enable the ACPI support
code in radeon(4) and amdgpu(4).
ok jsg@
-rw-r--r-- | sys/dev/pci/drm/amd/amdgpu/amdgpu_bios.c | 8 | ||||
-rw-r--r-- | sys/dev/pci/drm/drm_drv.c | 16 | ||||
-rw-r--r-- | sys/dev/pci/drm/drm_linux.c | 129 | ||||
-rw-r--r-- | sys/dev/pci/drm/files.drm | 6 | ||||
-rw-r--r-- | sys/dev/pci/drm/i915/i915_drv.h | 5 | ||||
-rw-r--r-- | sys/dev/pci/drm/include/drm/drmP.h | 3 | ||||
-rw-r--r-- | sys/dev/pci/drm/include/generated/autoconf.h | 37 | ||||
-rw-r--r-- | sys/dev/pci/drm/include/linux/acpi.h | 59 | ||||
-rw-r--r-- | sys/dev/pci/drm/include/linux/backlight.h | 8 | ||||
-rw-r--r-- | sys/dev/pci/drm/include/linux/kconfig.h | 30 | ||||
-rw-r--r-- | sys/dev/pci/drm/include/linux/notifier.h | 3 | ||||
-rw-r--r-- | sys/dev/pci/drm/include/linux/pci.h | 19 | ||||
-rw-r--r-- | sys/dev/pci/drm/radeon/radeon_bios.c | 8 |
13 files changed, 273 insertions, 58 deletions
diff --git a/sys/dev/pci/drm/amd/amdgpu/amdgpu_bios.c b/sys/dev/pci/drm/amd/amdgpu/amdgpu_bios.c index 0dfe4041015..9035c3cdf5d 100644 --- a/sys/dev/pci/drm/amd/amdgpu/amdgpu_bios.c +++ b/sys/dev/pci/drm/amd/amdgpu/amdgpu_bios.c @@ -37,10 +37,6 @@ #include <dev/isa/isavar.h> #endif -#ifdef __HAVE_ACPI -#include "acpi.h" -#endif - /* * BIOS. */ @@ -477,10 +473,6 @@ static bool amdgpu_read_disabled_bios(struct amdgpu_device *adev) return amdgpu_asic_read_disabled_bios(adev); } -#if NACPI > 0 -#define CONFIG_ACPI -#endif - #ifdef CONFIG_ACPI static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev) { diff --git a/sys/dev/pci/drm/drm_drv.c b/sys/dev/pci/drm/drm_drv.c index a8278ace6db..e1cbe5a4259 100644 --- a/sys/dev/pci/drm/drm_drv.c +++ b/sys/dev/pci/drm/drm_drv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: drm_drv.c,v 1.164 2019/07/30 05:50:20 jsg Exp $ */ +/* $OpenBSD: drm_drv.c,v 1.165 2019/08/18 13:11:47 kettenis Exp $ */ /*- * Copyright 2007-2009 Owain G. Ainsworth <oga@openbsd.org> * Copyright © 2008 Intel Corporation @@ -55,6 +55,14 @@ #include <uvm/uvm.h> #include <uvm/uvm_device.h> +#include <machine/bus.h> + +#ifdef __HAVE_ACPI +#include <dev/acpi/acpidev.h> +#include <dev/acpi/acpivar.h> +#include <dev/acpi/dsdt.h> +#endif + #include <drm/drmP.h> #include <drm/drm_gem.h> #include <uapi/drm/drm.h> @@ -257,6 +265,12 @@ drm_attach(struct device *parent, struct device *self, void *aux) dev->pdev->tag = da->tag; dev->pdev->pci = (struct pci_softc *)parent->dv_parent; +#ifdef CONFIG_ACPI + dev->pdev->dev.node = acpi_find_pci(da->pc, da->tag); + aml_register_notify(dev->pdev->dev.node, NULL, + drm_linux_acpi_notify, NULL, ACPIDEV_NOPOLL); +#endif + rw_init(&dev->struct_mutex, "drmdevlk"); mtx_init(&dev->event_lock, IPL_TTY); mtx_init(&dev->quiesce_mtx, IPL_NONE); diff --git a/sys/dev/pci/drm/drm_linux.c b/sys/dev/pci/drm/drm_linux.c index 4e77d829dbc..853d327db38 100644 --- a/sys/dev/pci/drm/drm_linux.c +++ b/sys/dev/pci/drm/drm_linux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: drm_linux.c,v 1.47 2019/08/05 08:35:59 anton Exp $ */ +/* $OpenBSD: drm_linux.c,v 1.48 2019/08/18 13:11:47 kettenis Exp $ */ /* * Copyright (c) 2013 Jonathan Gray <jsg@openbsd.org> * Copyright (c) 2015, 2016 Mark Kettenis <kettenis@openbsd.org> @@ -987,6 +987,8 @@ vga_put(struct pci_dev *pdev, int rsrc) #include <dev/acpi/acpireg.h> #include <dev/acpi/acpivar.h> +#include <dev/acpi/amltypes.h> +#include <dev/acpi/dsdt.h> acpi_status acpi_get_table(const char *sig, int instance, @@ -1010,6 +1012,131 @@ acpi_get_table(const char *sig, int instance, return AE_NOT_FOUND; } +acpi_status +acpi_get_handle(acpi_handle node, const char *name, acpi_handle *rnode) +{ + node = aml_searchname(node, name); + if (node == NULL) + return AE_NOT_FOUND; + + *rnode = node; + return 0; +} + +acpi_status +acpi_get_name(acpi_handle node, int type, struct acpi_buffer *buffer) +{ + KASSERT(buffer->length != ACPI_ALLOCATE_BUFFER); + KASSERT(type == ACPI_FULL_PATHNAME); + strlcpy(buffer->pointer, aml_nodename(node), buffer->length); + return 0; +} + +acpi_status +acpi_evaluate_object(acpi_handle node, const char *name, + struct acpi_object_list *params, struct acpi_buffer *result) +{ + struct aml_value args[4], res; + union acpi_object *obj; + uint8_t *data; + int i; + + KASSERT(params->count <= nitems(args)); + + for (i = 0; i < params->count; i++) { + args[i].type = params->pointer[i].type; + switch (args[i].type) { + case AML_OBJTYPE_INTEGER: + args[i].v_integer = params->pointer[i].integer.value; + break; + case AML_OBJTYPE_BUFFER: + args[i].length = params->pointer[i].buffer.length; + args[i].v_buffer = params->pointer[i].buffer.pointer; + break; + default: + printf("%s: arg type 0x%02x", __func__, args[i].type); + return AE_BAD_PARAMETER; + } + } + + if (name) { + node = aml_searchname(node, name); + if (node == NULL) + return AE_NOT_FOUND; + } + if (aml_evalnode(acpi_softc, node, params->count, args, &res)) { + aml_freevalue(&res); + return AE_ERROR; + } + + KASSERT(result->length == ACPI_ALLOCATE_BUFFER); + + result->length = sizeof(union acpi_object); + switch (res.type) { + case AML_OBJTYPE_BUFFER: + result->length += res.length; + result->pointer = malloc(result->length, M_DRM, M_WAITOK); + obj = (union acpi_object *)result->pointer; + data = (uint8_t *)(obj + 1); + obj->type = res.type; + obj->buffer.length = res.length; + obj->buffer.pointer = data; + memcpy(data, res.v_buffer, res.length); + break; + default: + printf("%s: return type 0x%02x", __func__, res.type); + aml_freevalue(&res); + return AE_ERROR; + } + + aml_freevalue(&res); + return 0; +} + +SLIST_HEAD(, notifier_block) drm_linux_acpi_notify_list = + SLIST_HEAD_INITIALIZER(drm_linux_acpi_notify_list); + +int +drm_linux_acpi_notify(struct aml_node *node, int notify, void *arg) +{ + struct acpi_bus_event event; + struct notifier_block *nb; + + event.device_class = ACPI_VIDEO_CLASS; + event.type = notify; + + SLIST_FOREACH(nb, &drm_linux_acpi_notify_list, link) + nb->notifier_call(nb, 0, &event); + return 0; +} + +int +register_acpi_notifier(struct notifier_block *nb) +{ + SLIST_INSERT_HEAD(&drm_linux_acpi_notify_list, nb, link); + return 0; +} + +int +unregister_acpi_notifier(struct notifier_block *nb) +{ + SLIST_REMOVE(&drm_linux_acpi_notify_list, nb, notifier_block, link); + return 0; +} + +const char * +acpi_format_exception(acpi_status status) +{ + switch (status) { + case AE_NOT_FOUND: + return "not found"; + case AE_BAD_PARAMETER: + return "bad parameter"; + default: + return "unknown"; + } +} + #endif void diff --git a/sys/dev/pci/drm/files.drm b/sys/dev/pci/drm/files.drm index 32c4958220b..c1b59918ed5 100644 --- a/sys/dev/pci/drm/files.drm +++ b/sys/dev/pci/drm/files.drm @@ -1,5 +1,5 @@ # $NetBSD: files.drm,v 1.2 2007/03/28 11:29:37 jmcneill Exp $ -# $OpenBSD: files.drm,v 1.45 2019/05/21 22:40:06 jsg Exp $ +# $OpenBSD: files.drm,v 1.46 2019/08/18 13:11:47 kettenis Exp $ # direct rendering modules define drmbase {[primary = -1]} @@ -235,7 +235,7 @@ file dev/pci/drm/radeon/r600_cs.c radeondrm file dev/pci/drm/radeon/r600_dma.c radeondrm file dev/pci/drm/radeon/r600_dpm.c radeondrm file dev/pci/drm/radeon/r600_hdmi.c radeondrm -#file dev/pci/drm/radeon/radeon_acpi.c radeondrm +file dev/pci/drm/radeon/radeon_acpi.c radeondrm & acpi file dev/pci/drm/radeon/radeon_agp.c radeondrm file dev/pci/drm/radeon/radeon_asic.c radeondrm file dev/pci/drm/radeon/radeon_atombios.c radeondrm @@ -518,7 +518,7 @@ file dev/pci/drm/amd/amdgpu/amdgpu_vce_v2_0.c amdgpu_cik device amdgpu: drmbase, ttm, wsemuldisplaydev, rasops8, rasops32, i2cbus, i2c_bitbang, drm_sched, chash, powerplay, amddal attach amdgpu at pci -#file dev/pci/drm/amd/amdgpu/amdgpu_acpi.c amdgpu +file dev/pci/drm/amd/amdgpu/amdgpu_acpi.c amdgpu & acpi file dev/pci/drm/amd/amdgpu/amdgpu_afmt.c amdgpu file dev/pci/drm/amd/amdgpu/amdgpu_amdkfd.c amdgpu file dev/pci/drm/amd/amdgpu/amdgpu_atombios.c amdgpu diff --git a/sys/dev/pci/drm/i915/i915_drv.h b/sys/dev/pci/drm/i915/i915_drv.h index 3e4606d04f6..9c8ba12b5fa 100644 --- a/sys/dev/pci/drm/i915/i915_drv.h +++ b/sys/dev/pci/drm/i915/i915_drv.h @@ -55,11 +55,6 @@ #include <drm/drm_gem.h> #include <drm/drm_cache.h> -#include "acpi.h" -#if NACPI > 0 -#define CONFIG_ACPI -#endif - #include "drm.h" #include "vga.h" diff --git a/sys/dev/pci/drm/include/drm/drmP.h b/sys/dev/pci/drm/include/drm/drmP.h index 61c608a21c0..2481d867937 100644 --- a/sys/dev/pci/drm/include/drm/drmP.h +++ b/sys/dev/pci/drm/include/drm/drmP.h @@ -1,4 +1,4 @@ -/* $OpenBSD: drmP.h,v 1.4 2019/08/14 05:32:56 jsg Exp $ */ +/* $OpenBSD: drmP.h,v 1.5 2019/08/18 13:11:47 kettenis Exp $ */ /* drmP.h -- Private header for Direct Rendering Manager -*- linux-c -*- * Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com */ @@ -242,6 +242,7 @@ struct drm_attach_args { #define DRMDEVCF_PRIMARY_UNK -1 void drm_linux_init(void); +int drm_linux_acpi_notify(struct aml_node *, int, void *); /* Device setup support (drm_drv.c) */ int drm_pciprobe(struct pci_attach_args *, const struct drm_pcidev * ); diff --git a/sys/dev/pci/drm/include/generated/autoconf.h b/sys/dev/pci/drm/include/generated/autoconf.h new file mode 100644 index 00000000000..110849b5e32 --- /dev/null +++ b/sys/dev/pci/drm/include/generated/autoconf.h @@ -0,0 +1,37 @@ +/* Public domain. */ + +#include <sys/param.h> + +#define CONFIG_BACKLIGHT_CLASS_DEVICE 1 +#define CONFIG_DRM_FBDEV_EMULATION 1 +#define CONFIG_DRM_FBDEV_OVERALLOC 0 +#define CONFIG_DRM_I915_DEBUG 0 +#define CONFIG_DRM_I915_DEBUG_GEM 0 +#define CONFIG_DRM_I915_FBDEV 1 +#define CONFIG_DRM_I915_ALPHA_SUPPORT 0 +#define CONFIG_DRM_I915_CAPTURE_ERROR 1 +#define CONFIG_DRM_I915_GVT 0 +#define CONFIG_DRM_I915_SW_FENCE_CHECK_DAG 0 +#define CONFIG_PM 0 +#define CONFIG_DRM_AMD_DC 1 +#define CONFIG_DRM_AMD_DC_DCN1_0 1 +#if 0 +#define CONFIG_DRM_AMDGPU_CIK 1 +#define CONFIG_DRM_AMDGPU_SI 1 +#endif + +#ifdef __HAVE_ACPI +#include "acpi.h" +#if NACPI > 0 +#define CONFIG_ACPI 1 +#endif +#endif + +#include "agp.h" +#if NAGP > 0 +#define CONFIG_AGP 1 +#endif + +#if defined(__amd64__) || defined(__i386__) +#define CONFIG_DMI 1 +#endif diff --git a/sys/dev/pci/drm/include/linux/acpi.h b/sys/dev/pci/drm/include/linux/acpi.h index 89c990fdd08..34744f31962 100644 --- a/sys/dev/pci/drm/include/linux/acpi.h +++ b/sys/dev/pci/drm/include/linux/acpi.h @@ -13,13 +13,70 @@ typedef size_t acpi_size; typedef int acpi_status; +typedef struct aml_node *acpi_handle; + +struct acpi_bus_event { + const char *device_class; + int type; +}; + +struct acpi_buffer { + size_t length; + void *pointer; +}; + +#define ACPI_ALLOCATE_BUFFER (size_t)-1 + +union acpi_object { + int type; + struct { + int type; + uint64_t value; + } integer; + struct { + int type; + size_t length; + void *pointer; + } buffer; +}; + +#define ACPI_TYPE_INTEGER 1 +#define ACPI_TYPE_BUFFER 3 + +struct acpi_object_list { + int count; + union acpi_object *pointer; +}; struct acpi_table_header; #define ACPI_SUCCESS(x) ((x) == 0) +#define ACPI_FAILURE(x) ((x) != 0) + +#define AE_ERROR 1 +#define AE_NOT_FOUND 2 +#define AE_BAD_PARAMETER 3 -#define AE_NOT_FOUND 0x0005 +acpi_status acpi_evaluate_object(acpi_handle, const char *, + struct acpi_object_list *, struct acpi_buffer *); +acpi_status acpi_get_handle(acpi_handle, const char *, acpi_handle *); +acpi_status acpi_get_name(acpi_handle, int, struct acpi_buffer *); acpi_status acpi_get_table(const char *, int, struct acpi_table_header **); +#define ACPI_FULL_PATHNAME 1 + +#define ACPI_VIDEO_CLASS "video" + +#define ACPI_VIDEO_NOTIFY_PROBE 0x81 + +#define ACPI_HANDLE(x) ((x)->node) + +const char *acpi_format_exception(acpi_status); + +struct notifier_block; + +int register_acpi_notifier(struct notifier_block *); +int unregister_acpi_notifier(struct notifier_block *); + #endif diff --git a/sys/dev/pci/drm/include/linux/backlight.h b/sys/dev/pci/drm/include/linux/backlight.h index a766ffdc2d3..cbf056d6977 100644 --- a/sys/dev/pci/drm/include/linux/backlight.h +++ b/sys/dev/pci/drm/include/linux/backlight.h @@ -31,6 +31,8 @@ struct backlight_device { #define BACKLIGHT_RAW 0 #define BACKLIGHT_FIRMWARE 1 +#define BACKLIGHT_UPDATE_HOTKEY 0 + struct backlight_device *backlight_device_register(const char *, void *, void *, const struct backlight_ops *, struct backlight_properties *); void backlight_device_unregister(struct backlight_device *); @@ -41,6 +43,12 @@ backlight_update_status(struct backlight_device *bd) bd->ops->update_status(bd); } +static inline void +backlight_force_update(struct backlight_device *bd, int reason) +{ + bd->props.brightness = bd->ops->get_brightness(bd); +} + void backlight_schedule_update_status(struct backlight_device *); #endif diff --git a/sys/dev/pci/drm/include/linux/kconfig.h b/sys/dev/pci/drm/include/linux/kconfig.h index 439c8f57879..86aa9464a9c 100644 --- a/sys/dev/pci/drm/include/linux/kconfig.h +++ b/sys/dev/pci/drm/include/linux/kconfig.h @@ -3,43 +3,17 @@ #ifndef _LINUX_KCONFIG_H #define _LINUX_KCONFIG_H -#include "agp.h" - #include <sys/endian.h> +#include <generated/autoconf.h> + #define IS_ENABLED(x) x - 0 #define IS_BUILTIN(x) 1 -#define CONFIG_DRM_FBDEV_EMULATION 1 -#define CONFIG_DRM_FBDEV_OVERALLOC 0 -#define CONFIG_BACKLIGHT_CLASS_DEVICE 1 -#define CONFIG_DRM_I915_DEBUG 0 -#define CONFIG_DRM_I915_DEBUG_GEM 0 -#define CONFIG_DRM_I915_FBDEV 1 -#define CONFIG_DRM_I915_ALPHA_SUPPORT 0 -#define CONFIG_DRM_I915_CAPTURE_ERROR 1 -#define CONFIG_DRM_I915_GVT 0 -#define CONFIG_DRM_I915_SW_FENCE_CHECK_DAG 0 -#define CONFIG_PM 0 -#define CONFIG_DRM_AMD_DC 1 -#define CONFIG_DRM_AMD_DC_DCN1_0 1 -#if 0 -#define CONFIG_DRM_AMDGPU_CIK 1 -#define CONFIG_DRM_AMDGPU_SI 1 -#endif - #if BYTE_ORDER == BIG_ENDIAN #define __BIG_ENDIAN #else #define __LITTLE_ENDIAN #endif -#if NAGP > 0 -#define CONFIG_AGP 1 -#endif - -#if defined(__amd64__) || defined(__i386__) -#define CONFIG_DMI 1 -#endif - #endif diff --git a/sys/dev/pci/drm/include/linux/notifier.h b/sys/dev/pci/drm/include/linux/notifier.h index ff376a2cc3f..e8030afff2d 100644 --- a/sys/dev/pci/drm/include/linux/notifier.h +++ b/sys/dev/pci/drm/include/linux/notifier.h @@ -4,7 +4,8 @@ #define _LINUX_NOTIFIER_H struct notifier_block { - void *notifier_call; + int (*notifier_call)(struct notifier_block *, unsigned long, void *); + SLIST_ENTRY(notifier_block) link; }; #define ATOMIC_INIT_NOTIFIER_HEAD(x) diff --git a/sys/dev/pci/drm/include/linux/pci.h b/sys/dev/pci/drm/include/linux/pci.h index 055ca68ca27..635463a40a3 100644 --- a/sys/dev/pci/drm/include/linux/pci.h +++ b/sys/dev/pci/drm/include/linux/pci.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pci.h,v 1.2 2019/07/15 03:35:23 jsg Exp $ */ +/* $OpenBSD: pci.h,v 1.3 2019/08/18 13:11:47 kettenis Exp $ */ /* * Copyright (c) 2015 Mark Kettenis * @@ -39,6 +39,10 @@ struct pci_bus { struct pci_dev *self; }; +struct pci_acpi { + struct aml_node *node; +}; + struct pci_dev { struct pci_bus _bus; struct pci_bus *bus; @@ -57,6 +61,8 @@ struct pci_dev { int irq; int msi_enabled; uint8_t no_64bit_msi; + + struct pci_acpi dev; }; #define PCI_ANY_ID (uint16_t) (~0U) @@ -273,6 +279,17 @@ pci_set_power_state(struct pci_dev *dev, int state) return 0; } +static inline struct pci_dev * +pci_get_class(pcireg_t class, struct pci_dev *pdev) +{ + return NULL; +} + +#define PCI_CLASS_DISPLAY_VGA \ + (PCI_CLASS_DISPLAY | PCI_SUBCLASS_DISPLAY_VGA) +#define PCI_CLASS_DISPLAY_OTHER \ + (PCI_CLASS_DISPLAY | PCI_SUBCLASS_DISPLAY_MISC) + #if defined(__amd64__) || defined(__i386__) #define PCI_DMA_BIDIRECTIONAL 0 diff --git a/sys/dev/pci/drm/radeon/radeon_bios.c b/sys/dev/pci/drm/radeon/radeon_bios.c index 182c4d87285..cdaf7c5b8bd 100644 --- a/sys/dev/pci/drm/radeon/radeon_bios.c +++ b/sys/dev/pci/drm/radeon/radeon_bios.c @@ -42,10 +42,6 @@ #include <machine/autoconf.h> #endif -#ifdef __HAVE_ACPI -#include "acpi.h" -#endif - /* * BIOS. */ @@ -738,10 +734,6 @@ static bool radeon_read_disabled_bios(struct radeon_device *rdev) return legacy_read_disabled_bios(rdev); } -#if NACPI > 0 -#define CONFIG_ACPI -#endif - #ifdef CONFIG_ACPI static bool radeon_acpi_vfct_bios(struct radeon_device *rdev) { |