blob: 189f48e8e9b1e38270586967dc8b2ea0d91cb194 [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 = {
Nico Huber2f8ba692020-04-05 14:05:24 +020027 .read_resources = noop_read_resources,
28 .set_resources = noop_set_resources,
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060029 .init = stoney_init_cpus,
Nico Huber68680dd2020-03-31 17:34:52 +020030 .acpi_fill_ssdt = generate_cpu_entries,
Marc Jones24484842017-05-04 21:17:45 -060031};
32
Duncan Laurie32bdffa2018-05-07 15:37:28 -070033const char *soc_acpi_name(const struct device *dev)
Justin TerAvest949d6662018-01-24 14:20:03 -070034{
35 if (dev->path.type == DEVICE_PATH_DOMAIN)
36 return "PCI0";
Duncan Laurie32bdffa2018-05-07 15:37:28 -070037
38 if (dev->path.type == DEVICE_PATH_USB) {
39 switch (dev->path.usb.port_type) {
40 case 0:
41 /* Root Hub */
42 return "RHUB";
43 case 2:
44 /* USB2 ports */
45 switch (dev->path.usb.port_id) {
46 case 0: return "HS01";
47 case 1: return "HS02";
48 case 2: return "HS03";
49 case 3: return "HS04";
50 case 4: return "HS05";
51 case 5: return "HS06";
52 case 6: return "HS07";
53 case 7: return "HS08";
54 }
55 break;
56 case 3:
57 /* USB3 ports */
58 switch (dev->path.usb.port_id) {
59 case 0: return "SS01";
60 case 1: return "SS02";
61 case 2: return "SS03";
62 }
63 break;
64 }
65 return NULL;
66 }
67
Justin TerAvest949d6662018-01-24 14:20:03 -070068 if (dev->path.type != DEVICE_PATH_PCI)
69 return NULL;
70
71 switch (dev->path.pci.devfn) {
Marc Jones6dcb6c22018-07-26 17:07:13 -060072 case GFX_DEVFN:
73 return "IGFX";
Marc Jones9022b9d2018-05-25 20:53:44 -060074 case PCIE0_DEVFN:
75 return "PBR4";
76 case PCIE1_DEVFN:
77 return "PBR5";
78 case PCIE2_DEVFN:
79 return "PBR6";
80 case PCIE3_DEVFN:
81 return "PBR7";
82 case PCIE4_DEVFN:
83 return "PBR8";
84 case HDA1_DEVFN:
85 return "AZHD";
Justin TerAvest949d6662018-01-24 14:20:03 -070086 case EHCI1_DEVFN:
87 return "EHC0";
88 case LPC_DEVFN:
89 return "LPCB";
90 case SATA_DEVFN:
91 return "STCR";
92 case SD_DEVFN:
93 return "SDCN";
94 case SMBUS_DEVFN:
95 return "SBUS";
96 case XHCI_DEVFN:
97 return "XHC0";
98 default:
99 return NULL;
100 }
101};
102
Marc Jones1587dc82017-05-15 18:55:11 -0600103struct device_operations pci_domain_ops = {
Martin Roth3424f382018-10-29 16:19:46 -0600104 .read_resources = pci_domain_read_resources,
Marc Jones1587dc82017-05-15 18:55:11 -0600105 .set_resources = domain_set_resources,
106 .enable_resources = domain_enable_resources,
Marc Jones1587dc82017-05-15 18:55:11 -0600107 .scan_bus = pci_domain_scan_bus,
Justin TerAvest949d6662018-01-24 14:20:03 -0700108 .acpi_name = soc_acpi_name,
Marc Jones24484842017-05-04 21:17:45 -0600109};
110
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200111static void enable_dev(struct device *dev)
Marc Jones24484842017-05-04 21:17:45 -0600112{
113 /* Set the operations if it is a special bus type */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600114 if (dev->path.type == DEVICE_PATH_DOMAIN)
Marc Jones24484842017-05-04 21:17:45 -0600115 dev->ops = &pci_domain_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600116 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
Marc Jones24484842017-05-04 21:17:45 -0600117 dev->ops = &cpu_bus_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600118 else if (dev->path.type == DEVICE_PATH_PCI)
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600119 sb_enable(dev);
Justin TerAvest13101a72018-01-24 14:23:12 -0700120 else if (dev->path.type == DEVICE_PATH_MMIO)
121 if (i2c_acpi_name(dev) != NULL)
122 dev->ops = &stoneyridge_i2c_mmio_ops;
Marc Jones24484842017-05-04 21:17:45 -0600123}
124
125static void soc_init(void *chip_info)
126{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600127 southbridge_init(chip_info);
Richard Spiegel9d0921b2017-12-19 10:24:50 -0700128 setup_bsp_ramtop();
Marc Jones24484842017-05-04 21:17:45 -0600129}
130
131static void soc_final(void *chip_info)
132{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600133 southbridge_final(chip_info);
Marc Jones1587dc82017-05-15 18:55:11 -0600134 fam15_finalize(chip_info);
Marc Jones24484842017-05-04 21:17:45 -0600135}
136
137struct chip_operations soc_amd_stoneyridge_ops = {
138 CHIP_NAME("AMD StoneyRidge SOC")
Elyes HAOUAS1d191272018-11-27 12:23:48 +0100139 .enable_dev = enable_dev,
140 .init = soc_init,
141 .final = soc_final
Marc Jones24484842017-05-04 21:17:45 -0600142};
Marshall Dawson9db8a442017-09-20 10:24:28 -0600143
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600144static void earliest_ramstage(void *unused)
Marshall Dawson9db8a442017-09-20 10:24:28 -0600145{
Kyösti Mälkkia8eb4772018-06-28 17:23:27 +0300146 int s3_resume = acpi_s3_resume_allowed() &&
147 romstage_handoff_is_resume();
148 if (!s3_resume) {
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600149 post_code(0x46);
Julius Wernercd49cce2019-03-05 16:53:33 -0800150 if (CONFIG(SOC_AMD_PSP_SELECTABLE_SMU_FW))
Marshall Dawson737e56a2020-01-19 16:32:08 -0700151 psp_load_named_blob(BLOB_SMU_FW2, "smu_fw2");
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600152
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600153 post_code(0x47);
Kyösti Mälkki6e512c42018-06-14 06:57:05 +0300154 do_agesawrapper(AMD_INIT_ENV, "amdinitenv");
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600155 } else {
156 /* Complete the initial system restoration */
157 post_code(0x46);
Kyösti Mälkki6e512c42018-06-14 06:57:05 +0300158 do_agesawrapper(AMD_S3LATE_RESTORE, "amds3laterestore");
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600159 }
Marshall Dawson9db8a442017-09-20 10:24:28 -0600160}
161
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600162BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, earliest_ramstage, NULL);