fw-device.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* -*- c-basic-offset: 8 -*-
  2. *
  3. * fw-device.h - Device probing and sysfs code.
  4. *
  5. * Copyright (C) 2005-2006 Kristian Hoegsberg <krh@bitplanet.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software Foundation,
  19. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. #ifndef __fw_device_h
  22. #define __fw_device_h
  23. #include <linux/fs.h>
  24. #include <linux/cdev.h>
  25. #include <asm/atomic.h>
  26. enum fw_device_state {
  27. FW_DEVICE_INITIALIZING,
  28. FW_DEVICE_RUNNING,
  29. FW_DEVICE_SHUTDOWN,
  30. };
  31. struct fw_device {
  32. atomic_t state;
  33. struct fw_node *node;
  34. int node_id;
  35. int generation;
  36. struct fw_card *card;
  37. struct device device;
  38. struct list_head link;
  39. struct list_head client_list;
  40. u32 *config_rom;
  41. size_t config_rom_length;
  42. int config_rom_retries;
  43. struct delayed_work work;
  44. };
  45. static inline struct fw_device *
  46. fw_device(struct device *dev)
  47. {
  48. return container_of(dev, struct fw_device, device);
  49. }
  50. static inline int
  51. fw_device_is_shutdown(struct fw_device *device)
  52. {
  53. return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN;
  54. }
  55. struct fw_device *fw_device_get(struct fw_device *device);
  56. void fw_device_put(struct fw_device *device);
  57. int fw_device_enable_phys_dma(struct fw_device *device);
  58. void fw_device_cdev_update(struct fw_device *device);
  59. void fw_device_cdev_remove(struct fw_device *device);
  60. struct fw_device *fw_device_from_devt(dev_t devt);
  61. extern int fw_cdev_major;
  62. struct fw_unit {
  63. struct device device;
  64. u32 *directory;
  65. };
  66. static inline struct fw_unit *
  67. fw_unit(struct device *dev)
  68. {
  69. return container_of(dev, struct fw_unit, device);
  70. }
  71. #define CSR_OFFSET 0x40
  72. #define CSR_LEAF 0x80
  73. #define CSR_DIRECTORY 0xc0
  74. #define CSR_DESCRIPTOR 0x01
  75. #define CSR_VENDOR 0x03
  76. #define CSR_HARDWARE_VERSION 0x04
  77. #define CSR_NODE_CAPABILITIES 0x0c
  78. #define CSR_UNIT 0x11
  79. #define CSR_SPECIFIER_ID 0x12
  80. #define CSR_VERSION 0x13
  81. #define CSR_DEPENDENT_INFO 0x14
  82. #define CSR_MODEL 0x17
  83. #define CSR_INSTANCE 0x18
  84. #define SBP2_COMMAND_SET_SPECIFIER 0x38
  85. #define SBP2_COMMAND_SET 0x39
  86. #define SBP2_COMMAND_SET_REVISION 0x3b
  87. #define SBP2_FIRMWARE_REVISION 0x3c
  88. struct fw_csr_iterator {
  89. u32 *p;
  90. u32 *end;
  91. };
  92. void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p);
  93. int fw_csr_iterator_next(struct fw_csr_iterator *ci,
  94. int *key, int *value);
  95. #define FW_MATCH_VENDOR 0x0001
  96. #define FW_MATCH_MODEL 0x0002
  97. #define FW_MATCH_SPECIFIER_ID 0x0004
  98. #define FW_MATCH_VERSION 0x0008
  99. struct fw_device_id {
  100. u32 match_flags;
  101. u32 vendor;
  102. u32 model;
  103. u32 specifier_id;
  104. u32 version;
  105. void *driver_data;
  106. };
  107. struct fw_driver {
  108. struct device_driver driver;
  109. /* Called when the parent device sits through a bus reset. */
  110. void (*update) (struct fw_unit *unit);
  111. const struct fw_device_id *id_table;
  112. };
  113. static inline struct fw_driver *
  114. fw_driver(struct device_driver *drv)
  115. {
  116. return container_of(drv, struct fw_driver, driver);
  117. }
  118. extern const struct file_operations fw_device_ops;
  119. #endif /* __fw_device_h */