xref: /openbmc/linux/include/linux/logic_iomem.h (revision ca2e3342)
1*ca2e3342SJohannes Berg /* SPDX-License-Identifier: GPL-2.0 */
2*ca2e3342SJohannes Berg /*
3*ca2e3342SJohannes Berg  * Copyright (C) 2021 Intel Corporation
4*ca2e3342SJohannes Berg  * Author: johannes@sipsolutions.net
5*ca2e3342SJohannes Berg  */
6*ca2e3342SJohannes Berg #ifndef __LOGIC_IOMEM_H
7*ca2e3342SJohannes Berg #define __LOGIC_IOMEM_H
8*ca2e3342SJohannes Berg #include <linux/types.h>
9*ca2e3342SJohannes Berg #include <linux/ioport.h>
10*ca2e3342SJohannes Berg 
11*ca2e3342SJohannes Berg /**
12*ca2e3342SJohannes Berg  * struct logic_iomem_ops - emulated IO memory ops
13*ca2e3342SJohannes Berg  * @read: read an 8, 16, 32 or 64 bit quantity from the given offset,
14*ca2e3342SJohannes Berg  *	size is given in bytes (1, 2, 4 or 8)
15*ca2e3342SJohannes Berg  *	(64-bit only necessary if CONFIG_64BIT is set)
16*ca2e3342SJohannes Berg  * @write: write an 8, 16 32 or 64 bit quantity to the given offset,
17*ca2e3342SJohannes Berg  *	size is given in bytes (1, 2, 4 or 8)
18*ca2e3342SJohannes Berg  *	(64-bit only necessary if CONFIG_64BIT is set)
19*ca2e3342SJohannes Berg  * @set: optional, for memset_io()
20*ca2e3342SJohannes Berg  * @copy_from: optional, for memcpy_fromio()
21*ca2e3342SJohannes Berg  * @copy_to: optional, for memcpy_toio()
22*ca2e3342SJohannes Berg  * @unmap: optional, this region is getting unmapped
23*ca2e3342SJohannes Berg  */
24*ca2e3342SJohannes Berg struct logic_iomem_ops {
25*ca2e3342SJohannes Berg 	unsigned long (*read)(void *priv, unsigned int offset, int size);
26*ca2e3342SJohannes Berg 	void (*write)(void *priv, unsigned int offset, int size,
27*ca2e3342SJohannes Berg 		      unsigned long val);
28*ca2e3342SJohannes Berg 
29*ca2e3342SJohannes Berg 	void (*set)(void *priv, unsigned int offset, u8 value, int size);
30*ca2e3342SJohannes Berg 	void (*copy_from)(void *priv, void *buffer, unsigned int offset,
31*ca2e3342SJohannes Berg 			  int size);
32*ca2e3342SJohannes Berg 	void (*copy_to)(void *priv, unsigned int offset, const void *buffer,
33*ca2e3342SJohannes Berg 			int size);
34*ca2e3342SJohannes Berg 
35*ca2e3342SJohannes Berg 	void (*unmap)(void *priv);
36*ca2e3342SJohannes Berg };
37*ca2e3342SJohannes Berg 
38*ca2e3342SJohannes Berg /**
39*ca2e3342SJohannes Berg  * struct logic_iomem_region_ops - ops for an IO memory handler
40*ca2e3342SJohannes Berg  * @map: map a range in the registered IO memory region, must
41*ca2e3342SJohannes Berg  *	fill *ops with the ops and may fill *priv to be passed
42*ca2e3342SJohannes Berg  *	to the ops. The offset is given as the offset into the
43*ca2e3342SJohannes Berg  *	registered resource region.
44*ca2e3342SJohannes Berg  *	The return value is negative for errors, or >= 0 for
45*ca2e3342SJohannes Berg  *	success. On success, the return value is added to the
46*ca2e3342SJohannes Berg  *	offset for later ops, to allow for partial mappings.
47*ca2e3342SJohannes Berg  */
48*ca2e3342SJohannes Berg struct logic_iomem_region_ops {
49*ca2e3342SJohannes Berg 	long (*map)(unsigned long offset, size_t size,
50*ca2e3342SJohannes Berg 		    const struct logic_iomem_ops **ops,
51*ca2e3342SJohannes Berg 		    void **priv);
52*ca2e3342SJohannes Berg };
53*ca2e3342SJohannes Berg 
54*ca2e3342SJohannes Berg /**
55*ca2e3342SJohannes Berg  * logic_iomem_add_region - register an IO memory region
56*ca2e3342SJohannes Berg  * @resource: the resource description for this region
57*ca2e3342SJohannes Berg  * @ops: the IO memory mapping ops for this resource
58*ca2e3342SJohannes Berg  */
59*ca2e3342SJohannes Berg int logic_iomem_add_region(struct resource *resource,
60*ca2e3342SJohannes Berg 			   const struct logic_iomem_region_ops *ops);
61*ca2e3342SJohannes Berg 
62*ca2e3342SJohannes Berg #endif /* __LOGIC_IOMEM_H */
63