Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * RapidIO configuration space access support
0004  *
0005  * Copyright 2005 MontaVista Software, Inc.
0006  * Matt Porter <mporter@kernel.crashing.org>
0007  */
0008 
0009 #include <linux/rio.h>
0010 #include <linux/module.h>
0011 
0012 #include <linux/rio_drv.h>
0013 
0014 /*
0015  *  Wrappers for all RIO configuration access functions.  They just check
0016  *  alignment and call the low-level functions pointed to by rio_mport->ops.
0017  */
0018 
0019 #define RIO_8_BAD 0
0020 #define RIO_16_BAD (offset & 1)
0021 #define RIO_32_BAD (offset & 3)
0022 
0023 /**
0024  * RIO_LOP_READ - Generate rio_local_read_config_* functions
0025  * @size: Size of configuration space read (8, 16, 32 bits)
0026  * @type: C type of value argument
0027  * @len: Length of configuration space read (1, 2, 4 bytes)
0028  *
0029  * Generates rio_local_read_config_* functions used to access
0030  * configuration space registers on the local device.
0031  */
0032 #define RIO_LOP_READ(size,type,len) \
0033 int __rio_local_read_config_##size \
0034     (struct rio_mport *mport, u32 offset, type *value)      \
0035 {                                   \
0036     int res;                            \
0037     u32 data = 0;                           \
0038     if (RIO_##size##_BAD) return RIO_BAD_SIZE;          \
0039     res = mport->ops->lcread(mport, mport->id, offset, len, &data); \
0040     *value = (type)data;                        \
0041     return res;                         \
0042 }
0043 
0044 /**
0045  * RIO_LOP_WRITE - Generate rio_local_write_config_* functions
0046  * @size: Size of configuration space write (8, 16, 32 bits)
0047  * @type: C type of value argument
0048  * @len: Length of configuration space write (1, 2, 4 bytes)
0049  *
0050  * Generates rio_local_write_config_* functions used to access
0051  * configuration space registers on the local device.
0052  */
0053 #define RIO_LOP_WRITE(size,type,len) \
0054 int __rio_local_write_config_##size \
0055     (struct rio_mport *mport, u32 offset, type value)       \
0056 {                                   \
0057     if (RIO_##size##_BAD) return RIO_BAD_SIZE;          \
0058     return mport->ops->lcwrite(mport, mport->id, offset, len, value);\
0059 }
0060 
0061 RIO_LOP_READ(8, u8, 1)
0062 RIO_LOP_READ(16, u16, 2)
0063 RIO_LOP_READ(32, u32, 4)
0064 RIO_LOP_WRITE(8, u8, 1)
0065 RIO_LOP_WRITE(16, u16, 2)
0066 RIO_LOP_WRITE(32, u32, 4)
0067 
0068 EXPORT_SYMBOL_GPL(__rio_local_read_config_8);
0069 EXPORT_SYMBOL_GPL(__rio_local_read_config_16);
0070 EXPORT_SYMBOL_GPL(__rio_local_read_config_32);
0071 EXPORT_SYMBOL_GPL(__rio_local_write_config_8);
0072 EXPORT_SYMBOL_GPL(__rio_local_write_config_16);
0073 EXPORT_SYMBOL_GPL(__rio_local_write_config_32);
0074 
0075 /**
0076  * RIO_OP_READ - Generate rio_mport_read_config_* functions
0077  * @size: Size of configuration space read (8, 16, 32 bits)
0078  * @type: C type of value argument
0079  * @len: Length of configuration space read (1, 2, 4 bytes)
0080  *
0081  * Generates rio_mport_read_config_* functions used to access
0082  * configuration space registers on the local device.
0083  */
0084 #define RIO_OP_READ(size,type,len) \
0085 int rio_mport_read_config_##size \
0086     (struct rio_mport *mport, u16 destid, u8 hopcount, u32 offset, type *value) \
0087 {                                   \
0088     int res;                            \
0089     u32 data = 0;                           \
0090     if (RIO_##size##_BAD) return RIO_BAD_SIZE;          \
0091     res = mport->ops->cread(mport, mport->id, destid, hopcount, offset, len, &data); \
0092     *value = (type)data;                        \
0093     return res;                         \
0094 }
0095 
0096 /**
0097  * RIO_OP_WRITE - Generate rio_mport_write_config_* functions
0098  * @size: Size of configuration space write (8, 16, 32 bits)
0099  * @type: C type of value argument
0100  * @len: Length of configuration space write (1, 2, 4 bytes)
0101  *
0102  * Generates rio_mport_write_config_* functions used to access
0103  * configuration space registers on the local device.
0104  */
0105 #define RIO_OP_WRITE(size,type,len) \
0106 int rio_mport_write_config_##size \
0107     (struct rio_mport *mport, u16 destid, u8 hopcount, u32 offset, type value)  \
0108 {                                   \
0109     if (RIO_##size##_BAD) return RIO_BAD_SIZE;          \
0110     return mport->ops->cwrite(mport, mport->id, destid, hopcount,   \
0111             offset, len, value);                \
0112 }
0113 
0114 RIO_OP_READ(8, u8, 1)
0115 RIO_OP_READ(16, u16, 2)
0116 RIO_OP_READ(32, u32, 4)
0117 RIO_OP_WRITE(8, u8, 1)
0118 RIO_OP_WRITE(16, u16, 2)
0119 RIO_OP_WRITE(32, u32, 4)
0120 
0121 EXPORT_SYMBOL_GPL(rio_mport_read_config_8);
0122 EXPORT_SYMBOL_GPL(rio_mport_read_config_16);
0123 EXPORT_SYMBOL_GPL(rio_mport_read_config_32);
0124 EXPORT_SYMBOL_GPL(rio_mport_write_config_8);
0125 EXPORT_SYMBOL_GPL(rio_mport_write_config_16);
0126 EXPORT_SYMBOL_GPL(rio_mport_write_config_32);
0127 
0128 /**
0129  * rio_mport_send_doorbell - Send a doorbell message
0130  *
0131  * @mport: RIO master port
0132  * @destid: RIO device destination ID
0133  * @data: Doorbell message data
0134  *
0135  * Send a doorbell message to a RIO device. The doorbell message
0136  * has a 16-bit info field provided by the data argument.
0137  */
0138 int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid, u16 data)
0139 {
0140     return mport->ops->dsend(mport, mport->id, destid, data);
0141 }
0142 
0143 EXPORT_SYMBOL_GPL(rio_mport_send_doorbell);