[PATCH] via: New TTM/GEM ioctls to support.

2013-07-04 Thread James Simmons

Add new TTM/GEM ioctls to be able to manage buffer regions from
different domains. Included in the new ioctls is the ability to
query hardware information.

Signed-Off-by: James Simmons 
---
 include/uapi/drm/via_drm.h |  115 
 1 file changed, 95 insertions(+), 20 deletions(-)

diff --git a/include/uapi/drm/via_drm.h b/include/uapi/drm/via_drm.h
index 8b0533c..7a32594 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.
@@ -24,7 +24,7 @@
 #ifndef _VIA_DRM_H_
 #define _VIA_DRM_H_

-#include 
+#include "drm.h"

 /* WARNING: These defines must be the same as what the Xserver uses.
  * if you change them, you must change the defines in the Xserver.
@@ -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 VIA_MAX_CACHELINE_SIZE 64
 #define XVMCLOCKPTR(saPriv,lockNo) \
((volatile struct drm_hw_lock *)(unsigned long) 
(saPriv)->XvMCLockArea) + \
  (VIA_MAX_CACHELINE_SIZE - 1)) &   \
@@ -64,21 +60,28 @@

 /* VIA specific ioctls */
 #define DRM_VIA_ALLOCMEM   0x00
-#define DRM_VIA_FREEMEM0x01
+#define DRM_VIA_FREEMEM0x01
 #define DRM_VIA_AGP_INIT   0x02
-#define DRM_VIA_FB_INIT0x03
+#define DRM_VIA_FB_INIT0x03
 #define DRM_VIA_MAP_INIT   0x04
-#define DRM_VIA_DEC_FUTEX   0x05
-#define NOT_USED
+#define DRM_VIA_DEC_FUTEX  0x05
+#define DRM_VIA_OLD_GEM_CREATE 0x06
 #define DRM_VIA_DMA_INIT   0x07
 #define DRM_VIA_CMDBUFFER  0x08
-#define DRM_VIA_FLUSH  0x09
-#define DRM_VIA_PCICMD 0x0a
+#define DRM_VIA_FLUSH  0x09
+#define DRM_VIA_PCICMD 0x0a
 #define DRM_VIA_CMDBUF_SIZE0x0b
 #define NOT_USED
-#define DRM_VIA_WAIT_IRQ0x0d
-#define DRM_VIA_DMA_BLIT0x0e
-#define DRM_VIA_BLIT_SYNC   0x0f
+#define DRM_VIA_WAIT_IRQ   0x0d
+#define DRM_VIA_DMA_BLIT   0x0e
+#define DRM_VIA_BLIT_SYNC  0x0f
+
+/* KMS ioctls */
+#define DRM_VIA_GETPARAM   0x10
+#define DRM_VIA_SETPARAM   0x11
+#define DRM_VIA_GEM_CREATE 0x12
+#define DRM_VIA_GEM_WAIT   0x13
+#define DRM_VIA_GEM_STATE  0x14

 #define DRM_IOCTL_VIA_ALLOCMEM   DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_ALLOCMEM, 
drm_via_mem_t)
 #define DRM_IOCTL_VIA_FREEMEMDRM_IOW( DRM_COMMAND_BASE + DRM_VIA_FREEMEM, 
drm_via_mem_t)
@@ -86,6 +89,7 @@
 #define DRM_IOCTL_VIA_FB_INITDRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_FB_INIT, 
drm_via_fb_t)
 #define DRM_IOCTL_VIA_MAP_INIT   DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_MAP_INIT, 
drm_via_init_t)
 #define DRM_IOCTL_VIA_DEC_FUTEX   DRM_IOW( DRM_COMMAND_BASE + 
DRM_VIA_DEC_FUTEX, drm_via_futex_t)
+#define DRM_IOCTL_VIA_OLD_GEM_CREATE  DRM_IOWR(DRM_COMMAND_BASE + 
DRM_VIA_OLD_GEM_CREATE, struct drm_via_gem_create)
 #define DRM_IOCTL_VIA_DMA_INIT   DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_DMA_INIT, 
drm_via_dma_init_t)
 #define DRM_IOCTL_VIA_CMDBUFFER  DRM_IOW( DRM_COMMAND_BASE + 
DRM_VIA_CMDBUFFER, drm_via_cmdbuffer_t)
 #define DRM_IOCTL_VIA_FLUSH  DRM_IO(  DRM_COMMAND_BASE + DRM_VIA_FLUSH)
@@ -96,6 +100,13 @@
 #define DRM_IOCTL_VIA_DMA_BLITDRM_IOW(DRM_COMMAND_BASE + DRM_VIA_DMA_BLIT, 
drm_via_dmablit_t)
 #define DRM_IOCTL_VIA_BLIT_SYNC   DRM_IOW(DRM_COMMAND_BASE + 
DRM_VIA_BLIT_SYNC, drm_via_blitsync_t)

+/* KMS ioctls */
+#define DRM_IOCTL_VIA_GETPARAMDRM_IOR(DRM_COMMAND_BASE + DRM_VIA_GETPARAM, 
struct drm_via_param)
+#define DRM_IOCTL_VIA_SETPARAMDRM_IOW(DRM_COMMAND_BASE + DRM_VIA_SETPARAM, 
struct drm_via_param)
+#define DRM_IOCTL_VIA_GEM_CREATE  DRM_IOWR(DRM_COMMAND_BASE + 
DRM_VIA_GEM_CREATE, struct drm_via_gem_create)
+#define DRM_IOCTL_VIA_GEM_WAITDRM_IOW(DRM_COMMAND_BASE + DRM_VIA_GEM_WAIT, 
struct drm_via_gem_wait)
+#define DRM_IOCTL_VIA_GEM_STATE   DRM_IOWR(DRM_COMMAND_BASE + 
DRM_VIA_GEM_STATE, struct drm_via_gem_create)
+
 /* Indices into buf.Setup where various bits of state are mirrored per
  * context and per buffer.  These can be fired at the 

[PATCH] via: New TTM/GEM ioctls to support.

2013-07-04 Thread James Simmons

Add new TTM/GEM ioctls to be able to manage buffer regions from
different domains. Included in the new ioctls is the ability to
query hardware information.

Signed-Off-by: James Simmons jsimm...@infradead.org
---
 include/uapi/drm/via_drm.h |  115 
 1 file changed, 95 insertions(+), 20 deletions(-)

diff --git a/include/uapi/drm/via_drm.h b/include/uapi/drm/via_drm.h
index 8b0533c..7a32594 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.
@@ -24,7 +24,7 @@
 #ifndef _VIA_DRM_H_
 #define _VIA_DRM_H_
 
-#include drm/drm.h
+#include drm.h
 
 /* WARNING: These defines must be the same as what the Xserver uses.
  * if you change them, you must change the defines in the Xserver.
@@ -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 VIA_MAX_CACHELINE_SIZE 64
 #define XVMCLOCKPTR(saPriv,lockNo) \
((volatile struct drm_hw_lock *)(unsigned long) 
(saPriv)-XvMCLockArea) + \
  (VIA_MAX_CACHELINE_SIZE - 1))\
@@ -64,21 +60,28 @@
 
 /* VIA specific ioctls */
 #define DRM_VIA_ALLOCMEM   0x00
-#define DRM_VIA_FREEMEM0x01
+#define DRM_VIA_FREEMEM0x01
 #define DRM_VIA_AGP_INIT   0x02
-#define DRM_VIA_FB_INIT0x03
+#define DRM_VIA_FB_INIT0x03
 #define DRM_VIA_MAP_INIT   0x04
-#define DRM_VIA_DEC_FUTEX   0x05
-#define NOT_USED
+#define DRM_VIA_DEC_FUTEX  0x05
+#define DRM_VIA_OLD_GEM_CREATE 0x06
 #define DRM_VIA_DMA_INIT   0x07
 #define DRM_VIA_CMDBUFFER  0x08
-#define DRM_VIA_FLUSH  0x09
-#define DRM_VIA_PCICMD 0x0a
+#define DRM_VIA_FLUSH  0x09
+#define DRM_VIA_PCICMD 0x0a
 #define DRM_VIA_CMDBUF_SIZE0x0b
 #define NOT_USED
-#define DRM_VIA_WAIT_IRQ0x0d
-#define DRM_VIA_DMA_BLIT0x0e
-#define DRM_VIA_BLIT_SYNC   0x0f
+#define DRM_VIA_WAIT_IRQ   0x0d
+#define DRM_VIA_DMA_BLIT   0x0e
+#define DRM_VIA_BLIT_SYNC  0x0f
+
+/* KMS ioctls */
+#define DRM_VIA_GETPARAM   0x10
+#define DRM_VIA_SETPARAM   0x11
+#define DRM_VIA_GEM_CREATE 0x12
+#define DRM_VIA_GEM_WAIT   0x13
+#define DRM_VIA_GEM_STATE  0x14
 
 #define DRM_IOCTL_VIA_ALLOCMEM   DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_ALLOCMEM, 
drm_via_mem_t)
 #define DRM_IOCTL_VIA_FREEMEMDRM_IOW( DRM_COMMAND_BASE + DRM_VIA_FREEMEM, 
drm_via_mem_t)
@@ -86,6 +89,7 @@
 #define DRM_IOCTL_VIA_FB_INITDRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_FB_INIT, 
drm_via_fb_t)
 #define DRM_IOCTL_VIA_MAP_INIT   DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_MAP_INIT, 
drm_via_init_t)
 #define DRM_IOCTL_VIA_DEC_FUTEX   DRM_IOW( DRM_COMMAND_BASE + 
DRM_VIA_DEC_FUTEX, drm_via_futex_t)
+#define DRM_IOCTL_VIA_OLD_GEM_CREATE  DRM_IOWR(DRM_COMMAND_BASE + 
DRM_VIA_OLD_GEM_CREATE, struct drm_via_gem_create)
 #define DRM_IOCTL_VIA_DMA_INIT   DRM_IOWR(DRM_COMMAND_BASE + DRM_VIA_DMA_INIT, 
drm_via_dma_init_t)
 #define DRM_IOCTL_VIA_CMDBUFFER  DRM_IOW( DRM_COMMAND_BASE + 
DRM_VIA_CMDBUFFER, drm_via_cmdbuffer_t)
 #define DRM_IOCTL_VIA_FLUSH  DRM_IO(  DRM_COMMAND_BASE + DRM_VIA_FLUSH)
@@ -96,6 +100,13 @@
 #define DRM_IOCTL_VIA_DMA_BLITDRM_IOW(DRM_COMMAND_BASE + DRM_VIA_DMA_BLIT, 
drm_via_dmablit_t)
 #define DRM_IOCTL_VIA_BLIT_SYNC   DRM_IOW(DRM_COMMAND_BASE + 
DRM_VIA_BLIT_SYNC, drm_via_blitsync_t)
 
+/* KMS ioctls */
+#define DRM_IOCTL_VIA_GETPARAMDRM_IOR(DRM_COMMAND_BASE + DRM_VIA_GETPARAM, 
struct drm_via_param)
+#define DRM_IOCTL_VIA_SETPARAMDRM_IOW(DRM_COMMAND_BASE + DRM_VIA_SETPARAM, 
struct drm_via_param)
+#define DRM_IOCTL_VIA_GEM_CREATE  DRM_IOWR(DRM_COMMAND_BASE + 
DRM_VIA_GEM_CREATE, struct drm_via_gem_create)
+#define DRM_IOCTL_VIA_GEM_WAITDRM_IOW(DRM_COMMAND_BASE + DRM_VIA_GEM_WAIT, 
struct drm_via_gem_wait)
+#define DRM_IOCTL_VIA_GEM_STATE   DRM_IOWR(DRM_COMMAND_BASE + 
DRM_VIA_GEM_STATE, struct drm_via_gem_create)
+
 /* Indices into buf.Setup where various bits of state are mirrored per
  * context and per buffer.  These can be fired at the card

drm-next status (or: drm-openchrome will not be in 3.11)

2013-06-30 Thread James Simmons

> Am Freitag, 28. Juni 2013, 13:31:50 schrieb Dave Airlie:
> > Okay drm-next is pretty big, possibly the biggest ever.
> > 
> > Outstanding things I know about, and will merge, if they arrive soon:
> > exynos -next
> > nouveau -next
> > 
> > Big things I've merged:
> > new rcar driver
> > intel next
> > radeon next
> > tegra next
> > shmob next
> > core/mutexes
> > ttm -> reservation conversion
> > tilcdc patches acked by Rob
> > mtrr reworking
> > prime + gem patches from samsung
> > Laurent's documentation updates
> > various mgag200 patches
> > 
> > Otherwise I'm sure I've missed some changes, please let me know of
> > anything you think has fallen down the cracks asap.
> > 
> > Slow down people :-P
> > 
> > Dave.
> 
> IRC #dri-devel:
> 
>  airlied: drm-openchrome will not be part of Kernel 3.11 because 
> jsimmons has not responded?
> 
>  jobermayr: seems likely, I don't merge just because someone posts 
> patchrs
> 
> 
> Tasks to do:
> http://lists.freedesktop.org/archives/dri-devel/2013-June/039695.html
> http://lists.freedesktop.org/archives/dri-devel/2013-June/039796.html

The VIA driver is pretty huge. Its going to take time to merge it. Plus 
I'm the new guy so I don't have the level of trust the other maintainers
have.


[Openchrome-devel] [RFC 1/21] Add VIA DRM driver

2013-06-30 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.
> 
> why remove all the __u32? seems to just undo
> 1d7f83d5ad6c30b385ba549c1c3a287cc872b7ae
> 
> and definitely shouldn't be in this patch.

Attempting to sync my userland header in xorg with what is used in the 
kernel. Since we have BSD users I attempted to play nice. This weekend
I played with a new header format that should satisfy everyone.

> Also I don't think its really necessary to add all the pci ids there,
> just put them in the driver.

Would you be okay with the pci ids being in via_drm.h instead? I have to 
look but if I remember correctly some of those pci ids are for the north 
bridge bus which is used to detect how much VRAM we have.

> >
> >  #define DRM_IOCTL_VIA_ALLOCMEM   DRM_IOWR(DRM_COMMAND_BASE + 
> > DRM_VIA_ALLOCMEM, drm_via_mem_t)
> >  #define DRM_IOCTL_VIA_FREEMEMDRM_IOW( DRM_COMMAND_BASE + 
> > DRM_VIA_FREEMEM, drm_via_mem_t)
> > @@ -86,6 +89,7 @@
> >  #define DRM_IOCTL_VIA_FB_INITDRM_IOWR(DRM_COMMAND_BASE + 
> > DRM_VIA_FB_INIT, drm_via_fb_t)
> >  #define DRM_IOCTL_VIA_MAP_INIT   DRM_IOWR(DRM_COMMAND_BASE + 
> > DRM_VIA_MAP_INIT, drm_via_init_t)
> >  #define DRM_IOCTL_VIA_DEC_FUTEX   DRM_IOW( DRM_COMMAND_BASE + 
> > DRM_VIA_DEC_FUTEX, drm_via_futex_t)
> > +#define DRM_IOCTL_VIA_OLD_GEM_CREATE  DRM_IOWR(DRM_COMMAND_BASE + 
> > DRM_VIA_OLD_GEM_CREATE, struct drm_via_gem_create)
> >  #define DRM_IOCTL_VIA_DMA_INIT   DRM_IOWR(DRM_COMMAND_BASE + 
> > DRM_VIA_DMA_INIT, drm_via_dma_init_t)
> >  #define DRM_IOCTL_VIA_CMDBUFFER  DRM_IOW( DRM_COMMAND_BASE + 
> > DRM_VIA_CMDBUFFER, drm_via_cmdbuffer_t)
> >  #define DRM_IOCTL_VIA_FLUSH  DRM_IO(  DRM_COMMAND_BASE + DRM_VIA_FLUSH)
> > @@ -96,6 +100,13 @@
> >  #define DRM_IOCTL_VIA_DMA_BLITDRM_IOW(DRM_COMMAND_BASE + 
> > DRM_VIA_DMA_BLIT, drm_via_dmablit_t)
> >  #define DRM_IOCTL_VIA_BLIT_SYNC   DRM_IOW(DRM_COMMAND_BASE + 
> > DRM_VIA_BLIT_SYNC, drm_via_blitsync_t)
> >
> > +/* KMS ioctls */
> > +#define DRM_IOCTL_VIA_GETPARAMDRM_IOR(DRM_COMMAND_BASE + 
> > DRM_VIA_GETPARAM, struct drm_via_param)
> > +#define DRM_IOCTL_VIA_SETPARAMDRM_IOW(DRM_COMMAND_BASE + 
> > DRM_VIA_SETPARAM, struct drm_via_param)
> > +#define DRM_IOCTL_VIA_GEM_CREATE  DRM_IOWR(DRM_COMMAND_BASE + 
> > DRM_VIA_GEM_CREATE, struct drm_via_gem_create)
> > +#define DRM_IOCTL_VIA_GEM_WAITDRM_IOW(DRM_COMMAND_BASE + 
> > DRM_VIA_GEM_WAIT, struct drm_via_gem_wait)
> > +#define DRM_IOCTL_VIA_GEM_STATE   DRM_IOWR(DRM_COMMAND_BASE + 
> > DRM_VIA_GEM_STATE, struct drm_via_gem_create)
> 
> why does gem_state take a gem_create struct? is it the same info it returns?

Yes that same info is returned. Prehaps struct drm_via_gem_create is a 
poor name. Maybe struct drm_via_gem_object ?

> >  typedef struct drm_via_dmablit {
> > -   __u32 num_lines;
> > -   __u32 line_length;
> > +   uint32_t num_lines;
> > +   uint32_t line_length;
> >
> > -   __u32 fb_addr;
> > -   __u32 fb_stride;
> > +   uint32_t fb_addr;
> > +   uint32_t fb_stride;
> >
> > unsigned char *mem_addr;
> > -   __u32 mem_stride;
> > +   uint32_t  mem_stride;
> >
> > -   __u32 flags;
> > +   int bounce_buffer;
> 
> ^ totally wtf here? no explains.

Leftovers from older work that doesn't exist anymore. My bad.

> > int to_fb;
> >
> > drm_via_blitsync_t sync;
> >  } drm_via_dmablit_t;
> >
> > -struct via_file_private {
> > -   struct list_head obj_list;
> > +/* Ioctl to query kernel params:
> > + */
> > +#define VIA_PARAM_CHIPSET_ID   0
> > +#define VIA_PARAM_REVISION_ID  1
> > +
> > +struct drm_via_param {
> > +   uint64_t param;
> > +   uint64_t value;
> > +};
> > +
> > +struct drm_via_gem_create {
> > +   /**
> > +* Requested size for the object.
> > +*
> > +* The (page-aligned) allocated size for the object will be 
> > returned.
> > +*/
> > +   uint64_t size;
> > +
> > +   /*
> > +* Place the memory at the proper byte alignment.
> > +*/
> > +   uint32_t alignment;
> > +
> > +   /

Re: [Openchrome-devel] [RFC 1/21] Add VIA DRM driver

2013-06-30 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.
 
 why remove all the __u32? seems to just undo
 1d7f83d5ad6c30b385ba549c1c3a287cc872b7ae
 
 and definitely shouldn't be in this patch.

Attempting to sync my userland header in xorg with what is used in the 
kernel. Since we have BSD users I attempted to play nice. This weekend
I played with a new header format that should satisfy everyone.
 
 Also I don't think its really necessary to add all the pci ids there,
 just put them in the driver.

Would you be okay with the pci ids being in via_drm.h instead? I have to 
look but if I remember correctly some of those pci ids are for the north 
bridge bus which is used to detect how much VRAM we have.

 
   #define DRM_IOCTL_VIA_ALLOCMEM   DRM_IOWR(DRM_COMMAND_BASE + 
  DRM_VIA_ALLOCMEM, drm_via_mem_t)
   #define DRM_IOCTL_VIA_FREEMEMDRM_IOW( DRM_COMMAND_BASE + 
  DRM_VIA_FREEMEM, drm_via_mem_t)
  @@ -86,6 +89,7 @@
   #define DRM_IOCTL_VIA_FB_INITDRM_IOWR(DRM_COMMAND_BASE + 
  DRM_VIA_FB_INIT, drm_via_fb_t)
   #define DRM_IOCTL_VIA_MAP_INIT   DRM_IOWR(DRM_COMMAND_BASE + 
  DRM_VIA_MAP_INIT, drm_via_init_t)
   #define DRM_IOCTL_VIA_DEC_FUTEX   DRM_IOW( DRM_COMMAND_BASE + 
  DRM_VIA_DEC_FUTEX, drm_via_futex_t)
  +#define DRM_IOCTL_VIA_OLD_GEM_CREATE  DRM_IOWR(DRM_COMMAND_BASE + 
  DRM_VIA_OLD_GEM_CREATE, struct drm_via_gem_create)
   #define DRM_IOCTL_VIA_DMA_INIT   DRM_IOWR(DRM_COMMAND_BASE + 
  DRM_VIA_DMA_INIT, drm_via_dma_init_t)
   #define DRM_IOCTL_VIA_CMDBUFFER  DRM_IOW( DRM_COMMAND_BASE + 
  DRM_VIA_CMDBUFFER, drm_via_cmdbuffer_t)
   #define DRM_IOCTL_VIA_FLUSH  DRM_IO(  DRM_COMMAND_BASE + DRM_VIA_FLUSH)
  @@ -96,6 +100,13 @@
   #define DRM_IOCTL_VIA_DMA_BLITDRM_IOW(DRM_COMMAND_BASE + 
  DRM_VIA_DMA_BLIT, drm_via_dmablit_t)
   #define DRM_IOCTL_VIA_BLIT_SYNC   DRM_IOW(DRM_COMMAND_BASE + 
  DRM_VIA_BLIT_SYNC, drm_via_blitsync_t)
 
  +/* KMS ioctls */
  +#define DRM_IOCTL_VIA_GETPARAMDRM_IOR(DRM_COMMAND_BASE + 
  DRM_VIA_GETPARAM, struct drm_via_param)
  +#define DRM_IOCTL_VIA_SETPARAMDRM_IOW(DRM_COMMAND_BASE + 
  DRM_VIA_SETPARAM, struct drm_via_param)
  +#define DRM_IOCTL_VIA_GEM_CREATE  DRM_IOWR(DRM_COMMAND_BASE + 
  DRM_VIA_GEM_CREATE, struct drm_via_gem_create)
  +#define DRM_IOCTL_VIA_GEM_WAITDRM_IOW(DRM_COMMAND_BASE + 
  DRM_VIA_GEM_WAIT, struct drm_via_gem_wait)
  +#define DRM_IOCTL_VIA_GEM_STATE   DRM_IOWR(DRM_COMMAND_BASE + 
  DRM_VIA_GEM_STATE, struct drm_via_gem_create)
 
 why does gem_state take a gem_create struct? is it the same info it returns?

