Skip to content

Commit 308e5bc

Browse files
jbarnes993airlied
authored andcommitted
drm: add an fb creation ioctl that takes a pixel format v5
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.syrjala@linux.intel.com> Acked-by: Alan Cox <alan@lxorguk.ukuu.org.uk> Reviewed-by: Rob Clark <rob.clark@linaro.org> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent 8cf5c91 commit 308e5bc

20 files changed

Lines changed: 327 additions & 66 deletions

‎drivers/gpu/drm/drm_crtc.c‎

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "drmP.h"
3737
#include "drm_crtc.h"
3838
#include "drm_edid.h"
39+
#include "drm_fourcc.h"
3940

4041
struct drm_prop_enum_list {
4142
int type;
@@ -568,7 +569,7 @@ int drm_plane_init(struct drm_device *dev, struct drm_plane *plane,
568569
return -ENOMEM;
569570
}
570571

571-
memcpy(plane->format_types, formats, format_count);
572+
memcpy(plane->format_types, formats, format_count * sizeof(uint32_t));
572573
plane->format_count = format_count;
573574
plane->possible_crtcs = possible_crtcs;
574575

@@ -1915,6 +1916,42 @@ int drm_mode_cursor_ioctl(struct drm_device *dev,
19151916
return ret;
19161917
}
19171918

1919+
/* Original addfb only supported RGB formats, so figure out which one */
1920+
uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
1921+
{
1922+
uint32_t fmt;
1923+
1924+
switch (bpp) {
1925+
case 8:
1926+
fmt = DRM_FOURCC_RGB332;
1927+
break;
1928+
case 16:
1929+
if (depth == 15)
1930+
fmt = DRM_FOURCC_RGB555;
1931+
else
1932+
fmt = DRM_FOURCC_RGB565;
1933+
break;
1934+
case 24:
1935+
fmt = DRM_FOURCC_RGB24;
1936+
break;
1937+
case 32:
1938+
if (depth == 24)
1939+
fmt = DRM_FOURCC_RGB24;
1940+
else if (depth == 30)
1941+
fmt = DRM_INTEL_RGB30;
1942+
else
1943+
fmt = DRM_FOURCC_RGB32;
1944+
break;
1945+
default:
1946+
DRM_ERROR("bad bpp, assuming RGB24 pixel format\n");
1947+
fmt = DRM_FOURCC_RGB24;
1948+
break;
1949+
}
1950+
1951+
return fmt;
1952+
}
1953+
EXPORT_SYMBOL(drm_mode_legacy_fb_format);
1954+
19181955
/**
19191956
* drm_mode_addfb - add an FB to the graphics configuration
19201957
* @inode: inode from the ioctl
@@ -1935,7 +1972,74 @@ int drm_mode_cursor_ioctl(struct drm_device *dev,
19351972
int drm_mode_addfb(struct drm_device *dev,
19361973
void *data, struct drm_file *file_priv)
19371974
{
1938-
struct drm_mode_fb_cmd *r = data;
1975+
struct drm_mode_fb_cmd *or = data;
1976+
struct drm_mode_fb_cmd2 r = {};
1977+
struct drm_mode_config *config = &dev->mode_config;
1978+
struct drm_framebuffer *fb;
1979+
int ret = 0;
1980+
1981+
/* Use new struct with format internally */
1982+
r.fb_id = or->fb_id;
1983+
r.width = or->width;
1984+
r.height = or->height;
1985+
r.pitches[0] = or->pitch;
1986+
r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth);
1987+
r.handles[0] = or->handle;
1988+
1989+
if (!drm_core_check_feature(dev, DRIVER_MODESET))
1990+
return -EINVAL;
1991+
1992+
if ((config->min_width > r.width) || (r.width > config->max_width)) {
1993+
DRM_ERROR("mode new framebuffer width not within limits\n");
1994+
return -EINVAL;
1995+
}
1996+
if ((config->min_height > r.height) || (r.height > config->max_height)) {
1997+
DRM_ERROR("mode new framebuffer height not within limits\n");
1998+
return -EINVAL;
1999+
}
2000+
2001+
mutex_lock(&dev->mode_config.mutex);
2002+
2003+
/* TODO check buffer is sufficiently large */
2004+
/* TODO setup destructor callback */
2005+
2006+
fb = dev->mode_config.funcs->fb_create(dev, file_priv, &r);
2007+
if (IS_ERR(fb)) {
2008+
DRM_ERROR("could not create framebuffer\n");
2009+
ret = PTR_ERR(fb);
2010+
goto out;
2011+
}
2012+
2013+
or->fb_id = fb->base.id;
2014+
list_add(&fb->filp_head, &file_priv->fbs);
2015+
DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id);
2016+
2017+
out:
2018+
mutex_unlock(&dev->mode_config.mutex);
2019+
return ret;
2020+
}
2021+
2022+
/**
2023+
* drm_mode_addfb2 - add an FB to the graphics configuration
2024+
* @inode: inode from the ioctl
2025+
* @filp: file * from the ioctl
2026+
* @cmd: cmd from ioctl
2027+
* @arg: arg from ioctl
2028+
*
2029+
* LOCKING:
2030+
* Takes mode config lock.
2031+
*
2032+
* Add a new FB to the specified CRTC, given a user request with format.
2033+
*
2034+
* Called by the user via ioctl.
2035+
*
2036+
* RETURNS:
2037+
* Zero on success, errno on failure.
2038+
*/
2039+
int drm_mode_addfb2(struct drm_device *dev,
2040+
void *data, struct drm_file *file_priv)
2041+
{
2042+
struct drm_mode_fb_cmd2 *r = data;
19392043
struct drm_mode_config *config = &dev->mode_config;
19402044
struct drm_framebuffer *fb;
19412045
int ret = 0;
@@ -1956,9 +2060,6 @@ int drm_mode_addfb(struct drm_device *dev,
19562060

19572061
mutex_lock(&dev->mode_config.mutex);
19582062

1959-
/* TODO check buffer is sufficiently large */
1960-
/* TODO setup destructor callback */
1961-
19622063
fb = dev->mode_config.funcs->fb_create(dev, file_priv, r);
19632064
if (IS_ERR(fb)) {
19642065
DRM_ERROR("could not create framebuffer\n");

‎drivers/gpu/drm/drm_crtc_helper.c‎

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include "drmP.h"
3636
#include "drm_crtc.h"
37+
#include "drm_fourcc.h"
3738
#include "drm_crtc_helper.h"
3839
#include "drm_fb_helper.h"
3940

@@ -810,14 +811,56 @@ void drm_helper_connector_dpms(struct drm_connector *connector, int mode)
810811
}
811812
EXPORT_SYMBOL(drm_helper_connector_dpms);
812813

814+
/*
815+
* Just need to support RGB formats here for compat with code that doesn't
816+
* use pixel formats directly yet.
817+
*/
818+
void drm_helper_get_fb_bpp_depth(uint32_t format, unsigned int *depth,
819+
int *bpp)
820+
{
821+
switch (format) {
822+
case DRM_FOURCC_RGB332:
823+
*depth = 8;
824+
*bpp = 8;
825+
break;
826+
case DRM_FOURCC_RGB555:
827+
*depth = 15;
828+
*bpp = 16;
829+
break;
830+
case DRM_FOURCC_RGB565:
831+
*depth = 16;
832+
*bpp = 16;
833+
break;
834+
case DRM_FOURCC_RGB24:
835+
*depth = 24;
836+
*bpp = 32;
837+
break;
838+
case DRM_INTEL_RGB30:
839+
*depth = 30;
840+
*bpp = 32;
841+
break;
842+
case DRM_FOURCC_RGB32:
843+
*depth = 32;
844+
*bpp = 32;
845+
break;
846+
default:
847+
DRM_DEBUG_KMS("unsupported pixel format\n");
848+
*depth = 0;
849+
*bpp = 0;
850+
break;
851+
}
852+
}
853+
EXPORT_SYMBOL(drm_helper_get_fb_bpp_depth);
854+
813855
int drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
814-
struct drm_mode_fb_cmd *mode_cmd)
856+
struct drm_mode_fb_cmd2 *mode_cmd)
815857
{
816858
fb->width = mode_cmd->width;
817859
fb->height = mode_cmd->height;
818-
fb->pitch = mode_cmd->pitch;
819-
fb->bits_per_pixel = mode_cmd->bpp;
820-
fb->depth = mode_cmd->depth;
860+
fb->pitch = mode_cmd->pitches[0];
861+
drm_helper_get_fb_bpp_depth(mode_cmd->pixel_format, &fb->depth,
862+
&fb->bits_per_pixel);
863+
fb->pixel_format = mode_cmd->pixel_format;
821864

822865
return 0;
823866
}

