rio_drv.h 14 KB

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