| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* |
| 3 |
* Copyright IBM Corp. 2024 |
| 4 |
*/ |
| 5 |
|
| 6 |
#define pr_fmt(fmt) "cpacf: " fmt |
| 7 |
|
| 8 |
#include <linux/cpu.h> |
| 9 |
#include <linux/device.h> |
| 10 |
#include <linux/sysfs.h> |
| 11 |
#include <asm/cpacf.h> |
| 12 |
|
| 13 |
#define CPACF_QUERY(name, instruction) \ |
| 14 |
static ssize_t name##_query_raw_read(struct file *fp, \ |
| 15 |
struct kobject *kobj, \ |
| 16 |
const struct bin_attribute *attr, \ |
| 17 |
char *buf, loff_t offs, \ |
| 18 |
size_t count) \ |
| 19 |
{ \ |
| 20 |
cpacf_mask_t mask; \ |
| 21 |
\ |
| 22 |
if (!cpacf_query(CPACF_##instruction, &mask)) \ |
| 23 |
return -EOPNOTSUPP; \ |
| 24 |
return memory_read_from_buffer(buf, count, &offs, &mask, sizeof(mask)); \ |
| 25 |
} \ |
| 26 |
static const BIN_ATTR_RO(name##_query_raw, sizeof(cpacf_mask_t)) |
| 27 |
|
| 28 |
CPACF_QUERY(km, KM); |
| 29 |
CPACF_QUERY(kmc, KMC); |
| 30 |
CPACF_QUERY(kimd, KIMD); |
| 31 |
CPACF_QUERY(klmd, KLMD); |
| 32 |
CPACF_QUERY(kmac, KMAC); |
| 33 |
CPACF_QUERY(pckmo, PCKMO); |
| 34 |
CPACF_QUERY(kmf, KMF); |
| 35 |
CPACF_QUERY(kmctr, KMCTR); |
| 36 |
CPACF_QUERY(kmo, KMO); |
| 37 |
CPACF_QUERY(pcc, PCC); |
| 38 |
CPACF_QUERY(prno, PRNO); |
| 39 |
CPACF_QUERY(kma, KMA); |
| 40 |
CPACF_QUERY(kdsa, KDSA); |
| 41 |
|
| 42 |
#define CPACF_QAI(name, instruction) \ |
| 43 |
static ssize_t name##_query_auth_info_raw_read( \ |
| 44 |
struct file *fp, struct kobject *kobj, \ |
| 45 |
const struct bin_attribute *attr, char *buf, loff_t offs, \ |
| 46 |
size_t count) \ |
| 47 |
{ \ |
| 48 |
cpacf_qai_t qai; \ |
| 49 |
\ |
| 50 |
if (!cpacf_qai(CPACF_##instruction, &qai)) \ |
| 51 |
return -EOPNOTSUPP; \ |
| 52 |
return memory_read_from_buffer(buf, count, &offs, &qai, \ |
| 53 |
sizeof(qai)); \ |
| 54 |
} \ |
| 55 |
static const BIN_ATTR_RO(name##_query_auth_info_raw, sizeof(cpacf_qai_t)) |
| 56 |
|
| 57 |
CPACF_QAI(km, KM); |
| 58 |
CPACF_QAI(kmc, KMC); |
| 59 |
CPACF_QAI(kimd, KIMD); |
| 60 |
CPACF_QAI(klmd, KLMD); |
| 61 |
CPACF_QAI(kmac, KMAC); |
| 62 |
CPACF_QAI(pckmo, PCKMO); |
| 63 |
CPACF_QAI(kmf, KMF); |
| 64 |
CPACF_QAI(kmctr, KMCTR); |
| 65 |
CPACF_QAI(kmo, KMO); |
| 66 |
CPACF_QAI(pcc, PCC); |
| 67 |
CPACF_QAI(prno, PRNO); |
| 68 |
CPACF_QAI(kma, KMA); |
| 69 |
CPACF_QAI(kdsa, KDSA); |
| 70 |
|
| 71 |
static const struct bin_attribute *const cpacf_attrs[] = { |
| 72 |
&bin_attr_km_query_raw, |
| 73 |
&bin_attr_kmc_query_raw, |
| 74 |
&bin_attr_kimd_query_raw, |
| 75 |
&bin_attr_klmd_query_raw, |
| 76 |
&bin_attr_kmac_query_raw, |
| 77 |
&bin_attr_pckmo_query_raw, |
| 78 |
&bin_attr_kmf_query_raw, |
| 79 |
&bin_attr_kmctr_query_raw, |
| 80 |
&bin_attr_kmo_query_raw, |
| 81 |
&bin_attr_pcc_query_raw, |
| 82 |
&bin_attr_prno_query_raw, |
| 83 |
&bin_attr_kma_query_raw, |
| 84 |
&bin_attr_kdsa_query_raw, |
| 85 |
&bin_attr_km_query_auth_info_raw, |
| 86 |
&bin_attr_kmc_query_auth_info_raw, |
| 87 |
&bin_attr_kimd_query_auth_info_raw, |
| 88 |
&bin_attr_klmd_query_auth_info_raw, |
| 89 |
&bin_attr_kmac_query_auth_info_raw, |
| 90 |
&bin_attr_pckmo_query_auth_info_raw, |
| 91 |
&bin_attr_kmf_query_auth_info_raw, |
| 92 |
&bin_attr_kmctr_query_auth_info_raw, |
| 93 |
&bin_attr_kmo_query_auth_info_raw, |
| 94 |
&bin_attr_pcc_query_auth_info_raw, |
| 95 |
&bin_attr_prno_query_auth_info_raw, |
| 96 |
&bin_attr_kma_query_auth_info_raw, |
| 97 |
&bin_attr_kdsa_query_auth_info_raw, |
| 98 |
NULL, |
| 99 |
}; |
| 100 |
|
| 101 |
static const struct attribute_group cpacf_attr_grp = { |
| 102 |
.name = "cpacf", |
| 103 |
.bin_attrs = cpacf_attrs, |
| 104 |
}; |
| 105 |
|
| 106 |
static int __init cpacf_init(void) |
| 107 |
{ |
| 108 |
struct device *cpu_root; |
| 109 |
int rc = 0; |
| 110 |
|
| 111 |
cpu_root = bus_get_dev_root(&cpu_subsys); |
| 112 |
if (cpu_root) { |
| 113 |
rc = sysfs_create_group(&cpu_root->kobj, &cpacf_attr_grp); |
| 114 |
put_device(cpu_root); |
| 115 |
} |
| 116 |
return rc; |
| 117 |
} |
| 118 |
device_initcall(cpacf_init); |