1 // SPDX-License-Identifier: GPL-2.0+
3 * MMIO 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>
19 * Each access to the 64-bit data register can be 8/16/32/64 bits wide.
32 struct qfw_mmio_plat {
33 volatile struct qfw_mmio *mmio;
36 static void qfw_mmio_read_entry_io(struct udevice *dev, u16 entry, u32 size,
39 struct qfw_mmio_plat *plat = dev_get_plat(dev);
42 * writing FW_CFG_INVALID will cause read operation to resume at last
43 * offset, otherwise read will start at offset 0
45 * Note: on platform where the control register is MMIO, the register
48 if (entry != FW_CFG_INVALID)
49 plat->mmio->selector = cpu_to_be16(entry);
51 /* the endianness of data register is string-preserving */
53 *(u64 *)address = plat->mmio->data64;
58 *(u32 *)address = plat->mmio->data32;
63 *(u16 *)address = plat->mmio->data16;
68 *(u8 *)address = plat->mmio->data8;
74 /* Read configuration item using fw_cfg DMA interface */
75 static void qfw_mmio_read_entry_dma(struct udevice *dev, struct qfw_dma *dma)
77 struct qfw_mmio_plat *plat = dev_get_plat(dev);
79 /* the DMA address register is big-endian */
80 plat->mmio->dma = cpu_to_be64((uintptr_t)dma);
82 while (be32_to_cpu(dma->control) & ~FW_CFG_DMA_ERROR);
85 static int qfw_mmio_of_to_plat(struct udevice *dev)
87 struct qfw_mmio_plat *plat = dev_get_plat(dev);
89 plat->mmio = map_physmem(dev_read_addr(dev),
90 sizeof(struct qfw_mmio),
96 static int qfw_mmio_probe(struct udevice *dev)
98 return qfw_register(dev);
101 static struct dm_qfw_ops qfw_mmio_ops = {
102 .read_entry_io = qfw_mmio_read_entry_io,
103 .read_entry_dma = qfw_mmio_read_entry_dma,
106 static const struct udevice_id qfw_mmio_ids[] = {
107 { .compatible = "qemu,fw-cfg-mmio" },
111 U_BOOT_DRIVER(qfw_mmio) = {
114 .of_match = qfw_mmio_ids,
115 .plat_auto = sizeof(struct qfw_mmio_plat),
116 .of_to_plat = qfw_mmio_of_to_plat,
117 .probe = qfw_mmio_probe,
118 .ops = &qfw_mmio_ops,