[PATCH 2/2] drm: add an fb creation ioctl that takes a pixel format v5

2011-11-18 Thread Seung-Woo Kim
Hi Jesse,

2011/11/15 Jesse Barnes 
>
> To properly support the various plane formats supported by different
> hardware, the kernel must know the pixel format of a framebuffer object.
> So add a new ioctl taking a format argument corresponding to a fourcc
> name from the new drm_fourcc.h header file. Implement the fb creation
> hooks in terms of the new mode_fb_cmd2 using helpers where the old
> bpp/depth values are needed.
>
> v2: create DRM specific fourcc header file for sharing with libdrm etc
> v3: fix rebase failure and use DRM fourcc codes in intel_display.c and
> update commit message
> v4: make fb_cmd2 handle field into an array for multi-object formats
> pull in Ville's fix for the memcpy in drm_plane_init
> apply Ville's cleanup to zero out fb_cmd2 arg in drm_mode_addfb
> v5: add 'flags' field for interlaced support (from Ville)
>
> Signed-off-by: Ville Syrj?l? 
> Acked-by: Alan Cox 
> Reviewed-by: Rob Clark 
> Signed-off-by: Jesse Barnes 
> ---
> drivers/gpu/drm/drm_crtc.c | 111 +++--
> drivers/gpu/drm/drm_crtc_helper.c | 51 -
> drivers/gpu/drm/drm_drv.c | 1 +
> drivers/gpu/drm/i915/intel_display.c | 39 ++-
> drivers/gpu/drm/i915/intel_drv.h | 2 +-
> drivers/gpu/drm/i915/intel_fb.c | 11 ++--
> drivers/gpu/drm/nouveau/nouveau_display.c | 6 +-
> drivers/gpu/drm/nouveau/nouveau_fb.h | 2 +-
> drivers/gpu/drm/nouveau/nouveau_fbcon.c | 13 ++--
> drivers/gpu/drm/radeon/radeon_display.c | 8 +-
> drivers/gpu/drm/radeon/radeon_fb.c | 18 +++--
> drivers/gpu/drm/radeon/radeon_mode.h | 2 +-
> drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 22 --
> drivers/gpu/drm/vmwgfx/vmwgfx_kms.h | 1 +
> drivers/staging/gma500/framebuffer.c | 2 +-
> include/drm/drm.h | 1 +
> include/drm/drm_crtc.h | 9 ++-
> include/drm/drm_crtc_helper.h | 4 +-
> include/drm/drm_fourcc.h | 63 
> include/drm/drm_mode.h | 27 +++
> 20 files changed, 327 insertions(+), 66 deletions(-)
> create mode 100644 include/drm/drm_fourcc.h
>



