blob: e8bc71a4c87b2490ff64fae14527aa36dc47188a [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marc Jones1587dc82017-05-15 18:55:11 -06002
Marshall Dawson9db8a442017-09-20 10:24:28 -06003#include <bootstate.h>
4#include <console/console.h>
Marc Jones1587dc82017-05-15 18:55:11 -06005#include <cpu/amd/mtrr.h>
Marc Jones24484842017-05-04 21:17:45 -06006#include <device/device.h>
7#include <device/pci.h>
Justin TerAvest13101a72018-01-24 14:23:12 -07008#include <drivers/i2c/designware/dw_i2c.h>
Marshall Dawson8f2a7e02017-11-01 11:44:48 -06009#include <romstage_handoff.h>
Duncan Laurie32bdffa2018-05-07 15:37:28 -070010#include <soc/acpi.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060011#include <soc/cpu.h>
Marc Jones1587dc82017-05-15 18:55:11 -060012#include <soc/northbridge.h>
Justin TerAvest949d6662018-01-24 14:20:03 -070013#include <soc/pci_devs.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060014#include <soc/southbridge.h>
Marshall Dawsonf5e057c2017-10-12 16:10:14 -060015#include <amdblocks/psp.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -070016#include <amdblocks/agesawrapper.h>
17#include <amdblocks/agesawrapper_call.h>
Marc Jones24484842017-05-04 21:17:45 -060018
Elyes HAOUASc3385072019-03-21 15:38:06 +010019#include "chip.h"
20
Justin TerAvest13101a72018-01-24 14:23:12 -070021/* Supplied by i2c.c */
22extern struct device_operations stoneyridge_i2c_mmio_ops;
23extern const char *i2c_acpi_name(const struct device *dev);
24
Marc Jones1587dc82017-05-15 18:55:11 -060025struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +020026 .read_resources = noop_read_resources,
27 .set_resources = noop_set_resources,
Kyösti Mälkki79e12ab2020-05-31 09:21:07 +030028 .init = mp_cpu_bus_init,
Nico Huber68680dd2020-03-31 17:34:52 +020029 .acpi_fill_ssdt = generate_cpu_entries,
Marc Jones24484842017-05-04 21:17:45 -060030};
31
Duncan Laurie32bdffa2018-05-07 15:37:28 -070032const char *soc_acpi_name(const struct device *dev)
Justin TerAvest949d6662018-01-24 14:20:03 -070033{
34 if (dev->path.type == DEVICE_PATH_DOMAIN)
35 return "PCI0";
Duncan Laurie32bdffa2018-05-07 15:37:28 -070036
37 if (dev->path.type == DEVICE_PATH_USB) {
38 switch (dev->path.usb.port_type) {
39 case 0:
40 /* Root Hub */
41 return "RHUB";
42 case 2:
43 /* USB2 ports */
44 switch (dev->path.usb.port_id) {
45 case 0: return "HS01";
46 case 1: return "HS02";
47 case 2: return "HS03";
48 case 3: return "HS04";
49 case 4: return "HS05";
50 case 5: return "HS06";
51 case 6: return "HS07";
52 case 7: return "HS08";
53 }
54 break;
55 case 3:
56 /* USB3 ports */
57 switch (dev->path.usb.port_id) {
58 case 0: return "SS01";
59 case 1: return "SS02";
60 case 2: return "SS03";
61 }
62 break;
63 }
64 return NULL;
65 }
66
Justin TerAvest949d6662018-01-24 14:20:03 -070067 if (dev->path.type != DEVICE_PATH_PCI)
68 return NULL;
69
70 switch (dev->path.pci.devfn) {
Marc Jones6dcb6c22018-07-26 17:07:13 -060071 case GFX_DEVFN:
72 return "IGFX";
Marc Jones9022b9d2018-05-25 20:53:44 -060073 case PCIE0_DEVFN:
74 return "PBR4";
75 case PCIE1_DEVFN:
76 return "PBR5";
77 case PCIE2_DEVFN:
78 return "PBR6";
79 case PCIE3_DEVFN:
80 return "PBR7";
81 case PCIE4_DEVFN:
82 return "PBR8";
Justin TerAvest949d6662018-01-24 14:20:03 -070083 case EHCI1_DEVFN:
84 return "EHC0";
85 case LPC_DEVFN:
86 return "LPCB";
Justin TerAvest949d6662018-01-24 14:20:03 -070087 case SD_DEVFN:
88 return "SDCN";
89 case SMBUS_DEVFN:
90 return "SBUS";
91 case XHCI_DEVFN:
92 return "XHC0";
93 default:
94 return NULL;
95 }
96};
97
Felix Heldd28e1592020-12-05 02:13:10 +010098static struct device_operations pci_domain_ops = {
Furquan Shaikhfc752b62020-05-13 12:14:11 -070099 .read_resources = domain_read_resources,
100 .set_resources = pci_domain_set_resources,
Marc Jones1587dc82017-05-15 18:55:11 -0600101 .enable_resources = domain_enable_resources,
Marc Jones1587dc82017-05-15 18:55:11 -0600102 .scan_bus = pci_domain_scan_bus,
Justin TerAvest949d6662018-01-24 14:20:03 -0700103 .acpi_name = soc_acpi_name,
Marc Jones24484842017-05-04 21:17:45 -0600104};
105
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200106static void enable_dev(struct device *dev)
Marc Jones24484842017-05-04 21:17:45 -0600107{
108 /* Set the operations if it is a special bus type */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600109 if (dev->path.type == DEVICE_PATH_DOMAIN)
Marc Jones24484842017-05-04 21:17:45 -0600110 dev->ops = &pci_domain_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600111 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
Marc Jones24484842017-05-04 21:17:45 -0600112 dev->ops = &cpu_bus_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600113 else if (dev->path.type == DEVICE_PATH_PCI)
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600114 sb_enable(dev);
Justin TerAvest13101a72018-01-24 14:23:12 -0700115 else if (dev->path.type == DEVICE_PATH_MMIO)
116 if (i2c_acpi_name(dev) != NULL)
117 dev->ops = &stoneyridge_i2c_mmio_ops;
Marc Jones24484842017-05-04 21:17:45 -0600118}
119
120static void soc_init(void *chip_info)
121{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600122 southbridge_init(chip_info);
Richard Spiegel9d0921b2017-12-19 10:24:50 -0700123 setup_bsp_ramtop();
Marc Jones24484842017-05-04 21:17:45 -0600124}
125
126static void soc_final(void *chip_info)
127{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600128 southbridge_final(chip_info);
Marc Jones1587dc82017-05-15 18:55:11 -0600129 fam15_finalize(chip_info);
Marc Jones24484842017-05-04 21:17:45 -0600130}
131
132struct chip_operations soc_amd_stoneyridge_ops = {
133 CHIP_NAME("AMD StoneyRidge SOC")
Elyes HAOUAS1d191272018-11-27 12:23:48 +0100134 .enable_dev = enable_dev,
135 .init = soc_init,
136 .final = soc_final
Marc Jones24484842017-05-04 21:17:45 -0600137};
Marshall Dawson9db8a442017-09-20 10:24:28 -0600138
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600139static void earliest_ramstage(void *unused)
Marshall Dawson9db8a442017-09-20 10:24:28 -0600140{
Kyösti Mälkkia8eb4772018-06-28 17:23:27 +0300141 int s3_resume = acpi_s3_resume_allowed() &&
142 romstage_handoff_is_resume();
143 if (!s3_resume) {
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600144 post_code(0x46);
Julius Wernercd49cce2019-03-05 16:53:33 -0800145 if (CONFIG(SOC_AMD_PSP_SELECTABLE_SMU_FW))
Marshall Dawson737e56a2020-01-19 16:32:08 -0700146 psp_load_named_blob(BLOB_SMU_FW2, "smu_fw2");
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600147
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600148 post_code(0x47);
Kyösti Mälkki6e512c42018-06-14 06:57:05 +0300149 do_agesawrapper(AMD_INIT_ENV, "amdinitenv");
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600150 } else {
151 /* Complete the initial system restoration */
152 post_code(0x46);
Kyösti Mälkki6e512c42018-06-14 06:57:05 +0300153 do_agesawrapper(AMD_S3LATE_RESTORE, "amds3laterestore");
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600154 }
Marshall Dawson9db8a442017-09-20 10:24:28 -0600155}
156
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600157BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, earliest_ramstage, NULL);