blob: 8efe64feca0de31b035b02094ee9e07c3ee339f0 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Marc Jones1587dc82017-05-15 18:55:11 -06003
Marshall Dawson9db8a442017-09-20 10:24:28 -06004#include <bootstate.h>
5#include <console/console.h>
Marc Jones1587dc82017-05-15 18:55:11 -06006#include <cpu/amd/mtrr.h>
Marc Jones24484842017-05-04 21:17:45 -06007#include <device/device.h>
8#include <device/pci.h>
Justin TerAvest13101a72018-01-24 14:23:12 -07009#include <drivers/i2c/designware/dw_i2c.h>
Marshall Dawson8f2a7e02017-11-01 11:44:48 -060010#include <romstage_handoff.h>
Duncan Laurie32bdffa2018-05-07 15:37:28 -070011#include <soc/acpi.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060012#include <soc/cpu.h>
Marc Jones1587dc82017-05-15 18:55:11 -060013#include <soc/northbridge.h>
Justin TerAvest949d6662018-01-24 14:20:03 -070014#include <soc/pci_devs.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060015#include <soc/southbridge.h>
Marshall Dawsonf5e057c2017-10-12 16:10:14 -060016#include <amdblocks/psp.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -070017#include <amdblocks/agesawrapper.h>
18#include <amdblocks/agesawrapper_call.h>
Marc Jones24484842017-05-04 21:17:45 -060019
Elyes HAOUASc3385072019-03-21 15:38:06 +010020#include "chip.h"
21
Justin TerAvest13101a72018-01-24 14:23:12 -070022/* Supplied by i2c.c */
23extern struct device_operations stoneyridge_i2c_mmio_ops;
24extern const char *i2c_acpi_name(const struct device *dev);
25
Marc Jones1587dc82017-05-15 18:55:11 -060026struct device_operations cpu_bus_ops = {
27 .read_resources = DEVICE_NOOP,
28 .set_resources = DEVICE_NOOP,
29 .enable_resources = DEVICE_NOOP,
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060030 .init = stoney_init_cpus,
Nico Huber68680dd2020-03-31 17:34:52 +020031 .acpi_fill_ssdt = generate_cpu_entries,
Marc Jones24484842017-05-04 21:17:45 -060032};
33
Duncan Laurie32bdffa2018-05-07 15:37:28 -070034const char *soc_acpi_name(const struct device *dev)
Justin TerAvest949d6662018-01-24 14:20:03 -070035{
36 if (dev->path.type == DEVICE_PATH_DOMAIN)
37 return "PCI0";
Duncan Laurie32bdffa2018-05-07 15:37:28 -070038
39 if (dev->path.type == DEVICE_PATH_USB) {
40 switch (dev->path.usb.port_type) {
41 case 0:
42 /* Root Hub */
43 return "RHUB";
44 case 2:
45 /* USB2 ports */
46 switch (dev->path.usb.port_id) {
47 case 0: return "HS01";
48 case 1: return "HS02";
49 case 2: return "HS03";
50 case 3: return "HS04";
51 case 4: return "HS05";
52 case 5: return "HS06";
53 case 6: return "HS07";
54 case 7: return "HS08";
55 }
56 break;
57 case 3:
58 /* USB3 ports */
59 switch (dev->path.usb.port_id) {
60 case 0: return "SS01";
61 case 1: return "SS02";
62 case 2: return "SS03";
63 }
64 break;
65 }
66 return NULL;
67 }
68
Justin TerAvest949d6662018-01-24 14:20:03 -070069 if (dev->path.type != DEVICE_PATH_PCI)
70 return NULL;
71
72 switch (dev->path.pci.devfn) {
Marc Jones6dcb6c22018-07-26 17:07:13 -060073 case GFX_DEVFN:
74 return "IGFX";
Marc Jones9022b9d2018-05-25 20:53:44 -060075 case PCIE0_DEVFN:
76 return "PBR4";
77 case PCIE1_DEVFN:
78 return "PBR5";
79 case PCIE2_DEVFN:
80 return "PBR6";
81 case PCIE3_DEVFN:
82 return "PBR7";
83 case PCIE4_DEVFN:
84 return "PBR8";
85 case HDA1_DEVFN:
86 return "AZHD";
Justin TerAvest949d6662018-01-24 14:20:03 -070087 case EHCI1_DEVFN:
88 return "EHC0";
89 case LPC_DEVFN:
90 return "LPCB";
91 case SATA_DEVFN:
92 return "STCR";
93 case SD_DEVFN:
94 return "SDCN";
95 case SMBUS_DEVFN:
96 return "SBUS";
97 case XHCI_DEVFN:
98 return "XHC0";
99 default:
100 return NULL;
101 }
102};
103
Marc Jones1587dc82017-05-15 18:55:11 -0600104struct device_operations pci_domain_ops = {
Martin Roth3424f382018-10-29 16:19:46 -0600105 .read_resources = pci_domain_read_resources,
Marc Jones1587dc82017-05-15 18:55:11 -0600106 .set_resources = domain_set_resources,
107 .enable_resources = domain_enable_resources,
Marc Jones1587dc82017-05-15 18:55:11 -0600108 .scan_bus = pci_domain_scan_bus,
Justin TerAvest949d6662018-01-24 14:20:03 -0700109 .acpi_name = soc_acpi_name,
Marc Jones24484842017-05-04 21:17:45 -0600110};
111
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200112static void enable_dev(struct device *dev)
Marc Jones24484842017-05-04 21:17:45 -0600113{
114 /* Set the operations if it is a special bus type */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600115 if (dev->path.type == DEVICE_PATH_DOMAIN)
Marc Jones24484842017-05-04 21:17:45 -0600116 dev->ops = &pci_domain_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600117 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
Marc Jones24484842017-05-04 21:17:45 -0600118 dev->ops = &cpu_bus_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600119 else if (dev->path.type == DEVICE_PATH_PCI)
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600120 sb_enable(dev);
Justin TerAvest13101a72018-01-24 14:23:12 -0700121 else if (dev->path.type == DEVICE_PATH_MMIO)
122 if (i2c_acpi_name(dev) != NULL)
123 dev->ops = &stoneyridge_i2c_mmio_ops;
Marc Jones24484842017-05-04 21:17:45 -0600124}
125
126static void soc_init(void *chip_info)
127{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600128 southbridge_init(chip_info);
Richard Spiegel9d0921b2017-12-19 10:24:50 -0700129 setup_bsp_ramtop();
Marc Jones24484842017-05-04 21:17:45 -0600130}
131
132static void soc_final(void *chip_info)
133{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600134 southbridge_final(chip_info);
Marc Jones1587dc82017-05-15 18:55:11 -0600135 fam15_finalize(chip_info);
Marc Jones24484842017-05-04 21:17:45 -0600136}
137
138struct chip_operations soc_amd_stoneyridge_ops = {
139 CHIP_NAME("AMD StoneyRidge SOC")
Elyes HAOUAS1d191272018-11-27 12:23:48 +0100140 .enable_dev = enable_dev,
141 .init = soc_init,
142 .final = soc_final
Marc Jones24484842017-05-04 21:17:45 -0600143};
Marshall Dawson9db8a442017-09-20 10:24:28 -0600144
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600145static void earliest_ramstage(void *unused)
Marshall Dawson9db8a442017-09-20 10:24:28 -0600146{
Kyösti Mälkkia8eb4772018-06-28 17:23:27 +0300147 int s3_resume = acpi_s3_resume_allowed() &&
148 romstage_handoff_is_resume();
149 if (!s3_resume) {
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600150 post_code(0x46);
Julius Wernercd49cce2019-03-05 16:53:33 -0800151 if (CONFIG(SOC_AMD_PSP_SELECTABLE_SMU_FW))
Marshall Dawson737e56a2020-01-19 16:32:08 -0700152 psp_load_named_blob(BLOB_SMU_FW2, "smu_fw2");
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600153
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600154 post_code(0x47);
Kyösti Mälkki6e512c42018-06-14 06:57:05 +0300155 do_agesawrapper(AMD_INIT_ENV, "amdinitenv");
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600156 } else {
157 /* Complete the initial system restoration */
158 post_code(0x46);
Kyösti Mälkki6e512c42018-06-14 06:57:05 +0300159 do_agesawrapper(AMD_S3LATE_RESTORE, "amds3laterestore");
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600160 }
Marshall Dawson9db8a442017-09-20 10:24:28 -0600161}
162
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600163BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, earliest_ramstage, NULL);