12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2394b701cSMatt Porter /*
3394b701cSMatt Porter * RapidIO configuration space access support
4394b701cSMatt Porter *
5394b701cSMatt Porter * Copyright 2005 MontaVista Software, Inc.
6394b701cSMatt Porter * Matt Porter <mporter@kernel.crashing.org>
7394b701cSMatt Porter */
8394b701cSMatt Porter
9394b701cSMatt Porter #include <linux/rio.h>
10394b701cSMatt Porter #include <linux/module.h>
11394b701cSMatt Porter
12*bd7bca43SBen Dooks (Codethink) #include <linux/rio_drv.h>
13*bd7bca43SBen Dooks (Codethink)
14394b701cSMatt Porter /*
15394b701cSMatt Porter * Wrappers for all RIO configuration access functions. They just check
1631d1e130SIoan Nicu * alignment and call the low-level functions pointed to by rio_mport->ops.
17394b701cSMatt Porter */
18394b701cSMatt Porter
19394b701cSMatt Porter #define RIO_8_BAD 0
20394b701cSMatt Porter #define RIO_16_BAD (offset & 1)
21394b701cSMatt Porter #define RIO_32_BAD (offset & 3)
22394b701cSMatt Porter
23394b701cSMatt Porter /**
24394b701cSMatt Porter * RIO_LOP_READ - Generate rio_local_read_config_* functions
25394b701cSMatt Porter * @size: Size of configuration space read (8, 16, 32 bits)
26394b701cSMatt Porter * @type: C type of value argument
27394b701cSMatt Porter * @len: Length of configuration space read (1, 2, 4 bytes)
28394b701cSMatt Porter *
29394b701cSMatt Porter * Generates rio_local_read_config_* functions used to access
30394b701cSMatt Porter * configuration space registers on the local device.
31394b701cSMatt Porter */
32394b701cSMatt Porter #define RIO_LOP_READ(size,type,len) \
33394b701cSMatt Porter int __rio_local_read_config_##size \
34394b701cSMatt Porter (struct rio_mport *mport, u32 offset, type *value) \
35394b701cSMatt Porter { \
36394b701cSMatt Porter int res; \
37394b701cSMatt Porter u32 data = 0; \
38394b701cSMatt Porter if (RIO_##size##_BAD) return RIO_BAD_SIZE; \
39ad1e9380SZhang Wei res = mport->ops->lcread(mport, mport->id, offset, len, &data); \
40394b701cSMatt Porter *value = (type)data; \
41394b701cSMatt Porter return res; \
42394b701cSMatt Porter }
43394b701cSMatt Porter
44394b701cSMatt Porter /**
45394b701cSMatt Porter * RIO_LOP_WRITE - Generate rio_local_write_config_* functions
46394b701cSMatt Porter * @size: Size of configuration space write (8, 16, 32 bits)
47394b701cSMatt Porter * @type: C type of value argument
48394b701cSMatt Porter * @len: Length of configuration space write (1, 2, 4 bytes)
49394b701cSMatt Porter *
50394b701cSMatt Porter * Generates rio_local_write_config_* functions used to access
51394b701cSMatt Porter * configuration space registers on the local device.
52394b701cSMatt Porter */
53394b701cSMatt Porter #define RIO_LOP_WRITE(size,type,len) \
54394b701cSMatt Porter int __rio_local_write_config_##size \
55394b701cSMatt Porter (struct rio_mport *mport, u32 offset, type value) \
56394b701cSMatt Porter { \
57394b701cSMatt Porter if (RIO_##size##_BAD) return RIO_BAD_SIZE; \
5831d1e130SIoan Nicu return mport->ops->lcwrite(mport, mport->id, offset, len, value);\
59394b701cSMatt Porter }
60394b701cSMatt Porter
61394b701cSMatt Porter RIO_LOP_READ(8, u8, 1)
62394b701cSMatt Porter RIO_LOP_READ(16, u16, 2)
63394b701cSMatt Porter RIO_LOP_READ(32, u32, 4)
64394b701cSMatt Porter RIO_LOP_WRITE(8, u8, 1)
65394b701cSMatt Porter RIO_LOP_WRITE(16, u16, 2)
66394b701cSMatt Porter RIO_LOP_WRITE(32, u32, 4)
67394b701cSMatt Porter
68394b701cSMatt Porter EXPORT_SYMBOL_GPL(__rio_local_read_config_8);
69394b701cSMatt Porter EXPORT_SYMBOL_GPL(__rio_local_read_config_16);
70394b701cSMatt Porter EXPORT_SYMBOL_GPL(__rio_local_read_config_32);
71394b701cSMatt Porter EXPORT_SYMBOL_GPL(__rio_local_write_config_8);
72394b701cSMatt Porter EXPORT_SYMBOL_GPL(__rio_local_write_config_16);
73394b701cSMatt Porter EXPORT_SYMBOL_GPL(__rio_local_write_config_32);
74394b701cSMatt Porter
75394b701cSMatt Porter /**
76394b701cSMatt Porter * RIO_OP_READ - Generate rio_mport_read_config_* functions
77394b701cSMatt Porter * @size: Size of configuration space read (8, 16, 32 bits)
78394b701cSMatt Porter * @type: C type of value argument
79394b701cSMatt Porter * @len: Length of configuration space read (1, 2, 4 bytes)
80394b701cSMatt Porter *
81394b701cSMatt Porter * Generates rio_mport_read_config_* functions used to access
82394b701cSMatt Porter * configuration space registers on the local device.
83394b701cSMatt Porter */
84394b701cSMatt Porter #define RIO_OP_READ(size,type,len) \
85394b701cSMatt Porter int rio_mport_read_config_##size \
86394b701cSMatt Porter (struct rio_mport *mport, u16 destid, u8 hopcount, u32 offset, type *value) \
87394b701cSMatt Porter { \
88394b701cSMatt Porter int res; \
89394b701cSMatt Porter u32 data = 0; \
90394b701cSMatt Porter if (RIO_##size##_BAD) return RIO_BAD_SIZE; \
91ad1e9380SZhang Wei res = mport->ops->cread(mport, mport->id, destid, hopcount, offset, len, &data); \
92394b701cSMatt Porter *value = (type)data; \
93394b701cSMatt Porter return res; \
94394b701cSMatt Porter }
95394b701cSMatt Porter
96394b701cSMatt Porter /**
97394b701cSMatt Porter * RIO_OP_WRITE - Generate rio_mport_write_config_* functions
98394b701cSMatt Porter * @size: Size of configuration space write (8, 16, 32 bits)
99394b701cSMatt Porter * @type: C type of value argument
100394b701cSMatt Porter * @len: Length of configuration space write (1, 2, 4 bytes)
101394b701cSMatt Porter *
102394b701cSMatt Porter * Generates rio_mport_write_config_* functions used to access
103394b701cSMatt Porter * configuration space registers on the local device.
104394b701cSMatt Porter */
105394b701cSMatt Porter #define RIO_OP_WRITE(size,type,len) \
106394b701cSMatt Porter int rio_mport_write_config_##size \
107394b701cSMatt Porter (struct rio_mport *mport, u16 destid, u8 hopcount, u32 offset, type value) \
108394b701cSMatt Porter { \
109394b701cSMatt Porter if (RIO_##size##_BAD) return RIO_BAD_SIZE; \
11031d1e130SIoan Nicu return mport->ops->cwrite(mport, mport->id, destid, hopcount, \
11131d1e130SIoan Nicu offset, len, value); \
112394b701cSMatt Porter }
113394b701cSMatt Porter
114394b701cSMatt Porter RIO_OP_READ(8, u8, 1)
115394b701cSMatt Porter RIO_OP_READ(16, u16, 2)
116394b701cSMatt Porter RIO_OP_READ(32, u32, 4)
117394b701cSMatt Porter RIO_OP_WRITE(8, u8, 1)
118394b701cSMatt Porter RIO_OP_WRITE(16, u16, 2)
119394b701cSMatt Porter RIO_OP_WRITE(32, u32, 4)
120394b701cSMatt Porter
121394b701cSMatt Porter EXPORT_SYMBOL_GPL(rio_mport_read_config_8);
122394b701cSMatt Porter EXPORT_SYMBOL_GPL(rio_mport_read_config_16);
123394b701cSMatt Porter EXPORT_SYMBOL_GPL(rio_mport_read_config_32);
124394b701cSMatt Porter EXPORT_SYMBOL_GPL(rio_mport_write_config_8);
125394b701cSMatt Porter EXPORT_SYMBOL_GPL(rio_mport_write_config_16);
126394b701cSMatt Porter EXPORT_SYMBOL_GPL(rio_mport_write_config_32);
127394b701cSMatt Porter
128394b701cSMatt Porter /**
129394b701cSMatt Porter * rio_mport_send_doorbell - Send a doorbell message
130394b701cSMatt Porter *
131394b701cSMatt Porter * @mport: RIO master port
132394b701cSMatt Porter * @destid: RIO device destination ID
133394b701cSMatt Porter * @data: Doorbell message data
134394b701cSMatt Porter *
135394b701cSMatt Porter * Send a doorbell message to a RIO device. The doorbell message
136394b701cSMatt Porter * has a 16-bit info field provided by the data argument.
137394b701cSMatt Porter */
rio_mport_send_doorbell(struct rio_mport * mport,u16 destid,u16 data)138394b701cSMatt Porter int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid, u16 data)
139394b701cSMatt Porter {
14031d1e130SIoan Nicu return mport->ops->dsend(mport, mport->id, destid, data);
141394b701cSMatt Porter }
142394b701cSMatt Porter
143394b701cSMatt Porter EXPORT_SYMBOL_GPL(rio_mport_send_doorbell);
144