rio_drv.h 14 KB

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