| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <stdio.h> |
| 5 |
#include <string.h> |
| 6 |
#include <types.h> |
| 7 |
|
| 8 |
#include "ec.h" |
| 9 |
#include "mainboard.h" |
| 10 |
#include "vpd.h" |
| 11 |
|
| 12 |
static void write_invalid_str(char *dest, size_t length) |
| 13 |
{ |
| 14 |
snprintf(dest, length, "%s", "INVALID"); |
| 15 |
} |
| 16 |
|
| 17 |
const struct emi_eeprom_vpd *get_emi_eeprom_vpd(void) |
| 18 |
{ |
| 19 |
static union { |
| 20 |
struct emi_eeprom_vpd layout; |
| 21 |
uint8_t raw[sizeof(struct emi_eeprom_vpd)]; |
| 22 |
} vpd = {}; |
| 23 |
|
| 24 |
|
| 25 |
if (vpd.layout.header.revision == VPD_LATEST_REVISION) |
| 26 |
return &vpd.layout; |
| 27 |
|
| 28 |
ec_emi_read(vpd.raw, EMI_0_IO_BASE_ADDR, 0, 0, sizeof(vpd.raw)); |
| 29 |
|
| 30 |
|
| 31 |
if (vpd.layout.header.magic != VPD_MAGIC) { |
| 32 |
printk(BIOS_WARNING, "Atlas VPD: Bad magic value, using fallback defaults\n"); |
| 33 |
vpd.layout.header.revision = 0; |
| 34 |
} else { |
| 35 |
printk(BIOS_DEBUG, "Atlas VPD: Got revision %u from EC\n", |
| 36 |
vpd.layout.header.revision); |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
switch (vpd.layout.header.revision) { |
| 54 |
case 0: |
| 55 |
memset(vpd.raw, 0, sizeof(vpd.raw)); |
| 56 |
vpd.layout.header.magic = VPD_MAGIC; |
| 57 |
write_invalid_str(vpd.layout.serial_number, sizeof(vpd.layout.serial_number)); |
| 58 |
write_invalid_str(vpd.layout.part_number, sizeof(vpd.layout.part_number)); |
| 59 |
vpd.layout.profile = ATLAS_PROF_UNPROGRAMMED; |
| 60 |
__fallthrough; |
| 61 |
default: |
| 62 |
|
| 63 |
vpd.layout.serial_number[ATLAS_SN_PN_LENGTH - 1] = '\0'; |
| 64 |
vpd.layout.part_number[ATLAS_SN_PN_LENGTH - 1] = '\0'; |
| 65 |
vpd.layout.header.revision = VPD_LATEST_REVISION; |
| 66 |
break; |
| 67 |
} |
| 68 |
|
| 69 |
return &vpd.layout; |
| 70 |
} |