|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
| 2 | +/* |
| 3 | + * Copyright (C) 2025 IBM Corporation, Srish Srinivasan <ssrish@linux.ibm.com> |
| 4 | + * |
| 5 | + * This code exposes PLPKS config to user via sysfs |
| 6 | + */ |
| 7 | + |
| 8 | +#define pr_fmt(fmt) "plpks-sysfs: "fmt |
| 9 | + |
| 10 | +#include <linux/init.h> |
| 11 | +#include <linux/printk.h> |
| 12 | +#include <linux/types.h> |
| 13 | +#include <asm/machdep.h> |
| 14 | +#include <asm/plpks.h> |
| 15 | + |
| 16 | +/* config attributes for sysfs */ |
| 17 | +#define PLPKS_CONFIG_ATTR(name, fmt, func) \ |
| 18 | + static ssize_t name##_show(struct kobject *kobj, \ |
| 19 | + struct kobj_attribute *attr, \ |
| 20 | + char *buf) \ |
| 21 | + { \ |
| 22 | + return sysfs_emit(buf, fmt, func()); \ |
| 23 | + } \ |
| 24 | + static struct kobj_attribute attr_##name = __ATTR_RO(name) |
| 25 | + |
| 26 | +PLPKS_CONFIG_ATTR(version, "%u\n", plpks_get_version); |
| 27 | +PLPKS_CONFIG_ATTR(max_object_size, "%u\n", plpks_get_maxobjectsize); |
| 28 | +PLPKS_CONFIG_ATTR(total_size, "%u\n", plpks_get_totalsize); |
| 29 | +PLPKS_CONFIG_ATTR(used_space, "%u\n", plpks_get_usedspace); |
| 30 | +PLPKS_CONFIG_ATTR(supported_policies, "%08x\n", plpks_get_supportedpolicies); |
| 31 | +PLPKS_CONFIG_ATTR(signed_update_algorithms, "%016llx\n", |
| 32 | + plpks_get_signedupdatealgorithms); |
| 33 | + |
| 34 | +static const struct attribute *config_attrs[] = { |
| 35 | + &attr_version.attr, |
| 36 | + &attr_max_object_size.attr, |
| 37 | + &attr_total_size.attr, |
| 38 | + &attr_used_space.attr, |
| 39 | + &attr_supported_policies.attr, |
| 40 | + &attr_signed_update_algorithms.attr, |
| 41 | + NULL, |
| 42 | +}; |
| 43 | + |
| 44 | +static struct kobject *plpks_kobj, *plpks_config_kobj; |
| 45 | + |
| 46 | +int plpks_config_create_softlink(struct kobject *from) |
| 47 | +{ |
| 48 | + if (!plpks_config_kobj) |
| 49 | + return -EINVAL; |
| 50 | + return sysfs_create_link(from, plpks_config_kobj, "config"); |
| 51 | +} |
| 52 | + |
| 53 | +static __init int plpks_sysfs_config(struct kobject *kobj) |
| 54 | +{ |
| 55 | + struct attribute_group config_group = { |
| 56 | + .name = NULL, |
| 57 | + .attrs = (struct attribute **)config_attrs, |
| 58 | + }; |
| 59 | + |
| 60 | + return sysfs_create_group(kobj, &config_group); |
| 61 | +} |
| 62 | + |
| 63 | +static __init int plpks_sysfs_init(void) |
| 64 | +{ |
| 65 | + int rc; |
| 66 | + |
| 67 | + if (!plpks_is_available()) |
| 68 | + return -ENODEV; |
| 69 | + |
| 70 | + plpks_kobj = kobject_create_and_add("plpks", firmware_kobj); |
| 71 | + if (!plpks_kobj) { |
| 72 | + pr_err("Failed to create plpks kobj\n"); |
| 73 | + return -ENOMEM; |
| 74 | + } |
| 75 | + |
| 76 | + plpks_config_kobj = kobject_create_and_add("config", plpks_kobj); |
| 77 | + if (!plpks_config_kobj) { |
| 78 | + pr_err("Failed to create plpks config kobj\n"); |
| 79 | + kobject_put(plpks_kobj); |
| 80 | + return -ENOMEM; |
| 81 | + } |
| 82 | + |
| 83 | + rc = plpks_sysfs_config(plpks_config_kobj); |
| 84 | + if (rc) { |
| 85 | + pr_err("Failed to create attribute group for plpks config\n"); |
| 86 | + kobject_put(plpks_config_kobj); |
| 87 | + kobject_put(plpks_kobj); |
| 88 | + return rc; |
| 89 | + } |
| 90 | + |
| 91 | + return 0; |
| 92 | +} |
| 93 | + |
| 94 | +machine_subsys_initcall(pseries, plpks_sysfs_init); |
0 commit comments