rio_drv.h 14 KB

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