From 63e7b7064137f1854256f07a8f49b986ea944080 Mon Sep 17 00:00:00 2001 From: Felix Held Date: Fri, 29 Apr 2022 18:41:03 +0200 Subject: 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 Change-Id: If3f00b6fd73c3f749154b77b940e6d5aa385ec49 Reviewed-on: https://review.coreboot.org/c/coreboot/+/63963 Tested-by: build bot (Jenkins) Reviewed-by: Raul Rangel --- src/soc/amd/common/block/psp/psp_gen2.c | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'src/soc/amd/common') diff --git a/src/soc/amd/common/block/psp/psp_gen2.c b/src/soc/amd/common/block/psp/psp_gen2.c index 6f46d82220..cbae7a5f5f 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 @@ static u16 rd_mbox_sts(struct pspv2_mbox *mbox) 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 @@ static void wr_mbox_cmd(struct pspv2_mbox *mbox, u8 cmd) /* 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 @@ static u8 rd_mbox_recovery(struct pspv2_mbox *mbox) 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 void wr_mbox_buffer_ptr(struct pspv2_mbox *mbox, void *buffer) 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 @@ static int wait_command(struct pspv2_mbox *mbox, bool wait_for_ready) 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; -- cgit v1.2.3