From patchwork Thu Apr 4 21:25:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janakarajan Natarajan X-Patchwork-Id: 10886363 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 C76EA922 for ; Thu, 4 Apr 2019 21:26:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B625228AF6 for ; Thu, 4 Apr 2019 21:26:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8B0F28AFA; Thu, 4 Apr 2019 21:26:18 +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 35AD228AF6 for ; Thu, 4 Apr 2019 21:26:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730723AbfDDVZ4 (ORCPT ); Thu, 4 Apr 2019 17:25:56 -0400 Received: from mail-eopbgr740047.outbound.protection.outlook.com ([40.107.74.47]:6544 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730674AbfDDVZ4 (ORCPT ); Thu, 4 Apr 2019 17:25:56 -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=ElAlkD+uZhbpdj0DyT5bL5qT98VOJp68BileWw2osEI=; b=XptcP6ebLNgEPvo54ipo3JMJlVsSjz9lyzvarKxoCegUenUNvT9HbLawT1FlGLXzAHaTh7L4htI07o7+ZaWWyOcZVYH2LCURpCFodC4ZXSK8P3pmWKkmt0burUpjNsn61jwUxySrW4QDxGynbY48/DYIYfD3paMlYzfwAvyl43I= Received: from SN6PR12MB2736.namprd12.prod.outlook.com (52.135.107.27) by SN6PR12MB2845.namprd12.prod.outlook.com (52.135.102.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1750.17; Thu, 4 Apr 2019 21:25:49 +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:49 +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 2/7] acpi/cppc: Ensure only supported CPPC sysfs entries are created Thread-Topic: [PATCH v2 2/7] acpi/cppc: Ensure only supported CPPC sysfs entries are created Thread-Index: AQHU6yz5Jgs7bPb6v0m5gJ5fN3WRzg== Date: Thu, 4 Apr 2019 21:25:49 +0000 Message-ID: <71114f283852625e3d88cd76ca4f8ac1fd8c25fa.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: 55d53135-e4a5-41e0-d400-08d6b9441b6c x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600139)(711020)(4605104)(4618075)(2017052603328)(7193020);SRVR:SN6PR12MB2845; x-ms-traffictypediagnostic: SN6PR12MB2845: x-microsoft-antispam-prvs: x-forefront-prvs: 0997523C40 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39860400002)(136003)(376002)(396003)(366004)(346002)(199004)(189003)(305945005)(5660300002)(26005)(102836004)(105586002)(66066001)(118296001)(8676002)(106356001)(6116002)(3846002)(81156014)(97736004)(68736007)(53936002)(81166006)(316002)(7736002)(2201001)(50226002)(71190400001)(71200400001)(86362001)(6512007)(2501003)(8936002)(99286004)(25786009)(36756003)(256004)(4326008)(6486002)(478600001)(186003)(110136005)(486006)(14454004)(54906003)(446003)(72206003)(11346002)(2906002)(52116002)(2616005)(476003)(6506007)(386003)(76176011)(6436002);DIR:OUT;SFP:1101;SCL:1;SRVR:SN6PR12MB2845;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: 2q074iE+Oam0Q2U1Ev9TmvW6UH/08+qiVUVZu5FBC6RuwXDshbsqvD/SI8+kH4gHsqRdQjUXDXAfAmne3WkPAFkg4aWqi1rf7U6AcP8X5i7RfMXNmFm56V9EXHNQXP9UOXujOqzCiFmkEokq/u0M07UaLHckSOI4f5Du9UavEPgML77JekunusTIaIPfereab7HqfdO4IE9OiAS906mWvbMCWnBXmDn/bm0GDKYBFSK+sD/f2iyPD4PiRFvxSzl+bwG5N1Ge0PcWaHQkJDWAFfXuNZgUP00j2jnoNVwNgu+5FvIAN+MlODs87P1LprXyy4ykEC0XZy3Bip8kpesojBW8hv9rdMK9poiLLlva3vsnd7HfSmKlaXE9ExpJ6IVXbkkHRincvhGHsXQs0Pel1FFq2oMr1VOI9mKzxfgN1hM= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 55d53135-e4a5-41e0-d400-08d6b9441b6c X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Apr 2019 21:25:49.2588 (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: SN6PR12MB2845 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add attributes for registers that are supported by the platform. This prevents unsupported optional registers from having sysfs entries created. Also, add a macro REG_SUPPORTED which will decide on the check to perform based on the type of register. Signed-off-by: Janakarajan Natarajan --- drivers/acpi/cppc_acpi.c | 100 +++++++++++++++++++++++++++++++++------ 1 file changed, 86 insertions(+), 14 deletions(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 56a09e057c4f..37157d19d2df 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -187,22 +187,8 @@ static ssize_t show_feedback_ctrs(struct kobject *kobj, } define_one_cppc_ro(feedback_ctrs); -static struct attribute *cppc_attrs[] = { - &feedback_ctrs.attr, - &reference_perf.attr, - &wraparound_time.attr, - &highest_perf.attr, - &lowest_perf.attr, - &lowest_nonlinear_perf.attr, - &nominal_perf.attr, - &nominal_freq.attr, - &lowest_freq.attr, - NULL -}; - static struct kobj_type cppc_ktype = { .sysfs_ops = &kobj_sysfs_ops, - .default_attrs = cppc_attrs, }; static int check_pcc_chan(int pcc_ss_id, bool chk_err_bit) @@ -717,6 +703,87 @@ static bool is_cppc_supported(int revision, int num_ent) * } */ +static bool is_buf_only(int reg_idx) +{ + switch (reg_idx) { + case HIGHEST_PERF: + case NOMINAL_PERF: + case LOW_NON_LINEAR_PERF: + case LOWEST_PERF: + case CTR_WRAP_TIME: + case AUTO_SEL_ENABLE: + case REFERENCE_PERF: + return false; + default: + return true; + } +} + +#define REG_SUPPORTED(cpc, idx) (is_buf_only(idx) ? \ + CPC_SUP_BUFFER_ONLY(&cpc->cpc_regs[idx]) : \ + CPC_SUPPORTED(&cpc->cpc_regs[idx])) + +static int is_mandatory_reg(int reg_idx) +{ + switch (reg_idx) { + case HIGHEST_PERF: + case NOMINAL_PERF: + case LOW_NON_LINEAR_PERF: + case LOWEST_PERF: + case REFERENCE_CTR: + case DELIVERED_CTR: + return 1; + } + + return 0; +} + +#define MANDATORY_REG_CNT 6 + +static int set_cppc_attrs(struct cpc_desc *cpc, int entries) +{ + int i, attr_i = 0, opt_reg_cnt = entries - MANDATORY_REG_CNT; + static struct attribute **cppc_attrs; + + cppc_attrs = kcalloc(entries, sizeof(*cppc_attrs), GFP_KERNEL); + if (!cppc_attrs) + return -ENOMEM; + + for (i = 0; i < MAX_CPC_REG_ENT && attr_i < opt_reg_cnt; i++) { + if (is_mandatory_reg(i) || !REG_SUPPORTED(cpc, i)) + continue; + + switch (i) { + case NOMINAL_FREQ: + cppc_attrs[attr_i++] = &nominal_freq.attr; + break; + case LOWEST_FREQ: + cppc_attrs[attr_i++] = &lowest_freq.attr; + break; + case REFERENCE_PERF: + cppc_attrs[attr_i++] = &reference_perf.attr; + break; + case CTR_WRAP_TIME: + cppc_attrs[attr_i++] = &wraparound_time.attr; + break; + } + } + + /* Set mandatory regs */ + cppc_attrs[attr_i++] = &highest_perf.attr; + cppc_attrs[attr_i++] = &nominal_perf.attr; + cppc_attrs[attr_i++] = &lowest_nonlinear_perf.attr; + cppc_attrs[attr_i++] = &lowest_perf.attr; + + /* Set feedback_ctr sysfs entry */ + cppc_attrs[attr_i] = &feedback_ctrs.attr; + + /* Set kobj_type member */ + cppc_ktype.default_attrs = cppc_attrs; + + return 0; +} + /** * acpi_cppc_processor_probe - Search for per CPU _CPC objects. * @pr: Ptr to acpi_processor containing this CPUs logical Id. @@ -871,6 +938,10 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) /* Plug PSD data into this CPUs CPC descriptor. */ per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr; + ret = set_cppc_attrs(cpc_ptr, num_ent - 2); + if (ret) + goto out_free; + ret = kobject_init_and_add(&cpc_ptr->kobj, &cppc_ktype, &cpu_dev->kobj, "acpi_cppc"); if (ret) { @@ -932,6 +1003,7 @@ void acpi_cppc_processor_exit(struct acpi_processor *pr) iounmap(addr); } + kfree(cppc_ktype.default_attrs); kobject_put(&cpc_ptr->kobj); kfree(cpc_ptr); }