Yes that same info is returned. Prehaps struct drm_via_gem_create is a 
poor name. Maybe struct drm_via_gem_object ?

   typedef struct drm_via_dmablit {
  -   __u32 num_lines;
  -   __u32 line_length;
  +   uint32_t num_lines;
  +   uint32_t line_length;
 
  -   __u32 fb_addr;
  -   __u32 fb_stride;
  +   uint32_t fb_addr;
  +   uint32_t fb_stride;
 
  unsigned char *mem_addr;
  -   __u32 mem_stride;
  +   uint32_t  mem_stride;
 
  -   __u32 flags;
  +   int bounce_buffer;
 
 ^ totally wtf here? no explains.

Leftovers from older work that doesn't exist anymore. My bad.
 
  int to_fb;
 
  drm_via_blitsync_t sync;
   } drm_via_dmablit_t;
 
  -struct via_file_private {
  -   struct list_head obj_list;
  +/* Ioctl to query kernel params:
  + */
  +#define VIA_PARAM_CHIPSET_ID   0
  +#define VIA_PARAM_REVISION_ID  1
  +
  +struct drm_via_param {
  +   uint64_t param;
  +   uint64_t value;
  +};
  +
  +struct drm_via_gem_create {
  +   /**
  +* Requested size for the object.
  +*
  +* The (page-aligned) allocated size for the object will be 
  returned.
  +*/
  +   uint64_t size;
  +
  +   /*
  +* Place the memory at the proper byte alignment.
  +*/
  +   uint32_t alignment;
  +
  +   /**
  +* Format of data i.e tile pitch, for linear it is zero
  +*/
  +   uint32_t pitch;
  +
  +   /**
  +* Give hints where to allocate this object.
  +*/
  +   uint32_t domains;
  +
  +   /**
  +* chmod values applied to a buffer.
  +*/
  +   uint32_t mode_t;
  +
  +   /**
  +* Offset to start of memory region.
  +*/
  +   uint64_t offset;
  +
  +   /**
  +* Returned handle need to mmap the buffer.
  +*/
  +   uint64_t map_handle;
  +
  +   /**
  +* Returned handle for the object.
  +*
  +* Object handles are nonzero.
  +*/
  +   uint32_t handle;
  +
  +   /**
  +* Padding for future expansion

Re: drm-next status (or: drm-openchrome will not be in 3.11)

2013-06-30 Thread James Simmons

 Am Freitag, 28. Juni 2013, 13:31:50 schrieb Dave Airlie:
  Okay drm-next is pretty big, possibly the biggest ever.
  
  Outstanding things I know about, and will merge, if they arrive soon:
  exynos -next
  nouveau -next
  
  Big things I've merged:
  new rcar driver
  intel next
  radeon next
  tegra next
  shmob next
  core/mutexes
  ttm - reservation conversion
  tilcdc patches acked by Rob
  mtrr reworking
  prime + gem patches from samsung
  Laurent's documentation updates
  various mgag200 patches
  
  Otherwise I'm sure I've missed some changes, please let me know of
  anything you think has fallen down the cracks asap.
  
  Slow down people :-P
  
  Dave.
 
 IRC #dri-devel:
 
 jobermayr_ airlied: drm-openchrome will not be part of Kernel 3.11 because 
 jsimmons has not responded?
 
 airlied jobermayr: seems likely, I don't merge just because someone posts 
 patchrs
 
 
 Tasks to do:
 http://lists.freedesktop.org/archives/dri-devel/2013-June/039695.html
 http://lists.freedesktop.org/archives/dri-devel/2013-June/039796.html

The VIA driver is pretty huge. Its going to take time to merge it. Plus 
I'm the new guy so I don't have the level of trust the other maintainers
have.
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[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.\

[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   

[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) - a

[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;
+ 

[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 = ad

[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,
+   .

[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(

[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 =

[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;
+  

[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;
+   

[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

[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_w

[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));
+   V

[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_TABLE0

[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,
+  

[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

[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]) {
+   

[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);

[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

[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

[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.



[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
+via_fence_seq_signaled

[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
http

[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]) {
+   pci_unmap_page(dev

[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));
+   VIA_WRITE(VIA_REG_TRANSPACE

[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

[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

[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, fsb

[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 = enc

[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

drm-openchrome status (or will it be in Kernel 3.10?)

2013-05-27 Thread James Simmons
> > Dave what is the best way to push this code? I am in no rush so
> > I like to do it the right way. We have scattered history in the external
> > tree but I would not lose sleep over its lost. I could just post pieces
> > of the code to this list for review. One choice is after all the code is
> > reviewed is to then merge the branch. Another choice is to create a new
> > branch for later merge that will be composed of the patches posted to this
> > list. We lose the history but that is not to be of deal for me. Just let
> > me know what you would like and I will start the process.
> 
> Hi James,
> 
> I would probably say history loss is inevitable unless the tree is at
> a fairly high standard wrt bisection fail etc.
> 
> But it would probably be good to post the driver to dri-devel at least
> once so people can take a look, not sure what
> the best way to split it up is, the initial patches can be split
> different than what we merge if it makes reading it easier.
> 
> Can you post a link to what you consider the best place for me to be
> looking so I can see if splitting it makes sense.

Except for new pci ids in include/linux/pci_ids.h all the code is here

http://cgit.freedesktop.org/openchrome/drm-openchrome/tree/drivers/gpu/drm/via

Thank you for taking a look. 


drm-openchrome status (or will it be in Kernel 3.10?)

2013-05-26 Thread James Simmons

>  wrote:
> > Am Dienstag, 30. April 2013, 06:06:22 schrieb Dave Airlie:
> >> On Tue, Apr 30, 2013 at 2:17 AM, Johannes Obermayr
> >>  wrote:
> >> > Hi James,
> >> >
> >> > Linus recently released Kernel 3.9, merge window for Kernel 3.10 has 
> >> > been opened, and the question is whether drm-openchrome will be part of 
> >> > the new Kernel version.
> >>
> >> Johannes,
> >>
> >> you misunderstand merge window. The merge window is for stuff to go
> >> from toplevel maintainers to Linus, not for new stuff to appear and be
> >> merged.
> >
> > Dave,
> >
> > I know you maintain also a merge window for drm stuff which starts at ~ rc6.
> >
> > But I am unsure when it closes: When Linus opens his merge window or when 
> > you forward your main drm pull request to Linus.
> > First case means it is definitely too late for drm-openchrome in 3.10. 
> > Second case means there can be hope (depending on James' answer) ...
> >
> > But regarding your answer I assume first case is right.
> 
> Once Linus opens his window, I won't accept anything major that hasn't
> been posted to the list for review before.
> 
> I generally have a lag time of hoovering up on the list stuff, but
> something like this that has never been posted would have no hope.

Hello.

Sorry I didn't responded earlier. I was swamped at work with 
projects and conferences. After I got back from my last conference
Xavier informed me about this email and we had a discussion about
merging. Currently we have a external tree which is two years old but 
most of the work has happened in the last 8 months. The reason for
delaying mergering was to ensure most distros would be carrying the 
version of openchrome xorg driver that supports KMS. Today with that
barrier gone we have to deal with the drm-openchrome branch not being
in top shape. Since I have been back the tree has been cleaned up and 
the last show stoppers were checked in yesterday. Currently we support
LVDS, HDMI/DVI, and VGA outputs which cover most people. By no means is 
the kernel driver complete but it is usable. I would say the branch is
now ready for merger.
Dave what is the best way to push this code? I am in no rush so 
I like to do it the right way. We have scattered history in the external 
tree but I would not lose sleep over its lost. I could just post pieces
of the code to this list for review. One choice is after all the code is 
reviewed is to then merge the branch. Another choice is to create a new 
branch for later merge that will be composed of the patches posted to this 
list. We lose the history but that is not to be of deal for me. Just let 
me know what you would like and I will start the process.


Re: drm-openchrome status (or will it be in Kernel 3.10?)

2013-05-26 Thread James Simmons

 johannesoberm...@gmx.de wrote:
  Am Dienstag, 30. April 2013, 06:06:22 schrieb Dave Airlie:
  On Tue, Apr 30, 2013 at 2:17 AM, Johannes Obermayr
  johannesoberm...@gmx.de wrote:
   Hi James,
  
   Linus recently released Kernel 3.9, merge window for Kernel 3.10 has 
   been opened, and the question is whether drm-openchrome will be part of 
   the new Kernel version.
 
  Johannes,
 
  you misunderstand merge window. The merge window is for stuff to go
  from toplevel maintainers to Linus, not for new stuff to appear and be
  merged.
 
  Dave,
 
  I know you maintain also a merge window for drm stuff which starts at ~ rc6.
 
  But I am unsure when it closes: When Linus opens his merge window or when 
  you forward your main drm pull request to Linus.
  First case means it is definitely too late for drm-openchrome in 3.10. 
  Second case means there can be hope (depending on James' answer) ...
 
  But regarding your answer I assume first case is right.
 
 Once Linus opens his window, I won't accept anything major that hasn't
 been posted to the list for review before.
 
 I generally have a lag time of hoovering up on the list stuff, but
 something like this that has never been posted would have no hope.

Hello.

Sorry I didn't responded earlier. I was swamped at work with 
projects and conferences. After I got back from my last conference
Xavier informed me about this email and we had a discussion about
merging. Currently we have a external tree which is two years old but 
most of the work has happened in the last 8 months. The reason for
delaying mergering was to ensure most distros would be carrying the 
version of openchrome xorg driver that supports KMS. Today with that
barrier gone we have to deal with the drm-openchrome branch not being
in top shape. Since I have been back the tree has been cleaned up and 
the last show stoppers were checked in yesterday. Currently we support
LVDS, HDMI/DVI, and VGA outputs which cover most people. By no means is 
the kernel driver complete but it is usable. I would say the branch is
now ready for merger.
Dave what is the best way to push this code? I am in no rush so 
I like to do it the right way. We have scattered history in the external 
tree but I would not lose sleep over its lost. I could just post pieces
of the code to this list for review. One choice is after all the code is 
reviewed is to then merge the branch. Another choice is to create a new 
branch for later merge that will be composed of the patches posted to this 
list. We lose the history but that is not to be of deal for me. Just let 
me know what you would like and I will start the process.
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: drm-openchrome status (or will it be in Kernel 3.10?)

2013-05-26 Thread James Simmons
  Dave what is the best way to push this code? I am in no rush so
  I like to do it the right way. We have scattered history in the external
  tree but I would not lose sleep over its lost. I could just post pieces
  of the code to this list for review. One choice is after all the code is
  reviewed is to then merge the branch. Another choice is to create a new
  branch for later merge that will be composed of the patches posted to this
  list. We lose the history but that is not to be of deal for me. Just let
  me know what you would like and I will start the process.
 
 Hi James,
 
 I would probably say history loss is inevitable unless the tree is at
 a fairly high standard wrt bisection fail etc.
 
 But it would probably be good to post the driver to dri-devel at least
 once so people can take a look, not sure what
 the best way to split it up is, the initial patches can be split
 different than what we merge if it makes reading it easier.
 
 Can you post a link to what you consider the best place for me to be
 looking so I can see if splitting it makes sense.

Except for new pci ids in include/linux/pci_ids.h all the code is here

http://cgit.freedesktop.org/openchrome/drm-openchrome/tree/drivers/gpu/drm/via

Thank you for taking a look. 
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH] drm via: initialize object_idr

2012-06-20 Thread James Simmons

The field obejct_idr of struct drm_via_private was introduced with the
commit  

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=77ee8f3825054f23b17e9c8f728f061defd86cdc
 .

In that patch idr_init(>object_name_idr) was called instead of
idr_init(_priv->object_idr) by mistake, leaving the dev_priv->object_idr
uninitialized. To be more exact, the object_idr buffer is filled with zeros
because of kzalloc(), but the dev_priv->object_idr.lock spinlock can cause
system freeze at lib/idr.c:move_to_free_list() when spin_lock_irqsave()
is called on this spinlock.

Signed-off-by: M?rton N?meth 
Signed-off-by: James Simmons 

diff --git a/drivers/gpu/drm/via/via_map.c b/drivers/gpu/drm/via/via_map.c
index 1f18225..240bc49 100644
--- a/drivers/gpu/drm/via/via_map.c
+++ b/drivers/gpu/drm/via/via_map.c
@@ -100,12 +100,10 @@ int via_driver_load(struct drm_device *dev, unsigned long 
chipset)
if (dev_priv == NULL)
return -ENOMEM;

+   idr_init(_priv->object_idr);
dev->dev_private = (void *)dev_priv;
-
dev_priv->chipset = chipset;

-   idr_init(>object_name_idr);
-
pci_set_master(dev->pdev);

ret = drm_vblank_init(dev, 1);


[PATCH] drm via: initialize object_idr

2012-06-19 Thread James Simmons

The field obejct_idr of struct drm_via_private was introduced with the
commit  

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=77ee8f3825054f23b17e9c8f728f061defd86cdc
 .

In that patch idr_init(dev-object_name_idr) was called instead of
idr_init(dev_priv-object_idr) by mistake, leaving the dev_priv-object_idr
uninitialized. To be more exact, the object_idr buffer is filled with zeros
because of kzalloc(), but the dev_priv-object_idr.lock spinlock can cause
system freeze at lib/idr.c:move_to_free_list() when spin_lock_irqsave()
is called on this spinlock.

Signed-off-by: Márton Németh nm...@freemail.hu
Signed-off-by: James Simmons jsimm...@infradead.org

diff --git a/drivers/gpu/drm/via/via_map.c b/drivers/gpu/drm/via/via_map.c
index 1f18225..240bc49 100644
--- a/drivers/gpu/drm/via/via_map.c
+++ b/drivers/gpu/drm/via/via_map.c
@@ -100,12 +100,10 @@ int via_driver_load(struct drm_device *dev, unsigned long 
chipset)
if (dev_priv == NULL)
return -ENOMEM;
 
+   idr_init(dev_priv-object_idr);
dev-dev_private = (void *)dev_priv;
-
dev_priv-chipset = chipset;
 
-   idr_init(dev-object_name_idr);
-
pci_set_master(dev-pdev);
 
ret = drm_vblank_init(dev, 1);___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


Process to merge Openchrome work

2012-04-02 Thread James Simmons

Hello!!

This last year the Openchrome support for the VIA chipsets has 
come along way from being in a state of decay. The plan is to release
a Xorg driver June 1 that will have support for the KMS as well as UMS.
The goal is to have this xorg driver out in the wild before the kernel
side is ready so that the migration to the new kernel drivers will be
as painless as possible. My hope is to merge the kernel tree for public 
use for Christmas.
This brings up the question I had with the other project leader.
How does one go about merging the tree? What makes this more complex is
that a old via drm kernel driver already exist. Do we just drop in the 
code into the staging area? Does it have to be piece meal? Does a rename 
of the driver need to happen? What would you recommend ?



Process to merge Openchrome work

2012-04-02 Thread James Simmons

Hello!!

This last year the Openchrome support for the VIA chipsets has 
come along way from being in a state of decay. The plan is to release
a Xorg driver June 1 that will have support for the KMS as well as UMS.
The goal is to have this xorg driver out in the wild before the kernel
side is ready so that the migration to the new kernel drivers will be
as painless as possible. My hope is to merge the kernel tree for public 
use for Christmas.
This brings up the question I had with the other project leader.
How does one go about merging the tree? What makes this more complex is
that a old via drm kernel driver already exist. Do we just drop in the 
code into the staging area? Does it have to be piece meal? Does a rename 
of the driver need to happen? What would you recommend ?

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


drm-core-next vs drm-next

2012-03-15 Thread James Simmons

> as a headsup, if you are basing a tree on mine, please use
> drm-core-next not drm-next itself as a basis for your tree.
> 
> At the moment they've diverged as I've put the UDL kms driver into
> drm-next but not drm-core-next as it needs an external fbdev patch to
> work.

Is this temporary?


Re: drm-core-next vs drm-next

2012-03-15 Thread James Simmons

 as a headsup, if you are basing a tree on mine, please use
 drm-core-next not drm-next itself as a basis for your tree.
 
 At the moment they've diverged as I've put the UDL kms driver into
 drm-next but not drm-core-next as it needs an external fbdev patch to
 work.

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


[PATCH] drm: exynos: Fix fb_videomode <-> drm_mode_modeinfo conversion

2012-03-08 Thread James Simmons

> The fb_videomode structure stores the front porch and back porch in the
> right_margin and left_margin fields respectively. right_margin should
> thus be computed with hsync_start - hdisplay, and left_margin with
> htotal - hsync_end. The same holds for the vertical direction.
> 
>Active   Front   SyncBack
>Region   Porch   Porch
> <---><><-><>
> 
>   //|
>  // |
> //  |..   ..
>___
> 
> <-- xres ---><- right_margin -><- hsync_len -><- left_margin -->
> 
> < hdisplay ->
> < hsync_start >
> <- hsync_end >
> <- htotal ->
> 
> Fix the fb_videomode <-> drm_mode_modeinfo conversion functions
> accordingly.
> 

Wow I see this has remegered. Some time last year I posted a patch that 
had these routines in a generic format for people to use. I can repost 
them again if people are interested.



Re: [PATCH] drm: exynos: Fix fb_videomode - drm_mode_modeinfo conversion

2012-03-08 Thread James Simmons

 The fb_videomode structure stores the front porch and back porch in the
 right_margin and left_margin fields respectively. right_margin should
 thus be computed with hsync_start - hdisplay, and left_margin with
 htotal - hsync_end. The same holds for the vertical direction.
 
Active   Front   SyncBack
Region   Porch   Porch
 
 
   //|
  // |
 //  |..   ..
___
 
 -- xres  right_margin -- hsync_len -- left_margin --
 
  hdisplay -
  hsync_start 
 - hsync_end 
 - htotal -
 
 Fix the fb_videomode - drm_mode_modeinfo conversion functions
 accordingly.
 

Wow I see this has remegered. Some time last year I posted a patch that 
had these routines in a generic format for people to use. I can repost 
them again if people are interested.

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


[PATCH] xf86-video-modesetting generic colormap handling

2012-03-06 Thread James Simmons

This patch replaces drmmode_load_palette with a very generic function
that removes the need of drmmode_crtc_private_rec to carry around 
color indexes. Also have the xorg driver actually call 
the xf86HandleColormaps function.

Signed-off-by: James Simmons 

diff --git a/src/driver.c b/src/driver.c
index 87431ff..a825f35 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -42,6 +42,7 @@
 #include "xf86Pci.h"
 #include "mipointer.h"
 #include "micmap.h"
+#include "xf86cmap.h"
 #include 
 #include "fb.h"
 #include "edid.h"
@@ -540,6 +541,62 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 return FALSE;
 }

+static void
+LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
+LOCO * colors, VisualPtr pVisual)
+{
+xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+CARD16 lut_r[256], lut_g[256], lut_b[256];
+int i, j, k, index;
+
+for (k = 0; k < xf86_config->num_crtc; k++) {
+xf86CrtcPtr crtc = xf86_config->crtc[k];
+
+switch (pScrn->depth) {
+case 15:
+for (i = 0; i < numColors; i++) {
+index = indices[i];
+for (j = 0; j < 8; j++) {
+lut_r[index * 8 + j] = colors[index].red << 8;
+lut_g[index * 8 + j] = colors[index].green << 8;
+lut_b[index * 8 + j] = colors[index].blue << 8;
+}
+}
+break;
+case 16:
+for (i = 0; i < numColors; i++) {
+index = indices[i];
+
+if (index <= 31) {
+for (j = 0; j < 8; j++) {
+lut_r[index * 8 + j] = colors[index].red << 8;
+lut_b[index * 8 + j] = colors[index].blue << 8;
+}
+}
+
+for (j = 0; j < 4; j++)
+lut_g[index * 4 + j] = colors[index].green << 8;
+}
+break;
+default:
+for (i = 0; i < numColors; i++) {
+index = indices[i];
+lut_r[index] = colors[index].red << 8;
+lut_g[index] = colors[index].green << 8;
+lut_b[index] = colors[index].blue << 8;
+}
+break;
+}
+
+/* Make the change through RandR */
+#ifdef RANDR_12_INTERFACE
+RRCrtcGammaSet(crtc->randr_crtc, lut_r, lut_g, lut_b);
+#else /*RANDR_12_INTERFACE*/
+crtc->funcs->gamma_set(crtc, lut_r, lut_g, lut_b, 256);
+#endif
+}
+}
+
 static void *
 msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode,
   CARD32 *size, void *closure)
