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/config.h>
13 #include <linux/types.h>
17 #include "ieee1394_types.h"
19 #include "ieee1394_core.h"
20 #include "highlevel.h"
22 #include "config_roms.h"
24 struct hpsb_config_rom_entry
{
27 /* Base initialization, called at module load */
30 /* Add entry to specified host */
31 int (*add
)(struct hpsb_host
*host
);
33 /* Remove entry from specified host */
34 void (*remove
)(struct hpsb_host
*host
);
36 /* Cleanup called at module exit */
37 void (*cleanup
)(void);
39 /* The flag added to host->config_roms */
44 int hpsb_default_host_entry(struct hpsb_host
*host
)
46 struct csr1212_keyval
*root
;
47 struct csr1212_keyval
*vend_id
= NULL
;
48 struct csr1212_keyval
*text
= NULL
;
52 sprintf(csr_name
, "Linux - %s", host
->driver
->name
);
53 root
= host
->csr
.rom
->root_kv
;
55 vend_id
= csr1212_new_immediate(CSR1212_KV_ID_VENDOR
, host
->csr
.guid_hi
>> 8);
56 text
= csr1212_new_string_descriptor_leaf(csr_name
);
58 if (!vend_id
|| !text
) {
60 csr1212_release_keyval(vend_id
);
62 csr1212_release_keyval(text
);
63 csr1212_destroy_csr(host
->csr
.rom
);
67 ret
= csr1212_associate_keyval(vend_id
, text
);
68 csr1212_release_keyval(text
);
69 ret
|= csr1212_attach_keyval_to_directory(root
, vend_id
);
70 csr1212_release_keyval(vend_id
);
71 if (ret
!= CSR1212_SUCCESS
) {
72 csr1212_destroy_csr(host
->csr
.rom
);
76 host
->update_config_rom
= 1;
82 #ifdef CONFIG_IEEE1394_CONFIG_ROM_IP1394
85 static struct csr1212_keyval
*ip1394_ud
;
87 static int config_rom_ip1394_init(void)
89 struct csr1212_keyval
*spec_id
= NULL
;
90 struct csr1212_keyval
*spec_desc
= NULL
;
91 struct csr1212_keyval
*ver
= NULL
;
92 struct csr1212_keyval
*ver_desc
= NULL
;
95 ip1394_ud
= csr1212_new_directory(CSR1212_KV_ID_UNIT
);
97 spec_id
= csr1212_new_immediate(CSR1212_KV_ID_SPECIFIER_ID
,
98 ETHER1394_GASP_SPECIFIER_ID
);
99 spec_desc
= csr1212_new_string_descriptor_leaf("IANA");
100 ver
= csr1212_new_immediate(CSR1212_KV_ID_VERSION
,
101 ETHER1394_GASP_VERSION
);
102 ver_desc
= csr1212_new_string_descriptor_leaf("IPv4");
104 if (!ip1394_ud
|| !spec_id
|| !spec_desc
|| !ver
|| !ver_desc
)
107 if (csr1212_associate_keyval(spec_id
, spec_desc
) == CSR1212_SUCCESS
&&
108 csr1212_associate_keyval(ver
, ver_desc
) == CSR1212_SUCCESS
&&
109 csr1212_attach_keyval_to_directory(ip1394_ud
, spec_id
) == CSR1212_SUCCESS
&&
110 csr1212_attach_keyval_to_directory(ip1394_ud
, ver
) == CSR1212_SUCCESS
)
114 if (ret
&& ip1394_ud
) {
115 csr1212_release_keyval(ip1394_ud
);
120 csr1212_release_keyval(spec_id
);
122 csr1212_release_keyval(spec_desc
);
124 csr1212_release_keyval(ver
);
126 csr1212_release_keyval(ver_desc
);
131 static void config_rom_ip1394_cleanup(void)
134 csr1212_release_keyval(ip1394_ud
);
139 static int config_rom_ip1394_add(struct hpsb_host
*host
)
144 if (csr1212_attach_keyval_to_directory(host
->csr
.rom
->root_kv
,
145 ip1394_ud
) != CSR1212_SUCCESS
)
151 static void config_rom_ip1394_remove(struct hpsb_host
*host
)
153 csr1212_detach_keyval_from_directory(host
->csr
.rom
->root_kv
, ip1394_ud
);
156 static struct hpsb_config_rom_entry ip1394_entry
= {
158 .init
= config_rom_ip1394_init
,
159 .add
= config_rom_ip1394_add
,
160 .remove
= config_rom_ip1394_remove
,
161 .cleanup
= config_rom_ip1394_cleanup
,
162 .flag
= HPSB_CONFIG_ROM_ENTRY_IP1394
,
164 #endif /* CONFIG_IEEE1394_CONFIG_ROM_IP1394 */
167 static struct hpsb_config_rom_entry
*const config_rom_entries
[] = {
168 #ifdef CONFIG_IEEE1394_CONFIG_ROM_IP1394
175 int hpsb_init_config_roms(void)
179 for (i
= 0; config_rom_entries
[i
]; i
++) {
180 if (!config_rom_entries
[i
]->init
)
183 if (config_rom_entries
[i
]->init()) {
184 HPSB_ERR("Failed to initialize config rom entry `%s'",
185 config_rom_entries
[i
]->name
);
188 HPSB_DEBUG("Initialized config rom entry `%s'",
189 config_rom_entries
[i
]->name
);
195 void hpsb_cleanup_config_roms(void)
199 for (i
= 0; config_rom_entries
[i
]; i
++) {
200 if (config_rom_entries
[i
]->cleanup
)
201 config_rom_entries
[i
]->cleanup();
205 int hpsb_add_extra_config_roms(struct hpsb_host
*host
)
209 for (i
= 0; config_rom_entries
[i
]; i
++) {
210 if (config_rom_entries
[i
]->add(host
)) {
211 HPSB_ERR("fw-host%d: Failed to attach config rom entry `%s'",
212 host
->id
, config_rom_entries
[i
]->name
);
215 host
->config_roms
|= config_rom_entries
[i
]->flag
;
216 host
->update_config_rom
= 1;
223 void hpsb_remove_extra_config_roms(struct hpsb_host
*host
)
227 for (i
= 0; config_rom_entries
[i
]; i
++) {
228 if (!(host
->config_roms
& config_rom_entries
[i
]->flag
))
231 config_rom_entries
[i
]->remove(host
);
233 host
->config_roms
&= ~config_rom_entries
[i
]->flag
;
234 host
->update_config_rom
= 1;