1 // SPDX-License-Identifier: GPL-2.0+
3 * Sandbox interface for QFW
5 * (C) Copyright 2015 Miao Yan <yanmiaobest@gmail.com>
6 * (C) Copyright 2021 Asherah Connor <ashe@kivikakk.ee>
9 #define LOG_CATEGORY UCLASS_QFW
11 #include <asm/types.h>
14 #include <dm/device.h>
17 struct qfw_sandbox_plat {
21 static void qfw_sandbox_read_entry_io(struct udevice *dev, u16 entry, u32 size,
24 debug("%s: entry 0x%x size %u address %p\n", __func__, entry, size,
28 case FW_CFG_SIGNATURE:
30 *((u32 *)address) = cpu_to_be32(QEMU_FW_CFG_SIGNATURE);
33 /* Advertise DMA support */
35 *((u8 *)address) = FW_CFG_DMA_ENABLED;
38 debug("%s got unsupported entry 0x%x\n", __func__, entry);
40 * Sandbox driver doesn't support other entries here, assume we use DMA
41 * to read them -- the uclass driver will exclusively use it when
47 static void qfw_sandbox_read_entry_dma(struct udevice *dev, struct qfw_dma *dma)
50 u32 control = be32_to_cpu(dma->control);
51 void *address = (void *)be64_to_cpu(dma->address);
52 u32 length = be32_to_cpu(dma->length);
53 struct qfw_sandbox_plat *plat = dev_get_plat(dev);
54 struct fw_cfg_file *file;
56 debug("%s\n", __func__);
58 if (!(control & FW_CFG_DMA_READ))
61 if (control & FW_CFG_DMA_SELECT) {
63 entry = control >> 16;
65 /* Arbitrary values to be used by tests. */
69 *((u16 *)address) = cpu_to_le16(5);
73 *((u32 *)address) = cpu_to_be32(2);
74 plat->file_dir_offset = 1;
78 debug("%s got unsupported entry 0x%x\n", __func__,
81 } else if (plat->file_dir_offset && length == 64) {
83 switch (plat->file_dir_offset) {
85 file->size = cpu_to_be32(8);
86 file->select = cpu_to_be16(FW_CFG_FILE_FIRST);
87 strcpy(file->name, "test-one");
88 plat->file_dir_offset++;
91 file->size = cpu_to_be32(8);
92 file->select = cpu_to_be16(FW_CFG_FILE_FIRST + 1);
93 strcpy(file->name, "test-two");
94 plat->file_dir_offset++;
100 * Signal that we are finished. No-one checks this in sandbox --
101 * normally the platform-specific driver looks for it -- but let's
102 * replicate the behaviour in case someone relies on it later.
107 static int qfw_sandbox_probe(struct udevice *dev)
109 return qfw_register(dev);
112 static struct dm_qfw_ops qfw_sandbox_ops = {
113 .read_entry_io = qfw_sandbox_read_entry_io,
114 .read_entry_dma = qfw_sandbox_read_entry_dma,
117 U_BOOT_DRIVER(qfw_sandbox) = {
118 .name = "qfw_sandbox",
120 .plat_auto = sizeof(struct qfw_sandbox_plat),
121 .probe = qfw_sandbox_probe,
122 .ops = &qfw_sandbox_ops,
125 U_BOOT_DRVINFO(qfw_sandbox) = {
126 .name = "qfw_sandbox",