rio_drv.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /*
  2. * RapidIO driver services
  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. #ifndef LINUX_RIO_DRV_H
  13. #define LINUX_RIO_DRV_H
  14. #include <linux/types.h>
  15. #include <linux/ioport.h>
  16. #include <linux/list.h>
  17. #include <linux/errno.h>
  18. #include <linux/string.h>
  19. #include <linux/rio.h>
  20. extern int __rio_local_read_config_32(struct rio_mport *port, u32 offset,
  21. u32 * data);
  22. extern int __rio_local_write_config_32(struct rio_mport *port, u32 offset,
  23. u32 data);
  24. extern int __rio_local_read_config_16(struct rio_mport *port, u32 offset,
  25. u16 * data);
  26. extern int __rio_local_write_config_16(struct rio_mport *port, u32 offset,
  27. u16 data);
  28. extern int __rio_local_read_config_8(struct rio_mport *port, u32 offset,
  29. u8 * data);
  30. extern int __rio_local_write_config_8(struct rio_mport *port, u32 offset,
  31. u8 data);
  32. extern int rio_mport_read_config_32(struct rio_mport *port, u16 destid,
  33. u8 hopcount, u32 offset, u32 * data);
  34. extern int rio_mport_write_config_32(struct rio_mport *port, u16 destid,
  35. u8 hopcount, u32 offset, u32 data);
  36. extern int rio_mport_read_config_16(struct rio_mport *port, u16 destid,
  37. u8 hopcount, u32 offset, u16 * data);
  38. extern int rio_mport_write_config_16(struct rio_mport *port, u16 destid,
  39. u8 hopcount, u32 offset, u16 data);
  40. extern int rio_mport_read_config_8(struct rio_mport *port, u16 destid,
  41. u8 hopcount, u32 offset, u8 * data);
  42. extern int rio_mport_write_config_8(struct rio_mport *port, u16 destid,
  43. u8 hopcount, u32 offset, u8 data);
  44. /**
  45. * rio_local_read_config_32 - Read 32 bits from local configuration space
  46. * @port: Master port
  47. * @offset: Offset into local configuration space
  48. * @data: Pointer to read data into
  49. *
  50. * Reads 32 bits of data from the specified offset within the local
  51. * device's configuration space.
  52. */
  53. static inline int rio_local_read_config_32(struct rio_mport *port, u32 offset,
  54. u32 * data)
  55. {
  56. return __rio_local_read_config_32(port, offset, data);
  57. }
  58. /**
  59. * rio_local_write_config_32 - Write 32 bits to local configuration space
  60. * @port: Master port
  61. * @offset: Offset into local configuration space
  62. * @data: Data to be written
  63. *
  64. * Writes 32 bits of data to the specified offset within the local
  65. * device's configuration space.
  66. */
  67. static inline int rio_local_write_config_32(struct rio_mport *port, u32 offset,
  68. u32 data)
  69. {
  70. return __rio_local_write_config_32(port, offset, data);
  71. }
  72. /**
  73. * rio_local_read_config_16 - Read 16 bits from local configuration space
  74. * @port: Master port
  75. * @offset: Offset into local configuration space
  76. * @data: Pointer to read data into
  77. *
  78. * Reads 16 bits of data from the specified offset within the local
  79. * device's configuration space.
  80. */
  81. static inline int rio_local_read_config_16(struct rio_mport *port, u32 offset,
  82. u16 * data)
  83. {
  84. return __rio_local_read_config_16(port, offset, data);
  85. }
  86. /**
  87. * rio_local_write_config_16 - Write 16 bits to local configuration space
  88. * @port: Master port
  89. * @offset: Offset into local configuration space
  90. * @data: Data to be written
  91. *
  92. * Writes 16 bits of data to the specified offset within the local
  93. * device's configuration space.
  94. */
  95. static inline int rio_local_write_config_16(struct rio_mport *port, u32 offset,
  96. u16 data)
  97. {
  98. return __rio_local_write_config_16(port, offset, data);
  99. }
  100. /**
  101. * rio_local_read_config_8 - Read 8 bits from local configuration space
  102. * @port: Master port
  103. * @offset: Offset into local configuration space
  104. * @data: Pointer to read data into
  105. *
  106. * Reads 8 bits of data from the specified offset within the local
  107. * device's configuration space.
  108. */
  109. static inline int rio_local_read_config_8(struct rio_mport *port, u32 offset,
  110. u8 * data)
  111. {
  112. return __rio_local_read_config_8(port, offset, data);
  113. }
  114. /**
  115. * rio_local_write_config_8 - Write 8 bits to local configuration space
  116. * @port: Master port
  117. * @offset: Offset into local configuration space
  118. * @data: Data to be written
  119. *
  120. * Writes 8 bits of data to the specified offset within the local
  121. * device's configuration space.
  122. */
  123. static inline int rio_local_write_config_8(struct rio_mport *port, u32 offset,
  124. u8 data)
  125. {
  126. return __rio_local_write_config_8(port, offset, data);
  127. }
  128. /**
  129. * rio_read_config_32 - Read 32 bits from configuration space
  130. * @rdev: RIO device
  131. * @offset: Offset into device configuration space
  132. * @data: Pointer to read data into
  133. *
  134. * Reads 32 bits of data from the specified offset within the
  135. * RIO device's configuration space.
  136. */
  137. static inline int rio_read_config_32(struct rio_dev *rdev, u32 offset,
  138. u32 * data)
  139. {
  140. return rio_mport_read_config_32(rdev->net->hport, rdev->destid,
  141. rdev->hopcount, offset, data);
  142. };
  143. /**
  144. * rio_write_config_32 - Write 32 bits to configuration space
  145. * @rdev: RIO device
  146. * @offset: Offset into device configuration space
  147. * @data: Data to be written
  148. *
  149. * Writes 32 bits of data to the specified offset within the
  150. * RIO device's configuration space.
  151. */
  152. static inline int rio_write_config_32(struct rio_dev *rdev, u32 offset,
  153. u32 data)
  154. {
  155. return rio_mport_write_config_32(rdev->net->hport, rdev->destid,
  156. rdev->hopcount, offset, data);
  157. };
  158. /**
  159. * rio_read_config_16 - Read 16 bits from configuration space
  160. * @rdev: RIO device
  161. * @offset: Offset into device configuration space
  162. * @data: Pointer to read data into
  163. *
  164. * Reads 16 bits of data from the specified offset within the
  165. * RIO device's configuration space.
  166. */
  167. static inline int rio_read_config_16(struct rio_dev *rdev, u32 offset,
  168. u16 * data)
  169. {
  170. return rio_mport_read_config_16(rdev->net->hport, rdev->destid,
  171. rdev->hopcount, offset, data);
  172. };
  173. /**
  174. * rio_write_config_16 - Write 16 bits to configuration space
  175. * @rdev: RIO device
  176. * @offset: Offset into device configuration space
  177. * @data: Data to be written
  178. *
  179. * Writes 16 bits of data to the specified offset within the
  180. * RIO device's configuration space.
  181. */
  182. static inline int rio_write_config_16(struct rio_dev *rdev, u32 offset,
  183. u16 data)
  184. {
  185. return rio_mport_write_config_16(rdev->net->hport, rdev->destid,
  186. rdev->hopcount, offset, data);
  187. };
  188. /**
  189. * rio_read_config_8 - Read 8 bits from configuration space
  190. * @rdev: RIO device
  191. * @offset: Offset into device configuration space
  192. * @data: Pointer to read data into
  193. *
  194. * Reads 8 bits of data from the specified offset within the
  195. * RIO device's configuration space.
  196. */
  197. static inline int rio_read_config_8(struct rio_dev *rdev, u32 offset, u8 * data)
  198. {
  199. return rio_mport_read_config_8(rdev->net->hport, rdev->destid,
  200. rdev->hopcount, offset, data);
  201. };
  202. /**
  203. * rio_write_config_8 - Write 8 bits to configuration space
  204. * @rdev: RIO device
  205. * @offset: Offset into device configuration space
  206. * @data: Data to be written
  207. *
  208. * Writes 8 bits of data to the specified offset within the
  209. * RIO device's configuration space.
  210. */
  211. static inline int rio_write_config_8(struct rio_dev *rdev, u32 offset, u8 data)
  212. {
  213. return rio_mport_write_config_8(rdev->net->hport, rdev->destid,
  214. rdev->hopcount, offset, data);
  215. };
  216. extern int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid,
  217. u16 data);
  218. /**
  219. * rio_send_doorbell - Send a doorbell message to a device
  220. * @rdev: RIO device
  221. * @data: Doorbell message data
  222. *
  223. * Send a doorbell message to a RIO device. The doorbell message
  224. * has a 16-bit info field provided by the @data argument.
  225. */
  226. static inline int rio_send_doorbell(struct rio_dev *rdev, u16 data)
  227. {
  228. return rio_mport_send_doorbell(rdev->net->hport, rdev->destid, data);
  229. };
  230. /**
  231. * rio_init_mbox_res - Initialize a RIO mailbox resource
  232. * @res: resource struct
  233. * @start: start of mailbox range
  234. * @end: end of mailbox range
  235. *
  236. * This function is used to initialize the fields of a resource
  237. * for use as a mailbox resource. It initializes a range of
  238. * mailboxes using the start and end arguments.
  239. */
  240. static inline void rio_init_mbox_res(struct resource *res, int start, int end)
  241. {
  242. memset(res, 0, sizeof(struct resource));
  243. res->start = start;
  244. res->end = end;
  245. res->flags = RIO_RESOURCE_MAILBOX;
  246. }
  247. /**
  248. * rio_init_dbell_res - Initialize a RIO doorbell resource
  249. * @res: resource struct
  250. * @start: start of doorbell range
  251. * @end: end of doorbell range
  252. *
  253. * This function is used to initialize the fields of a resource
  254. * for use as a doorbell resource. It initializes a range of
  255. * doorbell messages using the start and end arguments.
  256. */
  257. static inline void rio_init_dbell_res(struct resource *res, u16 start, u16 end)
  258. {
  259. memset(res, 0, sizeof(struct resource));
  260. res->start = start;
  261. res->end = end;
  262. res->flags = RIO_RESOURCE_DOORBELL;
  263. }
  264. /**
  265. * RIO_DEVICE - macro used to describe a specific RIO device
  266. * @dev: the 16 bit RIO device ID
  267. * @ven: the 16 bit RIO vendor ID
  268. *
  269. * This macro is used to create a struct rio_device_id that matches a
  270. * specific device. The assembly vendor and assembly device fields
  271. * will be set to %RIO_ANY_ID.
  272. */
  273. #define RIO_DEVICE(dev,ven) \
  274. .did = (dev), .vid = (ven), \
  275. .asm_did = RIO_ANY_ID, .asm_vid = RIO_ANY_ID
  276. /* Mailbox management */
  277. extern int rio_request_outb_mbox(struct rio_mport *, void *, int, int,
  278. void (*)(struct rio_mport *, void *,int, int));
  279. extern int rio_release_outb_mbox(struct rio_mport *, int);
  280. /**
  281. * rio_add_outb_message - Add RIO message to an outbound mailbox queue
  282. * @mport: RIO master port containing the outbound queue
  283. * @rdev: RIO device the message is be sent to
  284. * @mbox: The outbound mailbox queue
  285. * @buffer: Pointer to the message buffer
  286. * @len: Length of the message buffer
  287. *
  288. * Adds a RIO message buffer to an outbound mailbox queue for
  289. * transmission. Returns 0 on success.
  290. */
  291. static inline int rio_add_outb_message(struct rio_mport *mport,
  292. struct rio_dev *rdev, int mbox,
  293. void *buffer, size_t len)
  294. {
  295. return mport->ops->add_outb_message(mport, rdev, mbox,
  296. buffer, len);
  297. }
  298. extern int rio_request_inb_mbox(struct rio_mport *, void *, int, int,
  299. void (*)(struct rio_mport *, void *, int, int));
  300. extern int rio_release_inb_mbox(struct rio_mport *, int);
  301. /**
  302. * rio_add_inb_buffer - Add buffer to an inbound mailbox queue
  303. * @mport: Master port containing the inbound mailbox
  304. * @mbox: The inbound mailbox number
  305. * @buffer: Pointer to the message buffer
  306. *
  307. * Adds a buffer to an inbound mailbox queue for reception. Returns
  308. * 0 on success.
  309. */
  310. static inline int rio_add_inb_buffer(struct rio_mport *mport, int mbox,
  311. void *buffer)
  312. {
  313. return mport->ops->add_inb_buffer(mport, mbox, buffer);
  314. }
  315. /**
  316. * rio_get_inb_message - Get A RIO message from an inbound mailbox queue
  317. * @mport: Master port containing the inbound mailbox
  318. * @mbox: The inbound mailbox number
  319. *
  320. * Get a RIO message from an inbound mailbox queue. Returns 0 on success.
  321. */
  322. static inline void *rio_get_inb_message(struct rio_mport *mport, int mbox)
  323. {
  324. return mport->ops->get_inb_message(mport, mbox);
  325. }
  326. /* Doorbell management */
  327. extern int rio_request_inb_dbell(struct rio_mport *, void *, u16, u16,
  328. void (*)(struct rio_mport *, void *, u16, u16, u16));
  329. extern int rio_release_inb_dbell(struct rio_mport *, u16, u16);
  330. extern struct resource *rio_request_outb_dbell(struct rio_dev *, u16, u16);
  331. extern int rio_release_outb_dbell(struct rio_dev *, struct resource *);
  332. /* Memory region management */
  333. int rio_claim_resource(struct rio_dev *, int);
  334. int rio_request_regions(struct rio_dev *, char *);
  335. void rio_release_regions(struct rio_dev *);
  336. int rio_request_region(struct rio_dev *, int, char *);
  337. void rio_release_region(struct rio_dev *, int);
  338. /* Port-Write management */
  339. extern int rio_request_inb_pwrite(struct rio_dev *,
  340. int (*)(struct rio_dev *, union rio_pw_msg*, int));
  341. extern int rio_release_inb_pwrite(struct rio_dev *);
  342. extern int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg);
  343. /* LDM support */
  344. int rio_register_driver(struct rio_driver *);
  345. void rio_unregister_driver(struct rio_driver *);
  346. struct rio_dev *rio_dev_get(struct rio_dev *);
  347. void rio_dev_put(struct rio_dev *);
  348. /**
  349. * rio_name - Get the unique RIO device identifier
  350. * @rdev: RIO device
  351. *
  352. * Get the unique RIO device identifier. Returns the device
  353. * identifier string.
  354. */
  355. static inline const char *rio_name(struct rio_dev *rdev)
  356. {
  357. return dev_name(&rdev->dev);
  358. }
  359. /**
  360. * rio_get_drvdata - Get RIO driver specific data
  361. * @rdev: RIO device
  362. *
  363. * Get RIO driver specific data. Returns a pointer to the
  364. * driver specific data.
  365. */
  366. static inline void *rio_get_drvdata(struct rio_dev *rdev)
  367. {
  368. return dev_get_drvdata(&rdev->dev);
  369. }
  370. /**
  371. * rio_set_drvdata - Set RIO driver specific data
  372. * @rdev: RIO device
  373. * @data: Pointer to driver specific data
  374. *
  375. * Set RIO driver specific data. device struct driver data pointer
  376. * is set to the @data argument.
  377. */
  378. static inline void rio_set_drvdata(struct rio_dev *rdev, void *data)
  379. {
  380. dev_set_drvdata(&rdev->dev, data);
  381. }
  382. /* Misc driver helpers */
  383. extern u16 rio_local_get_device_id(struct rio_mport *port);
  384. extern struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from);
  385. extern struct rio_dev *rio_get_asm(u16 vid, u16 did, u16 asm_vid, u16 asm_did,
  386. struct rio_dev *from);
  387. #endif /* LINUX_RIO_DRV_H */