Felix Held has submitted this change. ( https://review.coreboot.org/c/coreboot/+/63963 )
Change subject: soc/amd/common/block/psp/psp_gen2: factor out pspv2_mbox_command union ......................................................................
soc/amd/common/block/psp/psp_gen2: factor out pspv2_mbox_command union
The pspv2_mbox struct contained an unnamed union that covered the 32 bits of the command register of the PSP v2 mailbox. Since the pspv2_mbox struct is mainly used for hardware register accesses and the union part is mostly used to access the different bits before/after writing/reading the command register, split this functionality. For the register access a command field is added to the pspv2_mbox struct instead of the unnamed union and for accessing the separate bits of the command register a new named union is added.
Signed-off-by: Felix Held felix-coreboot@felixheld.de Change-Id: If3f00b6fd73c3f749154b77b940e6d5aa385ec49 Reviewed-on: https://review.coreboot.org/c/coreboot/+/63963 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Raul Rangel rrangel@chromium.org --- M src/soc/amd/common/block/psp/psp_gen2.c 1 file changed, 18 insertions(+), 16 deletions(-)
Approvals: build bot (Jenkins): Verified Raul Rangel: Looks good to me, approved
diff --git a/src/soc/amd/common/block/psp/psp_gen2.c b/src/soc/amd/common/block/psp/psp_gen2.c index 6f46d82..cbae7a5 100644 --- a/src/soc/amd/common/block/psp/psp_gen2.c +++ b/src/soc/amd/common/block/psp/psp_gen2.c @@ -13,19 +13,21 @@ #define PSP_MAILBOX_OFFSET 0x10570
struct pspv2_mbox { - union { - u32 val; - struct pspv2_mbox_cmd_fields { - u16 mbox_status; - u8 mbox_command; - u32 reserved:6; - u32 recovery:1; - u32 ready:1; - } __packed fields; - }; + u32 command; u64 buffer; } __packed;
+union pspv2_mbox_command { + u32 val; + struct pspv2_mbox_cmd_fields { + u16 mbox_status; + u8 mbox_command; + u32 reserved:6; + u32 recovery:1; + u32 ready:1; + } __packed fields; +}; + static uintptr_t soc_get_psp_base_address(void) { uintptr_t psp_mmio = rdmsr(PSP_ADDR_MSR).lo; @@ -49,7 +51,7 @@ struct pspv2_mbox_cmd_fields fields; } tmp = { 0 };
- tmp.val = read32(&mbox->val); + tmp.val = read32(&mbox->command); return tmp.fields.mbox_status; }
@@ -62,7 +64,7 @@
/* Write entire 32-bit area to begin command execution */ tmp.fields.mbox_command = cmd; - write32(&mbox->val, tmp.val); + write32(&mbox->command, tmp.val); }
static u8 rd_mbox_recovery(struct pspv2_mbox *mbox) @@ -72,7 +74,7 @@ struct pspv2_mbox_cmd_fields fields; } tmp = { 0 };
- tmp.val = read32(&mbox->val); + tmp.val = read32(&mbox->command); return !!tmp.fields.recovery; }
@@ -83,8 +85,8 @@
static int wait_command(struct pspv2_mbox *mbox, bool wait_for_ready) { - struct pspv2_mbox and_mask = { .val = ~0 }; - struct pspv2_mbox expected = { .val = 0 }; + union pspv2_mbox_command and_mask = { .val = ~0 }; + union pspv2_mbox_command expected = { .val = 0 }; struct stopwatch sw; u32 tmp;
@@ -99,7 +101,7 @@ stopwatch_init_msecs_expire(&sw, PSP_CMD_TIMEOUT);
do { - tmp = read32(&mbox->val); + tmp = read32(&mbox->command); tmp &= ~and_mask.val; if (tmp == expected.val) return 0;