/kern_2.6.32/include/linux/firewire.h

http://omnia2droid.googlecode.com/ · C++ Header · 432 lines · 314 code · 63 blank · 55 comment · 2 complexity · 09cf5f5db127d6faa4828e2f4ee2aab0 MD5 · raw file

  1. #ifndef _LINUX_FIREWIRE_H
  2. #define _LINUX_FIREWIRE_H
  3. #include <linux/completion.h>
  4. #include <linux/device.h>
  5. #include <linux/dma-mapping.h>
  6. #include <linux/kernel.h>
  7. #include <linux/kref.h>
  8. #include <linux/list.h>
  9. #include <linux/mutex.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/sysfs.h>
  12. #include <linux/timer.h>
  13. #include <linux/types.h>
  14. #include <linux/workqueue.h>
  15. #include <asm/atomic.h>
  16. #include <asm/byteorder.h>
  17. #define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args)
  18. #define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args)
  19. static inline void fw_memcpy_from_be32(void *_dst, void *_src, size_t size)
  20. {
  21. u32 *dst = _dst;
  22. __be32 *src = _src;
  23. int i;
  24. for (i = 0; i < size / 4; i++)
  25. dst[i] = be32_to_cpu(src[i]);
  26. }
  27. static inline void fw_memcpy_to_be32(void *_dst, void *_src, size_t size)
  28. {
  29. fw_memcpy_from_be32(_dst, _src, size);
  30. }
  31. #define CSR_REGISTER_BASE 0xfffff0000000ULL
  32. /* register offsets are relative to CSR_REGISTER_BASE */
  33. #define CSR_STATE_CLEAR 0x0
  34. #define CSR_STATE_SET 0x4
  35. #define CSR_NODE_IDS 0x8
  36. #define CSR_RESET_START 0xc
  37. #define CSR_SPLIT_TIMEOUT_HI 0x18
  38. #define CSR_SPLIT_TIMEOUT_LO 0x1c
  39. #define CSR_CYCLE_TIME 0x200
  40. #define CSR_BUS_TIME 0x204
  41. #define CSR_BUSY_TIMEOUT 0x210
  42. #define CSR_BUS_MANAGER_ID 0x21c
  43. #define CSR_BANDWIDTH_AVAILABLE 0x220
  44. #define CSR_CHANNELS_AVAILABLE 0x224
  45. #define CSR_CHANNELS_AVAILABLE_HI 0x224
  46. #define CSR_CHANNELS_AVAILABLE_LO 0x228
  47. #define CSR_BROADCAST_CHANNEL 0x234
  48. #define CSR_CONFIG_ROM 0x400
  49. #define CSR_CONFIG_ROM_END 0x800
  50. #define CSR_FCP_COMMAND 0xB00
  51. #define CSR_FCP_RESPONSE 0xD00
  52. #define CSR_FCP_END 0xF00
  53. #define CSR_TOPOLOGY_MAP 0x1000
  54. #define CSR_TOPOLOGY_MAP_END 0x1400
  55. #define CSR_SPEED_MAP 0x2000
  56. #define CSR_SPEED_MAP_END 0x3000
  57. #define CSR_OFFSET 0x40
  58. #define CSR_LEAF 0x80
  59. #define CSR_DIRECTORY 0xc0
  60. #define CSR_DESCRIPTOR 0x01
  61. #define CSR_VENDOR 0x03
  62. #define CSR_HARDWARE_VERSION 0x04
  63. #define CSR_NODE_CAPABILITIES 0x0c
  64. #define CSR_UNIT 0x11
  65. #define CSR_SPECIFIER_ID 0x12
  66. #define CSR_VERSION 0x13
  67. #define CSR_DEPENDENT_INFO 0x14
  68. #define CSR_MODEL 0x17
  69. #define CSR_INSTANCE 0x18
  70. #define CSR_DIRECTORY_ID 0x20
  71. struct fw_csr_iterator {
  72. u32 *p;
  73. u32 *end;
  74. };
  75. void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p);
  76. int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value);
  77. extern struct bus_type fw_bus_type;
  78. struct fw_card_driver;
  79. struct fw_node;
  80. struct fw_card {
  81. const struct fw_card_driver *driver;
  82. struct device *device;
  83. struct kref kref;
  84. struct completion done;
  85. int node_id;
  86. int generation;
  87. int current_tlabel;
  88. u64 tlabel_mask;
  89. struct list_head transaction_list;
  90. struct timer_list flush_timer;
  91. unsigned long reset_jiffies;
  92. unsigned long long guid;
  93. unsigned max_receive;
  94. int link_speed;
  95. int config_rom_generation;
  96. spinlock_t lock; /* Take this lock when handling the lists in
  97. * this struct. */
  98. struct fw_node *local_node;
  99. struct fw_node *root_node;
  100. struct fw_node *irm_node;
  101. u8 color; /* must be u8 to match the definition in struct fw_node */
  102. int gap_count;
  103. bool beta_repeaters_present;
  104. int index;
  105. struct list_head link;
  106. /* Work struct for BM duties. */
  107. struct delayed_work work;
  108. int bm_retries;
  109. int bm_generation;
  110. __be32 bm_transaction_data[2];
  111. bool broadcast_channel_allocated;
  112. u32 broadcast_channel;
  113. u32 topology_map[(CSR_TOPOLOGY_MAP_END - CSR_TOPOLOGY_MAP) / 4];
  114. };
  115. struct fw_attribute_group {
  116. struct attribute_group *groups[2];
  117. struct attribute_group group;
  118. struct attribute *attrs[12];
  119. };
  120. enum fw_device_state {
  121. FW_DEVICE_INITIALIZING,
  122. FW_DEVICE_RUNNING,
  123. FW_DEVICE_GONE,
  124. FW_DEVICE_SHUTDOWN,
  125. };
  126. /*
  127. * Note, fw_device.generation always has to be read before fw_device.node_id.
  128. * Use SMP memory barriers to ensure this. Otherwise requests will be sent
  129. * to an outdated node_id if the generation was updated in the meantime due
  130. * to a bus reset.
  131. *
  132. * Likewise, fw-core will take care to update .node_id before .generation so
  133. * that whenever fw_device.generation is current WRT the actual bus generation,
  134. * fw_device.node_id is guaranteed to be current too.
  135. *
  136. * The same applies to fw_device.card->node_id vs. fw_device.generation.
  137. *
  138. * fw_device.config_rom and fw_device.config_rom_length may be accessed during
  139. * the lifetime of any fw_unit belonging to the fw_device, before device_del()
  140. * was called on the last fw_unit. Alternatively, they may be accessed while
  141. * holding fw_device_rwsem.
  142. */
  143. struct fw_device {
  144. atomic_t state;
  145. struct fw_node *node;
  146. int node_id;
  147. int generation;
  148. unsigned max_speed;
  149. struct fw_card *card;
  150. struct device device;
  151. struct mutex client_list_mutex;
  152. struct list_head client_list;
  153. u32 *config_rom;
  154. size_t config_rom_length;
  155. int config_rom_retries;
  156. unsigned is_local:1;
  157. unsigned max_rec:4;
  158. unsigned cmc:1;
  159. unsigned irmc:1;
  160. unsigned bc_implemented:2;
  161. struct delayed_work work;
  162. struct fw_attribute_group attribute_group;
  163. };
  164. static inline struct fw_device *fw_device(struct device *dev)
  165. {
  166. return container_of(dev, struct fw_device, device);
  167. }
  168. static inline int fw_device_is_shutdown(struct fw_device *device)
  169. {
  170. return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN;
  171. }
  172. static inline struct fw_device *fw_device_get(struct fw_device *device)
  173. {
  174. get_device(&device->device);
  175. return device;
  176. }
  177. static inline void fw_device_put(struct fw_device *device)
  178. {
  179. put_device(&device->device);
  180. }
  181. int fw_device_enable_phys_dma(struct fw_device *device);
  182. /*
  183. * fw_unit.directory must not be accessed after device_del(&fw_unit.device).
  184. */
  185. struct fw_unit {
  186. struct device device;
  187. u32 *directory;
  188. struct fw_attribute_group attribute_group;
  189. };
  190. static inline struct fw_unit *fw_unit(struct device *dev)
  191. {
  192. return container_of(dev, struct fw_unit, device);
  193. }
  194. static inline struct fw_unit *fw_unit_get(struct fw_unit *unit)
  195. {
  196. get_device(&unit->device);
  197. return unit;
  198. }
  199. static inline void fw_unit_put(struct fw_unit *unit)
  200. {
  201. put_device(&unit->device);
  202. }
  203. static inline struct fw_device *fw_parent_device(struct fw_unit *unit)
  204. {
  205. return fw_device(unit->device.parent);
  206. }
  207. struct ieee1394_device_id;
  208. struct fw_driver {
  209. struct device_driver driver;
  210. /* Called when the parent device sits through a bus reset. */
  211. void (*update)(struct fw_unit *unit);
  212. const struct ieee1394_device_id *id_table;
  213. };
  214. struct fw_packet;
  215. struct fw_request;
  216. typedef void (*fw_packet_callback_t)(struct fw_packet *packet,
  217. struct fw_card *card, int status);
  218. typedef void (*fw_transaction_callback_t)(struct fw_card *card, int rcode,
  219. void *data, size_t length,
  220. void *callback_data);
  221. /*
  222. * Important note: The callback must guarantee that either fw_send_response()
  223. * or kfree() is called on the @request.
  224. */
  225. typedef void (*fw_address_callback_t)(struct fw_card *card,
  226. struct fw_request *request,
  227. int tcode, int destination, int source,
  228. int generation, int speed,
  229. unsigned long long offset,
  230. void *data, size_t length,
  231. void *callback_data);
  232. struct fw_packet {
  233. int speed;
  234. int generation;
  235. u32 header[4];
  236. size_t header_length;
  237. void *payload;
  238. size_t payload_length;
  239. dma_addr_t payload_bus;
  240. u32 timestamp;
  241. /*
  242. * This callback is called when the packet transmission has
  243. * completed; for successful transmission, the status code is
  244. * the ack received from the destination, otherwise it's a
  245. * negative errno: ENOMEM, ESTALE, ETIMEDOUT, ENODEV, EIO.
  246. * The callback can be called from tasklet context and thus
  247. * must never block.
  248. */
  249. fw_packet_callback_t callback;
  250. int ack;
  251. struct list_head link;
  252. void *driver_data;
  253. };
  254. struct fw_transaction {
  255. int node_id; /* The generation is implied; it is always the current. */
  256. int tlabel;
  257. int timestamp;
  258. struct list_head link;
  259. struct fw_packet packet;
  260. /*
  261. * The data passed to the callback is valid only during the
  262. * callback.
  263. */
  264. fw_transaction_callback_t callback;
  265. void *callback_data;
  266. };
  267. struct fw_address_handler {
  268. u64 offset;
  269. size_t length;
  270. fw_address_callback_t address_callback;
  271. void *callback_data;
  272. struct list_head link;
  273. };
  274. struct fw_address_region {
  275. u64 start;
  276. u64 end;
  277. };
  278. extern const struct fw_address_region fw_high_memory_region;
  279. int fw_core_add_address_handler(struct fw_address_handler *handler,
  280. const struct fw_address_region *region);
  281. void fw_core_remove_address_handler(struct fw_address_handler *handler);
  282. void fw_send_response(struct fw_card *card,
  283. struct fw_request *request, int rcode);
  284. void fw_send_request(struct fw_card *card, struct fw_transaction *t,
  285. int tcode, int destination_id, int generation, int speed,
  286. unsigned long long offset, void *payload, size_t length,
  287. fw_transaction_callback_t callback, void *callback_data);
  288. int fw_cancel_transaction(struct fw_card *card,
  289. struct fw_transaction *transaction);
  290. int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
  291. int generation, int speed, unsigned long long offset,
  292. void *payload, size_t length);
  293. static inline int fw_stream_packet_destination_id(int tag, int channel, int sy)
  294. {
  295. return tag << 14 | channel << 8 | sy;
  296. }
  297. struct fw_descriptor {
  298. struct list_head link;
  299. size_t length;
  300. u32 immediate;
  301. u32 key;
  302. const u32 *data;
  303. };
  304. int fw_core_add_descriptor(struct fw_descriptor *desc);
  305. void fw_core_remove_descriptor(struct fw_descriptor *desc);
  306. /*
  307. * The iso packet format allows for an immediate header/payload part
  308. * stored in 'header' immediately after the packet info plus an
  309. * indirect payload part that is pointer to by the 'payload' field.
  310. * Applications can use one or the other or both to implement simple
  311. * low-bandwidth streaming (e.g. audio) or more advanced
  312. * scatter-gather streaming (e.g. assembling video frame automatically).
  313. */
  314. struct fw_iso_packet {
  315. u16 payload_length; /* Length of indirect payload. */
  316. u32 interrupt:1; /* Generate interrupt on this packet */
  317. u32 skip:1; /* Set to not send packet at all. */
  318. u32 tag:2;
  319. u32 sy:4;
  320. u32 header_length:8; /* Length of immediate header. */
  321. u32 header[0];
  322. };
  323. #define FW_ISO_CONTEXT_TRANSMIT 0
  324. #define FW_ISO_CONTEXT_RECEIVE 1
  325. #define FW_ISO_CONTEXT_MATCH_TAG0 1
  326. #define FW_ISO_CONTEXT_MATCH_TAG1 2
  327. #define FW_ISO_CONTEXT_MATCH_TAG2 4
  328. #define FW_ISO_CONTEXT_MATCH_TAG3 8
  329. #define FW_ISO_CONTEXT_MATCH_ALL_TAGS 15
  330. /*
  331. * An iso buffer is just a set of pages mapped for DMA in the
  332. * specified direction. Since the pages are to be used for DMA, they
  333. * are not mapped into the kernel virtual address space. We store the
  334. * DMA address in the page private. The helper function
  335. * fw_iso_buffer_map() will map the pages into a given vma.
  336. */
  337. struct fw_iso_buffer {
  338. enum dma_data_direction direction;
  339. struct page **pages;
  340. int page_count;
  341. };
  342. int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card,
  343. int page_count, enum dma_data_direction direction);
  344. void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer, struct fw_card *card);
  345. struct fw_iso_context;
  346. typedef void (*fw_iso_callback_t)(struct fw_iso_context *context,
  347. u32 cycle, size_t header_length,
  348. void *header, void *data);
  349. struct fw_iso_context {
  350. struct fw_card *card;
  351. int type;
  352. int channel;
  353. int speed;
  354. size_t header_size;
  355. fw_iso_callback_t callback;
  356. void *callback_data;
  357. };
  358. struct fw_iso_context *fw_iso_context_create(struct fw_card *card,
  359. int type, int channel, int speed, size_t header_size,
  360. fw_iso_callback_t callback, void *callback_data);
  361. int fw_iso_context_queue(struct fw_iso_context *ctx,
  362. struct fw_iso_packet *packet,
  363. struct fw_iso_buffer *buffer,
  364. unsigned long payload);
  365. int fw_iso_context_start(struct fw_iso_context *ctx,
  366. int cycle, int sync, int tags);
  367. int fw_iso_context_stop(struct fw_iso_context *ctx);
  368. void fw_iso_context_destroy(struct fw_iso_context *ctx);
  369. #endif /* _LINUX_FIREWIRE_H */