2 * Copyright (C) 2005-2006 Kristian Hoegsberg <krh@bitplanet.net>
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.
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.
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.
22 #include <linux/device.h>
24 #include <linux/idr.h>
25 #include <linux/kernel.h>
26 #include <linux/list.h>
27 #include <linux/mod_devicetable.h>
28 #include <linux/mutex.h>
29 #include <linux/rwsem.h>
30 #include <linux/sysfs.h>
31 #include <linux/types.h>
32 #include <linux/workqueue.h>
34 #include <asm/atomic.h>
36 enum fw_device_state
{
37 FW_DEVICE_INITIALIZING
,
43 struct fw_attribute_group
{
44 struct attribute_group
*groups
[2];
45 struct attribute_group group
;
46 struct attribute
*attrs
[12];
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
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.
62 * The same applies to fw_device.card->node_id vs. fw_device.generation.
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.
78 struct mutex client_list_mutex
;
79 struct list_head client_list
;
82 size_t config_rom_length
;
83 int config_rom_retries
;
86 unsigned bc_implemented
:2;
88 struct delayed_work work
;
89 struct fw_attribute_group attribute_group
;
92 static inline struct fw_device
*fw_device(struct device
*dev
)
94 return container_of(dev
, struct fw_device
, device
);
97 static inline int fw_device_is_shutdown(struct fw_device
*device
)
99 return atomic_read(&device
->state
) == FW_DEVICE_SHUTDOWN
;
102 static inline struct fw_device
*fw_device_get(struct fw_device
*device
)
104 get_device(&device
->device
);
109 static inline void fw_device_put(struct fw_device
*device
)
111 put_device(&device
->device
);
114 struct fw_device
*fw_device_get_by_devt(dev_t devt
);
115 int fw_device_enable_phys_dma(struct fw_device
*device
);
116 void fw_device_set_broadcast_channel(struct fw_device
*device
, int generation
);
118 void fw_device_cdev_update(struct fw_device
*device
);
119 void fw_device_cdev_remove(struct fw_device
*device
);
121 extern struct rw_semaphore fw_device_rwsem
;
122 extern struct idr fw_device_idr
;
123 extern int fw_cdev_major
;
126 * fw_unit.directory must not be accessed after device_del(&fw_unit.device).
129 struct device device
;
131 struct fw_attribute_group attribute_group
;
134 static inline struct fw_unit
*fw_unit(struct device
*dev
)
136 return container_of(dev
, struct fw_unit
, device
);
139 static inline struct fw_unit
*fw_unit_get(struct fw_unit
*unit
)
141 get_device(&unit
->device
);
146 static inline void fw_unit_put(struct fw_unit
*unit
)
148 put_device(&unit
->device
);
151 #define CSR_OFFSET 0x40
152 #define CSR_LEAF 0x80
153 #define CSR_DIRECTORY 0xc0
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
165 #define CSR_DIRECTORY_ID 0x20
167 struct fw_csr_iterator
{
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
);
177 struct device_driver driver
;
178 /* Called when the parent device sits through a bus reset. */
179 void (*update
)(struct fw_unit
*unit
);
180 const struct ieee1394_device_id
*id_table
;
183 static inline struct fw_driver
*fw_driver(struct device_driver
*drv
)
185 return container_of(drv
, struct fw_driver
, driver
);
188 extern const struct file_operations fw_device_ops
;
190 #endif /* __fw_device_h */