blob: cca240a33038fe148ca5e9324214ba988c62c6c2 [file] [log] [blame]
Huang Yinga643ce22010-05-18 14:35:12 +08001/*
2 * apei-internal.h - ACPI Platform Error Interface internal
3 * definations.
4 */
5
6#ifndef APEI_INTERNAL_H
7#define APEI_INTERNAL_H
8
Huang Ying06d65de2010-05-18 14:35:19 +08009#include <linux/cper.h>
10
Huang Yinga643ce22010-05-18 14:35:12 +080011struct apei_exec_context;
12
13typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
14 struct acpi_whea_header *entry);
15
16#define APEI_EXEC_INS_ACCESS_REGISTER 0x0001
17
18struct apei_exec_ins_type {
19 u32 flags;
20 apei_exec_ins_func_t run;
21};
22
23struct apei_exec_context {
24 u32 ip;
25 u64 value;
26 u64 var1;
27 u64 var2;
28 u64 src_base;
29 u64 dst_base;
30 struct apei_exec_ins_type *ins_table;
31 u32 instructions;
32 struct acpi_whea_header *action_table;
33 u32 entries;
34};
35
36void apei_exec_ctx_init(struct apei_exec_context *ctx,
37 struct apei_exec_ins_type *ins_table,
38 u32 instructions,
39 struct acpi_whea_header *action_table,
40 u32 entries);
41
42static inline void apei_exec_ctx_set_input(struct apei_exec_context *ctx,
43 u64 input)
44{
45 ctx->value = input;
46}
47
48static inline u64 apei_exec_ctx_get_output(struct apei_exec_context *ctx)
49{
50 return ctx->value;
51}
52
Huang Yingeecf2f72011-07-13 13:14:16 +080053int __apei_exec_run(struct apei_exec_context *ctx, u8 action, bool optional);
54
55static inline int apei_exec_run(struct apei_exec_context *ctx, u8 action)
56{
57 return __apei_exec_run(ctx, action, 0);
58}
59
60/* It is optional whether the firmware provides the action */
61static inline int apei_exec_run_optional(struct apei_exec_context *ctx, u8 action)
62{
63 return __apei_exec_run(ctx, action, 1);
64}
Huang Yinga643ce22010-05-18 14:35:12 +080065
66/* Common instruction implementation */
67
68/* IP has been set in instruction function */
69#define APEI_EXEC_SET_IP 1
70
Myron Stowe700130b2011-11-07 16:23:41 -070071int apei_read(u64 *val, struct acpi_generic_address *reg);
72int apei_write(u64 val, struct acpi_generic_address *reg);
73
Huang Yinga643ce22010-05-18 14:35:12 +080074int __apei_exec_read_register(struct acpi_whea_header *entry, u64 *val);
75int __apei_exec_write_register(struct acpi_whea_header *entry, u64 val);
76int apei_exec_read_register(struct apei_exec_context *ctx,
77 struct acpi_whea_header *entry);
78int apei_exec_read_register_value(struct apei_exec_context *ctx,
79 struct acpi_whea_header *entry);
80int apei_exec_write_register(struct apei_exec_context *ctx,
81 struct acpi_whea_header *entry);
82int apei_exec_write_register_value(struct apei_exec_context *ctx,
83 struct acpi_whea_header *entry);
84int apei_exec_noop(struct apei_exec_context *ctx,
85 struct acpi_whea_header *entry);
86int apei_exec_pre_map_gars(struct apei_exec_context *ctx);
87int apei_exec_post_unmap_gars(struct apei_exec_context *ctx);
88
89struct apei_resources {
90 struct list_head iomem;
91 struct list_head ioport;
92};
93
94static inline void apei_resources_init(struct apei_resources *resources)
95{
96 INIT_LIST_HEAD(&resources->iomem);
97 INIT_LIST_HEAD(&resources->ioport);
98}
99
100void apei_resources_fini(struct apei_resources *resources);
Huang Yingfdea1632011-12-08 11:25:47 +0800101int apei_resources_add(struct apei_resources *resources,
102 unsigned long start, unsigned long size,
103 bool iomem);
Huang Yinga643ce22010-05-18 14:35:12 +0800104int apei_resources_sub(struct apei_resources *resources1,
105 struct apei_resources *resources2);
106int apei_resources_request(struct apei_resources *resources,
107 const char *desc);
108void apei_resources_release(struct apei_resources *resources);
109int apei_exec_collect_resources(struct apei_exec_context *ctx,
110 struct apei_resources *resources);
111
112struct dentry;
113struct dentry *apei_get_debugfs_dir(void);
Huang Ying06d65de2010-05-18 14:35:19 +0800114
115#define apei_estatus_for_each_section(estatus, section) \
116 for (section = (struct acpi_hest_generic_data *)(estatus + 1); \
117 (void *)section - (void *)estatus < estatus->data_length; \
118 section = (void *)(section+1) + section->error_data_length)
119
120static inline u32 apei_estatus_len(struct acpi_hest_generic_status *estatus)
121{
122 if (estatus->raw_data_length)
123 return estatus->raw_data_offset + \
124 estatus->raw_data_length;
125 else
126 return sizeof(*estatus) + estatus->data_length;
127}
128
Huang Yingf59c55d2010-12-07 10:22:30 +0800129void apei_estatus_print(const char *pfx,
130 const struct acpi_hest_generic_status *estatus);
Huang Ying06d65de2010-05-18 14:35:19 +0800131int apei_estatus_check_header(const struct acpi_hest_generic_status *estatus);
132int apei_estatus_check(const struct acpi_hest_generic_status *estatus);
Huang Ying9fb0bfe2011-07-13 13:14:21 +0800133
134int apei_osc_setup(void);
Huang Yinga643ce22010-05-18 14:35:12 +0800135#endif