libiec61883-channel-allocation-without-local-node-rw.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. Date: Thu, 15 Jan 2009 15:41:16 +0100 (CET)
  2. From: Stefan Richter <stefanr@s5r6.in-berlin.de>
  3. Subject: [PATCH libiec61883] cmp: replace open-coded channel allocation by
  4. raw1394_channel_modify
  5. To: Dan Dennedy <dan@dennedy.org>
  6. Cc: linux1394-devel@lists.sourceforge.net
  7. On 15 Jan, Dan Dennedy wrote:
  8. > On Thu, Jan 1, 2009 at 5:13 AM, Stefan Richter
  9. > <stefanr@s5r6.in-berlin.de> wrote:
  10. >> input plug register on the local node? AFAICT neither dvgrab nor kino
  11. >> use raw1394_channel_modify and raw1394_bandwidth_modify, not even
  12. >> through libiec61883.)
  13. >
  14. > dvgrab indirectly uses channel_modify when you use its -guid option to
  15. > establish a point-to-point connection.
  16. >
  17. Hmm.
  18. $ dvgrab -guid 0x008088030960484b
  19. libiec61883 error: Failed to get channels available.
  20. Established connection over channel 63
  21. [...proceeds with capture...]
  22. --------------------------------- 8< ---------------------------------
  23. cmp: replace open-coded channel allocation by raw1394_channel_modify
  24. The benefit is that it works on kernel 2.6.30 firewire-core without
  25. write permission to the IRM's device file (provided that libraw1394 is
  26. extended for 2.6.30 ioctls too, otherwise it still needs access to the
  27. IRM's file).
  28. If I read the code correctly, iec61883_cmp_normalize_output doesn't care
  29. whether the channel was already allocated by somebody else; it only
  30. cares that the channel is allocated. That's what the new code does too.
  31. ---
  32. src/cmp.c | 56 +++++++++---------------------------------------------
  33. 1 file changed, 10 insertions(+), 46 deletions(-)
  34. Index: libiec61883-1.2.0/src/cmp.c
  35. ===================================================================
  36. --- libiec61883-1.2.0.orig/src/cmp.c
  37. +++ libiec61883-1.2.0/src/cmp.c
  38. @@ -973,55 +973,19 @@ iec61883_cmp_normalize_output (raw1394ha
  39. DEBUG ("iec61883_cmp_normalize_output: node %d\n", (int) node & 0x3f);
  40. - // Check for plugs on output
  41. + /* Check for plugs on output */
  42. result = iec61883_get_oMPR (handle, node, &ompr);
  43. if (result < 0)
  44. return result;
  45. - // locate an ouput plug that has a connection
  46. - for (oplug = 0; oplug < ompr.n_plugs; oplug++) {
  47. - if (iec61883_get_oPCRX (handle, node, &opcr, oplug) == 0) {
  48. - if (opcr.online && (opcr.n_p2p_connections > 0 ||
  49. - opcr.bcast_connection == 1)) {
  50. + /* Locate an ouptut plug that has a connection,
  51. + * make sure the plug's channel is allocated with IRM */
  52. + for (oplug = 0; oplug < ompr.n_plugs; oplug++)
  53. + if (iec61883_get_oPCRX (handle, node, &opcr, oplug) == 0
  54. + && opcr.online
  55. + && (opcr.n_p2p_connections > 0 || opcr.bcast_connection == 1)
  56. + && raw1394_channel_modify (handle, opcr.channel, RAW1394_MODIFY_ALLOC) < 0)
  57. + DEBUG ("Channel %d already allocated, or can't reach IRM", opcr.channel);
  58. - // Make sure the plug's channel is allocated with IRM
  59. - quadlet_t buffer;
  60. - nodeaddr_t addr = CSR_REGISTER_BASE;
  61. - unsigned int c = opcr.channel;
  62. - quadlet_t compare, swap = 0;
  63. - quadlet_t new;
  64. -
  65. - if (c > 31 && c < 64) {
  66. - addr += CSR_CHANNELS_AVAILABLE_LO;
  67. - c -= 32;
  68. - } else if (c < 64)
  69. - addr += CSR_CHANNELS_AVAILABLE_HI;
  70. - else
  71. - FAIL ("Invalid channel");
  72. - c = 31 - c;
  73. -
  74. - result = iec61883_cooked_read (handle, raw1394_get_irm_id (handle), addr,
  75. - sizeof (quadlet_t), &buffer);
  76. - if (result < 0)
  77. - FAIL ("Failed to get channels available.");
  78. -
  79. - buffer = ntohl (buffer);
  80. - DEBUG ("channels available before: 0x%08x", buffer);
  81. -
  82. - if ((buffer & (1 << c)) != 0) {
  83. - swap = htonl (buffer & ~(1 << c));
  84. - compare = htonl (buffer);
  85. -
  86. - result = raw1394_lock (handle, raw1394_get_irm_id (handle), addr,
  87. - EXTCODE_COMPARE_SWAP, swap, compare, &new);
  88. - if ( (result < 0) || (new != compare) ) {
  89. - FAIL ("Failed to modify channel %d", opcr.channel);
  90. - }
  91. - DEBUG ("channels available after: 0x%08x", ntohl (swap));
  92. - }
  93. - }
  94. - }
  95. - }
  96. -
  97. - return result;
  98. + return 0;
  99. }
  100. --
  101. Stefan Richter
  102. -=====-==--= ---= -====
  103. http://arcgraph.de/sr/