Commit 54c9fcd1 authored by Jithu Joseph's avatar Jithu Joseph Committed by Hans de Goede

platform/x86/intel/ifs: Reorganize driver data

The struct holding device driver data contained both read only(ro)
and read write(rw) fields.

Separating ro fields from rw fields was recommended as
a preferable design pattern during review[1].

Group ro fields into a separate const struct. Associate it to
the miscdevice being registered by keeping its pointer in the
same container struct as the miscdevice.

Link: https://lore.kernel.org/lkml/Y+9H9otxLYPqMkUh@kroah.com/ [1]
Signed-off-by: default avatarJithu Joseph <jithu.joseph@intel.com>
Reviewed-by: default avatarTony Luck <tony.luck@intel.com>
Link: https://lore.kernel.org/r/20230322003359.213046-3-jithu.joseph@intel.comReviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent 67f88ffa
......@@ -22,11 +22,13 @@ MODULE_DEVICE_TABLE(x86cpu, ifs_cpu_ids);
bool *ifs_pkg_auth;
static struct ifs_device ifs_device = {
.data = {
static const struct ifs_test_caps scan_test = {
.integrity_cap_bit = MSR_INTEGRITY_CAPS_PERIODIC_BIST_BIT,
.test_num = 0,
},
};
static struct ifs_device ifs_device = {
.test_caps = &scan_test,
.misc = {
.name = "intel_ifs_0",
.nodename = "intel_ifs/0",
......@@ -55,7 +57,7 @@ static int __init ifs_init(void)
ifs_device.misc.groups = ifs_get_groups();
if (!(msrval & BIT(ifs_device.data.integrity_cap_bit)))
if (!(msrval & BIT(ifs_device.test_caps->integrity_cap_bit)))
return -ENODEV;
ifs_pkg_auth = kmalloc_array(topology_max_packages(), sizeof(bool), GFP_KERNEL);
......
......@@ -197,9 +197,13 @@ union ifs_status {
#define IFS_SW_TIMEOUT 0xFD
#define IFS_SW_PARTIAL_COMPLETION 0xFE
struct ifs_test_caps {
int integrity_cap_bit;
int test_num;
};
/**
* struct ifs_data - attributes related to intel IFS driver
* @integrity_cap_bit: MSR_INTEGRITY_CAPS bit enumerating this test
* @loaded_version: stores the currently loaded ifs image version.
* @loaded: If a valid test binary has been loaded into the memory
* @loading_error: Error occurred on another CPU while loading image
......@@ -207,10 +211,8 @@ union ifs_status {
* @status: it holds simple status pass/fail/untested
* @scan_details: opaque scan status code from h/w
* @cur_batch: number indicating the currently loaded test file
* @test_num: number indicating the test type
*/
struct ifs_data {
int integrity_cap_bit;
int loaded_version;
bool loaded;
bool loading_error;
......@@ -218,7 +220,6 @@ struct ifs_data {
int status;
u64 scan_details;
u32 cur_batch;
int test_num;
};
struct ifs_work {
......@@ -227,7 +228,8 @@ struct ifs_work {
};
struct ifs_device {
struct ifs_data data;
const struct ifs_test_caps *test_caps;
struct ifs_data rw_data;
struct miscdevice misc;
};
......@@ -236,7 +238,15 @@ static inline struct ifs_data *ifs_get_data(struct device *dev)
struct miscdevice *m = dev_get_drvdata(dev);
struct ifs_device *d = container_of(m, struct ifs_device, misc);
return &d->data;
return &d->rw_data;
}
static inline const struct ifs_test_caps *ifs_get_test_caps(struct device *dev)
{
struct miscdevice *m = dev_get_drvdata(dev);
struct ifs_device *d = container_of(m, struct ifs_device, misc);
return d->test_caps;
}
extern bool *ifs_pkg_auth;
......
......@@ -257,13 +257,14 @@ static int image_sanity_check(struct device *dev, const struct microcode_header_
*/
int ifs_load_firmware(struct device *dev)
{
const struct ifs_test_caps *test = ifs_get_test_caps(dev);
struct ifs_data *ifsd = ifs_get_data(dev);
const struct firmware *fw;
char scan_path[64];
int ret = -EINVAL;
snprintf(scan_path, sizeof(scan_path), "intel/ifs_%d/%02x-%02x-%02x-%02x.scan",
ifsd->test_num, boot_cpu_data.x86, boot_cpu_data.x86_model,
test->test_num, boot_cpu_data.x86, boot_cpu_data.x86_model,
boot_cpu_data.x86_stepping, ifsd->cur_batch);
ret = request_firmware_direct(&fw, scan_path, dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment