blob: f5efcfd96f7700003181e3d317624e0584003064 [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>
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
Justin TerAvest949d6662018-01-24 14:20:03 -070045static const char *soc_acpi_name(const struct device *dev)
46{
47 if (dev->path.type == DEVICE_PATH_DOMAIN)
48 return "PCI0";
49 if (dev->path.type != DEVICE_PATH_PCI)
50 return NULL;
51
52 switch (dev->path.pci.devfn) {
53 case EHCI1_DEVFN:
54 return "EHC0";
55 case LPC_DEVFN:
56 return "LPCB";
57 case SATA_DEVFN:
58 return "STCR";
59 case SD_DEVFN:
60 return "SDCN";
61 case SMBUS_DEVFN:
62 return "SBUS";
63 case XHCI_DEVFN:
64 return "XHC0";
65 default:
66 return NULL;
67 }
68};
69
Marc Jones1587dc82017-05-15 18:55:11 -060070struct device_operations pci_domain_ops = {
71 .read_resources = domain_read_resources,
72 .set_resources = domain_set_resources,
73 .enable_resources = domain_enable_resources,
Marc Jones1587dc82017-05-15 18:55:11 -060074 .scan_bus = pci_domain_scan_bus,
75 .ops_pci_bus = pci_bus_default_ops,
Justin TerAvest949d6662018-01-24 14:20:03 -070076 .acpi_name = soc_acpi_name,
Marc Jones24484842017-05-04 21:17:45 -060077};
78
79static void enable_dev(device_t dev)
80{
81 /* Set the operations if it is a special bus type */
Marshall Dawson4e101ad2017-06-15 12:17:38 -060082 if (dev->path.type == DEVICE_PATH_DOMAIN)
Marc Jones24484842017-05-04 21:17:45 -060083 dev->ops = &pci_domain_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -060084 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
Marc Jones24484842017-05-04 21:17:45 -060085 dev->ops = &cpu_bus_ops;
Marshall Dawson4e101ad2017-06-15 12:17:38 -060086 else if (dev->path.type == DEVICE_PATH_PCI)
Marc Jonesdfeb1c42017-08-07 19:08:24 -060087 sb_enable(dev);
Justin TerAvest13101a72018-01-24 14:23:12 -070088 else if (dev->path.type == DEVICE_PATH_MMIO)
89 if (i2c_acpi_name(dev) != NULL)
90 dev->ops = &stoneyridge_i2c_mmio_ops;
Marc Jones24484842017-05-04 21:17:45 -060091}
92
93static void soc_init(void *chip_info)
94{
Marc Jonesdfeb1c42017-08-07 19:08:24 -060095 southbridge_init(chip_info);
Richard Spiegel9d0921b2017-12-19 10:24:50 -070096 setup_bsp_ramtop();
Marc Jones24484842017-05-04 21:17:45 -060097}
98
99static void soc_final(void *chip_info)
100{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600101 southbridge_final(chip_info);
Marc Jones1587dc82017-05-15 18:55:11 -0600102 fam15_finalize(chip_info);
Marc Jones24484842017-05-04 21:17:45 -0600103}
104
105struct chip_operations soc_amd_stoneyridge_ops = {
106 CHIP_NAME("AMD StoneyRidge SOC")
107 .enable_dev = &enable_dev,
108 .init = &soc_init,
109 .final = &soc_final
110};
Marshall Dawson9db8a442017-09-20 10:24:28 -0600111
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600112static void earliest_ramstage(void *unused)
Marshall Dawson9db8a442017-09-20 10:24:28 -0600113{
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600114 if (!romstage_handoff_is_resume()) {
115 post_code(0x46);
116 if (IS_ENABLED(CONFIG_SOC_AMD_PSP_SELECTABLE_SMU_FW))
117 psp_load_named_blob(MBOX_BIOS_CMD_SMU_FW2, "smu_fw2");
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600118
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600119 post_code(0x47);
120 do_agesawrapper(agesawrapper_amdinitenv, "amdinitenv");
121 } else {
122 /* Complete the initial system restoration */
123 post_code(0x46);
124 do_agesawrapper(agesawrapper_amds3laterestore,
125 "amds3laterestore");
126 }
Marshall Dawson9db8a442017-09-20 10:24:28 -0600127}
128
Marshall Dawsonf5e057c2017-10-12 16:10:14 -0600129BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, earliest_ramstage, NULL);