‎drivers/gpu/drm/drm_drv.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ static struct drm_ioctl_desc drm_ioctls[] = {
153153
DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPBLOB, drm_mode_getblob_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
154154
DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB, drm_mode_getfb, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
155155
DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB, drm_mode_addfb, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
156+
DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB2, drm_mode_addfb2, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
156157
DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMFB, drm_mode_rmfb, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
157158
DRM_IOCTL_DEF(DRM_IOCTL_MODE_PAGE_FLIP, drm_mode_page_flip_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
158159
DRM_IOCTL_DEF(DRM_IOCTL_MODE_DIRTYFB, drm_mode_dirtyfb_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),

‎drivers/gpu/drm/i915/intel_display.c‎

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6279,7 +6279,7 @@ static struct drm_display_mode load_detect_mode = {
62796279

62806280
static struct drm_framebuffer *
62816281
intel_framebuffer_create(struct drm_device *dev,
6282-
struct drm_mode_fb_cmd *mode_cmd,
6282+
struct drm_mode_fb_cmd2 *mode_cmd,
62836283
struct drm_i915_gem_object *obj)
62846284
{
62856285
struct intel_framebuffer *intel_fb;
@@ -6321,7 +6321,7 @@ intel_framebuffer_create_for_mode(struct drm_device *dev,
63216321
int depth, int bpp)
63226322
{
63236323
struct drm_i915_gem_object *obj;
6324-
struct drm_mode_fb_cmd mode_cmd;
6324+
struct drm_mode_fb_cmd2 mode_cmd;
63256325

63266326
obj = i915_gem_alloc_object(dev,
63276327
intel_framebuffer_size_for_mode(mode, bpp));
@@ -6330,9 +6330,9 @@ intel_framebuffer_create_for_mode(struct drm_device *dev,
63306330

63316331
mode_cmd.width = mode->hdisplay;
63326332
mode_cmd.height = mode->vdisplay;
6333-
mode_cmd.depth = depth;
6334-
mode_cmd.bpp = bpp;
6335-
mode_cmd.pitch = intel_framebuffer_pitch_for_width(mode_cmd.width, bpp);
6333+
mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
6334+
bpp);
6335+
mode_cmd.pixel_format = 0;
63366336

63376337
return intel_framebuffer_create(dev, &mode_cmd, obj);
63386338
}
@@ -7573,29 +7573,31 @@ static const struct drm_framebuffer_funcs intel_fb_funcs = {
75737573

75747574
int intel_framebuffer_init(struct drm_device *dev,
75757575
struct intel_framebuffer *intel_fb,
7576-
struct drm_mode_fb_cmd *mode_cmd,
7576+
struct drm_mode_fb_cmd2 *mode_cmd,
75777577
struct drm_i915_gem_object *obj)
75787578
{
75797579
int ret;
75807580

75817581
if (obj->tiling_mode == I915_TILING_Y)
75827582
return -EINVAL;
75837583

7584-
if (mode_cmd->pitch & 63)
7584+
if (mode_cmd->pitches[0] & 63)
75857585
return -EINVAL;
75867586

7587-
switch (mode_cmd->bpp) {
7588-
case 8:
7589-
case 16:
7590-
/* Only pre-ILK can handle 5:5:5 */
7591-
if (mode_cmd->depth == 15 && !HAS_PCH_SPLIT(dev))
7592-
return -EINVAL;
7587+
switch (mode_cmd->pixel_format) {
7588+
case DRM_FOURCC_RGB332:
7589+
case DRM_FOURCC_RGB565:
7590+
case DRM_FOURCC_RGB24:
7591+
case DRM_INTEL_RGB30:
7592+
/* RGB formats are common across chipsets */
75937593
break;
7594-
7595-
case 24:
7596-
case 32:
7594+
case DRM_FOURCC_YUYV:
7595+
case DRM_FOURCC_UYVY:
7596+
case DRM_FOURCC_YVYU:
7597+
case DRM_FOURCC_VYUY:
75977598
break;
75987599
default:
7600+
DRM_ERROR("unsupported pixel format\n");
75997601
return -EINVAL;
76007602
}
76017603

@@ -7613,11 +7615,12 @@ int intel_framebuffer_init(struct drm_device *dev,
76137615
static struct drm_framebuffer *
76147616
intel_user_framebuffer_create(struct drm_device *dev,
76157617
struct drm_file *filp,
7616-
struct drm_mode_fb_cmd *mode_cmd)
7618+
struct drm_mode_fb_cmd2 *mode_cmd)
76177619
{
76187620
struct drm_i915_gem_object *obj;
76197621

7620-
obj = to_intel_bo(drm_gem_object_lookup(dev, filp, mode_cmd->handle));
7622+
obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
7623+
mode_cmd->handles[0]));
76217624
if (&obj->base == NULL)
76227625
return ERR_PTR(-ENOENT);
76237626

‎drivers/gpu/drm/i915/intel_drv.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ extern int intel_pin_and_fence_fb_obj(struct drm_device *dev,
359359

360360
extern int intel_framebuffer_init(struct drm_device *dev,
361361
struct intel_framebuffer *ifb,
362-
struct drm_mode_fb_cmd *mode_cmd,
362+
struct drm_mode_fb_cmd2 *mode_cmd,
363363
struct drm_i915_gem_object *obj);
364364
extern int intel_fbdev_init(struct drm_device *dev);
365365
extern void intel_fbdev_fini(struct drm_device *dev);

‎drivers/gpu/drm/i915/intel_fb.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static int intelfb_create(struct intel_fbdev *ifbdev,
6565
struct drm_i915_private *dev_priv = dev->dev_private;
6666
struct fb_info *info;
6767
struct drm_framebuffer *fb;
68-
struct drm_mode_fb_cmd mode_cmd;
68+
struct drm_mode_fb_cmd2 mode_cmd;
6969
struct drm_i915_gem_object *obj;
7070
struct device *device = &dev->pdev->dev;
7171
int size, ret;
@@ -77,11 +77,12 @@ static int intelfb_create(struct intel_fbdev *ifbdev,
7777
mode_cmd.width = sizes->surface_width;
7878
mode_cmd.height = sizes->surface_height;
7979

80-
mode_cmd.bpp = sizes->surface_bpp;
81-
mode_cmd.pitch = ALIGN(mode_cmd.width * ((mode_cmd.bpp + 7) / 8), 64);
82-
mode_cmd.depth = sizes->surface_depth;
80+
mode_cmd.pitches[0] = ALIGN(mode_cmd.width * ((sizes->surface_bpp + 7) /
81+
8), 64);
82+
mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
83+
sizes->surface_depth);
8384

84-
size = mode_cmd.pitch * mode_cmd.height;
85+
size = mode_cmd.pitches[0] * mode_cmd.height;
8586
size = ALIGN(size, PAGE_SIZE);
8687
obj = i915_gem_alloc_object(dev, size);
8788
if (!obj) {

‎drivers/gpu/drm/nouveau/nouveau_display.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = {
6464
int
6565
nouveau_framebuffer_init(struct drm_device *dev,
6666
struct nouveau_framebuffer *nv_fb,
67-
struct drm_mode_fb_cmd *mode_cmd,
67+
struct drm_mode_fb_cmd2 *mode_cmd,
6868
struct nouveau_bo *nvbo)
6969
{
7070
struct drm_nouveau_private *dev_priv = dev->dev_private;
@@ -124,13 +124,13 @@ nouveau_framebuffer_init(struct drm_device *dev,
124124
static struct drm_framebuffer *
125125
nouveau_user_framebuffer_create(struct drm_device *dev,
126126
struct drm_file *file_priv,
127-
struct drm_mode_fb_cmd *mode_cmd)
127+
struct drm_mode_fb_cmd2 *mode_cmd)
128128
{
129129
struct nouveau_framebuffer *nouveau_fb;
130130
struct drm_gem_object *gem;
131131
int ret;
132132

133-
gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle);
133+
gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[0]);
134134
if (!gem)
135135
return ERR_PTR(-ENOENT);
136136

‎drivers/gpu/drm/nouveau/nouveau_fb.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ nouveau_framebuffer(struct drm_framebuffer *fb)
4545
extern const struct drm_mode_config_funcs nouveau_mode_config_funcs;
4646

4747
int nouveau_framebuffer_init(struct drm_device *dev, struct nouveau_framebuffer *nouveau_fb,
48-
struct drm_mode_fb_cmd *mode_cmd, struct nouveau_bo *nvbo);
48+
struct drm_mode_fb_cmd2 *mode_cmd, struct nouveau_bo *nvbo);
4949
#endif /* __NOUVEAU_FB_H__ */

0 commit comments

Comments
 (0)