From patchwork Fri Jul 24 15:02:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 6860961 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3E3CA9F358 for ; Fri, 24 Jul 2015 15:05:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4F377205E5 for ; Fri, 24 Jul 2015 15:05:49 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6964C204FC for ; Fri, 24 Jul 2015 15:05:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZIeVN-0000yB-23; Fri, 24 Jul 2015 15:03:21 +0000 Received: from mail-wi0-f178.google.com ([209.85.212.178]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZIeVJ-0000jR-BC for linux-arm-kernel@lists.infradead.org; Fri, 24 Jul 2015 15:03:18 +0000 Received: by wibud3 with SMTP id ud3so68985742wib.1 for ; Fri, 24 Jul 2015 08:02:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=X8G6K3IIDOr6mfc4GQwrdQRA8WsDJ8RzjWX6cqCSo14=; b=cYJtw59eBLwG7nyLcLF80C+j161J5NsEUfTafrpx/Tpx8+/1ZNeIJ32k5vmFxGgdnm ckm9nyPg8/l+RbVAQfYJRJLwDLmfPfuQS8uhRDQtF4gr4y8+8hPgMGGg3UMjp/kG4mHh 6D9uTaDoMdGZEyEIyCiWHltH1XayNFnAWfbb2KNYemqx/N+9M2a+YxJbDUxpWpmJLIdZ aZ0Zk5LfmNduwEWecNiZjPIqNDXpAbTyGlPf5C/OfbVN3seo6tP3Gk4igcMxRLIt4pbb Az74n8tBrD6mjoXdJQFWyaoW89po9Ij0Tz3mGfAfIUjlDVPBfjnj1DIMBjDrjwwvVwau EJtA== X-Gm-Message-State: ALoCoQmP27JNqZaDaQCZIagwcYuk4WqmRgYhWofp05U4uPcWoZ0KtFY6NdUD4b4Ha6JuWY4yn87p X-Received: by 10.180.19.102 with SMTP id d6mr8019912wie.86.1437750174238; Fri, 24 Jul 2015 08:02:54 -0700 (PDT) Received: from marmot.wormnet.eu (marmot.wormnet.eu. [188.246.204.87]) by smtp.gmail.com with ESMTPSA id ez4sm3936834wid.14.2015.07.24.08.02.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Jul 2015 08:02:53 -0700 (PDT) From: Steve Capper To: linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH] arm64: cpuinfo: Expose MIDR_EL1 and REVIDR_EL1 to sysfs Date: Fri, 24 Jul 2015 16:02:37 +0100 Message-Id: <1437750157-25238-1-git-send-email-steve.capper@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150724_080317_571604_81D39007 X-CRM114-Status: GOOD ( 15.30 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, Steve Capper , suzuki.poulose@arm.com, aph@redhat.com, catalin.marinas@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, edward.nevill@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- Hello, This RFC is meant to sit on top of Suzuki's set at: http://lists.infradead.org/pipermail/linux-arm-kernel/2015-July/358990.html On systems with different core types (for instance big.LITTLE systems), we need to be *very* careful that the REVIDR and MIDR are both read from the same core. Thus these registers are exposed in /sys rather than via MRS emulation. Cheers, diff --git a/arch/arm64/include/asm/cpu.h b/arch/arm64/include/asm/cpu.h index 17a871d..048b7bf 100644 --- a/arch/arm64/include/asm/cpu.h +++ b/arch/arm64/include/asm/cpu.h @@ -187,6 +187,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 678e7f6..d50eda1 100644 --- a/arch/arm64/kernel/cpuinfo.c +++ b/arch/arm64/kernel/cpuinfo.c @@ -533,6 +533,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); @@ -886,3 +887,50 @@ int __init arm64_cpuinfo_init(void) } late_initcall(arm64_cpuinfo_init); + +#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 (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, ret; + + for_each_present_cpu(cpu) { + struct device *dev = get_cpu_device(cpu); + + if (!dev) + return -1; + + ret = sysfs_create_group(&dev->kobj, &cpuregs_attr_group); + if (ret) + return ret; + } + + return 0; +} + +device_initcall(cpuinfo_regs_init);