From patchwork Wed Jan 11 17:01:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 9510671 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E5F406075C for ; Wed, 11 Jan 2017 17:03:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E39A9284AE for ; Wed, 11 Jan 2017 17:03:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5090285E1; Wed, 11 Jan 2017 17:03:04 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ED5C6284AE for ; Wed, 11 Jan 2017 17:02:52 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cRMIT-0007Z4-H7; Wed, 11 Jan 2017 17:02:49 +0000 Received: from mail-wj0-x22b.google.com ([2a00:1450:400c:c01::22b]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cRMIP-0007VG-SX for linux-arm-kernel@lists.infradead.org; Wed, 11 Jan 2017 17:02:47 +0000 Received: by mail-wj0-x22b.google.com with SMTP id kq3so61424123wjc.0 for ; Wed, 11 Jan 2017 09:02:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cvSxO0YnJXLU8GfoHkAQ/KLXNz+E/Tx+ozPt63CoWAU=; b=JmMeSirahaPN8tQF90ZWGv+2bzWHYv6NCouvLBhoX8BcyA85NvkVFEvNKMSPwD+3bg 0jPkl/hdh7LjIblwKi67kPkXM59njvjQjALfFlEMruXXkIZCV6tdFvG3fFVJlclYqyFk lKzhnE9wnyLMFvOVJ0Gos5fNGHTW/RUQMEvU8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cvSxO0YnJXLU8GfoHkAQ/KLXNz+E/Tx+ozPt63CoWAU=; b=k3JLLYS8diIyeOsIhAUGFO8YlXyMQAT65/9iHr+0U2p4+FGjc9lJ8XATQnH0Ph7KW9 3lEAfksNItYUPFTelNz4YIVx89vrO26nkvUp+tVYXvnMe7P7Xc5hBK5GJsfNq3aCQNWw wU1Qb+uJMOwnr6cFXknQFLuL9URawRUAbEHeXO+WdfNLfsddiZmEIHi2rcBCyp/iDdU1 f7XYilZrhj4/xsjYOMFfazP9z2yhT30VPGpifhv4F6JJI+ecpUcO7qJpSdY0YaC+ySJH AFu6Q9sdV+Ny32WaO7O5wJB6sTNvtOReR7L49obaa5xpfdQYW4B88cKHERnruUmGV2hs Y0/g== X-Gm-Message-State: AIkVDXKpfQG/lnx5ru/gj013kgPi6Fc43zlLr5T+lvmQlnn7ayT16rcHfUnnPtHAAays2m8o X-Received: by 10.194.146.228 with SMTP id tf4mr5998840wjb.183.1484154145426; Wed, 11 Jan 2017 09:02:25 -0800 (PST) Received: from localhost.localdomain ([160.167.203.25]) by smtp.gmail.com with ESMTPSA id o132sm9873491wmo.17.2017.01.11.09.02.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Jan 2017 09:02:24 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 1/5] ARM: wire up HWCAP2 feature bits to the CPU modalias Date: Wed, 11 Jan 2017 17:01:54 +0000 Message-Id: <1484154118-22139-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484154118-22139-1-git-send-email-ard.biesheuvel@linaro.org> References: <1484154118-22139-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170111_090246_088372_6BE08AF5 X-CRM114-Status: GOOD ( 15.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux@armlinux.org.uk, Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Wire up the generic support for exposing CPU feature bits via the modalias in /sys/device/system/cpu. This allows udev to automatically load modules for things like crypto algorithms that are implemented using optional instructions. Signed-off-by: Ard Biesheuvel --- arch/arm/Kconfig | 1 + arch/arm/include/asm/cpufeature.h | 32 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 5fab553fd03a..3758466365ee 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -21,6 +21,7 @@ config ARM select GENERIC_ALLOCATOR select GENERIC_ATOMIC64 if (CPU_V7M || CPU_V6 || !CPU_32v6K || !AEABI) select GENERIC_CLOCKEVENTS_BROADCAST if SMP + select GENERIC_CPU_AUTOPROBE select GENERIC_EARLY_IOREMAP select GENERIC_IDLE_POLL_SETUP select GENERIC_IRQ_PROBE diff --git a/arch/arm/include/asm/cpufeature.h b/arch/arm/include/asm/cpufeature.h new file mode 100644 index 000000000000..134bd4c63d53 --- /dev/null +++ b/arch/arm/include/asm/cpufeature.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2017 Linaro Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __ASM_CPUFEATURE_H +#define __ASM_CPUFEATURE_H + +#include + +/* + * Due to the fact that ELF_HWCAP is a 32-bit type on ARM, and given the number + * of optional CPU features it defines, ARM's CPU capability bits have been + * distributed over separate elf_hwcap and elf_hwcap2 variables, each of which + * covers a subset of the available CPU features. + * + * Currently, only a few of those are suitable for automatic module loading + * (which is the primary use case of this facility) and those happen to be all + * covered by HWCAP2. So let's only expose those via the CPU modalias for now. + */ +#define MAX_CPU_FEATURES (8 * sizeof(elf_hwcap2)) +#define cpu_feature(x) ilog2(HWCAP2_ ## x) + +static inline bool cpu_have_feature(unsigned int num) +{ + return elf_hwcap2 & (1UL << num); +} + +#endif