From patchwork Tue Oct 3 05:15:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 820737 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y5nLh5k23z9t48 for ; Tue, 3 Oct 2017 16:16:12 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3y5nLh4dtdzDqjP for ; Tue, 3 Oct 2017 16:16:12 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=ozlabs.ru (client-ip=107.173.13.209; helo=ozlabs.ru; envelope-from=aik@ozlabs.ru; receiver=) Received: from ozlabs.ru (ozlabs.ru [107.173.13.209]) by lists.ozlabs.org (Postfix) with ESMTP id 3y5nLV2gPtzDqhh for ; Tue, 3 Oct 2017 16:16:02 +1100 (AEDT) Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 9B86D3A6047A; Tue, 3 Oct 2017 01:14:12 -0400 (EDT) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Tue, 3 Oct 2017 16:15:19 +1100 Message-Id: <20171003051523.17650-2-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171003051523.17650-1-aik@ozlabs.ru> References: <20171003051523.17650-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof v3 1/5] Revert "board-qemu: add private hcall to inform host on "phandle" update" X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aravinda Prasad MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" This reverts commit 604d28cc3f7 "board-qemu: add private hcall to inform host on "phandle" update" as a bigger hammer is coming soon which will pass the entire device tree to QEMU, not just phandles. QEMU has never used the hcall this patch is removing so there will be no compatibility issues. Signed-off-by: Alexey Kardashevskiy Reviewed-by: Greg Kurz --- lib/libhvcall/libhvcall.h | 1 - board-qemu/slof/fdt.fs | 14 ++------------ lib/libhvcall/hvcall.code | 7 ------- lib/libhvcall/hvcall.in | 1 - 4 files changed, 2 insertions(+), 21 deletions(-) diff --git a/lib/libhvcall/libhvcall.h b/lib/libhvcall/libhvcall.h index 5776a2b..b2ea3f6 100644 --- a/lib/libhvcall/libhvcall.h +++ b/lib/libhvcall/libhvcall.h @@ -25,7 +25,6 @@ /* Client Architecture support */ #define KVMPPC_H_CAS (KVMPPC_HCALL_BASE + 0x2) #define KVMPPC_H_RTAS_UPDATE (KVMPPC_HCALL_BASE + 0x3) -#define KVMPPC_H_UPDATE_PHANDLE (KVMPPC_HCALL_BASE + 0x4) #ifndef __ASSEMBLY__ diff --git a/board-qemu/slof/fdt.fs b/board-qemu/slof/fdt.fs index a24e344..851645e 100644 --- a/board-qemu/slof/fdt.fs +++ b/board-qemu/slof/fdt.fs @@ -308,28 +308,18 @@ fdt-claim-reserve 3drop ; -\ Tell QEMU about the updated phandle: -: fdt-hv-update-phandle ( old new -- ) - hv-update-phandle ?dup IF - \ Ignore hcall not implemented error, print error otherwise - dup -2 <> IF ." HV-UPDATE-PHANDLE error: " . cr ELSE drop THEN - THEN -; - \ Replace one FDT phandle "val" with a OF1275 phandle "node" in the \ whole tree: : fdt-update-phandle ( val node -- ) >r FALSE TO (fdt-phandle-replaced) - r@ 2dup s" /" find-node ( val node val node root ) - fdt-replace-all-phandles ( val node ) + r@ s" /" find-node ( val node root ) + fdt-replace-all-phandles (fdt-phandle-replaced) IF - fdt-hv-update-phandle r@ set-node s" phandle" delete-property s" linux,phandle" delete-property ELSE - 2drop diagnostic-mode? IF cr ." Warning: Did not replace phandle in " r@ node>path type cr THEN diff --git a/lib/libhvcall/hvcall.code b/lib/libhvcall/hvcall.code index 8349748..0ff50f2 100644 --- a/lib/libhvcall/hvcall.code +++ b/lib/libhvcall/hvcall.code @@ -129,10 +129,3 @@ PRIM(check_X2d_and_X2d_patch_X2d_sc1) patch_broken_sc1((void*)start, (void*)end, (void*)patch_ins); MIRP - -// : hv-update-phandle ( old_phandle new_phandle -- res ) -PRIM(hv_X2d_update_X2d_phandle) - uint32_t new_phandle = TOS.u; POP; - uint32_t old_phandle = TOS.u; - TOS.u = hv_generic(KVMPPC_H_UPDATE_PHANDLE, old_phandle, new_phandle); -MIRP diff --git a/lib/libhvcall/hvcall.in b/lib/libhvcall/hvcall.in index ab7513a..4437b77 100644 --- a/lib/libhvcall/hvcall.in +++ b/lib/libhvcall/hvcall.in @@ -31,5 +31,4 @@ cod(RX!) cod(hv-logical-memop) cod(hv-cas) cod(hv-rtas-update) -cod(hv-update-phandle) cod(get-print-version) From patchwork Tue Oct 3 05:15:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 820738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y5nLm1LxWz9t48 for ; Tue, 3 Oct 2017 16:16:16 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3y5nLm01j2zDqlP for ; Tue, 3 Oct 2017 16:16:16 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=ozlabs.ru (client-ip=107.173.13.209; helo=ozlabs.ru; envelope-from=aik@ozlabs.ru; receiver=) Received: from ozlabs.ru (ozlabs.ru [107.173.13.209]) by lists.ozlabs.org (Postfix) with ESMTP id 3y5nLW6DrjzDqJ7 for ; Tue, 3 Oct 2017 16:16:03 +1100 (AEDT) Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 5044D3A6047B; Tue, 3 Oct 2017 01:14:14 -0400 (EDT) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Tue, 3 Oct 2017 16:15:20 +1100 Message-Id: <20171003051523.17650-3-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171003051523.17650-1-aik@ozlabs.ru> References: <20171003051523.17650-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof v3 2/5] Revert "libhvcall: drop unused KVMPPC_H_REPORT_MC_ERR and KVMPPC_H_NMI_MCE defines" X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aravinda Prasad MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" This reverts commit 089fc18a9b "libhvcall: drop unused KVMPPC_H_REPORT_MC_ERR and KVMPPC_H_NMI_MCE defines" as a bigger hammer is coming soon which will pass the entire device tree to QEMU, not just phandles. QEMU has never used the hcall this patch is removing so there will be no compatibility issues. Signed-off-by: Alexey Kardashevskiy --- lib/libhvcall/libhvcall.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/libhvcall/libhvcall.h b/lib/libhvcall/libhvcall.h index b2ea3f6..193b738 100644 --- a/lib/libhvcall/libhvcall.h +++ b/lib/libhvcall/libhvcall.h @@ -25,6 +25,8 @@ /* Client Architecture support */ #define KVMPPC_H_CAS (KVMPPC_HCALL_BASE + 0x2) #define KVMPPC_H_RTAS_UPDATE (KVMPPC_HCALL_BASE + 0x3) +#define KVMPPC_H_REPORT_MC_ERR (KVMPPC_HCALL_BASE + 0x4) +#define KVMPPC_HCALL_MAX KVMPPC_H_NMI_MCE #ifndef __ASSEMBLY__ From patchwork Tue Oct 3 05:15:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 820739 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y5nLq3N2Dz9t48 for ; Tue, 3 Oct 2017 16:16:19 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3y5nLq22s6zDqlT for ; Tue, 3 Oct 2017 16:16:19 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=ozlabs.ru (client-ip=107.173.13.209; helo=ozlabs.ru; envelope-from=aik@ozlabs.ru; receiver=) Received: from ozlabs.ru (ozlabs.ru [107.173.13.209]) by lists.ozlabs.org (Postfix) with ESMTP id 3y5nLY0qHVzDqJ7 for ; Tue, 3 Oct 2017 16:16:05 +1100 (AEDT) Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id C21BF3A6047C; Tue, 3 Oct 2017 01:14:15 -0400 (EDT) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Tue, 3 Oct 2017 16:15:21 +1100 Message-Id: <20171003051523.17650-4-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171003051523.17650-1-aik@ozlabs.ru> References: <20171003051523.17650-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof v3 3/5] Revert "rtas: Improve error handling in instantiate-rtas" X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aravinda Prasad MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" This reverts commit 1c17c13a57 "rtas: Improve error handling in instantiate-rtas" as it has improved a thing about to be reverted. Signed-off-by: Alexey Kardashevskiy --- board-qemu/slof/rtas.fs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/board-qemu/slof/rtas.fs b/board-qemu/slof/rtas.fs index 54d3929..0d2bf49 100644 --- a/board-qemu/slof/rtas.fs +++ b/board-qemu/slof/rtas.fs @@ -173,13 +173,10 @@ rtas-node set-node : instantiate-rtas ( adr -- entry ) dup rtas-base swap rtas-size move dup rtas-entry rtas-base - + - 2dup hv-rtas-update dup 0 <> IF - \ Ignore hcall not implemented error, print error otherwise - dup -2 <> IF ." HV-RTAS-UPDATE error: " . cr ELSE drop THEN - ELSE - drop + 2dup hv-rtas-update 0 <> IF + ." Failed to update RTAS " cr THEN - nip + nip ; device-end From patchwork Tue Oct 3 05:15:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 820740 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y5nLt5D4Vz9t48 for ; Tue, 3 Oct 2017 16:16:22 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3y5nLt3s2jzDqlP for ; Tue, 3 Oct 2017 16:16:22 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=ozlabs.ru (client-ip=107.173.13.209; helo=ozlabs.ru; envelope-from=aik@ozlabs.ru; receiver=) Received: from ozlabs.ru (ozlabs.ru [107.173.13.209]) by lists.ozlabs.org (Postfix) with ESMTP id 3y5nLb4lW4zDqjx for ; Tue, 3 Oct 2017 16:16:07 +1100 (AEDT) Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 3FA603A6047D; Tue, 3 Oct 2017 01:14:17 -0400 (EDT) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Tue, 3 Oct 2017 16:15:22 +1100 Message-Id: <20171003051523.17650-5-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171003051523.17650-1-aik@ozlabs.ru> References: <20171003051523.17650-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof v3 4/5] Revert "Add private HCALL to inform updated RTAS base and entry" X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aravinda Prasad MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" This reverts commit f9a60de30 "Add private HCALL to inform updated RTAS base and entry" as a bigger hammer is coming soon which will pass the entire device tree to QEMU, not just phandles. QEMU has never used the hcall this patch is removing so there will be no compatibility issues. Signed-off-by: Alexey Kardashevskiy --- lib/libhvcall/libhvcall.h | 4 +--- board-qemu/slof/rtas.fs | 6 +----- lib/libhvcall/hvcall.code | 6 ------ lib/libhvcall/hvcall.in | 1 - 4 files changed, 2 insertions(+), 15 deletions(-) diff --git a/lib/libhvcall/libhvcall.h b/lib/libhvcall/libhvcall.h index 193b738..6356a62 100644 --- a/lib/libhvcall/libhvcall.h +++ b/lib/libhvcall/libhvcall.h @@ -24,9 +24,7 @@ #define KVMPPC_H_LOGICAL_MEMOP (KVMPPC_HCALL_BASE + 0x1) /* Client Architecture support */ #define KVMPPC_H_CAS (KVMPPC_HCALL_BASE + 0x2) -#define KVMPPC_H_RTAS_UPDATE (KVMPPC_HCALL_BASE + 0x3) -#define KVMPPC_H_REPORT_MC_ERR (KVMPPC_HCALL_BASE + 0x4) -#define KVMPPC_HCALL_MAX KVMPPC_H_NMI_MCE +#define KVMPPC_HCALL_MAX KVMPPC_H_CAS #ifndef __ASSEMBLY__ diff --git a/board-qemu/slof/rtas.fs b/board-qemu/slof/rtas.fs index 0d2bf49..b17157e 100644 --- a/board-qemu/slof/rtas.fs +++ b/board-qemu/slof/rtas.fs @@ -172,11 +172,7 @@ rtas-node set-node : instantiate-rtas ( adr -- entry ) dup rtas-base swap rtas-size move - dup rtas-entry rtas-base - + - 2dup hv-rtas-update 0 <> IF - ." Failed to update RTAS " cr - THEN - nip + rtas-entry rtas-base - + ; device-end diff --git a/lib/libhvcall/hvcall.code b/lib/libhvcall/hvcall.code index 0ff50f2..744469f 100644 --- a/lib/libhvcall/hvcall.code +++ b/lib/libhvcall/hvcall.code @@ -111,12 +111,6 @@ PRIM(hv_X2d_cas) TOS.u = hv_cas(vec, buf, size); MIRP -PRIM(hv_X2d_rtas_X2d_update) - unsigned long rtas_entry = TOS.u; POP; - unsigned long rtas_base = TOS.u; - TOS.u = hv_generic(KVMPPC_H_RTAS_UPDATE, rtas_base, rtas_entry); -MIRP - PRIM(get_X2d_print_X2d_version) unsigned long addr = TOS.u; POP; get_print_banner(addr); diff --git a/lib/libhvcall/hvcall.in b/lib/libhvcall/hvcall.in index 4437b77..e99d6d1 100644 --- a/lib/libhvcall/hvcall.in +++ b/lib/libhvcall/hvcall.in @@ -30,5 +30,4 @@ cod(RX!) cod(hv-logical-memop) cod(hv-cas) -cod(hv-rtas-update) cod(get-print-version) From patchwork Tue Oct 3 05:15:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 820741 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y5nM7606Xz9t48 for ; Tue, 3 Oct 2017 16:16:35 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3y5nM755pTzDqjF for ; Tue, 3 Oct 2017 16:16:35 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=ozlabs.ru (client-ip=107.173.13.209; helo=ozlabs.ru; envelope-from=aik@ozlabs.ru; receiver=) Received: from ozlabs.ru (ozlabs.ru [107.173.13.209]) by lists.ozlabs.org (Postfix) with ESMTP id 3y5nM46Z0VzDqJ7 for ; Tue, 3 Oct 2017 16:16:32 +1100 (AEDT) Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id E291A3A6047E; Tue, 3 Oct 2017 01:14:18 -0400 (EDT) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Tue, 3 Oct 2017 16:15:23 +1100 Message-Id: <20171003051523.17650-6-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171003051523.17650-1-aik@ozlabs.ru> References: <20171003051523.17650-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof v3 5/5] fdt: Pass the resulting device tree to QEMU X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aravinda Prasad MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" This creates flatten device tree and passes it to QEMU via a custom hypercall right before jumping to RTAS. On a machine with 256 CPUs and 256 virtual Intel E1000 devices the blob is 360KB (356KB structs and 20KB of strings), building such a tree takes ~2s on a POWER8 box. A simple tree with 1 CPU and a couple of devices takes 38ms and creates 16KB blob. This preloads strings with 40 property names from CPU and PCI device nodes and the strings lookup only searches within these. Without string reusing at all, the strings blob is 200KB and rendering time is 1.7sec; with unlimited reusing, the strings blob is 4KB and rendering time is 2.8sec. While we are here, fix the version handling in fdt-init. It only matters a little for the fdt-debug==1 case though. Signed-off-by: Alexey Kardashevskiy --- Changes: v3: * fixed stack handling after hcall returned * fixed format versions in both rendering and parsing paths * rebased on top of removed unused hvcalls * renamed used variables to have fdtfl- prefixes as there are already some for parsing the initial dt v2: * fixed comments from review * added strings cache * changed last_compat_vers from 0x17 to 0x16 as suggested by dwg --- I tested the blob by storing it from QEMU to a file and decompiling it; this produces error which I do not really understand as the name of the root is an empty string (literaly: 00 00 00 01 00 00 00 00) and yet this error: aik@fstn1-p1:~$ dtc -f -I dtb -O dts -o dbg.dts dbg.dtb ERROR (name_properties): "name" property in / is incorrect ("/" instead of base node name) Warning: Input tree has errors, output forced --- lib/libhvcall/libhvcall.h | 3 +- board-qemu/slof/fdt.fs | 284 +++++++++++++++++++++++++++++++++++++++++++++- board-qemu/slof/rtas.fs | 7 ++ lib/libhvcall/hvcall.code | 5 + lib/libhvcall/hvcall.in | 1 + 5 files changed, 297 insertions(+), 3 deletions(-) diff --git a/lib/libhvcall/libhvcall.h b/lib/libhvcall/libhvcall.h index 6356a62..3fa4398 100644 --- a/lib/libhvcall/libhvcall.h +++ b/lib/libhvcall/libhvcall.h @@ -24,7 +24,8 @@ #define KVMPPC_H_LOGICAL_MEMOP (KVMPPC_HCALL_BASE + 0x1) /* Client Architecture support */ #define KVMPPC_H_CAS (KVMPPC_HCALL_BASE + 0x2) -#define KVMPPC_HCALL_MAX KVMPPC_H_CAS +#define KVMPPC_H_UPDATE_DT (KVMPPC_HCALL_BASE + 0x3) +#define KVMPPC_HCALL_MAX KVMPPC_H_UPDATE_DT #ifndef __ASSEMBLY__ diff --git a/board-qemu/slof/fdt.fs b/board-qemu/slof/fdt.fs index 851645e..548cc25 100644 --- a/board-qemu/slof/fdt.fs +++ b/board-qemu/slof/fdt.fs @@ -27,7 +27,7 @@ struct 4 field >fdth_boot_cpu 4 field >fdth_string_size 4 field >fdth_struct_size -drop +constant /fdth h# d00dfeed constant OF_DT_HEADER h# 1 constant OF_DT_BEGIN_NODE @@ -69,7 +69,7 @@ fdt-start fdt-init dup >fdth_version l@ 3 >= IF ." strings size : 0x" dup >fdth_string_size l@ . cr THEN - dup >fdth_version l@ 17 >= IF + dup >fdth_version l@ 11 >= IF ." struct size : 0x" dup >fdth_struct_size l@ . cr THEN THEN @@ -439,4 +439,284 @@ r> drop fdt-cas-fix? ; +VARIABLE fdtfl-struct +VARIABLE fdtfl-struct-here +VARIABLE fdtfl-strings +VARIABLE fdtfl-strings-cache +VARIABLE fdtfl-strings-here +VARIABLE fdtfl-strings-reused \ debug only +VARIABLE fdt-ms \ debug only + +: fdt-skip-string ( cur -- cur ) + BEGIN + dup c@ + WHILE + 1+ + REPEAT + 4 + -4 and +; + +: zstring= ( str len zstr -- flag ) + 2dup + c@ 0<> IF + 3drop false + EXIT + THEN + swap comp 0= +; + +: fdt-find-string ( name namelen -- nameoff true | false ) + fdtfl-strings @ + BEGIN + dup fdtfl-strings-cache @ < + WHILE + 3dup zstring= IF + fdtfl-strings @ - + -rot + 2drop + true + EXIT + THEN + fdt-skip-string + REPEAT + 3drop + false +; + +: fdt-str-allot ( len -- ) fdtfl-strings-here @ + to fdtfl-strings-here ; +: fdt-str-c, ( char -- ) fdtfl-strings-here @ 1 fdt-str-allot c! ; +: fdt-str-align ( -- ) + fdtfl-strings-here @ + dup dup 4 #aligned swap - ( here bytes-to-erase ) + dup -rot + erase + fdt-str-allot +; +: fdt-str-bytes, ( data len -- ) fdtfl-strings-here @ over fdt-str-allot swap move ; +: fdt-str-ztr, ( str len -- ) fdt-str-bytes, 0 fdt-str-c, ; + +: fdt-add-string ( name namelen -- nameoff ) + fdtfl-strings-here @ -rot + fdt-str-ztr, + fdt-str-align + fdtfl-strings @ - +; + +: fdt-get-string ( name namelen -- nameoff ) + 2dup fdt-find-string IF + -rot 2drop + fdt-debug IF + 1 fdtfl-strings-reused +! + THEN + EXIT + THEN + fdt-add-string +; + +: fdt-allot ( len -- ) fdtfl-struct-here @ + to fdtfl-struct-here ; +: fdt-c, ( char -- ) fdtfl-struct-here @ 1 fdt-allot c! ; +: fdt-align ( -- ) + fdtfl-struct-here @ + dup dup 4 #aligned swap - ( here bytes-to-erase ) + dup -rot + erase + fdt-allot +; +: fdt-bytes, ( data len -- ) fdtfl-struct-here @ over fdt-allot swap move ; +: fdt-ztr, ( str len -- ) fdt-bytes, 0 fdt-c, ; +: fdt-l, ( token -- ) fdtfl-struct-here @ l! /l fdt-allot ; + +: fdt-begin-node ( name namelen -- ) + OF_DT_BEGIN_NODE fdt-l, + 2dup 1 = swap c@ [char] / = and \ is it "/"? + IF + 2drop s" " \ dtc is still unhappy though + THEN + fdt-ztr, + fdt-align +; + +: fdt-end-node ( -- ) OF_DT_END_NODE fdt-l, ; + +: fdt-prop ( prop len name namelen -- ) + OF_DT_PROP fdt-l, + + \ get string offset + fdt-get-string ( prop len nameoff ) + + \ store len and nameoff + over fdt-l, + fdt-l, ( prop len ) + + \ now store the bytes + fdt-bytes, + fdt-align +; + +: fdt-end ( -- ) OF_DT_END fdt-l, ; + +: fdt-properties ( phandle -- ) + dup encode-int s" phandle" fdt-prop + >r + s" " + BEGIN + r@ next-property + WHILE + 2dup + 2dup r@ get-property + not IF + 2swap fdt-prop + THEN + REPEAT + r> + drop +; + +: fdt-flatten-node ( node -- ) + fdt-debug 1 > IF dup node>path type cr THEN + dup node>qname fdt-begin-node + dup fdt-properties + child + BEGIN + dup + WHILE + dup recurse + peer + REPEAT + drop + fdt-end-node +; + +: fdtfl-strings-preload ( -- ) + s" reg" fdt-add-string drop + s" status" fdt-add-string drop + s" 64-bit" fdt-add-string drop + s" phandle" fdt-add-string drop + s" ibm,vmx" fdt-add-string drop + s" ibm,dfp" fdt-add-string drop + s" slb-size" fdt-add-string drop + s" ibm,purr" fdt-add-string drop + s" vendor-id" fdt-add-string drop + s" device-id" fdt-add-string drop + s" min-grant" fdt-add-string drop + s" class-code" fdt-add-string drop + s" compatible" fdt-add-string drop + s" interrupts" fdt-add-string drop + s" cpu-version" fdt-add-string drop + s" #size-cells" fdt-add-string drop + s" ibm,req#msi" fdt-add-string drop + s" revision-id" fdt-add-string drop + s" device_type" fdt-add-string drop + s" max-latency" fdt-add-string drop + s" ibm,chip-id" fdt-add-string drop + s" ibm,pft-size" fdt-add-string drop + s" ibm,slb-size" fdt-add-string drop + s" devsel-speed" fdt-add-string drop + s" ibm,loc-code" fdt-add-string drop + s" subsystem-id" fdt-add-string drop + s" d-cache-size" fdt-add-string drop + s" i-cache-size" fdt-add-string drop + s" #address-cells" fdt-add-string drop + s" clock-frequency" fdt-add-string drop + s" cache-line-size" fdt-add-string drop + s" ibm,pa-features" fdt-add-string drop + s" ibm,my-drc-index" fdt-add-string drop + s" d-cache-line-size" fdt-add-string drop + s" i-cache-line-size" fdt-add-string drop + s" assigned-addresses" fdt-add-string drop + s" d-cache-block-size" fdt-add-string drop + s" i-cache-block-size" fdt-add-string drop + s" timebase-frequency" fdt-add-string drop + s" subsystem-vendor-id" fdt-add-string drop + s" ibm,segment-page-sizes" fdt-add-string drop + s" ibm,ppc-interrupt-server#s" fdt-add-string drop + s" ibm,processor-segment-sizes" fdt-add-string drop + s" ibm,ppc-interrupt-gserver#s" fdt-add-string drop +; + +: fdt-append-blob ( bytes cur blob -- cur ) + 3dup -rot swap move + drop + +; + +: fdt-flatten-tree ( root -- tree ) + 200000 alloc-mem dup fdtfl-struct-here ! fdtfl-struct ! + 200000 alloc-mem dup fdtfl-strings-here ! fdtfl-strings ! + + fdt-debug IF + 0 fdtfl-strings-reused ! + milliseconds fdt-ms ! + THEN + + \ Preload strings cache + fdtfl-strings-preload + fdtfl-strings-here @ fdtfl-strings-cache ! + \ Render the blobs + fdt-flatten-node + fdt-end + + \ Calculate strings and struct sizes + fdtfl-struct-here @ fdtfl-struct @ - + fdtfl-strings-here @ fdtfl-strings @ - ( struct-len strings-len ) + + 2dup + /fdth + + 10 + \ Reserve 16 bytes and an empty reserved block + + fdt-debug IF + 3dup + ." FDT flat size=" .d cr + ." Strings size=" .d cr + ." Struct size=" .d cr + ." Reused strings=" fdtfl-strings-reused @ .d cr + milliseconds fdt-ms @ - + ." Took " .d ." ms" cr + THEN + + \ Allocate flatten DT blob + dup alloc-mem ( struct-len strings-len total-len fdt ) + >r ( struct-len strings-len total-len r: fdt ) + + \ Write header + OF_DT_HEADER r@ >fdth_magic l! + dup r@ >fdth_tsize l! + /fdth 10 + 2 pick + r@ >fdth_struct_off l! + /fdth 10 + r@ >fdth_string_off l! + /fdth r@ >fdth_rsvmap_off l! + 11 r@ >fdth_version l! + 10 r@ >fdth_compat_vers l! + 0 r@ >fdth_boot_cpu l! + over r@ >fdth_string_size l! + 2 pick r@ >fdth_struct_size l! + ( struct-len strings-len total-len r: fdt ) + + drop ( struct-len strings-len r: fdt ) + r@ /fdth + ( struct-len strings-len cur r: fdt ) + + \ Write the reserved entry + 0 over ! + cell+ + 0 over ! + cell+ ( struct-len strings-len cur r: fdt ) + + \ Write strings and struct blobs + fdtfl-strings @ fdt-append-blob + fdtfl-struct @ fdt-append-blob + drop + + \ Free temporary blobs + fdtfl-struct @ 200000 free-mem + fdtfl-strings @ 200000 free-mem + + \ Return fdt + r> +; + +: fdt-flatten-tree-free ( tree ) + dup >fdth_tsize l@ free-mem +; + +: fdt ( -- ) + " /" find-node + fdt-flatten-tree +; + s" /" find-node fdt-fix-phandles diff --git a/board-qemu/slof/rtas.fs b/board-qemu/slof/rtas.fs index b17157e..219bcda 100644 --- a/board-qemu/slof/rtas.fs +++ b/board-qemu/slof/rtas.fs @@ -98,6 +98,13 @@ find-qemu-rtas ; : rtas-quiesce ( -- ) + " /" find-node + fdt-flatten-tree + dup hv-update-dt ?dup IF + \ Ignore hcall not implemented error, print error otherwise + dup -2 <> IF ." HV-UPDATE-DT error: " . cr ELSE drop THEN + THEN + fdt-flatten-tree-free " quiesce" rtas-get-token rtas-cb rtas>token l! 0 rtas-cb rtas>nargs l! 0 rtas-cb rtas>nret l! diff --git a/lib/libhvcall/hvcall.code b/lib/libhvcall/hvcall.code index 744469f..5918c90 100644 --- a/lib/libhvcall/hvcall.code +++ b/lib/libhvcall/hvcall.code @@ -123,3 +123,8 @@ PRIM(check_X2d_and_X2d_patch_X2d_sc1) patch_broken_sc1((void*)start, (void*)end, (void*)patch_ins); MIRP + +PRIM(hv_X2d_update_X2d_dt) + unsigned long dt = TOS.u; + TOS.u = hv_generic(KVMPPC_H_UPDATE_DT, dt); +MIRP diff --git a/lib/libhvcall/hvcall.in b/lib/libhvcall/hvcall.in index e99d6d1..9193162 100644 --- a/lib/libhvcall/hvcall.in +++ b/lib/libhvcall/hvcall.in @@ -30,4 +30,5 @@ cod(RX!) cod(hv-logical-memop) cod(hv-cas) +cod(hv-update-dt) cod(get-print-version)