]>
Commit | Line | Data |
---|---|---|
acf7d768 BH |
1 | #define DEBUG |
2 | ||
acf7d768 BH |
3 | #include <linux/types.h> |
4 | #include <linux/kernel.h> | |
5 | #include <linux/smp.h> | |
150f7e3c | 6 | #include <linux/reboot.h> |
acf7d768 BH |
7 | |
8 | #include <asm/reg.h> | |
9 | #include <asm/io.h> | |
10 | #include <asm/prom.h> | |
11 | #include <asm/machdep.h> | |
150f7e3c | 12 | #include <asm/rtas.h> |
acf7d768 BH |
13 | |
14 | #include "ras.h" | |
15 | #include "cbe_regs.h" | |
16 | ||
17 | ||
18 | static void dump_fir(int cpu) | |
19 | { | |
20 | struct cbe_pmd_regs __iomem *pregs = cbe_get_cpu_pmd_regs(cpu); | |
21 | struct cbe_iic_regs __iomem *iregs = cbe_get_cpu_iic_regs(cpu); | |
22 | ||
23 | if (pregs == NULL) | |
24 | return; | |
25 | ||
26 | /* Todo: do some nicer parsing of bits and based on them go down | |
27 | * to other sub-units FIRs and not only IIC | |
28 | */ | |
29 | printk(KERN_ERR "Global Checkstop FIR : 0x%016lx\n", | |
30 | in_be64(&pregs->checkstop_fir)); | |
31 | printk(KERN_ERR "Global Recoverable FIR : 0x%016lx\n", | |
32 | in_be64(&pregs->checkstop_fir)); | |
33 | printk(KERN_ERR "Global MachineCheck FIR : 0x%016lx\n", | |
34 | in_be64(&pregs->spec_att_mchk_fir)); | |
35 | ||
36 | if (iregs == NULL) | |
37 | return; | |
38 | printk(KERN_ERR "IOC FIR : 0x%016lx\n", | |
39 | in_be64(&iregs->ioc_fir)); | |
40 | ||
41 | } | |
42 | ||
43 | void cbe_system_error_exception(struct pt_regs *regs) | |
44 | { | |
45 | int cpu = smp_processor_id(); | |
46 | ||
47 | printk(KERN_ERR "System Error Interrupt on CPU %d !\n", cpu); | |
48 | dump_fir(cpu); | |
49 | dump_stack(); | |
50 | } | |
51 | ||
52 | void cbe_maintenance_exception(struct pt_regs *regs) | |
53 | { | |
54 | int cpu = smp_processor_id(); | |
55 | ||
56 | /* | |
57 | * Nothing implemented for the maintenance interrupt at this point | |
58 | */ | |
59 | ||
60 | printk(KERN_ERR "Unhandled Maintenance interrupt on CPU %d !\n", cpu); | |
61 | dump_stack(); | |
62 | } | |
63 | ||
64 | void cbe_thermal_exception(struct pt_regs *regs) | |
65 | { | |
66 | int cpu = smp_processor_id(); | |
67 | ||
68 | /* | |
69 | * Nothing implemented for the thermal interrupt at this point | |
70 | */ | |
71 | ||
72 | printk(KERN_ERR "Unhandled Thermal interrupt on CPU %d !\n", cpu); | |
73 | dump_stack(); | |
74 | } | |
75 | ||
76 | static int cbe_machine_check_handler(struct pt_regs *regs) | |
77 | { | |
78 | int cpu = smp_processor_id(); | |
79 | ||
80 | printk(KERN_ERR "Machine Check Interrupt on CPU %d !\n", cpu); | |
81 | dump_fir(cpu); | |
82 | ||
83 | /* No recovery from this code now, lets continue */ | |
84 | return 0; | |
85 | } | |
86 | ||
150f7e3c JK |
87 | struct ptcal_area { |
88 | struct list_head list; | |
89 | int nid; | |
90 | int order; | |
91 | struct page *pages; | |
92 | }; | |
93 | ||
94 | static LIST_HEAD(ptcal_list); | |
95 | ||
96 | static int ptcal_start_tok, ptcal_stop_tok; | |
97 | ||
98 | static int __init cbe_ptcal_enable_on_node(int nid, int order) | |
99 | { | |
100 | struct ptcal_area *area; | |
101 | int ret = -ENOMEM; | |
102 | unsigned long addr; | |
103 | ||
104 | #ifdef CONFIG_CRASH_DUMP | |
105 | rtas_call(ptcal_stop_tok, 1, 1, NULL, nid); | |
106 | #endif | |
107 | ||
108 | area = kmalloc(sizeof(*area), GFP_KERNEL); | |
109 | if (!area) | |
110 | goto out_err; | |
111 | ||
112 | area->nid = nid; | |
113 | area->order = order; | |
114 | area->pages = alloc_pages_node(area->nid, GFP_KERNEL, area->order); | |
115 | ||
116 | if (!area->pages) | |
117 | goto out_free_area; | |
118 | ||
119 | addr = __pa(page_address(area->pages)); | |
120 | ||
121 | ret = -EIO; | |
122 | if (rtas_call(ptcal_start_tok, 3, 1, NULL, area->nid, | |
123 | (unsigned int)(addr >> 32), | |
124 | (unsigned int)(addr & 0xffffffff))) { | |
125 | printk(KERN_ERR "%s: error enabling PTCAL on node %d!\n", | |
126 | __FUNCTION__, nid); | |
127 | goto out_free_pages; | |
128 | } | |
129 | ||
130 | list_add(&area->list, &ptcal_list); | |
131 | ||
132 | return 0; | |
133 | ||
134 | out_free_pages: | |
135 | __free_pages(area->pages, area->order); | |
136 | out_free_area: | |
137 | kfree(area); | |
138 | out_err: | |
139 | return ret; | |
140 | } | |
141 | ||
142 | static int __init cbe_ptcal_enable(void) | |
143 | { | |
144 | const u32 *size; | |
145 | struct device_node *np; | |
146 | int order, found_mic = 0; | |
147 | ||
148 | np = of_find_node_by_path("/rtas"); | |
149 | if (!np) | |
150 | return -ENODEV; | |
151 | ||
12d371a6 | 152 | size = of_get_property(np, "ibm,cbe-ptcal-size", NULL); |
150f7e3c JK |
153 | if (!size) |
154 | return -ENODEV; | |
155 | ||
156 | pr_debug("%s: enabling PTCAL, size = 0x%x\n", __FUNCTION__, *size); | |
157 | order = get_order(*size); | |
158 | of_node_put(np); | |
159 | ||
160 | /* support for malta device trees, with be@/mic@ nodes */ | |
161 | for_each_node_by_type(np, "mic-tm") { | |
162 | cbe_ptcal_enable_on_node(of_node_to_nid(np), order); | |
163 | found_mic = 1; | |
164 | } | |
165 | ||
166 | if (found_mic) | |
167 | return 0; | |
168 | ||
169 | /* support for older device tree - use cpu nodes */ | |
170 | for_each_node_by_type(np, "cpu") { | |
12d371a6 | 171 | const u32 *nid = of_get_property(np, "node-id", NULL); |
150f7e3c JK |
172 | if (!nid) { |
173 | printk(KERN_ERR "%s: node %s is missing node-id?\n", | |
174 | __FUNCTION__, np->full_name); | |
175 | continue; | |
176 | } | |
177 | cbe_ptcal_enable_on_node(*nid, order); | |
178 | found_mic = 1; | |
179 | } | |
180 | ||
181 | return found_mic ? 0 : -ENODEV; | |
182 | } | |
183 | ||
184 | static int cbe_ptcal_disable(void) | |
185 | { | |
186 | struct ptcal_area *area, *tmp; | |
187 | int ret = 0; | |
188 | ||
189 | pr_debug("%s: disabling PTCAL\n", __FUNCTION__); | |
190 | ||
191 | list_for_each_entry_safe(area, tmp, &ptcal_list, list) { | |
192 | /* disable ptcal on this node */ | |
193 | if (rtas_call(ptcal_stop_tok, 1, 1, NULL, area->nid)) { | |
194 | printk(KERN_ERR "%s: error disabling PTCAL " | |
195 | "on node %d!\n", __FUNCTION__, | |
196 | area->nid); | |
197 | ret = -EIO; | |
198 | continue; | |
199 | } | |
200 | ||
201 | /* ensure we can access the PTCAL area */ | |
202 | memset(page_address(area->pages), 0, | |
203 | 1 << (area->order + PAGE_SHIFT)); | |
204 | ||
205 | /* clean up */ | |
206 | list_del(&area->list); | |
207 | __free_pages(area->pages, area->order); | |
208 | kfree(area); | |
209 | } | |
210 | ||
211 | return ret; | |
212 | } | |
213 | ||
214 | static int cbe_ptcal_notify_reboot(struct notifier_block *nb, | |
215 | unsigned long code, void *data) | |
216 | { | |
217 | return cbe_ptcal_disable(); | |
218 | } | |
219 | ||
220 | static struct notifier_block cbe_ptcal_reboot_notifier = { | |
221 | .notifier_call = cbe_ptcal_notify_reboot | |
222 | }; | |
223 | ||
224 | int __init cbe_ptcal_init(void) | |
225 | { | |
226 | int ret; | |
227 | ptcal_start_tok = rtas_token("ibm,cbe-start-ptcal"); | |
228 | ptcal_stop_tok = rtas_token("ibm,cbe-stop-ptcal"); | |
229 | ||
230 | if (ptcal_start_tok == RTAS_UNKNOWN_SERVICE | |
231 | || ptcal_stop_tok == RTAS_UNKNOWN_SERVICE) | |
232 | return -ENODEV; | |
233 | ||
234 | ret = register_reboot_notifier(&cbe_ptcal_reboot_notifier); | |
235 | if (ret) { | |
236 | printk(KERN_ERR "Can't disable PTCAL, so not enabling\n"); | |
237 | return ret; | |
238 | } | |
239 | ||
240 | return cbe_ptcal_enable(); | |
241 | } | |
242 | ||
243 | arch_initcall(cbe_ptcal_init); | |
244 | ||
acf7d768 BH |
245 | void __init cbe_ras_init(void) |
246 | { | |
247 | unsigned long hid0; | |
248 | ||
249 | /* | |
250 | * Enable System Error & thermal interrupts and wakeup conditions | |
251 | */ | |
252 | ||
253 | hid0 = mfspr(SPRN_HID0); | |
254 | hid0 |= HID0_CBE_THERM_INT_EN | HID0_CBE_THERM_WAKEUP | | |
255 | HID0_CBE_SYSERR_INT_EN | HID0_CBE_SYSERR_WAKEUP; | |
256 | mtspr(SPRN_HID0, hid0); | |
257 | mb(); | |
258 | ||
259 | /* | |
260 | * Install machine check handler. Leave setting of precise mode to | |
261 | * what the firmware did for now | |
262 | */ | |
263 | ppc_md.machine_check_exception = cbe_machine_check_handler; | |
264 | mb(); | |
265 | ||
266 | /* | |
267 | * For now, we assume that IOC_FIR is already set to forward some | |
268 | * error conditions to the System Error handler. If that is not true | |
269 | * then it will have to be fixed up here. | |
270 | */ | |
271 | } |