From patchwork Thu Dec 5 04:24:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 1204468 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47T2gk0hvnz9sPJ for ; Thu, 5 Dec 2019 15:25:06 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.ru Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47T2gj6lLDzDqXd for ; Thu, 5 Dec 2019 15:25:05 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.ru (client-ip=107.174.27.60; helo=ozlabs.ru; envelope-from=aik@ozlabs.ru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.ru Received: from ozlabs.ru (unknown [107.174.27.60]) by lists.ozlabs.org (Postfix) with ESMTP id 47T2gf2D8BzDqXL for ; Thu, 5 Dec 2019 15:25:02 +1100 (AEDT) Received: from fstn1-p1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 45252AE8000F; Wed, 4 Dec 2019 23:23:57 -0500 (EST) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Thu, 5 Dec 2019 15:24:58 +1100 Message-Id: <20191205042458.57959-1-aik@ozlabs.ru> X-Mailer: git-send-email 2.17.1 Subject: [SLOF] [PATCH slof] fdt: Fix updating the tree at H_CAS X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" The previous approach to merge the QEMU FDT into the existing tree and then patch it turned to be broken as we patch properties based on their names only so we patch not just what QEMU provides (which was the intention) but also all properties SLOF created. This breaks one of them - "interrupt-map" - it is created by QEMU for a PHB but SLOF creates it for PCI bridges and since they have different sizes, patching phandles at fixed offset fails. Rather than skipping certain nodes in the SLOF tree, this uses different approach: now we read the QEMU FDT in 3 passes: 1. find all phandle/linux-phandle properties and store these in the SLOF internal tree to allow phandle->node lookup later; 2. walk through all FDT properties, patch them if needed using phandles from the SLOF tree and save patched values in SLOF properties; 3. delete phandle/linux-phandle properties created in 1. This is safe as SLOF does not create these properties anyway. Fixes: 44d06f9e68cf ("fdt: Update phandles after H_CAS") Signed-off-by: Alexey Kardashevskiy --- board-qemu/slof/archsupport.fs | 1 - board-qemu/slof/fdt.fs | 123 +++++++++++++++++++++++++++++++-- 2 files changed, 117 insertions(+), 7 deletions(-) diff --git a/board-qemu/slof/archsupport.fs b/board-qemu/slof/archsupport.fs index 6512d57d50ec..fc48830553e2 100644 --- a/board-qemu/slof/archsupport.fs +++ b/board-qemu/slof/archsupport.fs @@ -33,7 +33,6 @@ fdt-check-header fdt-struct fdt-fix-cas-node fdt-fix-cas-success NOT ( memaddr err? ) - s" /" find-node fdt-fix-phandles ELSE FALSE THEN diff --git a/board-qemu/slof/fdt.fs b/board-qemu/slof/fdt.fs index 5ece270f7c0b..fc39a82a10b5 100644 --- a/board-qemu/slof/fdt.fs +++ b/board-qemu/slof/fdt.fs @@ -12,6 +12,7 @@ 0 VALUE fdt-debug TRUE VALUE fdt-cas-fix? +0 VALUE fdt-cas-pass \ Bail out if no fdt fdt-start 0 = IF -1 throw THEN @@ -294,6 +295,81 @@ fdt-claim-reserve 2drop 2drop ; +: (phandle>node) ( phandle current -- node|0 ) + dup s" phandle" rot get-property 0= IF + decode-int nip nip ( phandle current phandle-prop ) + 2 pick = IF + fdt-debug IF ." Found phandle; " dup . ." <= " over . cr THEN + nip ( current ) + EXIT + THEN + ELSE + dup s" linux-phandle" rot get-property 0= IF + decode-int nip nip ( phandle current phandle-prop ) + 2 pick = IF + fdt-debug IF ." Found linux-phandle; " dup . ." <= " over . cr THEN + nip ( current ) + EXIT + THEN + THEN + THEN + child BEGIN + dup + WHILE + 2dup + RECURSE + ?dup 0<> IF + nip nip + EXIT + THEN + PEER + REPEAT + 2drop 0 +; + +: phandle>node ( phandle -- node ) s" /" find-node (phandle>node) ; + +: (fdt-patch-phandles) ( prop-addr prop-len -- ) + BEGIN + dup + WHILE ( prop-addr prop-len ) + over l@ phandle>node + ?dup 0<> IF + fdt-debug IF ." ### Patching phandle=" 2 pick l@ . cr THEN + 2 pick l! + TRUE TO (fdt-phandle-replaced) + THEN + 4 - swap 4 + swap + REPEAT + 2drop +; + +: (fdt-patch-interrupt-map) ( prop-addr prop-len -- ) + \ interrupt-controller phandle is expected to be the same accross the map + over 10 + l@ phandle>node ?dup 0= IF 2drop EXIT THEN + -rot + fdt-debug IF ." ### Patching interrupt-map: " over 10 + l@ . ." => " 2 pick . cr THEN + + TRUE TO (fdt-phandle-replaced) + BEGIN + dup + WHILE ( newph prop-addr prop-len ) + 2 pick 2 pick 10 + l! + 1c - swap 1c + swap + REPEAT + 3drop +; + +: fdt-patch-phandles ( prop-addr prop-len nameadd namelen -- ) + 2dup s" interrupt-map" str= IF 2drop (fdt-patch-interrupt-map) EXIT THEN + 2dup s" interrupt-parent" str= IF 2drop (fdt-patch-phandles) EXIT THEN + 2dup s" ibm,gpu" str= IF 2drop (fdt-patch-phandles) EXIT THEN + 2dup s" ibm,npu" str= IF 2drop (fdt-patch-phandles) EXIT THEN + 2dup s" ibm,nvlink" str= IF 2drop (fdt-patch-phandles) EXIT THEN + 2dup s" memory-region" str= IF 2drop (fdt-patch-phandles) EXIT THEN + 4drop +; + \ Replace one phandle "old" with a phandle "new" in "node" and recursively \ in its child nodes: : fdt-replace-all-phandles ( old new node -- ) @@ -394,6 +470,12 @@ r> drop find-node ?dup 0 <> IF set-node THEN ; +: str=phandle? ( s len -- true|false ) + 2dup s" phandle" str= >r + s" linux,phandle" str= + r> or +; + : (fdt-fix-cas-node) ( start -- end ) recursive fdt-next-tag dup OF_DT_BEGIN_NODE <> IF @@ -414,7 +496,7 @@ r> drop 2dup find-node ?dup 0 <> IF set-node 2drop ELSE - fdt-debug IF ." Node not found, creating " 2dup type cr THEN + fdt-debug IF ." Creating node: " 2dup type cr THEN fdt-create-cas-node THEN fdt-debug IF ." Current now: " pwd cr THEN @@ -422,22 +504,48 @@ r> drop fdt-next-tag dup OF_DT_END_NODE <> WHILE dup OF_DT_PROP = IF - fdt-debug IF ." Found property " cr THEN drop dup ( drop tag, dup addr : a1 a1 ) dup l@ dup rot 4 + ( fetch size, stack is : a1 s s a2) dup l@ swap 4 + ( fetch nameid, stack is : a1 s s i a3 ) rot ( we now have: a1 s i a3 s ) fdt-encode-prop rot ( a1 s pa ps i) fdt-fetch-string ( a1 s pa ps na ns ) - property - fdt-debug IF ." Setting property done " cr THEN + + fdt-cas-pass CASE + 0 OF + 2dup str=phandle? IF + fdt-debug IF 4dup ." Phandle: " type ." =" swap ." @" . ." " .d ." bytes" cr THEN + property + ELSE + 4drop + THEN + ENDOF + 1 OF + 2dup str=phandle? not IF + fdt-debug IF 4dup ." Property: " type ." =" swap ." @" . ." " .d ." bytes" cr THEN + 4dup fdt-patch-phandles + property + ELSE + 4drop + THEN + ENDOF + 2 OF + 2dup str=phandle? IF + fdt-debug IF 4dup ." Deleting: " type ." =" swap ." @" . ." " .d ." bytes" cr THEN + delete-property + 2drop + ELSE + 4drop + THEN + ENDOF + ENDCASE + + 8 + 3 + fffffffc and ELSE dup OF_DT_BEGIN_NODE = IF drop ( drop tag ) 4 - (fdt-fix-cas-node) get-parent set-node - fdt-debug IF ." Returning back " pwd cr THEN ELSE ." Error " cr drop @@ -450,7 +558,10 @@ r> drop ; : fdt-fix-cas-node ( start -- ) - (fdt-fix-cas-node) drop + 0 to fdt-cas-pass dup (fdt-fix-cas-node) drop \ Add phandles + 1 to fdt-cas-pass dup (fdt-fix-cas-node) drop \ Patch+add other properties + 2 to fdt-cas-pass dup (fdt-fix-cas-node) drop \ Delete phandles from pass 1 + drop ; : fdt-fix-cas-success