ACPI OpRegion support for Intel Integrated Graphics is meant to improve
the communication mechanisms between graphcis driver and system/video BIOS.

The Intel graphics driver stack is composed of several different modules:
kernel drivers, user level drivers, the video BIOS, system BIOS, 
and pre-programmed firmware tables. Communication between these various
components is complex and highly platform dependent in the past.

ACPI IGD OpRegion interface is intended to replace the various
inter-module communication schemes described above, particularly the
INT 10h and SMI mechanisms. With the new OpRegion interface,
system/video BIOS will send requests to kernel graphic driver for
configuring graphic hardware. With the graphic driver being the only
place to configure graphic hardware, many stability issues we encounter
in the current Linux graphics will be eliminated.

The patch is very simple now, we only enable the "driver ready" field in
the OpRegion memory. But it is needed by new platforms shipped with
intel-opregion-ready vbios. Otherwise hotkey may not work on these
platforms, since vbios will not do anything when "driver is not ready".
ACPI video driver will not receive any VGA notifications from vbios.

We can do more things when the kernel modesetting branch is ready.

Thanks,
Hong


---
 linux-core/Makefile.kernel  |    2 +-
 linux-core/i915_drv.c       |    4 +
 linux-core/intel_opregion.c |  411 +++++++++++++++++++++++++++++++++++++++++++
 shared-core/i915_dma.c      |    8 +
 shared-core/i915_drv.h      |   25 +++-
 shared-core/i915_irq.c      |    5 +
 6 files changed, 453 insertions(+), 2 deletions(-)
 create mode 100644 linux-core/intel_opregion.c

diff --git a/linux-core/Makefile.kernel b/linux-core/Makefile.kernel
index f012262..2bdd57f 100644
--- a/linux-core/Makefile.kernel
+++ b/linux-core/Makefile.kernel
@@ -20,7 +20,7 @@ r128-objs   := r128_drv.o r128_cce.o r128_state.o r128_irq.o
 mga-objs    := mga_drv.o mga_dma.o mga_state.o mga_warp.o mga_irq.o
 i810-objs   := i810_drv.o i810_dma.o
 i915-objs   := i915_drv.o i915_dma.o i915_irq.o i915_mem.o i915_fence.o \
-               i915_buffer.o i915_compat.o i915_execbuf.o
+               i915_buffer.o i915_compat.o i915_execbuf.o intel_opregion.o
 nouveau-objs := nouveau_drv.o nouveau_state.o nouveau_fifo.o nouveau_mem.o \
                nouveau_object.o nouveau_irq.o nouveau_notifier.o 
nouveau_swmthd.o \
                nouveau_sgdma.o nouveau_dma.o nouveau_bo.o nouveau_fence.o \
diff --git a/linux-core/i915_drv.c b/linux-core/i915_drv.c
index e18bc8d..bac07ce 100644
--- a/linux-core/i915_drv.c
+++ b/linux-core/i915_drv.c
@@ -392,6 +392,8 @@ static int i915_suspend(struct drm_device *dev, 
pm_message_t state)
 
        i915_save_vga(dev);
 
+       intel_opregion_free(dev);
+
        if (state.event == PM_EVENT_SUSPEND) {
                /* Shut down the device */
                pci_disable_device(dev->pdev);
@@ -549,6 +551,8 @@ static int i915_resume(struct drm_device *dev)
 
        i915_restore_vga(dev);
 
+       intel_opregion_init(dev);
+
        return 0;
 }
 
