From: Thomas Hellstrom <thellstrom@vmware.com>
To: airlied@redhat.com
Cc: Thomas Hellstrom <thellstrom@vmware.com>,
dri-devel@lists.freedesktop.org
Subject: [PATCH 07/15] vmwgfx: Prune modes based on available VRAM size
Date: Mon, 27 Sep 2010 15:20:24 +0200 [thread overview]
Message-ID: <1285593632-10585-8-git-send-email-thellstrom@vmware.com> (raw)
In-Reply-To: <1285593632-10585-7-git-send-email-thellstrom@vmware.com>
This needs to be reviewed once we support screen objects and don't rely
on VRAM for the frame-buffer.
Also fix some integer overflow issues pointed out by Michel Daenzer.
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
---
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 3 +++
drivers/gpu/drm/vmwgfx/vmwgfx_fb.c | 7 +++++++
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 11 +++++++++--
drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c | 28 +++++++++++++++++++---------
4 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 8f09a56..38e8b3c 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -522,6 +522,9 @@ void vmw_kms_write_svga(struct vmw_private *vmw_priv,
int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv);
void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
+bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
+ uint32_t pitch,
+ uint32_t height);
/**
* Overlay control - vmwgfx_overlay.c
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
index 870967a..cf38a61 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
@@ -144,6 +144,13 @@ static int vmw_fb_check_var(struct fb_var_screeninfo *var,
return -EINVAL;
}
+ if (!vmw_kms_validate_mode_vram(vmw_priv,
+ info->fix.line_length,
+ var->yoffset + var->yres)) {
+ DRM_ERROR("Requested geom can not fit in framebuffer\n");
+ return -EINVAL;
+ }
+
return 0;
}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 56ce75b..3ee2492 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -838,7 +838,7 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
struct vmw_framebuffer *vfb = NULL;
struct vmw_surface *surface = NULL;
struct vmw_dma_buffer *bo = NULL;
- unsigned int required_size;
+ u64 required_size;
int ret;
/**
@@ -848,7 +848,7 @@ static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev,
*/
required_size = mode_cmd->pitch * mode_cmd->height;
- if (unlikely(required_size > dev_priv->vram_size)) {
+ if (unlikely(required_size > (u64) dev_priv->vram_size)) {
DRM_ERROR("VRAM size is too small for requested mode.\n");
return NULL;
}
@@ -1132,3 +1132,10 @@ out_unlock:
ttm_read_unlock(&vmaster->lock);
return ret;
}
+
+bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
+ uint32_t pitch,
+ uint32_t height)
+{
+ return ((u64) pitch * (u64) height) < (u64) dev_priv->vram_size;
+}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
index 7083b1a..2337e72 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
@@ -425,7 +425,9 @@ static int vmw_ldu_connector_fill_modes(struct drm_connector *connector,
{
struct vmw_legacy_display_unit *ldu = vmw_connector_to_ldu(connector);
struct drm_device *dev = connector->dev;
+ struct vmw_private *dev_priv = vmw_priv(dev);
struct drm_display_mode *mode = NULL;
+ struct drm_display_mode *bmode;
struct drm_display_mode prefmode = { DRM_MODE("preferred",
DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -441,22 +443,30 @@ static int vmw_ldu_connector_fill_modes(struct drm_connector *connector,
mode->hdisplay = ldu->pref_width;
mode->vdisplay = ldu->pref_height;
mode->vrefresh = drm_mode_vrefresh(mode);
- drm_mode_probed_add(connector, mode);
+ if (vmw_kms_validate_mode_vram(dev_priv, mode->hdisplay * 2,
+ mode->vdisplay)) {
+ drm_mode_probed_add(connector, mode);
- if (ldu->pref_mode) {
- list_del_init(&ldu->pref_mode->head);
- drm_mode_destroy(dev, ldu->pref_mode);
- }
+ if (ldu->pref_mode) {
+ list_del_init(&ldu->pref_mode->head);
+ drm_mode_destroy(dev, ldu->pref_mode);
+ }
- ldu->pref_mode = mode;
+ ldu->pref_mode = mode;
+ }
}
for (i = 0; vmw_ldu_connector_builtin[i].type != 0; i++) {
- if (vmw_ldu_connector_builtin[i].hdisplay > max_width ||
- vmw_ldu_connector_builtin[i].vdisplay > max_height)
+ bmode = &vmw_ldu_connector_builtin[i];
+ if (bmode->hdisplay > max_width ||
+ bmode->vdisplay > max_height)
+ continue;
+
+ if (!vmw_kms_validate_mode_vram(dev_priv, bmode->hdisplay * 2,
+ bmode->vdisplay))
continue;
- mode = drm_mode_duplicate(dev, &vmw_ldu_connector_builtin[i]);
+ mode = drm_mode_duplicate(dev, bmode);
if (!mode)
return 0;
mode->vrefresh = drm_mode_vrefresh(mode);
--
1.6.2.5
next prev parent reply other threads:[~2010-09-27 13:31 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-27 13:20 [PATCH 0/15] vmwgfx updates Thomas Hellstrom
2010-09-27 13:20 ` [PATCH 01/15] vmwgfx: Add an option to choose whether to enable fbdev at load time Thomas Hellstrom
2010-09-27 13:20 ` [PATCH 02/15] vmwgfx: Really support other depths than 32 Thomas Hellstrom
2010-09-27 13:20 ` [PATCH 03/15] vmwgfx: Fix ACPI S3 & S4 functionality Thomas Hellstrom
2010-09-27 13:20 ` [PATCH 04/15] vmwgfx: Add new-style PM hooks to improve hibernation behavior Thomas Hellstrom
2010-09-27 13:20 ` [PATCH 05/15] drm: vmwgfx: Add a struct drm_file parameter to the dirty framebuffer callback Thomas Hellstrom
2010-09-27 13:20 ` [PATCH 06/15] vmwgfx: Take the ttm lock around the dirty ioctl Thomas Hellstrom
2010-09-27 13:20 ` Thomas Hellstrom [this message]
2010-09-27 13:20 ` [PATCH 08/15] vmwgfx: Don't flush fb if we're in the suspended state Thomas Hellstrom
2010-09-27 13:20 ` [PATCH 09/15] vmwgfx: Add a parameter to get the max fb size Thomas Hellstrom
2010-09-27 13:20 ` [PATCH 10/15] vmwgfx: Enable use of the vblank system Thomas Hellstrom
2010-09-27 13:20 ` [PATCH 11/15] vmwgfx: Add modinfo version Thomas Hellstrom
2010-09-27 13:20 ` [PATCH 12/15] vmwgfx: Remove initialisation of dev::devname Thomas Hellstrom
2010-09-27 13:20 ` [PATCH 13/15] vmwgfx: Add a get_vblank_counter function Thomas Hellstrom
2010-09-27 13:20 ` [PATCH 14/15] vmwgfx: Save at least one screen layout Thomas Hellstrom
2010-09-27 13:20 ` [PATCH 15/15] vmwgfx: Bump minor and driver date Thomas Hellstrom
2010-09-28 7:23 ` [PATCH 13/15] vmwgfx: Add a get_vblank_counter function Michel Dänzer
2010-09-28 8:06 ` Thomas Hellstrom
2010-09-27 22:41 ` [PATCH 03/15] vmwgfx: Fix ACPI S3 & S4 functionality Dave Airlie
2010-09-28 6:44 ` Thomas Hellstrom
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1285593632-10585-8-git-send-email-thellstrom@vmware.com \
--to=thellstrom@vmware.com \
--cc=airlied@redhat.com \
--cc=dri-devel@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.