Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Merge ACPI display driver. Provides generic support for...



details:   https://anonhg.NetBSD.org/src/rev/ee05803e5bf2
branches:  trunk
changeset: 758002:ee05803e5bf2
user:      gsutre <gsutre%NetBSD.org@localhost>
date:      Tue Oct 12 19:10:49 2010 +0000

description:
Merge ACPI display driver.  Provides generic support for brightness
control and output switching, through ACPI video extensions.

TODO: use wsconsctl(8) instead of sysctl(8) for brightness control.

ok jruoho@
also discussed with cegger@ and jmcneill@

diffstat:

 sys/arch/amd64/conf/GENERIC |     6 +-
 sys/arch/i386/conf/ALL      |     6 +-
 sys/arch/i386/conf/GENERIC  |     6 +-
 sys/dev/acpi/acpi.c         |     7 +-
 sys/dev/acpi/acpi_display.c |  2006 +++++++++++++++++++++++++++++++++++++++++++
 sys/dev/acpi/acpireg.h      |     3 +-
 sys/dev/acpi/files.acpi     |     9 +-
 7 files changed, 2031 insertions(+), 12 deletions(-)

diffs (truncated from 2161 to 300 lines):

diff -r db7dde00a0ba -r ee05803e5bf2 sys/arch/amd64/conf/GENERIC
--- a/sys/arch/amd64/conf/GENERIC       Tue Oct 12 16:18:19 2010 +0000
+++ b/sys/arch/amd64/conf/GENERIC       Tue Oct 12 19:10:49 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.285 2010/08/22 18:56:21 rmind Exp $
+# $NetBSD: GENERIC,v 1.286 2010/10/12 19:10:49 gsutre Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "GENERIC-$Revision: 1.285 $"
+#ident                 "GENERIC-$Revision: 1.286 $"
 
 maxusers       64              # estimated number of users
 
@@ -284,6 +284,8 @@
 acpilid*       at acpi?                # ACPI Lid Switch
 #acpismbus*    at acpi?                # ACPI SMBus CMI (experimental)
 acpitz*        at acpi?                # ACPI Thermal Zone
+acpivga*       at acpi?                # ACPI Display Adapter
+acpiout*       at acpivga?             # ACPI Display Output Device
 acpiwmi*       at acpi?                # ACPI WMI Mapper
 
 # Mainboard devices
diff -r db7dde00a0ba -r ee05803e5bf2 sys/arch/i386/conf/ALL
--- a/sys/arch/i386/conf/ALL    Tue Oct 12 16:18:19 2010 +0000
+++ b/sys/arch/i386/conf/ALL    Tue Oct 12 19:10:49 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.267 2010/08/22 18:56:21 rmind Exp $
+# $NetBSD: ALL,v 1.268 2010/10/12 19:10:50 gsutre Exp $
 # From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
 #
 # ALL machine description file
@@ -17,7 +17,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "ALL-$Revision: 1.267 $"
+#ident                 "ALL-$Revision: 1.268 $"
 
 maxusers       64              # estimated number of users
 
@@ -375,6 +375,8 @@
 # XXX the same bus, and bad things (tm) will happen!
 acpismbus*     at acpi?                # ACPI SMBus CMI (experimental)
 acpitz*        at acpi?                # ACPI Thermal Zone
+acpivga*       at acpi?                # ACPI Display Adapter
+acpiout*       at acpivga?             # ACPI Display Output Device
 acpiwmi*       at acpi?                # ACPI WMI Mapper
 
 # Mainboard devices
diff -r db7dde00a0ba -r ee05803e5bf2 sys/arch/i386/conf/GENERIC
--- a/sys/arch/i386/conf/GENERIC        Tue Oct 12 16:18:19 2010 +0000
+++ b/sys/arch/i386/conf/GENERIC        Tue Oct 12 19:10:49 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.993 2010/08/22 18:56:21 rmind Exp $
+# $NetBSD: GENERIC,v 1.994 2010/10/12 19:10:50 gsutre Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "GENERIC-$Revision: 1.993 $"
+#ident                 "GENERIC-$Revision: 1.994 $"
 
 maxusers       64              # estimated number of users
 
@@ -364,6 +364,8 @@
 acpilid*       at acpi?                # ACPI Lid Switch
 #acpismbus*    at acpi?                # ACPI SMBus CMI (experimental)
 acpitz*        at acpi?                # ACPI Thermal Zone
