2023-07-31 09:09:34

by LeoLiu-oc

[permalink] [raw]
Subject: [PATCH v2 0/2] Add Zhaoxin HW RNG support

From: leoliu-oc <[email protected]>

Implemented Zhaoxin rng driver to add support for Zhaoxin HW RNG.
Both Zhaoxin-rng and via-rng rely on the XSTORE feature,
but the actual implementation is different. So add Vendor ID/Family
restrictions in via-rng module.

v1->v2:
* Modify via-rng in a separate patch.
* Fix some formatting issues.

leoliu-oc (2):
hwrng: via-rng: convert to x86_cpu_id probing
hwrng: add Zhaoxin HW RNG driver

drivers/char/hw_random/Kconfig | 13 +++++
drivers/char/hw_random/Makefile | 1 +
drivers/char/hw_random/via-rng.c | 15 +++--
drivers/char/hw_random/zhaoxin-rng.c | 87 ++++++++++++++++++++++++++++
4 files changed, 108 insertions(+), 8 deletions(-)
create mode 100644 drivers/char/hw_random/zhaoxin-rng.c

--
2.34.1



2023-07-31 09:09:57

by LeoLiu-oc

[permalink] [raw]
Subject: [PATCH v2 1/2] hwrng: via-rng: convert to x86_cpu_id probing

From: leoliu-oc <[email protected]>

With this, In addition to the Feature matching check,
add the CPU Vendor ID/Family check.

Signed-off-by: leoliu-oc <[email protected]>
---
drivers/char/hw_random/via-rng.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
index a9a0a3b09c8b..d7feb3923819 100644
--- a/drivers/char/hw_random/via-rng.c
+++ b/drivers/char/hw_random/via-rng.c
@@ -135,7 +135,7 @@ static int via_rng_init(struct hwrng *rng)
* is always enabled if CPUID rng_en is set. There is no
* RNG configuration like it used to be the case in this
* register */
- if (((c->x86 == 6) && (c->x86_model >= 0x0f)) || (c->x86 > 6)){
+ if (((c->x86 == 6) && (c->x86_model >= 0x0f))) {
if (!boot_cpu_has(X86_FEATURE_XSTORE_EN)) {
pr_err(PFX "can't enable hardware RNG "
"if XSTORE is not enabled\n");
@@ -191,12 +191,17 @@ static struct hwrng via_rng = {
.data_read = via_rng_data_read,
};

+static const struct x86_cpu_id via_rng_cpu_ids[] = {
+ X86_MATCH_VENDOR_FAM_FEATURE(CENTAUR, 6, X86_FEATURE_XSTORE, NULL),
+ {}
+};
+MODULE_DEVICE_TABLE(x86cpu, via_rng_cpu_ids);

static int __init via_rng_mod_init(void)
{
int err;

- if (!boot_cpu_has(X86_FEATURE_XSTORE))
+ if (!x86_match_cpu(via_rng_cpu_ids))
return -ENODEV;

pr_info("VIA RNG detected\n");
@@ -217,11 +222,5 @@ static void __exit via_rng_mod_exit(void)
}
module_exit(via_rng_mod_exit);

-static struct x86_cpu_id __maybe_unused via_rng_cpu_id[] = {
- X86_MATCH_FEATURE(X86_FEATURE_XSTORE, NULL),
- {}
-};
-MODULE_DEVICE_TABLE(x86cpu, via_rng_cpu_id);
-
MODULE_DESCRIPTION("H/W RNG driver for VIA CPU with PadLock");
MODULE_LICENSE("GPL");
--
2.34.1