Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp19701lqs; Thu, 13 Jun 2024 02:30:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWG4jFqpmvML5Ic5De9JOn+hyQt9b7zh2riM/QqiofUCVIHR5xda9TmJ3pKXmhzD8LC3VWUTJ6cbM7nSWmrPKogeicV8NWDRZ45Dy0gfA== X-Google-Smtp-Source: AGHT+IFCimweEZX2YUwgSoSP2UHW5lBiOLrgosjyxMvjq++Fu2iBaJRX8jjmPG7RjUT2FcuIn6r9 X-Received: by 2002:a05:620a:394e:b0:795:8e6a:3c70 with SMTP id af79cd13be357-797f60c1307mr412051685a.62.1718271016338; Thu, 13 Jun 2024 02:30:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718271016; cv=pass; d=google.com; s=arc-20160816; b=QgWuSUUBgdHzI/2pHAPPlVEdfJNhK1htksoKxRuV3yY6N/TT8SkR/DCqBTH20IPvG7 XuPyRoeQ+tjSuaQidb6yfxpS8Rk2wjm2wdwS7JelEhY3T/DPVJyoEA9P7Yi5xrV1bbFr 07l9xtUREcl71MbjTDttx9Ew9wk7zHsZd4TJYu55N/za//TwgqoHn5IT5lo53vtEHbln E7X9c5ghshwPbnQXWQYQ5d/6zQqpQ+4eCPV0MUZR8So24HyTn9B16MRNlhoAJrpcjCS0 X4mdQs375petzohVciMCN7ORF0XyVpqLCECSfQRSGuRyRp6jF8kL2JvKsoKy1DNiigyl F7Ww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=5M3ELKqqsvIZfzOpsu+gAgFZkgR2tBXp2Hwr3Ne0u3I=; fh=Oxd+5b2/vVSci58eax61Cmg+N6b0lvTfONqketC1Dg0=; b=U2TyWk2/37d0UCl6g6qj7X9Opd/FK4FwWqwviQ7ivyceRR3lRK8XlH8TQsR03uGt4f Ew5KZNaWVrVH5W1uBK+DxO0mRaqJR91ns90Q2N9+7e5X8zJtz9sc748HEwTk/g6dOeOa 7Wyohxv/kQaOWx718DeG0YMT15DPkPUnkdOrwhStx6S+qZ3sB/Wsvk2wxHa2ZBqrs7Rn nQlRmDVX3vYgfLl7piBQq6URK8H4ctCLI7bJfHDmtB9WszU9mvK7+SU/xUC0PYQfbzag ETJ78RgkpcBtfVmx3IwipePa12S6GaQj/iNI5TA4DuHBFdVPEnZyR1d+Lt8xvsy9FgmZ sZkg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tomeuvizoso-net.20230601.gappssmtp.com header.s=20230601 header.b=2tZRMBmt; arc=pass (i=1 spf=pass spfdomain=tomeuvizoso.net dkim=pass dkdomain=tomeuvizoso-net.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-212951-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212951-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-798aadc4162si92683285a.200.2024.06.13.02.30.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 02:30:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212951-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@tomeuvizoso-net.20230601.gappssmtp.com header.s=20230601 header.b=2tZRMBmt; arc=pass (i=1 spf=pass spfdomain=tomeuvizoso.net dkim=pass dkdomain=tomeuvizoso-net.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-212951-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212951-linux.lists.archive=gmail.com@vger.kernel.org" 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 071811C23AA9 for ; Thu, 13 Jun 2024 09:30:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1879113D62C; Thu, 13 Jun 2024 09:30:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tomeuvizoso-net.20230601.gappssmtp.com header.i=@tomeuvizoso-net.20230601.gappssmtp.com header.b="2tZRMBmt" Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D6B413DDB8 for ; Thu, 13 Jun 2024 09:30:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718271005; cv=none; b=M2pDl8nuooHCCYgSxqcgViO+Tw/DhICp1B1mGCW+vUnOoW2S6NOa3zQOS1o5BBvNlEZsQesXokox7/WnYoLVKXq57yXwthOZI0xJ/+rKuEBEd09YXQnrYEJfetU0PbuA6C/Gnlb9dRiQi5dgRGyh5aW2opxmE9SuZo2w4bvy2Ig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718271005; c=relaxed/simple; bh=r70M0JfsYwTJ3NX7KJwbL08Y8oQ3NMtqgodl6EYlEYE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=DHTjas39E5UDD51q1K7TK3gMM/NFu9sZgNp1Vls7Z0yZ20xytvfhLAVqlCv4TucNgcDHBhvO+dCuXdH09gdw5AZakHghCofa6mGvul3Kwu/mKeR9Ec/VoVG4EEEWSUC7sJjR54Uok2dQWRxpmgMle+are9zNeywfwts97aLrBV4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tomeuvizoso.net; spf=pass smtp.mailfrom=tomeuvizoso.net; dkim=pass (2048-bit key) header.d=tomeuvizoso-net.20230601.gappssmtp.com header.i=@tomeuvizoso-net.20230601.gappssmtp.com header.b=2tZRMBmt; arc=none smtp.client-ip=209.85.219.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tomeuvizoso.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tomeuvizoso.net Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-6b06b78e716so4997906d6.3 for ; Thu, 13 Jun 2024 02:30:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tomeuvizoso-net.20230601.gappssmtp.com; s=20230601; t=1718271003; x=1718875803; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5M3ELKqqsvIZfzOpsu+gAgFZkgR2tBXp2Hwr3Ne0u3I=; b=2tZRMBmtyS/sMy5DahrXVexnJrsSbZEaGBuaf9no5PLZAopW+CqaM0ALoKiBcMjZTg mUMoNEVtzLgPMxaBmIDgRjWP9KXjGl6VkYmWLZ+BTVU7hA7UM9bg3XOUOjBiYwsxsmO9 MC5EUxnKpm0HsjjPVjWMNWNKGT39728nCD2alMRk3ekiwkqob50tAnkCqMZ1pmPcuoPT fTvfVHgDPAmJ6sr3bxIgXimxEQJ9b+2PamYE/1jYFiBXUMRoVTXy4lIATq6jg/kjlf94 F7zKXG86xTVACfXiw6DEQt3N7UO3gWmQRynyToXawQfkvnmNJcDelB9LidyAj6BGlTEo aX+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718271003; x=1718875803; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5M3ELKqqsvIZfzOpsu+gAgFZkgR2tBXp2Hwr3Ne0u3I=; b=Zt5Ejm9sxtBuLjjQYlUl0Tl/ty61t41SvIwnLH9uZKkeR4U4VQ4t3wiCF1sqt/AsQj TUIjD+OAbX0Lep4d55m/jAq/anklFbDA+9F839wxQfEdfqSqp56XW6N4d+A18K9qGorc SvI+VSJeYZIUeHMOJHk2yxlG6mqmNbcJ+uWfaay2SrIaqFUXeInomHnFuLvSMFBEzsml SzMURUfb1UqY2zVGu3L/FKWeq2TOraYpP+F0wTDIXVEAlZW5QqauOuvgHAKbnhYfKuPD v3VSkQbUOahvleev8gPk7O9l/3MfO9OsKK4yi+lM2Fh8U5i7VNWbU1xDxhexfMCWzqQC ysJw== X-Forwarded-Encrypted: i=1; AJvYcCWmZKYPSkb1Ms1oWgVeiKD90f+oZTr+9Mh8Q5jEOxcLMTG/9hLyA1MBHmadnwBX0uD29Jgthb4rVPu8Ar/SMhQHJbc1RITNNXTvuTzc X-Gm-Message-State: AOJu0YzmPtzSDEcxPB9xYwC8HA9w2fDFb+O98C89j8pNSRQ1uxmGcdtG LxN2yXKUlGuExjeW0KJwFzLkVlzLTxI5jC+9yZfQ6vOQ6yte4oFlHmCcw5qPvKMiot3pGqa4JJK Q/jI= X-Received: by 2002:a05:6214:4487:b0:6b0:90b4:1ca9 with SMTP id 6a1803df08f44-6b191778e7cmr46679026d6.6.1718271002972; Thu, 13 Jun 2024 02:30:02 -0700 (PDT) Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com. [209.85.222.171]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b2a5c20f53sm4888386d6.52.2024.06.13.02.30.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jun 2024 02:30:02 -0700 (PDT) Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-797f222c9f9so51098585a.3; Thu, 13 Jun 2024 02:30:02 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCV1BEnmaqWdxtnW46RtJ0Bb1nQK7kjbEkpYcYIPO+RMClQ9l+TeHajoxXyPJDGtFg15lcsxx4yyEvNx8+oRI5wc6k3/fv+iIRG81YDN0Q6CwJ4D6v5f4DrhXpm2Xce54O2SmKUR3dzZBZdBEKOvQQT22Ax8CCV9VNC2Hn94lmmd14vLL7K1 X-Received: by 2002:a05:6902:2207:b0:dfe:6002:683 with SMTP id 3f1490d57ef6-dfe67063c46mr4743823276.32.1718270658168; Thu, 13 Jun 2024 02:24:18 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240612-6-10-rocket-v1-0-060e48eea250@tomeuvizoso.net> <20240612-6-10-rocket-v1-2-060e48eea250@tomeuvizoso.net> In-Reply-To: From: Tomeu Vizoso Date: Thu, 13 Jun 2024 11:24:06 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/9] iommu/rockchip: Attach multiple power domains To: Sebastian Reichel Cc: Joerg Roedel , Will Deacon , Robin Murphy , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Oded Gabbay , Tomeu Vizoso , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Philipp Zabel , Sumit Semwal , =?UTF-8?Q?Christian_K=C3=B6nig?= , iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jun 13, 2024 at 2:05=E2=80=AFAM Sebastian Reichel wrote: > > Hi, > > On Wed, Jun 12, 2024 at 03:52:55PM GMT, Tomeu Vizoso wrote: > > IOMMUs with multiple base addresses can also have multiple power > > domains. > > > > The base framework only takes care of a single power domain, as some > > devices will need for these power domains to be powered on in a specifi= c > > order. > > > > Use a helper function to stablish links in the order in which they are > > in the DT. > > > > This is needed by the IOMMU used by the NPU in the RK3588. > > > > Signed-off-by: Tomeu Vizoso > > --- > > To me it looks like this is multiple IOMMUs, which should each get > their own node. I don't see a good reason for merging these > together. I have made quite a few attempts at splitting the IOMMUs and also the cores, but I wasn't able to get things working stably. The TRM is really scant about how the 4 IOMMU instances relate to each other, and what the fourth one is for. Given that the vendor driver treats them as a single IOMMU with four instances and we don't have any information on them, I resigned myself to just have them as a single device. I would love to be proved wrong though and find a way fo getting things stably as different devices so they can be powered on and off as needed. We could save quite some code as well. > I will still review this assuming there is one. That would require > to first of all update the DT binding: > > Documentation/devicetree/bindings/iommu/rockchip,iommu.yaml > > 1. It does not allow using "power-domain-names" property > 2. It limits the number of allowed power-domains to 1 > 3. It limits the number of allowed base addresses to 2 > > Looking at the DT patch you also add more interrupts and clocks, > which are also limited by the binding. You should see a bunch of > warnings when you check the DTBS via 'make dtbs_check' Oops, yeah, I was limiting dtbs_check with DT_SCHEMA_FILES, now I see the errors. > > drivers/iommu/rockchip-iommu.c | 36 ++++++++++++++++++++++++++++++++++= ++ > > 1 file changed, 36 insertions(+) > > > > diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-io= mmu.c > > index f5629515bd78..673b0ebb6262 100644 > > --- a/drivers/iommu/rockchip-iommu.c > > +++ b/drivers/iommu/rockchip-iommu.c > > @@ -6,6 +6,8 @@ > > * Daniel Kurtz > > */ > > > > +#include "linux/err.h" > > +#include "linux/pm_domain.h" > > #include > > #include > > #include > > @@ -115,6 +117,7 @@ struct rk_iommu { > > struct iommu_device iommu; > > struct list_head node; /* entry in rk_iommu_domain.iommus */ > > struct iommu_domain *domain; /* domain to which iommu is attached= */ > > + struct dev_pm_domain_list *pmdomains; > > }; > > > > struct rk_iommudata { > > @@ -1186,6 +1189,7 @@ static int rk_iommu_probe(struct platform_device = *pdev) > > struct resource *res; > > const struct rk_iommu_ops *ops; > > int num_res =3D pdev->num_resources; > > + int pm_domain_count; > > int err, i; > > > > iommu =3D devm_kzalloc(dev, sizeof(*iommu), GFP_KERNEL); > > @@ -1271,6 +1275,35 @@ static int rk_iommu_probe(struct platform_device= *pdev) > > if (!dma_dev) > > dma_dev =3D &pdev->dev; > > > > + pm_domain_count =3D of_property_count_strings(iommu->dev->of_node= , "power-domain-names"); > > pm_domain_count =3D device_property_string_array_count(iommu->dev, "power= -domain-names"); > > When possible using device_property_ is prefered, since it allows > reusing code for systems not using DT. > > > + if (pm_domain_count > 0) { > > + const char **pm_domains =3D kvmalloc_array(pm_domain_coun= t, sizeof(*pm_domains), GFP_KERNEL); > > + struct dev_pm_domain_attach_data pm_domain_data =3D { > > + .pd_names =3D pm_domains, > > + .num_pd_names =3D pm_domain_count, > > + .pd_flags =3D PD_FLAG_DEV_LINK_ON, > > + }; > > + int i; > > + > > + if (!pm_domain_data.pd_names) { > > + err =3D -ENOMEM; > > + goto err_remove_sysfs; > > + } > > + > > + for (i =3D 0; i < pm_domain_count; i++) { > > + err =3D of_property_read_string_index(iommu->dev-= >of_node, "power-domain-names", i, &pm_domains[i]); > > + if (err) { > > + kfree(pm_domains); > > + goto err_remove_sysfs; > > + } > > + } > > There is a helper to read a string array: > > err =3D device_property_read_string_array(iommu->dev, "power-domain-names= ", pm_domains, pm_domain_count); Thanks for the review, Tomeu > -- Sebastian > > > + > > + err =3D dev_pm_domain_attach_list(iommu->dev, &pm_domain_= data, &iommu->pmdomains); > > + kfree(pm_domains); > > + if (err < 0) > > + goto err_remove_sysfs; > > + } > > + > > pm_runtime_enable(dev); > > > > for (i =3D 0; i < iommu->num_irq; i++) { > > @@ -1292,6 +1325,7 @@ static int rk_iommu_probe(struct platform_device = *pdev) > > return 0; > > err_pm_disable: > > pm_runtime_disable(dev); > > + dev_pm_domain_detach_list(iommu->pmdomains); > > err_remove_sysfs: > > iommu_device_sysfs_remove(&iommu->iommu); > > err_unprepare_clocks: > > @@ -1310,6 +1344,8 @@ static void rk_iommu_shutdown(struct platform_dev= ice *pdev) > > devm_free_irq(iommu->dev, irq, iommu); > > } > > > > + dev_pm_domain_detach_list(iommu->pmdomains); > > + > > pm_runtime_force_suspend(&pdev->dev); > > } > > > > > > -- > > 2.45.2 > > > >