1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
|
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
*/
#include <linux/kernel.h>
#include <linux/edac.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/smp.h>
#include <linux/cpu.h>
#include <linux/cpu_pm.h>
#include <linux/interrupt.h>
#include <linux/notifier.h>
#include <linux/of_irq.h>
#include <asm/cputype.h>
#include "edac_mc.h"
#include "edac_device.h"
#include <linux/sec_debug.h>
#ifdef CONFIG_EDAC_KRYO_ARM64_PANIC_ON_UE
#define ARM64_ERP_PANIC_ON_UE 1
#else
#define ARM64_ERP_PANIC_ON_UE 0
#endif
#define ARM64_ERP_PANIC_ON_CE 1
#define L1_SILVER_BIT 0x0
#define L2_SILVER_BIT 0x1
#define L3_BIT 0x2
#define QCOM_CPU_PART_KRYO4XX_GOLD 0x804
#define QCOM_CPU_PART_KRYO5XX_GOLD 0xD0D
#define QCOM_CPU_PART_KRYO4XX_SILVER_V1 0x803
#define QCOM_CPU_PART_KRYO4XX_SILVER_V2 0x805
#define QCOM_CPU_PART_KRYO6XX_SILVER_V1 0xD05
#define QCOM_CPU_PART_KRYO6XX_GOLD 0xD41
#define QCOM_CPU_PART_KRYO6XX_GOLDPLUS 0xD44
#define L1_GOLD_IC_BIT 0x1
#define L1_GOLD_DC_BIT 0x4
#define L2_GOLD_BIT 0x8
#define L2_GOLD_TLB_BIT 0x2
#define L1 0x0
#define L2 0x1
#define L3 0x2
#define EDAC_CPU "kryo_edac"
#define KRYO_ERRXSTATUS_VALID(a) ((a >> 30) & 0x1)
#define KRYO_ERRXSTATUS_UE(a) ((a >> 29) & 0x1)
#define KRYO_ERRXSTATUS_SERR(a) (a & 0xFF)
#define KRYO_ERRXMISC_LVL(a) ((a >> 1) & 0x7)
#define KRYO_ERRXMISC_LVL_GOLD(a) (a & 0xF)
#define KRYO_ERRXMISC_WAY(a) ((a >> 28) & 0xF)
static inline void set_errxctlr_el1(void)
{
u64 val = 0x10f;
asm volatile("msr s3_0_c5_c4_1, %0" : : "r" (val));
}
static inline void set_errxmisc_overflow(void)
{
u64 val = 0x7F7F00000000ULL;
asm volatile("msr s3_0_c5_c5_0, %0" : : "r" (val));
}
static inline void write_errselr_el1(u64 val)
{
asm volatile("msr s3_0_c5_c3_1, %0" : : "r" (val));
}
static inline u64 read_errxstatus_el1(void)
{
u64 val;
asm volatile("mrs %0, s3_0_c5_c4_2" : "=r" (val));
return val;
}
static inline u64 read_errxmisc_el1(void)
{
u64 val;
asm volatile("mrs %0, s3_0_c5_c5_0" : "=r" (val));
return val;
}
static inline void clear_errxstatus_valid(u64 val)
{
asm volatile("msr s3_0_c5_c4_2, %0" : : "r" (val));
}
struct errors_edac {
const char * const msg;
void (*func)(struct edac_device_ctl_info *edac_dev,
int inst_nr, int block_nr, const char *msg);
};
static const struct errors_edac errors[] = {
{"Kryo L1 Correctable Error", edac_device_handle_ce },
{"Kryo L1 Uncorrectable Error", edac_device_handle_ue },
{"Kryo L2 Correctable Error", edac_device_handle_ce },
{"Kryo L2 Uncorrectable Error", edac_device_handle_ue },
{"L3 Correctable Error", edac_device_handle_ce },
{"L3 Uncorrectable Error", edac_device_handle_ue },
};
#define KRYO_L1_CE 0
#define KRYO_L1_UE 1
#define KRYO_L2_CE 2
#define KRYO_L2_UE 3
#define KRYO_L3_CE 4
#define KRYO_L3_UE 5
#define DATA_BUF_ERR 0x2
#define CACHE_DATA_ERR 0x6
#define CACHE_TAG_DIRTY_ERR 0x7
#define TLB_PARITY_ERR_DATA 0x8
#define TLB_PARITY_ERR_TAG 0x9
#define BUS_ERROR 0x12
struct erp_drvdata {
struct edac_device_ctl_info *edev_ctl;
struct erp_drvdata __percpu *erp_cpu_drvdata;
struct notifier_block nb_pm;
struct notifier_block nb_panic;
int ppi;
};
static struct erp_drvdata *panic_handler_drvdata;
static DEFINE_SPINLOCK(local_handler_lock);
#if IS_ENABLED(CONFIG_SEC_USER_RESET_DEBUG)
static ap_health_t *p_health;
static ap_health_t tmp_health;
enum {
ID_L1_CACHE = 0,
ID_L2_CACHE,
ID_L3_CACHE,
ID_BUS_ERR,
};
static int update_arm64_edac_count(int cpu, int block, int etype)
{
if (cpu < 0 || cpu >= num_present_cpus()) {
edac_printk(KERN_CRIT, EDAC_CPU, "%s : not available cpu = %d\n", __func__, cpu);
return -1;
}
if (p_health) {
switch (block) {
case ID_L1_CACHE:
if (etype == KRYO_L1_CE) {
p_health->cache.edac[cpu][block].ce_cnt++;
p_health->daily_cache.edac[cpu][block].ce_cnt++;
} else if (etype == KRYO_L1_UE) {
p_health->cache.edac[cpu][block].ue_cnt++;
p_health->daily_cache.edac[cpu][block].ue_cnt++;
}
break;
case ID_L2_CACHE:
if (etype == KRYO_L2_CE) {
p_health->cache.edac[cpu][block].ce_cnt++;
p_health->daily_cache.edac[cpu][block].ce_cnt++;
} else if (etype == KRYO_L2_UE) {
p_health->cache.edac[cpu][block].ue_cnt++;
p_health->daily_cache.edac[cpu][block].ue_cnt++;
}
break;
case ID_L3_CACHE:
if (etype == KRYO_L3_CE) {
p_health->cache.edac_l3.ce_cnt++;
p_health->daily_cache.edac_l3.ce_cnt++;
} else if (etype == KRYO_L3_UE) {
p_health->cache.edac_l3.ue_cnt++;
p_health->daily_cache.edac_l3.ue_cnt++;
}
break;
case ID_BUS_ERR:
p_health->cache.edac_bus_cnt++;
p_health->daily_cache.edac_bus_cnt++;
break;
}
ap_health_data_write(p_health);
} else {
tmp_health.header.magic = AP_HEALTH_MAGIC;
switch (block) {
case ID_L1_CACHE:
if (etype == KRYO_L1_CE) {
tmp_health.cache.edac[cpu][block].ce_cnt++;
tmp_health.daily_cache.edac[cpu][block].ce_cnt++;
} else if (etype == KRYO_L1_UE) {
tmp_health.cache.edac[cpu][block].ue_cnt++;
tmp_health.daily_cache.edac[cpu][block].ue_cnt++;
}
break;
case ID_L2_CACHE:
if (etype == KRYO_L2_CE) {
tmp_health.cache.edac[cpu][block].ce_cnt++;
tmp_health.daily_cache.edac[cpu][block].ce_cnt++;
} else if (etype == KRYO_L2_UE) {
tmp_health.cache.edac[cpu][block].ue_cnt++;
tmp_health.daily_cache.edac[cpu][block].ue_cnt++;
}
break;
case ID_L3_CACHE:
if (etype == KRYO_L3_CE) {
tmp_health.cache.edac_l3.ce_cnt++;
tmp_health.daily_cache.edac_l3.ce_cnt++;
} else if (etype == KRYO_L3_UE) {
tmp_health.cache.edac_l3.ue_cnt++;
tmp_health.daily_cache.edac_l3.ue_cnt++;
}
break;
case ID_BUS_ERR:
tmp_health.cache.edac_bus_cnt++;
tmp_health.daily_cache.edac_bus_cnt++;
break;
}
}
return 0;
}
#endif
static void l1_l2_irq_enable(void *info)
{
int irq = *(int *)info;
enable_percpu_irq(irq, IRQ_TYPE_LEVEL_HIGH);
}
static void l1_l2_irq_disable(void *info)
{
int irq = *(int *)info;
disable_percpu_irq(irq);
}
static int request_erp_irq(struct platform_device *pdev, const char *propname,
const char *desc, irq_handler_t handler,
void *ed, int percpu)
{
int rc;
struct resource *r;
struct erp_drvdata *drv = ed;
struct erp_drvdata *temp = NULL;
r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, propname);
if (!r) {
pr_err("ARM64 CPU ERP: Could not find <%s> IRQ property. Proceeding anyway.\n",
propname);
goto out;
}
if (!percpu) {
rc = devm_request_threaded_irq(&pdev->dev, r->start, NULL,
handler,
IRQF_ONESHOT | IRQF_TRIGGER_HIGH,
desc,
ed);
if (rc) {
pr_err("ARM64 CPU ERP: Failed to request IRQ %d: %d (%s / %s). Proceeding anyway.\n",
(int) r->start, rc, propname, desc);
goto out;
}
} else {
drv->erp_cpu_drvdata = alloc_percpu(struct erp_drvdata);
if (!drv->erp_cpu_drvdata) {
pr_err("Failed to allocate percpu erp data\n");
goto out;
}
temp = raw_cpu_ptr(drv->erp_cpu_drvdata);
temp->erp_cpu_drvdata = drv;
rc = request_percpu_irq(r->start, handler, desc,
drv->erp_cpu_drvdata);
if (rc) {
pr_err("ARM64 CPU ERP: Failed to request IRQ %d: %d (%s / %s). Proceeding anyway.\n",
(int) r->start, rc, propname, desc);
goto out_free;
}
drv->ppi = r->start;
on_each_cpu(l1_l2_irq_enable, &(r->start), 1);
}
return 0;
out_free:
free_percpu(drv->erp_cpu_drvdata);
drv->erp_cpu_drvdata = NULL;
out:
return -EINVAL;
}
static void dump_err_reg(int errorcode, int level, u64 errxstatus, u64 errxmisc,
struct edac_device_ctl_info *edev_ctl)
{
u32 part_num;
int way;
edac_printk(KERN_CRIT, EDAC_CPU, "ERRXSTATUS_EL1: %llx\n", errxstatus);
edac_printk(KERN_CRIT, EDAC_CPU, "ERRXMISC_EL1: %llx\n", errxmisc);
edac_printk(KERN_CRIT, EDAC_CPU, "Cache level: L%d\n", level + 1);
switch (KRYO_ERRXSTATUS_SERR(errxstatus)) {
case DATA_BUF_ERR:
edac_printk(KERN_CRIT, EDAC_CPU, "ECC Error from internal data buffer\n");
break;
case CACHE_DATA_ERR:
edac_printk(KERN_CRIT, EDAC_CPU, "ECC Error from cache data RAM\n");
break;
case CACHE_TAG_DIRTY_ERR:
edac_printk(KERN_CRIT, EDAC_CPU, "ECC Error from cache tag or dirty RAM\n");
break;
case TLB_PARITY_ERR_DATA:
edac_printk(KERN_CRIT, EDAC_CPU, "Parity error on TLB DATA RAM\n");
break;
case TLB_PARITY_ERR_TAG:
edac_printk(KERN_CRIT, EDAC_CPU, "Parity error on TLB TAG RAM\n");
break;
case BUS_ERROR:
edac_printk(KERN_CRIT, EDAC_CPU, "Bus Error\n");
break;
}
if (level == L3) {
way = (int) KRYO_ERRXMISC_WAY(errxmisc);
} else {
part_num = read_cpuid_part_number();
switch (part_num) {
case QCOM_CPU_PART_KRYO4XX_SILVER_V1:
case QCOM_CPU_PART_KRYO4XX_SILVER_V2:
case QCOM_CPU_PART_KRYO6XX_SILVER_V1:
way = (int) KRYO_ERRXMISC_WAY(errxmisc) >> 2;
break;
case QCOM_CPU_PART_KRYO4XX_GOLD:
case QCOM_CPU_PART_KRYO5XX_GOLD:
case QCOM_CPU_PART_KRYO6XX_GOLD:
case QCOM_CPU_PART_KRYO6XX_GOLDPLUS:
way = (int) KRYO_ERRXMISC_WAY(errxmisc);
break;
default:
edac_printk(KERN_CRIT, EDAC_CPU,
"Error in matching part num:%u\n", part_num);
return;
}
}
#if IS_ENABLED(CONFIG_SEC_USER_RESET_DEBUG)
if (level == L3)
update_arm64_edac_count(0, level, errorcode);
else
update_arm64_edac_count(smp_processor_id(), level, errorcode);
#endif
edac_printk(KERN_CRIT, EDAC_CPU, "Way: %d\n", way);
errors[errorcode].func(edev_ctl, smp_processor_id(),
level, errors[errorcode].msg);
}
static void kryo_parse_l1_l2_cache_error(u64 errxstatus, u64 errxmisc,
struct edac_device_ctl_info *edev_ctl, int cpu)
{
int level = 0;
u32 part_num;
part_num = read_cpuid_part_number();
switch (part_num) {
case QCOM_CPU_PART_KRYO4XX_SILVER_V1:
case QCOM_CPU_PART_KRYO4XX_SILVER_V2:
case QCOM_CPU_PART_KRYO6XX_SILVER_V1:
switch (KRYO_ERRXMISC_LVL(errxmisc)) {
case L1_SILVER_BIT:
level = L1;
break;
case L2_SILVER_BIT:
level = L2;
break;
default:
edac_printk(KERN_CRIT, EDAC_CPU,
"silver cpu:%d unknown error location:%llu\n",
cpu, KRYO_ERRXMISC_LVL(errxmisc));
}
break;
case QCOM_CPU_PART_KRYO4XX_GOLD:
case QCOM_CPU_PART_KRYO5XX_GOLD:
case QCOM_CPU_PART_KRYO6XX_GOLD:
case QCOM_CPU_PART_KRYO6XX_GOLDPLUS:
switch (KRYO_ERRXMISC_LVL_GOLD(errxmisc)) {
case L1_GOLD_DC_BIT:
case L1_GOLD_IC_BIT:
level = L1;
break;
case L2_GOLD_BIT:
case L2_GOLD_TLB_BIT:
level = L2;
break;
default:
edac_printk(KERN_CRIT, EDAC_CPU,
"gold cpu:%d unknown error location:%llu\n",
cpu, KRYO_ERRXMISC_LVL_GOLD(errxmisc));
}
break;
default:
edac_printk(KERN_CRIT, EDAC_CPU,
"Error in matching cpu%d with part num:%u\n",
cpu, part_num);
return;
}
switch (level) {
case L1:
if (KRYO_ERRXSTATUS_UE(errxstatus))
dump_err_reg(KRYO_L1_UE, level, errxstatus, errxmisc,
edev_ctl);
else
dump_err_reg(KRYO_L1_CE, level, errxstatus, errxmisc,
edev_ctl);
break;
case L2:
if (KRYO_ERRXSTATUS_UE(errxstatus))
dump_err_reg(KRYO_L2_UE, level, errxstatus, errxmisc,
edev_ctl);
else
dump_err_reg(KRYO_L2_CE, level, errxstatus, errxmisc,
edev_ctl);
break;
default:
edac_printk(KERN_CRIT, EDAC_CPU, "Unknown KRYO_ERRXMISC_LVL value\n");
}
}
static void kryo_check_l1_l2_ecc(void *info)
{
struct edac_device_ctl_info *edev_ctl = info;
u64 errxstatus = 0;
u64 errxmisc = 0;
int cpu = 0;
unsigned long flags;
spin_lock_irqsave(&local_handler_lock, flags);
write_errselr_el1(0);
errxstatus = read_errxstatus_el1();
cpu = smp_processor_id();
if (KRYO_ERRXSTATUS_VALID(errxstatus)) {
errxmisc = read_errxmisc_el1();
edac_printk(KERN_CRIT, EDAC_CPU,
"Kryo CPU%d detected a L1/L2 cache error, errxstatus = %llx, errxmisc = %llx\n",
cpu, errxstatus, errxmisc);
kryo_parse_l1_l2_cache_error(errxstatus, errxmisc, edev_ctl,
cpu);
clear_errxstatus_valid(errxstatus);
}
spin_unlock_irqrestore(&local_handler_lock, flags);
}
static bool l3_is_bus_error(u64 errxstatus)
{
if (KRYO_ERRXSTATUS_SERR(errxstatus) == BUS_ERROR) {
edac_printk(KERN_CRIT, EDAC_CPU, "Bus Error\n");
#if IS_ENABLED(CONFIG_SEC_USER_RESET_DEBUG)
update_arm64_edac_count(0, ID_BUS_ERR, BUS_ERROR);
#endif
return true;
}
return false;
}
static void kryo_check_l3_scu_error(struct edac_device_ctl_info *edev_ctl)
{
u64 errxstatus = 0;
u64 errxmisc = 0;
unsigned long flags;
spin_lock_irqsave(&local_handler_lock, flags);
write_errselr_el1(1);
errxstatus = read_errxstatus_el1();
errxmisc = read_errxmisc_el1();
if (KRYO_ERRXSTATUS_VALID(errxstatus) &&
KRYO_ERRXMISC_LVL(errxmisc) == L3_BIT) {
if (l3_is_bus_error(errxstatus)) {
if (edev_ctl->panic_on_ue) {
spin_unlock_irqrestore(&local_handler_lock, flags);
panic("Causing panic due to Bus Error\n");
}
goto unlock;
}
if (KRYO_ERRXSTATUS_UE(errxstatus)) {
edac_printk(KERN_CRIT, EDAC_CPU, "Detected L3 uncorrectable error\n");
dump_err_reg(KRYO_L3_UE, L3, errxstatus, errxmisc,
edev_ctl);
} else {
edac_printk(KERN_CRIT, EDAC_CPU, "Detected L3 correctable error\n");
dump_err_reg(KRYO_L3_CE, L3, errxstatus, errxmisc,
edev_ctl);
}
clear_errxstatus_valid(errxstatus);
}
unlock:
spin_unlock_irqrestore(&local_handler_lock, flags);
}
static int kryo_cpu_panic_notify(struct notifier_block *this,
unsigned long event, void *ptr)
{
struct edac_device_ctl_info *edev_ctl =
panic_handler_drvdata->edev_ctl;
#ifdef CONFIG_EDAC_KRYO_ARM64_PANIC_ON_CE
edev_ctl->panic_on_ce = 0;
#endif
edev_ctl->panic_on_ue = 0;
kryo_check_l3_scu_error(edev_ctl);
kryo_check_l1_l2_ecc(edev_ctl);
return NOTIFY_OK;
}
static irqreturn_t kryo_l1_l2_handler(int irq, void *drvdata)
{
kryo_check_l1_l2_ecc(panic_handler_drvdata->edev_ctl);
return IRQ_HANDLED;
}
static irqreturn_t kryo_l3_scu_handler(int irq, void *drvdata)
{
struct erp_drvdata *drv = drvdata;
struct edac_device_ctl_info *edev_ctl = drv->edev_ctl;
kryo_check_l3_scu_error(edev_ctl);
return IRQ_HANDLED;
}
static void initialize_registers(void *info)
{
set_errxctlr_el1();
set_errxmisc_overflow();
}
static void init_regs_on_cpu(bool all_cpus)
{
int cpu;
write_errselr_el1(0);
if (all_cpus) {
for_each_possible_cpu(cpu)
smp_call_function_single(cpu, initialize_registers,
NULL, 1);
} else
initialize_registers(NULL);
write_errselr_el1(1);
initialize_registers(NULL);
}
static int kryo_pmu_cpu_pm_notify(struct notifier_block *self,
unsigned long action, void *v)
{
switch (action) {
case CPU_PM_EXIT:
init_regs_on_cpu(false);
kryo_check_l3_scu_error(panic_handler_drvdata->edev_ctl);
kryo_check_l1_l2_ecc(panic_handler_drvdata->edev_ctl);
break;
}
return NOTIFY_OK;
}
#if IS_ENABLED(CONFIG_SEC_USER_RESET_DEBUG)
static int arm64_edac_dbg_part_notifier_callback(
struct notifier_block *nfb, unsigned long action, void *data)
{
unsigned int cpu = 0, block = 0;
switch (action) {
case DBG_PART_DRV_INIT_DONE:
p_health = ap_health_data_read();
if (tmp_health.header.magic == AP_HEALTH_MAGIC) {
for (cpu = 0; cpu < num_present_cpus(); cpu++) {
for (block = 0; block <= ID_L2_CACHE; block++) {
p_health->cache.edac[cpu][block].ce_cnt +=
tmp_health.cache.edac[cpu][block].ce_cnt;
p_health->daily_cache.edac[cpu][block].ce_cnt +=
tmp_health.cache.edac[cpu][block].ce_cnt;
}
}
p_health->cache.edac_l3.ce_cnt +=
tmp_health.cache.edac_l3.ce_cnt;
p_health->daily_cache.edac_l3.ce_cnt +=
tmp_health.daily_cache.edac_l3.ce_cnt;
p_health->cache.edac_l3.ue_cnt +=
tmp_health.cache.edac_l3.ue_cnt;
p_health->daily_cache.edac_l3.ue_cnt +=
tmp_health.daily_cache.edac_l3.ue_cnt;
p_health->cache.edac_bus_cnt +=
tmp_health.cache.edac_bus_cnt;
p_health->daily_cache.edac_bus_cnt +=
tmp_health.daily_cache.edac_bus_cnt;
ap_health_data_write(p_health);
pr_info("ap_health edac updated\n");
memset((void *)&tmp_health, 0, sizeof(ap_health_t));
}
break;
default:
return NOTIFY_DONE;
}
return NOTIFY_OK;
}
static struct notifier_block arm64_edac_dbg_part_notifier = {
.notifier_call = arm64_edac_dbg_part_notifier_callback,
};
#endif
static int kryo_cpu_erp_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct erp_drvdata *drv;
int rc = 0;
int fail = 0;
int num_irqs = 0;
init_regs_on_cpu(true);
drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL);
if (!drv)
return -ENOMEM;
drv->edev_ctl = edac_device_alloc_ctl_info(0, "cpu",
num_possible_cpus(), "L", 3, 1, NULL, 0,
edac_device_alloc_index());
if (!drv->edev_ctl)
return -ENOMEM;
drv->edev_ctl->dev = dev;
drv->edev_ctl->mod_name = dev_name(dev);
drv->edev_ctl->dev_name = dev_name(dev);
drv->edev_ctl->ctl_name = "cache";
#ifdef CONFIG_EDAC_KRYO_ARM64_PANIC_ON_CE
drv->edev_ctl->panic_on_ce = ARM64_ERP_PANIC_ON_CE;
if (of_property_read_bool(pdev->dev.of_node,
"qcom,disable-panic-on-ce"))
drv->edev_ctl->panic_on_ce = 0;
#endif
drv->edev_ctl->panic_on_ue = ARM64_ERP_PANIC_ON_UE;
drv->nb_pm.notifier_call = kryo_pmu_cpu_pm_notify;
drv->nb_panic.notifier_call = kryo_cpu_panic_notify;
atomic_notifier_chain_register(&panic_notifier_list,
&drv->nb_panic);
platform_set_drvdata(pdev, drv);
rc = edac_device_add_device(drv->edev_ctl);
if (rc)
goto out_mem;
panic_handler_drvdata = drv;
if (request_erp_irq(pdev, "l1-l2-faultirq",
"KRYO L1-L2 ECC FAULTIRQ",
kryo_l1_l2_handler, drv, 1))
fail++;
if (request_erp_irq(pdev, "l3-scu-faultirq",
"KRYO L3-SCU ECC FAULTIRQ",
kryo_l3_scu_handler, drv, 0))
fail++;
num_irqs = platform_irq_count(pdev);
if (num_irqs == 0) {
pr_err("KRYO ERP: No irqs found for error reporting\n");
rc = -EINVAL;
goto out_dev;
}
if (num_irqs < 0) {
rc = num_irqs;
goto out_dev;
}
if (fail == platform_irq_count(pdev)) {
pr_err("KRYO ERP: Could not request any IRQs. Giving up.\n");
rc = -ENODEV;
goto out_dev;
}
cpu_pm_register_notifier(&(drv->nb_pm));
#if IS_ENABLED(CONFIG_SEC_USER_RESET_DEBUG)
memset((void *)&tmp_health, 0, sizeof(ap_health_t));
dbg_partition_notifier_register(&arm64_edac_dbg_part_notifier);
#endif
return 0;
out_dev:
edac_device_del_device(dev);
out_mem:
edac_device_free_ctl_info(drv->edev_ctl);
return rc;
}
static int kryo_cpu_erp_remove(struct platform_device *pdev)
{
struct erp_drvdata *drv = dev_get_drvdata(&pdev->dev);
struct edac_device_ctl_info *edac_ctl = drv->edev_ctl;
if (drv->erp_cpu_drvdata != NULL) {
on_each_cpu(l1_l2_irq_disable, &(drv->ppi), 1);
free_percpu_irq(drv->ppi, drv->erp_cpu_drvdata);
free_percpu(drv->erp_cpu_drvdata);
}
cpu_pm_unregister_notifier(&(drv->nb_pm));
edac_device_del_device(edac_ctl->dev);
edac_device_free_ctl_info(edac_ctl);
return 0;
}
static const struct of_device_id kryo_cpu_erp_match_table[] = {
{ .compatible = "arm,arm64-kryo-cpu-erp" },
{ }
};
static struct platform_driver kryo_cpu_erp_driver = {
.probe = kryo_cpu_erp_probe,
.remove = kryo_cpu_erp_remove,
.driver = {
.name = "kryo_cpu_cache_erp",
.of_match_table = of_match_ptr(kryo_cpu_erp_match_table),
},
};
module_platform_driver(kryo_cpu_erp_driver);
MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("Kryo EDAC driver");
|