lkml.org 
[lkml]   [2020]   [Oct]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 4/6] fpga: m10bmc-sec: expose max10 canceled keys in sysfs
Date
Extend the MAX10 BMC Security Engine driver to provide a
handler to expose the canceled code signing key (CSK) bit
vectors in sysfs. These use the standard bitmap list format
(e.g. 1,2-6,9).

Signed-off-by: Russ Weight <russell.h.weight@intel.com>
---
v2:
- Replaced small function-creation macros for explicit function
declarations.
- Fixed get_csk_vector() function to properly apply the stride
variable in calls to m10bmc_raw_bulk_read()
- Added m10bmc_ prefix to functions in m10bmc_iops structure
---
drivers/fpga/intel-m10-bmc-secure.c | 72 +++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)

diff --git a/drivers/fpga/intel-m10-bmc-secure.c b/drivers/fpga/intel-m10-bmc-secure.c
index da61cfda3c50..5bb45499b332 100644
--- a/drivers/fpga/intel-m10-bmc-secure.c
+++ b/drivers/fpga/intel-m10-bmc-secure.c
@@ -135,14 +135,86 @@ static int m10bmc_user_flash_count(struct ifpga_sec_mgr *imgr)
return ret;
}

+#define CSK_BIT_LEN 128U
+#define CSK_32ARRAY_SIZE(_nbits) DIV_ROUND_UP(_nbits, 32)
+
+static int m10bmc_csk_cancel_nbits(struct ifpga_sec_mgr *imgr)
+{
+ return (int)CSK_BIT_LEN;
+}
+
+static int get_csk_vector(struct ifpga_sec_mgr *imgr, u32 addr,
+ unsigned long *csk_map, unsigned int nbits)
+{
+ unsigned int i, size, arr_size = CSK_32ARRAY_SIZE(nbits);
+ struct m10bmc_sec *sec = imgr->priv;
+ unsigned int stride;
+ u32 *csk32;
+ int ret;
+
+ stride = regmap_get_reg_stride(sec->m10bmc->regmap);
+ size = arr_size * sizeof(u32);
+ csk32 = vmalloc(size);
+ if (!csk32)
+ return -ENOMEM;
+
+ ret = m10bmc_raw_bulk_read(sec->m10bmc, addr, csk32, size / stride);
+ if (ret) {
+ dev_err(sec->dev, "%s failed to read %d\n", __func__, ret);
+ goto vfree_exit;
+ }
+
+ for (i = 0; i < arr_size; i++)
+ csk32[i] = le32_to_cpu(csk32[i]);
+
+ bitmap_from_arr32(csk_map, csk32, nbits);
+ bitmap_complement(csk_map, csk_map, nbits);
+
+vfree_exit:
+ vfree(csk32);
+ return ret;
+}
+
+#define CSK_VEC_OFFSET 0x34
+
+static int m10bmc_bmc_canceled_csks(struct ifpga_sec_mgr *imgr,
+ unsigned long *csk_map,
+ unsigned int nbits)
+{
+ return get_csk_vector(imgr, BMC_PROG_ADDR + CSK_VEC_OFFSET,
+ csk_map, nbits);
+}
+
+static int m10bmc_sr_canceled_csks(struct ifpga_sec_mgr *imgr,
+ unsigned long *csk_map,
+ unsigned int nbits)
+{
+ return get_csk_vector(imgr, SR_PROG_ADDR + CSK_VEC_OFFSET,
+ csk_map, nbits);
+}
+
+static int m10bmc_pr_canceled_csks(struct ifpga_sec_mgr *imgr,
+ unsigned long *csk_map,
+ unsigned int nbits)
+{
+ return get_csk_vector(imgr, PR_PROG_ADDR + CSK_VEC_OFFSET,
+ csk_map, nbits);
+}
+
static const struct ifpga_sec_mgr_ops m10bmc_iops = {
.user_flash_count = m10bmc_user_flash_count,
.bmc_root_entry_hash = m10bmc_bmc_root_entry_hash,
.sr_root_entry_hash = m10bmc_sr_root_entry_hash,
.pr_root_entry_hash = m10bmc_pr_root_entry_hash,
+ .bmc_canceled_csks = m10bmc_bmc_canceled_csks,
+ .sr_canceled_csks = m10bmc_sr_canceled_csks,
+ .pr_canceled_csks = m10bmc_pr_canceled_csks,
.bmc_reh_size = m10bmc_bmc_reh_size,
.sr_reh_size = m10bmc_sr_reh_size,
.pr_reh_size = m10bmc_pr_reh_size,
+ .bmc_canceled_csk_nbits = m10bmc_csk_cancel_nbits,
+ .sr_canceled_csk_nbits = m10bmc_csk_cancel_nbits,
+ .pr_canceled_csk_nbits = m10bmc_csk_cancel_nbits,
};

static int m10bmc_secure_probe(struct platform_device *pdev)
--
2.17.1
\
 
 \ /
  Last update: 2020-10-03 03:24    [W:0.206 / U:0.660 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site