blob: 33c17308c83ec4d8d263ae9bfcec8e5584bb2f4f [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 Jones6dcb6c22018-07-26 17:07:13 -060085 case GFX_DEVFN:
86 return "IGFX";
Marc Jones9022b9d2018-05-25 20:53:44 -060087 case PCIE0_DEVFN:
88 return "PBR4";
89 case PCIE1_DEVFN:
90 return "PBR5";
91 case PCIE2_DEVFN:
92 return "PBR6";
93 case PCIE3_DEVFN:
94 return "PBR7";
95 case PCIE4_DEVFN:
96 return "PBR8";
97 case HDA1_DEVFN:
98 return "AZHD";
Justin TerAvest949d6662018-01-24 14:20:03 -070099 case EHCI1_DEVFN:
100 return "EHC0";
101 case LPC_DEVFN:
102 return "LPCB";
103 case SATA_DEVFN:
104 return "STCR";
105 case SD_DEVFN:
106 return "SDCN";
107 case SMBUS_DEVFN:
108 return "SBUS";
109 case XHCI_DEVFN:
110 return "XHC0";
111 default:
112 return NULL;
113 }
114};
115
Marc Jones1587dc82017-05-15 18:55:11 -0600116struct device_operations pci_domain_ops = {
117 .read_resources = domain_read_resources,
118 .set_resources = domain_set_resources,
119 .enable_resources = domain_enable_resources,
Marc Jones1587dc82017-05-15 18:55:11 -0600120 .scan_bus = pci_domain_scan_bus,
Justin TerAvest949d6662018-01-24 14:20:03 -0700121 .acpi_name = soc_acpi_name,
Marc Jones24484842017-05-04 21:17:45 -0600122};
123
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200124static void enable_dev(struct device *dev)
Marc Jones24484842017-05-04 21:17:45 -0600125{
126 /* Set the operations if it is a special bus type */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600127 if (dev->path.type == DEVICE_PATH_DOMAIN)
Marc Jones24484842017-05-04 21:17:45 -0600128 dev->ops = &pci_domain_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600129 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
Marc Jones24484842017-05-04 21:17:45 -0600130 dev->ops = &cpu_bus_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600131 else if (dev->path.type == DEVICE_PATH_PCI)
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600132 sb_enable(dev);
Justin TerAvest13101a72018-01-24 14:23:12 -0700133 else if (dev->path.type == DEVICE_PATH_MMIO)
134 if (i2c_acpi_name(dev) != NULL)
135 dev->ops = &stoneyridge_i2c_mmio_ops;
Marc Jones24484842017-05-04 21:17:45 -0600136}
137
138static void soc_init(void *chip_info)
139{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600140 southbridge_init(chip_info);
Richard Spiegel9d0921b2017-12-19 10:24:50 -0700141 setup_bsp_ramtop();
Marc Jones24484842017-05-04 21:17:45 -0600142}
143
144static void soc_final(void *chip_info)
145{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600146 southbridge_final(chip_info);
Marc Jones1587dc82017-05-15 18:55:11 -0600147 fam15_finalize(chip_info);
Marc Jones24484842017-05-04 21:17:45 -0600148}
149
150struct chip_operations soc_amd_stoneyridge_ops = {
151 CHIP_NAME("AMD StoneyRidge SOC")
152 .enable_dev = &enable_dev,
153 .init = &soc_init,
154 .final = &soc_final
155};
Marshall Dawson9db8a442017-09-20 10:24:28 -0600156
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600157static void earliest_ramstage(void *unused)
Marshall Dawson9db8a442017-09-20 10:24:28 -0600158{
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600159 if (!romstage_handoff_is_resume()) {
160 post_code(0x46);
161 if (IS_ENABLED(CONFIG_SOC_AMD_PSP_SELECTABLE_SMU_FW))
162 psp_load_named_blob(MBOX_BIOS_CMD_SMU_FW2, "smu_fw2");
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600163
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600164 post_code(0x47);
165 do_agesawrapper(agesawrapper_amdinitenv, "amdinitenv");
166 } else {
167 /* Complete the initial system restoration */
168 post_code(0x46);
169 do_agesawrapper(agesawrapper_amds3laterestore,
170 "amds3laterestore");
171 }
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);