xref: /openbmc/u-boot/arch/sandbox/include/asm/axi.h (revision 282ce6454c45409805e2c470bbec170d21a4bd35)
1*9a8bcabdSMario Six /* SPDX-License-Identifier: GPL-2.0+ */
2*9a8bcabdSMario Six /*
3*9a8bcabdSMario Six  * (C) Copyright 2018
4*9a8bcabdSMario Six  * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
5*9a8bcabdSMario Six  */
6*9a8bcabdSMario Six 
7*9a8bcabdSMario Six #ifndef __asm_axi_h
8*9a8bcabdSMario Six #define __asm_axi_h
9*9a8bcabdSMario Six 
10*9a8bcabdSMario Six #define axi_emul_get_ops(dev)	((struct axi_emul_ops *)(dev)->driver->ops)
11*9a8bcabdSMario Six 
12*9a8bcabdSMario Six /**
13*9a8bcabdSMario Six  * axi_sandbox_get_emul() - Retrieve a pointer to a AXI emulation device
14*9a8bcabdSMario Six  * @bus:     The AXI bus from which to retrieve a emulation device
15*9a8bcabdSMario Six  * @address: The address of a transfer that should be handled by a emulation
16*9a8bcabdSMario Six  *	     device
17*9a8bcabdSMario Six  * @length:  The data width of a transfer that should be handled by a emulation
18*9a8bcabdSMario Six  *	     device
19*9a8bcabdSMario Six  * @emulp:   Pointer to a buffer receiving the emulation device that handles
20*9a8bcabdSMario Six  *	     the transfer specified by the address and length parameters
21*9a8bcabdSMario Six  *
22*9a8bcabdSMario Six  * To test the AXI uclass, we implement a simple AXI emulation device, which is
23*9a8bcabdSMario Six  * a virtual device on a AXI bus that exposes a simple storage interface: When
24*9a8bcabdSMario Six  * reading and writing from the device, the addresses are translated to offsets
25*9a8bcabdSMario Six  * within the device's storage. For write accesses the data is written to the
26*9a8bcabdSMario Six  * specified storage offset, and for read accesses the data is read from the
27*9a8bcabdSMario Six  * specified storage offset.
28*9a8bcabdSMario Six  *
29*9a8bcabdSMario Six  * A DTS entry might look like this:
30*9a8bcabdSMario Six  *
31*9a8bcabdSMario Six  * axi: axi@0 {
32*9a8bcabdSMario Six  *	compatible = "sandbox,axi";
33*9a8bcabdSMario Six  *	#address-cells = <0x1>;
34*9a8bcabdSMario Six  *	#size-cells = <0x1>;
35*9a8bcabdSMario Six  *	store@0 {
36*9a8bcabdSMario Six  *		compatible = "sandbox,sandbox_store";
37*9a8bcabdSMario Six  *		reg = <0x0 0x400>;
38*9a8bcabdSMario Six  *	};
39*9a8bcabdSMario Six  * };
40*9a8bcabdSMario Six  *
41*9a8bcabdSMario Six  * This function may then be used to retrieve the pointer to the sandbox_store
42*9a8bcabdSMario Six  * emulation device given the AXI bus device, and the data (address, data
43*9a8bcabdSMario Six  * width) of a AXI transfer which should be handled by a emulation device.
44*9a8bcabdSMario Six  *
45*9a8bcabdSMario Six  * Return: 0 of OK, -ENODEV if no device capable of handling the specified
46*9a8bcabdSMario Six  *	   transfer exists or the device could not be retrieved
47*9a8bcabdSMario Six  */
48*9a8bcabdSMario Six int axi_sandbox_get_emul(struct udevice *bus, ulong address, uint length,
49*9a8bcabdSMario Six 			 struct udevice **emulp);
50*9a8bcabdSMario Six /**
51*9a8bcabdSMario Six  * axi_get_store() - Get address of internal storage of a emulated AXI device
52*9a8bcabdSMario Six  * @dev:	Emulated AXI device to get the pointer of the internal storage
53*9a8bcabdSMario Six  *		for.
54*9a8bcabdSMario Six  * @storep:	Pointer to the internal storage of the emulated AXI device.
55*9a8bcabdSMario Six  *
56*9a8bcabdSMario Six  * To preset or read back the contents internal storage of the emulated AXI
57*9a8bcabdSMario Six  * device, this function returns the pointer to the storage. Changes to the
58*9a8bcabdSMario Six  * contents of the storage are reflected when using the AXI read/write API
59*9a8bcabdSMario Six  * methods, and vice versa, so by using this method expected read data can be
60*9a8bcabdSMario Six  * set up in advance, and written data can be checked in unit tests.
61*9a8bcabdSMario Six  *
62*9a8bcabdSMario Six  * Return: 0 if OK, -ve on error.
63*9a8bcabdSMario Six  */
64*9a8bcabdSMario Six int axi_get_store(struct udevice *dev, u8 **storep);
65*9a8bcabdSMario Six 
66*9a8bcabdSMario Six #endif /* __asm_axi_h */
67