From patchwork Thu Sep 15 13:30:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 76306 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp2444792qgf; Thu, 15 Sep 2016 06:31:01 -0700 (PDT) X-Received: by 10.66.22.102 with SMTP id c6mr798033paf.175.1473946261151; Thu, 15 Sep 2016 06:31:01 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id sk1si4289162pab.236.2016.09.15.06.31.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Sep 2016 06:31:01 -0700 (PDT) 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; 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 dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A49751A1F05; Thu, 15 Sep 2016 06:31:00 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-qk0-x22b.google.com (mail-qk0-x22b.google.com [IPv6:2607:f8b0:400d:c09::22b]) (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 693981A1F04 for ; Thu, 15 Sep 2016 06:30:58 -0700 (PDT) Received: by mail-qk0-x22b.google.com with SMTP id w204so49677367qka.0 for ; Thu, 15 Sep 2016 06:30:58 -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=gMk6T0p67TF1xhCwBwLt3hYunuSWwacKB1NXZ1BfXzs=; b=R365jlWf58GX85HDiOxY+h3uCEwyVhdOQWoSIgM4A994cTI2jRL8+MNoHOMNalmzTQ YvcsLEBdRUkOuoKPT5tfaC79bKLmDoWpQQCyUUKDg4XirrRTpdOpTXLuleAkIcbdZlAy PLfAWdm4mFPM0WgXHi7IP83StiVB2CIMBEFJ0= 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=gMk6T0p67TF1xhCwBwLt3hYunuSWwacKB1NXZ1BfXzs=; b=elmwYpNtJzvtsHyr63KYHouVQo4+AA9mNi6jJ3pbvXvSggSB0j0BQiz7unyykEdJZz 1eGheNKuQiAnJ/ByAG28meWzfJFs4DKLF2rF+Jxx7yaDbEcToDg2Vb/DCBxeCDcw9zBz K+SxhxfgTpnnEXlZImQwr3AvCr5dzORG3mIrJ8sBKyvZe2PLX/sQrac/BBGJ8bOkqxoz /AMvm+2SPb0uVT4NyvSbc3egtC5HPR0pEO6ZdmH5DeMrxrDA+B8EyAnTnQJDEWTyioyD EuZv1ukEeg71W02jT+cJJT66WuQOZw4EujF7y2HjjqVGIqCRASRCGRuqTQ3QuM1TEqc0 aasA== X-Gm-Message-State: AE9vXwPxvxMsn5yUksnXe/djFeoo1a3by9wVJHMsqkr975mV77SZGiJ67m8xq+bDJVAAU960 X-Received: by 10.194.141.13 with SMTP id rk13mr7687497wjb.25.1473946257367; Thu, 15 Sep 2016 06:30:57 -0700 (PDT) Received: from localhost.localdomain ([160.168.239.246]) by smtp.gmail.com with ESMTPSA id r9sm3532696wjp.15.2016.09.15.06.30.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Sep 2016 06:30:56 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, lersek@redhat.com Date: Thu, 15 Sep 2016 14:30:33 +0100 Message-Id: <1473946233-10547-5-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: [edk2] [PATCH 4/4] ArmVirtPkg/HighMemDxe: move to FDT client protocol 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: , Cc: Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Use the FDT client protocol rather than parsing the DT directly using fdtlib. While we're at it, update the code so it deals correctly with memory nodes that describe multiple disjoint regions in their "reg" properties, and make the code work with #address-cells/#size-cells properties of <1> as well as <2>. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/HighMemDxe/HighMemDxe.c | 120 +++++++++----------- ArmVirtPkg/HighMemDxe/HighMemDxe.inf | 16 ++- 2 files changed, 62 insertions(+), 74 deletions(-) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Laszlo Ersek diff --git a/ArmVirtPkg/HighMemDxe/HighMemDxe.c b/ArmVirtPkg/HighMemDxe/HighMemDxe.c index 4d56e6236b54..08de3cbb7e9c 100644 --- a/ArmVirtPkg/HighMemDxe/HighMemDxe.c +++ b/ArmVirtPkg/HighMemDxe/HighMemDxe.c @@ -1,7 +1,7 @@ /** @file * High memory node enumeration DXE driver for ARM Virtual Machines * -* Copyright (c) 2015, Linaro Ltd. All rights reserved. +* Copyright (c) 2015-2016, 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 which accompanies this @@ -15,12 +15,12 @@ **/ #include -#include #include -#include -#include -#include #include +#include +#include + +#include EFI_STATUS EFIAPI @@ -29,76 +29,66 @@ InitializeHighMemDxe ( IN EFI_SYSTEM_TABLE *SystemTable ) { - VOID *Hob; - VOID *DeviceTreeBase; - INT32 Node, Prev; - EFI_STATUS Status; - CONST CHAR8 *Type; - INT32 Len; - CONST VOID *RegProp; - UINT64 CurBase; - UINT64 CurSize; - - Hob = GetFirstGuidHob(&gFdtHobGuid); - if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (UINT64)) { - return EFI_NOT_FOUND; - } - DeviceTreeBase = (VOID *)(UINTN)*(UINT64 *)GET_GUID_HOB_DATA (Hob); - - if (fdt_check_header (DeviceTreeBase) != 0) { - DEBUG ((EFI_D_ERROR, "%a: No DTB found @ 0x%p\n", __FUNCTION__, - DeviceTreeBase)); - return EFI_NOT_FOUND; - } + FDT_CLIENT_PROTOCOL *FdtClient; + EFI_STATUS Status, FindNodeStatus; + INT32 Node; + CONST UINT32 *Reg; + UINT32 RegSize; + UINTN AddressCells, SizeCells; + UINT64 CurBase; + UINT64 CurSize; - DEBUG ((EFI_D_INFO, "%a: DTB @ 0x%p\n", __FUNCTION__, DeviceTreeBase)); + Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, + (VOID **)&FdtClient); + ASSERT_EFI_ERROR (Status); // - // Check for memory node and add the memory spaces expect the lowest one + // Check for memory node and add the memory spaces except the lowest one // - for (Prev = 0;; Prev = Node) { - Node = fdt_next_node (DeviceTreeBase, Prev, NULL); - if (Node < 0) { - break; - } + for (FindNodeStatus = FdtClient->FindMemoryNodeReg (FdtClient, &Node, + (CONST VOID **) &Reg, &AddressCells, + &SizeCells, &RegSize); + !EFI_ERROR (FindNodeStatus); + FindNodeStatus = FdtClient->FindNextMemoryNodeReg (FdtClient, Node, + &Node, (CONST VOID **) &Reg, &AddressCells, + &SizeCells, &RegSize)) { + + ASSERT (AddressCells <= 2); + ASSERT (SizeCells <= 2); - Type = fdt_getprop (DeviceTreeBase, Node, "device_type", &Len); - if (Type && AsciiStrnCmp (Type, "memory", Len) == 0) { - // - // Get the 'reg' property of this node. For now, we will assume - // two 8 byte quantities for base and size, respectively. - // - RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len); - if (RegProp != NULL && Len == (2 * sizeof (UINT64))) { + while (RegSize > 0) { - CurBase = fdt64_to_cpu (((UINT64 *)RegProp)[0]); - CurSize = fdt64_to_cpu (((UINT64 *)RegProp)[1]); + CurBase = SwapBytes32 (*Reg++); + if (AddressCells > 1) { + CurBase |= (CurBase << 32) | SwapBytes32 (*Reg++); + } + CurSize = SwapBytes32 (*Reg++); + if (SizeCells > 1) { + CurSize |= (CurSize << 32) | SwapBytes32 (*Reg++); + } + RegSize -= (AddressCells + SizeCells) * sizeof (UINT32); - if (PcdGet64 (PcdSystemMemoryBase) != CurBase) { - Status = gDS->AddMemorySpace ( - EfiGcdMemoryTypeSystemMemory, - CurBase, CurSize, - EFI_MEMORY_WB); + if (PcdGet64 (PcdSystemMemoryBase) != CurBase) { + Status = gDS->AddMemorySpace (EfiGcdMemoryTypeSystemMemory, CurBase, + CurSize, EFI_MEMORY_WB); - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, - "%a: Failed to add System RAM @ 0x%lx - 0x%lx (%r)\n", - __FUNCTION__, CurBase, CurBase + CurSize - 1, Status)); - continue; - } + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, + "%a: Failed to add System RAM @ 0x%lx - 0x%lx (%r)\n", + __FUNCTION__, CurBase, CurBase + CurSize - 1, Status)); + continue; + } - Status = gDS->SetMemorySpaceAttributes ( - CurBase, CurSize, - EFI_MEMORY_WB); + Status = gDS->SetMemorySpaceAttributes (CurBase, CurSize, + EFI_MEMORY_WB); - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, - "%a: Failed to set System RAM @ 0x%lx - 0x%lx attribute (%r)\n", - __FUNCTION__, CurBase, CurBase + CurSize - 1, Status)); - } else { - DEBUG ((EFI_D_INFO, "%a: Add System RAM @ 0x%lx - 0x%lx\n", - __FUNCTION__, CurBase, CurBase + CurSize - 1)); - } + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, + "%a: Failed to set System RAM @ 0x%lx - 0x%lx attribute (%r)\n", + __FUNCTION__, CurBase, CurBase + CurSize - 1, Status)); + } else { + DEBUG ((EFI_D_INFO, "%a: Add System RAM @ 0x%lx - 0x%lx\n", + __FUNCTION__, CurBase, CurBase + CurSize - 1)); } } } diff --git a/ArmVirtPkg/HighMemDxe/HighMemDxe.inf b/ArmVirtPkg/HighMemDxe/HighMemDxe.inf index ae632a8bee93..3661cfd8c80c 100644 --- a/ArmVirtPkg/HighMemDxe/HighMemDxe.inf +++ b/ArmVirtPkg/HighMemDxe/HighMemDxe.inf @@ -1,7 +1,7 @@ ## @file # High memory node enumeration DXE driver for ARM Virtual Machines # -# Copyright (c) 2015, Linaro Ltd. All rights reserved. +# Copyright (c) 2015-2016, 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 which accompanies this @@ -30,23 +30,21 @@ [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec ArmPkg/ArmPkg.dec - ArmPlatformPkg/ArmPlatformPkg.dec ArmVirtPkg/ArmVirtPkg.dec - EmbeddedPkg/EmbeddedPkg.dec [LibraryClasses] BaseLib + DebugLib + DxeServicesTableLib PcdLib + UefiBootServicesTableLib UefiDriverEntryPoint - FdtLib - HobLib - DxeServicesTableLib -[Guids] - gFdtHobGuid +[Protocols] + gFdtClientProtocolGuid ## CONSUMES [Pcd] gArmTokenSpaceGuid.PcdSystemMemoryBase [Depex] - gEfiCpuArchProtocolGuid + gEfiCpuArchProtocolGuid AND gFdtClientProtocolGuid