From: Qiang Yu <yuq825@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: Simon Shields <simon@lineageos.org>, Marek Vasut <marex@denx.de>,
Connor Abbott <cwabbott0@gmail.com>,
Neil Armstrong <narmstrong@baylibre.com>,
Andrei Paulau <7134956@gmail.com>,
Vasily Khoruzhick <anarsoul@gmail.com>,
Qiang Yu <yuq825@gmail.com>, Erico Nunes <nunes.erico@gmail.com>
Subject: [PATCH RFC 19/24] drm/lima: add buffer object functions
Date: Sat, 19 May 2018 14:52:38 +0800 [thread overview]
Message-ID: <20180519065243.27600-20-yuq825@gmail.com> (raw)
In-Reply-To: <20180519065243.27600-1-yuq825@gmail.com>
Signed-off-by: Qiang Yu <yuq825@gmail.com>
---
drivers/gpu/drm/lima/lima_object.c | 120 +++++++++++++++++++++++++++++
drivers/gpu/drm/lima/lima_object.h | 87 +++++++++++++++++++++
2 files changed, 207 insertions(+)
create mode 100644 drivers/gpu/drm/lima/lima_object.c
create mode 100644 drivers/gpu/drm/lima/lima_object.h
diff --git a/drivers/gpu/drm/lima/lima_object.c b/drivers/gpu/drm/lima/lima_object.c
new file mode 100644
index 000000000000..5a22b235626b
--- /dev/null
+++ b/drivers/gpu/drm/lima/lima_object.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2017-2018 Lima Project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <drm/drm_prime.h>
+
+#include "lima_object.h"
+
+static void lima_bo_init_placement(struct lima_bo *bo)
+{
+ struct ttm_placement *placement = &bo->placement;
+ struct ttm_place *place = &bo->place;
+
+ place->fpfn = 0;
+ place->lpfn = 0;
+ place->flags = TTM_PL_FLAG_TT | TTM_PL_FLAG_WC;
+
+ /* pin all bo for now */
+ place->flags |= TTM_PL_FLAG_NO_EVICT;
+
+ placement->num_placement = 1;
+ placement->placement = place;
+
+ placement->num_busy_placement = 1;
+ placement->busy_placement = place;
+}
+
+static void lima_bo_destroy(struct ttm_buffer_object *tbo)
+{
+ struct lima_bo *bo = ttm_to_lima_bo(tbo);
+
+ if (bo->gem.import_attach)
+ drm_prime_gem_destroy(&bo->gem, bo->tbo.sg);
+ drm_gem_object_release(&bo->gem);
+ kfree(bo);
+}
+
+struct lima_bo *lima_bo_create(struct lima_device *dev, u64 size,
+ u32 flags, enum ttm_bo_type type,
+ struct sg_table *sg,
+ struct reservation_object *resv)
+{
+ struct lima_bo *bo;
+ struct ttm_mem_type_manager *man;
+ size_t acc_size;
+ int err;
+
+ size = PAGE_ALIGN(size);
+ man = dev->mman.bdev.man + TTM_PL_TT;
+ if (size >= (man->size << PAGE_SHIFT))
+ return ERR_PTR(-ENOMEM);
+
+ acc_size = ttm_bo_dma_acc_size(&dev->mman.bdev, size,
+ sizeof(struct lima_bo));
+
+ bo = kzalloc(sizeof(*bo), GFP_KERNEL);
+ if (!bo)
+ return ERR_PTR(-ENOMEM);
+
+ drm_gem_private_object_init(dev->ddev, &bo->gem, size);
+
+ INIT_LIST_HEAD(&bo->va);
+
+ bo->tbo.bdev = &dev->mman.bdev;
+
+ lima_bo_init_placement(bo);
+
+ err = ttm_bo_init(&dev->mman.bdev, &bo->tbo, size, type,
+ &bo->placement, 0, type != ttm_bo_type_kernel,
+ acc_size, sg, resv, &lima_bo_destroy);
+ if (err)
+ goto err_out;
+
+ return bo;
+
+err_out:
+ kfree(bo);
+ return ERR_PTR(err);
+}
+
+dma_addr_t *lima_bo_get_pages(struct lima_bo *bo)
+{
+ struct lima_ttm_tt *ttm = (void *)bo->tbo.ttm;
+ return ttm->ttm.dma_address;
+}
+
+void *lima_bo_kmap(struct lima_bo *bo)
+{
+ bool is_iomem;
+ void *ret;
+ int err;
+
+ ret = ttm_kmap_obj_virtual(&bo->kmap, &is_iomem);
+ if (ret)
+ return ret;
+
+ err = ttm_bo_kmap(&bo->tbo, 0, bo->tbo.num_pages, &bo->kmap);
+ if (err)
+ return ERR_PTR(err);
+
+ return ttm_kmap_obj_virtual(&bo->kmap, &is_iomem);
+}
diff --git a/drivers/gpu/drm/lima/lima_object.h b/drivers/gpu/drm/lima/lima_object.h
new file mode 100644
index 000000000000..2b8b8fcb9063
--- /dev/null
+++ b/drivers/gpu/drm/lima/lima_object.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2017-2018 Lima Project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIMA_OBJECT_H__
+#define __LIMA_OBJECT_H__
+
+#include <drm/drm_gem.h>
+#include <drm/ttm/ttm_placement.h>
+#include <drm/ttm/ttm_bo_api.h>
+
+#include "lima_device.h"
+
+struct lima_bo {
+ struct drm_gem_object gem;
+
+ struct ttm_place place;
+ struct ttm_placement placement;
+ struct ttm_buffer_object tbo;
+ struct ttm_bo_kmap_obj kmap;
+
+ struct list_head va;
+};
+
+static inline struct lima_bo *
+to_lima_bo(struct drm_gem_object *obj)
+{
+ return container_of(obj, struct lima_bo, gem);
+}
+
+static inline struct lima_bo *
+ttm_to_lima_bo(struct ttm_buffer_object *tbo)
+{
+ return container_of(tbo, struct lima_bo, tbo);
+}
+
+static inline int lima_bo_reserve(struct lima_bo *bo, bool intr)
+{
+ struct lima_device *dev = ttm_to_lima_dev(bo->tbo.bdev);
+ int r;
+
+ r = ttm_bo_reserve(&bo->tbo, intr, false, NULL);
+ if (unlikely(r != 0)) {
+ if (r != -ERESTARTSYS)
+ dev_err(dev->dev, "%p reserve failed\n", bo);
+ return r;
+ }
+ return 0;
+}
+
+static inline void lima_bo_unreserve(struct lima_bo *bo)
+{
+ ttm_bo_unreserve(&bo->tbo);
+}
+
+struct lima_bo *lima_bo_create(struct lima_device *dev, u64 size,
+ u32 flags, enum ttm_bo_type type,
+ struct sg_table *sg,
+ struct reservation_object *resv);
+
+static inline void lima_bo_unref(struct lima_bo *bo)
+{
+ struct ttm_buffer_object *tbo = &bo->tbo;
+ ttm_bo_unref(&tbo);
+}
+
+dma_addr_t *lima_bo_get_pages(struct lima_bo *bo);
+void *lima_bo_kmap(struct lima_bo *bo);
+
+#endif
--
2.17.0
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2018-05-19 6:54 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-19 6:52 [PATCH RFC 00/24] Lima DRM driver Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 01/24] ARM: dts: add gpu node to exynos4 Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 02/24] dt-bindings: add switch-delay property for mali-utgard Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 03/24] arm64/dts: add switch-delay for meson mali Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 04/24] " Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 05/24] Revert "drm: Nerf the preclose callback for modern drivers" Qiang Yu
2018-05-21 19:37 ` Eric Anholt
2018-05-22 1:04 ` Qiang Yu
2018-05-23 9:04 ` Daniel Vetter
2018-05-23 12:59 ` Qiang Yu
2018-05-23 20:31 ` Daniel Vetter
2018-05-24 1:18 ` Qiang Yu
2018-05-24 7:51 ` Daniel Vetter
2018-05-24 8:55 ` Qiang Yu
2018-05-30 18:13 ` Eric Anholt
2018-05-31 14:04 ` Qiang Yu
2018-05-31 17:51 ` Eric Anholt
2018-05-31 18:04 ` Keith Packard
2018-06-01 2:03 ` Qiang Yu
2018-06-01 1:58 ` Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 06/24] drm/lima: add lima uapi header Qiang Yu
2018-05-21 19:51 ` Eric Anholt
2018-05-22 1:33 ` Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 07/24] drm/lima: add mali 4xx GPU hardware regs Qiang Yu
2018-05-19 11:20 ` Marek Vasut
2018-05-19 6:52 ` [PATCH RFC 08/24] drm/lima: add lima core driver Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 09/24] drm/lima: add GPU device functions Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 10/24] drm/lima: add PMU related functions Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 11/24] drm/lima: add L2 cache functions Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 12/24] drm/lima: add GP related functions Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 13/24] drm/lima: add PP " Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 14/24] drm/lima: add MMU " Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 15/24] drm/lima: add BCAST related function Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 16/24] drm/lima: add DLBU related functions Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 17/24] drm/lima: add GPU virtual memory space handing Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 18/24] drm/lima: add TTM subsystem functions Qiang Yu
2018-05-19 6:52 ` Qiang Yu [this message]
2018-05-19 6:52 ` [PATCH RFC 20/24] drm/lima: add GEM related functions Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 21/24] drm/lima: add GEM Prime " Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 22/24] drm/lima: add GPU schedule using DRM_SCHED Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 23/24] drm/lima: add context related functions Qiang Yu
2018-05-19 6:52 ` [PATCH RFC 24/24] drm/lima: add makefile and kconfig Qiang Yu
-- strict thread matches above, loose matches on Subject: below --
2018-05-18 9:27 [PATCH RFC 00/24] Lima DRM driver Qiang Yu
2018-05-18 9:28 ` [PATCH RFC 19/24] drm/lima: add buffer object functions Qiang Yu
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=20180519065243.27600-20-yuq825@gmail.com \
--to=yuq825@gmail.com \
--cc=7134956@gmail.com \
--cc=anarsoul@gmail.com \
--cc=cwabbott0@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=marex@denx.de \
--cc=narmstrong@baylibre.com \
--cc=nunes.erico@gmail.com \
--cc=simon@lineageos.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).