Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2017 Advanced Micro Devices, Inc. |
| 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 | */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 15 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 16 | #include <chip.h> |
Marshall Dawson | 9db8a44 | 2017-09-20 10:24:28 -0600 | [diff] [blame] | 17 | #include <bootstate.h> |
| 18 | #include <console/console.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 19 | #include <cpu/amd/mtrr.h> |
| 20 | #include <cpu/cpu.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 21 | #include <device/device.h> |
| 22 | #include <device/pci.h> |
Justin TerAvest | 13101a7 | 2018-01-24 14:23:12 -0700 | [diff] [blame] | 23 | #include <drivers/i2c/designware/dw_i2c.h> |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 24 | #include <romstage_handoff.h> |
Duncan Laurie | 32bdffa | 2018-05-07 15:37:28 -0700 | [diff] [blame] | 25 | #include <soc/acpi.h> |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 26 | #include <soc/cpu.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 27 | #include <soc/northbridge.h> |
Justin TerAvest | 949d666 | 2018-01-24 14:20:03 -0700 | [diff] [blame] | 28 | #include <soc/pci_devs.h> |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 29 | #include <soc/southbridge.h> |
Marshall Dawson | f5e057c | 2017-10-12 16:10:14 -0600 | [diff] [blame] | 30 | #include <amdblocks/psp.h> |
Richard Spiegel | 0ad74ac | 2017-12-08 16:53:29 -0700 | [diff] [blame] | 31 | #include <amdblocks/agesawrapper.h> |
| 32 | #include <amdblocks/agesawrapper_call.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 33 | |
Justin TerAvest | 13101a7 | 2018-01-24 14:23:12 -0700 | [diff] [blame] | 34 | /* Supplied by i2c.c */ |
| 35 | extern struct device_operations stoneyridge_i2c_mmio_ops; |
| 36 | extern const char *i2c_acpi_name(const struct device *dev); |
| 37 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 38 | struct device_operations cpu_bus_ops = { |
| 39 | .read_resources = DEVICE_NOOP, |
| 40 | .set_resources = DEVICE_NOOP, |
| 41 | .enable_resources = DEVICE_NOOP, |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 42 | .init = stoney_init_cpus, |
Marc Jones | 6bfcf66 | 2017-08-06 17:42:35 -0600 | [diff] [blame] | 43 | .acpi_fill_ssdt_generator = generate_cpu_entries, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 44 | }; |
| 45 | |
Duncan Laurie | 32bdffa | 2018-05-07 15:37:28 -0700 | [diff] [blame] | 46 | const char *soc_acpi_name(const struct device *dev) |
Justin TerAvest | 949d666 | 2018-01-24 14:20:03 -0700 | [diff] [blame] | 47 | { |
| 48 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 49 | return "PCI0"; |
Duncan Laurie | 32bdffa | 2018-05-07 15:37:28 -0700 | [diff] [blame] | 50 | |
| 51 | if (dev->path.type == DEVICE_PATH_USB) { |
| 52 | switch (dev->path.usb.port_type) { |
| 53 | case 0: |
| 54 | /* Root Hub */ |
| 55 | return "RHUB"; |
| 56 | case 2: |
| 57 | /* USB2 ports */ |
| 58 | switch (dev->path.usb.port_id) { |
| 59 | case 0: return "HS01"; |
| 60 | case 1: return "HS02"; |
| 61 | case 2: return "HS03"; |
| 62 | case 3: return "HS04"; |
| 63 | case 4: return "HS05"; |
| 64 | case 5: return "HS06"; |
| 65 | case 6: return "HS07"; |
| 66 | case 7: return "HS08"; |
| 67 | } |
| 68 | break; |
| 69 | case 3: |
| 70 | /* USB3 ports */ |
| 71 | switch (dev->path.usb.port_id) { |
| 72 | case 0: return "SS01"; |
| 73 | case 1: return "SS02"; |
| 74 | case 2: return "SS03"; |
| 75 | } |
| 76 | break; |
| 77 | } |
| 78 | return NULL; |
| 79 | } |
| 80 | |
Justin TerAvest | 949d666 | 2018-01-24 14:20:03 -0700 | [diff] [blame] | 81 | if (dev->path.type != DEVICE_PATH_PCI) |
| 82 | return NULL; |
| 83 | |
| 84 | switch (dev->path.pci.devfn) { |
| 85 | case EHCI1_DEVFN: |
| 86 | return "EHC0"; |
| 87 | case LPC_DEVFN: |
| 88 | return "LPCB"; |
| 89 | case SATA_DEVFN: |
| 90 | return "STCR"; |
| 91 | case SD_DEVFN: |
| 92 | return "SDCN"; |
| 93 | case SMBUS_DEVFN: |
| 94 | return "SBUS"; |
| 95 | case XHCI_DEVFN: |
| 96 | return "XHC0"; |
| 97 | default: |
| 98 | return NULL; |
| 99 | } |
| 100 | }; |
| 101 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 102 | struct device_operations pci_domain_ops = { |
| 103 | .read_resources = domain_read_resources, |
| 104 | .set_resources = domain_set_resources, |
| 105 | .enable_resources = domain_enable_resources, |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 106 | .scan_bus = pci_domain_scan_bus, |
Justin TerAvest | 949d666 | 2018-01-24 14:20:03 -0700 | [diff] [blame] | 107 | .acpi_name = soc_acpi_name, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 108 | }; |
| 109 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame^] | 110 | static void enable_dev(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 111 | { |
| 112 | /* Set the operations if it is a special bus type */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 113 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 114 | dev->ops = &pci_domain_ops; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 115 | else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 116 | dev->ops = &cpu_bus_ops; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 117 | else if (dev->path.type == DEVICE_PATH_PCI) |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 118 | sb_enable(dev); |
Justin TerAvest | 13101a7 | 2018-01-24 14:23:12 -0700 | [diff] [blame] | 119 | else if (dev->path.type == DEVICE_PATH_MMIO) |
| 120 | if (i2c_acpi_name(dev) != NULL) |
| 121 | dev->ops = &stoneyridge_i2c_mmio_ops; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static void soc_init(void *chip_info) |
| 125 | { |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 126 | southbridge_init(chip_info); |
Richard Spiegel | 9d0921b | 2017-12-19 10:24:50 -0700 | [diff] [blame] | 127 | setup_bsp_ramtop(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static void soc_final(void *chip_info) |
| 131 | { |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 132 | southbridge_final(chip_info); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 133 | fam15_finalize(chip_info); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | struct chip_operations soc_amd_stoneyridge_ops = { |
| 137 | CHIP_NAME("AMD StoneyRidge SOC") |
| 138 | .enable_dev = &enable_dev, |
| 139 | .init = &soc_init, |
| 140 | .final = &soc_final |
| 141 | }; |
Marshall Dawson | 9db8a44 | 2017-09-20 10:24:28 -0600 | [diff] [blame] | 142 | |
Marshall Dawson | f5e057c | 2017-10-12 16:10:14 -0600 | [diff] [blame] | 143 | static void earliest_ramstage(void *unused) |
Marshall Dawson | 9db8a44 | 2017-09-20 10:24:28 -0600 | [diff] [blame] | 144 | { |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 145 | if (!romstage_handoff_is_resume()) { |
| 146 | post_code(0x46); |
| 147 | if (IS_ENABLED(CONFIG_SOC_AMD_PSP_SELECTABLE_SMU_FW)) |
| 148 | psp_load_named_blob(MBOX_BIOS_CMD_SMU_FW2, "smu_fw2"); |
Marshall Dawson | f5e057c | 2017-10-12 16:10:14 -0600 | [diff] [blame] | 149 | |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 150 | post_code(0x47); |
| 151 | do_agesawrapper(agesawrapper_amdinitenv, "amdinitenv"); |
| 152 | } else { |
| 153 | /* Complete the initial system restoration */ |
| 154 | post_code(0x46); |
| 155 | do_agesawrapper(agesawrapper_amds3laterestore, |
| 156 | "amds3laterestore"); |
| 157 | } |
Marshall Dawson | 9db8a44 | 2017-09-20 10:24:28 -0600 | [diff] [blame] | 158 | } |
| 159 | |
Marshall Dawson | f5e057c | 2017-10-12 16:10:14 -0600 | [diff] [blame] | 160 | BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, earliest_ramstage, NULL); |