From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web12.26119.1629129022636250408 for ; Mon, 16 Aug 2021 08:50:22 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=m6RMfmrk; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from [10.0.0.120] (c-73-27-179-174.hsd1.fl.comcast.net [73.27.179.174]) by linux.microsoft.com (Postfix) with ESMTPSA id 85ADB20C29E6; Mon, 16 Aug 2021 08:50:21 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 85ADB20C29E6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1629129022; bh=n0/rMZEXztsT0aE2zariD7mIJHL8lFNrWcnH7xllIfA=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=m6RMfmrkFD04pEjSA737FoJ3kme0iCptTyc9nQtLwBh3DLxW7qrMSlu//gwRKcdb6 5CuGncc95J/vEpn8pPr9DhgMKAgey9qgXjjMAo+Rciz91xFdfI2bXkQHVBeqYZzBfX 0ko9gytMHMQIsTicxCBZkLe9nApZxa8dqGLDKU1E= Subject: Re: [edk2-devel] [edk2-platforms][PATCH v2 1/5] KabylakeOpenBoardPkg/BaseEcLib: Add some common EC commands To: devel@edk2.groups.io, benjamin.doron00@gmail.com Cc: Chasel Chiu , Nate DeSimone , Michael Kubacki References: <20210804203630.7080-1-benjamin.doron00@gmail.com> <20210814002445.10084-1-benjamin.doron00@gmail.com> <20210814002445.10084-2-benjamin.doron00@gmail.com> From: "Michael Kubacki" Message-ID: <3a0660c0-835f-db26-5f17-c53a43ce0969@linux.microsoft.com> Date: Mon, 16 Aug 2021 11:50:20 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: <20210814002445.10084-2-benjamin.doron00@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Reviewed-by: Michael Kubacki On 8/13/2021 8:24 PM, Benjamin Doron wrote: > Add EC read (0x80) and write (0x81) commands, as defined by ACPI. > > Cc: Chasel Chiu > Cc: Nate DeSimone > Cc: Michael Kubacki > Signed-off-by: Benjamin Doron > --- > Platform/Intel/KabylakeOpenBoardPkg/Include/Library/EcLib.h | 32 +++++++++ > Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/Include/EcCommands.h | 2 + > Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.c | 4 +- > Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.inf | 1 + > Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/EcCommands.c | 76 ++++++++++++++++++++ > 5 files changed, 114 insertions(+), 1 deletion(-) > > diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Include/Library/EcLib.h b/Platform/Intel/KabylakeOpenBoardPkg/Include/Library/EcLib.h > index 04ce076f91b7..7c58e592d965 100644 > --- a/Platform/Intel/KabylakeOpenBoardPkg/Include/Library/EcLib.h > +++ b/Platform/Intel/KabylakeOpenBoardPkg/Include/Library/EcLib.h > @@ -103,4 +103,36 @@ LpcEcInterface ( > IN OUT UINT8 *DataBuffer > > ); > > > > +/** > > + Read a byte of EC RAM. > > + > > + @param[in] Address Address to read > > + @param[out] Data Data received > > + > > + @retval EFI_SUCCESS Command success > > + @retval EFI_DEVICE_ERROR Command error > > + @retval EFI_TIMEOUT Command timeout > > +**/ > > +EFI_STATUS > > +EcRead ( > > + IN UINT8 Address, > > + OUT UINT8 *Data > > + ); > > + > > +/** > > + Write a byte of EC RAM. > > + > > + @param[in] Address Address to write > > + @param[in] Data Data to write > > + > > + @retval EFI_SUCCESS Command success > > + @retval EFI_DEVICE_ERROR Command error > > + @retval EFI_TIMEOUT Command timeout > > +**/ > > +EFI_STATUS > > +EcWrite ( > > + IN UINT8 Address, > > + IN UINT8 Data > > + ); > > + > > #endif > > diff --git a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/Include/EcCommands.h b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/Include/EcCommands.h > index be56d134edc7..a4ab192d8ce1 100644 > --- a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/Include/EcCommands.h > +++ b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/Include/EcCommands.h > @@ -40,5 +40,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > // Data read from the EC data port is valid only when OBF=1. > > // > > #define EC_C_FAB_ID 0x0D // Get the board fab ID in the lower 3 bits > > +#define EC_C_ACPI_READ 0x80 // Read a byte of EC RAM > > +#define EC_C_ACPI_WRITE 0x81 // Write a byte of EC RAM > > > > #endif // EC_COMMANDS_H_ > > diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.c > index eda6f7d2e142..66bd478906fb 100644 > --- a/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.c > +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.c > @@ -32,7 +32,9 @@ typedef struct { > } EC_COMMAND_TABLE; > > > > EC_COMMAND_TABLE mEcCommand[] = { > > - {EC_C_FAB_ID , 0, 2, TRUE} // Get the board fab ID in the lower 3 bits > > + {EC_C_FAB_ID , 0, 2, TRUE}, // Get the board fab ID in the lower 3 bits > > + {EC_C_ACPI_READ , 1, 1, TRUE}, // Read a byte of EC RAM > > + {EC_C_ACPI_WRITE , 2, 0, TRUE} // Write a byte of EC RAM > > }; > > > > // > > diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.inf > index c7de77d80f3d..f0b4c67fffc2 100644 > --- a/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.inf > +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/BaseEcLib.inf > @@ -27,3 +27,4 @@ > > > [Sources] > > BaseEcLib.c > > + EcCommands.c > > diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/EcCommands.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/EcCommands.c > new file mode 100644 > index 000000000000..d14edb75de36 > --- /dev/null > +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/BaseEcLib/EcCommands.c > @@ -0,0 +1,76 @@ > +/** @file > > + Common EC commands. > > + > > +Copyright (c) 2019, Intel Corporation. All rights reserved.
> > +SPDX-License-Identifier: BSD-2-Clause-Patent > > + > > +**/ > > + > > +#include > > +#include > > +#include > > + > > +/** > > + Read a byte of EC RAM. > > + > > + @param[in] Address Address to read > > + @param[out] Data Data received > > + > > + @retval EFI_SUCCESS Command success > > + @retval EFI_DEVICE_ERROR Command error > > + @retval EFI_TIMEOUT Command timeout > > +**/ > > +EFI_STATUS > > +EcRead ( > > + IN UINT8 Address, > > + OUT UINT8 *Data > > + ) > > +{ > > + UINT8 DataSize; > > + UINT8 DataBuffer[1]; > > + EFI_STATUS Status; > > + > > + if (Data == NULL) { > > + return EFI_INVALID_PARAMETER; > > + } > > + > > + // Prepare arguments for LpcEcInterface() > > + DataSize = 1; > > + DataBuffer[0] = Address; > > + > > + Status = LpcEcInterface (EC_C_ACPI_READ, &DataSize, DataBuffer); > > + if (EFI_ERROR(Status)) { > > + return Status; > > + } > > + > > + // Write caller's pointer from returned data and return success > > + *Data = DataBuffer[0]; > > + return EFI_SUCCESS; > > +} > > + > > +/** > > + Write a byte of EC RAM. > > + > > + @param[in] Address Address to write > > + @param[in] Data Data to write > > + > > + @retval EFI_SUCCESS Command success > > + @retval EFI_DEVICE_ERROR Command error > > + @retval EFI_TIMEOUT Command timeout > > +**/ > > +EFI_STATUS > > +EcWrite ( > > + IN UINT8 Address, > > + IN UINT8 Data > > + ) > > +{ > > + UINT8 DataSize; > > + UINT8 DataBuffer[2]; > > + > > + // Prepare arguments for LpcEcInterface() > > + DataSize = 2; > > + DataBuffer[0] = Address; > > + DataBuffer[1] = Data; > > + > > + return LpcEcInterface (EC_C_ACPI_WRITE, &DataSize, DataBuffer); > > +} >