From patchwork Tue Feb 6 17:27:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 197554 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1696931dyb; Tue, 6 Feb 2024 09:28:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmelZrZqXY63M2/AO4jRKa5RaKPs1jdzksa5LHAVwX4/rPBBHoPsrcVrrUeBHTs5OM5vF2 X-Received: by 2002:a0c:a9dc:0:b0:68c:4b59:d4ee with SMTP id c28-20020a0ca9dc000000b0068c4b59d4eemr4062357qvb.21.1707240528429; Tue, 06 Feb 2024 09:28:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707240528; cv=pass; d=google.com; s=arc-20160816; b=vz1WmKOX5i/daUbkyqqFOymtX8HtI4bD9I71/ThEJETRuorIT/VIBcPWzufhtEIoeK rK1YR78hQbuHSTi5a5/Zuc2n6e0LGiRxp9vtoB4ZTGUCOou0fc8HuQGQ3kQC+aFlNqj+ 7nAbEbS8ww3a0PyGyYNH8vTPRZD9jrPqdlZ/g+ckIfPnGfAfLeHXzTEFyrZfW24B/8EW iQUB2hZ/5aA/lfJuVSMiC39r1pF4M7dfGkDeOgCotYU6IRUsx7ZBEczGHgtou44k5r9D CfTHS4e4gp6ys+MFHNFs+RKsA36wqsFbs0cZGZrpjYXJiBUMNq94gvDhx5nIINE+Ny60 Q9Wg== 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=BJeg+jbAcpnrVW6uuGDu8kXydhp7MfSBefIfBQvVhDk=; fh=tJ39T9O5nbJO+YdjMxlBbaFDNmsp0QVSvAof+ws9ERI=; b=xnCtsIm+28GKnqcstnjWBEHNlJl3YbCFG45BjzMP5BH8ff95faKKVmFc28UnqSkizW DLwBaT0uvFRNU3ME8FsOORYg1jhEOnds1LJwZS8xulno0Va1VMy0jKdGV7QmP/Bmyi62 vaLG+e97lcNWnnKVXqk8iQ28KVhZsby5ds6DMFiZPpQgbUWON7bOL8+NHkUd8ZwMxW8V nzbby8jT+qqn0rhFC6O6W0wzCdEz7u/tezIi+/gexeWKpJRr1J0hVa2S77nMoLA50uTy MsxT62NSK2EZUQ3zfBRQBMLiWOWn4OB+2nRgKWk7+J7Lvmwher5sYOyikLJa+RGGn+lX 0SOQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=i0jM8bBH; 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-55372-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55372-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=1; AJvYcCVbXsLmLjWedRTczQT9yr2q/l8DpV6y516pXl0mTTE/5cBDD4la61aAkZANvW0qx1/ImgtG6pynTpewiLx2VEYUlrlG2w== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id bd25-20020ad45699000000b0068cb82b0b87si773322qvb.195.2024.02.06.09.28.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 09:28:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55372-ouuuleilei=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=i0jM8bBH; 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-55372-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55372-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3ACA71C233F9 for ; Tue, 6 Feb 2024 17:28:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E09CFDDDC; Tue, 6 Feb 2024 17:28:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="i0jM8bBH" Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) (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 65D968F6F for ; Tue, 6 Feb 2024 17:28:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240500; cv=none; b=ApiaRGJSoyPw8KPMzVkC4g4esku/TZpn25/RbqduXTPRD6vmnKRDhe/bNesvozbsRiv0vL1U4r0jqLY2ghxFBSkur1DyqVqHmrvdYXCGKFE2PO2r8LzRbl3sjrxNDPshHCTtj4QiV985SlnG0CVyS8hNw5cJK0nuY+iyp2eius0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240500; c=relaxed/simple; bh=LYt6rRRAtz1tm8JjwmQJDe6JgOXcLEFYmNIyU0Zk4ew=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XjECk0VJ4D42UxPs2G/W7e7w/ZRlg61+HZ0MQRZ56oibiJgY0+wt1SEYhcWBXPv8rCngR+Wz9gSH8Wvjthj27DCT+V+gy0oCaeOMDD2cz8Am/Acv1n1L5MRVAk9JyDiddfpqzhWXSz+nondtGbVy3GppRQQS0MGNPgAyRg99z68= 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=i0jM8bBH; arc=none smtp.client-ip=95.215.58.179 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=1707240496; 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=BJeg+jbAcpnrVW6uuGDu8kXydhp7MfSBefIfBQvVhDk=; b=i0jM8bBHnaZzGn07/ZaR92j+Iu1f4A+Cgb8phFRhlfoT8PgwxmsUTchLLn6lKUrr19AHY5 JdBUHc6dtAMo0LCObrJqRS4qFFuPhU1C69xvB4mmudD5s0YrJCAlbGN5/6pJwye5WVPsQY P9m2JwQ3BrypIAMlYED2dzpX4SUOX8g= 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 1/7] drm/etnaviv: Add a helper function to get clocks Date: Wed, 7 Feb 2024 01:27:53 +0800 Message-Id: <20240206172759.421737-2-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: 1790171444508710052 X-GMAIL-MSGID: 1790171444508710052 Because the current implementation is DT-based, this only works when the host platform has the DT support. The problem is that some host platforms does not provide DT-based clocks drivers, as a result, the driver rage quit. For example, the X86-64 and LoongArch desktop platform. Typically, PLL hardware is provided by the host platform, which is part of the entire clock tree, the PLL hardware provide clock pulse to the GPU core, but it's not belong to the GPU core. PLL registers can be manipulated directly by the device driver. Hence, add a dedicated helper function to get the various clocks, which make it possible to call this function only on the platform where DT support is available. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 53 ++++++++++++++++----------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index ce1e970f0209..654bf2631755 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1617,6 +1617,35 @@ static irqreturn_t irq_handler(int irq, void *data) return ret; } +static int etnaviv_gpu_clk_get(struct etnaviv_gpu *gpu) +{ + struct device *dev = gpu->dev; + + gpu->clk_reg = devm_clk_get_optional(dev, "reg"); + DBG("clk_reg: %p", gpu->clk_reg); + if (IS_ERR(gpu->clk_reg)) + return PTR_ERR(gpu->clk_reg); + + gpu->clk_bus = devm_clk_get_optional(dev, "bus"); + DBG("clk_bus: %p", gpu->clk_bus); + if (IS_ERR(gpu->clk_bus)) + return PTR_ERR(gpu->clk_bus); + + gpu->clk_core = devm_clk_get(dev, "core"); + DBG("clk_core: %p", gpu->clk_core); + if (IS_ERR(gpu->clk_core)) + return PTR_ERR(gpu->clk_core); + gpu->base_rate_core = clk_get_rate(gpu->clk_core); + + gpu->clk_shader = devm_clk_get_optional(dev, "shader"); + DBG("clk_shader: %p", gpu->clk_shader); + if (IS_ERR(gpu->clk_shader)) + return PTR_ERR(gpu->clk_shader); + gpu->base_rate_shader = clk_get_rate(gpu->clk_shader); + + return 0; +} + static int etnaviv_gpu_clk_enable(struct etnaviv_gpu *gpu) { int ret; @@ -1892,27 +1921,9 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) } /* Get Clocks: */ - gpu->clk_reg = devm_clk_get_optional(&pdev->dev, "reg"); - DBG("clk_reg: %p", gpu->clk_reg); - if (IS_ERR(gpu->clk_reg)) - return PTR_ERR(gpu->clk_reg); - - gpu->clk_bus = devm_clk_get_optional(&pdev->dev, "bus"); - DBG("clk_bus: %p", gpu->clk_bus); - if (IS_ERR(gpu->clk_bus)) - return PTR_ERR(gpu->clk_bus); - - gpu->clk_core = devm_clk_get(&pdev->dev, "core"); - DBG("clk_core: %p", gpu->clk_core); - if (IS_ERR(gpu->clk_core)) - return PTR_ERR(gpu->clk_core); - gpu->base_rate_core = clk_get_rate(gpu->clk_core); - - gpu->clk_shader = devm_clk_get_optional(&pdev->dev, "shader"); - DBG("clk_shader: %p", gpu->clk_shader); - if (IS_ERR(gpu->clk_shader)) - return PTR_ERR(gpu->clk_shader); - gpu->base_rate_shader = clk_get_rate(gpu->clk_shader); + err = etnaviv_gpu_clk_get(gpu); + if (err) + return err; /* TODO: figure out max mapped size */ dev_set_drvdata(dev, gpu); 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); } From patchwork Tue Feb 6 17:27:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 197556 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1697424dyb; Tue, 6 Feb 2024 09:29:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmXhFJz+/wBnLnnVJ5t+Nz1JuPO1VbmdcKt9bGYMjvd44sWVyLEBmKyvo91lA9lZ4/tFPP X-Received: by 2002:a05:6870:3290:b0:218:4c81:4f55 with SMTP id q16-20020a056870329000b002184c814f55mr4027496oac.44.1707240584606; Tue, 06 Feb 2024 09:29:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707240584; cv=pass; d=google.com; s=arc-20160816; b=jTTB88Vtxr+zQOuIWJ51Dm+JIbBjFNSseFgf2kMtogbP1BRbiIo8O89bUsC9cFYUlU kOKSxrQJUedbgw2XrKY2yurrbVfkMIIQQq49ziUq7Q6mqQunSew/86bSm4JxZZSQssq1 0pGUy8jD7yps+zK5FPfrTtKNMF/1Gn6zBvN8Eu0QUfPn90QwzVcFFK7xkxNHDh3NYsug lVZ2uoE6EW7rnCB3YHWqBydfWG0Om4f++RWE+b6kSGq8dXX4BUEODWpmzAmfiLQPDoKa pjjTcrsD6q3mKp6ypLxvchSv6bOk24z0ZpAdfIG5cwCofxsHI6XxY2AkroOr8q/m21yS PETA== 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=8HAy2xAuPJeCpNnNishsphDqlFIPREAv9Gabwc+YWgA=; fh=SJQASU3G9K3c8V6NqRiwXD0cwJ5yvyzLB5OCtOTxlX8=; b=AS4TUIRzzPk2JzF5cluNj1XRv31CnH6XQGatNdQWuEYcq3cuAw+ptIiT6LiHyoIiBv yQERxO2ZECecgCytgfMzHAX1VP7GMZd2xKYTFT8Mn8Jrb/rqe8aB3/K8Ls7CcMfp2KzJ vlMKO4WA+YzjLyLW7DrSizPoSp+/SL8SSrFpkNB/J+c3k9aTxHyoz/2yVHN0mhvDbdWc Y1qLhF2SpbyJx0oSJtlTWUcXZdptqobSuoU8ZKUchI7DFG79Rxw9JwVp/w2iBkg5w0jE /KwT/w6RgaD8zEgvwV8UiK7rEXsV+K1F/6KlM7zv2246OeymGP0dcRlrYzNv3ox2bVEY Z4qQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="LKEFZU8/"; 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-55374-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55374-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=1; AJvYcCVO2DK8P/CyxXFCNmyfH5GR8l+7bCMC2LVnSVzaaZsRcGVPryzQxQtv8w1rgjSAcu+sa6jQTo2uKu8vVDtHshReFr7ISw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i23-20020a63e457000000b005d8b44e7954si2007069pgk.607.2024.02.06.09.29.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 09:29:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55374-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="LKEFZU8/"; 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-55374-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55374-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 89F1F28357D for ; Tue, 6 Feb 2024 17:29:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF76313AF0; Tue, 6 Feb 2024 17:28:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="LKEFZU8/" Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (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 39CD612B7C for ; Tue, 6 Feb 2024 17:28:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240508; cv=none; b=QZUS3SEL12WNEZozQyCbml9rxd0snZEXUzFouZxTivv/fw1aC5FiGmd4xotkPuQ7RGUH67sJSazp5lS6bhpq6rIWxztR2H8g0iMdYEqWjcZcunyqeotehgik2ZvezNevsyDAcMr4D3FHIsH1dhz6dAK7ItjHqERmrtPla8dRWXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240508; c=relaxed/simple; bh=cyo2IJRkUo8l1uEpgQetd9cqnpugv4Go8aX89CgXTx4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V3a/SLlIMZsoHedD5KAwli0t2Ql93QxWCplcemK+h1Q75VXRf7rlQ+LSoI1rYKNqUwiorkEcMTNYXT9qWDZuVI08jLu7IHUxnOgKPihTXOt6pzMLxFI0lKDbJA+/LqMItwnliTK7Gdwksc2MPsvJPq3wpDWtXsC5GDCm9ySk/UQ= 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=LKEFZU8/; arc=none smtp.client-ip=95.215.58.173 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=1707240504; 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=8HAy2xAuPJeCpNnNishsphDqlFIPREAv9Gabwc+YWgA=; b=LKEFZU8/pHxDeB1+ZDDRHLp5JzF2MK73NhgWQzq5uiL9OlgqJN8Z6iG6QCZXR8q+sMXDcO E0Cc2OzMBnyaOicvvupO4LwLDe8RWRnTySRNhjIhobJUS8CXg8Sf/LULxmYY1Ipyj9mo/H l9mf7hud5VYfhzkShdKgg1s+vkDczBs= 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 3/7] drm/etnaviv: Embed struct drm_device in struct etnaviv_drm_private Date: Wed, 7 Feb 2024 01:27:55 +0800 Message-Id: <20240206172759.421737-4-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: 1790171503045488787 X-GMAIL-MSGID: 1790171503045488787 Both the instance of struct drm_device and the instance of struct etnaviv_drm_private are intended to be shared by all GPU cores. They both have only one instance across drm/etnaviv, therefore, embed struct drm_device into struct etnaviv_drm_private, and use container_of() to retrieve pointer for the containing structure. The benifit is that the DRM device can be initialized with devm_drm_dev_alloc() and the DRM device created is automatically put on driver detach, so don't need us to call drm_dev_put() explicitly on driver teardown. It's also eliminate the need to use the .dev_private member, which is deprecated according to the drm document. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 65 ++++++++------------ drivers/gpu/drm/etnaviv/etnaviv_drv.h | 7 +++ drivers/gpu/drm/etnaviv/etnaviv_gem.c | 6 +- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 6 +- drivers/gpu/drm/etnaviv/etnaviv_mmu.c | 4 +- 6 files changed, 40 insertions(+), 50 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 035ac0c6884f..5ba2b3a386b3 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -41,14 +41,9 @@ static struct device_node *etnaviv_of_first_available_node(void) return NULL; } -static struct etnaviv_drm_private *etnaviv_alloc_private(struct device *dev) +static int etnaviv_private_init(struct device *dev, + struct etnaviv_drm_private *priv) { - 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); @@ -58,15 +53,14 @@ static struct etnaviv_drm_private *etnaviv_alloc_private(struct device *dev) 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 -ENOMEM; } - return priv; + return 0; } -static void etnaviv_free_private(struct etnaviv_drm_private *priv) +static void etnaviv_private_fini(struct etnaviv_drm_private *priv) { if (!priv) return; @@ -74,13 +68,11 @@ static void etnaviv_free_private(struct etnaviv_drm_private *priv) 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; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); unsigned int i; for (i = 0; i < ETNA_MAX_PIPES; i++) { @@ -98,7 +90,7 @@ static void load_gpu(struct drm_device *dev) static int etnaviv_open(struct drm_device *dev, struct drm_file *file) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct etnaviv_file_private *ctx; int ret, i; @@ -141,7 +133,7 @@ static int etnaviv_open(struct drm_device *dev, struct drm_file *file) static void etnaviv_postclose(struct drm_device *dev, struct drm_file *file) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct etnaviv_file_private *ctx = file->driver_priv; unsigned int i; @@ -166,7 +158,7 @@ static void etnaviv_postclose(struct drm_device *dev, struct drm_file *file) #ifdef CONFIG_DEBUG_FS static int etnaviv_gem_show(struct drm_device *dev, struct seq_file *m) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); etnaviv_gem_describe_objects(priv, m); @@ -260,7 +252,7 @@ static int show_each_gpu(struct seq_file *m, void *arg) { struct drm_info_node *node = (struct drm_info_node *) m->private; struct drm_device *dev = node->minor->dev; - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct etnaviv_gpu *gpu; int (*show)(struct etnaviv_gpu *gpu, struct seq_file *m) = node->info_ent->data; @@ -303,7 +295,7 @@ static void etnaviv_debugfs_init(struct drm_minor *minor) static int etnaviv_ioctl_get_param(struct drm_device *dev, void *data, struct drm_file *file) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct drm_etnaviv_param *args = data; struct etnaviv_gpu *gpu; @@ -396,7 +388,7 @@ static int etnaviv_ioctl_wait_fence(struct drm_device *dev, void *data, struct drm_file *file) { struct drm_etnaviv_wait_fence *args = data; - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct drm_etnaviv_timespec *timeout = &args->timeout; struct etnaviv_gpu *gpu; @@ -444,7 +436,7 @@ static int etnaviv_ioctl_gem_userptr(struct drm_device *dev, void *data, static int etnaviv_ioctl_gem_wait(struct drm_device *dev, void *data, struct drm_file *file) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct drm_etnaviv_gem_wait *args = data; struct drm_etnaviv_timespec *timeout = &args->timeout; struct drm_gem_object *obj; @@ -478,7 +470,7 @@ static int etnaviv_ioctl_gem_wait(struct drm_device *dev, void *data, static int etnaviv_ioctl_pm_query_dom(struct drm_device *dev, void *data, struct drm_file *file) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct drm_etnaviv_pm_domain *args = data; struct etnaviv_gpu *gpu; @@ -495,7 +487,7 @@ static int etnaviv_ioctl_pm_query_dom(struct drm_device *dev, void *data, static int etnaviv_ioctl_pm_query_sig(struct drm_device *dev, void *data, struct drm_file *file) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct drm_etnaviv_pm_signal *args = data; struct etnaviv_gpu *gpu; @@ -554,17 +546,14 @@ static int etnaviv_bind(struct device *dev) struct drm_device *drm; int ret; - drm = drm_dev_alloc(&etnaviv_drm_driver, dev); - if (IS_ERR(drm)) - return PTR_ERR(drm); + priv = devm_drm_dev_alloc(dev, &etnaviv_drm_driver, + struct etnaviv_drm_private, drm); + if (IS_ERR(priv)) + return PTR_ERR(priv); - priv = etnaviv_alloc_private(dev); - if (IS_ERR(priv)) { - ret = PTR_ERR(priv); - goto out_put; - } + etnaviv_private_init(dev, priv); - drm->dev_private = priv; + drm = &priv->drm; dma_set_max_seg_size(dev, SZ_2G); @@ -585,9 +574,7 @@ static int etnaviv_bind(struct device *dev) out_unbind: component_unbind_all(dev, drm); out_free_priv: - etnaviv_free_private(priv); -out_put: - drm_dev_put(drm); + etnaviv_private_fini(priv); return ret; } @@ -595,17 +582,13 @@ static int etnaviv_bind(struct device *dev) static void etnaviv_unbind(struct device *dev) { struct drm_device *drm = dev_get_drvdata(dev); - struct etnaviv_drm_private *priv = drm->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(drm); drm_dev_unregister(drm); component_unbind_all(dev, drm); - etnaviv_free_private(priv); - - drm->dev_private = NULL; - - drm_dev_put(drm); + etnaviv_private_fini(priv); } static const struct component_master_ops etnaviv_master_ops = { diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_drv.h index b3eb1662e90c..1f9b50b5a6aa 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h @@ -35,6 +35,7 @@ struct etnaviv_file_private { }; struct etnaviv_drm_private { + struct drm_device drm; int num_gpus; struct etnaviv_gpu *gpu[ETNA_MAX_PIPES]; gfp_t shm_gfp_mask; @@ -50,6 +51,12 @@ struct etnaviv_drm_private { struct list_head gem_list; }; +static inline struct etnaviv_drm_private * +to_etnaviv_priv(struct drm_device *ddev) +{ + return container_of(ddev, struct etnaviv_drm_private, drm); +} + int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, struct drm_file *file); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c index 71a6d2b1c80f..aa95a5e98374 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c @@ -486,7 +486,7 @@ static const struct etnaviv_gem_ops etnaviv_gem_shmem_ops = { void etnaviv_gem_free_object(struct drm_gem_object *obj) { struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj); - struct etnaviv_drm_private *priv = obj->dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(obj->dev); struct etnaviv_vram_mapping *mapping, *tmp; /* object should not be active */ @@ -517,7 +517,7 @@ void etnaviv_gem_free_object(struct drm_gem_object *obj) void etnaviv_gem_obj_add(struct drm_device *dev, struct drm_gem_object *obj) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj); mutex_lock(&priv->gem_lock); @@ -584,7 +584,7 @@ static int etnaviv_gem_new_impl(struct drm_device *dev, u32 flags, int etnaviv_gem_new_handle(struct drm_device *dev, struct drm_file *file, u32 size, u32 flags, u32 *handle) { - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct drm_gem_object *obj = NULL; int ret; diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c index 3d0f8d182506..6b40a39fb8cd 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c @@ -413,7 +413,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, struct drm_file *file) { struct etnaviv_file_private *ctx = file->driver_priv; - struct etnaviv_drm_private *priv = dev->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(dev); struct drm_etnaviv_gem_submit *args = data; struct drm_etnaviv_gem_submit_reloc *relocs; struct drm_etnaviv_gem_submit_pmr *pmrs; diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index 654bf2631755..a407c2c9e140 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -38,7 +38,7 @@ static const struct platform_device_id gpu_ids[] = { int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value) { - struct etnaviv_drm_private *priv = gpu->drm->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(gpu->drm); switch (param) { case ETNAVIV_PARAM_GPU_MODEL: @@ -801,7 +801,7 @@ static void etnaviv_gpu_hw_init(struct etnaviv_gpu *gpu) int etnaviv_gpu_init(struct etnaviv_gpu *gpu) { - struct etnaviv_drm_private *priv = gpu->drm->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(gpu->drm); dma_addr_t cmdbuf_paddr; int ret, i; @@ -1791,7 +1791,7 @@ static int etnaviv_gpu_bind(struct device *dev, struct device *master, void *data) { struct drm_device *drm = data; - struct etnaviv_drm_private *priv = drm->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(drm); struct etnaviv_gpu *gpu = dev_get_drvdata(dev); int ret; diff --git a/drivers/gpu/drm/etnaviv/etnaviv_mmu.c b/drivers/gpu/drm/etnaviv/etnaviv_mmu.c index 1661d589bf3e..c38272868328 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_mmu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_mmu.c @@ -490,7 +490,7 @@ void etnaviv_iommu_dump(struct etnaviv_iommu_context *context, void *buf) int etnaviv_iommu_global_init(struct etnaviv_gpu *gpu) { enum etnaviv_iommu_version version = ETNAVIV_IOMMU_V1; - struct etnaviv_drm_private *priv = gpu->drm->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(gpu->drm); struct etnaviv_iommu_global *global; struct device *dev = gpu->drm->dev; @@ -550,7 +550,7 @@ int etnaviv_iommu_global_init(struct etnaviv_gpu *gpu) void etnaviv_iommu_global_fini(struct etnaviv_gpu *gpu) { - struct etnaviv_drm_private *priv = gpu->drm->dev_private; + struct etnaviv_drm_private *priv = to_etnaviv_priv(gpu->drm); struct etnaviv_iommu_global *global = priv->mmu_global; if (!global) From patchwork Tue Feb 6 17:27:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 197558 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1697527dyb; Tue, 6 Feb 2024 09:29:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFaMIJSUnepYQwbB+NN/t9xknqsYDpf72DT20/LXJlN3FM+QnRdO1A+TSzA+KYAxs3Ytiqx X-Received: by 2002:a17:902:e9cc:b0:1d7:524:a4f8 with SMTP id 12-20020a170902e9cc00b001d70524a4f8mr1885005plk.41.1707240593166; Tue, 06 Feb 2024 09:29:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707240593; cv=pass; d=google.com; s=arc-20160816; b=vvYuEDBqm4j+tNX4IYV4c0YY1qnwGB11OFoay9PaC2LPvKZzCXGV7ySDBpXMaK0IjL fooabNjUltsxWJoAXgSkpOTmTUA2BWya5zLVIDW+VmTuhP/anoL03xOSpODr514N7W4S TrcR89/yF9/h4BHZj2xIzkCWgYHTKnnzJwSinYVoftX8JWgT/JTnqUQAAG3blMNh0rBX Q8U/By2wLFTuIUTFRMPbLGPmPxRfVZHR++dZTrW5Ylf3i9NoMSu+xUPd6EbxSA6gRxt3 v0LIBQx6UZUPCyUsSMyeQtNf+nHb+Iqoqgr5661f4s9zw1PZ8n78pL7aXKmsDWBwIkHt qzFg== 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=dVVAqRzMJsdMeT1oOUAb65qyjBdxIyQ/VJBw576jp8g=; fh=HvSE2sN8oRGVg+rOiWYdPBdXt7tNrFwUBxY9UsYkawQ=; b=ZxZwNJDspqNwoyWKBWwVjCyfwlfIs34HR8PcVd5FB7+dM+euSU+FC3rWqOSrA8219+ 5No1NHXlSDJPtG4UTdjYAMI3lzi+8XfPBd0mhUwU7ZlVJpha/2+4RUlG4FTTHX3LycnS UC4xQt7m6QnoEjO8WnEyE7Eq9XMvi8Gbw2nAHQdupXr/FMcAV3YHkZgjYqwXHeP6NQgt aobvYsaxiIbP4PvRXX9MdaPIrLGUO+3zFpWJS75KGAPyGLp4AyQh0dPtViYBrnDNOJ3+ GE2YuJRde+q3ROXYSUruogj/ubLmfudessyAw5Z69x9aQG6Q4XN6w3wp3ceHUzso4XM2 uZFA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=CBSJ6Qu0; 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-55375-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55375-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=1; AJvYcCXUs2hqQuna3oRiJxOQuE5cRdgOihSPgDe2uKbVhYn/KrRq+4wyGyXD+kT7iPWo4RAJ+icwQvZtUmSMOycYm8ke9qwegQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id jv3-20020a170903058300b001d937ad07f4si1951883plb.256.2024.02.06.09.29.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 09:29:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55375-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=CBSJ6Qu0; 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-55375-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55375-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 AFFC6286CF3 for ; Tue, 6 Feb 2024 17:29:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C87B014008; Tue, 6 Feb 2024 17:28:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="CBSJ6Qu0" Received: from out-184.mta1.migadu.com (out-184.mta1.migadu.com [95.215.58.184]) (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 C03AC134C1 for ; Tue, 6 Feb 2024 17:28:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240511; cv=none; b=N+24sn/GOZ3poXanswjL0GxmteqYXuv2dnJQeoJHJ+tTeqnpAHNkMsPHRidYVX91e3Yi6l7bFPIO8f2xlyHNxd/tVb+ypTII2czD01oJpk785Df3S+gPeNRXp4siHunD7p+nvKIkf2wd034U4/KeIozbKkFiFwlf//suiQl2rpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240511; c=relaxed/simple; bh=G4vOW0cc6Sv9nxhDLNT0Pe4VnPsarPhEmrxuUpplrfY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ll1XsPw4aVcRTyyq7Q9P2Zhybz8oXGVZEKi0ZpaIst89RXxzm31UqMNpK7sQlBbLCctNkQDt19PV8mgR1hExsPViw+ZVE4nriANxpZiM4PnfNrVqZbldmxmfnjGTeWinjwzmaeryqjjBUf8kjhnAAFHJcxiKnXkoMWbWrfyF0nk= 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=CBSJ6Qu0; arc=none smtp.client-ip=95.215.58.184 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=1707240508; 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=dVVAqRzMJsdMeT1oOUAb65qyjBdxIyQ/VJBw576jp8g=; b=CBSJ6Qu0yJEpGwXujNr8pa0XwekuOg2d0/VV3w1I289ams5E59ep2xR/nyVFM6UYx0qUO8 /Uf+1eNfcC4j1cK+E16/5jvKTM2f3vxIZ2CBkJBpC95681X9ifZpg2pr+13T8kQQ4Xg1Us AL6jNDSBBuP4gDk4MPYOc2p1Mfmc7uQ= 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 4/7] drm/etnaviv: Add support for cached coherent caching mode Date: Wed, 7 Feb 2024 01:27:56 +0800 Message-Id: <20240206172759.421737-5-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: 1790171512154829174 X-GMAIL-MSGID: 1790171512154829174 In the etnaviv_gem_vmap_impl(), update the page property from writecombine to PAGE_KERNEL on cached mapping. Previously, it use writecombine page property to vmap cached buffer unconditionally. Many modern CPUs choose to define the peripheral devices as DMA coherent by default, to be specific, the peripheral devices are capable of snooping CPU's cache. Therefore, cached buffers should be accessed with cached mapping. While at it, probe cached coherent support at the host platform with the dev_is_dma_coherent() function. This allows userspace to query on the runtime, which avoid compile-time macros (#ifdefs). Modern CPUs choose to define the peripheral devices as DMA coherent by default, In other words, the peripheral devices are capable of snooping CPU's cache. This means that device drivers do not need to maintain the coherency issue between a processor and an peripheral I/O for the cached mapping buffers. Such a hardware feature is implementation-defined by host CPU platform, not the vivante GPU IP core itself. X86-64, LoongArch and Loongson Mips CPU and some ARM64 CPU has the hardware maintain cache coherency, but ARM CPU is not. So provide mechanism to let userspace know. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 3 +++ drivers/gpu/drm/etnaviv/etnaviv_drv.h | 8 ++++++++ drivers/gpu/drm/etnaviv/etnaviv_gem.c | 16 ++++++++++++++-- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 4 ++++ include/uapi/drm/etnaviv_drm.h | 1 + 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 5ba2b3a386b3..e3a05b8b9330 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -57,6 +58,8 @@ static int etnaviv_private_init(struct device *dev, return -ENOMEM; } + priv->cached_coherent = dev_is_dma_coherent(dev); + return 0; } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_drv.h index 1f9b50b5a6aa..9c05f503747a 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h @@ -46,6 +46,14 @@ struct etnaviv_drm_private { struct xarray active_contexts; u32 next_context_id; + /* + * If true, the cached mapping is consistent for all CPU cores and + * peripheral bus masters in the system. It means that vboth of the + * CPU and GPU will see the same data if the buffer being access is + * cached. And coherency is guaranteed by the arch specific hardware. + */ + bool cached_coherent; + /* list of GEM objects: */ struct mutex gem_lock; struct list_head gem_list; diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c index aa95a5e98374..eed98bb9e446 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c @@ -342,6 +342,7 @@ void *etnaviv_gem_vmap(struct drm_gem_object *obj) static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) { struct page **pages; + pgprot_t prot; lockdep_assert_held(&obj->lock); @@ -349,8 +350,19 @@ static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj) if (IS_ERR(pages)) return NULL; - return vmap(pages, obj->base.size >> PAGE_SHIFT, - VM_MAP, pgprot_writecombine(PAGE_KERNEL)); + switch (obj->flags) { + case ETNA_BO_CACHED: + prot = PAGE_KERNEL; + break; + case ETNA_BO_UNCACHED: + prot = pgprot_noncached(PAGE_KERNEL); + break; + case ETNA_BO_WC: + default: + prot = pgprot_writecombine(PAGE_KERNEL); + } + + return vmap(pages, obj->base.size >> PAGE_SHIFT, VM_MAP, prot); } static inline enum dma_data_direction etnaviv_op_to_dma_dir(u32 op) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index a407c2c9e140..306973660653 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -184,6 +184,10 @@ int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value) *value = gpu->identity.axi_sram_size; break; + case ETNAVIV_PARAM_CACHED_COHERENT: + *value = priv->cached_coherent; + break; + default: DBG("%s: invalid param: %u", dev_name(gpu->dev), param); return -EINVAL; diff --git a/include/uapi/drm/etnaviv_drm.h b/include/uapi/drm/etnaviv_drm.h index d87410a8443a..7c5d988a5b9f 100644 --- a/include/uapi/drm/etnaviv_drm.h +++ b/include/uapi/drm/etnaviv_drm.h @@ -82,6 +82,7 @@ struct drm_etnaviv_timespec { #define ETNAVIV_PARAM_GPU_TP_CORE_COUNT 0x21 #define ETNAVIV_PARAM_GPU_ON_CHIP_SRAM_SIZE 0x22 #define ETNAVIV_PARAM_GPU_AXI_SRAM_SIZE 0x23 +#define ETNAVIV_PARAM_CACHED_COHERENT 0x24 #define ETNA_MAX_PIPES 4 From patchwork Tue Feb 6 17:27:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 197557 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1697468dyb; Tue, 6 Feb 2024 09:29:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHTbXBAhdAjksm6LaurdtW3G37cp9EbU+iFvkpxkLvNzuwnt0N6OavXQWPBEyk4Z+rDMH0o X-Received: by 2002:a05:6402:2d0:b0:560:4e6:803c with SMTP id b16-20020a05640202d000b0056004e6803cmr2558094edx.27.1707240587843; Tue, 06 Feb 2024 09:29:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707240587; cv=pass; d=google.com; s=arc-20160816; b=V7vknQIF3+BQp7FfiieE/3u41LdyNy4qrWlPFx3eRErQxU5kbQ6Xh05Rz28tLdj/XJ TnMBLXb9VL+ioNTJkFVbyR7d9aL+oh6AyeUKUxeQ6a/KlEhua4YiHNp9gfRtnOpMIyNm jxQ/2pi3u+UU1kycqZGe2KZ1peZg3HD7+Vnqsny3sgSiOxIOrJEyhX+ztNzUb26N3vwe bn4eE4g8wTs9mH9YJyxbJ3BrZuQE9DfzuCcrYRpCABo3OrU6Ov3LU4g/x9EnvV86xEWy Zz8/OIkdEHr8BY3v8LBWs6mhNYTFdpziBe5iPFYztxL8PEDjzXgbYyJXj8JdAqXX6mY2 TX0w== 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=y0hdY76agQrzY+9gtVZaFHqY84LfFC9/R41cfmLOlh8=; fh=AXGRLwkvabcdH1E98DXMFXge6g78Tc18jGATMXYziDk=; b=wsGWh55/tbJZOyBcjX0W6cV61W+6k2fYQbNEE65CI5bYRsRCuD7ASIb2xXfnbMgrBP FwKTJsafg5e/RMyZkIfK72kQcopKcZJ/zkBIxnyFBLMcbQJOHNWRvrQ5FKafdmK/58Rr /9x9srEzkQRU6ZzMLs04+ydMmxjg7Hg7Yv7dsgPuy4VfQLryU3MY/+cznpOM/I99oJYh GvGh5FpElBgMqA76dEE3869dl/iuwCbw/c8DH45WX2GOwLnt/+OyCMgcllMg0BB1AIMn YqBBS9UI5N6CO1gApQomWAHYzVC/djKhlI+4L+RWDEIBUnTmlodCWj9AZs+gQPF13ViE K+TQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=dvCnJRTV; 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-55376-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55376-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=1; AJvYcCVtL4awHBALqNt/70HgwcO6f+BMqI3uy1uAuW4GGKp8T5iHAVF+Q9Iyw5o0HRKyILzIH0s7fEAt2KtTgxQAPhH9Tdggbg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i9-20020a056402054900b0056001f92c29si1309434edx.340.2024.02.06.09.29.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 09:29:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55376-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=dvCnJRTV; 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-55376-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55376-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 755C41F26681 for ; Tue, 6 Feb 2024 17:29:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 163A914A91; Tue, 6 Feb 2024 17:28:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="dvCnJRTV" Received: from out-184.mta1.migadu.com (out-184.mta1.migadu.com [95.215.58.184]) (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 76DDA13FE7 for ; Tue, 6 Feb 2024 17:28:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240515; cv=none; b=FiIn7dRV/xZ8zlj8A5JGDkzg1etEb3UvQ1CqT8hnULulGlomeRT8fK8U9hQcpG+U2g85vfMuTSi0k9+MeiaSu4cqgQ4HZCSo3g+wx/apcmsS/FC1eZWvaJlplwXai/U+hLnKd0OFuF+cwrw3+4ydnz8vXRRaK6xGf9bl2hO6nqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240515; c=relaxed/simple; bh=03yi27ExKzCdAz4CD/WXAaSXy3Go2ef741YE4yG2Vcg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kZqT+1iFOZz+6KJDAdSqpLS3ZnLh0Aw9ItTx1SbM1zE6XIP2UbjhW5Lj6ko+JBbOp73ZB0t5iokzwduhTk1kMAF343hXX7Q5pYKsmGSI/UowbMTDEYX7pzdfVlorNUTSkezlIfJWy0tl51b8tyur/5+HQQFgEgQosSpWE2XTD38= 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=dvCnJRTV; arc=none smtp.client-ip=95.215.58.184 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=1707240511; 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=y0hdY76agQrzY+9gtVZaFHqY84LfFC9/R41cfmLOlh8=; b=dvCnJRTVEODFXuwOO7YyVPHVEEu1sDKKoH+z9Dc8yc7y0A+nMKTi+8arxlg+5p3Lnj+S29 GpgdG3j7ZriNqqmz6xWa9RjvifOP2uLBlme0lZNYhINy9OcR/9VEfG2JrBHLxqt2u5taEb tXE6/8DzvG4NxsC3XmeerKEgsM0Y5ZU= 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 5/7] drm/etnaviv: Replace the '&pdev->dev' with 'dev' Date: Wed, 7 Feb 2024 01:27:57 +0800 Message-Id: <20240206172759.421737-6-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: 1790171506809187985 X-GMAIL-MSGID: 1790171506809187985 In the etnaviv_pdev_probe() and the etnaviv_gpu_platform_probe() function, the value of '&pdev->dev' has been cached to a local auto variable (which is named as 'dev'), but part of caller functions use 'dev' as argument, but the rest use '&pdev->dev'. To keep it consistent, use 'dev' uniformly. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 10 +++++----- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index e3a05b8b9330..d5a5fcc30341 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -612,7 +612,7 @@ static int etnaviv_pdev_probe(struct platform_device *pdev) if (!of_device_is_available(core_node)) continue; - drm_of_component_match_add(&pdev->dev, &match, + drm_of_component_match_add(dev, &match, component_compare_of, core_node); } } else { @@ -635,9 +635,9 @@ static int etnaviv_pdev_probe(struct platform_device *pdev) * bit to make sure we are allocating the command buffers and * TLBs in the lower 4 GiB address space. */ - if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(40)) || - dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32))) { - dev_dbg(&pdev->dev, "No suitable DMA available\n"); + if (dma_set_mask(dev, DMA_BIT_MASK(40)) || + dma_set_coherent_mask(dev, DMA_BIT_MASK(32))) { + dev_dbg(dev, "No suitable DMA available\n"); return -ENODEV; } @@ -648,7 +648,7 @@ static int etnaviv_pdev_probe(struct platform_device *pdev) */ first_node = etnaviv_of_first_available_node(); if (first_node) { - of_dma_configure(&pdev->dev, first_node, true); + of_dma_configure(dev, first_node, true); of_node_put(first_node); } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index 306973660653..3fd637c17797 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -1903,7 +1903,7 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) if (!gpu) return -ENOMEM; - gpu->dev = &pdev->dev; + gpu->dev = dev; mutex_init(&gpu->lock); mutex_init(&gpu->sched_lock); @@ -1917,8 +1917,8 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) if (gpu->irq < 0) return gpu->irq; - err = devm_request_irq(&pdev->dev, gpu->irq, irq_handler, 0, - dev_name(gpu->dev), gpu); + err = devm_request_irq(dev, gpu->irq, irq_handler, 0, + dev_name(dev), gpu); if (err) { dev_err(dev, "failed to request IRQ%u: %d\n", gpu->irq, err); return err; @@ -1937,13 +1937,13 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) * autosuspend delay is rather arbitary: no measurements have * yet been performed to determine an appropriate value. */ - pm_runtime_use_autosuspend(gpu->dev); - pm_runtime_set_autosuspend_delay(gpu->dev, 200); - pm_runtime_enable(gpu->dev); + pm_runtime_use_autosuspend(dev); + pm_runtime_set_autosuspend_delay(dev, 200); + pm_runtime_enable(dev); - err = component_add(&pdev->dev, &gpu_ops); + err = component_add(dev, &gpu_ops); if (err < 0) { - dev_err(&pdev->dev, "failed to register component: %d\n", err); + dev_err(dev, "failed to register component: %d\n", err); return err; } From patchwork Tue Feb 6 17:27:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 197559 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1697620dyb; Tue, 6 Feb 2024 09:30:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1oM+6KtphQ0S2sVaWiBoKSbk/pikFmIgh0LxN6ZdW1wbeVo3co1ye7K3eTd8/uXhrA8tk X-Received: by 2002:ad4:5d67:0:b0:68c:7e26:63ca with SMTP id fn7-20020ad45d67000000b0068c7e2663camr3305969qvb.46.1707240600819; Tue, 06 Feb 2024 09:30:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707240600; cv=pass; d=google.com; s=arc-20160816; b=o4BRhafFO3b3WrOkUAkpyeppJdvWf8fiyAdBLx22xDFocgoSELjFXpQ9tN5Qzavcar LHW05i+9Uh2sMPKm5MvtmOlJW98qOF6Fo6+WA4YsENuZrIjMS1i5BuWo4FSZVSMLt9sZ HM6P9H5qUVrGSjXSYx5Lw06thsgXJ4Yhg13W/+gHaeNfwlra6PYOtXLZxuf9yyrZ2W+2 OL7hiRKV/IrhwjOyl/gE1C8wv6YLjUrXG2MirXS45XqVrOLxRdo1pH6l/majOdsz1rpO Y6kcC3XB8NL+D85v7Nu5gdQxdKgQMRvUH6Q5zEuvIIVcex+4dU3+kdmgEEDGrkagnh2+ z00A== 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=jmVPFCNKCEoxyfP5fWPRoMeSPbEbmBVNboqHaLmwopU=; fh=e7Z8dKu3i2dq1SFtmTxnhODZWKTjAbotA7LL31aJqnQ=; b=d8Uh6HWgYwwziH7fiZ1DrXPlXYPPySW56KIhtLLQdny1EPtFDCfLdj+V8NU20psuhB yNlrDyWFLsEEUZrij3EFIrBawF/00CsT/24AJvqY1NsqX8SKgRc03tOsqu8MMQ4o5WFi w/0HFg3uZVbwsBGYzxtiKb8MwI1yRITua1nJmDBaQqJJeASz/H43UOCn992hXP/tNnT5 K73ea6Y+zhK2l9haNpp7+MfypgX9HbHclqERDChc8ZYcw8JJqJdeH1aU8XyBVI9n7eoj D7iGsplhPgtLMjXO1pmg2sD0dBaRDA4Xl1MW5oLP1xkwdezCyllR/07+F67zyw5IyJCf MkCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=bj9f6nPN; 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-55377-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55377-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=1; AJvYcCXKxLU5IFSfCqqE8Qvzrrk0i8MSHDjL9e+myOkUl36yvWYfwGuimwQVtZFbNZURDVYV5ssUJXFgrzT0UAPFZ0Dw025NiA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y12-20020a056214016c00b006819bda2532si2725861qvs.234.2024.02.06.09.30.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 09:30:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55377-ouuuleilei=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=bj9f6nPN; 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-55377-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55377-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 9A0F41C23204 for ; Tue, 6 Feb 2024 17:30:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03B6417579; Tue, 6 Feb 2024 17:28:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="bj9f6nPN" Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (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 BA14914A81 for ; Tue, 6 Feb 2024 17:28:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240519; cv=none; b=Jt7es5nZUmGM2Fk52ClYRvhr5rFCy1olBEofL5q3fQfXVNAiqWwj5pgxgvezE/zOjtvLWXrwCCGtpbIzy1WmrA2dIgYlerxeqpt6qCs1cSa+N8rAicHp7S5w0qEvnUa7Es29VuU0Te6LUy2phdfj6v8105M23vmNGgs0exyeXdA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240519; c=relaxed/simple; bh=ckxXDAMdL+HGgVVf2k5qWXyty13TiKMKkVY5UlvzvTM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SbbDI1Im5ikABZxPsTP1rZBWlSrdy8rCBoCZZzjme9RrpYahXZCfBcdKGz8a0M5MlBcH7Of/kdtL9vemlomlCOeKsU9bAQDLwJo7IR1VsLfeAM1fgVcH0APwGlRHmcA3iJUfZCzScqG2SE2gq6kYHP+oLYrL+NSEpRuJynHTr50= 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=bj9f6nPN; arc=none smtp.client-ip=95.215.58.186 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=1707240516; 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=jmVPFCNKCEoxyfP5fWPRoMeSPbEbmBVNboqHaLmwopU=; b=bj9f6nPNUnvNreGxSEJL4GRanUU7epVcP9jtGuoNULXnMXPcYRC8wNMLn1F/9NdkMVaYxx rsABrTZTT8ee69ohJDd7pIwPlD9xmEuQnkNVKaOW4GFfph5FtQCL9dcx2Rc6ilrBkL+lc7 W6tnQifptQj4MMRWcdDpGe/xKyH8moI= 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 6/7] drm/etnaviv: Update the implement of etnaviv_create_platform_device() Date: Wed, 7 Feb 2024 01:27:58 +0800 Message-Id: <20240206172759.421737-7-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: 1790171520323662534 X-GMAIL-MSGID: 1790171520323662534 Because we need this function to create virtial child. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 33 +++++++++++++++++++++++---- drivers/gpu/drm/etnaviv/etnaviv_drv.h | 9 ++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index d5a5fcc30341..5f65f2dead44 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -670,16 +670,36 @@ static struct platform_driver etnaviv_platform_driver = { }, }; -static int etnaviv_create_platform_device(const char *name, - struct platform_device **ppdev) +int etnaviv_create_platform_device(struct device *parent, + const char *name, int id, + struct resource *pres, + void *data, + struct platform_device **ppdev) { struct platform_device *pdev; int ret; - pdev = platform_device_alloc(name, PLATFORM_DEVID_NONE); + pdev = platform_device_alloc(name, id); if (!pdev) return -ENOMEM; + pdev->dev.parent = parent; + + if (pres) { + ret = platform_device_add_resources(pdev, pres, 1); + if (ret) { + platform_device_put(pdev); + return ret; + } + } + + if (data) { + void *pdata = kmalloc(sizeof(void *), GFP_KERNEL); + + *(void **)pdata = data; + pdev->dev.platform_data = pdata; + } + ret = platform_device_add(pdev); if (ret) { platform_device_put(pdev); @@ -691,7 +711,7 @@ static int etnaviv_create_platform_device(const char *name, return 0; } -static void etnaviv_destroy_platform_device(struct platform_device **ppdev) +void etnaviv_destroy_platform_device(struct platform_device **ppdev) { struct platform_device *pdev = *ppdev; @@ -728,7 +748,10 @@ static int __init etnaviv_init(void) if (np) { of_node_put(np); - ret = etnaviv_create_platform_device("etnaviv", &etnaviv_drm); + ret = etnaviv_create_platform_device(NULL, "etnaviv", + PLATFORM_DEVID_NONE, + NULL, NULL, + &etnaviv_drm); if (ret) goto unregister_platform_driver; } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_drv.h index 9c05f503747a..bd8ac64dbaf3 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -97,6 +98,14 @@ bool etnaviv_cmd_validate_one(struct etnaviv_gpu *gpu, u32 *stream, unsigned int size, struct drm_etnaviv_gem_submit_reloc *relocs, unsigned int reloc_size); +int etnaviv_create_platform_device(struct device *parent, + const char *name, int id, + struct resource *pres, + void *data, + struct platform_device **ppdev); + +void etnaviv_destroy_platform_device(struct platform_device **ppdev); + #ifdef CONFIG_DEBUG_FS void etnaviv_gem_describe_objects(struct etnaviv_drm_private *priv, struct seq_file *m); From patchwork Tue Feb 6 17:27:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Jingfeng X-Patchwork-Id: 197560 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1697962dyb; Tue, 6 Feb 2024 09:30:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkhXr6TyA8CZgadAM5TPuukT/Lfixox7qneCoG6Lz5XSFev1YEHMBnnJU+ExvZuA7lQzMS X-Received: by 2002:a05:6a00:1ca8:b0:6df:edcd:f44c with SMTP id y40-20020a056a001ca800b006dfedcdf44cmr252494pfw.6.1707240629770; Tue, 06 Feb 2024 09:30:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707240629; cv=pass; d=google.com; s=arc-20160816; b=dMcwIlxsNmivZOGMlITWLRO6XUQspq7MYW0aP7zLEDS8v2jae7WOOzz7+dmYu6OFJ2 K32dpKG3WhtiyYe0kH9+6BJ3A0xaI87cx/UyC+3c2NoKhrPe35QbZfISsOekn4IIyCKW v0kwXqJmQvTlLjB/xnViEDiPdH3Zf1Uvb6J5KKc0nI1GG85xH8ko8Iw0DF8nYpj4N4/L Xzqw1UIUUVP36NDNZDIxd3DYcy9VWniDhr9faJOM2iBVjw3hGrahF1ruyWyT/yLZwwQK 1E7af1iJPFtJlck6zkDR+NLsX7Sx1U5IPNLwM6xVIV42ltOKknQFhn7UQQ2fjMw/Ngqf H/dA== 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=IuDNXHrtfsKiiCQUnd7vhGhnPyKVBJ6ejLgzQPnQqMM=; fh=dKEHAiL0xx0QTbcHn2BZtKMjqXjbhIGNYRCW10TEn7k=; b=UPHYDH8wgbgl/2w82BDeNy5wEpK/w7VYWqTwGA/Q4AIhsQT2V2JGjrCBA6trpIO1sQ Ln/i3OMFatVsrhFynOSWVd/qmJSFzRZWNgFu2Z/s5zqEwlPs0BM1ERWKjCfoTdxdizJF tKh9R7zi5NFoucPsUFfO9fjjRmzA3XjwVGDDEvGYw+hu+jEpv9QvLbLzIUK/YCWBs89c 2WyTTwBdKLD2RCSHqiWBPls7cV6DnGKQVgU9jokA7QCw87pDeDjgOYGVpy0pHCwoBVQA oh6xjbGLNHJKIvIbHAkh6gb4LlJIrMQXGmLs1uSIy8HM7HOUlM60dul3vbhHPMGGMiEu P7QA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=N0V6+Fi0; 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-55378-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55378-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=1; AJvYcCVjY65ZJt1A4C8Hht5Y6IRmNZvEHQM30EXE0xYIfb+ztm/SjKmX66qD2rWzpCXEDpJSwWuXswsAEEzDo6vREScKRM07Mw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 11-20020a63000b000000b005dc1281f214si1996045pga.49.2024.02.06.09.30.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 09:30:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55378-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=N0V6+Fi0; 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-55378-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55378-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 23CD828717C for ; Tue, 6 Feb 2024 17:30:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4ECA28F6E; Tue, 6 Feb 2024 17:28:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="N0V6+Fi0" Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) (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 65A14171B6 for ; Tue, 6 Feb 2024 17:28:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240523; cv=none; b=kq1eJDJH+W20uyv3vYnOofuWP16CAbMdoFjjyYp2vkrt04rZ+vl8QnE2rDROm2qobbaJ5c2GtRMOZbmi/wggiVG/ZPNkUJ/3cdbRodioTBPC90IxpWTTY623tsD+X2CwraxvHoHTDiqL/erIgJOLNPxrTZ7Cm2FtY2rZUl6ybA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240523; c=relaxed/simple; bh=9sWdUEEWM2Tfs46jkgabpwtU9BiakYankMPthmg7kM4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Wh3Yp4f8PlzlAz8WE/Efm5QAFjwPVpBOhhhjdKZBheKdA5OpTJYiRoKMqo4RL6mFLPPGrv4544BfWWbGB1sYgUFvgcCBCK0MQQUc8fQRd1j/D7kxm1k6Cd22phUjFnvvigiWsXrqCrNssQwVPuOSjb6uXnVSdIN7hQZf3h89ImI= 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=N0V6+Fi0; arc=none smtp.client-ip=95.215.58.178 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=1707240519; 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=IuDNXHrtfsKiiCQUnd7vhGhnPyKVBJ6ejLgzQPnQqMM=; b=N0V6+Fi0RXnwW3dJ4Ogl6JoBR1dfoPD69CvJuAXnCmi2BDy5JBAQQAgh2/PYYk1r/bN1EI cqXzKgVUMld365VCGyYlVUt0mWI6geHRc8QIDSAlBox1Aqa+CTeTj58RsMUo1vKw7FsA3f p0UeLuGV+nWcZ7KvDoEp9gEYIKRinNc= 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 7/7] drm/etnaviv: Add support for vivante GPU cores attached via PCI(e) Date: Wed, 7 Feb 2024 01:27:59 +0800 Message-Id: <20240206172759.421737-8-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: 1790171550220137453 X-GMAIL-MSGID: 1790171550220137453 The component helper functions are the glue, which is used to bind multiple GPU cores to a virtual master platform device. Which is fine and works well for the SoCs who contains multiple GPU cores. The problem is that usperspace programs (such as X server and Mesa) will search the PCIe device to use if it is exist. In other words, usperspace programs open the PCIe device with higher priority. Creating a virtual master platform device for PCI(e) GPUs is unnecessary, as the PCI device has been created by the time drm/etnaviv is loaded. we create virtual platform devices as a representation for the vivante GPU ip core. As all of subcomponent are attached via the PCIe master device, we reflect this hardware layout by binding all of the virtual child to the the real master. Signed-off-by: Sui Jingfeng --- drivers/gpu/drm/etnaviv/Kconfig | 8 + drivers/gpu/drm/etnaviv/Makefile | 2 + drivers/gpu/drm/etnaviv/etnaviv_drv.c | 12 +- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 75 ++++++-- drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 4 + drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c | 224 ++++++++++++++++++++++ drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h | 18 ++ 7 files changed, 327 insertions(+), 16 deletions(-) create mode 100644 drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c create mode 100644 drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h diff --git a/drivers/gpu/drm/etnaviv/Kconfig b/drivers/gpu/drm/etnaviv/Kconfig index faa7fc68b009..38c251585ec1 100644 --- a/drivers/gpu/drm/etnaviv/Kconfig +++ b/drivers/gpu/drm/etnaviv/Kconfig @@ -15,6 +15,14 @@ config DRM_ETNAVIV help DRM driver for Vivante GPUs. +config DRM_ETNAVIV_PCI_DRIVER + bool "enable ETNAVIV PCI driver support" + depends on DRM_ETNAVIV + depends on PCI + help + Compile in support for Vivante GPUs attached via PCI(e). + Say Y if you have such hardwares. + config DRM_ETNAVIV_THERMAL bool "enable ETNAVIV thermal throttling" depends on DRM_ETNAVIV diff --git a/drivers/gpu/drm/etnaviv/Makefile b/drivers/gpu/drm/etnaviv/Makefile index 46e5ffad69a6..6829e1ebf2db 100644 --- a/drivers/gpu/drm/etnaviv/Makefile +++ b/drivers/gpu/drm/etnaviv/Makefile @@ -16,4 +16,6 @@ etnaviv-y := \ etnaviv_perfmon.o \ etnaviv_sched.o +etnaviv-$(CONFIG_DRM_ETNAVIV_PCI_DRIVER) += etnaviv_pci_drv.o + obj-$(CONFIG_DRM_ETNAVIV) += etnaviv.o diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 5f65f2dead44..48e2402adbe3 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -24,6 +24,7 @@ #include "etnaviv_gpu.h" #include "etnaviv_gem.h" #include "etnaviv_mmu.h" +#include "etnaviv_pci_drv.h" #include "etnaviv_perfmon.h" /* @@ -566,6 +567,10 @@ static int etnaviv_bind(struct device *dev) if (ret < 0) goto out_free_priv; + ret = etnaviv_register_irq_handler(dev, priv); + if (ret) + goto out_unbind; + load_gpu(drm); ret = drm_dev_register(drm, 0); @@ -594,7 +599,7 @@ static void etnaviv_unbind(struct device *dev) etnaviv_private_fini(priv); } -static const struct component_master_ops etnaviv_master_ops = { +const struct component_master_ops etnaviv_master_ops = { .bind = etnaviv_bind, .unbind = etnaviv_unbind, }; @@ -740,6 +745,10 @@ static int __init etnaviv_init(void) if (ret != 0) goto unregister_gpu_driver; + ret = etnaviv_register_pci_driver(); + if (ret != 0) + goto unregister_platform_driver; + /* * If the DT contains at least one available GPU device, instantiate * the DRM platform device. @@ -769,6 +778,7 @@ module_init(etnaviv_init); static void __exit etnaviv_exit(void) { etnaviv_destroy_platform_device(&etnaviv_drm); + etnaviv_unregister_pci_driver(); platform_driver_unregister(&etnaviv_platform_driver); platform_driver_unregister(&etnaviv_gpu_driver); } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index 3fd637c17797..221020e98900 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,7 @@ static const struct platform_device_id gpu_ids[] = { { .name = "etnaviv-gpu,2d" }, + { .name = "etnaviv-gpu,3d" }, { }, }; @@ -1555,14 +1557,22 @@ static void dump_mmu_fault(struct etnaviv_gpu *gpu) static irqreturn_t irq_handler(int irq, void *data) { - struct etnaviv_gpu *gpu = data; + struct etnaviv_drm_private *priv = data; irqreturn_t ret = IRQ_NONE; + int i; - u32 intr = gpu_read(gpu, VIVS_HI_INTR_ACKNOWLEDGE); - - if (intr != 0) { + for (i = 0; i < priv->num_gpus; i++) { + struct etnaviv_gpu *gpu = priv->gpu[i]; + u32 intr; int event; + if (!gpu) + continue; + + intr = gpu_read(gpu, VIVS_HI_INTR_ACKNOWLEDGE); + if (!intr) + continue; + pm_runtime_mark_last_busy(gpu->dev); dev_dbg(gpu->dev, "intr 0x%08x\n", intr); @@ -1893,10 +1903,44 @@ static const struct of_device_id etnaviv_gpu_match[] = { }; MODULE_DEVICE_TABLE(of, etnaviv_gpu_match); +/* + * dev point to the master. For platform device, it is virtual. + * For PCI(e) device, it is real. + */ +int etnaviv_register_irq_handler(struct device *dev, + struct etnaviv_drm_private *priv) +{ + bool is_pci = dev_is_pci(dev); + int ret = 0; + + if (is_pci) { + struct pci_dev *pdev = to_pci_dev(dev); + + ret = request_irq(pdev->irq, irq_handler, IRQF_SHARED, + dev_name(dev), priv); + } else { + int i; + + for (i = 0; i < priv->num_gpus; i++) { + struct etnaviv_gpu *gpu = priv->gpu[i]; + + ret = devm_request_irq(gpu->dev, gpu->irq, irq_handler, + 0, dev_name(dev), priv); + if (ret) { + dev_err(dev, "failed to request IRQ handler: %d\n", ret); + break; + } + } + } + + return ret; +} + static int etnaviv_gpu_platform_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct etnaviv_gpu *gpu; + bool is_pci; int err; gpu = devm_kzalloc(dev, sizeof(*gpu), GFP_KERNEL); @@ -1912,22 +1956,23 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) if (IS_ERR(gpu->mmio)) return PTR_ERR(gpu->mmio); + is_pci = dev->parent ? dev_is_pci(dev->parent) : false; + /* Get Interrupt: */ - gpu->irq = platform_get_irq(pdev, 0); + if (is_pci) + gpu->irq = to_pci_dev(dev->parent)->irq; + else + gpu->irq = platform_get_irq(pdev, 0); + if (gpu->irq < 0) return gpu->irq; - err = devm_request_irq(dev, gpu->irq, irq_handler, 0, - dev_name(dev), gpu); - if (err) { - dev_err(dev, "failed to request IRQ%u: %d\n", gpu->irq, err); - return err; - } - /* Get Clocks: */ - err = etnaviv_gpu_clk_get(gpu); - if (err) - return err; + if (!is_pci) { + err = etnaviv_gpu_clk_get(gpu); + if (err) + return err; + } /* TODO: figure out max mapped size */ dev_set_drvdata(dev, gpu); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h index 7d5e9158e13c..d354e096652c 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h @@ -208,6 +208,10 @@ static inline u32 gpu_read_power(struct etnaviv_gpu *gpu, u32 reg) int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value); int etnaviv_gpu_init(struct etnaviv_gpu *gpu); + +int etnaviv_register_irq_handler(struct device *dev, + struct etnaviv_drm_private *priv); + bool etnaviv_fill_identity_from_hwdb(struct etnaviv_gpu *gpu); #ifdef CONFIG_DEBUG_FS diff --git a/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c new file mode 100644 index 000000000000..ec5039866eda --- /dev/null +++ b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.c @@ -0,0 +1,224 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +#include "etnaviv_drv.h" +#include "etnaviv_pci_drv.h" + +enum etnaviv_pci_gpu_chip_id { + GC_CORE_UNKNOWN = 0, + JM9100 = 1, + JD9230P = 2, + GP102 = 3, + GC1000_IN_LS7A1000 = 4, + GC1000_IN_LS2K1000 = 5, + GC_CORE_PCI_LAST, +}; + +struct etnaviv_pci_gpu_data { + enum etnaviv_pci_gpu_chip_id chip_id; + u32 num_core; + u32 num_vram; + u32 vram_bars[2]; + u32 mmio_bar; + struct { + u32 id; + u32 offset; + u32 size; + char compatible[20]; + } cores[ETNA_MAX_PIPES]; + + bool has_dedicated_vram; + char market_name[24]; +}; + +static const struct etnaviv_pci_gpu_data +gc_core_plaform_data[GC_CORE_PCI_LAST] = { + { + .chip_id = GC_CORE_UNKNOWN, + }, + { + .chip_id = JM9100, + .num_core = 1, + .num_vram = 2, + .vram_bars = {0, 2}, + .mmio_bar = 1, + .cores = {{0, 0x00900000, 0x00010000, "etnaviv-gpu,3d"},}, + .has_dedicated_vram = true, + .market_name = "JingJia Micro JM9100", + }, + { + .chip_id = JD9230P, + .num_core = 2, + .num_vram = 2, + .vram_bars = {0, 2}, + .mmio_bar = 1, + .cores = {{0, 0x00900000, 0x00010000, "etnaviv-gpu,3d"}, + {1, 0x00910000, 0x00010000, "etnaviv-gpu,3d"},}, + .has_dedicated_vram = true, + .market_name = "JingJia Micro JD9230P", + }, + { + .chip_id = GP102, + .num_core = 2, + .num_vram = 1, + .vram_bars = {0,}, + .mmio_bar = 2, + .cores = {{0, 0x00040000, 0x00010000, "etnaviv-gpu,3d"}, + {0, 0x000C0000, 0x00010000, "etnaviv-gpu,2d"},}, + .has_dedicated_vram = true, + .market_name = "LingJiu GP102", + }, + { + .chip_id = GC1000_IN_LS7A1000, + .num_core = 1, + .num_vram = 1, + .vram_bars = {2,}, + .mmio_bar = 0, + .cores = {{0, 0, 0x00010000, "etnaviv-gpu,3d"}, {}, {}, {}}, + .has_dedicated_vram = true, + .market_name = "GC1000 in LS7A1000", + }, + { + .chip_id = GC1000_IN_LS2K1000, + .num_core = 1, + .num_vram = 0, + .mmio_bar = 0, + .cores = {{0, 0, 0x00010000, "etnaviv-gpu,3d"}, {}, {}, {}}, + .has_dedicated_vram = false, + .market_name = "GC1000 in LS2K1000", + }, +}; + +static const struct etnaviv_pci_gpu_data * +etnaviv_pci_get_platform_data(const struct pci_device_id *entity) +{ + enum etnaviv_pci_gpu_chip_id chip_id = entity->driver_data; + static const struct etnaviv_pci_gpu_data *pdata; + + pdata = &gc_core_plaform_data[chip_id]; + if (!pdata || pdata->chip_id == GC_CORE_UNKNOWN) + return NULL; + + return pdata; +} + +extern const struct component_master_ops etnaviv_master_ops; + +static int etnaviv_pci_probe(struct pci_dev *pdev, + const struct pci_device_id *ent) +{ + const struct etnaviv_pci_gpu_data *pdata; + struct device *dev = &pdev->dev; + struct component_match *matches = NULL; + unsigned int i; + unsigned int num_core; + int ret; + + ret = pcim_enable_device(pdev); + if (ret) { + dev_err(dev, "failed to enable\n"); + return ret; + } + + pci_set_master(pdev); + + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); + if (ret) + return ret; + + pdata = etnaviv_pci_get_platform_data(ent); + if (!pdata) + return -ENODEV; + + num_core = pdata->num_core; + + dev_info(dev, "%s has %u GPU cores\n", pdata->market_name, num_core); + + /* + * Create a virtual platform device for the sub-component, + * a sub-component is refer to a single vivante GPU core. + * But it can also be extended to stand for a display controller + * or any other IP core attached via the same PCIe master. + */ + for (i = 0; i < num_core; i++) { + struct platform_device *virtual_child; + resource_size_t start, offset, size; + struct resource res; + + start = pci_resource_start(pdev, pdata->mmio_bar); + offset = pdata->cores[i].offset; + size = pdata->cores[i].size; + + memset(&res, 0, sizeof(res)); + res.flags = IORESOURCE_MEM; + res.name = "reg"; + res.start = start + offset; + res.end = start + offset + size - 1; + + ret = etnaviv_create_platform_device(dev, + pdata->cores[i].compatible, + pdata->cores[i].id, + &res, + (void *)pdata, + &virtual_child); + if (ret) + return ret; + + component_match_add(dev, &matches, component_compare_dev, + &virtual_child->dev); + } + + ret = component_master_add_with_match(dev, &etnaviv_master_ops, matches); + + return ret; +} + +static int platform_device_remove_callback(struct device *dev, void *data) +{ + struct platform_device *pdev = to_platform_device(dev); + + etnaviv_destroy_platform_device(&pdev); + + return 0; +} + +static void etnaviv_pci_remove(struct pci_dev *pdev) +{ + struct device *dev = &pdev->dev; + + component_master_del(dev, &etnaviv_master_ops); + + device_for_each_child(dev, NULL, platform_device_remove_callback); + + pci_clear_master(pdev); +} + +static const struct pci_device_id etnaviv_pci_id_lists[] = { + {0x0731, 0x9100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, JM9100}, + {0x0731, 0x9230, PCI_ANY_ID, PCI_ANY_ID, 0, 0, JD9230P}, + {0x0709, 0x0001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, GP102}, + {0x0014, 0x7A15, PCI_ANY_ID, PCI_ANY_ID, 0, 0, GC1000_IN_LS7A1000}, + {0x0014, 0x7A05, PCI_ANY_ID, PCI_ANY_ID, 0, 0, GC1000_IN_LS2K1000}, + { } +}; + +static struct pci_driver etnaviv_pci_driver = { + .name = "etnaviv", + .id_table = etnaviv_pci_id_lists, + .probe = etnaviv_pci_probe, + .remove = etnaviv_pci_remove, +}; + +int etnaviv_register_pci_driver(void) +{ + return pci_register_driver(&etnaviv_pci_driver); +} + +void etnaviv_unregister_pci_driver(void) +{ + pci_unregister_driver(&etnaviv_pci_driver); +} + +MODULE_DEVICE_TABLE(pci, etnaviv_pci_id_lists); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h new file mode 100644 index 000000000000..1db559ee5e9b --- /dev/null +++ b/drivers/gpu/drm/etnaviv/etnaviv_pci_drv.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __ETNAVIV_PCI_DRV_H__ +#define __ETNAVIV_PCI_DRV_H__ + +#ifdef CONFIG_DRM_ETNAVIV_PCI_DRIVER + +int etnaviv_register_pci_driver(void); +void etnaviv_unregister_pci_driver(void); + +#else + +static inline int etnaviv_register_pci_driver(void) { return 0; } +static inline void etnaviv_unregister_pci_driver(void) { } + +#endif + +#endif