Commit | Line | Data |
---|---|---|
c781c06d | 1 | /* |
19a15b93 KH |
2 | * Copyright (C) 2005-2006 Kristian Hoegsberg <krh@bitplanet.net> |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write to the Free Software Foundation, | |
16 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | */ | |
18 | ||
19 | #ifndef __fw_device_h | |
20 | #define __fw_device_h | |
21 | ||
41f321c2 | 22 | #include <linux/device.h> |
19a15b93 | 23 | #include <linux/fs.h> |
d6053e08 | 24 | #include <linux/idr.h> |
41f321c2 SR |
25 | #include <linux/kernel.h> |
26 | #include <linux/list.h> | |
b3b29888 | 27 | #include <linux/mod_devicetable.h> |
d67cfb96 | 28 | #include <linux/mutex.h> |
41f321c2 SR |
29 | #include <linux/rwsem.h> |
30 | #include <linux/sysfs.h> | |
31 | #include <linux/types.h> | |
32 | #include <linux/workqueue.h> | |
33 | ||
641f8791 | 34 | #include <asm/atomic.h> |
19a15b93 KH |
35 | |
36 | enum fw_device_state { | |
37 | FW_DEVICE_INITIALIZING, | |
38 | FW_DEVICE_RUNNING, | |
3d36a0df | 39 | FW_DEVICE_GONE, |
5af4e5ea | 40 | FW_DEVICE_SHUTDOWN, |
19a15b93 KH |
41 | }; |
42 | ||
6f2e53d5 KH |
43 | struct fw_attribute_group { |
44 | struct attribute_group *groups[2]; | |
45 | struct attribute_group group; | |
0210b66d | 46 | struct attribute *attrs[12]; |
6f2e53d5 KH |
47 | }; |
48 | ||
41f321c2 SR |
49 | struct fw_node; |
50 | struct fw_card; | |
51 | ||
b5d2a5e0 SR |
52 | /* |
53 | * Note, fw_device.generation always has to be read before fw_device.node_id. | |
54 | * Use SMP memory barriers to ensure this. Otherwise requests will be sent | |
55 | * to an outdated node_id if the generation was updated in the meantime due | |
56 | * to a bus reset. | |
57 | * | |
58 | * Likewise, fw-core will take care to update .node_id before .generation so | |
59 | * that whenever fw_device.generation is current WRT the actual bus generation, | |
60 | * fw_device.node_id is guaranteed to be current too. | |
61 | * | |
62 | * The same applies to fw_device.card->node_id vs. fw_device.generation. | |
c9755e14 SR |
63 | * |
64 | * fw_device.config_rom and fw_device.config_rom_length may be accessed during | |
65 | * the lifetime of any fw_unit belonging to the fw_device, before device_del() | |
66 | * was called on the last fw_unit. Alternatively, they may be accessed while | |
67 | * holding fw_device_rwsem. | |
b5d2a5e0 | 68 | */ |
19a15b93 | 69 | struct fw_device { |
641f8791 | 70 | atomic_t state; |
19a15b93 KH |
71 | struct fw_node *node; |
72 | int node_id; | |
73 | int generation; | |
f1397490 | 74 | unsigned max_speed; |
19a15b93 KH |
75 | struct fw_card *card; |
76 | struct device device; | |
d67cfb96 SR |
77 | |
78 | struct mutex client_list_mutex; | |
97bd9efa | 79 | struct list_head client_list; |
d67cfb96 | 80 | |
945ac222 | 81 | u32 *config_rom; |
19a15b93 KH |
82 | size_t config_rom_length; |
83 | int config_rom_retries; | |
92368890 | 84 | unsigned is_local:1; |
7889b60e SR |
85 | unsigned cmc:1; |
86 | unsigned bc_implemented:2; | |
87 | ||
19a15b93 | 88 | struct delayed_work work; |
6f2e53d5 | 89 | struct fw_attribute_group attribute_group; |
19a15b93 KH |
90 | }; |
91 | ||
1dc3bea7 | 92 | static inline struct fw_device *fw_device(struct device *dev) |
19a15b93 | 93 | { |
5e20c282 | 94 | return container_of(dev, struct fw_device, device); |
19a15b93 KH |
95 | } |
96 | ||
1dc3bea7 | 97 | static inline int fw_device_is_shutdown(struct fw_device *device) |
2603bf21 KH |
98 | { |
99 | return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN; | |
100 | } | |
101 | ||
1dc3bea7 | 102 | static inline struct fw_device *fw_device_get(struct fw_device *device) |
855c603d SR |
103 | { |
104 | get_device(&device->device); | |
105 | ||
106 | return device; | |
107 | } | |
108 | ||
1dc3bea7 | 109 | static inline void fw_device_put(struct fw_device *device) |
855c603d SR |
110 | { |
111 | put_device(&device->device); | |
112 | } | |
113 | ||
96b19062 | 114 | struct fw_device *fw_device_get_by_devt(dev_t devt); |
19a15b93 | 115 | int fw_device_enable_phys_dma(struct fw_device *device); |
7889b60e | 116 | void fw_device_set_broadcast_channel(struct fw_device *device, int generation); |
19a15b93 | 117 | |
97bd9efa | 118 | void fw_device_cdev_update(struct fw_device *device); |
2603bf21 | 119 | void fw_device_cdev_remove(struct fw_device *device); |
97bd9efa | 120 | |
c9755e14 | 121 | extern struct rw_semaphore fw_device_rwsem; |
d6053e08 | 122 | extern struct idr fw_device_idr; |
a3aca3da KH |
123 | extern int fw_cdev_major; |
124 | ||
c9755e14 SR |
125 | /* |
126 | * fw_unit.directory must not be accessed after device_del(&fw_unit.device). | |
127 | */ | |
19a15b93 KH |
128 | struct fw_unit { |
129 | struct device device; | |
130 | u32 *directory; | |
6f2e53d5 | 131 | struct fw_attribute_group attribute_group; |
19a15b93 KH |
132 | }; |
133 | ||
1dc3bea7 | 134 | static inline struct fw_unit *fw_unit(struct device *dev) |
19a15b93 | 135 | { |
5e20c282 | 136 | return container_of(dev, struct fw_unit, device); |
19a15b93 KH |
137 | } |
138 | ||
1dc3bea7 SR |
139 | static inline struct fw_unit *fw_unit_get(struct fw_unit *unit) |
140 | { | |
141 | get_device(&unit->device); | |
142 | ||
143 | return unit; | |
144 | } | |
145 | ||
146 | static inline void fw_unit_put(struct fw_unit *unit) | |
147 | { | |
148 | put_device(&unit->device); | |
149 | } | |
150 | ||
19a15b93 KH |
151 | #define CSR_OFFSET 0x40 |
152 | #define CSR_LEAF 0x80 | |
153 | #define CSR_DIRECTORY 0xc0 | |
154 | ||
155 | #define CSR_DESCRIPTOR 0x01 | |
156 | #define CSR_VENDOR 0x03 | |
157 | #define CSR_HARDWARE_VERSION 0x04 | |
158 | #define CSR_NODE_CAPABILITIES 0x0c | |
159 | #define CSR_UNIT 0x11 | |
160 | #define CSR_SPECIFIER_ID 0x12 | |
161 | #define CSR_VERSION 0x13 | |
162 | #define CSR_DEPENDENT_INFO 0x14 | |
163 | #define CSR_MODEL 0x17 | |
164 | #define CSR_INSTANCE 0x18 | |
14e21986 | 165 | #define CSR_DIRECTORY_ID 0x20 |
19a15b93 | 166 | |
19a15b93 KH |
167 | struct fw_csr_iterator { |
168 | u32 *p; | |
169 | u32 *end; | |
170 | }; | |
171 | ||
172 | void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p); | |
173 | int fw_csr_iterator_next(struct fw_csr_iterator *ci, | |
174 | int *key, int *value); | |
175 | ||
19a15b93 KH |
176 | struct fw_driver { |
177 | struct device_driver driver; | |
178 | /* Called when the parent device sits through a bus reset. */ | |
b3b29888 SR |
179 | void (*update)(struct fw_unit *unit); |
180 | const struct ieee1394_device_id *id_table; | |
19a15b93 KH |
181 | }; |
182 | ||
53dca511 | 183 | static inline struct fw_driver *fw_driver(struct device_driver *drv) |
19a15b93 | 184 | { |
5e20c282 | 185 | return container_of(drv, struct fw_driver, driver); |
19a15b93 KH |
186 | } |
187 | ||
21ebcd12 | 188 | extern const struct file_operations fw_device_ops; |
19a15b93 | 189 | |
687198bb | 190 | #endif /* __fw_device_h */ |