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.web10.78285.1629418523817357090 for ; Thu, 19 Aug 2021 17:15:24 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=WciKbZBs; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from [10.0.0.19] (c-73-27-179-174.hsd1.fl.comcast.net [73.27.179.174]) by linux.microsoft.com (Postfix) with ESMTPSA id AA1EA20C33B3; Thu, 19 Aug 2021 17:15:22 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AA1EA20C33B3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1629418523; bh=DsEI9Z0M3nh+HK09NMugTEyrm05dRQxejdAgR569SpM=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=WciKbZBsewpYN6tXWVzWGooBz2SK2492TZMFIydga8wszuil1JmWVL0rT/2oyNJth LrCOYfOnhYFXuHpyKM+fvQmP4WMEPGTwFdq+BU5g+R1u1+BaIYR5fAk6h9aoT6ei3/ U4lcI/5cwu7RIyvZAtg6r+kXNCtPEevEotMwzazU= Subject: Re: [edk2-devel] [edk2-platforms][PATCH v3 1/7] KabylakeOpenBoardPkg/BaseEcLib: Add some common EC commands To: devel@edk2.groups.io, benjamin.doron00@gmail.com Cc: Chasel Chiu , Nate DeSimone , Isaac Oram , Michael Kubacki References: <20210818184903.7445-1-benjamin.doron00@gmail.com> <20210818184903.7445-2-benjamin.doron00@gmail.com> From: "Michael Kubacki" Message-ID: <03f372da-8ff1-4c38-b425-b0622de87c8e@linux.microsoft.com> Date: Thu, 19 Aug 2021 20:15:22 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210818184903.7445-2-benjamin.doron00@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit EcRead() should have EFI_INVALID_PARAMETER listed as a return value. I don't think you need to generate a new series for that but I will defer to Nate. Reviewed-by: Michael Kubacki On 8/18/2021 2:48 PM, Benjamin Doron wrote: > Add EC read (0x80) and write (0x81) commands, as defined by ACPI. > > Cc: Chasel Chiu > Cc: Nate DeSimone > Cc: Isaac Oram > 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); > > +} >