Werner Zeh | e5a1fc7 | 2021-07-01 13:40:11 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <baseboard/variants.h> |
Werner Zeh | 4cec1a2 | 2021-06-11 06:55:50 +0200 | [diff] [blame] | 4 | #include <bootstate.h> |
Werner Zeh | c2f85c6 | 2021-07-23 11:39:04 +0200 | [diff] [blame] | 5 | #include <console/console.h> |
Werner Zeh | e5a1fc7 | 2021-07-01 13:40:11 +0200 | [diff] [blame] | 6 | #include <device/device.h> |
Werner Zeh | 78ec750 | 2021-06-11 07:05:06 +0200 | [diff] [blame] | 7 | #include <device/pci_def.h> |
| 8 | #include <device/pci_ops.h> |
| 9 | #include <device/pci_ids.h> |
Werner Zeh | c2f85c6 | 2021-07-23 11:39:04 +0200 | [diff] [blame] | 10 | #include <hwilib.h> |
| 11 | #include <i210.h> |
Werner Zeh | e5a1fc7 | 2021-07-01 13:40:11 +0200 | [diff] [blame] | 12 | #include <soc/gpio.h> |
Werner Zeh | 2d04693 | 2021-11-03 07:26:44 +0100 | [diff] [blame] | 13 | #include <soc/ramstage.h> |
Werner Zeh | c2f85c6 | 2021-07-23 11:39:04 +0200 | [diff] [blame] | 14 | #include <string.h> |
Werner Zeh | 4cec1a2 | 2021-06-11 06:55:50 +0200 | [diff] [blame] | 15 | #include <timer.h> |
| 16 | #include <timestamp.h> |
Werner Zeh | c2f85c6 | 2021-07-23 11:39:04 +0200 | [diff] [blame] | 17 | |
| 18 | #define MAX_PATH_DEPTH 12 |
| 19 | #define MAX_NUM_MAPPINGS 10 |
| 20 | |
| 21 | /** \brief This function can decide if a given MAC address is valid or not. |
| 22 | * Currently, addresses filled with 0xff or 0x00 are not valid. |
| 23 | * @param mac Buffer to the MAC address to check |
| 24 | * @return 0 if address is not valid, otherwise 1 |
| 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 | /** \brief This function will search for a MAC address which can be assigned |
| 38 | * to a MACPHY. |
| 39 | * @param dev pointer to PCI device |
| 40 | * @param mac buffer where to store the MAC address |
| 41 | * @return cb_err CB_ERR or CB_SUCCESS |
| 42 | */ |
| 43 | enum cb_err mainboard_get_mac_address(struct device *dev, uint8_t mac[MAC_ADDR_LEN]) |
| 44 | { |
| 45 | struct bus *parent = dev->bus; |
| 46 | uint8_t buf[16], mapping[16], i = 0, chain_len = 0; |
| 47 | |
| 48 | memset(buf, 0, sizeof(buf)); |
| 49 | memset(mapping, 0, sizeof(mapping)); |
| 50 | |
| 51 | /* The first entry in the tree is the device itself. */ |
| 52 | buf[0] = dev->path.pci.devfn; |
| 53 | chain_len = 1; |
| 54 | for (i = 1; i < MAX_PATH_DEPTH && parent->dev->bus->subordinate; i++) { |
| 55 | buf[i] = parent->dev->path.pci.devfn; |
| 56 | chain_len++; |
| 57 | parent = parent->dev->bus; |
| 58 | } |
| 59 | if (i == MAX_PATH_DEPTH) { |
| 60 | /* The path is deeper than MAX_PATH_DEPTH devices, error. */ |
| 61 | printk(BIOS_ERR, "Too many bridges for %s\n", dev_path(dev)); |
| 62 | return CB_ERR; |
| 63 | } |
| 64 | /* |
| 65 | * Now construct the mapping based on the device chain starting from |
| 66 | * root bridge device to the device itself. |
| 67 | */ |
| 68 | mapping[0] = 1; |
| 69 | mapping[1] = chain_len; |
| 70 | for (i = 0; i < chain_len; i++) |
| 71 | mapping[i + 4] = buf[chain_len - i - 1]; |
| 72 | |
| 73 | /* Open main hwinfo block */ |
| 74 | if (hwilib_find_blocks("hwinfo.hex") != CB_SUCCESS) |
| 75 | return CB_ERR; |
| 76 | /* Now try to find a valid MAC address in hwinfo for this mapping. */ |
| 77 | for (i = 0; i < MAX_NUM_MAPPINGS; i++) { |
| 78 | if (hwilib_get_field(XMac1Mapping + i, buf, 16) != 16) |
| 79 | continue; |
| 80 | if (memcmp(buf, mapping, chain_len + 4)) |
| 81 | continue; |
| 82 | /* There is a matching mapping available, get MAC address. */ |
| 83 | if (hwilib_get_field(XMac1 + i, mac, MAC_ADDR_LEN) == MAC_ADDR_LEN) { |
| 84 | if (is_mac_adr_valid(mac)) |
| 85 | return CB_SUCCESS; |
| 86 | } |
| 87 | return CB_ERR; |
| 88 | } |
| 89 | /* No MAC address found for */ |
| 90 | return CB_ERR; |
| 91 | } |
Werner Zeh | e5a1fc7 | 2021-07-01 13:40:11 +0200 | [diff] [blame] | 92 | |
Werner Zeh | 4cec1a2 | 2021-06-11 06:55:50 +0200 | [diff] [blame] | 93 | static void wait_for_legacy_dev(void *unused) |
| 94 | { |
| 95 | uint32_t legacy_delay, us_since_boot; |
| 96 | struct stopwatch sw; |
| 97 | |
| 98 | /* Open main hwinfo block. */ |
| 99 | if (hwilib_find_blocks("hwinfo.hex") != CB_SUCCESS) |
| 100 | return; |
| 101 | |
| 102 | /* Get legacy delay parameter from hwinfo. */ |
| 103 | if (hwilib_get_field(LegacyDelay, (uint8_t *) &legacy_delay, |
| 104 | sizeof(legacy_delay)) != sizeof(legacy_delay)) |
| 105 | return; |
| 106 | |
| 107 | us_since_boot = get_us_since_boot(); |
| 108 | /* No need to wait if the time since boot is already long enough.*/ |
| 109 | if (us_since_boot > legacy_delay) |
| 110 | return; |
| 111 | stopwatch_init_msecs_expire(&sw, (legacy_delay - us_since_boot) / 1000); |
| 112 | printk(BIOS_NOTICE, "Wait remaining %d of %d us for legacy devices...", |
| 113 | legacy_delay - us_since_boot, legacy_delay); |
| 114 | stopwatch_wait_until_expired(&sw); |
| 115 | printk(BIOS_NOTICE, "done!\n"); |
| 116 | } |
| 117 | |
Werner Zeh | 2d04693 | 2021-11-03 07:26:44 +0100 | [diff] [blame] | 118 | void mainboard_silicon_init_params(FSP_S_CONFIG *params) |
| 119 | { |
| 120 | /* Disable CPU power states (C-states) */ |
| 121 | params->Cx = 0; |
| 122 | |
| 123 | /* Set maximum package C-state to PkgC0C1 */ |
| 124 | params->PkgCStateLimit = 0; |
Werner Zeh | 9916eb4 | 2021-11-03 10:37:57 +0100 | [diff] [blame] | 125 | |
| 126 | /* Disable P-States */ |
| 127 | params->MaxRatio = 0; |
Werner Zeh | 9f7e018 | 2021-11-03 11:44:43 +0100 | [diff] [blame] | 128 | |
| 129 | /* Disable PMC low power modes */ |
| 130 | params->PmcLpmS0ixSubStateEnableMask = 0; |
| 131 | params->PmcV1p05PhyExtFetControlEn = 0; |
| 132 | params->PmcV1p05IsExtFetControlEn = 0; |
Werner Zeh | 2d04693 | 2021-11-03 07:26:44 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Werner Zeh | e5a1fc7 | 2021-07-01 13:40:11 +0200 | [diff] [blame] | 135 | static void mainboard_init(void *chip_info) |
| 136 | { |
| 137 | const struct pad_config *pads; |
| 138 | size_t num; |
| 139 | |
| 140 | pads = variant_gpio_table(&num); |
| 141 | gpio_configure_pads(pads, num); |
| 142 | } |
| 143 | |
Werner Zeh | 78ec750 | 2021-06-11 07:05:06 +0200 | [diff] [blame] | 144 | static void mainboard_final(void *chip_info) |
| 145 | { |
| 146 | struct device *dev; |
| 147 | |
Mario Scheithauer | d7f45ea | 2021-08-24 12:43:45 +0200 | [diff] [blame] | 148 | /* Do board specific things */ |
| 149 | variant_mainboard_final(); |
| 150 | |
Werner Zeh | 78ec750 | 2021-06-11 07:05:06 +0200 | [diff] [blame] | 151 | if (CONFIG(PCI_ALLOW_BUS_MASTER_ANY_DEVICE)) { |
| 152 | /* Set Master Enable for on-board PCI devices if allowed. */ |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 153 | dev = dev_find_device(PCI_VID_SIEMENS, 0x403e, 0); |
Werner Zeh | 78ec750 | 2021-06-11 07:05:06 +0200 | [diff] [blame] | 154 | if (dev) |
| 155 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
| 156 | |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 157 | dev = dev_find_device(PCI_VID_SIEMENS, 0x403f, 0); |
Werner Zeh | 78ec750 | 2021-06-11 07:05:06 +0200 | [diff] [blame] | 158 | if (dev) |
| 159 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
| 160 | } |
| 161 | } |
| 162 | |
Mario Scheithauer | d7f45ea | 2021-08-24 12:43:45 +0200 | [diff] [blame] | 163 | /* The following function performs board specific things. */ |
| 164 | void __weak variant_mainboard_final(void) |
| 165 | { |
| 166 | } |
| 167 | |
Werner Zeh | e5a1fc7 | 2021-07-01 13:40:11 +0200 | [diff] [blame] | 168 | struct chip_operations mainboard_ops = { |
Werner Zeh | 78ec750 | 2021-06-11 07:05:06 +0200 | [diff] [blame] | 169 | .init = mainboard_init, |
| 170 | .final = mainboard_final |
Werner Zeh | e5a1fc7 | 2021-07-01 13:40:11 +0200 | [diff] [blame] | 171 | }; |
Werner Zeh | 4cec1a2 | 2021-06-11 06:55:50 +0200 | [diff] [blame] | 172 | |
| 173 | BOOT_STATE_INIT_ENTRY(BS_DEV_ENUMERATE, BS_ON_ENTRY, wait_for_legacy_dev, NULL); |