From patchwork Sat Nov 17 00:45:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 151392 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1075517ljp; Fri, 16 Nov 2018 16:45:34 -0800 (PST) X-Google-Smtp-Source: AJdET5cXpePXQeJyLrESubYQYh510yOihy82GjPKmtEFMywG+W1ctgalcf9hK+rvy2gY8fS8ejdc X-Received: by 2002:a17:902:a58a:: with SMTP id az10mr13420858plb.151.1542415534501; Fri, 16 Nov 2018 16:45:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542415534; cv=none; d=google.com; s=arc-20160816; b=Pq8e2Gw4Xp9nxaCXfFXt9sSUGm8k6qEYMFyZ+YKR95fhOBB6bY2jwbhaxy1OscUgq3 l/VDERLMIwBiPgWY5U+IN5bOrzth/BRNWmG0yt6wPeossZQW0FfYbrU/JBA7JueAqNkW Vh9AipV1sYjj4Zh+AUTg0HieCcPdMLc11o/Q0OaDKf4u9CaxPWZ4cSV+u/om1jXFEfOP 9doBiexnKNIZzR3bY935Y4alsJ0nvyZxGLW2S3MHx4QLRz4H2eHyjZtNwJYB5ZLzy/FS SFkZyiZ9ztHJPtdLLJrlf6Gpp5DjMAKQFLn/SatdwMNmX+p5a5eugiUEtjUmyu6nE6fI /J5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=QpMtsX3vDpJ2uPKCCRnaYpVyRz9bTl+/IQ1RzpuPxb0=; b=iiDDY5N8PPUMcaFgzwxaPZDMIaaFJD2Pyx8ixPha8SIhXrZei6V60g6c3PGB0wV8mh Ln0B1/Aj1zBozCIVt79RHb9wDYreeouj6jUHnY0t+DrKkH1uqA4EzErKQjQjWR1ivB9t thmqPrhIPusFTrgzSGiZp//SxOpCcApCK8GDttVRHZeM8S7MoSA+c3xeS6k0x1fXZjKB 2ryq02jBoISmEZu7GQBo4X0G1nHBmJucYs7l+xcqXfNlzt1FOTKA9s1n8E/JucTNXTnH 2R0EoEiXfQWI8VhSsNr16JyVqRVi5h6sSD3FWIsErBuM/PcEi8u2GY1hU0Tt+0EH6cjV UiBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="GEH6///k"; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id j14si31754821pgi.354.2018.11.16.16.45.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Nov 2018 16:45:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="GEH6///k"; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 02A7C2194D387; Fri, 16 Nov 2018 16:45:33 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::641; helo=mail-pl1-x641.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 689182118EF7C for ; Fri, 16 Nov 2018 16:45:31 -0800 (PST) Received: by mail-pl1-x641.google.com with SMTP id u6so1004217plm.8 for ; Fri, 16 Nov 2018 16:45:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HaRKF86kdPcDrDdc2MxZ4GGv5xFlCftrB/Lv6dYwy+U=; b=GEH6///kPzEdKZV28/QaSDWfGtodCoybJyOpk+wuew4HlyflQ8OXvC4zJwiHaOFcFB r7DbUgq+ud4K5I+2iSFL/Pgd9vetNN3GAIRFCZdJ79x950MTakarx5BaA5pIeLKggoiT 0W4owKcF1uGxGWrjbQG0g/ZoarMOJUx8YW6Vw= 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; bh=HaRKF86kdPcDrDdc2MxZ4GGv5xFlCftrB/Lv6dYwy+U=; b=AclQjsNKUnO7TPQ6ZSaQ328/aym4ugd8wyqZ+Z03KdghdP7j3IIkVJTGtO8YRDuIaA gcPm8/jtLBiH6wqo/wJZMlRqHBQClTxbCl3h0ntQOQajClgDqmJQmQSfq6pECAGKFn8U mWij8Km9k6EfZHItB/GcmiS84ULjd3LVrty9QnI+s9L1ZaqLBbPJ5jZvSIjJYikZg73x XTkpP0MWPdXy/cL8kaOW6KcD/MpIca3uRN9/eqQeqGB029Tv5GM89H7Z2R56etvJkgSC JeKLDm9mxAbIQbD8Ozse+rn0hT71mQcOjZWT1FEXKk5oLTltR7etH6XdfmyuBPgFC5s4 x5iQ== X-Gm-Message-State: AGRZ1gJC877aG9sjwClIIj4QCHiq3T4hUxBeuGlcqX09ckLCLF1lLjAq pOGJVgtS9wtOKfjCbRk12GURO5+v9x2AmA== X-Received: by 2002:a17:902:c5:: with SMTP id a63-v6mr13054718pla.201.1542415530776; Fri, 16 Nov 2018 16:45:30 -0800 (PST) Received: from mba13.psav.com ([64.114.255.114]) by smtp.gmail.com with ESMTPSA id f193-v6sm45674235pfc.74.2018.11.16.16.45.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Nov 2018 16:45:29 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Fri, 16 Nov 2018 16:45:23 -0800 Message-Id: <20181117004524.31851-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181117004524.31851-1-ard.biesheuvel@linaro.org> References: <20181117004524.31851-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH 1/2] ArmPlatformPkg/NorFlashDxe: use one GUID plus index to identify flash banks X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lersek@redhat.com MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Currently, each flash bank controlled by ArmPlatformPkg/NorFlashDxe has its own VendorHw GUID, and instances of NorFlashPlatformLib describe each bank to the driver, along with the GUID for each. This works ok for bare metal platforms, but it would be useful for virtual platforms if we could obtain this information from a device tree, which would require us to invent GUIDs on the fly, given that the 'cfi-flash' binding does not include a GUID. So instead, let's switch to a single GUID for all flash banks, and update the driver's device path handling to include an index to identify each bank uniquely. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c | 15 +++++++++------ ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h | 3 +++ 2 files changed, 12 insertions(+), 6 deletions(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Laszlo Ersek Reviewed-by: Leif Lindholm diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c index 46e815beb343..60a06e4a5058 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c @@ -82,10 +82,14 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = { { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, - { (UINT8)sizeof(VENDOR_DEVICE_PATH), (UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8) } + { + (UINT8)(OFFSET_OF(NOR_FLASH_DEVICE_PATH, End)), + (UINT8)(OFFSET_OF(NOR_FLASH_DEVICE_PATH, End) >> 8) + } }, { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }, // GUID ... NEED TO BE FILLED }, + 0, // Index { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, @@ -99,10 +103,9 @@ NorFlashCreateInstance ( IN UINTN NorFlashDeviceBase, IN UINTN NorFlashRegionBase, IN UINTN NorFlashSize, - IN UINT32 MediaId, + IN UINT32 Index, IN UINT32 BlockSize, IN BOOLEAN SupportFvb, - IN CONST GUID *NorFlashGuid, OUT NOR_FLASH_INSTANCE** NorFlashInstance ) { @@ -121,11 +124,12 @@ NorFlashCreateInstance ( Instance->Size = NorFlashSize; Instance->BlockIoProtocol.Media = &Instance->Media; - Instance->Media.MediaId = MediaId; + Instance->Media.MediaId = Index; Instance->Media.BlockSize = BlockSize; Instance->Media.LastBlock = (NorFlashSize / BlockSize)-1; - CopyGuid (&Instance->DevicePath.Vendor.Guid, NorFlashGuid); + CopyGuid (&Instance->DevicePath.Vendor.Guid, &gEfiCallerIdGuid); + Instance->DevicePath.Index = Index; Instance->ShadowBuffer = AllocateRuntimePool (BlockSize);; if (Instance->ShadowBuffer == NULL) { @@ -1311,7 +1315,6 @@ NorFlashInitialise ( Index, NorFlashDevices[Index].BlockSize, ContainVariableStorage, - &NorFlashDevices[Index].Guid, &mNorFlashInstances[Index] ); if (EFI_ERROR(Status)) { diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h index 5c07694fbfaa..8886aa43d9f3 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h @@ -122,10 +122,13 @@ typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE; +#pragma pack(1) typedef struct { VENDOR_DEVICE_PATH Vendor; + UINT8 Index; EFI_DEVICE_PATH_PROTOCOL End; } NOR_FLASH_DEVICE_PATH; +#pragma pack() struct _NOR_FLASH_INSTANCE { UINT32 Signature; From patchwork Sat Nov 17 00:45:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 151393 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1075551ljp; Fri, 16 Nov 2018 16:45:37 -0800 (PST) X-Google-Smtp-Source: AJdET5fvYniXwWSxua3Pm+KcAiZIfbIYIof/zaTG+Euzr9Ax6QGvFE9hCFVT3ZEzEulk8KhWb9Zy X-Received: by 2002:a63:d441:: with SMTP id i1-v6mr11778151pgj.31.1542415537148; Fri, 16 Nov 2018 16:45:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542415537; cv=none; d=google.com; s=arc-20160816; b=zNIa89sc0su5aZBhsRUgNVSNzmDhmCMgDHAxFelgKhbrRzyjHTEMqYDbXMnt/oM8a3 rpCtQMFxceIAmHfjXfy0qKz9Bvv1Z8bXlyTlL4xUFxRbokzNXoYf16WoWum/N0Z93FHh UIB0JgKd/O3mHZKbslrxJ1ZZ6KvCxeRDS6nuUy9K23atT4fILtHev8lWvtHvRA+45+ze 6neyYTA7IETPTjl3QgbIPfyxg7cEKvFKtuNSnplYwUJV0UijKsvKYYxSaxJ7km9e8Cp5 hxQTM/FjMy/UROhhm93hb+dOqu/xOEgVorpLKla9/2CmgOda6gtIQ1Uf63bTH7qfZq3g dKCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=ZMOwW2wboptNLy52iJ6e2dR26RHSbATnGKzglNo5BzE=; b=D/RTqQLldky+nT678HiHusFVKk6XrCgUaMttuxiOuIiHij8wSmXDd6FFvvPQXO2Cyk 2nYiNi3kcF5X9lUJJFxkiLPEriQR22LXE86S2PJfkKZM5qT5uOgK5/tOf7ub2srsczi1 CISd9djCdUE1fivmTyicCMuTyJizwVuE040sCq6EkpxURElgWcjSXa6dDfQ1Vnht7gYs Fc50bZ1cibKk/1Vmg768gS/oby0a1ro1gOx4Is5CP0hcvl8LvqVyQVrjJ9GibW/RJbd/ ptO7PC371yJd9nbEnMJCJUqoIptOkwy+enBrtwZC6zK2i1a3Ql9UhRXsQ/CzQl508T9X WYxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=UEKJRzrl; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id t3-v6si35737809pfa.170.2018.11.16.16.45.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Nov 2018 16:45:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=UEKJRzrl; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 36E4221191F29; Fri, 16 Nov 2018 16:45:34 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::444; helo=mail-pf1-x444.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2DCEB2194D3B3 for ; Fri, 16 Nov 2018 16:45:33 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id u3-v6so9475221pfm.4 for ; Fri, 16 Nov 2018 16:45:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5Qp66iDwi/DtvecFlTdQ5YJJRjRTEbThq+9WMgHFhTM=; b=UEKJRzrlnLl3unYP+WUH/ohdi01jMPXzTl0ai9s9z4TLxN4F4QRkIPGn927/eMoucq qNriivpGwmBc9NeIrc8IvIQ3ltb7mVVCn2BWUlwMPfcC+BB9tHVhq5IAnJdhkupChCBl 1M9Z0RFBThfR2duAWpTqMHcN7OVaC6Ax4CPlA= 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; bh=5Qp66iDwi/DtvecFlTdQ5YJJRjRTEbThq+9WMgHFhTM=; b=sP7eujiLwCm3g0wrkSlcZYc4hNylmgwGP80pxPLzM5WsXxvSG5kUuDRSrua+LZ7YtR EHAArewj+DQjGc1sa2kJ53D4XwUlz3Wdnw1s7A7PCDcjWI3eXdpwtjKS1/7lllphajx8 fn3gTXkCXq4LE7TeBTp6aNpCjlo9PRZHbg3o0pMyGSh2ibYbyzJ6GVjKr1ZFFNyoGo3T U7HxIG2Ezm52dgDF1qdE0jaOGActqCwmaY4fk8gaJDDsNX5LF7Fh38voz1QNV/OiEfs5 B7i8UXaXylR5+4/JCP/0gCxJMSapKkh/ui8CEA+h+zm+OuDbz2+q/snFt1g74hULP0nc 525Q== X-Gm-Message-State: AGRZ1gKLaa19xvdK8pgO/IuL4EeRoemKxLoLTHRXceMqlsLvQAu3IKwc 5xtilVFCDvUPLKB7r31keRqrmqh2cnupqg== X-Received: by 2002:a62:114c:: with SMTP id z73-v6mr13109964pfi.192.1542415532534; Fri, 16 Nov 2018 16:45:32 -0800 (PST) Received: from mba13.psav.com ([64.114.255.114]) by smtp.gmail.com with ESMTPSA id f193-v6sm45674235pfc.74.2018.11.16.16.45.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Nov 2018 16:45:30 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Fri, 16 Nov 2018 16:45:24 -0800 Message-Id: <20181117004524.31851-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181117004524.31851-1-ard.biesheuvel@linaro.org> References: <20181117004524.31851-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH 2/2] ArmVirtPkg/NorFlashQemuLib: discover NOR flash banks dynamically X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lersek@redhat.com MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" NorFlashQemuLib is one of the last remaining drivers in ArmVirtPkg that are not based on the device tree received from QEMU. For ArmVirtQemu, this does not really matter, given that the NOR flash banks are always the same: the PEI code is linked to execute in place from flash bank #0, and the fixed varstore PCDs refer to flash bank #1 directly. However, ArmVirtQemuKernel can execute at any offset, and flash bank In this case, NorFlashQemuLib should not expose the first flash bank at all. To prevent introducing too much internal knowledge about which flash bank is accessible under which circumstances, let's switch to using the DTB to decide which flash banks to expose to the NOR flash driver. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c | 84 +++++++++++++++----- ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf | 12 +++ 2 files changed, 75 insertions(+), 21 deletions(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm diff --git a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c index e3bbae5b06c5..dc0a15e77170 100644 --- a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c +++ b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c @@ -1,6 +1,6 @@ /** @file - Copyright (c) 2014, Linaro Ltd. All rights reserved.
+ Copyright (c) 2014-2018, Linaro Ltd. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -12,13 +12,16 @@ **/ +#include +#include #include +#include + +#include #define QEMU_NOR_BLOCK_SIZE SIZE_256KB -#define QEMU_NOR0_BASE 0x0 -#define QEMU_NOR0_SIZE SIZE_64MB -#define QEMU_NOR1_BASE 0x04000000 -#define QEMU_NOR1_SIZE SIZE_64MB + +#define MAX_FLASH_BANKS 4 EFI_STATUS NorFlashPlatformInitialization ( @@ -28,21 +31,7 @@ NorFlashPlatformInitialization ( return EFI_SUCCESS; } -NOR_FLASH_DESCRIPTION mNorFlashDevices[] = { - { - QEMU_NOR0_BASE, - QEMU_NOR0_BASE, - QEMU_NOR0_SIZE, - QEMU_NOR_BLOCK_SIZE, - {0xF9B94AE2, 0x8BA6, 0x409B, {0x9D, 0x56, 0xB9, 0xB4, 0x17, 0xF5, 0x3C, 0xB3}} - }, { - QEMU_NOR1_BASE, - QEMU_NOR1_BASE, - QEMU_NOR1_SIZE, - QEMU_NOR_BLOCK_SIZE, - {0x8047DB4B, 0x7E9C, 0x4C0C, {0x8E, 0xBC, 0xDF, 0xBB, 0xAA, 0xCA, 0xCE, 0x8F}} - } -}; +NOR_FLASH_DESCRIPTION mNorFlashDevices[MAX_FLASH_BANKS]; EFI_STATUS NorFlashPlatformGetDevices ( @@ -50,7 +39,60 @@ NorFlashPlatformGetDevices ( OUT UINT32 *Count ) { + FDT_CLIENT_PROTOCOL *FdtClient; + INT32 Node; + EFI_STATUS Status; + EFI_STATUS FindNodeStatus; + CONST UINT64 *Reg; + UINT32 RegSize; + CONST CHAR8 *NodeStatus; + UINTN Num; + + Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, + (VOID **)&FdtClient); + ASSERT_EFI_ERROR (Status); + + Num = 0; + for (FindNodeStatus = FdtClient->FindCompatibleNode (FdtClient, + "cfi-flash", &Node); + !EFI_ERROR (FindNodeStatus); + FindNodeStatus = FdtClient->FindNextCompatibleNode (FdtClient, + "cfi-flash", Node, &Node)) { + + Status = FdtClient->GetNodeProperty (FdtClient, Node, "status", + (CONST VOID **)&NodeStatus, NULL); + if (!EFI_ERROR (Status) && AsciiStrnCmp (NodeStatus, "ok", 2) != 0) { + continue; + } + + Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg", + (CONST VOID **)&Reg, &RegSize); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "%a: GetNodeProperty () failed (Status == %r)\n", + __FUNCTION__, Status)); + continue; + } + + ASSERT ((RegSize % (2 * sizeof(UINT64))) == 0); + + while (RegSize > 0) { + mNorFlashDevices[Num].DeviceBaseAddress = (UINTN)SwapBytes64 (Reg[0]); + mNorFlashDevices[Num].RegionBaseAddress = (UINTN)SwapBytes64 (Reg[0]); + mNorFlashDevices[Num].Size = (UINTN)SwapBytes64 (Reg[1]); + mNorFlashDevices[Num].BlockSize = QEMU_NOR_BLOCK_SIZE; + + Num++; + Reg += 2; + RegSize -= 2 * sizeof(UINT64); + + if (Num >= MAX_FLASH_BANKS) { + goto Finished; + } + } + } + +Finished: *NorFlashDescriptions = mNorFlashDevices; - *Count = ARRAY_SIZE (mNorFlashDevices); + *Count = Num; return EFI_SUCCESS; } diff --git a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf index 126d1671f544..d86ff36dbd58 100644 --- a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf +++ b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf @@ -28,3 +28,15 @@ [Packages] MdePkg/MdePkg.dec ArmPlatformPkg/ArmPlatformPkg.dec + ArmVirtPkg/ArmVirtPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + UefiBootServicesTableLib + +[Protocols] + gFdtClientProtocolGuid ## CONSUMES + +[Depex] + gFdtClientProtocolGuid