rio-access.c 4.4 KB

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