From 6ef4a1ccee37fe19408d671632eaf1d33225da96 Mon Sep 17 00:00:00 2001 From: "Terry J. Opie" Date: Tue, 6 Dec 2011 13:26:00 -0600 Subject: I2C to use Attribute based Mutexes Additionally: - Static initializer for EEPROM mutex - Move I2C back to extended image Change-Id: I3cb4bd755aff7c223b3fd794ee88947b0e77f179 Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/565 Tested-by: Jenkins Server Reviewed-by: Daniel M. Crowell Reviewed-by: A. Patrick Williams III --- src/usr/i2c/i2c.C | 59 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 19 deletions(-) (limited to 'src/usr/i2c/i2c.C') diff --git a/src/usr/i2c/i2c.C b/src/usr/i2c/i2c.C index 9d7c64464..a503e97cf 100755 --- a/src/usr/i2c/i2c.C +++ b/src/usr/i2c/i2c.C @@ -44,11 +44,6 @@ // ---------------------------------------------- // Globals // ---------------------------------------------- -// TODO - These are temporary until we get some sort of locking mutex -// in the attributes for each master target. All operations will be -// sequential no matter what target or what engine. -mutex_t g_i2cMutex; -bool g_initI2CMutex = true; // ---------------------------------------------- // Trace definitions @@ -58,6 +53,7 @@ TRAC_INIT( & g_trac_i2c, "I2C", 4096 ); trace_desc_t* g_trac_i2cr = NULL; TRAC_INIT( & g_trac_i2cr, "I2CR", 4096 ); + // Easy macro replace for unit testing //#define TRACUCOMP(args...) TRACFCOMP(args) #define TRACUCOMP(args...) @@ -67,6 +63,7 @@ TRAC_INIT( & g_trac_i2cr, "I2CR", 4096 ); // ---------------------------------------------- #define I2C_COMMAND_ATTEMPTS 2 // 1 Retry on failure #define I2C_RETRY_DELAY 10000000 // Sleep for 10 ms before retrying +#define MAX_I2C_ENGINES 3 // Maximum of 3 engines per I2C Master // ---------------------------------------------- namespace I2C @@ -108,12 +105,6 @@ errlHndl_t i2cPerformOp( DeviceFW::OperationType i_opType, do { - if( g_initI2CMutex ) - { - mutex_init( &g_i2cMutex ); - g_initI2CMutex = false; - } - // Check for Master Sentinel chip if( TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL == i_target ) { @@ -140,13 +131,38 @@ errlHndl_t i2cPerformOp( DeviceFW::OperationType i_opType, break; } - // TODO - Locking needs to be implemented for each engine on each - // possible chip. The details of this still need to be worked out. - // This will be implemented with the bad machine path story (3629). - // TODO - Locking will be waiting on Story 4158 to see how we can - // handle the mutexes in the attributes... Use the global mutex - // until then. - mutex_lock( &g_i2cMutex ); + // Get the mutex for the requested engine + mutex_t * engineLock = NULL; + switch( args.engine ) + { + case 0: + engineLock = i_target->getHbMutexAttr(); + break; + + case 1: + engineLock = i_target->getHbMutexAttr(); + break; + + case 2: + engineLock = i_target->getHbMutexAttr(); + break; + + default: + TRACFCOMP( g_trac_i2c, + ERR_MRK"Invalid engine for getting Mutex!" ); + // TODO - Create an error here + break; + }; + + // Lock on this engine + TRACUCOMP( g_trac_i2c, + INFO_MRK"Obtaining lock for engine: %d", + args.engine ); + (void)mutex_lock( engineLock ); + TRACUCOMP( g_trac_i2c, + INFO_MRK"Locked on engine: %d", + args.engine ); + for( int attempt = 0; attempt < I2C_COMMAND_ATTEMPTS; attempt++ ) { if( err ) @@ -222,7 +238,12 @@ errlHndl_t i2cPerformOp( DeviceFW::OperationType i_opType, break; } } - mutex_unlock( &g_i2cMutex ); + + // Unlock + (void) mutex_unlock( engineLock ); + TRACUCOMP( g_trac_i2c, + INFO_MRK"Unlocked engine: %d", + args.engine ); if( err ) { -- cgit v1.2.1