From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>,
Thomas Zimmermann <tzimmermann@suse.de>,
Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: [PATCH 1/2] drm: Add DRM-managed drm_mm_init()
Date: Fri, 24 May 2024 15:35:17 +0200 [thread overview]
Message-ID: <20240524133518.976-2-michal.wajdeczko@intel.com> (raw)
In-Reply-To: <20240524133518.976-1-michal.wajdeczko@intel.com>
Add drmm_mm_init(), a helper that provides managed allocator cleanup.
The allocator will be cleaned up with the final reference of the DRM
device.
Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
---
drivers/gpu/drm/drm_managed.c | 27 +++++++++++++++++++++++++++
include/drm/drm_managed.h | 3 +++
2 files changed, 30 insertions(+)
diff --git a/drivers/gpu/drm/drm_managed.c b/drivers/gpu/drm/drm_managed.c
index 7646f67bda4e..2fb9656bada3 100644
--- a/drivers/gpu/drm/drm_managed.c
+++ b/drivers/gpu/drm/drm_managed.c
@@ -13,6 +13,7 @@
#include <linux/spinlock.h>
#include <drm/drm_device.h>
+#include <drm/drm_mm.h>
#include <drm/drm_print.h>
#include "drm_internal.h"
@@ -310,3 +311,29 @@ void __drmm_mutex_release(struct drm_device *dev, void *res)
mutex_destroy(lock);
}
EXPORT_SYMBOL(__drmm_mutex_release);
+
+static void __drmm_mm_takedown(struct drm_device *dev, void *res)
+{
+ struct drm_mm *mm = res;
+
+ drm_mm_takedown(mm);
+}
+
+/**
+ * drmm_mm_init - &drm_device managed drm_mm_init()
+ * @dev: DRM device
+ * @mm: the drm_mm structure to initialize
+ * @start: start of the range managed by @mm
+ * @size: end of the range managed by @mm
+ *
+ * This is a &drm_device managed version of drm_mm_init().
+ * The initialized allocator will be cleaned up on the final drm_dev_put().
+ *
+ * Return: 0 on success, or a negative errno code otherwise.
+ */
+int drmm_mm_init(struct drm_device *dev, struct drm_mm *mm, u64 start, u64 size)
+{
+ drm_mm_init(mm, start, size);
+ return drmm_add_action_or_reset(dev, __drmm_mm_takedown, mm);
+}
+EXPORT_SYMBOL(drmm_mm_init);
diff --git a/include/drm/drm_managed.h b/include/drm/drm_managed.h
index f547b09ca023..e8c2f29cb88a 100644
--- a/include/drm/drm_managed.h
+++ b/include/drm/drm_managed.h
@@ -8,6 +8,7 @@
#include <linux/types.h>
struct drm_device;
+struct drm_mm;
struct mutex;
typedef void (*drmres_release_t)(struct drm_device *dev, void *res);
@@ -127,4 +128,6 @@ void __drmm_mutex_release(struct drm_device *dev, void *res);
drmm_add_action_or_reset(dev, __drmm_mutex_release, lock); \
}) \
+int drmm_mm_init(struct drm_device *dev, struct drm_mm *mm, u64 start, u64 size);
+
#endif
--
2.43.0
next prev parent reply other threads:[~2024-05-24 13:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-24 13:35 [PATCH 0/2] Add DRM-managed drm_mm_init() Michal Wajdeczko
2024-05-24 13:35 ` Michal Wajdeczko [this message]
2024-06-06 17:27 ` [PATCH 1/2] drm: " Rodrigo Vivi
2024-05-24 13:35 ` [PATCH 2/2] drm/xe: Use drm_device managed mutex/mm init helpers in GGTT Michal Wajdeczko
2024-06-06 17:25 ` Rodrigo Vivi
2024-06-06 18:33 ` Michal Wajdeczko
2024-05-24 13:41 ` ✓ CI.Patch_applied: success for Add DRM-managed drm_mm_init() Patchwork
2024-05-24 13:42 ` ✓ CI.checkpatch: " Patchwork
2024-05-24 13:43 ` ✓ CI.KUnit: " Patchwork
2024-05-24 13:54 ` ✓ CI.Build: " Patchwork
2024-05-24 13:57 ` ✓ CI.Hooks: " Patchwork
2024-05-24 13:58 ` ✗ CI.checksparse: warning " Patchwork
2024-05-24 14:28 ` ✗ CI.BAT: failure " Patchwork
2024-05-24 17:25 ` Michal Wajdeczko
2024-05-27 11:27 ` ✗ CI.FULL: " Patchwork
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=20240524133518.976-2-michal.wajdeczko@intel.com \
--to=michal.wajdeczko@intel.com \
--cc=daniel.vetter@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=tzimmermann@suse.de \
/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