> diff --git a/drivers/staging/gma500/framebuffer.c
b/drivers/staging/gma500/framebuffer.c
> index 3f39a37..1e77229 100644
> --- a/drivers/staging/gma500/framebuffer.c
> +++ b/drivers/staging/gma500/framebuffer.c
> @@ -546,7 +546,7 @@ out_err1:
> */
> static struct drm_framebuffer *psb_user_framebuffer_create
> (struct drm_device *dev, struct drm_file *filp,
> - struct drm_mode_fb_cmd *cmd)
> + struct drm_mode_fb_cmd2 *cmd)
> {
> struct gtt_range *r;
> struct drm_gem_object *obj;

I have no idea that this staging driver is really used or not, but anyway
if drm_mode_fb_cmd2 is
used here, then also it looks like that *cmd->handle* and
*psb_framebuffer_create(dev, cmd, r)*
are changed.

psb_framebuffer_create() and psb_framebuffer_init() still use
drm_mode_fb_cmd, so maybe
changed like vmwgfx_kms.c.



> +++ b/include/drm/drm_mode.h
> @@ -266,6 +266,33 @@ struct drm_mode_fb_cmd {
> __u32 handle;
> };
>
> +#define DRM_MODE_FB_INTERLACED (1<<0 /* for interlaced framebuffers */
> +
> +struct drm_mode_fb_cmd2 {
> + __u32 fb_id;
> + __u32 width, height;
> + __u32 pixel_format; /* fourcc code from drm_fourcc.h */
> + __u32 flags; /* see above flags */
> +
> + /*
> + * In case of planar formats, this ioctl allows up to 4
> + * buffer objects with offets and pitches per plane.
> + * The pitch and offset order is dictated by the fourcc,
> + * e.g. NV12 (http://fourcc.org/yuv.php#NV12) is described as:
> + *
> + * YUV 4:2:0 image with a plane of 8 bit Y samples
> + * followed by an interleaved U/V plane containing
> + * 8 bit 2x2 subsampled colour difference samples.
> + *
> + * So it would consist of Y as offset[0] and UV as
> + * offeset[1]. Note that offset[0] will generally
> + * be 0.
> + */
> + __u32 handles[4];
> + __u32 pitches[4]; /* pitch for each plane */
> + __u32 offsets[4]; /* offset of each plane */
> +};



Regards,
- Seung-Woo Kim
-- next part --
An HTML attachment was scrubbed...
URL: 



[PATCH 2/2] drm: add an fb creation ioctl that takes a pixel format v5

2011-11-14 Thread Jesse Barnes
To properly support the various plane formats supported by different
hardware, the kernel must know the pixel format of a framebuffer object.
So add a new ioctl taking a format argument corresponding to a fourcc
name from the new drm_fourcc.h header file.  Implement the fb creation
hooks in terms of the new mode_fb_cmd2 using helpers where the old
bpp/depth values are needed.

v2: create DRM specific fourcc header file for sharing with libdrm etc
v3: fix rebase failure and use DRM fourcc codes in intel_display.c and
update commit message
v4: make fb_cmd2 handle field into an array for multi-object formats
pull in Ville's fix for the memcpy in drm_plane_init
apply Ville's cleanup to zero out fb_cmd2 arg in drm_mode_addfb
v5: add 'flags' field for interlaced support (from Ville)

Signed-off-by: Ville Syrj?l? 
Acked-by: Alan Cox 
Reviewed-by: Rob Clark 
Signed-off-by: Jesse Barnes 
---
 drivers/gpu/drm/drm_crtc.c|  111 +++--
 drivers/gpu/drm/drm_crtc_helper.c |   51 -
 drivers/gpu/drm/drm_drv.c |1 +
 drivers/gpu/drm/i915/intel_display.c  |   39 ++-
 drivers/gpu/drm/i915/intel_drv.h  |2 +-
 drivers/gpu/drm/i915/intel_fb.c   |   11 ++--
 drivers/gpu/drm/nouveau/nouveau_display.c |6 +-
 drivers/gpu/drm/nouveau/nouveau_fb.h  |2 +-
 drivers/gpu/drm/nouveau/nouveau_fbcon.c   |   13 ++--
 drivers/gpu/drm/radeon/radeon_display.c   |8 +-
 drivers/gpu/drm/radeon/radeon_fb.c|   18 +++--
 drivers/gpu/drm/radeon/radeon_mode.h  |2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c   |   22 --
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.h   |1 +
 drivers/staging/gma500/framebuffer.c  |2 +-
 include/drm/drm.h |1 +
 include/drm/drm_crtc.h|9 ++-
 include/drm/drm_crtc_helper.h |4 +-
 include/drm/drm_fourcc.h  |   63 
 include/drm/drm_mode.h|   27 +++
 20 files changed, 327 insertions(+), 66 deletions(-)
 create mode 100644 include/drm/drm_fourcc.h

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 804ef12..30a70a4 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -35,6 +35,7 @@
 #include "drmP.h"
 #include "drm_crtc.h"
 #include "drm_edid.h"
+#include "drm_fourcc.h"

 struct drm_prop_enum_list {
int type;
@@ -563,7 +564,7 @@ int drm_plane_init(struct drm_device *dev, struct drm_plane 
*plane,
return -ENOMEM;
}

-   memcpy(plane->format_types, formats, format_count);
+   memcpy(plane->format_types, formats, format_count * sizeof(uint32_t));
plane->format_count = format_count;
plane->possible_crtcs = possible_crtcs;

@@ -1910,6 +1911,42 @@ out:
return ret;
 }

+/* Original addfb only supported RGB formats, so figure out which one */
+uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
+{
+   uint32_t fmt;
+
+   switch (bpp) {
+   case 8:
+   fmt = DRM_FOURCC_RGB332;
+   break;
+   case 16:
+   if (depth == 15)
+   fmt = DRM_FOURCC_RGB555;
+   else
+   fmt = DRM_FOURCC_RGB565;
+   break;
+   case 24:
+   fmt = DRM_FOURCC_RGB24;
+   break;
+   case 32:
+   if (depth == 24)
+   fmt = DRM_FOURCC_RGB24;
+   else if (depth == 30)
+   fmt = DRM_INTEL_RGB30;
+   else
+   fmt = DRM_FOURCC_RGB32;
+   break;
+   default:
+   DRM_ERROR("bad bpp, assuming RGB24 pixel format\n");
+   fmt = DRM_FOURCC_RGB24;
+   break;
+   }
+
+   return fmt;
+}
+EXPORT_SYMBOL(drm_mode_legacy_fb_format);
+
 /**
  * drm_mode_addfb - add an FB to the graphics configuration
  * @inode: inode from the ioctl
@@ -1930,7 +1967,74 @@ out:
 int drm_mode_addfb(struct drm_device *dev,
   void *data, struct drm_file *file_priv)
 {
-   struct drm_mode_fb_cmd *r = data;
+   struct drm_mode_fb_cmd *or = data;
+   struct drm_mode_fb_cmd2 r = {};
+   struct drm_mode_config *config = >mode_config;
+   struct drm_framebuffer *fb;
+   int ret = 0;
+
+   /* Use new struct with format internally */
+   r.fb_id = or->fb_id;
+   r.width = or->width;
+   r.height = or->height;
+   r.pitches[0] = or->pitch;
+   r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth);
+   r.handles[0] = or->handle;
+
+   if (!drm_core_check_feature(dev, DRIVER_MODESET))
+   return -EINVAL;
+
+   if ((config->min_width > r.width) || (r.width > config->max_width)) {
+   DRM_ERROR("mode new framebuffer width not within limits\n");
+   return -EINVAL;
+   }
+   if 

