diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2019-08-04 14:28:59 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2019-08-04 14:28:59 +0000 |
commit | bacbc8a6271d36c35f0dcfabe4f57d351acbe09e (patch) | |
tree | bc471932bdc76908ca978adc0dd03dd6adedb396 /sys/arch/arm64 | |
parent | cf244d1d3321086426c5e883583cd2f0087c03eb (diff) |
Cleanup the bios(4)/smbios(4) code a bit. Fix some KNF issues, reduce
differences between the i386 and amd64 versions of the code and
switch to using the standard C integer exact width integer types.
ok deraadt@
Diffstat (limited to 'sys/arch/arm64')
-rw-r--r-- | sys/arch/arm64/dev/smbios.c | 43 | ||||
-rw-r--r-- | sys/arch/arm64/include/smbiosvar.h | 222 |
2 files changed, 133 insertions, 132 deletions
diff --git a/sys/arch/arm64/dev/smbios.c b/sys/arch/arm64/dev/smbios.c index 911e056bb86..d9e9d906a63 100644 --- a/sys/arch/arm64/dev/smbios.c +++ b/sys/arch/arm64/dev/smbios.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smbios.c,v 1.2 2019/08/04 10:00:37 kettenis Exp $ */ +/* $OpenBSD: smbios.c,v 1.3 2019/08/04 14:28:58 kettenis Exp $ */ /* * Copyright (c) 2006 Gordon Willem Klok <gklok@cogeco.ca> * Copyright (c) 2019 Mark Kettenis <kettenis@openbsd.org> @@ -167,9 +167,9 @@ fail: * smbios_find_table with the same arguments. */ int -smbios_find_table(u_int8_t type, struct smbtable *st) +smbios_find_table(uint8_t type, struct smbtable *st) { - u_int8_t *va, *end; + uint8_t *va, *end; struct smbtblhdr *hdr; int ret = 0, tcount = 1; @@ -184,20 +184,20 @@ smbios_find_table(u_int8_t type, struct smbtable *st) * preceding that referenced by the handle is encoded in bits 15:31. */ if ((st->cookie & 0xfff) == type && st->cookie >> 16) { - if ((u_int8_t *)st->hdr >= va && (u_int8_t *)st->hdr < end) { + if ((uint8_t *)st->hdr >= va && (uint8_t *)st->hdr < end) { hdr = st->hdr; if (hdr->type == type) { - va = (u_int8_t *)hdr + hdr->size; + va = (uint8_t *)hdr + hdr->size; for (; va + 1 < end; va++) if (*va == 0 && *(va + 1) == 0) break; - va+= 2; + va += 2; tcount = st->cookie >> 16; } } } - for (; va + sizeof(struct smbtblhdr) < end && tcount <= - smbios_entry.count; tcount++) { + for (; va + sizeof(struct smbtblhdr) < end && + tcount <= smbios_entry.count; tcount++) { hdr = (struct smbtblhdr *)va; if (hdr->type == type) { ret = 1; @@ -208,23 +208,23 @@ smbios_find_table(u_int8_t type, struct smbtable *st) } if (hdr->type == SMBIOS_TYPE_EOT) break; - va+= hdr->size; + va += hdr->size; for (; va + 1 < end; va++) if (*va == 0 && *(va + 1) == 0) break; - va+=2; + va += 2; } return ret; } char * -smbios_get_string(struct smbtable *st, u_int8_t indx, char *dest, size_t len) +smbios_get_string(struct smbtable *st, uint8_t indx, char *dest, size_t len) { - u_int8_t *va, *end; + uint8_t *va, *end; char *ret = NULL; int i; - va = (u_int8_t *)st->hdr + st->hdr->size; + va = (uint8_t *)st->hdr + st->hdr->size; end = smbios_entry.addr + smbios_entry.len; for (i = 1; va < end && i < indx && *va; i++) while (*va++) @@ -233,7 +233,7 @@ smbios_get_string(struct smbtable *st, u_int8_t indx, char *dest, size_t len) if (va + len < end) { ret = dest; memcpy(ret, va, len); - ret[len-1] = '\0'; + ret[len - 1] = '\0'; } } @@ -248,7 +248,7 @@ fixstring(char *s) for (i = 0; i < nitems(smbios_uninfo); i++) if ((strncasecmp(s, smbios_uninfo[i], - strlen(smbios_uninfo[i])))==0) + strlen(smbios_uninfo[i]))) == 0) return NULL; /* * Remove leading and trailing whitespace @@ -271,7 +271,7 @@ fixstring(char *s) } void -smbios_info(char * str) +smbios_info(char *str) { char *sminfop, sminfo[64]; struct smbtable stbl, btbl; @@ -295,11 +295,12 @@ smbios_info(char * str) if (havebb) board = (struct smbios_board *)btbl.tblhdr; /* - * Some smbios implementations have no system vendor or product strings, - * some have very uninformative data which is harder to work around - * and we must rely upon various heuristics to detect this. In both - * cases we attempt to fall back on the base board information in the - * perhaps naive belief that motherboard vendors will supply this + * Some smbios implementations have no system vendor or + * product strings, some have very uninformative data which is + * harder to work around and we must rely upon various + * heuristics to detect this. In both cases we attempt to fall + * back on the base board information in the perhaps naive + * belief that motherboard vendors will supply this * information. */ sminfop = NULL; diff --git a/sys/arch/arm64/include/smbiosvar.h b/sys/arch/arm64/include/smbiosvar.h index 8e4b59e3fea..bb55285509c 100644 --- a/sys/arch/arm64/include/smbiosvar.h +++ b/sys/arch/arm64/include/smbiosvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smbiosvar.h,v 1.1 2019/08/04 09:27:09 kettenis Exp $ */ +/* $OpenBSD: smbiosvar.h,v 1.2 2019/08/04 14:28:58 kettenis Exp $ */ /* * Copyright (c) 2006 Gordon Willem Klok <gklok@cogeco.ca> * Copyright (c) 2005 Jordan Hargrave @@ -41,53 +41,53 @@ #define SMBIOS_UUID_REPLEN 37 /* 16 zero padded values, 4 hyphens, 1 null */ struct smbios_entry { - u_int8_t mjr; - u_int8_t min; - u_int8_t *addr; - u_int16_t len; - u_int16_t count; + uint8_t mjr; + uint8_t min; + uint8_t *addr; + uint16_t len; + uint16_t count; }; struct smbhdr { - u_int32_t sig; /* "_SM_" */ - u_int8_t checksum; /* Entry point checksum */ - u_int8_t len; /* Entry point structure length */ - u_int8_t majrev; /* Specification major revision */ - u_int8_t minrev; /* Specification minor revision */ - u_int16_t mss; /* Maximum Structure Size */ - u_int8_t epr; /* Entry Point Revision */ - u_int8_t fa[5]; /* value determined by EPR */ - u_int8_t sasig[5]; /* Secondary Anchor "_DMI_" */ - u_int8_t sachecksum; /* Secondary Checksum */ - u_int16_t size; /* Length of structure table in bytes */ - u_int32_t addr; /* Structure table address */ - u_int16_t count; /* Number of SMBIOS structures */ - u_int8_t rev; /* BCD revision */ + uint32_t sig; /* "_SM_" */ + uint8_t checksum; /* Entry point checksum */ + uint8_t len; /* Entry point structure length */ + uint8_t majrev; /* Specification major revision */ + uint8_t minrev; /* Specification minor revision */ + uint16_t mss; /* Maximum Structure Size */ + uint8_t epr; /* Entry Point Revision */ + uint8_t fa[5]; /* value determined by EPR */ + uint8_t sasig[5]; /* Secondary Anchor "_DMI_" */ + uint8_t sachecksum; /* Secondary Checksum */ + uint16_t size; /* Length of structure table in bytes */ + uint32_t addr; /* Structure table address */ + uint16_t count; /* Number of SMBIOS structures */ + uint8_t rev; /* BCD revision */ } __packed; struct smb3hdr { - u_int8_t sig[5]; /* "_SM3_" */ - u_int8_t checksum; /* Entry point structure checksum */ - u_int8_t len; /* Entry point length */ - u_int8_t majrev; /* SMBIOS major version */ - u_int8_t minrev; /* SMBIOS minor version */ - u_int8_t docrev; /* SMBIOS docrev */ - u_int8_t epr; /* Entry point revision */ - u_int8_t reserved; /* Reserved */ - u_int32_t size; /* Structure table maximum size */ - u_int64_t addr; /* Structure table address */ + uint8_t sig[5]; /* "_SM3_" */ + uint8_t checksum; /* Entry point structure checksum */ + uint8_t len; /* Entry point length */ + uint8_t majrev; /* SMBIOS major version */ + uint8_t minrev; /* SMBIOS minor version */ + uint8_t docrev; /* SMBIOS docrev */ + uint8_t epr; /* Entry point revision */ + uint8_t reserved; /* Reserved */ + uint32_t size; /* Structure table maximum size */ + uint64_t addr; /* Structure table address */ } __packed; struct smbtblhdr { - u_int8_t type; - u_int8_t size; - u_int16_t handle; + uint8_t type; + uint8_t size; + uint16_t handle; } __packed; struct smbtable { struct smbtblhdr *hdr; void *tblhdr; - u_int32_t cookie; + uint32_t cookie; }; #define SMBIOS_TYPE_BIOS 0 @@ -138,17 +138,17 @@ struct smbtable { * DMTF Specification DSP0134 Section: 3.3.1 p.g. 34 */ struct smbios_struct_bios { - u_int8_t vendor; /* string */ - u_int8_t version; /* string */ - u_int16_t startaddr; - u_int8_t release; /* string */ - u_int8_t romsize; - u_int64_t characteristics; - u_int32_t charext; - u_int8_t major_rel; - u_int8_t minor_rel; - u_int8_t ecf_mjr_rel; /* embedded controler firmware */ - u_int8_t ecf_min_rel; /* embedded controler firmware */ + uint8_t vendor; /* string */ + uint8_t version; /* string */ + uint16_t startaddr; + uint8_t release; /* string */ + uint8_t romsize; + uint64_t characteristics; + uint32_t charext; + uint8_t major_rel; + uint8_t minor_rel; + uint8_t ecf_mjr_rel; /* embedded controler firmware */ + uint8_t ecf_min_rel; /* embedded controler firmware */ } __packed; /* @@ -158,16 +158,16 @@ struct smbios_struct_bios { struct smbios_sys { /* SMBIOS spec 2.0+ */ - u_int8_t vendor; /* string */ - u_int8_t product; /* string */ - u_int8_t version; /* string */ - u_int8_t serial; /* string */ + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ /* SMBIOS spec 2.1+ */ - u_int8_t uuid[16]; - u_int8_t wakeup; + uint8_t uuid[16]; + uint8_t wakeup; /* SMBIOS spec 2.4+ */ - u_int8_t sku; /* string */ - u_int8_t family; /* string */ + uint8_t sku; /* string */ + uint8_t family; /* string */ } __packed; /* @@ -175,16 +175,16 @@ struct smbios_sys { * DMTF Specification DSP0134 Section 3.3.3 p.g. 37 */ struct smbios_board { - u_int8_t vendor; /* string */ - u_int8_t product; /* string */ - u_int8_t version; /* string */ - u_int8_t serial; /* string */ - u_int8_t asset; /* stirng */ - u_int8_t feature; /* feature flags */ - u_int8_t location; /* location in chassis */ - u_int16_t handle; /* chassis handle */ - u_int8_t type; /* board type */ - u_int8_t noc; /* number of contained objects */ + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset; /* stirng */ + uint8_t feature; /* feature flags */ + uint8_t location; /* location in chassis */ + uint16_t handle; /* chassis handle */ + uint8_t type; /* board type */ + uint8_t noc; /* number of contained objects */ } __packed; /* @@ -193,25 +193,25 @@ struct smbios_board { */ struct smbios_enclosure { /* SMBIOS spec 2.0+ */ - u_int8_t vendor; /* string */ - u_int8_t type; - u_int8_t version; /* string */ - u_int8_t serial; /* string */ - u_int8_t asset_tag; /* string */ + uint8_t vendor; /* string */ + uint8_t type; + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset_tag; /* string */ /* SMBIOS spec 2.1+ */ - u_int8_t boot_state; - u_int8_t psu_state; - u_int8_t thermal_state; - u_int8_t security_status; + uint8_t boot_state; + uint8_t psu_state; + uint8_t thermal_state; + uint8_t security_status; /* SMBIOS spec 2.3+ */ - u_int16_t oem_defined; - u_int8_t height; - u_int8_t no_power_cords; - u_int8_t no_contained_element; - u_int8_t reclen_contained_element; - u_int8_t contained_elements; + uint16_t oem_defined; + uint8_t height; + uint8_t no_power_cords; + uint8_t no_contained_element; + uint8_t reclen_contained_element; + uint8_t contained_elements; /* SMBIOS spec 2.7+ */ - u_int8_t sku; /* string */ + uint8_t sku; /* string */ } __packed; /* @@ -219,32 +219,32 @@ struct smbios_enclosure { * DMTF Specification DSP0134 v2.5 Section 3.3.5 p.g. 24 */ struct smbios_cpu { - u_int8_t cpu_socket_designation; /* string */ - u_int8_t cpu_type; - u_int8_t cpu_family; - u_int8_t cpu_mfg; /* string */ - u_int32_t cpu_id_eax; - u_int32_t cpu_id_edx; - u_int8_t cpu_version; /* string */ - u_int8_t cpu_voltage; - u_int16_t cpu_clock; - u_int16_t cpu_max_speed; - u_int16_t cpu_current_speed; - u_int8_t cpu_status; + uint8_t cpu_socket_designation; /* string */ + uint8_t cpu_type; + uint8_t cpu_family; + uint8_t cpu_mfg; /* string */ + uint32_t cpu_id_eax; + uint32_t cpu_id_edx; + uint8_t cpu_version; /* string */ + uint8_t cpu_voltage; + uint16_t cpu_clock; + uint16_t cpu_max_speed; + uint16_t cpu_current_speed; + uint8_t cpu_status; #define SMBIOS_CPUST_POPULATED (1<<6) #define SMBIOS_CPUST_STATUSMASK (0x07) - u_int8_t cpu_upgrade; - u_int16_t cpu_l1_handle; - u_int16_t cpu_l2_handle; - u_int16_t cpu_l3_handle; - u_int8_t cpu_serial; /* string */ - u_int8_t cpu_asset_tag; /* string */ - u_int8_t cpu_part_nr; /* string */ + uint8_t cpu_upgrade; + uint16_t cpu_l1_handle; + uint16_t cpu_l2_handle; + uint16_t cpu_l3_handle; + uint8_t cpu_serial; /* string */ + uint8_t cpu_asset_tag; /* string */ + uint8_t cpu_part_nr; /* string */ /* following fields were added in smbios 2.5 */ - u_int8_t cpu_core_count; - u_int8_t cpu_core_enabled; - u_int8_t cpu_thread_count; - u_int16_t cpu_characteristics; + uint8_t cpu_core_count; + uint8_t cpu_core_enabled; + uint8_t cpu_thread_count; + uint16_t cpu_characteristics; } __packed; /* @@ -252,14 +252,14 @@ struct smbios_cpu { * DMTF Specification DSP0134 Section 3.3.39 p.g. 91 */ struct smbios_ipmi { - u_int8_t smipmi_if_type; /* IPMI Interface Type */ - u_int8_t smipmi_if_rev; /* BCD IPMI Revision */ - u_int8_t smipmi_i2c_address; /* I2C address of BMC */ - u_int8_t smipmi_nvram_address; /* I2C address of NVRAM + uint8_t smipmi_if_type; /* IPMI Interface Type */ + uint8_t smipmi_if_rev; /* BCD IPMI Revision */ + uint8_t smipmi_i2c_address; /* I2C address of BMC */ + uint8_t smipmi_nvram_address; /* I2C address of NVRAM * storage */ - u_int64_t smipmi_base_address; /* Base address of BMC (BAR + uint64_t smipmi_base_address; /* Base address of BMC (BAR * format */ - u_int8_t smipmi_base_flags; /* Flags field: + uint8_t smipmi_base_flags; /* Flags field: * bit 7:6 : register spacing * 00 = byte * 01 = dword @@ -269,10 +269,10 @@ struct smbios_ipmi { * bit 2 : N/A * bit 1 : Interrupt polarity * bit 0 : Interrupt trigger */ - u_int8_t smipmi_irq; /* IRQ if applicable */ + uint8_t smipmi_irq; /* IRQ if applicable */ } __packed; -int smbios_find_table(u_int8_t, struct smbtable *); -char *smbios_get_string(struct smbtable *, u_int8_t, char *, size_t); +int smbios_find_table(uint8_t, struct smbtable *); +char *smbios_get_string(struct smbtable *, uint8_t, char *, size_t); #endif |