Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Marshall Dawson | beb1288 | 2017-05-23 18:57:47 -0600 | [diff] [blame] | 4 | * Copyright (C) 2015-2017 Advanced Micro Devices, Inc. |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
Simon Glass | b5c5177 | 2018-03-05 12:18:40 -0700 | [diff] [blame^] | 16 | #include <string.h> |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 17 | #include <console/console.h> |
| 18 | #include <device/device.h> |
| 19 | #include <arch/acpi.h> |
Richard Spiegel | 0ad74ac | 2017-12-08 16:53:29 -0700 | [diff] [blame] | 20 | #include <amdblocks/agesawrapper.h> |
Richard Spiegel | 2bbc3dc | 2017-12-06 16:14:58 -0700 | [diff] [blame] | 21 | #include <amdblocks/amd_pci_util.h> |
Marc Jones | 067031e | 2017-11-02 11:36:53 -0600 | [diff] [blame] | 22 | #include <cbmem.h> |
Martin Roth | b77bc6f | 2017-11-11 14:33:47 -0700 | [diff] [blame] | 23 | #include <baseboard/variants.h> |
Marc Jones | 71f7f0a | 2017-11-21 23:29:55 -0700 | [diff] [blame] | 24 | #include <boardid.h> |
Simon Glass | b5c5177 | 2018-03-05 12:18:40 -0700 | [diff] [blame^] | 25 | #include <smbios.h> |
Marc Jones | 067031e | 2017-11-02 11:36:53 -0600 | [diff] [blame] | 26 | #include <soc/nvs.h> |
Richard Spiegel | 9dc5600 | 2017-12-18 16:25:42 -0700 | [diff] [blame] | 27 | #include <soc/pci_devs.h> |
Marc Jones | b6ac3a2 | 2017-10-05 21:57:33 -0600 | [diff] [blame] | 28 | #include <soc/smi.h> |
Marc Jones | df6b51b | 2017-11-29 20:07:46 -0700 | [diff] [blame] | 29 | #include <soc/southbridge.h> |
Martin Roth | 6c623ca | 2017-11-16 22:14:53 -0700 | [diff] [blame] | 30 | #include <variant/ec.h> |
Marc Jones | 067031e | 2017-11-02 11:36:53 -0600 | [diff] [blame] | 31 | #include <variant/thermal.h> |
Marc Jones | 0a15ed5 | 2017-06-22 22:22:20 -0600 | [diff] [blame] | 32 | #include <vendorcode/google/chromeos/chromeos.h> |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 33 | |
| 34 | /*********************************************************** |
| 35 | * These arrays set up the FCH PCI_INTR registers 0xC00/0xC01. |
| 36 | * This table is responsible for physically routing the PIC and |
| 37 | * IOAPIC IRQs to the different PCI devices on the system. It |
| 38 | * is read and written via registers 0xC00/0xC01 as an |
| 39 | * Index/Data pair. These values are chipset and mainboard |
| 40 | * dependent and should be updated accordingly. |
| 41 | * |
| 42 | * These values are used by the PCI configuration space, |
| 43 | * MP Tables. TODO: Make ACPI use these values too. |
| 44 | */ |
Martin Roth | 6c14cd3 | 2018-01-11 16:25:28 -0800 | [diff] [blame] | 45 | |
| 46 | // TODO: Move these to board variant specific file |
| 47 | #if IS_ENABLED(CONFIG_BOARD_GOOGLE_KAHLEE) |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 48 | const u8 mainboard_picr_data[] = { |
| 49 | [0x00] = 0x03, 0x04, 0x05, 0x07, 0x0B, 0x0A, 0x1F, 0x1F, |
| 50 | [0x08] = 0xFA, 0xF1, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F, |
Richard Spiegel | 8f825e0 | 2018-02-12 08:36:10 -0700 | [diff] [blame] | 51 | [0x10] = 0x09, 0x1F, 0x1F, 0x03, 0x1F, 0x1F, 0x1F, 0x03, |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 52 | [0x18] = 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 53 | [0x20] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, |
| 54 | [0x28] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 55 | [0x30] = 0x05, 0x04, 0x05, 0x04, 0x04, 0x05, 0x04, 0x05, |
| 56 | [0x38] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Richard Spiegel | 8f825e0 | 2018-02-12 08:36:10 -0700 | [diff] [blame] | 57 | [0x40] = 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 58 | [0x48] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 59 | [0x50] = 0x03, 0x04, 0x05, 0x07, 0x1F, 0x1F, 0x1F, 0x1F, |
| 60 | [0x58] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, |
| 61 | [0x60] = 0x1F, 0x1F, 0x07, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, |
| 62 | [0x68] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, |
| 63 | [0x70] = 0x03, 0x0F, 0x06, 0x0E, 0x0A, 0x0B, 0x1F, 0x1F, |
| 64 | [0x78] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, |
| 65 | }; |
| 66 | |
| 67 | const u8 mainboard_intr_data[] = { |
| 68 | [0x00] = 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 69 | [0x08] = 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F, |
| 70 | [0x10] = 0x09, 0x1F, 0x1F, 0x10, 0x1F, 0x1F, 0x1F, 0x10, |
| 71 | [0x18] = 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 72 | [0x20] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, |
| 73 | [0x28] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 74 | [0x30] = 0x12, 0x11, 0x12, 0x11, 0x12, 0x11, 0x12, 0x00, |
| 75 | [0x38] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 76 | [0x40] = 0x11, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 77 | [0x48] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 78 | [0x50] = 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, |
| 79 | [0x58] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 80 | [0x60] = 0x1F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 81 | [0x68] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 82 | [0x70] = 0x03, 0x0F, 0x06, 0x0E, 0x0A, 0x0B, 0x1F, 0x1F, |
| 83 | [0x78] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 84 | }; |
Martin Roth | 6c14cd3 | 2018-01-11 16:25:28 -0800 | [diff] [blame] | 85 | #else |
| 86 | const u8 mainboard_picr_data[] = { |
| 87 | [0x00] = 0x03, 0x04, 0x05, 0x07, 0x0B, 0x1F, 0x1F, 0x1F, |
| 88 | [0x08] = 0xFA, 0xF1, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F, |
Richard Spiegel | 8f825e0 | 2018-02-12 08:36:10 -0700 | [diff] [blame] | 89 | [0x10] = 0x09, 0x1F, 0x1F, 0x03, 0x1F, 0x1F, 0x1F, 0x03, |
Martin Roth | 6c14cd3 | 2018-01-11 16:25:28 -0800 | [diff] [blame] | 90 | [0x18] = 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 91 | [0x20] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, |
| 92 | [0x28] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 93 | [0x30] = 0x05, 0x04, 0x05, 0x04, 0x04, 0x05, 0x04, 0x05, |
| 94 | [0x38] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Richard Spiegel | 8f825e0 | 2018-02-12 08:36:10 -0700 | [diff] [blame] | 95 | [0x40] = 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Martin Roth | 6c14cd3 | 2018-01-11 16:25:28 -0800 | [diff] [blame] | 96 | [0x48] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 97 | [0x50] = 0x03, 0x04, 0x05, 0x07, 0x1F, 0x1F, 0x1F, 0x1F, |
| 98 | [0x58] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, |
| 99 | [0x60] = 0x1F, 0x1F, 0x07, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, |
| 100 | [0x68] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, |
| 101 | [0x70] = 0x03, 0x0F, 0x06, 0x0E, 0x0A, 0x0B, 0x1F, 0x1F, |
| 102 | [0x78] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, |
| 103 | }; |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 104 | |
Martin Roth | 6c14cd3 | 2018-01-11 16:25:28 -0800 | [diff] [blame] | 105 | const u8 mainboard_intr_data[] = { |
| 106 | [0x00] = 0x10, 0x11, 0x12, 0x13, 0x14, 0x1F, 0x16, 0x17, |
| 107 | [0x08] = 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F, |
| 108 | [0x10] = 0x09, 0x1F, 0x1F, 0x10, 0x1F, 0x1F, 0x1F, 0x10, |
| 109 | [0x18] = 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 110 | [0x20] = 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, |
| 111 | [0x28] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 112 | [0x30] = 0x12, 0x11, 0x12, 0x11, 0x12, 0x11, 0x12, 0x00, |
| 113 | [0x38] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 114 | [0x40] = 0x11, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 115 | [0x48] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 116 | [0x50] = 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, |
| 117 | [0x58] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 118 | [0x60] = 0x1F, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 119 | [0x68] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 120 | [0x70] = 0x03, 0x0F, 0x06, 0x0E, 0x0A, 0x0B, 0x1F, 0x1F, |
| 121 | [0x78] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 122 | }; |
| 123 | #endif |
Richard Spiegel | 9dc5600 | 2017-12-18 16:25:42 -0700 | [diff] [blame] | 124 | |
| 125 | /* |
| 126 | * This table defines the index into the picr/intr_data tables for each |
| 127 | * device. Any enabled device and slot that uses hardware interrupts should |
| 128 | * have an entry in this table to define its index into the FCH PCI_INTR |
| 129 | * register 0xC00/0xC01. This index will define the interrupt that it should |
| 130 | * use. Putting PIRQ_A into the PIN A index for a device will tell that |
| 131 | * device to use PIC IRQ 10 if it uses PIN A for its hardware INT. |
| 132 | */ |
| 133 | static const struct pirq_struct mainboard_pirq_data[] = { |
| 134 | { PCIE0_DEVFN, { PIRQ_A, PIRQ_B, PIRQ_C, PIRQ_D } }, |
| 135 | { PCIE1_DEVFN, { PIRQ_B, PIRQ_C, PIRQ_D, PIRQ_A } }, |
| 136 | { PCIE2_DEVFN, { PIRQ_C, PIRQ_D, PIRQ_A, PIRQ_B } }, |
| 137 | { PCIE3_DEVFN, { PIRQ_D, PIRQ_A, PIRQ_B, PIRQ_C } }, |
| 138 | { PCIE4_DEVFN, { PIRQ_A, PIRQ_B, PIRQ_C, PIRQ_D } }, |
| 139 | { HDA0_DEVFN, { PIRQ_NC, PIRQ_HDA, PIRQ_NC, PIRQ_NC } }, |
| 140 | { SD_DEVFN, { PIRQ_SD, PIRQ_NC, PIRQ_NC, PIRQ_NC } }, |
| 141 | { SMBUS_DEVFN, { PIRQ_SMBUS, PIRQ_NC, PIRQ_NC, PIRQ_NC } }, |
| 142 | { SATA_DEVFN, { PIRQ_SATA, PIRQ_NC, PIRQ_NC, PIRQ_NC } }, |
| 143 | { EHCI1_DEVFN, { PIRQ_EHCI, PIRQ_NC, PIRQ_NC, PIRQ_NC } }, |
| 144 | { XHCI_DEVFN, { PIRQ_XHCI, PIRQ_NC, PIRQ_NC, PIRQ_NC } }, |
| 145 | }; |
| 146 | |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 147 | /* PIRQ Setup */ |
| 148 | static void pirq_setup(void) |
| 149 | { |
Richard Spiegel | 9dc5600 | 2017-12-18 16:25:42 -0700 | [diff] [blame] | 150 | pirq_data_ptr = mainboard_pirq_data; |
| 151 | pirq_data_size = ARRAY_SIZE(mainboard_pirq_data); |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 152 | intr_data_ptr = mainboard_intr_data; |
| 153 | picr_data_ptr = mainboard_picr_data; |
| 154 | } |
| 155 | |
Marc Jones | 9ad593b | 2017-06-22 22:19:55 -0600 | [diff] [blame] | 156 | static void mainboard_init(void *chip_info) |
| 157 | { |
Marc Jones | b6ac3a2 | 2017-10-05 21:57:33 -0600 | [diff] [blame] | 158 | const struct sci_source *gpes; |
| 159 | size_t num; |
Marc Jones | 71f7f0a | 2017-11-21 23:29:55 -0700 | [diff] [blame] | 160 | int boardid = board_id(); |
Justin TerAvest | 3fe3f04 | 2018-02-14 19:10:15 -0700 | [diff] [blame] | 161 | size_t num_gpios; |
| 162 | const struct soc_amd_stoneyridge_gpio *gpios; |
Marc Jones | 71f7f0a | 2017-11-21 23:29:55 -0700 | [diff] [blame] | 163 | |
| 164 | printk(BIOS_INFO, "Board ID: %d\n", boardid); |
Marc Jones | b6ac3a2 | 2017-10-05 21:57:33 -0600 | [diff] [blame] | 165 | |
Marc Jones | 9ad593b | 2017-06-22 22:19:55 -0600 | [diff] [blame] | 166 | mainboard_ec_init(); |
Marc Jones | b6ac3a2 | 2017-10-05 21:57:33 -0600 | [diff] [blame] | 167 | |
Justin TerAvest | 3fe3f04 | 2018-02-14 19:10:15 -0700 | [diff] [blame] | 168 | gpios = variant_gpio_table(&num_gpios); |
| 169 | sb_program_gpios(gpios, num_gpios); |
| 170 | |
Marc Jones | b6ac3a2 | 2017-10-05 21:57:33 -0600 | [diff] [blame] | 171 | gpes = get_gpe_table(&num); |
| 172 | gpe_configure_sci(gpes, num); |
Martin Roth | 6c14cd3 | 2018-01-11 16:25:28 -0800 | [diff] [blame] | 173 | |
Daniel Kurtz | f5e3775 | 2018-02-01 15:58:40 -0700 | [diff] [blame] | 174 | /* Initialize i2c busses that were not initialized in bootblock */ |
| 175 | i2c_soc_init(); |
| 176 | |
Martin Roth | 6c14cd3 | 2018-01-11 16:25:28 -0800 | [diff] [blame] | 177 | /* Set GenIntDisable so that GPIO 90 is configured as a GPIO. */ |
| 178 | if (!IS_ENABLED(CONFIG_BOARD_GOOGLE_KAHLEE)) |
| 179 | pm_write8(PM_PCIB_CFG, |
| 180 | pm_read8(PM_PCIB_CFG) | PM_GENINT_DISABLE); |
Marc Jones | 9ad593b | 2017-06-22 22:19:55 -0600 | [diff] [blame] | 181 | } |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 182 | |
| 183 | /************************************************* |
Marshall Dawson | beb1288 | 2017-05-23 18:57:47 -0600 | [diff] [blame] | 184 | * Dedicated mainboard function |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 185 | *************************************************/ |
| 186 | static void kahlee_enable(device_t dev) |
| 187 | { |
| 188 | printk(BIOS_INFO, "Mainboard " |
| 189 | CONFIG_MAINBOARD_PART_NUMBER " Enable.\n"); |
| 190 | |
| 191 | /* Initialize the PIRQ data structures for consumption */ |
| 192 | pirq_setup(); |
Marc Jones | 0a15ed5 | 2017-06-22 22:22:20 -0600 | [diff] [blame] | 193 | |
| 194 | dev->ops->acpi_inject_dsdt_generator = chromeos_dsdt_generator; |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 195 | } |
| 196 | |
Marc Jones | 067031e | 2017-11-02 11:36:53 -0600 | [diff] [blame] | 197 | |
| 198 | static void mainboard_final(void *chip_info) |
| 199 | { |
| 200 | struct global_nvs_t *gnvs; |
| 201 | |
| 202 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 203 | |
| 204 | if (gnvs) { |
| 205 | gnvs->tmps = CTL_TDP_SENSOR_ID; |
| 206 | gnvs->tcrt = CRITICAL_TEMPERATURE; |
| 207 | gnvs->tpsv = PASSIVE_TEMPERATURE; |
| 208 | } |
| 209 | } |
| 210 | |
Marc Jones | df6b51b | 2017-11-29 20:07:46 -0700 | [diff] [blame] | 211 | int mainboard_get_xhci_oc_map(uint16_t *map) |
| 212 | { |
| 213 | return variant_get_xhci_oc_map(map); |
| 214 | } |
| 215 | |
| 216 | int mainboard_get_ehci_oc_map(uint16_t *map) |
| 217 | { |
| 218 | return variant_get_ehci_oc_map(map); |
| 219 | } |
| 220 | |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 221 | struct chip_operations mainboard_ops = { |
Marc Jones | 9ad593b | 2017-06-22 22:19:55 -0600 | [diff] [blame] | 222 | .init = mainboard_init, |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 223 | .enable_dev = kahlee_enable, |
Marc Jones | 067031e | 2017-11-02 11:36:53 -0600 | [diff] [blame] | 224 | .final = mainboard_final, |
Marc Jones | 2d79f16 | 2017-05-22 21:35:16 -0600 | [diff] [blame] | 225 | }; |
Simon Glass | b5c5177 | 2018-03-05 12:18:40 -0700 | [diff] [blame^] | 226 | |
| 227 | /* Variants may override this function so see definitions in variants/ */ |
| 228 | uint8_t __attribute__((weak)) variant_board_sku(void) |
| 229 | { |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | const char *smbios_mainboard_sku(void) |
| 234 | { |
| 235 | static char sku_str[7]; /* sku{0..255} */ |
| 236 | |
| 237 | snprintf(sku_str, sizeof(sku_str), "sku%d", variant_board_sku()); |
| 238 | |
| 239 | return sku_str; |
| 240 | } |