From: Alexandre Bailon <abailon@baylibre.com>
To: airlied@gmail.com, daniel@ffwll.ch,
maarten.lankhorst@linux.intel.com, mripard@kernel.org,
tzimmermann@suse.de
Cc: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
conor+dt@kernel.org, matthias.bgg@gmail.com,
angelogioacchino.delregno@collabora.com, sumit.semwal@linaro.org,
christian.koenig@amd.com, jstephan@baylibre.com,
dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, linux-media@vger.kernel.org,
linaro-mm-sig@lists.linaro.org, khilman@baylibre.com,
nbelin@baylibre.com, bero@baylibre.com,
Alexandre Bailon <abailon@baylibre.com>
Subject: [PATCH 2/7] drm/apu: Add memory allocator
Date: Wed, 17 May 2023 16:52:32 +0200 [thread overview]
Message-ID: <20230517145237.295461-3-abailon@baylibre.com> (raw)
In-Reply-To: <20230517145237.295461-1-abailon@baylibre.com>
This adds a new ioctl to allocate GEM object.
Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
Reviewed-by: Julien Stephan <jstephan@baylibre.com>
---
drivers/gpu/drm/apu/Makefile | 1 +
drivers/gpu/drm/apu/apu_drv.c | 2 ++
drivers/gpu/drm/apu/apu_gem.c | 56 ++++++++++++++++++++++++++++++
drivers/gpu/drm/apu/apu_internal.h | 30 ++++++++++++++++
include/uapi/drm/apu_drm.h | 16 ++++++++-
5 files changed, 104 insertions(+), 1 deletion(-)
create mode 100644 drivers/gpu/drm/apu/apu_gem.c
diff --git a/drivers/gpu/drm/apu/Makefile b/drivers/gpu/drm/apu/Makefile
index ad85b88a8b52..91894250d4c1 100644
--- a/drivers/gpu/drm/apu/Makefile
+++ b/drivers/gpu/drm/apu/Makefile
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
drm_apu-y += apu_drv.o
+drm_apu-y += apu_gem.o
obj-$(CONFIG_DRM_APU) += drm_apu.o
diff --git a/drivers/gpu/drm/apu/apu_drv.c b/drivers/gpu/drm/apu/apu_drv.c
index b420b13a9ffd..323e267b0f53 100644
--- a/drivers/gpu/drm/apu/apu_drv.c
+++ b/drivers/gpu/drm/apu/apu_drv.c
@@ -20,6 +20,8 @@ static int ioctl_apu_state(struct drm_device *dev, void *data,
static const struct drm_ioctl_desc ioctls[] = {
DRM_IOCTL_DEF_DRV(APU_STATE, ioctl_apu_state,
DRM_RENDER_ALLOW),
+ DRM_IOCTL_DEF_DRV(APU_GEM_NEW, ioctl_gem_new,
+ DRM_RENDER_ALLOW),
};
DEFINE_DRM_GEM_DMA_FOPS(apu_drm_ops);
diff --git a/drivers/gpu/drm/apu/apu_gem.c b/drivers/gpu/drm/apu/apu_gem.c
new file mode 100644
index 000000000000..0e7b3b27942c
--- /dev/null
+++ b/drivers/gpu/drm/apu/apu_gem.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Copyright 2020 BayLibre SAS
+
+#include <drm/drm_gem_dma_helper.h>
+
+#include <uapi/drm/apu_drm.h>
+
+#include "apu_internal.h"
+
+struct drm_gem_object *apu_gem_create_object(struct drm_device *dev,
+ size_t size)
+{
+ struct drm_gem_dma_object *dma_obj;
+
+ dma_obj = drm_gem_dma_create(dev, size);
+ if (!dma_obj)
+ return NULL;
+
+ return &dma_obj->base;
+}
+
+int ioctl_gem_new(struct drm_device *dev, void *data,
+ struct drm_file *file_priv)
+{
+ struct drm_apu_gem_new *args = data;
+ struct drm_gem_dma_object *dma_obj;
+ struct apu_gem_object *apu_obj;
+ struct drm_gem_object *gem_obj;
+ int ret;
+
+ dma_obj = drm_gem_dma_create(dev, args->size);
+ if (IS_ERR(dma_obj))
+ return PTR_ERR(dma_obj);
+
+ gem_obj = &dma_obj->base;
+ apu_obj = to_apu_bo(gem_obj);
+
+ /*
+ * Save the size of buffer expected by application instead of the
+ * aligned one.
+ */
+ apu_obj->size = args->size;
+ apu_obj->offset = 0;
+ mutex_init(&apu_obj->mutex);
+
+ ret = drm_gem_handle_create(file_priv, gem_obj, &args->handle);
+ drm_gem_object_put(gem_obj);
+ if (ret) {
+ drm_gem_dma_object_free(gem_obj);
+ return ret;
+ }
+ args->offset = drm_vma_node_offset_addr(&gem_obj->vma_node);
+
+ return 0;
+}
diff --git a/drivers/gpu/drm/apu/apu_internal.h b/drivers/gpu/drm/apu/apu_internal.h
index 58d93a16c68f..203aadc58b72 100644
--- a/drivers/gpu/drm/apu/apu_internal.h
+++ b/drivers/gpu/drm/apu/apu_internal.h
@@ -3,6 +3,14 @@
#define __APU_INTERNAL_H__
#include <drm/drm_drv.h>
+#include <drm/drm_gem_dma_helper.h>
+
+struct apu_gem_object {
+ struct drm_gem_dma_object base;
+ struct mutex mutex;
+ size_t size;
+ u32 offset;
+};
struct apu_core {
int device_id;
@@ -54,6 +62,17 @@ struct apu_core_ops {
int (*is_ready)(struct apu_core *core);
};
+static inline struct apu_gem_object *to_apu_bo(struct drm_gem_object *obj)
+{
+ return container_of(to_drm_gem_dma_obj(obj), struct apu_gem_object,
+ base);
+}
+
+static inline void *apu_drm_priv(struct apu_core *apu_core)
+{
+ return apu_core->dev_priv;
+}
+
struct apu_drm *apu_dev_alloc(struct device *dev);
int apu_dev_register(struct apu_drm *apu);
void apu_dev_unregister(struct apu_drm *apu);
@@ -65,4 +84,15 @@ int apu_core_register(struct device *dev, struct apu_core *core, void *priv);
void apu_core_remove(struct apu_core *core);
struct apu_core *apu_find_core_by_priv(void *priv);
+struct apu_gem_object *to_apu_bo(struct drm_gem_object *obj);
+struct drm_gem_object *apu_gem_create_object(struct drm_device *dev,
+ size_t size);
+
+int ioctl_gem_new(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+int ioctl_gem_user_new(struct drm_device *dev, void *data,
+ struct drm_file *file_priv);
+struct dma_buf *apu_gem_prime_export(struct drm_gem_object *gem,
+ int flags);
+
#endif /* __APU_INTERNAL_H__ */
diff --git a/include/uapi/drm/apu_drm.h b/include/uapi/drm/apu_drm.h
index d50c63d1b813..14fc478f45dc 100644
--- a/include/uapi/drm/apu_drm.h
+++ b/include/uapi/drm/apu_drm.h
@@ -9,6 +9,18 @@
extern "C" {
#endif
+/*
+ * Please note that modifications to all structs defined here are
+ * subject to backwards-compatibility constraints.
+ */
+
+struct drm_apu_gem_new {
+ __u32 size; /* in */
+ __u32 flags; /* in */
+ __u32 handle; /* out */
+ __u64 offset; /* out */
+};
+
#define APU_ONLINE BIT(0)
struct drm_apu_state {
@@ -17,9 +29,11 @@ struct drm_apu_state {
};
#define DRM_APU_STATE 0x00
-#define DRM_APU_NUM_IOCTLS 0x01
+#define DRM_APU_GEM_NEW 0x01
+#define DRM_APU_NUM_IOCTLS 0x02
#define DRM_IOCTL_APU_STATE DRM_IOWR(DRM_COMMAND_BASE + DRM_APU_STATE, struct drm_apu_state)
+#define DRM_IOCTL_APU_GEM_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_APU_GEM_NEW, struct drm_apu_gem_new)
#if defined(__cplusplus)
}
--
2.39.2
next prev parent reply other threads:[~2023-05-17 14:53 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-17 14:52 [PATCH 0/7] Add a DRM driver to support AI Processing Unit (APU) Alexandre Bailon
2023-05-17 14:52 ` [PATCH 1/7] drm: Add support of AI Processor " Alexandre Bailon
2023-05-17 14:52 ` Alexandre Bailon [this message]
2023-05-17 14:52 ` [PATCH 3/7] drm/apu: Add support of requests Alexandre Bailon
2023-05-17 14:52 ` [PATCH 4/7] drm/apu: Add support of IOMMU Alexandre Bailon
2023-05-18 13:24 ` Robin Murphy
2023-05-17 14:52 ` [PATCH 5/7] drm/apu: allow platform driver to implement their own mmap function Alexandre Bailon
2023-05-17 19:45 ` Krzysztof Kozlowski
2023-05-26 15:08 ` Alexandre Bailon
2023-05-17 14:52 ` [PATCH 6/7] drm/apu: Add support for a simulated APU Alexandre Bailon
2023-05-17 14:52 ` [PATCH 7/7] dt-bindings: Add bidings for mtk,apu-drm Alexandre Bailon
2023-05-17 15:04 ` AngeloGioacchino Del Regno
2023-05-17 17:28 ` Conor Dooley
2023-05-22 8:53 ` Alexandre Bailon
2023-05-17 15:28 ` Rob Herring
2023-05-17 16:53 ` Krzysztof Kozlowski
2023-05-17 19:38 ` Krzysztof Kozlowski
2023-05-17 19:41 ` Krzysztof Kozlowski
2023-05-17 15:05 ` [PATCH 0/7] Add a DRM driver to support AI Processing Unit (APU) Thomas Zimmermann
2023-05-17 15:12 ` Jeffrey Hugo
2023-05-23 23:34 ` Kevin Hilman
2023-05-24 10:27 ` Oded Gabbay
2023-05-24 10:40 ` Daniel Vetter
2023-05-26 15:45 ` Alexandre Bailon
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=20230517145237.295461-3-abailon@baylibre.com \
--to=abailon@baylibre.com \
--cc=airlied@gmail.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=bero@baylibre.com \
--cc=christian.koenig@amd.com \
--cc=conor+dt@kernel.org \
--cc=daniel@ffwll.ch \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=jstephan@baylibre.com \
--cc=khilman@baylibre.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthias.bgg@gmail.com \
--cc=mripard@kernel.org \
--cc=nbelin@baylibre.com \
--cc=robh+dt@kernel.org \
--cc=sumit.semwal@linaro.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