dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: kraxel@redhat.com, daniel@ffwll.ch, airlied@gmail.com,
	mripard@kernel.org, maarten.lankhorst@linux.intel.com
Cc: dri-devel@lists.freedesktop.org, virtualization@lists.linux.dev,
	Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 09/10] drm/bochs: Validate display modes against available video memory
Date: Fri, 23 Aug 2024 14:28:52 +0200	[thread overview]
Message-ID: <20240823124422.286989-10-tzimmermann@suse.de> (raw)
In-Reply-To: <20240823124422.286989-1-tzimmermann@suse.de>

For each mode, test the required memory against the available video
memory. Filters out modes that do not fit into display memory.

Also remove the old test against the 4 MiB limit. It is now obsolete
and did not necessarily produce correct results.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/tiny/bochs.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/tiny/bochs.c b/drivers/gpu/drm/tiny/bochs.c
index bde70a6075ec..b09c6c76923b 100644
--- a/drivers/gpu/drm/tiny/bochs.c
+++ b/drivers/gpu/drm/tiny/bochs.c
@@ -558,8 +558,28 @@ static const struct drm_connector_funcs bochs_connector_funcs = {
 	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
 };
 
+static enum drm_mode_status bochs_mode_config_mode_valid(struct drm_device *dev,
+							 const struct drm_display_mode *mode)
+{
+	struct bochs_device *bochs = to_bochs_device(dev);
+	const struct drm_format_info *format = drm_format_info(DRM_FORMAT_XRGB8888);
+	uint64_t pitch;
+
+	if (drm_WARN_ON(dev, !format))
+		return MODE_ERROR;
+
+	pitch = drm_format_info_min_pitch(format, 0, mode->vdisplay);
+	if (!pitch)
+		return MODE_BAD_WIDTH;
+	if (bochs->fb_size / pitch < mode->hdisplay)
+		return MODE_MEM;
+
+	return MODE_OK;
+}
+
 static const struct drm_mode_config_funcs bochs_mode_config_funcs = {
 	.fb_create = drm_gem_fb_create_with_dirty,
+	.mode_valid = bochs_mode_config_mode_valid,
 	.atomic_check = drm_atomic_helper_check,
 	.atomic_commit = drm_atomic_helper_commit,
 };
@@ -687,15 +707,8 @@ static int bochs_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent
 {
 	struct bochs_device *bochs;
 	struct drm_device *dev;
-	unsigned long fbsize;
 	int ret;
 
-	fbsize = pci_resource_len(pdev, 0);
-	if (fbsize < 4 * 1024 * 1024) {
-		DRM_ERROR("less than 4 MB video memory, ignoring device\n");
-		return -ENOMEM;
-	}
-
 	ret = drm_aperture_remove_conflicting_pci_framebuffers(pdev, &bochs_driver);
 	if (ret)
 		return ret;
-- 
2.46.0


  parent reply	other threads:[~2024-08-23 12:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-23 12:28 [PATCH 00/10] rm/bochs: Modernize driver Thomas Zimmermann
2024-08-23 12:28 ` [PATCH 01/10] drm/bochs: Remove manual format test from fb_create Thomas Zimmermann
2024-08-23 12:28 ` [PATCH 02/10] drm/bochs: Use helpers for struct drm_edid Thomas Zimmermann
2024-08-23 12:28 ` [PATCH 03/10] drm/bochs: Do managed resource cleanup Thomas Zimmermann
2024-08-23 12:28 ` [PATCH 04/10] drm/bochs: Pass bochs device to various functions Thomas Zimmermann
2024-08-23 12:28 ` [PATCH 05/10] drm/bochs: Upcast with to_bochs_device() Thomas Zimmermann
2024-08-23 12:28 ` [PATCH 06/10] drm/bochs: Allocate DRM device in struct bochs_device Thomas Zimmermann
2024-08-23 12:28 ` [PATCH 07/10] drm/bochs: Use regular atomic helpers Thomas Zimmermann
2024-08-23 12:28 ` [PATCH 08/10] drm/bochs: Use GEM SHMEM helpers for memory management Thomas Zimmermann
2024-08-23 12:28 ` Thomas Zimmermann [this message]
2024-08-29 20:37   ` [PATCH 09/10] drm/bochs: Validate display modes against available video memory kernel test robot
2024-08-23 12:28 ` [PATCH 10/10] drm/gem-vram: Remove support for simple display pipelines Thomas Zimmermann
2024-08-23 14:34 ` [PATCH 00/10] rm/bochs: Modernize driver Gerd Hoffmann
2024-08-23 15:00   ` Thomas Zimmermann
2024-08-26  7:32     ` Gerd Hoffmann
2024-08-26  8:08       ` Thomas Zimmermann

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=20240823124422.286989-10-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@gmail.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kraxel@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=virtualization@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox