From 118ee80f7921e8b062c445ac3986ee11409520d0 Mon Sep 17 00:00:00 2001 From: "Collin L. Walling" Date: Fri, 23 Feb 2018 10:43:11 -0500 Subject: s390-ccw: move auxiliary IPL data to separate location The s390-ccw firmware needs some information in support of the boot process which is not available on the native machine. Examples are the netboot firmware load address and now the boot menu parameters. While storing that data in unused fields of the IPL parameter block works, that approach could create problems if the parameter block definition should change in the future. Because then a guest could overwrite these fields using the set IPLB diagnose. In fact the data in question is of more global nature and not really tied to an IPL device, so separating it is rather logical. This commit introduces a new structure to hold firmware relevant IPL parameters set by QEMU. The data is stored at location 204 (dec) and can contain up to 7 32-bit words. This area is available to programming in the z/Architecture Principles of Operation and can thus safely be used by the firmware until the IPL has completed. Signed-off-by: Viktor Mihajlovski Signed-off-by: Collin L. Walling Reviewed-by: Thomas Huth Acked-by: Christian Borntraeger [thuth: fixed "4 + 8 * n" comment] Signed-off-by: Thomas Huth --- hw/s390x/ipl.c | 18 +++++++++++++++++- hw/s390x/ipl.h | 25 +++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) (limited to 'hw/s390x') diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c index 0d06fc12b6..79f5a58adb 100644 --- a/hw/s390x/ipl.c +++ b/hw/s390x/ipl.c @@ -399,6 +399,21 @@ void s390_reipl_request(void) qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); } +static void s390_ipl_prepare_qipl(S390CPU *cpu) +{ + S390IPLState *ipl = get_ipl_device(); + uint8_t *addr; + uint64_t len = 4096; + + addr = cpu_physical_memory_map(cpu->env.psa, &len, 1); + if (!addr || len < QIPL_ADDRESS + sizeof(QemuIplParameters)) { + error_report("Cannot set QEMU IPL parameters"); + return; + } + memcpy(addr + QIPL_ADDRESS, &ipl->qipl, sizeof(QemuIplParameters)); + cpu_physical_memory_unmap(addr, len, 1, len); +} + void s390_ipl_prepare_cpu(S390CPU *cpu) { S390IPLState *ipl = get_ipl_device(); @@ -418,8 +433,9 @@ void s390_ipl_prepare_cpu(S390CPU *cpu) error_report_err(err); vm_stop(RUN_STATE_INTERNAL_ERROR); } - ipl->iplb.ccw.netboot_start_addr = cpu_to_be64(ipl->start_addr); + ipl->qipl.netboot_start_addr = cpu_to_be64(ipl->start_addr); } + s390_ipl_prepare_qipl(cpu); } static void s390_ipl_reset(DeviceState *dev) diff --git a/hw/s390x/ipl.h b/hw/s390x/ipl.h index 8a705e0428..5cc3b770d4 100644 --- a/hw/s390x/ipl.h +++ b/hw/s390x/ipl.h @@ -16,8 +16,7 @@ #include "cpu.h" struct IplBlockCcw { - uint64_t netboot_start_addr; - uint8_t reserved0[77]; + uint8_t reserved0[85]; uint8_t ssid; uint16_t devno; uint8_t vm_flags; @@ -90,6 +89,27 @@ void s390_ipl_prepare_cpu(S390CPU *cpu); IplParameterBlock *s390_ipl_get_iplb(void); void s390_reipl_request(void); +#define QIPL_ADDRESS 0xcc + +/* + * The QEMU IPL Parameters will be stored at absolute address + * 204 (0xcc) which means it is 32-bit word aligned but not + * double-word aligned. + * Placement of data fields in this area must account for + * their alignment needs. E.g., netboot_start_address must + * have an offset of 4 + n * 8 bytes within the struct in order + * to keep it double-word aligned. + * The total size of the struct must never exceed 28 bytes. + * This definition must be kept in sync with the defininition + * in pc-bios/s390-ccw/iplb.h. + */ +struct QemuIplParameters { + uint8_t reserved1[4]; + uint64_t netboot_start_addr; + uint8_t reserved2[16]; +} QEMU_PACKED; +typedef struct QemuIplParameters QemuIplParameters; + #define TYPE_S390_IPL "s390-ipl" #define S390_IPL(obj) OBJECT_CHECK(S390IPLState, (obj), TYPE_S390_IPL) @@ -105,6 +125,7 @@ struct S390IPLState { bool iplb_valid; bool reipl_requested; bool netboot; + QemuIplParameters qipl; /*< public >*/ char *kernel; -- cgit v1.2.1 From 26b2a2a49171ff44286722681f5aebdfee23e9cf Mon Sep 17 00:00:00 2001 From: "Collin L. Walling" Date: Fri, 23 Feb 2018 10:43:12 -0500 Subject: s390-ccw: parse and set boot menu options Set boot menu options for an s390 guest and store them in the iplb. These options are set via the QEMU command line option: -boot menu=on|off[,splash-time=X] or via the libvirt domain xml: Where X represents some positive integer representing milliseconds. Any value set for loadparm will override all boot menu options. If loadparm=PROMPT, then the menu will be enabled without a timeout. Signed-off-by: Collin L. Walling Reviewed-by: Janosch Frank Reviewed-by: Thomas Huth Signed-off-by: Thomas Huth --- hw/s390x/ipl.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/ipl.h | 9 +++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) (limited to 'hw/s390x') diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c index 79f5a58adb..ee2039dc69 100644 --- a/hw/s390x/ipl.c +++ b/hw/s390x/ipl.c @@ -23,6 +23,9 @@ #include "hw/s390x/ebcdic.h" #include "ipl.h" #include "qemu/error-report.h" +#include "qemu/config-file.h" +#include "qemu/cutils.h" +#include "qemu/option.h" #define KERN_IMAGE_START 0x010000UL #define KERN_PARM_AREA 0x010480UL @@ -219,6 +222,54 @@ static Property s390_ipl_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +static void s390_ipl_set_boot_menu(S390IPLState *ipl) +{ + QemuOptsList *plist = qemu_find_opts("boot-opts"); + QemuOpts *opts = QTAILQ_FIRST(&plist->head); + uint8_t *flags = &ipl->qipl.qipl_flags; + uint32_t *timeout = &ipl->qipl.boot_menu_timeout; + const char *tmp; + unsigned long splash_time = 0; + + if (!get_boot_device(0)) { + if (boot_menu) { + error_report("boot menu requires a bootindex to be specified for " + "the IPL device."); + } + return; + } + + switch (ipl->iplb.pbt) { + case S390_IPL_TYPE_CCW: + break; + default: + error_report("boot menu is not supported for this device type."); + return; + } + + if (!boot_menu) { + return; + } + + *flags |= QIPL_FLAG_BM_OPTS_CMD; + + tmp = qemu_opt_get(opts, "splash-time"); + + if (tmp && qemu_strtoul(tmp, NULL, 10, &splash_time)) { + error_report("splash-time is invalid, forcing it to 0."); + *timeout = 0; + return; + } + + if (splash_time > 0xffffffff) { + error_report("splash-time is too large, forcing it to max value."); + *timeout = 0xffffffff; + return; + } + + *timeout = cpu_to_be32(splash_time); +} + static bool s390_gen_initial_iplb(S390IPLState *ipl) { DeviceState *dev_st; @@ -435,6 +486,7 @@ void s390_ipl_prepare_cpu(S390CPU *cpu) } ipl->qipl.netboot_start_addr = cpu_to_be64(ipl->start_addr); } + s390_ipl_set_boot_menu(ipl); s390_ipl_prepare_qipl(cpu); } diff --git a/hw/s390x/ipl.h b/hw/s390x/ipl.h index 5cc3b770d4..d6c6f75b76 100644 --- a/hw/s390x/ipl.h +++ b/hw/s390x/ipl.h @@ -91,6 +91,9 @@ void s390_reipl_request(void); #define QIPL_ADDRESS 0xcc +/* Boot Menu flags */ +#define QIPL_FLAG_BM_OPTS_CMD 0x80 + /* * The QEMU IPL Parameters will be stored at absolute address * 204 (0xcc) which means it is 32-bit word aligned but not @@ -104,9 +107,11 @@ void s390_reipl_request(void); * in pc-bios/s390-ccw/iplb.h. */ struct QemuIplParameters { - uint8_t reserved1[4]; + uint8_t qipl_flags; + uint8_t reserved1[3]; uint64_t netboot_start_addr; - uint8_t reserved2[16]; + uint32_t boot_menu_timeout; + uint8_t reserved2[12]; } QEMU_PACKED; typedef struct QemuIplParameters QemuIplParameters; -- cgit v1.2.1 From 53b310ce539cfadf1f2fad5927a9e8f88ec9db13 Mon Sep 17 00:00:00 2001 From: "Collin L. Walling" Date: Fri, 23 Feb 2018 10:43:18 -0500 Subject: s390-ccw: use zipl values when no boot menu options are present If no boot menu options are present, then flag the boot menu to use the zipl options that were set in the zipl configuration file (and stored on disk by zipl). These options are found at some offset prior to the start of the zipl boot menu banner. The zipl timeout value is limited to a 16-bit unsigned integer and stored as seconds, so we take care to convert it to milliseconds in order to conform to the rest of the boot menu functionality. This is limited to CCW devices. For reference, the zipl configuration file uses the following fields in the menu section: prompt=1 enable the boot menu timeout=X set the timeout to X seconds To explicitly disregard any boot menu options, then menu=off or must be specified. Signed-off-by: Collin L. Walling Reviewed-by: Thomas Huth Signed-off-by: Thomas Huth --- hw/s390x/ipl.c | 5 +++++ hw/s390x/ipl.h | 1 + 2 files changed, 6 insertions(+) (limited to 'hw/s390x') diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c index ee2039dc69..c12e460a7f 100644 --- a/hw/s390x/ipl.c +++ b/hw/s390x/ipl.c @@ -241,6 +241,11 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl) switch (ipl->iplb.pbt) { case S390_IPL_TYPE_CCW: + /* In the absence of -boot menu, use zipl parameters */ + if (!qemu_opt_get(opts, "menu")) { + *flags |= QIPL_FLAG_BM_OPTS_ZIPL; + return; + } break; default: error_report("boot menu is not supported for this device type."); diff --git a/hw/s390x/ipl.h b/hw/s390x/ipl.h index d6c6f75b76..0570d0ad75 100644 --- a/hw/s390x/ipl.h +++ b/hw/s390x/ipl.h @@ -93,6 +93,7 @@ void s390_reipl_request(void); /* Boot Menu flags */ #define QIPL_FLAG_BM_OPTS_CMD 0x80 +#define QIPL_FLAG_BM_OPTS_ZIPL 0x40 /* * The QEMU IPL Parameters will be stored at absolute address -- cgit v1.2.1 From ffb4a1c80792aa71da900dbb495b21fbc0130073 Mon Sep 17 00:00:00 2001 From: "Collin L. Walling" Date: Fri, 23 Feb 2018 10:43:19 -0500 Subject: s390-ccw: interactive boot menu for scsi Interactive boot menu for scsi. This follows a similar procedure as the interactive menu for eckd dasd. An example follows: s390x Enumerated Boot Menu. 3 entries detected. Select from index 0 to 2. Signed-off-by: Collin L. Walling Reviewed-by: Thomas Huth [thuth: Added additional "break;" statement to avoid analyzer warnings] Signed-off-by: Thomas Huth --- hw/s390x/ipl.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'hw/s390x') diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c index c12e460a7f..798e99aadf 100644 --- a/hw/s390x/ipl.c +++ b/hw/s390x/ipl.c @@ -247,6 +247,8 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl) return; } break; + case S390_IPL_TYPE_QEMU_SCSI: + break; default: error_report("boot menu is not supported for this device type."); return; -- cgit v1.2.1