From patchwork Thu Apr 4 21:25:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janakarajan Natarajan X-Patchwork-Id: 10886371 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A014F922 for ; Thu, 4 Apr 2019 21:26:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 923B728AF6 for ; Thu, 4 Apr 2019 21:26:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8638328AFA; Thu, 4 Apr 2019 21:26:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCFE128AF6 for ; Thu, 4 Apr 2019 21:26:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730210AbfDDV0U (ORCPT ); Thu, 4 Apr 2019 17:26:20 -0400 Received: from mail-eopbgr760073.outbound.protection.outlook.com ([40.107.76.73]:65094 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729400AbfDDV0U (ORCPT ); Thu, 4 Apr 2019 17:26:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nCLOiXEqYHT5rVVxMtxxuuqR9NNXeUhqaZrcZ9KShG0=; b=CH1GCdKkrcKFeq0u6JwVfamapQXc/A1MkKOb9m2eeBdu5MpFExqyYlf3yfuZqHg47lfaanNt8OHaGdSkEdlygiOWvRNUgI4EFSj1ZrultGukouV1udfS5K/DSanUqU5M0iDiPJfNR8LA9VjsKQFGU3em47/92MQG51H+yu+lHkY= Received: from SN6PR12MB2736.namprd12.prod.outlook.com (52.135.107.27) by SN6PR12MB2784.namprd12.prod.outlook.com (52.135.107.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1750.22; Thu, 4 Apr 2019 21:25:55 +0000 Received: from SN6PR12MB2736.namprd12.prod.outlook.com ([fe80::65cb:af55:6bd4:55a]) by SN6PR12MB2736.namprd12.prod.outlook.com ([fe80::65cb:af55:6bd4:55a%4]) with mapi id 15.20.1750.017; Thu, 4 Apr 2019 21:25:55 +0000 From: "Natarajan, Janakarajan" To: "linux-acpi@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-pm@vger.kernel.org" , "devel@acpica.org" CC: "Rafael J . Wysocki" , Len Brown , Viresh Kumar , Robert Moore , Erik Schmauss , "Ghannam, Yazen" , "Natarajan, Janakarajan" Subject: [PATCH v2 6/7] acpi/cppc: Add support for optional CPPC registers Thread-Topic: [PATCH v2 6/7] acpi/cppc: Add support for optional CPPC registers Thread-Index: AQHU6yz8Ze4s7qGdUEKuNcRjfPi3YA== Date: Thu, 4 Apr 2019 21:25:55 +0000 Message-ID: <7c999115c8ef4cdaeb4ca2839fdcd01485292ac8.1554410643.git.Janakarajan.Natarajan@amd.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN4PR0201CA0052.namprd02.prod.outlook.com (2603:10b6:803:20::14) To SN6PR12MB2736.namprd12.prod.outlook.com (2603:10b6:805:77::27) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Janakarajan.Natarajan@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [165.204.78.2] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b8af6c15-9ad3-4e5b-b84b-08d6b9441f12 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600139)(711020)(4605104)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020);SRVR:SN6PR12MB2784; x-ms-traffictypediagnostic: SN6PR12MB2784: x-microsoft-antispam-prvs: x-forefront-prvs: 0997523C40 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39860400002)(346002)(366004)(396003)(136003)(376002)(199004)(189003)(97736004)(6436002)(478600001)(71200400001)(118296001)(7736002)(71190400001)(36756003)(14444005)(256004)(72206003)(4326008)(2201001)(86362001)(486006)(68736007)(14454004)(6486002)(66066001)(316002)(8676002)(2501003)(102836004)(52116002)(2906002)(110136005)(26005)(99286004)(6506007)(54906003)(76176011)(2616005)(186003)(81156014)(5660300002)(81166006)(305945005)(50226002)(8936002)(6512007)(25786009)(53936002)(6116002)(446003)(106356001)(105586002)(3846002)(476003)(11346002)(386003);DIR:OUT;SFP:1101;SCL:1;SRVR:SN6PR12MB2784;H:SN6PR12MB2736.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: SrxzS1TXSuZJSSdG8VTCe7TwrT1cLYQuzqjl93dTVWqax6ZygZ7/HAMmfnE5rNJh3jrLnrtTpRX8D5/JIB5mOtk9pvmp5L/pW+eRNJswpd6vM/5DBBOf5SpkGVn0HerQoNclOeE1LqGfdLyhs9wCW4TAbknIXhKVvayq0QLd0mIiUhj/3MXU60/IeF4Cdc1XJeYhxSmh0Ssy6WHG458McE7RW0Ok+PI+2eG+yNCBwhn2tASzBANYpFw7fysoUCv66bV0i/SfIUnEFbFALE7Ublgs+CrkZw7s2j2qwY8FYtu9/80+RFEZzBQWSihGod4CD2I3oS08sMFS1rlX4sEs0Gr01rJ9Gz3Elt9w8TlVTsro7cbiOmXV4MZzD2ht+V5MntymOgKzBMDgUGwMSgZMOxHCh7qiwJU91OkZqFueAfI= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b8af6c15-9ad3-4e5b-b84b-08d6b9441f12 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Apr 2019 21:25:55.3221 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2784 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Yazen Ghannam Newer AMD processors support a subset of the optional CPPC registers. Create show, store and helper routines for supported CPPC registers. Signed-off-by: Yazen Ghannam [ carved out into a patch, cleaned up, productized ] Signed-off-by: Janakarajan Natarajan --- drivers/acpi/cppc_acpi.c | 120 ++++++++++++++++++++++++++++++++++++--- include/acpi/cppc_acpi.h | 3 + 2 files changed, 115 insertions(+), 8 deletions(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 1e862415faf0..bb57d526e54e 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -204,6 +204,17 @@ show_cppc_data_ro(cppc_get_perf_caps, cppc_perf_caps, nominal_freq); show_cppc_data_ro(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, reference_perf); show_cppc_data_ro(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, wraparound_time); +show_cppc_data(cppc_get_perf, cppc_perf_ctrls, desired_perf); +show_cppc_data(cppc_get_perf, cppc_perf_ctrls, max_perf); +show_cppc_data(cppc_get_perf, cppc_perf_ctrls, min_perf); +show_cppc_data(cppc_get_perf, cppc_perf_ctrls, energy_perf); +show_cppc_data(cppc_get_perf, cppc_perf_ctrls, auto_sel_enable); + +store_cppc_data_rw(cppc_perf_ctrls, desired_perf, DESIRED_PERF); +store_cppc_data_rw(cppc_perf_ctrls, max_perf, MAX_PERF); +store_cppc_data_rw(cppc_perf_ctrls, min_perf, MIN_PERF); +store_cppc_data_rw(cppc_perf_ctrls, energy_perf, ENERGY_PERF); +store_cppc_data_rw(cppc_perf_ctrls, auto_sel_enable, AUTO_SEL_ENABLE); static ssize_t show_feedback_ctrs(struct kobject *kobj, struct attribute *attr, char *buf) @@ -800,6 +811,21 @@ static int set_cppc_attrs(struct cpc_desc *cpc, int entries) case CTR_WRAP_TIME: cppc_attrs[attr_i++] = &wraparound_time.attr; break; + case MAX_PERF: + cppc_attrs[attr_i++] = &max_perf.attr; + break; + case MIN_PERF: + cppc_attrs[attr_i++] = &min_perf.attr; + break; + case ENERGY_PERF: + cppc_attrs[attr_i++] = &energy_perf.attr; + break; + case AUTO_SEL_ENABLE: + cppc_attrs[attr_i++] = &auto_sel_enable.attr; + break; + case DESIRED_PERF: + cppc_attrs[attr_i++] = &desired_perf.attr; + break; } } @@ -1391,7 +1417,7 @@ int cppc_set_reg(int cpu, struct cppc_perf_ctrls *perf_ctrls, int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu); struct cppc_pcc_data *pcc_ss_data = NULL; struct cpc_register_resource *reg; - int ret = 0; + int ret = 0, regs_in_pcc = 0; u32 value; if (!cpc_desc) { @@ -1403,6 +1429,18 @@ int cppc_set_reg(int cpu, struct cppc_perf_ctrls *perf_ctrls, case DESIRED_PERF: value = perf_ctrls->desired_perf; break; + case MAX_PERF: + value = perf_ctrls->max_perf; + break; + case MIN_PERF: + value = perf_ctrls->min_perf; + break; + case ENERGY_PERF: + value = perf_ctrls->energy_perf; + break; + case AUTO_SEL_ENABLE: + value = perf_ctrls->auto_sel_enable; + break; default: pr_debug("CPC register index #%d not writeable\n", reg_idx); return -EINVAL; @@ -1418,6 +1456,7 @@ int cppc_set_reg(int cpu, struct cppc_perf_ctrls *perf_ctrls, * achieve that goal here */ if (CPC_IN_PCC(reg)) { + regs_in_pcc = 1; if (pcc_ss_id < 0) { pr_debug("Invalid pcc_ss_id\n"); return -ENODEV; @@ -1440,13 +1479,10 @@ int cppc_set_reg(int cpu, struct cppc_perf_ctrls *perf_ctrls, cpc_desc->write_cmd_status = 0; } - /* - * Skip writing MIN/MAX until Linux knows how to come up with - * useful values. - */ - cpc_write(cpu, reg, value); + if (CPC_SUPPORTED(reg)) + cpc_write(cpu, reg, value); - if (CPC_IN_PCC(reg)) + if (regs_in_pcc) up_read(&pcc_ss_data->pcc_lock); /* END Phase-I */ /* * This is Phase-II where we transfer the ownership of PCC to Platform @@ -1494,7 +1530,7 @@ int cppc_set_reg(int cpu, struct cppc_perf_ctrls *perf_ctrls, * case during a CMD_READ and if there are pending writes it delivers * the write command before servicing the read command */ - if (CPC_IN_PCC(reg)) { + if (regs_in_pcc) { if (down_write_trylock(&pcc_ss_data->pcc_lock)) {/* BEGIN Phase-II */ /* Update only if there are pending write commands */ if (pcc_ss_data->pending_pcc_write_cmd) @@ -1512,6 +1548,74 @@ int cppc_set_reg(int cpu, struct cppc_perf_ctrls *perf_ctrls, } EXPORT_SYMBOL_GPL(cppc_set_reg); +int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) +{ + struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpu); + struct cpc_register_resource *desired_reg, *max_reg, *min_reg; + struct cpc_register_resource *energy_reg, *auto_sel_enable_reg; + int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu); + u64 desired, max, min, energy, auto_sel_enable; + struct cppc_pcc_data *pcc_ss_data = NULL; + int ret = 0, regs_in_pcc = 0; + + if (!cpc_desc) { + pr_debug("No CPC descriptor for CPU: %d\n", cpu); + return -ENODEV; + } + + desired_reg = &cpc_desc->cpc_regs[DESIRED_PERF]; + max_reg = &cpc_desc->cpc_regs[MAX_PERF]; + min_reg = &cpc_desc->cpc_regs[MIN_PERF]; + energy_reg = &cpc_desc->cpc_regs[ENERGY_PERF]; + auto_sel_enable_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE]; + + if (CPC_IN_PCC(desired_reg) || CPC_IN_PCC(max_reg) || + CPC_IN_PCC(min_reg) || CPC_IN_PCC(energy_reg) || + CPC_IN_PCC(auto_sel_enable_reg)) { + pcc_ss_data = pcc_data[pcc_ss_id]; + down_write(&pcc_ss_data->pcc_lock); + regs_in_pcc = 1; + + /*Ring doorbell once to update PCC subspace */ + if (send_pcc_cmd(pcc_ss_id, CMD_READ) < 0) { + ret = -EIO; + goto out_err; + } + } + + /* desired_perf is the only mandatory value in perf_ctrls */ + if (cpc_read(cpu, desired_reg, &desired)) + ret = -EFAULT; + + if (CPC_SUP_BUFFER_ONLY(max_reg) && cpc_read(cpu, max_reg, &max)) + ret = -EFAULT; + + if (CPC_SUP_BUFFER_ONLY(min_reg) && cpc_read(cpu, min_reg, &min)) + ret = -EFAULT; + + if (CPC_SUP_BUFFER_ONLY(energy_reg) && + cpc_read(cpu, energy_reg, &energy)) + ret = -EFAULT; + + if (CPC_SUPPORTED(auto_sel_enable_reg) && + cpc_read(cpu, auto_sel_enable_reg, &auto_sel_enable)) + ret = -EFAULT; + + if (!ret) { + perf_ctrls->desired_perf = desired; + perf_ctrls->max_perf = max; + perf_ctrls->min_perf = min; + perf_ctrls->energy_perf = energy; + perf_ctrls->auto_sel_enable = auto_sel_enable; + } + +out_err: + if (regs_in_pcc) + up_write(&pcc_ss_data->pcc_lock); + return ret; +} +EXPORT_SYMBOL_GPL(cppc_get_perf); + /** * cppc_get_transition_latency - returns frequency transition latency in ns * diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index ba3b3fb64572..6f651235933c 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -117,6 +117,8 @@ struct cppc_perf_ctrls { u32 max_perf; u32 min_perf; u32 desired_perf; + u32 auto_sel_enable; + u32 energy_perf; }; struct cppc_perf_fb_ctrs { @@ -140,6 +142,7 @@ struct cppc_cpudata { extern int cppc_get_desired_perf(int cpunum, u64 *desired_perf); extern int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs); extern int cppc_set_reg(int cpu, struct cppc_perf_ctrls *perf_ctrls, enum cppc_regs reg_idx); +extern int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls); extern int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps); extern int acpi_get_psd_map(struct cppc_cpudata **); extern unsigned int cppc_get_transition_latency(int cpu);