coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
psp.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/mmio.h>
4 #include <bootstate.h>
5 #include <console/console.h>
6 #include <amdblocks/psp.h>
7 #include <soc/iomap.h>
8 #include "psp_def.h"
9 
10 static const char *psp_status_nobase = "error: PSP_ADDR_MSR and PSP BAR3 not assigned";
11 static const char *psp_status_halted = "error: PSP in halted state";
12 static const char *psp_status_recovery = "error: PSP recovery required";
13 static const char *psp_status_errcmd = "error sending command";
14 static const char *psp_status_init_timeout = "error: PSP init timeout";
15 static const char *psp_status_cmd_timeout = "error: PSP command timeout";
16 static const char *psp_status_noerror = "";
17 
18 static const char *status_to_string(int err)
19 {
20  switch (err) {
21  case -PSPSTS_NOBASE:
22  return psp_status_nobase;
23  case -PSPSTS_HALTED:
24  return psp_status_halted;
25  case -PSPSTS_RECOVERY:
26  return psp_status_recovery;
27  case -PSPSTS_SEND_ERROR:
28  return psp_status_errcmd;
29  case -PSPSTS_INIT_TIMEOUT:
31  case -PSPSTS_CMD_TIMEOUT:
33  default:
34  return psp_status_noerror;
35  }
36 }
37 
39 {
40  return read32(&header->status);
41 }
42 
43 /*
44  * Print meaningful status to the console. Caller only passes a pointer to a
45  * buffer header if it's expected to contain its own status.
46  */
47 void psp_print_cmd_status(int cmd_status, struct mbox_buffer_header *header)
48 {
49  if (header && rd_resp_sts(header))
50  printk(BIOS_DEBUG, "buffer status=0x%x ", rd_resp_sts(header));
51 
52  if (cmd_status)
53  printk(BIOS_WARNING, "%s\n", status_to_string(cmd_status));
54  else
55  printk(BIOS_DEBUG, "OK\n");
56 }
57 
58 /*
59  * Notify the PSP that the system is completing the boot process. Upon
60  * receiving this command, the PSP will only honor commands where the buffer
61  * is in SMM space.
62  */
63 static void psp_notify_boot_done(void *unused)
64 {
65  int cmd_status;
66  struct mbox_default_buffer buffer = {
67  .header = {
68  .size = sizeof(buffer)
69  }
70  };
71 
72  printk(BIOS_DEBUG, "PSP: Notify that POST is finishing... ");
73 
75 
76  /* buffer's status shouldn't change but report it if it does */
77  psp_print_cmd_status(cmd_status, &buffer.header);
78 }
79 
struct arm64_kernel_header header
Definition: fit_payload.c:30
static uint32_t read32(const void *addr)
Definition: mmio.h:22
@ BS_PAYLOAD_BOOT
Definition: bootstate.h:89
@ BS_ON_ENTRY
Definition: bootstate.h:95
static const char * status_to_string(int err)
Definition: psp.c:18
static const char * psp_status_halted
Definition: psp.c:11
static const char * psp_status_cmd_timeout
Definition: psp.c:15
static const char * psp_status_noerror
Definition: psp.c:16
static const char * psp_status_init_timeout
Definition: psp.c:14
static u32 rd_resp_sts(struct mbox_buffer_header *header)
Definition: psp.c:38
static const char * psp_status_nobase
Definition: psp.c:10
static void psp_notify_boot_done(void *unused)
Definition: psp.c:63
static const char * psp_status_recovery
Definition: psp.c:12
BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, psp_notify_boot_done, NULL)
static const char * psp_status_errcmd
Definition: psp.c:13
void psp_print_cmd_status(int cmd_status, struct mbox_buffer_header *header)
Definition: psp.c:47
#define printk(level,...)
Definition: stdlib.h:16
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition: loglevel.h:86
#define PSPSTS_NOBASE
Definition: psp.h:43
#define PSPSTS_INIT_TIMEOUT
Definition: psp.h:47
#define PSPSTS_RECOVERY
Definition: psp.h:45
#define PSPSTS_CMD_TIMEOUT
Definition: psp.h:48
#define PSPSTS_HALTED
Definition: psp.h:44
#define PSPSTS_SEND_ERROR
Definition: psp.h:46
int send_psp_command(u32 command, void *buffer)
Definition: psp_gen1.c:115
#define MBOX_BIOS_CMD_BOOT_DONE
Definition: psp_def.h:16
u8 buffer[C2P_BUFFER_MAXSIZE]
Definition: psp_smm.c:18
#define NULL
Definition: stddef.h:19
uint32_t u32
Definition: stdint.h:51