From patchwork Tue Feb 6 17:27:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 197555 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1697313dyb; Tue, 6 Feb 2024 09:29:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IG2k69K5+gNstL9yBvayOJrr8BKVXUIy4P6ixn3SyRIb60ZFzou6xCQ5gLEX4MLr2nDdLvp X-Received: by 2002:a17:90a:c288:b0:295:ee75:6090 with SMTP id f8-20020a17090ac28800b00295ee756090mr224663pjt.1.1707240569544; Tue, 06 Feb 2024 09:29:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707240569; cv=pass; d=google.com; s=arc-20160816; b=Q7sLZe9VUixFON+r5XJ8FX6NrvBpJHrwAKukeJAOUsLZia2YMiIEaR9Kzd3iAy+wrT 6vWEHu1cmj7VI36UjdPoYMxfbheMQN6xWo3UPqQE5v8vVkzq8g84ou+iCS0EO9guqEQI zNlmFxh21tmuoB4uuSU+wDV2iM1va1vnkZoobpvsjDdYSdDkjT/xxd1RmSMnFJDRsGsh qfni6vYwKoRcwjiUgvctvPURktOrqxtnZQWyuGY/Nn2BziJ0JKeoQMpdbLHBzSJAWCVo r24zwe+3hisuYbay6pO2u7EBP6/eKJC+/cXi+sHCxL27A8qdHZNNKfyASMDQAY0AK8t3 PIHA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=pOl+WgTjKJZRKMCx8JnZTX+9XX5z/UJw+mIPtTzvouc=; fh=x+k4nvlUewG1sdNF/UlPPurVXvjvIfUnAl/qaoT+1Z4=; b=zEuZfSh66JpCvd8sZSREyHCLU9uf5E0S2B2LvZHuwkjmvCdQuPtX5GfYdB8eEqvfbe 9bFk+W/kFqOD1neNaG1xEbzr84bhEHkTdoBJg2JVVExUcZGgNUGbsi9QY/IRcLUScyG/ 5Cv4RKVljL73yUa73veLFrTEKMq9uaBMvQKHIFlemGu3w/XjldwT9aq1xp0QhzMXvcmj 6JLhLxO7Kmljrhi0A6a1rtdocXdSwAE12DLMlvifpuzVJ4MaLlZScRNE+ChCd/cY3LUh QIVhQ1iaBykYjzqGeo/hd9XtC2gTO5/qX7UAriN3ISzHmhTK3WRK+JYuJMUtPGsy+jdp cV0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=AXkiw7Lk; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-55373-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55373-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=2; AJvYcCUq6+ru3g8vrzZUVlff9NGYTrBJj/4zrjdTIGT4TrH8ugi+yfckjWNZBQoezssHB3/0eXIy1638mr4IXM5wR1r4FazlVA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id o14-20020a17090a55ce00b00296049f2f70si1416810pjm.28.2024.02.06.09.29.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 09:29:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55373-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=AXkiw7Lk; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-55373-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55373-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D61C22870E3 for ; Tue, 6 Feb 2024 17:29:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 568CA134A4; Tue, 6 Feb 2024 17:28:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="AXkiw7Lk" Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91FBDDDCF for ; Tue, 6 Feb 2024 17:28:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240504; cv=none; b=WSPqEPlRDUJFlNVNfqWy9magI/QpjluexMHtLx8Cbj3QmF1ZhM0fqdoZrG+IaG6A48mgcf6ycc/RCMYH9gpHvFaoigqbKslozE0iKHEfg7v3jdmuLeWp53/7EfeFjGwetW1bEeDldIq+YaLERazG2xWo4h9iUaX2Rdz79VsxgPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240504; c=relaxed/simple; bh=xdcil5/20PO+KeGbybqbjvkgcj4h6betK4pcVEN+kEQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KP3pKew4RdML4ghKgAxCnl18JoffupjAj+6V7iTgx5GG2AQI69cjz+ZXWL4bxLCNvm68ASw1ulnVxDQk1YXEfhEfMosGJInD3PeC2Q2PorursT4NUK0O1GMHt+J6ovPtr0fnmSI1rTkaPEs/VQp4qsK7H30CWH340QdSWcT4+/s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=AXkiw7Lk; arc=none smtp.client-ip=95.215.58.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707240500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pOl+WgTjKJZRKMCx8JnZTX+9XX5z/UJw+mIPtTzvouc=; b=AXkiw7LknosjTimkeNik72XnkwvC61hx6D3LsGKh3kTI1I/TDMAln3jApZGBBVprJdtDwC QsXjZBfSBItjfO6qMXzR79qZHUpy2A/PWqu8f5rPQEeqKpuMG4QVhiec/ApWQgyhYc0IXP J6r5xZy2gtdavK8l5wuefY9tDUrPxco= From: Sui Jingfeng To: Lucas Stach Cc: Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , Maxime Ripard , Thomas Zimmermann , dri-devel@lists.freedesktop.org, etnaviv@lists.freedesktop.org, linux-kernel@vger.kernel.org, Sui Jingfeng Subject: [etnaviv-next v13 2/7] drm/etnaviv: Add constructor and destructor for the etnaviv_drm_private struct Date: Wed, 7 Feb 2024 01:27:54 +0800 Message-Id: <20240206172759.421737-3-sui.jingfeng@linux.dev> In-Reply-To: <20240206172759.421737-1-sui.jingfeng@linux.dev> References: <20240206172759.421737-1-sui.jingfeng@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790171487712855160 X-GMAIL-MSGID: 1790171487712855160 There are a lot of data members in the struct etnaviv_drm_private, which are intended to be shared by all GPU cores. Introduces two dedicated helper functions for the purpose of construction and destruction. After applied this patch, the error handling of the etnaviv_bind() gets simplified a lot. Another potential benefit is that we can also put the struct drm_device into struct etnaviv_drm_private in the future, as the instance of struct drm_device is also unique across all GPU cores. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 70 +++++++++++++++++---------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 4bdfb1c81eff..035ac0c6884f 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -41,6 +41,43 @@ static struct device_node *etnaviv_of_first_available_node(void) return NULL; } +static struct etnaviv_drm_private *etnaviv_alloc_private(struct device *dev) +{ + struct etnaviv_drm_private *priv; + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) + return ERR_PTR(-ENOMEM); + + xa_init_flags(&priv->active_contexts, XA_FLAGS_ALLOC); + + mutex_init(&priv->gem_lock); + INIT_LIST_HEAD(&priv->gem_list); + priv->num_gpus = 0; + priv->shm_gfp_mask = GFP_HIGHUSER | __GFP_RETRY_MAYFAIL | __GFP_NOWARN; + + priv->cmdbuf_suballoc = etnaviv_cmdbuf_suballoc_new(dev); + if (IS_ERR(priv->cmdbuf_suballoc)) { + kfree(priv); + dev_err(dev, "Failed to create cmdbuf suballocator\n"); + return ERR_PTR(-ENOMEM); + } + + return priv; +} + +static void etnaviv_free_private(struct etnaviv_drm_private *priv) +{ + if (!priv) + return; + + etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); + + xa_destroy(&priv->active_contexts); + + kfree(priv); +} + static void load_gpu(struct drm_device *dev) { struct etnaviv_drm_private *priv = dev->dev_private; @@ -521,35 +558,21 @@ static int etnaviv_bind(struct device *dev) if (IS_ERR(drm)) return PTR_ERR(drm); - priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) { - dev_err(dev, "failed to allocate private data\n"); - ret = -ENOMEM; + priv = etnaviv_alloc_private(dev); + if (IS_ERR(priv)) { + ret = PTR_ERR(priv); goto out_put; } + drm->dev_private = priv; dma_set_max_seg_size(dev, SZ_2G); - xa_init_flags(&priv->active_contexts, XA_FLAGS_ALLOC); - - mutex_init(&priv->gem_lock); - INIT_LIST_HEAD(&priv->gem_list); - priv->num_gpus = 0; - priv->shm_gfp_mask = GFP_HIGHUSER | __GFP_RETRY_MAYFAIL | __GFP_NOWARN; - - priv->cmdbuf_suballoc = etnaviv_cmdbuf_suballoc_new(drm->dev); - if (IS_ERR(priv->cmdbuf_suballoc)) { - dev_err(drm->dev, "Failed to create cmdbuf suballocator\n"); - ret = PTR_ERR(priv->cmdbuf_suballoc); - goto out_free_priv; - } - dev_set_drvdata(dev, drm); ret = component_bind_all(dev, drm); if (ret < 0) - goto out_destroy_suballoc; + goto out_free_priv; load_gpu(drm); @@ -561,10 +584,8 @@ static int etnaviv_bind(struct device *dev) out_unbind: component_unbind_all(dev, drm); -out_destroy_suballoc: - etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); out_free_priv: - kfree(priv); + etnaviv_free_private(priv); out_put: drm_dev_put(drm); @@ -580,12 +601,9 @@ static void etnaviv_unbind(struct device *dev) component_unbind_all(dev, drm); - etnaviv_cmdbuf_suballoc_destroy(priv->cmdbuf_suballoc); - - xa_destroy(&priv->active_contexts); + etnaviv_free_private(priv); drm->dev_private = NULL; - kfree(priv); drm_dev_put(drm); }