[PATCH 1/2] drm/gma500/psb: Unpin framebuffer on crtc disable

2013-06-08 Thread Daniel Vetter
On Sat, Jun 08, 2013 at 09:07:33PM +0200, Patrik Jakobsson wrote:
> On Sat, Jun 8, 2013 at 9:01 PM, Patrik Jakobsson
>  wrote:
> > The framebuffer needs to be unpinned in the crtc->disable callback
> > because of previous pinning in psb_intel_pipe_set_base(). This will fix
> > a memory leak where the framebuffer was released but not unpinned
> > properly. This patch only affects Poulsbo.
> >
> > Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=889511
> > Bugzilla: https://bugzilla.novell.com/show_bug.cgi?id=812113
> > Signed-off-by: Patrik Jakobsson 
> > ---
> >  drivers/gpu/drm/gma500/psb_intel_display.c | 14 ++
> >  1 file changed, 14 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/gma500/psb_intel_display.c 
> > b/drivers/gpu/drm/gma500/psb_intel_display.c
> > index 6e8f42b..12d129e 100644
> > --- a/drivers/gpu/drm/gma500/psb_intel_display.c
> > +++ b/drivers/gpu/drm/gma500/psb_intel_display.c
> > @@ -1150,6 +1150,19 @@ static void psb_intel_crtc_destroy(struct drm_crtc 
> > *crtc)
> > kfree(psb_intel_crtc);
> >  }
> >
> > +static void psb_intel_crtc_disable(struct drm_crtc *crtc)
> > +{
> > +   struct gtt_range *gt;
> > +   struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
> > +
> > +   crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
> > +
> > +   if (crtc->fb) {
> > +   gt = to_psb_fb(crtc->fb)->gtt;
> > +   psb_gtt_unpin(gt);
> > +   }
> > +}
> > +
> >  const struct drm_crtc_helper_funcs psb_intel_helper_funcs = {
> > .dpms = psb_intel_crtc_dpms,
> > .mode_fixup = psb_intel_crtc_mode_fixup,
> > @@ -1157,6 +1170,7 @@ const struct drm_crtc_helper_funcs 
> > psb_intel_helper_funcs = {
> > .mode_set_base = psb_intel_pipe_set_base,
> > .prepare = psb_intel_crtc_prepare,
> > .commit = psb_intel_crtc_commit,
> > +   .disable = psb_intel_crtc_disable,
> >  };
> >
> >  const struct drm_crtc_funcs psb_intel_crtc_funcs = {
> > --
> > 1.8.1.2
> >
> 
> Dave, this is a "less hackish" fix to the framebuffer leak bug I've been 
> having.
> Daniel Vetter suggested this approach and it works as expected. ACK or NACK?

Yeah, this is how we've done it in i915 before switching away from crtc
helpers. For both patches:

Reviewed-by: Daniel Vetter 
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch


[PATCH 1/2] drm/gma500/psb: Unpin framebuffer on crtc disable

2013-06-08 Thread Patrik Jakobsson
On Sat, Jun 8, 2013 at 9:01 PM, Patrik Jakobsson
 wrote:
> The framebuffer needs to be unpinned in the crtc->disable callback
> because of previous pinning in psb_intel_pipe_set_base(). This will fix
> a memory leak where the framebuffer was released but not unpinned
> properly. This patch only affects Poulsbo.
>
> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=889511
> Bugzilla: https://bugzilla.novell.com/show_bug.cgi?id=812113
> Signed-off-by: Patrik Jakobsson 
> ---
>  drivers/gpu/drm/gma500/psb_intel_display.c | 14 ++
>  1 file changed, 14 insertions(+)
>
> diff --git a/drivers/gpu/drm/gma500/psb_intel_display.c 
> b/drivers/gpu/drm/gma500/psb_intel_display.c
> index 6e8f42b..12d129e 100644
> --- a/drivers/gpu/drm/gma500/psb_intel_display.c
> +++ b/drivers/gpu/drm/gma500/psb_intel_display.c
> @@ -1150,6 +1150,19 @@ static void psb_intel_crtc_destroy(struct drm_crtc 
> *crtc)
> kfree(psb_intel_crtc);
>  }
>
> +static void psb_intel_crtc_disable(struct drm_crtc *crtc)
> +{
> +   struct gtt_range *gt;
> +   struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
> +
> +   crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
> +
> +   if (crtc->fb) {
> +   gt = to_psb_fb(crtc->fb)->gtt;
> +   psb_gtt_unpin(gt);
> +   }
> +}
> +
>  const struct drm_crtc_helper_funcs psb_intel_helper_funcs = {
> .dpms = psb_intel_crtc_dpms,
> .mode_fixup = psb_intel_crtc_mode_fixup,
> @@ -1157,6 +1170,7 @@ const struct drm_crtc_helper_funcs 
> psb_intel_helper_funcs = {
> .mode_set_base = psb_intel_pipe_set_base,
> .prepare = psb_intel_crtc_prepare,
> .commit = psb_intel_crtc_commit,
> +   .disable = psb_intel_crtc_disable,
>  };
>
>  const struct drm_crtc_funcs psb_intel_crtc_funcs = {
> --
> 1.8.1.2
>

Dave, this is a "less hackish" fix to the framebuffer leak bug I've been having.
Daniel Vetter suggested this approach and it works as expected. ACK or NACK?

If this is ok I'll send you a pull request early next week so we can get it
into 3.10.

Thanks
Patrik


[PATCH 2/2] drm/gma500/cdv: Unpin framebuffer on crtc disable

2013-06-08 Thread Patrik Jakobsson
The framebuffer needs to be unpinned in the crtc->disable callback
because of previous pinning in psb_intel_pipe_set_base(). This will fix
a memory leak where the framebuffer was released but not unpinned
properly. This patch only affects Cedarview.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=889511
Bugzilla: https://bugzilla.novell.com/show_bug.cgi?id=812113
Signed-off-by: Patrik Jakobsson 
---
 drivers/gpu/drm/gma500/cdv_intel_display.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/gma500/cdv_intel_display.c 
b/drivers/gpu/drm/gma500/cdv_intel_display.c
index 3cfd093..d6742dc 100644
--- a/drivers/gpu/drm/gma500/cdv_intel_display.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_display.c
@@ -1750,6 +1750,19 @@ static void cdv_intel_crtc_destroy(struct drm_crtc *crtc)
kfree(psb_intel_crtc);
 }

+static void cdv_intel_crtc_disable(struct drm_crtc *crtc)
+{
+   struct gtt_range *gt;
+   struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
+
+   crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
+
+   if (crtc->fb) {
+   gt = to_psb_fb(crtc->fb)->gtt;
+   psb_gtt_unpin(gt);
+   }
+}
+
 const struct drm_crtc_helper_funcs cdv_intel_helper_funcs = {
.dpms = cdv_intel_crtc_dpms,
.mode_fixup = cdv_intel_crtc_mode_fixup,
@@ -1757,6 +1770,7 @@ const struct drm_crtc_helper_funcs cdv_intel_helper_funcs 
= {
.mode_set_base = cdv_intel_pipe_set_base,
.prepare = cdv_intel_crtc_prepare,
.commit = cdv_intel_crtc_commit,
+   .disable = cdv_intel_crtc_disable,
 };

 const struct drm_crtc_funcs cdv_intel_crtc_funcs = {
-- 
1.8.1.2



[PATCH 1/2] drm/gma500/psb: Unpin framebuffer on crtc disable

2013-06-08 Thread Patrik Jakobsson
The framebuffer needs to be unpinned in the crtc->disable callback
because of previous pinning in psb_intel_pipe_set_base(). This will fix
a memory leak where the framebuffer was released but not unpinned
properly. This patch only affects Poulsbo.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=889511
Bugzilla: https://bugzilla.novell.com/show_bug.cgi?id=812113
Signed-off-by: Patrik Jakobsson 
---
 drivers/gpu/drm/gma500/psb_intel_display.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/gma500/psb_intel_display.c 
b/drivers/gpu/drm/gma500/psb_intel_display.c
index 6e8f42b..12d129e 100644
--- a/drivers/gpu/drm/gma500/psb_intel_display.c
+++ b/drivers/gpu/drm/gma500/psb_intel_display.c
@@ -1150,6 +1150,19 @@ static void psb_intel_crtc_destroy(struct drm_crtc *crtc)
kfree(psb_intel_crtc);
 }

+static void psb_intel_crtc_disable(struct drm_crtc *crtc)
+{
+   struct gtt_range *gt;
+   struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
+
+   crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
+
+   if (crtc->fb) {
+   gt = to_psb_fb(crtc->fb)->gtt;
+   psb_gtt_unpin(gt);
+   }
+}
+
 const struct drm_crtc_helper_funcs psb_intel_helper_funcs = {
.dpms = psb_intel_crtc_dpms,
.mode_fixup = psb_intel_crtc_mode_fixup,
@@ -1157,6 +1170,7 @@ const struct drm_crtc_helper_funcs psb_intel_helper_funcs 
= {
.mode_set_base = psb_intel_pipe_set_base,
.prepare = psb_intel_crtc_prepare,
.commit = psb_intel_crtc_commit,
+   .disable = psb_intel_crtc_disable,
 };

 const struct drm_crtc_funcs psb_intel_crtc_funcs = {
-- 
1.8.1.2



[RFC 21/21] DRM: Add VIA drm driver

2013-06-08 Thread James Simmons
commit f4101ca539b83c824747d657bbdc28834276fea8
Author: James Simmons 
Date:   Sat Jun 8 12:28:13 2013 -0400

via: Piece all the TTM/KMS changes together.

This updates the core VIA drm driver to support KMS/TTM/GEM. This includes
setting up the graphics cards resources and enabling the dumb scanout api.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index b16c50e..b773b42 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -188,6 +188,11 @@ config DRM_SIS
 config DRM_VIA
tristate "Via unichrome video cards"
depends on DRM && PCI
+   select FB_CFB_FILLRECT
+   select FB_CFB_COPYAREA
+   select FB_CFB_IMAGEBLIT
+   select DRM_KMS_HELPER
+   select DRM_TTM
help
  Choose this option if you have a Via unichrome or compatible video
  chipset. If M is selected the module will be called via.
diff --git a/drivers/gpu/drm/via/Makefile b/drivers/gpu/drm/via/Makefile
index b537e4b..a0479bb 100644
--- a/drivers/gpu/drm/via/Makefile
+++ b/drivers/gpu/drm/via/Makefile
@@ -3,6 +3,10 @@
 # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.

 ccflags-y := -Iinclude/drm
-via-y:= via_irq.o via_drv.o via_map.o via_mm.o via_h1_cmdbuf.o 
via_verifier.o via_video.o via_h1_dma.o
+via-y:= via_drv.o via_pm.o via_i2c.o via_irq.o via_verifier.o via_ioc32.o \
+   init_ttm.o ttm_gem.o via_ttm.o via_fence.o via_sgdma.o \
+   via_h1_dma.o via_h1_cmdbuf.o \
+   via_display.o via_crtc.o via_fb.o crtc_hw.o via_clocks.o \
+   via_analog.o via_lvds.o via_tmds.o via_hdmi.o

-obj-$(CONFIG_DRM_VIA)  +=via.o
+obj-$(CONFIG_DRM_VIA)  += via.o
diff --git a/drivers/gpu/drm/via/via_drv.c b/drivers/gpu/drm/via/via_drv.c
index f4ae203..2a8592b 100644
--- a/drivers/gpu/drm/via/via_drv.c
+++ b/drivers/gpu/drm/via/via_drv.c
@@ -16,72 +16,436 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
-
 #include 

 #include 
 #include 
+#include 
+
 #include "via_drv.h"

-#include 
+int via_modeset = 0;
+
+MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
+module_param_named(modeset, via_modeset, int, 0400);
+
+int via_hdmi_audio = 0;
+
+MODULE_PARM_DESC(audio, "HDMI Audio enable (1 = enable)");
+module_param_named(audio, via_hdmi_audio, int, 0444);

-static int via_driver_open(struct drm_device *dev, struct drm_file *file)
+static struct pci_device_id via_pci_table[] = {
+   viadrv_PCI_IDS,
+};
+MODULE_DEVICE_TABLE(pci, via_pci_table);
+
+#define SGDMA_MEMORY (256*1024)
+#define VQ_MEMORY (256*1024)
+
+#if __OS_HAS_AGP
+
+#define VIA_AGP_MODE_MASK  0x17
+#define VIA_AGPV3_MODE 0x08
+#define VIA_AGPV3_8X_MODE  0x02
+#define VIA_AGPV3_4X_MODE  0x01
+#define VIA_AGP_4X_MODE0x04
+#define VIA_AGP_2X_MODE0x02
+#define VIA_AGP_1X_MODE0x01
+#define VIA_AGP_FW_MODE0x10
+
+static int
+via_detect_agp(struct drm_device *dev)
 {
-   struct via_file_private *file_priv;
+   struct drm_via_private *dev_priv = dev->dev_private;
+   struct drm_agp_info agp_info;
+   struct drm_agp_mode mode;
+   int ret = 0;

-   DRM_DEBUG_DRIVER("\n");
-   file_priv = kmalloc(sizeof(*file_priv), GFP_KERNEL);
-   if (!file_priv)
-   return -ENOMEM;
+   ret = drm_agp_acquire(dev);
+   if (ret) {
+   DRM_ERROR("Failed acquiring AGP device.\n");
+   return ret;
+   }
+
+   ret = drm_agp_info(dev, _info);
+   if (ret) {
+   DRM_ERROR("Failed detecting AGP aperture size.\n");
+   goto out_err0;
+   }
+
+   mode.mode = agp_info.mode & ~VIA_AGP_MODE_MASK;
+   if (mode.mode & VIA_AGPV3_MODE)
+   mode.mode |= VIA_AGPV3_8X_MODE;
+   else
+   mode.mode |= VIA_AGP_4X_MODE;
+
+   mode.mode |= VIA_AGP_FW_MODE;
+   ret = drm_agp_enable(dev, mode);
+   if (ret) {
+   DRM_ERROR("Failed to enable the AGP bus.\n");
+   goto out_err0;
+   }
+
+   ret = ttm_bo_init_mm(_priv->bdev, TTM_PL_TT, agp_info.aperture_size 
>> PAGE_SHIFT);
+   if (!ret) {
+   DRM_INFO("Detected %lu MB of AGP Aperture at "
+   "physical address 0x%08lx.\n",
+   agp_info.aperture_size >> 20,
+   agp_info.aperture_base);
+   } else {
+out_err0:
+

[RFC 20/21] DRM: Add VIA drm driver

2013-06-08 Thread James Simmons

commit adafa472a5426e6e6ce513fbbad77b0aef0005a3
Author: James Simmons 
Date:   Sat Jun 8 12:24:50 2013 -0400

via: IRQ code updates

Expand the IRQ code to handle more than just the DMA and MPEG engines.
Now we handle hotplug as well and improve vblank support on both crtcs.
We also hook into the fence mechanism.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
index ac98964..d5ab553 100644
--- a/drivers/gpu/drm/via/via_irq.c
+++ b/drivers/gpu/drm/via/via_irq.c
@@ -1,5 +1,4 @@
-/* via_irq.c
- *
+/*
  * Copyright 2004 BEAM Ltd.
  * Copyright 2002 Tungsten Graphics, Inc.
  * Copyright 2005 Thomas Hellstrom.
@@ -18,9 +17,8 @@
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BEAM LTD, TUNGSTEN GRAPHICS  AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
@@ -35,29 +33,81 @@
  * The refresh rate is also calculated for video playback sync purposes.
  */

-#include 
-#include 
+#include "drmP.h"
 #include "via_drv.h"

-#define VIA_REG_INTERRUPT   0x200
-
-/* VIA_REG_INTERRUPT */
-#define VIA_IRQ_GLOBAL   (1 << 31)
-#define VIA_IRQ_VBLANK_ENABLE   (1 << 19)
-#define VIA_IRQ_VBLANK_PENDING  (1 << 3)
-#define VIA_IRQ_HQV0_ENABLE (1 << 11)
-#define VIA_IRQ_HQV1_ENABLE (1 << 25)
-#define VIA_IRQ_HQV0_PENDING(1 << 9)
-#define VIA_IRQ_HQV1_PENDING(1 << 10)
-#define VIA_IRQ_DMA0_DD_ENABLE  (1 << 20)
-#define VIA_IRQ_DMA0_TD_ENABLE  (1 << 21)
-#define VIA_IRQ_DMA1_DD_ENABLE  (1 << 22)
-#define VIA_IRQ_DMA1_TD_ENABLE  (1 << 23)
-#define VIA_IRQ_DMA0_DD_PENDING (1 << 4)
-#define VIA_IRQ_DMA0_TD_PENDING (1 << 5)
-#define VIA_IRQ_DMA1_DD_PENDING (1 << 6)
-#define VIA_IRQ_DMA1_TD_PENDING (1 << 7)
+/* HW Interrupt Register Setting */
+#define INTERRUPT_CTRL_REG10x200
+
+/* mmio 0x200 IRQ enable and status bits. */
+#define VIA_IRQ_ALL_ENABLE BIT(31)
+
+#define VIA_IRQ_IGA1_VBLANK_STATUS BIT(1)
+
+#define VIA_IRQ_IGA1_VSYNC_ENABLE  BIT(19)
+#define VIA_IRQ_IGA2_VSYNC_ENABLE  BIT(17)
+#define VIA_IRQ_IGA1_VSYNC_STATUS  BIT(3)
+#define VIA_IRQ_IGA2_VSYNC_STATUS  BIT(15)
+
+#define VIA_IRQ_CAPTURE0_ACTIVE_ENABLE BIT(28)
+#define VIA_IRQ_CAPTURE1_ACTIVE_ENABLE BIT(24)
+#define VIA_IRQ_CAPTURE0_ACTIVE_STATUS BIT(12)
+#define VIA_IRQ_CAPTURE1_ACTIVE_STATUS BIT(8)
+
+#define VIA_IRQ_HQV0_ENABLEBIT(25)
+#define VIA_IRQ_HQV1_ENABLEBIT(9)
+#define VIA_IRQ_HQV0_STATUSBIT(12)
+#define VIA_IRQ_HQV1_STATUSBIT(10)
+
+#define VIA_IRQ_DMA0_DD_ENABLE BIT(20)
+#define VIA_IRQ_DMA0_TD_ENABLE BIT(21)
+#define VIA_IRQ_DMA1_DD_ENABLE BIT(22)
+#define VIA_IRQ_DMA1_TD_ENABLE BIT(23)
+
+#define VIA_IRQ_DMA0_DD_STATUS BIT(4)
+#define VIA_IRQ_DMA0_TD_STATUS BIT(5)
+#define VIA_IRQ_DMA1_DD_STATUS BIT(6)
+#define VIA_IRQ_DMA1_TD_STATUS BIT(7)
+
+#define VIA_IRQ_LVDS_ENABLEBIT(30)
+#define VIA_IRQ_TMDS_ENABLEBIT(16)

+#define VIA_IRQ_LVDS_STATUSBIT(27)
+#define VIA_IRQ_TMDS_STATUSBIT(0)
+
+#define INTR_ENABLE_MASK (VIA_IRQ_DMA0_TD_ENABLE | VIA_IRQ_DMA1_TD_ENABLE | \
+   VIA_IRQ_DMA0_DD_ENABLE | VIA_IRQ_DMA1_DD_ENABLE | \
+   VIA_IRQ_IGA1_VSYNC_ENABLE | VIA_IRQ_IGA2_VSYNC_ENABLE)
+
+#define INTERRUPT_ENABLE_MASK (VIA_IRQ_CAPTURE0_ACTIVE_ENABLE | 
VIA_IRQ_CAPTURE1_ACTIVE_ENABLE | \
+   VIA_IRQ_HQV0_ENABLE | VIA_IRQ_HQV1_ENABLE | \
+   INTR_ENABLE_MASK)
+
+#define INTR_STATUS_MASK (VIA_IRQ_DMA0_TD_STATUS | VIA_IRQ_DMA1_TD_STATUS | \
+   VIA_IRQ_DMA0_DD_STATUS  | VIA_IRQ_DMA1_DD_STATUS  | \
+   VIA_IRQ_IGA1_VSYNC_STATUS | VIA_IRQ_IGA2_VSYNC_STATUS)
+
+#define INTERRUPT_STATUS_MASK (VIA_IRQ_CAPTURE0_ACTIVE_STATUS | 
VIA_IRQ_CAPTURE1_ACTIVE_STATUS | \
+   VIA_IRQ_HQV0_STATUS | VIA_IRQ_HQV1_STATUS | \
+   INTR_STATUS_MASK)
+
+/* mmio 0x1280 IRQ enabe and status bits. */
+#define INTERRUPT_CTRL_REG30x1280
+
+/* MM1280[9], internal TMDS interrupt status = SR3E[6] */
+#define INTERRUPT_TMDS_STATUS  0x200
+/* MM1280[30], internal TMDS interrupt control = SR3E[7] */
+#define INTERNAL_TMDS_INT_CONTROL  0x4000
+
+#define VIA_IRQ_DP1_ENABLE BIT(24)
+#define VIA_IRQ_DP2_ENABLE BIT(26)
+#define 

[RFC 19/21] DRM: Add VIA drm driver

2013-06-08 Thread James Simmons

commit 36ec6a4cc78da33291b2031979b9ac5efbae0daf
Author: James Simmons 
Date:   Sat Jun 8 12:22:19 2013 -0400

via: Update DMA and command buffer handling to TTM

Update the DMA engine and command buffer code to use the TTM layer.
More work needs to be done here.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/Makefile b/drivers/gpu/drm/via/Makefile
index d59e258..b537e4b 100644
--- a/drivers/gpu/drm/via/Makefile
+++ b/drivers/gpu/drm/via/Makefile
@@ -3,6 +3,6 @@
 # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.

 ccflags-y := -Iinclude/drm
-via-y:= via_irq.o via_drv.o via_map.o via_mm.o via_dma.o via_verifier.o 
via_video.o via_dmablit.o
+via-y:= via_irq.o via_drv.o via_map.o via_mm.o via_h1_cmdbuf.o 
via_verifier.o via_video.o via_h1_dma.o

 obj-$(CONFIG_DRM_VIA)  +=via.o
diff --git a/drivers/gpu/drm/via/via_dma.c b/drivers/gpu/drm/via/via_dma.c
deleted file mode 100644
index 13558f5..000
--- a/drivers/gpu/drm/via/via_dma.c
+++ /dev/null
@@ -1,740 +0,0 @@
-/* via_dma.c -- DMA support for the VIA Unichrome/Pro
- *
- * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Copyright 2004 Digeo, Inc., Palo Alto, CA, U.S.A.
- * All Rights Reserved.
- *
- * Copyright 2004 The Unichrome project.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sub license,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *Tungsten Graphics,
- *Erdi Chen,
- *Thomas Hellstrom.
- */
-
-#include 
-#include 
-#include "via_drv.h"
-#include "via_3d_reg.h"
-
-#define CMDBUF_ALIGNMENT_SIZE   (0x100)
-#define CMDBUF_ALIGNMENT_MASK   (0x0ff)
-
-/* defines for VIA 3D registers */
-#define VIA_REG_STATUS  0x400
-#define VIA_REG_TRANSET 0x43C
-#define VIA_REG_TRANSPACE   0x440
-
-/* VIA_REG_STATUS(0x400): Engine Status */
-#define VIA_CMD_RGTR_BUSY   0x0080 /* Command Regulator is busy */
-#define VIA_2D_ENG_BUSY 0x0001 /* 2D Engine is busy */
-#define VIA_3D_ENG_BUSY 0x0002 /* 3D Engine is busy */
-#define VIA_VR_QUEUE_BUSY   0x0002 /* Virtual Queue is busy */
-
-#define SetReg2DAGP(nReg, nData) { \
-   *((uint32_t *)(vb)) = ((nReg) >> 2) | HALCYON_HEADER1;  \
-   *((uint32_t *)(vb) + 1) = (nData);  \
-   vb = ((uint32_t *)vb) + 2;  \
-   dev_priv->dma_low += 8; \
-}
-
-#define via_flush_write_combine() DRM_MEMORYBARRIER()
-
-#define VIA_OUT_RING_QW(w1, w2)do {\
-   *vb++ = (w1);   \
-   *vb++ = (w2);   \
-   dev_priv->dma_low += 8; \
-} while (0)
-
-static void via_cmdbuf_start(drm_via_private_t *dev_priv);
-static void via_cmdbuf_pause(drm_via_private_t *dev_priv);
-static void via_cmdbuf_reset(drm_via_private_t *dev_priv);
-static void via_cmdbuf_rewind(drm_via_private_t *dev_priv);
-static int via_wait_idle(drm_via_private_t *dev_priv);
-static void via_pad_cache(drm_via_private_t *dev_priv, int qwords);
-
-/*
- * Free space in command buffer.
- */
-
-static uint32_t via_cmdbuf_space(drm_via_private_t *dev_priv)
-{
-   uint32_t agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
-   uint32_t hw_addr = *(dev_priv->hw_addr_ptr) - agp_base;
-
-   return ((hw_addr <= dev_priv->dma_low) ?
-   (dev_priv->dma_high + hw_addr - dev_priv->dma_low) :
-   (hw_addr - dev_priv->dma_low));
-}
-
-/*
- * How much does the command regulator lag behind?
- */
-
-static uint32_t via_cmdbuf_lag(drm_via_private_t *dev_priv)
-{
-   uint32_t agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
-   uint32_t hw_addr = *(dev_priv->hw_addr_ptr) - agp_base;
-
-   return ((hw_addr <= dev_priv->dma_low) ?
-   

[RFC 18/21] DRM: Add VIA drm driver

2013-06-08 Thread James Simmons

commit 589665935a7ec7c29103c9ea4eb1d0ffc4b918d5
Author: James Simmons 
Date:   Sat Jun 8 12:15:30 2013 -0400

via: New GEM/TTM kms ioctls

New ioctls to allow userland to allocate TTM/GEM buffer objects. Obsolete
UMS ioctls.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_ioc32.c b/drivers/gpu/drm/via/via_ioc32.c
new file mode 100644
index 000..03b8508
--- /dev/null
+++ b/drivers/gpu/drm/via/via_ioc32.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright 2006 Tungsten Graphics Inc., Bismarck, ND., USA.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY 
CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+/*
+ * Authors: Thomas Hellstr?m 
+ */
+
+#include "drmP.h"
+#include "via_drv.h"
+
+static int
+via_getparam(struct drm_device *dev, void *data,
+   struct drm_file *filp)
+{
+   struct drm_via_private *dev_priv = dev->dev_private;
+   struct drm_via_param *args = data;
+   int ret = 0;
+
+   switch (args->param) {
+   case VIA_PARAM_CHIPSET_ID:
+   args->value = dev->pci_device;
+   break;
+   case VIA_PARAM_REVISION_ID:
+   args->value = dev_priv->revision;
+   break;
+   default:
+   ret = -EINVAL;
+   break;
+   }
+   return ret;
+}
+
+/* Not yet supported */
+static int
+via_setparam(struct drm_device *dev, void *data,
+   struct drm_file *filp)
+{
+   return -EINVAL;
+}
+
+static int
+via_gem_alloc(struct drm_device *dev, void *data,
+   struct drm_file *filp)
+{
+   struct drm_via_private *dev_priv = dev->dev_private;
+   struct drm_via_gem_create *args = data;
+   struct drm_gem_object *obj;
+   int ret = -ENOMEM;
+
+   obj = ttm_gem_create(dev, _priv->bdev, args->domains, false,
+   args->alignment, PAGE_SIZE, args->size);
+   if (obj && obj->driver_private) {
+   ret = drm_gem_handle_create(filp, obj, >handle);
+   /* drop reference from allocate - handle holds it now */
+   drm_gem_object_unreference_unlocked(obj);
+   if (!ret) {
+   struct ttm_buffer_object *bo = obj->driver_private;
+
+   args->domains = bo->mem.placement & TTM_PL_MASK_MEM;
+   args->map_handle = bo->addr_space_offset;
+   args->offset = bo->offset;
+   args->size = bo->mem.size;
+
+   obj->read_domains = obj->write_domain = args->domains;
+   }
+   }
+   return ret;
+}
+
+static int
+via_gem_state(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+   struct ttm_buffer_object *bo = NULL;
+   struct drm_via_gem_create *args = data;
+   struct drm_gem_object *obj = NULL;
+   struct ttm_placement placement;
+   int ret = -EINVAL;
+
+   obj = drm_gem_object_lookup(dev, file_priv, args->handle);
+   if (!obj || !obj->driver_private)
+   return ret;
+
+   bo = obj->driver_private;
+
+   /* Don't bother to migrate to same domain */
+   args->domains &= ~(bo->mem.placement & TTM_PL_MASK_MEM);
+   if (args->domains) {
+   ret = ttm_bo_reserve(bo, true, false, false, 0);
+   if (unlikely(ret))
+   return ret;
+
+   ttm_placement_from_domain(bo, , args->domains, 
bo->bdev);
+   ret = ttm_bo_validate(bo, , false, false);
+   ttm_bo_unreserve(bo);
+
+   if (!ret) {
+   args->domains = bo->mem.placement & TTM_PL_MASK_MEM;
+   args->map_handle = bo->addr_space_offset;
+   args->offset = bo->offset;
+   args->size = bo->mem.size;
+
+   obj->read_domains = obj->write_domain = args->domains;
+   }
+ 

[RFC 17/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 467eefb4a02972c5f9747ddaa7d8d582fb15a759
Author: James Simmons 
Date:   Sat Jun 8 12:13:25 2013 -0400

via: HDMI/DVI-D support

Implement the encoder and connector for HDMI/DVI-D displays.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_hdmi.c b/drivers/gpu/drm/via/via_hdmi.c
new file mode 100644
index 000..b37405a
--- /dev/null
+++ b/drivers/gpu/drm/via/via_hdmi.c
@@ -0,0 +1,716 @@
+/*
+ * Copyright ? 2013 James Simmons
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * James Simmons 
+ */
+#include "via_drv.h"
+
+#define HDMI_AUDIO_ENABLED BIT(0)
+#define HDMI_COLOR_RANGE   BIT(1)
+
+/*
+ * Routines for controlling stuff on the HDMI port
+ */
+static const struct drm_encoder_funcs via_hdmi_enc_funcs = {
+   .destroy = via_encoder_cleanup,
+};
+
+static void
+via_hdmi_enc_dpms(struct drm_encoder *encoder, int mode)
+{
+   struct drm_via_private *dev_priv = encoder->dev->dev_private;
+
+   switch (mode) {
+   case DRM_MODE_DPMS_SUSPEND:
+   case DRM_MODE_DPMS_STANDBY:
+   case DRM_MODE_DPMS_OFF:
+   /* disable HDMI */
+   VIA_WRITE_MASK(0xC280, 0x0, 0x2);
+   break;
+
+   case DRM_MODE_DPMS_ON:
+   default:
+   /* enable band gap */
+   VIA_WRITE_MASK(0xC740, BIT(0), BIT(0));
+   /* enable video */
+   VIA_WRITE_MASK(0xC640, BIT(3), BIT(3));
+   /* enable HDMI */
+   VIA_WRITE_MASK(0xC280, BIT(1), BIT(1));
+   break;
+   }
+}
+
+static bool
+via_hdmi_enc_mode_fixup(struct drm_encoder *encoder,
+const struct drm_display_mode *mode,
+struct drm_display_mode *adjusted_mode)
+{
+   uint32_t panelHSyncTime = 0, panelHBlankStart = 0, newHBlankStart = 0;
+   uint32_t panelVSyncTime = 0, panelVBlankStart = 0, newVBlankStart = 0;
+   uint32_t left_border = 0, right_border = 0;
+   uint32_t top_border = 0, bottom_border = 0;
+
+   if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
+/* when interlace mode,
+ * we should consider halve vertical timings. */
+panelHSyncTime = adjusted_mode->hsync_end -
+adjusted_mode->hsync_start;
+panelVSyncTime = adjusted_mode->vsync_end / 2 -
+adjusted_mode->vsync_start / 2;
+panelHBlankStart = adjusted_mode->hdisplay;
+panelVBlankStart = adjusted_mode->vdisplay / 2;
+newHBlankStart = adjusted_mode->hdisplay - left_border;
+newVBlankStart = adjusted_mode->vdisplay / 2 - top_border;
+
+adjusted_mode->hdisplay =
+adjusted_mode->hdisplay - left_border - right_border;
+adjusted_mode->hsync_start =
+(adjusted_mode->hsync_start - panelHBlankStart) +
+newHBlankStart;
+adjusted_mode->hsync_end =
+adjusted_mode->hsync_start + panelHSyncTime;
+
+adjusted_mode->vdisplay = adjusted_mode->vdisplay / 2 -
+top_border - bottom_border;
+adjusted_mode->vsync_start =
+(adjusted_mode->vsync_start / 2 - panelVBlankStart) +
+newVBlankStart;
+adjusted_mode->vsync_end =
+adjusted_mode->vsync_start + panelVSyncTime;
+
+   } else {
+panelHSyncTime =
+adjusted_mode->hsync_end - adjusted_mode->hsync_start;
+panelVSyncTime =
+adjusted_mode->vsync_end - adjusted_mode->vsync_start;
+panelHBlankStart = adjusted_mode->hdisplay;
+panelVBlankStart = adjusted_mode->vdisplay;
+newHBlankStart = 

[RFC 16/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit a2e0f8fc0ded9788815cdc68d3acded9f43116b4
Author: James Simmons 
Date:   Sat Jun 8 12:08:57 2013 -0400

via: TMDS support

Implement the encoder and connector for TMDS devices. This handles the case
of DVI port devices not based on an HDMI encoder. This is basic support will
will need to be expanded in the future to handle more corner cases on older
hardware.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_tmds.c b/drivers/gpu/drm/via/via_tmds.c
new file mode 100644
index 000..a906661
--- /dev/null
+++ b/drivers/gpu/drm/via/via_tmds.c
@@ -0,0 +1,187 @@
+/*
+ * Copyright ? 2013 James Simmons
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * James Simmons 
+ */
+#include "via_drv.h"
+
+/*
+ * Routines for controlling stuff on the TMDS port
+ */
+static const struct drm_encoder_funcs via_tmds_enc_funcs = {
+   .destroy = via_encoder_cleanup,
+};
+
+/* Manage the power state of the DAC */
+static void
+via_tmds_dpms(struct drm_encoder *encoder, int mode)
+{
+   struct drm_via_private *dev_priv = encoder->dev->dev_private;
+
+   switch (mode) {
+   case DRM_MODE_DPMS_SUSPEND:
+   case DRM_MODE_DPMS_STANDBY:
+   case DRM_MODE_DPMS_OFF:
+   svga_wcrt_mask(VGABASE, 0xD2, BIT(4), BIT(4));
+   svga_wcrt_mask(VGABASE, 0x91, 0x00, BIT(0));
+
+   /* Internal TMDS only use DFP_L */
+   /* Turn on DVI panel path(Only for internal),
+* otherwise, the screen of DVI will be black. */
+   svga_wcrt_mask(VGABASE, 0x91, 0x00, BIT(7));
+   /* Power on TMDS */
+   svga_wcrt_mask(VGABASE, 0xD2, 0x00, BIT(3));
+   break;
+
+   case DRM_MODE_DPMS_ON:
+   default:
+   svga_wcrt_mask(VGABASE, 0x91, BIT(7), BIT(7));
+   /* Power off TMDS */
+   svga_wcrt_mask(VGABASE, 0xD2, BIT(3), BIT(3));
+   break;
+   }
+}
+
+/* Pass our mode to the connectors and the CRTC to give them a chance to
+ * adjust it according to limitations or connector properties, and also
+ * a chance to reject the mode entirely. Usefule for things like scaling.
+ */
+static bool
+via_tmds_mode_fixup(struct drm_encoder *encoder,
+const struct drm_display_mode *mode,
+struct drm_display_mode *adjusted_mode)
+{
+   drm_mode_set_crtcinfo(adjusted_mode, 0);
+   return true;
+}
+
+static const struct drm_encoder_helper_funcs via_tmds_enc_helper_funcs = {
+   .dpms = via_tmds_dpms,
+   .mode_fixup = via_tmds_mode_fixup,
+   .mode_set = via_set_sync_polarity,
+   .prepare = via_encoder_prepare,
+   .commit = via_encoder_commit,
+   .disable = via_encoder_disable,
+};
+
+static enum drm_connector_status
+via_dvi_detect(struct drm_connector *connector, bool force)
+{
+   struct via_connector *con = container_of(connector, struct 
via_connector, base);
+   enum drm_connector_status ret = connector_status_disconnected;
+   struct edid *edid = NULL;
+
+   drm_mode_connector_update_edid_property(connector, edid);
+   if (con->ddc_bus) {
+   edid = drm_get_edid(connector, con->ddc_bus);
+   if (edid) {
+   if ((connector->connector_type == 
DRM_MODE_CONNECTOR_DVIA) ^
+   (edid->input & DRM_EDID_INPUT_DIGITAL)) {
+   
drm_mode_connector_update_edid_property(connector, edid);
+   ret = connector_status_connected;
+   }
+   kfree(edid);
+   }
+   }
+   return ret;
+}
+
+static const struct drm_connector_funcs via_dvi_connector_funcs = {
+   .dpms = drm_helper_connector_dpms,
+   .detect = via_dvi_detect,
+   .fill_modes = drm_helper_probe_single_connector_modes,
+   

[RFC 15/21] DRM: Add VIA drm driver

2013-06-08 Thread James Simmons

commit 1c886b4f35ec239f7787a6a4db10ecc80b3c9824
Author: James Simmons 
Date:   Sat Jun 8 12:04:31 2013 -0400

via: LVDS support

Implement the encoder and connector for LVDS lcd type displays.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_lvds.c b/drivers/gpu/drm/via/via_lvds.c
new file mode 100644
index 000..d8ed81c
--- /dev/null
+++ b/drivers/gpu/drm/via/via_lvds.c
@@ -0,0 +1,778 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#include 
+#include 
+
+#include "via_drv.h"
+
+/* Encoder flags for LVDS */
+#define LVDS_DUAL_CHANNEL  1
+
+/* caculate the cetering timing using mode and adjusted_mode */
+static void
+via_centering_timing(const struct drm_display_mode *mode,
+   struct drm_display_mode *adjusted_mode)
+{
+   int panel_hsync_time = adjusted_mode->hsync_end -
+   adjusted_mode->hsync_start;
+   int panel_vsync_time = adjusted_mode->vsync_end -
+   adjusted_mode->vsync_start;
+   int panel_hblank_start = adjusted_mode->hdisplay;
+   int panel_vbank_start = adjusted_mode->vdisplay;
+   int hborder = (adjusted_mode->hdisplay - mode->hdisplay) / 2;
+   int vborder = (adjusted_mode->vdisplay - mode->vdisplay) / 2;
+   int new_hblank_start = hborder + mode->hdisplay;
+   int new_vblank_start = vborder + mode->vdisplay;
+
+   adjusted_mode->hdisplay = mode->hdisplay;
+   adjusted_mode->hsync_start = (adjusted_mode->hsync_start -
+   panel_hblank_start) + new_hblank_start;
+   adjusted_mode->hsync_end = adjusted_mode->hsync_start +
+   panel_hsync_time;
+   adjusted_mode->vdisplay = mode->vdisplay;
+   adjusted_mode->vsync_start = (adjusted_mode->vsync_start -
+   panel_vbank_start) + new_vblank_start;
+   adjusted_mode->vsync_end = adjusted_mode->vsync_start +
+   panel_vsync_time;
+   /* Adjust Crtc H and V */
+   adjusted_mode->crtc_hdisplay = adjusted_mode->hdisplay;
+   adjusted_mode->crtc_hblank_start = new_hblank_start;
+   adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_htotal - hborder;
+   adjusted_mode->crtc_hsync_start = adjusted_mode->hsync_start;
+   adjusted_mode->crtc_hsync_end = adjusted_mode->hsync_end;
+   adjusted_mode->crtc_vdisplay = adjusted_mode->vdisplay;
+   adjusted_mode->crtc_vblank_start = new_vblank_start;
+   adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vtotal - vborder;
+   adjusted_mode->crtc_vsync_start = adjusted_mode->vsync_start;
+   adjusted_mode->crtc_vsync_end = adjusted_mode->vsync_end;
+}
+
+static void
+via_enable_internal_lvds(struct drm_encoder *encoder)
+{
+   struct via_encoder *enc = container_of(encoder, struct via_encoder, 
base);
+   struct drm_via_private *dev_priv = encoder->dev->dev_private;
+   struct drm_device *dev = encoder->dev;
+
+   /* Turn on LCD panel */
+   if ((enc->diPort & DISP_DI_DFPL) || (enc->diPort == DISP_DI_DVP1)) {
+   if ((dev->pci_device == PCI_DEVICE_ID_VIA_VT1122) ||
+   (dev->pci_device == PCI_DEVICE_ID_VIA_CLE266)) {
+   /* Software control power sequence ON */
+   svga_wcrt_mask(VGABASE, 0x91, 0x00, BIT(7));
+   svga_wcrt_mask(VGABASE, 0x91, BIT(0), BIT(0));
+   /* Delay td0 msec. */
+   mdelay(200);
+   /* VDD ON */
+   svga_wcrt_mask(VGABASE, 0x91, BIT(4), BIT(4));
+   /* Delay td1 msec. */
+   mdelay(25);
+   /* DATA ON */
+   svga_wcrt_mask(VGABASE, 0x91, BIT(3), BIT(3));
+   /* VEE ON (unused on vt3353) */
+   svga_wcrt_mask(VGABASE, 0x91, BIT(2), BIT(2));
+   /* Delay td3 msec. 

[RFC 14/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 9549976c231b676c2c8e70fd6979115c1c8ed747
Author: James Simmons 
Date:   Sat Jun 8 12:02:59 2013 -0400

via: VGA analog support

Implement the encoder and connector for VGA analog displays.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_analog.c b/drivers/gpu/drm/via/via_analog.c
new file mode 100644
index 000..8fabeac
--- /dev/null
+++ b/drivers/gpu/drm/via/via_analog.c
@@ -0,0 +1,146 @@
+/*
+ * Copyright ? 2012 James Simmons
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * James Simmons 
+ */
+#include "via_drv.h"
+
+/*
+ * Routines for controlling stuff on the analog port
+ */
+static const struct drm_encoder_funcs via_dac_enc_funcs = {
+   .destroy = via_encoder_cleanup,
+};
+
+/* Manage the power state of the DAC */
+static void
+via_dac_dpms(struct drm_encoder *encoder, int mode)
+{
+   struct drm_via_private *dev_priv = encoder->dev->dev_private;
+   u8 mask = 0;
+
+   switch (mode) {
+   case DRM_MODE_DPMS_SUSPEND:
+   mask = BIT(5);  // VSync off
+   break;
+   case DRM_MODE_DPMS_STANDBY:
+   mask = BIT(4);  // HSync off
+   break;
+   case DRM_MODE_DPMS_OFF:
+   mask = (BIT(5) | BIT(4));// HSync and VSync off
+   break;
+   case DRM_MODE_DPMS_ON:
+   default:
+   break;
+   }
+   svga_wcrt_mask(VGABASE, 0x36, mask, BIT(5) | BIT(4));
+}
+
+/* Pass our mode to the connectors and the CRTC to give them a chance to
+ * adjust it according to limitations or connector properties, and also
+ * a chance to reject the mode entirely. Usefule for things like scaling.
+ */
+static bool
+via_dac_mode_fixup(struct drm_encoder *encoder,
+const struct drm_display_mode *mode,
+struct drm_display_mode *adjusted_mode)
+{
+   drm_mode_set_crtcinfo(adjusted_mode, 0);
+   return true;
+}
+
+static const struct drm_encoder_helper_funcs via_dac_enc_helper_funcs = {
+   .dpms = via_dac_dpms,
+   .mode_fixup = via_dac_mode_fixup,
+   .mode_set = via_set_sync_polarity,
+   .prepare = via_encoder_prepare,
+   .commit = via_encoder_commit,
+   .disable = via_encoder_disable,
+};
+
+static enum drm_connector_status
+via_analog_detect(struct drm_connector *connector, bool force)
+{
+   struct via_connector *con = container_of(connector, struct 
via_connector, base);
+   enum drm_connector_status ret = connector_status_disconnected;
+   struct edid *edid = NULL;
+
+   drm_mode_connector_update_edid_property(connector, edid);
+   if (con->ddc_bus) {
+   edid = drm_get_edid(connector, con->ddc_bus);
+   if (edid) {
+   drm_mode_connector_update_edid_property(connector, 
edid);
+   kfree(edid);
+   ret = connector_status_connected;
+   }
+   }
+   return ret;
+}
+
+static const struct drm_connector_funcs via_analog_connector_funcs = {
+   .dpms = drm_helper_connector_dpms,
+   .detect = via_analog_detect,
+   .fill_modes = drm_helper_probe_single_connector_modes,
+   .set_property = via_connector_set_property,
+   .destroy = via_connector_destroy,
+};
+
+static const struct drm_connector_helper_funcs 
via_analog_connector_helper_funcs = {
+   .mode_valid = via_connector_mode_valid,
+   .get_modes = via_get_edid_modes,
+   .best_encoder = via_best_encoder,
+};
+
+void
+via_analog_init(struct drm_device *dev)
+{
+   struct via_connector *con;
+   struct via_encoder *enc;
+
+   enc = kzalloc(sizeof(*enc) + sizeof(*con), GFP_KERNEL);
+   if (!enc) {
+   DRM_ERROR("Failed to allocate connector and encoder\n");
+   return;
+   }
+   con = >cons[0];
+
+   /* Piece together our connector */
+   

[RFC 13/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 991c37448ff8403727f12af331eb164eb5ed4048
Author: James Simmons 
Date:   Sat Jun 8 11:12:36 2013 -0400

via: VIA kms frame buffer support

Each version of hardware has a unquie way to detect the amount of
video ram. We detect the amount for all known device. Here we
implement the drm_framebuffer user land interface hooks as well
as setup a framebuffer for the fbdev emulator.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_fb.c b/drivers/gpu/drm/via/via_fb.c
new file mode 100644
index 000..5cca9f2
--- /dev/null
+++ b/drivers/gpu/drm/via/via_fb.c
@@ -0,0 +1,1267 @@
+/*
+ * Copyright 2012 James Simmons . All Rights 
Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#include "drmP.h"
+#include "via_drv.h"
+#include "drm_fb_helper.h"
+#include "drm_crtc_helper.h"
+
+struct ttm_fb_helper {
+   struct drm_fb_helper base;
+   struct ttm_bo_kmap_obj kmap;
+};
+
+static int
+cle266_mem_type(struct drm_via_private *dev_priv, struct pci_dev *bridge)
+{
+   u8 type, fsb, freq;
+   int ret;
+
+   ret = pci_read_config_byte(bridge, 0x54, );
+   if (ret)
+   return ret;
+   ret = pci_read_config_byte(bridge, 0x69, );
+   if (ret)
+   return ret;
+
+   freq >>= 6;
+   fsb >>= 6;
+
+   /* FSB frequency */
+   switch (fsb) {
+   case 0x01: /* 100MHz */
+   switch (freq) {
+   case 0x00:
+   freq = 100;
+   break;
+   case 0x01:
+   freq = 133;
+   break;
+   case 0x02:
+   freq = 66;
+   break;
+   default:
+   freq = 0;
+   break;
+   }
+   break;
+
+   case 0x02: /* 133 MHz */
+   case 0x03:
+   switch (freq) {
+   case 0x00:
+   freq = 133;
+   break;
+   case 0x02:
+   freq = 100;
+   break;
+   default:
+   freq = 0;
+   break;
+   }
+   break;
+   default:
+   freq = 0;
+   break;
+   }
+
+   ret = pci_read_config_byte(bridge, 0x60, );
+   if (ret)
+   return ret;
+   ret = pci_read_config_byte(bridge, 0xE3, );
+   if (ret)
+   return ret;
+
+   /* On bank 2/3 */
+   if (type & 0x02)
+   fsb >>= 2;
+
+   /* Memory type */
+   switch (fsb & 0x03) {
+   case 0x00: /* SDR */
+   switch (freq) {
+   case 66:
+   dev_priv->vram_type = VIA_MEM_SDR66;
+   break;
+   case 100:
+   dev_priv->vram_type = VIA_MEM_SDR100;
+   break;
+   case 133:
+   dev_priv->vram_type = VIA_MEM_SDR133;
+   default:
+   break;
+   }
+   break;
+
+   case 0x02: /* DDR */
+   switch (freq) {
+   case 100:
+   dev_priv->vram_type = VIA_MEM_DDR_200;
+   break;
+   case 133:
+   dev_priv->vram_type = VIA_MEM_DDR_266;
+   default:
+   break;
+   }
+   default:
+   break;
+   }
+   return ret;
+}
+
+static int
+km400_mem_type(struct drm_via_private *dev_priv, struct pci_dev *bridge)
+{
+   u8 fsb, freq, rev;
+   int ret;
+
+   ret = pci_read_config_byte(bridge, 0xF6, );
+   if (ret)
+   return ret;
+   ret = pci_read_config_byte(bridge, 0x54, );
+   if (ret)
+   return ret;
+   ret = 

[RFC 12/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit ab2beb77d5889b18112ee02c381e817eebbdccff
Author: James Simmons 
Date:   Sat Jun 8 11:02:43 2013 -0400

via: IGA (CRTC) handling

Routines to program all things crtc related. This covers gamma tables, 
cursors
and of course resolution setting.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_crtc.c b/drivers/gpu/drm/via/via_crtc.c
new file mode 100644
index 000..10a5017
--- /dev/null
+++ b/drivers/gpu/drm/via/via_crtc.c
@@ -0,0 +1,1622 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * James Simmons 
+ */
+#include 
+#include "drmP.h"
+#include "drm_crtc.h"
+#include "drm_crtc_helper.h"
+
+#include "via_drv.h"
+#include "via_disp_reg.h"
+
+static struct vga_regset vpit_table[] = {
+   { VGA_SEQ_I, 0x01, 0xFF, 0x01 },
+   { VGA_SEQ_I, 0x02, 0xFF, 0x0F },
+   { VGA_SEQ_I, 0x03, 0xFF, 0x00 },
+   { VGA_SEQ_I, 0x04, 0xFF, 0x0E },
+   { VGA_GFX_I, 0x00, 0xFF, 0x00 },
+   { VGA_GFX_I, 0x01, 0xFF, 0x00 },
+   { VGA_GFX_I, 0x02, 0xFF, 0x00 },
+   { VGA_GFX_I, 0x03, 0xFF, 0x00 },
+   { VGA_GFX_I, 0x04, 0xFF, 0x00 },
+   { VGA_GFX_I, 0x05, 0xFF, 0x00 },
+   { VGA_GFX_I, 0x06, 0xFF, 0x05 },
+   { VGA_GFX_I, 0x07, 0xFF, 0x0F },
+   { VGA_GFX_I, 0x08, 0xFF, 0xFF }
+};
+
+static void
+via_hide_cursor(struct drm_crtc *crtc)
+{
+   struct via_crtc *iga = container_of(crtc, struct via_crtc, base);
+   struct drm_via_private *dev_priv = crtc->dev->dev_private;
+   uint32_t temp;
+
+   if (iga->index) {
+   temp = VIA_READ(HI_CONTROL);
+   VIA_WRITE(HI_CONTROL, temp & 0xFFFA);
+   } else {
+   temp = VIA_READ(PRIM_HI_CTRL);
+   VIA_WRITE(PRIM_HI_CTRL, temp & 0xFFFA);
+   }
+}
+
+static void
+via_show_cursor(struct drm_crtc *crtc)
+{
+   struct via_crtc *iga = container_of(crtc, struct via_crtc, base);
+   struct drm_via_private *dev_priv = crtc->dev->dev_private;
+
+   if (!iga->cursor_kmap.bo)
+   return;
+
+   /* Program the offset and turn on Hardware icon Cursor */
+   if (iga->index) {
+   VIA_WRITE(HI_FBOFFSET, iga->cursor_kmap.bo->offset);
+   VIA_WRITE(HI_CONTROL, 0xB605);
+   } else {
+   VIA_WRITE(PRIM_HI_FBOFFSET, iga->cursor_kmap.bo->offset);
+   VIA_WRITE(PRIM_HI_CTRL, 0x3605);
+   }
+}
+
+static int
+via_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
+   uint32_t handle, uint32_t width, uint32_t height)
+{
+   struct via_crtc *iga = container_of(crtc, struct via_crtc, base);
+   int max_height = 64, max_width = 64, ret = 0, i;
+   struct drm_device *dev = crtc->dev;
+   struct drm_gem_object *obj = NULL;
+   struct ttm_bo_kmap_obj user_kmap;
+
+   if (!iga->cursor_kmap.bo)
+   return -ENXIO;
+
+   if (!handle) {
+   /* turn off cursor */
+   via_hide_cursor(crtc);
+   return ret;
+   }
+
+   if (dev->pdev->device == PCI_DEVICE_ID_VIA_CLE266 ||
+   dev->pdev->device == PCI_DEVICE_ID_VIA_KM400) {
+   max_height >>= 1;
+   max_width >>= 1;
+   }
+
+   if ((height > max_height) || (width > max_width)) {
+   DRM_ERROR("bad cursor width or height %d x %d\n", width, 
height);
+   return -EINVAL;
+   }
+
+   obj = drm_gem_object_lookup(dev, file_priv, handle);
+   if (!obj || !obj->driver_private) {
+   DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle, 
crtc->base.id);
+   return -ENOENT;
+   }
+
+   user_kmap.bo = obj->driver_private;
+   ret = ttm_bo_kmap(user_kmap.bo, 0, user_kmap.bo->mem.size, _kmap);
+   if (!ret) {
+   /* Copy data from userland to cursor memory region */
+   u32 

[RFC 11/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 4ed0199a92b71506100240b625da173ef7afaf4c
Author: James Simmons 
Date:   Sat Jun 8 10:57:59 2013 -0400

via: VIA clock handling

The routines that generate the PLL values to program the registers with.
Here the VCLK is programmed to properly set the video mode.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_clocks.c b/drivers/gpu/drm/via/via_clocks.c
new file mode 100644
index 000..eae424a
--- /dev/null
+++ b/drivers/gpu/drm/via/via_clocks.c
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2012 James Simmons 
+ *
+ * Based on code for the viafb driver.
+ * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
+ * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE.See the GNU General Public License
+ * for more details.
+ */
+
+#include "drmP.h"
+#include "via_drv.h"
+
+#define CSR_VCO_UP 6
+#define CSR_VCO_DOWN   3
+
+#define PLL_DTZ_DEFAULT(BIT(0) | BIT(1))
+
+#define VIA_CLK_REFERENCE  14318180
+
+struct pll_mrn_value {
+   u32 pll_m;
+   u32 pll_r;
+   u32 pll_n;
+   u32 diff_clk;
+   u32 pll_fout;
+};
+
+/*
+ * This function first gets the best frequency M, R, N value
+ * to program the PLL according to the supplied frequence
+ * passed in. After we get the MRN values the results are
+ * formatted to fit properly into the PLL clock registers.
+ *
+ * PLL registers M, R, N value
+ * [31:16]  DM[7:0]
+ * [15:8 ]  DR[2:0]
+ * [7 :0 ]  DN[6:0]
+ */
+u32
+via_get_clk_value(struct drm_device *dev, u32 freq)
+{
+   u32 best_pll_n = 2, best_pll_r = 0, best_pll_m = 2, best_clk_diff = 
freq;
+   u32 pll_fout, pll_fvco, pll_mrn = 0;
+   u32 pll_n, pll_r, pll_m, clk_diff;
+   struct pll_mrn_value pll_tmp[5] = {
+   { 0, 0, 0, 0, 0 },
+   { 0, 0, 0, 0, 0 },
+   { 0, 0, 0, 0, 0 },
+   { 0, 0, 0, 0, 0 },
+   { 0, 0, 0, 0, 0 } };
+   int count;
+
+   /* DN[6:0] */
+   for (pll_n = 2; pll_n < 6; pll_n++) {
+   /* DR[2:0] */
+   for (pll_r = 0; pll_r < 6; pll_r++) {
+   /* DM[9:0] */
+   for (pll_m = 2; pll_m < 512; pll_m++) {
+   /* first divide pll_n then multiply
+* pll_m. We have to reduce pll_m
+* to 512 to get rid of the overflow */
+   pll_fvco = (VIA_CLK_REFERENCE / pll_n) * pll_m;
+   if ((pll_fvco >= CSR_VCO_DOWN) && (pll_fvco <= 
CSR_VCO_UP)) {
+   pll_fout = pll_fvco >> pll_r;
+   if (pll_fout < freq)
+   clk_diff = freq - pll_fout;
+   else
+   clk_diff = pll_fout - freq;
+
+   /* if frequency (which is the PLL we 
want
+* to set) > 150MHz, the MRN value we
+* write in register must < frequency, 
and
+* get MRN value whose M is the 
largeset */
+   if (freq >= 15000) {
+   if ((clk_diff <= 
pll_tmp[0].diff_clk) || pll_tmp[0].pll_fout == 0) {
+   for (count = 
ARRAY_SIZE(pll_tmp) - 1; count >= 1; count--)
+   pll_tmp[count] 
= pll_tmp[count - 1];
+
+   pll_tmp[0].pll_m = 
pll_m;
+   pll_tmp[0].pll_r = 
pll_r;
+   pll_tmp[0].pll_n = 
pll_n;
+   pll_tmp[0].diff_clk = 
clk_diff;
+   pll_tmp[0].pll_fout = 
pll_fout;
+   }
+   }
+
+   if (clk_diff < best_clk_diff) {
+   best_clk_diff = clk_diff;
+   best_pll_m = pll_m;
+   best_pll_n = pll_n;
+   best_pll_r = pll_r;
+ 

[RFC 10/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 86edf1f84ab36213c3bd3a6deb9c0811c7458b2c
Author: James Simmons 
Date:   Sat Jun 8 09:57:49 2013 -0400

via: Our implementation of KMS outputs and crtc

The header file defines via_crtc, via_connector, and via_encoder. Our
via_connector extents drm_connector by including the i2c_adaptor if
the connector supports it and a flags field to tell if a connector specific
feature is enabled or not. The flags field in via_encoder is used the same
way. The via_encoder needs to know what diport it needs to use. The via_crtc
is the most complex. Settings like the display fifo vary depending on the
hardware platform so we cache the value in via_crtc and can use the same
routine to set the registers on all platforms. The same is for the register
sets which not only varies per platform but also per each crtc on board.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_display.c 
b/drivers/gpu/drm/via/via_display.c
new file mode 100644
index 000..4a7223d6
--- /dev/null
+++ b/drivers/gpu/drm/via/via_display.c
@@ -0,0 +1,583 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * James Simmons 
+ */
+
+#include "drmP.h"
+#include "drm_crtc.h"
+#include "drm_crtc_helper.h"
+
+#include "via_drv.h"
+
+/*
+ * Shared encoder routines.
+ */
+void
+via_encoder_commit(struct drm_encoder *encoder)
+{
+   struct via_encoder *enc = container_of(encoder, struct via_encoder, 
base);
+   struct drm_encoder_helper_funcs *encoder_funcs = 
encoder->helper_private;
+   struct drm_via_private *dev_priv = encoder->dev->dev_private;
+   struct drm_device *dev = encoder->dev;
+   struct via_crtc *iga = NULL;
+   u8 value = 0;
+
+   if (encoder->crtc == NULL)
+   return;
+
+   iga = container_of(encoder->crtc, struct via_crtc, base);
+   if (iga->index)
+   value = BIT(4);
+
+   /* Set IGA source and turn on DI port clock */
+   switch (enc->diPort) {
+   case DISP_DI_DVP0:
+   /* DVP0 Data Source Selection. */
+   svga_wcrt_mask(VGABASE, 0x96, value, BIT(4));
+   /* enable DVP0 under CX700 */
+   if (encoder->dev->pdev->device == PCI_DEVICE_ID_VIA_VT3157)
+   svga_wcrt_mask(VGABASE, 0x91, BIT(5), BIT(5));
+   /* Turn on DVP0 clk */
+   svga_wseq_mask(VGABASE, 0x1E, 0xC0, BIT(7) | BIT(6));
+   break;
+
+   case DISP_DI_DVP1:
+   svga_wcrt_mask(VGABASE, 0x9B, value, BIT(4));
+   /* enable DVP1 under these chipset. Does DVI exist
+* for pre CX700 hardware */
+   if ((dev->pdev->device == PCI_DEVICE_ID_VIA_VT3157) ||
+   (dev->pdev->device == PCI_DEVICE_ID_VIA_VT1122) ||
+   (dev->pdev->device == PCI_DEVICE_ID_VIA_VX875) ||
+   (dev->pdev->device == PCI_DEVICE_ID_VIA_VX900))
+   svga_wcrt_mask(VGABASE, 0xD3, 0x00, BIT(5));
+   /* Turn on DVP1 clk */
+   svga_wseq_mask(VGABASE, 0x1E, 0x30, BIT(5) | BIT(4));
+   break;
+
+   case DISP_DI_DFPH:
+   /* Port 96 is used on older hardware for the DVP0 */
+   if ((dev->pdev->device != PCI_DEVICE_ID_VIA_VT3157) &&
+   (dev->pdev->device != PCI_DEVICE_ID_VIA_VT1122) &&
+   (dev->pdev->device != PCI_DEVICE_ID_VIA_VX875) &&
+   (dev->pdev->device != PCI_DEVICE_ID_VIA_VX900))
+   svga_wcrt_mask(VGABASE, 0x96, value, BIT(4));
+
+   svga_wcrt_mask(VGABASE, 0x97, value, BIT(4));
+   /* Turn on DFPH clock */
+   svga_wseq_mask(VGABASE, 0x2A, 0x0C, BIT(3) | BIT(2));
+   break;
+
+   case DISP_DI_DFPL:
+   /* Port 9B is used on older hardware for the DVP1 */
+   

[RFC 9/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 761567d6dd4ec80dbc39052ac74edf7626922f55
Author: James Simmons 
Date:   Sat Jun 8 09:39:04 2013 -0400

via: Hardware initalization/power management functions.

This code handles setting the inital state of the 2D,3D and MPEG engine
as well as our pcie gart tables. The code was separated out here because
these routines will be needed when we return from suspend.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_pm.c b/drivers/gpu/drm/via/via_pm.c
new file mode 100644
index 000..874540a
--- /dev/null
+++ b/drivers/gpu/drm/via/via_pm.c
@@ -0,0 +1,246 @@
+/*
+ * Copyright 2012 James Simmons . All Rights 
Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "via_drv.h"
+
+static void
+via_init_2d(struct drm_via_private *dev_priv, int pci_device)
+{
+   int i;
+
+   for (i = 0x04; i < 0x5c; i += 4)
+   VIA_WRITE(i, 0x0);
+
+   /* For 410 chip*/
+   if (pci_device == PCI_DEVICE_ID_VIA_VX900)
+   VIA_WRITE(0x60, 0x0);
+}
+
+static void
+via_init_3d(struct drm_via_private *dev_priv)
+{
+   unsigned long texture_stage;
+   int i;
+
+   VIA_WRITE(VIA_REG_TRANSET, 0x0001);
+   for (i = 0; i <= 0x9A; i++)
+   VIA_WRITE(VIA_REG_TRANSPACE, i << 24);
+
+   /* guardband clipping default setting */
+   VIA_WRITE(VIA_REG_TRANSPACE, (0x88 << 24) | 0x1ed0);
+   VIA_WRITE(VIA_REG_TRANSPACE, (0x89 << 24) | 0x0800);
+
+   /* Initial Texture Stage Setting */
+   for (texture_stage = 0; texture_stage <= 0xf; texture_stage++) {
+   VIA_WRITE(VIA_REG_TRANSET, (0x0002 | 0x |
+   (texture_stage & 0xf) << 24));
+   for (i = 0 ; i <= 0x30 ; i++)
+   VIA_WRITE(VIA_REG_TRANSPACE, i << 24);
+   }
+
+   /* Initial Texture Sampler Setting */
+   for (texture_stage = 0; texture_stage <= 0xf; texture_stage++) {
+   VIA_WRITE(VIA_REG_TRANSET, (0x0002 | 0x2000 |
+   (texture_stage & 0x10) << 24));
+   for (i = 0; i <= 0x36; i++)
+   VIA_WRITE(VIA_REG_TRANSPACE, i << 24);
+   }
+
+   VIA_WRITE(VIA_REG_TRANSET, (0x0002 | 0xfe00));
+   for (i = 0 ; i <= 0x13 ; i++)
+   VIA_WRITE(VIA_REG_TRANSPACE, i << 24);
+
+   /* degamma table */
+   VIA_WRITE(VIA_REG_TRANSET, (0x0003 | 0x1500));
+   VIA_WRITE(VIA_REG_TRANSPACE, (0x4000 | (30 << 20) | (15 << 10) | 
(5)));
+   VIA_WRITE(VIA_REG_TRANSPACE, ((119 << 20) | (81 << 10) | (52)));
+   VIA_WRITE(VIA_REG_TRANSPACE, ((283 << 20) | (219 << 10) | (165)));
+   VIA_WRITE(VIA_REG_TRANSPACE, ((535 << 20) | (441 << 10) | (357)));
+   VIA_WRITE(VIA_REG_TRANSPACE, ((119 << 20) | (884 << 20) | (757 << 10) | 
(640)));
+
+   /* gamma table */
+   VIA_WRITE(VIA_REG_TRANSET, (0x0003 | 0x1700));
+   VIA_WRITE(VIA_REG_TRANSPACE, (0x4000 | (13 << 20) | (13 << 10) | 
(13)));
+   VIA_WRITE(VIA_REG_TRANSPACE, (0x4000 | (26 << 20) | (26 << 10) | 
(26)));
+   VIA_WRITE(VIA_REG_TRANSPACE, (0x4000 | (39 << 20) | (39 << 10) | 
(39)));
+   VIA_WRITE(VIA_REG_TRANSPACE, ((51 << 20) | (51 << 10) | (51)));
+   VIA_WRITE(VIA_REG_TRANSPACE, ((71 << 20) | (71 << 10) | (71)));
+   VIA_WRITE(VIA_REG_TRANSPACE, (87 << 20) | (87 << 10) | (87));
+   VIA_WRITE(VIA_REG_TRANSPACE, (113 << 20) | (113 << 10) | (113));
+   VIA_WRITE(VIA_REG_TRANSPACE, (135 << 20) | (135 << 10) | (135));
+   VIA_WRITE(VIA_REG_TRANSPACE, (170 << 20) | (170 << 10) | (170));
+   VIA_WRITE(VIA_REG_TRANSPACE, (199 << 20) | (199 << 10) | (199));
+   VIA_WRITE(VIA_REG_TRANSPACE, (246 << 20) | (246 << 10) | (246));
+   VIA_WRITE(VIA_REG_TRANSPACE, (284 << 20) | (284 << 10) | (284));
+ 

[RFC 8/21] DRM: Add VIA drm driver

2013-06-08 Thread James Simmons

commit 33c7dca3f212ef8dff75312e1e4044fb1bcae898
Author: James Simmons 
Date:   Sat Jun 8 09:24:11 2013 -0400

via: Display register tables and engine register definitions

The via_disp_reg.h contains tables that define the registers
and their bit fields we need for various resolution settings
or property handing (i.e scaling). The second header via_regs.h
contains convient names for registers relating to the graphic
engines. We also update the command verifier to handle these
changes. More 3D register definitions are added to via_3d_reg.h.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_3d_reg.h b/drivers/gpu/drm/via/via_3d_reg.h
index 462375d..e42705b 100644
--- a/drivers/gpu/drm/via/via_3d_reg.h
+++ b/drivers/gpu/drm/via/via_3d_reg.h
@@ -1,6 +1,6 @@
 /*
- * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
- * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
+ * Copyright 1998-2011 VIA Technologies, Inc. All Rights Reserved.
+ * Copyright 2001-2011 S3 Graphics, Inc. All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -16,7 +16,7 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
@@ -50,6 +50,7 @@
 #define HC_ParaType_Palette 0x0003
 #define HC_ParaType_PreCR   0x0010
 #define HC_ParaType_Auto0x00fe
+#define INV_ParaType_Dummy  0x0030

 /* Transmission Space
  */
@@ -176,7 +177,7 @@
 /* Command
  * Command A
  */
-#define HC_HCmdHeader_MASK  0xfe00 /*0xffe0 */
+#define HC_HCmdHeader_MASK  0xfe00  /*0xffe0 */
 #define HC_HE3Fire_MASK 0x0010
 #define HC_HPMType_MASK 0x000f
 #define HC_HEFlag_MASK  0xe000
@@ -236,6 +237,8 @@
 /* Enable Setting
  */
 #define HC_SubA_HEnable 0x
+#define HC_HenForce1P_MASK  0x0080  //[Force 1 Pipe]
+#define HC_HenZDCheck_MASK  0x0040  //[Z dirty bit settings]
 #define HC_HenTXEnvMap_MASK 0x0020
 #define HC_HenVertexCNT_MASK0x0010
 #define HC_HenCPUDAZ_MASK   0x0008
@@ -684,6 +687,12 @@

 /* Texture subtype definitions
  */
+#define HC_SubType_Samp00x0020
+#define HC_SubType_Samp10x0021
+
+
+/* Texture subtype definitions
+ */
 #define HC_SubType_Tex0 0x
 #define HC_SubType_Tex1 0x0001
 #define HC_SubType_TexGeneral   0x00fe
@@ -762,7 +771,13 @@
 #define HC_SubA_HTXnBumpM10 0x0092
 #define HC_SubA_HTXnBumpM11 0x0093
 #define HC_SubA_HTXnLScale  0x0094
-#define HC_SubA_HTXSMD  0x
+
+#define HC_SubA_HTXSMD 0x
+#define HC_SubA_HTXYUV2RGB10x0001
+#define HC_SubA_HTXYUV2RGB20x0002
+#define HC_SubA_HTXYUV2RGB30x0003
+#define HTXYUV2RGB4BT601   (1<<23)
+#define HTXYUV2RGB4BT709   (1<<22)
 /* HC_SubA_HTXnL012BasH0x0020
  */
 #define HC_HTXnL0BasH_MASK  0x00ff
@@ -965,6 +980,7 @@
 #define HC_HTXnFM_Lum   0x0010
 #define HC_HTXnFM_Alpha 0x0018
 #define HC_HTXnFM_DX0x0028
+#define HC_HTXnFM_YUV   0x0030
 #define HC_HTXnFM_ARGB160x0088
 #define HC_HTXnFM_ARGB320x0098
 #define HC_HTXnFM_ABGR160x00a8
@@ -995,6 +1011,12 @@
 #define HC_HTXnFM_DX1   (HC_HTXnFM_DX| 0x0001)
 #define HC_HTXnFM_DX23  (HC_HTXnFM_DX| 0x0002)
 #define HC_HTXnFM_DX45  (HC_HTXnFM_DX| 0x0003)
+//YUV package mode
+#define HC_HTXnFM_YUY2  (HC_HTXnFM_YUV   | 0x)
+//YUV planner mode
+#define HC_HTXnFM_YV12  (HC_HTXnFM_YUV   | 0x0004)
+//YUV planner mode
+#define HC_HTXnFM_IYUV  (HC_HTXnFM_YUV   | 0x0004)
 #define HC_HTXnFM_RGB555(HC_HTXnFM_ARGB16| 0x)
 #define HC_HTXnFM_RGB565(HC_HTXnFM_ARGB16| 0x0001)
 #define HC_HTXnFM_ARGB1555  (HC_HTXnFM_ARGB16| 0x0002)
@@ -1023,6 +1045,13 @@
 #define HC_HTXnLoc_Local0x
 #define HC_HTXnLoc_Sys  0x0002
 #define HC_HTXnLoc_AGP  0x0003
+
+// Video Texture
+#define HC_HTXnYUV2RGBMode_RGB  0x
+#define HC_HTXnYUV2RGBMode_SDTV 0x0001
+#define HC_HTXnYUV2RGBMode_HDTV 0x0002
+#define HC_HTXnYUV2RGBMode_TABLE0x0003
+
 /* HC_SubA_HTXnTRAH

[RFC 7/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit a1296bc36bbc68963ef0294e94bef69ddb998c9a
Author: James Simmons 
Date:   Sat Jun 8 08:53:44 2013 -0400

via: i2c handling

In order to support EDID retrieval and the via camera on the XO data
much be collected over the i2c buses. We use the i2c layer developed
by the viafb project.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_i2c.c b/drivers/gpu/drm/via/via_i2c.c
new file mode 100644
index 000..f4fcdea
--- /dev/null
+++ b/drivers/gpu/drm/via/via_i2c.c
@@ -0,0 +1,204 @@
+/*
+ * Copyright 2012 James Simmons  All Rights 
Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE.See the GNU General Public License
+ * for more details.
+ *
+ * This part was influenced by the via i2c code written for the viafb
+ * driver by VIA Technologies and S3 Graphics
+ */
+#include "via_drv.h"
+
+enum viafb_i2c_adap;
+
+#include 
+
+#define SERIAL 0
+#defineGPIO1
+
+static struct via_i2c_stuff via_i2c_par[5];
+
+static void via_i2c_setscl(void *data, int state)
+{
+   struct via_i2c_stuff *i2c = data;
+   struct drm_device *dev = i2c_get_adapdata(>adapter);
+   struct drm_via_private *dev_priv = dev->dev_private;
+   u8 value, mask;
+
+   if (i2c->is_active == GPIO) {
+   mask = state ? BIT(7) : BIT(7) | BIT(5);
+   value = state ? 0x00 : BIT(7);
+   } else {
+   value = state ? BIT(5) : 0x00;
+   mask = BIT(5);
+   }
+   svga_wseq_mask(VGABASE, i2c->i2c_port, value, mask);
+}
+
+static int via_i2c_getscl(void *data)
+{
+   struct via_i2c_stuff *i2c = data;
+   struct drm_device *dev = i2c_get_adapdata(>adapter);
+   struct drm_via_private *dev_priv = dev->dev_private;
+
+   return (vga_rseq(VGABASE, i2c->i2c_port) & BIT(3));
+}
+
+static int via_i2c_getsda(void *data)
+{
+   struct via_i2c_stuff *i2c = data;
+   struct drm_device *dev = i2c_get_adapdata(>adapter);
+   struct drm_via_private *dev_priv = dev->dev_private;
+
+   return (vga_rseq(VGABASE, i2c->i2c_port) & BIT(2));
+}
+
+static void via_i2c_setsda(void *data, int state)
+{
+   struct via_i2c_stuff *i2c = data;
+   struct drm_device *dev = i2c_get_adapdata(>adapter);
+   struct drm_via_private *dev_priv = dev->dev_private;
+   u8 value, mask;
+
+   if (i2c->is_active == GPIO) {
+   mask = state ? BIT(6) : BIT(6) | BIT(4);
+   value = state ? 0x00 : BIT(6);
+   } else {
+   value = state ? BIT(4) : 0x00;
+   mask = BIT(4);
+   }
+   svga_wseq_mask(VGABASE, i2c->i2c_port, value, mask);
+}
+
+struct i2c_adapter *via_find_ddc_bus(int port)
+{
+   struct i2c_adapter *adapter = NULL;
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(via_i2c_par); i++) {
+   struct via_i2c_stuff *i2c = _i2c_par[i];
+
+   if (i2c->i2c_port == port) {
+   adapter = >adapter;
+   break;
+   }
+   }
+   return adapter;
+}
+
+static int
+create_i2c_bus(struct drm_device *dev, struct via_i2c_stuff *i2c_par)
+{
+   struct i2c_adapter *adapter = _par->adapter;
+   struct i2c_algo_bit_data *algo = _par->algo;
+
+   algo->setsda = via_i2c_setsda;
+   algo->setscl = via_i2c_setscl;
+   algo->getsda = via_i2c_getsda;
+   algo->getscl = via_i2c_getscl;
+   algo->udelay = 15;
+   algo->timeout = usecs_to_jiffies(2200); /* from VESA */
+   algo->data = i2c_par;
+
+   sprintf(adapter->name, "via i2c bit bus 0x%02x", i2c_par->i2c_port);
+   adapter->owner = THIS_MODULE;
+   adapter->class = I2C_CLASS_DDC;
+   adapter->algo_data = algo;
+   i2c_set_adapdata(adapter, dev);
+
+   /* Raise SCL and SDA */
+   via_i2c_setsda(i2c_par, 1);
+   via_i2c_setscl(i2c_par, 1);
+   udelay(20);
+
+   return i2c_bit_add_bus(adapter);
+}
+
+void
+via_i2c_readbytes(struct i2c_adapter *adapter,
+   u8 slave_addr, char offset,
+   u8 *buffer, unsigned int size)
+{
+   u8 out_buf[2];
+   u8 in_buf[2];
+   struct i2c_msg msgs[] = {
+   {
+   .addr = slave_addr,
+   .flags = 0,
+   .len = 1,
+   .buf = out_buf,
+   },
+   {
+   .addr = slave_addr,
+   .flags = I2C_M_RD,
+   .len = size,
+   .buf = in_buf,
+   }
+   };
+
+   out_buf[0] 

[RFC 6/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 5ec2cdc6f99549122329253b1c4d1a04193b81d0
Author: James Simmons 
Date:   Sat Jun 8 07:59:56 2013 -0400

via: TTM and GEM memory handling

TTM buffer object life cycle and state handling is done in init_ttm.c.
The VIA GEM implemenation is a simple wrapper around the TTM layer
that uses our ttm functions from init_ttm.c

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/init_ttm.c b/drivers/gpu/drm/via/init_ttm.c
new file mode 100644
index 000..ead32a1
--- /dev/null
+++ b/drivers/gpu/drm/via/init_ttm.c
@@ -0,0 +1,249 @@
+/*
+ * Copyright (c) 2012 James Simmons
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "drmP.h"
+#include "ttm/ttm_bo_driver.h"
+#include "ttm/ttm_placement.h"
+
+#define DRM_FILE_PAGE_OFFSET (0x1ULL >> PAGE_SHIFT)
+
+struct ttm_heap {
+   uint32_t busy_placements[TTM_NUM_MEM_TYPES];
+   uint32_t placements[TTM_NUM_MEM_TYPES];
+   struct ttm_buffer_object pbo;
+};
+
+static int
+ttm_global_mem_init(struct drm_global_reference *ref)
+{
+   return ttm_mem_global_init(ref->object);
+}
+
+static void
+ttm_global_mem_release(struct drm_global_reference *ref)
+{
+   ttm_mem_global_release(ref->object);
+}
+
+void
+ttm_global_fini(struct drm_global_reference *global_ref,
+   struct ttm_bo_global_ref *global_bo,
+   struct ttm_bo_device *bdev)
+{
+   if (global_ref->release == NULL)
+   return;
+
+   if (bdev)
+   ttm_bo_device_release(bdev);
+   drm_global_item_unref(_bo->ref);
+   drm_global_item_unref(global_ref);
+   global_ref->release = NULL;
+}
+
+int
+ttm_global_init(struct drm_global_reference *global_ref,
+   struct ttm_bo_global_ref *global_bo,
+   struct ttm_bo_driver *driver,
+   struct ttm_bo_device *bdev,
+   bool dma32)
+{
+   struct drm_global_reference *bo_ref;
+   int rc;
+
+   global_ref->global_type = DRM_GLOBAL_TTM_MEM;
+   global_ref->size = sizeof(struct ttm_mem_global);
+   global_ref->init = _global_mem_init;
+   global_ref->release = _global_mem_release;
+
+   rc = drm_global_item_ref(global_ref);
+   if (unlikely(rc != 0)) {
+   DRM_ERROR("Failed setting up TTM memory accounting\n");
+   global_ref->release = NULL;
+   return rc;
+   }
+
+   global_bo->mem_glob = global_ref->object;
+   bo_ref = _bo->ref;
+   bo_ref->global_type = DRM_GLOBAL_TTM_BO;
+   bo_ref->size = sizeof(struct ttm_bo_global);
+   bo_ref->init = _bo_global_init;
+   bo_ref->release = _bo_global_release;
+
+   rc = drm_global_item_ref(bo_ref);
+   if (unlikely(rc != 0)) {
+   DRM_ERROR("Failed setting up TTM BO subsystem\n");
+   drm_global_item_unref(global_ref);
+   global_ref->release = NULL;
+   return rc;
+   }
+
+   rc = ttm_bo_device_init(bdev, bo_ref->object, driver,
+   DRM_FILE_PAGE_OFFSET, dma32);
+   if (rc) {
+   DRM_ERROR("Error initialising bo driver: %d\n", rc);
+   ttm_global_fini(global_ref, global_bo, NULL);
+   }
+   return rc;
+}
+
+static void
+ttm_buffer_object_destroy(struct ttm_buffer_object *bo)
+{
+   struct ttm_heap *heap = container_of(bo, struct ttm_heap, pbo);
+
+   kfree(heap);
+   heap = NULL;
+}
+
+/*
+ * the buffer object domain
+ */
+void
+ttm_placement_from_domain(struct ttm_buffer_object *bo, struct ttm_placement 
*placement, u32 domains,
+   struct ttm_bo_device *bdev)
+{
+   struct ttm_heap *heap = container_of(bo, struct ttm_heap, pbo);
+   int cnt = 0, i = 0;
+
+   if (!(domains & TTM_PL_MASK_MEM)) domains = TTM_PL_FLAG_SYSTEM;
+
+ 

[RFC 5/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit fa8599a207fbd0b4ffaa8c6961d34797f615ed7d
Author: James Simmons 
Date:   Fri Jun 7 19:58:14 2013 -0400

via: ttm bo driver implementation

The openchrome project decided to use the TTM api as the backend to
support GEM. The core needed to support TTM is struct ttm_bo_driver
which is implemented in via_ttm.c. This back end supports both AGP
and PCIe.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_ttm.c b/drivers/gpu/drm/via/via_ttm.c
new file mode 100644
index 000..5d6aead
--- /dev/null
+++ b/drivers/gpu/drm/via/via_ttm.c
@@ -0,0 +1,495 @@
+/*
+ * Copyright 2012 James Simmons . All Rights 
Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#include 
+#ifdef CONFIG_SWIOTLB
+#include 
+#endif
+
+#include "via_drv.h"
+
+static struct ttm_tt *
+via_ttm_tt_create(struct ttm_bo_device *bdev, unsigned long size,
+   uint32_t page_flags, struct page *dummy_read_page)
+{
+#if __OS_HAS_AGP
+   struct drm_via_private *dev_priv =
+   container_of(bdev, struct drm_via_private, bdev);
+
+   if (drm_pci_device_is_agp(dev_priv->dev))
+   return ttm_agp_tt_create(bdev, dev_priv->dev->agp->bridge,
+   size, page_flags, dummy_read_page);
+#endif
+   return via_sgdma_backend_init(bdev, size, page_flags, dummy_read_page);
+}
+
+static int
+via_ttm_tt_populate(struct ttm_tt *ttm)
+{
+   struct sgdma_tt *dma_tt = (struct sgdma_tt *) ttm;
+   struct ttm_dma_tt *sgdma = _tt->sgdma;
+   struct ttm_bo_device *bdev = ttm->bdev;
+   struct drm_via_private *dev_priv =
+   container_of(bdev, struct drm_via_private, bdev);
+   struct drm_device *dev = dev_priv->dev;
+   unsigned int i;
+   int ret = 0;
+
+   if (ttm->state != tt_unpopulated)
+   return 0;
+
+#if __OS_HAS_AGP
+   if (drm_pci_device_is_agp(dev_priv->dev))
+   return ttm_agp_tt_populate(ttm);
+#endif
+
+#ifdef CONFIG_SWIOTLB
+   if (swiotlb_nr_tbl())
+   return ttm_dma_populate(sgdma, dev->dev);
+#endif
+
+   ret = ttm_pool_populate(ttm);
+   if (ret)
+   return ret;
+
+   for (i = 0; i < ttm->num_pages; i++) {
+   sgdma->dma_address[i] = pci_map_page(dev->pdev, ttm->pages[i],
+   0, PAGE_SIZE,
+   PCI_DMA_BIDIRECTIONAL);
+   if (pci_dma_mapping_error(dev->pdev, sgdma->dma_address[i])) {
+   while (--i) {
+   pci_unmap_page(dev->pdev, sgdma->dma_address[i],
+   PAGE_SIZE, 
PCI_DMA_BIDIRECTIONAL);
+   sgdma->dma_address[i] = 0;
+   }
+   ttm_pool_unpopulate(ttm);
+   return -EFAULT;
+   }
+   }
+   return ret;
+}
+
+static void
+via_ttm_tt_unpopulate(struct ttm_tt *ttm)
+{
+   struct sgdma_tt *dma_tt = (struct sgdma_tt *) ttm;
+   struct ttm_dma_tt *sgdma = _tt->sgdma;
+   struct ttm_bo_device *bdev = ttm->bdev;
+   struct drm_via_private *dev_priv =
+   container_of(bdev, struct drm_via_private, bdev);
+   struct drm_device *dev = dev_priv->dev;
+   unsigned int i;
+
+#if __OS_HAS_AGP
+   if (drm_pci_device_is_agp(dev_priv->dev)) {
+   ttm_agp_tt_unpopulate(ttm);
+   return;
+   }
+#endif
+
+#ifdef CONFIG_SWIOTLB
+   if (swiotlb_nr_tbl()) {
+   ttm_dma_unpopulate(sgdma, dev->dev);
+   return;
+   }
+#endif
+
+   for (i = 0; i < ttm->num_pages; i++) {
+   if (sgdma->dma_address[i]) {
+   pci_unmap_page(dev->pdev, sgdma->dma_address[i],
+   PAGE_SIZE, 

[RFC 4/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 6e79030fb92d3461b4a962630245d93944d5d349
Author: James Simmons 
Date:   Fri Jun 7 20:17:06 2013 -0400

via: ttm pcie dma bo_driver handling

Newer VIA hardware has moved from AGP to more modern PCIe
based hardware. The TTM layer provides support for AGP but
drm drivers need to handle PCIe support themselves. The
code in via_sgdma.c provides the TTM backend so one can
allows the graphics card direct access to the host system
memory.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_sgdma.c b/drivers/gpu/drm/via/via_sgdma.c
new file mode 100644
index 000..0dfd1a6
--- /dev/null
+++ b/drivers/gpu/drm/via/via_sgdma.c
@@ -0,0 +1,118 @@
+/**
+ *
+ * Copyright (c) 2012 James Simmons 
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include "via_drv.h"
+
+static int
+via_pcie_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem)
+{
+   struct sgdma_tt *dma_tt = (struct sgdma_tt *) ttm;
+   struct ttm_bo_device *bdev = dma_tt->sgdma.ttm.bdev;
+   struct drm_via_private *dev_priv =
+   container_of(bdev, struct drm_via_private, bdev);
+   int i;
+
+   /* Disable gart table HW protect */
+   svga_wseq_mask(VGABASE, 0x6C, 0x00, BIT(7));
+
+   /* Update the relevant entries */
+   dma_tt->offset = mem->start << PAGE_SHIFT;
+   for (i = 0; i < ttm->num_pages; i++) {
+   writel(page_to_pfn(ttm->pages[i]) & 0x3FFF,
+   dev_priv->gart.virtual + dma_tt->offset + i);
+   }
+
+   /* Invalided GTI cache */
+   svga_wseq_mask(VGABASE, 0x6F, BIT(7), BIT(7));
+
+   /* Enable gart table HW protect */
+   svga_wseq_mask(VGABASE, 0x6C, BIT(7), BIT(7));
+   return 1;
+}
+
+static int
+via_pcie_sgdma_unbind(struct ttm_tt *ttm)
+{
+   struct sgdma_tt *dma_tt = (struct sgdma_tt *) ttm;
+   struct ttm_bo_device *bdev = dma_tt->sgdma.ttm.bdev;
+   struct drm_via_private *dev_priv =
+   container_of(bdev, struct drm_via_private, bdev);
+   int i;
+
+   if (ttm->state != tt_bound)
+   return 0;
+
+   /* Disable gart table HW protect */
+   svga_wseq_mask(VGABASE, 0x6C, 0x00, BIT(7));
+
+   /* Update the relevant entries */
+   for (i = 0; i < ttm->num_pages; i++)
+   writel(0x8000, dev_priv->gart.virtual + dma_tt->offset + i);
+   dma_tt->offset = 0;
+
+   /* Invalided GTI cache */
+   svga_wseq_mask(VGABASE, 0x6F, BIT(7), BIT(7));
+
+   /* Enable gart table HW protect */
+   svga_wseq_mask(VGABASE, 0x6C, BIT(7), BIT(7));
+   return 0;
+}
+
+static void
+via_sgdma_destroy(struct ttm_tt *ttm)
+{
+   struct sgdma_tt *dma_tt = (struct sgdma_tt *) ttm;
+
+   if (ttm) {
+   ttm_dma_tt_fini(_tt->sgdma);
+   kfree(dma_tt);
+   }
+}
+
+static struct ttm_backend_func ttm_sgdma_func = {
+   .bind = via_pcie_sgdma_bind,
+   .unbind = via_pcie_sgdma_unbind,
+   .destroy = via_sgdma_destroy,
+};
+
+struct ttm_tt *
+via_sgdma_backend_init(struct ttm_bo_device *bdev, unsigned long size,
+   uint32_t page_flags, struct page *dummy_read_page)
+{
+   struct sgdma_tt *dma_tt;
+
+   dma_tt = kzalloc(sizeof(*dma_tt), GFP_KERNEL);
+   if (!dma_tt)
+   return NULL;
+
+   dma_tt->sgdma.ttm.func = _sgdma_func;
+
+   if (ttm_dma_tt_init(_tt->sgdma, bdev, size, page_flags, 
dummy_read_page)) {
+   kfree(dma_tt);
+   return NULL;
+   }
+   return _tt->sgdma.ttm;
+}
+EXPORT_SYMBOL(via_sgdma_backend_init);


[RFC 3/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons
commit 30a9dda2deeebcf611cbeaffb38f0f94c708a976
Author: James Simmons 
Date:   Thu Jun 6 20:28:33 2013 -0400

via: fence implementation

For each buffer object we create a fence in order to know what
its state is. A fence notifies us when a object is consumed by
the command queue or if it lost in the queue so we can time it
out. In our design each fence (struct via_fence) belongs to a
fence_pool. A fence_pool represents the way the hardware
handles the buffer object i.e DMA, 2D etc. Each pool itself
will have a number of fence engines to represent each hardware
channel. For exmaple for via hardare we have four DMA engines
which is represented by one type of pool.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_fence.c b/drivers/gpu/drm/via/via_fence.c
new file mode 100644
index 000..98489d5
--- /dev/null
+++ b/drivers/gpu/drm/via/via_fence.c
@@ -0,0 +1,282 @@
+/*
+ * Copyright 2013 James Simmons 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#include 
+#include "drmP.h"
+
+#include "via_drv.h"
+
+static void
+via_fence_destroy(struct kref *kref)
+{
+   struct via_fence *fence = container_of(kref, struct via_fence, kref);
+
+   if (fence->pool->fence_cleanup)
+   fence->pool->fence_cleanup(fence);
+   kfree(fence);
+}
+
+struct via_fence *
+via_fence_create_and_emit(struct via_fence_pool *pool, void *data,
+   unsigned int engine)
+{
+   struct via_fence *fence = NULL;
+
+   fence = kzalloc(sizeof(*fence), GFP_KERNEL);
+   if (fence) {
+   unsigned long flags;
+   int ret = -EINVAL;
+
+   fence->timeout = jiffies + 3 * HZ;
+   fence->engine = engine;
+   fence->pool = pool;
+   fence->priv = data;
+   kref_init(>kref);
+
+   if (engine >= pool->num_engines) {
+   via_fence_unref((void **) );
+   return ERR_PTR(-ENXIO);
+   }
+   spin_lock_irqsave(>lock, flags);
+try_again:
+   /* I like to use get_random_init but it is not exported :-( */
+   get_random_bytes(>seq.key, 3);
+   /* For the small change you get a zero */
+   if (unlikely(fence->seq.key == 0))
+   goto try_again;
+
+   ret = drm_ht_insert_item_rcu(>pending, >seq);
+   if (unlikely(ret))
+   goto try_again;
+
+   ret = pool->fence_emit(fence);
+   if (ret) {
+   DRM_INFO("Failed to emit fence\n");
+   drm_ht_remove_item_rcu(>pending, >seq);
+   via_fence_unref((void **) );
+   fence = ERR_PTR(ret);
+   }
+   spin_unlock_irqrestore(>lock, flags);
+   }
+   return fence;
+}
+
+static void
+via_fence_work(struct work_struct *work)
+{
+   struct via_fence_engine *eng = container_of(work, struct 
via_fence_engine,
+   fence_work);
+   unsigned long seq = readl(eng->read_seq), flags;
+   struct via_fence_pool *pool = eng->pool;
+   struct drm_hash_item *hash = NULL;
+   int ret;
+
+   spin_lock_irqsave(>pool->lock, flags);
+   ret = drm_ht_find_item_rcu(>pending, seq, );
+   if (likely(ret == 0)) {
+   ret = drm_ht_remove_item_rcu(>pending, hash);
+   if (ret < 0)
+   DRM_DEBUG("Failed to remove seq %lx\n", seq);
+   }
+   if (eng->pool->fence_signaled)
+   eng->pool->fence_signaled(eng);
+   spin_unlock_irqrestore(>pool->lock, flags);
+}
+
+static bool
+via_fence_seq_signaled(struct via_fence *fence, u64 seq)
+{
+   struct drm_hash_item *key;
+   unsigned long flags;
+   bool ret = 

[RFC 2/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit f0be3523498cd2422d95af1e5e47f51e099f90e4
Author: James Simmons 
Date:   Thu Jun 6 18:57:00 2013 -0400

via: register setting helpers

The code in the crtc_hw was written to handle to cases of
programming the registers on the graphics card. Basic
routines of programming of the registers already existing
in the vga.h header in include/video that has been used
for some of the frame buffer drivers. We add some of the
missing bit masking and setting  routines into crtc_hw.h
but it would be nice some day to move those over to vga.h
itself.

Addition code had been written to handle two common cases.
The first case is that all the bits to be set are all located
into the same register. The function to handle this is
load_register_table. The second case is when the bits for
a specific function are scattered across several registers.
The load_value_to_registers handles the second case. This
code is written such that it can be used by any other driver
and could even be placed some where that it can be shared
by multiple drivers.

Signed-Off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/crtc_hw.c b/drivers/gpu/drm/via/crtc_hw.c
new file mode 100644
index 000..f71c14e
--- /dev/null
+++ b/drivers/gpu/drm/via/crtc_hw.c
@@ -0,0 +1,88 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * James Simmons 
+ */
+
+#include 
+#include "crtc_hw.h"
+
+/*
+ * load_register_table enables the ability to set entire
+ * tables of registers. For each register defined by the
+ * port and the index for that register is programmed
+ * with a masked value.
+ */
+void
+load_register_tables(void __iomem *regbase, struct vga_registers *regs)
+{
+   u8 cr_index, orig, reg_mask, data;
+   unsigned int i;
+   u16 port;
+
+   for (i = 0; i < regs->count; i++) {
+   reg_mask = regs->regs[i].start_bit;
+   data = regs->regs[i].end_bit;
+   cr_index = regs->regs[i].io_addr;
+   port = regs->regs[i].ioport;
+
+   vga_w(regbase, port, cr_index);
+   orig = (vga_r(regbase, port + 1) & ~reg_mask);
+   vga_w(regbase, port + 1, ((data & reg_mask) | orig));
+   }
+}
+
+/*
+ * Due to the limitation of how much data you can write to a single
+ * register we run into data that can't be written in only one register.
+ * So load_value_to_register was developed to be able to define register
+ * tables that can load different bit ranges of the data to different
+ * registers.
+ */
+void
+load_value_to_registers(void __iomem *regbase, struct vga_registers *regs,
+   unsigned int value)
+{
+   unsigned int bit_num = 0, shift_next_reg, reg_mask;
+   u8 start_index, end_index, cr_index, orig;
+   unsigned int data, i, j;
+   u16 get_bit, port;
+
+   for (i = 0; i < regs->count; i++) {
+   start_index = regs->regs[i].start_bit;
+   end_index = regs->regs[i].end_bit;
+   cr_index = regs->regs[i].io_addr;
+   port = regs->regs[i].ioport;
+   reg_mask = data = 0;
+
+   shift_next_reg = bit_num;
+   for (j = start_index; j <= end_index; j++) {
+   reg_mask = reg_mask | (1 << j);
+   get_bit = (value & (1 << bit_num));
+   data |= ((get_bit >> shift_next_reg) << start_index);
+   bit_num++;
+   }
+
+   vga_w(regbase, port, cr_index);
+   orig = (vga_r(regbase, port + 1) & ~reg_mask);
+   vga_w(regbase, port + 1, ((data & reg_mask) | orig));
+   }
+}
diff --git a/drivers/gpu/drm/via/crtc_hw.h b/drivers/gpu/drm/via/crtc_hw.h
new file mode 100644
index 000..a04b469
--- /dev/null
+++ b/drivers/gpu/drm/via/crtc_hw.h
@@ -0,0 +1,81 @@
+/*
+ * 

[RFC 1/21] Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 1fcf23d361375645d586756d126b436796ba4fba
Author: James Simmons 
Date:   Sat Jun 8 09:31:57 2013 -0400

via: New KMS ioctls and hardware to support.

Add new VIA pci ids to support newer hardware. Cleanup userspace
api structs to remove kernel types and add the new KMS ioctls we
will be supporting.

Signed-Off-by: James Simmons 

diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index c129162..5a4 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -1370,8 +1370,11 @@
 #define PCI_DEVICE_ID_VIA_VT3324   0x0324
 #define PCI_DEVICE_ID_VIA_VT3336   0x0336
 #define PCI_DEVICE_ID_VIA_VT3351   0x0351
+#define PCI_DEVICE_ID_VIA_VT3353   0x0353
 #define PCI_DEVICE_ID_VIA_VT3364   0x0364
 #define PCI_DEVICE_ID_VIA_8371_0   0x0391
+#define PCI_DEVICE_ID_VIA_VT3409   0x0409
+#define PCI_DEVICE_ID_VIA_VT3410   0x0410
 #define PCI_DEVICE_ID_VIA_6415 0x0415
 #define PCI_DEVICE_ID_VIA_8501_0   0x0501
 #define PCI_DEVICE_ID_VIA_82C561   0x0561
@@ -1385,6 +1388,7 @@
 #define PCI_DEVICE_ID_VIA_8605_0   0x0605
 #define PCI_DEVICE_ID_VIA_82C686   0x0686
 #define PCI_DEVICE_ID_VIA_82C691_0 0x0691
+#define PCI_DEVICE_ID_VIA_VT1122   0x1122
 #define PCI_DEVICE_ID_VIA_82C576_1 0x1571
 #define PCI_DEVICE_ID_VIA_82C586_2 0x3038
 #define PCI_DEVICE_ID_VIA_82C586_3 0x3040
@@ -1399,16 +1403,20 @@
 #define PCI_DEVICE_ID_VIA_8653_0   0x3101
 #define PCI_DEVICE_ID_VIA_8622 0x3102
 #define PCI_DEVICE_ID_VIA_8235_USB_2   0x3104
+#define PCI_DEVICE_ID_VIA_K8M800   0x3108
 #define PCI_DEVICE_ID_VIA_8233C_0  0x3109
 #define PCI_DEVICE_ID_VIA_8361 0x3112
 #define PCI_DEVICE_ID_VIA_XM2660x3116
+#define PCI_DEVICE_ID_VIA_PM8000x3118
 #define PCI_DEVICE_ID_VIA_612X 0x3119
+#define PCI_DEVICE_ID_VIA_CLE266   0x3122
 #define PCI_DEVICE_ID_VIA_862X_0   0x3123
 #define PCI_DEVICE_ID_VIA_8753_0   0x3128
 #define PCI_DEVICE_ID_VIA_8233A0x3147
 #define PCI_DEVICE_ID_VIA_8703_51_00x3148
 #define PCI_DEVICE_ID_VIA_8237_SATA0x3149
 #define PCI_DEVICE_ID_VIA_XN2660x3156
+#define PCI_DEVICE_ID_VIA_VT3157   0x3157
 #define PCI_DEVICE_ID_VIA_6410 0x3164
 #define PCI_DEVICE_ID_VIA_8754C_0  0x3168
 #define PCI_DEVICE_ID_VIA_8235 0x3177
@@ -1416,12 +1424,20 @@
 #define PCI_DEVICE_ID_VIA_8377_0   0x3189
 #define PCI_DEVICE_ID_VIA_8378_0   0x3205
 #define PCI_DEVICE_ID_VIA_8783_0   0x3208
+#define PCI_DEVICE_ID_VIA_CN7500x3225
 #define PCI_DEVICE_ID_VIA_8237 0x3227
+#define PCI_DEVICE_ID_VIA_K8M890   0x3230
 #define PCI_DEVICE_ID_VIA_8251 0x3287
 #define PCI_DEVICE_ID_VIA_8261 0x3402
 #define PCI_DEVICE_ID_VIA_8237A0x3337
+#define PCI_DEVICE_ID_VIA_VT3343   0x3343
+#define PCI_DEVICE_ID_VIA_CN7000x3344
+#define PCI_DEVICE_ID_VIA_P4M900   0x3371
 #define PCI_DEVICE_ID_VIA_8237S0x3372
+#define PCI_DEVICE_ID_VIA_VX8750x5122
 #define PCI_DEVICE_ID_VIA_SATA_EIDE0x5324
+#define PCI_DEVICE_ID_VIA_KM4000x7205
+#define PCI_DEVICE_ID_VIA_VX9000x7122
 #define PCI_DEVICE_ID_VIA_8231 0x8231
 #define PCI_DEVICE_ID_VIA_8231_4   0x8235
 #define PCI_DEVICE_ID_VIA_8365_1   0x8305
@@ -1429,7 +1445,7 @@
 #define PCI_DEVICE_ID_VIA_CX700_IDE0x0581
 #define PCI_DEVICE_ID_VIA_VX8000x8353
 #define PCI_DEVICE_ID_VIA_VX8550x8409
-#define PCI_DEVICE_ID_VIA_VX9000x8410
+#define PCI_DEVICE_ID_VIA_8410 0x8410
 #define PCI_DEVICE_ID_VIA_8371_1   0x8391
 #define PCI_DEVICE_ID_VIA_82C598_1 0x8598
 #define PCI_DEVICE_ID_VIA_838X_1   0xB188
diff --git a/include/uapi/drm/via_drm.h b/include/uapi/drm/via_drm.h
index 8b0533c..73ccb10 100644
--- a/include/uapi/drm/via_drm.h
+++ b/include/uapi/drm/via_drm.h
@@ -16,7 +16,7 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
@@ -33,14 +33,10 @@
 #ifndef _VIA_DEFINES_
 #define _VIA_DEFINES_

-#ifndef __KERNEL__
-#include "via_drmclient.h"
-#endif
-
 #define VIA_NR_SAREA_CLIPRECTS 8
-#define VIA_NR_XVMC_PORTS   10
-#define VIA_NR_XVMC_LOCKS   5
-#define VIA_MAX_CACHELINE_SIZE  64
+#define VIA_NR_XVMC_PORTS  10
+#define VIA_NR_XVMC_LOCKS  5
+#define 

[RPC 0/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

Hello

Here is the first run at inspection of the VIA openchrome dri 
driver. Now that the Xorg driver has been out over a year with KMS support
most people should be able to use this feature. The driver is totaly 
complete but we wanted to merge it so people with newer hardware that has 
HDMI/DVI-D support can be able to run X windows. Your xorg driver does not 
implement HDMI/DVI in UMS mode and we don't have the resources to do this 
work. Basic TTM/GEM is supported but currently you can't run any 
acceleration with the command queue. Over the next 6 months this should be 
implemented. Thank you.



[PULL] drm-intel-next

2013-06-08 Thread Daniel Vetter
Hi Dave,

Another round of drm-intel-next for 3.11. Highlights:
- Haswell IPS support (Paulo Zanoni)
- VECS support on Haswell (Ben Widawsky, Xiang Haihao, ...)
- Haswell watermark fixes (Paulo Zanoni)
- "Make the gun bigger again" multithread fence fix from Chris.
- i915_error_state finnally no longer fails with -ENOMEM! Big thanks to
  Mika for tackling this.
- vlv sideband locking fixes from Jani
- Hangcheck prep work for arb_robustness support (Mika)
- edp vs cpu port confusion clean-up from Imre
- pile of smaller fixes and cleanups all over.

Cheers, Daniel

The following changes since commit e1b73cba13a0cc68dd4f746eced15bd6bb24cda4:

  Merge tag 'v3.10-rc2' into drm-intel-next-queued (2013-05-21 09:52:16 +0200)

are available in the git repository at:


  git://people.freedesktop.org/~danvet/drm-intel tags/drm-intel-next-2013-06-01

for you to fetch changes up to 92d44621ad2d083bc03920c904ca0a5eb10d9ded:

  drm/i915: add i915_ips_status debugfs entry (2013-05-31 21:40:20 +0200)


Ben Widawsky (20):
  drm/i915: Fix error state memory leaks
  drm/i915: pre-fixes for checkpatch
  drm/i915: use mappable size for fb kickout
  drm/i915: use drm_mm_takedown
  drm/i915: context debug messages
  drm/i915: Call context fini at cleanup
  drm/i915: Comments for semaphore clarification
  drm/i915: Semaphore MBOX update generalization
  drm/i915: Introduce VECS: the 4th ring
  drm/i915: Add VECS semaphore bits
  drm/i915: Rename ring flush functions
  drm/i915: Vebox ringbuffer init
  drm/i915: Create a more generic pm handler for hsw+
  drm/i915: Create an ivybridge_irq_preinstall
  drm/i915: Add PM regs to pre/post install
  drm/i915: make PM interrupt writes non-destructive
  drm/i915: Convert irq_refounct to struct
  drm/i915: consolidate interrupt naming scheme
  drm/i915: vebox interrupt get/put
  drm/i915: Enable vebox interrupts

Chris Wilson (3):
  drm/i915: Be more informative when reporting "too large for aperture" 
error
  drm/i915: Workaround incoherence with fence updates on Valleyview
  drm/i915: Avoid promoting a simulated hang to 'wedged'

Daniel Vetter (6):
  drm/i915: fixup i915_pipe_enabled check in i915_irq.c
  drm/i915: hw state readout support for cpu_transcoder
  drm/i915: add basic pipe config dump support
  drm/i915: drop a few really redundant WARNs in hsw mode_set
  drm/i915: fix pch_nop support
  drm/i915: fix up the edp power well check

Imre Deak (5):
  drm/i915: release scratch page at module unload
  drm/i915: stop using is_cpu_edp() in intel_disable/post_disable_dp
  drm/i915: merge VLV eDP and DP AUX clock divider calculation
  drm/i915: replace is_cpu_edp() with a check for port A
  drm/i915: remove unused is_cpu_edp()

Jani Nikula (6):
  drm/i915: group sideband register accessors to a new file
  drm/i915: refactor VLV IOSF sideband accessors to use one helper
  drm/i915: drop redundant warnings on not holding dpio_lock
  drm/i915: rename VLV IOSF sideband functions logically
  drm/i915: change VLV IOSF sideband accessors to not return error code
  drm/i915: document why dvo/sdvo/crt need a special dpms function

Jesse Barnes (1):
  drm/i915: add encoder get_config function v5

Mika Kuoppala (5):
  drm/i915: avoid big kmallocs on reading error state
  drm/i915: pass seqno to i915_hangcheck_ring_idle
  drm/i915: track ring progression using seqnos
  drm/i915: introduce i915_hangcheck_ring_hung
  drm/i915: release cursor when crtc is destroyed

Paulo Zanoni (16):
  drm/i915: ILK, SNB and IVB don't have linetime watermarks
  drm/i915: remove intel_update_linetime_watermarks
  drm/i915: use the mode->htotal to calculate linetime watermarks
  drm/i915: fix haswell linetime watermarks calculation
  drm/i915: make intel_ddi_get_cdclk_freq return values in KHz
  drm/i915: set the IPS linetime watermark
  drm/i915: MCH_SSKPD is a 64 bit register on Haswell
  drm/i915: set FORCE_ARB_IDLE_PLANES workaround
  drm/i915: add "enable" argument to intel_update_sprite_watermarks
  drm/i915: add haswell_update_sprite_wm
  drm/i915: properly set HSW WM_PIPE registers
  drm/i915: properly set HSW WM_LP watermarks
  drm/i915: add support for 5/6 data buffer partitioning on Haswell
  drm/i915: implement IPS feature
  drm/i915: add enable_ips module option
  drm/i915: add i915_ips_status debugfs entry

Thomas Meyer (1):
  drm/i915: Cocci spatch "memdup.spatch"

Ville Syrj?l? (2):
  drm/i915: Fix WARN_ON() on UP machines
  drm: Fix drm_rect documentation

Wei Yongjun (1):
  drm/i915: fix error return code in init_pipe_control()

Xiang, Haihao (4):
  drm/i915: add HAS_VEBOX
  drm/i915: add VEBOX into debugfs
  drm/i915: add I915_EXEC_VEBOX to i915_gem_do_execbuffer()
 

[Bug 36602] Hierarchical Z support for R600

2013-06-08 Thread bugzilla-dae...@freedesktop.org
https://bugs.freedesktop.org/show_bug.cgi?id=36602

Alex Deucher  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #52 from Alex Deucher  ---
HyperZ support was merged a while ago.  Closing.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://lists.freedesktop.org/archives/dri-devel/attachments/20130608/a660683e/attachment.html>


[PATCH] drm: Avoid forcing a detection cycle following a hotplug event

2013-06-08 Thread Daniel Vetter
On Wed, Jun 5, 2013 at 5:50 PM, Chris Wilson  
wrote:
> The typical procedure after a hotplug event is then to enumerate all the
> new modes. In the existing code, this is achieved by performing a forced
> detection cycle over all connectors. Ideally, we should just be able to
> use the current detection status and only enumerate the modes on the
> connectors that changed. This is a step in that direction by teaching
> the hotplug path to only use the known detection status rather than
> performing a second *forced* detection on every connector. As it
> currently stands, the first thing userspace does upon receipt of a
> hotplug uevent is call DRM_IOCTL_MODE_GETCONNECTOR on each connector,
> which of course, performs another full detection cycle.
>
> Signed-off-by: Chris Wilson 
> Cc: dri-devel at lists.freedesktop.org
> Cc: Jakob Bornecrantz 
> Cc: Inki Dae 
> Cc: Adam Jackson 

I've dumped a bit a longer blabla text onto the i915 patch in this
series (and cc'ed dri-devel on it), so just the gist: I'm a bit
unhappy that we add a force parameter here essentially just for the
fbdev helper. Imo userspace and legacy fbdev should use the same api,
if that's not good enough the interface is probably not fully
suitable. The end result is a pretty convoluted sequence:
- hpd/poll work calls ->detect
- fbdev calls into ->fill_modes, but avoids ->detect with the
force=false parameter, so this is the part which calls ->get_modes
- userspace avoids calling ->fill_modes with a special trick

I prefer things more explicit ;-)

Cheers, Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch


[Intel-gfx] [PATCH] drm/i915: Add a hotplug connector property

2013-06-08 Thread Daniel Vetter
On Sat, Jun 8, 2013 at 9:08 AM, Chris Wilson  
wrote:
> On Wed, Jun 05, 2013 at 10:59:23PM +0100, Chris Wilson wrote:
>> It is useful for userspace to know when it may be able to skip a forced
>> detection cycle as the connector maintains an accurate status. It also
>> provides status feedback to the user of the hotplug storm detection,
>> and the ability to override the method used for detecting changes in
>> connection status.
>
> Please review this in the context of the user being able to manually
> override the hotplug detection method for an individual connector. In
> that role this makes a lot of sense as it should improve the user
> experience in quite a few situations.

The problem I see is that userspace _can't_ trust the kernel like
this, i.e. the optimization you do in

http://cgit.freedesktop.org/~ickle/xf86-video-intel/commit/?h=hotplug-property=995173e5e5adf8297957155cceab28bdf928022b

to not force the kernel into the full ->fill_modes dance will break
systems. We do have a bunch of machines on record where we claim to
have full hpd support, but it doesn't seem to do anything useful.

But it's not just machines where hotplug flat-out does nothing, hw
hotplug is also pretty racy. We've tried to plug them a bit, but due
to the completely broken machines that regressed again.

The other thing that irks me is that we give the user the option to
override stuff. Imo stuff _really_ should just work, and it sounds
like we have to do the same retraining exercise with "please drop
poll=0 from your boot options" as with disabling modeset. So up to a
certain catastrophic level I prefer pitchforks in front of my house
over people just quirking each and every machine themselves.

Lastly I'm not too happy about how complicated the re-detect avoidance
logic works with your two kernel patches + the userspace change.
Originally I've thought it doesn't solve the edid re-reading issue,
but after carefully re-reading things I stand corrected:
- output poll work or hpd handler call just ->detect from the helpers interface
- if a change has happened it'll eventually call down to the fb helper
(note that we might end up with kms only drivers who punt on this
eventually). Thanks to the new force parameter it'll forego the
->detect and only call ->get_modes.
- Then userspace makes sure that none of ->fill_modes will get called,
which avoids both the ->detect and the ->get_modes.

So it's pretty tricky, and also doesn't avoid re-reading the EDID if
both ->detect and ->get_modes does that. Also I don't like that fbdev
gets special treatment interface-wise compared to userspace (it can
set force=false, which userspace can't). I've very much like to avoid
this, our kms interface should be good enough for both userspace and
legacy fbdev.

Finally a pure process thing on top: I'd like to confirm that Egbert's
hotplug storm stuff is solid before we frob our detect code a bit
more. Which means 3.10 should get out the door first and we need to
ping the various bug reporters a bit.

Cheers, Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch


[PATCH] drm/radeon: fix AVI infoframe generation

2013-06-08 Thread Rafał Miłecki
2013/6/7  :
> From: Alex Deucher 
>
> - remove adding 2 to checksum, this breaks certain monitors
> - properly emit the AVI infoframe version, not emitting
> the version breaks some monitors.
>
> This should fix blank screen when HDMI audio is enabled on
> certain monitors.

Err, nack. I believe this it actually going to *break* some monitors
compatibility.

For some unknown reason AMD hardware uses 0x81 and 0x01 for type and
version of infoframe. See this comment (written/published by you):
/* The following packets and infoframes are required for HDMI:
 * Packets:
 * 0x00 - Null packet
 * 0x01 - Audio clock regen
 * 0x02 - Audio sample
 * 0x03 - General Control
 * Infoframes:
 * 0x81 0x01 - AVI
 * 0x83 0x03 - audio
 */

As you can see, AMD hardware uses 0x81 and 0x01. I've no idea why,
according to the HDMI standard it should be 0x82 and 0x02. All other
vendors seems to also use 0x82 and 0x02. In function
hdmi_avi_infoframe_init type it set to 0x82 and 0x02.

This type and version it's written anywhere, but they are used to
calculate checksum. Checksum it what we store is frame[0x0]. We
calculate checksum as 0x100 - sum (see hdmi_infoframe_checksum).

Now... with common drm code we use 0x82 and 0x02 instead of 0x81 and
0x01. It means our "sum" is too big by 0x02. It means we have to use
0x100 - sum + 0x02 as checksum for AMD hardware.

This whole hack was introduced in 92db7f6c860b8190571a9dc1fcbc16d003422fe8:
drm/radeon/kms: workaround invalid AVI infoframe checksum issue
and I'm pretty sure it was verified to fix somebody's HDMI mode. It
also seems to be compatible with AMD specs (at least the part of it we
can see in the quoted comment).

For proof of fglrx doing the same, please see my e-mail where I
provided dumps from registers when using fglrx:
http://lists.freedesktop.org/archives/dri-devel/2011-December/017717.html
(it was tested on 5 different cards!).

When working on that patch I was talking & debugging with few people
on IRC. That mean I don't have logs anymore, but I'm sure I was
testing exactly that single value and it was immediately fixing
selected displays. I mean testing by writing something like:

avivotool regset 0x10884 0x00a85e4f
vs.
avivotool regset 0x10884 0x00a85e4d

-- 
Rafa?


[Bug 65438] GTK apps crash X11 since last update of LLVMM

2013-06-08 Thread bugzilla-dae...@freedesktop.org
https://bugs.freedesktop.org/show_bug.cgi?id=65438

--- Comment #4 from hadack at gmx.de ---
I have the same problem on a 7750 CAPE VERDE card.

When starting a xfce session X craches with the error message from above,
starting kde works fine.

bisecting shows this bad commit:

8a72c73032707c7b3c042b716286a1ac33720991 is the first bad commit
commit 8a72c73032707c7b3c042b716286a1ac33720991
Author: Tom Stellard 
Date:   Mon Jun 3 17:39:46 2013 +

R600/SI: Fixup CopyToReg register class in PostprocessISelDAG()

The CopyToReg nodes will sometimes try to copy a value from a VGPR to an
SGPR.  This kind of copy is not possible, so we need to detect
VGPR->SGPR copies and do something else.  The current strategy is to
replace these copies with VGPR->VGPR copies and hope that all the users
of CopyToReg can accept VGPRs as arguments.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk at 183132
91177308-0d34-0410-b5e6-96231b3b80d8

-- 
You are receiving this mail because:
You are the assignee for the bug.
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://lists.freedesktop.org/archives/dri-devel/attachments/20130608/8c3193ba/attachment.html>


[Bug 65091] power_profile not working for HD5650

2013-06-08 Thread bugzilla-dae...@freedesktop.org
https://bugs.freedesktop.org/show_bug.cgi?id=65091

--- Comment #4 from Alan Swanson  ---
You can try my patch *if* you have good cooling as Alex indicated (on IRC) he
would not be applying the patch due to potential overheating. We're all still
awaiting the lawyers "review" of improved power manangement code.

http://lists.freedesktop.org/archives/dri-devel/2013-May/039247.html

My patch didn't include memory clocks as I'm running an APU rather than a
discrete card so could not test. So if you add a max_mclk setting, note to
guard it with an "if !(rdev->flags & RADEON_IS_IGP)" in
radeon_pm_get_max_clocks().

Unsurprisingly my frame rates improved over 100% from the default 200MHz but
idles back down on DPMS off with the auto power profile.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://lists.freedesktop.org/archives/dri-devel/attachments/20130608/b163f6e1/attachment.html>


[Bug 65091] power_profile not working for HD5650

2013-06-08 Thread bugzilla-dae...@freedesktop.org
https://bugs.freedesktop.org/show_bug.cgi?id=65091

--- Comment #3 from Kamil Bar  ---
I have found an issue, my vbios default clocks are set to 15 and 157000,
and  my switching profiles aren't working because of this lines in radeon_pm.c:

if (sclk > rdev->pm.default_sclk) {
sclk = rdev->pm.default_sclk;
}

and

if (mclk > rdev->pm.default_mclk) {
sclk = rdev->pm.default_mclk;
}

when I try to switch to 55Mhz ( pass sclk == 55000 ) for clock this
compares it with default ( rdev->pm.default_sclk == 15 which atombios
provides from vbl ), and then kernel switch this request to default.

So, anyone know solution to this, with possibility to push the fix to linux
main branch, so I and possibly many other people can use profiles in future
kernels without recompiling the kernel and apply patch? It would require
modifying radeon_atombios.c and it's methods, I could try to fix it someway,
but it will require testing on many devices.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://lists.freedesktop.org/archives/dri-devel/attachments/20130608/e6b91b3c/attachment-0001.html>


[PATCH] drm/radeon: fix AVI infoframe generation

2013-06-08 Thread Alex Deucher
On Sat, Jun 8, 2013 at 7:46 AM, Rafa? Mi?ecki  wrote:
> 2013/6/7  :
>> From: Alex Deucher 
>>
>> - remove adding 2 to checksum, this breaks certain monitors
>> - properly emit the AVI infoframe version, not emitting
>> the version breaks some monitors.
>>
>> This should fix blank screen when HDMI audio is enabled on
>> certain monitors.
>
> Err, nack. I believe this it actually going to *break* some monitors
> compatibility.

Yeah, it seems to break as many as it fixes :(

>
> For some unknown reason AMD hardware uses 0x81 and 0x01 for type and
> version of infoframe. See this comment (written/published by you):
> /* The following packets and infoframes are required for HDMI:
>  * Packets:
>  * 0x00 - Null packet
>  * 0x01 - Audio clock regen
>  * 0x02 - Audio sample
>  * 0x03 - General Control
>  * Infoframes:
>  * 0x81 0x01 - AVI
>  * 0x83 0x03 - audio
>  */
>
> As you can see, AMD hardware uses 0x81 and 0x01. I've no idea why,
> according to the HDMI standard it should be 0x82 and 0x02. All other
> vendors seems to also use 0x82 and 0x02. In function
> hdmi_avi_infoframe_init type it set to 0x82 and 0x02.


The internal afmt validation code I've seen uses 0x82 and 0x2 (for
DCE4 and newer asics, I'm not sure what we do for older versions), so
I think it may depend on the monitor and the GPU hardware.  We may
need to add some logic to determine what version to send based on the
monitor's caps.

>
> This type and version it's written anywhere, but they are used to
> calculate checksum. Checksum it what we store is frame[0x0]. We
> calculate checksum as 0x100 - sum (see hdmi_infoframe_checksum).
>
> Now... with common drm code we use 0x82 and 0x02 instead of 0x81 and
> 0x01. It means our "sum" is too big by 0x02. It means we have to use
> 0x100 - sum + 0x02 as checksum for AMD hardware.
>

It would probably be cleaner to just adjust the header and version
before calling hdmi_avi_infoframe_pack() so we don't have to add the
hack.

Alex

> This whole hack was introduced in 92db7f6c860b8190571a9dc1fcbc16d003422fe8:
> drm/radeon/kms: workaround invalid AVI infoframe checksum issue
> and I'm pretty sure it was verified to fix somebody's HDMI mode. It
> also seems to be compatible with AMD specs (at least the part of it we
> can see in the quoted comment).
>
> For proof of fglrx doing the same, please see my e-mail where I
> provided dumps from registers when using fglrx:
> http://lists.freedesktop.org/archives/dri-devel/2011-December/017717.html
> (it was tested on 5 different cards!).
>
> When working on that patch I was talking & debugging with few people
> on IRC. That mean I don't have logs anymore, but I'm sure I was
> testing exactly that single value and it was immediately fixing
> selected displays. I mean testing by writing something like:
>
> avivotool regset 0x10884 0x00a85e4f
> vs.
> avivotool regset 0x10884 0x00a85e4d
>
> --
> Rafa?


Quick question about status of bug 36602, "Hierarchical Z support for R600"

2013-06-08 Thread Alex Deucher
On Fri, Jun 7, 2013 at 9:03 PM, Dave Witbrodt  wrote:
> I was just clearing out some bookmarks in my browser and noticed that #36602
> is still open.  Seems like you've had HiZ in r600 for a while, so I was
> wondering if this bug can be closed?  No new posts there since September.

Yes, HyperZ support was merged a while ago.  I've closed the bug.

Alex


[PATCH] drm: Avoid forcing a detection cycle following a hotplug event

2013-06-08 Thread Laurent Pinchart
Hi Chris,

Thanks for the patch.

On Wednesday 05 June 2013 16:50:14 Chris Wilson wrote:
> The typical procedure after a hotplug event is then to enumerate all the
> new modes. In the existing code, this is achieved by performing a forced
> detection cycle over all connectors. Ideally, we should just be able to
> use the current detection status and only enumerate the modes on the
> connectors that changed. This is a step in that direction by teaching
> the hotplug path to only use the known detection status rather than
> performing a second *forced* detection on every connector. As it
> currently stands, the first thing userspace does upon receipt of a
> hotplug uevent is call DRM_IOCTL_MODE_GETCONNECTOR on each connector,
> which of course, performs another full detection cycle.
> 
> Signed-off-by: Chris Wilson 
> Cc: dri-devel at lists.freedesktop.org
> Cc: Jakob Bornecrantz 
> Cc: Inki Dae 
> Cc: Adam Jackson 
> ---
>  drivers/gpu/drm/drm_crtc.c|3 ++-
>  drivers/gpu/drm/drm_crtc_helper.c |8 ++--
>  drivers/gpu/drm/drm_fb_helper.c   |   14 --
>  drivers/gpu/drm/exynos/exynos_drm_connector.c |7 ---
>  drivers/gpu/drm/i2c/ch7006_drv.c  |2 +-
>  drivers/gpu/drm/nouveau/dispnv04/tvnv17.c |2 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c   |3 ++-
>  drivers/gpu/drm/vmwgfx/vmwgfx_kms.h   |3 ++-
>  include/drm/drm_crtc.h|2 +-
>  include/drm/drm_crtc_helper.h |2 +-

Could you please also update Documentation/DocBook/drm.tmpl ?

>  10 files changed, 28 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index e7e9242..635276c 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -1537,7 +1537,8 @@ int drm_mode_getconnector(struct drm_device *dev, void
> *data, if (out_resp->count_modes == 0) {
>   connector->funcs->fill_modes(connector,
>dev->mode_config.max_width,
> -  dev->mode_config.max_height);
> +  dev->mode_config.max_height,
> +  true);
>   }
> 
>   /* delayed so we get modes regardless of pre-fill_modes state */
> diff --git a/drivers/gpu/drm/drm_crtc_helper.c
> b/drivers/gpu/drm/drm_crtc_helper.c index ed1334e..7f2128c 100644
> --- a/drivers/gpu/drm/drm_crtc_helper.c
> +++ b/drivers/gpu/drm/drm_crtc_helper.c
> @@ -96,6 +96,9 @@ static void drm_mode_validate_flag(struct drm_connector
> *connector, * @connector: connector to probe
>   * @maxX: max width for modes
>   * @maxY: max height for modes
> + * @force: whether to use the cached connector status or to force a
> + * fresh detection cycle, for instance after a hotplug event, we
> + * want to simply use the known status.
>   *
>   * LOCKING:
>   * Caller must hold mode config lock.
> @@ -113,7 +116,8 @@ static void drm_mode_validate_flag(struct drm_connector
> *connector, * Number of modes found on @connector.
>   */
>  int drm_helper_probe_single_connector_modes(struct drm_connector
> *connector, - uint32_t maxX, uint32_t 
> maxY)
> + uint32_t maxX, uint32_t maxY,
> + bool force)
>  {
>   struct drm_device *dev = connector->dev;
>   struct drm_display_mode *mode;
> @@ -136,7 +140,7 @@ int drm_helper_probe_single_connector_modes(struct
> drm_connector *connector, connector->status =
> connector_status_disconnected;
>   if (connector->funcs->force)
>   connector->funcs->force(connector);
> - } else {
> + } else if (force) {
>   connector->status = connector->funcs->detect(connector, true);
>   }
> 
> diff --git a/drivers/gpu/drm/drm_fb_helper.c
> b/drivers/gpu/drm/drm_fb_helper.c index b78cbe7..3e0802d 100644
> --- a/drivers/gpu/drm/drm_fb_helper.c
> +++ b/drivers/gpu/drm/drm_fb_helper.c
> @@ -1087,8 +1087,8 @@ void drm_fb_helper_fill_var(struct fb_info *info,
> struct drm_fb_helper *fb_helpe EXPORT_SYMBOL(drm_fb_helper_fill_var);
> 
>  static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper
> *fb_helper, -uint32_t maxX,
> -uint32_t maxY)
> +uint32_t maxX, uint32_t maxY,
> +bool force)
>  {
>   struct drm_connector *connector;
>   int count = 0;
> @@ -1096,7 +1096,7 @@ static int drm_fb_helper_probe_connector_modes(struct
> drm_fb_helper *fb_helper,
> 
>   for (i = 0; i < fb_helper->connector_count; i++) {
>   connector = fb_helper->connector_info[i]->connector;
> - count += connector->funcs->fill_modes(connector, 

[PULL] GEM CMA DMA-BUF

2013-06-08 Thread Laurent Pinchart
Hi Dave,

Here's a small pull request for v3.11 that contains the GEM CMA DMA-BUF 
support patches. The content is identical to "[PATCH v3 0/5] GEM CMA DMA-BUF 
support" with acks picked up from the list.

The following changes since commit 328a4719b6a0930721b5f8d5c69993d3b6e3913f:

  drm_modes: videomode: add doubleclk flag (2013-06-03 18:42:35 +1000)

are available in the git repository at:

  git://linuxtv.org/pinchartl/fbdev.git drm/next

for you to fetch changes up to 71d7282a0f1abb488e5be4d154893579624bc683:

  drm: GEM CMA: Add DRM PRIME support (2013-06-08 09:14:05 +0200)


Laurent Pinchart (5):
  drm/gem: Split drm_gem_mmap() into object search and object mapping
  drm/omap: Use drm_gem_mmap_obj() to implement dma-buf mmap
  drm: GEM CMA: Split object creation into object alloc and DMA memory 
alloc
  drm: GEM CMA: Split object mapping into GEM mapping and CMA mapping
  drm: GEM CMA: Add DRM PRIME support

 drivers/gpu/drm/drm_gem.c |  83 +---
 drivers/gpu/drm/drm_gem_cma_helper.c  | 404 ++---
 drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c |  32 +--
 include/drm/drmP.h|   2 +
 include/drm/drm_gem_cma_helper.h  |   9 +
 5 files changed, 434 insertions(+), 96 deletions(-)

-- 
Regards,

Laurent Pinchart



[PATCH] drm: Avoid forcing a detection cycle following a hotplug event

2013-06-08 Thread Chris Wilson
On Sat, Jun 08, 2013 at 09:28:17AM +0200, Laurent Pinchart wrote:
> Could you please also update Documentation/DocBook/drm.tmpl ?

It looks out of context there, as nothing explains the hotplug ->
fill_modes -> probe -> detect loop...

How about:

  Modes
  int (*fill_modes)(struct drm_connector *connector, uint32_t 
max_width,
  uint32_t max_height, bool force);
  
Fill the mode list with all supported modes for the connector. If the
max_width and max_height
arguments are non-zero, the implementation must ignore all modes wider
than max_width or higher than
max_height. The driver may use the existing
connector status, unless force is passed. During a
hotplug event, the driver may already have updated its knowledge of the
output and so may simply refresh the modes list from the information it
acquired whilst handling the event. However, the caller may explicitly
request that any cached information be dropped, and for the output to be
queried for its current status and modes - under such circumstances
force is true.
  
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


[PATCH 1/4] drm: Print pretty names for pixel formats

2013-06-08 Thread Dave Airlie
On Sat, Jun 8, 2013 at 6:35 AM, Ville Syrj?l?
 wrote:
> On Sat, Jun 08, 2013 at 06:09:42AM +1000, Dave Airlie wrote:
>> On Sat, Jun 8, 2013 at 1:43 AM,   wrote:
>> > From: Foo Bar 
>>
>> ^ ??
>>
>> git config error?
>
> Whoops. Sorry about that. I created the original patch on a test
> machine where I apparently had been too lazy to set up my git
> correctly. And then I used suppress-cc=author to avoid spamming
> myself too much, so I didn't notice it when sending the mail.
>
> Do you want a fixed patch, or will you take care of it on your end?

can you resend that one, otherwise i'll probably forget when I pick it up :-)

Dave.


[PATCH 1/4] drm: Print pretty names for pixel formats

2013-06-08 Thread Dave Airlie
On Sat, Jun 8, 2013 at 1:43 AM,   wrote:
> From: Foo Bar 

^ ??

git config error?

Dave.


[PATCH 1/4] drm: Print pretty names for pixel formats

2013-06-08 Thread Ville Syrjälä
On Sat, Jun 08, 2013 at 06:09:42AM +1000, Dave Airlie wrote:
> On Sat, Jun 8, 2013 at 1:43 AM,   wrote:
> > From: Foo Bar 
> 
> ^ ??
> 
> git config error?

Whoops. Sorry about that. I created the original patch on a test
machine where I apparently had been too lazy to set up my git
correctly. And then I used suppress-cc=author to avoid spamming
myself too much, so I didn't notice it when sending the mail.

Do you want a fixed patch, or will you take care of it on your end?

-- 
Ville Syrj?l?
Intel OTC


[PULL] GEM CMA DMA-BUF

2013-06-08 Thread Laurent Pinchart
Hi Dave,

Here's a small pull request for v3.11 that contains the GEM CMA DMA-BUF 
support patches. The content is identical to [PATCH v3 0/5] GEM CMA DMA-BUF 
support with acks picked up from the list.

The following changes since commit 328a4719b6a0930721b5f8d5c69993d3b6e3913f:

  drm_modes: videomode: add doubleclk flag (2013-06-03 18:42:35 +1000)

are available in the git repository at:

  git://linuxtv.org/pinchartl/fbdev.git drm/next

for you to fetch changes up to 71d7282a0f1abb488e5be4d154893579624bc683:

  drm: GEM CMA: Add DRM PRIME support (2013-06-08 09:14:05 +0200)


Laurent Pinchart (5):
  drm/gem: Split drm_gem_mmap() into object search and object mapping
  drm/omap: Use drm_gem_mmap_obj() to implement dma-buf mmap
  drm: GEM CMA: Split object creation into object alloc and DMA memory 
alloc
  drm: GEM CMA: Split object mapping into GEM mapping and CMA mapping
  drm: GEM CMA: Add DRM PRIME support

 drivers/gpu/drm/drm_gem.c |  83 +---
 drivers/gpu/drm/drm_gem_cma_helper.c  | 404 ++---
 drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c |  32 +--
 include/drm/drmP.h|   2 +
 include/drm/drm_gem_cma_helper.h  |   9 +
 5 files changed, 434 insertions(+), 96 deletions(-)

-- 
Regards,

Laurent Pinchart

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] drm: Avoid forcing a detection cycle following a hotplug event

2013-06-08 Thread Laurent Pinchart
Hi Chris,

Thanks for the patch.

On Wednesday 05 June 2013 16:50:14 Chris Wilson wrote:
 The typical procedure after a hotplug event is then to enumerate all the
 new modes. In the existing code, this is achieved by performing a forced
 detection cycle over all connectors. Ideally, we should just be able to
 use the current detection status and only enumerate the modes on the
 connectors that changed. This is a step in that direction by teaching
 the hotplug path to only use the known detection status rather than
 performing a second *forced* detection on every connector. As it
 currently stands, the first thing userspace does upon receipt of a
 hotplug uevent is call DRM_IOCTL_MODE_GETCONNECTOR on each connector,
 which of course, performs another full detection cycle.
 
 Signed-off-by: Chris Wilson ch...@chris-wilson.co.uk
 Cc: dri-devel@lists.freedesktop.org
 Cc: Jakob Bornecrantz ja...@vmware.com
 Cc: Inki Dae inki@samsung.com
 Cc: Adam Jackson a...@redhat.com
 ---
  drivers/gpu/drm/drm_crtc.c|3 ++-
  drivers/gpu/drm/drm_crtc_helper.c |8 ++--
  drivers/gpu/drm/drm_fb_helper.c   |   14 --
  drivers/gpu/drm/exynos/exynos_drm_connector.c |7 ---
  drivers/gpu/drm/i2c/ch7006_drv.c  |2 +-
  drivers/gpu/drm/nouveau/dispnv04/tvnv17.c |2 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c   |3 ++-
  drivers/gpu/drm/vmwgfx/vmwgfx_kms.h   |3 ++-
  include/drm/drm_crtc.h|2 +-
  include/drm/drm_crtc_helper.h |2 +-

Could you please also update Documentation/DocBook/drm.tmpl ?

  10 files changed, 28 insertions(+), 18 deletions(-)
 
 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
 index e7e9242..635276c 100644
 --- a/drivers/gpu/drm/drm_crtc.c
 +++ b/drivers/gpu/drm/drm_crtc.c
 @@ -1537,7 +1537,8 @@ int drm_mode_getconnector(struct drm_device *dev, void
 *data, if (out_resp-count_modes == 0) {
   connector-funcs-fill_modes(connector,
dev-mode_config.max_width,
 -  dev-mode_config.max_height);
 +  dev-mode_config.max_height,
 +  true);
   }
 
   /* delayed so we get modes regardless of pre-fill_modes state */
 diff --git a/drivers/gpu/drm/drm_crtc_helper.c
 b/drivers/gpu/drm/drm_crtc_helper.c index ed1334e..7f2128c 100644
 --- a/drivers/gpu/drm/drm_crtc_helper.c
 +++ b/drivers/gpu/drm/drm_crtc_helper.c
 @@ -96,6 +96,9 @@ static void drm_mode_validate_flag(struct drm_connector
 *connector, * @connector: connector to probe
   * @maxX: max width for modes
   * @maxY: max height for modes
 + * @force: whether to use the cached connector status or to force a
 + * fresh detection cycle, for instance after a hotplug event, we
 + * want to simply use the known status.
   *
   * LOCKING:
   * Caller must hold mode config lock.
 @@ -113,7 +116,8 @@ static void drm_mode_validate_flag(struct drm_connector
 *connector, * Number of modes found on @connector.
   */
  int drm_helper_probe_single_connector_modes(struct drm_connector
 *connector, - uint32_t maxX, uint32_t 
 maxY)
 + uint32_t maxX, uint32_t maxY,
 + bool force)
  {
   struct drm_device *dev = connector-dev;
   struct drm_display_mode *mode;
 @@ -136,7 +140,7 @@ int drm_helper_probe_single_connector_modes(struct
 drm_connector *connector, connector-status =
 connector_status_disconnected;
   if (connector-funcs-force)
   connector-funcs-force(connector);
 - } else {
 + } else if (force) {
   connector-status = connector-funcs-detect(connector, true);
   }
 
 diff --git a/drivers/gpu/drm/drm_fb_helper.c
 b/drivers/gpu/drm/drm_fb_helper.c index b78cbe7..3e0802d 100644
 --- a/drivers/gpu/drm/drm_fb_helper.c
 +++ b/drivers/gpu/drm/drm_fb_helper.c
 @@ -1087,8 +1087,8 @@ void drm_fb_helper_fill_var(struct fb_info *info,
 struct drm_fb_helper *fb_helpe EXPORT_SYMBOL(drm_fb_helper_fill_var);
 
  static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper
 *fb_helper, -uint32_t maxX,
 -uint32_t maxY)
 +uint32_t maxX, uint32_t maxY,
 +bool force)
  {
   struct drm_connector *connector;
   int count = 0;
 @@ -1096,7 +1096,7 @@ static int drm_fb_helper_probe_connector_modes(struct
 drm_fb_helper *fb_helper,
 
   for (i = 0; i  fb_helper-connector_count; i++) {
   connector = fb_helper-connector_info[i]-connector;
 - count += connector-funcs-fill_modes(connector, maxX, maxY);
 + count += 

Re: [PATCH] drm: Avoid forcing a detection cycle following a hotplug event

2013-06-08 Thread Chris Wilson
On Sat, Jun 08, 2013 at 09:28:17AM +0200, Laurent Pinchart wrote:
 Could you please also update Documentation/DocBook/drm.tmpl ?

It looks out of context there, as nothing explains the hotplug -
fill_modes - probe - detect loop...

How about:

  titleModes/title
  synopsisint (*fill_modes)(struct drm_connector *connector, uint32_t 
max_width,
  uint32_t max_height, bool force);/synopsis
  para
Fill the mode list with all supported modes for the connector. If the
parametermax_width/parameter and parametermax_height/parameter
arguments are non-zero, the implementation must ignore all modes wider
than parametermax_width/parameter or higher than
parametermax_height/parameter. The driver may use the existing
connector status, unless parameterforce/parameter is passed. During a
hotplug event, the driver may already have updated its knowledge of the
output and so may simply refresh the modes list from the information it
acquired whilst handling the event. However, the caller may explicitly
request that any cached information be dropped, and for the output to be
queried for its current status and modes - under such circumstances
parameterforce/parameter is true.
  /para
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


Quick question about status of bug 36602, Hierarchical Z support for R600

2013-06-08 Thread Dave Witbrodt
I was just clearing out some bookmarks in my browser and noticed that 
#36602 is still open.  Seems like you've had HiZ in r600 for a while, so 
I was wondering if this bug can be closed?  No new posts there since 
September.



DW
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] drm/radeon: fix AVI infoframe generation

2013-06-08 Thread Rafał Miłecki
2013/6/7  alexdeuc...@gmail.com:
 From: Alex Deucher alexander.deuc...@amd.com

 - remove adding 2 to checksum, this breaks certain monitors
 - properly emit the AVI infoframe version, not emitting
 the version breaks some monitors.

 This should fix blank screen when HDMI audio is enabled on
 certain monitors.

Err, nack. I believe this it actually going to *break* some monitors
compatibility.

For some unknown reason AMD hardware uses 0x81 and 0x01 for type and
version of infoframe. See this comment (written/published by you):
/* The following packets and infoframes are required for HDMI:
 * Packets:
 * 0x00 - Null packet
 * 0x01 - Audio clock regen
 * 0x02 - Audio sample
 * 0x03 - General Control
 * Infoframes:
 * 0x81 0x01 - AVI
 * 0x83 0x03 - audio
 */

As you can see, AMD hardware uses 0x81 and 0x01. I've no idea why,
according to the HDMI standard it should be 0x82 and 0x02. All other
vendors seems to also use 0x82 and 0x02. In function
hdmi_avi_infoframe_init type it set to 0x82 and 0x02.

This type and version it's written anywhere, but they are used to
calculate checksum. Checksum it what we store is frame[0x0]. We
calculate checksum as 0x100 - sum (see hdmi_infoframe_checksum).

Now... with common drm code we use 0x82 and 0x02 instead of 0x81 and
0x01. It means our sum is too big by 0x02. It means we have to use
0x100 - sum + 0x02 as checksum for AMD hardware.

This whole hack was introduced in 92db7f6c860b8190571a9dc1fcbc16d003422fe8:
drm/radeon/kms: workaround invalid AVI infoframe checksum issue
and I'm pretty sure it was verified to fix somebody's HDMI mode. It
also seems to be compatible with AMD specs (at least the part of it we
can see in the quoted comment).

For proof of fglrx doing the same, please see my e-mail where I
provided dumps from registers when using fglrx:
http://lists.freedesktop.org/archives/dri-devel/2011-December/017717.html
(it was tested on 5 different cards!).

When working on that patch I was talking  debugging with few people
on IRC. That mean I don't have logs anymore, but I'm sure I was
testing exactly that single value and it was immediately fixing
selected displays. I mean testing by writing something like:

avivotool regset 0x10884 0x00a85e4f
vs.
avivotool regset 0x10884 0x00a85e4d

-- 
Rafał
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[Bug 65091] power_profile not working for HD5650

2013-06-08 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=65091

--- Comment #3 from Kamil Bar nevehan...@gmail.com ---
I have found an issue, my vbios default clocks are set to 15 and 157000,
and  my switching profiles aren't working because of this lines in radeon_pm.c:

if (sclk  rdev-pm.default_sclk) {
sclk = rdev-pm.default_sclk;
}

and

if (mclk  rdev-pm.default_mclk) {
sclk = rdev-pm.default_mclk;
}

when I try to switch to 55Mhz ( pass sclk == 55000 ) for clock this
compares it with default ( rdev-pm.default_sclk == 15 which atombios
provides from vbl ), and then kernel switch this request to default.

So, anyone know solution to this, with possibility to push the fix to linux
main branch, so I and possibly many other people can use profiles in future
kernels without recompiling the kernel and apply patch? It would require
modifying radeon_atombios.c and it's methods, I could try to fix it someway,
but it will require testing on many devices.

-- 
You are receiving this mail because:
You are the assignee for the bug.
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [Intel-gfx] [PATCH] drm/i915: Add a hotplug connector property

2013-06-08 Thread Daniel Vetter
On Sat, Jun 8, 2013 at 9:08 AM, Chris Wilson ch...@chris-wilson.co.uk wrote:
 On Wed, Jun 05, 2013 at 10:59:23PM +0100, Chris Wilson wrote:
 It is useful for userspace to know when it may be able to skip a forced
 detection cycle as the connector maintains an accurate status. It also
 provides status feedback to the user of the hotplug storm detection,
 and the ability to override the method used for detecting changes in
 connection status.

 Please review this in the context of the user being able to manually
 override the hotplug detection method for an individual connector. In
 that role this makes a lot of sense as it should improve the user
 experience in quite a few situations.

The problem I see is that userspace _can't_ trust the kernel like
this, i.e. the optimization you do in

http://cgit.freedesktop.org/~ickle/xf86-video-intel/commit/?h=hotplug-propertyid=995173e5e5adf8297957155cceab28bdf928022b

to not force the kernel into the full -fill_modes dance will break
systems. We do have a bunch of machines on record where we claim to
have full hpd support, but it doesn't seem to do anything useful.

But it's not just machines where hotplug flat-out does nothing, hw
hotplug is also pretty racy. We've tried to plug them a bit, but due
to the completely broken machines that regressed again.

The other thing that irks me is that we give the user the option to
override stuff. Imo stuff _really_ should just work, and it sounds
like we have to do the same retraining exercise with please drop
poll=0 from your boot options as with disabling modeset. So up to a
certain catastrophic level I prefer pitchforks in front of my house
over people just quirking each and every machine themselves.

Lastly I'm not too happy about how complicated the re-detect avoidance
logic works with your two kernel patches + the userspace change.
Originally I've thought it doesn't solve the edid re-reading issue,
but after carefully re-reading things I stand corrected:
- output poll work or hpd handler call just -detect from the helpers interface
- if a change has happened it'll eventually call down to the fb helper
(note that we might end up with kms only drivers who punt on this
eventually). Thanks to the new force parameter it'll forego the
-detect and only call -get_modes.
- Then userspace makes sure that none of -fill_modes will get called,
which avoids both the -detect and the -get_modes.

So it's pretty tricky, and also doesn't avoid re-reading the EDID if
both -detect and -get_modes does that. Also I don't like that fbdev
gets special treatment interface-wise compared to userspace (it can
set force=false, which userspace can't). I've very much like to avoid
this, our kms interface should be good enough for both userspace and
legacy fbdev.

Finally a pure process thing on top: I'd like to confirm that Egbert's
hotplug storm stuff is solid before we frob our detect code a bit
more. Which means 3.10 should get out the door first and we need to
ping the various bug reporters a bit.

Cheers, Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[Bug 65091] power_profile not working for HD5650

2013-06-08 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=65091

--- Comment #4 from Alan Swanson swan...@ukfsn.org ---
You can try my patch *if* you have good cooling as Alex indicated (on IRC) he
would not be applying the patch due to potential overheating. We're all still
awaiting the lawyers review of improved power manangement code.

http://lists.freedesktop.org/archives/dri-devel/2013-May/039247.html

My patch didn't include memory clocks as I'm running an APU rather than a
discrete card so could not test. So if you add a max_mclk setting, note to
guard it with an if !(rdev-flags  RADEON_IS_IGP) in
radeon_pm_get_max_clocks().

Unsurprisingly my frame rates improved over 100% from the default 200MHz but
idles back down on DPMS off with the auto power profile.

-- 
You are receiving this mail because:
You are the assignee for the bug.
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] drm: Avoid forcing a detection cycle following a hotplug event

2013-06-08 Thread Daniel Vetter
On Wed, Jun 5, 2013 at 5:50 PM, Chris Wilson ch...@chris-wilson.co.uk wrote:
 The typical procedure after a hotplug event is then to enumerate all the
 new modes. In the existing code, this is achieved by performing a forced
 detection cycle over all connectors. Ideally, we should just be able to
 use the current detection status and only enumerate the modes on the
 connectors that changed. This is a step in that direction by teaching
 the hotplug path to only use the known detection status rather than
 performing a second *forced* detection on every connector. As it
 currently stands, the first thing userspace does upon receipt of a
 hotplug uevent is call DRM_IOCTL_MODE_GETCONNECTOR on each connector,
 which of course, performs another full detection cycle.

 Signed-off-by: Chris Wilson ch...@chris-wilson.co.uk
 Cc: dri-devel@lists.freedesktop.org
 Cc: Jakob Bornecrantz ja...@vmware.com
 Cc: Inki Dae inki@samsung.com
 Cc: Adam Jackson a...@redhat.com

I've dumped a bit a longer blabla text onto the i915 patch in this
series (and cc'ed dri-devel on it), so just the gist: I'm a bit
unhappy that we add a force parameter here essentially just for the
fbdev helper. Imo userspace and legacy fbdev should use the same api,
if that's not good enough the interface is probably not fully
suitable. The end result is a pretty convoluted sequence:
- hpd/poll work calls -detect
- fbdev calls into -fill_modes, but avoids -detect with the
force=false parameter, so this is the part which calls -get_modes
- userspace avoids calling -fill_modes with a special trick

I prefer things more explicit ;-)

Cheers, Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[PULL] drm-intel-next

2013-06-08 Thread Daniel Vetter
Hi Dave,

Another round of drm-intel-next for 3.11. Highlights:
- Haswell IPS support (Paulo Zanoni)
- VECS support on Haswell (Ben Widawsky, Xiang Haihao, ...)
- Haswell watermark fixes (Paulo Zanoni)
- Make the gun bigger again multithread fence fix from Chris.
- i915_error_state finnally no longer fails with -ENOMEM! Big thanks to
  Mika for tackling this.
- vlv sideband locking fixes from Jani
- Hangcheck prep work for arb_robustness support (MikaChris)
- edp vs cpu port confusion clean-up from Imre
- pile of smaller fixes and cleanups all over.

Cheers, Daniel

The following changes since commit e1b73cba13a0cc68dd4f746eced15bd6bb24cda4:

  Merge tag 'v3.10-rc2' into drm-intel-next-queued (2013-05-21 09:52:16 +0200)

are available in the git repository at:


  git://people.freedesktop.org/~danvet/drm-intel tags/drm-intel-next-2013-06-01

for you to fetch changes up to 92d44621ad2d083bc03920c904ca0a5eb10d9ded:

  drm/i915: add i915_ips_status debugfs entry (2013-05-31 21:40:20 +0200)


Ben Widawsky (20):
  drm/i915: Fix error state memory leaks
  drm/i915: pre-fixes for checkpatch
  drm/i915: use mappable size for fb kickout
  drm/i915: use drm_mm_takedown
  drm/i915: context debug messages
  drm/i915: Call context fini at cleanup
  drm/i915: Comments for semaphore clarification
  drm/i915: Semaphore MBOX update generalization
  drm/i915: Introduce VECS: the 4th ring
  drm/i915: Add VECS semaphore bits
  drm/i915: Rename ring flush functions
  drm/i915: Vebox ringbuffer init
  drm/i915: Create a more generic pm handler for hsw+
  drm/i915: Create an ivybridge_irq_preinstall
  drm/i915: Add PM regs to pre/post install
  drm/i915: make PM interrupt writes non-destructive
  drm/i915: Convert irq_refounct to struct
  drm/i915: consolidate interrupt naming scheme
  drm/i915: vebox interrupt get/put
  drm/i915: Enable vebox interrupts

Chris Wilson (3):
  drm/i915: Be more informative when reporting too large for aperture 
error
  drm/i915: Workaround incoherence with fence updates on Valleyview
  drm/i915: Avoid promoting a simulated hang to 'wedged'

Daniel Vetter (6):
  drm/i915: fixup i915_pipe_enabled check in i915_irq.c
  drm/i915: hw state readoutcheck support for cpu_transcoder
  drm/i915: add basic pipe config dump support
  drm/i915: drop a few really redundant WARNs in hsw mode_set
  drm/i915: fix pch_nop support
  drm/i915: fix up the edp power well check

Imre Deak (5):
  drm/i915: release scratch page at module unload
  drm/i915: stop using is_cpu_edp() in intel_disable/post_disable_dp
  drm/i915: merge VLV eDP and DP AUX clock divider calculation
  drm/i915: replace is_cpu_edp() with a check for port A
  drm/i915: remove unused is_cpu_edp()

Jani Nikula (6):
  drm/i915: group sideband register accessors to a new file
  drm/i915: refactor VLV IOSF sideband accessors to use one helper
  drm/i915: drop redundant warnings on not holding dpio_lock
  drm/i915: rename VLV IOSF sideband functions logically
  drm/i915: change VLV IOSF sideband accessors to not return error code
  drm/i915: document why dvo/sdvo/crt need a special dpms function

Jesse Barnes (1):
  drm/i915: add encoder get_config function v5

Mika Kuoppala (5):
  drm/i915: avoid big kmallocs on reading error state
  drm/i915: pass seqno to i915_hangcheck_ring_idle
  drm/i915: track ring progression using seqnos
  drm/i915: introduce i915_hangcheck_ring_hung
  drm/i915: release cursor when crtc is destroyed

Paulo Zanoni (16):
  drm/i915: ILK, SNB and IVB don't have linetime watermarks
  drm/i915: remove intel_update_linetime_watermarks
  drm/i915: use the mode-htotal to calculate linetime watermarks
  drm/i915: fix haswell linetime watermarks calculation
  drm/i915: make intel_ddi_get_cdclk_freq return values in KHz
  drm/i915: set the IPS linetime watermark
  drm/i915: MCH_SSKPD is a 64 bit register on Haswell
  drm/i915: set FORCE_ARB_IDLE_PLANES workaround
  drm/i915: add enable argument to intel_update_sprite_watermarks
  drm/i915: add haswell_update_sprite_wm
  drm/i915: properly set HSW WM_PIPE registers
  drm/i915: properly set HSW WM_LP watermarks
  drm/i915: add support for 5/6 data buffer partitioning on Haswell
  drm/i915: implement IPS feature
  drm/i915: add enable_ips module option
  drm/i915: add i915_ips_status debugfs entry

Thomas Meyer (1):
  drm/i915: Cocci spatch memdup.spatch

Ville Syrjälä (2):
  drm/i915: Fix WARN_ON() on UP machines
  drm: Fix drm_rect documentation

Wei Yongjun (1):
  drm/i915: fix error return code in init_pipe_control()

Xiang, Haihao (4):
  drm/i915: add HAS_VEBOX
  drm/i915: add VEBOX into debugfs
  drm/i915: add I915_EXEC_VEBOX to i915_gem_do_execbuffer()

[Bug 36602] Hierarchical Z support for R600

2013-06-08 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=36602

Alex Deucher ag...@yahoo.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #52 from Alex Deucher ag...@yahoo.com ---
HyperZ support was merged a while ago.  Closing.

-- 
You are receiving this mail because:
You are the assignee for the bug.
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: Quick question about status of bug 36602, Hierarchical Z support for R600

2013-06-08 Thread Alex Deucher
On Fri, Jun 7, 2013 at 9:03 PM, Dave Witbrodt dawit...@sbcglobal.net wrote:
 I was just clearing out some bookmarks in my browser and noticed that #36602
 is still open.  Seems like you've had HiZ in r600 for a while, so I was
 wondering if this bug can be closed?  No new posts there since September.

Yes, HyperZ support was merged a while ago.  I've closed the bug.

Alex
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] drm/radeon: fix AVI infoframe generation

2013-06-08 Thread Alex Deucher
On Sat, Jun 8, 2013 at 7:46 AM, Rafał Miłecki zaj...@gmail.com wrote:
 2013/6/7  alexdeuc...@gmail.com:
 From: Alex Deucher alexander.deuc...@amd.com

 - remove adding 2 to checksum, this breaks certain monitors
 - properly emit the AVI infoframe version, not emitting
 the version breaks some monitors.

 This should fix blank screen when HDMI audio is enabled on
 certain monitors.

 Err, nack. I believe this it actually going to *break* some monitors
 compatibility.

Yeah, it seems to break as many as it fixes :(


 For some unknown reason AMD hardware uses 0x81 and 0x01 for type and
 version of infoframe. See this comment (written/published by you):
 /* The following packets and infoframes are required for HDMI:
  * Packets:
  * 0x00 - Null packet
  * 0x01 - Audio clock regen
  * 0x02 - Audio sample
  * 0x03 - General Control
  * Infoframes:
  * 0x81 0x01 - AVI
  * 0x83 0x03 - audio
  */

 As you can see, AMD hardware uses 0x81 and 0x01. I've no idea why,
 according to the HDMI standard it should be 0x82 and 0x02. All other
 vendors seems to also use 0x82 and 0x02. In function
 hdmi_avi_infoframe_init type it set to 0x82 and 0x02.


The internal afmt validation code I've seen uses 0x82 and 0x2 (for
DCE4 and newer asics, I'm not sure what we do for older versions), so
I think it may depend on the monitor and the GPU hardware.  We may
need to add some logic to determine what version to send based on the
monitor's caps.


 This type and version it's written anywhere, but they are used to
 calculate checksum. Checksum it what we store is frame[0x0]. We
 calculate checksum as 0x100 - sum (see hdmi_infoframe_checksum).

 Now... with common drm code we use 0x82 and 0x02 instead of 0x81 and
 0x01. It means our sum is too big by 0x02. It means we have to use
 0x100 - sum + 0x02 as checksum for AMD hardware.


It would probably be cleaner to just adjust the header and version
before calling hdmi_avi_infoframe_pack() so we don't have to add the
hack.

Alex

 This whole hack was introduced in 92db7f6c860b8190571a9dc1fcbc16d003422fe8:
 drm/radeon/kms: workaround invalid AVI infoframe checksum issue
 and I'm pretty sure it was verified to fix somebody's HDMI mode. It
 also seems to be compatible with AMD specs (at least the part of it we
 can see in the quoted comment).

 For proof of fglrx doing the same, please see my e-mail where I
 provided dumps from registers when using fglrx:
 http://lists.freedesktop.org/archives/dri-devel/2011-December/017717.html
 (it was tested on 5 different cards!).

 When working on that patch I was talking  debugging with few people
 on IRC. That mean I don't have logs anymore, but I'm sure I was
 testing exactly that single value and it was immediately fixing
 selected displays. I mean testing by writing something like:

 avivotool regset 0x10884 0x00a85e4f
 vs.
 avivotool regset 0x10884 0x00a85e4d

 --
 Rafał
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[RPC 0/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

Hello

Here is the first run at inspection of the VIA openchrome dri 
driver. Now that the Xorg driver has been out over a year with KMS support
most people should be able to use this feature. The driver is totaly 
complete but we wanted to merge it so people with newer hardware that has 
HDMI/DVI-D support can be able to run X windows. Your xorg driver does not 
implement HDMI/DVI in UMS mode and we don't have the resources to do this 
work. Basic TTM/GEM is supported but currently you can't run any 
acceleration with the command queue. Over the next 6 months this should be 
implemented. Thank you.
 
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[RFC 1/21] Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 1fcf23d361375645d586756d126b436796ba4fba
Author: James Simmons jsimm...@infradead.org
Date:   Sat Jun 8 09:31:57 2013 -0400

via: New KMS ioctls and hardware to support.

Add new VIA pci ids to support newer hardware. Cleanup userspace
api structs to remove kernel types and add the new KMS ioctls we
will be supporting.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index c129162..5a4 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -1370,8 +1370,11 @@
 #define PCI_DEVICE_ID_VIA_VT3324   0x0324
 #define PCI_DEVICE_ID_VIA_VT3336   0x0336
 #define PCI_DEVICE_ID_VIA_VT3351   0x0351
+#define PCI_DEVICE_ID_VIA_VT3353   0x0353
 #define PCI_DEVICE_ID_VIA_VT3364   0x0364
 #define PCI_DEVICE_ID_VIA_8371_0   0x0391
+#define PCI_DEVICE_ID_VIA_VT3409   0x0409
+#define PCI_DEVICE_ID_VIA_VT3410   0x0410
 #define PCI_DEVICE_ID_VIA_6415 0x0415
 #define PCI_DEVICE_ID_VIA_8501_0   0x0501
 #define PCI_DEVICE_ID_VIA_82C561   0x0561
@@ -1385,6 +1388,7 @@
 #define PCI_DEVICE_ID_VIA_8605_0   0x0605
 #define PCI_DEVICE_ID_VIA_82C686   0x0686
 #define PCI_DEVICE_ID_VIA_82C691_0 0x0691
+#define PCI_DEVICE_ID_VIA_VT1122   0x1122
 #define PCI_DEVICE_ID_VIA_82C576_1 0x1571
 #define PCI_DEVICE_ID_VIA_82C586_2 0x3038
 #define PCI_DEVICE_ID_VIA_82C586_3 0x3040
@@ -1399,16 +1403,20 @@
 #define PCI_DEVICE_ID_VIA_8653_0   0x3101
 #define PCI_DEVICE_ID_VIA_8622 0x3102
 #define PCI_DEVICE_ID_VIA_8235_USB_2   0x3104
+#define PCI_DEVICE_ID_VIA_K8M800   0x3108
 #define PCI_DEVICE_ID_VIA_8233C_0  0x3109
 #define PCI_DEVICE_ID_VIA_8361 0x3112
 #define PCI_DEVICE_ID_VIA_XM2660x3116
+#define PCI_DEVICE_ID_VIA_PM8000x3118
 #define PCI_DEVICE_ID_VIA_612X 0x3119
+#define PCI_DEVICE_ID_VIA_CLE266   0x3122
 #define PCI_DEVICE_ID_VIA_862X_0   0x3123
 #define PCI_DEVICE_ID_VIA_8753_0   0x3128
 #define PCI_DEVICE_ID_VIA_8233A0x3147
 #define PCI_DEVICE_ID_VIA_8703_51_00x3148
 #define PCI_DEVICE_ID_VIA_8237_SATA0x3149
 #define PCI_DEVICE_ID_VIA_XN2660x3156
+#define PCI_DEVICE_ID_VIA_VT3157   0x3157
 #define PCI_DEVICE_ID_VIA_6410 0x3164
 #define PCI_DEVICE_ID_VIA_8754C_0  0x3168
 #define PCI_DEVICE_ID_VIA_8235 0x3177
@@ -1416,12 +1424,20 @@
 #define PCI_DEVICE_ID_VIA_8377_0   0x3189
 #define PCI_DEVICE_ID_VIA_8378_0   0x3205
 #define PCI_DEVICE_ID_VIA_8783_0   0x3208
+#define PCI_DEVICE_ID_VIA_CN7500x3225
 #define PCI_DEVICE_ID_VIA_8237 0x3227
+#define PCI_DEVICE_ID_VIA_K8M890   0x3230
 #define PCI_DEVICE_ID_VIA_8251 0x3287
 #define PCI_DEVICE_ID_VIA_8261 0x3402
 #define PCI_DEVICE_ID_VIA_8237A0x3337
+#define PCI_DEVICE_ID_VIA_VT3343   0x3343
+#define PCI_DEVICE_ID_VIA_CN7000x3344
+#define PCI_DEVICE_ID_VIA_P4M900   0x3371
 #define PCI_DEVICE_ID_VIA_8237S0x3372
+#define PCI_DEVICE_ID_VIA_VX8750x5122
 #define PCI_DEVICE_ID_VIA_SATA_EIDE0x5324
+#define PCI_DEVICE_ID_VIA_KM4000x7205
+#define PCI_DEVICE_ID_VIA_VX9000x7122
 #define PCI_DEVICE_ID_VIA_8231 0x8231
 #define PCI_DEVICE_ID_VIA_8231_4   0x8235
 #define PCI_DEVICE_ID_VIA_8365_1   0x8305
@@ -1429,7 +1445,7 @@
 #define PCI_DEVICE_ID_VIA_CX700_IDE0x0581
 #define PCI_DEVICE_ID_VIA_VX8000x8353
 #define PCI_DEVICE_ID_VIA_VX8550x8409
-#define PCI_DEVICE_ID_VIA_VX9000x8410
+#define PCI_DEVICE_ID_VIA_8410 0x8410
 #define PCI_DEVICE_ID_VIA_8371_1   0x8391
 #define PCI_DEVICE_ID_VIA_82C598_1 0x8598
 #define PCI_DEVICE_ID_VIA_838X_1   0xB188
diff --git a/include/uapi/drm/via_drm.h b/include/uapi/drm/via_drm.h
index 8b0533c..73ccb10 100644
--- a/include/uapi/drm/via_drm.h
+++ b/include/uapi/drm/via_drm.h
@@ -16,7 +16,7 @@
  * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
@@ -33,14 +33,10 @@
 #ifndef _VIA_DEFINES_
 #define _VIA_DEFINES_
 
-#ifndef __KERNEL__
-#include via_drmclient.h
-#endif
-
 #define VIA_NR_SAREA_CLIPRECTS 8
-#define VIA_NR_XVMC_PORTS   10
-#define VIA_NR_XVMC_LOCKS   5
-#define VIA_MAX_CACHELINE_SIZE  64
+#define VIA_NR_XVMC_PORTS  10
+#define 

[RFC 2/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit f0be3523498cd2422d95af1e5e47f51e099f90e4
Author: James Simmons jsimm...@infradead.org
Date:   Thu Jun 6 18:57:00 2013 -0400

via: register setting helpers

The code in the crtc_hw was written to handle to cases of
programming the registers on the graphics card. Basic
routines of programming of the registers already existing
in the vga.h header in include/video that has been used
for some of the frame buffer drivers. We add some of the
missing bit masking and setting  routines into crtc_hw.h
but it would be nice some day to move those over to vga.h
itself.

Addition code had been written to handle two common cases.
The first case is that all the bits to be set are all located
into the same register. The function to handle this is
load_register_table. The second case is when the bits for
a specific function are scattered across several registers.
The load_value_to_registers handles the second case. This
code is written such that it can be used by any other driver
and could even be placed some where that it can be shared
by multiple drivers.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/crtc_hw.c b/drivers/gpu/drm/via/crtc_hw.c
new file mode 100644
index 000..f71c14e
--- /dev/null
+++ b/drivers/gpu/drm/via/crtc_hw.c
@@ -0,0 +1,88 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the Software),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * James Simmons jsimm...@infradead.org
+ */
+
+#include video/vga.h
+#include crtc_hw.h
+
+/*
+ * load_register_table enables the ability to set entire
+ * tables of registers. For each register defined by the
+ * port and the index for that register is programmed
+ * with a masked value.
+ */
+void
+load_register_tables(void __iomem *regbase, struct vga_registers *regs)
+{
+   u8 cr_index, orig, reg_mask, data;
+   unsigned int i;
+   u16 port;
+
+   for (i = 0; i  regs-count; i++) {
+   reg_mask = regs-regs[i].start_bit;
+   data = regs-regs[i].end_bit;
+   cr_index = regs-regs[i].io_addr;
+   port = regs-regs[i].ioport;
+
+   vga_w(regbase, port, cr_index);
+   orig = (vga_r(regbase, port + 1)  ~reg_mask);
+   vga_w(regbase, port + 1, ((data  reg_mask) | orig));
+   }
+}
+
+/*
+ * Due to the limitation of how much data you can write to a single
+ * register we run into data that can't be written in only one register.
+ * So load_value_to_register was developed to be able to define register
+ * tables that can load different bit ranges of the data to different
+ * registers.
+ */
+void
+load_value_to_registers(void __iomem *regbase, struct vga_registers *regs,
+   unsigned int value)
+{
+   unsigned int bit_num = 0, shift_next_reg, reg_mask;
+   u8 start_index, end_index, cr_index, orig;
+   unsigned int data, i, j;
+   u16 get_bit, port;
+
+   for (i = 0; i  regs-count; i++) {
+   start_index = regs-regs[i].start_bit;
+   end_index = regs-regs[i].end_bit;
+   cr_index = regs-regs[i].io_addr;
+   port = regs-regs[i].ioport;
+   reg_mask = data = 0;
+
+   shift_next_reg = bit_num;
+   for (j = start_index; j = end_index; j++) {
+   reg_mask = reg_mask | (1  j);
+   get_bit = (value  (1  bit_num));
+   data |= ((get_bit  shift_next_reg)  start_index);
+   bit_num++;
+   }
+
+   vga_w(regbase, port, cr_index);
+   orig = (vga_r(regbase, port + 1)  ~reg_mask);
+   vga_w(regbase, port + 1, ((data  reg_mask) | orig));
+   }
+}
diff --git a/drivers/gpu/drm/via/crtc_hw.h b/drivers/gpu/drm/via/crtc_hw.h
new file mode 100644
index 000..a04b469
--- /dev/null
+++ 

[RFC 3/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons
commit 30a9dda2deeebcf611cbeaffb38f0f94c708a976
Author: James Simmons jsimm...@infradead.org
Date:   Thu Jun 6 20:28:33 2013 -0400

via: fence implementation

For each buffer object we create a fence in order to know what
its state is. A fence notifies us when a object is consumed by
the command queue or if it lost in the queue so we can time it
out. In our design each fence (struct via_fence) belongs to a
fence_pool. A fence_pool represents the way the hardware
handles the buffer object i.e DMA, 2D etc. Each pool itself
will have a number of fence engines to represent each hardware
channel. For exmaple for via hardare we have four DMA engines
which is represented by one type of pool.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/via_fence.c b/drivers/gpu/drm/via/via_fence.c
new file mode 100644
index 000..98489d5
--- /dev/null
+++ b/drivers/gpu/drm/via/via_fence.c
@@ -0,0 +1,282 @@
+/*
+ * Copyright 2013 James Simmons jsimm...@infradead.org
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the Software),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#include linux/random.h
+#include drmP.h
+
+#include via_drv.h
+
+static void
+via_fence_destroy(struct kref *kref)
+{
+   struct via_fence *fence = container_of(kref, struct via_fence, kref);
+
+   if (fence-pool-fence_cleanup)
+   fence-pool-fence_cleanup(fence);
+   kfree(fence);
+}
+
+struct via_fence *
+via_fence_create_and_emit(struct via_fence_pool *pool, void *data,
+   unsigned int engine)
+{
+   struct via_fence *fence = NULL;
+
+   fence = kzalloc(sizeof(*fence), GFP_KERNEL);
+   if (fence) {
+   unsigned long flags;
+   int ret = -EINVAL;
+
+   fence-timeout = jiffies + 3 * HZ;
+   fence-engine = engine;
+   fence-pool = pool;
+   fence-priv = data;
+   kref_init(fence-kref);
+
+   if (engine = pool-num_engines) {
+   via_fence_unref((void **) fence);
+   return ERR_PTR(-ENXIO);
+   }
+   spin_lock_irqsave(pool-lock, flags);
+try_again:
+   /* I like to use get_random_init but it is not exported :-( */
+   get_random_bytes(fence-seq.key, 3);
+   /* For the small change you get a zero */
+   if (unlikely(fence-seq.key == 0))
+   goto try_again;
+
+   ret = drm_ht_insert_item_rcu(pool-pending, fence-seq);
+   if (unlikely(ret))
+   goto try_again;
+
+   ret = pool-fence_emit(fence);
+   if (ret) {
+   DRM_INFO(Failed to emit fence\n);
+   drm_ht_remove_item_rcu(pool-pending, fence-seq);
+   via_fence_unref((void **) fence);
+   fence = ERR_PTR(ret);
+   }
+   spin_unlock_irqrestore(pool-lock, flags);
+   }
+   return fence;
+}
+
+static void
+via_fence_work(struct work_struct *work)
+{
+   struct via_fence_engine *eng = container_of(work, struct 
via_fence_engine,
+   fence_work);
+   unsigned long seq = readl(eng-read_seq), flags;
+   struct via_fence_pool *pool = eng-pool;
+   struct drm_hash_item *hash = NULL;
+   int ret;
+
+   spin_lock_irqsave(eng-pool-lock, flags);
+   ret = drm_ht_find_item_rcu(pool-pending, seq, hash);
+   if (likely(ret == 0)) {
+   ret = drm_ht_remove_item_rcu(pool-pending, hash);
+   if (ret  0)
+   DRM_DEBUG(Failed to remove seq %lx\n, seq);
+   }
+   if (eng-pool-fence_signaled)
+   eng-pool-fence_signaled(eng);
+   spin_unlock_irqrestore(eng-pool-lock, flags);
+}
+
+static bool

[RFC 4/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 6e79030fb92d3461b4a962630245d93944d5d349
Author: James Simmons jsimm...@infradead.org
Date:   Fri Jun 7 20:17:06 2013 -0400

via: ttm pcie dma bo_driver handling

Newer VIA hardware has moved from AGP to more modern PCIe
based hardware. The TTM layer provides support for AGP but
drm drivers need to handle PCIe support themselves. The
code in via_sgdma.c provides the TTM backend so one can
allows the graphics card direct access to the host system
memory.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/via_sgdma.c b/drivers/gpu/drm/via/via_sgdma.c
new file mode 100644
index 000..0dfd1a6
--- /dev/null
+++ b/drivers/gpu/drm/via/via_sgdma.c
@@ -0,0 +1,118 @@
+/**
+ *
+ * Copyright (c) 2012 James Simmons jsimm...@infradead.org
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * Software), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include via_drv.h
+
+static int
+via_pcie_sgdma_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem)
+{
+   struct sgdma_tt *dma_tt = (struct sgdma_tt *) ttm;
+   struct ttm_bo_device *bdev = dma_tt-sgdma.ttm.bdev;
+   struct drm_via_private *dev_priv =
+   container_of(bdev, struct drm_via_private, bdev);
+   int i;
+
+   /* Disable gart table HW protect */
+   svga_wseq_mask(VGABASE, 0x6C, 0x00, BIT(7));
+
+   /* Update the relevant entries */
+   dma_tt-offset = mem-start  PAGE_SHIFT;
+   for (i = 0; i  ttm-num_pages; i++) {
+   writel(page_to_pfn(ttm-pages[i])  0x3FFF,
+   dev_priv-gart.virtual + dma_tt-offset + i);
+   }
+
+   /* Invalided GTI cache */
+   svga_wseq_mask(VGABASE, 0x6F, BIT(7), BIT(7));
+
+   /* Enable gart table HW protect */
+   svga_wseq_mask(VGABASE, 0x6C, BIT(7), BIT(7));
+   return 1;
+}
+
+static int
+via_pcie_sgdma_unbind(struct ttm_tt *ttm)
+{
+   struct sgdma_tt *dma_tt = (struct sgdma_tt *) ttm;
+   struct ttm_bo_device *bdev = dma_tt-sgdma.ttm.bdev;
+   struct drm_via_private *dev_priv =
+   container_of(bdev, struct drm_via_private, bdev);
+   int i;
+
+   if (ttm-state != tt_bound)
+   return 0;
+
+   /* Disable gart table HW protect */
+   svga_wseq_mask(VGABASE, 0x6C, 0x00, BIT(7));
+
+   /* Update the relevant entries */
+   for (i = 0; i  ttm-num_pages; i++)
+   writel(0x8000, dev_priv-gart.virtual + dma_tt-offset + i);
+   dma_tt-offset = 0;
+
+   /* Invalided GTI cache */
+   svga_wseq_mask(VGABASE, 0x6F, BIT(7), BIT(7));
+
+   /* Enable gart table HW protect */
+   svga_wseq_mask(VGABASE, 0x6C, BIT(7), BIT(7));
+   return 0;
+}
+
+static void
+via_sgdma_destroy(struct ttm_tt *ttm)
+{
+   struct sgdma_tt *dma_tt = (struct sgdma_tt *) ttm;
+
+   if (ttm) {
+   ttm_dma_tt_fini(dma_tt-sgdma);
+   kfree(dma_tt);
+   }
+}
+
+static struct ttm_backend_func ttm_sgdma_func = {
+   .bind = via_pcie_sgdma_bind,
+   .unbind = via_pcie_sgdma_unbind,
+   .destroy = via_sgdma_destroy,
+};
+
+struct ttm_tt *
+via_sgdma_backend_init(struct ttm_bo_device *bdev, unsigned long size,
+   uint32_t page_flags, struct page *dummy_read_page)
+{
+   struct sgdma_tt *dma_tt;
+
+   dma_tt = kzalloc(sizeof(*dma_tt), GFP_KERNEL);
+   if (!dma_tt)
+   return NULL;
+
+   dma_tt-sgdma.ttm.func = ttm_sgdma_func;
+
+   if (ttm_dma_tt_init(dma_tt-sgdma, bdev, size, page_flags, 
dummy_read_page)) {
+   kfree(dma_tt);
+   return NULL;
+   }
+   return dma_tt-sgdma.ttm;
+}
+EXPORT_SYMBOL(via_sgdma_backend_init);
___
dri-devel mailing list
dri-devel@lists.freedesktop.org

[RFC 5/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit fa8599a207fbd0b4ffaa8c6961d34797f615ed7d
Author: James Simmons jsimm...@infradead.org
Date:   Fri Jun 7 19:58:14 2013 -0400

via: ttm bo driver implementation

The openchrome project decided to use the TTM api as the backend to
support GEM. The core needed to support TTM is struct ttm_bo_driver
which is implemented in via_ttm.c. This back end supports both AGP
and PCIe.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/via_ttm.c b/drivers/gpu/drm/via/via_ttm.c
new file mode 100644
index 000..5d6aead
--- /dev/null
+++ b/drivers/gpu/drm/via/via_ttm.c
@@ -0,0 +1,495 @@
+/*
+ * Copyright 2012 James Simmons jsimm...@infradead.org. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the Software),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#include linux/dma-mapping.h
+#ifdef CONFIG_SWIOTLB
+#include linux/swiotlb.h
+#endif
+
+#include via_drv.h
+
+static struct ttm_tt *
+via_ttm_tt_create(struct ttm_bo_device *bdev, unsigned long size,
+   uint32_t page_flags, struct page *dummy_read_page)
+{
+#if __OS_HAS_AGP
+   struct drm_via_private *dev_priv =
+   container_of(bdev, struct drm_via_private, bdev);
+
+   if (drm_pci_device_is_agp(dev_priv-dev))
+   return ttm_agp_tt_create(bdev, dev_priv-dev-agp-bridge,
+   size, page_flags, dummy_read_page);
+#endif
+   return via_sgdma_backend_init(bdev, size, page_flags, dummy_read_page);
+}
+
+static int
+via_ttm_tt_populate(struct ttm_tt *ttm)
+{
+   struct sgdma_tt *dma_tt = (struct sgdma_tt *) ttm;
+   struct ttm_dma_tt *sgdma = dma_tt-sgdma;
+   struct ttm_bo_device *bdev = ttm-bdev;
+   struct drm_via_private *dev_priv =
+   container_of(bdev, struct drm_via_private, bdev);
+   struct drm_device *dev = dev_priv-dev;
+   unsigned int i;
+   int ret = 0;
+
+   if (ttm-state != tt_unpopulated)
+   return 0;
+
+#if __OS_HAS_AGP
+   if (drm_pci_device_is_agp(dev_priv-dev))
+   return ttm_agp_tt_populate(ttm);
+#endif
+
+#ifdef CONFIG_SWIOTLB
+   if (swiotlb_nr_tbl())
+   return ttm_dma_populate(sgdma, dev-dev);
+#endif
+
+   ret = ttm_pool_populate(ttm);
+   if (ret)
+   return ret;
+
+   for (i = 0; i  ttm-num_pages; i++) {
+   sgdma-dma_address[i] = pci_map_page(dev-pdev, ttm-pages[i],
+   0, PAGE_SIZE,
+   PCI_DMA_BIDIRECTIONAL);
+   if (pci_dma_mapping_error(dev-pdev, sgdma-dma_address[i])) {
+   while (--i) {
+   pci_unmap_page(dev-pdev, sgdma-dma_address[i],
+   PAGE_SIZE, 
PCI_DMA_BIDIRECTIONAL);
+   sgdma-dma_address[i] = 0;
+   }
+   ttm_pool_unpopulate(ttm);
+   return -EFAULT;
+   }
+   }
+   return ret;
+}
+
+static void
+via_ttm_tt_unpopulate(struct ttm_tt *ttm)
+{
+   struct sgdma_tt *dma_tt = (struct sgdma_tt *) ttm;
+   struct ttm_dma_tt *sgdma = dma_tt-sgdma;
+   struct ttm_bo_device *bdev = ttm-bdev;
+   struct drm_via_private *dev_priv =
+   container_of(bdev, struct drm_via_private, bdev);
+   struct drm_device *dev = dev_priv-dev;
+   unsigned int i;
+
+#if __OS_HAS_AGP
+   if (drm_pci_device_is_agp(dev_priv-dev)) {
+   ttm_agp_tt_unpopulate(ttm);
+   return;
+   }
+#endif
+
+#ifdef CONFIG_SWIOTLB
+   if (swiotlb_nr_tbl()) {
+   ttm_dma_unpopulate(sgdma, dev-dev);
+   return;
+   }
+#endif
+
+   for (i = 0; i  ttm-num_pages; i++) {
+   if (sgdma-dma_address[i]) {
+   

[RFC 6/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 5ec2cdc6f99549122329253b1c4d1a04193b81d0
Author: James Simmons jsimm...@infradead.org
Date:   Sat Jun 8 07:59:56 2013 -0400

via: TTM and GEM memory handling

TTM buffer object life cycle and state handling is done in init_ttm.c.
The VIA GEM implemenation is a simple wrapper around the TTM layer
that uses our ttm functions from init_ttm.c

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/init_ttm.c b/drivers/gpu/drm/via/init_ttm.c
new file mode 100644
index 000..ead32a1
--- /dev/null
+++ b/drivers/gpu/drm/via/init_ttm.c
@@ -0,0 +1,249 @@
+/*
+ * Copyright (c) 2012 James Simmons
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the Software),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include drmP.h
+#include ttm/ttm_bo_driver.h
+#include ttm/ttm_placement.h
+
+#define DRM_FILE_PAGE_OFFSET (0x1ULL  PAGE_SHIFT)
+
+struct ttm_heap {
+   uint32_t busy_placements[TTM_NUM_MEM_TYPES];
+   uint32_t placements[TTM_NUM_MEM_TYPES];
+   struct ttm_buffer_object pbo;
+};
+
+static int
+ttm_global_mem_init(struct drm_global_reference *ref)
+{
+   return ttm_mem_global_init(ref-object);
+}
+
+static void
+ttm_global_mem_release(struct drm_global_reference *ref)
+{
+   ttm_mem_global_release(ref-object);
+}
+
+void
+ttm_global_fini(struct drm_global_reference *global_ref,
+   struct ttm_bo_global_ref *global_bo,
+   struct ttm_bo_device *bdev)
+{
+   if (global_ref-release == NULL)
+   return;
+
+   if (bdev)
+   ttm_bo_device_release(bdev);
+   drm_global_item_unref(global_bo-ref);
+   drm_global_item_unref(global_ref);
+   global_ref-release = NULL;
+}
+
+int
+ttm_global_init(struct drm_global_reference *global_ref,
+   struct ttm_bo_global_ref *global_bo,
+   struct ttm_bo_driver *driver,
+   struct ttm_bo_device *bdev,
+   bool dma32)
+{
+   struct drm_global_reference *bo_ref;
+   int rc;
+
+   global_ref-global_type = DRM_GLOBAL_TTM_MEM;
+   global_ref-size = sizeof(struct ttm_mem_global);
+   global_ref-init = ttm_global_mem_init;
+   global_ref-release = ttm_global_mem_release;
+
+   rc = drm_global_item_ref(global_ref);
+   if (unlikely(rc != 0)) {
+   DRM_ERROR(Failed setting up TTM memory accounting\n);
+   global_ref-release = NULL;
+   return rc;
+   }
+
+   global_bo-mem_glob = global_ref-object;
+   bo_ref = global_bo-ref;
+   bo_ref-global_type = DRM_GLOBAL_TTM_BO;
+   bo_ref-size = sizeof(struct ttm_bo_global);
+   bo_ref-init = ttm_bo_global_init;
+   bo_ref-release = ttm_bo_global_release;
+
+   rc = drm_global_item_ref(bo_ref);
+   if (unlikely(rc != 0)) {
+   DRM_ERROR(Failed setting up TTM BO subsystem\n);
+   drm_global_item_unref(global_ref);
+   global_ref-release = NULL;
+   return rc;
+   }
+
+   rc = ttm_bo_device_init(bdev, bo_ref-object, driver,
+   DRM_FILE_PAGE_OFFSET, dma32);
+   if (rc) {
+   DRM_ERROR(Error initialising bo driver: %d\n, rc);
+   ttm_global_fini(global_ref, global_bo, NULL);
+   }
+   return rc;
+}
+
+static void
+ttm_buffer_object_destroy(struct ttm_buffer_object *bo)
+{
+   struct ttm_heap *heap = container_of(bo, struct ttm_heap, pbo);
+
+   kfree(heap);
+   heap = NULL;
+}
+
+/*
+ * the buffer object domain
+ */
+void
+ttm_placement_from_domain(struct ttm_buffer_object *bo, struct ttm_placement 
*placement, u32 domains,
+   struct ttm_bo_device *bdev)
+{
+   struct ttm_heap *heap = container_of(bo, struct ttm_heap, pbo);
+   int cnt = 0, i = 0;
+
+   if (!(domains  TTM_PL_MASK_MEM)) 

[RFC 7/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit a1296bc36bbc68963ef0294e94bef69ddb998c9a
Author: James Simmons jsimm...@infradead.org
Date:   Sat Jun 8 08:53:44 2013 -0400

via: i2c handling

In order to support EDID retrieval and the via camera on the XO data
much be collected over the i2c buses. We use the i2c layer developed
by the viafb project.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/via_i2c.c b/drivers/gpu/drm/via/via_i2c.c
new file mode 100644
index 000..f4fcdea
--- /dev/null
+++ b/drivers/gpu/drm/via/via_i2c.c
@@ -0,0 +1,204 @@
+/*
+ * Copyright 2012 James Simmons jsimm...@infradead.org All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE.See the GNU General Public License
+ * for more details.
+ *
+ * This part was influenced by the via i2c code written for the viafb
+ * driver by VIA Technologies and S3 Graphics
+ */
+#include via_drv.h
+
+enum viafb_i2c_adap;
+
+#include linux/via_i2c.h
+
+#define SERIAL 0
+#defineGPIO1
+
+static struct via_i2c_stuff via_i2c_par[5];
+
+static void via_i2c_setscl(void *data, int state)
+{
+   struct via_i2c_stuff *i2c = data;
+   struct drm_device *dev = i2c_get_adapdata(i2c-adapter);
+   struct drm_via_private *dev_priv = dev-dev_private;
+   u8 value, mask;
+
+   if (i2c-is_active == GPIO) {
+   mask = state ? BIT(7) : BIT(7) | BIT(5);
+   value = state ? 0x00 : BIT(7);
+   } else {
+   value = state ? BIT(5) : 0x00;
+   mask = BIT(5);
+   }
+   svga_wseq_mask(VGABASE, i2c-i2c_port, value, mask);
+}
+
+static int via_i2c_getscl(void *data)
+{
+   struct via_i2c_stuff *i2c = data;
+   struct drm_device *dev = i2c_get_adapdata(i2c-adapter);
+   struct drm_via_private *dev_priv = dev-dev_private;
+
+   return (vga_rseq(VGABASE, i2c-i2c_port)  BIT(3));
+}
+
+static int via_i2c_getsda(void *data)
+{
+   struct via_i2c_stuff *i2c = data;
+   struct drm_device *dev = i2c_get_adapdata(i2c-adapter);
+   struct drm_via_private *dev_priv = dev-dev_private;
+
+   return (vga_rseq(VGABASE, i2c-i2c_port)  BIT(2));
+}
+
+static void via_i2c_setsda(void *data, int state)
+{
+   struct via_i2c_stuff *i2c = data;
+   struct drm_device *dev = i2c_get_adapdata(i2c-adapter);
+   struct drm_via_private *dev_priv = dev-dev_private;
+   u8 value, mask;
+
+   if (i2c-is_active == GPIO) {
+   mask = state ? BIT(6) : BIT(6) | BIT(4);
+   value = state ? 0x00 : BIT(6);
+   } else {
+   value = state ? BIT(4) : 0x00;
+   mask = BIT(4);
+   }
+   svga_wseq_mask(VGABASE, i2c-i2c_port, value, mask);
+}
+
+struct i2c_adapter *via_find_ddc_bus(int port)
+{
+   struct i2c_adapter *adapter = NULL;
+   int i;
+
+   for (i = 0; i  ARRAY_SIZE(via_i2c_par); i++) {
+   struct via_i2c_stuff *i2c = via_i2c_par[i];
+
+   if (i2c-i2c_port == port) {
+   adapter = i2c-adapter;
+   break;
+   }
+   }
+   return adapter;
+}
+
+static int
+create_i2c_bus(struct drm_device *dev, struct via_i2c_stuff *i2c_par)
+{
+   struct i2c_adapter *adapter = i2c_par-adapter;
+   struct i2c_algo_bit_data *algo = i2c_par-algo;
+
+   algo-setsda = via_i2c_setsda;
+   algo-setscl = via_i2c_setscl;
+   algo-getsda = via_i2c_getsda;
+   algo-getscl = via_i2c_getscl;
+   algo-udelay = 15;
+   algo-timeout = usecs_to_jiffies(2200); /* from VESA */
+   algo-data = i2c_par;
+
+   sprintf(adapter-name, via i2c bit bus 0x%02x, i2c_par-i2c_port);
+   adapter-owner = THIS_MODULE;
+   adapter-class = I2C_CLASS_DDC;
+   adapter-algo_data = algo;
+   i2c_set_adapdata(adapter, dev);
+
+   /* Raise SCL and SDA */
+   via_i2c_setsda(i2c_par, 1);
+   via_i2c_setscl(i2c_par, 1);
+   udelay(20);
+
+   return i2c_bit_add_bus(adapter);
+}
+
+void
+via_i2c_readbytes(struct i2c_adapter *adapter,
+   u8 slave_addr, char offset,
+   u8 *buffer, unsigned int size)
+{
+   u8 out_buf[2];
+   u8 in_buf[2];
+   struct i2c_msg msgs[] = {
+   {
+   .addr = slave_addr,
+   .flags = 0,
+   .len = 1,
+   .buf = out_buf,
+   },
+   {
+   .addr = slave_addr,
+   .flags = I2C_M_RD,
+   .len = size,
+ 

[RFC 9/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 761567d6dd4ec80dbc39052ac74edf7626922f55
Author: James Simmons jsimm...@infradead.org
Date:   Sat Jun 8 09:39:04 2013 -0400

via: Hardware initalization/power management functions.

This code handles setting the inital state of the 2D,3D and MPEG engine
as well as our pcie gart tables. The code was separated out here because
these routines will be needed when we return from suspend.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/via_pm.c b/drivers/gpu/drm/via/via_pm.c
new file mode 100644
index 000..874540a
--- /dev/null
+++ b/drivers/gpu/drm/via/via_pm.c
@@ -0,0 +1,246 @@
+/*
+ * Copyright 2012 James Simmons jsimm...@infradead.org. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the Software),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include drmP.h
+#include via_drv.h
+
+static void
+via_init_2d(struct drm_via_private *dev_priv, int pci_device)
+{
+   int i;
+
+   for (i = 0x04; i  0x5c; i += 4)
+   VIA_WRITE(i, 0x0);
+
+   /* For 410 chip*/
+   if (pci_device == PCI_DEVICE_ID_VIA_VX900)
+   VIA_WRITE(0x60, 0x0);
+}
+
+static void
+via_init_3d(struct drm_via_private *dev_priv)
+{
+   unsigned long texture_stage;
+   int i;
+
+   VIA_WRITE(VIA_REG_TRANSET, 0x0001);
+   for (i = 0; i = 0x9A; i++)
+   VIA_WRITE(VIA_REG_TRANSPACE, i  24);
+
+   /* guardband clipping default setting */
+   VIA_WRITE(VIA_REG_TRANSPACE, (0x88  24) | 0x1ed0);
+   VIA_WRITE(VIA_REG_TRANSPACE, (0x89  24) | 0x0800);
+
+   /* Initial Texture Stage Setting */
+   for (texture_stage = 0; texture_stage = 0xf; texture_stage++) {
+   VIA_WRITE(VIA_REG_TRANSET, (0x0002 | 0x |
+   (texture_stage  0xf)  24));
+   for (i = 0 ; i = 0x30 ; i++)
+   VIA_WRITE(VIA_REG_TRANSPACE, i  24);
+   }
+
+   /* Initial Texture Sampler Setting */
+   for (texture_stage = 0; texture_stage = 0xf; texture_stage++) {
+   VIA_WRITE(VIA_REG_TRANSET, (0x0002 | 0x2000 |
+   (texture_stage  0x10)  24));
+   for (i = 0; i = 0x36; i++)
+   VIA_WRITE(VIA_REG_TRANSPACE, i  24);
+   }
+
+   VIA_WRITE(VIA_REG_TRANSET, (0x0002 | 0xfe00));
+   for (i = 0 ; i = 0x13 ; i++)
+   VIA_WRITE(VIA_REG_TRANSPACE, i  24);
+
+   /* degamma table */
+   VIA_WRITE(VIA_REG_TRANSET, (0x0003 | 0x1500));
+   VIA_WRITE(VIA_REG_TRANSPACE, (0x4000 | (30  20) | (15  10) | 
(5)));
+   VIA_WRITE(VIA_REG_TRANSPACE, ((119  20) | (81  10) | (52)));
+   VIA_WRITE(VIA_REG_TRANSPACE, ((283  20) | (219  10) | (165)));
+   VIA_WRITE(VIA_REG_TRANSPACE, ((535  20) | (441  10) | (357)));
+   VIA_WRITE(VIA_REG_TRANSPACE, ((119  20) | (884  20) | (757  10) | 
(640)));
+
+   /* gamma table */
+   VIA_WRITE(VIA_REG_TRANSET, (0x0003 | 0x1700));
+   VIA_WRITE(VIA_REG_TRANSPACE, (0x4000 | (13  20) | (13  10) | 
(13)));
+   VIA_WRITE(VIA_REG_TRANSPACE, (0x4000 | (26  20) | (26  10) | 
(26)));
+   VIA_WRITE(VIA_REG_TRANSPACE, (0x4000 | (39  20) | (39  10) | 
(39)));
+   VIA_WRITE(VIA_REG_TRANSPACE, ((51  20) | (51  10) | (51)));
+   VIA_WRITE(VIA_REG_TRANSPACE, ((71  20) | (71  10) | (71)));
+   VIA_WRITE(VIA_REG_TRANSPACE, (87  20) | (87  10) | (87));
+   VIA_WRITE(VIA_REG_TRANSPACE, (113  20) | (113  10) | (113));
+   VIA_WRITE(VIA_REG_TRANSPACE, (135  20) | (135  10) | (135));
+   VIA_WRITE(VIA_REG_TRANSPACE, (170  20) | (170  10) | (170));
+   VIA_WRITE(VIA_REG_TRANSPACE, (199  20) | (199  10) | (199));
+   VIA_WRITE(VIA_REG_TRANSPACE, (246  20) | (246  10) | (246));
+   VIA_WRITE(VIA_REG_TRANSPACE, (284  20) | (284  10) | (284));
+   

[RFC 10/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 86edf1f84ab36213c3bd3a6deb9c0811c7458b2c
Author: James Simmons jsimm...@infradead.org
Date:   Sat Jun 8 09:57:49 2013 -0400

via: Our implementation of KMS outputs and crtc

The header file defines via_crtc, via_connector, and via_encoder. Our
via_connector extents drm_connector by including the i2c_adaptor if
the connector supports it and a flags field to tell if a connector specific
feature is enabled or not. The flags field in via_encoder is used the same
way. The via_encoder needs to know what diport it needs to use. The via_crtc
is the most complex. Settings like the display fifo vary depending on the
hardware platform so we cache the value in via_crtc and can use the same
routine to set the registers on all platforms. The same is for the register
sets which not only varies per platform but also per each crtc on board.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/via_display.c 
b/drivers/gpu/drm/via/via_display.c
new file mode 100644
index 000..4a7223d6
--- /dev/null
+++ b/drivers/gpu/drm/via/via_display.c
@@ -0,0 +1,583 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the Software),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * James Simmons jsimm...@infradead.org
+ */
+
+#include drmP.h
+#include drm_crtc.h
+#include drm_crtc_helper.h
+
+#include via_drv.h
+
+/*
+ * Shared encoder routines.
+ */
+void
+via_encoder_commit(struct drm_encoder *encoder)
+{
+   struct via_encoder *enc = container_of(encoder, struct via_encoder, 
base);
+   struct drm_encoder_helper_funcs *encoder_funcs = 
encoder-helper_private;
+   struct drm_via_private *dev_priv = encoder-dev-dev_private;
+   struct drm_device *dev = encoder-dev;
+   struct via_crtc *iga = NULL;
+   u8 value = 0;
+
+   if (encoder-crtc == NULL)
+   return;
+
+   iga = container_of(encoder-crtc, struct via_crtc, base);
+   if (iga-index)
+   value = BIT(4);
+
+   /* Set IGA source and turn on DI port clock */
+   switch (enc-diPort) {
+   case DISP_DI_DVP0:
+   /* DVP0 Data Source Selection. */
+   svga_wcrt_mask(VGABASE, 0x96, value, BIT(4));
+   /* enable DVP0 under CX700 */
+   if (encoder-dev-pdev-device == PCI_DEVICE_ID_VIA_VT3157)
+   svga_wcrt_mask(VGABASE, 0x91, BIT(5), BIT(5));
+   /* Turn on DVP0 clk */
+   svga_wseq_mask(VGABASE, 0x1E, 0xC0, BIT(7) | BIT(6));
+   break;
+
+   case DISP_DI_DVP1:
+   svga_wcrt_mask(VGABASE, 0x9B, value, BIT(4));
+   /* enable DVP1 under these chipset. Does DVI exist
+* for pre CX700 hardware */
+   if ((dev-pdev-device == PCI_DEVICE_ID_VIA_VT3157) ||
+   (dev-pdev-device == PCI_DEVICE_ID_VIA_VT1122) ||
+   (dev-pdev-device == PCI_DEVICE_ID_VIA_VX875) ||
+   (dev-pdev-device == PCI_DEVICE_ID_VIA_VX900))
+   svga_wcrt_mask(VGABASE, 0xD3, 0x00, BIT(5));
+   /* Turn on DVP1 clk */
+   svga_wseq_mask(VGABASE, 0x1E, 0x30, BIT(5) | BIT(4));
+   break;
+
+   case DISP_DI_DFPH:
+   /* Port 96 is used on older hardware for the DVP0 */
+   if ((dev-pdev-device != PCI_DEVICE_ID_VIA_VT3157) 
+   (dev-pdev-device != PCI_DEVICE_ID_VIA_VT1122) 
+   (dev-pdev-device != PCI_DEVICE_ID_VIA_VX875) 
+   (dev-pdev-device != PCI_DEVICE_ID_VIA_VX900))
+   svga_wcrt_mask(VGABASE, 0x96, value, BIT(4));
+
+   svga_wcrt_mask(VGABASE, 0x97, value, BIT(4));
+   /* Turn on DFPH clock */
+   svga_wseq_mask(VGABASE, 0x2A, 0x0C, BIT(3) | BIT(2));
+   break;
+
+   case DISP_DI_DFPL:
+   /* Port 9B is used on older hardware for 

[RFC 11/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 4ed0199a92b71506100240b625da173ef7afaf4c
Author: James Simmons jsimm...@infradead.org
Date:   Sat Jun 8 10:57:59 2013 -0400

via: VIA clock handling

The routines that generate the PLL values to program the registers with.
Here the VCLK is programmed to properly set the video mode.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/via_clocks.c b/drivers/gpu/drm/via/via_clocks.c
new file mode 100644
index 000..eae424a
--- /dev/null
+++ b/drivers/gpu/drm/via/via_clocks.c
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2012 James Simmons jsimm...@infradead.org
+ *
+ * Based on code for the viafb driver.
+ * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
+ * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE.See the GNU General Public License
+ * for more details.
+ */
+
+#include drmP.h
+#include via_drv.h
+
+#define CSR_VCO_UP 6
+#define CSR_VCO_DOWN   3
+
+#define PLL_DTZ_DEFAULT(BIT(0) | BIT(1))
+
+#define VIA_CLK_REFERENCE  14318180
+
+struct pll_mrn_value {
+   u32 pll_m;
+   u32 pll_r;
+   u32 pll_n;
+   u32 diff_clk;
+   u32 pll_fout;
+};
+
+/*
+ * This function first gets the best frequency M, R, N value
+ * to program the PLL according to the supplied frequence
+ * passed in. After we get the MRN values the results are
+ * formatted to fit properly into the PLL clock registers.
+ *
+ * PLL registers M, R, N value
+ * [31:16]  DM[7:0]
+ * [15:8 ]  DR[2:0]
+ * [7 :0 ]  DN[6:0]
+ */
+u32
+via_get_clk_value(struct drm_device *dev, u32 freq)
+{
+   u32 best_pll_n = 2, best_pll_r = 0, best_pll_m = 2, best_clk_diff = 
freq;
+   u32 pll_fout, pll_fvco, pll_mrn = 0;
+   u32 pll_n, pll_r, pll_m, clk_diff;
+   struct pll_mrn_value pll_tmp[5] = {
+   { 0, 0, 0, 0, 0 },
+   { 0, 0, 0, 0, 0 },
+   { 0, 0, 0, 0, 0 },
+   { 0, 0, 0, 0, 0 },
+   { 0, 0, 0, 0, 0 } };
+   int count;
+
+   /* DN[6:0] */
+   for (pll_n = 2; pll_n  6; pll_n++) {
+   /* DR[2:0] */
+   for (pll_r = 0; pll_r  6; pll_r++) {
+   /* DM[9:0] */
+   for (pll_m = 2; pll_m  512; pll_m++) {
+   /* first divide pll_n then multiply
+* pll_m. We have to reduce pll_m
+* to 512 to get rid of the overflow */
+   pll_fvco = (VIA_CLK_REFERENCE / pll_n) * pll_m;
+   if ((pll_fvco = CSR_VCO_DOWN)  (pll_fvco = 
CSR_VCO_UP)) {
+   pll_fout = pll_fvco  pll_r;
+   if (pll_fout  freq)
+   clk_diff = freq - pll_fout;
+   else
+   clk_diff = pll_fout - freq;
+
+   /* if frequency (which is the PLL we 
want
+* to set)  150MHz, the MRN value we
+* write in register must  frequency, 
and
+* get MRN value whose M is the 
largeset */
+   if (freq = 15000) {
+   if ((clk_diff = 
pll_tmp[0].diff_clk) || pll_tmp[0].pll_fout == 0) {
+   for (count = 
ARRAY_SIZE(pll_tmp) - 1; count = 1; count--)
+   pll_tmp[count] 
= pll_tmp[count - 1];
+
+   pll_tmp[0].pll_m = 
pll_m;
+   pll_tmp[0].pll_r = 
pll_r;
+   pll_tmp[0].pll_n = 
pll_n;
+   pll_tmp[0].diff_clk = 
clk_diff;
+   pll_tmp[0].pll_fout = 
pll_fout;
+   }
+   }
+
+   if (clk_diff  best_clk_diff) {
+   best_clk_diff = clk_diff;
+   best_pll_m = pll_m;
+   best_pll_n = pll_n;
+   

[RFC 12/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit ab2beb77d5889b18112ee02c381e817eebbdccff
Author: James Simmons jsimm...@infradead.org
Date:   Sat Jun 8 11:02:43 2013 -0400

via: IGA (CRTC) handling

Routines to program all things crtc related. This covers gamma tables, 
cursors
and of course resolution setting.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/via_crtc.c b/drivers/gpu/drm/via/via_crtc.c
new file mode 100644
index 000..10a5017
--- /dev/null
+++ b/drivers/gpu/drm/via/via_crtc.c
@@ -0,0 +1,1622 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the Software),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * James Simmons jsimm...@infradead.org
+ */
+#include drm/drm_mode.h
+#include drmP.h
+#include drm_crtc.h
+#include drm_crtc_helper.h
+
+#include via_drv.h
+#include via_disp_reg.h
+
+static struct vga_regset vpit_table[] = {
+   { VGA_SEQ_I, 0x01, 0xFF, 0x01 },
+   { VGA_SEQ_I, 0x02, 0xFF, 0x0F },
+   { VGA_SEQ_I, 0x03, 0xFF, 0x00 },
+   { VGA_SEQ_I, 0x04, 0xFF, 0x0E },
+   { VGA_GFX_I, 0x00, 0xFF, 0x00 },
+   { VGA_GFX_I, 0x01, 0xFF, 0x00 },
+   { VGA_GFX_I, 0x02, 0xFF, 0x00 },
+   { VGA_GFX_I, 0x03, 0xFF, 0x00 },
+   { VGA_GFX_I, 0x04, 0xFF, 0x00 },
+   { VGA_GFX_I, 0x05, 0xFF, 0x00 },
+   { VGA_GFX_I, 0x06, 0xFF, 0x05 },
+   { VGA_GFX_I, 0x07, 0xFF, 0x0F },
+   { VGA_GFX_I, 0x08, 0xFF, 0xFF }
+};
+
+static void
+via_hide_cursor(struct drm_crtc *crtc)
+{
+   struct via_crtc *iga = container_of(crtc, struct via_crtc, base);
+   struct drm_via_private *dev_priv = crtc-dev-dev_private;
+   uint32_t temp;
+
+   if (iga-index) {
+   temp = VIA_READ(HI_CONTROL);
+   VIA_WRITE(HI_CONTROL, temp  0xFFFA);
+   } else {
+   temp = VIA_READ(PRIM_HI_CTRL);
+   VIA_WRITE(PRIM_HI_CTRL, temp  0xFFFA);
+   }
+}
+
+static void
+via_show_cursor(struct drm_crtc *crtc)
+{
+   struct via_crtc *iga = container_of(crtc, struct via_crtc, base);
+   struct drm_via_private *dev_priv = crtc-dev-dev_private;
+
+   if (!iga-cursor_kmap.bo)
+   return;
+
+   /* Program the offset and turn on Hardware icon Cursor */
+   if (iga-index) {
+   VIA_WRITE(HI_FBOFFSET, iga-cursor_kmap.bo-offset);
+   VIA_WRITE(HI_CONTROL, 0xB605);
+   } else {
+   VIA_WRITE(PRIM_HI_FBOFFSET, iga-cursor_kmap.bo-offset);
+   VIA_WRITE(PRIM_HI_CTRL, 0x3605);
+   }
+}
+
+static int
+via_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
+   uint32_t handle, uint32_t width, uint32_t height)
+{
+   struct via_crtc *iga = container_of(crtc, struct via_crtc, base);
+   int max_height = 64, max_width = 64, ret = 0, i;
+   struct drm_device *dev = crtc-dev;
+   struct drm_gem_object *obj = NULL;
+   struct ttm_bo_kmap_obj user_kmap;
+
+   if (!iga-cursor_kmap.bo)
+   return -ENXIO;
+
+   if (!handle) {
+   /* turn off cursor */
+   via_hide_cursor(crtc);
+   return ret;
+   }
+
+   if (dev-pdev-device == PCI_DEVICE_ID_VIA_CLE266 ||
+   dev-pdev-device == PCI_DEVICE_ID_VIA_KM400) {
+   max_height = 1;
+   max_width = 1;
+   }
+
+   if ((height  max_height) || (width  max_width)) {
+   DRM_ERROR(bad cursor width or height %d x %d\n, width, 
height);
+   return -EINVAL;
+   }
+
+   obj = drm_gem_object_lookup(dev, file_priv, handle);
+   if (!obj || !obj-driver_private) {
+   DRM_ERROR(Cannot find cursor object %x for crtc %d\n, handle, 
crtc-base.id);
+   return -ENOENT;
+   }
+
+   user_kmap.bo = obj-driver_private;
+   ret = ttm_bo_kmap(user_kmap.bo, 0, user_kmap.bo-mem.size, user_kmap);
+   if (!ret) {
+   /* Copy data from userland to 

[RFC 13/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 991c37448ff8403727f12af331eb164eb5ed4048
Author: James Simmons jsimm...@infradead.org
Date:   Sat Jun 8 11:12:36 2013 -0400

via: VIA kms frame buffer support

Each version of hardware has a unquie way to detect the amount of
video ram. We detect the amount for all known device. Here we
implement the drm_framebuffer user land interface hooks as well
as setup a framebuffer for the fbdev emulator.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/via_fb.c b/drivers/gpu/drm/via/via_fb.c
new file mode 100644
index 000..5cca9f2
--- /dev/null
+++ b/drivers/gpu/drm/via/via_fb.c
@@ -0,0 +1,1267 @@
+/*
+ * Copyright 2012 James Simmons jsimm...@infradead.org. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the Software),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#include drmP.h
+#include via_drv.h
+#include drm_fb_helper.h
+#include drm_crtc_helper.h
+
+struct ttm_fb_helper {
+   struct drm_fb_helper base;
+   struct ttm_bo_kmap_obj kmap;
+};
+
+static int
+cle266_mem_type(struct drm_via_private *dev_priv, struct pci_dev *bridge)
+{
+   u8 type, fsb, freq;
+   int ret;
+
+   ret = pci_read_config_byte(bridge, 0x54, fsb);
+   if (ret)
+   return ret;
+   ret = pci_read_config_byte(bridge, 0x69, freq);
+   if (ret)
+   return ret;
+
+   freq = 6;
+   fsb = 6;
+
+   /* FSB frequency */
+   switch (fsb) {
+   case 0x01: /* 100MHz */
+   switch (freq) {
+   case 0x00:
+   freq = 100;
+   break;
+   case 0x01:
+   freq = 133;
+   break;
+   case 0x02:
+   freq = 66;
+   break;
+   default:
+   freq = 0;
+   break;
+   }
+   break;
+
+   case 0x02: /* 133 MHz */
+   case 0x03:
+   switch (freq) {
+   case 0x00:
+   freq = 133;
+   break;
+   case 0x02:
+   freq = 100;
+   break;
+   default:
+   freq = 0;
+   break;
+   }
+   break;
+   default:
+   freq = 0;
+   break;
+   }
+
+   ret = pci_read_config_byte(bridge, 0x60, fsb);
+   if (ret)
+   return ret;
+   ret = pci_read_config_byte(bridge, 0xE3, type);
+   if (ret)
+   return ret;
+
+   /* On bank 2/3 */
+   if (type  0x02)
+   fsb = 2;
+
+   /* Memory type */
+   switch (fsb  0x03) {
+   case 0x00: /* SDR */
+   switch (freq) {
+   case 66:
+   dev_priv-vram_type = VIA_MEM_SDR66;
+   break;
+   case 100:
+   dev_priv-vram_type = VIA_MEM_SDR100;
+   break;
+   case 133:
+   dev_priv-vram_type = VIA_MEM_SDR133;
+   default:
+   break;
+   }
+   break;
+
+   case 0x02: /* DDR */
+   switch (freq) {
+   case 100:
+   dev_priv-vram_type = VIA_MEM_DDR_200;
+   break;
+   case 133:
+   dev_priv-vram_type = VIA_MEM_DDR_266;
+   default:
+   break;
+   }
+   default:
+   break;
+   }
+   return ret;
+}
+
+static int
+km400_mem_type(struct drm_via_private *dev_priv, struct pci_dev *bridge)
+{
+   u8 fsb, freq, rev;
+   int ret;
+
+   ret = pci_read_config_byte(bridge, 0xF6, rev);
+   if (ret)
+   return ret;
+   ret = pci_read_config_byte(bridge, 0x54, 

[RFC 14/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit 9549976c231b676c2c8e70fd6979115c1c8ed747
Author: James Simmons jsimm...@infradead.org
Date:   Sat Jun 8 12:02:59 2013 -0400

via: VGA analog support

Implement the encoder and connector for VGA analog displays.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/via_analog.c b/drivers/gpu/drm/via/via_analog.c
new file mode 100644
index 000..8fabeac
--- /dev/null
+++ b/drivers/gpu/drm/via/via_analog.c
@@ -0,0 +1,146 @@
+/*
+ * Copyright © 2012 James Simmons
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the Software),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * James Simmons jsimm...@infradead.org
+ */
+#include via_drv.h
+
+/*
+ * Routines for controlling stuff on the analog port
+ */
+static const struct drm_encoder_funcs via_dac_enc_funcs = {
+   .destroy = via_encoder_cleanup,
+};
+
+/* Manage the power state of the DAC */
+static void
+via_dac_dpms(struct drm_encoder *encoder, int mode)
+{
+   struct drm_via_private *dev_priv = encoder-dev-dev_private;
+   u8 mask = 0;
+
+   switch (mode) {
+   case DRM_MODE_DPMS_SUSPEND:
+   mask = BIT(5);  // VSync off
+   break;
+   case DRM_MODE_DPMS_STANDBY:
+   mask = BIT(4);  // HSync off
+   break;
+   case DRM_MODE_DPMS_OFF:
+   mask = (BIT(5) | BIT(4));// HSync and VSync off
+   break;
+   case DRM_MODE_DPMS_ON:
+   default:
+   break;
+   }
+   svga_wcrt_mask(VGABASE, 0x36, mask, BIT(5) | BIT(4));
+}
+
+/* Pass our mode to the connectors and the CRTC to give them a chance to
+ * adjust it according to limitations or connector properties, and also
+ * a chance to reject the mode entirely. Usefule for things like scaling.
+ */
+static bool
+via_dac_mode_fixup(struct drm_encoder *encoder,
+const struct drm_display_mode *mode,
+struct drm_display_mode *adjusted_mode)
+{
+   drm_mode_set_crtcinfo(adjusted_mode, 0);
+   return true;
+}
+
+static const struct drm_encoder_helper_funcs via_dac_enc_helper_funcs = {
+   .dpms = via_dac_dpms,
+   .mode_fixup = via_dac_mode_fixup,
+   .mode_set = via_set_sync_polarity,
+   .prepare = via_encoder_prepare,
+   .commit = via_encoder_commit,
+   .disable = via_encoder_disable,
+};
+
+static enum drm_connector_status
+via_analog_detect(struct drm_connector *connector, bool force)
+{
+   struct via_connector *con = container_of(connector, struct 
via_connector, base);
+   enum drm_connector_status ret = connector_status_disconnected;
+   struct edid *edid = NULL;
+
+   drm_mode_connector_update_edid_property(connector, edid);
+   if (con-ddc_bus) {
+   edid = drm_get_edid(connector, con-ddc_bus);
+   if (edid) {
+   drm_mode_connector_update_edid_property(connector, 
edid);
+   kfree(edid);
+   ret = connector_status_connected;
+   }
+   }
+   return ret;
+}
+
+static const struct drm_connector_funcs via_analog_connector_funcs = {
+   .dpms = drm_helper_connector_dpms,
+   .detect = via_analog_detect,
+   .fill_modes = drm_helper_probe_single_connector_modes,
+   .set_property = via_connector_set_property,
+   .destroy = via_connector_destroy,
+};
+
+static const struct drm_connector_helper_funcs 
via_analog_connector_helper_funcs = {
+   .mode_valid = via_connector_mode_valid,
+   .get_modes = via_get_edid_modes,
+   .best_encoder = via_best_encoder,
+};
+
+void
+via_analog_init(struct drm_device *dev)
+{
+   struct via_connector *con;
+   struct via_encoder *enc;
+
+   enc = kzalloc(sizeof(*enc) + sizeof(*con), GFP_KERNEL);
+   if (!enc) {
+   DRM_ERROR(Failed to allocate connector and encoder\n);
+   return;
+   }
+   con = 

[RFC 15/21] DRM: Add VIA drm driver

2013-06-08 Thread James Simmons

commit 1c886b4f35ec239f7787a6a4db10ecc80b3c9824
Author: James Simmons jsimm...@infradead.org
Date:   Sat Jun 8 12:04:31 2013 -0400

via: LVDS support

Implement the encoder and connector for LVDS lcd type displays.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/via_lvds.c b/drivers/gpu/drm/via/via_lvds.c
new file mode 100644
index 000..d8ed81c
--- /dev/null
+++ b/drivers/gpu/drm/via/via_lvds.c
@@ -0,0 +1,778 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the Software),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#include linux/dmi.h
+#include asm/olpc.h
+
+#include via_drv.h
+
+/* Encoder flags for LVDS */
+#define LVDS_DUAL_CHANNEL  1
+
+/* caculate the cetering timing using mode and adjusted_mode */
+static void
+via_centering_timing(const struct drm_display_mode *mode,
+   struct drm_display_mode *adjusted_mode)
+{
+   int panel_hsync_time = adjusted_mode-hsync_end -
+   adjusted_mode-hsync_start;
+   int panel_vsync_time = adjusted_mode-vsync_end -
+   adjusted_mode-vsync_start;
+   int panel_hblank_start = adjusted_mode-hdisplay;
+   int panel_vbank_start = adjusted_mode-vdisplay;
+   int hborder = (adjusted_mode-hdisplay - mode-hdisplay) / 2;
+   int vborder = (adjusted_mode-vdisplay - mode-vdisplay) / 2;
+   int new_hblank_start = hborder + mode-hdisplay;
+   int new_vblank_start = vborder + mode-vdisplay;
+
+   adjusted_mode-hdisplay = mode-hdisplay;
+   adjusted_mode-hsync_start = (adjusted_mode-hsync_start -
+   panel_hblank_start) + new_hblank_start;
+   adjusted_mode-hsync_end = adjusted_mode-hsync_start +
+   panel_hsync_time;
+   adjusted_mode-vdisplay = mode-vdisplay;
+   adjusted_mode-vsync_start = (adjusted_mode-vsync_start -
+   panel_vbank_start) + new_vblank_start;
+   adjusted_mode-vsync_end = adjusted_mode-vsync_start +
+   panel_vsync_time;
+   /* Adjust Crtc H and V */
+   adjusted_mode-crtc_hdisplay = adjusted_mode-hdisplay;
+   adjusted_mode-crtc_hblank_start = new_hblank_start;
+   adjusted_mode-crtc_hblank_end = adjusted_mode-crtc_htotal - hborder;
+   adjusted_mode-crtc_hsync_start = adjusted_mode-hsync_start;
+   adjusted_mode-crtc_hsync_end = adjusted_mode-hsync_end;
+   adjusted_mode-crtc_vdisplay = adjusted_mode-vdisplay;
+   adjusted_mode-crtc_vblank_start = new_vblank_start;
+   adjusted_mode-crtc_vblank_end = adjusted_mode-crtc_vtotal - vborder;
+   adjusted_mode-crtc_vsync_start = adjusted_mode-vsync_start;
+   adjusted_mode-crtc_vsync_end = adjusted_mode-vsync_end;
+}
+
+static void
+via_enable_internal_lvds(struct drm_encoder *encoder)
+{
+   struct via_encoder *enc = container_of(encoder, struct via_encoder, 
base);
+   struct drm_via_private *dev_priv = encoder-dev-dev_private;
+   struct drm_device *dev = encoder-dev;
+
+   /* Turn on LCD panel */
+   if ((enc-diPort  DISP_DI_DFPL) || (enc-diPort == DISP_DI_DVP1)) {
+   if ((dev-pci_device == PCI_DEVICE_ID_VIA_VT1122) ||
+   (dev-pci_device == PCI_DEVICE_ID_VIA_CLE266)) {
+   /* Software control power sequence ON */
+   svga_wcrt_mask(VGABASE, 0x91, 0x00, BIT(7));
+   svga_wcrt_mask(VGABASE, 0x91, BIT(0), BIT(0));
+   /* Delay td0 msec. */
+   mdelay(200);
+   /* VDD ON */
+   svga_wcrt_mask(VGABASE, 0x91, BIT(4), BIT(4));
+   /* Delay td1 msec. */
+   mdelay(25);
+   /* DATA ON */
+   svga_wcrt_mask(VGABASE, 0x91, BIT(3), BIT(3));
+   /* VEE ON (unused on vt3353) */
+   svga_wcrt_mask(VGABASE, 0x91, BIT(2), BIT(2));
+   /* 

[RFC 16/21] DRM: Add VIA DRM driver

2013-06-08 Thread James Simmons

commit a2e0f8fc0ded9788815cdc68d3acded9f43116b4
Author: James Simmons jsimm...@infradead.org
Date:   Sat Jun 8 12:08:57 2013 -0400

via: TMDS support

Implement the encoder and connector for TMDS devices. This handles the case
of DVI port devices not based on an HDMI encoder. This is basic support will
will need to be expanded in the future to handle more corner cases on older
hardware.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/via_tmds.c b/drivers/gpu/drm/via/via_tmds.c
new file mode 100644
index 000..a906661
--- /dev/null
+++ b/drivers/gpu/drm/via/via_tmds.c
@@ -0,0 +1,187 @@
+/*
+ * Copyright © 2013 James Simmons
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the Software),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * James Simmons jsimm...@infradead.org
+ */
+#include via_drv.h
+
+/*
+ * Routines for controlling stuff on the TMDS port
+ */
+static const struct drm_encoder_funcs via_tmds_enc_funcs = {
+   .destroy = via_encoder_cleanup,
+};
+
+/* Manage the power state of the DAC */
+static void
+via_tmds_dpms(struct drm_encoder *encoder, int mode)
+{
+   struct drm_via_private *dev_priv = encoder-dev-dev_private;
+
+   switch (mode) {
+   case DRM_MODE_DPMS_SUSPEND:
+   case DRM_MODE_DPMS_STANDBY:
+   case DRM_MODE_DPMS_OFF:
+   svga_wcrt_mask(VGABASE, 0xD2, BIT(4), BIT(4));
+   svga_wcrt_mask(VGABASE, 0x91, 0x00, BIT(0));
+
+   /* Internal TMDS only use DFP_L */
+   /* Turn on DVI panel path(Only for internal),
+* otherwise, the screen of DVI will be black. */
+   svga_wcrt_mask(VGABASE, 0x91, 0x00, BIT(7));
+   /* Power on TMDS */
+   svga_wcrt_mask(VGABASE, 0xD2, 0x00, BIT(3));
+   break;
+
+   case DRM_MODE_DPMS_ON:
+   default:
+   svga_wcrt_mask(VGABASE, 0x91, BIT(7), BIT(7));
+   /* Power off TMDS */
+   svga_wcrt_mask(VGABASE, 0xD2, BIT(3), BIT(3));
+   break;
+   }
+}
+
+/* Pass our mode to the connectors and the CRTC to give them a chance to
+ * adjust it according to limitations or connector properties, and also
+ * a chance to reject the mode entirely. Usefule for things like scaling.
+ */
+static bool
+via_tmds_mode_fixup(struct drm_encoder *encoder,
+const struct drm_display_mode *mode,
+struct drm_display_mode *adjusted_mode)
+{
+   drm_mode_set_crtcinfo(adjusted_mode, 0);
+   return true;
+}
+
+static const struct drm_encoder_helper_funcs via_tmds_enc_helper_funcs = {
+   .dpms = via_tmds_dpms,
+   .mode_fixup = via_tmds_mode_fixup,
+   .mode_set = via_set_sync_polarity,
+   .prepare = via_encoder_prepare,
+   .commit = via_encoder_commit,
+   .disable = via_encoder_disable,
+};
+
+static enum drm_connector_status
+via_dvi_detect(struct drm_connector *connector, bool force)
+{
+   struct via_connector *con = container_of(connector, struct 
via_connector, base);
+   enum drm_connector_status ret = connector_status_disconnected;
+   struct edid *edid = NULL;
+
+   drm_mode_connector_update_edid_property(connector, edid);
+   if (con-ddc_bus) {
+   edid = drm_get_edid(connector, con-ddc_bus);
+   if (edid) {
+   if ((connector-connector_type == 
DRM_MODE_CONNECTOR_DVIA) ^
+   (edid-input  DRM_EDID_INPUT_DIGITAL)) {
+   
drm_mode_connector_update_edid_property(connector, edid);
+   ret = connector_status_connected;
+   }
+   kfree(edid);
+   }
+   }
+   return ret;
+}
+
+static const struct drm_connector_funcs via_dvi_connector_funcs = {
+   .dpms = drm_helper_connector_dpms,
+   .detect = via_dvi_detect,
+   

[RFC 18/21] DRM: Add VIA drm driver

2013-06-08 Thread James Simmons

commit 589665935a7ec7c29103c9ea4eb1d0ffc4b918d5
Author: James Simmons jsimm...@infradead.org
Date:   Sat Jun 8 12:15:30 2013 -0400

via: New GEM/TTM kms ioctls

New ioctls to allow userland to allocate TTM/GEM buffer objects. Obsolete
UMS ioctls.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/via_ioc32.c b/drivers/gpu/drm/via/via_ioc32.c
new file mode 100644
index 000..03b8508
--- /dev/null
+++ b/drivers/gpu/drm/via/via_ioc32.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright 2006 Tungsten Graphics Inc., Bismarck, ND., USA.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the Software),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY 
CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+/*
+ * Authors: Thomas Hellström thomas-at-tungstengraphics-dot-com
+ */
+
+#include drmP.h
+#include via_drv.h
+
+static int
+via_getparam(struct drm_device *dev, void *data,
+   struct drm_file *filp)
+{
+   struct drm_via_private *dev_priv = dev-dev_private;
+   struct drm_via_param *args = data;
+   int ret = 0;
+
+   switch (args-param) {
+   case VIA_PARAM_CHIPSET_ID:
+   args-value = dev-pci_device;
+   break;
+   case VIA_PARAM_REVISION_ID:
+   args-value = dev_priv-revision;
+   break;
+   default:
+   ret = -EINVAL;
+   break;
+   }
+   return ret;
+}
+
+/* Not yet supported */
+static int
+via_setparam(struct drm_device *dev, void *data,
+   struct drm_file *filp)
+{
+   return -EINVAL;
+}
+
+static int
+via_gem_alloc(struct drm_device *dev, void *data,
+   struct drm_file *filp)
+{
+   struct drm_via_private *dev_priv = dev-dev_private;
+   struct drm_via_gem_create *args = data;
+   struct drm_gem_object *obj;
+   int ret = -ENOMEM;
+
+   obj = ttm_gem_create(dev, dev_priv-bdev, args-domains, false,
+   args-alignment, PAGE_SIZE, args-size);
+   if (obj  obj-driver_private) {
+   ret = drm_gem_handle_create(filp, obj, args-handle);
+   /* drop reference from allocate - handle holds it now */
+   drm_gem_object_unreference_unlocked(obj);
+   if (!ret) {
+   struct ttm_buffer_object *bo = obj-driver_private;
+
+   args-domains = bo-mem.placement  TTM_PL_MASK_MEM;
+   args-map_handle = bo-addr_space_offset;
+   args-offset = bo-offset;
+   args-size = bo-mem.size;
+
+   obj-read_domains = obj-write_domain = args-domains;
+   }
+   }
+   return ret;
+}
+
+static int
+via_gem_state(struct drm_device *dev, void *data, struct drm_file *file_priv)
+{
+   struct ttm_buffer_object *bo = NULL;
+   struct drm_via_gem_create *args = data;
+   struct drm_gem_object *obj = NULL;
+   struct ttm_placement placement;
+   int ret = -EINVAL;
+
+   obj = drm_gem_object_lookup(dev, file_priv, args-handle);
+   if (!obj || !obj-driver_private)
+   return ret;
+
+   bo = obj-driver_private;
+
+   /* Don't bother to migrate to same domain */
+   args-domains = ~(bo-mem.placement  TTM_PL_MASK_MEM);
+   if (args-domains) {
+   ret = ttm_bo_reserve(bo, true, false, false, 0);
+   if (unlikely(ret))
+   return ret;
+
+   ttm_placement_from_domain(bo, placement, args-domains, 
bo-bdev);
+   ret = ttm_bo_validate(bo, placement, false, false);
+   ttm_bo_unreserve(bo);
+
+   if (!ret) {
+   args-domains = bo-mem.placement  TTM_PL_MASK_MEM;
+   args-map_handle = bo-addr_space_offset;
+   args-offset = bo-offset;
+   args-size = bo-mem.size;
+
+   obj-read_domains = 

[RFC 20/21] DRM: Add VIA drm driver

2013-06-08 Thread James Simmons

commit adafa472a5426e6e6ce513fbbad77b0aef0005a3
Author: James Simmons jsimm...@infradead.org
Date:   Sat Jun 8 12:24:50 2013 -0400

via: IRQ code updates

Expand the IRQ code to handle more than just the DMA and MPEG engines.
Now we handle hotplug as well and improve vblank support on both crtcs.
We also hook into the fence mechanism.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
index ac98964..d5ab553 100644
--- a/drivers/gpu/drm/via/via_irq.c
+++ b/drivers/gpu/drm/via/via_irq.c
@@ -1,5 +1,4 @@
-/* via_irq.c
- *
+/*
  * Copyright 2004 BEAM Ltd.
  * Copyright 2002 Tungsten Graphics, Inc.
  * Copyright 2005 Thomas Hellstrom.
@@ -18,9 +17,8 @@
  *
  * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BEAM LTD, TUNGSTEN GRAPHICS  AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
@@ -35,29 +33,81 @@
  * The refresh rate is also calculated for video playback sync purposes.
  */
 
-#include drm/drmP.h
-#include drm/via_drm.h
+#include drmP.h
 #include via_drv.h
 
-#define VIA_REG_INTERRUPT   0x200
-
-/* VIA_REG_INTERRUPT */
-#define VIA_IRQ_GLOBAL   (1  31)
-#define VIA_IRQ_VBLANK_ENABLE   (1  19)
-#define VIA_IRQ_VBLANK_PENDING  (1  3)
-#define VIA_IRQ_HQV0_ENABLE (1  11)
-#define VIA_IRQ_HQV1_ENABLE (1  25)
-#define VIA_IRQ_HQV0_PENDING(1  9)
-#define VIA_IRQ_HQV1_PENDING(1  10)
-#define VIA_IRQ_DMA0_DD_ENABLE  (1  20)
-#define VIA_IRQ_DMA0_TD_ENABLE  (1  21)
-#define VIA_IRQ_DMA1_DD_ENABLE  (1  22)
-#define VIA_IRQ_DMA1_TD_ENABLE  (1  23)
-#define VIA_IRQ_DMA0_DD_PENDING (1  4)
-#define VIA_IRQ_DMA0_TD_PENDING (1  5)
-#define VIA_IRQ_DMA1_DD_PENDING (1  6)
-#define VIA_IRQ_DMA1_TD_PENDING (1  7)
+/* HW Interrupt Register Setting */
+#define INTERRUPT_CTRL_REG10x200
+
+/* mmio 0x200 IRQ enable and status bits. */
+#define VIA_IRQ_ALL_ENABLE BIT(31)
+
+#define VIA_IRQ_IGA1_VBLANK_STATUS BIT(1)
+
+#define VIA_IRQ_IGA1_VSYNC_ENABLE  BIT(19)
+#define VIA_IRQ_IGA2_VSYNC_ENABLE  BIT(17)
+#define VIA_IRQ_IGA1_VSYNC_STATUS  BIT(3)
+#define VIA_IRQ_IGA2_VSYNC_STATUS  BIT(15)
+
+#define VIA_IRQ_CAPTURE0_ACTIVE_ENABLE BIT(28)
+#define VIA_IRQ_CAPTURE1_ACTIVE_ENABLE BIT(24)
+#define VIA_IRQ_CAPTURE0_ACTIVE_STATUS BIT(12)
+#define VIA_IRQ_CAPTURE1_ACTIVE_STATUS BIT(8)
+
+#define VIA_IRQ_HQV0_ENABLEBIT(25)
+#define VIA_IRQ_HQV1_ENABLEBIT(9)
+#define VIA_IRQ_HQV0_STATUSBIT(12)
+#define VIA_IRQ_HQV1_STATUSBIT(10)
+
+#define VIA_IRQ_DMA0_DD_ENABLE BIT(20)
+#define VIA_IRQ_DMA0_TD_ENABLE BIT(21)
+#define VIA_IRQ_DMA1_DD_ENABLE BIT(22)
+#define VIA_IRQ_DMA1_TD_ENABLE BIT(23)
+
+#define VIA_IRQ_DMA0_DD_STATUS BIT(4)
+#define VIA_IRQ_DMA0_TD_STATUS BIT(5)
+#define VIA_IRQ_DMA1_DD_STATUS BIT(6)
+#define VIA_IRQ_DMA1_TD_STATUS BIT(7)
+
+#define VIA_IRQ_LVDS_ENABLEBIT(30)
+#define VIA_IRQ_TMDS_ENABLEBIT(16)
 
+#define VIA_IRQ_LVDS_STATUSBIT(27)
+#define VIA_IRQ_TMDS_STATUSBIT(0)
+
+#define INTR_ENABLE_MASK (VIA_IRQ_DMA0_TD_ENABLE | VIA_IRQ_DMA1_TD_ENABLE | \
+   VIA_IRQ_DMA0_DD_ENABLE | VIA_IRQ_DMA1_DD_ENABLE | \
+   VIA_IRQ_IGA1_VSYNC_ENABLE | VIA_IRQ_IGA2_VSYNC_ENABLE)
+
+#define INTERRUPT_ENABLE_MASK (VIA_IRQ_CAPTURE0_ACTIVE_ENABLE | 
VIA_IRQ_CAPTURE1_ACTIVE_ENABLE | \
+   VIA_IRQ_HQV0_ENABLE | VIA_IRQ_HQV1_ENABLE | \
+   INTR_ENABLE_MASK)
+
+#define INTR_STATUS_MASK (VIA_IRQ_DMA0_TD_STATUS | VIA_IRQ_DMA1_TD_STATUS | \
+   VIA_IRQ_DMA0_DD_STATUS  | VIA_IRQ_DMA1_DD_STATUS  | \
+   VIA_IRQ_IGA1_VSYNC_STATUS | VIA_IRQ_IGA2_VSYNC_STATUS)
+
+#define INTERRUPT_STATUS_MASK (VIA_IRQ_CAPTURE0_ACTIVE_STATUS | 
VIA_IRQ_CAPTURE1_ACTIVE_STATUS | \
+   VIA_IRQ_HQV0_STATUS | VIA_IRQ_HQV1_STATUS | \
+   INTR_STATUS_MASK)
+
+/* mmio 0x1280 IRQ enabe and status bits. */
+#define INTERRUPT_CTRL_REG30x1280
+
+/* MM1280[9], internal TMDS interrupt status = SR3E[6] */
+#define INTERRUPT_TMDS_STATUS  0x200
+/* MM1280[30], internal TMDS interrupt control = SR3E[7] */
+#define INTERNAL_TMDS_INT_CONTROL  0x4000
+
+#define VIA_IRQ_DP1_ENABLE BIT(24)
+#define VIA_IRQ_DP2_ENABLE 

[RFC 21/21] DRM: Add VIA drm driver

2013-06-08 Thread James Simmons
commit f4101ca539b83c824747d657bbdc28834276fea8
Author: James Simmons jsimm...@infradead.org
Date:   Sat Jun 8 12:28:13 2013 -0400

via: Piece all the TTM/KMS changes together.

This updates the core VIA drm driver to support KMS/TTM/GEM. This includes
setting up the graphics cards resources and enabling the dumb scanout api.

Signed-Off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index b16c50e..b773b42 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -188,6 +188,11 @@ config DRM_SIS
 config DRM_VIA
tristate Via unichrome video cards
depends on DRM  PCI
+   select FB_CFB_FILLRECT
+   select FB_CFB_COPYAREA
+   select FB_CFB_IMAGEBLIT
+   select DRM_KMS_HELPER
+   select DRM_TTM
help
  Choose this option if you have a Via unichrome or compatible video
  chipset. If M is selected the module will be called via.
diff --git a/drivers/gpu/drm/via/Makefile b/drivers/gpu/drm/via/Makefile
index b537e4b..a0479bb 100644
--- a/drivers/gpu/drm/via/Makefile
+++ b/drivers/gpu/drm/via/Makefile
@@ -3,6 +3,10 @@
 # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
 
 ccflags-y := -Iinclude/drm
-via-y:= via_irq.o via_drv.o via_map.o via_mm.o via_h1_cmdbuf.o 
via_verifier.o via_video.o via_h1_dma.o
+via-y:= via_drv.o via_pm.o via_i2c.o via_irq.o via_verifier.o via_ioc32.o \
+   init_ttm.o ttm_gem.o via_ttm.o via_fence.o via_sgdma.o \
+   via_h1_dma.o via_h1_cmdbuf.o \
+   via_display.o via_crtc.o via_fb.o crtc_hw.o via_clocks.o \
+   via_analog.o via_lvds.o via_tmds.o via_hdmi.o
 
-obj-$(CONFIG_DRM_VIA)  +=via.o
+obj-$(CONFIG_DRM_VIA)  += via.o
diff --git a/drivers/gpu/drm/via/via_drv.c b/drivers/gpu/drm/via/via_drv.c
index f4ae203..2a8592b 100644
--- a/drivers/gpu/drm/via/via_drv.c
+++ b/drivers/gpu/drm/via/via_drv.c
@@ -16,72 +16,436 @@
  * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
-
 #include linux/module.h
 
 #include drm/drmP.h
 #include drm/via_drm.h
+#include drm/drm_pciids.h
+
 #include via_drv.h
 
-#include drm/drm_pciids.h
+int via_modeset = 0;
+
+MODULE_PARM_DESC(modeset, Disable/Enable modesetting);
+module_param_named(modeset, via_modeset, int, 0400);
+
+int via_hdmi_audio = 0;
+
+MODULE_PARM_DESC(audio, HDMI Audio enable (1 = enable));
+module_param_named(audio, via_hdmi_audio, int, 0444);
 
-static int via_driver_open(struct drm_device *dev, struct drm_file *file)
+static struct pci_device_id via_pci_table[] = {
+   viadrv_PCI_IDS,
+};
+MODULE_DEVICE_TABLE(pci, via_pci_table);
+
+#define SGDMA_MEMORY (256*1024)
+#define VQ_MEMORY (256*1024)
+
+#if __OS_HAS_AGP
+
+#define VIA_AGP_MODE_MASK  0x17
+#define VIA_AGPV3_MODE 0x08
+#define VIA_AGPV3_8X_MODE  0x02
+#define VIA_AGPV3_4X_MODE  0x01
+#define VIA_AGP_4X_MODE0x04
+#define VIA_AGP_2X_MODE0x02
+#define VIA_AGP_1X_MODE0x01
+#define VIA_AGP_FW_MODE0x10
+
+static int
+via_detect_agp(struct drm_device *dev)
 {
-   struct via_file_private *file_priv;
+   struct drm_via_private *dev_priv = dev-dev_private;
+   struct drm_agp_info agp_info;
+   struct drm_agp_mode mode;
+   int ret = 0;
 
-   DRM_DEBUG_DRIVER(\n);
-   file_priv = kmalloc(sizeof(*file_priv), GFP_KERNEL);
-   if (!file_priv)
-   return -ENOMEM;
+   ret = drm_agp_acquire(dev);
+   if (ret) {
+   DRM_ERROR(Failed acquiring AGP device.\n);
+   return ret;
+   }
+
+   ret = drm_agp_info(dev, agp_info);
+   if (ret) {
+   DRM_ERROR(Failed detecting AGP aperture size.\n);
+   goto out_err0;
+   }
+
+   mode.mode = agp_info.mode  ~VIA_AGP_MODE_MASK;
+   if (mode.mode  VIA_AGPV3_MODE)
+   mode.mode |= VIA_AGPV3_8X_MODE;
+   else
+   mode.mode |= VIA_AGP_4X_MODE;
+
+   mode.mode |= VIA_AGP_FW_MODE;
+   ret = drm_agp_enable(dev, mode);
+   if (ret) {
+   DRM_ERROR(Failed to enable the AGP bus.\n);
+   goto out_err0;
+   }
+
+   ret = ttm_bo_init_mm(dev_priv-bdev, TTM_PL_TT, agp_info.aperture_size 
 PAGE_SHIFT);
+   if (!ret) {
+   DRM_INFO(Detected %lu MB of AGP Aperture at 
+   physical address 0x%08lx.\n,
+   

[PATCH 1/2] drm/gma500/psb: Unpin framebuffer on crtc disable

2013-06-08 Thread Patrik Jakobsson
The framebuffer needs to be unpinned in the crtc-disable callback
because of previous pinning in psb_intel_pipe_set_base(). This will fix
a memory leak where the framebuffer was released but not unpinned
properly. This patch only affects Poulsbo.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=889511
Bugzilla: https://bugzilla.novell.com/show_bug.cgi?id=812113
Signed-off-by: Patrik Jakobsson patrik.r.jakobs...@gmail.com
---
 drivers/gpu/drm/gma500/psb_intel_display.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/gma500/psb_intel_display.c 
b/drivers/gpu/drm/gma500/psb_intel_display.c
index 6e8f42b..12d129e 100644
--- a/drivers/gpu/drm/gma500/psb_intel_display.c
+++ b/drivers/gpu/drm/gma500/psb_intel_display.c
@@ -1150,6 +1150,19 @@ static void psb_intel_crtc_destroy(struct drm_crtc *crtc)
kfree(psb_intel_crtc);
 }
 
+static void psb_intel_crtc_disable(struct drm_crtc *crtc)
+{
+   struct gtt_range *gt;
+   struct drm_crtc_helper_funcs *crtc_funcs = crtc-helper_private;
+
+   crtc_funcs-dpms(crtc, DRM_MODE_DPMS_OFF);
+
+   if (crtc-fb) {
+   gt = to_psb_fb(crtc-fb)-gtt;
+   psb_gtt_unpin(gt);
+   }
+}
+
 const struct drm_crtc_helper_funcs psb_intel_helper_funcs = {
.dpms = psb_intel_crtc_dpms,
.mode_fixup = psb_intel_crtc_mode_fixup,
@@ -1157,6 +1170,7 @@ const struct drm_crtc_helper_funcs psb_intel_helper_funcs 
= {
.mode_set_base = psb_intel_pipe_set_base,
.prepare = psb_intel_crtc_prepare,
.commit = psb_intel_crtc_commit,
+   .disable = psb_intel_crtc_disable,
 };
 
 const struct drm_crtc_funcs psb_intel_crtc_funcs = {
-- 
1.8.1.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 2/2] drm/gma500/cdv: Unpin framebuffer on crtc disable

2013-06-08 Thread Patrik Jakobsson
The framebuffer needs to be unpinned in the crtc-disable callback
because of previous pinning in psb_intel_pipe_set_base(). This will fix
a memory leak where the framebuffer was released but not unpinned
properly. This patch only affects Cedarview.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=889511
Bugzilla: https://bugzilla.novell.com/show_bug.cgi?id=812113
Signed-off-by: Patrik Jakobsson patrik.r.jakobs...@gmail.com
---
 drivers/gpu/drm/gma500/cdv_intel_display.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/gma500/cdv_intel_display.c 
b/drivers/gpu/drm/gma500/cdv_intel_display.c
index 3cfd093..d6742dc 100644
--- a/drivers/gpu/drm/gma500/cdv_intel_display.c
+++ b/drivers/gpu/drm/gma500/cdv_intel_display.c
@@ -1750,6 +1750,19 @@ static void cdv_intel_crtc_destroy(struct drm_crtc *crtc)
kfree(psb_intel_crtc);
 }
 
+static void cdv_intel_crtc_disable(struct drm_crtc *crtc)
+{
+   struct gtt_range *gt;
+   struct drm_crtc_helper_funcs *crtc_funcs = crtc-helper_private;
+
+   crtc_funcs-dpms(crtc, DRM_MODE_DPMS_OFF);
+
+   if (crtc-fb) {
+   gt = to_psb_fb(crtc-fb)-gtt;
+   psb_gtt_unpin(gt);
+   }
+}
+
 const struct drm_crtc_helper_funcs cdv_intel_helper_funcs = {
.dpms = cdv_intel_crtc_dpms,
.mode_fixup = cdv_intel_crtc_mode_fixup,
@@ -1757,6 +1770,7 @@ const struct drm_crtc_helper_funcs cdv_intel_helper_funcs 
= {
.mode_set_base = cdv_intel_pipe_set_base,
.prepare = cdv_intel_crtc_prepare,
.commit = cdv_intel_crtc_commit,
+   .disable = cdv_intel_crtc_disable,
 };
 
 const struct drm_crtc_funcs cdv_intel_crtc_funcs = {
-- 
1.8.1.2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 1/2] drm/gma500/psb: Unpin framebuffer on crtc disable

2013-06-08 Thread Patrik Jakobsson
On Sat, Jun 8, 2013 at 9:01 PM, Patrik Jakobsson
patrik.r.jakobs...@gmail.com wrote:
 The framebuffer needs to be unpinned in the crtc-disable callback
 because of previous pinning in psb_intel_pipe_set_base(). This will fix
 a memory leak where the framebuffer was released but not unpinned
 properly. This patch only affects Poulsbo.

 Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=889511
 Bugzilla: https://bugzilla.novell.com/show_bug.cgi?id=812113
 Signed-off-by: Patrik Jakobsson patrik.r.jakobs...@gmail.com
 ---
  drivers/gpu/drm/gma500/psb_intel_display.c | 14 ++
  1 file changed, 14 insertions(+)

 diff --git a/drivers/gpu/drm/gma500/psb_intel_display.c 
 b/drivers/gpu/drm/gma500/psb_intel_display.c
 index 6e8f42b..12d129e 100644
 --- a/drivers/gpu/drm/gma500/psb_intel_display.c
 +++ b/drivers/gpu/drm/gma500/psb_intel_display.c
 @@ -1150,6 +1150,19 @@ static void psb_intel_crtc_destroy(struct drm_crtc 
 *crtc)
 kfree(psb_intel_crtc);
  }

 +static void psb_intel_crtc_disable(struct drm_crtc *crtc)
 +{
 +   struct gtt_range *gt;
 +   struct drm_crtc_helper_funcs *crtc_funcs = crtc-helper_private;
 +
 +   crtc_funcs-dpms(crtc, DRM_MODE_DPMS_OFF);
 +
 +   if (crtc-fb) {
 +   gt = to_psb_fb(crtc-fb)-gtt;
 +   psb_gtt_unpin(gt);
 +   }
 +}
 +
  const struct drm_crtc_helper_funcs psb_intel_helper_funcs = {
 .dpms = psb_intel_crtc_dpms,
 .mode_fixup = psb_intel_crtc_mode_fixup,
 @@ -1157,6 +1170,7 @@ const struct drm_crtc_helper_funcs 
 psb_intel_helper_funcs = {
 .mode_set_base = psb_intel_pipe_set_base,
 .prepare = psb_intel_crtc_prepare,
 .commit = psb_intel_crtc_commit,
 +   .disable = psb_intel_crtc_disable,
  };

  const struct drm_crtc_funcs psb_intel_crtc_funcs = {
 --
 1.8.1.2


Dave, this is a less hackish fix to the framebuffer leak bug I've been having.
Daniel Vetter suggested this approach and it works as expected. ACK or NACK?

If this is ok I'll send you a pull request early next week so we can get it
into 3.10.

Thanks
Patrik
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH 1/2] drm/gma500/psb: Unpin framebuffer on crtc disable

2013-06-08 Thread Daniel Vetter
On Sat, Jun 08, 2013 at 09:07:33PM +0200, Patrik Jakobsson wrote:
 On Sat, Jun 8, 2013 at 9:01 PM, Patrik Jakobsson
 patrik.r.jakobs...@gmail.com wrote:
  The framebuffer needs to be unpinned in the crtc-disable callback
  because of previous pinning in psb_intel_pipe_set_base(). This will fix
  a memory leak where the framebuffer was released but not unpinned
  properly. This patch only affects Poulsbo.
 
  Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=889511
  Bugzilla: https://bugzilla.novell.com/show_bug.cgi?id=812113
  Signed-off-by: Patrik Jakobsson patrik.r.jakobs...@gmail.com
  ---
   drivers/gpu/drm/gma500/psb_intel_display.c | 14 ++
   1 file changed, 14 insertions(+)
 
  diff --git a/drivers/gpu/drm/gma500/psb_intel_display.c 
  b/drivers/gpu/drm/gma500/psb_intel_display.c
  index 6e8f42b..12d129e 100644
  --- a/drivers/gpu/drm/gma500/psb_intel_display.c
  +++ b/drivers/gpu/drm/gma500/psb_intel_display.c
  @@ -1150,6 +1150,19 @@ static void psb_intel_crtc_destroy(struct drm_crtc 
  *crtc)
  kfree(psb_intel_crtc);
   }
 
  +static void psb_intel_crtc_disable(struct drm_crtc *crtc)
  +{
  +   struct gtt_range *gt;
  +   struct drm_crtc_helper_funcs *crtc_funcs = crtc-helper_private;
  +
  +   crtc_funcs-dpms(crtc, DRM_MODE_DPMS_OFF);
  +
  +   if (crtc-fb) {
  +   gt = to_psb_fb(crtc-fb)-gtt;
  +   psb_gtt_unpin(gt);
  +   }
  +}
  +
   const struct drm_crtc_helper_funcs psb_intel_helper_funcs = {
  .dpms = psb_intel_crtc_dpms,
  .mode_fixup = psb_intel_crtc_mode_fixup,
  @@ -1157,6 +1170,7 @@ const struct drm_crtc_helper_funcs 
  psb_intel_helper_funcs = {
  .mode_set_base = psb_intel_pipe_set_base,
  .prepare = psb_intel_crtc_prepare,
  .commit = psb_intel_crtc_commit,
  +   .disable = psb_intel_crtc_disable,
   };
 
   const struct drm_crtc_funcs psb_intel_crtc_funcs = {
  --
  1.8.1.2
 
 
 Dave, this is a less hackish fix to the framebuffer leak bug I've been 
 having.
 Daniel Vetter suggested this approach and it works as expected. ACK or NACK?

Yeah, this is how we've done it in i915 before switching away from crtc
helpers. For both patches:

Reviewed-by: Daniel Vetter daniel.vet...@ffwll.ch
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[Bug 65438] GTK apps crash X11 since last update of LLVMM

2013-06-08 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=65438

--- Comment #5 from Rafael Castillo jrch2...@gmail.com ---
i confirm that commit 8a72c73032707c7b3c042b716286a1ac33720991
seems the culprit

btw hadack and michael many thanks for you help

-- 
You are receiving this mail because:
You are the assignee for the bug.
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[Bug 65438] GTK apps crash X11 since last update of LLVMM

2013-06-08 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=65438

--- Comment #6 from Rafael Castillo jrch2...@gmail.com ---
btw hadack your 7750 can reclock? i mean profile mid/high or dynpm, in case it
crashes the kernel like mine i made this bug report 
https://bugzilla.kernel.org/show_bug.cgi?id=58621

-- 
You are receiving this mail because:
You are the assignee for the bug.
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[Bug 65438] GTK apps crash X11 since last update of LLVMM

2013-06-08 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=65438

--- Comment #7 from Tom Stellard tstel...@gmail.com ---
Can you set the environment variable RADEON_DUMP_SHADERS=1 and re-post the
output you get when starting xfce?

-- 
You are receiving this mail because:
You are the assignee for the bug.
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[Bug 65514] Mesa can't render Google Maps WebGL preview in Firefox

2013-06-08 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=65514

Nicholas Miell nmi...@gmail.com changed:

   What|Removed |Added

   See Also||https://bugzilla.mozilla.or
   ||g/show_bug.cgi?id=880734

--- Comment #1 from Nicholas Miell nmi...@gmail.com ---
Mozilla bug implies this also happens with Intel GPUs.

-- 
You are receiving this mail because:
You are the assignee for the bug.
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[Bug 65514] Mesa can't render Google Maps WebGL preview in Firefox

2013-06-08 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=65514

Nicholas Miell nmi...@gmail.com changed:

   What|Removed |Added

   Assignee|dri-devel@lists.freedesktop |mesa-dev@lists.freedesktop.
   |.org|org
  Component|Drivers/Gallium/r600|Mesa core

-- 
You are receiving this mail because:
You are the assignee for the bug.
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[Bug 65068] vgaswitcheroo doesn't deal with powered off dGPU on resume

2013-06-08 Thread bugzilla-daemon
https://bugs.freedesktop.org/show_bug.cgi?id=65068

--- Comment #9 from Austin Lund austin.l...@gmail.com ---
Created attachment 80547
  -- https://bugs.freedesktop.org/attachment.cgi?id=80547action=edit
pci_restore_config_dword debugging when resuming with dGPU off at suspend

It is log output like this that worries my about the 0xff reads from the pci
config space.

I set this in dynamic_debug:

drivers/pci/pci.c:964 [pci]pci_restore_config_dword =p restoring config space
at offset %#x (was %#x, writing %#x)\012

Then it gives this 0xff writing to the pci address space on restore when using
the integrated gpu.  Surely this cannot help.  My guess is that the hardware
should be removed from the kernel when the power is turned off.  But that's
just a hunch.

-- 
You are receiving this mail because:
You are the assignee for the bug.
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel