coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
spi_debug.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/console.h>
4 #include <soc/spi.h>
5 
6 const char *spi_opcode_name(int opcode)
7 {
8  const char *op_name;
9 
10  switch (opcode) {
11  default:
12  op_name = "Unknown";
13  break;
14  case 1:
15  op_name = "Write Status";
16  break;
17  case 2:
18  op_name = "Page Program";
19  break;
20  case 3:
21  op_name = "Read Data";
22  break;
23  case 5:
24  op_name = "Read Status";
25  break;
26  case 6:
27  op_name = "Write Data Enable";
28  break;
29  case 0x0b:
30  op_name = "Fast Read";
31  break;
32  case 0x20:
33  op_name = "Erase 4 KiB";
34  break;
35  case 0x50:
36  op_name = "Write Status Enable";
37  break;
38  case 0x9f:
39  op_name = "Read ID";
40  break;
41  case 0xd8:
42  op_name = "Erase 64 KiB";
43  break;
44  }
45  return op_name;
46 }
47 
48 void spi_display(volatile struct flash_ctrlr *ctrlr)
49 {
50  int index;
51  int opcode;
52  const char *op_name;
53  int prefix;
54  int status;
55  int type;
56 
57  /* Display the prefixes */
58  printk(BIOS_DEBUG, "Prefix Table\n");
59  for (index = 0; index < 2; index++) {
60  prefix = ctrlr->prefix[index];
61  op_name = spi_opcode_name(prefix);
62  printk(BIOS_DEBUG, " %d: 0x%02x (%s)\n", index, prefix,
63  op_name);
64  }
65 
66  /* Display the opcodes */
67  printk(BIOS_DEBUG, "Opcode Menu\n");
68  for (index = 0; index < 8; index++) {
69  opcode = ctrlr->opmenu[index];
70  type = (ctrlr->type >> (index << 1)) & 3;
71  op_name = spi_opcode_name(opcode);
72  printk(BIOS_DEBUG, " %d: 0x%02x (%s), %s%s\n", index, opcode,
73  op_name,
74  (type & SPITYPE_PREFIX) ? "Write" : "Read",
75  (type & SPITYPE_ADDRESS) ? ", w/3 byte address" : "");
76  }
77 
78  /* Display the BIOS base address */
79  printk(BIOS_DEBUG, "0x%08x: BIOS Base Address\n", ctrlr->bbar);
80 
81  /* Display the protection ranges */
82  printk(BIOS_DEBUG, "BIOS Protected Range Registers\n");
83  for (index = 0; index < ARRAY_SIZE(ctrlr->pbr); index++) {
84  status = ctrlr->pbr[index];
85  printk(BIOS_DEBUG, " %d: 0x%08x: 0x%08x - 0x%08x %s\n",
86  index, status,
87  0xff000000 | (0x1000000 - CONFIG_ROM_SIZE)
88  | ((status & SPIPBR_PRB) << SPIPBR_PRB_SHIFT),
89  0xff800fff | (0x1000000 - CONFIG_ROM_SIZE)
90  | (status & SPIPBR_PRL),
91  (status & SPIPBR_WPE) ? "Protected" : "Unprotected");
92  }
93 
94  /* Display locked status */
95  status = ctrlr->status;
96  printk(BIOS_DEBUG, "0x%04x: SPISTS, Tables %s\n", status,
97  (status & SPISTS_CLD) ? "Locked" : "Unlocked");
98 }
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
unsigned int type
Definition: edid.c:57
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define SPIPBR_PRL
Definition: spi.h:64
#define SPIPBR_PRB
Definition: spi.h:66
#define SPITYPE_ADDRESS
Definition: spi.h:55
#define SPIPBR_WPE
Definition: spi.h:63
#define SPISTS_CLD
Definition: spi.h:36
#define SPIPBR_PRB_SHIFT
Definition: spi.h:65
#define SPITYPE_PREFIX
Definition: spi.h:56
void spi_display(volatile struct flash_ctrlr *ctrlr)
Definition: spi_debug.c:48
const char * spi_opcode_name(int opcode)
Definition: spi_debug.c:6
uint8_t opmenu[8]
Definition: spi.h:31
uint16_t type
Definition: spi.h:30
uint32_t bbar
Definition: spi.h:28
uint32_t pbr[3]
Definition: spi.h:32
uint16_t status
Definition: spi.h:23
uint8_t prefix[2]
Definition: spi.h:29