blob: 9ca2db7e857d4064aa212cd6461d3638bedf0be0 [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>
20#include <cpu/cpu.h>
Marc Jones24484842017-05-04 21:17:45 -060021#include <device/device.h>
22#include <device/pci.h>
Justin TerAvest13101a72018-01-24 14:23:12 -070023#include <drivers/i2c/designware/dw_i2c.h>
Marshall Dawson8f2a7e02017-11-01 11:44:48 -060024#include <romstage_handoff.h>
Duncan Laurie32bdffa2018-05-07 15:37:28 -070025#include <soc/acpi.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060026#include <soc/cpu.h>
Marc Jones1587dc82017-05-15 18:55:11 -060027#include <soc/northbridge.h>
Justin TerAvest949d6662018-01-24 14:20:03 -070028#include <soc/pci_devs.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060029#include <soc/southbridge.h>
Marshall Dawsonf5e057c2017-10-12 16:10:14 -060030#include <amdblocks/psp.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -070031#include <amdblocks/agesawrapper.h>
32#include <amdblocks/agesawrapper_call.h>
Marc Jones24484842017-05-04 21:17:45 -060033
Justin TerAvest13101a72018-01-24 14:23:12 -070034/* Supplied by i2c.c */
35extern struct device_operations stoneyridge_i2c_mmio_ops;
36extern const char *i2c_acpi_name(const struct device *dev);
37
Marc Jones1587dc82017-05-15 18:55:11 -060038struct device_operations cpu_bus_ops = {
39 .read_resources = DEVICE_NOOP,
40 .set_resources = DEVICE_NOOP,
41 .enable_resources = DEVICE_NOOP,
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060042 .init = stoney_init_cpus,
Marc Jones6bfcf662017-08-06 17:42:35 -060043 .acpi_fill_ssdt_generator = generate_cpu_entries,
Marc Jones24484842017-05-04 21:17:45 -060044};
45
Duncan Laurie32bdffa2018-05-07 15:37:28 -070046const char *soc_acpi_name(const struct device *dev)
Justin TerAvest949d6662018-01-24 14:20:03 -070047{
48 if (dev->path.type == DEVICE_PATH_DOMAIN)
49 return "PCI0";
Duncan Laurie32bdffa2018-05-07 15:37:28 -070050
51 if (dev->path.type == DEVICE_PATH_USB) {
52 switch (dev->path.usb.port_type) {
53 case 0:
54 /* Root Hub */
55 return "RHUB";
56 case 2:
57 /* USB2 ports */
58 switch (dev->path.usb.port_id) {
59 case 0: return "HS01";
60 case 1: return "HS02";
61 case 2: return "HS03";
62 case 3: return "HS04";
63 case 4: return "HS05";
64 case 5: return "HS06";
65 case 6: return "HS07";
66 case 7: return "HS08";
67 }
68 break;
69 case 3:
70 /* USB3 ports */
71 switch (dev->path.usb.port_id) {
72 case 0: return "SS01";
73 case 1: return "SS02";
74 case 2: return "SS03";
75 }
76 break;
77 }
78 return NULL;
79 }
80
Justin TerAvest949d6662018-01-24 14:20:03 -070081 if (dev->path.type != DEVICE_PATH_PCI)
82 return NULL;
83
84 switch (dev->path.pci.devfn) {
Marc Jones9022b9d2018-05-25 20:53:44 -060085 case PCIE0_DEVFN:
86 return "PBR4";
87 case PCIE1_DEVFN:
88 return "PBR5";
89 case PCIE2_DEVFN:
90 return "PBR6";
91 case PCIE3_DEVFN:
92 return "PBR7";
93 case PCIE4_DEVFN:
94 return "PBR8";
95 case HDA1_DEVFN:
96 return "AZHD";
Justin TerAvest949d6662018-01-24 14:20:03 -070097 case EHCI1_DEVFN:
98 return "EHC0";
99 case LPC_DEVFN:
100 return "LPCB";
101 case SATA_DEVFN:
102 return "STCR";
103 case SD_DEVFN:
104 return "SDCN";
105 case SMBUS_DEVFN:
106 return "SBUS";
107 case XHCI_DEVFN:
108 return "XHC0";
109 default:
110 return NULL;
111 }
112};
113
Marc Jones1587dc82017-05-15 18:55:11 -0600114struct device_operations pci_domain_ops = {
115 .read_resources = domain_read_resources,
116 .set_resources = domain_set_resources,
117 .enable_resources = domain_enable_resources,
Marc Jones1587dc82017-05-15 18:55:11 -0600118 .scan_bus = pci_domain_scan_bus,
Justin TerAvest949d6662018-01-24 14:20:03 -0700119 .acpi_name = soc_acpi_name,
Marc Jones24484842017-05-04 21:17:45 -0600120};
121
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200122static void enable_dev(struct device *dev)
Marc Jones24484842017-05-04 21:17:45 -0600123{
124 /* Set the operations if it is a special bus type */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600125 if (dev->path.type == DEVICE_PATH_DOMAIN)
Marc Jones24484842017-05-04 21:17:45 -0600126 dev->ops = &pci_domain_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600127 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
Marc Jones24484842017-05-04 21:17:45 -0600128 dev->ops = &cpu_bus_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600129 else if (dev->path.type == DEVICE_PATH_PCI)
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600130 sb_enable(dev);
Justin TerAvest13101a72018-01-24 14:23:12 -0700131 else if (dev->path.type == DEVICE_PATH_MMIO)
132 if (i2c_acpi_name(dev) != NULL)
133 dev->ops = &stoneyridge_i2c_mmio_ops;
Marc Jones24484842017-05-04 21:17:45 -0600134}
135
136static void soc_init(void *chip_info)
137{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600138 southbridge_init(chip_info);
Richard Spiegel9d0921b2017-12-19 10:24:50 -0700139 setup_bsp_ramtop();
Marc Jones24484842017-05-04 21:17:45 -0600140}
141
142static void soc_final(void *chip_info)
143{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600144 southbridge_final(chip_info);
Marc Jones1587dc82017-05-15 18:55:11 -0600145 fam15_finalize(chip_info);
Marc Jones24484842017-05-04 21:17:45 -0600146}
147
148struct chip_operations soc_amd_stoneyridge_ops = {
149 CHIP_NAME("AMD StoneyRidge SOC")
150 .enable_dev = &enable_dev,
151 .init = &soc_init,
152 .final = &soc_final
153};
Marshall Dawson9db8a442017-09-20 10:24:28 -0600154
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600155static void earliest_ramstage(void *unused)
Marshall Dawson9db8a442017-09-20 10:24:28 -0600156{
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600157 if (!romstage_handoff_is_resume()) {
158 post_code(0x46);
159 if (IS_ENABLED(CONFIG_SOC_AMD_PSP_SELECTABLE_SMU_FW))
160 psp_load_named_blob(MBOX_BIOS_CMD_SMU_FW2, "smu_fw2");
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600161
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600162 post_code(0x47);
163 do_agesawrapper(agesawrapper_amdinitenv, "amdinitenv");
164 } else {
165 /* Complete the initial system restoration */
166 post_code(0x46);
167 do_agesawrapper(agesawrapper_amds3laterestore,
168 "amds3laterestore");
169 }
Marshall Dawson9db8a442017-09-20 10:24:28 -0600170}
171
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600172BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, earliest_ramstage, NULL);