12
#include "qemu/osdep.h"
13
#include "qapi/error.h"
14
#include "hw/qdev-core.h"
15
#include "exec/memory.h"
16
#include "qom/object.h"
17
#include "hw/pci/pci_device.h"
18
#include "qom/object_interfaces.h"
19
#include "qemu/error-report.h"
20
#include "migration/vmstate.h"
21
#include "hw/qdev-properties.h"
22
#include "hw/acpi/acpi.h"
23
#include "hw/acpi/acpi-defs.h"
24
#include "hw/acpi/aml-build.h"
25
#include "hw/acpi/bios-linker-loader.h"
26
#include "exec/address-spaces.h"
27
#include "sysemu/hostmem.h"
28
#include "hw/acpi/erst.h"
32
#define ACTION_BEGIN_WRITE_OPERATION 0x0
33
#define ACTION_BEGIN_READ_OPERATION 0x1
34
#define ACTION_BEGIN_CLEAR_OPERATION 0x2
35
#define ACTION_END_OPERATION 0x3
36
#define ACTION_SET_RECORD_OFFSET 0x4
37
#define ACTION_EXECUTE_OPERATION 0x5
38
#define ACTION_CHECK_BUSY_STATUS 0x6
39
#define ACTION_GET_COMMAND_STATUS 0x7
40
#define ACTION_GET_RECORD_IDENTIFIER 0x8
41
#define ACTION_SET_RECORD_IDENTIFIER 0x9
42
#define ACTION_GET_RECORD_COUNT 0xA
43
#define ACTION_BEGIN_DUMMY_WRITE_OPERATION 0xB
44
#define ACTION_RESERVED 0xC
45
#define ACTION_GET_ERROR_LOG_ADDRESS_RANGE 0xD
46
#define ACTION_GET_ERROR_LOG_ADDRESS_LENGTH 0xE
47
#define ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES 0xF
48
#define ACTION_GET_EXECUTE_OPERATION_TIMINGS 0x10
51
#define STATUS_SUCCESS 0x00
52
#define STATUS_NOT_ENOUGH_SPACE 0x01
53
#define STATUS_HARDWARE_NOT_AVAILABLE 0x02
54
#define STATUS_FAILED 0x03
55
#define STATUS_RECORD_STORE_EMPTY 0x04
56
#define STATUS_RECORD_NOT_FOUND 0x05
59
#define INST_READ_REGISTER 0x00
60
#define INST_READ_REGISTER_VALUE 0x01
61
#define INST_WRITE_REGISTER 0x02
62
#define INST_WRITE_REGISTER_VALUE 0x03
64
#define INST_LOAD_VAR1 0x05
65
#define INST_LOAD_VAR2 0x06
66
#define INST_STORE_VAR1 0x07
68
#define INST_SUBTRACT 0x09
69
#define INST_ADD_VALUE 0x0A
70
#define INST_SUBTRACT_VALUE 0x0B
71
#define INST_STALL 0x0C
72
#define INST_STALL_WHILE_TRUE 0x0D
73
#define INST_SKIP_NEXT_INSTRUCTION_IF_TRUE 0x0E
75
#define INST_SET_SRC_ADDRESS_BASE 0x10
76
#define INST_SET_DST_ADDRESS_BASE 0x11
77
#define INST_MOVE_DATA 0x12
80
#define UEFI_CPER_RECORD_MIN_SIZE 128U
81
#define UEFI_CPER_RECORD_LENGTH_OFFSET 20U
82
#define UEFI_CPER_RECORD_ID_OFFSET 96U
93
#define ERST_REG_SIZE (16UL)
94
#define ERST_ACTION_OFFSET (0UL)
95
#define ERST_VALUE_OFFSET (8UL)
112
#define ERST_RECORD_SIZE (8192UL)
114
#define ACPI_ERST_MEMDEV_PROP "memdev"
115
#define ACPI_ERST_RECORD_SIZE_PROP "record_size"
122
#define ERST_UNSPECIFIED_RECORD_ID (0UL)
123
#define ERST_EMPTY_END_RECORD_ID (~0UL)
125
#define ERST_IS_VALID_RECORD_ID(rid) \
126
((rid != ERST_UNSPECIFIED_RECORD_ID) && \
127
(rid != ERST_EMPTY_END_RECORD_ID))
134
#define ERST_EXECUTE_OPERATION_MAGIC 0x9CUL
135
#define ERST_STORE_MAGIC 0x524F545354535245UL
138
uint32_t record_size;
139
uint32_t storage_offset;
142
uint32_t record_count;
144
} __attribute__((packed)) ERSTStorageHeader;
149
#define ACPIERST(obj) \
150
OBJECT_CHECK(ERSTDeviceState, (obj), TYPE_ACPI_ERST)
156
PCIDevice parent_obj;
159
HostMemoryBackend *hostmem;
160
MemoryRegion *hostmem_mr;
161
uint32_t storage_size;
162
uint32_t default_record_size;
165
MemoryRegion iomem_mr;
168
MemoryRegion exchange_mr;
173
uint8_t command_status;
174
uint32_t record_offset;
177
uint64_t record_identifier;
178
ERSTStorageHeader *header;
179
unsigned first_record_index;
180
unsigned last_record_index;
181
unsigned next_record_index;
192
uint8_t register_bit_width;
193
pcibus_t register_offset;
194
} BuildSerializationInstructionEntry;
197
static void build_serialization_instruction(
198
BuildSerializationInstructionEntry *e,
199
uint8_t serialization_action,
203
struct AcpiGenericAddress gas;
207
build_append_int_noprefix(e->table_data, serialization_action, 1);
209
build_append_int_noprefix(e->table_data, e->instruction, 1);
211
build_append_int_noprefix(e->table_data, e->flags, 1);
213
build_append_int_noprefix(e->table_data, 0, 1);
215
gas.space_id = AML_SYSTEM_MEMORY;
216
gas.bit_width = e->register_bit_width;
218
gas.access_width = (uint8_t)ctz32(e->register_bit_width) - 2;
219
gas.address = (uint64_t)(e->bar + e->register_offset);
220
build_append_gas_from_struct(e->table_data, &gas);
222
build_append_int_noprefix(e->table_data, value, 8);
224
mask = (1ULL << (e->register_bit_width - 1) << 1) - 1;
225
build_append_int_noprefix(e->table_data, mask, 8);
229
void build_erst(GArray *table_data, BIOSLinker *linker, Object *erst_dev,
230
const char *oem_id, const char *oem_table_id)
239
GArray *table_instruction_data = g_array_new(FALSE, FALSE, sizeof(char));
240
pcibus_t bar0 = pci_get_bar_addr(PCI_DEVICE(erst_dev), 0);
241
AcpiTable table = { .sig = "ERST", .rev = 1, .oem_id = oem_id,
242
.oem_table_id = oem_table_id };
244
BuildSerializationInstructionEntry rd_value_32_val = {
245
.table_data = table_instruction_data, .bar = bar0, .flags = 0,
246
.instruction = INST_READ_REGISTER_VALUE,
247
.register_bit_width = 32,
248
.register_offset = ERST_VALUE_OFFSET,
250
BuildSerializationInstructionEntry rd_value_32 = {
251
.table_data = table_instruction_data, .bar = bar0, .flags = 0,
252
.instruction = INST_READ_REGISTER,
253
.register_bit_width = 32,
254
.register_offset = ERST_VALUE_OFFSET,
256
BuildSerializationInstructionEntry rd_value_64 = {
257
.table_data = table_instruction_data, .bar = bar0, .flags = 0,
258
.instruction = INST_READ_REGISTER,
259
.register_bit_width = 64,
260
.register_offset = ERST_VALUE_OFFSET,
262
BuildSerializationInstructionEntry wr_value_32_val = {
263
.table_data = table_instruction_data, .bar = bar0, .flags = 0,
264
.instruction = INST_WRITE_REGISTER_VALUE,
265
.register_bit_width = 32,
266
.register_offset = ERST_VALUE_OFFSET,
268
BuildSerializationInstructionEntry wr_value_32 = {
269
.table_data = table_instruction_data, .bar = bar0, .flags = 0,
270
.instruction = INST_WRITE_REGISTER,
271
.register_bit_width = 32,
272
.register_offset = ERST_VALUE_OFFSET,
274
BuildSerializationInstructionEntry wr_value_64 = {
275
.table_data = table_instruction_data, .bar = bar0, .flags = 0,
276
.instruction = INST_WRITE_REGISTER,
277
.register_bit_width = 64,
278
.register_offset = ERST_VALUE_OFFSET,
280
BuildSerializationInstructionEntry wr_action = {
281
.table_data = table_instruction_data, .bar = bar0, .flags = 0,
282
.instruction = INST_WRITE_REGISTER_VALUE,
283
.register_bit_width = 32,
284
.register_offset = ERST_ACTION_OFFSET,
287
trace_acpi_erst_pci_bar_0(bar0);
290
action = ACTION_BEGIN_WRITE_OPERATION;
291
build_serialization_instruction(&wr_action, action, action);
293
action = ACTION_BEGIN_READ_OPERATION;
294
build_serialization_instruction(&wr_action, action, action);
296
action = ACTION_BEGIN_CLEAR_OPERATION;
297
build_serialization_instruction(&wr_action, action, action);
299
action = ACTION_END_OPERATION;
300
build_serialization_instruction(&wr_action, action, action);
302
action = ACTION_SET_RECORD_OFFSET;
303
build_serialization_instruction(&wr_value_32, action, 0);
304
build_serialization_instruction(&wr_action, action, action);
306
action = ACTION_EXECUTE_OPERATION;
307
build_serialization_instruction(&wr_value_32_val, action,
308
ERST_EXECUTE_OPERATION_MAGIC);
309
build_serialization_instruction(&wr_action, action, action);
311
action = ACTION_CHECK_BUSY_STATUS;
312
build_serialization_instruction(&wr_action, action, action);
313
build_serialization_instruction(&rd_value_32_val, action, 0x01);
315
action = ACTION_GET_COMMAND_STATUS;
316
build_serialization_instruction(&wr_action, action, action);
317
build_serialization_instruction(&rd_value_32, action, 0);
319
action = ACTION_GET_RECORD_IDENTIFIER;
320
build_serialization_instruction(&wr_action, action, action);
321
build_serialization_instruction(&rd_value_64, action, 0);
323
action = ACTION_SET_RECORD_IDENTIFIER;
324
build_serialization_instruction(&wr_value_64, action, 0);
325
build_serialization_instruction(&wr_action, action, action);
327
action = ACTION_GET_RECORD_COUNT;
328
build_serialization_instruction(&wr_action, action, action);
329
build_serialization_instruction(&rd_value_32, action, 0);
331
action = ACTION_BEGIN_DUMMY_WRITE_OPERATION;
332
build_serialization_instruction(&wr_action, action, action);
334
action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE;
335
build_serialization_instruction(&wr_action, action, action);
336
build_serialization_instruction(&rd_value_64, action, 0);
338
action = ACTION_GET_ERROR_LOG_ADDRESS_LENGTH;
339
build_serialization_instruction(&wr_action, action, action);
340
build_serialization_instruction(&rd_value_64, action, 0);
342
action = ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES;
343
build_serialization_instruction(&wr_action, action, action);
344
build_serialization_instruction(&rd_value_32, action, 0);
346
action = ACTION_GET_EXECUTE_OPERATION_TIMINGS;
347
build_serialization_instruction(&wr_action, action, action);
348
build_serialization_instruction(&rd_value_64, action, 0);
351
acpi_table_begin(&table, table_data);
354
build_append_int_noprefix(table_data, 48, 4);
357
build_append_int_noprefix(table_data, 0, 4);
363
g_assert((table_instruction_data->len) % 32 == 0);
364
build_append_int_noprefix(table_data,
365
(table_instruction_data->len / 32), 4);
368
g_array_append_vals(table_data, table_instruction_data->data,
369
table_instruction_data->len);
370
g_array_free(table_instruction_data, TRUE);
372
acpi_table_end(linker, &table);
377
static uint8_t *get_nvram_ptr_by_index(ERSTDeviceState *s, unsigned index)
380
off_t offset = (index * le32_to_cpu(s->header->record_size));
382
g_assert(offset < s->storage_size);
384
rc = memory_region_get_ram_ptr(s->hostmem_mr);
390
static void make_erst_storage_header(ERSTDeviceState *s)
392
ERSTStorageHeader *header = s->header;
393
unsigned mapsz, headersz;
395
header->magic = cpu_to_le64(ERST_STORE_MAGIC);
396
header->record_size = cpu_to_le32(s->default_record_size);
397
header->version = cpu_to_le16(0x0100);
398
header->reserved = cpu_to_le16(0x0000);
401
mapsz = s->storage_size / s->default_record_size;
402
mapsz *= sizeof(uint64_t);
404
headersz = sizeof(ERSTStorageHeader) + mapsz;
406
headersz = QEMU_ALIGN_UP(headersz, s->default_record_size);
407
header->storage_offset = cpu_to_le32(headersz);
416
static void check_erst_backend_storage(ERSTDeviceState *s, Error **errp)
418
ERSTStorageHeader *header;
419
uint32_t record_size;
421
header = memory_region_get_ram_ptr(s->hostmem_mr);
425
g_assert(QEMU_PTR_IS_ALIGNED(header, sizeof(uint64_t)));
430
if (le64_to_cpu(header->magic) == 0UL) {
431
make_erst_storage_header(s);
435
record_size = le32_to_cpu(header->record_size);
438
(record_size >= UEFI_CPER_RECORD_MIN_SIZE) &&
439
(((record_size - 1) & record_size) == 0) &&
440
(record_size >= 4096)
442
error_setg(errp, "ERST record_size %u is invalid", record_size);
448
(le64_to_cpu(header->magic) == ERST_STORE_MAGIC) &&
449
((le32_to_cpu(header->storage_offset) % record_size) == 0) &&
450
(le16_to_cpu(header->version) == 0x0100) &&
451
(le16_to_cpu(header->reserved) == 0)
453
error_setg(errp, "ERST backend storage header is invalid");
458
if (((s->storage_size % record_size) != 0) ||
459
(record_size > s->storage_size)) {
460
error_setg(errp, "ACPI ERST requires storage size be multiple of "
461
"record size (%uKiB)", record_size);
466
s->first_record_index = le32_to_cpu(header->storage_offset)
468
s->last_record_index = (s->storage_size / record_size);
471
static void update_map_entry(ERSTDeviceState *s, unsigned index,
474
if (index < s->last_record_index) {
475
s->header->map[index] = cpu_to_le64(record_id);
479
static unsigned find_next_empty_record_index(ERSTDeviceState *s)
482
unsigned index = s->first_record_index;
484
for (; index < s->last_record_index; ++index) {
485
if (le64_to_cpu(s->header->map[index]) == ERST_UNSPECIFIED_RECORD_ID) {
494
static unsigned lookup_erst_record(ERSTDeviceState *s,
495
uint64_t record_identifier)
500
if (record_identifier != ERST_UNSPECIFIED_RECORD_ID) {
505
uint32_t record_count = le32_to_cpu(s->header->record_count);
508
for (index = s->first_record_index; index < s->last_record_index &&
509
count < record_count; ++index) {
510
if (le64_to_cpu(s->header->map[index]) == record_identifier) {
514
if (le64_to_cpu(s->header->map[index]) !=
515
ERST_UNSPECIFIED_RECORD_ID) {
528
static unsigned get_next_record_identifier(ERSTDeviceState *s,
529
uint64_t *record_identifier, bool first)
537
s->next_record_index = s->first_record_index;
539
index = s->next_record_index;
541
*record_identifier = ERST_EMPTY_END_RECORD_ID;
543
if (le32_to_cpu(s->header->record_count)) {
544
for (; index < s->last_record_index; ++index) {
545
if (le64_to_cpu(s->header->map[index]) !=
546
ERST_UNSPECIFIED_RECORD_ID) {
548
s->next_record_index = index + 1;
549
*record_identifier = le64_to_cpu(s->header->map[index]);
557
s->next_record_index = s->first_record_index;
560
return STATUS_SUCCESS;
564
static unsigned clear_erst_record(ERSTDeviceState *s)
566
unsigned rc = STATUS_RECORD_NOT_FOUND;
570
if (!ERST_IS_VALID_RECORD_ID(s->record_identifier)) {
571
return STATUS_FAILED;
574
index = lookup_erst_record(s, s->record_identifier);
577
uint32_t record_count;
578
update_map_entry(s, index, ERST_UNSPECIFIED_RECORD_ID);
579
record_count = le32_to_cpu(s->header->record_count);
581
s->header->record_count = cpu_to_le32(record_count);
589
static unsigned read_erst_record(ERSTDeviceState *s)
591
unsigned rc = STATUS_RECORD_NOT_FOUND;
592
unsigned exchange_length;
596
if (le32_to_cpu(s->header->record_count) == 0) {
597
return STATUS_RECORD_STORE_EMPTY;
600
exchange_length = memory_region_size(&s->exchange_mr);
603
if (s->record_identifier == ERST_UNSPECIFIED_RECORD_ID) {
605
get_next_record_identifier(s, &s->record_identifier, true);
610
if (s->record_identifier == ERST_EMPTY_END_RECORD_ID) {
611
return STATUS_FAILED;
615
if (s->record_offset > (exchange_length - UEFI_CPER_RECORD_MIN_SIZE)) {
616
return STATUS_FAILED;
619
index = lookup_erst_record(s, s->record_identifier);
623
uint32_t record_length;
626
exchange = memory_region_get_ram_ptr(&s->exchange_mr);
627
exchange += s->record_offset;
629
nvram = get_nvram_ptr_by_index(s, index);
631
memcpy((uint8_t *)&record_length,
632
&nvram[UEFI_CPER_RECORD_LENGTH_OFFSET],
634
record_length = le32_to_cpu(record_length);
635
if (record_length < UEFI_CPER_RECORD_MIN_SIZE) {
638
if (record_length > exchange_length - s->record_offset) {
642
if (rc != STATUS_FAILED) {
643
memcpy(exchange, nvram, record_length);
651
get_next_record_identifier(s, &s->record_identifier, true);
658
static unsigned write_erst_record(ERSTDeviceState *s)
660
unsigned rc = STATUS_FAILED;
661
unsigned exchange_length;
663
uint64_t record_identifier;
664
uint32_t record_length;
666
uint8_t *nvram = NULL;
667
bool record_found = false;
669
exchange_length = memory_region_size(&s->exchange_mr);
672
if (s->record_offset > (exchange_length - UEFI_CPER_RECORD_MIN_SIZE)) {
673
return STATUS_FAILED;
677
exchange = memory_region_get_ram_ptr(&s->exchange_mr);
678
exchange += s->record_offset;
681
memcpy((uint8_t *)&record_length, &exchange[UEFI_CPER_RECORD_LENGTH_OFFSET],
683
record_length = le32_to_cpu(record_length);
684
if (record_length < UEFI_CPER_RECORD_MIN_SIZE) {
685
return STATUS_FAILED;
687
if (record_length > exchange_length - s->record_offset) {
688
return STATUS_FAILED;
692
memcpy((uint8_t *)&record_identifier, &exchange[UEFI_CPER_RECORD_ID_OFFSET],
694
record_identifier = le64_to_cpu(record_identifier);
697
if (!ERST_IS_VALID_RECORD_ID(record_identifier)) {
698
return STATUS_FAILED;
701
index = lookup_erst_record(s, record_identifier);
704
nvram = get_nvram_ptr_by_index(s, index);
708
index = find_next_empty_record_index(s);
710
nvram = get_nvram_ptr_by_index(s, index);
713
rc = STATUS_NOT_ENOUGH_SPACE;
718
memcpy(nvram, exchange, record_length);
719
memset(nvram + record_length, 0xFF, exchange_length - record_length);
722
uint32_t record_count;
723
record_count = le32_to_cpu(s->header->record_count);
725
s->header->record_count = cpu_to_le32(record_count);
727
update_map_entry(s, index, record_identifier);
736
static uint64_t erst_rd_reg64(hwaddr addr,
737
uint64_t reg, unsigned size)
743
if (size == sizeof(uint64_t)) {
745
mask = 0xFFFFFFFFFFFFFFFFUL;
749
mask = 0x00000000FFFFFFFFUL;
750
shift = ((addr & 0x4) == 0x4) ? 32 : 0;
760
static uint64_t erst_wr_reg64(hwaddr addr,
761
uint64_t reg, uint64_t val, unsigned size)
767
if (size == sizeof(uint64_t)) {
769
mask = 0xFFFFFFFFFFFFFFFFUL;
773
mask = 0x00000000FFFFFFFFUL;
774
shift = ((addr & 0x4) == 0x4) ? 32 : 0;
787
static void erst_reg_write(void *opaque, hwaddr addr,
788
uint64_t val, unsigned size)
790
ERSTDeviceState *s = (ERSTDeviceState *)opaque;
797
trace_acpi_erst_reg_write(addr, val, size);
800
case ERST_VALUE_OFFSET + 0:
801
case ERST_VALUE_OFFSET + 4:
802
s->reg_value = erst_wr_reg64(addr, s->reg_value, val, size);
804
case ERST_ACTION_OFFSET + 0:
812
case ACTION_BEGIN_WRITE_OPERATION:
813
case ACTION_BEGIN_READ_OPERATION:
814
case ACTION_BEGIN_CLEAR_OPERATION:
815
case ACTION_BEGIN_DUMMY_WRITE_OPERATION:
816
case ACTION_END_OPERATION:
819
case ACTION_SET_RECORD_OFFSET:
820
s->record_offset = s->reg_value;
822
case ACTION_EXECUTE_OPERATION:
823
if ((uint8_t)s->reg_value == ERST_EXECUTE_OPERATION_MAGIC) {
825
switch (s->operation) {
826
case ACTION_BEGIN_WRITE_OPERATION:
827
s->command_status = write_erst_record(s);
829
case ACTION_BEGIN_READ_OPERATION:
830
s->command_status = read_erst_record(s);
832
case ACTION_BEGIN_CLEAR_OPERATION:
833
s->command_status = clear_erst_record(s);
835
case ACTION_BEGIN_DUMMY_WRITE_OPERATION:
836
s->command_status = STATUS_SUCCESS;
838
case ACTION_END_OPERATION:
839
s->command_status = STATUS_SUCCESS;
842
s->command_status = STATUS_FAILED;
848
case ACTION_CHECK_BUSY_STATUS:
849
s->reg_value = s->busy_status;
851
case ACTION_GET_COMMAND_STATUS:
852
s->reg_value = s->command_status;
854
case ACTION_GET_RECORD_IDENTIFIER:
855
s->command_status = get_next_record_identifier(s,
856
&s->reg_value, false);
858
case ACTION_SET_RECORD_IDENTIFIER:
859
s->record_identifier = s->reg_value;
861
case ACTION_GET_RECORD_COUNT:
862
s->reg_value = le32_to_cpu(s->header->record_count);
864
case ACTION_GET_ERROR_LOG_ADDRESS_RANGE:
865
s->reg_value = (hwaddr)pci_get_bar_addr(PCI_DEVICE(s), 1);
867
case ACTION_GET_ERROR_LOG_ADDRESS_LENGTH:
868
s->reg_value = le32_to_cpu(s->header->record_size);
870
case ACTION_GET_ERROR_LOG_ADDRESS_RANGE_ATTRIBUTES:
873
case ACTION_GET_EXECUTE_OPERATION_TIMINGS:
889
static uint64_t erst_reg_read(void *opaque, hwaddr addr,
892
ERSTDeviceState *s = (ERSTDeviceState *)opaque;
896
case ERST_ACTION_OFFSET + 0:
897
case ERST_ACTION_OFFSET + 4:
898
val = erst_rd_reg64(addr, s->reg_action, size);
900
case ERST_VALUE_OFFSET + 0:
901
case ERST_VALUE_OFFSET + 4:
902
val = erst_rd_reg64(addr, s->reg_value, size);
907
trace_acpi_erst_reg_read(addr, val, size);
911
static const MemoryRegionOps erst_reg_ops = {
912
.read = erst_reg_read,
913
.write = erst_reg_write,
914
.endianness = DEVICE_NATIVE_ENDIAN,
919
static int erst_post_load(void *opaque, int version_id)
921
ERSTDeviceState *s = opaque;
924
s->header = (ERSTStorageHeader *)get_nvram_ptr_by_index(s, 0);
925
trace_acpi_erst_post_load(s->header, le32_to_cpu(s->header->record_size));
930
static const VMStateDescription erst_vmstate = {
933
.minimum_version_id = 1,
934
.post_load = erst_post_load,
935
.fields = (const VMStateField[]) {
936
VMSTATE_UINT8(operation, ERSTDeviceState),
937
VMSTATE_UINT8(busy_status, ERSTDeviceState),
938
VMSTATE_UINT8(command_status, ERSTDeviceState),
939
VMSTATE_UINT32(record_offset, ERSTDeviceState),
940
VMSTATE_UINT64(reg_action, ERSTDeviceState),
941
VMSTATE_UINT64(reg_value, ERSTDeviceState),
942
VMSTATE_UINT64(record_identifier, ERSTDeviceState),
943
VMSTATE_UINT32(next_record_index, ERSTDeviceState),
944
VMSTATE_END_OF_LIST()
948
static void erst_realizefn(PCIDevice *pci_dev, Error **errp)
951
ERSTDeviceState *s = ACPIERST(pci_dev);
953
trace_acpi_erst_realizefn_in();
956
error_setg(errp, "'" ACPI_ERST_MEMDEV_PROP "' property is not set");
958
} else if (host_memory_backend_is_mapped(s->hostmem)) {
959
error_setg(errp, "can't use already busy memdev: %s",
960
object_get_canonical_path_component(OBJECT(s->hostmem)));
964
s->hostmem_mr = host_memory_backend_get_memory(s->hostmem);
967
s->storage_size = object_property_get_int(OBJECT(s->hostmem), "size", errp);
973
check_erst_backend_storage(s, errp);
979
memory_region_init_io(&s->iomem_mr, OBJECT(pci_dev), &erst_reg_ops, s,
980
TYPE_ACPI_ERST, ERST_REG_SIZE);
981
pci_register_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->iomem_mr);
984
memory_region_init_ram(&s->exchange_mr, OBJECT(pci_dev),
986
le32_to_cpu(s->header->record_size), errp);
990
pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY,
994
vmstate_register_ram_global(s->hostmem_mr);
996
trace_acpi_erst_realizefn_out(s->storage_size);
999
static void erst_reset(DeviceState *dev)
1001
ERSTDeviceState *s = ACPIERST(dev);
1003
trace_acpi_erst_reset_in(le32_to_cpu(s->header->record_count));
1006
s->command_status = STATUS_SUCCESS;
1007
s->record_identifier = ERST_UNSPECIFIED_RECORD_ID;
1008
s->record_offset = 0;
1009
s->next_record_index = s->first_record_index;
1011
trace_acpi_erst_reset_out(le32_to_cpu(s->header->record_count));
1014
static Property erst_properties[] = {
1015
DEFINE_PROP_LINK(ACPI_ERST_MEMDEV_PROP, ERSTDeviceState, hostmem,
1016
TYPE_MEMORY_BACKEND, HostMemoryBackend *),
1017
DEFINE_PROP_UINT32(ACPI_ERST_RECORD_SIZE_PROP, ERSTDeviceState,
1018
default_record_size, ERST_RECORD_SIZE),
1019
DEFINE_PROP_END_OF_LIST(),
1022
static void erst_class_init(ObjectClass *klass, void *data)
1024
DeviceClass *dc = DEVICE_CLASS(klass);
1025
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
1027
trace_acpi_erst_class_init_in();
1028
k->realize = erst_realizefn;
1029
k->vendor_id = PCI_VENDOR_ID_REDHAT;
1030
k->device_id = PCI_DEVICE_ID_REDHAT_ACPI_ERST;
1032
k->class_id = PCI_CLASS_OTHERS;
1033
dc->reset = erst_reset;
1034
dc->vmsd = &erst_vmstate;
1035
dc->user_creatable = true;
1036
dc->hotpluggable = false;
1037
device_class_set_props(dc, erst_properties);
1038
dc->desc = "ACPI Error Record Serialization Table (ERST) device";
1039
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
1040
trace_acpi_erst_class_init_out();
1043
static const TypeInfo erst_type_info = {
1044
.name = TYPE_ACPI_ERST,
1045
.parent = TYPE_PCI_DEVICE,
1046
.class_init = erst_class_init,
1047
.instance_size = sizeof(ERSTDeviceState),
1048
.interfaces = (InterfaceInfo[]) {
1049
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
1054
static void erst_register_types(void)
1056
type_register_static(&erst_type_info);
1059
type_init(erst_register_types)