blob: 3b73a054b8821da1560e524624e00d1afabbc0f1 [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) {
85 case EHCI1_DEVFN:
86 return "EHC0";
87 case LPC_DEVFN:
88 return "LPCB";
89 case SATA_DEVFN:
90 return "STCR";
91 case SD_DEVFN:
92 return "SDCN";
93 case SMBUS_DEVFN:
94 return "SBUS";
95 case XHCI_DEVFN:
96 return "XHC0";
97 default:
98 return NULL;
99 }
100};
101
Marc Jones1587dc82017-05-15 18:55:11 -0600102struct device_operations pci_domain_ops = {
103 .read_resources = domain_read_resources,
104 .set_resources = domain_set_resources,
105 .enable_resources = domain_enable_resources,
Marc Jones1587dc82017-05-15 18:55:11 -0600106 .scan_bus = pci_domain_scan_bus,
Justin TerAvest949d6662018-01-24 14:20:03 -0700107 .acpi_name = soc_acpi_name,
Marc Jones24484842017-05-04 21:17:45 -0600108};
109
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200110static void enable_dev(struct device *dev)
Marc Jones24484842017-05-04 21:17:45 -0600111{
112 /* Set the operations if it is a special bus type */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600113 if (dev->path.type == DEVICE_PATH_DOMAIN)
Marc Jones24484842017-05-04 21:17:45 -0600114 dev->ops = &pci_domain_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600115 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
Marc Jones24484842017-05-04 21:17:45 -0600116 dev->ops = &cpu_bus_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600117 else if (dev->path.type == DEVICE_PATH_PCI)
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600118 sb_enable(dev);
Justin TerAvest13101a72018-01-24 14:23:12 -0700119 else if (dev->path.type == DEVICE_PATH_MMIO)
120 if (i2c_acpi_name(dev) != NULL)
121 dev->ops = &stoneyridge_i2c_mmio_ops;
Marc Jones24484842017-05-04 21:17:45 -0600122}
123
124static void soc_init(void *chip_info)
125{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600126 southbridge_init(chip_info);
Richard Spiegel9d0921b2017-12-19 10:24:50 -0700127 setup_bsp_ramtop();
Marc Jones24484842017-05-04 21:17:45 -0600128}
129
130static void soc_final(void *chip_info)
131{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600132 southbridge_final(chip_info);
Marc Jones1587dc82017-05-15 18:55:11 -0600133 fam15_finalize(chip_info);
Marc Jones24484842017-05-04 21:17:45 -0600134}
135
136struct chip_operations soc_amd_stoneyridge_ops = {
137 CHIP_NAME("AMD StoneyRidge SOC")
138 .enable_dev = &enable_dev,
139 .init = &soc_init,
140 .final = &soc_final
141};
Marshall Dawson9db8a442017-09-20 10:24:28 -0600142
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600143static void earliest_ramstage(void *unused)
Marshall Dawson9db8a442017-09-20 10:24:28 -0600144{
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600145 if (!romstage_handoff_is_resume()) {
146 post_code(0x46);
147 if (IS_ENABLED(CONFIG_SOC_AMD_PSP_SELECTABLE_SMU_FW))
148 psp_load_named_blob(MBOX_BIOS_CMD_SMU_FW2, "smu_fw2");
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600149
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600150 post_code(0x47);
151 do_agesawrapper(agesawrapper_amdinitenv, "amdinitenv");
152 } else {
153 /* Complete the initial system restoration */
154 post_code(0x46);
155 do_agesawrapper(agesawrapper_amds3laterestore,
156 "amds3laterestore");
157 }
Marshall Dawson9db8a442017-09-20 10:24:28 -0600158}
159
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600160BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, earliest_ramstage, NULL);