| 1 |
|
| 2 |
|
| 3 |
#include <assert.h> |
| 4 |
#include <soc/ramstage.h> |
| 5 |
#include <types.h> |
| 6 |
|
| 7 |
union eeprom_dimm_layout { |
| 8 |
struct __packed { |
| 9 |
char name[50]; |
| 10 |
char manufacturer[50]; |
| 11 |
uint8_t ranks; |
| 12 |
uint8_t controller_id; |
| 13 |
uint8_t data_width_bits; |
| 14 |
uint8_t bus_width_bits; |
| 15 |
uint32_t capacity_mib; |
| 16 |
uint32_t max_tdp_milliwatts; |
| 17 |
}; |
| 18 |
uint8_t raw[0x80]; |
| 19 |
}; |
| 20 |
|
| 21 |
_Static_assert(sizeof(union eeprom_dimm_layout) == 0x80, |
| 22 |
"union eeprom_dimm_layout has invalid size!"); |
| 23 |
|
| 24 |
struct __packed eeprom_board_layout { |
| 25 |
uint32_t signature; |
| 26 |
union { |
| 27 |
struct __packed { |
| 28 |
char cpu_name[50]; |
| 29 |
uint8_t cpu_count; |
| 30 |
uint32_t cpu_max_non_turbo_frequency; |
| 31 |
char pch_name[50]; |
| 32 |
union eeprom_dimm_layout dimm[4]; |
| 33 |
}; |
| 34 |
uint8_t raw_layout[617]; |
| 35 |
}; |
| 36 |
}; |
| 37 |
|
| 38 |
_Static_assert(sizeof(struct eeprom_board_layout) == (617 + sizeof(uint32_t)), |
| 39 |
"struct eeprom_board_layout has invalid size!"); |
| 40 |
|
| 41 |
struct __packed eeprom_reset_cause_regs { |
| 42 |
uint32_t gblrst_cause0; |
| 43 |
uint32_t gblrst_cause1; |
| 44 |
uint32_t hpr_cause0; |
| 45 |
}; |
| 46 |
|
| 47 |
struct __packed eeprom_board_settings { |
| 48 |
uint32_t signature; |
| 49 |
union { |
| 50 |
struct __packed { |
| 51 |
uint8_t secureboot; |
| 52 |
uint8_t primary_video; |
| 53 |
uint8_t deep_sx_enabled; |
| 54 |
uint8_t wake_on_usb; |
| 55 |
uint8_t usb_powered_in_s5; |
| 56 |
uint8_t power_state_after_g3; |
| 57 |
uint8_t blue_rear_vref; |
| 58 |
uint8_t front_panel_audio; |
| 59 |
uint8_t pxe_boot_capability; |
| 60 |
uint8_t pink_rear_vref; |
| 61 |
uint8_t vtx_disabled; |
| 62 |
uint8_t boot_menu_disabled; |
| 63 |
}; |
| 64 |
uint8_t raw_settings[12]; |
| 65 |
}; |
| 66 |
}; |
| 67 |
|
| 68 |
enum { |
| 69 |
PRIMARY_VIDEO_ASPEED = 0, |
| 70 |
PRIMARY_VIDEO_INTEL = 1, |
| 71 |
}; |
| 72 |
|
| 73 |
_Static_assert(sizeof(struct eeprom_board_settings) == (12 + sizeof(uint32_t)), |
| 74 |
"struct eeprom_board_settings has invalid size!"); |
| 75 |
|
| 76 |
struct __packed eeprom_bmc_settings { |
| 77 |
uint8_t pcie_mux; |
| 78 |
uint8_t hsi; |
| 79 |
uint8_t efp3_displayport; |
| 80 |
}; |
| 81 |
|
| 82 |
#define HERMES_SN_PN_LENGTH 32 |
| 83 |
|
| 84 |
|
| 85 |
struct __packed eeprom_layout { |
| 86 |
union { |
| 87 |
uint8_t raw_fspm_upd[0x600]; |
| 88 |
FSPM_UPD mupd; |
| 89 |
}; |
| 90 |
union { |
| 91 |
uint8_t raw_fsps_upd[0xc00]; |
| 92 |
FSPS_UPD supd; |
| 93 |
}; |
| 94 |
union { |
| 95 |
uint8_t raw_board_layout[0x400]; |
| 96 |
struct eeprom_board_layout board_layout; |
| 97 |
}; |
| 98 |
char system_serial_number[HERMES_SN_PN_LENGTH]; |
| 99 |
char board_serial_number[HERMES_SN_PN_LENGTH]; |
| 100 |
uint8_t boot_order[0x200]; |
| 101 |
char board_part_number[HERMES_SN_PN_LENGTH]; |
| 102 |
char product_part_number[HERMES_SN_PN_LENGTH]; |
| 103 |
union { |
| 104 |
struct eeprom_reset_cause_regs reset_cause_regs; |
| 105 |
uint8_t raw_reset_cause_registers[0x80]; |
| 106 |
}; |
| 107 |
uint8_t unused[0x600]; |
| 108 |
union { |
| 109 |
uint8_t raw_board_settings[0xf8]; |
| 110 |
struct eeprom_board_settings board_settings; |
| 111 |
}; |
| 112 |
union { |
| 113 |
uint8_t raw_bmc_settings[0x8]; |
| 114 |
struct eeprom_bmc_settings bmc_settings; |
| 115 |
}; |
| 116 |
}; |
| 117 |
|
| 118 |
_Static_assert(sizeof(FSPM_UPD) <= 0x600, "FSPM_UPD too big"); |
| 119 |
_Static_assert(sizeof(FSPS_UPD) <= 0xc00, "FSPS_UPD too big"); |
| 120 |
_Static_assert(sizeof(struct eeprom_layout) == 0x2000, "EEPROM layout size mismatch"); |
| 121 |
|
| 122 |
bool eeprom_read_buffer(void *blob, size_t read_offset, size_t size); |
| 123 |
int check_signature(const size_t offset, const uint64_t signature); |
| 124 |
struct eeprom_board_settings *get_board_settings(void); |
| 125 |
struct eeprom_bmc_settings *get_bmc_settings(void); |
| 126 |
const char *eeprom_read_serial(size_t offset, const char *fallback); |
| 127 |
uint8_t get_bmc_hsi(void); |
| 128 |
void report_eeprom_error(const size_t off); |
| 129 |
bool eeprom_write_byte(const uint8_t data, const uint16_t write_offset); |
| 130 |
bool write_board_settings(const struct eeprom_board_layout *new_layout); |
| 131 |
|
| 132 |
#define READ_EEPROM(section_type, section_name, dest, opt_name) \ |
| 133 |
do { \ |
| 134 |
typeof(dest->opt_name) __tmp; \ |
| 135 |
size_t __off = offsetof(struct eeprom_layout, section_name); \ |
| 136 |
bool ret = eeprom_read_buffer(&__tmp, \ |
| 137 |
__off + offsetof(section_type, opt_name), \ |
| 138 |
sizeof(__tmp)); \ |
| 139 |
if (ret) { \ |
| 140 |
report_eeprom_error(__off + offsetof(section_type, opt_name)); \ |
| 141 |
} else { \ |
| 142 |
dest->opt_name = __tmp; \ |
| 143 |
} \ |
| 144 |
} while (0) |
| 145 |
|
| 146 |
#define READ_EEPROM_FSP_M(dest, opt_name) READ_EEPROM(FSPM_UPD, raw_fspm_upd, dest, opt_name) |
| 147 |
#define READ_EEPROM_FSP_S(dest, opt_name) READ_EEPROM(FSPS_UPD, raw_fsps_upd, dest, opt_name) |