diff --git a/linux-core/intel_opregion.c b/linux-core/intel_opregion.c
new file mode 100644
index 0000000..5e64b51
--- /dev/null
+++ b/linux-core/intel_opregion.c
@@ -0,0 +1,411 @@
+#include <linux/acpi.h>
+
+#include "drmP.h"
+#include "i915_drm.h"
+#include "i915_drv.h"
+
+#define PCI_ASLE 0xe4
+#define PCI_ASLS 0xfc
+
+#define OPREGION_SZ            (8*1024)
+#define OPREGION_HEADER_OFFSET 0
+#define OPREGION_ACPI_OFFSET   0x100
+#define OPREGION_SWSCI_OFFSET  0x200
+#define OPREGION_ASLE_OFFSET   0x300
+#define OPREGION_VBT_OFFSET    0x1000
+
+#define OPREGION_SIGNATURE "IntelGraphicsMem"
+#define MBOX_ACPI      (1<<0)
+#define MBOX_SWSCI     (1<<1)
+#define MBOX_ASLE      (1<<2)
+
+/* _DOD id definitions */
+#define OUTPUT_CONNECTOR_MSK   0xf000
+#define OUTPUT_CONNECTOR_OFFSET        12
+
+#define OUTPUT_PORT_MSK                0x00f0
+#define OUTPUT_PORT_OFFSET     4
+  #define OUTPUT_PORT_ANALOG   0
+  #define OUTPUT_PORT_LVDS     1
+  #define OUTPUT_PORT_SDVOB    2
+  #define OUTPUT_PORT_SDVOC    3
+  #define OUTPUT_PORT_TV       4
+
+#define OUTPUT_DISPLAY_MSK     0x0f00
+#define OUTPUT_DISPLAY_OFFSET  8
+  #define OUTPUT_DISPLAY_OTHER         0
+  #define OUTPUT_DISPLAY_VGA           1
+  #define OUTPUT_DISPLAY_TV            2
+  #define OUTPUT_DISPLAY_DIGI          3
+  #define OUTPUT_DISPLAY_FLAT_PANEL    4
+
+/* predefined id for integrated LVDS and VGA connector */
+#define OUTPUT_INT_LVDS        0x00000110
+#define OUTPUT_INT_VGA 0x80000100
+
+struct opregion_header {
+       u8 signature[16];
+       u32 size;
+       u32 opregion_ver;
+       u8 bios_ver[32];
+       u8 vbios_ver[16];
+       u8 driver_ver[16];
+       u32 mboxes;
+       u8 reserved[164];
+} __attribute__((packed));
+
+/* OpRegion mailbox #1: public ACPI methods */
+struct opregion_acpi {
+       u32 drdy;       /* driver readiness */
+       u32 csts;       /* notification status */
+       u32 cevt;       /* current event */
+       u8 rsvd1[20];
+       u32 didl[8];    /* supported display devices ID list */
+       u32 cpdl[8];    /* currently presented display list */
+       u32 cadl[8];    /* currently active display list */
+       u32 nadl[8];    /* next active devices list */
+       u32 aslp;       /* ASL sleep time-out */
+       u32 tidx;       /* toggle table index */
+       u32 chpd;       /* current hotplug enable indicator */
+       u32 clid;       /* current lid state*/
+       u32 cdck;       /* current docking state */
+       u32 sxsw;       /* Sx state resume */
+       u32 evts;       /* ASL supported events */
+       u32 cnot;       /* current OS notification */
+       u32 nrdy;       /* driver status */
+       u8 rsvd2[60];
+} __attribute__((packed));
+
+/* OpRegion mailbox #2: SWSCI */
+struct opregion_swsci {
+       u32 scic;       /* SWSCI command|status|data */
+       u32 parm;       /* command parameters */
+       u32 dslp;       /* driver sleep time-out */
+       u8 rsvd[244];
+} __attribute__((packed));
+
+/* OpRegion mailbox #3: ASLE */
+struct opregion_asle {
+       u32 ardy;       /* driver readiness */
+       u32 aslc;       /* ASLE interrupt command */
+       u32 tche;       /* technology enabled indicator */
+       u32 alsi;       /* current ALS illuminance reading */
+       u32 bclp;       /* backlight brightness to set */
+       u32 pfit;       /* panel fitting state */
+       u32 cblv;       /* current brightness level */
+       u16 bclm[20];   /* backlight level duty cycle mapping table */
+       u32 cpfm;       /* current panel fitting mode */
+       u32 epfm;       /* enabled panel fitting modes */
+       u8 plut[74];    /* panel LUT and identifier */
+       u32 pfmb;       /* PWM freq and min brightness */
+       u8 rsvd[102];
+} __attribute__((packed));
+
+#if 0
+void opregion_set_display_devs(struct drm_device *dev,
+                       struct opregion_acpi *acpi)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       struct drm_output *output;
+       int i = 0, j = 0;
+
+       /*
+        we may need walk through the drm_output list for update
+        these fields:
+        update current attached
+        update current active
+        update current next_active
+       */
+       mutex_lock(&dev->mode_config.mutex);
+
+       list_for_each_entry(output, &dev->mode_config.output_list, head) {
+               struct intel_output *intel_output = output->driver_private;
+
+               switch (intel_output->type) {
+               case INTEL_OUTPUT_ANALOG:
+                       if (output->status == output_status_connected) {
+                               acpi->cadl[i++] = OUTPUT_INT_VGA;
+                               acpi->cpdl[j++] = OUTPUT_INT_VGA; //??
+                       }
+                       break;
+
+               case INTEL_OUTPUT_LVDS:
+                       if (output->status == output_status_connected) {
+                               acpi->cadl[i++] = OUTPUT_INT_LVDS;
+                               acpi->cpdl[j++] = OUTPUT_INT_LVDS; //??
+                       }
+                       break;
+
+               default:
+                       DRM_DEBUG("unknow output type!\n");
+
+               }
+       }
+       acpi->cadl[i] = acpi->cpdl[j] = 0;
+
+       mutex_unlock(&dev->mode_config.mutex);
+}
+
+static int opregion_set_supp_devs(struct drm_device *dev,
+                               struct opregion_acpi *acpi)
+{
+       int i = 0;
+
+       if (IS_MOBILE(dev))
+               acpi->didl[i++] = OUTPUT_INT_LVDS;
+
+       acpi->didl[i++] = OUTPUT_INT_VGA;
+
+       if (i < 8)
+               acpi->didl[i] = 0;
+
+       return i;
+}
+#endif
+
+/* ASLE irq request bits */
+#define ASLE_SET_ALS_ILLUM     (1 << 0)
+#define ASLE_SET_BACKLIGHT     (1 << 1)
+#define ASLE_SET_PFIT          (1 << 2)
+#define ASLE_SET_PWM_FREQ      (1 << 3)
+#define ASLE_REQ_MSK           0xf
+
+/* response bits of ASLE irq request */
+#define ASLE_ALS_ILLUM_FAIL    (2<<10)
+#define ASLE_BACKLIGHT_FAIL    (2<<12)
+#define ASLE_PFIT_FAIL         (2<<14)
+#define ASLE_PWM_FREQ_FAIL     (2<<16)
+
+/* ASLE backlight brightness to set */
+#define ASLE_BCLP_VALID                (1<<31)
+#define ASLE_BCLP_MSK          (~(1<<31))
+
+static u32 asle_set_backlight(struct drm_device *dev, u32 bclp)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       u32 blc_pwm_ctl;
+
+       if (!(bclp & ASLE_BCLP_VALID))
+               return ASLE_BACKLIGHT_FAIL;
+
+       bclp &= ASLE_BCLP_MSK;
+       if (bclp < 0 || bclp > 255)
+               return ASLE_BACKLIGHT_FAIL;
+
+       blc_pwm_ctl = I915_READ(BLC_PWM_CTL);
+       blc_pwm_ctl &= ~BACKLIGHT_DUTY_CYCLE_MASK;
+       I915_WRITE(BLC_PWM_CTL,
+                  blc_pwm_ctl | (bclp << BACKLIGHT_DUTY_CYCLE_SHIFT));
+       return 0;
+}
+
+static u32 asle_set_als_illum(struct drm_device *dev, u32 alsi)
+{
+       return 0;
+}
+
+static u32 asle_set_pwm_freq(struct drm_device *dev, u32 pfmb)
+{
+       return 0;
+}
+
+static u32 asle_set_pfit(struct drm_device *dev, u32 pfit)
+{
+       return 0;
+}
+
+void opregion_asle_intr(struct drm_device *dev)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       struct opregion_asle *asle = dev_priv->opregion.asle;
+       u32 asle_req = asle->aslc & ASLE_REQ_MSK;
+       u32 asle_stat = 0;
+
+       if (!asle)
+               return;
+
+       if (!asle_req) {
+               DRM_DEBUG("non asle set request??\n");
+               return;
+       }
+
+       if (asle_req & ASLE_SET_ALS_ILLUM)
+               asle_stat |= asle_set_als_illum(dev, asle->alsi);
+
+       if (asle_req & ASLE_SET_BACKLIGHT)
+               asle_stat |= asle_set_backlight(dev, asle->bclp);
+
+       if (asle_req & ASLE_SET_PFIT)
+               asle_stat |= asle_set_pfit(dev, asle->pfit);
+
+       if (asle_req & ASLE_SET_PWM_FREQ)
+               asle_stat |= asle_set_pwm_freq(dev, asle->pfmb);
+
+       asle->aslc = asle_stat;
+}
+
+#define ASLE_ASL_EN    (1<<0)
+#define ASLE_BLC_EN    (1<<1)
+#define ASLE_PFIT_EN   (1<<2)
+#define ASLE_PFMB_EN   (1<<3)
+
+void opregion_enable_asle(struct drm_device *dev)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       struct opregion_asle *asle = dev_priv->opregion.asle;
+
+       if (asle) {
+               dev_priv->irq_enable_reg |= I915_ASLE_INTERRUPT;
+
+               /* we will handle backlight control */
+               asle->tche = ASLE_BLC_EN;
+               asle->ardy = 1;
+       }
+}
+
+#define ACPI_EV_DISPLAY_SWITCH (1<<0)
+#define ACPI_EV_LID            (1<<1)
+#define ACPI_EV_DOCK           (1<<2)
+
+static struct intel_opregion *only_for_acpi_video_notif;
+
+int intel_opregion_video_event(struct notifier_block *nb, unsigned long val,
+                               void *data)
+{
+       struct opregion_acpi *acpi;
+       struct acpi_bus_event *event = data;
+
+       DRM_DEBUG("enter\n");
+
+       /* Currenlty acpi only call notifier_chain when
+        * receiving video notification. No need to check now. */
+#if 0
+       /* only handle acpi video notification */
+       if (event < 0x80 || event > 0x90)
+               return NOTIFY_DONE;
+#endif
+
+       if (!only_for_acpi_video_notif)
+               return NOTIFY_DONE;
+
+       DRM_DEBUG("event num: 0x%x\n", event->type);
+
+       acpi = only_for_acpi_video_notif->acpi;
+
+       /* check the current event */
+       if (acpi->cevt & ACPI_EV_DISPLAY_SWITCH) {
+               DRM_DEBUG("display switch hot-key pressed\n");
+       } else if (acpi->cevt & ACPI_EV_LID) {
+               DRM_DEBUG("lid open/close event\n");
+               /* check acpi->clid for detailed state */
+       } else if (acpi->cevt & ACPI_EV_DOCK) {
+               DRM_DEBUG("dock/undock event\n");
+               /* check acpi->cdck for docking state, we may need to
+                * increase/decreate backlight brigtness accordingly */ 
+       }
+
+       /* currently just set to Success */
+       acpi->csts = 0;
+       DRM_DEBUG("exit\n");
+
+       return NOTIFY_OK;
+}
+
+static struct notifier_block intel_opregion_notifier = {
+       .notifier_call = intel_opregion_video_event,
+};
+
+int intel_opregion_init(struct drm_device *dev)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       struct intel_opregion *opregion = &dev_priv->opregion;
+       void *base;
+       u32 asls, mboxes;
+       int err = 0;
+
+       pci_read_config_dword(dev->pdev, PCI_ASLS, &asls);
+       DRM_DEBUG("graphic opregion physical addr: 0x%x\n", asls);
+       if (asls == 0) {
+               DRM_DEBUG("ACPI OpRegion not supported!\n");
+               return -ENOTSUPP;
+       }
+
+       base = ioremap(asls, OPREGION_SZ);
+       if (!base)
+               return -ENOMEM;
+
+       opregion->header = base;
+       if (memcmp(opregion->header->signature, OPREGION_SIGNATURE, 16)) {
+               DRM_DEBUG("opregion signature mismatch\n");
+               err = -EINVAL;
+               goto err_out;
+       }
+
+       mboxes = opregion->header->mboxes;
+       if (mboxes & MBOX_ACPI) {
+               DRM_DEBUG("Public ACPI methods supported\n");
+               opregion->acpi = base + OPREGION_ACPI_OFFSET;
+       } else {
+               DRM_DEBUG("Public ACPI methods not supported\n");
+               err = -ENOTSUPP;
+               goto err_out;
+       }
+       opregion->enabled = 1;
+
+       if (mboxes & MBOX_SWSCI) {
+               DRM_DEBUG("SWSCI supported\n");
+               opregion->swsci = base + OPREGION_SWSCI_OFFSET;
+       }
+       if (mboxes & MBOX_ASLE) {
+               DRM_DEBUG("ASLE supported\n");
+               opregion->asle = base + OPREGION_ASLE_OFFSET;
+       }
+
+       //opregion_set_display_devs(dev, opregion->acpi);
+
+#if 0
+       /* enable ASLE interrupt */
+       if (opregion->asle)
+               opregion_asle_init(dev, opregion->asle);
+       /* we have to enable asle interrupt in i915_enable_interrupt?? */
+#endif
+
+       /* Notify BIOS we are ready to handle ACPI video ext notifs.
+        * We don't do anything now, hoping BIOS will not also.
+        * BIOS will just send VGA notifications to ACPI video driver
+        * which will send the notifications to kernel input layer.*/
+       opregion->acpi->drdy = 1;
+
+       only_for_acpi_video_notif = opregion;
+       register_acpi_notifier(&intel_opregion_notifier);
+
+       return 0;
+
+err_out:
+       iounmap(opregion->header);
+       opregion->header = NULL;
+       return err;
+}
+
+void intel_opregion_free(struct drm_device *dev)
+{
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       struct intel_opregion *opregion = &dev_priv->opregion;
+
+       if (!opregion->enabled)
+               return;
+
+       opregion->acpi->drdy = 0;
+
+       only_for_acpi_video_notif = NULL;
+       unregister_acpi_notifier(&intel_opregion_notifier);
+
+       /* just clear all opregion memory pointers now */
+       iounmap(opregion->header);
+       opregion->header = NULL;
+       opregion->acpi = NULL;
+       opregion->swsci = NULL;
+       opregion->asle = NULL;
+
+       opregion->enabled = 0;
+}
diff --git a/shared-core/i915_dma.c b/shared-core/i915_dma.c
index 1e493e3..77d8134 100644
--- a/shared-core/i915_dma.c
+++ b/shared-core/i915_dma.c
@@ -1036,6 +1036,10 @@ int i915_driver_load(struct drm_device *dev, unsigned 
long flags)
 #endif
 #endif
 