@@ -716,7 +773,12 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, 
char **argv)
return FALSE;

 if (!miCreateDefColormap(pScreen))
-   return FALSE;
+return FALSE;
+
+if (!xf86HandleColormaps(pScreen, 256, 8, LoadPalette, NULL,
+ CMAP_RELOAD_ON_MODE_SWITCH
+ | CMAP_PALETTED_TRUECOLOR))
+return FALSE;

 xf86DPMSInit(pScreen, xf86DPMSSet, 0);

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 7fa933a..d1da19a 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -1134,89 +1132,6 @@ Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, 
drmmode_ptr drmmode)
return TRUE;
 }

-static void drmmode_load_palette(ScrnInfoPtr pScrn, int numColors,
- int *indices, LOCO *colors, VisualPtr pVisual)
-{
-xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-uint16_t   lut_r[256], lut_g[256], lut_b[256];
-int index, j, i;
-int c;
-
-for (c = 0; c < xf86_config->num_crtc; c++) {
-xf86CrtcPtr crtc = xf86_config->crtc[c];
-   drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-
-for (i = 0 ; i < 256; i++) {
-lut_r[i] = drmmode_crtc->lut_r[i] << 6;
-lut_g[i] = drmmode_crtc->lut_g[i] << 6;
-lut_b[i] = drmmode_crtc->lut_b[i] << 6;
-}
-
-switch(pScrn->depth) {
-case 15:
-for (i = 0; i < numColors; i++) {
-index = indices[i];
-for (j = 0; j < 8; j++) {
-lut_r[index * 8 + j] = colors[index].red << 6;
-lut_g[index * 8 + j] = colors[index].green << 6;
-lut_b[index * 8 + j] = colors[index].blue << 6;
-}
-}
- break;
- case 16:
- for (i = 0; i < numColors; i++) {
- index = indices[i];
-
-  if (i <= 31) {
-  for (j = 0; j < 8; j++) {
-  lut_r[index * 8 + j] = colors[index].red << 6

[PATCH] xf86-video-modesetting cursor reload

2012-03-06 Thread James Simmons

Enable after a resolution change reload the cursor image.

Signed-off-by: James Simmons 

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 7fa933a..8a49103 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -361,11 +361,9 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr 
mode,
}
}

-#if 0
-   if (pScrn->pScreen &&
-   !xf86ReturnOptValBool(info->Options, OPTION_SW_CURSOR, FALSE))
+   if (pScrn->pScreen && !drmmode->sw_cursor)
xf86_reload_cursors(pScrn->pScreen);
-#endif
+
 done:
if (!ret) {
crtc->x = saved_x;


[PATCH] xf86-video-modesetting cursor reload

2012-03-06 Thread James Simmons

Enable after a resolution change reload the cursor image.

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

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 7fa933a..8a49103 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -361,11 +361,9 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr 
mode,
}
}
 
-#if 0
-   if (pScrn-pScreen 
-   !xf86ReturnOptValBool(info-Options, OPTION_SW_CURSOR, FALSE))
+   if (pScrn-pScreen  !drmmode-sw_cursor)
xf86_reload_cursors(pScrn-pScreen);
-#endif
+
 done:
if (!ret) {
crtc-x = saved_x;
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH] xf86-video-modesetting generic colormap handling

2012-03-06 Thread James Simmons

This patch replaces drmmode_load_palette with a very generic function
that removes the need of drmmode_crtc_private_rec to carry around 
color indexes. Also have the xorg driver actually call 
the xf86HandleColormaps function.

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

diff --git a/src/driver.c b/src/driver.c
index 87431ff..a825f35 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -42,6 +42,7 @@
 #include xf86Pci.h
 #include mipointer.h
 #include micmap.h
+#include xf86cmap.h
 #include X11/extensions/randr.h
 #include fb.h
 #include edid.h
@@ -540,6 +541,62 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 return FALSE;
 }
 
+static void
+LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
+LOCO * colors, VisualPtr pVisual)
+{
+xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+CARD16 lut_r[256], lut_g[256], lut_b[256];
+int i, j, k, index;
+
+for (k = 0; k  xf86_config-num_crtc; k++) {
+xf86CrtcPtr crtc = xf86_config-crtc[k];
+
+switch (pScrn-depth) {
+case 15:
+for (i = 0; i  numColors; i++) {
+index = indices[i];
+for (j = 0; j  8; j++) {
+lut_r[index * 8 + j] = colors[index].red  8;
+lut_g[index * 8 + j] = colors[index].green  8;
+lut_b[index * 8 + j] = colors[index].blue  8;
+}
+}
+break;
+case 16:
+for (i = 0; i  numColors; i++) {
+index = indices[i];
+
+if (index = 31) {
+for (j = 0; j  8; j++) {
+lut_r[index * 8 + j] = colors[index].red  8;
+lut_b[index * 8 + j] = colors[index].blue  8;
+}
+}
+
+for (j = 0; j  4; j++)
+lut_g[index * 4 + j] = colors[index].green  8;
+}
+break;
+default:
+for (i = 0; i  numColors; i++) {
+index = indices[i];
+lut_r[index] = colors[index].red  8;
+lut_g[index] = colors[index].green  8;
+lut_b[index] = colors[index].blue  8;
+}
+break;
+}
+
+/* Make the change through RandR */
+#ifdef RANDR_12_INTERFACE
+RRCrtcGammaSet(crtc-randr_crtc, lut_r, lut_g, lut_b);
+#else /*RANDR_12_INTERFACE*/
+crtc-funcs-gamma_set(crtc, lut_r, lut_g, lut_b, 256);
+#endif
+}
+}
+
 static void *
 msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode,
   CARD32 *size, void *closure)
@@ -716,7 +773,12 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, 
char **argv)
return FALSE;
 
 if (!miCreateDefColormap(pScreen))
-   return FALSE;
+return FALSE;
+
+if (!xf86HandleColormaps(pScreen, 256, 8, LoadPalette, NULL,
+ CMAP_RELOAD_ON_MODE_SWITCH
+ | CMAP_PALETTED_TRUECOLOR))
+return FALSE;
 
 xf86DPMSInit(pScreen, xf86DPMSSet, 0);
 
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 7fa933a..d1da19a 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -1134,89 +1132,6 @@ Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, 
drmmode_ptr drmmode)
return TRUE;
 }
 
