18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * apei-internal.h - ACPI Platform Error Interface internal 48c2ecf20Sopenharmony_ci * definitions. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef APEI_INTERNAL_H 88c2ecf20Sopenharmony_ci#define APEI_INTERNAL_H 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/cper.h> 118c2ecf20Sopenharmony_ci#include <linux/acpi.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistruct apei_exec_context; 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_citypedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx, 168c2ecf20Sopenharmony_ci struct acpi_whea_header *entry); 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define APEI_EXEC_INS_ACCESS_REGISTER 0x0001 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistruct apei_exec_ins_type { 218c2ecf20Sopenharmony_ci u32 flags; 228c2ecf20Sopenharmony_ci apei_exec_ins_func_t run; 238c2ecf20Sopenharmony_ci}; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cistruct apei_exec_context { 268c2ecf20Sopenharmony_ci u32 ip; 278c2ecf20Sopenharmony_ci u64 value; 288c2ecf20Sopenharmony_ci u64 var1; 298c2ecf20Sopenharmony_ci u64 var2; 308c2ecf20Sopenharmony_ci u64 src_base; 318c2ecf20Sopenharmony_ci u64 dst_base; 328c2ecf20Sopenharmony_ci struct apei_exec_ins_type *ins_table; 338c2ecf20Sopenharmony_ci u32 instructions; 348c2ecf20Sopenharmony_ci struct acpi_whea_header *action_table; 358c2ecf20Sopenharmony_ci u32 entries; 368c2ecf20Sopenharmony_ci}; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_civoid apei_exec_ctx_init(struct apei_exec_context *ctx, 398c2ecf20Sopenharmony_ci struct apei_exec_ins_type *ins_table, 408c2ecf20Sopenharmony_ci u32 instructions, 418c2ecf20Sopenharmony_ci struct acpi_whea_header *action_table, 428c2ecf20Sopenharmony_ci u32 entries); 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic inline void apei_exec_ctx_set_input(struct apei_exec_context *ctx, 458c2ecf20Sopenharmony_ci u64 input) 468c2ecf20Sopenharmony_ci{ 478c2ecf20Sopenharmony_ci ctx->value = input; 488c2ecf20Sopenharmony_ci} 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistatic inline u64 apei_exec_ctx_get_output(struct apei_exec_context *ctx) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci return ctx->value; 538c2ecf20Sopenharmony_ci} 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ciint __apei_exec_run(struct apei_exec_context *ctx, u8 action, bool optional); 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cistatic inline int apei_exec_run(struct apei_exec_context *ctx, u8 action) 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci return __apei_exec_run(ctx, action, 0); 608c2ecf20Sopenharmony_ci} 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/* It is optional whether the firmware provides the action */ 638c2ecf20Sopenharmony_cistatic inline int apei_exec_run_optional(struct apei_exec_context *ctx, u8 action) 648c2ecf20Sopenharmony_ci{ 658c2ecf20Sopenharmony_ci return __apei_exec_run(ctx, action, 1); 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci/* Common instruction implementation */ 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* IP has been set in instruction function */ 718c2ecf20Sopenharmony_ci#define APEI_EXEC_SET_IP 1 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ciint apei_map_generic_address(struct acpi_generic_address *reg); 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistatic inline void apei_unmap_generic_address(struct acpi_generic_address *reg) 768c2ecf20Sopenharmony_ci{ 778c2ecf20Sopenharmony_ci acpi_os_unmap_generic_address(reg); 788c2ecf20Sopenharmony_ci} 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ciint apei_read(u64 *val, struct acpi_generic_address *reg); 818c2ecf20Sopenharmony_ciint apei_write(u64 val, struct acpi_generic_address *reg); 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ciint __apei_exec_read_register(struct acpi_whea_header *entry, u64 *val); 848c2ecf20Sopenharmony_ciint __apei_exec_write_register(struct acpi_whea_header *entry, u64 val); 858c2ecf20Sopenharmony_ciint apei_exec_read_register(struct apei_exec_context *ctx, 868c2ecf20Sopenharmony_ci struct acpi_whea_header *entry); 878c2ecf20Sopenharmony_ciint apei_exec_read_register_value(struct apei_exec_context *ctx, 888c2ecf20Sopenharmony_ci struct acpi_whea_header *entry); 898c2ecf20Sopenharmony_ciint apei_exec_write_register(struct apei_exec_context *ctx, 908c2ecf20Sopenharmony_ci struct acpi_whea_header *entry); 918c2ecf20Sopenharmony_ciint apei_exec_write_register_value(struct apei_exec_context *ctx, 928c2ecf20Sopenharmony_ci struct acpi_whea_header *entry); 938c2ecf20Sopenharmony_ciint apei_exec_noop(struct apei_exec_context *ctx, 948c2ecf20Sopenharmony_ci struct acpi_whea_header *entry); 958c2ecf20Sopenharmony_ciint apei_exec_pre_map_gars(struct apei_exec_context *ctx); 968c2ecf20Sopenharmony_ciint apei_exec_post_unmap_gars(struct apei_exec_context *ctx); 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistruct apei_resources { 998c2ecf20Sopenharmony_ci struct list_head iomem; 1008c2ecf20Sopenharmony_ci struct list_head ioport; 1018c2ecf20Sopenharmony_ci}; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_cistatic inline void apei_resources_init(struct apei_resources *resources) 1048c2ecf20Sopenharmony_ci{ 1058c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&resources->iomem); 1068c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&resources->ioport); 1078c2ecf20Sopenharmony_ci} 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_civoid apei_resources_fini(struct apei_resources *resources); 1108c2ecf20Sopenharmony_ciint apei_resources_add(struct apei_resources *resources, 1118c2ecf20Sopenharmony_ci unsigned long start, unsigned long size, 1128c2ecf20Sopenharmony_ci bool iomem); 1138c2ecf20Sopenharmony_ciint apei_resources_sub(struct apei_resources *resources1, 1148c2ecf20Sopenharmony_ci struct apei_resources *resources2); 1158c2ecf20Sopenharmony_ciint apei_resources_request(struct apei_resources *resources, 1168c2ecf20Sopenharmony_ci const char *desc); 1178c2ecf20Sopenharmony_civoid apei_resources_release(struct apei_resources *resources); 1188c2ecf20Sopenharmony_ciint apei_exec_collect_resources(struct apei_exec_context *ctx, 1198c2ecf20Sopenharmony_ci struct apei_resources *resources); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_cistruct dentry; 1228c2ecf20Sopenharmony_cistruct dentry *apei_get_debugfs_dir(void); 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cistatic inline u32 cper_estatus_len(struct acpi_hest_generic_status *estatus) 1258c2ecf20Sopenharmony_ci{ 1268c2ecf20Sopenharmony_ci if (estatus->raw_data_length) 1278c2ecf20Sopenharmony_ci return estatus->raw_data_offset + \ 1288c2ecf20Sopenharmony_ci estatus->raw_data_length; 1298c2ecf20Sopenharmony_ci else 1308c2ecf20Sopenharmony_ci return sizeof(*estatus) + estatus->data_length; 1318c2ecf20Sopenharmony_ci} 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_civoid cper_estatus_print(const char *pfx, 1348c2ecf20Sopenharmony_ci const struct acpi_hest_generic_status *estatus); 1358c2ecf20Sopenharmony_ciint cper_estatus_check_header(const struct acpi_hest_generic_status *estatus); 1368c2ecf20Sopenharmony_ciint cper_estatus_check(const struct acpi_hest_generic_status *estatus); 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ciint apei_osc_setup(void); 1398c2ecf20Sopenharmony_ci#endif 140