[PATCH 2/2] drm: add an fb creation ioctl that takes a pixel format v5

2011-11-14 Thread Jesse Barnes
To properly support the various plane formats supported by different
hardware, the kernel must know the pixel format of a framebuffer object.
So add a new ioctl taking a format argument corresponding to a fourcc
name from the new drm_fourcc.h header file.  Implement the fb creation
hooks in terms of the new mode_fb_cmd2 using helpers where the old
bpp/depth values are needed.

v2: create DRM specific fourcc header file for sharing with libdrm etc
v3: fix rebase failure and use DRM fourcc codes in intel_display.c and
update commit message
v4: make fb_cmd2 handle field into an array for multi-object formats
pull in Ville's fix for the memcpy in drm_plane_init
apply Ville's cleanup to zero out fb_cmd2 arg in drm_mode_addfb
v5: add 'flags' field for interlaced support (from Ville)

Signed-off-by: Ville Syrjälä ville.syrj...@linux.intel.com
Acked-by: Alan Cox a...@lxorguk.ukuu.org.uk
Reviewed-by: Rob Clark rob.cl...@linaro.org
Signed-off-by: Jesse Barnes jbar...@virtuousgeek.org
---
 drivers/gpu/drm/drm_crtc.c|  111 +++--
 drivers/gpu/drm/drm_crtc_helper.c |   51 -
 drivers/gpu/drm/drm_drv.c |1 +
 drivers/gpu/drm/i915/intel_display.c  |   39 ++-
 drivers/gpu/drm/i915/intel_drv.h  |2 +-
 drivers/gpu/drm/i915/intel_fb.c   |   11 ++--
 drivers/gpu/drm/nouveau/nouveau_display.c |6 +-
 drivers/gpu/drm/nouveau/nouveau_fb.h  |2 +-
 drivers/gpu/drm/nouveau/nouveau_fbcon.c   |   13 ++--
 drivers/gpu/drm/radeon/radeon_display.c   |8 +-
 drivers/gpu/drm/radeon/radeon_fb.c|   18 +++--
 drivers/gpu/drm/radeon/radeon_mode.h  |2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c   |   22 --
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.h   |1 +
 drivers/staging/gma500/framebuffer.c  |2 +-
 include/drm/drm.h |1 +
 include/drm/drm_crtc.h|9 ++-
 include/drm/drm_crtc_helper.h |4 +-
 include/drm/drm_fourcc.h  |   63 
 include/drm/drm_mode.h|   27 +++
 20 files changed, 327 insertions(+), 66 deletions(-)
 create mode 100644 include/drm/drm_fourcc.h

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 804ef12..30a70a4 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -35,6 +35,7 @@
 #include drmP.h
 #include drm_crtc.h
 #include drm_edid.h
