diff mbox series

[v8,02/11] skiboot.tcl: ultravisor support

Message ID 20200826183749.143980-3-grimm@linux.ibm.com
State Changes Requested
Headers show
Series Ultravisor support in skiboot | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch master (abe4c4799ffee4be12674ad59fc0bc521b0724f3)
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot-dco success Signed-off-by present

Commit Message

Ryan Grimm Aug. 26, 2020, 6:37 p.m. UTC
This tcl code turns on the S bit in MSR and sets up SMFCTRL and SIM_CTRL
if MAMBO_ENABLE_SMF is set.  Skiboot will run its exit_uv_mode function
because there's no ibm,utlravisor device tree node.

If ULTRA_IMAGE is set, it loads the image at 0xc0000000 and sets up the
ibm,ultravisor device tree node.

This can be tested using this (hacked) skiboot as the ultravisor image
with:

export SKIBOOT=skiboot.lid
export ULTRA_IMAGE=$SKIBOOT
export ULTRA_ENTRY=$(grep exit_uv_mode skiboot.map|cut -f1 -d " ")
export MAMBO_ENABLE_SMF=1

Although you need to hack up exit_uv_mode to ignore the fdt pointer and
treat as primary thread.

Signed-off-by: Ryan Grimm <grimm@linux.ibm.com>
---
 external/mambo/skiboot.tcl | 74 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 73 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/external/mambo/skiboot.tcl b/external/mambo/skiboot.tcl
index 6003fcbe..c823985a 100644
--- a/external/mambo/skiboot.tcl
+++ b/external/mambo/skiboot.tcl
@@ -56,6 +56,16 @@  if { ![info exists env(SKIBOOT_ZIMAGE)] } {
 }
 mconfig payload PAYLOAD $env(SKIBOOT_ZIMAGE)
 
+mconfig enable_smf MAMBO_ENABLE_SMF none
+
+mconfig ultra_image ULTRA_IMAGE none
+
+mconfig ultra_src_addr ULTRA_SRC_ADDR 0xc0000000;
+
+mconfig spr_urmor ULTRA_URMOR 0xe0000000
+
+mconfig ultra_entry ULTRA_ENTRY 0;
+
 mconfig linux_cmdline LINUX_CMDLINE ""
 
 # Paylod: Memory location for a Linux style ramdisk/initrd
@@ -140,6 +150,11 @@  if { $default_config == "P9" } {
     if { $mconf(numa) } {
         myconf config memory_region_id_shift 45
     }
+
+    if { $mconf(enable_smf) != "none" } {
+        myconf config processor/initial/SMFCTRL 0x8000000000000002
+        myconf config processor/initial/SIM_CTRL1 0x4228100404004000
+    }
 }
 
 if { $mconf(numa) } {
@@ -507,12 +522,16 @@  for { set c 0 } { $c < $mconf(cpus) } { incr c } {
 	mysim mcm 0 cpu $c thread $t set spr pir $pir
 	lappend irqreg $pir
 	incr pir
+	if { $mconf(enable_smf) != "none" } {
+	    mysim mcm 0 cpu $c thread $t set spr msr 0x9000000000400000
+       }
     }
     mysim of addprop $cpu_node array "ibm,ppc-interrupt-server#s" irqreg
 }
 
 #Add In-Memory Collection Counter nodes
-if { $default_config == "P9" } {
+#if { $default_config == "P9" && $mconf(enable_ultra) == "none" } {
+if { $default_config == "P9" && $mconf(ultra_image) == "none" } {
    #Add the base node "imc-counters"
    set imc_c [mysim of addchild $root_node "imc-counters" ""]
    mysim of addprop $imc_c string "compatible" "ibm,opal-in-memory-counters"
@@ -669,6 +688,59 @@  if { [info exists env(SKIBOOT_ENABLE_MAMBO_STB)] } {
     }
 }
 
+if {$mconf(ultra_image) != "none"} {
+    set uv_node [ mysim of addchild $root_node "ibm,ultravisor" "" ]
+    mysim of addprop $uv_node string "compatible" "ibm,ultravisor"
+    mysim of addprop $uv_node int "#address-cells" 2
+    mysim of addprop $uv_node int "#size-cells" 2
+
+    set uv_fw_node [ mysim of addchild $uv_node "firmware" "" ]
+    mysim of addprop $uv_fw_node string "compatible" "ibm,uv-firmware"
+    set uv_entry $mconf(ultra_entry)
+    set uv_entry_prop [ list [expr $uv_entry >> 32] [expr $uv_entry & 0xffffffff] ]
+    mysim of addprop $uv_fw_node array "uv-entry" uv_entry_prop
+
+    set range [list]
+    lappend range $mconf(spr_urmor)
+    lappend range [expr  [mysim display memory_size] - $mconf(spr_urmor)]
+    mysim of addprop  $uv_fw_node array64 "secure-memory-ranges" range
+
+
+    set start $mconf(spr_urmor)
+
+    if {[file exists $mconf(ultra_image)]} {
+        set ultra_file $mconf(ultra_image)
+    } else {
+        puts "ERROR: Could not find ultra: $mconf(ultra_image)"
+        exit
+    }
+
+    set ultra_size [file size $ultra_file]
+    set reg [list [expr $start >> 32] [expr $start & 0xffffffff] [expr $ultra_size >> 32] [expr $ultra_size & 0xffffffff]]
+    mysim of addprop $uv_fw_node array "reg" reg
+
+    #secure-memory node
+    set start_hex [format %x $start]
+    set size [expr [mysim display memory_size] - $mconf(spr_urmor)]
+    set secure_mem_node [mysim of addchild $root_node "secure-memory@$start_hex" ""]
+    mysim of addprop $secure_mem_node string "compatible" "ibm,secure-memory"
+    set reg [list [expr $start >> 32] [expr $start & 0xffffffff] [expr $size >> 32] [expr $size & 0xffffffff]]
+    mysim of addprop $secure_mem_node array "reg" reg
+    mysim of addprop $secure_mem_node string "device_type" "secure-memory"
+    set associativity [list 4 0 0 0 0]
+    mysim of addprop $secure_mem_node "array" "ibm,associativity" associativity
+    set chip_id [format %x 0]
+    mysim of addprop $secure_mem_node array "ibm,chip-id" chip_id
+
+    set src_addr $mconf(ultra_src_addr)
+    mysim memory fread $src_addr $ultra_size $ultra_file
+
+    set uv_firmware [mysim of addchild $reserved_memory "ibm,uv-firmware" ""]
+    set reg [list $src_addr $ultra_size]
+    mysim of addprop $uv_firmware array64 "reg" reg
+    mysim of addprop $uv_firmware empty "name" "ibm,uv-firmware"
+}
+
 # Kernel command line args, appended to any from the device tree
 # e.g.: of::set_bootargs "xmon"
 #