From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=iSazM9J2; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.221.68, mailfrom: pete@akeo.ie) Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by groups.io with SMTP; Tue, 08 Oct 2019 05:38:56 -0700 Received: by mail-wr1-f68.google.com with SMTP id z9so19180559wrl.11 for ; Tue, 08 Oct 2019 05:38:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3iJjPxO6CdF2B1tjnfOAIywhvvrbpyWWIxeYEuXLbCE=; b=iSazM9J2RCmRhToWZn5989Xnx9f/2LOLiuz6q4UYIQV8ADg8KkTmGZzQdQlMiVJt5u kWHI9O9b4IsuQxzcFbSvfV7IPUnb24bptk/YsFxueGdsB97nbc3ouM9lA10pT/oS8Rds BEUBITT6Gnq5QxHx6xtSnw3f67kG3cPh0+RdmY9C8ONPkcHnRFTHpjBR7nya0etziJoO Q9kFpER6nkwzjTNaXS9ER842iUO4g8uHVK0ACNoF/EUzBxU3Kr8l6MYqQdIH+2qyq7CG 4OTxTYoyYfyFVELqPogq0I/py8fw5sHP+yyaONH/k6zKCR7uEhHf3raEmoxZtTq3cf1k fY6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3iJjPxO6CdF2B1tjnfOAIywhvvrbpyWWIxeYEuXLbCE=; b=DuZXXNN0vrQ12X+TwF7M5vVX71YhzLUEFQs4zZ3KFCx9t+qoJR8odnCwaROsMKbhgV EkrJIfr64S2nqLtwbadbjuNPDoJ1Tx+mzAuU9W8wUkO75A/je7DzsRyjM4ngQZO1gWTF KkelayIaqKcjnyck13dZcCtRAFyYNVjIqJ7NVQJ25dX2nXCO9yUrSycyrlG8H9VwQCbK qq2yKnxSaqJLDv43UIiFn6APnW8iP8WO/RJKBXyRM8ruVH4GWTKouUOItExuokffZgL6 plnDPxyhG7nc7qs3HJ9RAmsNJ4DynNcoZnvhNMIT0ZGBflwcK2m++e0ieViYfo8hrCp4 eaKg== X-Gm-Message-State: APjAAAVIdFX7V0M7hyfv3zBnpZxra982KiSlswDw9tQFrzuvKNFfM6y5 FGi/Mf+77uZEm89ru5/P5l+RvFsUW2s= X-Google-Smtp-Source: APXvYqwNLLDRWSV1/SQ6o+XKrWPJ9t7ABHrZSXsz5g3uXv/9x6nE6Z9VFTULffPiTsZLzYOFL45l6w== X-Received: by 2002:a5d:6284:: with SMTP id k4mr27136180wru.205.1570538334618; Tue, 08 Oct 2019 05:38:54 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([84.203.40.122]) by smtp.gmail.com with ESMTPSA id r6sm3203087wmh.38.2019.10.08.05.38.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Oct 2019 05:38:54 -0700 (PDT) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org Subject: [edk2-platforms][PATCH v2 1/5] Platform/RPi3/RpiFirmwareDxe: Add more query functions Date: Tue, 8 Oct 2019 13:38:37 +0100 Message-Id: <20191008123841.12952-2-pete@akeo.ie> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20191008123841.12952-1-pete@akeo.ie> References: <20191008123841.12952-1-pete@akeo.ie> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch introduces the capability to also query the Model Name/ Manufacturer Name/CPU Name/Firmware Revision using the RpiFirmware protocol. This is aims at making the driver more suitable to cater for platforms other than the Raspberry Pi 3 as well as simplifying the population of entries in PlatformSmbiosDxe. Signed-off-by: Pete Batard --- Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c | 155 +++++++++++++++++++- Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h | 58 ++++++-- 2 files changed, 196 insertions(+), 17 deletions(-) diff --git a/Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c b/Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c index 9b5ee1946279..378c99bcba05 100644 --- a/Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c +++ b/Platform/RaspberryPi/RPi3/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c @@ -461,7 +461,7 @@ typedef struct { RPI_FW_TAG_HEAD TagHead; RPI_FW_MODEL_REVISION_TAG TagBody; UINT32 EndTag; -} RPI_FW_GET_MODEL_REVISION_CMD; +} RPI_FW_GET_REVISION_CMD; #pragma pack() STATIC @@ -471,7 +471,7 @@ RpiFirmwareGetModelRevision ( OUT UINT32 *Revision ) { - RPI_FW_GET_MODEL_REVISION_CMD *Cmd; + RPI_FW_GET_REVISION_CMD *Cmd; EFI_STATUS Status; UINT32 Result; @@ -506,6 +506,153 @@ RpiFirmwareGetModelRevision ( return EFI_SUCCESS; } +STATIC +EFI_STATUS +EFIAPI +RpiFirmwareGetFirmwareRevision ( + OUT UINT32 *Revision + ) +{ + RPI_FW_GET_REVISION_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 = mDmaBuffer; + ZeroMem (Cmd, sizeof (*Cmd)); + + Cmd->BufferHead.BufferSize = sizeof (*Cmd); + Cmd->BufferHead.Response = 0; + Cmd->TagHead.TagId = RPI_MBOX_GET_REVISION; + Cmd->TagHead.TagSize = sizeof (Cmd->TagBody); + Cmd->TagHead.TagValueSize = 0; + Cmd->EndTag = 0; + + Status = MailboxTransaction (Cmd->BufferHead.BufferSize, RPI_MBOX_VC_CHANNEL, &Result); + + ReleaseSpinLock (&mMailboxLock); + + if (EFI_ERROR (Status) || + Cmd->BufferHead.Response != RPI_MBOX_RESP_SUCCESS) { + DEBUG ((DEBUG_ERROR, + "%a: mailbox transaction error: Status == %r, Response == 0x%x\n", + __FUNCTION__, Status, Cmd->BufferHead.Response)); + return EFI_DEVICE_ERROR; + } + + *Revision = Cmd->TagBody.Revision; + return EFI_SUCCESS; +} + +STATIC +CHAR8* +EFIAPI +RpiFirmwareGetModelName ( + IN INTN ModelId + ) +{ + UINT32 Revision; + + // If a negative ModelId is passed, detect it. + if ((ModelId < 0) && (RpiFirmwareGetModelRevision (&Revision) == EFI_SUCCESS)) + ModelId = (Revision >> 4) & 0xFF; + + switch (ModelId) { + // www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md + case 0x00: + return "Raspberry Pi Model A"; + case 0x01: + return "Raspberry Pi Model B"; + case 0x02: + return "Raspberry Pi Model A+"; + case 0x03: + return "Raspberry Pi Model B+"; + case 0x04: + return "Raspberry Pi 2 Model B"; + case 0x06: + return "Raspberry Pi Compute Module 1"; + case 0x08: + return "Raspberry Pi 3 Model B"; + case 0x09: + return "Raspberry Pi Zero"; + case 0x0A: + return "Raspberry Pi Compute Module 3"; + case 0x0C: + return "Raspberry Pi Zero W"; + case 0x0D: + return "Raspberry Pi 3 Model B+"; + case 0x0E: + return "Raspberry Pi 3 Model A+"; + case 0x11: + return "Raspberry Pi 4 Model B"; + default: + return "Unknown Raspberry Pi Model"; + } +} + +STATIC +CHAR8* +EFIAPI +RpiFirmwareGetManufacturerName ( + IN INTN ManufacturerId + ) +{ + UINT32 Revision; + + // If a negative ModelId is passed, detect it. + if ((ManufacturerId < 0) && (RpiFirmwareGetModelRevision (&Revision) == EFI_SUCCESS)) + ManufacturerId = (Revision >> 16) & 0x0F; + + switch (ManufacturerId) { + // www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md + case 0x00: + return "Sony UK"; + case 0x01: + return "Egoman"; + case 0x02: + case 0x04: + return "Embest"; + case 0x03: + return "Sony Japan"; + case 0x05: + return "Stadium"; + default: + return "Unknown Manufacturer"; + } +} + +STATIC +CHAR8* +EFIAPI +RpiFirmwareGetCpuName ( + IN INTN CpuId + ) +{ + UINT32 Revision; + + // If a negative CpuId is passed, detect it. + if ((CpuId < 0) && (RpiFirmwareGetModelRevision (&Revision) == EFI_SUCCESS)) + CpuId = (Revision >> 12) & 0x0F; + + switch (CpuId) { + // www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md + case 0x00: + return "BCM2835 (ARM11)"; + case 0x01: + return "BCM2836 (ARM Cortex-A7)"; + case 0x02: + return "BCM2837 (ARM Cortex-A53)"; + case 0x03: + return "BCM2711 (ARM Cortex-A72)"; + default: + return "Unknown CPU Model"; + } +} + #pragma pack() typedef struct { UINT32 Width; @@ -1009,6 +1156,10 @@ STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL mRpiFirmwareProtocol = { RpiFirmwareGetSerial, RpiFirmwareGetModel, RpiFirmwareGetModelRevision, + RpiFirmwareGetModelName, + RpiFirmwareGetFirmwareRevision, + RpiFirmwareGetManufacturerName, + RpiFirmwareGetCpuName, RpiFirmwareGetArmMemory }; diff --git a/Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h b/Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h index ec70f28efe1a..e49d6e6132d9 100644 --- a/Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h +++ b/Platform/RaspberryPi/RPi3/Include/Protocol/RpiFirmware.h @@ -96,6 +96,30 @@ EFI_STATUS UINT32 *Revision ); +typedef +CHAR8* +(EFIAPI *GET_MODEL_NAME) ( + INTN ModelId + ); + +typedef +EFI_STATUS +(EFIAPI *GET_FIRMWARE_REVISION) ( + UINT32 *Revision + ); + +typedef +CHAR8* +(EFIAPI *GET_MANUFACTURER_NAME) ( + INTN ManufacturerId + ); + +typedef +CHAR8* +(EFIAPI *GET_CPU_NAME) ( + INTN CpuId + ); + typedef EFI_STATUS (EFIAPI *GET_ARM_MEM) ( @@ -104,21 +128,25 @@ EFI_STATUS ); typedef struct { - SET_POWER_STATE SetPowerState; - GET_MAC_ADDRESS GetMacAddress; - GET_COMMAND_LINE GetCommandLine; - GET_CLOCK_RATE GetClockRate; - GET_CLOCK_RATE GetMaxClockRate; - GET_CLOCK_RATE GetMinClockRate; - SET_CLOCK_RATE SetClockRate; - GET_FB GetFB; - FREE_FB FreeFB; - GET_FB_SIZE GetFBSize; - SET_LED SetLed; - GET_SERIAL GetSerial; - GET_MODEL GetModel; - GET_MODEL_REVISION GetModelRevision; - GET_ARM_MEM GetArmMem; + SET_POWER_STATE SetPowerState; + GET_MAC_ADDRESS GetMacAddress; + GET_COMMAND_LINE GetCommandLine; + GET_CLOCK_RATE GetClockRate; + GET_CLOCK_RATE GetMaxClockRate; + GET_CLOCK_RATE GetMinClockRate; + SET_CLOCK_RATE SetClockRate; + GET_FB GetFB; + FREE_FB FreeFB; + GET_FB_SIZE GetFBSize; + SET_LED SetLed; + GET_SERIAL GetSerial; + GET_MODEL GetModel; + GET_MODEL_REVISION GetModelRevision; + GET_MODEL_NAME GetModelName; + GET_FIRMWARE_REVISION GetFirmwareRevision; + GET_MANUFACTURER_NAME GetManufacturerName; + GET_CPU_NAME GetCpuName; + GET_ARM_MEM GetArmMem; } RASPBERRY_PI_FIRMWARE_PROTOCOL; extern EFI_GUID gRaspberryPiFirmwareProtocolGuid; -- 2.21.0.windows.1