+acpivga*       at acpi?                # ACPI Display Adapter
+acpiout*       at acpivga?             # ACPI Display Output Device
 acpiwmi*       at acpi?                # ACPI WMI Mapper
 
 # Mainboard devices
diff -r db7dde00a0ba -r ee05803e5bf2 sys/dev/acpi/acpi.c
--- a/sys/dev/acpi/acpi.c       Tue Oct 12 16:18:19 2010 +0000
+++ b/sys/dev/acpi/acpi.c       Tue Oct 12 19:10:49 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi.c,v 1.220 2010/10/02 18:06:47 gsutre Exp $        */
+/*     $NetBSD: acpi.c,v 1.221 2010/10/12 19:10:50 gsutre Exp $        */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.220 2010/10/02 18:06:47 gsutre Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.221 2010/10/12 19:10:50 gsutre Exp $");
 
 #include "opt_acpi.h"
 #include "opt_pcifixup.h"
@@ -665,11 +665,10 @@
        /*
         * Scan the internal namespace.
         */
+       (void)acpi_pcidev_scan(sc->sc_root);
        (void)acpi_rescan(sc->sc_dev, NULL, NULL);
 
        acpi_rescan_capabilities(sc);
-
-       (void)acpi_pcidev_scan(sc->sc_root);
 }
 
 static ACPI_STATUS
