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

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