Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 Miao Yan <yanmiaobest@gmail.com> |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 4 | * (C) Copyright 2021 Asherah Connor <ashe@kivikakk.ee> |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 7 | #define LOG_CATEGORY UCLASS_QFW |
| 8 | |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 9 | #include <common.h> |
Simon Glass | 77ca5ff | 2023-01-28 15:00:24 -0700 | [diff] [blame] | 10 | #include <bootdev.h> |
| 11 | #include <bootflow.h> |
| 12 | #include <bootmeth.h> |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 13 | #include <command.h> |
| 14 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 16 | #include <malloc.h> |
Miao Yan | 9210627 | 2016-05-22 19:37:17 -0700 | [diff] [blame] | 17 | #include <qfw.h> |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 18 | #include <dm.h> |
| 19 | #include <misc.h> |
Simon Glass | f3425cb | 2021-12-01 09:02:40 -0700 | [diff] [blame] | 20 | #include <tables_csum.h> |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 21 | |
Simon Glass | 1617088 | 2021-12-01 09:02:49 -0700 | [diff] [blame] | 22 | #if defined(CONFIG_GENERATE_ACPI_TABLE) && !defined(CONFIG_SANDBOX) |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 23 | /* |
| 24 | * This function allocates memory for ACPI tables |
| 25 | * |
| 26 | * @entry : BIOS linker command entry which tells where to allocate memory |
| 27 | * (either high memory or low memory) |
| 28 | * @addr : The address that should be used for low memory allcation. If the |
| 29 | * memory allocation request is 'ZONE_HIGH' then this parameter will |
| 30 | * be ignored. |
| 31 | * @return: 0 on success, or negative value on failure |
| 32 | */ |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 33 | static int bios_linker_allocate(struct udevice *dev, |
| 34 | struct bios_linker_entry *entry, ulong *addr) |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 35 | { |
| 36 | uint32_t size, align; |
| 37 | struct fw_file *file; |
| 38 | unsigned long aligned_addr; |
| 39 | |
| 40 | align = le32_to_cpu(entry->alloc.align); |
| 41 | /* align must be power of 2 */ |
| 42 | if (align & (align - 1)) { |
| 43 | printf("error: wrong alignment %u\n", align); |
| 44 | return -EINVAL; |
| 45 | } |
| 46 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 47 | file = qfw_find_file(dev, entry->alloc.file); |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 48 | if (!file) { |
| 49 | printf("error: can't find file %s\n", entry->alloc.file); |
| 50 | return -ENOENT; |
| 51 | } |
| 52 | |
| 53 | size = be32_to_cpu(file->cfg.size); |
| 54 | |
| 55 | /* |
| 56 | * ZONE_HIGH means we need to allocate from high memory, since |
| 57 | * malloc space is already at the end of RAM, so we directly use it. |
| 58 | * If allocation zone is ZONE_FSEG, then we use the 'addr' passed |
| 59 | * in which is low memory |
| 60 | */ |
| 61 | if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH) { |
| 62 | aligned_addr = (unsigned long)memalign(align, size); |
| 63 | if (!aligned_addr) { |
| 64 | printf("error: allocating resource\n"); |
| 65 | return -ENOMEM; |
| 66 | } |
| 67 | } else if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG) { |
| 68 | aligned_addr = ALIGN(*addr, align); |
| 69 | } else { |
| 70 | printf("error: invalid allocation zone\n"); |
| 71 | return -EINVAL; |
| 72 | } |
| 73 | |
| 74 | debug("bios_linker_allocate: allocate file %s, size %u, zone %d, align %u, addr 0x%lx\n", |
| 75 | file->cfg.name, size, entry->alloc.zone, align, aligned_addr); |
| 76 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 77 | qfw_read_entry(dev, be16_to_cpu(file->cfg.select), size, |
| 78 | (void *)aligned_addr); |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 79 | file->addr = aligned_addr; |
| 80 | |
| 81 | /* adjust address for low memory allocation */ |
| 82 | if (entry->alloc.zone == BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG) |
| 83 | *addr = (aligned_addr + size); |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * This function patches ACPI tables previously loaded |
| 90 | * by bios_linker_allocate() |
| 91 | * |
| 92 | * @entry : BIOS linker command entry which tells how to patch |
| 93 | * ACPI tables |
| 94 | * @return: 0 on success, or negative value on failure |
| 95 | */ |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 96 | static int bios_linker_add_pointer(struct udevice *dev, |
| 97 | struct bios_linker_entry *entry) |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 98 | { |
| 99 | struct fw_file *dest, *src; |
| 100 | uint32_t offset = le32_to_cpu(entry->pointer.offset); |
| 101 | uint64_t pointer = 0; |
| 102 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 103 | dest = qfw_find_file(dev, entry->pointer.dest_file); |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 104 | if (!dest || !dest->addr) |
| 105 | return -ENOENT; |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 106 | src = qfw_find_file(dev, entry->pointer.src_file); |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 107 | if (!src || !src->addr) |
| 108 | return -ENOENT; |
| 109 | |
| 110 | debug("bios_linker_add_pointer: dest->addr 0x%lx, src->addr 0x%lx, offset 0x%x size %u, 0x%llx\n", |
| 111 | dest->addr, src->addr, offset, entry->pointer.size, pointer); |
| 112 | |
| 113 | memcpy(&pointer, (char *)dest->addr + offset, entry->pointer.size); |
| 114 | pointer = le64_to_cpu(pointer); |
| 115 | pointer += (unsigned long)src->addr; |
| 116 | pointer = cpu_to_le64(pointer); |
| 117 | memcpy((char *)dest->addr + offset, &pointer, entry->pointer.size); |
| 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * This function updates checksum fields of ACPI tables previously loaded |
| 124 | * by bios_linker_allocate() |
| 125 | * |
| 126 | * @entry : BIOS linker command entry which tells where to update ACPI table |
| 127 | * checksums |
| 128 | * @return: 0 on success, or negative value on failure |
| 129 | */ |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 130 | static int bios_linker_add_checksum(struct udevice *dev, |
| 131 | struct bios_linker_entry *entry) |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 132 | { |
| 133 | struct fw_file *file; |
| 134 | uint8_t *data, cksum = 0; |
| 135 | uint8_t *cksum_start; |
| 136 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 137 | file = qfw_find_file(dev, entry->cksum.file); |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 138 | if (!file || !file->addr) |
| 139 | return -ENOENT; |
| 140 | |
| 141 | data = (uint8_t *)(file->addr + le32_to_cpu(entry->cksum.offset)); |
| 142 | cksum_start = (uint8_t *)(file->addr + le32_to_cpu(entry->cksum.start)); |
| 143 | cksum = table_compute_checksum(cksum_start, |
| 144 | le32_to_cpu(entry->cksum.length)); |
| 145 | *data = cksum; |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | /* This function loads and patches ACPI tables provided by QEMU */ |
Simon Glass | ca37a39 | 2017-01-16 07:03:35 -0700 | [diff] [blame] | 151 | ulong write_acpi_tables(ulong addr) |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 152 | { |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 153 | int i, ret; |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 154 | struct fw_file *file; |
| 155 | struct bios_linker_entry *table_loader; |
| 156 | struct bios_linker_entry *entry; |
| 157 | uint32_t size; |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 158 | struct udevice *dev; |
| 159 | |
| 160 | ret = qfw_get_dev(&dev); |
| 161 | if (ret) { |
| 162 | printf("error: no qfw\n"); |
| 163 | return addr; |
| 164 | } |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 165 | |
| 166 | /* make sure fw_list is loaded */ |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 167 | ret = qfw_read_firmware_list(dev); |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 168 | if (ret) { |
| 169 | printf("error: can't read firmware file list\n"); |
| 170 | return addr; |
| 171 | } |
| 172 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 173 | file = qfw_find_file(dev, "etc/table-loader"); |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 174 | if (!file) { |
| 175 | printf("error: can't find etc/table-loader\n"); |
| 176 | return addr; |
| 177 | } |
| 178 | |
| 179 | size = be32_to_cpu(file->cfg.size); |
| 180 | if ((size % sizeof(*entry)) != 0) { |
| 181 | printf("error: table-loader maybe corrupted\n"); |
| 182 | return addr; |
| 183 | } |
| 184 | |
| 185 | table_loader = malloc(size); |
| 186 | if (!table_loader) { |
| 187 | printf("error: no memory for table-loader\n"); |
| 188 | return addr; |
| 189 | } |
| 190 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 191 | qfw_read_entry(dev, be16_to_cpu(file->cfg.select), size, table_loader); |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 192 | |
| 193 | for (i = 0; i < (size / sizeof(*entry)); i++) { |
| 194 | entry = table_loader + i; |
| 195 | switch (le32_to_cpu(entry->command)) { |
| 196 | case BIOS_LINKER_LOADER_COMMAND_ALLOCATE: |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 197 | ret = bios_linker_allocate(dev, entry, &addr); |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 198 | if (ret) |
| 199 | goto out; |
| 200 | break; |
| 201 | case BIOS_LINKER_LOADER_COMMAND_ADD_POINTER: |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 202 | ret = bios_linker_add_pointer(dev, entry); |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 203 | if (ret) |
| 204 | goto out; |
| 205 | break; |
| 206 | case BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM: |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 207 | ret = bios_linker_add_checksum(dev, entry); |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 208 | if (ret) |
| 209 | goto out; |
| 210 | break; |
| 211 | default: |
| 212 | break; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | out: |
| 217 | if (ret) { |
| 218 | struct fw_cfg_file_iter iter; |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 219 | for (file = qfw_file_iter_init(dev, &iter); |
| 220 | !qfw_file_iter_end(&iter); |
| 221 | file = qfw_file_iter_next(&iter)) { |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 222 | if (file->addr) { |
| 223 | free((void *)file->addr); |
| 224 | file->addr = 0; |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | free(table_loader); |
| 230 | return addr; |
| 231 | } |
Bin Meng | 22069e2 | 2018-01-30 05:01:17 -0800 | [diff] [blame] | 232 | |
| 233 | ulong acpi_get_rsdp_addr(void) |
| 234 | { |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 235 | int ret; |
Bin Meng | 22069e2 | 2018-01-30 05:01:17 -0800 | [diff] [blame] | 236 | struct fw_file *file; |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 237 | struct udevice *dev; |
Bin Meng | 22069e2 | 2018-01-30 05:01:17 -0800 | [diff] [blame] | 238 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 239 | ret = qfw_get_dev(&dev); |
| 240 | if (ret) { |
| 241 | printf("error: no qfw\n"); |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | file = qfw_find_file(dev, "etc/acpi/rsdp"); |
Bin Meng | 22069e2 | 2018-01-30 05:01:17 -0800 | [diff] [blame] | 246 | return file->addr; |
| 247 | } |
Miao Yan | 12970d2 | 2016-05-22 19:37:20 -0700 | [diff] [blame] | 248 | #endif |
| 249 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 250 | static void qfw_read_entry_io(struct qfw_dev *qdev, u16 entry, u32 size, |
| 251 | void *address) |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 252 | { |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 253 | struct dm_qfw_ops *ops = dm_qfw_get_ops(qdev->dev); |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 254 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 255 | debug("%s: entry 0x%x, size %u address %p\n", __func__, entry, size, |
| 256 | address); |
| 257 | |
| 258 | ops->read_entry_io(qdev->dev, entry, size, address); |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 261 | static void qfw_read_entry_dma(struct qfw_dev *qdev, u16 entry, u32 size, |
| 262 | void *address) |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 263 | { |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 264 | struct dm_qfw_ops *ops = dm_qfw_get_ops(qdev->dev); |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 265 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 266 | struct qfw_dma dma = { |
| 267 | .length = cpu_to_be32(size), |
| 268 | .address = cpu_to_be64((uintptr_t)address), |
| 269 | .control = cpu_to_be32(FW_CFG_DMA_READ), |
| 270 | }; |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 271 | |
| 272 | /* |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 273 | * writing FW_CFG_INVALID will cause read operation to resume at last |
| 274 | * offset, otherwise read will start at offset 0 |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 275 | */ |
| 276 | if (entry != FW_CFG_INVALID) |
| 277 | dma.control |= cpu_to_be32(FW_CFG_DMA_SELECT | (entry << 16)); |
| 278 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 279 | debug("%s: entry 0x%x, size %u address %p, control 0x%x\n", __func__, |
Miao Yan | 8a15383 | 2016-05-22 19:37:15 -0700 | [diff] [blame] | 280 | entry, size, address, be32_to_cpu(dma.control)); |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 281 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 282 | barrier(); |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 283 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 284 | ops->read_entry_dma(qdev->dev, &dma); |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 287 | void qfw_read_entry(struct udevice *dev, u16 entry, u32 size, void *address) |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 288 | { |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 289 | struct qfw_dev *qdev = dev_get_uclass_priv(dev); |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 290 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 291 | if (qdev->dma_present) |
| 292 | qfw_read_entry_dma(qdev, entry, size, address); |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 293 | else |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 294 | qfw_read_entry_io(qdev, entry, size, address); |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 297 | int qfw_register(struct udevice *dev) |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 298 | { |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 299 | struct qfw_dev *qdev = dev_get_uclass_priv(dev); |
| 300 | u32 qemu, dma_enabled; |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 301 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 302 | qdev->dev = dev; |
| 303 | INIT_LIST_HEAD(&qdev->fw_list); |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 304 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 305 | qfw_read_entry_io(qdev, FW_CFG_SIGNATURE, 4, &qemu); |
| 306 | if (be32_to_cpu(qemu) != QEMU_FW_CFG_SIGNATURE) |
| 307 | return -ENODEV; |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 308 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 309 | qfw_read_entry_io(qdev, FW_CFG_ID, 1, &dma_enabled); |
| 310 | if (dma_enabled & FW_CFG_DMA_ENABLED) |
| 311 | qdev->dma_present = true; |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 312 | |
| 313 | return 0; |
Miao Yan | 4fcd7f2 | 2016-05-22 19:37:14 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Simon Glass | 77ca5ff | 2023-01-28 15:00:24 -0700 | [diff] [blame] | 316 | static int qfw_post_bind(struct udevice *dev) |
| 317 | { |
| 318 | int ret; |
| 319 | |
| 320 | ret = bootdev_setup_for_dev(dev, "qfw_bootdev"); |
| 321 | if (ret) |
| 322 | return log_msg_ret("dev", ret); |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | static int qfw_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, |
| 328 | struct bootflow *bflow) |
| 329 | { |
| 330 | const struct udevice *media = dev_get_parent(dev); |
| 331 | int ret; |
| 332 | |
| 333 | if (!CONFIG_IS_ENABLED(BOOTSTD)) |
| 334 | return -ENOSYS; |
| 335 | |
| 336 | log_debug("media=%s\n", media->name); |
| 337 | ret = bootmeth_check(bflow->method, iter); |
| 338 | if (ret) |
| 339 | return log_msg_ret("check", ret); |
| 340 | |
| 341 | log_debug("iter->part=%d\n", iter->part); |
| 342 | |
| 343 | /* We only support the whole device, not partitions */ |
| 344 | if (iter->part) |
| 345 | return log_msg_ret("max", -ESHUTDOWN); |
| 346 | |
| 347 | log_debug("reading bootflow with method: %s\n", bflow->method->name); |
| 348 | ret = bootmeth_read_bootflow(bflow->method, bflow); |
| 349 | if (ret) |
| 350 | return log_msg_ret("method", ret); |
| 351 | |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | static int qfw_bootdev_bind(struct udevice *dev) |
| 356 | { |
| 357 | struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); |
| 358 | |
| 359 | ucp->prio = BOOTDEVP_4_SCAN_FAST; |
| 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | static int qfw_bootdev_hunt(struct bootdev_hunter *info, bool show) |
| 365 | { |
| 366 | int ret; |
| 367 | |
| 368 | ret = uclass_probe_all(UCLASS_QFW); |
| 369 | if (ret && ret != -ENOENT) |
| 370 | return log_msg_ret("vir", ret); |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 375 | UCLASS_DRIVER(qfw) = { |
| 376 | .id = UCLASS_QFW, |
| 377 | .name = "qfw", |
Simon Glass | 77ca5ff | 2023-01-28 15:00:24 -0700 | [diff] [blame] | 378 | .post_bind = qfw_post_bind, |
Asherah Connor | 4ffa95d | 2021-03-19 18:21:40 +1100 | [diff] [blame] | 379 | .per_device_auto = sizeof(struct qfw_dev), |
| 380 | }; |
Simon Glass | 77ca5ff | 2023-01-28 15:00:24 -0700 | [diff] [blame] | 381 | |
| 382 | struct bootdev_ops qfw_bootdev_ops = { |
| 383 | .get_bootflow = qfw_get_bootflow, |
| 384 | }; |
| 385 | |
| 386 | static const struct udevice_id qfw_bootdev_ids[] = { |
| 387 | { .compatible = "u-boot,bootdev-qfw" }, |
| 388 | { } |
| 389 | }; |
| 390 | |
| 391 | U_BOOT_DRIVER(qfw_bootdev) = { |
| 392 | .name = "qfw_bootdev", |
| 393 | .id = UCLASS_BOOTDEV, |
| 394 | .ops = &qfw_bootdev_ops, |
| 395 | .bind = qfw_bootdev_bind, |
| 396 | .of_match = qfw_bootdev_ids, |
| 397 | }; |
| 398 | |
| 399 | BOOTDEV_HUNTER(qfw_bootdev_hunter) = { |
| 400 | .prio = BOOTDEVP_4_SCAN_FAST, |
| 401 | .uclass = UCLASS_QFW, |
| 402 | .hunt = qfw_bootdev_hunt, |
| 403 | .drv = DM_DRIVER_REF(qfw_bootdev), |
| 404 | }; |