1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#ifndef _POWERPC_EEH_H
21#define _POWERPC_EEH_H
22#ifdef __KERNEL__
23
24#include <linux/init.h>
25#include <linux/list.h>
26#include <linux/string.h>
27
28struct pci_dev;
29struct pci_bus;
30struct device_node;
31
32#ifdef CONFIG_EEH
33
34extern int eeh_subsystem_enabled;
35
36
37#define EEH_MODE_SUPPORTED (1<<0)
38#define EEH_MODE_NOCHECK (1<<1)
39#define EEH_MODE_ISOLATED (1<<2)
40#define EEH_MODE_RECOVERING (1<<3)
41#define EEH_MODE_IRQ_DISABLED (1<<4)
42
43
44
45#define EEH_MAX_ALLOWED_FREEZES 5
46
47void __init eeh_init(void);
48unsigned long eeh_check_failure(const volatile void __iomem *token,
49 unsigned long val);
50int eeh_dn_check_failure(struct device_node *dn, struct pci_dev *dev);
51void __init pci_addr_cache_build(void);
52
53
54
55
56
57
58
59
60
61
62void eeh_add_device_tree_early(struct device_node *);
63void eeh_add_device_tree_late(struct pci_bus *);
64
65
66
67
68
69
70
71
72void eeh_remove_bus_device(struct pci_dev *);
73
74
75
76
77
78
79
80#define EEH_POSSIBLE_ERROR(val, type) ((val) == (type)~0 && eeh_subsystem_enabled)
81
82
83
84
85
86
87#define EEH_IO_ERROR_VALUE(size) (~0U >> ((4 - (size)) * 8))
88
89#else
90static inline void eeh_init(void) { }
91
92static inline unsigned long eeh_check_failure(const volatile void __iomem *token, unsigned long val)
93{
94 return val;
95}
96
97static inline int eeh_dn_check_failure(struct device_node *dn, struct pci_dev *dev)
98{
99 return 0;
100}
101
102static inline void pci_addr_cache_build(void) { }
103
104static inline void eeh_add_device_tree_early(struct device_node *dn) { }
105
106static inline void eeh_add_device_tree_late(struct pci_bus *bus) { }
107
108static inline void eeh_remove_bus_device(struct pci_dev *dev) { }
109#define EEH_POSSIBLE_ERROR(val, type) (0)
110#define EEH_IO_ERROR_VALUE(size) (-1UL)
111#endif
112
113#ifdef CONFIG_PPC64
114
115
116
117static inline u8 eeh_readb(const volatile void __iomem *addr)
118{
119 u8 val = in_8(addr);
120 if (EEH_POSSIBLE_ERROR(val, u8))
121 return eeh_check_failure(addr, val);
122 return val;
123}
124
125static inline u16 eeh_readw(const volatile void __iomem *addr)
126{
127 u16 val = in_le16(addr);
128 if (EEH_POSSIBLE_ERROR(val, u16))
129 return eeh_check_failure(addr, val);
130 return val;
131}
132
133static inline u32 eeh_readl(const volatile void __iomem *addr)
134{
135 u32 val = in_le32(addr);
136 if (EEH_POSSIBLE_ERROR(val, u32))
137 return eeh_check_failure(addr, val);
138 return val;
139}
140
141static inline u64 eeh_readq(const volatile void __iomem *addr)
142{
143 u64 val = in_le64(addr);
144 if (EEH_POSSIBLE_ERROR(val, u64))
145 return eeh_check_failure(addr, val);
146 return val;
147}
148
149static inline u16 eeh_readw_be(const volatile void __iomem *addr)
150{
151 u16 val = in_be16(addr);
152 if (EEH_POSSIBLE_ERROR(val, u16))
153 return eeh_check_failure(addr, val);
154 return val;
155}
156
157static inline u32 eeh_readl_be(const volatile void __iomem *addr)
158{
159 u32 val = in_be32(addr);
160 if (EEH_POSSIBLE_ERROR(val, u32))
161 return eeh_check_failure(addr, val);
162 return val;
163}
164
165static inline u64 eeh_readq_be(const volatile void __iomem *addr)
166{
167 u64 val = in_be64(addr);
168 if (EEH_POSSIBLE_ERROR(val, u64))
169 return eeh_check_failure(addr, val);
170 return val;
171}
172
173static inline void eeh_memcpy_fromio(void *dest, const
174 volatile void __iomem *src,
175 unsigned long n)
176{
177 _memcpy_fromio(dest, src, n);
178
179
180
181
182 if (n >= 4 && EEH_POSSIBLE_ERROR(*((u32 *)(dest + n - 4)), u32))
183 eeh_check_failure(src, *((u32 *)(dest + n - 4)));
184}
185
186
187static inline void eeh_readsb(const volatile void __iomem *addr, void * buf,
188 int ns)
189{
190 _insb(addr, buf, ns);
191 if (EEH_POSSIBLE_ERROR((*(((u8*)buf)+ns-1)), u8))
192 eeh_check_failure(addr, *(u8*)buf);
193}
194
195static inline void eeh_readsw(const volatile void __iomem *addr, void * buf,
196 int ns)
197{
198 _insw(addr, buf, ns);
199 if (EEH_POSSIBLE_ERROR((*(((u16*)buf)+ns-1)), u16))
200 eeh_check_failure(addr, *(u16*)buf);
201}
202
203static inline void eeh_readsl(const volatile void __iomem *addr, void * buf,
204 int nl)
205{
206 _insl(addr, buf, nl);
207 if (EEH_POSSIBLE_ERROR((*(((u32*)buf)+nl-1)), u32))
208 eeh_check_failure(addr, *(u32*)buf);
209}
210
211#endif
212#endif
213#endif
214