Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * License.  See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2012 Cavium, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (C) 2009 Wind River Systems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *   written by Ralf Baechle <ralf@linux-mips.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/edac.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "edac_module.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/octeon/cvmx.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/mipsregs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) extern int register_co_cache_error_notifier(struct notifier_block *nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) extern int unregister_co_cache_error_notifier(struct notifier_block *nb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) extern unsigned long long cache_err_dcache[NR_CPUS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) struct co_cache_error {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct notifier_block notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct edac_device_ctl_info *ed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * EDAC CPU cache error callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * @event: non-zero if unrecoverable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static int  co_cache_error_event(struct notifier_block *this,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	unsigned long event, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct co_cache_error *p = container_of(this, struct co_cache_error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 						notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	unsigned int core = cvmx_get_core_num();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	unsigned int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	u64 icache_err = read_octeon_c0_icacheerr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	u64 dcache_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	if (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		dcache_err = cache_err_dcache[core];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		cache_err_dcache[core] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		dcache_err = read_octeon_c0_dcacheerr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (icache_err & 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		edac_device_printk(p->ed, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 				   "CacheErr (Icache):%llx, core %d/cpu %d, cp0_errorepc == %lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 				   (unsigned long long)icache_err, core, cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 				   read_c0_errorepc());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		write_octeon_c0_icacheerr(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		edac_device_handle_ce(p->ed, cpu, 1, "icache");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (dcache_err & 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		edac_device_printk(p->ed, KERN_ERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				   "CacheErr (Dcache):%llx, core %d/cpu %d, cp0_errorepc == %lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 				   (unsigned long long)dcache_err, core, cpu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 				   read_c0_errorepc());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		if (event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			edac_device_handle_ue(p->ed, cpu, 0, "dcache");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			edac_device_handle_ce(p->ed, cpu, 0, "dcache");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		/* Clear the error indication */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		if (OCTEON_IS_OCTEON2())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			write_octeon_c0_dcacheerr(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			write_octeon_c0_dcacheerr(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	return NOTIFY_STOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static int co_cache_error_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct co_cache_error *p = devm_kzalloc(&pdev->dev, sizeof(*p),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 						GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	p->notifier.notifier_call = co_cache_error_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	platform_set_drvdata(pdev, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	p->ed = edac_device_alloc_ctl_info(0, "cpu", num_possible_cpus(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 					   "cache", 2, 0, NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 					   edac_device_alloc_index());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (!p->ed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	p->ed->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	p->ed->dev_name = dev_name(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	p->ed->mod_name = "octeon-cpu";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	p->ed->ctl_name = "cache";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (edac_device_add_device(p->ed)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		pr_err("%s: edac_device_add_device() failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		goto err1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	register_co_cache_error_notifier(&p->notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) err1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	edac_device_free_ctl_info(p->ed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static int co_cache_error_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct co_cache_error *p = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	unregister_co_cache_error_notifier(&p->notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	edac_device_del_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	edac_device_free_ctl_info(p->ed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static struct platform_driver co_cache_error_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	.probe = co_cache_error_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	.remove = co_cache_error_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		   .name = "octeon_pc_edac",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) module_platform_driver(co_cache_error_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");