6 * Copyright (C) 2004 Ben Collins
8 * This code is licensed under the GPL. See the file COPYING in the root
9 * directory of the kernel sources for details.
12 #include <linux/types.h>
16 #include "ieee1394_types.h"
18 #include "ieee1394_core.h"
19 #include "highlevel.h"
21 #include "config_roms.h"
23 struct hpsb_config_rom_entry
{
26 /* Base initialization, called at module load */
29 /* Add entry to specified host */
30 int (*add
)(struct hpsb_host
*host
);
32 /* Remove entry from specified host */
33 void (*remove
)(struct hpsb_host
*host
);
35 /* Cleanup called at module exit */
36 void (*cleanup
)(void);
38 /* The flag added to host->config_roms */
43 int hpsb_default_host_entry(struct hpsb_host
*host
)
45 struct csr1212_keyval
*root
;
46 struct csr1212_keyval
*vend_id
= NULL
;
47 struct csr1212_keyval
*text
= NULL
;
51 sprintf(csr_name
, "Linux - %s", host
->driver
->name
);
52 root
= host
->csr
.rom
->root_kv
;
54 vend_id
= csr1212_new_immediate(CSR1212_KV_ID_VENDOR
, host
->csr
.guid_hi
>> 8);
55 text
= csr1212_new_string_descriptor_leaf(csr_name
);
57 if (!vend_id
|| !text
) {
59 csr1212_release_keyval(vend_id
);
61 csr1212_release_keyval(text
);
62 csr1212_destroy_csr(host
->csr
.rom
);
66 ret
= csr1212_associate_keyval(vend_id
, text
);
67 csr1212_release_keyval(text
);
68 ret
|= csr1212_attach_keyval_to_directory(root
, vend_id
);
69 csr1212_release_keyval(vend_id
);
70 if (ret
!= CSR1212_SUCCESS
) {
71 csr1212_destroy_csr(host
->csr
.rom
);
75 host
->update_config_rom
= 1;
81 #ifdef CONFIG_IEEE1394_CONFIG_ROM_IP1394
84 static struct csr1212_keyval
*ip1394_ud
;
86 static int config_rom_ip1394_init(void)
88 struct csr1212_keyval
*spec_id
= NULL
;
89 struct csr1212_keyval
*spec_desc
= NULL
;
90 struct csr1212_keyval
*ver
= NULL
;
91 struct csr1212_keyval
*ver_desc
= NULL
;
94 ip1394_ud
= csr1212_new_directory(CSR1212_KV_ID_UNIT
);
96 spec_id
= csr1212_new_immediate(CSR1212_KV_ID_SPECIFIER_ID
,
97 ETHER1394_GASP_SPECIFIER_ID
);
98 spec_desc
= csr1212_new_string_descriptor_leaf("IANA");
99 ver
= csr1212_new_immediate(CSR1212_KV_ID_VERSION
,
100 ETHER1394_GASP_VERSION
);
101 ver_desc
= csr1212_new_string_descriptor_leaf("IPv4");
103 if (!ip1394_ud
|| !spec_id
|| !spec_desc
|| !ver
|| !ver_desc
)
106 if (csr1212_associate_keyval(spec_id
, spec_desc
) == CSR1212_SUCCESS
&&
107 csr1212_associate_keyval(ver
, ver_desc
) == CSR1212_SUCCESS
&&
108 csr1212_attach_keyval_to_directory(ip1394_ud
, spec_id
) == CSR1212_SUCCESS
&&
109 csr1212_attach_keyval_to_directory(ip1394_ud
, ver
) == CSR1212_SUCCESS
)
113 if (ret
&& ip1394_ud
) {
114 csr1212_release_keyval(ip1394_ud
);
119 csr1212_release_keyval(spec_id
);
121 csr1212_release_keyval(spec_desc
);
123 csr1212_release_keyval(ver
);
125 csr1212_release_keyval(ver_desc
);
130 static void config_rom_ip1394_cleanup(void)
133 csr1212_release_keyval(ip1394_ud
);
138 static int config_rom_ip1394_add(struct hpsb_host
*host
)
143 if (csr1212_attach_keyval_to_directory(host
->csr
.rom
->root_kv
,
144 ip1394_ud
) != CSR1212_SUCCESS
)
150 static void config_rom_ip1394_remove(struct hpsb_host
*host
)
152 csr1212_detach_keyval_from_directory(host
->csr
.rom
->root_kv
, ip1394_ud
);
155 static struct hpsb_config_rom_entry ip1394_entry
= {
157 .init
= config_rom_ip1394_init
,
158 .add
= config_rom_ip1394_add
,
159 .remove
= config_rom_ip1394_remove
,
160 .cleanup
= config_rom_ip1394_cleanup
,
161 .flag
= HPSB_CONFIG_ROM_ENTRY_IP1394
,
163 #endif /* CONFIG_IEEE1394_CONFIG_ROM_IP1394 */
166 static struct hpsb_config_rom_entry
*const config_rom_entries
[] = {
167 #ifdef CONFIG_IEEE1394_CONFIG_ROM_IP1394
174 int hpsb_init_config_roms(void)
178 for (i
= 0; config_rom_entries
[i
]; i
++) {
179 if (!config_rom_entries
[i
]->init
)
182 if (config_rom_entries
[i
]->init()) {
183 HPSB_ERR("Failed to initialize config rom entry `%s'",
184 config_rom_entries
[i
]->name
);
187 HPSB_DEBUG("Initialized config rom entry `%s'",
188 config_rom_entries
[i
]->name
);
194 void hpsb_cleanup_config_roms(void)
198 for (i
= 0; config_rom_entries
[i
]; i
++) {
199 if (config_rom_entries
[i
]->cleanup
)
200 config_rom_entries
[i
]->cleanup();
204 int hpsb_add_extra_config_roms(struct hpsb_host
*host
)
208 for (i
= 0; config_rom_entries
[i
]; i
++) {
209 if (config_rom_entries
[i
]->add(host
)) {
210 HPSB_ERR("fw-host%d: Failed to attach config rom entry `%s'",
211 host
->id
, config_rom_entries
[i
]->name
);
214 host
->config_roms
|= config_rom_entries
[i
]->flag
;
215 host
->update_config_rom
= 1;
222 void hpsb_remove_extra_config_roms(struct hpsb_host
*host
)
226 for (i
= 0; config_rom_entries
[i
]; i
++) {
227 if (!(host
->config_roms
& config_rom_entries
[i
]->flag
))
230 config_rom_entries
[i
]->remove(host
);
232 host
->config_roms
&= ~config_rom_entries
[i
]->flag
;
233 host
->update_config_rom
= 1;