From patchwork Tue Oct 24 01:31:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 829754 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 3yLbNy0Q5xz9s83 for ; Tue, 24 Oct 2017 12:32:34 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yLbNx6GY7zDqkj for ; Tue, 24 Oct 2017 12:32:33 +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 3yLbNv1JCczDqZ3 for ; Tue, 24 Oct 2017 12:32:31 +1100 (AEDT) Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 7E38A3A60021; Mon, 23 Oct 2017 21:30:50 -0400 (EDT) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Tue, 24 Oct 2017 12:31:48 +1100 Message-Id: <20171024013153.28200-2-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171024013153.28200-1-aik@ozlabs.ru> References: <20171024013153.28200-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof v6 1/6] tree: Rework set-chosen-cpu and store /chosen ihandle and phandle 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: Greg Kurz MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" This replaces current set-chosen-cpu with a cleaner and faster implementation which does not clobber the current node and stores the chosen CPU phandle/ihandle. This adds a helper to get the chosen CPU unit address. This moves chosen cpu words to root.fs as otherwise it is quite hard to maintain dependencies. Signed-off-by: Alexey Kardashevskiy Reviewed-by: Segher Boessenkool --- board-qemu/slof/tree.fs | 6 ------ slof/fs/root.fs | 11 +++++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/board-qemu/slof/tree.fs b/board-qemu/slof/tree.fs index cc35fa3..d95fde3 100644 --- a/board-qemu/slof/tree.fs +++ b/board-qemu/slof/tree.fs @@ -155,12 +155,6 @@ populate-pci-busses 6c0 cp -\ Do not assume that cpu0 is available -: set-chosen-cpu - " /cpus" find-device - get-node child dup 0= ABORT" CPU not found" - node>path open-dev encode-int s" cpu" set-chosen -; set-chosen-cpu s" /memory@0" open-dev encode-int s" memory" set-chosen diff --git a/slof/fs/root.fs b/slof/fs/root.fs index 44d087a..3818790 100644 --- a/slof/fs/root.fs +++ b/slof/fs/root.fs @@ -33,6 +33,17 @@ defer continue-client : get-chosen ( name len -- [ prop len ] success ) chosen get-property 0= ; +\ Do not assume that cpu0 is available +VARIABLE chosen-cpu-ihandle +: set-chosen-cpu ( -- ) + s" /cpus" find-node dup 0= ABORT" /cpus not found" + child dup 0= ABORT" /cpus/cpu not found" + 0 0 rot open-node + dup chosen-cpu-ihandle ! encode-int s" cpu" set-chosen +; + +: chosen-cpu-unit ( -- ret ) chosen-cpu-ihandle @ ihandle>phandle >unit ; + \ Look for an exising root, create one if needed " /" find-node dup 0= IF drop From patchwork Tue Oct 24 01:31:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 829755 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 3yLbP04kzYz9s83 for ; Tue, 24 Oct 2017 12:32:36 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yLbP03QYCzDqmQ for ; Tue, 24 Oct 2017 12:32:36 +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 3yLbNw74G7zDqZ3 for ; Tue, 24 Oct 2017 12:32:32 +1100 (AEDT) Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id B62653A6003E; Mon, 23 Oct 2017 21:30:52 -0400 (EDT) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Tue, 24 Oct 2017 12:31:49 +1100 Message-Id: <20171024013153.28200-3-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171024013153.28200-1-aik@ozlabs.ru> References: <20171024013153.28200-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof v6 2/6] fdt: Fix version and add a word for FDT header size 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: Greg Kurz MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" This fixes the version handling in fdt-init. It only matters a little for the fdt-debug==1 case though. This defines /fdth word for the FDT header size; this will be used in the next patch. Signed-off-by: Alexey Kardashevskiy Reviewed-by: Greg Kurz --- board-qemu/slof/fdt.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/board-qemu/slof/fdt.fs b/board-qemu/slof/fdt.fs index 851645e..8e8921f 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 From patchwork Tue Oct 24 01:31:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 829750 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 3yLbNV5xxPz9s3w for ; Tue, 24 Oct 2017 12:32:10 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yLbNV4nVjzDqkm for ; Tue, 24 Oct 2017 12:32:10 +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 3yLbNN2vxczDqZ3 for ; Tue, 24 Oct 2017 12:32:04 +1100 (AEDT) Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 8FE053A6004B; Mon, 23 Oct 2017 21:30:54 -0400 (EDT) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Tue, 24 Oct 2017 12:31:50 +1100 Message-Id: <20171024013153.28200-4-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171024013153.28200-1-aik@ozlabs.ru> References: <20171024013153.28200-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof v6 3/6] 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: Greg Kurz 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. This preloads strings with 40 property names from CPU and PCI device nodes and the strings lookup only searches within these. Test results on a guest with 256 CPUs and 256 virtual Intel E1000 devices running on a POWER8 box: FDTsize=366024 Strings=15888 Struct=350080 Reused str=12457 242 ms A simple guest (one CPU, no PCI) with this patch as is: FDTsize=15940 Strings=3148 Struct=12736 Reused str=84 7 ms 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: v6: * fix memory sizes for free-mem * store correct chosen-cpu to the header (used to be just 0) * fdt-skip-string uses zcount now and works 30% faster * moved to a new file - fdt-fl.fs v5: * applied latest comments from Segher * s/fdt-property/fdt-copy-property/, s/fdt-properties/fdt-copy-properties/ * reduced the temporary buffers to 1MB each as the guest uses 1MB in total anyway * do not pass root phandle to fdt-flatten-tree, it fetches it from device-tree itself * reworked fdt-copy-properties to use for-all-words proposed by Segher v4: * reworked fdt-properties, works lot faster * do not store "name" properties as nodes have names already 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. --- lib/libhvcall/libhvcall.h | 3 +- board-qemu/slof/OF.fs | 2 + board-qemu/slof/fdt-fl.fs | 266 ++++++++++++++++++++++++++++++++++++++++++++++ board-qemu/slof/rtas.fs | 6 ++ lib/libhvcall/hvcall.code | 5 + lib/libhvcall/hvcall.in | 1 + 6 files changed, 282 insertions(+), 1 deletion(-) create mode 100644 board-qemu/slof/fdt-fl.fs 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/OF.fs b/board-qemu/slof/OF.fs index 4e04b84..35fe233 100644 --- a/board-qemu/slof/OF.fs +++ b/board-qemu/slof/OF.fs @@ -119,6 +119,8 @@ check-boot-menu 380 cp +#include "fdt-fl.fs" + \ Grab rtas from qemu #include "rtas.fs" diff --git a/board-qemu/slof/fdt-fl.fs b/board-qemu/slof/fdt-fl.fs new file mode 100644 index 0000000..71b2efc --- /dev/null +++ b/board-qemu/slof/fdt-fl.fs @@ -0,0 +1,266 @@ +\ ***************************************************************************** +\ * Copyright (c) 2017 IBM Corporation +\ * All rights reserved. +\ * This program and the accompanying materials +\ * are made available under the terms of the BSD License +\ * which accompanies this distribution, and is available at +\ * http://www.opensource.org/licenses/bsd-license.php +\ ****************************************************************************/ + +0 VALUE fdtfl-debug + +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 fdlfl-ms \ debug only + +: fdt-skip-string ( cur -- cur ) zcount + char+ 4 #aligned ; + +: 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 + nip nip ( curstr ) + fdtfl-strings @ - + 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 + fdtfl-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 ( phandle -- ) + OF_DT_BEGIN_NODE fdt-l, + dup device-tree @ = IF drop s" " ELSE node>qname 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-copy-property ( link -- ) + dup link> execute + rot + link>name name>string + 2dup s" name" str= IF 4drop EXIT THEN \ skipping useless "name" + fdt-prop +; + +: for-all-words ( wid xt -- ) \ xt has sig ( lfa -- ) + >r + cell+ @ BEGIN dup WHILE dup r@ execute @ REPEAT + r> 2drop +; + +: fdt-copy-properties ( phandle -- ) + dup encode-int s" phandle" fdt-prop + node>properties @ + ['] fdt-copy-property for-all-words +; + +: fdt-copy-node ( node -- ) + fdtfl-debug 1 > IF dup node>path type cr THEN + dup fdt-begin-node + dup fdt-copy-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 ( -- tree ) + 100000 alloc-mem dup fdtfl-struct-here ! fdtfl-struct ! + 100000 alloc-mem dup fdtfl-strings-here ! fdtfl-strings ! + + fdtfl-debug IF + 0 fdtfl-strings-reused ! + milliseconds fdlfl-ms ! + THEN + + \ Preload strings cache + fdtfl-strings-preload + fdtfl-strings-here @ fdtfl-strings-cache ! + \ Render the blobs + device-tree @ fdt-copy-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 for an empty reserved block + + fdtfl-debug IF + 3dup + ." FDTsize=" .d ." Strings=" .d ." Struct=" .d + ." Reused str=" fdtfl-strings-reused @ .d + milliseconds fdlfl-ms @ - .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! + chosen-cpu-unit 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+ + + \ Write strings and struct blobs + fdtfl-strings @ fdt-append-blob + fdtfl-struct @ fdt-append-blob + drop + + \ Free temporary blobs + fdtfl-struct @ 100000 free-mem + fdtfl-strings @ 100000 free-mem + + \ Return fdt + r> +; + +: fdt-flatten-tree-free ( tree ) + dup >fdth_tsize l@ free-mem +; diff --git a/board-qemu/slof/rtas.fs b/board-qemu/slof/rtas.fs index b17157e..f1a4abe 100644 --- a/board-qemu/slof/rtas.fs +++ b/board-qemu/slof/rtas.fs @@ -98,6 +98,12 @@ find-qemu-rtas ; : rtas-quiesce ( -- ) + 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) From patchwork Tue Oct 24 01:31:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 829751 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 3yLbNY5d1bz9sNx for ; Tue, 24 Oct 2017 12:32:13 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yLbNY3bkwzDqlH for ; Tue, 24 Oct 2017 12:32:13 +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 3yLbNP5l3tzDqZ3 for ; Tue, 24 Oct 2017 12:32:05 +1100 (AEDT) Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 66E923A60050; Mon, 23 Oct 2017 21:30:56 -0400 (EDT) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Tue, 24 Oct 2017 12:31:51 +1100 Message-Id: <20171024013153.28200-5-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171024013153.28200-1-aik@ozlabs.ru> References: <20171024013153.28200-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof v6 4/6] board-qemu: Fix slof-build-id length 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: Greg Kurz MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" The existing code hardcodes the length of /openprom/model to 10 characters even though it is less than that - len("aik")==3. All 10 chars go to the device tree blob and DTC complains on such a property as there are characters after terminating null: aik@fstn1-p1:~$ dtc -f -I dtb -O dts -o dbg.dts dbg.dtb Warning (model_is_string): "model" property in /openprom is not a string This uses the real length and limits it by 10 to avoid breaking something. Since the same code parses the build id field, this moves from-cstring to a common place for both js2x and qemu boards. Signed-off-by: Alexey Kardashevskiy --- board-js2x/slof/helper.fs | 2 +- board-qemu/slof/helper.fs | 8 +------- slof/fs/base.fs | 5 +++++ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/board-js2x/slof/helper.fs b/board-js2x/slof/helper.fs index c522c90..d2f19e6 100644 --- a/board-js2x/slof/helper.fs +++ b/board-js2x/slof/helper.fs @@ -11,7 +11,7 @@ \ ****************************************************************************/ : slof-build-id ( -- str len ) - flash-header 10 + a + flash-header 10 + dup from-cstring a min ; : slof-revision s" 001" ; diff --git a/board-qemu/slof/helper.fs b/board-qemu/slof/helper.fs index 40d4abc..4b2c1ee 100644 --- a/board-qemu/slof/helper.fs +++ b/board-qemu/slof/helper.fs @@ -11,7 +11,7 @@ \ ****************************************************************************/ : slof-build-id ( -- str len ) - flash-header 10 + a + flash-header 10 + dup from-cstring a min ; : slof-revision s" 001" ; @@ -27,12 +27,6 @@ bdate2human $cat encode-string THEN ; -\ Fetch C string -: from-cstring ( addr - len ) - dup dup BEGIN c@ 0 <> WHILE 1 + dup REPEAT - swap - -; - : invert-region-cs ( addr len cellsize -- ) >r over swap r@ rshift r> swap 1 hv-logical-memop drop ; diff --git a/slof/fs/base.fs b/slof/fs/base.fs index 0aca5f5..e2104fb 100644 --- a/slof/fs/base.fs +++ b/slof/fs/base.fs @@ -107,6 +107,11 @@ CONSTANT <2constant> : str= ( str1 len1 str2 len2 -- equal? ) rot over <> IF 3drop false ELSE comp 0= THEN ; +: from-cstring ( addr - len ) + dup dup BEGIN c@ 0 <> WHILE 1 + dup REPEAT + swap - +; + : test-string ( param len -- true | false ) 0 ?DO dup i + c@ \ Get character / byte at current index From patchwork Tue Oct 24 01:31:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 829752 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 3yLbNb5gryz9s3w for ; Tue, 24 Oct 2017 12:32:15 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yLbNb4rMrzDql4 for ; Tue, 24 Oct 2017 12:32:15 +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 3yLbNS3Sd7zDqln for ; Tue, 24 Oct 2017 12:32:08 +1100 (AEDT) Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 3E7523A60054; Mon, 23 Oct 2017 21:30:58 -0400 (EDT) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Tue, 24 Oct 2017 12:31:52 +1100 Message-Id: <20171024013153.28200-6-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171024013153.28200-1-aik@ozlabs.ru> References: <20171024013153.28200-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof v6 5/6] rtas: Store RTAS address and entry in the device tree 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: Greg Kurz MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" At the moment we count on the guest kernel to update or create device tree properties pointing to the instantiated RTAS copy which is not very reliable. This stores rtas-base and rtas-size in the DT at the instantiation point so later on the H_UPDATE_DT hcall can supply QEMU with an updated location of RTAS. This superseeds f9a60de30 "Add private HCALL to inform updated RTAS base and entry". Signed-off-by: Alexey Kardashevskiy --- Changes: v5: * ditched rtas-entry, added rtas-size (which is always 20 bytes though) --- board-qemu/slof/rtas.fs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/board-qemu/slof/rtas.fs b/board-qemu/slof/rtas.fs index f1a4abe..092f5b1 100644 --- a/board-qemu/slof/rtas.fs +++ b/board-qemu/slof/rtas.fs @@ -176,7 +176,14 @@ rtas-node set-node : open true ; : close ; +: store-rtas-loc ( adr ) + s" /rtas" find-node >r + encode-int s" slof,rtas-base" r@ set-property + rtas-size encode-int s" slof,rtas-size" r> set-property +; + : instantiate-rtas ( adr -- entry ) + dup store-rtas-loc dup rtas-base swap rtas-size move rtas-entry rtas-base - + ; From patchwork Tue Oct 24 01:31:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 829753 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 3yLbNd6j6Fz9sPm for ; Tue, 24 Oct 2017 12:32:17 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yLbNd4B8SzDqlT for ; Tue, 24 Oct 2017 12:32:17 +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 3yLbNV0s2XzDqln for ; Tue, 24 Oct 2017 12:32:10 +1100 (AEDT) Received: from vpl1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 7C8143A600A2; Mon, 23 Oct 2017 21:31:00 -0400 (EDT) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Tue, 24 Oct 2017 12:31:53 +1100 Message-Id: <20171024013153.28200-7-aik@ozlabs.ru> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171024013153.28200-1-aik@ozlabs.ru> References: <20171024013153.28200-1-aik@ozlabs.ru> Subject: [SLOF] [PATCH slof v6 6/6] fdt: Implement "fdt-fetch" method for client interface 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: Greg Kurz MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" The guest kernel fetches the device tree via the client interface, calling it for every node and property, and traversing the entire tree twice - first to build strings blob, second - to build struct blob. On top of that there is also not so efficient implementation of the "getprop" method - it calls slow "get-property" which does full search for a property. As the result, on a 256 CPU + 256 Intel E1000 virtual devices, the guest's flatten_device_tree() takes roughly 8.5sec. However now we have a FDT rendering helper in SLOF which takes about 350ms to render the FDT. This implements a client interface call to allow the guest to read it during early boot and save time. The produced DTB is almost the same as the guest kernel would have produced itself - the differences are: 1. SLOF creates an empty reserved map; the guest can easily fix it up later; 2. SLOF only reuses 40 most popular strings; the guest reuses everything it can - on a 256CPU + 256 PCI devices guest, the difference is about 20KB for 350KB FDT blob. Note, that the guest also ditches the "name" property just like SLOF does: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/kernel/prom_init.c?h=v4.13#n2302 Signed-off-by: Alexey Kardashevskiy --- If the guest tries "fdt-fetch" and SLOF does not have it, than SLOF prints an error: === copying OF device tree... fdt-fetch NOT FOUNDBuilding dt strings... Building dt structure... === and the guest continues with the old method. We could suppress SLOF error for such unlikely situation though. --- slof/fs/client.fs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/slof/fs/client.fs b/slof/fs/client.fs index 7d537a6..8a7f6ac 100644 --- a/slof/fs/client.fs +++ b/slof/fs/client.fs @@ -308,4 +308,20 @@ ALSO client-voc DEFINITIONS : set-callback ( newfunc -- oldfunc ) client-callback @ swap client-callback ! ; +\ Custom method to get FDT blob +: fdt-fetch ( buf len -- ret ) + fdt-flatten-tree ( buf len dtb ) + dup >r + >fdth_tsize l@ ( buf len size r: dtb ) + 2dup < IF + ." ERROR: need " .d ." bytes, the buffer is " .d ." bytes only" cr + drop + -1 + ELSE + nip r@ -rot move + 0 + THEN + r> fdt-flatten-tree-free +; + PREVIOUS DEFINITIONS