Blame SOURCES/libiec61883-channel-allocation-without-local-node-rw.patch

39bcae
Date: Thu, 15 Jan 2009 15:41:16 +0100 (CET)
39bcae
From: Stefan Richter <stefanr@s5r6.in-berlin.de>
39bcae
Subject: [PATCH libiec61883] cmp: replace open-coded channel allocation by
39bcae
	raw1394_channel_modify
39bcae
To: Dan Dennedy <dan@dennedy.org>
39bcae
Cc: linux1394-devel@lists.sourceforge.net
39bcae
39bcae
On 15 Jan, Dan Dennedy wrote:
39bcae
> On Thu, Jan 1, 2009 at 5:13 AM, Stefan Richter
39bcae
> <stefanr@s5r6.in-berlin.de> wrote:
39bcae
>> input plug register on the local node?  AFAICT neither dvgrab nor kino
39bcae
>> use raw1394_channel_modify and raw1394_bandwidth_modify, not even
39bcae
>> through libiec61883.)
39bcae
> 
39bcae
> dvgrab indirectly uses channel_modify when you use its -guid option to
39bcae
> establish a point-to-point connection.
39bcae
> 
39bcae
39bcae
Hmm.
39bcae
39bcae
$ dvgrab -guid 0x008088030960484b
39bcae
libiec61883 error: Failed to get channels available.
39bcae
Established connection over channel 63
39bcae
[...proceeds with capture...]
39bcae
39bcae
39bcae
--------------------------------- 8< ---------------------------------
39bcae
39bcae
cmp: replace open-coded channel allocation by raw1394_channel_modify
39bcae
39bcae
The benefit is that it works on kernel 2.6.30 firewire-core without
39bcae
write permission to the IRM's device file (provided that libraw1394 is
39bcae
extended for 2.6.30 ioctls too, otherwise it still needs access to the
39bcae
IRM's file).
39bcae
39bcae
If I read the code correctly, iec61883_cmp_normalize_output doesn't care
39bcae
whether the channel was already allocated by somebody else; it only
39bcae
cares that the channel is allocated.  That's what the new code does too.
39bcae
---
39bcae
 src/cmp.c |   56 +++++++++---------------------------------------------
39bcae
 1 file changed, 10 insertions(+), 46 deletions(-)
39bcae
39bcae
Index: libiec61883-1.2.0/src/cmp.c
39bcae
===================================================================
39bcae
--- libiec61883-1.2.0.orig/src/cmp.c
39bcae
+++ libiec61883-1.2.0/src/cmp.c
39bcae
@@ -973,55 +973,19 @@ iec61883_cmp_normalize_output (raw1394ha
39bcae
 
39bcae
 	DEBUG ("iec61883_cmp_normalize_output: node %d\n", (int) node & 0x3f);
39bcae
 
39bcae
-	// Check for plugs on output
39bcae
+	/* Check for plugs on output */
39bcae
 	result = iec61883_get_oMPR (handle, node, &ompr);
39bcae
 	if (result < 0)
39bcae
 		return result;
39bcae
 	
39bcae
-	// locate an ouput plug that has a connection
39bcae
-	for (oplug = 0; oplug < ompr.n_plugs; oplug++) {
39bcae
-		if (iec61883_get_oPCRX (handle, node, &opcr, oplug) == 0) {
39bcae
-			if (opcr.online && (opcr.n_p2p_connections > 0 || 
39bcae
-				                opcr.bcast_connection == 1)) {
39bcae
+	/* Locate an ouptut plug that has a connection,
39bcae
+	 * make sure the plug's channel is allocated with IRM */
39bcae
+	for (oplug = 0; oplug < ompr.n_plugs; oplug++)
39bcae
+		if (iec61883_get_oPCRX (handle, node, &opcr, oplug) == 0
39bcae
+		    && opcr.online
39bcae
+		    && (opcr.n_p2p_connections > 0 || opcr.bcast_connection == 1)
39bcae
+		    && raw1394_channel_modify (handle, opcr.channel, RAW1394_MODIFY_ALLOC) < 0)
39bcae
+			DEBUG ("Channel %d already allocated, or can't reach IRM", opcr.channel);
39bcae
 
39bcae
-				// Make sure the plug's channel is allocated with IRM
39bcae
-				quadlet_t buffer;
39bcae
-				nodeaddr_t addr = CSR_REGISTER_BASE;
39bcae
-				unsigned int c = opcr.channel;
39bcae
-				quadlet_t compare, swap = 0;
39bcae
-				quadlet_t new;
39bcae
-				
39bcae
-				if (c > 31 && c < 64) {
39bcae
-					addr += CSR_CHANNELS_AVAILABLE_LO;
39bcae
-					c -= 32;
39bcae
-				} else if (c < 64)
39bcae
-					addr += CSR_CHANNELS_AVAILABLE_HI;
39bcae
-				else
39bcae
-					FAIL ("Invalid channel");
39bcae
-				c = 31 - c;
39bcae
-
39bcae
-				result = iec61883_cooked_read (handle, raw1394_get_irm_id (handle), addr, 
39bcae
-					sizeof (quadlet_t), &buffer);
39bcae
-				if (result < 0)
39bcae
-					FAIL ("Failed to get channels available.");
39bcae
-				
39bcae
-				buffer = ntohl (buffer);
39bcae
-				DEBUG ("channels available before: 0x%08x", buffer);
39bcae
-
39bcae
-				if ((buffer & (1 << c)) != 0) {
39bcae
-					swap = htonl (buffer & ~(1 << c));
39bcae
-					compare = htonl (buffer);
39bcae
-
39bcae
-					result = raw1394_lock (handle, raw1394_get_irm_id (handle), addr,
39bcae
-							   EXTCODE_COMPARE_SWAP, swap, compare, &new;;
39bcae
-					if ( (result < 0) || (new != compare) ) {
39bcae
-						FAIL ("Failed to modify channel %d", opcr.channel);
39bcae
-					}
39bcae
-					DEBUG ("channels available after: 0x%08x", ntohl (swap));
39bcae
-				}
39bcae
-			}
39bcae
-		}
39bcae
-	}
39bcae
-		
39bcae
-	return result;
39bcae
+	return 0;
39bcae
 }
39bcae
39bcae
-- 
39bcae
Stefan Richter
39bcae
-=====-==--= ---= -====
39bcae
http://arcgraph.de/sr/