diff -r db7dde00a0ba -r ee05803e5bf2 sys/dev/acpi/acpi_display.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/acpi/acpi_display.c       Tue Oct 12 19:10:49 2010 +0000
@@ -0,0 +1,2006 @@
+/*     $NetBSD: acpi_display.c,v 1.1 2010/10/12 19:10:50 gsutre Exp $  */
+
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Gregoire Sutre.
+ *
+ * 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.
+ */
+
+/*
+ * ACPI Display Adapter Driver.
+ *
+ * Appendix B of the ACPI specification presents ACPI extensions for display
+ * adapters.  Systems containing a built-in display adapter are required to
+ * implement these extensions (in their ACPI BIOS).  This driver uses these
+ * extensions to provide generic support for brightness control and display
+ * switching.
+ *
+ * If brightness control methods are absent or non-functional, ACPI brightness
+ * notifications are relayed to the PMF framework.
+ *
+ * This driver sets the BIOS switch policy (_DOS method) as follows:
+ * - The BIOS should automatically switch the active display output, with no
+ *   interaction required on the OS part.
+ * - The BIOS should not automatically control the brightness levels.
+ *
+ * Brightness and BIOS switch policy can be adjusted from userland, via the
+ * sysctl variables acpivga<n>.policy and acpiout<n>.brightness under hw.acpi.
+ */
+
+/*
+ * The driver uses mutex(9) protection since changes to the hardware/software
+ * state may be initiated both by the BIOS (ACPI notifications) and by the user
+ * (sysctl).  The ACPI display adapter's mutex is shared with all ACPI display
+ * output devices attached to it.
+ *
+ * The mutex only prevents undesired interleavings of ACPI notify handlers,
+ * sysctl callbacks, and pmf(9) suspend/resume routines.  Race conditions with
+ * autoconf(9) detachment routines could, in theory, still occur.
+ *
+ * The array of connected output devices (sc_odinfo) is, after attachment, only
+ * used in ACPI notify handler callbacks.  Since two such callbacks cannot be
+ * running simultaneously, this information does not need protection.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: acpi_display.c,v 1.1 2010/10/12 19:10:50 gsutre Exp $");
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/kmem.h>
+#include <sys/mutex.h>
+#include <sys/sysctl.h>
+#include <sys/systm.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcidevs.h>
+
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+
+#define _COMPONENT             ACPI_DISPLAY_COMPONENT
+ACPI_MODULE_NAME               ("acpi_display")
+
+/* Type for integer values that are passed to/from ACPICA. */
+#define ACPI_UINT64    uint64_t
+
+/* Notifications specific to display adapter devices (ACPI 4.0a, Sec. B.5). */
+#define ACPI_NOTIFY_CycleOutputDevice                  0x80
+#define ACPI_NOTIFY_OutputDeviceStatusChange           0x81
+#define ACPI_NOTIFY_CycleDisplayOutputHotkeyPressed    0x82
+#define ACPI_NOTIFY_NextDisplayOutputHotkeyPressed     0x83
+#define ACPI_NOTIFY_PreviousDisplayOutputHotkeyPressed 0x84
+
+/* Notifications specific to display output devices (ACPI 4.0a, Sec. B.7). */
+#define ACPI_NOTIFY_CycleBrightness                    0x85
+#define ACPI_NOTIFY_IncreaseBrightness                 0x86
+#define ACPI_NOTIFY_DecreaseBrightness                 0x87
+#define ACPI_NOTIFY_ZeroBrightness                     0x88
+#define ACPI_NOTIFY_DisplayDeviceOff                   0x89
+
+/* Format of the BIOS switch policy set by _DOS (ACPI 4.0a, Sec. B.4.1). */
+typedef union acpidisp_bios_policy_t {
+       uint8_t                 raw;
+       struct {
+               uint8_t         output:2;
+               uint8_t         brightness:1;
+               uint8_t         reserved:5;
+       } __packed              fmt;
+} acpidisp_bios_policy_t;
+
+/* Default BIOS switch policy (ACPI 4.0a, Sec. B.4.1). */
+static const acpidisp_bios_policy_t acpidisp_default_bios_policy = {
+       .raw = 0x1
+};
+
+/* BIOS output switch policies (ACPI 4.0a, Sec. B.4.1). */
+#define ACPI_DISP_POLICY_OUTPUT_NORMAL         0x0
+#define ACPI_DISP_POLICY_OUTPUT_AUTO           0x1
+#define ACPI_DISP_POLICY_OUTPUT_LOCKED         0x2
+#define ACPI_DISP_POLICY_OUTPUT_HOTKEY         0x3
+
+/* BIOS brightness switch policies (ACPI 4.0a, Sec. B.4.1). */
+#define ACPI_DISP_POLICY_BRIGHTNESS_AUTO       0x0
+#define ACPI_DISP_POLICY_BRIGHTNESS_NORMAL     0x1
+
+/* Format of output device attributes (ACPI 4.0a, Table B-2). */
+typedef union acpidisp_od_attrs_t {
+       uint16_t                device_id;
+       uint32_t                raw;
+       struct {
+               uint8_t         index:4;
+               uint8_t         port:4;
+               uint8_t         type:4;
+               uint8_t         vendor_specific:4;
+               uint8_t         bios_detect:1;
+               uint8_t         non_vga:1;
+               uint8_t         head_id:3;
+               uint16_t        reserved:10;
+               uint8_t         device_id_scheme:1;
+       } __packed              fmt;
+} acpidisp_od_attrs_t;
+
+/* Common legacy output device IDs (ACPI 2.0c, Table B-3). */
+#define ACPI_DISP_OUT_LEGACY_DEVID_MONITOR     0x0100
+#define ACPI_DISP_OUT_LEGACY_DEVID_PANEL       0x0110
+#define ACPI_DISP_OUT_LEGACY_DEVID_TV          0x0200
+
+/* Output device display types (ACPI 4.0a, Table B-2). */
+#define ACPI_DISP_OUT_ATTR_TYPE_OTHER          0x0
+#define ACPI_DISP_OUT_ATTR_TYPE_VGA            0x1
+#define ACPI_DISP_OUT_ATTR_TYPE_TV             0x2
+#define ACPI_DISP_OUT_ATTR_TYPE_EXTDIG         0x3
+#define ACPI_DISP_OUT_ATTR_TYPE_INTDFP         0x4
+
+/* Format of output device status (ACPI 4.0a, Table B-4). */
+typedef union acpidisp_od_status_t {
+       uint32_t                raw;
+       struct {
+               uint8_t         exists:1;
+               uint8_t         activated:1;
+               uint8_t         ready:1;
+               uint8_t         not_defective:1;
+               uint8_t         attached:1;
+               uint32_t        reserved:27;
+       } __packed              fmt;
+} acpidisp_od_status_t;
+
+/* Format of output device state (ACPI 4.0a, Table B-6). */
+typedef union acpidisp_od_state_t {
+       uint32_t                raw;
+       struct {
+               uint8_t         active:1;
+               uint32_t        reserved:29;
+               uint8_t         no_switch:1;
+               uint8_t         commit:1;
+       } __packed              fmt;
+} acpidisp_od_state_t;
+
+/*
+ * acpidisp_outdev:
+ *



Home | Main Index | Thread Index | Old Index