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