From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by mx.groups.io with SMTP id smtpd.web10.10143.1574163507370033717 for ; Tue, 19 Nov 2019 03:38:27 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=jvoK3mL9; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.221.67, mailfrom: pete@akeo.ie) Received: by mail-wr1-f67.google.com with SMTP id t1so23417444wrv.4 for ; Tue, 19 Nov 2019 03:38:27 -0800 (PST) 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=p9X0Li0JZP3tHv6vt4d0dYfvMxm5M4W0EQjLOLq8qZ0=; b=jvoK3mL9Bk9COMKsD4mN1FjTdaeJV5GUxgvd06+lBK/uen6hWAL34CNWwfH3ke3MGJ xWVgXw1vex7ByJppyknVnutbMycF45TuB3JmuGoA4NmJ4SXdkDZDoFRaayQWqOoz4Tx5 dHMDvPc3482zqO8WlRI8lBhpdnT/0YPsWlqeit/Y3itndL1leoFrkiUO+zT7dvkl+KVb SGKHlx6zTlqTaXDfER24lSNzUt5TMvQtlmuxNDcm8z8dqKTuRdM5+EbUJkZC3kuemwZT EBhrLFHr40tt664CJE5+mvD147/83m41LAd3RPTgmp7BBY2z+NkECW1w+Ul1FRQ7oIAU sOZw== 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=p9X0Li0JZP3tHv6vt4d0dYfvMxm5M4W0EQjLOLq8qZ0=; b=ULiguGtxGwkh8Ds1Qk8c+IMaHL91pDGFJvJkBtw+onnb/1oZ+DkWxFS4v6Fn0BUstj JYeeC8m/dwJrzyJ/i6SGIYJIFrOLAbE8N/kVIDClZS8t26AU0WiMuNlmqtA9Le+cQLUx JYBPBlMg+MdkOQRsNgRjcdZPlSGM7HtVLGOVt695FraOOWwOA6cmOrj8YVqP0CJFCqO4 UhSU1rJM5P+gqrkFur6c2Us1FcVzi2tXAUiO6pb6Y0zVSr0OndVfeUgJwLKLiaVxpSxJ GVbF5/nwgL7i/dAaJViS3KQKX+qzEmfLEKUz2mxFOPw6sya622W8UY1WuMliefyJyh37 /pag== X-Gm-Message-State: APjAAAXYPulXfZuu32BAREsK7KeB8JAdyROd4JeBbZ494L16q+o70lwP KH7dsa+VdQjYHeMYufoeoZVhhvev5YQ= X-Google-Smtp-Source: APXvYqwNVaEbS/6OXyWbYgYgA3TolPn2NnMU+jgnaXsHKODxe2t1j686LC1/6LrzGorid209khHc8w== X-Received: by 2002:adf:f9c4:: with SMTP id w4mr35327967wrr.88.1574163505560; Tue, 19 Nov 2019 03:38:25 -0800 (PST) Return-Path: Received: from localhost.localdomain ([84.203.67.47]) by smtp.gmail.com with ESMTPSA id j66sm2608273wma.19.2019.11.19.03.38.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Nov 2019 03:38:25 -0800 (PST) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, philmd@redhat.com, samer.el-haj-mahmoud@arm.com Subject: [edk2-platforms][PATCH v2 2/7] Platform/RPi: Add model family detection Date: Tue, 19 Nov 2019 11:38:04 +0000 Message-Id: <20191119113809.2472-3-pete@akeo.ie> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20191119113809.2472-1-pete@akeo.ie> References: <20191119113809.2472-1-pete@akeo.ie> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Samer El-Haj-Mahmoud Add GetModelFamily to RASPBERRY_PI_FIRMWARE_PROTOCOL. This uses the board revision to return a numeric value representing the RPi family (1=RPi, 2=RPi2, 3=RPi3 and 4=RPi4). Knowing the Pi family will help us set the SD card routing when we introduce support for the Pi 4 and should also be easier to maintain than if using individual model detection. Signed-off-by: Pete Batard --- Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c | 61 ++++++++++++++++++++ Platform/RaspberryPi/Include/Protocol/RpiFirmware.h | 8 +++ 2 files changed, 69 insertions(+) diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c index dcb434fabefe..dd61ef089ca7 100644 --- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c +++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c @@ -605,6 +605,66 @@ RpiFirmwareGetModelName ( } } +STATIC +EFI_STATUS +EFIAPI +RPiFirmwareGetModelFamily ( + OUT UINT32 *ModelFamily + ) +{ + EFI_STATUS Status; + UINT32 Revision; + UINT32 ModelId; + + Status = RpiFirmwareGetModelRevision(&Revision); + if (EFI_ERROR(Status)) { + DEBUG ((DEBUG_ERROR, + "%a: Could not get the board revision: Status == %r\n", + __FUNCTION__, Status)); + return EFI_DEVICE_ERROR; + } else { + ModelId = (Revision >> 4) & 0xFF; + } + + switch (ModelId) { + // www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md + case 0x00: // Raspberry Pi Model A + case 0x01: // Raspberry Pi Model B + case 0x02: // Raspberry Pi Model A+ + case 0x03: // Raspberry Pi Model B+ + case 0x06: // Raspberry Pi Compute Module 1 + case 0x09: // Raspberry Pi Zero + case 0x0C: // Raspberry Pi Zero W + *ModelFamily = 1; + break; + case 0x04: // Raspberry Pi 2 Model B + *ModelFamily = 2; + break; + case 0x08: // Raspberry Pi 3 Model B + case 0x0A: // Raspberry Pi Compute Module 3 + case 0x0D: // Raspberry Pi 3 Model B+ + case 0x0E: // Raspberry Pi 3 Model A+ + case 0x10: // Raspberry Pi Compute Module 3+ + *ModelFamily = 3; + break; + case 0x11: // Raspberry Pi 4 Model B + *ModelFamily = 4; + break; + default: + *ModelFamily = 0; + break; + } + + if (*ModelFamily == 0) { + DEBUG ((DEBUG_ERROR, + "%a: Unknown Raspberry Pi model family : ModelId == 0x%x\n", + __FUNCTION__, ModelId)); + return EFI_UNSUPPORTED; + } + + return EFI_SUCCESS; +} + STATIC CHAR8* EFIAPI @@ -1171,6 +1231,7 @@ STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL mRpiFirmwareProtocol = { RpiFirmwareGetModel, RpiFirmwareGetModelRevision, RpiFirmwareGetModelName, + RPiFirmwareGetModelFamily, RpiFirmwareGetFirmwareRevision, RpiFirmwareGetManufacturerName, RpiFirmwareGetCpuName, diff --git a/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h b/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h index e49d6e6132d9..e3287e3c040f 100644 --- a/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h +++ b/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h @@ -1,5 +1,6 @@ /** @file * + * Copyright (c) 2019, ARM Limited. All rights reserved. * Copyright (c) 2016, Linaro Limited. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause-Patent @@ -102,6 +103,12 @@ CHAR8* INTN ModelId ); +typedef +EFI_STATUS +(EFIAPI *GET_MODEL_FAMILY) ( + UINT32 *ModelFamily + ); + typedef EFI_STATUS (EFIAPI *GET_FIRMWARE_REVISION) ( @@ -143,6 +150,7 @@ typedef struct { GET_MODEL GetModel; GET_MODEL_REVISION GetModelRevision; GET_MODEL_NAME GetModelName; + GET_MODEL_FAMILY GetModelFamily; GET_FIRMWARE_REVISION GetFirmwareRevision; GET_MANUFACTURER_NAME GetManufacturerName; GET_CPU_NAME GetCpuName; -- 2.21.0.windows.1