2 * RapidIO configuration space access support
4 * Copyright 2005 MontaVista Software, Inc.
5 * Matt Porter <mporter@kernel.crashing.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
13 #include <linux/rio.h>
14 #include <linux/module.h>
17 * Wrappers for all RIO configuration access functions. They just check
18 * alignment and call the low-level functions pointed to by rio_mport->ops.
22 #define RIO_16_BAD (offset & 1)
23 #define RIO_32_BAD (offset & 3)
26 * RIO_LOP_READ - Generate rio_local_read_config_* functions
27 * @size: Size of configuration space read (8, 16, 32 bits)
28 * @type: C type of value argument
29 * @len: Length of configuration space read (1, 2, 4 bytes)
31 * Generates rio_local_read_config_* functions used to access
32 * configuration space registers on the local device.
34 #define RIO_LOP_READ(size,type,len) \
35 int __rio_local_read_config_##size \
36 (struct rio_mport *mport, u32 offset, type *value) \
40 if (RIO_##size##_BAD) return RIO_BAD_SIZE; \
41 res = mport->ops->lcread(mport, mport->id, offset, len, &data); \
42 *value = (type)data; \
47 * RIO_LOP_WRITE - Generate rio_local_write_config_* functions
48 * @size: Size of configuration space write (8, 16, 32 bits)
49 * @type: C type of value argument
50 * @len: Length of configuration space write (1, 2, 4 bytes)
52 * Generates rio_local_write_config_* functions used to access
53 * configuration space registers on the local device.
55 #define RIO_LOP_WRITE(size,type,len) \
56 int __rio_local_write_config_##size \
57 (struct rio_mport *mport, u32 offset, type value) \
59 if (RIO_##size##_BAD) return RIO_BAD_SIZE; \
60 return mport->ops->lcwrite(mport, mport->id, offset, len, value);\
63 RIO_LOP_READ(8, u8, 1)
64 RIO_LOP_READ(16, u16, 2)
65 RIO_LOP_READ(32, u32, 4)
66 RIO_LOP_WRITE(8, u8, 1)
67 RIO_LOP_WRITE(16, u16, 2)
68 RIO_LOP_WRITE(32, u32, 4)
70 EXPORT_SYMBOL_GPL(__rio_local_read_config_8);
71 EXPORT_SYMBOL_GPL(__rio_local_read_config_16);
72 EXPORT_SYMBOL_GPL(__rio_local_read_config_32);
73 EXPORT_SYMBOL_GPL(__rio_local_write_config_8);
74 EXPORT_SYMBOL_GPL(__rio_local_write_config_16);
75 EXPORT_SYMBOL_GPL(__rio_local_write_config_32);
78 * RIO_OP_READ - Generate rio_mport_read_config_* functions
79 * @size: Size of configuration space read (8, 16, 32 bits)
80 * @type: C type of value argument
81 * @len: Length of configuration space read (1, 2, 4 bytes)
83 * Generates rio_mport_read_config_* functions used to access
84 * configuration space registers on the local device.
86 #define RIO_OP_READ(size,type,len) \
87 int rio_mport_read_config_##size \
88 (struct rio_mport *mport, u16 destid, u8 hopcount, u32 offset, type *value) \
92 if (RIO_##size##_BAD) return RIO_BAD_SIZE; \
93 res = mport->ops->cread(mport, mport->id, destid, hopcount, offset, len, &data); \
94 *value = (type)data; \
99 * RIO_OP_WRITE - Generate rio_mport_write_config_* functions
100 * @size: Size of configuration space write (8, 16, 32 bits)
101 * @type: C type of value argument
102 * @len: Length of configuration space write (1, 2, 4 bytes)
104 * Generates rio_mport_write_config_* functions used to access
105 * configuration space registers on the local device.
107 #define RIO_OP_WRITE(size,type,len) \
108 int rio_mport_write_config_##size \
109 (struct rio_mport *mport, u16 destid, u8 hopcount, u32 offset, type value) \
111 if (RIO_##size##_BAD) return RIO_BAD_SIZE; \
112 return mport->ops->cwrite(mport, mport->id, destid, hopcount, \
113 offset, len, value); \
116 RIO_OP_READ(8, u8, 1)
117 RIO_OP_READ(16, u16, 2)
118 RIO_OP_READ(32, u32, 4)
119 RIO_OP_WRITE(8, u8, 1)
120 RIO_OP_WRITE(16, u16, 2)
121 RIO_OP_WRITE(32, u32, 4)
123 EXPORT_SYMBOL_GPL(rio_mport_read_config_8);
124 EXPORT_SYMBOL_GPL(rio_mport_read_config_16);
125 EXPORT_SYMBOL_GPL(rio_mport_read_config_32);
126 EXPORT_SYMBOL_GPL(rio_mport_write_config_8);
127 EXPORT_SYMBOL_GPL(rio_mport_write_config_16);
128 EXPORT_SYMBOL_GPL(rio_mport_write_config_32);
131 * rio_mport_send_doorbell - Send a doorbell message
133 * @mport: RIO master port
134 * @destid: RIO device destination ID
135 * @data: Doorbell message data
137 * Send a doorbell message to a RIO device. The doorbell message
138 * has a 16-bit info field provided by the data argument.
140 int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid, u16 data)
142 return mport->ops->dsend(mport, mport->id, destid, data);
145 EXPORT_SYMBOL_GPL(rio_mport_send_doorbell);