1 // SPDX-License-Identifier: GPL-2.0+
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
12 * struct sandbox_store_priv - Private data structure of a AXI store device
13 * @store: The buffer holding the device's internal memory, which is read from
14 * and written to using the driver's methods
16 struct sandbox_store_priv {
21 * copy_axi_data() - Copy data from source to destination with a given AXI
23 * @src: Pointer to the data source from where data will be read
24 * @dst: Pointer to the data destination where data will be written to
25 * @size: Size of the data to be copied given by a axi_size_t enum value
27 * Return: 0 if OK, -ve on error
29 static int copy_axi_data(void *src, void *dst, enum axi_size_t size)
33 *((u8 *)dst) = *((u8 *)src);
36 *((u16 *)dst) = be16_to_cpu(*((u16 *)src));
39 *((u32 *)dst) = be32_to_cpu(*((u32 *)src));
42 debug("%s: Unknown AXI transfer size '%d'\n", __func__, size);
47 static int sandbox_store_read(struct udevice *dev, ulong address, void *data,
50 struct sandbox_store_priv *priv = dev_get_priv(dev);
52 return copy_axi_data(priv->store + address, data, size);
55 static int sandbox_store_write(struct udevice *dev, ulong address, void *data,
58 struct sandbox_store_priv *priv = dev_get_priv(dev);
60 return copy_axi_data(data, priv->store + address, size);
63 static int sandbox_store_get_store(struct udevice *dev, u8 **store)
65 struct sandbox_store_priv *priv = dev_get_priv(dev);
72 static const struct udevice_id sandbox_store_ids[] = {
73 { .compatible = "sandbox,sandbox_store" },
77 static const struct axi_emul_ops sandbox_store_ops = {
78 .read = sandbox_store_read,
79 .write = sandbox_store_write,
80 .get_store = sandbox_store_get_store,
83 static int sandbox_store_probe(struct udevice *dev)
85 struct sandbox_store_priv *priv = dev_get_priv(dev);
89 ret = dev_read_u32_array(dev, "reg", reg, ARRAY_SIZE(reg));
91 debug("%s: Could not read 'reg' property\n", dev->name);
96 * Allocate the device's internal storage that will be read
99 priv->store = calloc(reg[1], 1);
106 static int sandbox_store_remove(struct udevice *dev)
108 struct sandbox_store_priv *priv = dev_get_priv(dev);
115 U_BOOT_DRIVER(sandbox_axi_store) = {
116 .name = "sandbox_axi_store",
117 .id = UCLASS_AXI_EMUL,
118 .of_match = sandbox_store_ids,
119 .ops = &sandbox_store_ops,
120 .priv_auto_alloc_size = sizeof(struct sandbox_store_priv),
121 .probe = sandbox_store_probe,
122 .remove = sandbox_store_remove,