platform/x86/amd/pmf: Use struct for cookie header
authorArmin Wolf <W_Armin@gmx.de>
Mon, 4 Mar 2024 20:50:04 +0000 (21:50 +0100)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Tue, 12 Mar 2024 10:48:05 +0000 (12:48 +0200)
The cookie header consists of a sign field and a length field.
Combine both in a single struct to make accesses simpler.

Compile-tested only.

Suggested-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Reviewed-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
Link: https://lore.kernel.org/r/20240304205005.10078-4-W_Armin@gmx.de
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/amd/pmf/pmf.h
drivers/platform/x86/amd/pmf/tee-if.c

index bcf777a5659aa50340d6834503b7a87f69577b33..0c90805dc85bd0206de86c59fea3e5eb7546febe 100644 (file)
 #define POLICY_BUF_MAX_SZ              0x4b000
 #define POLICY_SIGN_COOKIE             0x31535024
 #define POLICY_COOKIE_OFFSET           0x10
-#define POLICY_COOKIE_LEN              0x14
+
+struct cookie_header {
+       u32 sign;
+       u32 length;
+} __packed;
 
 /* APMF Functions */
 #define APMF_FUNC_VERIFY_INTERFACE                     0
index 58ec2c9606e10fb4655d11fa58e577b89dc6a499..71ea7eefc211586ca619154179a21b942cf44f34 100644 (file)
@@ -246,17 +246,16 @@ static void amd_pmf_invoke_cmd(struct work_struct *work)
 
 static int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev)
 {
-       u32 cookie, length;
+       struct cookie_header *header;
        int res;
 
-       cookie = *(u32 *)(dev->policy_buf + POLICY_COOKIE_OFFSET);
-       length = *(u32 *)(dev->policy_buf + POLICY_COOKIE_LEN);
+       header = (struct cookie_header *)(dev->policy_buf + POLICY_COOKIE_OFFSET);
 
-       if (cookie != POLICY_SIGN_COOKIE || !length)
+       if (header->sign != POLICY_SIGN_COOKIE || !header->length)
                return -EINVAL;
 
        /* Update the actual length */
-       dev->policy_sz = length + 512;
+       dev->policy_sz = header->length + 512;
        res = amd_pmf_invoke_cmd_init(dev);
        if (res == TA_PMF_TYPE_SUCCESS) {
                /* Now its safe to announce that smart pc is enabled */