+#ifdef __linux__
+       intel_opregion_init(dev);
+#endif
+
        return ret;
 }
 
@@ -1046,6 +1050,10 @@ int i915_driver_unload(struct drm_device *dev)
        if (dev_priv->mmio_map)
                drm_rmmap(dev, dev_priv->mmio_map);
 
+#ifdef __linux__
+       intel_opregion_free(dev);
+#endif
+
        drm_free(dev->dev_private, sizeof(drm_i915_private_t),
                 DRM_MEM_DRIVER);
 #ifdef __linux__
diff --git a/shared-core/i915_drv.h b/shared-core/i915_drv.h
index 59f515c..9f5da36 100644
--- a/shared-core/i915_drv.h
+++ b/shared-core/i915_drv.h
@@ -100,6 +100,21 @@ typedef struct _drm_i915_vbl_swap {
        int flip;
 } drm_i915_vbl_swap_t;
 
+struct opregion_header;
+struct opregion_acpi;
+struct opregion_swsci;
+struct opregion_asle;
+
+struct intel_opregion {
+       //spinlock_t lock;
+       struct opregion_header *header;
+       struct opregion_acpi *acpi;
+       struct opregion_swsci *swsci;
+       struct opregion_asle *asle;
+
+       int enabled;
+};
+
 typedef struct drm_i915_private {
        drm_local_map_t *sarea;
        drm_local_map_t *mmio_map;
@@ -153,6 +168,8 @@ typedef struct drm_i915_private {
        struct drm_buffer_object *sarea_bo;
        struct drm_bo_kmap_obj sarea_kmap;
 
+       struct intel_opregion opregion;
+
        /* Register state */
        u8 saveLBB;
        u32 saveDSPACNTR;
@@ -330,6 +347,12 @@ int i915_execbuffer(struct drm_device *dev, void *data,
 
 #endif
 
+/* intel_opregion.c */
+extern int intel_opregion_init(struct drm_device *dev);
+extern void intel_opregion_free(struct drm_device *dev);
+extern void opregion_asle_intr(struct drm_device *dev);
+extern void opregion_enable_asle(struct drm_device *dev);
+
 #ifdef __linux__
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
 extern void intel_init_chipset_flush_compat(struct drm_device *dev);
@@ -492,7 +515,7 @@ extern int i915_wait_ring(struct drm_device * dev, int n, 
const char *caller);
 #define I915_DISPLAY_PIPE_B_EVENT_INTERRUPT            (1<<4)
 #define I915_DEBUG_INTERRUPT                           (1<<2)
 #define I915_USER_INTERRUPT                            (1<<1)
-
+#define I915_ASLE_INTERRUPT                            (1<<0)
 
 #define I915REG_HWSTAM         0x02098
 #define I915REG_INT_IDENTITY_R 0x020a4
diff --git a/shared-core/i915_irq.c b/shared-core/i915_irq.c
index a9b67a9..b4cc225 100644
--- a/shared-core/i915_irq.c
+++ b/shared-core/i915_irq.c
@@ -477,6 +477,9 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
                        drm_locked_tasklet(dev, i915_vblank_tasklet);
        }
 
+       if (iir & I915_ASLE_INTERRUPT)
+               opregion_asle_intr(dev);
+
        return IRQ_HANDLED;
 }
 
@@ -678,6 +681,8 @@ static void i915_enable_interrupt (struct drm_device *dev)
        
        dev_priv->irq_enable_reg |= I915_USER_INTERRUPT;
 
+       opregion_enable_asle(dev);
+
        I915_WRITE(I915REG_INT_ENABLE_R, dev_priv->irq_enable_reg);
        dev_priv->irq_enabled = 1;
 }
-- 
1.5.0.5





-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
--
_______________________________________________
Dri-devel mailing list
Dri-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dri-devel

Reply via email to