xref: /netbsd-src/sys/arch/mips/sibyte/dev/sbbuswatch.c (revision 7ed56e8c18ac18ea40a6aaa37b3aff4f7d17de0f)
1*7ed56e8cSmrg /*	$NetBSD: sbbuswatch.c,v 1.4 2017/07/24 09:56:46 mrg Exp $	*/
26f35b2ecSmatt /*
36f35b2ecSmatt  * Copyright (c) 2010, The NetBSD Foundation, Inc.  All rights reserved.
46f35b2ecSmatt  *
56f35b2ecSmatt  * This code is derived from software contributed to The NetBSD Foundation
66f35b2ecSmatt  * by Cliff Neighbors.
76f35b2ecSmatt  *
86f35b2ecSmatt  * Redistribution and use in source and binary forms, with or without
96f35b2ecSmatt  * modification, are permitted provided that the following conditions
106f35b2ecSmatt  * are met:
116f35b2ecSmatt  * 1. Redistributions of source code must retain the above copyright
126f35b2ecSmatt  *    notice, this list of conditions and the following disclaimer.
136f35b2ecSmatt  * 2. Redistributions in binary form must reproduce the above copyright
146f35b2ecSmatt  *    notice, this list of conditions and the following disclaimer in the
156f35b2ecSmatt  *    documentation and/or other materials provided with the distribution.
166f35b2ecSmatt  *
176f35b2ecSmatt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
186f35b2ecSmatt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
196f35b2ecSmatt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
206f35b2ecSmatt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
216f35b2ecSmatt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
226f35b2ecSmatt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
236f35b2ecSmatt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
246f35b2ecSmatt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
256f35b2ecSmatt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
266f35b2ecSmatt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
276f35b2ecSmatt  * POSSIBILITY OF SUCH DAMAGE.
286f35b2ecSmatt  */
296f35b2ecSmatt 
306f35b2ecSmatt #include <sys/param.h>
316f35b2ecSmatt #include <sys/systm.h>
326f35b2ecSmatt #include <sys/cpu.h>
336f35b2ecSmatt 
346f35b2ecSmatt #include <mips/cpu.h>
356f35b2ecSmatt #include <mips/locore.h>
366f35b2ecSmatt 
376f35b2ecSmatt #include <mips/sibyte/include/sb1250_int.h>
386f35b2ecSmatt #include <mips/sibyte/include/sb1250_regs.h>
396f35b2ecSmatt #include <mips/sibyte/dev/sbbuswatchvar.h>
406f35b2ecSmatt 
41*7ed56e8cSmrg #include <evbmips/sbmips/systemsw.h>
42*7ed56e8cSmrg 
4367c90d24Schristos #define READ_REG(rp)            mips3_ld((register_t)(rp))
4467c90d24Schristos #define WRITE_REG(rp, val)      mips3_sd((register_t)(rp), (val))
456f35b2ecSmatt 
466f35b2ecSmatt static void sibyte_bus_watch_intr(void *, uint32_t, vaddr_t);
476f35b2ecSmatt 
486f35b2ecSmatt void
sibyte_bus_watch_init(void)496f35b2ecSmatt sibyte_bus_watch_init(void)
506f35b2ecSmatt {
516f35b2ecSmatt 	(void)READ_REG(MIPS_PHYS_TO_KSEG1(A_SCD_BUS_ERR_STATUS));
526f35b2ecSmatt 	WRITE_REG(MIPS_PHYS_TO_KSEG1(A_BUS_L2_ERRORS), 0);
536f35b2ecSmatt 	WRITE_REG(MIPS_PHYS_TO_KSEG1(A_BUS_MEM_IO_ERRORS), 0);
546f35b2ecSmatt 
556f35b2ecSmatt 	(void)cpu_intr_establish(K_INT_BAD_ECC, IPL_DDB,
566f35b2ecSmatt 		sibyte_bus_watch_intr, (void *)K_INT_BAD_ECC);
576f35b2ecSmatt 	(void)cpu_intr_establish(K_INT_COR_ECC, IPL_DDB,
586f35b2ecSmatt 		sibyte_bus_watch_intr, (void *)K_INT_COR_ECC);
596f35b2ecSmatt 	(void)cpu_intr_establish(K_INT_IO_BUS, IPL_DDB,
606f35b2ecSmatt 		sibyte_bus_watch_intr, (void *)K_INT_IO_BUS);
616f35b2ecSmatt }
626f35b2ecSmatt 
636f35b2ecSmatt int
sibyte_bus_watch_check(unsigned int cause)646f35b2ecSmatt sibyte_bus_watch_check(unsigned int cause)
656f35b2ecSmatt {
666f35b2ecSmatt 	uint64_t err_ctl;
676f35b2ecSmatt 	uint64_t cache_err_i;
686f35b2ecSmatt 	uint64_t cache_err_d;
696f35b2ecSmatt 	uint64_t cache_err_dpa;
706f35b2ecSmatt 	uint64_t bus_err_dpa;
716f35b2ecSmatt 	uint32_t bus_err_status;
726f35b2ecSmatt 	uint32_t l2_errors;
736f35b2ecSmatt 	uint32_t mem_io_errors;
746f35b2ecSmatt 
756f35b2ecSmatt 	bus_err_status = READ_REG(
766f35b2ecSmatt 		MIPS_PHYS_TO_KSEG1(A_SCD_BUS_ERR_STATUS));
776f35b2ecSmatt 
786f35b2ecSmatt 	if (bus_err_status == 0)
796f35b2ecSmatt 		return 0;
806f35b2ecSmatt 
816f35b2ecSmatt 	l2_errors = READ_REG(
826f35b2ecSmatt 		MIPS_PHYS_TO_KSEG1(A_BUS_L2_ERRORS));
836f35b2ecSmatt 	if (l2_errors != 0)
846f35b2ecSmatt 		WRITE_REG(MIPS_PHYS_TO_KSEG1(A_BUS_L2_ERRORS), 0);
856f35b2ecSmatt 
866f35b2ecSmatt 	mem_io_errors = READ_REG(
876f35b2ecSmatt 		MIPS_PHYS_TO_KSEG1(A_BUS_MEM_IO_ERRORS));
886f35b2ecSmatt 	if (mem_io_errors != 0)
896f35b2ecSmatt 		WRITE_REG(MIPS_PHYS_TO_KSEG1(A_BUS_MEM_IO_ERRORS), 0);
906f35b2ecSmatt 
916f35b2ecSmatt 	asm volatile("dmfc0 %0, $26, 0;" : "=r"(err_ctl));
926f35b2ecSmatt 	asm volatile("dmfc0 %0, $26, 1;" : "=r"(bus_err_dpa));
936f35b2ecSmatt 	asm volatile("dmfc0 %0, $27, 0;" : "=r"(cache_err_i));
946f35b2ecSmatt 	asm volatile("dmfc0 %0, $27, 1;" : "=r"(cache_err_d));
956f35b2ecSmatt 	asm volatile("dmfc0 %0, $27, 3;" : "=r"(cache_err_dpa));
966f35b2ecSmatt 
976f35b2ecSmatt 	printf("bus_err_status=%#x\n", bus_err_status);
986f35b2ecSmatt 	printf("l2_errors=%#x\n", l2_errors);
996f35b2ecSmatt 	printf("mem_io_errors=%#x\n", mem_io_errors);
1006f35b2ecSmatt 	printf("err_ctl=%#"PRIx64"\n", err_ctl);
1016f35b2ecSmatt 	printf("bus_err_dpa=%#"PRIx64"\n", bus_err_dpa);
1026f35b2ecSmatt 	printf("cache_err_i=%#"PRIx64"\n", cache_err_i);
1036f35b2ecSmatt 	printf("cache_err_d=%#"PRIx64"\n", cache_err_d);
1046f35b2ecSmatt 	printf("cache_err_dpa=%#"PRIx64"\n", cache_err_dpa);
1056f35b2ecSmatt 
1066f35b2ecSmatt 	return -1;
1076f35b2ecSmatt }
1086f35b2ecSmatt 
1096f35b2ecSmatt static void
sibyte_bus_watch_intr(void * arg,uint32_t status,vaddr_t pc)1106f35b2ecSmatt sibyte_bus_watch_intr(void *arg, uint32_t status, vaddr_t pc)
1116f35b2ecSmatt {
1126f35b2ecSmatt 	printf("%s: %p\n", __func__, arg);
1136f35b2ecSmatt 	(void)sibyte_bus_watch_check(0);
1146f35b2ecSmatt }
115