blob: cb4126051f6220ba18bbd793e7b1684bc3fc448a [file] [log] [blame]
Huang Yinga643ce22010-05-18 14:35:12 +08001/*
2 * apei-internal.h - ACPI Platform Error Interface internal
Huang Yinga3e2acc2016-06-29 13:04:29 -07003 * definitions.
Huang Yinga643ce22010-05-18 14:35:12 +08004 */
5
6#ifndef APEI_INTERNAL_H
7#define APEI_INTERNAL_H
8
Huang Ying06d65de2010-05-18 14:35:19 +08009#include <linux/cper.h>
Huang Ying34ddeb02012-06-12 11:20:19 +080010#include <linux/acpi.h>
Huang Ying06d65de2010-05-18 14:35:19 +080011
Huang Yinga643ce22010-05-18 14:35:12 +080012struct apei_exec_context;
13
14typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
15 struct acpi_whea_header *entry);
16
17#define APEI_EXEC_INS_ACCESS_REGISTER 0x0001
18
19struct apei_exec_ins_type {
20 u32 flags;
21 apei_exec_ins_func_t run;
22};
23
24struct apei_exec_context {
25 u32 ip;
26 u64 value;
27 u64 var1;
28 u64 var2;
29 u64 src_base;
30 u64 dst_base;
31 struct apei_exec_ins_type *ins_table;
32 u32 instructions;
33 struct acpi_whea_header *action_table;
34 u32 entries;
35};
36
37void apei_exec_ctx_init(struct apei_exec_context *ctx,
38 struct apei_exec_ins_type *ins_table,
39 u32 instructions,
40 struct acpi_whea_header *action_table,
41 u32 entries);
42
43static inline void apei_exec_ctx_set_input(struct apei_exec_context *ctx,
44 u64 input)
45{
46 ctx->value = input;
47}
48
49static inline u64 apei_exec_ctx_get_output(struct apei_exec_context *ctx)
50{
51 return ctx->value;
52}
53
Huang Yingeecf2f72011-07-13 13:14:16 +080054int __apei_exec_run(struct apei_exec_context *ctx, u8 action, bool optional);
55
56static inline int apei_exec_run(struct apei_exec_context *ctx, u8 action)
57{
58 return __apei_exec_run(ctx, action, 0);
59}
60
61/* It is optional whether the firmware provides the action */
62static inline int apei_exec_run_optional(struct apei_exec_context *ctx, u8 action)
63{
64 return __apei_exec_run(ctx, action, 1);
65}
Huang Yinga643ce22010-05-18 14:35:12 +080066
67/* Common instruction implementation */
68
69/* IP has been set in instruction function */
70#define APEI_EXEC_SET_IP 1
71
Huang Ying34ddeb02012-06-12 11:20:19 +080072int apei_map_generic_address(struct acpi_generic_address *reg);
73
74static inline void apei_unmap_generic_address(struct acpi_generic_address *reg)
75{
76 acpi_os_unmap_generic_address(reg);
77}
78
Myron Stowe700130b2011-11-07 16:23:41 -070079int apei_read(u64 *val, struct acpi_generic_address *reg);
80int apei_write(u64 val, struct acpi_generic_address *reg);
81
Huang Yinga643ce22010-05-18 14:35:12 +080082int __apei_exec_read_register(struct acpi_whea_header *entry, u64 *val);
83int __apei_exec_write_register(struct acpi_whea_header *entry, u64 val);
84int apei_exec_read_register(struct apei_exec_context *ctx,
85 struct acpi_whea_header *entry);
86int apei_exec_read_register_value(struct apei_exec_context *ctx,
87 struct acpi_whea_header *entry);
88int apei_exec_write_register(struct apei_exec_context *ctx,
89 struct acpi_whea_header *entry);
90int apei_exec_write_register_value(struct apei_exec_context *ctx,
91 struct acpi_whea_header *entry);
92int apei_exec_noop(struct apei_exec_context *ctx,
93 struct acpi_whea_header *entry);
94int apei_exec_pre_map_gars(struct apei_exec_context *ctx);
95int apei_exec_post_unmap_gars(struct apei_exec_context *ctx);
96
97struct apei_resources {
98 struct list_head iomem;
99 struct list_head ioport;
100};
101
102static inline void apei_resources_init(struct apei_resources *resources)
103{
104 INIT_LIST_HEAD(&resources->iomem);
105 INIT_LIST_HEAD(&resources->ioport);
106}
107
108void apei_resources_fini(struct apei_resources *resources);
Huang Yingfdea1632011-12-08 11:25:47 +0800109int apei_resources_add(struct apei_resources *resources,
110 unsigned long start, unsigned long size,
111 bool iomem);
Huang Yinga643ce22010-05-18 14:35:12 +0800112int apei_resources_sub(struct apei_resources *resources1,
113 struct apei_resources *resources2);
114int apei_resources_request(struct apei_resources *resources,
115 const char *desc);
116void apei_resources_release(struct apei_resources *resources);
117int apei_exec_collect_resources(struct apei_exec_context *ctx,
118 struct apei_resources *resources);
119
120struct dentry;
121struct dentry *apei_get_debugfs_dir(void);
Huang Ying06d65de2010-05-18 14:35:19 +0800122
Lv Zheng0a00fd52014-06-03 16:32:53 +0800123static inline u32 cper_estatus_len(struct acpi_hest_generic_status *estatus)
Huang Ying06d65de2010-05-18 14:35:19 +0800124{
125 if (estatus->raw_data_length)
126 return estatus->raw_data_offset + \
127 estatus->raw_data_length;
128 else
129 return sizeof(*estatus) + estatus->data_length;
130}
131
Chen, Gong88f074f2013-10-18 14:28:59 -0700132void cper_estatus_print(const char *pfx,
Lv Zheng0a00fd52014-06-03 16:32:53 +0800133 const struct acpi_hest_generic_status *estatus);
134int cper_estatus_check_header(const struct acpi_hest_generic_status *estatus);
135int cper_estatus_check(const struct acpi_hest_generic_status *estatus);
Huang Ying9fb0bfe2011-07-13 13:14:21 +0800136
137int apei_osc_setup(void);
Huang Yinga643ce22010-05-18 14:35:12 +0800138#endif