Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1443957pxb; Sat, 17 Apr 2021 18:47:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZ+5gyaF1p95KooOtx4dl1wIik9XkFHSrBAFETp1Vu/oruuypDTJBoA03080tKWjqdldlM X-Received: by 2002:a17:906:1a0d:: with SMTP id i13mr14743956ejf.197.1618710424351; Sat, 17 Apr 2021 18:47:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618710424; cv=none; d=google.com; s=arc-20160816; b=lA6TK6l6Ck1If3IZRMmTOqzMSAGfKQzohwUrlt2H28li5NYSJNB3l4PHHxI5EThLZF 79ypHKHPtyJ/zbF3mK1wkoJfhOUh92SNfjAquS/0rNoPE5IuiocdiTqQIKS96eTWFT7D /B0UM2oYO7J5YBEvBEpjn2HczVH7PX0BeJH7TErzgSiTi+jztcOU5mZeSR3jzeZyjwta /rfFzx96i2DcC/dLDE8d/eLLIpnp+mvhiqA0Z8uAHVUK+Fiws6htZPtgBfUlh4Dsmatg ub++kq5J075QX8UjW6W/VQPHAoVxLG7N6SZlFcYDpJzTaJqDqnHGGoi21EeUemavqvcQ /E9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:reply-to :from:subject:message-id:ironport-sdr:ironport-sdr; bh=cqRXei7aS05VJfTDc286rm77NjNgFproXHilLFhuZ6s=; b=cC1edA4hv6Wr6P7Z/RHrHKaHpzL6e6F9wu8X/reaYyoO/BqMLiG4AUW+1l3ZxDWz8o KEuV5HP4oY1kBiuho6ITe3gZCrTwRgWal3yb32FXC88U8aRuM1TnExq71S8V2bEEEnmQ bW5j/U9mLJOezYw0bCrnXuc2m6Pxmsahw0RFf4JCoPWnO9M3qhbnTwOjAdzVUctB3xUT N/Mw9Ou892jVu5gLH2mTkOXG3+6M5bBL1pMCo4TJQnAzPve2LSK5qWy86+N3W3ANLSK6 R3EmyMMc8qMSHefv0Ze8S4DcxQR7Y67j5aE221AbmvKtpEAlUA4Ihc4kldj2LoVf9cI1 sCCQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bf20si7065449edb.271.2021.04.17.18.46.40; Sat, 17 Apr 2021 18:47:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235843AbhDRBoT (ORCPT + 99 others); Sat, 17 Apr 2021 21:44:19 -0400 Received: from mga11.intel.com ([192.55.52.93]:1668 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229870AbhDRBoT (ORCPT ); Sat, 17 Apr 2021 21:44:19 -0400 IronPort-SDR: XDcX4RfvB7H14otMHwiJXrsDhGDQo2TTjxVcs73WvU6VDrPpeipRXe0k+UoPYeTRMBufux3w/B fi9Q1qKgrlPw== X-IronPort-AV: E=McAfee;i="6200,9189,9957"; a="192005351" X-IronPort-AV: E=Sophos;i="5.82,230,1613462400"; d="scan'208";a="192005351" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2021 18:43:51 -0700 IronPort-SDR: S9CHhZOoOZeY8fNo4ZM5k/yi6Zk5TlKy5xj1q1NTZO/Mdj0JkXbTRN4909LrJS9NgqKS2zlFrF 9eLQwl3/Dieg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,230,1613462400"; d="scan'208";a="400268800" Received: from linux.intel.com ([10.54.29.200]) by orsmga002.jf.intel.com with ESMTP; 17 Apr 2021 18:43:51 -0700 Received: from debox1-desk1.jf.intel.com (debox1-desk1.jf.intel.com [10.54.75.174]) by linux.intel.com (Postfix) with ESMTP id 3B65B5808AE; Sat, 17 Apr 2021 18:43:51 -0700 (PDT) Message-ID: <7dfdf70d8d98dde9698f544c054847c141044688.camel@linux.intel.com> Subject: Re: [PATCH V2 5/9] platform/x86: intel_pmc_core: Get LPM requirements for Tiger Lake From: "David E. Box" Reply-To: david.e.box@linux.intel.com To: Hans de Goede , irenic.rajneesh@gmail.com, mgross@linux.intel.com, gayatri.kammela@intel.com Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Date: Sat, 17 Apr 2021 18:43:51 -0700 In-Reply-To: <6dd84b65-44b4-ae12-fe84-c61d8efd43f3@redhat.com> References: <20210417031252.3020837-1-david.e.box@linux.intel.com> <20210417031252.3020837-6-david.e.box@linux.intel.com> <6dd84b65-44b4-ae12-fe84-c61d8efd43f3@redhat.com> Organization: David E. Box Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2021-04-17 at 11:00 +0200, Hans de Goede wrote: > Hi, > > On 4/17/21 5:12 AM, David E. Box wrote: > > From: Gayatri Kammela > > > > Platforms that support low power modes (LPM) such as Tiger Lake > > maintain > > requirements for each sub-state that a readable in the PMC. > > However, unlike > > LPM status registers, requirement registers are not memory mapped > > but are > > available from an ACPI _DSM. Collect the requirements for Tiger > > Lake using > > the _DSM method and store in a buffer. > > > > Signed-off-by: Gayatri Kammela > > Co-developed-by: David E. Box > > Signed-off-by: David E. Box > > Reviewed-by: Hans de Goede > > --- > > > > V2:     - Move buffer allocation so that it does not need to be > > freed > >           (which was missing anyway) when an error is encountered. > >         - Use label to free out_obj after errors > >         - Use memcpy instead of memcpy_fromio for ACPI memory > > > >  drivers/platform/x86/intel_pmc_core.c | 56 > > +++++++++++++++++++++++++++ > >  drivers/platform/x86/intel_pmc_core.h |  2 + > >  2 files changed, 58 insertions(+) > > > > diff --git a/drivers/platform/x86/intel_pmc_core.c > > b/drivers/platform/x86/intel_pmc_core.c > > index 0e59a84b51bf..97efe9a6bd01 100644 > > --- a/drivers/platform/x86/intel_pmc_core.c > > +++ b/drivers/platform/x86/intel_pmc_core.c > > @@ -23,7 +23,9 @@ > >  #include > >  #include > >  #include > > +#include > >   > > +#include > >  #include > >  #include > >  #include > > @@ -31,6 +33,9 @@ > >   > >  #include "intel_pmc_core.h" > >   > > +#define ACPI_S0IX_DSM_UUID             "57a6512e-3979-4e9d-9708- > > ff13b2508972" > > +#define ACPI_GET_LOW_MODE_REGISTERS    1 > > + > >  /* PKGC MSRs are common across Intel Core SoCs */ > >  static const struct pmc_bit_map msr_map[] = { > >         {"Package C2",                  MSR_PKG_C2_RESIDENCY}, > > @@ -590,6 +595,53 @@ static const struct pmc_reg_map tgl_reg_map = > > { > >         .etr3_offset = ETR3_OFFSET, > >  }; > >   > > +static void pmc_core_get_tgl_lpm_reqs(struct platform_device > > *pdev) > > +{ > > +       struct pmc_dev *pmcdev = platform_get_drvdata(pdev); > > +       const int num_maps = pmcdev->map->lpm_num_maps; > > +       size_t lpm_size = LPM_MAX_NUM_MODES * num_maps * 4; > > The type of lpm_size should be an u32, so that it matches > the type of out_obj->buffer.length. > > > +       union acpi_object *out_obj; > > +       struct acpi_device *adev; > > +       guid_t s0ix_dsm_guid; > > +       u32 *lpm_req_regs, *addr; > > + > > +       adev = ACPI_COMPANION(&pdev->dev); > > +       if (!adev) > > +               return; > > + > > +       guid_parse(ACPI_S0IX_DSM_UUID, &s0ix_dsm_guid); > > + > > +       out_obj = acpi_evaluate_dsm(adev->handle, &s0ix_dsm_guid, > > 0, > > +                                   ACPI_GET_LOW_MODE_REGISTERS, > > NULL); > > +       if (out_obj && out_obj->type == ACPI_TYPE_BUFFER) { > > +               int size = out_obj->buffer.length; > > out_obj->buffer.length is an u32, please make this an u32 too. > > > + > > +               if (size != lpm_size) { > > +                       acpi_handle_debug(adev->handle, > > +                               "_DSM returned unexpected buffer > > size," > > +                               " have %d, expect %ld\n", size, > > lpm_size); > > And use %u here (twice), this should also fix the warnings reported > by the kernel test robot. > > If there are no objections against the suggested changes, then I can > fix this up while merging this. > > Please let me know if the suggested changes are ok with you. Changes are good with me. Thanks for the fixup. David > > Regards, > > Hans > > > > +                       goto free_acpi_obj; > > +               } > > +       } else { > > +               acpi_handle_debug(adev->handle, > > +                                 "_DSM function 0 evaluation > > failed\n"); > > +               goto free_acpi_obj; > > +       } > > + > > +       addr = (u32 *)out_obj->buffer.pointer; > > + > > +       lpm_req_regs = devm_kzalloc(&pdev->dev, lpm_size * > > sizeof(u32), > > +                                    GFP_KERNEL); > > +       if (!lpm_req_regs) > > +               goto free_acpi_obj; > > + > > +       memcpy(lpm_req_regs, addr, lpm_size); > > +       pmcdev->lpm_req_regs = lpm_req_regs; > > + > > +free_acpi_obj: > > +       ACPI_FREE(out_obj); > > +} > > + > >  static inline u32 pmc_core_reg_read(struct pmc_dev *pmcdev, int > > reg_offset) > >  { > >         return readl(pmcdev->regbase + reg_offset); > > @@ -1424,10 +1476,14 @@ static int pmc_core_probe(struct > > platform_device *pdev) > >                 return -ENOMEM; > >   > >         mutex_init(&pmcdev->lock); > > + > >         pmcdev->pmc_xram_read_bit = > > pmc_core_check_read_lock_bit(pmcdev); > >         pmc_core_get_low_power_modes(pmcdev); > >         pmc_core_do_dmi_quirks(pmcdev); > >   > > +       if (pmcdev->map == &tgl_reg_map) > > +               pmc_core_get_tgl_lpm_reqs(pdev); > > + > >         /* > >          * On TGL, due to a hardware limitation, the GBE LTR blocks > > PC10 when > >          * a cable is attached. Tell the PMC to ignore it. > > diff --git a/drivers/platform/x86/intel_pmc_core.h > > b/drivers/platform/x86/intel_pmc_core.h > > index aa44fd5399cc..64fb368f40f6 100644 > > --- a/drivers/platform/x86/intel_pmc_core.h > > +++ b/drivers/platform/x86/intel_pmc_core.h > > @@ -294,6 +294,7 @@ struct pmc_reg_map { > >   * @s0ix_counter:      S0ix residency (step adjusted) > >   * @num_lpm_modes:     Count of enabled modes > >   * @lpm_en_modes:      Array of enabled modes from lowest to > > highest priority > > + * @lpm_req_regs:      List of substate requirements > >   * > >   * pmc_dev contains info about power management controller device. > >   */ > > @@ -310,6 +311,7 @@ struct pmc_dev { > >         u64 s0ix_counter; > >         int num_lpm_modes; > >         int lpm_en_modes[LPM_MAX_NUM_MODES]; > > +       u32 *lpm_req_regs; > >  }; > >   > >  #define pmc_for_each_mode(i, mode, pmcdev)             \ > > >