From patchwork Mon Oct 19 13:00:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suzuki K Poulose X-Patchwork-Id: 55226 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id 71EB322EA2 for ; Mon, 19 Oct 2015 13:02:30 +0000 (UTC) Received: by wikv3 with SMTP id v3sf1009339wik.1 for ; Mon, 19 Oct 2015 06:02:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:content-type :content-transfer-encoding:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=t7WzzWnVEVvM230HsO9uO01sNsXhH/qht1ALFflnLrU=; b=kTMS+B2RSu73YyPv5ax7Ro3fRQ9e98L8gGhW5Ahyio8x8HjXa22ZGeo30SLU9Q8ein qRI5yD/t+mo28/BpNxOOW4pbJxMM9ewtNGGzLs/K5uCaZDBrokp/nstcy3bzd3Rg1z9g HnB5WZY0t2ywbqtipGiqr6p6jVTuZT7T4O2auukZFaGDl0aHGuNiHRT9CQ8JNaNYP4/d q+ZXW1uztqvwvPrBoK6Qn0JUlHSNK+7Zmd6obIfUkcdxpRTev3VveUP4ot8qdgkfY2jC UC1yFnWRShaVzrkUw/1pk62TZeK/7BXKotfWx4uCxvcIwEKOSeDWC1W1vSj3swtIsynW d18A== X-Gm-Message-State: ALoCoQl+mz9jcek6cb5FSo/c2ATrdIuyCftrNhTPpZ4CgaBtg7iClLeiWv5YBgNh+K4C3xhRSLAS X-Received: by 10.180.79.68 with SMTP id h4mr686818wix.6.1445259749753; Mon, 19 Oct 2015 06:02:29 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.82.3 with SMTP id g3ls584678lfb.10.gmail; Mon, 19 Oct 2015 06:02:29 -0700 (PDT) X-Received: by 10.112.184.137 with SMTP id eu9mr14543953lbc.21.1445259749456; Mon, 19 Oct 2015 06:02:29 -0700 (PDT) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id z9si22763070lbu.161.2015.10.19.06.02.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2015 06:02:29 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by lffz202 with SMTP id z202so28631140lff.3 for ; Mon, 19 Oct 2015 06:02:29 -0700 (PDT) X-Received: by 10.25.19.97 with SMTP id j94mr9842537lfi.106.1445259749009; Mon, 19 Oct 2015 06:02:29 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1458166lbq; Mon, 19 Oct 2015 06:02:27 -0700 (PDT) X-Received: by 10.69.17.1 with SMTP id ga1mr34116001pbd.163.1445259747708; Mon, 19 Oct 2015 06:02:27 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xo9si52560352pab.125.2015.10.19.06.02.27; Mon, 19 Oct 2015 06:02:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932266AbbJSNCK (ORCPT + 28 others); Mon, 19 Oct 2015 09:02:10 -0400 Received: from eu-smtp-delivery-143.mimecast.com ([207.82.80.143]:37185 "EHLO eu-smtp-delivery-143.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752837AbbJSNCE (ORCPT ); Mon, 19 Oct 2015 09:02:04 -0400 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-27--dUwQ5lRS6mtYHZ1io5GcA-13; Mon, 19 Oct 2015 14:01:02 +0100 Received: from e106634-lin.cambridge.arm.com ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 19 Oct 2015 14:00:54 +0100 From: "Suzuki K. Poulose" To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will.deacon@arm.com, mark.rutland@arm.com, chirstoffer.dall@linaro.org, steve.capper@linaro.org, Vladimir.Murzin@arm.com, james.morse@arm.com, andre.przywara@arm.com, ryan.arnold@linaro.org, aph@redhat.com, edward.nevill@linaro.org, dave.martin@arm.com, ard.biesheuvel@linaro.org, marc.zyngier@arm.com, "Suzuki K. Poulose" Subject: [PATCHv4 24/24] arm64: cpuinfo: Expose MIDR_EL1 and REVIDR_EL1 to sysfs Date: Mon, 19 Oct 2015 14:00:47 +0100 Message-Id: <1445259647-21541-25-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1445259647-21541-1-git-send-email-suzuki.poulose@arm.com> References: <1445259647-21541-1-git-send-email-suzuki.poulose@arm.com> X-OriginalArrivalTime: 19 Oct 2015 13:00:54.0003 (UTC) FILETIME=[30183C30:01D10A6E] X-MC-Unique: -dUwQ5lRS6mtYHZ1io5GcA-13 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linux-kernel-owner@vger.kernel.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Steve Capper It can be useful for JIT software to be aware of MIDR_EL1 and REVIDR_EL1 to ascertain the presence of any core errata that could affect codegen. This patch exposes these registers through sysfs: /sys/devices/system/cpu/cpu$ID/identification/midr /sys/devices/system/cpu/cpu$ID/identification/revidr where $ID is the cpu number. For big.LITTLE systems, one can have a mixture of cores (e.g. Cortex A53 and Cortex A57), thus all CPUs need to be enumerated. If the kernel does not have valid information to populate these entries with, an empty string is returned to userspace. Signed-off-by: Steve Capper [ Return error for access to !present CPU registers ] Signed-off-by: Suzuki K. Poulose --- arch/arm64/include/asm/cpu.h | 1 + arch/arm64/kernel/cpuinfo.c | 69 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/arch/arm64/include/asm/cpu.h b/arch/arm64/include/asm/cpu.h index b5e9cee..bb1b0cf 100644 --- a/arch/arm64/include/asm/cpu.h +++ b/arch/arm64/include/asm/cpu.h @@ -29,6 +29,7 @@ struct cpuinfo_arm64 { u32 reg_cntfrq; u32 reg_dczid; u32 reg_midr; + u32 reg_revidr; u64 reg_id_aa64dfr0; u64 reg_id_aa64dfr1; diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c index 52331ff..349ebf7 100644 --- a/arch/arm64/kernel/cpuinfo.c +++ b/arch/arm64/kernel/cpuinfo.c @@ -199,6 +199,7 @@ static void __cpuinfo_store_cpu(struct cpuinfo_arm64 *info) info->reg_ctr = read_cpuid_cachetype(); info->reg_dczid = read_cpuid(DCZID_EL0); info->reg_midr = read_cpuid_id(); + info->reg_revidr = read_cpuid(REVIDR_EL1); info->reg_id_aa64dfr0 = read_cpuid(ID_AA64DFR0_EL1); info->reg_id_aa64dfr1 = read_cpuid(ID_AA64DFR1_EL1); @@ -247,3 +248,71 @@ void __init cpuinfo_store_boot_cpu(void) boot_cpu_data = *info; init_cpu_features(&boot_cpu_data); } + +#define CPUINFO_ATTR_RO(_name) \ + static ssize_t show_##_name (struct device *dev, \ + struct device_attribute *attr, char *buf) \ + { \ + struct cpuinfo_arm64 *info = &per_cpu(cpu_data, dev->id); \ + if (!cpu_present(dev->id)) \ + return -ENODEV; \ + \ + if (info->reg_midr) \ + return sprintf(buf, "0x%016x\n", info->reg_##_name); \ + else \ + return 0; \ + } \ + static DEVICE_ATTR(_name, 0444, show_##_name, NULL) + +CPUINFO_ATTR_RO(midr); +CPUINFO_ATTR_RO(revidr); + +static struct attribute *cpuregs_attrs[] = { + &dev_attr_midr.attr, + &dev_attr_revidr.attr, + NULL +}; + +static struct attribute_group cpuregs_attr_group = { + .attrs = cpuregs_attrs, + .name = "identification" +}; + +static int __init cpuinfo_regs_init(void) +{ + int cpu, finalcpu, ret; + struct device *dev; + + for_each_present_cpu(cpu) { + dev = get_cpu_device(cpu); + + if (!dev) { + ret = -ENODEV; + break; + } + + ret = sysfs_create_group(&dev->kobj, &cpuregs_attr_group); + if (ret) + break; + } + + if (!ret) + return 0; + /* + * We were unable to put down sysfs groups for all the CPUs, revert + * all the groups we have placed down s.t. none are visible. + * Otherwise we could give a misleading picture of what's present. + */ + finalcpu = cpu; + for_each_present_cpu(cpu) { + if (cpu == finalcpu) + break; + dev = get_cpu_device(cpu); + if (dev) + sysfs_remove_group(&dev->kobj, &cpuregs_attr_group); + } + + return ret; +} + +device_initcall(cpuinfo_regs_init);