-/**\r
- Checks the parameter of SmbusExecute().\r
-\r
- This function checks the input parameters of SmbusExecute(). If the input parameters are valid\r
- for certain SMBus bus protocol, it will return EFI_SUCCESS; otherwise, it will return certain\r
- error code based on the input SMBus bus protocol.\r
-\r
- @param SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length, \r
- and PEC.\r
- @param Operation Signifies which particular SMBus hardware protocol instance that\r
- it will use to execute the SMBus transactions. This SMBus\r
- hardware protocol is defined by the SMBus Specification and is\r
- not related to EFI.\r
- @param Length Signifies the number of bytes that this operation will do. The\r
- maximum number of bytes can be revision specific and operation\r
- specific. This field will contain the actual number of bytes that\r
- are executed for this operation. Not all operations require this\r
- argument.\r
- @param Buffer Contains the value of data to execute to the SMBus slave device.\r
- Not all operations require this argument. The length of this\r
- buffer is identified by Length.\r
-\r
- @retval EFI_SUCCESS All the parameters are valid for the corresponding SMBus bus\r
- protocol. \r
- @retval EFI_INVALID_PARAMETER Operation is not defined in EFI_SMBUS_OPERATION.\r
- @retval EFI_INVALID_PARAMETER Length/Buffer is NULL for operations except for EfiSmbusQuickRead\r
- and EfiSmbusQuickWrite. Length is outside the range of valid\r
- values.\r
- @retval EFI_UNSUPPORTED The SMBus operation or PEC is not supported.\r
- @retval EFI_BUFFER_TOO_SMALL Buffer is not sufficient for this operation.\r
-\r
-**/\r
-EFI_STATUS\r
-CheckParameters (\r
- IN UINTN SmBusAddress,\r
- IN EFI_SMBUS_OPERATION Operation,\r
- IN OUT UINTN *Length,\r
- IN OUT VOID *Buffer\r
- )\r
-{\r
- EFI_STATUS Status;\r
- UINTN RequiredLen;\r
- EFI_SMBUS_DEVICE_COMMAND Command;\r
- BOOLEAN PecCheck;\r
- \r
- Command = SMBUS_LIB_COMMAND (SmBusAddress);\r
- PecCheck = SMBUS_LIB_PEC (SmBusAddress);\r
- //\r
- // Set default value to be 2:\r
- // for SmbusReadWord, SmbusWriteWord and SmbusProcessCall. \r
- //\r
- RequiredLen = 2;\r
- Status = EFI_SUCCESS;\r
- switch (Operation) {\r
- case EfiSmbusQuickRead:\r
- case EfiSmbusQuickWrite:\r
- if (PecCheck || Command != 0) {\r
- return EFI_UNSUPPORTED;\r
- }\r
- break;\r
- case EfiSmbusReceiveByte:\r
- case EfiSmbusSendByte:\r
- if (Command != 0) {\r
- return EFI_UNSUPPORTED;\r
- }\r
- //\r
- // Cascade to check length parameter.\r
- //\r
- case EfiSmbusReadByte:\r
- case EfiSmbusWriteByte:\r
- RequiredLen = 1;\r
- //\r
- // Cascade to check length parameter.\r
- //\r
- case EfiSmbusReadWord:\r
- case EfiSmbusWriteWord:\r
- case EfiSmbusProcessCall:\r
- if (Buffer == NULL || Length == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- } else if (*Length < RequiredLen) {\r
- Status = EFI_BUFFER_TOO_SMALL;\r
- }\r
- *Length = RequiredLen;\r
- break;\r
- case EfiSmbusReadBlock:\r
- case EfiSmbusWriteBlock:\r
- if ((Buffer == NULL) || \r
- (Length == NULL) || \r
- (*Length < MIN_SMBUS_BLOCK_LEN) ||\r
- (*Length > MAX_SMBUS_BLOCK_LEN)) {\r
- return EFI_INVALID_PARAMETER;\r
- } \r
- break;\r
- case EfiSmbusBWBRProcessCall:\r
- return EFI_UNSUPPORTED;\r
- default:\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- return Status;\r
-}\r
-\r