Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include "psp_verstage.h" |
| 4 | |
| 5 | #include <amdblocks/acpimmio.h> |
Felix Held | ba35f35 | 2022-10-18 20:43:00 +0200 | [diff] [blame] | 6 | #include <amdblocks/aoac.h> |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 7 | #include <amdblocks/espi.h> |
Kangheui Won | 32f43e0 | 2021-05-26 13:40:21 +1000 | [diff] [blame] | 8 | #include <amdblocks/i2c.h> |
Martin Roth | e52edfc | 2020-07-08 10:54:07 -0600 | [diff] [blame] | 9 | #include <amdblocks/spi.h> |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 10 | #include <arch/exception.h> |
| 11 | #include <arch/hlt.h> |
| 12 | #include <arch/io.h> |
| 13 | #include <bl_uapp/bl_errorcodes_public.h> |
| 14 | #include <bl_uapp/bl_syscall_public.h> |
| 15 | #include <console/console.h> |
Felix Held | 2e78570 | 2022-09-29 16:17:53 +0200 | [diff] [blame] | 16 | #include <device/mmio.h> |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 17 | #include <soc/i2c.h> |
| 18 | #include <soc/southbridge.h> |
| 19 | #include <stdint.h> |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 20 | |
| 21 | static void i2c3_set_bar(void *bar) |
| 22 | { |
| 23 | i2c_set_bar(3, (uintptr_t)bar); |
| 24 | } |
| 25 | |
| 26 | static void i2c2_set_bar(void *bar) |
| 27 | { |
| 28 | i2c_set_bar(2, (uintptr_t)bar); |
| 29 | } |
| 30 | |
| 31 | static void espi_set_bar(void *bar) |
| 32 | { |
| 33 | espi_update_static_bar((uintptr_t)bar); |
| 34 | } |
| 35 | |
| 36 | static void iomux_set_bar(void *bar) |
| 37 | { |
| 38 | acpimmio_iomux = bar; |
| 39 | } |
| 40 | |
| 41 | static void misc_set_bar(void *bar) |
| 42 | { |
| 43 | acpimmio_misc = bar; |
| 44 | } |
| 45 | |
| 46 | static void gpio_set_bar(void *bar) |
| 47 | { |
| 48 | acpimmio_gpio0 = bar; |
| 49 | } |
| 50 | |
| 51 | static uintptr_t io_bar; |
| 52 | |
| 53 | static void io_set_bar(void *bar) |
| 54 | { |
| 55 | io_bar = (uintptr_t)bar; |
| 56 | } |
| 57 | |
| 58 | u8 io_read8(u16 reg) |
| 59 | { |
Felix Held | 2e78570 | 2022-09-29 16:17:53 +0200 | [diff] [blame] | 60 | return read8p(io_bar + reg); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void io_write8(u16 reg, u8 value) |
| 64 | { |
Felix Held | 2e78570 | 2022-09-29 16:17:53 +0200 | [diff] [blame] | 65 | write8p(io_bar + reg, value); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 66 | } |
| 67 | |
Martin Roth | 853c623 | 2020-07-09 15:55:15 -0600 | [diff] [blame] | 68 | static void aoac_set_bar(void *bar) |
| 69 | { |
| 70 | acpimmio_aoac = bar; |
| 71 | } |
| 72 | |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 73 | static struct { |
| 74 | const char *name; |
| 75 | struct { |
Jason Glenesk | 90f7191 | 2020-10-13 04:35:09 -0700 | [diff] [blame] | 76 | enum fch_io_device device; |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 77 | uint32_t arg0; |
| 78 | } args; |
| 79 | void (*set_bar)(void *bar); |
| 80 | void *_bar; |
| 81 | } bar_map[] = { |
| 82 | {"IOMUX", {FCH_IO_DEVICE_IOMUX}, iomux_set_bar}, |
| 83 | {"MISC", {FCH_IO_DEVICE_MISC}, misc_set_bar}, |
| 84 | {"GPIO", {FCH_IO_DEVICE_GPIO}, gpio_set_bar}, |
| 85 | {"IO", {FCH_IO_DEVICE_IOPORT}, io_set_bar}, |
| 86 | {"eSPI", {FCH_IO_DEVICE_ESPI}, espi_set_bar}, |
| 87 | {"I2C2", {FCH_IO_DEVICE_I2C, 2}, i2c2_set_bar}, |
| 88 | {"I2C3", {FCH_IO_DEVICE_I2C, 3}, i2c3_set_bar}, |
Martin Roth | e52edfc | 2020-07-08 10:54:07 -0600 | [diff] [blame] | 89 | {"SPI", {FCH_IO_DEVICE_SPI}, spi_set_base}, |
Martin Roth | 853c623 | 2020-07-09 15:55:15 -0600 | [diff] [blame] | 90 | {"AOAC", {FCH_IO_DEVICE_AOAC}, aoac_set_bar}, |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 91 | }; |
| 92 | |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame^] | 93 | void *map_spi_rom(void) |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 94 | { |
Jason Glenesk | 90f7191 | 2020-10-13 04:35:09 -0700 | [diff] [blame] | 95 | struct spirom_info spi = {0}; |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 96 | |
| 97 | if (svc_get_spi_rom_info(&spi)) |
| 98 | printk(BIOS_DEBUG, "Error getting SPI ROM info.\n"); |
| 99 | |
Karthikeyan Ramasubramanian | 6f1b03b | 2023-04-21 14:26:51 -0600 | [diff] [blame^] | 100 | return spi.SpiBiosSmnBase; |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 101 | } |
| 102 | |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 103 | static uint32_t map_fch_devices(void) |
| 104 | { |
| 105 | void *bar; |
| 106 | uint32_t err; |
| 107 | unsigned int i; |
| 108 | |
| 109 | for (i = 0; i < ARRAY_SIZE(bar_map); ++i) { |
| 110 | err = svc_map_fch_dev(bar_map[i].args.device, bar_map[i].args.arg0, 0, &bar); |
| 111 | if (err) { |
| 112 | printk(BIOS_ERR, "Failed to map %s: %u\n", bar_map[i].name, err); |
| 113 | return err; |
| 114 | } |
| 115 | |
| 116 | bar_map[i]._bar = bar; |
| 117 | bar_map[i].set_bar(bar); |
| 118 | } |
| 119 | |
Martin Roth | fdcbae0 | 2020-10-01 15:39:42 -0600 | [diff] [blame] | 120 | return BL_OK; |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | uint32_t unmap_fch_devices(void) |
| 124 | { |
| 125 | void *bar; |
Martin Roth | fdcbae0 | 2020-10-01 15:39:42 -0600 | [diff] [blame] | 126 | uint32_t err, rtn = BL_OK; |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 127 | unsigned int i; |
| 128 | |
| 129 | for (i = 0; i < ARRAY_SIZE(bar_map); ++i) { |
| 130 | bar = bar_map[i]._bar; |
| 131 | if (!bar) |
| 132 | continue; |
| 133 | |
| 134 | err = svc_unmap_fch_dev(bar_map[i].args.device, bar); |
| 135 | if (err) { |
| 136 | printk(BIOS_ERR, "Failed to unmap %s: %u\n", bar_map[i].name, err); |
| 137 | rtn = err; |
| 138 | } else { |
| 139 | bar_map[i]._bar = NULL; |
| 140 | bar_map[i].set_bar(NULL); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | return rtn; |
| 145 | } |
| 146 | |
| 147 | uint32_t verstage_soc_early_init(void) |
| 148 | { |
| 149 | return map_fch_devices(); |
| 150 | } |
| 151 | |
Rob Barnes | 847a39f | 2021-11-15 12:56:34 -0700 | [diff] [blame] | 152 | void verstage_soc_espi_init(void) |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 153 | { |
Rob Barnes | 847a39f | 2021-11-15 12:56:34 -0700 | [diff] [blame] | 154 | if (!CONFIG(SOC_AMD_COMMON_BLOCK_USE_ESPI)) |
| 155 | return; |
| 156 | printk(BIOS_DEBUG, "Setting up espi\n"); |
| 157 | espi_setup(); |
| 158 | } |
Kangheui Won | 32f43e0 | 2021-05-26 13:40:21 +1000 | [diff] [blame] | 159 | |
Rob Barnes | 847a39f | 2021-11-15 12:56:34 -0700 | [diff] [blame] | 160 | void verstage_soc_i2c_init(void) |
| 161 | { |
Kangheui Won | 32f43e0 | 2021-05-26 13:40:21 +1000 | [diff] [blame] | 162 | printk(BIOS_DEBUG, "Setting up i2c\n"); |
| 163 | i2c_soc_early_init(); |
Rob Barnes | 847a39f | 2021-11-15 12:56:34 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | void verstage_soc_aoac_init(void) |
| 167 | { |
| 168 | printk(BIOS_DEBUG, "Setting up aoac\n"); |
| 169 | enable_aoac_devices(); |
| 170 | } |
| 171 | |
| 172 | void verstage_soc_spi_init(void) |
| 173 | { |
| 174 | printk(BIOS_DEBUG, "Setting up spi\n"); |
Karthikeyan Ramasubramanian | 5705b63 | 2021-10-05 14:11:13 -0600 | [diff] [blame] | 175 | fch_spi_config_modes(); |
| 176 | show_spi_speeds_and_modes(); |
Martin Roth | c7acf16 | 2020-05-28 00:44:50 -0600 | [diff] [blame] | 177 | } |