[PATCH] w1: Make w1 connector notifications depend on connector.
[linux-2.6/verdex.git] / drivers / ieee1394 / config_roms.c
blob1017fd7172486dd3058694ca22368b973f707469
1 /*
2 * IEEE 1394 for Linux
4 * ConfigROM entries
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>
15 #include "csr1212.h"
16 #include "ieee1394.h"
17 #include "ieee1394_types.h"
18 #include "hosts.h"
19 #include "ieee1394_core.h"
20 #include "highlevel.h"
21 #include "csr.h"
22 #include "config_roms.h"
24 struct hpsb_config_rom_entry {
25 const char *name;
27 /* Base initialization, called at module load */
28 int (*init)(void);
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 */
40 unsigned int flag;
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;
49 char csr_name[128];
50 int ret;
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) {
59 if (vend_id)
60 csr1212_release_keyval(vend_id);
61 if (text)
62 csr1212_release_keyval(text);
63 csr1212_destroy_csr(host->csr.rom);
64 return -ENOMEM;
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);
73 return -ENOMEM;
76 host->update_config_rom = 1;
78 return 0;
82 #ifdef CONFIG_IEEE1394_CONFIG_ROM_IP1394
83 #include "eth1394.h"
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;
93 int ret = -ENOMEM;
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)
105 goto ip1394_fail;
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)
111 ret = 0;
113 ip1394_fail:
114 if (ret && ip1394_ud) {
115 csr1212_release_keyval(ip1394_ud);
116 ip1394_ud = NULL;
119 if (spec_id)
120 csr1212_release_keyval(spec_id);
121 if (spec_desc)
122 csr1212_release_keyval(spec_desc);
123 if (ver)
124 csr1212_release_keyval(ver);
125 if (ver_desc)
126 csr1212_release_keyval(ver_desc);
128 return ret;
131 static void config_rom_ip1394_cleanup(void)
133 if (ip1394_ud) {
134 csr1212_release_keyval(ip1394_ud);
135 ip1394_ud = NULL;
139 static int config_rom_ip1394_add(struct hpsb_host *host)
141 if (!ip1394_ud)
142 return -ENODEV;
144 if (csr1212_attach_keyval_to_directory(host->csr.rom->root_kv,
145 ip1394_ud) != CSR1212_SUCCESS)
146 return -ENOMEM;
148 return 0;
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 = {
157 .name = "ip1394",
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
169 &ip1394_entry,
170 #endif
171 NULL,
175 int hpsb_init_config_roms(void)
177 int i, error = 0;
179 for (i = 0; config_rom_entries[i]; i++) {
180 if (!config_rom_entries[i]->init)
181 continue;
183 if (config_rom_entries[i]->init()) {
184 HPSB_ERR("Failed to initialize config rom entry `%s'",
185 config_rom_entries[i]->name);
186 error = -1;
187 } else
188 HPSB_DEBUG("Initialized config rom entry `%s'",
189 config_rom_entries[i]->name);
192 return error;
195 void hpsb_cleanup_config_roms(void)
197 int i;
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)
207 int i, error = 0;
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);
213 error = -1;
214 } else {
215 host->config_roms |= config_rom_entries[i]->flag;
216 host->update_config_rom = 1;
220 return error;
223 void hpsb_remove_extra_config_roms(struct hpsb_host *host)
225 int i;
227 for (i = 0; config_rom_entries[i]; i++) {
228 if (!(host->config_roms & config_rom_entries[i]->flag))
229 continue;
231 config_rom_entries[i]->remove(host);
233 host->config_roms &= ~config_rom_entries[i]->flag;
234 host->update_config_rom = 1;