From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c09::244; helo=mail-wm0-x244.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) (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 5F4EF21107479 for ; Thu, 30 Aug 2018 11:55:04 -0700 (PDT) Received: by mail-wm0-x244.google.com with SMTP id j192-v6so3061683wmj.1 for ; Thu, 30 Aug 2018 11:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=wcIHk2LdRjNmDox80L3xxuq5dFe0BNxNst/kU6DPSyU=; b=eM3YBHe48sULSc0kihs9xzG0k+6AqPPMrVyiHr/+PFmIzxmeg4mUMRqt9D0LK+Zn/p 9PH7XRkJi8+wSZPHN2nGqaP2v5DL/N8nk05AXqV7XdwCu5p+HkNBoMp7UlUq73Y1z0VN BAKWdVtvATrpSTwYgZ9Q6YDxmSaqgsU1qWm1M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=wcIHk2LdRjNmDox80L3xxuq5dFe0BNxNst/kU6DPSyU=; b=drYdVyTK3KBn6DBBAEnW19roAxX4HVaDq5/ZTex86TRBYZubdIYoA8kUOqlyQK7SXB zv5fvWLg27Fj42AmpMT2l7Gr7slbTbiQy0Yq8seUcm0Yl9YxBMfyTaeufPNZCKvde2k6 exsMnaVTsseMImkm2lVP7c/pDHRu6QOCd/uWpJn6v8wb/wl9C+sr/zk0J2Wn3zTZ7wRZ yas9Go7NTAfnS6yuIcMYA3JAF95Nn1xJTgqN3w3YOHh2UJ9CSMueX3qRa+aZQrHh0lSf ebM3qYdlj6vszxvOiitUHOpaCVQWsFF5u3IjIyzYPX8wt+qdbfx1kkIBWKdJzOs6aRjp gCeA== X-Gm-Message-State: APzg51De7SaMNIi7qRsp4RL/tK2iaFJvXCmm3pQzrVm6glNP7gkFmWET yrUe3pvo2SHD2fS+YMX9l2Xp0A== X-Google-Smtp-Source: ANB0VdYloueApZ5TNmJ40ZmT2f6J9b8LDrIOG4hmaWEtmwqESM4PQ76HfhO4/Ir2JUjW2yNqwRvj9Q== X-Received: by 2002:a1c:85cb:: with SMTP id h194-v6mr2760613wmd.54.1535655302865; Thu, 30 Aug 2018 11:55:02 -0700 (PDT) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id f18-v6sm7845383wru.51.2018.08.30.11.55.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 Aug 2018 11:55:01 -0700 (PDT) Date: Thu, 30 Aug 2018 19:55:00 +0100 From: Leif Lindholm To: Ming Huang Cc: linaro-uefi@lists.linaro.org, edk2-devel@lists.01.org, graeme.gregory@linaro.org, ard.biesheuvel@linaro.org, michael.d.kinney@intel.com, lersek@redhat.com, guoheyi@huawei.com, wanghuiqiang@huawei.com, huangming23@huawei.com, zhangjinsong2@huawei.com, huangdaode@hisilicon.com, john.garry@huawei.com, xinliang.liu@linaro.org Message-ID: <20180830185500.wed5q2hwnyklew7o@bivouac.eciton.net> References: <20180823160743.45638-1-ming.huang@linaro.org> <20180823160743.45638-30-ming.huang@linaro.org> MIME-Version: 1.0 In-Reply-To: <20180823160743.45638-30-ming.huang@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH edk2-platforms v4 29/31] Silicon/Hisilicon/setup: Enable/disable SMMU 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: , X-List-Received-Date: Thu, 30 Aug 2018 18:55:04 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Aug 24, 2018 at 12:07:41AM +0800, Ming Huang wrote: > Select without SMMU iort while SMMU item is disable, > Select with SMMU iort while SMMU item is enable. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ming Huang Reviewed-by: Leif Lindholm > --- > Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/AcpiPlatformDxe.inf | 1 + > Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c | 89 ++++++++++++++++++++ > 2 files changed, 90 insertions(+) > > diff --git a/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/AcpiPlatformDxe.inf b/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/AcpiPlatformDxe.inf > index 281a4f2ebd..3d133aff85 100644 > --- a/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/AcpiPlatformDxe.inf > +++ b/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/AcpiPlatformDxe.inf > @@ -51,6 +51,7 @@ > > [Guids] > gHisiEfiMemoryMapGuid > + gOemConfigGuid > > [Pcd] > gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiTableStorageFile ## CONSUMES > diff --git a/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c b/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c > index 54f49977c3..c2c8f687b0 100644 > --- a/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c > +++ b/Silicon/Hisilicon/Drivers/HisiAcpiPlatformDxe/UpdateAcpiTable.c > @@ -16,12 +16,98 @@ > #include > #include > #include > +#include > #include > #include > +#include > #include > > #define CORECOUNT(X) ((X) * CORE_NUM_PER_SOCKET) > > +#define FIELD_IORT_NODE_OFFSET 40 > + > +typedef enum { > + NodeTypeIts = 0, > + NodeTypeNameComponent, > + NodeTypePciRC, > + NodeTypeSmmuV1, > + NodeTypeSmmuV3, > + NodeTypePMCG > +} IORT_NODE_TYPE; > + > +#pragma pack(1) > +typedef struct { > + UINT8 Type; > + UINT16 Length; > + UINT8 Revision; > + UINT32 Reserved; > + UINT32 IdMapNumber; > + UINT32 IdArrayOffset; > +} IORT_NODE_HEAD; > +#pragma pack() > + > +BOOLEAN > +IsIortWithSmmu ( > + IN EFI_ACPI_DESCRIPTION_HEADER *TableHeader > + ) > +{ > + UINT32 *NodeOffset; > + UINT32 NextOffset; > + IORT_NODE_HEAD *Node; > + > + NodeOffset = (UINT32 *)((UINT8 *)TableHeader + FIELD_IORT_NODE_OFFSET); > + NextOffset = *NodeOffset; > + > + while (NextOffset < TableHeader->Length) { > + Node = (IORT_NODE_HEAD *)((UINT8 *)TableHeader + NextOffset); > + NextOffset += Node->Length; > + > + if ((Node->Type == NodeTypeSmmuV1) || (Node->Type == NodeTypeSmmuV3)) { > + return TRUE; > + } > + } > + > + return FALSE; > +} > + > +EFI_STATUS > +SelectIort ( > + IN EFI_ACPI_DESCRIPTION_HEADER *TableHeader > + ) > +{ > + EFI_STATUS Status; > + UINTN Size; > + OEM_CONFIG_DATA Configuration; > + > + Configuration.EnableSmmu = 0; > + Size = sizeof (OEM_CONFIG_DATA); > + Status = gRT->GetVariable ( > + OEM_CONFIG_NAME, > + &gOemConfigGuid, > + NULL, > + &Size, > + &Configuration > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Get OemConfig variable (%r).\n", Status)); > + } > + > + Status = EFI_SUCCESS; > + if (IsIortWithSmmu (TableHeader)) { > + if (!Configuration.EnableSmmu) { > + Status = EFI_ABORTED; > + } > + } else { > + if (Configuration.EnableSmmu) { > + Status = EFI_ABORTED; > + } > + } > + DEBUG ((DEBUG_INFO, "SmmuEnable=%x, return %r for Iort table.\n", > + Configuration.EnableSmmu, Status)); > + > + return Status; > +} > + > STATIC > VOID > RemoveUnusedMemoryNode ( > @@ -130,6 +216,9 @@ UpdateAcpiTable ( > case EFI_ACPI_6_0_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE: > Status = UpdateSlit (TableHeader); > break; > + case EFI_ACPI_6_2_IO_REMAPPING_TABLE_SIGNATURE: > + Status = SelectIort (TableHeader); > + break; > } > return Status; > } > -- > 2.18.0 >