dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Brace <kevinbrace@gmx.com>
To: dri-devel@lists.freedesktop.org
Cc: Kevin Brace <kevinbrace@bracecomputerlab.com>
Subject: [PATCH v3 24/32] drm/via: Add via_ttm.c
Date: Mon, 25 Jul 2022 16:53:51 -0700	[thread overview]
Message-ID: <20220725235359.20516-5-kevinbrace@gmx.com> (raw)
In-Reply-To: <20220725235359.20516-1-kevinbrace@gmx.com>

From: Kevin Brace <kevinbrace@bracecomputerlab.com>

Signed-off-by: Kevin Brace <kevinbrace@bracecomputerlab.com>
---
 drivers/gpu/drm/via/via_ttm.c | 168 ++++++++++++++++++++++++++++++++++
 1 file changed, 168 insertions(+)
 create mode 100644 drivers/gpu/drm/via/via_ttm.c

diff --git a/drivers/gpu/drm/via/via_ttm.c b/drivers/gpu/drm/via/via_ttm.c
new file mode 100644
index 000000000000..8676623ee074
--- /dev/null
+++ b/drivers/gpu/drm/via/via_ttm.c
@@ -0,0 +1,168 @@
+/*
+ * Copyright © 2018-2019 Kevin Brace.
+ *
+ * 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, sub license,
+ * 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 (including the
+ * next paragraph) 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 NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(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.
+ *
+ * Author(s):
+ * Kevin Brace <kevinbrace@bracecomputerlab.com>
+ */
+/*
+ * via_ttm.c
+ *
+ * TTM code as part of the TTM memory allocator.
+ * Currently a basic implementation with no DMA support.
+ *
+ */
+
+#include <linux/pci.h>
+
+#include <drm/ttm/ttm_bo_api.h>
+#include <drm/ttm/ttm_bo_driver.h>
+
+#include "via_drv.h"
+
+
+static void via_bo_move_notify(struct ttm_buffer_object *bo, bool evict,
+				struct ttm_resource *new_mem)
+{
+	DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+	DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+	return;
+}
+
+static struct ttm_tt *via_ttm_tt_create(struct ttm_buffer_object *bo,
+					uint32_t page_flags)
+{
+	struct ttm_tt *tt;
+	int ret;
+
+	tt = kzalloc(sizeof(*tt), GFP_KERNEL);
+	if (!tt)
+		return NULL;
+
+	ret = ttm_tt_init(tt, bo, page_flags, ttm_cached, 0);
+	if (ret < 0)
+		goto err_ttm_tt_init;
+
+	return tt;
+
+err_ttm_tt_init:
+	kfree(tt);
+	return NULL;
+}
+
+static void via_ttm_tt_destroy(struct ttm_device *bdev, struct ttm_tt *tt)
+{
+	ttm_tt_fini(tt);
+	kfree(tt);
+}
+
+static void via_bo_evict_flags(struct ttm_buffer_object *bo,
+				struct ttm_placement *placement)
+{
+	struct via_bo *driver_bo = to_ttm_bo(bo);
+
+	DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+	if (bo->destroy == &via_ttm_bo_destroy) {
+		goto exit;
+	}
+
+	switch (bo->resource->mem_type) {
+	case TTM_PL_VRAM:
+		via_ttm_domain_to_placement(driver_bo, TTM_PL_VRAM);
+		break;
+	default:
+		via_ttm_domain_to_placement(driver_bo, TTM_PL_SYSTEM);
+		break;
+	}
+
+	*placement = driver_bo->placement;
+exit:
+	DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+}
+
+static int via_bo_move(struct ttm_buffer_object *bo, bool evict,
+			struct ttm_operation_ctx *ctx,
+			struct ttm_resource *new_mem,
+			struct ttm_place *hop)
+{
+	int ret;
+
+	DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+	via_bo_move_notify(bo, evict, new_mem);
+	ret = ttm_bo_move_memcpy(bo, ctx, new_mem);
+	if (ret) {
+		swap(*new_mem, *bo->resource);
+		via_bo_move_notify(bo, false, new_mem);
+		swap(*new_mem, *bo->resource);
+	}
+
+	DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+	return ret;
+}
+
+static void via_bo_delete_mem_notify(struct ttm_buffer_object *bo)
+{
+	DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+	via_bo_move_notify(bo, false, NULL);
+
+	DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+	return;
+}
+
+static int via_bo_io_mem_reserve(struct ttm_device *bdev,
+					struct ttm_resource *mem)
+{
+	struct via_drm_priv *dev_priv = container_of(bdev,
+						struct via_drm_priv, bdev);
+	int ret = 0;
+
+	DRM_DEBUG_KMS("Entered %s.\n", __func__);
+
+	switch (mem->mem_type) {
+	case TTM_PL_SYSTEM:
+		break;
+	case TTM_PL_VRAM:
+		mem->bus.offset = dev_priv->vram_start +
+					(mem->start << PAGE_SHIFT);
+		mem->bus.is_iomem = true;
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	DRM_DEBUG_KMS("Exiting %s.\n", __func__);
+	return ret;
+}
+
+struct ttm_device_funcs via_bo_driver = {
+	.ttm_tt_create = via_ttm_tt_create,
+	.ttm_tt_destroy = via_ttm_tt_destroy,
+	.eviction_valuable = ttm_bo_eviction_valuable,
+	.evict_flags = via_bo_evict_flags,
+	.move = via_bo_move,
+	.delete_mem_notify = via_bo_delete_mem_notify,
+	.io_mem_reserve = via_bo_io_mem_reserve,
+};
--
2.35.1


  parent reply	other threads:[~2022-07-25 23:54 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-25 23:53 [PATCH v3 20/32] drm/via: Add via_pll.c Kevin Brace
2022-07-25 23:53 ` [PATCH v3 21/32] drm/via: Add via_pm.c Kevin Brace
2022-07-25 23:53 ` [PATCH v3 22/32] drm/via: Add via_sii164.c Kevin Brace
2022-07-25 23:53 ` [PATCH v3 23/32] drm/via: Add via_tmds.c Kevin Brace
2022-07-25 23:53 ` Kevin Brace [this message]
2022-07-25 23:53 ` [PATCH v3 25/32] drm/via: Add via_vt1632.c Kevin Brace
2022-07-25 23:53 ` [PATCH v3 26/32] drm/via: Add via_drm.h Kevin Brace
2022-07-26 17:41   ` Sam Ravnborg
2022-07-26 18:18     ` Thomas Zimmermann
2022-07-26 20:20       ` Dave Airlie
2022-07-27  7:36         ` Thomas Zimmermann
2022-07-29  1:06         ` Kevin Brace
2022-07-31  2:14     ` Kevin Brace
2022-07-26 18:24   ` Thomas Zimmermann
2022-07-30 22:48     ` Kevin Brace
2022-08-01 14:40       ` Sam Ravnborg
2022-08-02  0:10         ` Kevin Brace
2022-08-02 11:09           ` Sam Ravnborg
2022-08-02 18:12             ` Kevin Brace
2022-08-01 18:49       ` Thomas Zimmermann
2022-08-02  3:45         ` Kevin Brace
2022-08-02 11:38           ` Thomas Zimmermann
2022-08-03  1:49             ` Kevin Brace
2022-08-04 12:20               ` Thomas Zimmermann
2022-08-04 15:09                 ` Sam Ravnborg
2022-07-25 23:53 ` [PATCH v3 27/32] drm/via: Add new VIA Technologies Chrome supporting PCI IDs to DRM Kevin Brace
2022-07-25 23:53 ` [PATCH v3 28/32] drm/via: Zero out chip type field Kevin Brace
2022-07-25 23:53 ` [PATCH v3 29/32] drm/via: Add new VIA Technologies PCI device IDs related to graphics Kevin Brace
2022-07-25 23:53 ` [PATCH v3 30/32] drm/via: Add Kconfig Kevin Brace
2022-07-26  7:28   ` Thomas Zimmermann
2022-07-31  1:49     ` Kevin Brace
2022-08-01 10:36       ` Thomas Zimmermann
2022-07-25 23:53 ` [PATCH v3 31/32] drm/via: Add Makefile Kevin Brace
2022-07-26  7:29   ` Thomas Zimmermann
2022-07-31  1:55     ` Kevin Brace
2022-07-25 23:53 ` [PATCH v3 32/32] drm/via: Modify DRM core to be able to build OpenChrome DRM Kevin Brace

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=20220725235359.20516-5-kevinbrace@gmx.com \
    --to=kevinbrace@gmx.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kevinbrace@bracecomputerlab.com \
    /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).