Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3186188rdb; Tue, 6 Feb 2024 09:28:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IFNcCDJQqQqSynCUk7R7BGOgIluoHeAVTpXynAE21qAXZTNYAsz/kMXXyiEBXTIRPhMNsz5 X-Received: by 2002:ac8:604a:0:b0:42a:a6ff:c889 with SMTP id k10-20020ac8604a000000b0042aa6ffc889mr2990167qtm.39.1707240534285; Tue, 06 Feb 2024 09:28:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707240534; cv=pass; d=google.com; s=arc-20160816; b=zy5QEetEKA6SKsvSxKlhq/K5vkfx0nG2tVrdwLvm/3CI8gIgA7aUYN5GrWpaMxkXan pUEL3Af9r2UHJnnSG0JcwblU2vmx9kgehVfbPWC3mNHCwGCKavEFeW0+uF/+hWEi8+gv JQTAQBX73PU5YeBUB/7omzHptWodbAbMOX4qWolQ8ZUcJ/semc7uH/JSaQKptqInZSSX aHe4b6zuQcnnsIq2S9erxvsZtX0h6htDUa6dJB2LuA1Z167FAiuhc5Sx1h74+JS81PZX 0NrXJXPxkkRLKltHqz4zbYfGzGtNgynJNqnXKUBcAi9HPRazslA5+Jggs19g+dE1eaYt 7TfA== 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=TT0vQD93KsASrxdbGswZqMKYovVF2LCmz64Rb1Zdy+s=; b=mAG3FLVJRX4H8XB9KvAApObTDZP5RdLtkmEdWuiR6HqzyS1UzkMAqb5V6r13PplD58 5sdWClv05RMuFtxrpmJ8igUQHJ8+oljlZTjTpiNjgFKYKJLYHSR2vSQRmaPXubnYVXdr irV4Qo722doTH1Q+2DEjiof795NEnZ81G89O8OAaYCGV+Dbe5onlXYL5VoD4H/xuP4yT JebWDgnqVWeKsFcdmuRr7X3k8JkEboWfzQmLqKM7ijBt3RueiLZglLujuQRPi77uOcmt ugk7SdYOUZfpHCcRbJbFalCuasjt6uG1JtIK1MG2CAnE7Iwe38l9afccnYy6qsn+kvzO y/xA==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55373-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=1; AJvYcCUxD93dY8WAEl0eVo+0r7aoIS+IJaaxdgTY89jXOG1dbXaEY99htvYb+DWJpZfrQWU1xJ7dkjXjMSJ9z+BXR0w+6oK0+/j/GtFIIEPpHg== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g13-20020ac8580d000000b0042c3b2613a2si615812qtg.546.2024.02.06.09.28.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 09:28:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55373-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55373-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 112071C234CE for ; Tue, 6 Feb 2024 17:28:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 52A32101CE; Tue, 6 Feb 2024 17:28:25 +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 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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); } -- 2.34.1