Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * RapidIO configuration space access support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2005 MontaVista Software, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Matt Porter <mporter@kernel.crashing.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/rio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/rio_drv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *  Wrappers for all RIO configuration access functions.  They just check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *  alignment and call the low-level functions pointed to by rio_mport->ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define RIO_8_BAD 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define RIO_16_BAD (offset & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define RIO_32_BAD (offset & 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * RIO_LOP_READ - Generate rio_local_read_config_* functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * @size: Size of configuration space read (8, 16, 32 bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * @type: C type of value argument
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * @len: Length of configuration space read (1, 2, 4 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * Generates rio_local_read_config_* functions used to access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * configuration space registers on the local device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define RIO_LOP_READ(size,type,len) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) int __rio_local_read_config_##size \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	(struct rio_mport *mport, u32 offset, type *value)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	int res;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	u32 data = 0;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (RIO_##size##_BAD) return RIO_BAD_SIZE;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	res = mport->ops->lcread(mport, mport->id, offset, len, &data);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	*value = (type)data;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return res;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * RIO_LOP_WRITE - Generate rio_local_write_config_* functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * @size: Size of configuration space write (8, 16, 32 bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * @type: C type of value argument
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * @len: Length of configuration space write (1, 2, 4 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * Generates rio_local_write_config_* functions used to access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * configuration space registers on the local device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define RIO_LOP_WRITE(size,type,len) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) int __rio_local_write_config_##size \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	(struct rio_mport *mport, u32 offset, type value)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (RIO_##size##_BAD) return RIO_BAD_SIZE;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	return mport->ops->lcwrite(mport, mport->id, offset, len, value);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) RIO_LOP_READ(8, u8, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) RIO_LOP_READ(16, u16, 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) RIO_LOP_READ(32, u32, 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) RIO_LOP_WRITE(8, u8, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) RIO_LOP_WRITE(16, u16, 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) RIO_LOP_WRITE(32, u32, 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) EXPORT_SYMBOL_GPL(__rio_local_read_config_8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) EXPORT_SYMBOL_GPL(__rio_local_read_config_16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) EXPORT_SYMBOL_GPL(__rio_local_read_config_32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) EXPORT_SYMBOL_GPL(__rio_local_write_config_8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) EXPORT_SYMBOL_GPL(__rio_local_write_config_16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) EXPORT_SYMBOL_GPL(__rio_local_write_config_32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * RIO_OP_READ - Generate rio_mport_read_config_* functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * @size: Size of configuration space read (8, 16, 32 bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * @type: C type of value argument
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * @len: Length of configuration space read (1, 2, 4 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * Generates rio_mport_read_config_* functions used to access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * configuration space registers on the local device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #define RIO_OP_READ(size,type,len) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) int rio_mport_read_config_##size \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	(struct rio_mport *mport, u16 destid, u8 hopcount, u32 offset, type *value)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	int res;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	u32 data = 0;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (RIO_##size##_BAD) return RIO_BAD_SIZE;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	res = mport->ops->cread(mport, mport->id, destid, hopcount, offset, len, &data); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	*value = (type)data;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	return res;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * RIO_OP_WRITE - Generate rio_mport_write_config_* functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * @size: Size of configuration space write (8, 16, 32 bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * @type: C type of value argument
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * @len: Length of configuration space write (1, 2, 4 bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * Generates rio_mport_write_config_* functions used to access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * configuration space registers on the local device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define RIO_OP_WRITE(size,type,len) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int rio_mport_write_config_##size \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	(struct rio_mport *mport, u16 destid, u8 hopcount, u32 offset, type value)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if (RIO_##size##_BAD) return RIO_BAD_SIZE;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return mport->ops->cwrite(mport, mport->id, destid, hopcount,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			offset, len, value);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) RIO_OP_READ(8, u8, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) RIO_OP_READ(16, u16, 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) RIO_OP_READ(32, u32, 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) RIO_OP_WRITE(8, u8, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) RIO_OP_WRITE(16, u16, 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) RIO_OP_WRITE(32, u32, 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) EXPORT_SYMBOL_GPL(rio_mport_read_config_8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) EXPORT_SYMBOL_GPL(rio_mport_read_config_16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) EXPORT_SYMBOL_GPL(rio_mport_read_config_32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) EXPORT_SYMBOL_GPL(rio_mport_write_config_8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) EXPORT_SYMBOL_GPL(rio_mport_write_config_16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) EXPORT_SYMBOL_GPL(rio_mport_write_config_32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * rio_mport_send_doorbell - Send a doorbell message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  * @mport: RIO master port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  * @destid: RIO device destination ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  * @data: Doorbell message data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * Send a doorbell message to a RIO device. The doorbell message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * has a 16-bit info field provided by the data argument.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid, u16 data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	return mport->ops->dsend(mport, mport->id, destid, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) EXPORT_SYMBOL_GPL(rio_mport_send_doorbell);