]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseSmbusLib/SmbusLib.c
1. UINTN & INTN issue for EBC architecture:
[mirror_edk2.git] / MdePkg / Library / BaseSmbusLib / SmbusLib.c
index 29c09e730e7728b210040a56cdfb0f94b93b7433..39fa7e6f375907e5c6e913b48fe41568b968c46a 100644 (file)
@@ -18,9 +18,9 @@
 \r
 #define SMBUS_LIB_SLAVE_ADDRESS(SmBusAddress)      (((SmBusAddress) >> 1)  & 0x7f)\r
 #define SMBUS_LIB_COMMAND(SmBusAddress)            (((SmBusAddress) >> 8)  & 0xff)\r
-#define SMBUS_LIB_LENGTH(SmBusAddress)             (((SmBusAddress) >> 16) & 0x1f)\r
+#define SMBUS_LIB_LENGTH(SmBusAddress)             (((SmBusAddress) >> 16) & 0x3f)\r
 #define SMBUS_LIB_PEC(SmBusAddress)     ((BOOLEAN) (((SmBusAddress) & SMBUS_LIB_PEC_BIT) != 0))\r
-#define SMBUS_LIB_RESEARVED(SmBusAddress)          ((SmBusAddress) & ~(((1 << 21) - 2) | SMBUS_LIB_PEC_BIT))\r
+#define SMBUS_LIB_RESEARVED(SmBusAddress)          ((SmBusAddress) & ~(((1 << 22) - 2) | SMBUS_LIB_PEC_BIT))\r
 \r
 //\r
 // Replaced by PCD\r
