diff options
Diffstat (limited to 'drivers/gpu/drm/omapdrm/omap_fb.c')
-rw-r--r-- | drivers/gpu/drm/omapdrm/omap_fb.c | 91 |
1 files changed, 46 insertions, 45 deletions
diff --git a/drivers/gpu/drm/omapdrm/omap_fb.c b/drivers/gpu/drm/omapdrm/omap_fb.c index 7646df33f9a1..6315d68989fc 100644 --- a/drivers/gpu/drm/omapdrm/omap_fb.c +++ b/drivers/gpu/drm/omapdrm/omap_fb.c | |||
@@ -29,37 +29,30 @@ | |||
29 | * framebuffer funcs | 29 | * framebuffer funcs |
30 | */ | 30 | */ |
31 | 31 | ||
32 | /* per-format info: */ | 32 | /* DSS to DRM formats mapping */ |
33 | struct format { | 33 | static const struct { |
34 | enum omap_color_mode dss_format; | 34 | enum omap_color_mode dss_format; |
35 | uint32_t pixel_format; | 35 | uint32_t pixel_format; |
36 | struct { | 36 | } formats[] = { |
37 | int stride_bpp; /* this times width is stride */ | ||
38 | int sub_y; /* sub-sample in y dimension */ | ||
39 | } planes[2]; | ||
40 | bool yuv; | ||
41 | }; | ||
42 | |||
43 | static const struct format formats[] = { | ||
44 | /* 16bpp [A]RGB: */ | 37 | /* 16bpp [A]RGB: */ |
45 | { OMAP_DSS_COLOR_RGB16, DRM_FORMAT_RGB565, {{2, 1}}, false }, /* RGB16-565 */ | 38 | { OMAP_DSS_COLOR_RGB16, DRM_FORMAT_RGB565 }, /* RGB16-565 */ |
46 | { OMAP_DSS_COLOR_RGB12U, DRM_FORMAT_RGBX4444, {{2, 1}}, false }, /* RGB12x-4444 */ | 39 | { OMAP_DSS_COLOR_RGB12U, DRM_FORMAT_RGBX4444 }, /* RGB12x-4444 */ |
47 | { OMAP_DSS_COLOR_RGBX16, DRM_FORMAT_XRGB4444, {{2, 1}}, false }, /* xRGB12-4444 */ | 40 | { OMAP_DSS_COLOR_RGBX16, DRM_FORMAT_XRGB4444 }, /* xRGB12-4444 */ |
48 | { OMAP_DSS_COLOR_RGBA16, DRM_FORMAT_RGBA4444, {{2, 1}}, false }, /* RGBA12-4444 */ | 41 | { OMAP_DSS_COLOR_RGBA16, DRM_FORMAT_RGBA4444 }, /* RGBA12-4444 */ |
49 | { OMAP_DSS_COLOR_ARGB16, DRM_FORMAT_ARGB4444, {{2, 1}}, false }, /* ARGB16-4444 */ | 42 | { OMAP_DSS_COLOR_ARGB16, DRM_FORMAT_ARGB4444 }, /* ARGB16-4444 */ |
50 | { OMAP_DSS_COLOR_XRGB16_1555, DRM_FORMAT_XRGB1555, {{2, 1}}, false }, /* xRGB15-1555 */ | 43 | { OMAP_DSS_COLOR_XRGB16_1555, DRM_FORMAT_XRGB1555 }, /* xRGB15-1555 */ |
51 | { OMAP_DSS_COLOR_ARGB16_1555, DRM_FORMAT_ARGB1555, {{2, 1}}, false }, /* ARGB16-1555 */ | 44 | { OMAP_DSS_COLOR_ARGB16_1555, DRM_FORMAT_ARGB1555 }, /* ARGB16-1555 */ |
52 | /* 24bpp RGB: */ | 45 | /* 24bpp RGB: */ |
53 | { OMAP_DSS_COLOR_RGB24P, DRM_FORMAT_RGB888, {{3, 1}}, false }, /* RGB24-888 */ | 46 | { OMAP_DSS_COLOR_RGB24P, DRM_FORMAT_RGB888 }, /* RGB24-888 */ |
54 | /* 32bpp [A]RGB: */ | 47 | /* 32bpp [A]RGB: */ |
55 | { OMAP_DSS_COLOR_RGBX32, DRM_FORMAT_RGBX8888, {{4, 1}}, false }, /* RGBx24-8888 */ | 48 | { OMAP_DSS_COLOR_RGBX32, DRM_FORMAT_RGBX8888 }, /* RGBx24-8888 */ |
56 | { OMAP_DSS_COLOR_RGB24U, DRM_FORMAT_XRGB8888, {{4, 1}}, false }, /* xRGB24-8888 */ | 49 | { OMAP_DSS_COLOR_RGB24U, DRM_FORMAT_XRGB8888 }, /* xRGB24-8888 */ |
57 | { OMAP_DSS_COLOR_RGBA32, DRM_FORMAT_RGBA8888, {{4, 1}}, false }, /* RGBA32-8888 */ | 50 | { OMAP_DSS_COLOR_RGBA32, DRM_FORMAT_RGBA8888 }, /* RGBA32-8888 */ |
58 | { OMAP_DSS_COLOR_ARGB32, DRM_FORMAT_ARGB8888, {{4, 1}}, false }, /* ARGB32-8888 */ | 51 | { OMAP_DSS_COLOR_ARGB32, DRM_FORMAT_ARGB8888 }, /* ARGB32-8888 */ |
59 | /* YUV: */ | 52 | /* YUV: */ |
60 | { OMAP_DSS_COLOR_NV12, DRM_FORMAT_NV12, {{1, 1}, {1, 2}}, true }, | 53 | { OMAP_DSS_COLOR_NV12, DRM_FORMAT_NV12 }, |
61 | { OMAP_DSS_COLOR_YUV2, DRM_FORMAT_YUYV, {{2, 1}}, true }, | 54 | { OMAP_DSS_COLOR_YUV2, DRM_FORMAT_YUYV }, |
62 | { OMAP_DSS_COLOR_UYVY, DRM_FORMAT_UYVY, {{2, 1}}, true }, | 55 | { OMAP_DSS_COLOR_UYVY, DRM_FORMAT_UYVY }, |
63 | }; | 56 | }; |
64 | 57 | ||
65 | /* convert from overlay's pixel formats bitmask to an array of fourcc's */ | 58 | /* convert from overlay's pixel formats bitmask to an array of fourcc's */ |
@@ -89,7 +82,8 @@ struct plane { | |||
89 | struct omap_framebuffer { | 82 | struct omap_framebuffer { |
90 | struct drm_framebuffer base; | 83 | struct drm_framebuffer base; |
91 | int pin_count; | 84 | int pin_count; |
92 | const struct format *format; | 85 | const struct drm_format_info *format; |
86 | enum omap_color_mode dss_format; | ||
93 | struct plane planes[2]; | 87 | struct plane planes[2]; |
94 | /* lock for pinning (pin_count and planes.paddr) */ | 88 | /* lock for pinning (pin_count and planes.paddr) */ |
95 | struct mutex lock; | 89 | struct mutex lock; |
@@ -128,13 +122,13 @@ static const struct drm_framebuffer_funcs omap_framebuffer_funcs = { | |||
128 | }; | 122 | }; |
129 | 123 | ||
130 | static uint32_t get_linear_addr(struct plane *plane, | 124 | static uint32_t get_linear_addr(struct plane *plane, |
131 | const struct format *format, int n, int x, int y) | 125 | const struct drm_format_info *format, int n, int x, int y) |
132 | { | 126 | { |
133 | uint32_t offset; | 127 | uint32_t offset; |
134 | 128 | ||
135 | offset = plane->offset + | 129 | offset = plane->offset |
136 | (x * format->planes[n].stride_bpp) + | 130 | + (x * format->cpp[n] / (n == 0 ? 1 : format->hsub)) |
137 | (y * plane->pitch / format->planes[n].sub_y); | 131 | + (y * plane->pitch / (n == 0 ? 1 : format->vsub)); |
138 | 132 | ||
139 | return plane->paddr + offset; | 133 | return plane->paddr + offset; |
140 | } | 134 | } |
@@ -153,11 +147,11 @@ void omap_framebuffer_update_scanout(struct drm_framebuffer *fb, | |||
153 | struct omap_drm_window *win, struct omap_overlay_info *info) | 147 | struct omap_drm_window *win, struct omap_overlay_info *info) |
154 | { | 148 | { |
155 | struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb); | 149 | struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb); |
156 | const struct format *format = omap_fb->format; | 150 | const struct drm_format_info *format = omap_fb->format; |
157 | struct plane *plane = &omap_fb->planes[0]; | 151 | struct plane *plane = &omap_fb->planes[0]; |
158 | uint32_t x, y, orient = 0; | 152 | uint32_t x, y, orient = 0; |
159 | 153 | ||
160 | info->color_mode = format->dss_format; | 154 | info->color_mode = omap_fb->dss_format; |
161 | 155 | ||
162 | info->pos_x = win->crtc_x; | 156 | info->pos_x = win->crtc_x; |
163 | info->pos_y = win->crtc_y; | 157 | info->pos_y = win->crtc_y; |
@@ -231,9 +225,9 @@ void omap_framebuffer_update_scanout(struct drm_framebuffer *fb, | |||
231 | } | 225 | } |
232 | 226 | ||
233 | /* convert to pixels: */ | 227 | /* convert to pixels: */ |
234 | info->screen_width /= format->planes[0].stride_bpp; | 228 | info->screen_width /= format->cpp[0]; |
235 | 229 | ||
236 | if (format->dss_format == OMAP_DSS_COLOR_NV12) { | 230 | if (omap_fb->dss_format == OMAP_DSS_COLOR_NV12) { |
237 | plane = &omap_fb->planes[1]; | 231 | plane = &omap_fb->planes[1]; |
238 | 232 | ||
239 | if (info->rotation_type == OMAP_DSS_ROT_TILER) { | 233 | if (info->rotation_type == OMAP_DSS_ROT_TILER) { |
@@ -382,23 +376,26 @@ struct drm_framebuffer *omap_framebuffer_create(struct drm_device *dev, | |||
382 | struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev, | 376 | struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev, |
383 | const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos) | 377 | const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos) |
384 | { | 378 | { |
379 | const struct drm_format_info *format = NULL; | ||
385 | struct omap_framebuffer *omap_fb = NULL; | 380 | struct omap_framebuffer *omap_fb = NULL; |
386 | struct drm_framebuffer *fb = NULL; | 381 | struct drm_framebuffer *fb = NULL; |
387 | const struct format *format = NULL; | 382 | enum omap_color_mode dss_format = 0; |
388 | int ret, i, n = drm_format_num_planes(mode_cmd->pixel_format); | 383 | int ret, i; |
389 | 384 | ||
390 | DBG("create framebuffer: dev=%p, mode_cmd=%p (%dx%d@%4.4s)", | 385 | DBG("create framebuffer: dev=%p, mode_cmd=%p (%dx%d@%4.4s)", |
391 | dev, mode_cmd, mode_cmd->width, mode_cmd->height, | 386 | dev, mode_cmd, mode_cmd->width, mode_cmd->height, |
392 | (char *)&mode_cmd->pixel_format); | 387 | (char *)&mode_cmd->pixel_format); |
393 | 388 | ||
389 | format = drm_format_info(mode_cmd->pixel_format); | ||
390 | |||
394 | for (i = 0; i < ARRAY_SIZE(formats); i++) { | 391 | for (i = 0; i < ARRAY_SIZE(formats); i++) { |
395 | if (formats[i].pixel_format == mode_cmd->pixel_format) { | 392 | if (formats[i].pixel_format == mode_cmd->pixel_format) { |
396 | format = &formats[i]; | 393 | dss_format = formats[i].dss_format; |
397 | break; | 394 | break; |
398 | } | 395 | } |
399 | } | 396 | } |
400 | 397 | ||
401 | if (!format) { | 398 | if (!format || !dss_format) { |
402 | dev_err(dev->dev, "unsupported pixel format: %4.4s\n", | 399 | dev_err(dev->dev, "unsupported pixel format: %4.4s\n", |
403 | (char *)&mode_cmd->pixel_format); | 400 | (char *)&mode_cmd->pixel_format); |
404 | ret = -EINVAL; | 401 | ret = -EINVAL; |
@@ -413,28 +410,32 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev, | |||
413 | 410 | ||
414 | fb = &omap_fb->base; | 411 | fb = &omap_fb->base; |
415 | omap_fb->format = format; | 412 | omap_fb->format = format; |
413 | omap_fb->dss_format = dss_format; | ||
416 | mutex_init(&omap_fb->lock); | 414 | mutex_init(&omap_fb->lock); |
417 | 415 | ||
418 | for (i = 0; i < n; i++) { | 416 | for (i = 0; i < format->num_planes; i++) { |
419 | struct plane *plane = &omap_fb->planes[i]; | 417 | struct plane *plane = &omap_fb->planes[i]; |
420 | int size, pitch = mode_cmd->pitches[i]; | 418 | unsigned int pitch = mode_cmd->pitches[i]; |
419 | unsigned int hsub = i == 0 ? 1 : format->hsub; | ||
420 | unsigned int vsub = i == 0 ? 1 : format->vsub; | ||
421 | unsigned int size; | ||
421 | 422 | ||
422 | if (pitch < (mode_cmd->width * format->planes[i].stride_bpp)) { | 423 | if (pitch < mode_cmd->width * format->cpp[i] / hsub) { |
423 | dev_err(dev->dev, "provided buffer pitch is too small! %d < %d\n", | 424 | dev_err(dev->dev, "provided buffer pitch is too small! %d < %d\n", |
424 | pitch, mode_cmd->width * format->planes[i].stride_bpp); | 425 | pitch, mode_cmd->width * format->cpp[i] / hsub); |
425 | ret = -EINVAL; | 426 | ret = -EINVAL; |
426 | goto fail; | 427 | goto fail; |
427 | } | 428 | } |
428 | 429 | ||
429 | if (pitch % format->planes[i].stride_bpp != 0) { | 430 | if (pitch % format->cpp[i] != 0) { |
430 | dev_err(dev->dev, | 431 | dev_err(dev->dev, |
431 | "buffer pitch (%d bytes) is not a multiple of pixel size (%d bytes)\n", | 432 | "buffer pitch (%d bytes) is not a multiple of pixel size (%d bytes)\n", |
432 | pitch, format->planes[i].stride_bpp); | 433 | pitch, format->cpp[i]); |
433 | ret = -EINVAL; | 434 | ret = -EINVAL; |
434 | goto fail; | 435 | goto fail; |
435 | } | 436 | } |
436 | 437 | ||
437 | size = pitch * mode_cmd->height / format->planes[i].sub_y; | 438 | size = pitch * mode_cmd->height / vsub; |
438 | 439 | ||
439 | if (size > (omap_gem_mmap_size(bos[i]) - mode_cmd->offsets[i])) { | 440 | if (size > (omap_gem_mmap_size(bos[i]) - mode_cmd->offsets[i])) { |
440 | dev_err(dev->dev, "provided buffer object is too small! %d < %d\n", | 441 | dev_err(dev->dev, "provided buffer object is too small! %d < %d\n", |