From: ard.biesheuvel@linaro.org (Ard Biesheuvel)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 2/4] cpu: advertise CPU features over udev in a generic way
Date: Thu, 7 Nov 2013 18:17:35 +0100 [thread overview]
Message-ID: <1383844657-17487-3-git-send-email-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <1383844657-17487-1-git-send-email-ard.biesheuvel@linaro.org>
This patch implements a generic modalias 'cpu:feature:...' which
enables CPU feature flag based module loading in a generic way.
All the arch needs to do is enable CONFIG_ARCH_HAS_CPU_AUTOPROBE
and export a u32 called 'cpu_features'. (What each bit actually
means is irrelevant on this level.)
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
drivers/base/cpu.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 49c6f4b..a661d31 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -276,6 +276,30 @@ static void cpu_device_release(struct device *dev)
}
#ifdef CONFIG_ARCH_HAS_CPU_AUTOPROBE
+ssize_t print_cpu_modalias(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ extern u32 __weak cpu_features;
+ ssize_t n;
+ int i;
+ u32 f;
+
+ /*
+ * With 32 features maximum (taking 3 bytes each to print), we don't
+ * need to worry about overrunning the PAGE_SIZE sized buffer.
+ */
+ n = sprintf(buf, "cpu:feature:");
+ for (f = cpu_features, i = 0; f; f >>= 1, i++)
+ if (f & 1)
+ n += sprintf(&buf[n], ",%02X", i);
+ buf[n++] = '\n';
+ return n;
+}
+
+ssize_t __attribute__((weak, alias("print_cpu_modalias")))
+arch_print_cpu_modalias(struct device *, struct device_attribute *, char *);
+
static int cpu_uevent(struct device *dev, struct kobj_uevent_env *env)
{
char *buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
--
1.8.3.2
next prev parent reply other threads:[~2013-11-07 17:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-07 17:17 [RFC PATCH 0/4] wire up CPU features to udev based module loading Ard Biesheuvel
2013-11-07 17:17 ` [RFC PATCH 1/4] x86: move arch_cpu_uevent() to generic code Ard Biesheuvel
2013-11-07 17:17 ` Ard Biesheuvel [this message]
2013-11-07 19:33 ` [RFC PATCH 2/4] cpu: advertise CPU features over udev in a generic way Dave Martin
2013-11-07 20:00 ` Ard Biesheuvel
2013-11-07 20:55 ` Ard Biesheuvel
2013-11-07 17:17 ` [RFC PATCH 3/4] scripts/mod: add generic CPU features as module alias Ard Biesheuvel
2013-11-07 17:17 ` [RFC PATCH 4/4] arm64: advertise CPU features using module aliases Ard Biesheuvel
2013-11-07 21:09 ` [RFC PATCH 0/4] wire up CPU features to udev based module loading H. Peter Anvin
2013-11-07 21:39 ` Andi Kleen
2013-11-07 22:15 ` Ard Biesheuvel
2013-11-07 22:30 ` Andi Kleen
2013-11-08 15:09 ` H. Peter Anvin
2013-11-07 22:49 ` H. Peter Anvin
2013-11-08 10:20 ` Ard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1383844657-17487-3-git-send-email-ard.biesheuvel@linaro.org \
--to=ard.biesheuvel@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).