+#include drm_fourcc.h
 
 struct drm_prop_enum_list {
int type;
@@ -563,7 +564,7 @@ int drm_plane_init(struct drm_device *dev, struct drm_plane 
*plane,
return -ENOMEM;
}
 
-   memcpy(plane-format_types, formats, format_count);
+   memcpy(plane-format_types, formats, format_count * sizeof(uint32_t));
plane-format_count = format_count;
plane-possible_crtcs = possible_crtcs;
 
@@ -1910,6 +1911,42 @@ out:
return ret;
 }
 
+/* Original addfb only supported RGB formats, so figure out which one */
+uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
+{
+   uint32_t fmt;
+
+   switch (bpp) {
+   case 8:
+   fmt = DRM_FOURCC_RGB332;
+   break;
+   case 16:
+   if (depth == 15)
+   fmt = DRM_FOURCC_RGB555;
+   else
+   fmt = DRM_FOURCC_RGB565;
+   break;
+   case 24:
+   fmt = DRM_FOURCC_RGB24;
+   break;
+   case 32:
+   if (depth == 24)
+   fmt = DRM_FOURCC_RGB24;
+   else if (depth == 30)
+   fmt = DRM_INTEL_RGB30;
+   else
+   fmt = DRM_FOURCC_RGB32;
+   break;
+   default:
+   DRM_ERROR(bad bpp, assuming RGB24 pixel format\n);
+   fmt = DRM_FOURCC_RGB24;
+   break;
+   }
+
+   return fmt;
+}
+EXPORT_SYMBOL(drm_mode_legacy_fb_format);
+
 /**
  * drm_mode_addfb - add an FB to the graphics configuration
  * @inode: inode from the ioctl
@@ -1930,7 +1967,74 @@ out:
 int drm_mode_addfb(struct drm_device *dev,
   void *data, struct drm_file *file_priv)
 {
-   struct drm_mode_fb_cmd *r = data;
+   struct drm_mode_fb_cmd *or = data;
+   struct drm_mode_fb_cmd2 r = {};
+   struct drm_mode_config *config = dev-mode_config;
+   struct drm_framebuffer *fb;
+   int ret = 0;
+
+   /* Use new struct with format internally */
+   r.fb_id = or-fb_id;
+   r.width = or-width;
+   r.height = or-height;
+   r.pitches[0] = or-pitch;
+   r.pixel_format = drm_mode_legacy_fb_format(or-bpp, or-depth);
+   r.handles[0] = or-handle;
+
+   if (!drm_core_check_feature(dev, DRIVER_MODESET))
+   return -EINVAL;
+
+   if ((config-min_width  r.width) || (r.width  config-max_width)) {
+   DRM_ERROR(mode new framebuffer width not within