@@ -639,14 +639,14 @@ SmBusProcessCall (
   Bytes are read from the SMBUS and stored in Buffer.\r
   The number of bytes read is returned, and will never return a value larger than 32-bytes.\r
   If Status is not NULL, then the status of the executed command is returned in Status.\r
-  It is the caller¡¯s responsibility to make sure Buffer is large enough for the total number of bytes read.\r
+  It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.\r
   SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
 \r
   @param  HostControl     The value of Host Control Register to set.  \r
   @param  SmBusAddress    Address that encodes the SMBUS Slave Address,\r
                           SMBUS Command, SMBUS Data Length, and PEC.\r
-  @param  OutBuffer       Pointer to the buffer of bytes to write to the SMBUS.\r
-  @param  InBuffer        Pointer to the buffer of bytes to read from the SMBUS.\r
+  @param  WriteBuffer     Pointer to the buffer of bytes to write to the SMBUS.\r
+  @param  ReadBuffer      Pointer to the buffer of bytes to read from the SMBUS.\r
   @param  Status          Return status for the executed command.\r
                           This is an optional parameter and may be NULL.\r
 \r
@@ -657,8 +657,8 @@ UINTN
 InternalSmBusBlock (\r
   IN  UINT8                     HostControl,\r
   IN  UINTN                     SmBusAddress,\r
-  IN  UINT8                     *OutBuffer,\r
-  OUT UINT8                     *InBuffer,\r
+  IN  UINT8                     *WriteBuffer,\r
+  OUT UINT8                     *ReadBuffer,\r
   OUT RETURN_STATUS             *Status\r
   )\r
 {\r
@@ -667,7 +667,7 @@ InternalSmBusBlock (
   UINTN                         BytesCount;\r
   UINT8                         AuxiliaryControl;\r
 \r
-  BytesCount = SMBUS_LIB_LENGTH (SmBusAddress) + 1;\r
+  BytesCount = SMBUS_LIB_LENGTH (SmBusAddress);\r
 \r
   ReturnStatus = InternalSmBusAcquire ();\r
   if (RETURN_ERROR (ReturnStatus)) {\r
@@ -684,9 +684,9 @@ InternalSmBusBlock (
 \r
   InternalSmBusIoWrite8 (SMBUS_R_HST_D0, (UINT8) BytesCount);\r
 \r
-  if (OutBuffer != NULL) {\r
+  if (WriteBuffer != NULL) {\r
     for (Index = 0; Index < BytesCount; Index++) {\r
-      InternalSmBusIoWrite8 (SMBUS_R_HOST_BLOCK_DB, OutBuffer[Index]);\r
+      InternalSmBusIoWrite8 (SMBUS_R_HOST_BLOCK_DB, WriteBuffer[Index]);\r
     }\r
   }\r
   //\r
@@ -711,9 +711,9 @@ InternalSmBusBlock (
   }\r
 \r
   BytesCount = InternalSmBusIoRead8 (SMBUS_R_HST_D0);\r
-  if (InBuffer != NULL) {\r
+  if (ReadBuffer != NULL) {\r
     for (Index = 0; Index < BytesCount; Index++) {\r
-      InBuffer[Index] = InternalSmBusIoRead8 (SMBUS_R_HOST_BLOCK_DB);\r
+      ReadBuffer[Index] = InternalSmBusIoRead8 (SMBUS_R_HOST_BLOCK_DB);\r
     }\r
   }\r
 \r
@@ -738,7 +738,7 @@ Done:
   Bytes are read from the SMBUS and stored in Buffer.\r
   The number of bytes read is returned, and will never return a value larger than 32-bytes.\r
   If Status is not NULL, then the status of the executed command is returned in Status.\r
-  It is the caller¡¯s responsibility to make sure Buffer is large enough for the total number of bytes read.\r
+  It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read.\r
   SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
   If Length in SmBusAddress is not zero, then ASSERT().\r
   If Buffer is NULL, then ASSERT().\r
@@ -804,6 +804,8 @@ SmBusWriteBlock (
   )\r
 {\r
   ASSERT (Buffer != NULL);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32);\r
   ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
 \r
   return InternalSmBusBlock (\r
@@ -820,18 +822,19 @@ SmBusWriteBlock (
 \r
   Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress.\r
   The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required.\r
-  Bytes are written to the SMBUS from OutBuffer.  Bytes are then read from the SMBUS into InBuffer.\r
+  Bytes are written to the SMBUS from WriteBuffer.  Bytes are then read from the SMBUS into ReadBuffer.\r
   If Status is not NULL, then the status of the executed command is returned in Status.\r
-  It is the caller¡¯s responsibility to make sure InBuffer is large enough for the total number of bytes read.\r
+  It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read.\r
   SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes.\r
-  If OutBuffer is NULL, then ASSERT().\r
-  If InBuffer is NULL, then ASSERT().\r
+  If Length in SmBusAddress is zero or greater than 32, then ASSERT().\r
+  If WriteBuffer is NULL, then ASSERT().\r
+  If ReadBuffer is NULL, then ASSERT().\r
   If any reserved bits of SmBusAddress are set, then ASSERT().\r
 \r
   @param  SmBusAddress    Address that encodes the SMBUS Slave Address,\r
                           SMBUS Command, SMBUS Data Length, and PEC.\r
-  @param  OutBuffer       Pointer to the buffer of bytes to write to the SMBUS.\r
-  @param  InBuffer        Pointer to the buffer of bytes to read from the SMBUS.\r
+  @param  WriteBuffer     Pointer to the buffer of bytes to write to the SMBUS.\r
+  @param  ReadBuffer      Pointer to the buffer of bytes to read from the SMBUS.\r
   @param  Status          Return status for the executed command.\r
                           This is an optional parameter and may be NULL.\r
 \r
@@ -842,20 +845,22 @@ UINTN
 EFIAPI\r
 SmBusBlockProcessCall (\r
   IN  UINTN          SmBusAddress,\r
-  IN  VOID           *OutBuffer,\r
-  OUT VOID           *InBuffer,\r
+  IN  VOID           *WriteBuffer,\r
+  OUT VOID           *ReadBuffer,\r
   OUT RETURN_STATUS  *Status        OPTIONAL\r
   )\r
 {\r
-  ASSERT (InBuffer  != NULL);\r
-  ASSERT (OutBuffer != NULL);\r
+  ASSERT (WriteBuffer != NULL);\r
+  ASSERT (ReadBuffer  != NULL);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1);\r
+  ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32);\r
   ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0);\r
 \r
   return InternalSmBusBlock (\r
            SMBUS_V_SMB_CMD_BLOCK_PROCESS,\r
            SmBusAddress | SMBUS_B_WRITE,\r
-           OutBuffer,\r
-           InBuffer,\r
+           WriteBuffer,\r
+           ReadBuffer,\r
            Status\r
            );\r
 }\r