powerpc/powernv: Add OPAL takeover from PowerVM
PATCH 8/20 powerpc/powernv: Add OPAL takeover from PowerVM
On machines supporting the OPAL firmware version 1, the system is initially booted under pHyp. We then use a special hypercall to verify if OPAL is available and if it is, we then trigger a "takeover" which disables pHyp and loads the OPAL runtime firmware, giving control to the kernel in hypervisor mode.
This patch add the necessary code to detect that the OPAL takeover capability is present when running under PowerVM (aka pHyp) and perform said takeover to get hypervisor control of the processor.
To perform the takeover, we must first use RTAS (within Open Firmware runtime environment) to start all processors & threads, in order to give control to OPAL on all of them. We then call the takeover hypercall on everybody, OPAL will re-enter the kernel main entry point passing it a flat device-tree.
--- arch/powerpc/include/asm/opal.h | 50 +++++ arch/powerpc/kernel/head_64.S | 4 + arch/powerpc/kernel/prom_init.c | 239 ++++++++++++++++++++++-- arch/powerpc/kernel/prom_init_check.sh | 3 +- arch/powerpc/platforms/powernv/Makefile | 2 +- arch/powerpc/platforms/powernv/opal-takeover.S | 140 ++++++++++++++ 6 files changed, 419 insertions(+), 19 deletions(-) create mode 100644 arch/powerpc/include/asm/opal.h create mode 100644 arch/powerpc/platforms/powernv/opal-takeover.S
arch/powerpc/include/asm/opal.h new file +50 -0
@@ -0,0 +1,50 @@ +/* +* PowerNV OPAL definitions. +* +* Copyright 2011 IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#ifndef __OPAL_H +#define __OPAL_H + +/****** Takeover interface ********/ + +/* PAPR H-Call used to querty the HAL existence and/or instanciate +* it from within pHyp (tech preview only). +* +* This is exclusively used in prom_init.c +*/ + +#ifndef __ASSEMBLY__ + +struct opal_takeover_args { +u64 k_image;/* r4 */ +u64 k_size;/* r5 */ +u64 k_entry;/* r6 */ +u64 k_entry2;/* r7 */ +u64 hal_addr;/* r8 */ +u64 rd_image;/* r9 */ +u64 rd_size;/* r10 */ +u64 rd_loc;/* r11 */ +}; + +extern long opal_query_takeover (u64 *hal_size,u64 *hal_align); + +extern long opal_do_takeover (struct opal_takeover_args *args); + +extern int opal_enter_rtas (struct rtas_args *args, +unsigned long data, +unsigned long entry); + + +#endif /* __ASSEMBLY__ */ + +/****** OPAL APIs ******/ + + +#endif /* __OPAL_H */
arch/powerpc/kernel/head_64.S +4 -0
@@ -51,6 +51,10 @@ * For pSeries or server processors: * 1. The MMU is off & open firmware is running in real mode. * 2. The kernel is entered at __start + * -or- For OPAL entry: + * 1. The MMU is off, processor in HV mode, primary CPU enters at 0 + * with device-tree in gpr3 + * 2. Secondary processors enter at 0x60 with PIR in gpr3 * * For iSeries: * 1. The MMU is on (as it always is for iSeries)
arch/powerpc/kernel/prom_init.c +222 -17
302 lines not on this page · raw message
arch/powerpc/kernel/prom_init_check.sh +2 -1
@@ -20,7 +20,8 @@ WHITELIST="add_reloc_offset __bss_start __bss_stop copy_and_flush _end enter_prom memcpy memset reloc_offset __secondary_hold __secondary_hold_acknowledge __secondary_hold_spinloop __start strcmp strcpy strlcpy strlen strncmp strstr logo_linux_clut224 -reloc_got2 kernstart_addr memstart_addr linux_banner" +reloc_got2 kernstart_addr memstart_addr linux_banner _stext +opal_query_takeover opal_do_takeover opal_enter_rtas opal_secondary_entry" NM="$1" OBJ="$2"
arch/powerpc/platforms/powernv/Makefile +1 -1
@@ -1,2 +1,2 @@ -obj-y += setup.o +obj-y += setup.o opal-takeover.o obj-$(CONFIG_SMP) += smp.o
arch/powerpc/platforms/powernv/opal-takeover.S new file +140 -0
140 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 11/20 powerpc/powernv: Add support for instanciating OPAL v2 from Open Firmware
OPAL v2 is instantiated in a way similar to RTAS using Open Firmware client interface calls, and the resulting address and entry point are put in the device-tree
--- arch/powerpc/kernel/prom_init.c | 136 +++++++++++++++++++++++++++++++++------ 1 files changed, 117 insertions(+), 19 deletions(-)
arch/powerpc/kernel/prom_init.c +117 -19
@@ -140,7 +140,9 @@ struct mem_map_entry {typedef u32 cell_t ; -extern void __start (unsigned long r3,unsigned long r4,unsigned long r5); +extern void __start (unsigned long r3,unsigned long r4,unsigned long r5, +unsigned long r6,unsigned long r7,unsigned long r8, +unsigned long r9);#ifdef CONFIG_PPC64 extern int enter_prom (struct prom_args *args,unsigned long entry);
@@ -1293,6 +1295,11 @@ static int __initdata prom_rtas_start_cpu;static u64 __initdata prom_rtas_data;static u64 __initdata prom_rtas_entry; +#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL +static u64 __initdata prom_opal_base; +static u64 __initdata prom_opal_entry; +#endif +/* XXX Don't change this structure without updating opal-takeover.S */ static struct opal_secondary_data { s64 ack; /* 0 */
@@ -1468,6 +1475,76 @@ static void prom_opal_takeover(void)for (;;) opal_do_takeover(args); } + +/* +* Allocate room for and instantiate OPAL +*/ +static void __init prom_instantiate_opal (void ) +{ +phandle opal_node; +ihandle opal_inst; +u64 base, entry; +u64 size =0 , align =0x10000 ; +u32 rets[2 ]; + +prom_debug ("prom_instantiate_opal: start...\n" ); + + opal_node =call_prom ("finddevice" ,1 ,1 ,ADDR ("/ibm,opal" )); +prom_debug ("opal_node: %x\n" , opal_node); +if (!PHANDLE_VALID (opal_node)) +return ; + +prom_getprop (opal_node,"opal-runtime-size" , &size,sizeof (size)); +if (size ==0 ) +return ; +prom_getprop (opal_node,"opal-runtime-alignment" , &align, +sizeof (align)); + + base =alloc_down (size, align,0 ); +if (base ==0 ) { +prom_printf ("OPAL allocation failed !\n" ); +return ; + } + + opal_inst =call_prom ("open" ,1 ,1 ,ADDR ("/ibm,opal" )); +if (!IHANDLE_VALID (opal_inst)) { +prom_printf ("opening opal package failed (%x)\n" , opal_inst); +return ; + } + +prom_printf ("instantiating opal at 0x%x..." , base); + +if (call_prom_ret ("call-method" ,4 ,3 , rets, +ADDR ("load-opal-runtime" ), + opal_inst, + base >>32 , base &0xffffffff ) !=0 + || (rets[0 ] ==0 && rets[1 ] ==0 )) { +prom_printf (" failed\n" ); +return ; + } + entry = (((u64 )rets[0 ]) <<32 ) | rets[1 ]; + +prom_printf (" done\n" ); + +reserve_mem (base, size); + +prom_debug ("opal base = 0x%x\n" , base); +prom_debug ("opal align = 0x%x\n" , align); +prom_debug ("opal entry = 0x%x\n" , entry); +prom_debug ("opal size = 0x%x\n" , (long )size); + +prom_setprop (opal_node,"/ibm,opal" ,"opal-base-address" , + &base,sizeof (base)); +prom_setprop (opal_node,"/ibm,opal" ,"opal-entry-address" , + &entry,sizeof (entry)); + +#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL +RELOC (prom_opal_base) = base; +RELOC (prom_opal_entry) = entry; +#endif +prom_debug ("prom_instantiate_opal: end...\n" ); +} +#endif /* CONFIG_PPC_POWERNV */ /*
@@ -1863,7 +1940,7 @@ static int __init prom_find_machine_type(void)int x;#endif -/* Look for a PowerMac */ +/* Look for a PowerMac or a Cell */ len =prom_getprop (_prom->root,"compatible" , compat,sizeof (compat)-1 );if (len >0 ) {
@@ -1889,7 +1966,11 @@ static int __init prom_find_machine_type(void) } }#ifdef CONFIG_PPC64 -/* If not a mac, try to figure out if it's an IBM pSeries or any other +/* Try to detect OPAL */ +if (PHANDLE_VALID (call_prom ("finddevice" ,1 ,1 ,ADDR ("/ibm,opal" )))) +return PLATFORM_OPAL ; + +/* Try to figure out if it's an IBM pSeries or any other * PAPR compliant platform. We assume it is if : * - /device_type is "chrp" (please, do NOT use that for future * non-IBM designs !
@@ -2116,7 +2197,7 @@ static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start,unsigned long soff;unsigned char *valp;static char pname[MAX_PROPERTY_NAME ]; -int l, room; +int l, room, has_phandle =0 ;dt_push_token (OF_DT_BEGIN_NODE , mem_start, mem_end);
@@ -2200,19 +2281,26 @@ static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start, valp =make_room (mem_start, mem_end, l,4 );call_prom ("getprop" ,4 ,1 , node,RELOC (pname), valp, l); *mem_start =_ALIGN (*mem_start,4 ); + +if (!strcmp (RELOC (pname),RELOC ("phandle" ))) + has_phandle =1 ; } -/* Add a "linux,phandle" property. */ - soff =dt_find_string (RELOC ("linux,phandle" )); -if (soff ==0 ) -prom_printf ("WARNING: Can't find string index for" -" <linux-phandle> node %s\n" , path); -else { -dt_push_token (OF_DT_PROP , mem_start, mem_end); -dt_push_token (4 , mem_start, mem_end); -dt_push_token (soff, mem_start, mem_end); - valp =make_room (mem_start, mem_end,4 ,4 ); - *(u32 *)valp = node; +/* Add a "linux,phandle" property if no "phandle" property already +* existed (can happen with OPAL) +*/ +if (!has_phandle) { + soff =dt_find_string (RELOC ("linux,phandle" )); +if (soff ==0 ) +prom_printf ("WARNING: Can't find string index for" +" <linux-phandle> node %s\n" , path); +else { +dt_push_token (OF_DT_PROP , mem_start, mem_end); +dt_push_token (4 , mem_start, mem_end); +dt_push_token (soff, mem_start, mem_end); + valp =make_room (mem_start, mem_end,4 ,4 ); + *(u32 *)valp = node; + } }/* do all our children */
@@ -2746,6 +2834,7 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,* between pSeries SMP and pSeries LPAR */ RELOC (of_platform) =prom_find_machine_type (); +prom_printf ("Detected machine type: %x\n" ,RELOC (of_platform));#ifndef CONFIG_RELOCATABLE /* Bail if this is a kdump kernel. */
@@ -2807,7 +2896,8 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,* On non-powermacs, try to instantiate RTAS. PowerMacs don't * have a usable RTAS implementation. */ -if (RELOC (of_platform) !=PLATFORM_POWERMAC ) +if (RELOC (of_platform) !=PLATFORM_POWERMAC && +RELOC (of_platform) !=PLATFORM_OPAL )prom_instantiate_rtas ();#ifdef CONFIG_PPC_POWERNV
@@ -2818,7 +2908,8 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,prom_opal_hold_cpus (); prom_opal_takeover(); } - } + }else if (RELOC (of_platform) ==PLATFORM_OPAL ) +prom_instantiate_opal ();#endif /*
@@ -2826,7 +2917,8 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,* * PowerMacs use a different mechanism to spin CPUs */ -if (RELOC (of_platform) !=PLATFORM_POWERMAC ) +if (RELOC (of_platform) !=PLATFORM_POWERMAC && +RELOC (of_platform) !=PLATFORM_OPAL )prom_hold_cpus ();/*
@@ -2894,7 +2986,13 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,reloc_got2 (-offset);#endif -__start (hdr, kbase,0 ); +#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL +/* OPAL early debug gets the OPAL base & entry in r8 and r9 */ +__start (hdr, kbase,0 ,0 ,0 , +RELOC (prom_opal_base),RELOC (prom_opal_entry)); +#else +__start (hdr, kbase,0 ,0 ,0 ,0 ,0 ); +#endif return 0 ; }
Signature · 1 line
1.7.4.1
PATCH 13/20 powerpc/powernv: Hookup reboot and poweroff functions
In reply to Benjamin HerrenschmidtThis calls the respective HAL functions, and spin on hal_poll_event() to ensure the HAL has a chance to communicate with the FSP to trigger the reboot or shutdown operation
--- arch/powerpc/platforms/powernv/setup.c | 32 ++++++++++++++++++++++++++------ 1 files changed, 26 insertions(+), 6 deletions(-)
arch/powerpc/platforms/powernv/setup.c +26 -6
@@ -83,19 +83,39 @@ static void pnv_show_cpuinfo(struct seq_file *m)of_node_put (root); } -static void pnv_restart (char *cmd) +static void __noreturn pnv_restart (char *cmd) { -for (;;); +long rc =OPAL_BUSY ; + +while (rc ==OPAL_BUSY || rc ==OPAL_BUSY_EVENT ) { + rc =opal_cec_reboot (); +if (rc ==OPAL_BUSY_EVENT ) +opal_poll_events (NULL ); +else +mdelay (10 ); + } +for (;;) +opal_poll_events (NULL ); } -static void pnv_power_off (void ) +static void __noreturn pnv_power_off (void ) { -for (;;); +long rc =OPAL_BUSY ; + +while (rc ==OPAL_BUSY || rc ==OPAL_BUSY_EVENT ) { + rc =opal_cec_power_down (0 ); +if (rc ==OPAL_BUSY_EVENT ) +opal_poll_events (NULL ); +else +mdelay (10 ); + } +for (;;) +opal_poll_events (NULL ); } -static void pnv_halt (void ) +static void __noreturn pnv_halt (void ) { -for (;;); +pnv_power_off (); }static unsigned long __init pnv_get_boot_time (void )
Signature · 1 line
1.7.4.1