]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - drivers/ieee1394/config_roms.c
Remove obsolete #include <linux/config.h>
[linux-2.6.git] / drivers / ieee1394 / config_roms.c
1 /*
2  * IEEE 1394 for Linux
3  *
4  * ConfigROM  entries
5  *
6  * Copyright (C) 2004 Ben Collins
7  *
8  * This code is licensed under the GPL.  See the file COPYING in the root
9  * directory of the kernel sources for details.
10  */
11
12 #include <linux/types.h>
13
14 #include "csr1212.h"
15 #include "ieee1394.h"
16 #include "ieee1394_types.h"
17 #include "hosts.h"
18 #include "ieee1394_core.h"
19 #include "highlevel.h"
20 #include "csr.h"
21 #include "config_roms.h"
22
23 struct hpsb_config_rom_entry {
24         const char *name;
25
26         /* Base initialization, called at module load */
27         int (*init)(void);
28
29         /* Add entry to specified host */
30         int (*add)(struct hpsb_host *host);
31
32         /* Remove entry from specified host */
33         void (*remove)(struct hpsb_host *host);
34
35         /* Cleanup called at module exit */
36         void (*cleanup)(void);
37
38         /* The flag added to host->config_roms */
39         unsigned int flag;
40 };
41
42
43 int hpsb_default_host_entry(struct hpsb_host *host)
44 {
45         struct csr1212_keyval *root;
46         struct csr1212_keyval *vend_id = NULL;
47         struct csr1212_keyval *text = NULL;
48         char csr_name[128];
49         int ret;
50
51         sprintf(csr_name, "Linux - %s", host->driver->name);
52         root = host->csr.rom->root_kv;
53
54         vend_id = csr1212_new_immediate(CSR1212_KV_ID_VENDOR, host->csr.guid_hi >> 8);
55         text = csr1212_new_string_descriptor_leaf(csr_name);
56
57         if (!vend_id || !text) {
58                 if (vend_id)
59                         csr1212_release_keyval(vend_id);
60                 if (text)
61                         csr1212_release_keyval(text);
62                 csr1212_destroy_csr(host->csr.rom);
63                 return -ENOMEM;
64         }
65
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);
72                 return -ENOMEM;
73         }
74
75         host->update_config_rom = 1;
76
77         return 0;
78 }
79
80
81 #ifdef CONFIG_IEEE1394_CONFIG_ROM_IP1394
82 #include "eth1394.h"
83
84 static struct csr1212_keyval *ip1394_ud;
85
86 static int config_rom_ip1394_init(void)
87 {
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;
92         int ret = -ENOMEM;
93
94         ip1394_ud = csr1212_new_directory(CSR1212_KV_ID_UNIT);
95
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");
102
103         if (!ip1394_ud || !spec_id || !spec_desc || !ver || !ver_desc)
104                 goto ip1394_fail;
105
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)
110                 ret = 0;
111
112 ip1394_fail:
113         if (ret && ip1394_ud) {
114                 csr1212_release_keyval(ip1394_ud);
115                 ip1394_ud = NULL;
116         }
117
118         if (spec_id)
119                 csr1212_release_keyval(spec_id);
120         if (spec_desc)
121                 csr1212_release_keyval(spec_desc);
122         if (ver)
123                 csr1212_release_keyval(ver);
124         if (ver_desc)
125                 csr1212_release_keyval(ver_desc);
126
127         return ret;
128 }
129
130 static void config_rom_ip1394_cleanup(void)
131 {
132         if (ip1394_ud) {
133                 csr1212_release_keyval(ip1394_ud);
134                 ip1394_ud = NULL;
135         }
136 }
137
138 static int config_rom_ip1394_add(struct hpsb_host *host)
139 {
140         if (!ip1394_ud)
141                 return -ENODEV;
142
143         if (csr1212_attach_keyval_to_directory(host->csr.rom->root_kv,
144                                                ip1394_ud) != CSR1212_SUCCESS)
145                 return -ENOMEM;
146
147         return 0;
148 }
149
150 static void config_rom_ip1394_remove(struct hpsb_host *host)
151 {
152         csr1212_detach_keyval_from_directory(host->csr.rom->root_kv, ip1394_ud);
153 }
154
155 static struct hpsb_config_rom_entry ip1394_entry = {
156         .name           = "ip1394",
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,
162 };
163 #endif /* CONFIG_IEEE1394_CONFIG_ROM_IP1394 */
164
165
166 static struct hpsb_config_rom_entry *const config_rom_entries[] = {
167 #ifdef CONFIG_IEEE1394_CONFIG_ROM_IP1394
168         &ip1394_entry,
169 #endif
170         NULL,
171 };
172
173
174 int hpsb_init_config_roms(void)
175 {
176         int i, error = 0;
177
178         for (i = 0; config_rom_entries[i]; i++) {
179                 if (!config_rom_entries[i]->init)
180                         continue;
181
182                 if (config_rom_entries[i]->init()) {
183                         HPSB_ERR("Failed to initialize config rom entry `%s'",
184                                  config_rom_entries[i]->name);
185                         error = -1;
186                 } else
187                         HPSB_DEBUG("Initialized config rom entry `%s'",
188                                    config_rom_entries[i]->name);
189         }
190
191         return error;
192 }
193
194 void hpsb_cleanup_config_roms(void)
195 {
196         int i;
197
198         for (i = 0; config_rom_entries[i]; i++) {
199                 if (config_rom_entries[i]->cleanup)
200                         config_rom_entries[i]->cleanup();
201         }
202 }
203
204 int hpsb_add_extra_config_roms(struct hpsb_host *host)
205 {
206         int i, error = 0;
207
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);
212                         error = -1;
213                 } else {
214                         host->config_roms |= config_rom_entries[i]->flag;
215                         host->update_config_rom = 1;
216                 }
217         }
218
219         return error;
220 }
221
222 void hpsb_remove_extra_config_roms(struct hpsb_host *host)
223 {
224         int i;
225
226         for (i = 0; config_rom_entries[i]; i++) {
227                 if (!(host->config_roms & config_rom_entries[i]->flag))
228                         continue;
229
230                 config_rom_entries[i]->remove(host);
231
232                 host->config_roms &= ~config_rom_entries[i]->flag;
233                 host->update_config_rom = 1;
234         }
235 }