Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 2 | |
Marshall Dawson | 9db8a44 | 2017-09-20 10:24:28 -0600 | [diff] [blame] | 3 | #include <bootstate.h> |
| 4 | #include <console/console.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 5 | #include <cpu/amd/mtrr.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 6 | #include <device/device.h> |
| 7 | #include <device/pci.h> |
Justin TerAvest | 13101a7 | 2018-01-24 14:23:12 -0700 | [diff] [blame] | 8 | #include <drivers/i2c/designware/dw_i2c.h> |
Duncan Laurie | 32bdffa | 2018-05-07 15:37:28 -0700 | [diff] [blame] | 9 | #include <soc/acpi.h> |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 10 | #include <soc/cpu.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 11 | #include <soc/northbridge.h> |
Justin TerAvest | 949d666 | 2018-01-24 14:20:03 -0700 | [diff] [blame] | 12 | #include <soc/pci_devs.h> |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 13 | #include <soc/southbridge.h> |
Marshall Dawson | f5e057c | 2017-10-12 16:10:14 -0600 | [diff] [blame] | 14 | #include <amdblocks/psp.h> |
Richard Spiegel | 0ad74ac | 2017-12-08 16:53:29 -0700 | [diff] [blame] | 15 | #include <amdblocks/agesawrapper.h> |
| 16 | #include <amdblocks/agesawrapper_call.h> |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame^] | 17 | #include <amdblocks/i2c.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 18 | |
Elyes HAOUAS | c338507 | 2019-03-21 15:38:06 +0100 | [diff] [blame] | 19 | #include "chip.h" |
| 20 | |
Justin TerAvest | 13101a7 | 2018-01-24 14:23:12 -0700 | [diff] [blame] | 21 | /* Supplied by i2c.c */ |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame^] | 22 | extern struct device_operations soc_amd_i2c_mmio_ops; |
Justin TerAvest | 13101a7 | 2018-01-24 14:23:12 -0700 | [diff] [blame] | 23 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 24 | struct device_operations cpu_bus_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 25 | .read_resources = noop_read_resources, |
| 26 | .set_resources = noop_set_resources, |
Kyösti Mälkki | 79e12ab | 2020-05-31 09:21:07 +0300 | [diff] [blame] | 27 | .init = mp_cpu_bus_init, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 28 | .acpi_fill_ssdt = generate_cpu_entries, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 29 | }; |
| 30 | |
Duncan Laurie | 32bdffa | 2018-05-07 15:37:28 -0700 | [diff] [blame] | 31 | const char *soc_acpi_name(const struct device *dev) |
Justin TerAvest | 949d666 | 2018-01-24 14:20:03 -0700 | [diff] [blame] | 32 | { |
| 33 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 34 | return "PCI0"; |
Duncan Laurie | 32bdffa | 2018-05-07 15:37:28 -0700 | [diff] [blame] | 35 | |
| 36 | if (dev->path.type == DEVICE_PATH_USB) { |
| 37 | switch (dev->path.usb.port_type) { |
| 38 | case 0: |
| 39 | /* Root Hub */ |
| 40 | return "RHUB"; |
| 41 | case 2: |
| 42 | /* USB2 ports */ |
| 43 | switch (dev->path.usb.port_id) { |
| 44 | case 0: return "HS01"; |
| 45 | case 1: return "HS02"; |
| 46 | case 2: return "HS03"; |
| 47 | case 3: return "HS04"; |
| 48 | case 4: return "HS05"; |
| 49 | case 5: return "HS06"; |
| 50 | case 6: return "HS07"; |
| 51 | case 7: return "HS08"; |
| 52 | } |
| 53 | break; |
| 54 | case 3: |
| 55 | /* USB3 ports */ |
| 56 | switch (dev->path.usb.port_id) { |
| 57 | case 0: return "SS01"; |
| 58 | case 1: return "SS02"; |
| 59 | case 2: return "SS03"; |
| 60 | } |
| 61 | break; |
| 62 | } |
| 63 | return NULL; |
| 64 | } |
| 65 | |
Justin TerAvest | 949d666 | 2018-01-24 14:20:03 -0700 | [diff] [blame] | 66 | if (dev->path.type != DEVICE_PATH_PCI) |
| 67 | return NULL; |
| 68 | |
| 69 | switch (dev->path.pci.devfn) { |
Marc Jones | 6dcb6c2 | 2018-07-26 17:07:13 -0600 | [diff] [blame] | 70 | case GFX_DEVFN: |
| 71 | return "IGFX"; |
Marc Jones | 9022b9d | 2018-05-25 20:53:44 -0600 | [diff] [blame] | 72 | case PCIE0_DEVFN: |
| 73 | return "PBR4"; |
| 74 | case PCIE1_DEVFN: |
| 75 | return "PBR5"; |
| 76 | case PCIE2_DEVFN: |
| 77 | return "PBR6"; |
| 78 | case PCIE3_DEVFN: |
| 79 | return "PBR7"; |
| 80 | case PCIE4_DEVFN: |
| 81 | return "PBR8"; |
Justin TerAvest | 949d666 | 2018-01-24 14:20:03 -0700 | [diff] [blame] | 82 | case EHCI1_DEVFN: |
| 83 | return "EHC0"; |
Justin TerAvest | 949d666 | 2018-01-24 14:20:03 -0700 | [diff] [blame] | 84 | case SD_DEVFN: |
| 85 | return "SDCN"; |
Justin TerAvest | 949d666 | 2018-01-24 14:20:03 -0700 | [diff] [blame] | 86 | case XHCI_DEVFN: |
| 87 | return "XHC0"; |
| 88 | default: |
| 89 | return NULL; |
| 90 | } |
| 91 | }; |
| 92 | |
Felix Held | d28e159 | 2020-12-05 02:13:10 +0100 | [diff] [blame] | 93 | static struct device_operations pci_domain_ops = { |
Furquan Shaikh | fc752b6 | 2020-05-13 12:14:11 -0700 | [diff] [blame] | 94 | .read_resources = domain_read_resources, |
| 95 | .set_resources = pci_domain_set_resources, |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 96 | .enable_resources = domain_enable_resources, |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 97 | .scan_bus = pci_domain_scan_bus, |
Justin TerAvest | 949d666 | 2018-01-24 14:20:03 -0700 | [diff] [blame] | 98 | .acpi_name = soc_acpi_name, |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 99 | }; |
| 100 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame^] | 101 | static void set_mmio_dev_ops(struct device *dev) |
| 102 | { |
| 103 | switch (dev->path.mmio.addr) { |
| 104 | case I2CA_BASE_ADDRESS: |
| 105 | case I2CB_BASE_ADDRESS: |
| 106 | case I2CC_BASE_ADDRESS: |
| 107 | case I2CD_BASE_ADDRESS: |
| 108 | dev->ops = &soc_amd_i2c_mmio_ops; |
| 109 | break; |
| 110 | } |
| 111 | } |
| 112 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 113 | static void enable_dev(struct device *dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 114 | { |
| 115 | /* Set the operations if it is a special bus type */ |
Felix Held | 237bc2ef | 2021-02-09 16:46:14 +0100 | [diff] [blame] | 116 | switch (dev->path.type) { |
| 117 | case DEVICE_PATH_DOMAIN: |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 118 | dev->ops = &pci_domain_ops; |
Felix Held | 237bc2ef | 2021-02-09 16:46:14 +0100 | [diff] [blame] | 119 | break; |
| 120 | case DEVICE_PATH_CPU_CLUSTER: |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 121 | dev->ops = &cpu_bus_ops; |
Felix Held | 237bc2ef | 2021-02-09 16:46:14 +0100 | [diff] [blame] | 122 | break; |
Felix Held | 237bc2ef | 2021-02-09 16:46:14 +0100 | [diff] [blame] | 123 | case DEVICE_PATH_MMIO: |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame^] | 124 | set_mmio_dev_ops(dev); |
Felix Held | 237bc2ef | 2021-02-09 16:46:14 +0100 | [diff] [blame] | 125 | break; |
| 126 | default: |
| 127 | break; |
| 128 | } |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static void soc_init(void *chip_info) |
| 132 | { |
Felix Held | a21690b | 2021-01-29 16:01:10 +0100 | [diff] [blame] | 133 | fch_init(chip_info); |
Richard Spiegel | 9d0921b | 2017-12-19 10:24:50 -0700 | [diff] [blame] | 134 | setup_bsp_ramtop(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static void soc_final(void *chip_info) |
| 138 | { |
Felix Held | a21690b | 2021-01-29 16:01:10 +0100 | [diff] [blame] | 139 | fch_final(chip_info); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 140 | fam15_finalize(chip_info); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | struct chip_operations soc_amd_stoneyridge_ops = { |
| 144 | CHIP_NAME("AMD StoneyRidge SOC") |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 145 | .enable_dev = enable_dev, |
| 146 | .init = soc_init, |
| 147 | .final = soc_final |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 148 | }; |
Marshall Dawson | 9db8a44 | 2017-09-20 10:24:28 -0600 | [diff] [blame] | 149 | |
Marshall Dawson | f5e057c | 2017-10-12 16:10:14 -0600 | [diff] [blame] | 150 | static void earliest_ramstage(void *unused) |
Marshall Dawson | 9db8a44 | 2017-09-20 10:24:28 -0600 | [diff] [blame] | 151 | { |
Kyösti Mälkki | 9e591c4 | 2021-01-09 12:37:25 +0200 | [diff] [blame] | 152 | if (!acpi_is_wakeup_s3()) { |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 153 | post_code(0x46); |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 154 | if (CONFIG(SOC_AMD_PSP_SELECTABLE_SMU_FW)) |
Marshall Dawson | 737e56a | 2020-01-19 16:32:08 -0700 | [diff] [blame] | 155 | psp_load_named_blob(BLOB_SMU_FW2, "smu_fw2"); |
Marshall Dawson | f5e057c | 2017-10-12 16:10:14 -0600 | [diff] [blame] | 156 | |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 157 | post_code(0x47); |
Kyösti Mälkki | 6e512c4 | 2018-06-14 06:57:05 +0300 | [diff] [blame] | 158 | do_agesawrapper(AMD_INIT_ENV, "amdinitenv"); |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 159 | } else { |
| 160 | /* Complete the initial system restoration */ |
| 161 | post_code(0x46); |
Kyösti Mälkki | 6e512c4 | 2018-06-14 06:57:05 +0300 | [diff] [blame] | 162 | do_agesawrapper(AMD_S3LATE_RESTORE, "amds3laterestore"); |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 163 | } |
Marshall Dawson | 9db8a44 | 2017-09-20 10:24:28 -0600 | [diff] [blame] | 164 | } |
| 165 | |
Marshall Dawson | f5e057c | 2017-10-12 16:10:14 -0600 | [diff] [blame] | 166 | BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, earliest_ramstage, NULL); |