firewire-cdev.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /*
  2. * Char device interface.
  3. *
  4. * Copyright (C) 2005-2006 Kristian Hoegsberg <krh@bitplanet.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #ifndef _LINUX_FIREWIRE_CDEV_H
  21. #define _LINUX_FIREWIRE_CDEV_H
  22. #include <linux/ioctl.h>
  23. #include <linux/types.h>
  24. #include <linux/firewire-constants.h>
  25. #define FW_CDEV_EVENT_BUS_RESET 0x00
  26. #define FW_CDEV_EVENT_RESPONSE 0x01
  27. #define FW_CDEV_EVENT_REQUEST 0x02
  28. #define FW_CDEV_EVENT_ISO_INTERRUPT 0x03
  29. /**
  30. * struct fw_cdev_event_common - Common part of all fw_cdev_event_ types
  31. * @closure: For arbitrary use by userspace
  32. * @type: Discriminates the fw_cdev_event_ types
  33. *
  34. * This struct may be used to access generic members of all fw_cdev_event_
  35. * types regardless of the specific type.
  36. *
  37. * Data passed in the @closure field for a request will be returned in the
  38. * corresponding event. It is big enough to hold a pointer on all platforms.
  39. * The ioctl used to set @closure depends on the @type of event.
  40. */
  41. struct fw_cdev_event_common {
  42. __u64 closure;
  43. __u32 type;
  44. };
  45. /**
  46. * struct fw_cdev_event_bus_reset - Sent when a bus reset occurred
  47. * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_GET_INFO ioctl
  48. * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_BUS_RESET
  49. * @node_id: New node ID of this node
  50. * @local_node_id: Node ID of the local node, i.e. of the controller
  51. * @bm_node_id: Node ID of the bus manager
  52. * @irm_node_id: Node ID of the iso resource manager
  53. * @root_node_id: Node ID of the root node
  54. * @generation: New bus generation
  55. *
  56. * This event is sent when the bus the device belongs to goes through a bus
  57. * reset. It provides information about the new bus configuration, such as
  58. * new node ID for this device, new root ID, and others.
  59. */
  60. struct fw_cdev_event_bus_reset {
  61. __u64 closure;
  62. __u32 type;
  63. __u32 node_id;
  64. __u32 local_node_id;
  65. __u32 bm_node_id;
  66. __u32 irm_node_id;
  67. __u32 root_node_id;
  68. __u32 generation;
  69. };
  70. /**
  71. * struct fw_cdev_event_response - Sent when a response packet was received
  72. * @closure: See &fw_cdev_event_common;
  73. * set by %FW_CDEV_IOC_SEND_REQUEST ioctl
  74. * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_RESPONSE
  75. * @rcode: Response code returned by the remote node
  76. * @length: Data length, i.e. the response's payload size in bytes
  77. * @data: Payload data, if any
  78. *
  79. * This event is sent when the stack receives a response to an outgoing request
  80. * sent by %FW_CDEV_IOC_SEND_REQUEST ioctl. The payload data for responses
  81. * carrying data (read and lock responses) follows immediately and can be
  82. * accessed through the @data field.
  83. */
  84. struct fw_cdev_event_response {
  85. __u64 closure;
  86. __u32 type;
  87. __u32 rcode;
  88. __u32 length;
  89. __u32 data[0];
  90. };
  91. /**
  92. * struct fw_cdev_event_request - Sent on incoming request to an address region
  93. * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl
  94. * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST
  95. * @tcode: Transaction code of the incoming request
  96. * @offset: The offset into the 48-bit per-node address space
  97. * @handle: Reference to the kernel-side pending request
  98. * @length: Data length, i.e. the request's payload size in bytes
  99. * @data: Incoming data, if any
  100. *
  101. * This event is sent when the stack receives an incoming request to an address
  102. * region registered using the %FW_CDEV_IOC_ALLOCATE ioctl. The request is
  103. * guaranteed to be completely contained in the specified region. Userspace is
  104. * responsible for sending the response by %FW_CDEV_IOC_SEND_RESPONSE ioctl,
  105. * using the same @handle.
  106. *
  107. * The payload data for requests carrying data (write and lock requests)
  108. * follows immediately and can be accessed through the @data field.
  109. */
  110. struct fw_cdev_event_request {
  111. __u64 closure;
  112. __u32 type;
  113. __u32 tcode;
  114. __u64 offset;
  115. __u32 handle;
  116. __u32 length;
  117. __u32 data[0];
  118. };
  119. /**
  120. * struct fw_cdev_event_iso_interrupt - Sent when an iso packet was completed
  121. * @closure: See &fw_cdev_event_common;
  122. * set by %FW_CDEV_CREATE_ISO_CONTEXT ioctl
  123. * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_ISO_INTERRUPT
  124. * @cycle: Cycle counter of the interrupt packet
  125. * @header_length: Total length of following headers, in bytes
  126. * @header: Stripped headers, if any
  127. *
  128. * This event is sent when the controller has completed an &fw_cdev_iso_packet
  129. * with the %FW_CDEV_ISO_INTERRUPT bit set. In the receive case, the headers
  130. * stripped of all packets up until and including the interrupt packet are
  131. * returned in the @header field.
  132. */
  133. struct fw_cdev_event_iso_interrupt {
  134. __u64 closure;
  135. __u32 type;
  136. __u32 cycle;
  137. __u32 header_length;
  138. __u32 header[0];
  139. };
  140. /**
  141. * union fw_cdev_event - Convenience union of fw_cdev_event_ types
  142. * @common: Valid for all types
  143. * @bus_reset: Valid if @common.type == %FW_CDEV_EVENT_BUS_RESET
  144. * @response: Valid if @common.type == %FW_CDEV_EVENT_RESPONSE
  145. * @request: Valid if @common.type == %FW_CDEV_EVENT_REQUEST
  146. * @iso_interrupt: Valid if @common.type == %FW_CDEV_EVENT_ISO_INTERRUPT
  147. *
  148. * Convenience union for userspace use. Events could be read(2) into an
  149. * appropriately aligned char buffer and then cast to this union for further
  150. * processing. Note that for a request, response or iso_interrupt event,
  151. * the data[] or header[] may make the size of the full event larger than
  152. * sizeof(union fw_cdev_event). Also note that if you attempt to read(2)
  153. * an event into a buffer that is not large enough for it, the data that does
  154. * not fit will be discarded so that the next read(2) will return a new event.
  155. */
  156. union fw_cdev_event {
  157. struct fw_cdev_event_common common;
  158. struct fw_cdev_event_bus_reset bus_reset;
  159. struct fw_cdev_event_response response;
  160. struct fw_cdev_event_request request;
  161. struct fw_cdev_event_iso_interrupt iso_interrupt;
  162. };
  163. #define FW_CDEV_IOC_GET_INFO _IOWR('#', 0x00, struct fw_cdev_get_info)
  164. #define FW_CDEV_IOC_SEND_REQUEST _IOW('#', 0x01, struct fw_cdev_send_request)
  165. #define FW_CDEV_IOC_ALLOCATE _IOWR('#', 0x02, struct fw_cdev_allocate)
  166. #define FW_CDEV_IOC_DEALLOCATE _IOW('#', 0x03, struct fw_cdev_deallocate)
  167. #define FW_CDEV_IOC_SEND_RESPONSE _IOW('#', 0x04, struct fw_cdev_send_response)
  168. #define FW_CDEV_IOC_INITIATE_BUS_RESET _IOW('#', 0x05, struct fw_cdev_initiate_bus_reset)
  169. #define FW_CDEV_IOC_ADD_DESCRIPTOR _IOWR('#', 0x06, struct fw_cdev_add_descriptor)
  170. #define FW_CDEV_IOC_REMOVE_DESCRIPTOR _IOW('#', 0x07, struct fw_cdev_remove_descriptor)
  171. #define FW_CDEV_IOC_CREATE_ISO_CONTEXT _IOWR('#', 0x08, struct fw_cdev_create_iso_context)
  172. #define FW_CDEV_IOC_QUEUE_ISO _IOWR('#', 0x09, struct fw_cdev_queue_iso)
  173. #define FW_CDEV_IOC_START_ISO _IOW('#', 0x0a, struct fw_cdev_start_iso)
  174. #define FW_CDEV_IOC_STOP_ISO _IOW('#', 0x0b, struct fw_cdev_stop_iso)
  175. #define FW_CDEV_IOC_GET_CYCLE_TIMER _IOR('#', 0x0c, struct fw_cdev_get_cycle_timer)
  176. /* FW_CDEV_VERSION History
  177. *
  178. * 1 Feb 18, 2007: Initial version.
  179. */
  180. #define FW_CDEV_VERSION 1
  181. /**
  182. * struct fw_cdev_get_info - General purpose information ioctl
  183. * @version: The version field is just a running serial number.
  184. * We never break backwards compatibility, but may add more
  185. * structs and ioctls in later revisions.
  186. * @rom_length: If @rom is non-zero, at most rom_length bytes of configuration
  187. * ROM will be copied into that user space address. In either
  188. * case, @rom_length is updated with the actual length of the
  189. * configuration ROM.
  190. * @rom: If non-zero, address of a buffer to be filled by a copy of the
  191. * local node's configuration ROM
  192. * @bus_reset: If non-zero, address of a buffer to be filled by a
  193. * &struct fw_cdev_event_bus_reset with the current state
  194. * of the bus. This does not cause a bus reset to happen.
  195. * @bus_reset_closure: Value of &closure in this and subsequent bus reset events
  196. * @card: The index of the card this device belongs to
  197. */
  198. struct fw_cdev_get_info {
  199. __u32 version;
  200. __u32 rom_length;
  201. __u64 rom;
  202. __u64 bus_reset;
  203. __u64 bus_reset_closure;
  204. __u32 card;
  205. };
  206. /**
  207. * struct fw_cdev_send_request - Send an asynchronous request packet
  208. * @tcode: Transaction code of the request
  209. * @length: Length of outgoing payload, in bytes
  210. * @offset: 48-bit offset at destination node
  211. * @closure: Passed back to userspace in the response event
  212. * @data: Userspace pointer to payload
  213. * @generation: The bus generation where packet is valid
  214. *
  215. * Send a request to the device. This ioctl implements all outgoing requests.
  216. * Both quadlet and block request specify the payload as a pointer to the data
  217. * in the @data field. Once the transaction completes, the kernel writes an
  218. * &fw_cdev_event_request event back. The @closure field is passed back to
  219. * user space in the response event.
  220. */
  221. struct fw_cdev_send_request {
  222. __u32 tcode;
  223. __u32 length;
  224. __u64 offset;
  225. __u64 closure;
  226. __u64 data;
  227. __u32 generation;
  228. };
  229. /**
  230. * struct fw_cdev_send_response - Send an asynchronous response packet
  231. * @rcode: Response code as determined by the userspace handler
  232. * @length: Length of outgoing payload, in bytes
  233. * @data: Userspace pointer to payload
  234. * @handle: The handle from the &fw_cdev_event_request
  235. *
  236. * Send a response to an incoming request. By setting up an address range using
  237. * the %FW_CDEV_IOC_ALLOCATE ioctl, userspace can listen for incoming requests. An
  238. * incoming request will generate an %FW_CDEV_EVENT_REQUEST, and userspace must
  239. * send a reply using this ioctl. The event has a handle to the kernel-side
  240. * pending transaction, which should be used with this ioctl.
  241. */
  242. struct fw_cdev_send_response {
  243. __u32 rcode;
  244. __u32 length;
  245. __u64 data;
  246. __u32 handle;
  247. };
  248. /**
  249. * struct fw_cdev_allocate - Allocate a CSR address range
  250. * @offset: Start offset of the address range
  251. * @closure: To be passed back to userspace in request events
  252. * @length: Length of the address range, in bytes
  253. * @handle: Handle to the allocation, written by the kernel
  254. *
  255. * Allocate an address range in the 48-bit address space on the local node
  256. * (the controller). This allows userspace to listen for requests with an
  257. * offset within that address range. When the kernel receives a request
  258. * within the range, an &fw_cdev_event_request event will be written back.
  259. * The @closure field is passed back to userspace in the response event.
  260. * The @handle field is an out parameter, returning a handle to the allocated
  261. * range to be used for later deallocation of the range.
  262. */
  263. struct fw_cdev_allocate {
  264. __u64 offset;
  265. __u64 closure;
  266. __u32 length;
  267. __u32 handle;
  268. };
  269. /**
  270. * struct fw_cdev_deallocate - Free an address range allocation
  271. * @handle: Handle to the address range, as returned by the kernel when the
  272. * range was allocated
  273. */
  274. struct fw_cdev_deallocate {
  275. __u32 handle;
  276. };
  277. #define FW_CDEV_LONG_RESET 0
  278. #define FW_CDEV_SHORT_RESET 1
  279. /**
  280. * struct fw_cdev_initiate_bus_reset - Initiate a bus reset
  281. * @type: %FW_CDEV_SHORT_RESET or %FW_CDEV_LONG_RESET
  282. *
  283. * Initiate a bus reset for the bus this device is on. The bus reset can be
  284. * either the original (long) bus reset or the arbitrated (short) bus reset
  285. * introduced in 1394a-2000.
  286. */
  287. struct fw_cdev_initiate_bus_reset {
  288. __u32 type; /* FW_CDEV_SHORT_RESET or FW_CDEV_LONG_RESET */
  289. };
  290. /**
  291. * struct fw_cdev_add_descriptor - Add contents to the local node's config ROM
  292. * @immediate: If non-zero, immediate key to insert before pointer
  293. * @key: Upper 8 bits of root directory pointer
  294. * @data: Userspace pointer to contents of descriptor block
  295. * @length: Length of descriptor block data, in bytes
  296. * @handle: Handle to the descriptor, written by the kernel
  297. *
  298. * Add a descriptor block and optionally a preceding immediate key to the local
  299. * node's configuration ROM.
  300. *
  301. * The @key field specifies the upper 8 bits of the descriptor root directory
  302. * pointer and the @data and @length fields specify the contents. The @key
  303. * should be of the form 0xXX000000. The offset part of the root directory entry
  304. * will be filled in by the kernel.
  305. *
  306. * If not 0, the @immediate field specifies an immediate key which will be
  307. * inserted before the root directory pointer.
  308. *
  309. * If successful, the kernel adds the descriptor and writes back a handle to the
  310. * kernel-side object to be used for later removal of the descriptor block and
  311. * immediate key.
  312. */
  313. struct fw_cdev_add_descriptor {
  314. __u32 immediate;
  315. __u32 key;
  316. __u64 data;
  317. __u32 length;
  318. __u32 handle;
  319. };
  320. /**
  321. * struct fw_cdev_remove_descriptor - Remove contents from the configuration ROM
  322. * @handle: Handle to the descriptor, as returned by the kernel when the
  323. * descriptor was added
  324. *
  325. * Remove a descriptor block and accompanying immediate key from the local
  326. * node's configuration ROM.
  327. */
  328. struct fw_cdev_remove_descriptor {
  329. __u32 handle;
  330. };
  331. #define FW_CDEV_ISO_CONTEXT_TRANSMIT 0
  332. #define FW_CDEV_ISO_CONTEXT_RECEIVE 1
  333. /**
  334. * struct fw_cdev_create_iso_context - Create a context for isochronous IO
  335. * @type: %FW_CDEV_ISO_CONTEXT_TRANSMIT or %FW_CDEV_ISO_CONTEXT_RECEIVE
  336. * @header_size: Header size to strip for receive contexts
  337. * @channel: Channel to bind to
  338. * @speed: Speed to transmit at
  339. * @closure: To be returned in &fw_cdev_event_iso_interrupt
  340. * @handle: Handle to context, written back by kernel
  341. *
  342. * Prior to sending or receiving isochronous I/O, a context must be created.
  343. * The context records information about the transmit or receive configuration
  344. * and typically maps to an underlying hardware resource. A context is set up
  345. * for either sending or receiving. It is bound to a specific isochronous
  346. * channel.
  347. *
  348. * If a context was successfully created, the kernel writes back a handle to the
  349. * context, which must be passed in for subsequent operations on that context.
  350. */
  351. struct fw_cdev_create_iso_context {
  352. __u32 type;
  353. __u32 header_size;
  354. __u32 channel;
  355. __u32 speed;
  356. __u64 closure;
  357. __u32 handle;
  358. };
  359. #define FW_CDEV_ISO_PAYLOAD_LENGTH(v) (v)
  360. #define FW_CDEV_ISO_INTERRUPT (1 << 16)
  361. #define FW_CDEV_ISO_SKIP (1 << 17)
  362. #define FW_CDEV_ISO_SYNC (1 << 17)
  363. #define FW_CDEV_ISO_TAG(v) ((v) << 18)
  364. #define FW_CDEV_ISO_SY(v) ((v) << 20)
  365. #define FW_CDEV_ISO_HEADER_LENGTH(v) ((v) << 24)
  366. /**
  367. * struct fw_cdev_iso_packet - Isochronous packet
  368. * @control: Contains the header length (8 uppermost bits), the sy field
  369. * (4 bits), the tag field (2 bits), a sync flag (1 bit),
  370. * a skip flag (1 bit), an interrupt flag (1 bit), and the
  371. * payload length (16 lowermost bits)
  372. * @header: Header and payload
  373. *
  374. * &struct fw_cdev_iso_packet is used to describe isochronous packet queues.
  375. *
  376. * Use the FW_CDEV_ISO_ macros to fill in @control. The sy and tag fields are
  377. * specified by IEEE 1394a and IEC 61883.
  378. *
  379. * FIXME - finish this documentation
  380. */
  381. struct fw_cdev_iso_packet {
  382. __u32 control;
  383. __u32 header[0];
  384. };
  385. /**
  386. * struct fw_cdev_queue_iso - Queue isochronous packets for I/O
  387. * @packets: Userspace pointer to packet data
  388. * @data: Pointer into mmap()'ed payload buffer
  389. * @size: Size of packet data in bytes
  390. * @handle: Isochronous context handle
  391. *
  392. * Queue a number of isochronous packets for reception or transmission.
  393. * This ioctl takes a pointer to an array of &fw_cdev_iso_packet structs,
  394. * which describe how to transmit from or receive into a contiguous region
  395. * of a mmap()'ed payload buffer. As part of the packet descriptors,
  396. * a series of headers can be supplied, which will be prepended to the
  397. * payload during DMA.
  398. *
  399. * The kernel may or may not queue all packets, but will write back updated
  400. * values of the @packets, @data and @size fields, so the ioctl can be
  401. * resubmitted easily.
  402. */
  403. struct fw_cdev_queue_iso {
  404. __u64 packets;
  405. __u64 data;
  406. __u32 size;
  407. __u32 handle;
  408. };
  409. #define FW_CDEV_ISO_CONTEXT_MATCH_TAG0 1
  410. #define FW_CDEV_ISO_CONTEXT_MATCH_TAG1 2
  411. #define FW_CDEV_ISO_CONTEXT_MATCH_TAG2 4
  412. #define FW_CDEV_ISO_CONTEXT_MATCH_TAG3 8
  413. #define FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS 15
  414. /**
  415. * struct fw_cdev_start_iso - Start an isochronous transmission or reception
  416. * @cycle: Cycle in which to start I/O. If @cycle is greater than or
  417. * equal to 0, the I/O will start on that cycle.
  418. * @sync: Determines the value to wait for for receive packets that have
  419. * the %FW_CDEV_ISO_SYNC bit set
  420. * @tags: Tag filter bit mask. Only valid for isochronous reception.
  421. * Determines the tag values for which packets will be accepted.
  422. * Use FW_CDEV_ISO_CONTEXT_MATCH_ macros to set @tags.
  423. * @handle: Isochronous context handle within which to transmit or receive
  424. */
  425. struct fw_cdev_start_iso {
  426. __s32 cycle;
  427. __u32 sync;
  428. __u32 tags;
  429. __u32 handle;
  430. };
  431. /**
  432. * struct fw_cdev_stop_iso - Stop an isochronous transmission or reception
  433. * @handle: Handle of isochronous context to stop
  434. */
  435. struct fw_cdev_stop_iso {
  436. __u32 handle;
  437. };
  438. /**
  439. * struct fw_cdev_get_cycle_timer - read cycle timer register
  440. * @local_time: system time, in microseconds since the Epoch
  441. * @cycle_timer: isochronous cycle timer, as per OHCI 1.1 clause 5.13
  442. *
  443. * The %FW_CDEV_IOC_GET_CYCLE_TIMER ioctl reads the isochronous cycle timer
  444. * and also the system clock. This allows to express the receive time of an
  445. * isochronous packet as a system time with microsecond accuracy.
  446. */
  447. struct fw_cdev_get_cycle_timer {
  448. __u64 local_time;
  449. __u32 cycle_timer;
  450. };
  451. #endif /* _LINUX_FIREWIRE_CDEV_H */