Skip to content

Commit 1cd59b8

Browse files
mchehabmstsirkin
authored andcommitted
acpi/ghes: move offset calculus to a separate function
Currently, CPER address location is calculated as an offset of the hardware_errors table. It is also badly named, as the offset actually used is the address where the CPER data starts, and not the beginning of the error source. Move the logic which calculates such offset to a separate function, in preparation for a patch that will be changing the logic to calculate it from the HEST table. While here, properly name the variable which stores the cper address. Signed-off-by: Mauro Carvalho Chehab <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Message-Id: <60fdd1bf379ba1db3099710868802aa49a27febb.1736945236.git.mchehab+huawei@kernel.org> Reviewed-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 652f6d8 commit 1cd59b8

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

hw/acpi/ghes.c

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,37 @@ void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,
364364
ags->present = true;
365365
}
366366

367+
static void get_hw_error_offsets(uint64_t ghes_addr,
368+
uint64_t *cper_addr,
369+
uint64_t *read_ack_register_addr)
370+
{
371+
if (!ghes_addr) {
372+
return;
373+
}
374+
375+
/*
376+
* non-HEST version supports only one source, so no need to change
377+
* the start offset based on the source ID. Also, we can't validate
378+
* the source ID, as it is stored inside the HEST table.
379+
*/
380+
381+
cpu_physical_memory_read(ghes_addr, cper_addr,
382+
sizeof(*cper_addr));
383+
384+
*cper_addr = le64_to_cpu(*cper_addr);
385+
386+
/*
387+
* As the current version supports only one source, the ack offset is
388+
* just sizeof(uint64_t).
389+
*/
390+
*read_ack_register_addr = ghes_addr +
391+
ACPI_GHES_ERROR_SOURCE_COUNT * sizeof(uint64_t);
392+
}
393+
367394
void ghes_record_cper_errors(const void *cper, size_t len,
368395
uint16_t source_id, Error **errp)
369396
{
370-
uint64_t error_block_addr, read_ack_register_addr, read_ack_register = 0;
397+
uint64_t cper_addr = 0, read_ack_register_addr = 0, read_ack_register;
371398
uint64_t start_addr;
372399
AcpiGedState *acpi_ged_state;
373400
AcpiGhesState *ags;
@@ -389,18 +416,13 @@ void ghes_record_cper_errors(const void *cper, size_t len,
389416

390417
start_addr += source_id * sizeof(uint64_t);
391418

392-
cpu_physical_memory_read(start_addr, &error_block_addr,
393-
sizeof(error_block_addr));
419+
get_hw_error_offsets(start_addr, &cper_addr, &read_ack_register_addr);
394420

395-
error_block_addr = le64_to_cpu(error_block_addr);
396-
if (!error_block_addr) {
421+
if (!cper_addr) {
397422
error_setg(errp, "can not find Generic Error Status Block");
398423
return;
399424
}
400425

401-
read_ack_register_addr = start_addr +
402-
ACPI_GHES_ERROR_SOURCE_COUNT * sizeof(uint64_t);
403-
404426
cpu_physical_memory_read(read_ack_register_addr,
405427
&read_ack_register, sizeof(read_ack_register));
406428

@@ -421,7 +443,7 @@ void ghes_record_cper_errors(const void *cper, size_t len,
421443
&read_ack_register, sizeof(uint64_t));
422444

423445
/* Write the generic error data entry into guest memory */
424-
cpu_physical_memory_write(error_block_addr, cper, len);
446+
cpu_physical_memory_write(cper_addr, cper, len);
425447

426448
return;
427449
}

0 commit comments

Comments
 (0)