rio-access.c 4.6 KB

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