blob: 033af6ec2116156d49177daea601f668301358a9 [file] [log] [blame]
Marc Jones24484842017-05-04 21:17:45 -06001/*
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 Jones1587dc82017-05-15 18:55:11 -060015
Marc Jones24484842017-05-04 21:17:45 -060016#include <chip.h>
Marshall Dawson9db8a442017-09-20 10:24:28 -060017#include <bootstate.h>
18#include <console/console.h>
Marc Jones1587dc82017-05-15 18:55:11 -060019#include <cpu/amd/mtrr.h>
Marc Jones24484842017-05-04 21:17:45 -060020#include <device/device.h>
21#include <device/pci.h>
Justin TerAvest13101a72018-01-24 14:23:12 -070022#include <drivers/i2c/designware/dw_i2c.h>
Marshall Dawson8f2a7e02017-11-01 11:44:48 -060023#include <romstage_handoff.h>
Duncan Laurie32bdffa2018-05-07 15:37:28 -070024#include <soc/acpi.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060025#include <soc/cpu.h>
Marc Jones1587dc82017-05-15 18:55:11 -060026#include <soc/northbridge.h>
Justin TerAvest949d6662018-01-24 14:20:03 -070027#include <soc/pci_devs.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060028#include <soc/southbridge.h>
Marshall Dawsonf5e057c2017-10-12 16:10:14 -060029#include <amdblocks/psp.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -070030#include <amdblocks/agesawrapper.h>
31#include <amdblocks/agesawrapper_call.h>
Marc Jones24484842017-05-04 21:17:45 -060032
Justin TerAvest13101a72018-01-24 14:23:12 -070033/* Supplied by i2c.c */
34extern struct device_operations stoneyridge_i2c_mmio_ops;
35extern const char *i2c_acpi_name(const struct device *dev);
36
Marc Jones1587dc82017-05-15 18:55:11 -060037struct device_operations cpu_bus_ops = {
38 .read_resources = DEVICE_NOOP,
39 .set_resources = DEVICE_NOOP,
40 .enable_resources = DEVICE_NOOP,
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060041 .init = stoney_init_cpus,
Marc Jones6bfcf662017-08-06 17:42:35 -060042 .acpi_fill_ssdt_generator = generate_cpu_entries,
Marc Jones24484842017-05-04 21:17:45 -060043};
44
Duncan Laurie32bdffa2018-05-07 15:37:28 -070045const char *soc_acpi_name(const struct device *dev)
Justin TerAvest949d6662018-01-24 14:20:03 -070046{
47 if (dev->path.type == DEVICE_PATH_DOMAIN)
48 return "PCI0";
Duncan Laurie32bdffa2018-05-07 15:37:28 -070049
50 if (dev->path.type == DEVICE_PATH_USB) {
51 switch (dev->path.usb.port_type) {
52 case 0:
53 /* Root Hub */
54 return "RHUB";
55 case 2:
56 /* USB2 ports */
57 switch (dev->path.usb.port_id) {
58 case 0: return "HS01";
59 case 1: return "HS02";
60 case 2: return "HS03";
61 case 3: return "HS04";
62 case 4: return "HS05";
63 case 5: return "HS06";
64 case 6: return "HS07";
65 case 7: return "HS08";
66 }
67 break;
68 case 3:
69 /* USB3 ports */
70 switch (dev->path.usb.port_id) {
71 case 0: return "SS01";
72 case 1: return "SS02";
73 case 2: return "SS03";
74 }
75 break;
76 }
77 return NULL;
78 }
79
Justin TerAvest949d6662018-01-24 14:20:03 -070080 if (dev->path.type != DEVICE_PATH_PCI)
81 return NULL;
82
83 switch (dev->path.pci.devfn) {
Marc Jones6dcb6c22018-07-26 17:07:13 -060084 case GFX_DEVFN:
85 return "IGFX";
Marc Jones9022b9d2018-05-25 20:53:44 -060086 case PCIE0_DEVFN:
87 return "PBR4";
88 case PCIE1_DEVFN:
89 return "PBR5";
90 case PCIE2_DEVFN:
91 return "PBR6";
92 case PCIE3_DEVFN:
93 return "PBR7";
94 case PCIE4_DEVFN:
95 return "PBR8";
96 case HDA1_DEVFN:
97 return "AZHD";
Justin TerAvest949d6662018-01-24 14:20:03 -070098 case EHCI1_DEVFN:
99 return "EHC0";
100 case LPC_DEVFN:
101 return "LPCB";
102 case SATA_DEVFN:
103 return "STCR";
104 case SD_DEVFN:
105 return "SDCN";
106 case SMBUS_DEVFN:
107 return "SBUS";
108 case XHCI_DEVFN:
109 return "XHC0";
110 default:
111 return NULL;
112 }
113};
114
Marc Jones1587dc82017-05-15 18:55:11 -0600115struct device_operations pci_domain_ops = {
Martin Roth3424f382018-10-29 16:19:46 -0600116 .read_resources = pci_domain_read_resources,
Marc Jones1587dc82017-05-15 18:55:11 -0600117 .set_resources = domain_set_resources,
118 .enable_resources = domain_enable_resources,
Marc Jones1587dc82017-05-15 18:55:11 -0600119 .scan_bus = pci_domain_scan_bus,
Justin TerAvest949d6662018-01-24 14:20:03 -0700120 .acpi_name = soc_acpi_name,
Marc Jones24484842017-05-04 21:17:45 -0600121};
122
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200123static void enable_dev(struct device *dev)
Marc Jones24484842017-05-04 21:17:45 -0600124{
125 /* Set the operations if it is a special bus type */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600126 if (dev->path.type == DEVICE_PATH_DOMAIN)
Marc Jones24484842017-05-04 21:17:45 -0600127 dev->ops = &pci_domain_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600128 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
Marc Jones24484842017-05-04 21:17:45 -0600129 dev->ops = &cpu_bus_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600130 else if (dev->path.type == DEVICE_PATH_PCI)
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600131 sb_enable(dev);
Justin TerAvest13101a72018-01-24 14:23:12 -0700132 else if (dev->path.type == DEVICE_PATH_MMIO)
133 if (i2c_acpi_name(dev) != NULL)
134 dev->ops = &stoneyridge_i2c_mmio_ops;
Marc Jones24484842017-05-04 21:17:45 -0600135}
136
137static void soc_init(void *chip_info)
138{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600139 southbridge_init(chip_info);
Richard Spiegel9d0921b2017-12-19 10:24:50 -0700140 setup_bsp_ramtop();
Marc Jones24484842017-05-04 21:17:45 -0600141}
142
143static void soc_final(void *chip_info)
144{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600145 southbridge_final(chip_info);
Marc Jones1587dc82017-05-15 18:55:11 -0600146 fam15_finalize(chip_info);
Marc Jones24484842017-05-04 21:17:45 -0600147}
148
149struct chip_operations soc_amd_stoneyridge_ops = {
150 CHIP_NAME("AMD StoneyRidge SOC")
Elyes HAOUAS1d191272018-11-27 12:23:48 +0100151 .enable_dev = enable_dev,
152 .init = soc_init,
153 .final = soc_final
Marc Jones24484842017-05-04 21:17:45 -0600154};
Marshall Dawson9db8a442017-09-20 10:24:28 -0600155
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600156static void earliest_ramstage(void *unused)
Marshall Dawson9db8a442017-09-20 10:24:28 -0600157{
Kyösti Mälkkia8eb4772018-06-28 17:23:27 +0300158 int s3_resume = acpi_s3_resume_allowed() &&
159 romstage_handoff_is_resume();
160 if (!s3_resume) {
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600161 post_code(0x46);
Julius Wernercd49cce2019-03-05 16:53:33 -0800162 if (CONFIG(SOC_AMD_PSP_SELECTABLE_SMU_FW))
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600163 psp_load_named_blob(MBOX_BIOS_CMD_SMU_FW2, "smu_fw2");
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600164
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600165 post_code(0x47);
Kyösti Mälkki6e512c42018-06-14 06:57:05 +0300166 do_agesawrapper(AMD_INIT_ENV, "amdinitenv");
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600167 } else {
168 /* Complete the initial system restoration */
169 post_code(0x46);
Kyösti Mälkki6e512c42018-06-14 06:57:05 +0300170 do_agesawrapper(AMD_S3LATE_RESTORE, "amds3laterestore");
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600171 }
Marshall Dawson9db8a442017-09-20 10:24:28 -0600172}
173
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600174BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, earliest_ramstage, NULL);