From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailgw02.mediatek.com (mailgw02.mediatek.com [210.61.82.184]) by mx.groups.io with SMTP id smtpd.web08.81373.1657004115654570817 for ; Mon, 04 Jul 2022 23:55:16 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: mediatek.com, ip: 210.61.82.184, mailfrom: mark-pk.tsai@mediatek.com) X-UUID: b12e7f896dff4da8aa56cae262b8b198-20220705 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.8,REQID:30736602-9316-46be-bea9-8aa157425143,OB:0,LO B:0,IP:0,URL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,RULE:Release_Ham,ACTI ON:release,TS:0 X-CID-META: VersionHash:0f94e32,CLOUDID:d308a2d6-5d6d-4eaf-a635-828a3ee48b7c,C OID:IGNORED,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,IP:nil,URL:0,File:nil ,QS:nil,BEC:nil,COL:0 X-UUID: b12e7f896dff4da8aa56cae262b8b198-20220705 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 457716794; Tue, 05 Jul 2022 14:55:09 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Tue, 5 Jul 2022 14:55:08 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.3 via Frontend Transport; Tue, 5 Jul 2022 14:55:08 +0800 From: mark-pk.tsai@mediatek.com To: CC: , , , , , , "Mark-PK Tsai" , YJ Chiang Subject: [PATCH] ArmVirtPkg: Fix boot fail on numa system. Date: Tue, 5 Jul 2022 14:55:03 +0800 Message-ID: <20220705065503.29583-1-mark-pk.tsai@mediatek.com> X-Mailer: git-send-email 2.18.0 Return-Path: mark-pk.tsai@mediatek.com MIME-Version: 1.0 X-MTK: N Content-Type: text/plain If "numa-node-id" is specified in a memory node, take node 0 as system memory instead of taking the first memory node. Cc: YJ Chiang Signed-off-by: Mark-PK Tsai --- ArmVirtPkg/PrePi/FdtParser.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/ArmVirtPkg/PrePi/FdtParser.c b/ArmVirtPkg/PrePi/FdtParser.c index 5a91f7e62d..5c7de3bc31 100644 --- a/ArmVirtPkg/PrePi/FdtParser.c +++ b/ArmVirtPkg/PrePi/FdtParser.c @@ -19,19 +19,43 @@ FindMemnode ( INT32 SizeCells; INT32 Length; CONST INT32 *Prop; + INT32 NumaId; + INT32 Node, Prev; + CONST CHAR8 *Type; if (fdt_check_header (DeviceTreeBlob) != 0) { return FALSE; } // - // Look for a node called "memory" at the lowest level of the tree + // Look for the lowest memory node. + // On Numa system, use node 0 as system memory. // - MemoryNode = fdt_path_offset (DeviceTreeBlob, "/memory"); - if (MemoryNode <= 0) { - return FALSE; + MemoryNode = -1; + NumaId = -1; + + for (Prev = 0; ; Prev = Node) { + Node = fdt_next_node (DeviceTreeBlob, Prev, NULL); + if (Node < 0) + break; + + Type = fdt_getprop (DeviceTreeBlob, Node, "device_type", &Length); + if (Type && (AsciiStrnCmp (Type, "memory", Length) == 0)) { + Prop = fdt_getprop (DeviceTreeBlob, Node, "numa-node-id", &Length); + if (Prop && Length == 4) { + NumaId = fdt32_to_cpu (*Prop); + } + + if (!Prop || (Prop && NumaId == 0)) { + MemoryNode = Node; + break; + } + } } + if (MemoryNode < 0) + return FALSE; + // // Retrieve the #address-cells and #size-cells properties // from the root node, or use the default if not provided. -- 2.32.0