From cbae61951b3562e1b0233a21ac0b7d871a31e4f8 Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Mon, 9 Jul 2018 13:41:07 +0300 Subject: 9773 loader.efi: parity and stop bits switches are missing default case Reviewed by: Yuri Pankov Reviewed by: Garrett D'Amore Approved by: Garrett D'Amore --- usr/src/boot/sys/boot/efi/loader/comconsole.c | 49 ++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/usr/src/boot/sys/boot/efi/loader/comconsole.c b/usr/src/boot/sys/boot/efi/loader/comconsole.c index 57168cca17..7fb19b11f1 100644 --- a/usr/src/boot/sys/boot/efi/loader/comconsole.c +++ b/usr/src/boot/sys/boot/efi/loader/comconsole.c @@ -310,28 +310,49 @@ comc_ischar(struct console *cp) static char * comc_asprint_mode(struct serial *sp) { - char par = 'n', *buf; - int stop = 1; + char par, *buf; + char *stop; if (sp == NULL) return (NULL); switch (sp->parity) { - case NoParity: par = 'n'; + case NoParity: + par = 'n'; break; - case EvenParity: par = 'e'; + case EvenParity: + par = 'e'; break; - case OddParity: par = 'o'; + case OddParity: + par = 'o'; + break; + case MarkParity: + par = 'm'; + break; + case SpaceParity: + par = 's'; + break; + default: + par = 'n'; break; } + switch (sp->stopbits) { - case OneStopBit: stop = 1; + case OneStopBit: + stop = "1"; + break; + case TwoStopBits: + stop = "2"; break; - case TwoStopBits: stop = 2; + case OneFiveStopBits: + stop = "1.5"; + break; + default: + stop = "1"; break; } - asprintf(&buf, "%ju,%d,%c,%d,-", sp->baudrate, sp->databits, par, stop); + asprintf(&buf, "%ju,%d,%c,%s,-", sp->baudrate, sp->databits, par, stop); return (buf); } @@ -360,6 +381,10 @@ comc_parse_mode(struct serial *sp, const char *value) return (CMD_ERROR); switch (n) { + case 5: databits = 5; + break; + case 6: databits = 6; + break; case 7: databits = 7; break; case 8: databits = 8; @@ -376,6 +401,10 @@ comc_parse_mode(struct serial *sp, const char *value) break; case 'o': parity = OddParity; break; + case 'm': parity = MarkParity; + break; + case 's': parity = SpaceParity; + break; default: return (CMD_ERROR); } @@ -387,6 +416,10 @@ comc_parse_mode(struct serial *sp, const char *value) switch (*ep++) { case '1': stopbits = OneStopBit; + if (ep[0] == '.' && ep[1] == '5') { + ep += 2; + stopbits = OneFiveStopBits; + } break; case '2': stopbits = TwoStopBits; break; -- cgit v1.2.3 From dd891561fb3e50f856d7d730f22a12cc1db51788 Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Sat, 7 Jan 2017 00:03:49 +0200 Subject: 9854 uts: add type for early boot properties Reviewed by: Yuri Pankov Reviewed by: John Howard Approved by: Dan McDonald --- usr/src/uts/i86pc/os/ddi_impl.c | 96 ++++++++++++++++------------ usr/src/uts/i86pc/os/fakebop.c | 135 +++++++++++++++++++++++++++++---------- usr/src/uts/intel/sys/bootconf.h | 1 + 3 files changed, 157 insertions(+), 75 deletions(-) diff --git a/usr/src/uts/i86pc/os/ddi_impl.c b/usr/src/uts/i86pc/os/ddi_impl.c index 0143b20922..3478a6bf5b 100644 --- a/usr/src/uts/i86pc/os/ddi_impl.c +++ b/usr/src/uts/i86pc/os/ddi_impl.c @@ -1841,7 +1841,7 @@ get_boot_properties(void) extern char hw_provider[]; dev_info_t *devi; char *name; - int length; + int length, flags; char property_name[50], property_val[50]; void *bop_staging_area; @@ -1872,7 +1872,7 @@ get_boot_properties(void) } length = BOP_GETPROPLEN(bootops, property_name); - if (length == 0) + if (length < 0) continue; if (length > MMU_PAGESIZE) { cmn_err(CE_NOTE, @@ -1881,6 +1881,7 @@ get_boot_properties(void) continue; } BOP_GETPROP(bootops, property_name, bop_staging_area); + flags = do_bsys_getproptype(bootops, property_name); /* * special properties: @@ -1895,54 +1896,67 @@ get_boot_properties(void) if (strcmp(name, "si-machine") == 0) { (void) strncpy(utsname.machine, bop_staging_area, SYS_NMLN); - utsname.machine[SYS_NMLN - 1] = (char)NULL; - } else if (strcmp(name, "si-hw-provider") == 0) { + utsname.machine[SYS_NMLN - 1] = '\0'; + continue; + } + if (strcmp(name, "si-hw-provider") == 0) { (void) strncpy(hw_provider, bop_staging_area, SYS_NMLN); - hw_provider[SYS_NMLN - 1] = (char)NULL; - } else if (strcmp(name, "bios-boot-device") == 0) { - copy_boot_str(bop_staging_area, property_val, 50); - (void) ndi_prop_update_string(DDI_DEV_T_NONE, devi, - property_name, property_val); - } else if (strcmp(name, "acpi-root-tab") == 0) { - (void) ndi_prop_update_int64(DDI_DEV_T_NONE, devi, - property_name, *((int64_t *)bop_staging_area)); - } else if (strcmp(name, "smbios-address") == 0) { - (void) ndi_prop_update_int64(DDI_DEV_T_NONE, devi, - property_name, *((int64_t *)bop_staging_area)); - } else if (strcmp(name, "efi-systab") == 0) { - (void) ndi_prop_update_int64(DDI_DEV_T_NONE, devi, - property_name, *((int64_t *)bop_staging_area)); - } else if (strcmp(name, "efi-systype") == 0) { + hw_provider[SYS_NMLN - 1] = '\0'; + continue; + } + if (strcmp(name, "bios-boot-device") == 0) { copy_boot_str(bop_staging_area, property_val, 50); (void) ndi_prop_update_string(DDI_DEV_T_NONE, devi, property_name, property_val); - } else if (strcmp(name, "stdout") == 0) { + continue; + } + if (strcmp(name, "stdout") == 0) { (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, property_name, *((int *)bop_staging_area)); - } else if (strcmp(name, "boot-args") == 0) { - copy_boot_str(bop_staging_area, property_val, 50); - (void) e_ddi_prop_update_string(DDI_DEV_T_NONE, devi, - property_name, property_val); - } else if (strcmp(name, "bootargs") == 0) { - copy_boot_str(bop_staging_area, property_val, 50); + continue; + } + + /* Boolean property */ + if (length == 0) { + (void) e_ddi_prop_create(DDI_DEV_T_NONE, devi, + DDI_PROP_CANSLEEP, property_name, NULL, 0); + continue; + } + + /* Now anything else based on type. */ + switch (flags) { + case DDI_PROP_TYPE_INT: + if (length == sizeof (int)) { + (void) e_ddi_prop_update_int(DDI_DEV_T_NONE, + devi, property_name, + *((int *)bop_staging_area)); + } else { + (void) e_ddi_prop_update_int_array( + DDI_DEV_T_NONE, devi, property_name, + bop_staging_area, length / sizeof (int)); + } + break; + case DDI_PROP_TYPE_STRING: (void) e_ddi_prop_update_string(DDI_DEV_T_NONE, devi, - property_name, property_val); - } else if (strcmp(name, "bootp-response") == 0) { + property_name, bop_staging_area); + break; + case DDI_PROP_TYPE_BYTE: (void) e_ddi_prop_update_byte_array(DDI_DEV_T_NONE, devi, property_name, bop_staging_area, length); - } else if (strcmp(name, "ramdisk_start") == 0) { - (void) e_ddi_prop_update_int64(DDI_DEV_T_NONE, devi, - property_name, *((int64_t *)bop_staging_area)); - } else if (strcmp(name, "ramdisk_end") == 0) { - (void) e_ddi_prop_update_int64(DDI_DEV_T_NONE, devi, - property_name, *((int64_t *)bop_staging_area)); - } else if (strncmp(name, "module-addr-", 12) == 0) { - (void) e_ddi_prop_update_int64(DDI_DEV_T_NONE, devi, - property_name, *((int64_t *)bop_staging_area)); - } else if (strncmp(name, "module-size-", 12) == 0) { - (void) e_ddi_prop_update_int64(DDI_DEV_T_NONE, devi, - property_name, *((int64_t *)bop_staging_area)); - } else { + break; + case DDI_PROP_TYPE_INT64: + if (length == sizeof (int64_t)) { + (void) e_ddi_prop_update_int64(DDI_DEV_T_NONE, + devi, property_name, + *((int64_t *)bop_staging_area)); + } else { + (void) e_ddi_prop_update_int64_array( + DDI_DEV_T_NONE, devi, property_name, + bop_staging_area, + length / sizeof (int64_t)); + } + break; + default: /* Property type unknown, use old prop interface */ (void) e_ddi_prop_create(DDI_DEV_T_NONE, devi, DDI_PROP_CANSLEEP, property_name, bop_staging_area, diff --git a/usr/src/uts/i86pc/os/fakebop.c b/usr/src/uts/i86pc/os/fakebop.c index f381504e39..2ee67b522b 100644 --- a/usr/src/uts/i86pc/os/fakebop.c +++ b/usr/src/uts/i86pc/os/fakebop.c @@ -72,6 +72,7 @@ #include #include #include +#include /* For DDI prop types */ static int have_console = 0; /* set once primitive console is initialized */ static char *boot_args = ""; @@ -115,7 +116,8 @@ static char buffer[BUFFERSIZE]; typedef struct bootprop { struct bootprop *bp_next; char *bp_name; - uint_t bp_vlen; + int bp_flags; /* DDI prop type */ + uint_t bp_vlen; /* 0 for boolean */ char *bp_value; } bootprop_t; @@ -352,7 +354,7 @@ do_bsys_ealloc(bootops_t *bop, caddr_t virthint, size_t size, static void -bsetprop(char *name, int nlen, void *value, int vlen) +bsetprop(int flags, char *name, int nlen, void *value, int vlen) { uint_t size; uint_t need_size; @@ -387,6 +389,11 @@ bsetprop(char *name, int nlen, void *value, int vlen) *curr_page++ = 0; curr_space -= nlen + 1; + /* + * set the property type + */ + b->bp_flags = flags & DDI_PROP_TYPE_MASK; + /* * copy in value, but no ending zero byte */ @@ -410,13 +417,22 @@ bsetprop(char *name, int nlen, void *value, int vlen) static void bsetprops(char *name, char *value) { - bsetprop(name, strlen(name), value, strlen(value) + 1); + bsetprop(DDI_PROP_TYPE_STRING, name, strlen(name), + value, strlen(value) + 1); +} + +static void +bsetprop32(char *name, uint32_t value) +{ + bsetprop(DDI_PROP_TYPE_INT, name, strlen(name), + (void *)&value, sizeof (value)); } static void bsetprop64(char *name, uint64_t value) { - bsetprop(name, strlen(name), (void *)&value, sizeof (value)); + bsetprop(DDI_PROP_TYPE_INT64, name, strlen(name), + (void *)&value, sizeof (value)); } static void @@ -428,6 +444,23 @@ bsetpropsi(char *name, int value) bsetprops(name, prop_val); } +/* + * to find the type of the value associated with this name + */ +/*ARGSUSED*/ +int +do_bsys_getproptype(bootops_t *bop, const char *name) +{ + bootprop_t *b; + + for (b = bprops; b != NULL; b = b->bp_next) { + if (strcmp(name, b->bp_name) != 0) + continue; + return (b->bp_flags); + } + return (-1); +} + /* * to find the size of the buffer to allocate */ @@ -568,7 +601,8 @@ static void boot_prop_display(char *buffer) { char *name = ""; - int i, len; + int i, len, flags, *buf32; + int64_t *buf64; bop_printf(NULL, "\nBoot properties:\n"); @@ -576,16 +610,43 @@ boot_prop_display(char *buffer) bop_printf(NULL, "\t0x%p %s = ", (void *)name, name); (void) do_bsys_getprop(NULL, name, buffer); len = do_bsys_getproplen(NULL, name); + flags = do_bsys_getproptype(NULL, name); bop_printf(NULL, "len=%d ", len); - if (!unprintable(buffer, len)) { - buffer[len] = 0; - bop_printf(NULL, "%s\n", buffer); - continue; - } - for (i = 0; i < len; i++) { - bop_printf(NULL, "%02x", buffer[i] & 0xff); - if (i < len - 1) - bop_printf(NULL, "."); + + switch (flags) { + case DDI_PROP_TYPE_INT: + len = len / sizeof (int); + buf32 = (int *)buffer; + for (i = 0; i < len; i++) { + bop_printf(NULL, "%08x", buf32[i]); + if (i < len - 1) + bop_printf(NULL, "."); + } + break; + case DDI_PROP_TYPE_STRING: + bop_printf(NULL, "%s", buffer); + break; + case DDI_PROP_TYPE_INT64: + len = len / sizeof (int64_t); + buf64 = (int64_t *)buffer; + for (i = 0; i < len; i++) { + bop_printf(NULL, "%016" PRIx64, buf64[i]); + if (i < len - 1) + bop_printf(NULL, "."); + } + break; + default: + if (!unprintable(buffer, len)) { + buffer[len] = 0; + bop_printf(NULL, "%s", buffer); + break; + } + for (i = 0; i < len; i++) { + bop_printf(NULL, "%02x", buffer[i] & 0xff); + if (i < len - 1) + bop_printf(NULL, "."); + } + break; } bop_printf(NULL, "\n"); } @@ -715,10 +776,10 @@ boot_prop_finish(void) * If a property was explicitly set on the command line * it will override a setting in bootenv.rc */ - if (do_bsys_getproplen(NULL, name) > 0) + if (do_bsys_getproplen(NULL, name) >= 0) continue; - bsetprop(name, n_len, value, v_len + 1); + bsetprops(name, value); } done: if (fd >= 0) @@ -1004,7 +1065,7 @@ xen_nfsroot_props(char *s) }; int n_prop = sizeof (prop_map) / sizeof (prop_map[0]); - bsetprop("fstype", 6, "nfs", 4); + bsetprops("fstype", "nfs"); xen_parse_props(s, prop_map, n_prop); @@ -1621,7 +1682,8 @@ build_boot_properties(struct xboot_info *xbp) } if (value_len == 0) { - bsetprop(name, name_len, "true", 5); + bsetprop(DDI_PROP_TYPE_ANY, name, name_len, + NULL, 0); } else { char *v = value; int l = value_len; @@ -1632,8 +1694,8 @@ build_boot_properties(struct xboot_info *xbp) } bcopy(v, propbuf, l); propbuf[l] = '\0'; - bsetprop(name, name_len, propbuf, - l + 1); + bsetprop(DDI_PROP_TYPE_STRING, name, name_len, + propbuf, l + 1); } name = value + value_len; while (*name == ',') @@ -1692,7 +1754,8 @@ build_boot_properties(struct xboot_info *xbp) if (netboot && mbi->drives_length != 0) { sip = (struct sol_netinfo *)(uintptr_t)mbi->drives_addr; if (sip->sn_infotype == SN_TYPE_BOOTP) - bsetprop("bootp-response", + bsetprop(DDI_PROP_TYPE_BYTE, + "bootp-response", sizeof ("bootp-response"), (void *)(uintptr_t)mbi->drives_addr, mbi->drives_length); @@ -1719,15 +1782,15 @@ build_boot_properties(struct xboot_info *xbp) bsetprops("bios-boot-device", str); } if (netdev != NULL) { - bsetprop("bootp-response", sizeof ("bootp-response"), + bsetprop(DDI_PROP_TYPE_BYTE, + "bootp-response", sizeof ("bootp-response"), (void *)(uintptr_t)netdev->mb_dhcpack, netdev->mb_size - sizeof (multiboot_tag_network_t)); } } - bsetprop("stdout", strlen("stdout"), - &stdout_val, sizeof (stdout_val)); + bsetprop32("stdout", stdout_val); #endif /* __xpv */ /* @@ -2357,7 +2420,8 @@ process_mcfg(ACPI_TABLE_MCFG *tp) ecfginfo[1] = cfg_baap->PciSegment; ecfginfo[2] = cfg_baap->StartBusNumber; ecfginfo[3] = cfg_baap->EndBusNumber; - bsetprop(MCFG_PROPNAME, strlen(MCFG_PROPNAME), + bsetprop(DDI_PROP_TYPE_INT64, + MCFG_PROPNAME, strlen(MCFG_PROPNAME), ecfginfo, sizeof (ecfginfo)); break; } @@ -2445,7 +2509,8 @@ process_madt(ACPI_TABLE_MADT *tp) * Make boot property for array of "final" APIC IDs for each * CPU */ - bsetprop(BP_CPU_APICID_ARRAY, strlen(BP_CPU_APICID_ARRAY), + bsetprop(DDI_PROP_TYPE_INT, + BP_CPU_APICID_ARRAY, strlen(BP_CPU_APICID_ARRAY), cpu_apicid_array, cpu_count * sizeof (*cpu_apicid_array)); } @@ -2538,7 +2603,8 @@ process_srat(ACPI_TABLE_SRAT *tp) processor.sapic_id = cpu->LocalSapicEid; (void) snprintf(prop_name, 30, "acpi-srat-processor-%d", proc_num); - bsetprop(prop_name, strlen(prop_name), &processor, + bsetprop(DDI_PROP_TYPE_INT, + prop_name, strlen(prop_name), &processor, sizeof (processor)); proc_num++; break; @@ -2555,7 +2621,8 @@ process_srat(ACPI_TABLE_SRAT *tp) memory.flags = mem->Flags; (void) snprintf(prop_name, 30, "acpi-srat-memory-%d", mem_num); - bsetprop(prop_name, strlen(prop_name), &memory, + bsetprop(DDI_PROP_TYPE_INT, + prop_name, strlen(prop_name), &memory, sizeof (memory)); if ((mem->Flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) && (memory.addr + memory.length > maxmem)) { @@ -2574,7 +2641,8 @@ process_srat(ACPI_TABLE_SRAT *tp) x2apic.x2apic_id = x2cpu->ApicId; (void) snprintf(prop_name, 30, "acpi-srat-processor-%d", proc_num); - bsetprop(prop_name, strlen(prop_name), &x2apic, + bsetprop(DDI_PROP_TYPE_INT, + prop_name, strlen(prop_name), &x2apic, sizeof (x2apic)); proc_num++; break; @@ -2615,9 +2683,9 @@ process_slit(ACPI_TABLE_SLIT *tp) if (tp->LocalityCount >= SLIT_LOCALITIES_MAX) return; - bsetprop(SLIT_NUM_PROPNAME, strlen(SLIT_NUM_PROPNAME), - &tp->LocalityCount, sizeof (tp->LocalityCount)); - bsetprop(SLIT_PROPNAME, strlen(SLIT_PROPNAME), &tp->Entry, + bsetprop64(SLIT_NUM_PROPNAME, tp->LocalityCount); + bsetprop(DDI_PROP_TYPE_BYTE, + SLIT_PROPNAME, strlen(SLIT_PROPNAME), &tp->Entry, tp->LocalityCount * tp->LocalityCount); } @@ -2809,8 +2877,7 @@ defcons_init(size_t size) p = do_bsys_alloc(NULL, NULL, size, MMU_PAGESIZE); *p = 0; - bsetprop("deferred-console-buf", strlen("deferred-console-buf") + 1, - &p, sizeof (p)); + bsetprop32("deferred-console-buf", (uint32_t)((uintptr_t)&p)); return (p); } diff --git a/usr/src/uts/intel/sys/bootconf.h b/usr/src/uts/intel/sys/bootconf.h index 5d21143d38..03bd4b70b8 100644 --- a/usr/src/uts/intel/sys/bootconf.h +++ b/usr/src/uts/intel/sys/bootconf.h @@ -250,6 +250,7 @@ extern paddr_t do_bop_phys_alloc(uint64_t, uint64_t); extern int do_bsys_getproplen(bootops_t *, const char *); extern int do_bsys_getprop(bootops_t *, const char *, void *); +extern int do_bsys_getproptype(bootops_t *, const char *); #endif /* _KERNEL && !_BOOT */ -- cgit v1.2.3