| 1 |
|
| 2 |
|
| 3 |
#include <baseboard/gpio.h> |
| 4 |
#include <baseboard/variants.h> |
| 5 |
#include <device/device.h> |
| 6 |
#include <soc/gpio.h> |
| 7 |
#include <stdint.h> |
| 8 |
#include <stdio.h> |
| 9 |
#include <hwilib.h> |
| 10 |
#include <i210.h> |
| 11 |
#include <soc/ramstage.h> |
| 12 |
#include <device/pci_def.h> |
| 13 |
#include <device/pci_ops.h> |
| 14 |
#include <device/pci_ids.h> |
| 15 |
#include <cpu/x86/msr.h> |
| 16 |
#include <soc/msr.h> |
| 17 |
|
| 18 |
#define MAX_PATH_DEPTH 12 |
| 19 |
#define MAX_NUM_MAPPINGS 10 |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
static uint8_t is_mac_adr_valid(uint8_t mac[MAC_ADDR_LEN]) |
| 27 |
{ |
| 28 |
for (size_t i = 0; i < MAC_ADDR_LEN; i++) { |
| 29 |
if (mac[i] != 0x00 && mac[i] != 0xff) |
| 30 |
return 1; |
| 31 |
if (mac[i] != mac[0]) |
| 32 |
return 1; |
| 33 |
} |
| 34 |
return 0; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
enum cb_err mainboard_get_mac_address(struct device *dev, uint8_t mac[MAC_ADDR_LEN]) |
| 45 |
{ |
| 46 |
struct bus *parent = dev->upstream; |
| 47 |
uint8_t buf[16], mapping[16], i = 0, chain_len = 0; |
| 48 |
|
| 49 |
memset(buf, 0, sizeof(buf)); |
| 50 |
memset(mapping, 0, sizeof(mapping)); |
| 51 |
|
| 52 |
|
| 53 |
buf[0] = dev->path.pci.devfn; |
| 54 |
chain_len = 1; |
| 55 |
for (i = 1; i < MAX_PATH_DEPTH && parent->dev->upstream->subordinate; i++) { |
| 56 |
buf[i] = parent->dev->path.pci.devfn; |
| 57 |
chain_len++; |
| 58 |
parent = parent->dev->upstream; |
| 59 |
} |
| 60 |
if (i == MAX_PATH_DEPTH) { |
| 61 |
|
| 62 |
printk(BIOS_ERR, "Too many bridges for %s\n", dev_path(dev)); |
| 63 |
return CB_ERR; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
mapping[0] = 1; |
| 70 |
mapping[1] = chain_len; |
| 71 |
for (i = 0; i < chain_len; i++) |
| 72 |
mapping[i + 4] = buf[chain_len - i - 1]; |
| 73 |
|
| 74 |
|
| 75 |
if (hwilib_find_blocks("hwinfo.hex") != CB_SUCCESS) |
| 76 |
return CB_ERR; |
| 77 |
|
| 78 |
for (i = 0; i < MAX_NUM_MAPPINGS; i++) { |
| 79 |
if (hwilib_get_field(XMac1Mapping + i, buf, 16) != 16) |
| 80 |
continue; |
| 81 |
if (memcmp(buf, mapping, chain_len + 4)) |
| 82 |
continue; |
| 83 |
|
| 84 |
if (hwilib_get_field(XMac1 + i, mac, MAC_ADDR_LEN) == MAC_ADDR_LEN) { |
| 85 |
if (is_mac_adr_valid(mac)) |
| 86 |
return CB_SUCCESS; |
| 87 |
} |
| 88 |
return CB_ERR; |
| 89 |
} |
| 90 |
|
| 91 |
return CB_ERR; |
| 92 |
} |
| 93 |
|
| 94 |
void mainboard_silicon_init_params(FSP_S_CONFIG *params) |
| 95 |
{ |
| 96 |
params->Eist = 0; |
| 97 |
params->TurboMode = 0; |
| 98 |
} |
| 99 |
|
| 100 |
static void disable_c1e(void) |
| 101 |
{ |
| 102 |
msr_t msr; |
| 103 |
|
| 104 |
msr = rdmsr(MSR_POWER_CTL); |
| 105 |
msr.lo &= ~(1 << 1); |
| 106 |
wrmsr(MSR_POWER_CTL, msr); |
| 107 |
} |
| 108 |
|
| 109 |
static void mainboard_final(void *chip_info) |
| 110 |
{ |
| 111 |
struct device *dev; |
| 112 |
|
| 113 |
if (CONFIG(PCI_ALLOW_BUS_MASTER_ANY_DEVICE)) { |
| 114 |
|
| 115 |
dev = dev_find_device(PCI_VID_SIEMENS, 0x403f, 0); |
| 116 |
if (dev) |
| 117 |
pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
| 118 |
} |
| 119 |
|
| 120 |
disable_c1e(); |
| 121 |
} |
| 122 |
|
| 123 |
static void mainboard_init(void *chip_info) |
| 124 |
{ |
| 125 |
variant_configure_gpio_pads(); |
| 126 |
|
| 127 |
} |
| 128 |
|
| 129 |
struct chip_operations mainboard_ops = { |
| 130 |
.init = mainboard_init, |
| 131 |
.final = mainboard_final, |
| 132 |
}; |