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