History

drm/cirrus: allow 32bpp framebuffers for cirrus drm

This patch allows framebuffers for cirrus to be created with 32bpp pixel formats provided that they do not violate certain restrictions of the cirrus hardware. v2: Use pci resource length for vram size.

Zach Reizner committed 12 years ago

Commit 89756261 parent ebfdd6d3 files · +30 −5Browse files

Unified · Split

3 files
  1. drivers/gpu/drm/cirrus/cirrus_drv.h +3 −0
  2. drivers/gpu/drm/cirrus/cirrus_fbdev.c +4 −1
  3. drivers/gpu/drm/cirrus/cirrus_main.c +23 −4
drivers/gpu/drm/cirrus/cirrus_drv.h+3−0
@@ -210,6 +210,9 @@ int cirrus_framebuffer_init(struct drm_device *dev, · 209 unmodified lines
210210 struct drm_mode_fb_cmd2 *mode_cmd,
211211 struct drm_gem_object *obj);
212212
213+bool cirrus_check_framebuffer(struct cirrus_device *cdev, int width, int height,
214+ int bpp, int pitch);
215+
213216 /* cirrus_display.c */
214217 int cirrus_modeset_init(struct cirrus_device *cdev);
215218 void cirrus_modeset_fini(struct cirrus_device *cdev);
drivers/gpu/drm/cirrus/cirrus_fbdev.c+4−1
@@ -139,6 +139,7 @@ static int cirrusfb_create_object(struct cirrus_fbdev *afbdev, · 138 unmodified lines
139139 struct drm_gem_object **gobj_p)
140140 {
141141 struct drm_device *dev = afbdev->helper.dev;
142+ struct cirrus_device *cdev = dev->dev_private;
142143 u32 bpp, depth;
143144 u32 size;
144145 struct drm_gem_object *gobj;
@@ -146,8 +147,10 @@ static int cirrusfb_create_object(struct cirrus_fbdev *afbdev, · 1 unmodified line
146147 int ret = 0;
147148 drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
148149
149− if (bpp > 24)
150+ if (!cirrus_check_framebuffer(cdev, mode_cmd->width, mode_cmd->height,
151+ bpp, mode_cmd->pitches[0]))
150152 return -EINVAL;
153+
151154 size = mode_cmd->pitches[0] * mode_cmd->height;
152155 ret = cirrus_gem_create(dev, size, true, &gobj);
153156 if (ret)
drivers/gpu/drm/cirrus/cirrus_main.c+23−4
@@ -49,14 +49,16 @@ cirrus_user_framebuffer_create(struct drm_device *dev, · 48 unmodified lines
4949 struct drm_file *filp,
5050 struct drm_mode_fb_cmd2 *mode_cmd)
5151 {
52+ struct cirrus_device *cdev = dev->dev_private;
5253 struct drm_gem_object *obj;
5354 struct cirrus_framebuffer *cirrus_fb;
5455 int ret;
5556 u32 bpp, depth;
5657
5758 drm_fb_get_bpp_depth(mode_cmd->pixel_format, &depth, &bpp);
58− /* cirrus can't handle > 24bpp framebuffers at all */
59− if (bpp > 24)
59+
60+ if (!cirrus_check_framebuffer(cdev, mode_cmd->width, mode_cmd->height,
61+ bpp, mode_cmd->pitches[0]))
6062 return ERR_PTR(-EINVAL);
6163
6264 obj = drm_gem_object_lookup(dev, filp, mode_cmd->handles[0]);
@@ -96,8 +98,7 @@ static int cirrus_vram_init(struct cirrus_device *cdev) · 33 unmodified lines
9698 {
9799 /* BAR 0 is VRAM */
98100 cdev->mc.vram_base = pci_resource_start(cdev->dev->pdev, 0);
99− /* We have 4MB of VRAM */
100− cdev->mc.vram_size = 4 * 1024 * 1024;
101+ cdev->mc.vram_size = pci_resource_len(cdev->dev->pdev, 0);
101102
102103 if (!request_mem_region(cdev->mc.vram_base, cdev->mc.vram_size,
103104 "cirrusdrmfb_vram")) {
@@ -312,3 +313,21 @@ out_unlock: · 208 unmodified lines
312313 return ret;
313314
314315 }
316+
317+bool cirrus_check_framebuffer(struct cirrus_device *cdev, int width, int height,
318+ int bpp, int pitch)
319+{
320+ const int max_pitch = 0x1FF << 3; /* (4096 - 1) & ~111b bytes */
321+ const int max_size = cdev->mc.vram_size;
322+
323+ if (bpp > 32)
324+ return false;
325+
326+ if (pitch > max_pitch)
327+ return false;
328+
329+ if (pitch * height > max_size)
330+ return false;
331+
332+ return true;
333+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t