fw-device.h 4.91 KB
Newer Older
1
/*
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * Copyright (C) 2005-2006  Kristian Hoegsberg <krh@bitplanet.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef __fw_device_h
#define __fw_device_h

22
#include <linux/device.h>
23
#include <linux/fs.h>
24
#include <linux/idr.h>
25 26
#include <linux/kernel.h>
#include <linux/list.h>
27
#include <linux/mod_devicetable.h>
28
#include <linux/mutex.h>
29 30 31 32 33
#include <linux/rwsem.h>
#include <linux/sysfs.h>
#include <linux/types.h>
#include <linux/workqueue.h>

34
#include <asm/atomic.h>
35 36 37 38

enum fw_device_state {
	FW_DEVICE_INITIALIZING,
	FW_DEVICE_RUNNING,
39
	FW_DEVICE_GONE,
40
	FW_DEVICE_SHUTDOWN,
41 42
};

43 44 45
struct fw_attribute_group {
	struct attribute_group *groups[2];
	struct attribute_group group;
46
	struct attribute *attrs[12];
47 48
};

49 50 51
struct fw_node;
struct fw_card;

52 53 54 55 56 57 58 59 60 61 62
/*
 * Note, fw_device.generation always has to be read before fw_device.node_id.
 * Use SMP memory barriers to ensure this.  Otherwise requests will be sent
 * to an outdated node_id if the generation was updated in the meantime due
 * to a bus reset.
 *
 * Likewise, fw-core will take care to update .node_id before .generation so
 * that whenever fw_device.generation is current WRT the actual bus generation,
 * fw_device.node_id is guaranteed to be current too.
 *
 * The same applies to fw_device.card->node_id vs. fw_device.generation.
63 64 65 66 67
 *
 * fw_device.config_rom and fw_device.config_rom_length may be accessed during
 * the lifetime of any fw_unit belonging to the fw_device, before device_del()
 * was called on the last fw_unit.  Alternatively, they may be accessed while
 * holding fw_device_rwsem.
68
 */
69
struct fw_device {
70
	atomic_t state;
71 72 73
	struct fw_node *node;
	int node_id;
	int generation;
74
	unsigned max_speed;
75 76
	struct fw_card *card;
	struct device device;
77 78

	struct mutex client_list_mutex;
79
	struct list_head client_list;
80

81
	u32 *config_rom;
82 83
	size_t config_rom_length;
	int config_rom_retries;
84
	unsigned is_local:1;
85 86 87
	unsigned cmc:1;
	unsigned bc_implemented:2;

88
	struct delayed_work work;
89
	struct fw_attribute_group attribute_group;
90 91
};

92
static inline struct fw_device *fw_device(struct device *dev)
93
{
94
	return container_of(dev, struct fw_device, device);
95 96
}

97
static inline int fw_device_is_shutdown(struct fw_device *device)
98 99 100 101
{
	return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN;
}

102
static inline struct fw_device *fw_device_get(struct fw_device *device)
103 104 105 106 107 108
{
	get_device(&device->device);

	return device;
}

109
static inline void fw_device_put(struct fw_device *device)
110 111 112 113
{
	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);
117

118
void fw_device_cdev_update(struct fw_device *device);
119
void fw_device_cdev_remove(struct fw_device *device);
120

121
extern struct rw_semaphore fw_device_rwsem;
122
extern struct idr fw_device_idr;
123 124
extern int fw_cdev_major;

125 126 127
/*
 * fw_unit.directory must not be accessed after device_del(&fw_unit.device).
 */
128 129 130
struct fw_unit {
	struct device device;
	u32 *directory;
131
	struct fw_attribute_group attribute_group;
132 133
};

134
static inline struct fw_unit *fw_unit(struct device *dev)
135
{
136
	return container_of(dev, struct fw_unit, device);
137 138
}

139 140 141 142 143 144 145 146 147 148 149 150
static inline struct fw_unit *fw_unit_get(struct fw_unit *unit)
{
	get_device(&unit->device);

	return unit;
}

static inline void fw_unit_put(struct fw_unit *unit)
{
	put_device(&unit->device);
}

151 152 153 154 155 156 157 158 159 160 161 162 163 164
#define CSR_OFFSET	0x40
#define CSR_LEAF	0x80
#define CSR_DIRECTORY	0xc0

#define CSR_DESCRIPTOR		0x01
#define CSR_VENDOR		0x03
#define CSR_HARDWARE_VERSION	0x04
#define CSR_NODE_CAPABILITIES	0x0c
#define CSR_UNIT		0x11
#define CSR_SPECIFIER_ID	0x12
#define CSR_VERSION		0x13
#define CSR_DEPENDENT_INFO	0x14
#define CSR_MODEL		0x17
#define CSR_INSTANCE		0x18
165
#define CSR_DIRECTORY_ID	0x20
166 167 168 169 170 171 172 173 174 175 176 177 178

struct fw_csr_iterator {
	u32 *p;
	u32 *end;
};

void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p);
int fw_csr_iterator_next(struct fw_csr_iterator *ci,
			 int *key, int *value);

struct fw_driver {
	struct device_driver driver;
	/* Called when the parent device sits through a bus reset. */
179 180
	void (*update)(struct fw_unit *unit);
	const struct ieee1394_device_id *id_table;
181 182
};

183
static inline struct fw_driver *fw_driver(struct device_driver *drv)
184
{
185
	return container_of(drv, struct fw_driver, driver);
186 187
}

188
extern const struct file_operations fw_device_ops;
189

190
#endif /* __fw_device_h */