Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id DF137C83F12 for ; Wed, 9 Jul 2025 10:55:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A387C10E79E; Wed, 9 Jul 2025 10:55:06 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="EwKWQhX2"; dkim-atps=neutral Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id C024210E79A for ; Wed, 9 Jul 2025 10:55:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=XQ+drx5YwqY90JUZegQXFOMecCJ6zGYMg/Q3wa2Y+xw=; b=EwKWQhX2CNfjEuANS1wOxwjtty JEKXj1Md4GTFzA0fqpFdmCPn/Wj8BU3hx4B1Nf2v5rxlv3VPdJFZ6aFduoFiLjQG+6NEzUGBvDTzk A895nSo8P1SNOmtpQ5Vz/oS1uSdeLhWksHXkABWzRYSAwYiwKDkq8pyviKs0An5M1XKO0jc2kuh6S YGGT4O+RwUhPcWjLlJcyKQd8iXC+01lXcvgFIV8eHvVgYtVQ874YuQihhy7ZLeoOCeXMG53ONCXcV i0ogIHOdRLlhptpj9Vggagt1y4urOwgSNfQMrd6qbcv2s3MYuidS2mbNjfslhYYH7A/BBTSgDL5dc k3fK+tmA==; Received: from [84.65.48.237] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uZSS4-00EQnh-0Y; Wed, 09 Jul 2025 12:55:00 +0200 From: Tvrtko Ursulin To: intel-xe@lists.freedesktop.org Cc: kernel-dev@igalia.com, Tvrtko Ursulin , Lucas De Marchi Subject: [PATCH v9 2/8] drm/xe: Pass wa bb setup arguments in a struct Date: Wed, 9 Jul 2025 11:54:49 +0100 Message-ID: <20250709105455.93902-3-tvrtko.ursulin@igalia.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: <20250709105455.93902-1-tvrtko.ursulin@igalia.com> References: <20250709105455.93902-1-tvrtko.ursulin@igalia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" Group the function arguments in a struct for more readable code and easier extending. Signed-off-by: Tvrtko Ursulin Cc: Lucas De Marchi --- drivers/gpu/drm/xe/xe_lrc.c | 91 +++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_lrc.c b/drivers/gpu/drm/xe/xe_lrc.c index 2385e22437b3..578bef1e8140 100644 --- a/drivers/gpu/drm/xe/xe_lrc.c +++ b/drivers/gpu/drm/xe/xe_lrc.c @@ -977,32 +977,39 @@ struct bo_setup { u32 *batch, size_t max_size); }; -static u32 *setup_bo(struct xe_lrc *lrc, - struct xe_hw_engine *hwe, - const size_t max_size, - unsigned int offset, - const struct bo_setup *funcs, - unsigned int num_funcs, - u32 **free) +struct bo_setup_state { + /* Input: */ + struct xe_lrc *lrc; + struct xe_hw_engine *hwe; + size_t max_size; + unsigned offset; + const struct bo_setup *funcs; + unsigned num_funcs; + + /* State: */ + u32 *buffer; + u32 *ptr; +}; + +static int setup_bo(struct bo_setup_state *state) { - u32 *cmd, *buf = NULL; ssize_t remain; - if (lrc->bo->vmap.is_iomem) { - buf = kmalloc(max_size, GFP_KERNEL); - if (!buf) - return ERR_PTR(-ENOMEM); - cmd = buf; - *free = buf; + if (state->lrc->bo->vmap.is_iomem) { + state->buffer = kmalloc(state->max_size, GFP_KERNEL); + if (!state->buffer) + return -ENOMEM; + state->ptr = state->buffer; } else { - cmd = lrc->bo->vmap.vaddr + offset; - *free = NULL; + state->ptr = state->lrc->bo->vmap.vaddr + state->offset; + state->buffer = NULL; } - remain = max_size / sizeof(*cmd); + remain = state->max_size / sizeof(u32); - for (size_t i = 0; i < num_funcs; i++) { - ssize_t len = funcs[i].setup(lrc, hwe, cmd, remain); + for (size_t i = 0; i < state->num_funcs; i++) { + ssize_t len = state->funcs[i].setup(state->lrc, state->hwe, + state->ptr, remain); remain -= len; @@ -1010,28 +1017,28 @@ static u32 *setup_bo(struct xe_lrc *lrc, * There should always be at least 1 additional dword for * the end marker */ - if (len < 0 || xe_gt_WARN_ON(lrc->gt, remain < 1)) + if (len < 0 || xe_gt_WARN_ON(state->lrc->gt, remain < 1)) goto fail; - cmd += len; + state->ptr += len; } - return cmd; + return 0; fail: - kfree(buf); - return ERR_PTR(-ENOSPC); + kfree(state->buffer); + return -ENOSPC; } -static void finish_bo(struct xe_lrc *lrc, unsigned int offset, u32 *cmd, - u32 *free) +static void finish_bo(struct bo_setup_state *state) { - if (!free) + if (!state->buffer) return; - xe_map_memcpy_to(gt_to_xe(lrc->gt), &lrc->bo->vmap, offset, free, - (cmd - free) * sizeof(*cmd)); - kfree(free); + xe_map_memcpy_to(gt_to_xe(state->lrc->gt), &state->lrc->bo->vmap, + state->offset, state->buffer, + (state->ptr - state->buffer) * sizeof(u32)); + kfree(state->buffer); } static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe) @@ -1039,20 +1046,26 @@ static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe) static const struct bo_setup funcs[] = { { .setup = wa_bb_setup_utilization }, }; - unsigned int offset = __xe_lrc_wa_bb_offset(lrc); - u32 *cmd, *buf = NULL; + struct bo_setup_state state = { + .lrc = lrc, + .hwe = hwe, + .max_size = LRC_WA_BB_SIZE, + .offset = __xe_lrc_wa_bb_offset(lrc), + .funcs = funcs, + .num_funcs = ARRAY_SIZE(funcs), + }; + int ret; - cmd = setup_bo(lrc, hwe, LRC_WA_BB_SIZE, offset, funcs, - ARRAY_SIZE(funcs), &buf); - if (IS_ERR(cmd)) - return PTR_ERR(cmd); + ret = setup_bo(&state); + if (ret) + return ret; - *cmd++ = MI_BATCH_BUFFER_END; + *state.ptr++ = MI_BATCH_BUFFER_END; - finish_bo(lrc, offset, cmd, buf); + finish_bo(&state); xe_lrc_write_ctx_reg(lrc, CTX_BB_PER_CTX_PTR, - xe_bo_ggtt_addr(lrc->bo) + offset + 1); + xe_bo_ggtt_addr(lrc->bo) + state.offset + 1); return 0; } -- 2.48.0