1 // SPDX-License-Identifier: GPL-2.0+
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
14 * struct sandbox_store_priv - Private data structure of a AXI store device
15 * @store: The buffer holding the device's internal memory, which is read from
16 * and written to using the driver's methods
18 struct sandbox_store_priv {
23 * copy_axi_data() - Copy data from source to destination with a given AXI
25 * @src: Pointer to the data source from where data will be read
26 * @dst: Pointer to the data destination where data will be written to
27 * @size: Size of the data to be copied given by a axi_size_t enum value
29 * Return: 0 if OK, -ve on error
31 static int copy_axi_data(void *src, void *dst, enum axi_size_t size)
35 *((u8 *)dst) = *((u8 *)src);
38 *((u16 *)dst) = be16_to_cpu(*((u16 *)src));
41 *((u32 *)dst) = be32_to_cpu(*((u32 *)src));
44 debug("%s: Unknown AXI transfer size '%d'\n", __func__, size);
49 static int sandbox_store_read(struct udevice *dev, ulong address, void *data,
52 struct sandbox_store_priv *priv = dev_get_priv(dev);
54 return copy_axi_data(priv->store + address, data, size);
57 static int sandbox_store_write(struct udevice *dev, ulong address, void *data,
60 struct sandbox_store_priv *priv = dev_get_priv(dev);
62 return copy_axi_data(data, priv->store + address, size);
65 static int sandbox_store_get_store(struct udevice *dev, u8 **store)
67 struct sandbox_store_priv *priv = dev_get_priv(dev);
74 static const struct udevice_id sandbox_store_ids[] = {
75 { .compatible = "sandbox,sandbox_store" },
79 static const struct axi_emul_ops sandbox_store_ops = {
80 .read = sandbox_store_read,
81 .write = sandbox_store_write,
82 .get_store = sandbox_store_get_store,
85 static int sandbox_store_probe(struct udevice *dev)
87 struct sandbox_store_priv *priv = dev_get_priv(dev);
91 ret = dev_read_u32_array(dev, "reg", reg, ARRAY_SIZE(reg));
93 debug("%s: Could not read 'reg' property\n", dev->name);
98 * Allocate the device's internal storage that will be read
101 priv->store = calloc(reg[1], 1);
108 static int sandbox_store_remove(struct udevice *dev)
110 struct sandbox_store_priv *priv = dev_get_priv(dev);
117 U_BOOT_DRIVER(sandbox_axi_store) = {
118 .name = "sandbox_axi_store",
119 .id = UCLASS_AXI_EMUL,
120 .of_match = sandbox_store_ids,
121 .ops = &sandbox_store_ops,
122 .priv_auto = sizeof(struct sandbox_store_priv),
123 .probe = sandbox_store_probe,
124 .remove = sandbox_store_remove,