From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk0-x231.google.com (mail-qk0-x231.google.com [IPv6:2607:f8b0:400d:c09::231]) (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 C0E0A1A1F01 for ; Thu, 15 Sep 2016 06:30:55 -0700 (PDT) Received: by mail-qk0-x231.google.com with SMTP id z190so50031929qkc.3 for ; Thu, 15 Sep 2016 06:30:55 -0700 (PDT) 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=YWS0cjDgV45miFAmPZkoov0nSmReIu8gSxlNhkTzHbg=; b=MHyM+wbH72ovRYkBU39EHyipqtV+0Xf0l63LD5gtqsAqDEm8QLehSzviDtf55T7BqI QkH4lThWyrGTMfCFpt+kAO7ridne5BE2MZzyHdeqkqilaIHrfvpqEXpwuHB4uKb7jsTD eANxMXOtUefXpfOrdwVRknPB4tbZAsNOF5niI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YWS0cjDgV45miFAmPZkoov0nSmReIu8gSxlNhkTzHbg=; b=asSWYzKX1SFTL53v9mN6Te+MTdoBbjA0nFBo5dbejpRvUDqz86CUaw02gh2Q8jjpSg YLCZKC33EP9V/Cas+2eK/EQsVjFYZces/OHD2JqS62gu4pFqGkcPWJNt83Xzs31N1vS0 PssufIyrQiX7XDHfpqxm/uEPZae1Dl105lQk7bRL1uy8SPvRS6gytreuOP8oUG5lrBVL MG7nFL/+v59EWLRIt3Pu7q9e8is7icIoBJQnrmTgbosOiwxGDTDfM4I4O1DObuLH5C+T vT2oMmu5zFCynKdFiwWeOdi0v4XOz63E2S9ZEeWjuHPthfGnAgY/dFxOqpxtbYqhsdIE 6YZg== X-Gm-Message-State: AE9vXwN/3YwoK9AmoM5hdAHKcHX2Rd00Cd3CHtOjVryadXzF40FDZb2X4JaR8CF3qg3YGw0y X-Received: by 10.194.126.133 with SMTP id my5mr7687533wjb.47.1473946254818; Thu, 15 Sep 2016 06:30:54 -0700 (PDT) Received: from localhost.localdomain ([160.168.239.246]) by smtp.gmail.com with ESMTPSA id r9sm3532696wjp.15.2016.09.15.06.30.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Sep 2016 06:30:54 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, lersek@redhat.com Cc: zhaoshenglong@huawei.com, sakar.arora@nxp.com, Ard Biesheuvel Date: Thu, 15 Sep 2016 14:30:32 +0100 Message-Id: <1473946233-10547-4-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473946233-10547-1-git-send-email-ard.biesheuvel@linaro.org> References: <1473946233-10547-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [PATCH 3/4] ArmVirtPkg/FdtClient: add methods to iterate over memory nodes X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Sep 2016 13:30:56 -0000 Add high level methods to iterate over all 'reg' properties of all DT nodes whose device_type properties have the value "memory". Since we are modifying the FdtClient protocol, update the protocol and the only existing implementation at the same time. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/FdtClientDxe/FdtClientDxe.c | 76 ++++++++++++++++++++ ArmVirtPkg/Include/Protocol/FdtClient.h | 26 +++++++ 2 files changed, 102 insertions(+) diff --git a/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c b/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c index 382e9af6bf84..099cce7821d6 100644 --- a/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c +++ b/ArmVirtPkg/FdtClientDxe/FdtClientDxe.c @@ -194,6 +194,80 @@ FindCompatibleNodeReg ( STATIC EFI_STATUS +EFIAPI +FindNextMemoryNodeReg ( + IN FDT_CLIENT_PROTOCOL *This, + IN INT32 PrevNode, + OUT INT32 *Node, + OUT CONST VOID **Reg, + OUT UINTN *AddressCells, + OUT UINTN *SizeCells, + OUT UINT32 *RegSize + ) +{ + INT32 Prev, Next; + CONST CHAR8 *DeviceType; + INT32 Len; + EFI_STATUS Status; + + ASSERT (mDeviceTreeBase != NULL); + ASSERT (Node != NULL); + + for (Prev = PrevNode;; Prev = Next) { + Next = fdt_next_node (mDeviceTreeBase, Prev, NULL); + if (Next < 0) { + break; + } + + DeviceType = fdt_getprop (mDeviceTreeBase, Next, "device_type", &Len); + if (DeviceType != NULL && AsciiStrCmp (DeviceType, "memory") == 0) { + + // + // Get the 'reg' property of this memory node. For now, we will assume + // 8 byte quantities for base and size, respectively. + // TODO use #cells root properties instead + // + Status = GetNodeProperty (This, Next, "reg", Reg, RegSize); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_WARN, + "%a: ignoring memory node with no 'reg' property\n", + __FUNCTION__)); + continue; + } + if ((*RegSize % 16) != 0) { + DEBUG ((EFI_D_WARN, + "%a: ignoring memory node with invalid 'reg' property (size == 0x%x)\n", + __FUNCTION__, RegSize)); + continue; + } + + *Node = Next; + *AddressCells = 2; + *SizeCells = 2; + return EFI_SUCCESS; + } + } + return EFI_NOT_FOUND; +} + +STATIC +EFI_STATUS +EFIAPI +FindMemoryNodeReg ( + IN FDT_CLIENT_PROTOCOL *This, + OUT INT32 *Node, + OUT CONST VOID **Reg, + OUT UINTN *AddressCells, + OUT UINTN *SizeCells, + OUT UINT32 *RegSize + ) +{ + return FindNextMemoryNodeReg (This, 0, Node, Reg, AddressCells, SizeCells, + RegSize); +} + +STATIC +EFI_STATUS GetOrInsertChosenNode ( IN FDT_CLIENT_PROTOCOL *This, OUT INT32 *Node @@ -225,6 +299,8 @@ STATIC FDT_CLIENT_PROTOCOL mFdtClientProtocol = { FindNextCompatibleNode, FindCompatibleNodeProperty, FindCompatibleNodeReg, + FindMemoryNodeReg, + FindNextMemoryNodeReg, GetOrInsertChosenNode, }; diff --git a/ArmVirtPkg/Include/Protocol/FdtClient.h b/ArmVirtPkg/Include/Protocol/FdtClient.h index b593c7441426..aad76db388be 100644 --- a/ArmVirtPkg/Include/Protocol/FdtClient.h +++ b/ArmVirtPkg/Include/Protocol/FdtClient.h @@ -87,6 +87,29 @@ EFI_STATUS typedef EFI_STATUS +(EFIAPI *FDT_CLIENT_FIND_NEXT_MEMORY_NODE_REG) ( + IN FDT_CLIENT_PROTOCOL *This, + IN INT32 PrevNode, + OUT INT32 *Node, + OUT CONST VOID **Reg, + OUT UINTN *AddressCells, + OUT UINTN *SizeCells, + OUT UINT32 *RegSize + ); + +typedef +EFI_STATUS +(EFIAPI *FDT_CLIENT_FIND_MEMORY_NODE_REG) ( + IN FDT_CLIENT_PROTOCOL *This, + OUT INT32 *Node, + OUT CONST VOID **Reg, + OUT UINTN *AddressCells, + OUT UINTN *SizeCells, + OUT UINT32 *RegSize + ); + +typedef +EFI_STATUS (EFIAPI *FDT_CLIENT_GET_OR_INSERT_CHOSEN_NODE) ( IN FDT_CLIENT_PROTOCOL *This, OUT INT32 *Node @@ -101,6 +124,9 @@ struct _FDT_CLIENT_PROTOCOL { FDT_CLIENT_FIND_COMPATIBLE_NODE_PROPERTY FindCompatibleNodeProperty; FDT_CLIENT_FIND_COMPATIBLE_NODE_REG FindCompatibleNodeReg; + FDT_CLIENT_FIND_MEMORY_NODE_REG FindMemoryNodeReg; + FDT_CLIENT_FIND_NEXT_MEMORY_NODE_REG FindNextMemoryNodeReg; + FDT_CLIENT_GET_OR_INSERT_CHOSEN_NODE GetOrInsertChosenNode; }; -- 2.7.4