public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: mark-pk.tsai@mediatek.com
To: <ardb+tianocore@kernel.org>
Cc: <quic_llindhol@quicinc.com>, <sami.mujawar@arm.com>,
	<kraxel@redhat.com>, <julien@xen.org>, <devel@edk2.groups.io>,
	<yj.chiang@mediatek.com>,
	"Mark-PK Tsai" <mark-pk.tsai@mediatek.com>,
	YJ Chiang <yj.chiang@medaitek.com>
Subject: [PATCH] ArmVirtPkg: Fix boot fail on numa system.
Date: Tue, 5 Jul 2022 14:55:03 +0800	[thread overview]
Message-ID: <20220705065503.29583-1-mark-pk.tsai@mediatek.com> (raw)

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 <yj.chiang@medaitek.com>
Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
---
 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


             reply	other threads:[~2022-07-05  6:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-05  6:55 mark-pk.tsai [this message]
2022-09-07  7:06 ` [PATCH] ArmVirtPkg: Fix boot fail on numa system Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220705065503.29583-1-mark-pk.tsai@mediatek.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox