config_roms.c 5.3 KB

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