1
2
3
4
5
6
7#include <common.h>
8#include <axi.h>
9#include <dm.h>
10
11
12
13
14
15
16struct sandbox_store_priv {
17 u8 *store;
18};
19
20
21
22
23
24
25
26
27
28
29static int copy_axi_data(void *src, void *dst, enum axi_size_t size)
30{
31 switch (size) {
32 case AXI_SIZE_8:
33 *((u8 *)dst) = *((u8 *)src);
34 return 0;
35 case AXI_SIZE_16:
36 *((u16 *)dst) = be16_to_cpu(*((u16 *)src));
37 return 0;
38 case AXI_SIZE_32:
39 *((u32 *)dst) = be32_to_cpu(*((u32 *)src));
40 return 0;
41 default:
42 debug("%s: Unknown AXI transfer size '%d'\n", __func__, size);
43 return -EINVAL;
44 }
45}
46
47static int sandbox_store_read(struct udevice *dev, ulong address, void *data,
48 enum axi_size_t size)
49{
50 struct sandbox_store_priv *priv = dev_get_priv(dev);
51
52 return copy_axi_data(priv->store + address, data, size);
53}
54
55static int sandbox_store_write(struct udevice *dev, ulong address, void *data,
56 enum axi_size_t size)
57{
58 struct sandbox_store_priv *priv = dev_get_priv(dev);
59
60 return copy_axi_data(data, priv->store + address, size);
61}
62
63static int sandbox_store_get_store(struct udevice *dev, u8 **store)
64{
65 struct sandbox_store_priv *priv = dev_get_priv(dev);
66
67 *store = priv->store;
68
69 return 0;
70}
71
72static const struct udevice_id sandbox_store_ids[] = {
73 { .compatible = "sandbox,sandbox_store" },
74 { }
75};
76
77static 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,
81};
82
83static int sandbox_store_probe(struct udevice *dev)
84{
85 struct sandbox_store_priv *priv = dev_get_priv(dev);
86 u32 reg[2];
87 int ret;
88
89 ret = dev_read_u32_array(dev, "reg", reg, ARRAY_SIZE(reg));
90 if (ret) {
91 debug("%s: Could not read 'reg' property\n", dev->name);
92 return -EINVAL;
93 }
94
95
96
97
98
99 priv->store = calloc(reg[1], 1);
100 if (!priv->store)
101 return -ENOMEM;
102
103 return 0;
104}
105
106static int sandbox_store_remove(struct udevice *dev)
107{
108 struct sandbox_store_priv *priv = dev_get_priv(dev);
109
110 free(priv->store);
111
112 return 0;
113}
114
115U_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,
123};
124