Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | /* Cleanup called at module exit */ |
| 30 | void (*cleanup)(void); |
| 31 | |
| 32 | /* The flag added to host->config_roms */ |
| 33 | unsigned int flag; |
| 34 | }; |
| 35 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 36 | /* The default host entry. This must succeed. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | int hpsb_default_host_entry(struct hpsb_host *host) |
| 38 | { |
| 39 | struct csr1212_keyval *root; |
| 40 | struct csr1212_keyval *vend_id = NULL; |
| 41 | struct csr1212_keyval *text = NULL; |
| 42 | char csr_name[128]; |
| 43 | int ret; |
| 44 | |
| 45 | sprintf(csr_name, "Linux - %s", host->driver->name); |
| 46 | root = host->csr.rom->root_kv; |
| 47 | |
| 48 | vend_id = csr1212_new_immediate(CSR1212_KV_ID_VENDOR, host->csr.guid_hi >> 8); |
| 49 | text = csr1212_new_string_descriptor_leaf(csr_name); |
| 50 | |
| 51 | if (!vend_id || !text) { |
| 52 | if (vend_id) |
| 53 | csr1212_release_keyval(vend_id); |
| 54 | if (text) |
| 55 | csr1212_release_keyval(text); |
| 56 | csr1212_destroy_csr(host->csr.rom); |
| 57 | return -ENOMEM; |
| 58 | } |
| 59 | |
Stefan Richter | 64ff712 | 2007-03-11 22:50:13 +0100 | [diff] [blame] | 60 | csr1212_associate_keyval(vend_id, text); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | csr1212_release_keyval(text); |
Stefan Richter | 64ff712 | 2007-03-11 22:50:13 +0100 | [diff] [blame] | 62 | ret = csr1212_attach_keyval_to_directory(root, vend_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | csr1212_release_keyval(vend_id); |
| 64 | if (ret != CSR1212_SUCCESS) { |
| 65 | csr1212_destroy_csr(host->csr.rom); |
| 66 | return -ENOMEM; |
| 67 | } |
| 68 | |
| 69 | host->update_config_rom = 1; |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 75 | #ifdef CONFIG_IEEE1394_ETH1394_ROM_ENTRY |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | #include "eth1394.h" |
| 77 | |
| 78 | static struct csr1212_keyval *ip1394_ud; |
| 79 | |
| 80 | static int config_rom_ip1394_init(void) |
| 81 | { |
| 82 | struct csr1212_keyval *spec_id = NULL; |
| 83 | struct csr1212_keyval *spec_desc = NULL; |
| 84 | struct csr1212_keyval *ver = NULL; |
| 85 | struct csr1212_keyval *ver_desc = NULL; |
| 86 | int ret = -ENOMEM; |
| 87 | |
| 88 | ip1394_ud = csr1212_new_directory(CSR1212_KV_ID_UNIT); |
| 89 | |
| 90 | spec_id = csr1212_new_immediate(CSR1212_KV_ID_SPECIFIER_ID, |
| 91 | ETHER1394_GASP_SPECIFIER_ID); |
| 92 | spec_desc = csr1212_new_string_descriptor_leaf("IANA"); |
| 93 | ver = csr1212_new_immediate(CSR1212_KV_ID_VERSION, |
| 94 | ETHER1394_GASP_VERSION); |
| 95 | ver_desc = csr1212_new_string_descriptor_leaf("IPv4"); |
| 96 | |
| 97 | if (!ip1394_ud || !spec_id || !spec_desc || !ver || !ver_desc) |
| 98 | goto ip1394_fail; |
| 99 | |
Stefan Richter | 64ff712 | 2007-03-11 22:50:13 +0100 | [diff] [blame] | 100 | csr1212_associate_keyval(spec_id, spec_desc); |
| 101 | csr1212_associate_keyval(ver, ver_desc); |
| 102 | if (csr1212_attach_keyval_to_directory(ip1394_ud, spec_id) |
| 103 | == CSR1212_SUCCESS && |
| 104 | csr1212_attach_keyval_to_directory(ip1394_ud, ver) |
| 105 | == CSR1212_SUCCESS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | ret = 0; |
| 107 | |
| 108 | ip1394_fail: |
| 109 | if (ret && ip1394_ud) { |
| 110 | csr1212_release_keyval(ip1394_ud); |
| 111 | ip1394_ud = NULL; |
| 112 | } |
| 113 | |
| 114 | if (spec_id) |
| 115 | csr1212_release_keyval(spec_id); |
| 116 | if (spec_desc) |
| 117 | csr1212_release_keyval(spec_desc); |
| 118 | if (ver) |
| 119 | csr1212_release_keyval(ver); |
| 120 | if (ver_desc) |
| 121 | csr1212_release_keyval(ver_desc); |
| 122 | |
| 123 | return ret; |
| 124 | } |
| 125 | |
| 126 | static void config_rom_ip1394_cleanup(void) |
| 127 | { |
| 128 | if (ip1394_ud) { |
| 129 | csr1212_release_keyval(ip1394_ud); |
| 130 | ip1394_ud = NULL; |
| 131 | } |
| 132 | } |
| 133 | |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 134 | int hpsb_config_rom_ip1394_add(struct hpsb_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | { |
| 136 | if (!ip1394_ud) |
| 137 | return -ENODEV; |
| 138 | |
| 139 | if (csr1212_attach_keyval_to_directory(host->csr.rom->root_kv, |
| 140 | ip1394_ud) != CSR1212_SUCCESS) |
| 141 | return -ENOMEM; |
| 142 | |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 143 | host->config_roms |= HPSB_CONFIG_ROM_ENTRY_IP1394; |
| 144 | host->update_config_rom = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | return 0; |
| 146 | } |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 147 | EXPORT_SYMBOL_GPL(hpsb_config_rom_ip1394_add); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 149 | void hpsb_config_rom_ip1394_remove(struct hpsb_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
| 151 | csr1212_detach_keyval_from_directory(host->csr.rom->root_kv, ip1394_ud); |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 152 | host->config_roms &= ~HPSB_CONFIG_ROM_ENTRY_IP1394; |
| 153 | host->update_config_rom = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | } |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 155 | EXPORT_SYMBOL_GPL(hpsb_config_rom_ip1394_remove); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | static struct hpsb_config_rom_entry ip1394_entry = { |
| 158 | .name = "ip1394", |
| 159 | .init = config_rom_ip1394_init, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | .cleanup = config_rom_ip1394_cleanup, |
| 161 | .flag = HPSB_CONFIG_ROM_ENTRY_IP1394, |
| 162 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 164 | #endif /* CONFIG_IEEE1394_ETH1394_ROM_ENTRY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | static struct hpsb_config_rom_entry *const config_rom_entries[] = { |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 167 | #ifdef CONFIG_IEEE1394_ETH1394_ROM_ENTRY |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | &ip1394_entry, |
| 169 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | }; |
| 171 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 172 | /* Initialize all config roms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | int hpsb_init_config_roms(void) |
| 174 | { |
| 175 | int i, error = 0; |
| 176 | |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 177 | for (i = 0; i < ARRAY_SIZE(config_rom_entries); i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | if (config_rom_entries[i]->init()) { |
| 179 | HPSB_ERR("Failed to initialize config rom entry `%s'", |
| 180 | config_rom_entries[i]->name); |
| 181 | error = -1; |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 182 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | return error; |
| 185 | } |
| 186 | |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 187 | /* Cleanup all config roms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | void hpsb_cleanup_config_roms(void) |
| 189 | { |
| 190 | int i; |
| 191 | |
Stefan Richter | 70093cf | 2007-03-27 01:36:50 +0200 | [diff] [blame] | 192 | for (i = 0; i < ARRAY_SIZE(config_rom_entries); i++) |
| 193 | config_rom_entries[i]->cleanup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |