rio_drv.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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. u8 hopcount = 0xff;
  142. u16 destid = rdev->destid;
  143. if (rdev->rswitch) {
  144. destid = rdev->rswitch->destid;
  145. hopcount = rdev->rswitch->hopcount;
  146. }
  147. return rio_mport_read_config_32(rdev->net->hport, destid, hopcount,
  148. offset, data);
  149. };
  150. /**
  151. * rio_write_config_32 - Write 32 bits to configuration space
  152. * @rdev: RIO device
  153. * @offset: Offset into device configuration space
  154. * @data: Data to be written
  155. *
  156. * Writes 32 bits of data to the specified offset within the
  157. * RIO device's configuration space.
  158. */
  159. static inline int rio_write_config_32(struct rio_dev *rdev, u32 offset,
  160. u32 data)
  161. {
  162. u8 hopcount = 0xff;
  163. u16 destid = rdev->destid;
  164. if (rdev->rswitch) {
  165. destid = rdev->rswitch->destid;
  166. hopcount = rdev->rswitch->hopcount;
  167. }
  168. return rio_mport_write_config_32(rdev->net->hport, destid, hopcount,
  169. offset, data);
  170. };
  171. /**
  172. * rio_read_config_16 - Read 16 bits from configuration space
  173. * @rdev: RIO device
  174. * @offset: Offset into device configuration space
  175. * @data: Pointer to read data into
  176. *
  177. * Reads 16 bits of data from the specified offset within the
  178. * RIO device's configuration space.
  179. */
  180. static inline int rio_read_config_16(struct rio_dev *rdev, u32 offset,
  181. u16 * data)
  182. {
  183. u8 hopcount = 0xff;
  184. u16 destid = rdev->destid;
  185. if (rdev->rswitch) {
  186. destid = rdev->rswitch->destid;
  187. hopcount = rdev->rswitch->hopcount;
  188. }
  189. return rio_mport_read_config_16(rdev->net->hport, destid, hopcount,
  190. offset, data);
  191. };
  192. /**
  193. * rio_write_config_16 - Write 16 bits to configuration space
  194. * @rdev: RIO device
  195. * @offset: Offset into device configuration space
  196. * @data: Data to be written
  197. *
  198. * Writes 16 bits of data to the specified offset within the
  199. * RIO device's configuration space.
  200. */
  201. static inline int rio_write_config_16(struct rio_dev *rdev, u32 offset,
  202. u16 data)
  203. {
  204. u8 hopcount = 0xff;
  205. u16 destid = rdev->destid;
  206. if (rdev->rswitch) {
  207. destid = rdev->rswitch->destid;
  208. hopcount = rdev->rswitch->hopcount;
  209. }
  210. return rio_mport_write_config_16(rdev->net->hport, destid, hopcount,
  211. offset, data);
  212. };
  213. /**
  214. * rio_read_config_8 - Read 8 bits from configuration space
  215. * @rdev: RIO device
  216. * @offset: Offset into device configuration space
  217. * @data: Pointer to read data into
  218. *
  219. * Reads 8 bits of data from the specified offset within the
  220. * RIO device's configuration space.
  221. */
  222. static inline int rio_read_config_8(struct rio_dev *rdev, u32 offset, u8 * data)
  223. {
  224. u8 hopcount = 0xff;
  225. u16 destid = rdev->destid;
  226. if (rdev->rswitch) {
  227. destid = rdev->rswitch->destid;
  228. hopcount = rdev->rswitch->hopcount;
  229. }
  230. return rio_mport_read_config_8(rdev->net->hport, destid, hopcount,
  231. offset, data);
  232. };
  233. /**
  234. * rio_write_config_8 - Write 8 bits to configuration space
  235. * @rdev: RIO device
  236. * @offset: Offset into device configuration space
  237. * @data: Data to be written
  238. *
  239. * Writes 8 bits of data to the specified offset within the
  240. * RIO device's configuration space.
  241. */
  242. static inline int rio_write_config_8(struct rio_dev *rdev, u32 offset, u8 data)
  243. {
  244. u8 hopcount = 0xff;
  245. u16 destid = rdev->destid;
  246. if (rdev->rswitch) {
  247. destid = rdev->rswitch->destid;
  248. hopcount = rdev->rswitch->hopcount;
  249. }
  250. return rio_mport_write_config_8(rdev->net->hport, destid, hopcount,
  251. offset, data);
  252. };
  253. extern int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid,
  254. u16 data);
  255. /**
  256. * rio_send_doorbell - Send a doorbell message to a device
  257. * @rdev: RIO device
  258. * @data: Doorbell message data
  259. *
  260. * Send a doorbell message to a RIO device. The doorbell message
  261. * has a 16-bit info field provided by the @data argument.
  262. */
  263. static inline int rio_send_doorbell(struct rio_dev *rdev, u16 data)
  264. {
  265. return rio_mport_send_doorbell(rdev->net->hport, rdev->destid, data);
  266. };
  267. /**
  268. * rio_init_mbox_res - Initialize a RIO mailbox resource
  269. * @res: resource struct
  270. * @start: start of mailbox range
  271. * @end: end of mailbox range
  272. *
  273. * This function is used to initialize the fields of a resource
  274. * for use as a mailbox resource. It initializes a range of
  275. * mailboxes using the start and end arguments.
  276. */
  277. static inline void rio_init_mbox_res(struct resource *res, int start, int end)
  278. {
  279. memset(res, 0, sizeof(struct resource));
  280. res->start = start;
  281. res->end = end;
  282. res->flags = RIO_RESOURCE_MAILBOX;
  283. }
  284. /**
  285. * rio_init_dbell_res - Initialize a RIO doorbell resource
  286. * @res: resource struct
  287. * @start: start of doorbell range
  288. * @end: end of doorbell range
  289. *
  290. * This function is used to initialize the fields of a resource
  291. * for use as a doorbell resource. It initializes a range of
  292. * doorbell messages using the start and end arguments.
  293. */
  294. static inline void rio_init_dbell_res(struct resource *res, u16 start, u16 end)
  295. {
  296. memset(res, 0, sizeof(struct resource));
  297. res->start = start;
  298. res->end = end;
  299. res->flags = RIO_RESOURCE_DOORBELL;
  300. }
  301. /**
  302. * RIO_DEVICE - macro used to describe a specific RIO device
  303. * @dev: the 16 bit RIO device ID
  304. * @ven: the 16 bit RIO vendor ID
  305. *
  306. * This macro is used to create a struct rio_device_id that matches a
  307. * specific device. The assembly vendor and assembly device fields
  308. * will be set to %RIO_ANY_ID.
  309. */
  310. #define RIO_DEVICE(dev,ven) \
  311. .did = (dev), .vid = (ven), \
  312. .asm_did = RIO_ANY_ID, .asm_vid = RIO_ANY_ID
  313. /* Mailbox management */
  314. extern int rio_request_outb_mbox(struct rio_mport *, void *, int, int,
  315. void (*)(struct rio_mport *, void *,int, int));
  316. extern int rio_release_outb_mbox(struct rio_mport *, int);
  317. /**
  318. * rio_add_outb_message - Add RIO message to an outbound mailbox queue
  319. * @mport: RIO master port containing the outbound queue
  320. * @rdev: RIO device the message is be sent to
  321. * @mbox: The outbound mailbox queue
  322. * @buffer: Pointer to the message buffer
  323. * @len: Length of the message buffer
  324. *
  325. * Adds a RIO message buffer to an outbound mailbox queue for
  326. * transmission. Returns 0 on success.
  327. */
  328. static inline int rio_add_outb_message(struct rio_mport *mport,
  329. struct rio_dev *rdev, int mbox,
  330. void *buffer, size_t len)
  331. {
  332. return rio_hw_add_outb_message(mport, rdev, mbox, buffer, len);
  333. }
  334. extern int rio_request_inb_mbox(struct rio_mport *, void *, int, int,
  335. void (*)(struct rio_mport *, void *, int, int));
  336. extern int rio_release_inb_mbox(struct rio_mport *, int);
  337. /**
  338. * rio_add_inb_buffer - Add buffer to an inbound mailbox queue
  339. * @mport: Master port containing the inbound mailbox
  340. * @mbox: The inbound mailbox number
  341. * @buffer: Pointer to the message buffer
  342. *
  343. * Adds a buffer to an inbound mailbox queue for reception. Returns
  344. * 0 on success.
  345. */
  346. static inline int rio_add_inb_buffer(struct rio_mport *mport, int mbox,
  347. void *buffer)
  348. {
  349. return rio_hw_add_inb_buffer(mport, mbox, buffer);
  350. }
  351. /**
  352. * rio_get_inb_message - Get A RIO message from an inbound mailbox queue
  353. * @mport: Master port containing the inbound mailbox
  354. * @mbox: The inbound mailbox number
  355. *
  356. * Get a RIO message from an inbound mailbox queue. Returns 0 on success.
  357. */
  358. static inline void *rio_get_inb_message(struct rio_mport *mport, int mbox)
  359. {
  360. return rio_hw_get_inb_message(mport, mbox);
  361. }
  362. /* Doorbell management */
  363. extern int rio_request_inb_dbell(struct rio_mport *, void *, u16, u16,
  364. void (*)(struct rio_mport *, void *, u16, u16, u16));
  365. extern int rio_release_inb_dbell(struct rio_mport *, u16, u16);
  366. extern struct resource *rio_request_outb_dbell(struct rio_dev *, u16, u16);
  367. extern int rio_release_outb_dbell(struct rio_dev *, struct resource *);
  368. /* Memory region management */
  369. int rio_claim_resource(struct rio_dev *, int);
  370. int rio_request_regions(struct rio_dev *, char *);
  371. void rio_release_regions(struct rio_dev *);
  372. int rio_request_region(struct rio_dev *, int, char *);
  373. void rio_release_region(struct rio_dev *, int);
  374. /* Port-Write management */
  375. extern int rio_request_inb_pwrite(struct rio_dev *,
  376. int (*)(struct rio_dev *, union rio_pw_msg*, int));
  377. extern int rio_release_inb_pwrite(struct rio_dev *);
  378. extern int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg);
  379. /* LDM support */
  380. int rio_register_driver(struct rio_driver *);
  381. void rio_unregister_driver(struct rio_driver *);
  382. struct rio_dev *rio_dev_get(struct rio_dev *);
  383. void rio_dev_put(struct rio_dev *);
  384. /**
  385. * rio_name - Get the unique RIO device identifier
  386. * @rdev: RIO device
  387. *
  388. * Get the unique RIO device identifier. Returns the device
  389. * identifier string.
  390. */
  391. static inline const char *rio_name(struct rio_dev *rdev)
  392. {
  393. return dev_name(&rdev->dev);
  394. }
  395. /**
  396. * rio_get_drvdata - Get RIO driver specific data
  397. * @rdev: RIO device
  398. *
  399. * Get RIO driver specific data. Returns a pointer to the
  400. * driver specific data.
  401. */
  402. static inline void *rio_get_drvdata(struct rio_dev *rdev)
  403. {
  404. return dev_get_drvdata(&rdev->dev);
  405. }
  406. /**
  407. * rio_set_drvdata - Set RIO driver specific data
  408. * @rdev: RIO device
  409. * @data: Pointer to driver specific data
  410. *
  411. * Set RIO driver specific data. device struct driver data pointer
  412. * is set to the @data argument.
  413. */
  414. static inline void rio_set_drvdata(struct rio_dev *rdev, void *data)
  415. {
  416. dev_set_drvdata(&rdev->dev, data);
  417. }
  418. /* Misc driver helpers */
  419. extern u16 rio_local_get_device_id(struct rio_mport *port);
  420. extern struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from);
  421. extern struct rio_dev *rio_get_asm(u16 vid, u16 did, u16 asm_vid, u16 asm_did,
  422. struct rio_dev *from);
  423. #endif /* LINUX_RIO_DRV_H */