hv: create 8-bit sum function

Move 8-bit sum code to a separate new function calculate_sum8() in
util.h and replace the old code with a call to calculate_sum8()

Minor code cleanup in found_rsdp() to make it more readable. Both break and
continue statements are used in a single for loop, changed to only use break
statement to make the logic simpler.

Fixed some coding style issues reported by checkpatch.pl for file
hypervisor/boot/acpi_base.c

Tracked-On: #3601
Signed-off-by: dongshen <dongsheng.x.zhang@intel.com>
Reviewed-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
dongshen 2019-08-23 12:43:08 -07:00 committed by wenlingz
parent 81e2152af8
commit 96b422ce9d
2 changed files with 21 additions and 14 deletions

View File

@ -34,32 +34,22 @@
#include <ioapic.h>
#include <logmsg.h>
#include <acrn_common.h>
#include <util.h>
static struct acpi_table_rsdp *acpi_rsdp;
static struct acpi_table_rsdp *found_rsdp(char *base, int32_t length)
{
struct acpi_table_rsdp *rsdp, *ret = NULL;
uint8_t *cp, sum;
int32_t ofs;
uint32_t idx;
/* search on 16-byte boundaries */
for (ofs = 0; ofs < length; ofs += 16) {
rsdp = (struct acpi_table_rsdp *)(base + ofs);
/* compare signature, validate checksum */
if (strncmp(rsdp->signature, ACPI_SIG_RSDP, strnlen_s(ACPI_SIG_RSDP, 8U)) == 0) {
cp = (uint8_t *)rsdp;
sum = 0U;
for (idx = 0; idx < ACPI_RSDP_CHECKSUM_LENGTH; idx++) {
sum += *(cp + idx);
}
if (sum != 0U) {
continue;
}
if ((strncmp(rsdp->signature, ACPI_SIG_RSDP, strnlen_s(ACPI_SIG_RSDP, sizeof(rsdp->signature))) == 0)
&& (calculate_sum8(rsdp, ACPI_RSDP_CHECKSUM_LENGTH) == 0U)) {
ret = rsdp;
break;
}
@ -112,7 +102,7 @@ static bool probe_table(uint64_t address, const char *signature)
bool ret;
if (strncmp(table->signature, signature, ACPI_NAME_SIZE) != 0) {
ret = false;
ret = false;
} else {
ret = true;
}
@ -245,6 +235,7 @@ uint16_t parse_madt(uint32_t lapic_id_array[CONFIG_MAX_PCPU_NUM])
rsdp = get_rsdp();
if (rsdp != NULL) {
struct acpi_table_madt *madt = (struct acpi_table_madt *)get_acpi_tbl(ACPI_SIG_MADT);
if (madt != NULL) {
ret = local_parse_madt(madt, lapic_id_array);
}
@ -261,6 +252,7 @@ uint16_t parse_madt_ioapic(struct ioapic_info *ioapic_id_array)
rsdp = get_rsdp();
if (rsdp != NULL) {
void *madt = get_acpi_tbl(ACPI_SIG_MADT);
if (madt != NULL) {
ret = ioapic_parse_madt(madt, ioapic_id_array);
}

View File

@ -31,4 +31,19 @@ static inline bool mem_aligned_check(uint64_t value, uint64_t req_align)
return ((value & (req_align - 1UL)) == 0UL);
}
/**
* @pre buf != NULL
*/
static inline uint8_t calculate_sum8(const void *buf, uint32_t length)
{
uint32_t i;
uint8_t sum = 0U;
for (i = 0U; i < length; i++) {
sum += *((const uint8_t *)buf + i);
}
return sum;
}
#endif /* UTIL_H */