From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jesse Barnes Subject: Re: [RFC] Updated DRM plane handling patches Date: Thu, 21 Jul 2011 10:15:54 -0700 Message-ID: <20110721101554.77ca3134@jbarnes-desktop> References: <1307477262-8242-1-git-send-email-jbarnes@virtuousgeek.org> <20110615102911.3fa27a7a@jbarnes-desktop> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org Errors-To: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org To: Joonyoung Shim Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org On Thu, 21 Jul 2011 19:15:24 +0900 Joonyoung Shim wrote: > Hi, > = > 2011/6/16 Jesse Barnes : > > On Tue, =A07 Jun 2011 13:07:38 -0700 > > Jesse Barnes wrote: > > > >> This patchset updates the previous one, incorporating the feedback I > >> received: > >> =A0 1) uses the v4l fourcc codes to communicate pixel format > >> =A0 2) adds a new addfb ioctl that takes a format > >> =A0 3) adds working SNB support for the new code > >> > >> Comments welcome. =A0I'll be pushing intel-gpu-tools testdisplay suppo= rt > >> for this shortly if people want to play around with it. =A0Next step i= s to > >> incorporate it into X and Wayland to see if the API is rich enough for > >> our needs. > > > > And here's a very early & hackish DDX patch for this code in case other > > people want to test things out. =A0I still have to update it with the > > scaling stuff we talked about and support various things (disabling > > planes, controlling attributes, etc) but it's enough to get bits on the > > screen at least. > > > = > Could you share libdrm patch for drm plane? > = Sure, see below. You'll also need to update the copy of the libdrm headers from the patched sources. -- = Jesse Barnes, Intel Open Source Technology Center >>From 38e64d416a6d1ae41b7a0867e4d4c2c44ea42941 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Fri, 29 Apr 2011 08:54:25 -0700 Subject: [PATCH 2/2] libdrm: add plane handling functions & structs --- include/drm/drm.h | 7 +- include/drm/drm_mode.h | 33 +++++++---- xf86drmMode.c | 148 ++++++++++++++++++++++++++++++++++++++++++++= ++++ xf86drmMode.h | 29 +++++++++ 4 files changed, 201 insertions(+), 16 deletions(-) diff --git a/include/drm/drm.h b/include/drm/drm.h index cd384f2..bb2dea8 100644 --- a/include/drm/drm.h +++ b/include/drm/drm.h @@ -718,9 +718,10 @@ struct drm_get_cap { #define DRM_IOCTL_MODE_CREATE_DUMB DRM_IOWR(0xB2, struct drm_mode_create_d= umb) #define DRM_IOCTL_MODE_MAP_DUMB DRM_IOWR(0xB3, struct drm_mode_map_dumb) #define DRM_IOCTL_MODE_DESTROY_DUMB DRM_IOWR(0xB4, struct drm_mode_dest= roy_dumb) -#define DRM_IOCTL_MODE_GETOVERLAYRESOURCES DRM_IOWR(0xB5, struct drm_mode_= get_overlay_res) -#define DRM_IOCTL_MODE_GETOVERLAY DRM_IOWR(0xB6, struct drm_mode_get_overl= ay) -#define DRM_IOCTL_MODE_SETOVERLAY DRM_IOWR(0xB7, struct drm_mode_set_overl= ay) +#define DRM_IOCTL_MODE_GETPLANERESOURCES DRM_IOWR(0xB5, struct drm_mode_ge= t_plane_res) +#define DRM_IOCTL_MODE_GETPLANE DRM_IOWR(0xB6, struct drm_mode_get_plane) +#define DRM_IOCTL_MODE_SETPLANE DRM_IOWR(0xB7, struct drm_mode_set_plane) +#define DRM_IOCTL_MODE_ADDFB2 DRM_IOWR(0xB8, struct drm_mode_fb_cmd2) = /** * Device specific ioctls should only be in their respective headers diff --git a/include/drm/drm_mode.h b/include/drm/drm_mode.h index 349052a..4c5f01f 100644 --- a/include/drm/drm_mode.h +++ b/include/drm/drm_mode.h @@ -120,14 +120,9 @@ struct drm_mode_crtc { struct drm_mode_modeinfo mode; }; = -#define DRM_MODE_OVERLAY_FORMAT_YUV422 1 /* YUV 4:2:2 packed */ -#define DRM_MODE_OVERLAY_FORMAT_RGBX101010 2 /* RGB 10bpc, ign. alpha */ -#define DRM_MODE_OVERLAY_FORMAT_RGBX888 3 /* Standard x:8:8:8 RGB */ -#define DRM_MODE_OVERLAY_FORMAT_RGBX161616 4 /* x:16:16:16 float RGB */ - -/* Overlays blend with or override other bits on the CRTC */ -struct drm_mode_set_overlay { - __u32 overlay_id; +/* Planes blend with or override other bits on the CRTC */ +struct drm_mode_set_plane { + __u32 plane_id; __u32 crtc_id; __u32 fb_id; /* contains surface format type */ = @@ -137,9 +132,9 @@ struct drm_mode_set_overlay { /* FIXME: color key/mask, scaling, z-order, other? */ }; = -struct drm_mode_get_overlay { +struct drm_mode_get_plane { __u64 format_type_ptr; - __u32 overlay_id; + __u32 plane_id; = __u32 crtc_id; __u32 fb_id; @@ -154,9 +149,9 @@ struct drm_mode_get_overlay { }; = = -struct drm_mode_get_overlay_res { - __u64 overlay_id_ptr; - __u32 count_overlays; +struct drm_mode_get_plane_res { + __u64 plane_id_ptr; + __u32 count_planes; }; = #define DRM_MODE_ENCODER_NONE 0 @@ -268,6 +263,18 @@ struct drm_mode_fb_cmd { __u32 handle; }; = +/* For addfb2 ioctl, contains format info */ +struct drm_mode_fb_cmd2 { + __u32 fb_id; + __u32 width, height; + __u32 pitch; + __u32 bpp; + __u32 depth; + __u32 pixel_format; /* fourcc code from videodev2.h */ + /* driver specific handle */ + __u32 handle; +}; + #define DRM_MODE_FB_DIRTY_ANNOTATE_COPY 0x01 #define DRM_MODE_FB_DIRTY_ANNOTATE_FILL 0x02 #define DRM_MODE_FB_DIRTY_FLAGS 0x03 diff --git a/xf86drmMode.c b/xf86drmMode.c index 0d268fc..cf62412 100644 --- a/xf86drmMode.c +++ b/xf86drmMode.c @@ -255,6 +255,28 @@ int drmModeAddFB(int fd, uint32_t width, uint32_t heig= ht, uint8_t depth, return 0; } = +int drmModeAddFB2(int fd, uint32_t width, uint32_t height, + uint32_t pixel_format, uint8_t depth, uint8_t bpp, + uint32_t pitch, uint32_t bo_handle, uint32_t *buf_id) +{ + struct drm_mode_fb_cmd2 f; + int ret; + + f.width =3D width; + f.height =3D height; + f.pitch =3D pitch; + f.bpp =3D bpp; + f.depth =3D depth; + f.pixel_format =3D pixel_format; + f.handle =3D bo_handle; + + if ((ret =3D DRM_IOCTL(fd, DRM_IOCTL_MODE_ADDFB2, &f))) + return ret; + + *buf_id =3D f.fb_id; + return 0; +} + int drmModeRmFB(int fd, uint32_t bufferId) { return DRM_IOCTL(fd, DRM_IOCTL_MODE_RMFB, &bufferId); @@ -806,3 +828,129 @@ int drmModePageFlip(int fd, uint32_t crtc_id, uint32_= t fb_id, = return DRM_IOCTL(fd, DRM_IOCTL_MODE_PAGE_FLIP, &flip); } + +int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id, + uint32_t fb_id, uint32_t crtc_x, uint32_t crtc_y, + uint32_t x, uint32_t y) + +{ + struct drm_mode_set_plane s; + + s.plane_id =3D plane_id; + s.crtc_id =3D crtc_id; + s.fb_id =3D fb_id; + s.crtc_x =3D crtc_x; + s.crtc_y =3D crtc_y; + s.x =3D x; + s.y =3D y; + + return DRM_IOCTL(fd, DRM_IOCTL_MODE_SETPLANE, &s); +} + + +drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id) +{ + struct drm_mode_get_plane ovr, counts; + drmModePlanePtr r =3D 0; + +retry: + memset(&ovr, 0, sizeof(struct drm_mode_get_plane)); + ovr.plane_id =3D plane_id; + if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr)) + return 0; + + counts =3D ovr; + + if (ovr.count_format_types) { + ovr.format_type_ptr =3D VOID2U64(drmMalloc(ovr.count_format_types * + sizeof(uint32_t))); + if (!ovr.format_type_ptr) + goto err_allocs; + } + + if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANE, &ovr)) + goto err_allocs; + + if (counts.count_format_types < ovr.count_format_types) { + drmFree(U642VOID(ovr.format_type_ptr)); + goto retry; + } + + if (!(r =3D drmMalloc(sizeof(*r)))) + goto err_allocs; + + r->count_formats =3D ovr.count_format_types; + r->plane_id =3D ovr.plane_id; + r->crtc_id =3D ovr.crtc_id; + r->fb_id =3D ovr.fb_id; + r->crtc_x =3D ovr.crtc_x; + r->crtc_y =3D ovr.crtc_y; + r->x =3D ovr.x; + r->y =3D ovr.y; + r->possible_crtcs =3D ovr.possible_crtcs; + r->gamma_size =3D ovr.gamma_size; + r->formats =3D drmAllocCpy(U642VOID(ovr.format_type_ptr), + ovr.count_format_types, sizeof(uint32_t)); + if (ovr.count_format_types && !r->formats) { + drmFree(r->formats); + r =3D 0; + } + +err_allocs: + drmFree(U642VOID(ovr.format_type_ptr)); + + return r; +} + +void drmModeFreePlane(drmModePlanePtr ptr) +{ + if (!ptr) + return; + + drmFree(ptr->formats); + drmFree(ptr); +} + +drmModePlaneResPtr drmModeGetPlaneResources(int fd) +{ + struct drm_mode_get_plane_res res, counts; + drmModePlaneResPtr r =3D 0; + +retry: + memset(&res, 0, sizeof(struct drm_mode_get_plane_res)); + if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &res)) + return 0; + + counts =3D res; + + if (res.count_planes) { + res.plane_id_ptr =3D VOID2U64(drmMalloc(res.count_planes * + sizeof(uint32_t))); + if (!res.plane_id_ptr) + goto err_allocs; + } + + if (drmIoctl(fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &res)) + goto err_allocs; + + if (counts.count_planes < res.count_planes) { + drmFree(U642VOID(res.plane_id_ptr)); + goto retry; + } + + if (!(r =3D drmMalloc(sizeof(*r)))) + goto err_allocs; + + r->count_planes =3D res.count_planes; + r->planes =3D drmAllocCpy(U642VOID(res.plane_id_ptr), + res.count_planes, sizeof(uint32_t)); + if (res.count_planes && !r->planes) { + drmFree(r->planes); + r =3D 0; + } + +err_allocs: + drmFree(U642VOID(res.plane_id_ptr)); + + return r; +} diff --git a/xf86drmMode.h b/xf86drmMode.h index ee7c454..5d36ba5 100644 --- a/xf86drmMode.h +++ b/xf86drmMode.h @@ -33,6 +33,7 @@ * */ = +#include #include = /* @@ -274,7 +275,25 @@ typedef struct _drmModeConnector { uint32_t *encoders; /**< List of encoder ids */ } drmModeConnector, *drmModeConnectorPtr; = +typedef struct _drmModePlane { + uint32_t count_formats; + uint32_t *formats; + uint32_t plane_id; = + uint32_t crtc_id; + uint32_t fb_id; + + uint32_t crtc_x, crtc_y; + uint32_t x, y; + + uint32_t possible_crtcs; + uint32_t gamma_size; +} drmModePlane, *drmModePlanePtr; + +typedef struct _drmModePlaneRes { + uint32_t count_planes; + uint32_t *planes; +} drmModePlaneRes, *drmModePlaneResPtr; = extern void drmModeFreeModeInfo( drmModeModeInfoPtr ptr ); extern void drmModeFreeResources( drmModeResPtr ptr ); @@ -282,6 +301,7 @@ extern void drmModeFreeFB( drmModeFBPtr ptr ); extern void drmModeFreeCrtc( drmModeCrtcPtr ptr ); extern void drmModeFreeConnector( drmModeConnectorPtr ptr ); extern void drmModeFreeEncoder( drmModeEncoderPtr ptr ); +extern void drmModeFreePlane( drmModePlanePtr ptr ); = /** * Retrives all of the resources associated with a card. @@ -303,6 +323,10 @@ extern drmModeFBPtr drmModeGetFB(int fd, uint32_t buff= erId); extern int drmModeAddFB(int fd, uint32_t width, uint32_t height, uint8_t d= epth, uint8_t bpp, uint32_t pitch, uint32_t bo_handle, uint32_t *buf_id); +/* ...with a specific pixel format */ +extern int drmModeAddFB2(int fd, uint32_t width, uint32_t height, + uint32_t pixel_format, uint8_t depth, uint8_t bpp, + uint32_t pitch, uint32_t bo_handle, uint32_t *buf_id); /** * Destroies the given framebuffer. */ @@ -386,3 +410,8 @@ extern int drmModeCrtcGetGamma(int fd, uint32_t crtc_id= , uint32_t size, uint16_t *red, uint16_t *green, uint16_t *blue); extern int drmModePageFlip(int fd, uint32_t crtc_id, uint32_t fb_id, uint32_t flags, void *user_data); +extern drmModePlaneResPtr drmModeGetPlaneResources(int fd); +extern drmModePlanePtr drmModeGetPlane(int fd, uint32_t plane_id); +extern int drmModeSetPlane(int fd, uint32_t plane_id, uint32_t crtc_id, + uint32_t fb_id, uint32_t crtc_x, uint32_t crtc_y, + uint32_t x, uint32_t y); -- = 1.7.4.1