1 // SPDX-License-Identifier: GPL-2.0+
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
13 * struct sandbox_store_priv - Private data structure of a AXI store device
14 * @store: The buffer holding the device's internal memory, which is read from
15 * and written to using the driver's methods
17 struct sandbox_store_priv {
22 * copy_axi_data() - Copy data from source to destination with a given AXI
24 * @src: Pointer to the data source from where data will be read
25 * @dst: Pointer to the data destination where data will be written to
26 * @size: Size of the data to be copied given by a axi_size_t enum value
28 * Return: 0 if OK, -ve on error
30 static int copy_axi_data(void *src, void *dst, enum axi_size_t size)
34 *((u8 *)dst) = *((u8 *)src);
37 *((u16 *)dst) = be16_to_cpu(*((u16 *)src));
40 *((u32 *)dst) = be32_to_cpu(*((u32 *)src));
43 debug("%s: Unknown AXI transfer size '%d'\n", __func__, size);
48 static int sandbox_store_read(struct udevice *dev, ulong address, void *data,
51 struct sandbox_store_priv *priv = dev_get_priv(dev);
53 return copy_axi_data(priv->store + address, data, size);
56 static int sandbox_store_write(struct udevice *dev, ulong address, void *data,
59 struct sandbox_store_priv *priv = dev_get_priv(dev);
61 return copy_axi_data(data, priv->store + address, size);
64 static int sandbox_store_get_store(struct udevice *dev, u8 **store)
66 struct sandbox_store_priv *priv = dev_get_priv(dev);
73 static const struct udevice_id sandbox_store_ids[] = {
74 { .compatible = "sandbox,sandbox_store" },
78 static const struct axi_emul_ops sandbox_store_ops = {
79 .read = sandbox_store_read,
80 .write = sandbox_store_write,
81 .get_store = sandbox_store_get_store,
84 static int sandbox_store_probe(struct udevice *dev)
86 struct sandbox_store_priv *priv = dev_get_priv(dev);
90 ret = dev_read_u32_array(dev, "reg", reg, ARRAY_SIZE(reg));
92 debug("%s: Could not read 'reg' property\n", dev->name);
97 * Allocate the device's internal storage that will be read
100 priv->store = calloc(reg[1], 1);
107 static int sandbox_store_remove(struct udevice *dev)
109 struct sandbox_store_priv *priv = dev_get_priv(dev);
116 U_BOOT_DRIVER(sandbox_axi_store) = {
117 .name = "sandbox_axi_store",
118 .id = UCLASS_AXI_EMUL,
119 .of_match = sandbox_store_ids,
120 .ops = &sandbox_store_ops,
121 .priv_auto_alloc_size = sizeof(struct sandbox_store_priv),
122 .probe = sandbox_store_probe,
123 .remove = sandbox_store_remove,