From nobody Wed Apr 24 10:20:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+70015+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+70015+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1610086469; cv=none; d=zohomail.com; s=zohoarc; b=XRhMq1kGSpbzn2uqHcoMNiCHd6fN5mLjGvDyoB3xRkg3i6zdO1q18QO4IASaoryxVw+D5TqrBMaTYoRILK450BohqdxAP3FLZqm33nkQUuqiBv+899vEe0WQuBWqNTj3J2LI3tHj4UIZ+YBSPJ/JdK+mIL6ybMDIecIlqnI3lE4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610086469; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=gugctB3teFxO4ODzxS1bBpi7RFTSuNPc13aJtnKDwGE=; b=fl3HMGbKtCQ4GkDVklzwlMI/s/x/gg/pk9ZWnZ9ayPrUPECXXZyHhWMbaiN22J0LoEzkb0eS9t/iMIgfuvuukmdVARP9/JBUJ1h27tkpdZmnhRJWjtzBj0ZNqp5piT0GYExeMcoAd1k09WZn+67jqfdwoioYjhipWKJH+DMQxLw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+70015+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1610086469170563.2677640259146; Thu, 7 Jan 2021 22:14:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id k2ouYY1788612xfkmqQJCGko; Thu, 07 Jan 2021 22:14:26 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.379.1610086461269600807 for ; Thu, 07 Jan 2021 22:14:21 -0800 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DC8B6ED1; Thu, 7 Jan 2021 22:14:20 -0800 (PST) X-Received: from mammon-tx2.austin.arm.com (mammon-tx2.austin.arm.com [10.118.28.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D34903F66E; Thu, 7 Jan 2021 22:14:20 -0800 (PST) From: "Jeremy Linton" To: devel@edk2.groups.io Cc: ard.biesheuvel@arm.com, leif@nuviainc.com, pete@akeo.ie, samer.el-haj-mahmoud@arm.com, awarkentin@vmware.com, Jeremy Linton , Philippe Mathieu-Daude Subject: [edk2-devel] [PATCH v5 2/7] Platform/RaspberryPi: Add further mailbox helpers Date: Fri, 8 Jan 2021 00:14:06 -0600 Message-Id: <20210108061411.1721734-3-jeremy.linton@arm.com> In-Reply-To: <20210108061411.1721734-1-jeremy.linton@arm.com> References: <20210108061411.1721734-1-jeremy.linton@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,jeremy.linton@arm.com X-Gm-Message-State: iUkLzIxyeQrIQx1lTBsL7CJ7x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610086466; bh=/Lt9ksVzXk6Y60aRgLYcmiNXBzodYnarmxG48Y1RA0Y=; h=Cc:Date:From:Reply-To:Subject:To; b=imKsXioFV7HEGyOfLyDUD6AkUljBSnX/mcFMjRcGvPOZxadl4L/tPTSIi0ZYHzirb7D DUqScTt0OHfwjrnFLArxWE6jDFIGSZIflrDcALlG9ERJtzrrSb8OHHLVVtiV5AvCRobnD x6JXqCl54imRyvEaYtjssAjXE5gVfGWn8uE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Lets add some further mailbox helpers and convert the existing RpiFirmwareSetLed into a generic SetGpio() function. Signed-off-by: Jeremy Linton Reviewed-by: Andrei Warkentin Reviewed-by: Philippe Mathieu-Daude --- .../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; } =20 - #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; +} =20 #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; =20 @@ -1242,6 +1306,16 @@ RpiFirmwareSetLed ( __FUNCTION__, Status, Cmd->BufferHead.Response)); } } + +STATIC +VOID +EFIAPI +RpiFirmwareSetLed ( + IN BOOLEAN On + ) +{ + RpiFirmwareSetGpio (RPI_EXP_GPIO_LED, On); +} =20 #pragma pack() typedef struct { @@ -1299,6 +1373,149 @@ RpiFirmwareNotifyXhciReset ( return Status; } =20 +#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", __FUNCTION__)= ); + 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 }; =20 /** 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 =20 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 ); =20 +typedef=20 +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; =20 extern EFI_GUID gRaspberryPiFirmwareProtocolGuid; --=20 2.13.7 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#70015): https://edk2.groups.io/g/devel/message/70015 Mute This Topic: https://groups.io/mt/79518678/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-