Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2918013rdb; Wed, 4 Oct 2023 16:10:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwsq/hzHAyRud+cHcRX1ncD7Hv3Y4QHTbB4N5RQ5uYlDWbyWfFs1IYUryFtW6bNIDsLcdg X-Received: by 2002:a05:6870:d214:b0:1d5:8fb8:98ef with SMTP id g20-20020a056870d21400b001d58fb898efmr3976192oac.31.1696461044418; Wed, 04 Oct 2023 16:10:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696461044; cv=none; d=google.com; s=arc-20160816; b=d5KD4HkhY/UudLuuSCdBKiqeZef21nWzfaQ53VMM+aaaEvyvKr4FkXddxd63koIdpj J6DbBTj350wF5b3rYPl/qfmwUgF/odjRpZvU+BhORnpAIqfw0OdkZyUWexeD2L43pD1M HcQaKDs9T9/ZAgTu1nPiAxR+GPLna12jyvTpysWTuu6Mdwjjee2W+F1rWvWAbhDALXqU Js/P2rrYCfE/FR7og+8c3lZqYflhd3r20gQmZyPROiidF0B7ZzXGedtZIHUfVS3WTYpe iEnAlmE4wBAlz60YSL9Lp/ZOzrSjzrmDAcZnwSrdsIRxKp118SLUgh0/XhnJP1u0srY4 KGkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=69gIpyK7nv2Iea6jvMYtm72gHswTYP8DsvGBEyD4Qnk=; fh=4yqZa5qMIeexWjIRXZHjjSz79zM/hq9GqUqPY4KPUpg=; b=b6ZMUplSG4TJF+sA+uJxQvzzbwSMdDVp0f8tl2WmpfbGzu0zEnNHcINKsz/j95IBVp hMj6HCvhh29HlQvTR+V5OIErBcBe/WkSXyx+uPOiRILGwOvmufliWvDDfVsuNnkiydCk fH4EUmLBg3qM/vKD4kzXm1ulEsxoV5YjXpd89XVxHEKp3Y5SEmvDO3t/TzRavUOU3Dll +aT3C6D1mfGhOGQf9zkyGCpvZgpMvfAp/+BDoxukPFhsaZF1MNMo5nSA/xYUBjlvviYh GoaKNhWdHHBaoLrqSdI9D3i/ngEjsA7vKztnfJT2gskFZccIdKP+qp4os3UtZlC/76NH d0kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CIyVh30k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id cq13-20020a056a00330d00b0069339f19f93si120336pfb.277.2023.10.04.16.10.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 16:10:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CIyVh30k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id AF1DD825A9AB; Wed, 4 Oct 2023 16:10:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240657AbjJDXKM (ORCPT + 99 others); Wed, 4 Oct 2023 19:10:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240519AbjJDXKL (ORCPT ); Wed, 4 Oct 2023 19:10:11 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BFC3D8; Wed, 4 Oct 2023 16:10:07 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A01CEC433C7; Wed, 4 Oct 2023 23:10:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696461006; bh=sr3ifcYlnQGpK7RnHCI5qP/JfUY4gY6cRzG0hwZktu8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CIyVh30kCx/E3HkEEl2nSJkUfwb0kjb3KXI8ARak+kw+rvNQCmJglP/CtQEaDBYOP UmJgRx1niIHuZVu4fiOMIgM/xdw8s/DHLyfteoAF9i91+74oPnxgaSVFgPqxVQxweM XYaRLUNX1C6k4R5n9S0lI0bCMK2o5Ck45irETSBscxPno1fsrsFattKipt61D0NwG9 x1ocuKJBWNjJjS/B14TN+SU3kAuHDrUgdr1cKqJskBA/uaVMKgNZx0tQ+j1gdrZIhg 9WIc2//ILIuhU4N2mnGJh+bVkeVx82YFrXhrsvuPZPhJllvTE7UZ3YBIekGloVb7sc O/MzMZwgP7sYw== Received: by mercury (Postfix, from userid 1000) id B812E106052D; Thu, 5 Oct 2023 01:10:03 +0200 (CEST) Date: Thu, 5 Oct 2023 01:10:03 +0200 From: Sebastian Reichel To: Mario Limonciello Cc: amd-gfx@lists.freedesktop.org, Alex Deucher , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Jun.ma2@amd.com Subject: Re: [PATCH 2/3] power: supply: Don't count 'unknown' scope power supplies Message-ID: <20231004231003.z55btgajmixxadqo@mercury.elektranox.org> References: <20230926225955.386553-1-mario.limonciello@amd.com> <20230926225955.386553-3-mario.limonciello@amd.com> <20230930201826.biy27esyw4ttxt4p@mercury.elektranox.org> <8d4e4b74-4477-41e0-a690-8b9f38907a7b@amd.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="mavrvis2xy3vzwff" Content-Disposition: inline In-Reply-To: <8d4e4b74-4477-41e0-a690-8b9f38907a7b@amd.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 04 Oct 2023 16:10:19 -0700 (PDT) --mavrvis2xy3vzwff Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, On Sun, Oct 01, 2023 at 07:00:11PM -0500, Mario Limonciello wrote: > Let me try to add more detail. >=20 > This is an OEM system that has 3 USB type C ports. It's an Intel system, > but this doesn't matter for the issue. > * when ucsi_acpi is not loaded there are no power supplies in the system = and > it reports power_supply_is_system_supplied() as AC. > * When ucsi_acpi is loaded 3 power supplies will be registered. > power_supply_is_system_supplied() reports as DC. >=20 > Now when you add in a Navi3x AMD dGPU to the system the power supplies do= n't > change. This particular dGPU model doesn't contain a USB-C port, so there > is no UCSI power supply registered. >=20 > As amdgpu is loaded it looks at device initialization whether the system = is > powered by AC or DC. Here is how it looks: >=20 > https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/dri= vers/gpu/drm/amd/amdgpu/amdgpu_device.c?h=3Dlinux-6.5.y#n3834 >=20 > On the OEM system if amdgpu loads before the ucsi_acpi driver (such as in > the initramfs) then the right value is returned for > power_supply_is_system_supplied() - AC. >=20 > If amdgpu is loaded after the ucsi_acpi driver, the wrong value is return= ed > for power_supply_is_system_supplied() - DC. >=20 > This value is very important to set up the dGPU properly. If the wrong > value is returned, the wrong value will be notified to the hardware and t= he > hardware will not behave properly. On the OEM system this is a "black > screen" at bootup along with RAS errors emitted by the dGPU. >=20 > With no changes to a malfunctioning kernel or initramfs binaries I can add > modprobe.blacklist=3Ducsi_acpi to kernel command line avoid registering t= hose > 3 power supplies and the system behaves properly. >=20 > So I think it's inappropriate for "UNKNOWN" scope power supplies to be > registered and treated as system supplies, at least as it pertains to > power_supply_is_system_supplied(). So the main issue is, that the ucsi_acpi registers a bunch of power-supply chargers with unknown scope on a desktop systems and that results in the system assumed to be supplied from battery. The problem with your change is, that many of the charger drivers don't set a scope at all (and thus report unknown scope). Those obviously should not be skipped. Probably most of these drivers could be changed to properly set the scope, but it needs to be checked on a case-by-case basis. With your current patch they would regress in the oposite direction of your use-case. Ideally ucsi is changed to properly describe the scope, but I suppose this information is not available in ACPI? Assuming that the above are not solvable easily, my idea would be to only count the number of POWER_SUPPLY_TYPE_BATTERY device, which have !POWER_SUPPLY_SCOPE_DEVICE and exit early if there are none. Basically change __power_supply_is_system_supplied(), so that it looks like this: =2E.. if (!psy->desc->get_property(psy, POWER_SUPPLY_PROP_SCOPE, &ret)) if (ret.intval =3D=3D POWER_SUPPLY_SCOPE_DEVICE) return 0; if (psy->desc->type =3D=3D POWER_SUPPLY_TYPE_BATTERY) (*count)++; else if (!psy->desc->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &ret)) return ret.intval; =2E.. That should work in both cases. -- Sebastian > > > drivers/power/supply/power_supply_core.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > >=20 > > > diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power= /supply/power_supply_core.c > > > index d325e6dbc770..3de6e6d00815 100644 > > > --- a/drivers/power/supply/power_supply_core.c > > > +++ b/drivers/power/supply/power_supply_core.c > > > @@ -349,7 +349,7 @@ static int __power_supply_is_system_supplied(stru= ct device *dev, void *data) > > > unsigned int *count =3D data; > > > if (!psy->desc->get_property(psy, POWER_SUPPLY_PROP_SCOPE, &ret)) > > > - if (ret.intval =3D=3D POWER_SUPPLY_SCOPE_DEVICE) > > > + if (ret.intval !=3D POWER_SUPPLY_SCOPE_SYSTEM) > > > return 0; > > > (*count)++; > > > --=20 > > > 2.34.1 > > >=20 >=20 --mavrvis2xy3vzwff Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAmUd8McACgkQ2O7X88g7 +poWjA/9HdkzUe4iv3N7kLQ1MX8LLpg04IlI4kPsSscO2XL8B9FQgQVSaVaH8bSc IB0/8clq1dhPvpsC2lZBKGxEnzm1DA3Q97UZ+i+pO2yCeYB2b/I5dnXLYr5m3teZ prHUSgoGMNF3lc5QeLO7hc/RT4pKbk7eme3geqCj8Z1JDRUnJLychMMhtzqRch7k 14ZZWZ3e93vDs6J0Kz5/MT4ws/4m831MzA9sbXK2qRtugV259jeEw/6UtUIdyp8V QK2/P9k6ZXfcZjzkm0JVm19lWvyF3YM2WzeoLLeYE8bz6BIBQauw/DyTknKFDmQx 3ftwFyd6fbnfOfKRgXac2zlrG5W1v1y6Xs8GfMvrWf1KxvXNrpzU8VBCArJk67k3 CP2s6f7CvFxe9XrMinsge58mraayaqSUmc9QeM/tKuBNpUGglUJo/FFFHMBfITqb M1zll2uGFGajOfEpiI9pHIIVWhXzVCoYUdvu3KJsmTciuqSX2qJWY/76P6YdVLXR JT1i64+6ca7VklC5PWgG98s2xoGHYowVmGSChtEkYvAD8GpR+CQELBj8R6xcApAu njA+xFNG6ZvP8BSLYUd5Qon+EHqHmBA70oj9FkZueKie1+YLSlH4prMn5aQqThkP WZodfhxa5KMbzTbnsd62i4yZkfbU1uKFsgYPXDCA/feQeuQLLwE= =/PRi -----END PGP SIGNATURE----- --mavrvis2xy3vzwff--