From patchwork Fri Sep 10 13:15:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Hellstrom X-Patchwork-Id: 12485123 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FD6FC433EF for ; Fri, 10 Sep 2021 13:15:51 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4205061074 for ; Fri, 10 Sep 2021 13:15:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4205061074 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 446EF6E9F8; Fri, 10 Sep 2021 13:15:47 +0000 (UTC) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 27F0D6E9F7; Fri, 10 Sep 2021 13:15:45 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10102"; a="284777475" X-IronPort-AV: E=Sophos;i="5.85,282,1624345200"; d="scan'208";a="284777475" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2021 06:15:44 -0700 X-IronPort-AV: E=Sophos;i="5.85,282,1624345200"; d="scan'208";a="467107526" Received: from gjanssen-mobl5.ger.corp.intel.com (HELO thellstr-mobl1.intel.com) ([10.249.254.69]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2021 06:15:42 -0700 From: =?utf-8?q?Thomas_Hellstr=C3=B6m?= To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: maarten.lankhorst@linux.intel.com, matthew.auld@intel.com, =?utf-8?q?Tho?= =?utf-8?q?mas_Hellstr=C3=B6m?= , Matthew Auld , =?utf-8?q?K=C3=B6nig_Christi?= =?utf-8?q?an?= Date: Fri, 10 Sep 2021 15:15:12 +0200 Message-Id: <20210910131512.161655-1-thomas.hellstrom@linux.intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [Intel-gfx] [RFC PATCH] drm/ttm: Add a private member to the struct ttm_resource X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Both the provider (resource manager) and the consumer (the TTM driver) want to subclass struct ttm_resource. Since this is left for the resource manager, we need to provide a private pointer for the TTM driver. Provide a struct ttm_resource_private for the driver to subclass for data with the same lifetime as the struct ttm_resource: In the i915 case it will, for example, be an sg-table and radix tree into the LMEM /VRAM pages that currently are awkwardly attached to the GEM object. Provide an ops structure for associated ops (Which is only destroy() ATM) It might seem pointless to provide a separate ops structure, but Linus has previously made it clear that that's the norm. After careful audit one could perhaps also on a per-driver basis replace the delete_mem_notify() TTM driver callback with the above destroy function. Cc: Matthew Auld Cc: König Christian Signed-off-by: Thomas Hellström --- drivers/gpu/drm/ttm/ttm_resource.c | 10 +++++++--- include/drm/ttm/ttm_resource.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c index 2431717376e7..973e7c50bfed 100644 --- a/drivers/gpu/drm/ttm/ttm_resource.c +++ b/drivers/gpu/drm/ttm/ttm_resource.c @@ -57,13 +57,17 @@ int ttm_resource_alloc(struct ttm_buffer_object *bo, void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res) { struct ttm_resource_manager *man; + struct ttm_resource *resource = *res; - if (!*res) + if (!resource) return; - man = ttm_manager_type(bo->bdev, (*res)->mem_type); - man->func->free(man, *res); *res = NULL; + if (resource->priv) + resource->priv->ops.destroy(resource->priv); + + man = ttm_manager_type(bo->bdev, resource->mem_type); + man->func->free(man, resource); } EXPORT_SYMBOL(ttm_resource_free); diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h index 140b6b9a8bbe..5a22c9a29c05 100644 --- a/include/drm/ttm/ttm_resource.h +++ b/include/drm/ttm/ttm_resource.h @@ -44,6 +44,7 @@ struct dma_buf_map; struct io_mapping; struct sg_table; struct scatterlist; +struct ttm_resource_private; struct ttm_resource_manager_func { /** @@ -153,6 +154,32 @@ struct ttm_bus_placement { enum ttm_caching caching; }; +/** + * struct ttm_resource_private_ops - Operations for a struct + * ttm_resource_private + * + * Not much benefit to keep this as a separate struct with only a single member, + * but keeping a separate ops struct is the norm. + */ +struct ttm_resource_private_ops { + /** + * destroy() - Callback to destroy the private data + * @priv - The private data to destroy + */ + void (*destroy) (struct ttm_resource_private *priv); +}; + +/** + * struct ttm_resource_private - TTM driver private data + * @ops: Pointer to struct ttm_resource_private_ops with associated operations + * + * Intended to be subclassed to hold, for example cached data sharing the + * lifetime with a struct ttm_resource. + */ +struct ttm_resource_private { + const struct ttm_resource_private_ops ops; +}; + /** * struct ttm_resource * @@ -171,6 +198,7 @@ struct ttm_resource { uint32_t mem_type; uint32_t placement; struct ttm_bus_placement bus; + struct ttm_resource_private *priv; }; /**