coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
post.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <stdint.h>
4 #include <post.h>
5 #include <console/console.h>
6 #include <device/device.h>
7 #include <pc80/mc146818rtc.h>
8 #include <smp/spinlock.h>
9 
10 #if CONFIG(USE_OPTION_TABLE)
11 # include "option_table.h"
12 # define CMOS_POST_OFFSET (CMOS_VSTART_cmos_post_offset >> 3)
13 #else
14 # if (CONFIG_CMOS_POST_OFFSET != 0)
15 # define CMOS_POST_OFFSET CONFIG_CMOS_POST_OFFSET
16 # else
17 # error "Must configure CONFIG_CMOS_POST_OFFSET"
18 # endif
19 #endif
20 
21 /*
22  * 0 = Bank Select Magic
23  * 1 = Bank 0 POST
24  * 2 = Bank 1 POST
25  * 3-6 = BANK 0 Extra log
26  * 7-10 = BANK 1 Extra log
27  */
28 #define CMOS_POST_BANK_OFFSET (CMOS_POST_OFFSET)
29 #define CMOS_POST_BANK_0_MAGIC 0x80
30 #define CMOS_POST_BANK_0_OFFSET (CMOS_POST_OFFSET + 1)
31 #define CMOS_POST_BANK_0_EXTRA (CMOS_POST_OFFSET + 3)
32 #define CMOS_POST_BANK_1_MAGIC 0x81
33 #define CMOS_POST_BANK_1_OFFSET (CMOS_POST_OFFSET + 2)
34 #define CMOS_POST_BANK_1_EXTRA (CMOS_POST_OFFSET + 7)
35 
36 #define CMOS_POST_EXTRA_DEV_PATH 0x01
37 
38 DECLARE_SPIN_LOCK(cmos_post_lock)
39 
40 int cmos_post_previous_boot(u8 *code, u32 *extra)
41 {
42  *code = 0;
43  *extra = 0;
44 
45  spin_lock(&cmos_post_lock);
46 
47  /* Get post code from other bank */
52  break;
56  break;
57  }
58 
59  spin_unlock(&cmos_post_lock);
60 
61  /* Check last post code in previous boot against normal list */
62  switch (*code) {
63  case POST_OS_BOOT:
64  case POST_OS_RESUME:
66  case 0:
67  break;
68  default:
69  return -1;
70  }
71 
72  return 0;
73 }
74 
75 void cmos_post_init(void)
76 {
77  u8 magic = CMOS_POST_BANK_0_MAGIC;
78 
79  /* Switch to the other bank */
82  break;
84  magic = CMOS_POST_BANK_1_MAGIC;
85  break;
86  default:
87  /* Initialize to zero */
92  }
93 
95 }
96 
98 {
99  spin_lock(&cmos_post_lock);
100 
101  switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
104  break;
107  break;
108  }
109 
110  spin_unlock(&cmos_post_lock);
111 }
112 
114 {
115  spin_lock(&cmos_post_lock);
116 
117  switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
120  break;
123  break;
124  }
125 
126  spin_unlock(&cmos_post_lock);
127 }
128 
129 void cmos_post_path(const struct device *dev)
130 {
131  /* Encode path into lower 3 bytes */
132  u32 path = dev_path_encode(dev);
133  /* Upper byte contains the log type */
134  path |= CMOS_POST_EXTRA_DEV_PATH << 24;
135  cmos_post_extra(path);
136 }
pte_t value
Definition: mmu.c:91
#define DECLARE_SPIN_LOCK(x)
Definition: spinlock.h:18
u32 dev_path_encode(const struct device *dev)
Encode the device path into 3 bytes for logging to CMOS.
Definition: device_util.c:83
#define CMOS_POST_BANK_0_MAGIC
Definition: post.c:29
#define CMOS_POST_BANK_1_OFFSET
Definition: post.c:33
void cmos_post_extra(u32 value)
Definition: post.c:113
int cmos_post_previous_boot(u8 *code, u32 *extra)
Definition: post.c:40
#define CMOS_POST_BANK_0_OFFSET
Definition: post.c:30
void cmos_post_code(u8 value)
Definition: post.c:97
#define CMOS_POST_BANK_1_EXTRA
Definition: post.c:34
#define CMOS_POST_BANK_OFFSET
Definition: post.c:28
#define CMOS_POST_BANK_1_MAGIC
Definition: post.c:32
#define CMOS_POST_BANK_0_EXTRA
Definition: post.c:31
void cmos_post_init(void)
Definition: post.c:75
#define CMOS_POST_EXTRA_DEV_PATH
Definition: post.c:36
void cmos_post_path(const struct device *dev)
Definition: post.c:129
#define spin_lock(lock)
Definition: spinlock.h:11
#define spin_unlock(lock)
Definition: spinlock.h:12
static u32 cmos_read32(u8 offset)
Definition: mc146818rtc.h:157
static void cmos_write(unsigned char val, unsigned char addr)
Definition: mc146818rtc.h:141
static void cmos_write32(u32 value, u8 offset)
Definition: mc146818rtc.h:166
static unsigned char cmos_read(unsigned char addr)
Definition: mc146818rtc.h:105
#define POST_OS_BOOT
Final code before OS boots.
Definition: post_codes.h:414
#define POST_OS_RESUME
Final code before OS resumes.
Definition: post_codes.h:407
#define POST_ENTER_ELF_BOOT
Entry into elf boot.
Definition: post_codes.h:400
uint32_t u32
Definition: stdint.h:51
uint8_t u8
Definition: stdint.h:45
Definition: device.h:107