Skip to content

Commit 96b422c

Browse files
donshengwenlingz
authored andcommitted
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>
1 parent 81e2152 commit 96b422c

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

hypervisor/boot/acpi_base.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,22 @@
3434
#include <ioapic.h>
3535
#include <logmsg.h>
3636
#include <acrn_common.h>
37+
#include <util.h>
3738

3839
static struct acpi_table_rsdp *acpi_rsdp;
3940

4041
static struct acpi_table_rsdp *found_rsdp(char *base, int32_t length)
4142
{
4243
struct acpi_table_rsdp *rsdp, *ret = NULL;
43-
uint8_t *cp, sum;
4444
int32_t ofs;
45-
uint32_t idx;
4645

4746
/* search on 16-byte boundaries */
4847
for (ofs = 0; ofs < length; ofs += 16) {
4948
rsdp = (struct acpi_table_rsdp *)(base + ofs);
5049

5150
/* compare signature, validate checksum */
52-
if (strncmp(rsdp->signature, ACPI_SIG_RSDP, strnlen_s(ACPI_SIG_RSDP, 8U)) == 0) {
53-
cp = (uint8_t *)rsdp;
54-
sum = 0U;
55-
for (idx = 0; idx < ACPI_RSDP_CHECKSUM_LENGTH; idx++) {
56-
sum += *(cp + idx);
57-
}
58-
59-
if (sum != 0U) {
60-
continue;
61-
}
62-
51+
if ((strncmp(rsdp->signature, ACPI_SIG_RSDP, strnlen_s(ACPI_SIG_RSDP, sizeof(rsdp->signature))) == 0)
52+
&& (calculate_sum8(rsdp, ACPI_RSDP_CHECKSUM_LENGTH) == 0U)) {
6353
ret = rsdp;
6454
break;
6555
}
@@ -112,7 +102,7 @@ static bool probe_table(uint64_t address, const char *signature)
112102
bool ret;
113103

114104
if (strncmp(table->signature, signature, ACPI_NAME_SIZE) != 0) {
115-
ret = false;
105+
ret = false;
116106
} else {
117107
ret = true;
118108
}
@@ -245,6 +235,7 @@ uint16_t parse_madt(uint32_t lapic_id_array[CONFIG_MAX_PCPU_NUM])
245235
rsdp = get_rsdp();
246236
if (rsdp != NULL) {
247237
struct acpi_table_madt *madt = (struct acpi_table_madt *)get_acpi_tbl(ACPI_SIG_MADT);
238+
248239
if (madt != NULL) {
249240
ret = local_parse_madt(madt, lapic_id_array);
250241
}
@@ -261,6 +252,7 @@ uint16_t parse_madt_ioapic(struct ioapic_info *ioapic_id_array)
261252
rsdp = get_rsdp();
262253
if (rsdp != NULL) {
263254
void *madt = get_acpi_tbl(ACPI_SIG_MADT);
255+
264256
if (madt != NULL) {
265257
ret = ioapic_parse_madt(madt, ioapic_id_array);
266258
}

hypervisor/include/lib/util.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,19 @@ static inline bool mem_aligned_check(uint64_t value, uint64_t req_align)
3131
return ((value & (req_align - 1UL)) == 0UL);
3232
}
3333

34+
/**
35+
* @pre buf != NULL
36+
*/
37+
static inline uint8_t calculate_sum8(const void *buf, uint32_t length)
38+
{
39+
uint32_t i;
40+
uint8_t sum = 0U;
41+
42+
for (i = 0U; i < length; i++) {
43+
sum += *((const uint8_t *)buf + i);
44+
}
45+
46+
return sum;
47+
}
48+
3449
#endif /* UTIL_H */

0 commit comments

Comments
 (0)