config_roms.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. #include <linux/config.h>
  12. #include <linux/types.h>
  13. #include "csr1212.h"
  14. #include "ieee1394.h"
  15. #include "ieee1394_types.h"
  16. #include "hosts.h"
  17. #include "ieee1394_core.h"
  18. #include "highlevel.h"
  19. #include "csr.h"
  20. #include "config_roms.h"
  21. struct hpsb_config_rom_entry {
  22. const char *name;
  23. /* Base initialization, called at module load */
  24. int (*init)(void);
  25. /* Add entry to specified host */
  26. int (*add)(struct hpsb_host *host);
  27. /* Remove entry from specified host */
  28. void (*remove)(struct hpsb_host *host);
  29. /* Cleanup called at module exit */
  30. void (*cleanup)(void);
  31. /* The flag added to host->config_roms */
  32. unsigned int flag;
  33. };
  34. int hpsb_default_host_entry(struct hpsb_host *host)
  35. {
  36. struct csr1212_keyval *root;
  37. struct csr1212_keyval *vend_id = NULL;
  38. struct csr1212_keyval *text = NULL;
  39. char csr_name[128];
  40. int ret;
  41. sprintf(csr_name, "Linux - %s", host->driver->name);
  42. root = host->csr.rom->root_kv;
  43. vend_id = csr1212_new_immediate(CSR1212_KV_ID_VENDOR, host->csr.guid_hi >> 8);
  44. text = csr1212_new_string_descriptor_leaf(csr_name);
  45. if (!vend_id || !text) {
  46. if (vend_id)
  47. csr1212_release_keyval(vend_id);
  48. if (text)
  49. csr1212_release_keyval(text);
  50. csr1212_destroy_csr(host->csr.rom);
  51. return -ENOMEM;
  52. }
  53. ret = csr1212_associate_keyval(vend_id, text);
  54. csr1212_release_keyval(text);
  55. ret |= csr1212_attach_keyval_to_directory(root, vend_id);
  56. csr1212_release_keyval(vend_id);
  57. if (ret != CSR1212_SUCCESS) {
  58. csr1212_destroy_csr(host->csr.rom);
  59. return -ENOMEM;
  60. }
  61. host->update_config_rom = 1;
  62. return 0;
  63. }
  64. #ifdef CONFIG_IEEE1394_CONFIG_ROM_IP1394
  65. #include "eth1394.h"
  66. static struct csr1212_keyval *ip1394_ud;
  67. static int config_rom_ip1394_init(void)
  68. {
  69. struct csr1212_keyval *spec_id = NULL;
  70. struct csr1212_keyval *spec_desc = NULL;
  71. struct csr1212_keyval *ver = NULL;
  72. struct csr1212_keyval *ver_desc = NULL;
  73. int ret = -ENOMEM;
  74. ip1394_ud = csr1212_new_directory(CSR1212_KV_ID_UNIT);
  75. spec_id = csr1212_new_immediate(CSR1212_KV_ID_SPECIFIER_ID,
  76. ETHER1394_GASP_SPECIFIER_ID);
  77. spec_desc = csr1212_new_string_descriptor_leaf("IANA");
  78. ver = csr1212_new_immediate(CSR1212_KV_ID_VERSION,
  79. ETHER1394_GASP_VERSION);
  80. ver_desc = csr1212_new_string_descriptor_leaf("IPv4");
  81. if (!ip1394_ud || !spec_id || !spec_desc || !ver || !ver_desc)
  82. goto ip1394_fail;
  83. if (csr1212_associate_keyval(spec_id, spec_desc) == CSR1212_SUCCESS &&
  84. csr1212_associate_keyval(ver, ver_desc) == CSR1212_SUCCESS &&
  85. csr1212_attach_keyval_to_directory(ip1394_ud, spec_id) == CSR1212_SUCCESS &&
  86. csr1212_attach_keyval_to_directory(ip1394_ud, ver) == CSR1212_SUCCESS)
  87. ret = 0;
  88. ip1394_fail:
  89. if (ret && ip1394_ud) {
  90. csr1212_release_keyval(ip1394_ud);
  91. ip1394_ud = NULL;
  92. }
  93. if (spec_id)
  94. csr1212_release_keyval(spec_id);
  95. if (spec_desc)
  96. csr1212_release_keyval(spec_desc);
  97. if (ver)
  98. csr1212_release_keyval(ver);
  99. if (ver_desc)
  100. csr1212_release_keyval(ver_desc);
  101. return ret;
  102. }
  103. static void config_rom_ip1394_cleanup(void)
  104. {
  105. if (ip1394_ud) {
  106. csr1212_release_keyval(ip1394_ud);
  107. ip1394_ud = NULL;
  108. }
  109. }
  110. static int config_rom_ip1394_add(struct hpsb_host *host)
  111. {
  112. if (!ip1394_ud)
  113. return -ENODEV;
  114. if (csr1212_attach_keyval_to_directory(host->csr.rom->root_kv,
  115. ip1394_ud) != CSR1212_SUCCESS)
  116. return -ENOMEM;
  117. return 0;
  118. }
  119. static void config_rom_ip1394_remove(struct hpsb_host *host)
  120. {
  121. csr1212_detach_keyval_from_directory(host->csr.rom->root_kv, ip1394_ud);
  122. }
  123. static struct hpsb_config_rom_entry ip1394_entry = {
  124. .name = "ip1394",
  125. .init = config_rom_ip1394_init,
  126. .add = config_rom_ip1394_add,
  127. .remove = config_rom_ip1394_remove,
  128. .cleanup = config_rom_ip1394_cleanup,
  129. .flag = HPSB_CONFIG_ROM_ENTRY_IP1394,
  130. };
  131. #endif /* CONFIG_IEEE1394_CONFIG_ROM_IP1394 */
  132. static struct hpsb_config_rom_entry *const config_rom_entries[] = {
  133. #ifdef CONFIG_IEEE1394_CONFIG_ROM_IP1394
  134. &ip1394_entry,
  135. #endif
  136. NULL,
  137. };
  138. int hpsb_init_config_roms(void)
  139. {
  140. int i, error = 0;
  141. for (i = 0; config_rom_entries[i]; i++) {
  142. if (!config_rom_entries[i]->init)
  143. continue;
  144. if (config_rom_entries[i]->init()) {
  145. HPSB_ERR("Failed to initialize config rom entry `%s'",
  146. config_rom_entries[i]->name);
  147. error = -1;
  148. } else
  149. HPSB_DEBUG("Initialized config rom entry `%s'",
  150. config_rom_entries[i]->name);
  151. }
  152. return error;
  153. }
  154. void hpsb_cleanup_config_roms(void)
  155. {
  156. int i;
  157. for (i = 0; config_rom_entries[i]; i++) {
  158. if (config_rom_entries[i]->cleanup)
  159. config_rom_entries[i]->cleanup();
  160. }
  161. }
  162. int hpsb_add_extra_config_roms(struct hpsb_host *host)
  163. {
  164. int i, error = 0;
  165. for (i = 0; config_rom_entries[i]; i++) {
  166. if (config_rom_entries[i]->add(host)) {
  167. HPSB_ERR("fw-host%d: Failed to attach config rom entry `%s'",
  168. host->id, config_rom_entries[i]->name);
  169. error = -1;
  170. } else {
  171. host->config_roms |= config_rom_entries[i]->flag;
  172. host->update_config_rom = 1;
  173. }
  174. }
  175. return error;
  176. }
  177. void hpsb_remove_extra_config_roms(struct hpsb_host *host)
  178. {
  179. int i;
  180. for (i = 0; config_rom_entries[i]; i++) {
  181. if (!(host->config_roms & config_rom_entries[i]->flag))
  182. continue;
  183. config_rom_entries[i]->remove(host);
  184. host->config_roms &= ~config_rom_entries[i]->flag;
  185. host->update_config_rom = 1;
  186. }
  187. }