From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com [40.107.102.49]) by mx.groups.io with SMTP id smtpd.web10.1738.1608056290553373094 for ; Tue, 15 Dec 2020 10:18:10 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@vmware.com header.s=selector2 header.b=ObL6qcvZ; spf=pass (domain: vmware.com, ip: 40.107.102.49, mailfrom: awarkentin@vmware.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QlS2NJ7gRfQYPe6pfWlgPFmFTddYnvovYoWw73JfOT8TBGIpo+V2YszbcusJTBJSXT0FSfFyGfUbwLHmrlmp6IN0MNZBMwY20qWacpbxOLiiLDE2QvJLxAG038uYWODT5WzSP40dnGJU7DKfTa0J4z8AhMTR5rB35ic7B8u2jtnWfYcXrXQPx7atoNQwMQ8M9bFGckv13LCCPs/CeoLPY8wT5F+4pTsumBTrT9ZdZ8ycITTwb/5nX+yNFrxAwgfaRzb1pijtoi+SCx48nMQsdKkQ5AI5DPlujT/2JH+zakJsBBQ4P0hqkfM5Cb0oSaWX9jmEVZJNnOtsCNyv7XyI3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FxT28BPpZwJfM0KeT+v14jCTrZkc9M0JeQFJl2dlMhU=; b=FlynQzVlA1P7JX8u2R8vP0HRdkSlKi9g/R+B8vqMklHHLn+I9ss8j4HgWwjmkzN3fsx1xo/mTYfJwKvK6gjJTlwAGc/WjIqw/M+VP8s3aEnDa2AJlb4ir2ahcHY8wbQNvSo54pBvQrxLw/q3/QAmVeDRx6X48pYgicwNZbHrchcJGCiNNOTPRdgrIZtAZf39R4u+Ao6xQoVesLV3r3O360udLkytQrldMC1RnVYtPiVusTCBuAcZIl3oZ3WqXp0re90esPOIByVLePPCH+SASIAHDt8XTb8RWC7xD1DqXwaVxll1s0rAAVfdrlI5X5+wSa8EM6lS0d7e/i6Dj2Dssw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vmware.com; dmarc=pass action=none header.from=vmware.com; dkim=pass header.d=vmware.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmware.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FxT28BPpZwJfM0KeT+v14jCTrZkc9M0JeQFJl2dlMhU=; b=ObL6qcvZO8p5aHHJp1IpzJcTuDumXhv1XKOTbInKh8ypVJ8yK0uimCbIh2B0FXGd4Y4XF3Zw3zRn3LFEnEpPglA0XoPh01h2u+DEEXOa87A64eSCJJniogZ60MsIK5OlMAbGV2ihp7YSfUTbZ9TSPHr9RGA19uo0qk9L1Z4H2MA= Received: from SJ0PR05MB7580.namprd05.prod.outlook.com (2603:10b6:a03:2e0::24) by BYAPR05MB4374.namprd05.prod.outlook.com (2603:10b6:a02:f9::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3676.12; Tue, 15 Dec 2020 18:18:06 +0000 Received: from SJ0PR05MB7580.namprd05.prod.outlook.com ([fe80::ad1c:9900:1bea:47cf]) by SJ0PR05MB7580.namprd05.prod.outlook.com ([fe80::ad1c:9900:1bea:47cf%6]) with mapi id 15.20.3654.025; Tue, 15 Dec 2020 18:18:06 +0000 From: "Andrei Warkentin" To: "devel@edk2.groups.io" , "jeremy.linton@arm.com" CC: "ard.biesheuvel@arm.com" , "leif@nuviainc.com" , "pete@akeo.ie" , "andrey.warkentin@gmail.com" , "samer.el-haj-mahmoud@arm.com" Subject: Re: [edk2-devel] [PATCH 2/7] Platform/RaspberryPi: Add further mailbox helpers Thread-Topic: [edk2-devel] [PATCH 2/7] Platform/RaspberryPi: Add further mailbox helpers Thread-Index: AQHW0nA1rC0acsPfZkqqyRKV0fZe4qn4eFyc Date: Tue, 15 Dec 2020 18:18:06 +0000 Message-ID: References: <20201214232350.1192387-1-jeremy.linton@arm.com>,<20201214232350.1192387-3-jeremy.linton@arm.com> In-Reply-To: <20201214232350.1192387-3-jeremy.linton@arm.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=vmware.com; x-originating-ip: [98.214.99.181] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e3496717-387d-49e2-f318-08d8a125c52b x-ms-traffictypediagnostic: BYAPR05MB4374: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:121; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: kEPxoXPcOJk/2wjh/Nfmw/5z+RUDxpvfWOPDcz9jSM4wZka+45XxU8biO9J301lGIVps1GIjEICATMhpDfnKGMbK8fOm9MF2LCexT6FEQVEkQW3Tx5cDEcMLswog77glfBUqFDX29GUnhWrmQE3E2W+GkObVg1DgzSDxSNaz2xYlH9QbG8twidB+ceUodK4NBQ5SYG2f22TLsDzDhWUhUx/i8TD12v6mEPnRmhK42XvSYVJ/MN7fDNjcF5u/8tkl8JT46QqzJx3knhiw0yHF3DED65GuT3o8C0ArKlu75s9PYZXnc1Mw8KWN78ctzeP3tbC7VxvJvQxgDsujFHpIgEzhfG3r5heBWTDGfJMSqceqb44byehOGcNHLBC8dtzT4etvPGUbZSdRPTzMfnOeySOKA473TDQ9lHoU2B6+4SX4DxMfFOGswPafAswXttBMd48tvaweUO/maxs4ftSKPQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR05MB7580.namprd05.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(376002)(346002)(39860400002)(366004)(396003)(86362001)(26005)(66556008)(4326008)(8676002)(64756008)(30864003)(7696005)(76116006)(54906003)(110136005)(71200400001)(33656002)(66476007)(91956017)(2906002)(316002)(5660300002)(55016002)(166002)(966005)(9686003)(52536014)(15650500001)(66446008)(66946007)(53546011)(6506007)(83380400001)(186003)(19627405001)(478600001)(8936002)(45080400002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?ALKVb2ECssjC4FQXESAVoO19w0RmfXODubGYj4XnPSZF4e9LtG4NY3Cd5W1L?= =?us-ascii?Q?gh8IAemH2t6oUldTNRWxAQkBczQEOckb/UcgWzWTEZmauKydqtrRJ6zY25k+?= =?us-ascii?Q?WV2A6HzGN4R+gAq+QlIGawFO60r3s36LsTpwlyLSFujxDlE6fIczZL5B9IKw?= =?us-ascii?Q?3fA0pWph01MaxSpEV0M8k4+PeepqqT0cNUoPZDTIwW077qiyeuIbD308zpAJ?= =?us-ascii?Q?V6TJhpQhNx3E9oGUQhO2MVIM4BVHMvRnQR64U9O4Qn1ieCk6XXBMS22JufJL?= =?us-ascii?Q?WOpLuwqu5nCCWJcX3MtUzpwX/XYSoa4jX0frZCm5qAC26n5LZF/UBtHM/A3Q?= =?us-ascii?Q?FxnxdkxfBbyV2giSuY/TNxSmbpcg5cRSHYc4ZGqHuyescy0FILmrqzGoH6aD?= =?us-ascii?Q?HWyHudykvzUeOSaA1PvLg9MbFf566lAN6ngHyv2ZRWtp/WT0Pm5gpj0RQgEG?= =?us-ascii?Q?bU7NXQhYySSEiZAJS1qp21nZp3uz9piOIcVn9acBJCB9oHcwIHGIzSqk6XaV?= =?us-ascii?Q?Omhbu0FhmJlfmho2+ctGdnAuEL56X63FQ/Lm4UaJ96MaT0QrNRHQ+wCWXjJ9?= =?us-ascii?Q?TbVvJ73PE19OZSE2FemU6O6zby1kyZkfpIhawO5KNufM5IF5d2fSDH36CaDY?= =?us-ascii?Q?Y76s6YkGWK9w1UJ6/yBUYYGr1u0OOQ1T1rtCbnFxIVXGKAj6MtlYRDUPzxgx?= =?us-ascii?Q?Lb4FtBXpFtSaMzxdmcc4QD8tl7puf2AUC+OfJn6hJQH8O85+C9rmVVfUaB7S?= =?us-ascii?Q?qH4uFyeCtruKjhTUXm6VuYMu6UyXXgdutBbFhty0+SzUUcNkDEjfi9Kqfzuq?= =?us-ascii?Q?Nbtt/lTz4bP68RPM8JIK7INt+o41Q5K9H1ALO1uNhnrJAFT4qS+XWpidV4hj?= =?us-ascii?Q?/gwKpJKKO75EVwTu6Mrd1GiBMRIXRem0DxZR8xfWxcOVnCphlNSzIxY1eX9d?= =?us-ascii?Q?OCPu6EwGVrTOP4V4vCPkUhcyn4NeSjGztwUUM6iyltM=3D?= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SJ0PR05MB7580.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e3496717-387d-49e2-f318-08d8a125c52b X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Dec 2020 18:18:06.5275 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: TsT3/PECRcy9V6mXsivlT4r5FiGZinGsS1uNMTCIsIsZHsvFMrGpO6iAtMEm5jiegPt358VCCj/cZcRPyZMIoQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR05MB4374 Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_SJ0PR05MB7580B5599B9F4927E84EF78AB9C60SJ0PR05MB7580namp_" --_000_SJ0PR05MB7580B5599B9F4927E84EF78AB9C60SJ0PR05MB7580namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable LGTM. Seems reasonable. Reviewed-by: Andrei Warkentin ________________________________ From: devel@edk2.groups.io on behalf of Jeremy Linto= n via groups.io Sent: Monday, December 14, 2020 5:23 PM To: devel@edk2.groups.io Cc: ard.biesheuvel@arm.com ; leif@nuviainc.com ; pete@akeo.ie ; andrey.warkentin@gmail.com ; samer.el-haj-mahmoud@arm.com ; Jeremy Linton Subject: [edk2-devel] [PATCH 2/7] Platform/RaspberryPi: Add further mailbox= helpers Lets add some further mailbox helpers and convert the existing RpiFirmwareSetLed into a generic SetGpio() function. Signed-off-by: Jeremy Linton --- .../Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c | 240 +++++++++++++++++= +++- .../RaspberryPi/Include/Protocol/RpiFirmware.h | 25 +++ 2 files changed, 255 insertions(+), 10 deletions(-) diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c b= /Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c index ade91c9f34..bf74148bbb 100644 --- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c +++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c @@ -1090,7 +1090,6 @@ RpiFirmwareSetClockRate ( return EFI_SUCCESS; } - #pragma pack() typedef struct { UINT32 ClockId; @@ -1152,6 +1151,17 @@ RpiFirmwareGetClockRate ( STATIC EFI_STATUS EFIAPI +RpiFirmwareGetCurrentClockState ( + IN UINT32 ClockId, + OUT UINT32 *ClockState + ) +{ + return RpiFirmwareGetClockRate (ClockId, RPI_MBOX_GET_CLOCK_STATE, Clock= State); +} + +STATIC +EFI_STATUS +EFIAPI RpiFirmwareGetCurrentClockRate ( IN UINT32 ClockId, OUT UINT32 *ClockRate @@ -1181,6 +1191,63 @@ RpiFirmwareGetMinClockRate ( { return RpiFirmwareGetClockRate (ClockId, RPI_MBOX_GET_MIN_CLOCK_RATE, Cl= ockRate); } + +#pragma pack() +typedef struct { + UINT32 ClockId; + UINT32 ClockState; +} RPI_FW_GET_CLOCK_STATE_TAG; + +typedef struct { + RPI_FW_BUFFER_HEAD BufferHead; + RPI_FW_TAG_HEAD TagHead; + RPI_FW_GET_CLOCK_STATE_TAG TagBody; + UINT32 EndTag; +} RPI_FW_SET_CLOCK_STATE_CMD; +#pragma pack() + +STATIC +EFI_STATUS +RpiFirmwareSetClockState ( + IN UINT32 ClockId, + IN UINT32 ClockState + ) +{ + RPI_FW_SET_CLOCK_STATE_CMD *Cmd; + EFI_STATUS Status; + UINT32 Result; + + if (!AcquireSpinLockOrFail (&mMailboxLock)) { + DEBUG ((DEBUG_ERROR, "%a: failed to acquire spinlock\n", __FUNCTION__)= ); + return EFI_DEVICE_ERROR; + } + + Cmd =3D mDmaBuffer; + ZeroMem (Cmd, sizeof (*Cmd)); + + Cmd->BufferHead.BufferSize =3D sizeof (*Cmd); + Cmd->BufferHead.Response =3D 0; + Cmd->TagHead.TagId =3D RPI_MBOX_SET_CLOCK_STATE; + Cmd->TagHead.TagSize =3D sizeof (Cmd->TagBody); + Cmd->TagHead.TagValueSize =3D 0; + Cmd->TagBody.ClockId =3D ClockId; + Cmd->TagBody.ClockState =3D ClockState; + Cmd->EndTag =3D 0; + + Status =3D MailboxTransaction (Cmd->BufferHead.BufferSize, RPI_MBOX_VC_C= HANNEL, &Result); + + ReleaseSpinLock (&mMailboxLock); + + if (EFI_ERROR (Status) || + Cmd->BufferHead.Response !=3D RPI_MBOX_RESP_SUCCESS) { + DEBUG ((DEBUG_ERROR, + "%a: mailbox transaction error: Status =3D=3D %r, Response =3D=3D 0x= %x\n", + __FUNCTION__, Status, Cmd->BufferHead.Response)); + return EFI_DEVICE_ERROR; + } + + return EFI_SUCCESS; +} #pragma pack() typedef struct { @@ -1199,8 +1266,9 @@ typedef struct { STATIC VOID EFIAPI -RpiFirmwareSetLed ( - IN BOOLEAN On +RpiFirmwareSetGpio ( + IN UINT32 Gpio, + IN BOOLEAN State ) { RPI_FW_SET_GPIO_CMD *Cmd; @@ -1220,14 +1288,10 @@ RpiFirmwareSetLed ( Cmd->TagHead.TagId =3D RPI_MBOX_SET_GPIO; Cmd->TagHead.TagSize =3D sizeof (Cmd->TagBody); /* - * GPIO_PIN_2 =3D Activity LED - * GPIO_PIN_4 =3D HDMI Detect (Input / Active Low) - * GPIO_PIN_7 =3D Power LED (Input / Active Low) - * * There's also a 128 pin offset. */ - Cmd->TagBody.Pin =3D 128 + 2; - Cmd->TagBody.State =3D On; + Cmd->TagBody.Pin =3D 128 + Gpio; + Cmd->TagBody.State =3D State; Cmd->TagHead.TagValueSize =3D 0; Cmd->EndTag =3D 0; @@ -1242,6 +1306,16 @@ RpiFirmwareSetLed ( __FUNCTION__, Status, Cmd->BufferHead.Response)); } } + +STATIC +VOID +EFIAPI +RpiFirmwareSetLed ( + IN BOOLEAN On + ) +{ + RpiFirmwareSetGpio (RPI_EXP_GPIO_LED, On); +} #pragma pack() typedef struct { @@ -1299,6 +1373,149 @@ RpiFirmwareNotifyXhciReset ( return Status; } +#pragma pack() +typedef struct { + UINT32 Gpio; + UINT32 Direction; + UINT32 Polarity; + UINT32 TermEn; + UINT32 TermPullUp; +} RPI_FW_GPIO_GET_CFG_TAG; + +typedef struct { + RPI_FW_BUFFER_HEAD BufferHead; + RPI_FW_TAG_HEAD TagHead; + RPI_FW_GPIO_GET_CFG_TAG TagBody; + UINT32 EndTag; +} RPI_FW_NOTIFY_GPIO_GET_CFG_CMD; +#pragma pack() + + +STATIC +EFI_STATUS +EFIAPI +RpiFirmwareNotifyGpioGetCfg ( + IN UINTN Gpio, + IN UINT32 *Polarity + ) +{ + RPI_FW_NOTIFY_GPIO_GET_CFG_CMD *Cmd; + EFI_STATUS Status; + UINT32 Result; + + if (!AcquireSpinLockOrFail (&mMailboxLock)) { + DEBUG ((DEBUG_ERROR, "%a: failed to acquire spinlock\n", __FUNCTION__)= ); + return EFI_DEVICE_ERROR; + } + + Cmd =3D mDmaBuffer; + ZeroMem (Cmd, sizeof (*Cmd)); + + Cmd->BufferHead.BufferSize =3D sizeof (*Cmd); + Cmd->BufferHead.Response =3D 0; + Cmd->TagHead.TagId =3D RPI_MBOX_GET_GPIO_CONFIG; + Cmd->TagHead.TagSize =3D sizeof (Cmd->TagBody); + Cmd->TagBody.Gpio =3D 128 + Gpio; + + Cmd->TagHead.TagValueSize =3D 0; + Cmd->EndTag =3D 0; + + Status =3D MailboxTransaction (Cmd->BufferHead.BufferSize, RPI_MBOX_VC_C= HANNEL, &Result); + + *Polarity =3D Cmd->TagBody.Polarity; + + ReleaseSpinLock (&mMailboxLock); + + if (EFI_ERROR (Status) || + Cmd->BufferHead.Response !=3D RPI_MBOX_RESP_SUCCESS) { + DEBUG ((DEBUG_ERROR, + "%a: mailbox transaction error: Status =3D=3D %r, Response =3D=3D 0= x%x\n", + __FUNCTION__, Status, Cmd->BufferHead.Response)); + } + + return Status; +} + + +#pragma pack() +typedef struct { + UINT32 Gpio; + UINT32 Direction; + UINT32 Polarity; + UINT32 TermEn; + UINT32 TermPullUp; + UINT32 State; +} RPI_FW_GPIO_SET_CFG_TAG; + +typedef struct { + RPI_FW_BUFFER_HEAD BufferHead; + RPI_FW_TAG_HEAD TagHead; + RPI_FW_GPIO_SET_CFG_TAG TagBody; + UINT32 EndTag; +} RPI_FW_NOTIFY_GPIO_SET_CFG_CMD; +#pragma pack() + + +STATIC +EFI_STATUS +EFIAPI +RpiFirmwareNotifyGpioSetCfg ( + IN UINTN Gpio, + IN UINTN Direction, + IN UINTN State + ) +{ + RPI_FW_NOTIFY_GPIO_SET_CFG_CMD *Cmd; + EFI_STATUS Status; + UINT32 Result; + + Status =3D RpiFirmwareNotifyGpioGetCfg (Gpio, &Result); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get GPIO polarity\n", __FUNCT= ION__)); + Result =3D 0; //default polarity + } + + + if (!AcquireSpinLockOrFail (&mMailboxLock)) { + DEBUG ((DEBUG_ERROR, "%a: failed to acquire spinlock\n", __FUNCTION__)= ); + return EFI_DEVICE_ERROR; + } + + Cmd =3D mDmaBuffer; + ZeroMem (Cmd, sizeof (*Cmd)); + + Cmd->BufferHead.BufferSize =3D sizeof (*Cmd); + Cmd->BufferHead.Response =3D 0; + Cmd->TagHead.TagId =3D RPI_MBOX_SET_GPIO_CONFIG; + Cmd->TagHead.TagSize =3D sizeof (Cmd->TagBody); + + Cmd->TagBody.Gpio =3D 128 + Gpio; + Cmd->TagBody.Direction =3D Direction; + Cmd->TagBody.Polarity =3D Result; + Cmd->TagBody.TermEn =3D 0; + Cmd->TagBody.TermPullUp =3D 0; + Cmd->TagBody.State =3D State; + + Cmd->TagHead.TagValueSize =3D 0; + Cmd->EndTag =3D 0; + + Status =3D MailboxTransaction (Cmd->BufferHead.BufferSize, RPI_MBOX_VC_C= HANNEL, &Result); + + ReleaseSpinLock (&mMailboxLock); + + if (EFI_ERROR (Status) || + Cmd->BufferHead.Response !=3D RPI_MBOX_RESP_SUCCESS) { + DEBUG ((DEBUG_ERROR, + "%a: mailbox transaction error: Status =3D=3D %r, Response =3D=3D 0= x%x\n", + __FUNCTION__, Status, Cmd->BufferHead.Response)); + } + + RpiFirmwareSetGpio (Gpio,!State); + + + return Status; +} + STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL mRpiFirmwareProtocol =3D { RpiFirmwareSetPowerState, RpiFirmwareGetMacAddress, @@ -1321,7 +1538,10 @@ STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL mRpiFirmwarePr= otocol =3D { RpiFirmwareGetCpuName, RpiFirmwareGetArmMemory, RPiFirmwareGetModelInstalledMB, - RpiFirmwareNotifyXhciReset + RpiFirmwareNotifyXhciReset, + RpiFirmwareGetCurrentClockState, + RpiFirmwareSetClockState, + RpiFirmwareNotifyGpioSetCfg }; /** diff --git a/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h b/Platform= /RaspberryPi/Include/Protocol/RpiFirmware.h index 56a8d15a38..d841608e57 100644 --- a/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h +++ b/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h @@ -37,6 +37,20 @@ EFI_STATUS typedef EFI_STATUS +(EFIAPI *GET_CLOCK_STATE) ( + IN UINT32 ClockId, + OUT UINT32 *ClockState + ); + +typedef +EFI_STATUS +(EFIAPI *SET_CLOCK_STATE) ( + IN UINT32 ClockId, + IN UINT32 ClockState + ); + +typedef +EFI_STATUS (EFIAPI *GET_CLOCK_RATE) ( IN UINT32 ClockId, OUT UINT32 *ClockRate @@ -149,6 +163,14 @@ EFI_STATUS UINTN FunctionNumber ); +typedef +EFI_STATUS +(EFIAPI *GPIO_SET_CFG) ( + UINTN Gpio, + UINTN Direction, + UINTN State + ); + typedef struct { SET_POWER_STATE SetPowerState; GET_MAC_ADDRESS GetMacAddress; @@ -172,6 +194,9 @@ typedef struct { GET_ARM_MEM GetArmMem; GET_MODEL_INSTALLED_MB GetModelInstalledMB; NOTIFY_XHCI_RESET NotifyXhciReset; + GET_CLOCK_STATE GetClockState; + SET_CLOCK_STATE SetClockState; + GPIO_SET_CFG SetGpioConfig; } RASPBERRY_PI_FIRMWARE_PROTOCOL; extern EFI_GUID gRaspberryPiFirmwareProtocolGuid; -- 2.13.7 -=3D-=3D-=3D-=3D-=3D-=3D Groups.io Links: You receive all messages sent to this group. View/Reply Online (#68814): https://nam04.safelinks.protection.outlook.com/= ?url=3Dhttps%3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Fmessage%2F68814&data= =3D04%7C01%7Cawarkentin%40vmware.com%7Cd008b6c3109a4d90740b08d8a08755fc%7Cb= 39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C637435850424785824%7CUnknown%7CTW= FpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3= D%7C1000&sdata=3DiJY0BHT2JMnlQXHGFAjB1b0LF5yqTAKpxSoHVThwXHI%3D&res= erved=3D0 Mute This Topic: https://nam04.safelinks.protection.outlook.com/?url=3Dhttp= s%3A%2F%2Fgroups.io%2Fmt%2F78964891%2F4387333&data=3D04%7C01%7Cawarkent= in%40vmware.com%7Cd008b6c3109a4d90740b08d8a08755fc%7Cb39138ca3cee4b4aa4d6cd= 83d9dd62f0%7C0%7C0%7C637435850424785824%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4= wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=3D= xC9ynLadafljUyR%2BOqCDFmgIxzCCiXtaJFo%2Brq%2BeGjE%3D&reserved=3D0 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://nam04.safelinks.protection.outlook.com/?url=3Dhttps%3A= %2F%2Fedk2.groups.io%2Fg%2Fdevel%2Funsub&data=3D04%7C01%7Cawarkentin%40= vmware.com%7Cd008b6c3109a4d90740b08d8a08755fc%7Cb39138ca3cee4b4aa4d6cd83d9d= d62f0%7C0%7C0%7C637435850424785824%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw= MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=3DYxVZV= IiiwGR37p34ccfqVIbjrCaS%2FYNF64CBf99ebq0%3D&reserved=3D0 [awarkentin@vm= ware.com] -=3D-=3D-=3D-=3D-=3D-=3D --_000_SJ0PR05MB7580B5599B9F4927E84EF78AB9C60SJ0PR05MB7580namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
LGTM. S= eems reasonable.

Reviewed-by: Andrei Warkentin <= awarkentin@vmware.com>


From: devel@edk2.groups.io = <devel@edk2.groups.io> on behalf of Jeremy Linton via groups.io <j= eremy.linton=3Darm.com@groups.io>
Sent: Monday, December 14, 2020 5:23 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: ard.biesheuvel@arm.com <ard.biesheuvel@arm.com>; leif@nuvi= ainc.com <leif@nuviainc.com>; pete@akeo.ie <pete@akeo.ie>; andr= ey.warkentin@gmail.com <andrey.warkentin@gmail.com>; samer.el-haj-mah= moud@arm.com <samer.el-haj-mahmoud@arm.com>; Jeremy Linton <jeremy.linton@arm.com>
Subject: [edk2-devel] [PATCH 2/7] Platform/RaspberryPi: Add further = mailbox helpers
 
Lets add some further mailbox helpers and convert = the existing
RpiFirmwareSetLed into a generic SetGpio() function.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
---
 .../Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c    &n= bsp;   | 240 ++++++++++++++++++++-
 .../RaspberryPi/Include/Protocol/RpiFirmware.h    = ; |  25 +++
 2 files changed, 255 insertions(+), 10 deletions(-)

diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c b= /Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
index ade91c9f34..bf74148bbb 100644
--- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
+++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
@@ -1090,7 +1090,6 @@ RpiFirmwareSetClockRate (
   return EFI_SUCCESS;

 }

 

-

 #pragma pack()

 typedef struct {

   UINT32         &n= bsp;          ClockId;

@@ -1152,6 +1151,17 @@ RpiFirmwareGetClockRate (
 STATIC

 EFI_STATUS

 EFIAPI

+RpiFirmwareGetCurrentClockState (

+  IN  UINT32    ClockId,

+  OUT UINT32    *ClockState

+  )

+{

+  return RpiFirmwareGetClockRate (ClockId, RPI_MBOX_GET_CLOCK_STATE, = ClockState);

+}

+

+STATIC

+EFI_STATUS

+EFIAPI

 RpiFirmwareGetCurrentClockRate (

   IN  UINT32    ClockId,

   OUT UINT32    *ClockRate

@@ -1181,6 +1191,63 @@ RpiFirmwareGetMinClockRate (
 {

   return RpiFirmwareGetClockRate (ClockId, RPI_MBOX_GET_MIN_CLOC= K_RATE, ClockRate);

 }

+
+#pragma pack()

+typedef struct {

+  UINT32          &= nbsp;         ClockId;

+  UINT32          &= nbsp;         ClockState;

+} RPI_FW_GET_CLOCK_STATE_TAG;

+

+typedef struct {

+  RPI_FW_BUFFER_HEAD         = BufferHead;

+  RPI_FW_TAG_HEAD        &nbs= p;   TagHead;

+  RPI_FW_GET_CLOCK_STATE_TAG TagBody;

+  UINT32          &= nbsp;          EndTag;

+} RPI_FW_SET_CLOCK_STATE_CMD;

+#pragma pack()

+

+STATIC

+EFI_STATUS

+RpiFirmwareSetClockState (

+  IN  UINT32 ClockId,

+  IN  UINT32 ClockState

+  )

+{

+  RPI_FW_SET_CLOCK_STATE_CMD  *Cmd;

+  EFI_STATUS         &nb= sp;        Status;

+  UINT32          &= nbsp;           Result;
+

+  if (!AcquireSpinLockOrFail (&mMailboxLock)) {

+    DEBUG ((DEBUG_ERROR, "%a: failed to acquire spinlo= ck\n", __FUNCTION__));

+    return EFI_DEVICE_ERROR;

+  }

+

+  Cmd =3D mDmaBuffer;

+  ZeroMem (Cmd, sizeof (*Cmd));

+

+  Cmd->BufferHead.BufferSize  =3D sizeof (*Cmd);

+  Cmd->BufferHead.Response    =3D 0;

+  Cmd->TagHead.TagId       &nbs= p;  =3D RPI_MBOX_SET_CLOCK_STATE;

+  Cmd->TagHead.TagSize        = =3D sizeof (Cmd->TagBody);

+  Cmd->TagHead.TagValueSize   =3D 0;

+  Cmd->TagBody.ClockId        = =3D ClockId;

+  Cmd->TagBody.ClockState     =3D ClockState;<= br>
+  Cmd->EndTag         = ;        =3D 0;

+

+  Status =3D MailboxTransaction (Cmd->BufferHead.BufferSize, RPI_M= BOX_VC_CHANNEL, &Result);

+

+  ReleaseSpinLock (&mMailboxLock);

+

+  if (EFI_ERROR (Status) ||

+      Cmd->BufferHead.Response !=3D RPI_MBOX_R= ESP_SUCCESS) {

+    DEBUG ((DEBUG_ERROR,

+      "%a: mailbox transaction error: Status= =3D=3D %r, Response =3D=3D 0x%x\n",

+      __FUNCTION__, Status, Cmd->BufferHead.Re= sponse));

+    return EFI_DEVICE_ERROR;

+  }

+

+  return EFI_SUCCESS;

+}

 

 #pragma pack()

 typedef struct {

@@ -1199,8 +1266,9 @@ typedef struct {
 STATIC

 VOID

 EFIAPI

-RpiFirmwareSetLed (

-  IN  BOOLEAN On

+RpiFirmwareSetGpio (

+  IN  UINT32  Gpio,

+  IN  BOOLEAN State

   )

 {

   RPI_FW_SET_GPIO_CMD *Cmd;

@@ -1220,14 +1288,10 @@ RpiFirmwareSetLed (
   Cmd->TagHead.TagId       = ;   =3D RPI_MBOX_SET_GPIO;

   Cmd->TagHead.TagSize      &nb= sp; =3D sizeof (Cmd->TagBody);

   /*

-   * GPIO_PIN_2 =3D Activity LED

-   * GPIO_PIN_4 =3D HDMI Detect (Input / Active Low)

-   * GPIO_PIN_7 =3D Power LED (Input / Active Low)

-   *

    * There's also a 128 pin offset.

    */

-  Cmd->TagBody.Pin =3D 128 + 2;

-  Cmd->TagBody.State =3D On;

+  Cmd->TagBody.Pin =3D 128 + Gpio;

+  Cmd->TagBody.State =3D State;

   Cmd->TagHead.TagValueSize   =3D 0;

   Cmd->EndTag        =          =3D 0;

 

@@ -1242,6 +1306,16 @@ RpiFirmwareSetLed (
       __FUNCTION__, Status, Cmd->BufferHe= ad.Response));

   }

 }

+
+STATIC

+VOID

+EFIAPI

+RpiFirmwareSetLed (

+  IN  BOOLEAN On

+  )

+{

+  RpiFirmwareSetGpio (RPI_EXP_GPIO_LED, On);

+}

 

 #pragma pack()

 typedef struct {

@@ -1299,6 +1373,149 @@ RpiFirmwareNotifyXhciReset (
   return Status;

 }

 

+#pragma pack()

+typedef struct {

+  UINT32          &= nbsp;            Gpi= o;

+  UINT32          &= nbsp;            Dir= ection;

+  UINT32          &= nbsp;            Pol= arity;

+  UINT32          &= nbsp;            Ter= mEn;

+  UINT32          &= nbsp;            Ter= mPullUp;

+} RPI_FW_GPIO_GET_CFG_TAG;

+

+typedef struct {

+  RPI_FW_BUFFER_HEAD        &= nbsp;  BufferHead;

+  RPI_FW_TAG_HEAD        &nbs= p;     TagHead;

+  RPI_FW_GPIO_GET_CFG_TAG      TagBody;

+  UINT32          &= nbsp;            End= Tag;

+} RPI_FW_NOTIFY_GPIO_GET_CFG_CMD;

+#pragma pack()

+

+

+STATIC

+EFI_STATUS

+EFIAPI

+RpiFirmwareNotifyGpioGetCfg (

+  IN UINTN  Gpio,

+  IN UINT32 *Polarity

+  )

+{

+  RPI_FW_NOTIFY_GPIO_GET_CFG_CMD *Cmd;

+  EFI_STATUS         &nb= sp;         Status;

+  UINT32          &= nbsp;            Res= ult;

+

+  if (!AcquireSpinLockOrFail (&mMailboxLock)) {

+    DEBUG ((DEBUG_ERROR, "%a: failed to acquire spinlo= ck\n", __FUNCTION__));

+    return EFI_DEVICE_ERROR;

+  }

+

+  Cmd =3D mDmaBuffer;

+  ZeroMem (Cmd, sizeof (*Cmd));

+

+  Cmd->BufferHead.BufferSize  =3D sizeof (*Cmd);

+  Cmd->BufferHead.Response    =3D 0;

+  Cmd->TagHead.TagId       &nbs= p;  =3D RPI_MBOX_GET_GPIO_CONFIG;

+  Cmd->TagHead.TagSize        = =3D sizeof (Cmd->TagBody);

+  Cmd->TagBody.Gpio =3D 128 + Gpio;

+

+  Cmd->TagHead.TagValueSize   =3D 0;

+  Cmd->EndTag         = ;        =3D 0;

+

+  Status =3D MailboxTransaction (Cmd->BufferHead.BufferSize, RPI_M= BOX_VC_CHANNEL, &Result);

+

+  *Polarity =3D Cmd->TagBody.Polarity;

+

+  ReleaseSpinLock (&mMailboxLock);

+

+  if (EFI_ERROR (Status) ||

+      Cmd->BufferHead.Response !=3D RPI_MBOX_R= ESP_SUCCESS) {

+    DEBUG ((DEBUG_ERROR,

+      "%a: mailbox  transaction error: = Status =3D=3D %r, Response =3D=3D 0x%x\n",

+      __FUNCTION__, Status, Cmd->BufferHead.Re= sponse));

+  }

+

+  return Status;

+}

+

+

+#pragma pack()

+typedef struct {

+  UINT32          &= nbsp;            Gpi= o;

+  UINT32          &= nbsp;            Dir= ection;

+  UINT32          &= nbsp;            Pol= arity;

+  UINT32          &= nbsp;            Ter= mEn;

+  UINT32          &= nbsp;            Ter= mPullUp;

+  UINT32          &= nbsp;            Sta= te;

+} RPI_FW_GPIO_SET_CFG_TAG;

+

+typedef struct {

+  RPI_FW_BUFFER_HEAD        &= nbsp;  BufferHead;

+  RPI_FW_TAG_HEAD        &nbs= p;     TagHead;

+  RPI_FW_GPIO_SET_CFG_TAG      TagBody;

+  UINT32          &= nbsp;            End= Tag;

+} RPI_FW_NOTIFY_GPIO_SET_CFG_CMD;

+#pragma pack()

+

+

+STATIC

+EFI_STATUS

+EFIAPI

+RpiFirmwareNotifyGpioSetCfg (

+  IN UINTN Gpio,

+  IN UINTN Direction,

+  IN UINTN State

+  )

+{

+  RPI_FW_NOTIFY_GPIO_SET_CFG_CMD *Cmd;

+  EFI_STATUS         &nb= sp;         Status;

+  UINT32          &= nbsp;            Res= ult;

+

+  Status =3D RpiFirmwareNotifyGpioGetCfg (Gpio, &Result);

+  if (EFI_ERROR (Status)) {

+         DEBUG ((DEBUG_ERROR, &quo= t;%a: Failed to get GPIO polarity\n", __FUNCTION__));

+         Result =3D 0; //default p= olarity

+  }

+

+

+  if (!AcquireSpinLockOrFail (&mMailboxLock)) {

+    DEBUG ((DEBUG_ERROR, "%a: failed to acquire spinlo= ck\n", __FUNCTION__));

+    return EFI_DEVICE_ERROR;

+  }

+

+  Cmd =3D mDmaBuffer;

+  ZeroMem (Cmd, sizeof (*Cmd));

+

+  Cmd->BufferHead.BufferSize  =3D sizeof (*Cmd);

+  Cmd->BufferHead.Response    =3D 0;

+  Cmd->TagHead.TagId       &nbs= p;  =3D RPI_MBOX_SET_GPIO_CONFIG;

+  Cmd->TagHead.TagSize        = =3D sizeof (Cmd->TagBody);

+
+  Cmd->TagBody.Gpio =3D 128 + Gpio;

+  Cmd->TagBody.Direction =3D Direction;

+  Cmd->TagBody.Polarity =3D Result;

+  Cmd->TagBody.TermEn =3D 0;

+  Cmd->TagBody.TermPullUp =3D 0;

+  Cmd->TagBody.State =3D State;

+

+  Cmd->TagHead.TagValueSize   =3D 0;

+  Cmd->EndTag         = ;        =3D 0;

+

+  Status =3D MailboxTransaction (Cmd->BufferHead.BufferSize, RPI_M= BOX_VC_CHANNEL, &Result);

+

+  ReleaseSpinLock (&mMailboxLock);

+

+  if (EFI_ERROR (Status) ||

+      Cmd->BufferHead.Response !=3D RPI_MBOX_R= ESP_SUCCESS) {

+    DEBUG ((DEBUG_ERROR,

+      "%a: mailbox  transaction error: = Status =3D=3D %r, Response =3D=3D 0x%x\n",

+      __FUNCTION__, Status, Cmd->BufferHead.Re= sponse));

+  }

+
+  RpiFirmwareSetGpio (Gpio,!State);
+
+

+  return Status;

+}

+

 STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL mRpiFirmwareProtocol =3D {

   RpiFirmwareSetPowerState,

   RpiFirmwareGetMacAddress,

@@ -1321,7 +1538,10 @@ STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL mRpiFirmwarePr= otocol =3D {
   RpiFirmwareGetCpuName,

   RpiFirmwareGetArmMemory,

   RPiFirmwareGetModelInstalledMB,

-  RpiFirmwareNotifyXhciReset

+  RpiFirmwareNotifyXhciReset,

+  RpiFirmwareGetCurrentClockState,

+  RpiFirmwareSetClockState,
+  RpiFirmwareNotifyGpioSetCfg

 };

 

 /**

diff --git a/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h b/Platform= /RaspberryPi/Include/Protocol/RpiFirmware.h
index 56a8d15a38..d841608e57 100644
--- a/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h
+++ b/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h
@@ -37,6 +37,20 @@ EFI_STATUS
 

 typedef

 EFI_STATUS

+(EFIAPI *GET_CLOCK_STATE) (

+  IN  UINT32    ClockId,

+  OUT UINT32    *ClockState

+  );

+

+typedef

+EFI_STATUS

+(EFIAPI *SET_CLOCK_STATE) (

+  IN  UINT32 ClockId,

+  IN  UINT32 ClockState

+  );

+

+typedef

+EFI_STATUS

 (EFIAPI *GET_CLOCK_RATE) (

   IN  UINT32    ClockId,

   OUT UINT32    *ClockRate

@@ -149,6 +163,14 @@ EFI_STATUS
   UINTN FunctionNumber

   );

 

+typedef

+EFI_STATUS

+(EFIAPI *GPIO_SET_CFG) (

+  UINTN Gpio,

+  UINTN Direction,

+  UINTN State

+  );

+

 typedef struct {

   SET_POWER_STATE        SetP= owerState;

   GET_MAC_ADDRESS        GetM= acAddress;

@@ -172,6 +194,9 @@ typedef struct {
   GET_ARM_MEM        &nb= sp;   GetArmMem;

   GET_MODEL_INSTALLED_MB GetModelInstalledMB;

   NOTIFY_XHCI_RESET      NotifyXhciRese= t;

+  GET_CLOCK_STATE        GetClockS= tate;

+  SET_CLOCK_STATE        SetClockS= tate;

+  GPIO_SET_CFG         &= nbsp; SetGpioConfig;

 } RASPBERRY_PI_FIRMWARE_PROTOCOL;

 

 extern EFI_GUID gRaspberryPiFirmwareProtocolGuid;

--
2.13.7



-=3D-=3D-=3D-=3D-=3D-=3D
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#68814): https://nam04.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fedk2.gr= oups.io%2Fg%2Fdevel%2Fmessage%2F68814&amp;data=3D04%7C01%7Cawarkentin%4= 0vmware.com%7Cd008b6c3109a4d90740b08d8a08755fc%7Cb39138ca3cee4b4aa4d6cd83d9= dd62f0%7C0%7C0%7C637435850424785824%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjA= wMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=3D= iJY0BHT2JMnlQXHGFAjB1b0LF5yqTAKpxSoHVThwXHI%3D&amp;reserved=3D0
Mute This Topic: https://nam04.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fgroups.= io%2Fmt%2F78964891%2F4387333&amp;data=3D04%7C01%7Cawarkentin%40vmware.c= om%7Cd008b6c3109a4d90740b08d8a08755fc%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C= 0%7C0%7C637435850424785824%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQ= IjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=3DxC9ynLada= fljUyR%2BOqCDFmgIxzCCiXtaJFo%2Brq%2BeGjE%3D&amp;reserved=3D0
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://nam04.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fedk2.gr= oups.io%2Fg%2Fdevel%2Funsub&amp;data=3D04%7C01%7Cawarkentin%40vmware.co= m%7Cd008b6c3109a4d90740b08d8a08755fc%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0= %7C0%7C637435850424785824%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQI= joiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=3DYxVZVIiiwG= R37p34ccfqVIbjrCaS%2FYNF64CBf99ebq0%3D&amp;reserved=3D0 [awarkentin@vmware.com]
-=3D-=3D-=3D-=3D-=3D-=3D


--_000_SJ0PR05MB7580B5599B9F4927E84EF78AB9C60SJ0PR05MB7580namp_--