-static void drmmode_load_palette(ScrnInfoPtr pScrn, int numColors,
- int *indices, LOCO *colors, VisualPtr pVisual)
-{
-xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-uint16_t   lut_r[256], lut_g[256], lut_b[256];
-int index, j, i;
-int c;
-
-for (c = 0; c  xf86_config-num_crtc; c++) {
-xf86CrtcPtr crtc = xf86_config-crtc[c];
-   drmmode_crtc_private_ptr drmmode_crtc = crtc-driver_private;
-
-for (i = 0 ; i  256; i++) {
-lut_r[i] = drmmode_crtc-lut_r[i]  6;
-lut_g[i] = drmmode_crtc-lut_g[i]  6;
-lut_b[i] = drmmode_crtc-lut_b[i]  6;
-}
-
-switch(pScrn-depth) {
-case 15:
-for (i = 0; i  numColors; i++) {
-index = indices[i];
-for (j = 0; j  8; j++) {
-lut_r[index * 8 + j] = colors[index].red  6;
-lut_g[index * 8 + j] = colors[index].green  6;
-lut_b[index * 8 + j] = colors[index].blue  6;
-}
-}
- break;
- case 16:
- for (i = 0; i  numColors; i++) {
- index = indices[i];
-
-  if (i = 31) {
-  for (j = 0; j  8; j++) {
-  lut_r[index * 8 + j] = colors[index].red  6;
-  lut_b[index * 8 + j] = colors[index].blue  6;
-  }
-  }
-
-  for (j = 0; j  4; j++) {
-  lut_g[index * 4 + j] = colors[index].green  6

Kernel Display and Video API Consolidation mini-summit at ELC 2012 - Notes

2012-02-22 Thread James Simmons

> > Ensuring that nothing prevents the switch to fbcon and displaying the
> > panic message is the reason why we haven't felt inclined to accelerate
> > fbcon - it just gets messy for no real gain.
> 
> and when doing 2d accel on a 3d core..  it basically amounts to
> putting a shader compiler in the kernel.   Wh!

Yikes. I'm not suggesting that. In fact I doubt accelerating the imageblit
would be worthy it due to the small size of the images being pushed. The 
real cost is the copyarea which is used for scrolling when no panning is 
available. 

> > For example: https://bugs.freedesktop.org/attachment.cgi?id=48933
> > which doesn't handle flushing of pending updates via the GPU when
> > writing with the CPU during interrupts (i.e. a panic).
> > -Chris
> >
> > --
> > Chris Wilson, Intel Open Source Technology Centre
> --
> To unsubscribe from this list: send the line "unsubscribe linux-fbdev" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


Kernel Display and Video API Consolidation mini-summit at ELC 2012 - Notes

2012-02-22 Thread James Simmons

> > Imo we should ditch this - fb accel doesn't belong into the kernel. Even
> > on hw that still has a blitter for easy 2d accel without a complete 3d
> > state setup necessary, it's not worth it. Chris Wilson from our team once
> > played around with implementing fb accel in the kernel (i915 hw still has
> > a blitter engine in the latest generations). He quickly noticed that to
> > have decent speed, competitive with s/w rendering by the cpu he needs the
> > entire batch and buffer management stuff from userspace. And to really
> > beat the cpu, you need even more magic.
> > 
> > If you want fast 2d accel, use something like cairo.
> 
> Our conclusion on this is that we should not expose an explicit 2D 
> acceleration API at the kernel level. If really needed, hardware 2D 
> acceleration could be implemented as a DRM device to handle memory 
> management, 
> commands ring setup, synchronization, ... but I'm not even sure if that's 
> worth it. I might not have conveyed it well in my notes.

Fbcon scrolling at be painful at HD or better modes. Fbcon needs 3 
possible accels; copyarea, imageblit, and fillrect. The first two could be 
hooked from the TTM layer. Its something I plan to experiment to see if 
its worth it.


Re: Kernel Display and Video API Consolidation mini-summit at ELC 2012 - Notes

2012-02-22 Thread James Simmons

  Imo we should ditch this - fb accel doesn't belong into the kernel. Even
  on hw that still has a blitter for easy 2d accel without a complete 3d
  state setup necessary, it's not worth it. Chris Wilson from our team once
  played around with implementing fb accel in the kernel (i915 hw still has
  a blitter engine in the latest generations). He quickly noticed that to
  have decent speed, competitive with s/w rendering by the cpu he needs the
  entire batch and buffer management stuff from userspace. And to really
  beat the cpu, you need even more magic.
  
  If you want fast 2d accel, use something like cairo.
 
 Our conclusion on this is that we should not expose an explicit 2D 
 acceleration API at the kernel level. If really needed, hardware 2D 
 acceleration could be implemented as a DRM device to handle memory 
 management, 
 commands ring setup, synchronization, ... but I'm not even sure if that's 
 worth it. I might not have conveyed it well in my notes.

Fbcon scrolling at be painful at HD or better modes. Fbcon needs 3 
possible accels; copyarea, imageblit, and fillrect. The first two could be 
hooked from the TTM layer. Its something I plan to experiment to see if 
its worth it.
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: Kernel Display and Video API Consolidation mini-summit at ELC 2012 - Notes

2012-02-22 Thread James Simmons

  Ensuring that nothing prevents the switch to fbcon and displaying the
  panic message is the reason why we haven't felt inclined to accelerate
  fbcon - it just gets messy for no real gain.
 
 and when doing 2d accel on a 3d core..  it basically amounts to
 putting a shader compiler in the kernel.   Wh!

Yikes. I'm not suggesting that. In fact I doubt accelerating the imageblit
would be worthy it due to the small size of the images being pushed. The 
real cost is the copyarea which is used for scrolling when no panning is 
available. 

  For example: https://bugs.freedesktop.org/attachment.cgi?id=48933
  which doesn't handle flushing of pending updates via the GPU when
  writing with the CPU during interrupts (i.e. a panic).
  -Chris
 
  --
  Chris Wilson, Intel Open Source Technology Centre
 --
 To unsubscribe from this list: send the line unsubscribe linux-fbdev in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
 
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


TTM and AGP conflicts

2012-01-06 Thread James Simmons

> >> You can achieve what you want by either adding a new domain so you would 
> >> have
> >> system, vram, agp, pcidma and object can be bound to one and only one. Or 
> >> you
> >> can hack your own agp ttm backend that could bind bo to agp or pci or
> >> both at the same time depending on what you want to achieve.
> >
> > The question is how does one know which domain you want in tt_create.
> > Currenty drivers are using there dev_priv but if you have have more than
> > one option available how does one choose? Would you be okay with passing
> > in a domain flag?
> >
> 
> Well i agree that something would be usefull there so the driver know
> which bind/unbind function it should use. Thomas i would prefer
> passing the bo to the tt_create callback but a flag is the minimum we
> need.

We can discuss this after the merge widow. Jerome your patch does fix a 
regression whereas my proposal is a enhancement. 


Re: TTM and AGP conflicts

2012-01-06 Thread James Simmons

  You can achieve what you want by either adding a new domain so you would 
  have
  system, vram, agp, pcidma and object can be bound to one and only one. Or 
  you
  can hack your own agp ttm backend that could bind bo to agp or pci or
  both at the same time depending on what you want to achieve.
 
  The question is how does one know which domain you want in tt_create.
  Currenty drivers are using there dev_priv but if you have have more than
  one option available how does one choose? Would you be okay with passing
  in a domain flag?
 
 
 Well i agree that something would be usefull there so the driver know
 which bind/unbind function it should use. Thomas i would prefer
 passing the bo to the tt_create callback but a flag is the minimum we
 need.

We can discuss this after the merge widow. Jerome your patch does fix a 
regression whereas my proposal is a enhancement. 
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


TTM and AGP conflicts

2012-01-04 Thread James Simmons

> >> Attached is patch to fix this, so sorry about that, i must have lost my
> >> agp change along the way when working on the patchset. This patch is not
> >> extensively tested, i will do more testing tomorrow on more gpu, might
> >> even found an nvidia agp i can try. Again sorry for breaking this.
> >
> > Thanks for the fix up. I was wondering if this purposed change could be
> > done instead. Its the same as your fix up except that you pass in the
> > ttm_buffer_object for tt_create. The reason is I really like to have the
> > ability to have more than one back end to grab a bunch pf pages from.
> > Currently its AGP or something else. On some of my embedded devices the
> > AGP space is not very large and can be exhausted very quickly. Those
> > embedded devices have DMA engines I could use instead.
> 
> This change violate the layer separation ttm wish to preserve see :
> http://www.mail-archive.com/dri-devel at lists.freedesktop.org/msg16443.html
> 
> You can achieve what you want by either adding a new domain so you would have
> system, vram, agp, pcidma and object can be bound to one and only one. Or you
> can hack your own agp ttm backend that could bind bo to agp or pci or
> both at the same time depending on what you want to achieve.

The question is how does one know which domain you want in tt_create. 
Currenty drivers are using there dev_priv but if you have have more than 
one option available how does one choose? Would you be okay with passing 
in a domain flag?



TTM and AGP conflicts

2012-01-04 Thread James Simmons

> Attached is patch to fix this, so sorry about that, i must have lost my
> agp change along the way when working on the patchset. This patch is not
> extensively tested, i will do more testing tomorrow on more gpu, might
> even found an nvidia agp i can try. Again sorry for breaking this.

Thanks for the fix up. I was wondering if this purposed change could be 
done instead. Its the same as your fix up except that you pass in the 
ttm_buffer_object for tt_create. The reason is I really like to have the 
ability to have more than one back end to grab a bunch pf pages from. 
Currently its AGP or something else. On some of my embedded devices the 
AGP space is not very large and can be exhausted very quickly. Those 
embedded devices have DMA engines I could use instead.

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c 
b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 8cf4a48..58ad508 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -349,10 +349,11 @@ nouveau_bo_wr32(struct nouveau_bo *nvbo, unsigned index, 
u32 val)
 }

 static struct ttm_tt *
-nouveau_ttm_tt_create(struct ttm_bo_device *bdev,
+nouveau_ttm_tt_create(struct ttm_buffer_object *bo,
  unsigned long size, uint32_t page_flags,
  struct page *dummy_read_page)
 {
+   struct ttm_bo_device *bdev = bo->bdev;
struct drm_nouveau_private *dev_priv = nouveau_bdev(bdev);
struct drm_device *dev = dev_priv->dev;

@@ -1066,6 +1067,12 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)
dev_priv = nouveau_bdev(ttm->bdev);
dev = dev_priv->dev;

+#if __OS_HAS_AGP
+   if (dev_priv->gart_info.type == NOUVEAU_GART_AGP) {
+   return ttm_agp_tt_populate(ttm);
+   }
+#endif
+
 #ifdef CONFIG_SWIOTLB
if (swiotlb_nr_tbl()) {
return ttm_dma_populate((void *)ttm, dev->dev);
@@ -1105,6 +1112,13 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
dev_priv = nouveau_bdev(ttm->bdev);
dev = dev_priv->dev;

+#if __OS_HAS_AGP
+   if (dev_priv->gart_info.type == NOUVEAU_GART_AGP) {
+   ttm_agp_tt_unpopulate(ttm);
+   return;
+   }
+#endif
+
 #ifdef CONFIG_SWIOTLB
if (swiotlb_nr_tbl()) {
ttm_dma_unpopulate((void *)ttm, dev->dev);
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c 
b/drivers/gpu/drm/radeon/radeon_ttm.c
index b0ebaf8..655f8e9 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -549,10 +549,12 @@ static struct ttm_backend_func radeon_backend_func = {
.destroy = _ttm_backend_destroy,
 };

-struct ttm_tt *radeon_ttm_tt_create(struct ttm_bo_device *bdev,
-   unsigned long size, uint32_t page_flags,
+struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo,
+   unsigned long size,
+   uint32_t page_flags,
struct page *dummy_read_page)
 {
+   struct ttm_bo_device *bdev = bo->bdev;
struct radeon_device *rdev;
struct radeon_ttm_tt *gtt;

@@ -588,6 +590,11 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm)
return 0;

rdev = radeon_get_rdev(ttm->bdev);
+#if __OS_HAS_AGP
+   if (rdev->flags & RADEON_IS_AGP) {
+   return ttm_agp_tt_populate(ttm);
+   }
+#endif

 #ifdef CONFIG_SWIOTLB
if (swiotlb_nr_tbl()) {
@@ -624,6 +631,12 @@ static void radeon_ttm_tt_unpopulate(struct ttm_tt *ttm)
unsigned i;

rdev = radeon_get_rdev(ttm->bdev);
+#if __OS_HAS_AGP
+   if (rdev->flags & RADEON_IS_AGP) {
+   ttm_agp_tt_unpopulate(ttm);
+   return;
+   }
+#endif

 #ifdef CONFIG_SWIOTLB
if (swiotlb_nr_tbl()) {
diff --git a/drivers/gpu/drm/ttm/ttm_agp_backend.c 
b/drivers/gpu/drm/ttm/ttm_agp_backend.c
index 14ebd36..747c141 100644
--- a/drivers/gpu/drm/ttm/ttm_agp_backend.c
+++ b/drivers/gpu/drm/ttm/ttm_agp_backend.c
@@ -31,6 +31,7 @@

 #include "ttm/ttm_module.h"
 #include "ttm/ttm_bo_driver.h"
+#include "ttm/ttm_page_alloc.h"
 #ifdef TTM_HAS_AGP
 #include "ttm/ttm_placement.h"
 #include 
@@ -97,6 +98,7 @@ static void ttm_agp_destroy(struct ttm_tt *ttm)

if (agp_be->mem)
ttm_agp_unbind(ttm);
+   ttm_tt_fini(ttm);
kfree(agp_be);
 }

@@ -129,4 +131,19 @@ struct ttm_tt *ttm_agp_tt_create(struct ttm_bo_device 
*bdev,
 }
 EXPORT_SYMBOL(ttm_agp_tt_create);

+int ttm_agp_tt_populate(struct ttm_tt *ttm)
+{
+   if (ttm->state != tt_unpopulated)
+   return 0;
+
+   return ttm_pool_populate(ttm);
+}
+EXPORT_SYMBOL(ttm_agp_tt_populate);
+
+void ttm_agp_tt_unpopulate(struct ttm_tt *ttm)
+{
+   ttm_pool_unpopulate(ttm);
+}
+EXPORT_SYMBOL(ttm_agp_tt_unpopulate);
+
 #endif
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 2f0eab6..1adc149 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ 

Re: TTM and AGP conflicts

2012-01-04 Thread James Simmons

 Attached is patch to fix this, so sorry about that, i must have lost my
 agp change along the way when working on the patchset. This patch is not
 extensively tested, i will do more testing tomorrow on more gpu, might
 even found an nvidia agp i can try. Again sorry for breaking this.

Thanks for the fix up. I was wondering if this purposed change could be 
done instead. Its the same as your fix up except that you pass in the 
ttm_buffer_object for tt_create. The reason is I really like to have the 
ability to have more than one back end to grab a bunch pf pages from. 
Currently its AGP or something else. On some of my embedded devices the 
AGP space is not very large and can be exhausted very quickly. Those 
embedded devices have DMA engines I could use instead.

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c 
b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 8cf4a48..58ad508 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -349,10 +349,11 @@ nouveau_bo_wr32(struct nouveau_bo *nvbo, unsigned index, 
u32 val)
 }
 
 static struct ttm_tt *
-nouveau_ttm_tt_create(struct ttm_bo_device *bdev,
+nouveau_ttm_tt_create(struct ttm_buffer_object *bo,
  unsigned long size, uint32_t page_flags,
  struct page *dummy_read_page)
 {
+   struct ttm_bo_device *bdev = bo-bdev;
struct drm_nouveau_private *dev_priv = nouveau_bdev(bdev);
struct drm_device *dev = dev_priv-dev;
 
@@ -1066,6 +1067,12 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)
dev_priv = nouveau_bdev(ttm-bdev);
dev = dev_priv-dev;
 
+#if __OS_HAS_AGP
+   if (dev_priv-gart_info.type == NOUVEAU_GART_AGP) {
+   return ttm_agp_tt_populate(ttm);
+   }
+#endif
+
 #ifdef CONFIG_SWIOTLB
if (swiotlb_nr_tbl()) {
return ttm_dma_populate((void *)ttm, dev-dev);
@@ -1105,6 +1112,13 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
dev_priv = nouveau_bdev(ttm-bdev);
dev = dev_priv-dev;
 
+#if __OS_HAS_AGP
+   if (dev_priv-gart_info.type == NOUVEAU_GART_AGP) {
+   ttm_agp_tt_unpopulate(ttm);
+   return;
+   }
+#endif
+
 #ifdef CONFIG_SWIOTLB
if (swiotlb_nr_tbl()) {
ttm_dma_unpopulate((void *)ttm, dev-dev);
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c 
b/drivers/gpu/drm/radeon/radeon_ttm.c
index b0ebaf8..655f8e9 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -549,10 +549,12 @@ static struct ttm_backend_func radeon_backend_func = {
.destroy = radeon_ttm_backend_destroy,
 };
 
-struct ttm_tt *radeon_ttm_tt_create(struct ttm_bo_device *bdev,
-   unsigned long size, uint32_t page_flags,
+struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo,
+   unsigned long size,
+   uint32_t page_flags,
struct page *dummy_read_page)
 {
+   struct ttm_bo_device *bdev = bo-bdev;
struct radeon_device *rdev;
struct radeon_ttm_tt *gtt;
 
@@ -588,6 +590,11 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm)
return 0;
 
rdev = radeon_get_rdev(ttm-bdev);
+#if __OS_HAS_AGP
+   if (rdev-flags  RADEON_IS_AGP) {
+   return ttm_agp_tt_populate(ttm);
+   }
+#endif
 
 #ifdef CONFIG_SWIOTLB
if (swiotlb_nr_tbl()) {
@@ -624,6 +631,12 @@ static void radeon_ttm_tt_unpopulate(struct ttm_tt *ttm)
unsigned i;
 
rdev = radeon_get_rdev(ttm-bdev);
+#if __OS_HAS_AGP
+   if (rdev-flags  RADEON_IS_AGP) {
+   ttm_agp_tt_unpopulate(ttm);
+   return;
+   }
+#endif
 
 #ifdef CONFIG_SWIOTLB
if (swiotlb_nr_tbl()) {
diff --git a/drivers/gpu/drm/ttm/ttm_agp_backend.c 
b/drivers/gpu/drm/ttm/ttm_agp_backend.c
index 14ebd36..747c141 100644
--- a/drivers/gpu/drm/ttm/ttm_agp_backend.c
+++ b/drivers/gpu/drm/ttm/ttm_agp_backend.c
@@ -31,6 +31,7 @@
 
 #include ttm/ttm_module.h
 #include ttm/ttm_bo_driver.h
+#include ttm/ttm_page_alloc.h
 #ifdef TTM_HAS_AGP
 #include ttm/ttm_placement.h
 #include linux/agp_backend.h
@@ -97,6 +98,7 @@ static void ttm_agp_destroy(struct ttm_tt *ttm)
 
if (agp_be-mem)
ttm_agp_unbind(ttm);
+   ttm_tt_fini(ttm);
kfree(agp_be);
 }
 
@@ -129,4 +131,19 @@ struct ttm_tt *ttm_agp_tt_create(struct ttm_bo_device 
*bdev,
 }
 EXPORT_SYMBOL(ttm_agp_tt_create);
 
+int ttm_agp_tt_populate(struct ttm_tt *ttm)
+{
+   if (ttm-state != tt_unpopulated)
+   return 0;
+
+   return ttm_pool_populate(ttm);
+}
+EXPORT_SYMBOL(ttm_agp_tt_populate);
+
+void ttm_agp_tt_unpopulate(struct ttm_tt *ttm)
+{
+   ttm_pool_unpopulate(ttm);
+}
+EXPORT_SYMBOL(ttm_agp_tt_unpopulate);
+
 #endif
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 2f0eab6..1adc149 100644
--- 

Re: TTM and AGP conflicts

2012-01-04 Thread James Simmons

  Attached is patch to fix this, so sorry about that, i must have lost my
  agp change along the way when working on the patchset. This patch is not
  extensively tested, i will do more testing tomorrow on more gpu, might
  even found an nvidia agp i can try. Again sorry for breaking this.
 
  Thanks for the fix up. I was wondering if this purposed change could be
  done instead. Its the same as your fix up except that you pass in the
  ttm_buffer_object for tt_create. The reason is I really like to have the
  ability to have more than one back end to grab a bunch pf pages from.
  Currently its AGP or something else. On some of my embedded devices the
  AGP space is not very large and can be exhausted very quickly. Those
  embedded devices have DMA engines I could use instead.
 
 This change violate the layer separation ttm wish to preserve see :
 http://www.mail-archive.com/dri-devel@lists.freedesktop.org/msg16443.html
 
 You can achieve what you want by either adding a new domain so you would have
 system, vram, agp, pcidma and object can be bound to one and only one. Or you
 can hack your own agp ttm backend that could bind bo to agp or pci or
 both at the same time depending on what you want to achieve.

The question is how does one know which domain you want in tt_create. 
Currenty drivers are using there dev_priv but if you have have more than 
one option available how does one choose? Would you be okay with passing 
in a domain flag?

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


[PULL] remove drm_sman and some i815 fixes

2011-12-23 Thread James Simmons

> > > > Last attempt at your branch still had problem. Start I didn't have time 
> > > > track down the exact issue. I'm cloning the below branch and will test 
> > > > it.
> > > > Thanks for cleanup.
> > > 
> > > Jakob Bornecrantz quickly tested my attempt at fixing the deadlock you've
> > > reported and noticed that the X server fails to start up (and that the
> > > kernel hangs). Is that the same you're seeing?
> > 
> > What was just merged to drm-next works fine. Its the reclaim buffer 
> > patches that cause the problem. In my case the X server starts but I get  
> > a blank screen. I have full debug on so this is what happens.
> 
> Thanks for testing and gathering the logs.
> 
> Judging from the dmesg you've attached the via driver opens and closes the
> via drm node at least twice while starting X. Which explains why things
> blow up for you and Jakob already at startup. But ...

> Can you please retest with that and again grab the dmesg with full
> logging? Jakob reported that this still blows up, so there's a problem
> left somewhere. But I've rechecked the patches and couldn't see it.

Done. Using your latest branch.

Initializing cgroup subsys cpu
Linux version 3.2.0-rc6-openchrome+ (jsimmons at debian) (gcc version 4.6.2 
(Debian 4.6.2-7) ) #42 SMP Fri Dec 23 10:16:38 EST 2011
Command line: BOOT_IMAGE=/boot/vmlinuz-test 
root=UUID=2539cb3b-47b9-47fc-81c1-97dabc51b2b2 ro drm.debug=255
BIOS-provided physical RAM map:
 BIOS-e820:  - 0009f400 (usable)
 BIOS-e820: 0009f400 - 000a (reserved)
 BIOS-e820: 000f - 0010 (reserved)
 BIOS-e820: 0010 - 7bef (usable)
 BIOS-e820: 7bef - 7bef3000 (ACPI NVS)
 BIOS-e820: 7bef3000 - 7bf0 (ACPI data)
 BIOS-e820: fec0 - 0001 (reserved)
NX (Execute Disable) protection: active
DMI 2.3 present.
DMI: MICRO-STAR INTERNATIONAL CO., LTD MS-7312/MS-7312, BIOS V1.2 01/25/2007
e820 update range:  - 0001 (usable) ==> (reserved)
e820 remove range: 000a - 0010 (usable)
AGP bridge at 00:00:00
Aperture from AGP @ e800 old size 32 MB
Aperture from AGP @ e800 size 128 MB (APSIZE f20)
last_pfn = 0x7bef0 max_arch_pfn = 0x4
MTRR default type: uncachable
MTRR fixed ranges enabled:
  0-9 write-back
  A-B uncachable
  C-C7FFF write-protect
  C8000-CBFFF uncachable
  CC000-D3FFF write-back
  D4000-F uncachable
MTRR variable ranges enabled:
  0 base 00 mask FFC000 write-back
  1 base 004000 mask FFE000 write-back
  2 base 006000 mask FFF000 write-back
  3 base 007000 mask FFF800 write-back
  4 base 007800 mask FFFC00 write-back
  5 base 007BF0 mask F0 uncachable
  6 base 00E800 mask FFF800 write-combining
  7 disabled
x86 PAT enabled: cpu 0, old 0x7040600070406, new 0x7010600070106
initial memory mapped : 0 - 2000
Base memory trampoline at [8809d000] 9d000 size 8192
init_memory_mapping: -7bef
 00 - 007be0 page 2M
 007be0 - 007bef page 4k
kernel direct mapping tables up to 7bef @ 1fffc000-2000
RAMDISK: 37aba000 - 37d55000
ACPI: RSDP 000f78c0 00014 (v00 VIAK8M)
ACPI: RSDT 7bef3040 0002C (v01 VIAK8M AWRDACPI 42302E31 AWRD )
ACPI: FACP 7bef30c0 00074 (v01 VIAK8M AWRDACPI 42302E31 AWRD )
ACPI: DSDT 7bef3180 05396 (v01 VIAK8M AWRDACPI 1000 MSFT 010E)
ACPI: FACS 7bef 00040
ACPI: APIC 7bef8580 00068 (v01 VIAK8M AWRDACPI 42302E31 AWRD )
ACPI: Local APIC address 0xfee0
 [ea00-ea0001bf] PMD -> [88007960-88007b1f] 
on node 0
Zone PFN ranges:
  DMA  0x0010 -> 0x1000
  DMA320x1000 -> 0x0010
  Normal   empty
Movable zone start PFN for each node
early_node_map[2] active PFN ranges
0: 0x0010 -> 0x009f
0: 0x0100 -> 0x0007bef0
On node 0 totalpages: 507519
  DMA zone: 56 pages used for memmap
  DMA zone: 2 pages reserved
  DMA zone: 3925 pages, LIFO batch:0
  DMA32 zone: 6885 pages used for memmap
  DMA32 zone: 496651 pages, LIFO batch:31
Detected use of extended apic ids on hypertransport bus
ACPI: PM-Timer IO Port: 0x4008
ACPI: Local APIC address 0xfee0
ACPI: LAPIC (acpi_id[0x00] lapic_id[0x00] enabled)
ACPI: LAPIC (acpi_id[0x01] lapic_id[0x01] enabled)
ACPI: LAPIC_NMI (acpi_id[0x00] high edge lint[0x1])
ACPI: LAPIC_NMI (acpi_id[0x01] high edge lint[0x1])
ACPI: IOAPIC (id[0x02] address[0xfec0] gsi_base[0])
IOAPIC[0]: apic_id 2, version 3, address 0xfec0, GSI 0-23
ACPI: INT_SRC_OVR (bus 0 bus_irq 0 global_irq 2 dfl dfl)
ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 low level)
ACPI: IRQ0 used by override.
ACPI: IRQ2 used by override.
ACPI: IRQ9 used by override.
Using ACPI (MADT) for SMP configuration information
SMP: Allowing 2 CPUs, 0 hotplug CPUs

TTM and AGP conflicts

2011-12-23 Thread James Simmons

> > Hi!
> >
> > ? ? ? ?I updated the openchrome tree and while testing on the AGP system
> > discovered some interesting problems with the new TTM changes. The
> > problems center around the ttm_tt_[un]populate which I modeled after the
> > radeon and nouveau driver.
> > ? ? ? ?First problem I noticed was on a AGP system that my ttm_tt_populate
> > function would oops. Tracking it down I found the problem was the
> > ttm_agp_tt_create calls ttm_tt_init instead of ttm_dma_tt_init so once my
> > ttm_tt_populate function would attempt to touch the dma_address it would
> > oops. The second issue is the assumption of the cast for struct ttm_tt in
> > both the populate and unpopulate function. For the AGP case the proper
> > case would be to ttm_agp_backend.
> > ? ? ? ?At this point my assumption is the ttm_bo_move function has to be
> > rewritten to handle the AGP case to avoid calling ttm_tt_bind and in all
> > cases ttm_tt_bind needs to be avoided. Looking at the radeon and nouveau
> > drivers I don't see that testing happening. Am I just missing something?
> 
> Happens on AGP radeons as well:
> https://bugs.freedesktop.org/show_bug.cgi?id=43719

So I'm not crazy, so this needs to be fixed. Here is what my 
understanding of the TTM layer is. My impression is that struct ttm_bo_driver
handles multiple domains, AGP, pcie etc and in each method you have to 
handle each specific domain you support. Also *move gives the impression of
moving between these different domains. 
Where as for struct ttm_backend_func was more for allocating from
a specific domain. Also I never saw a clear way to handle multiple backends. 
For example my AGP systems can also do pci dma as well. 


Re: [PULL] remove drm_sman and some i815 fixes

2011-12-23 Thread James Simmons

Last attempt at your branch still had problem. Start I didn't have time 
track down the exact issue. I'm cloning the below branch and will test 
it.
Thanks for cleanup.
   
   Jakob Bornecrantz quickly tested my attempt at fixing the deadlock you've
   reported and noticed that the X server fails to start up (and that the
   kernel hangs). Is that the same you're seeing?
  
  What was just merged to drm-next works fine. Its the reclaim buffer 
  patches that cause the problem. In my case the X server starts but I get  
  a blank screen. I have full debug on so this is what happens.
 
 Thanks for testing and gathering the logs.
 
 Judging from the dmesg you've attached the via driver opens and closes the
 via drm node at least twice while starting X. Which explains why things
 blow up for you and Jakob already at startup. But ...

 Can you please retest with that and again grab the dmesg with full
 logging? Jakob reported that this still blows up, so there's a problem
 left somewhere. But I've rechecked the patches and couldn't see it.

Done. Using your latest branch.

Initializing cgroup subsys cpu
Linux version 3.2.0-rc6-openchrome+ (jsimmons@debian) (gcc version 4.6.2 
(Debian 4.6.2-7) ) #42 SMP Fri Dec 23 10:16:38 EST 2011
Command line: BOOT_IMAGE=/boot/vmlinuz-test 
root=UUID=2539cb3b-47b9-47fc-81c1-97dabc51b2b2 ro drm.debug=255
BIOS-provided physical RAM map:
 BIOS-e820:  - 0009f400 (usable)
 BIOS-e820: 0009f400 - 000a (reserved)
 BIOS-e820: 000f - 0010 (reserved)
 BIOS-e820: 0010 - 7bef (usable)
 BIOS-e820: 7bef - 7bef3000 (ACPI NVS)
 BIOS-e820: 7bef3000 - 7bf0 (ACPI data)
 BIOS-e820: fec0 - 0001 (reserved)
NX (Execute Disable) protection: active
DMI 2.3 present.
DMI: MICRO-STAR INTERNATIONAL CO., LTD MS-7312/MS-7312, BIOS V1.2 01/25/2007
e820 update range:  - 0001 (usable) == (reserved)
e820 remove range: 000a - 0010 (usable)
AGP bridge at 00:00:00
Aperture from AGP @ e800 old size 32 MB
Aperture from AGP @ e800 size 128 MB (APSIZE f20)
last_pfn = 0x7bef0 max_arch_pfn = 0x4
MTRR default type: uncachable
MTRR fixed ranges enabled:
  0-9 write-back
  A-B uncachable
  C-C7FFF write-protect
  C8000-CBFFF uncachable
  CC000-D3FFF write-back
  D4000-F uncachable
MTRR variable ranges enabled:
  0 base 00 mask FFC000 write-back
  1 base 004000 mask FFE000 write-back
  2 base 006000 mask FFF000 write-back
  3 base 007000 mask FFF800 write-back
  4 base 007800 mask FFFC00 write-back
  5 base 007BF0 mask F0 uncachable
  6 base 00E800 mask FFF800 write-combining
  7 disabled
x86 PAT enabled: cpu 0, old 0x7040600070406, new 0x7010600070106
initial memory mapped : 0 - 2000
Base memory trampoline at [8809d000] 9d000 size 8192
init_memory_mapping: -7bef
 00 - 007be0 page 2M
 007be0 - 007bef page 4k
kernel direct mapping tables up to 7bef @ 1fffc000-2000
RAMDISK: 37aba000 - 37d55000
ACPI: RSDP 000f78c0 00014 (v00 VIAK8M)
ACPI: RSDT 7bef3040 0002C (v01 VIAK8M AWRDACPI 42302E31 AWRD )
ACPI: FACP 7bef30c0 00074 (v01 VIAK8M AWRDACPI 42302E31 AWRD )
ACPI: DSDT 7bef3180 05396 (v01 VIAK8M AWRDACPI 1000 MSFT 010E)
ACPI: FACS 7bef 00040
ACPI: APIC 7bef8580 00068 (v01 VIAK8M AWRDACPI 42302E31 AWRD )
ACPI: Local APIC address 0xfee0
 [ea00-ea0001bf] PMD - [88007960-88007b1f] 
on node 0
Zone PFN ranges:
  DMA  0x0010 - 0x1000
  DMA320x1000 - 0x0010
  Normal   empty
Movable zone start PFN for each node
early_node_map[2] active PFN ranges
0: 0x0010 - 0x009f
0: 0x0100 - 0x0007bef0
On node 0 totalpages: 507519
  DMA zone: 56 pages used for memmap
  DMA zone: 2 pages reserved
  DMA zone: 3925 pages, LIFO batch:0
  DMA32 zone: 6885 pages used for memmap
  DMA32 zone: 496651 pages, LIFO batch:31
Detected use of extended apic ids on hypertransport bus
ACPI: PM-Timer IO Port: 0x4008
ACPI: Local APIC address 0xfee0
ACPI: LAPIC (acpi_id[0x00] lapic_id[0x00] enabled)
ACPI: LAPIC (acpi_id[0x01] lapic_id[0x01] enabled)
ACPI: LAPIC_NMI (acpi_id[0x00] high edge lint[0x1])
ACPI: LAPIC_NMI (acpi_id[0x01] high edge lint[0x1])
ACPI: IOAPIC (id[0x02] address[0xfec0] gsi_base[0])
IOAPIC[0]: apic_id 2, version 3, address 0xfec0, GSI 0-23
ACPI: INT_SRC_OVR (bus 0 bus_irq 0 global_irq 2 dfl dfl)
ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 low level)
ACPI: IRQ0 used by override.
ACPI: IRQ2 used by override.
ACPI: IRQ9 used by override.
Using ACPI (MADT) for SMP configuration information
SMP: Allowing 2 CPUs, 0 hotplug CPUs
nr_irqs_gsi: 40
Allocating PCI resources starting at 7bf0 

[PULL] remove drm_sman and some i815 fixes

2011-12-22 Thread James Simmons

> > > Hi Dave,
> > > 
> > > I've failed to correctly fix the via hang in the reclaim buffers rework
> > > till now, so I'm only submitting the drm_sman removal of my drm cruft
> > > removal series.
> > 
> > Last attempt at your branch still had problem. Start I didn't have time 
> > track down the exact issue. I'm cloning the below branch and will test it.
> > Thanks for cleanup.
> 
> Jakob Bornecrantz quickly tested my attempt at fixing the deadlock you've
> reported and noticed that the X server fails to start up (and that the
> kernel hangs). Is that the same you're seeing?

What was just merged to drm-next works fine. Its the reclaim buffer 
patches that cause the problem. In my case the X server starts but I get  
a blank screen. I have full debug on so this is what happens.

Initializing cgroup subsys cpu
Linux version 3.2.0-rc6-openchrome+ (jsimmons at debian) (gcc version 4.6.2 
(Debian 4.6.2-7) ) #41 SMP Thu Dec 22 17:37:42 EST 2011
Command line: BOOT_IMAGE=/boot/vmlinuz-test 
root=UUID=2539cb3b-47b9-47fc-81c1-97dabc51b2b2 ro drm.debug=255
BIOS-provided physical RAM map:
 BIOS-e820:  - 0009f400 (usable)
 BIOS-e820: 0009f400 - 000a (reserved)
 BIOS-e820: 000f - 0010 (reserved)
 BIOS-e820: 0010 - 7bef (usable)
 BIOS-e820: 7bef - 7bef3000 (ACPI NVS)
 BIOS-e820: 7bef3000 - 7bf0 (ACPI data)
 BIOS-e820: fec0 - 0001 (reserved)
NX (Execute Disable) protection: active
DMI 2.3 present.
DMI: MICRO-STAR INTERNATIONAL CO., LTD MS-7312/MS-7312, BIOS V1.2 01/25/2007
e820 update range:  - 0001 (usable) ==> (reserved)
e820 remove range: 000a - 0010 (usable)
AGP bridge at 00:00:00
Aperture from AGP @ e800 old size 32 MB
Aperture from AGP @ e800 size 128 MB (APSIZE f20)
last_pfn = 0x7bef0 max_arch_pfn = 0x4
MTRR default type: uncachable
MTRR fixed ranges enabled:
  0-9 write-back
  A-B uncachable
  C-C7FFF write-protect
  C8000-CBFFF uncachable
  CC000-D3FFF write-back
  D4000-F uncachable
MTRR variable ranges enabled:
  0 base 00 mask FFC000 write-back
  1 base 004000 mask FFE000 write-back
  2 base 006000 mask FFF000 write-back
  3 base 007000 mask FFF800 write-back
  4 base 007800 mask FFFC00 write-back
  5 base 007BF0 mask F0 uncachable
  6 base 00E800 mask FFF800 write-combining
  7 disabled
x86 PAT enabled: cpu 0, old 0x7040600070406, new 0x7010600070106
initial memory mapped : 0 - 2000
Base memory trampoline at [8809d000] 9d000 size 8192
init_memory_mapping: -7bef
 00 - 007be0 page 2M
 007be0 - 007bef page 4k
kernel direct mapping tables up to 7bef @ 1fffc000-2000
RAMDISK: 37aba000 - 37d55000
ACPI: RSDP 000f78c0 00014 (v00 VIAK8M)
ACPI: RSDT 7bef3040 0002C (v01 VIAK8M AWRDACPI 42302E31 AWRD )
ACPI: FACP 7bef30c0 00074 (v01 VIAK8M AWRDACPI 42302E31 AWRD )
ACPI: DSDT 7bef3180 05396 (v01 VIAK8M AWRDACPI 1000 MSFT 010E)
ACPI: FACS 7bef 00040
ACPI: APIC 7bef8580 00068 (v01 VIAK8M AWRDACPI 42302E31 AWRD )
ACPI: Local APIC address 0xfee0
 [ea00-ea0001bf] PMD -> [88007960-88007b1f] 
on node 0
Zone PFN ranges:
  DMA  0x0010 -> 0x1000
  DMA320x1000 -> 0x0010
  Normal   empty
Movable zone start PFN for each node
early_node_map[2] active PFN ranges
0: 0x0010 -> 0x009f
0: 0x0100 -> 0x0007bef0
On node 0 totalpages: 507519
  DMA zone: 56 pages used for memmap
  DMA zone: 2 pages reserved
  DMA zone: 3925 pages, LIFO batch:0
  DMA32 zone: 6885 pages used for memmap
  DMA32 zone: 496651 pages, LIFO batch:31
Detected use of extended apic ids on hypertransport bus
ACPI: PM-Timer IO Port: 0x4008
ACPI: Local APIC address 0xfee0
ACPI: LAPIC (acpi_id[0x00] lapic_id[0x00] enabled)
ACPI: LAPIC (acpi_id[0x01] lapic_id[0x01] enabled)
ACPI: LAPIC_NMI (acpi_id[0x00] high edge lint[0x1])
ACPI: LAPIC_NMI (acpi_id[0x01] high edge lint[0x1])
ACPI: IOAPIC (id[0x02] address[0xfec0] gsi_base[0])
IOAPIC[0]: apic_id 2, version 3, address 0xfec0, GSI 0-23
ACPI: INT_SRC_OVR (bus 0 bus_irq 0 global_irq 2 dfl dfl)
ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 low level)
ACPI: IRQ0 used by override.
ACPI: IRQ2 used by override.
ACPI: IRQ9 used by override.
Using ACPI (MADT) for SMP configuration information
SMP: Allowing 2 CPUs, 0 hotplug CPUs
nr_irqs_gsi: 40
Allocating PCI resources starting at 7bf0 (gap: 7bf0:82d0)
setup_percpu: NR_CPUS:2 nr_cpumask_bits:2 nr_cpu_ids:2 nr_node_ids:1
PERCPU: Embedded 25 pages/cpu @88007bc0 s70592 r8192 d23616 u1048576
pcpu-alloc: s70592 r8192 d23616 u1048576 alloc=1*2097152
pcpu-alloc: [0] 0 1 
Built 1 zonelists in Zone order, mobility grouping 

TTM and AGP conflicts

2011-12-22 Thread James Simmons

Hi!

I updated the openchrome tree and while testing on the AGP system 
discovered some interesting problems with the new TTM changes. The 
problems center around the ttm_tt_[un]populate which I modeled after the 
radeon and nouveau driver. 
First problem I noticed was on a AGP system that my ttm_tt_populate
function would oops. Tracking it down I found the problem was the 
ttm_agp_tt_create calls ttm_tt_init instead of ttm_dma_tt_init so once my 
ttm_tt_populate function would attempt to touch the dma_address it would 
oops. The second issue is the assumption of the cast for struct ttm_tt in
both the populate and unpopulate function. For the AGP case the proper 
case would be to ttm_agp_backend.
At this point my assumption is the ttm_bo_move function has to be
rewritten to handle the AGP case to avoid calling ttm_tt_bind and in all 
cases ttm_tt_bind needs to be avoided. Looking at the radeon and nouveau 
drivers I don't see that testing happening. Am I just missing something?



[PULL] remove drm_sman and some i815 fixes

2011-12-22 Thread James Simmons

> Hi Dave,
> 
> I've failed to correctly fix the via hang in the reclaim buffers rework
> till now, so I'm only submitting the drm_sman removal of my drm cruft
> removal series.

Last attempt at your branch still had problem. Start I didn't have time 
track down the exact issue. I'm cloning the below branch and will test it.
Thanks for cleanup.

> While beating on this stuff with my i815 I've discovered a preexisting
> use-after free issue in lastclose (which is new compared to what I've
> submitted to dri-devel) and a reclaim buffers locking problem.  Also added
> these two patches.
> 
> Please pull for 3.3.
> 
> Thanks, Daniel
> 
> --
> The following changes since commit 4cf73129cbe001b41be2f8b56f763fbf3acaa4ce:
> 
>   Merge remote-tracking branch 'pfdo/drm-fixes' into drm-core-next 
> (2011-12-21 09:50:56 +)
> 
> are available in the git repository at:
> 
>   git://people.freedesktop.org/~danvet/drm for-airlied
> 
> Daniel Vetter (12):
>   drm/sis: track obj->drm_fd relations in the driver
>   drm/via: track obj->drm_fd relations in the driver
>   drm/sman: kill owner tracking interface functions
>   drm/sman: rip out owner tracking
>   drm/via: track user->memblock mapping with idr
>   drm/sis: track user->memblock mapping with idr
>   drm/sman: kill user_hash_tab
>   drm/via: use drm_mm instead of drm_sman
>   drm/sis: use drm_mm instead of drm_sman
>   drm: kill drm_sman
>   drm/i810: cleanup reclaim_buffers
>   drm/i810: don't acces hw regs in lastclose
> 
>  drivers/gpu/drm/Makefile|2 +-
>  drivers/gpu/drm/drm_sman.c  |  351 
> ---
>  drivers/gpu/drm/i810/i810_dma.c |   19 ++-
>  drivers/gpu/drm/i810/i810_drv.c |1 -
>  drivers/gpu/drm/i810/i810_drv.h |6 +-
>  drivers/gpu/drm/sis/sis_drv.c   |   33 -
>  drivers/gpu/drm/sis/sis_drv.h   |7 +-
>  drivers/gpu/drm/sis/sis_mm.c|  196 +--
>  drivers/gpu/drm/via/via_drv.c   |   25 +++
>  drivers/gpu/drm/via/via_drv.h   |7 +-
>  drivers/gpu/drm/via/via_map.c   |   10 +-
>  drivers/gpu/drm/via/via_mm.c|  132 ++-
>  include/drm/drm_sman.h  |  176 
>  include/drm/sis_drm.h   |4 +
>  include/drm/via_drm.h   |4 +
>  15 files changed, 289 insertions(+), 684 deletions(-)
>  delete mode 100644 drivers/gpu/drm/drm_sman.c
>  delete mode 100644 include/drm/drm_sman.h
> -- 
> Daniel Vetter
> Mail: daniel at ffwll.ch
> Mobile: +41 (0)79 365 57 48
> ___
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
> 


Re: [PULL] remove drm_sman and some i815 fixes

2011-12-22 Thread James Simmons

 Hi Dave,
 
 I've failed to correctly fix the via hang in the reclaim buffers rework
 till now, so I'm only submitting the drm_sman removal of my drm cruft
 removal series.

Last attempt at your branch still had problem. Start I didn't have time 
track down the exact issue. I'm cloning the below branch and will test it.
Thanks for cleanup.
 
 While beating on this stuff with my i815 I've discovered a preexisting
 use-after free issue in lastclose (which is new compared to what I've
 submitted to dri-devel) and a reclaim buffers locking problem.  Also added
 these two patches.
 
 Please pull for 3.3.
 
 Thanks, Daniel
 
 --
 The following changes since commit 4cf73129cbe001b41be2f8b56f763fbf3acaa4ce:
 
   Merge remote-tracking branch 'pfdo/drm-fixes' into drm-core-next 
 (2011-12-21 09:50:56 +)
 
 are available in the git repository at:
 
   git://people.freedesktop.org/~danvet/drm for-airlied
 
 Daniel Vetter (12):
   drm/sis: track obj-drm_fd relations in the driver
   drm/via: track obj-drm_fd relations in the driver
   drm/sman: kill owner tracking interface functions
   drm/sman: rip out owner tracking
   drm/via: track user-memblock mapping with idr
   drm/sis: track user-memblock mapping with idr
   drm/sman: kill user_hash_tab
   drm/via: use drm_mm instead of drm_sman
   drm/sis: use drm_mm instead of drm_sman
   drm: kill drm_sman
   drm/i810: cleanup reclaim_buffers
   drm/i810: don't acces hw regs in lastclose
 
  drivers/gpu/drm/Makefile|2 +-
  drivers/gpu/drm/drm_sman.c  |  351 
 ---
  drivers/gpu/drm/i810/i810_dma.c |   19 ++-
  drivers/gpu/drm/i810/i810_drv.c |1 -
  drivers/gpu/drm/i810/i810_drv.h |6 +-
  drivers/gpu/drm/sis/sis_drv.c   |   33 -
  drivers/gpu/drm/sis/sis_drv.h   |7 +-
  drivers/gpu/drm/sis/sis_mm.c|  196 +--
  drivers/gpu/drm/via/via_drv.c   |   25 +++
  drivers/gpu/drm/via/via_drv.h   |7 +-
  drivers/gpu/drm/via/via_map.c   |   10 +-
  drivers/gpu/drm/via/via_mm.c|  132 ++-
  include/drm/drm_sman.h  |  176 
  include/drm/sis_drm.h   |4 +
  include/drm/via_drm.h   |4 +
  15 files changed, 289 insertions(+), 684 deletions(-)
  delete mode 100644 drivers/gpu/drm/drm_sman.c
  delete mode 100644 include/drm/drm_sman.h
 -- 
 Daniel Vetter
 Mail: dan...@ffwll.ch
 Mobile: +41 (0)79 365 57 48
 ___
 dri-devel mailing list
 dri-devel@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/dri-devel
 
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


TTM and AGP conflicts

2011-12-22 Thread James Simmons

Hi!

I updated the openchrome tree and while testing on the AGP system 
discovered some interesting problems with the new TTM changes. The 
problems center around the ttm_tt_[un]populate which I modeled after the 
radeon and nouveau driver. 
First problem I noticed was on a AGP system that my ttm_tt_populate
function would oops. Tracking it down I found the problem was the 
ttm_agp_tt_create calls ttm_tt_init instead of ttm_dma_tt_init so once my 
ttm_tt_populate function would attempt to touch the dma_address it would 
oops. The second issue is the assumption of the cast for struct ttm_tt in
both the populate and unpopulate function. For the AGP case the proper 
case would be to ttm_agp_backend.
At this point my assumption is the ttm_bo_move function has to be
rewritten to handle the AGP case to avoid calling ttm_tt_bind and in all 
cases ttm_tt_bind needs to be avoided. Looking at the radeon and nouveau 
drivers I don't see that testing happening. Am I just missing something?
  
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PULL] remove drm_sman and some i815 fixes

2011-12-22 Thread James Simmons

   Hi Dave,
   
   I've failed to correctly fix the via hang in the reclaim buffers rework
   till now, so I'm only submitting the drm_sman removal of my drm cruft
   removal series.
  
  Last attempt at your branch still had problem. Start I didn't have time 
  track down the exact issue. I'm cloning the below branch and will test it.
  Thanks for cleanup.
 
 Jakob Bornecrantz quickly tested my attempt at fixing the deadlock you've
 reported and noticed that the X server fails to start up (and that the
 kernel hangs). Is that the same you're seeing?

What was just merged to drm-next works fine. Its the reclaim buffer 
patches that cause the problem. In my case the X server starts but I get  
a blank screen. I have full debug on so this is what happens.

Initializing cgroup subsys cpu
Linux version 3.2.0-rc6-openchrome+ (jsimmons@debian) (gcc version 4.6.2 
(Debian 4.6.2-7) ) #41 SMP Thu Dec 22 17:37:42 EST 2011
Command line: BOOT_IMAGE=/boot/vmlinuz-test 
root=UUID=2539cb3b-47b9-47fc-81c1-97dabc51b2b2 ro drm.debug=255
BIOS-provided physical RAM map:
 BIOS-e820:  - 0009f400 (usable)
 BIOS-e820: 0009f400 - 000a (reserved)
 BIOS-e820: 000f - 0010 (reserved)
 BIOS-e820: 0010 - 7bef (usable)
 BIOS-e820: 7bef - 7bef3000 (ACPI NVS)
 BIOS-e820: 7bef3000 - 7bf0 (ACPI data)
 BIOS-e820: fec0 - 0001 (reserved)
NX (Execute Disable) protection: active
DMI 2.3 present.
DMI: MICRO-STAR INTERNATIONAL CO., LTD MS-7312/MS-7312, BIOS V1.2 01/25/2007
e820 update range:  - 0001 (usable) == (reserved)
e820 remove range: 000a - 0010 (usable)
AGP bridge at 00:00:00
Aperture from AGP @ e800 old size 32 MB
Aperture from AGP @ e800 size 128 MB (APSIZE f20)
last_pfn = 0x7bef0 max_arch_pfn = 0x4
MTRR default type: uncachable
MTRR fixed ranges enabled:
  0-9 write-back
  A-B uncachable
  C-C7FFF write-protect
  C8000-CBFFF uncachable
  CC000-D3FFF write-back
  D4000-F uncachable
MTRR variable ranges enabled:
  0 base 00 mask FFC000 write-back
  1 base 004000 mask FFE000 write-back
  2 base 006000 mask FFF000 write-back
  3 base 007000 mask FFF800 write-back
  4 base 007800 mask FFFC00 write-back
  5 base 007BF0 mask F0 uncachable
  6 base 00E800 mask FFF800 write-combining
  7 disabled
x86 PAT enabled: cpu 0, old 0x7040600070406, new 0x7010600070106
initial memory mapped : 0 - 2000
Base memory trampoline at [8809d000] 9d000 size 8192
init_memory_mapping: -7bef
 00 - 007be0 page 2M
 007be0 - 007bef page 4k
kernel direct mapping tables up to 7bef @ 1fffc000-2000
RAMDISK: 37aba000 - 37d55000
ACPI: RSDP 000f78c0 00014 (v00 VIAK8M)
ACPI: RSDT 7bef3040 0002C (v01 VIAK8M AWRDACPI 42302E31 AWRD )
ACPI: FACP 7bef30c0 00074 (v01 VIAK8M AWRDACPI 42302E31 AWRD )
ACPI: DSDT 7bef3180 05396 (v01 VIAK8M AWRDACPI 1000 MSFT 010E)
ACPI: FACS 7bef 00040
ACPI: APIC 7bef8580 00068 (v01 VIAK8M AWRDACPI 42302E31 AWRD )
ACPI: Local APIC address 0xfee0
 [ea00-ea0001bf] PMD - [88007960-88007b1f] 
on node 0
Zone PFN ranges:
  DMA  0x0010 - 0x1000
  DMA320x1000 - 0x0010
  Normal   empty
Movable zone start PFN for each node
early_node_map[2] active PFN ranges
0: 0x0010 - 0x009f
0: 0x0100 - 0x0007bef0
On node 0 totalpages: 507519
  DMA zone: 56 pages used for memmap
  DMA zone: 2 pages reserved
  DMA zone: 3925 pages, LIFO batch:0
  DMA32 zone: 6885 pages used for memmap
  DMA32 zone: 496651 pages, LIFO batch:31
Detected use of extended apic ids on hypertransport bus
ACPI: PM-Timer IO Port: 0x4008
ACPI: Local APIC address 0xfee0
ACPI: LAPIC (acpi_id[0x00] lapic_id[0x00] enabled)
ACPI: LAPIC (acpi_id[0x01] lapic_id[0x01] enabled)
ACPI: LAPIC_NMI (acpi_id[0x00] high edge lint[0x1])
ACPI: LAPIC_NMI (acpi_id[0x01] high edge lint[0x1])
ACPI: IOAPIC (id[0x02] address[0xfec0] gsi_base[0])
IOAPIC[0]: apic_id 2, version 3, address 0xfec0, GSI 0-23
ACPI: INT_SRC_OVR (bus 0 bus_irq 0 global_irq 2 dfl dfl)
ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 low level)
ACPI: IRQ0 used by override.
ACPI: IRQ2 used by override.
ACPI: IRQ9 used by override.
Using ACPI (MADT) for SMP configuration information
SMP: Allowing 2 CPUs, 0 hotplug CPUs
nr_irqs_gsi: 40
Allocating PCI resources starting at 7bf0 (gap: 7bf0:82d0)
setup_percpu: NR_CPUS:2 nr_cpumask_bits:2 nr_cpu_ids:2 nr_node_ids:1
PERCPU: Embedded 25 pages/cpu @88007bc0 s70592 r8192 d23616 u1048576
pcpu-alloc: s70592 r8192 d23616 u1048576 alloc=1*2097152
pcpu-alloc: [0] 0 1 
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 500576
Kernel 

Re: TTM and AGP conflicts

2011-12-22 Thread James Simmons

  Hi!
 
         I updated the openchrome tree and while testing on the AGP system
  discovered some interesting problems with the new TTM changes. The
  problems center around the ttm_tt_[un]populate which I modeled after the
  radeon and nouveau driver.
         First problem I noticed was on a AGP system that my ttm_tt_populate
  function would oops. Tracking it down I found the problem was the
  ttm_agp_tt_create calls ttm_tt_init instead of ttm_dma_tt_init so once my
  ttm_tt_populate function would attempt to touch the dma_address it would
  oops. The second issue is the assumption of the cast for struct ttm_tt in
  both the populate and unpopulate function. For the AGP case the proper
  case would be to ttm_agp_backend.
         At this point my assumption is the ttm_bo_move function has to be
  rewritten to handle the AGP case to avoid calling ttm_tt_bind and in all
  cases ttm_tt_bind needs to be avoided. Looking at the radeon and nouveau
  drivers I don't see that testing happening. Am I just missing something?
 
 Happens on AGP radeons as well:
 https://bugs.freedesktop.org/show_bug.cgi?id=43719

So I'm not crazy, so this needs to be fixed. Here is what my 
understanding of the TTM layer is. My impression is that struct ttm_bo_driver
handles multiple domains, AGP, pcie etc and in each method you have to 
handle each specific domain you support. Also *move gives the impression of
moving between these different domains. 
Where as for struct ttm_backend_func was more for allocating from
a specific domain. Also I never saw a clear way to handle multiple backends. 
For example my AGP systems can also do pci dma as well. ___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH] fixes to drm-next - TTM DMA code (v1)

2011-12-13 Thread James Simmons

> Hi!
> 
> I'm not whether any drivers are still using the AGP backend?

Actually the openchrome projects KMS kernel uses a AGP backend.


> Calling unpopulate / (previous clear) each time unbind is done should be quite
> inefficient with that one, as AGP sets up its own data structures and copies
> page tables
> on each populate. That should really be avoided unless there is a good reason
> to have it.
> 
> /Thomas
> 
> 
> ___
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
> 


Re: [PATCH] fixes to drm-next - TTM DMA code (v1)

2011-12-13 Thread James Simmons

 Hi!
 
 I'm not whether any drivers are still using the AGP backend?

Actually the openchrome projects KMS kernel uses a AGP backend.


 Calling unpopulate / (previous clear) each time unbind is done should be quite
 inefficient with that one, as AGP sets up its own data structures and copies
 page tables
 on each populate. That should really be avoided unless there is a good reason
 to have it.
 
 /Thomas
 
 
 ___
 dri-devel mailing list
 dri-devel@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/dri-devel
 
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 11/23] drm/via: clean up reclaim_buffers

2011-12-08 Thread James Simmons

> A few things
> - kill reclaim_buffers, it's never ever called because via does not set
>   DRIVER_HAVE_DMA
> - inline the idlelock dance into the buffer reclaim logic and make it
>   a simple preclose cleanup function
> - directly call the the dma_quiescent function and kill the needless
>   if check.
> 
> Export the idlelock drm functions so that drivers can call them.
> 
> Signed-off-by: Daniel Vetter 
> ---
>  drivers/gpu/drm/drm_lock.c|2 ++
>  drivers/gpu/drm/via/via_drv.c |4 +---
>  drivers/gpu/drm/via/via_mm.c  |   11 +--
>  3 files changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
> index 632ae24..b107e1d 100644
> --- a/drivers/gpu/drm/drm_lock.c
> +++ b/drivers/gpu/drm/drm_lock.c
> @@ -345,6 +345,7 @@ void drm_idlelock_take(struct drm_lock_data *lock_data)
>   }
>   spin_unlock_bh(_data->spinlock);
>  }
> +EXPORT_SYMBOL(drm_idlelock_take);
>  
>  void drm_idlelock_release(struct drm_lock_data *lock_data)
>  {
> @@ -364,6 +365,7 @@ void drm_idlelock_release(struct drm_lock_data *lock_data)
>   }
>   spin_unlock_bh(_data->spinlock);
>  }
> +EXPORT_SYMBOL(drm_idlelock_release);
>  
>  int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv)
>  {

Need the following for modules to work.

#include 



> diff --git a/drivers/gpu/drm/via/via_drv.c b/drivers/gpu/drm/via/via_drv.c
> index 472adcf..f50431c 100644
> --- a/drivers/gpu/drm/via/via_drv.c
> +++ b/drivers/gpu/drm/via/via_drv.c
> @@ -62,6 +62,7 @@ static struct drm_driver driver = {
>   .load = via_driver_load,
>   .unload = via_driver_unload,
>   .open = via_driver_open,
> + .preclose = via_reclaim_buffers_locked,
>   .postclose = via_driver_postclose,
>   .context_dtor = via_final_context,
>   .get_vblank_counter = via_get_vblank_counter,
> @@ -72,9 +73,6 @@ static struct drm_driver driver = {
>   .irq_uninstall = via_driver_irq_uninstall,
>   .irq_handler = via_driver_irq_handler,
>   .dma_quiescent = via_driver_dma_quiescent,
> - .reclaim_buffers = drm_core_reclaim_buffers,
> - .reclaim_buffers_locked = NULL,
> - .reclaim_buffers_idlelocked = via_reclaim_buffers_locked,
>   .lastclose = via_lastclose,
>   .ioctls = via_ioctls,
>   .fops = {
> diff --git a/drivers/gpu/drm/via/via_mm.c b/drivers/gpu/drm/via/via_mm.c
> index 80eab7d..8ce95c5 100644
> --- a/drivers/gpu/drm/via/via_mm.c
> +++ b/drivers/gpu/drm/via/via_mm.c
> @@ -217,6 +217,10 @@ void via_reclaim_buffers_locked(struct drm_device *dev,
>  {
>   struct via_file_private *file_priv = file->driver_priv;
>   struct via_memblock *entry, *next;
> + int release_idlelock = 0;
> +
> + if (file->master && file->master->lock.hw_lock)
> + drm_idlelock_take(>master->lock);
>  
>   mutex_lock(>struct_mutex);
>   if (list_empty(_priv->obj_list)) {
> @@ -224,8 +228,7 @@ void via_reclaim_buffers_locked(struct drm_device *dev,
>   return;
>   }
>  
> - if (dev->driver->dma_quiescent)
> - dev->driver->dma_quiescent(dev);
> + via_driver_dma_quiescent(dev);
>  
>   list_for_each_entry_safe(entry, next, _priv->obj_list,
>owner_list) {
> @@ -234,5 +237,9 @@ void via_reclaim_buffers_locked(struct drm_device *dev,
>   kfree(entry);
>   }
>   mutex_unlock(>struct_mutex);
> +
> + if (release_idlelock)
> + drm_idlelock_release(>master->lock);
> +

When does release_idlelock get set?

>   return;
>  }
> -- 
> 1.7.7.1
> 
> ___
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
> 


[PATCH 08/23] drm/via: use drm_mm instead of drm_sman

2011-12-07 Thread James Simmons

> Chris Wilson rightly complained that this doesn't explain the list_del
> magic going on. New commit msg reads:
> 
> To make the transition in a piece-wise and bisectable way possible,
> I've hijacked the ->owner_list from drm_sman. While transitioning, the
> list_add was done by the driver, while the list_del was still done by
> the dying sman code.
> 
> Now that we are in full control of ->owner_list, do the list_del
> ourselves.
> 
> He also noted the superflous additions of INIT_LIST_HEAD and the stale
> comment about spinlock locking in the idr allocation (protected by
> dev->struct_mutex) that I've copied over. All fixed up and pushed out for
> the moment to my fdo repo:
> 
> http://cgit.freedesktop.org/~danvet/drm/log/?h=kill-with-fire

Speaking of I attempted to clone that repo but it gives me

warning: remote HEAD refers to nonexistent ref, unable to checkout.




[PATCH 10/23] drm: kill drm_sman

2011-12-07 Thread James Simmons

> No longer used.
> 
> Signed-off-by: Daniel Vetter 

Acked-by: James Simmons 

> ---
>  drivers/gpu/drm/Makefile   |2 +-
>  drivers/gpu/drm/drm_sman.c |  210 
> 
>  include/drm/drm_sman.h |  151 ---
>  3 files changed, 1 insertions(+), 362 deletions(-)
>  delete mode 100644 drivers/gpu/drm/drm_sman.c
>  delete mode 100644 include/drm/drm_sman.h
> 
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index 89cf05a..ea083cf 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -9,7 +9,7 @@ drm-y   :=drm_auth.o drm_buffer.o drm_bufs.o 
> drm_cache.o \
>   drm_drv.o drm_fops.o drm_gem.o drm_ioctl.o drm_irq.o \
>   drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
>   drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \
> - drm_platform.o drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o \
> + drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \
>   drm_crtc.o drm_modes.o drm_edid.o \
>   drm_info.o drm_debugfs.o drm_encoder_slave.o \
>   drm_trace_points.o drm_global.o drm_usb.o
> diff --git a/drivers/gpu/drm/drm_sman.c b/drivers/gpu/drm/drm_sman.c
> deleted file mode 100644
> index 1a4fb9f..000
> --- a/drivers/gpu/drm/drm_sman.c
> +++ /dev/null
> @@ -1,210 +0,0 @@
> -/**
> - *
> - * 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 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.
> - *
> - * The above copyright notice and this permission notice (including the
> - * next paragraph) shall be included in all copies or substantial portions
> - * of the Software.
> - *
> - *
> - **/
> -/*
> - * Simple memory manager interface that keeps track on allocate regions on a
> - * per "owner" basis. All regions associated with an "owner" can be released
> - * with a simple call. Typically if the "owner" exists. The owner is any
> - * "unsigned long" identifier. Can typically be a pointer to a file private
> - * struct or a context identifier.
> - *
> - * Authors:
> - * Thomas Hellstr?m 
> - */
> -
> -#include "drm_sman.h"
> -
> -struct drm_owner_item {
> - struct drm_hash_item owner_hash;
> - struct list_head sman_list;
> - struct list_head mem_blocks;
> -};
> -
> -void drm_sman_takedown(struct drm_sman * sman)
> -{
> - kfree(sman->mm);
> -}
> -
> -EXPORT_SYMBOL(drm_sman_takedown);
> -
> -int
> -drm_sman_init(struct drm_sman * sman, unsigned int num_managers,
> -   unsigned int user_order, unsigned int owner_order)
> -{
> - int ret = 0;
> -
> - sman->mm = kcalloc(num_managers, sizeof(*sman->mm), GFP_KERNEL);
> - if (!sman->mm) {
> - ret = -ENOMEM;
> - return ret;
> - }
> - sman->num_managers = num_managers;
> -
> - return 0;
> -}
> -
> -EXPORT_SYMBOL(drm_sman_init);
> -
> -static void *drm_sman_mm_allocate(void *private, unsigned long size,
> -   unsigned alignment)
> -{
> - struct drm_mm *mm = (struct drm_mm *) private;
> - struct drm_mm_node *tmp;
> -
> - tmp = drm_mm_search_free(mm, size, alignment, 1);
> - if (!tmp) {
> - return NULL;
> - }
> - tmp = drm_mm_get_block(tmp, size, alignment);
> - return tmp;
> -}
> -
> -static void drm_sman_mm_free(void *private, void *ref)
&

[PATCH 09/23] drm/sis: use drm_mm instead of drm_sman

2011-12-07 Thread James Simmons

> Signed-off-by: Daniel Vetter 

Can't test on SiS but does nothing to my VIA hardware.

Acked-by: James Simmons 

> ---
>  drivers/gpu/drm/sis/sis_drv.c |4 -
>  drivers/gpu/drm/sis/sis_drv.h |5 +-
>  drivers/gpu/drm/sis/sis_mm.c  |  137 +++-
>  3 files changed, 68 insertions(+), 78 deletions(-)
> 
> diff --git a/drivers/gpu/drm/sis/sis_drv.c b/drivers/gpu/drm/sis/sis_drv.c
> index 9f5fbcf..278d1b0 100644
> --- a/drivers/gpu/drm/sis/sis_drv.c
> +++ b/drivers/gpu/drm/sis/sis_drv.c
> @@ -47,9 +47,6 @@ static int sis_driver_load(struct drm_device *dev, unsigned 
> long chipset)
>   dev->dev_private = (void *)dev_priv;
>   dev_priv->chipset = chipset;
>   idr_init(>object_name_idr);
> - ret = drm_sman_init(_priv->sman, 2, 12, 8);
> - if (ret)
> - kfree(dev_priv);
>  
>   return ret;
>  }
> @@ -58,7 +55,6 @@ static int sis_driver_unload(struct drm_device *dev)
>  {
>   drm_sis_private_t *dev_priv = dev->dev_private;
>  
> - drm_sman_takedown(_priv->sman);
>   idr_remove_all(_priv->object_idr);
>   idr_destroy(_priv->object_idr);
>  
> diff --git a/drivers/gpu/drm/sis/sis_drv.h b/drivers/gpu/drm/sis/sis_drv.h
> index fcdd06a..573758b 100644
> --- a/drivers/gpu/drm/sis/sis_drv.h
> +++ b/drivers/gpu/drm/sis/sis_drv.h
> @@ -44,7 +44,7 @@ enum sis_family {
>   SIS_CHIP_315 = 1,
>  };
>  
> -#include "drm_sman.h"
> +#include "drm_mm.h"
>  
>  
>  #define SIS_BASE (dev_priv->mmio)
> @@ -54,12 +54,13 @@ enum sis_family {
>  typedef struct drm_sis_private {
>   drm_local_map_t *mmio;
>   unsigned int idle_fault;
> - struct drm_sman sman;
>   unsigned int chipset;
>   int vram_initialized;
>   int agp_initialized;
>   unsigned long vram_offset;
>   unsigned long agp_offset;
> + struct drm_mm vram_mm;
> + struct drm_mm agp_mm;
>   /** Mapping of userspace keys to mm objects */
>   struct idr object_idr;
>  } drm_sis_private_t;
> diff --git a/drivers/gpu/drm/sis/sis_mm.c b/drivers/gpu/drm/sis/sis_mm.c
> index ef6045a..ff34680 100644
> --- a/drivers/gpu/drm/sis/sis_mm.c
> +++ b/drivers/gpu/drm/sis/sis_mm.c
> @@ -41,40 +41,18 @@
>  #define AGP_TYPE 1
>  
>  
> +struct sis_memblock {
> + struct drm_mm_node mm_node;
> + struct sis_memreq req;
> + struct list_head owner_list;
> +};
> +
>  #if defined(CONFIG_FB_SIS) || defined(CONFIG_FB_SIS_MODULE)
>  /* fb management via fb device */
>  
>  #define SIS_MM_ALIGN_SHIFT 0
>  #define SIS_MM_ALIGN_MASK 0
>  
> -static void *sis_sman_mm_allocate(void *private, unsigned long size,
> -   unsigned alignment)
> -{
> - struct sis_memreq req;
> -
> - req.size = size;
> - sis_malloc();
> - if (req.size == 0)
> - return NULL;
> - else
> - return (void *)(unsigned long)~req.offset;
> -}
> -
> -static void sis_sman_mm_free(void *private, void *ref)
> -{
> - sis_free(~((unsigned long)ref));
> -}
> -
> -static void sis_sman_mm_destroy(void *private)
> -{
> - ;
> -}
> -
> -static unsigned long sis_sman_mm_offset(void *private, void *ref)
> -{
> - return ~((unsigned long)ref);
> -}
> -
>  #else /* CONFIG_FB_SIS[_MODULE] */
>  
>  #define SIS_MM_ALIGN_SHIFT 4
> @@ -86,30 +64,11 @@ static int sis_fb_init(struct drm_device *dev, void 
> *data, struct drm_file *file
>  {
>   drm_sis_private_t *dev_priv = dev->dev_private;
>   drm_sis_fb_t *fb = data;
> - int ret;
>  
>   mutex_lock(>struct_mutex);
> -#if defined(CONFIG_FB_SIS) || defined(CONFIG_FB_SIS_MODULE)
> - {
> - struct drm_sman_mm sman_mm;
> - sman_mm.private = (void *)0x;
> - sman_mm.allocate = sis_sman_mm_allocate;
> - sman_mm.free = sis_sman_mm_free;
> - sman_mm.destroy = sis_sman_mm_destroy;
> - sman_mm.offset = sis_sman_mm_offset;
> - ret =
> - drm_sman_set_manager(_priv->sman, VIDEO_TYPE, _mm);
> - }
> -#else
> - ret = drm_sman_set_range(_priv->sman, VIDEO_TYPE, 0,
> -  fb->size >> SIS_MM_ALIGN_SHIFT);
> -#endif
> -
> - if (ret) {
> - DRM_ERROR("VRAM memory manager initialisation error\n");
> - mutex_unlock(>struct_mutex);
> - return ret;
> - }
> + /* Unconditionally init the drm_mm, even though we don't use it when the
> +  * fb sis driver is available - make cleanup easier. */
>

[PATCH 08/23] drm/via: use drm_mm instead of drm_sman

2011-12-07 Thread James Simmons

> Now that we are again in proper control of owner_list, we need to
> properly list_del it on free.
> 
> Signed-off-by: Daniel Vetter 

Acked-by: James Simmons 

> ---
>  drivers/gpu/drm/via/via_drv.h |5 ++-
>  drivers/gpu/drm/via/via_map.c |7 
>  drivers/gpu/drm/via/via_mm.c  |   72 ++--
>  3 files changed, 43 insertions(+), 41 deletions(-)
> 
> diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
> index 108ea71..88edacc 100644
> --- a/drivers/gpu/drm/via/via_drv.h
> +++ b/drivers/gpu/drm/via/via_drv.h
> @@ -24,7 +24,7 @@
>  #ifndef _VIA_DRV_H_
>  #define _VIA_DRV_H_
>  
> -#include "drm_sman.h"
> +#include "drm_mm.h"
>  #define DRIVER_AUTHOR"Various"
>  
>  #define DRIVER_NAME  "via"
> @@ -88,9 +88,10 @@ typedef struct drm_via_private {
>   uint32_t irq_pending_mask;
>   int *irq_map;
>   unsigned int idle_fault;
> - struct drm_sman sman;
>   int vram_initialized;
> + struct drm_mm vram_mm;
>   int agp_initialized;
> + struct drm_mm agp_mm;
>   /** Mapping of userspace keys to mm objects */
>   struct idr object_idr;
>   unsigned long vram_offset;
> diff --git a/drivers/gpu/drm/via/via_map.c b/drivers/gpu/drm/via/via_map.c
> index fa5afbc..a2ab343 100644
> --- a/drivers/gpu/drm/via/via_map.c
> +++ b/drivers/gpu/drm/via/via_map.c
> @@ -105,15 +105,9 @@ int via_driver_load(struct drm_device *dev, unsigned 
> long chipset)
>   dev_priv->chipset = chipset;
>  
>   idr_init(>object_name_idr);
> - ret = drm_sman_init(_priv->sman, 2, 12, 8);
> - if (ret) {
> - kfree(dev_priv);
> - return ret;
> - }
>  
>   ret = drm_vblank_init(dev, 1);
>   if (ret) {
> - drm_sman_takedown(_priv->sman);
>   kfree(dev_priv);
>   return ret;
>   }
> @@ -125,7 +119,6 @@ int via_driver_unload(struct drm_device *dev)
>  {
>   drm_via_private_t *dev_priv = dev->dev_private;
>  
> - drm_sman_takedown(_priv->sman);
>   idr_remove_all(_priv->object_idr);
>   idr_destroy(_priv->object_idr);
>  
> diff --git a/drivers/gpu/drm/via/via_mm.c b/drivers/gpu/drm/via/via_mm.c
> index af9e771..80eab7d 100644
> --- a/drivers/gpu/drm/via/via_mm.c
> +++ b/drivers/gpu/drm/via/via_mm.c
> @@ -28,26 +28,22 @@
>  #include "drmP.h"
>  #include "via_drm.h"
>  #include "via_drv.h"
> -#include "drm_sman.h"
>  
>  #define VIA_MM_ALIGN_SHIFT 4
>  #define VIA_MM_ALIGN_MASK ((1 << VIA_MM_ALIGN_SHIFT) - 1)
>  
> +struct via_memblock {
> + struct drm_mm_node mm_node;
> + struct list_head owner_list;
> +};
> +
>  int via_agp_init(struct drm_device *dev, void *data, struct drm_file 
> *file_priv)
>  {
>   drm_via_agp_t *agp = data;
>   drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
> - int ret;
>  
>   mutex_lock(>struct_mutex);
> - ret = drm_sman_set_range(_priv->sman, VIA_MEM_AGP, 0,
> -  agp->size >> VIA_MM_ALIGN_SHIFT);
> -
> - if (ret) {
> - DRM_ERROR("AGP memory manager initialisation error\n");
> - mutex_unlock(>struct_mutex);
> - return ret;
> - }
> + drm_mm_init(_priv->agp_mm, 0, agp->size >> VIA_MM_ALIGN_SHIFT);
>  
>   dev_priv->agp_initialized = 1;
>   dev_priv->agp_offset = agp->offset;
> @@ -61,17 +57,9 @@ int via_fb_init(struct drm_device *dev, void *data, struct 
> drm_file *file_priv)
>  {
>   drm_via_fb_t *fb = data;
>   drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
> - int ret;
>  
>   mutex_lock(>struct_mutex);
> - ret = drm_sman_set_range(_priv->sman, VIA_MEM_VIDEO, 0,
> -  fb->size >> VIA_MM_ALIGN_SHIFT);
> -
> - if (ret) {
> - DRM_ERROR("VRAM memory manager initialisation error\n");
> - mutex_unlock(>struct_mutex);
> - return ret;
> - }
> + drm_mm_init(_priv->vram_mm, 0, fb->size >> VIA_MM_ALIGN_SHIFT);
>  
>   dev_priv->vram_initialized = 1;
>   dev_priv->vram_offset = fb->offset;
> @@ -108,9 +96,14 @@ void via_lastclose(struct drm_device *dev)
>   return;
>  
>   mutex_lock(>struct_mutex);
> - drm_sman_cleanup(_priv->sman);
> - dev_priv->vram_initialized = 0;
> - dev_priv->agp_initialized = 0;
> + if (d

[PATCH 07/23] drm/sman: kill user_hash_tab

2011-12-07 Thread James Simmons

> No longer used.
> 
> Signed-off-by: Daniel Vetter 

Acked-by: James Simmons 

> ---
>  drivers/gpu/drm/drm_sman.c |   36 ++--
>  include/drm/drm_sman.h |5 -
>  2 files changed, 2 insertions(+), 39 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_sman.c b/drivers/gpu/drm/drm_sman.c
> index 37a8844..1a4fb9f 100644
> --- a/drivers/gpu/drm/drm_sman.c
> +++ b/drivers/gpu/drm/drm_sman.c
> @@ -46,7 +46,6 @@ struct drm_owner_item {
>  
>  void drm_sman_takedown(struct drm_sman * sman)
>  {
> - drm_ht_remove(>user_hash_tab);
>   kfree(sman->mm);
>  }
>  
> @@ -61,16 +60,11 @@ drm_sman_init(struct drm_sman * sman, unsigned int 
> num_managers,
>   sman->mm = kcalloc(num_managers, sizeof(*sman->mm), GFP_KERNEL);
>   if (!sman->mm) {
>   ret = -ENOMEM;
> - goto out;
> + return ret;
>   }
>   sman->num_managers = num_managers;
> - ret = drm_ht_create(>user_hash_tab, user_order);
> - if (!ret)
> - goto out;
>  
> - kfree(sman->mm);
> -out:
> - return ret;
> + return 0;
>  }
>  
>  EXPORT_SYMBOL(drm_sman_init);
> @@ -179,15 +173,8 @@ struct drm_memblock_item *drm_sman_alloc(struct drm_sman 
> *sman, unsigned int man
>   memblock->mm = sman_mm;
>   memblock->sman = sman;
>  
> - if (drm_ht_just_insert_please
> - (>user_hash_tab, >user_hash,
> -  (unsigned long)memblock, 32, 0, 0))
> - goto out1;
> -
>   return memblock;
>  
> -out1:
> - kfree(memblock);
>  out:
>   sman_mm->free(sman_mm->private, tmp);
>  
> @@ -198,31 +185,12 @@ EXPORT_SYMBOL(drm_sman_alloc);
>  
>  void drm_sman_free(struct drm_memblock_item *item)
>  {
> - struct drm_sman *sman = item->sman;
> -
>   list_del(>owner_list);
> - drm_ht_remove_item(>user_hash_tab, >user_hash);
>   item->mm->free(item->mm->private, item->mm_info);
>   kfree(item);
>  }
>  EXPORT_SYMBOL(drm_sman_free);
>  
> -int drm_sman_free_key(struct drm_sman *sman, unsigned int key)
> -{
> - struct drm_hash_item *hash_item;
> - struct drm_memblock_item *memblock_item;
> -
> - if (drm_ht_find_item(>user_hash_tab, key, _item))
> - return -EINVAL;
> -
> - memblock_item = drm_hash_entry(hash_item, struct drm_memblock_item,
> -user_hash);
> - drm_sman_free(memblock_item);
> - return 0;
> -}
> -
> -EXPORT_SYMBOL(drm_sman_free_key);
> -
>  void drm_sman_cleanup(struct drm_sman *sman)
>  {
>   unsigned int i;
> diff --git a/include/drm/drm_sman.h b/include/drm/drm_sman.h
> index 34ae5ca..031e521 100644
> --- a/include/drm/drm_sman.h
> +++ b/include/drm/drm_sman.h
> @@ -87,7 +87,6 @@ struct drm_memblock_item {
>  struct drm_sman {
>   struct drm_sman_mm *mm;
>   int num_managers;
> - struct drm_open_hash user_hash_tab;
>  };
>  
>  /*
> @@ -139,11 +138,7 @@ extern struct drm_memblock_item *drm_sman_alloc(struct 
> drm_sman * sman,
>   unsigned long size,
>   unsigned alignment,
>   unsigned long owner);
> -/*
> - * Free a memory block identified by its user hash key.
> - */
>  
> -extern int drm_sman_free_key(struct drm_sman * sman, unsigned int key);
>  extern void drm_sman_free(struct drm_memblock_item *item);
>  
>  /*
> -- 
> 1.7.7.1
> 
> ___
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
> 


[PATCH 06/23] drm/sis: track user->memblock mapping with idr

2011-12-07 Thread James Simmons

> Signed-off-by: Daniel Vetter 

Acked-by: James Simmons 

> ---
>  drivers/gpu/drm/sis/sis_drv.c |4 +++
>  drivers/gpu/drm/sis/sis_drv.h |2 +
>  drivers/gpu/drm/sis/sis_mm.c  |   60 ++--
>  drivers/gpu/drm/via/via_map.c |2 +
>  4 files changed, 53 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/gpu/drm/sis/sis_drv.c b/drivers/gpu/drm/sis/sis_drv.c
> index a5dcd0a..9f5fbcf 100644
> --- a/drivers/gpu/drm/sis/sis_drv.c
> +++ b/drivers/gpu/drm/sis/sis_drv.c
> @@ -46,6 +46,7 @@ static int sis_driver_load(struct drm_device *dev, unsigned 
> long chipset)
>  
>   dev->dev_private = (void *)dev_priv;
>   dev_priv->chipset = chipset;
> + idr_init(>object_name_idr);
>   ret = drm_sman_init(_priv->sman, 2, 12, 8);
>   if (ret)
>   kfree(dev_priv);
> @@ -58,6 +59,9 @@ static int sis_driver_unload(struct drm_device *dev)
>   drm_sis_private_t *dev_priv = dev->dev_private;
>  
>   drm_sman_takedown(_priv->sman);
> + idr_remove_all(_priv->object_idr);
> + idr_destroy(_priv->object_idr);
> +
>   kfree(dev_priv);
>  
>   return 0;
> diff --git a/drivers/gpu/drm/sis/sis_drv.h b/drivers/gpu/drm/sis/sis_drv.h
> index 194303c..fcdd06a 100644
> --- a/drivers/gpu/drm/sis/sis_drv.h
> +++ b/drivers/gpu/drm/sis/sis_drv.h
> @@ -60,6 +60,8 @@ typedef struct drm_sis_private {
>   int agp_initialized;
>   unsigned long vram_offset;
>   unsigned long agp_offset;
> + /** Mapping of userspace keys to mm objects */
> + struct idr object_idr;
>  } drm_sis_private_t;
>  
>  extern int sis_idle(struct drm_device *dev);
> diff --git a/drivers/gpu/drm/sis/sis_mm.c b/drivers/gpu/drm/sis/sis_mm.c
> index dff70da..ef6045a 100644
> --- a/drivers/gpu/drm/sis/sis_mm.c
> +++ b/drivers/gpu/drm/sis/sis_mm.c
> @@ -125,7 +125,7 @@ static int sis_drm_alloc(struct drm_device *dev, struct 
> drm_file *file,
>  {
>   drm_sis_private_t *dev_priv = dev->dev_private;
>   drm_sis_mem_t *mem = data;
> - int retval = 0;
> + int retval = 0, user_key;
>   struct drm_memblock_item *item;
>   struct sis_file_private *file_priv = file->driver_priv;
>  
> @@ -141,24 +141,46 @@ static int sis_drm_alloc(struct drm_device *dev, struct 
> drm_file *file,
>  
>   mem->size = (mem->size + SIS_MM_ALIGN_MASK) >> SIS_MM_ALIGN_SHIFT;
>   item = drm_sman_alloc(_priv->sman, pool, mem->size, 0, 0);
> + if (!item) {
> + retval = -ENOMEM;
> + goto fail_alloc;
> + }
>  
> - if (item) {
> - INIT_LIST_HEAD(>owner_list);
> - list_add(>owner_list, _priv->obj_list);
> - mem->offset = ((pool == 0) ?
> -   dev_priv->vram_offset : dev_priv->agp_offset) +
> - (item->mm->
> -  offset(item->mm, item->mm_info) << SIS_MM_ALIGN_SHIFT);
> - mem->free = item->user_hash.key;
> - mem->size = mem->size << SIS_MM_ALIGN_SHIFT;
> - } else {
> - mem->offset = 0;
> - mem->size = 0;
> - mem->free = 0;
> +again:
> + if (idr_pre_get(_priv->object_idr, GFP_KERNEL) == 0) {
>   retval = -ENOMEM;
> + goto fail_idr;
>   }
> +
> + /* do the allocation under our spinlock */
> + retval = idr_get_new_above(_priv->object_idr, item, 1, _key);
> + if (retval == -EAGAIN)
> + goto again;
> + if (retval)
> + goto fail_idr;
> +
> + INIT_LIST_HEAD(>owner_list);
> + list_add(>owner_list, _priv->obj_list);
> + mutex_unlock(>struct_mutex);
> +
> + mem->offset = ((pool == 0) ?
> +   dev_priv->vram_offset : dev_priv->agp_offset) +
> + (item->mm->
> +  offset(item->mm, item->mm_info) << SIS_MM_ALIGN_SHIFT);
> + mem->free = user_key;
> + mem->size = mem->size << SIS_MM_ALIGN_SHIFT;
> +
> + return 0;
> +
> +fail_idr:
> + drm_sman_free(item);
> +fail_alloc:
>   mutex_unlock(>struct_mutex);
>  
> + mem->offset = 0;
> + mem->size = 0;
> + mem->free = 0;
> +
>   DRM_DEBUG("alloc %d, size = %d, offset = %d\n", pool, mem->size,
> mem->offset);
>  
> @@ -169,10 +191,18 @@ static int sis_drm_free(struct drm_device *dev, void 
> *data, struct drm_file *fil
>  {
>   drm_sis_private_t *dev_priv = dev->dev_private;
>   drm_sis_mem_t *mem = data;
> +   

[PATCH 05/23] drm/via: track user->memblock mapping with idr

2011-12-07 Thread James Simmons

> Massive indirection through a hashtable for a simple key->pointer
> look-up actually just adds bloat.
> 
> Signed-off-by: Daniel Vetter 
> ---
>  drivers/gpu/drm/via/via_drv.h |2 +
>  drivers/gpu/drm/via/via_map.c |1 +
>  drivers/gpu/drm/via/via_mm.c  |   61 
> +++--
>  3 files changed, 49 insertions(+), 15 deletions(-)

Acked-by: James Simmons 

> diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
> index 9cf87d9..108ea71 100644
> --- a/drivers/gpu/drm/via/via_drv.h
> +++ b/drivers/gpu/drm/via/via_drv.h
> @@ -91,6 +91,8 @@ typedef struct drm_via_private {
>   struct drm_sman sman;
>   int vram_initialized;
>   int agp_initialized;
> + /** Mapping of userspace keys to mm objects */
> + struct idr object_idr;
>   unsigned long vram_offset;
>   unsigned long agp_offset;
>   drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES];
> diff --git a/drivers/gpu/drm/via/via_map.c b/drivers/gpu/drm/via/via_map.c
> index 6cca9a7..b09f659 100644
> --- a/drivers/gpu/drm/via/via_map.c
> +++ b/drivers/gpu/drm/via/via_map.c
> @@ -104,6 +104,7 @@ int via_driver_load(struct drm_device *dev, unsigned long 
> chipset)
>  
>   dev_priv->chipset = chipset;
>  
> + idr_init(>object_name_idr);
>   ret = drm_sman_init(_priv->sman, 2, 12, 8);
>   if (ret) {
>   kfree(dev_priv);
> diff --git a/drivers/gpu/drm/via/via_mm.c b/drivers/gpu/drm/via/via_mm.c
> index ea3d621..af9e771 100644
> --- a/drivers/gpu/drm/via/via_mm.c
> +++ b/drivers/gpu/drm/via/via_mm.c
> @@ -118,7 +118,7 @@ int via_mem_alloc(struct drm_device *dev, void *data,
> struct drm_file *file)
>  {
>   drm_via_mem_t *mem = data;
> - int retval = 0;
> + int retval = 0, user_key;
>   struct drm_memblock_item *item;
>   drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
>   struct via_file_private *file_priv = file->driver_priv;
> @@ -139,24 +139,46 @@ int via_mem_alloc(struct drm_device *dev, void *data,
>  
>   tmpSize = (mem->size + VIA_MM_ALIGN_MASK) >> VIA_MM_ALIGN_SHIFT;
>   item = drm_sman_alloc(_priv->sman, mem->type, tmpSize, 0, 0);
> + if (!item) {
> + retval = -ENOMEM;
> + goto fail_alloc;
> + }
>  
> - if (item) {
> - INIT_LIST_HEAD(>owner_list);
> - list_add(>owner_list, _priv->obj_list);
> - mem->offset = ((mem->type == VIA_MEM_VIDEO) ?
> -   dev_priv->vram_offset : dev_priv->agp_offset) +
> - (item->mm->
> -  offset(item->mm, item->mm_info) << VIA_MM_ALIGN_SHIFT);
> - mem->index = item->user_hash.key;
> - } else {
> - mem->offset = 0;
> - mem->size = 0;
> - mem->index = 0;
> - DRM_DEBUG("Video memory allocation failed\n");
> +again:
> + if (idr_pre_get(_priv->object_idr, GFP_KERNEL) == 0) {
>   retval = -ENOMEM;
> + goto fail_idr;
>   }
> +
> + /* do the allocation under our spinlock */
> + retval = idr_get_new_above(_priv->object_idr, item, 1, _key);
> + if (retval == -EAGAIN)
> + goto again;
> + if (retval)
> + goto fail_idr;
> +
> + INIT_LIST_HEAD(>owner_list);
> + list_add(>owner_list, _priv->obj_list);
>   mutex_unlock(>struct_mutex);
>  
> + mem->offset = ((mem->type == VIA_MEM_VIDEO) ?
> +   dev_priv->vram_offset : dev_priv->agp_offset) +
> + (item->mm->
> +  offset(item->mm, item->mm_info) << VIA_MM_ALIGN_SHIFT);
> + mem->index = user_key;
> +
> + return 0;
> +
> +fail_idr:
> + drm_sman_free(item);
> +fail_alloc:
> + mutex_unlock(>struct_mutex);
> +
> + mem->offset = 0;
> + mem->size = 0;
> + mem->index = 0;
> + DRM_DEBUG("Video memory allocation failed\n");
> +
>   return retval;
>  }
>  
> @@ -164,11 +186,20 @@ int via_mem_free(struct drm_device *dev, void *data, 
> struct drm_file *file_priv)
>  {
>   drm_via_private_t *dev_priv = dev->dev_private;
>   drm_via_mem_t *mem = data;
> + struct drm_memblock_item *obj;
>   int ret;
>  
>   mutex_lock(>struct_mutex);
> - ret = drm_sman_free_key(_priv->sman, mem->index);
> + obj = idr_find(_priv->object_idr, mem->index);
> + if (obj == NULL) {
> + mutex_unlock(>struct_mutex);
> + return -EINVAL;
> + }
> +
> + idr_remove(_priv->object_idr, mem->index);
> + drm_sman_free(obj);
>   mutex_unlock(>struct_mutex);
> +
>   DRM_DEBUG("free = 0x%lx\n", mem->index);
>  
>   return ret;
> -- 
> 1.7.7.1
> 
> ___
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
> 


[PATCH 04/23] drm/sman: rip out owner tracking

2011-12-07 Thread James Simmons

> In contrast to kms drivers, sis/via _always_ associated a buffer with
> a drm fd. So by the time we reach lastclose, all open drm fds are gone
> and with them their associated objects.
> 
> So when sis/via call drm_sman_cleanup in their lastclose funcs, that
> will free 0 objects.
> 
> The owner tracking now serves no purpose at all, hence rip it ou. We
> can't kill the corresponding fields in struct drm_memblock_item yet
> because we hijack these in the new driver private owner tracking. But
> now that drm_sman.c doesn't touch ->owner_list anymore, we need to
> kill the list_move hack and properly add the item to the file_priv
> list.
> 
> Also leave the list_del(>owner_list) in drm_sman_free for the
> moment, it will move to the drivers when sman disappears completely.
> 
> Signed-off-by: Daniel Vetter 

Acked-by: James Simmons 

> ---
>  drivers/gpu/drm/drm_sman.c   |   71 
> --
>  drivers/gpu/drm/sis/sis_mm.c |3 +-
>  drivers/gpu/drm/via/via_mm.c |3 +-
>  include/drm/drm_sman.h   |2 -
>  4 files changed, 4 insertions(+), 75 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_sman.c b/drivers/gpu/drm/drm_sman.c
> index a672fea..37a8844 100644
> --- a/drivers/gpu/drm/drm_sman.c
> +++ b/drivers/gpu/drm/drm_sman.c
> @@ -47,7 +47,6 @@ struct drm_owner_item {
>  void drm_sman_takedown(struct drm_sman * sman)
>  {
>   drm_ht_remove(>user_hash_tab);
> - drm_ht_remove(>owner_hash_tab);
>   kfree(sman->mm);
>  }
>  
> @@ -65,16 +64,10 @@ drm_sman_init(struct drm_sman * sman, unsigned int 
> num_managers,
>   goto out;
>   }
>   sman->num_managers = num_managers;
> - INIT_LIST_HEAD(>owner_items);
> - ret = drm_ht_create(>owner_hash_tab, owner_order);
> - if (ret)
> - goto out1;
>   ret = drm_ht_create(>user_hash_tab, user_order);
>   if (!ret)
>   goto out;
>  
> - drm_ht_remove(>owner_hash_tab);
> -out1:
>   kfree(sman->mm);
>  out:
>   return ret;
> @@ -160,44 +153,12 @@ drm_sman_set_manager(struct drm_sman * sman, unsigned 
> int manager,
>  }
>  EXPORT_SYMBOL(drm_sman_set_manager);
>  
> -static struct drm_owner_item *drm_sman_get_owner_item(struct drm_sman * sman,
> -  unsigned long owner)
> -{
> - int ret;
> - struct drm_hash_item *owner_hash_item;
> - struct drm_owner_item *owner_item;
> -
> - ret = drm_ht_find_item(>owner_hash_tab, owner, _hash_item);
> - if (!ret) {
> - return drm_hash_entry(owner_hash_item, struct drm_owner_item,
> -   owner_hash);
> - }
> -
> - owner_item = kzalloc(sizeof(*owner_item), GFP_KERNEL);
> - if (!owner_item)
> - goto out;
> -
> - INIT_LIST_HEAD(_item->mem_blocks);
> - owner_item->owner_hash.key = owner;
> - if (drm_ht_insert_item(>owner_hash_tab, _item->owner_hash))
> - goto out1;
> -
> - list_add_tail(_item->sman_list, >owner_items);
> - return owner_item;
> -
> -out1:
> - kfree(owner_item);
> -out:
> - return NULL;
> -}
> -
>  struct drm_memblock_item *drm_sman_alloc(struct drm_sman *sman, unsigned int 
> manager,
>   unsigned long size, unsigned alignment,
>   unsigned long owner)
>  {
>   void *tmp;
>   struct drm_sman_mm *sman_mm;
> - struct drm_owner_item *owner_item;
>   struct drm_memblock_item *memblock;
>  
>   BUG_ON(manager >= sman->num_managers);
> @@ -223,16 +184,8 @@ struct drm_memblock_item *drm_sman_alloc(struct drm_sman 
> *sman, unsigned int man
>(unsigned long)memblock, 32, 0, 0))
>   goto out1;
>  
> - owner_item = drm_sman_get_owner_item(sman, owner);
> - if (!owner_item)
> - goto out2;
> -
> - list_add_tail(>owner_list, _item->mem_blocks);
> -
>   return memblock;
>  
> -out2:
> - drm_ht_remove_item(>user_hash_tab, >user_hash);
>  out1:
>   kfree(memblock);
>  out:
> @@ -270,35 +223,11 @@ int drm_sman_free_key(struct drm_sman *sman, unsigned 
> int key)
>  
>  EXPORT_SYMBOL(drm_sman_free_key);
>  
> -static void drm_sman_remove_owner(struct drm_sman *sman,
> -   struct drm_owner_item *owner_item)
> -{
> - list_del(_item->sman_list);
> - drm_ht_remove_item(>owner_hash_tab, _item->owner_hash);
> - kfree(owner_item);
> -}
> -
> -static void drm_sman_do_owner_cleanup(struc

[PATCH 03/23] drm/sman: kill owner tracking interface functions

2011-12-07 Thread James Simmons

> These are now unused.
> 
> Signed-off-by: Daniel Vetter 

Acked-by: James Simmons 

> ---
>  drivers/gpu/drm/drm_sman.c |   38 --
>  include/drm/drm_sman.h |   19 ---
>  2 files changed, 0 insertions(+), 57 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_sman.c b/drivers/gpu/drm/drm_sman.c
> index 37548b7..a672fea 100644
> --- a/drivers/gpu/drm/drm_sman.c
> +++ b/drivers/gpu/drm/drm_sman.c
> @@ -278,27 +278,6 @@ static void drm_sman_remove_owner(struct drm_sman *sman,
>   kfree(owner_item);
>  }
>  
> -int drm_sman_owner_clean(struct drm_sman *sman, unsigned long owner)
> -{
> -
> - struct drm_hash_item *hash_item;
> - struct drm_owner_item *owner_item;
> -
> - if (drm_ht_find_item(>owner_hash_tab, owner, _item)) {
> - return -1;
> - }
> -
> - owner_item = drm_hash_entry(hash_item, struct drm_owner_item, 
> owner_hash);
> - if (owner_item->mem_blocks.next == _item->mem_blocks) {
> - drm_sman_remove_owner(sman, owner_item);
> - return -1;
> - }
> -
> - return 0;
> -}
> -
> -EXPORT_SYMBOL(drm_sman_owner_clean);
> -
>  static void drm_sman_do_owner_cleanup(struct drm_sman *sman,
> struct drm_owner_item *owner_item)
>  {
> @@ -311,23 +290,6 @@ static void drm_sman_do_owner_cleanup(struct drm_sman 
> *sman,
>   drm_sman_remove_owner(sman, owner_item);
>  }
>  
> -void drm_sman_owner_cleanup(struct drm_sman *sman, unsigned long owner)
> -{
> -
> - struct drm_hash_item *hash_item;
> - struct drm_owner_item *owner_item;
> -
> - if (drm_ht_find_item(>owner_hash_tab, owner, _item)) {
> -
> - return;
> - }
> -
> - owner_item = drm_hash_entry(hash_item, struct drm_owner_item, 
> owner_hash);
> - drm_sman_do_owner_cleanup(sman, owner_item);
> -}
> -
> -EXPORT_SYMBOL(drm_sman_owner_cleanup);
> -
>  void drm_sman_cleanup(struct drm_sman *sman)
>  {
>   struct drm_owner_item *entry, *next;
> diff --git a/include/drm/drm_sman.h b/include/drm/drm_sman.h
> index 3b65ccf..d5ed903 100644
> --- a/include/drm/drm_sman.h
> +++ b/include/drm/drm_sman.h
> @@ -149,25 +149,6 @@ extern int drm_sman_free_key(struct drm_sman * sman, 
> unsigned int key);
>  extern void drm_sman_free(struct drm_memblock_item *item);
>  
>  /*
> - * returns 1 iff there are no stale memory blocks associated with this owner.
> - * Typically called to determine if we need to idle the hardware and call
> - * drm_sman_owner_cleanup. If there are no stale memory blocks, it removes 
> all
> - * resources associated with owner.
> - */
> -
> -extern int drm_sman_owner_clean(struct drm_sman * sman, unsigned long owner);
> -
> -/*
> - * Frees all stale memory blocks associated with this owner. Note that this
> - * requires that the hardware is finished with all blocks, so the graphics 
> engine
> - * should be idled before this call is made. This function also frees
> - * any resources associated with "owner" and should be called when owner
> - * is not going to be referenced anymore.
> - */
> -
> -extern void drm_sman_owner_cleanup(struct drm_sman * sman, unsigned long 
> owner);
> -
> -/*
>   * Frees all stale memory blocks associated with the memory manager.
>   * See idling above.
>   */
> -- 
> 1.7.7.1
> 
> ___
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
> 


[PATCH 02/23] drm/via: track obj->drm_fd relations in the driver

2011-12-07 Thread James Simmons


> Exactly like the previous patch for sis.
> 
> Signed-off-by: Daniel Vetter 

Acked-by: James Simmons 

Same goes for PATCH 01 which I'm missing in my inbox.

> ---
>  drivers/gpu/drm/via/via_drv.c |   25 +
>  drivers/gpu/drm/via/via_mm.c  |   22 ++
>  include/drm/via_drm.h |4 
>  3 files changed, 43 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/via/via_drv.c b/drivers/gpu/drm/via/via_drv.c
> index 920a552..472adcf 100644
> --- a/drivers/gpu/drm/via/via_drv.c
> +++ b/drivers/gpu/drm/via/via_drv.c
> @@ -28,6 +28,29 @@
>  
>  #include "drm_pciids.h"
>  
> +static int via_driver_open(struct drm_device *dev, struct drm_file *file)
> +{
> + struct via_file_private *file_priv;
> +
> + DRM_DEBUG_DRIVER("\n");
> + file_priv = kmalloc(sizeof(*file_priv), GFP_KERNEL);
> + if (!file_priv)
> + return -ENOMEM;
> +
> + file->driver_priv = file_priv;
> +
> + INIT_LIST_HEAD(_priv->obj_list);
> +
> + return 0;
> +}
> +
> +void via_driver_postclose(struct drm_device *dev, struct drm_file *file)
> +{
> + struct via_file_private *file_priv = file->driver_priv;
> +
> + kfree(file_priv);
> +}
> +
>  static struct pci_device_id pciidlist[] = {
>   viadrv_PCI_IDS
>  };
> @@ -38,6 +61,8 @@ static struct drm_driver driver = {
>   DRIVER_IRQ_SHARED,
>   .load = via_driver_load,
>   .unload = via_driver_unload,
> + .open = via_driver_open,
> + .postclose = via_driver_postclose,
>   .context_dtor = via_final_context,
>   .get_vblank_counter = via_get_vblank_counter,
>   .enable_vblank = via_enable_vblank,
> diff --git a/drivers/gpu/drm/via/via_mm.c b/drivers/gpu/drm/via/via_mm.c
> index 6cc2dad..19bb77c 100644
> --- a/drivers/gpu/drm/via/via_mm.c
> +++ b/drivers/gpu/drm/via/via_mm.c
> @@ -115,12 +115,13 @@ void via_lastclose(struct drm_device *dev)
>  }
>  
>  int via_mem_alloc(struct drm_device *dev, void *data,
> -   struct drm_file *file_priv)
> +   struct drm_file *file)
>  {
>   drm_via_mem_t *mem = data;
>   int retval = 0;
>   struct drm_memblock_item *item;
>   drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
> + struct via_file_private *file_priv = file->driver_priv;
>   unsigned long tmpSize;
>  
>   if (mem->type > VIA_MEM_AGP) {
> @@ -137,10 +138,10 @@ int via_mem_alloc(struct drm_device *dev, void *data,
>   }
>  
>   tmpSize = (mem->size + VIA_MM_ALIGN_MASK) >> VIA_MM_ALIGN_SHIFT;
> - item = drm_sman_alloc(_priv->sman, mem->type, tmpSize, 0,
> -   (unsigned long)file_priv);
> - mutex_unlock(>struct_mutex);
> + item = drm_sman_alloc(_priv->sman, mem->type, tmpSize, 0, 0);
> +
>   if (item) {
> + list_move(>owner_list, _priv->obj_list);
>   mem->offset = ((mem->type == VIA_MEM_VIDEO) ?
> dev_priv->vram_offset : dev_priv->agp_offset) +
>   (item->mm->
> @@ -153,6 +154,7 @@ int via_mem_alloc(struct drm_device *dev, void *data,
>   DRM_DEBUG("Video memory allocation failed\n");
>   retval = -ENOMEM;
>   }
> + mutex_unlock(>struct_mutex);
>  
>   return retval;
>  }
> @@ -173,12 +175,13 @@ int via_mem_free(struct drm_device *dev, void *data, 
> struct drm_file *file_priv)
>  
>  
>  void via_reclaim_buffers_locked(struct drm_device *dev,
> - struct drm_file *file_priv)
> + struct drm_file *file)
>  {
> - drm_via_private_t *dev_priv = dev->dev_private;
> + struct via_file_private *file_priv = file->driver_priv;
> + struct drm_memblock_item *entry, *next;
>  
>   mutex_lock(>struct_mutex);
> - if (drm_sman_owner_clean(_priv->sman, (unsigned long)file_priv)) {
> + if (list_empty(_priv->obj_list)) {
>   mutex_unlock(>struct_mutex);
>   return;
>   }
> @@ -186,7 +189,10 @@ void via_reclaim_buffers_locked(struct drm_device *dev,
>   if (dev->driver->dma_quiescent)
>   dev->driver->dma_quiescent(dev);
>  
> - drm_sman_owner_cleanup(_priv->sman, (unsigned long)file_priv);
> + list_for_each_entry_safe(entry, next, _priv->obj_list,
> +  owner_list) {
> + drm_sman_free(entry);
> + }
>   mutex_unlock(>struct_mutex);
>   return;
>  }
> diff --git a/include/dr

[PATCH 00/23] kill drm cruft with fire

2011-12-07 Thread James Simmons

> > >> Testing this on via would be awesome! Iirc I haven't changed anything in
> > >> the via specific patches, but if it's more convenient you can also
> > >> directly test my branch:
> > >>
> > >> http://cgit.freedesktop.org/~danvet/drm/log/?h=kill-with-fire
> > >
> > > Okay I tried the patches and it locked up the openchrome X server. I'm
> > > going to try your branch tonight to see if it makes any difference. If it
> > > still fails I will have to track down what the problem is.
> >
> > If you can bisect the issue, that would be awesome. Meanwhile my sis
> > card arrived, so I'm hopefully get around to test that part of the
> > series rsn. I'm traveling atm though, so response time will suffer a
> > bit.
> 
> Any updates on testing results?

Yes I do. I'm using the patches you posted. Patches 1 to 10 work with no 
problems. Ist patch 11 that breaks the openchrome xorg driver. Have to 
do some digging to find the exact problem.



Re: [PATCH 00/23] kill drm cruft with fire

2011-12-07 Thread James Simmons

   Testing this on via would be awesome! Iirc I haven't changed anything in
   the via specific patches, but if it's more convenient you can also
   directly test my branch:
  
   http://cgit.freedesktop.org/~danvet/drm/log/?h=kill-with-fire
  
   Okay I tried the patches and it locked up the openchrome X server. I'm
   going to try your branch tonight to see if it makes any difference. If it
   still fails I will have to track down what the problem is.
 
  If you can bisect the issue, that would be awesome. Meanwhile my sis
  card arrived, so I'm hopefully get around to test that part of the
  series rsn. I'm traveling atm though, so response time will suffer a
  bit.
 
 Any updates on testing results?

Yes I do. I'm using the patches you posted. Patches 1 to 10 work with no 
problems. Ist patch 11 that breaks the openchrome xorg driver. Have to 
do some digging to find the exact problem.

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


Re: [PATCH 02/23] drm/via: track obj-drm_fd relations in the driver

2011-12-07 Thread James Simmons


 Exactly like the previous patch for sis.
 
 Signed-off-by: Daniel Vetter daniel.vet...@ffwll.ch

Acked-by: James Simmons jsimm...@infradead.org

Same goes for PATCH 01 which I'm missing in my inbox.

 ---
  drivers/gpu/drm/via/via_drv.c |   25 +
  drivers/gpu/drm/via/via_mm.c  |   22 ++
  include/drm/via_drm.h |4 
  3 files changed, 43 insertions(+), 8 deletions(-)
 
 diff --git a/drivers/gpu/drm/via/via_drv.c b/drivers/gpu/drm/via/via_drv.c
 index 920a552..472adcf 100644
 --- a/drivers/gpu/drm/via/via_drv.c
 +++ b/drivers/gpu/drm/via/via_drv.c
 @@ -28,6 +28,29 @@
  
  #include drm_pciids.h
  
 +static int via_driver_open(struct drm_device *dev, struct drm_file *file)
 +{
 + struct via_file_private *file_priv;
 +
 + DRM_DEBUG_DRIVER(\n);
 + file_priv = kmalloc(sizeof(*file_priv), GFP_KERNEL);
 + if (!file_priv)
 + return -ENOMEM;
 +
 + file-driver_priv = file_priv;
 +
 + INIT_LIST_HEAD(file_priv-obj_list);
 +
 + return 0;
 +}
 +
 +void via_driver_postclose(struct drm_device *dev, struct drm_file *file)
 +{
 + struct via_file_private *file_priv = file-driver_priv;
 +
 + kfree(file_priv);
 +}
 +
  static struct pci_device_id pciidlist[] = {
   viadrv_PCI_IDS
  };
 @@ -38,6 +61,8 @@ static struct drm_driver driver = {
   DRIVER_IRQ_SHARED,
   .load = via_driver_load,
   .unload = via_driver_unload,
 + .open = via_driver_open,
 + .postclose = via_driver_postclose,
   .context_dtor = via_final_context,
   .get_vblank_counter = via_get_vblank_counter,
   .enable_vblank = via_enable_vblank,
 diff --git a/drivers/gpu/drm/via/via_mm.c b/drivers/gpu/drm/via/via_mm.c
 index 6cc2dad..19bb77c 100644
 --- a/drivers/gpu/drm/via/via_mm.c
 +++ b/drivers/gpu/drm/via/via_mm.c
 @@ -115,12 +115,13 @@ void via_lastclose(struct drm_device *dev)
  }
  
  int via_mem_alloc(struct drm_device *dev, void *data,
 -   struct drm_file *file_priv)
 +   struct drm_file *file)
  {
   drm_via_mem_t *mem = data;
   int retval = 0;
   struct drm_memblock_item *item;
   drm_via_private_t *dev_priv = (drm_via_private_t *) dev-dev_private;
 + struct via_file_private *file_priv = file-driver_priv;
   unsigned long tmpSize;
  
   if (mem-type  VIA_MEM_AGP) {
 @@ -137,10 +138,10 @@ int via_mem_alloc(struct drm_device *dev, void *data,
   }
  
   tmpSize = (mem-size + VIA_MM_ALIGN_MASK)  VIA_MM_ALIGN_SHIFT;
 - item = drm_sman_alloc(dev_priv-sman, mem-type, tmpSize, 0,
 -   (unsigned long)file_priv);
 - mutex_unlock(dev-struct_mutex);
 + item = drm_sman_alloc(dev_priv-sman, mem-type, tmpSize, 0, 0);
 +
   if (item) {
 + list_move(item-owner_list, file_priv-obj_list);
   mem-offset = ((mem-type == VIA_MEM_VIDEO) ?
 dev_priv-vram_offset : dev_priv-agp_offset) +
   (item-mm-
 @@ -153,6 +154,7 @@ int via_mem_alloc(struct drm_device *dev, void *data,
   DRM_DEBUG(Video memory allocation failed\n);
   retval = -ENOMEM;
   }
 + mutex_unlock(dev-struct_mutex);
  
   return retval;
  }
 @@ -173,12 +175,13 @@ int via_mem_free(struct drm_device *dev, void *data, 
 struct drm_file *file_priv)
  
  
  void via_reclaim_buffers_locked(struct drm_device *dev,
 - struct drm_file *file_priv)
 + struct drm_file *file)
  {
 - drm_via_private_t *dev_priv = dev-dev_private;
 + struct via_file_private *file_priv = file-driver_priv;
 + struct drm_memblock_item *entry, *next;
  
   mutex_lock(dev-struct_mutex);
 - if (drm_sman_owner_clean(dev_priv-sman, (unsigned long)file_priv)) {
 + if (list_empty(file_priv-obj_list)) {
   mutex_unlock(dev-struct_mutex);
   return;
   }
 @@ -186,7 +189,10 @@ void via_reclaim_buffers_locked(struct drm_device *dev,
   if (dev-driver-dma_quiescent)
   dev-driver-dma_quiescent(dev);
  
 - drm_sman_owner_cleanup(dev_priv-sman, (unsigned long)file_priv);
 + list_for_each_entry_safe(entry, next, file_priv-obj_list,
 +  owner_list) {
 + drm_sman_free(entry);
 + }
   mutex_unlock(dev-struct_mutex);
   return;
  }
 diff --git a/include/drm/via_drm.h b/include/drm/via_drm.h
 index fd11a5b..79b3b6e 100644
 --- a/include/drm/via_drm.h
 +++ b/include/drm/via_drm.h
 @@ -274,4 +274,8 @@ typedef struct drm_via_dmablit {
   drm_via_blitsync_t sync;
  } drm_via_dmablit_t;
  
 +struct via_file_private {
 + struct list_head obj_list;
 +};
 +
  #endif   /* _VIA_DRM_H_ */
 -- 
 1.7.7.1
 
 ___
 dri-devel mailing list
 dri-devel@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/dri-devel

Re: [PATCH 03/23] drm/sman: kill owner tracking interface functions

2011-12-07 Thread James Simmons

 These are now unused.
 
 Signed-off-by: Daniel Vetter daniel.vet...@ffwll.ch

Acked-by: James Simmons jsimm...@infradead.org

 ---
  drivers/gpu/drm/drm_sman.c |   38 --
  include/drm/drm_sman.h |   19 ---
  2 files changed, 0 insertions(+), 57 deletions(-)
 
 diff --git a/drivers/gpu/drm/drm_sman.c b/drivers/gpu/drm/drm_sman.c
 index 37548b7..a672fea 100644
 --- a/drivers/gpu/drm/drm_sman.c
 +++ b/drivers/gpu/drm/drm_sman.c
 @@ -278,27 +278,6 @@ static void drm_sman_remove_owner(struct drm_sman *sman,
   kfree(owner_item);
  }
  
 -int drm_sman_owner_clean(struct drm_sman *sman, unsigned long owner)
 -{
 -
 - struct drm_hash_item *hash_item;
 - struct drm_owner_item *owner_item;
 -
 - if (drm_ht_find_item(sman-owner_hash_tab, owner, hash_item)) {
 - return -1;
 - }
 -
 - owner_item = drm_hash_entry(hash_item, struct drm_owner_item, 
 owner_hash);
 - if (owner_item-mem_blocks.next == owner_item-mem_blocks) {
 - drm_sman_remove_owner(sman, owner_item);
 - return -1;
 - }
 -
 - return 0;
 -}
 -
 -EXPORT_SYMBOL(drm_sman_owner_clean);
 -
  static void drm_sman_do_owner_cleanup(struct drm_sman *sman,
 struct drm_owner_item *owner_item)
  {
 @@ -311,23 +290,6 @@ static void drm_sman_do_owner_cleanup(struct drm_sman 
 *sman,
   drm_sman_remove_owner(sman, owner_item);
  }
  
 -void drm_sman_owner_cleanup(struct drm_sman *sman, unsigned long owner)
 -{
 -
 - struct drm_hash_item *hash_item;
 - struct drm_owner_item *owner_item;
 -
 - if (drm_ht_find_item(sman-owner_hash_tab, owner, hash_item)) {
 -
 - return;
 - }
 -
 - owner_item = drm_hash_entry(hash_item, struct drm_owner_item, 
 owner_hash);
 - drm_sman_do_owner_cleanup(sman, owner_item);
 -}
 -
 -EXPORT_SYMBOL(drm_sman_owner_cleanup);
 -
  void drm_sman_cleanup(struct drm_sman *sman)
  {
   struct drm_owner_item *entry, *next;
 diff --git a/include/drm/drm_sman.h b/include/drm/drm_sman.h
 index 3b65ccf..d5ed903 100644
 --- a/include/drm/drm_sman.h
 +++ b/include/drm/drm_sman.h
 @@ -149,25 +149,6 @@ extern int drm_sman_free_key(struct drm_sman * sman, 
 unsigned int key);
  extern void drm_sman_free(struct drm_memblock_item *item);
  
  /*
 - * returns 1 iff there are no stale memory blocks associated with this owner.
 - * Typically called to determine if we need to idle the hardware and call
 - * drm_sman_owner_cleanup. If there are no stale memory blocks, it removes 
 all
 - * resources associated with owner.
 - */
 -
 -extern int drm_sman_owner_clean(struct drm_sman * sman, unsigned long owner);
 -
 -/*
 - * Frees all stale memory blocks associated with this owner. Note that this
 - * requires that the hardware is finished with all blocks, so the graphics 
 engine
 - * should be idled before this call is made. This function also frees
 - * any resources associated with owner and should be called when owner
 - * is not going to be referenced anymore.
 - */
 -
 -extern void drm_sman_owner_cleanup(struct drm_sman * sman, unsigned long 
 owner);
 -
 -/*
   * Frees all stale memory blocks associated with the memory manager.
   * See idling above.
   */
 -- 
 1.7.7.1
 
 ___
 dri-devel mailing list
 dri-devel@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/dri-devel
 
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


  1   2   >