sbbuswatch.c revision 1.4 1 1.4 mrg /* $NetBSD: sbbuswatch.c,v 1.4 2017/07/24 09:56:46 mrg Exp $ */
2 1.2 matt /*
3 1.2 matt * Copyright (c) 2010, The NetBSD Foundation, Inc. All rights reserved.
4 1.2 matt *
5 1.2 matt * This code is derived from software contributed to The NetBSD Foundation
6 1.2 matt * by Cliff Neighbors.
7 1.2 matt *
8 1.2 matt * Redistribution and use in source and binary forms, with or without
9 1.2 matt * modification, are permitted provided that the following conditions
10 1.2 matt * are met:
11 1.2 matt * 1. Redistributions of source code must retain the above copyright
12 1.2 matt * notice, this list of conditions and the following disclaimer.
13 1.2 matt * 2. Redistributions in binary form must reproduce the above copyright
14 1.2 matt * notice, this list of conditions and the following disclaimer in the
15 1.2 matt * documentation and/or other materials provided with the distribution.
16 1.2 matt *
17 1.2 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 1.2 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 1.2 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 1.2 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 1.2 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 1.2 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 1.2 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 1.2 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 1.2 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 1.2 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 1.2 matt * POSSIBILITY OF SUCH DAMAGE.
28 1.2 matt */
29 1.2 matt
30 1.2 matt #include <sys/param.h>
31 1.2 matt #include <sys/systm.h>
32 1.2 matt #include <sys/cpu.h>
33 1.2 matt
34 1.2 matt #include <mips/cpu.h>
35 1.2 matt #include <mips/locore.h>
36 1.2 matt
37 1.2 matt #include <mips/sibyte/include/sb1250_int.h>
38 1.2 matt #include <mips/sibyte/include/sb1250_regs.h>
39 1.2 matt #include <mips/sibyte/dev/sbbuswatchvar.h>
40 1.2 matt
41 1.4 mrg #include <evbmips/sbmips/systemsw.h>
42 1.4 mrg
43 1.3 christos #define READ_REG(rp) mips3_ld((register_t)(rp))
44 1.3 christos #define WRITE_REG(rp, val) mips3_sd((register_t)(rp), (val))
45 1.2 matt
46 1.2 matt static void sibyte_bus_watch_intr(void *, uint32_t, vaddr_t);
47 1.2 matt
48 1.2 matt void
49 1.2 matt sibyte_bus_watch_init(void)
50 1.2 matt {
51 1.2 matt (void)READ_REG(MIPS_PHYS_TO_KSEG1(A_SCD_BUS_ERR_STATUS));
52 1.2 matt WRITE_REG(MIPS_PHYS_TO_KSEG1(A_BUS_L2_ERRORS), 0);
53 1.2 matt WRITE_REG(MIPS_PHYS_TO_KSEG1(A_BUS_MEM_IO_ERRORS), 0);
54 1.2 matt
55 1.2 matt (void)cpu_intr_establish(K_INT_BAD_ECC, IPL_DDB,
56 1.2 matt sibyte_bus_watch_intr, (void *)K_INT_BAD_ECC);
57 1.2 matt (void)cpu_intr_establish(K_INT_COR_ECC, IPL_DDB,
58 1.2 matt sibyte_bus_watch_intr, (void *)K_INT_COR_ECC);
59 1.2 matt (void)cpu_intr_establish(K_INT_IO_BUS, IPL_DDB,
60 1.2 matt sibyte_bus_watch_intr, (void *)K_INT_IO_BUS);
61 1.2 matt }
62 1.2 matt
63 1.2 matt int
64 1.2 matt sibyte_bus_watch_check(unsigned int cause)
65 1.2 matt {
66 1.2 matt uint64_t err_ctl;
67 1.2 matt uint64_t cache_err_i;
68 1.2 matt uint64_t cache_err_d;
69 1.2 matt uint64_t cache_err_dpa;
70 1.2 matt uint64_t bus_err_dpa;
71 1.2 matt uint32_t bus_err_status;
72 1.2 matt uint32_t l2_errors;
73 1.2 matt uint32_t mem_io_errors;
74 1.2 matt
75 1.2 matt bus_err_status = READ_REG(
76 1.2 matt MIPS_PHYS_TO_KSEG1(A_SCD_BUS_ERR_STATUS));
77 1.2 matt
78 1.2 matt if (bus_err_status == 0)
79 1.2 matt return 0;
80 1.2 matt
81 1.2 matt l2_errors = READ_REG(
82 1.2 matt MIPS_PHYS_TO_KSEG1(A_BUS_L2_ERRORS));
83 1.2 matt if (l2_errors != 0)
84 1.2 matt WRITE_REG(MIPS_PHYS_TO_KSEG1(A_BUS_L2_ERRORS), 0);
85 1.2 matt
86 1.2 matt mem_io_errors = READ_REG(
87 1.2 matt MIPS_PHYS_TO_KSEG1(A_BUS_MEM_IO_ERRORS));
88 1.2 matt if (mem_io_errors != 0)
89 1.2 matt WRITE_REG(MIPS_PHYS_TO_KSEG1(A_BUS_MEM_IO_ERRORS), 0);
90 1.2 matt
91 1.2 matt asm volatile("dmfc0 %0, $26, 0;" : "=r"(err_ctl));
92 1.2 matt asm volatile("dmfc0 %0, $26, 1;" : "=r"(bus_err_dpa));
93 1.2 matt asm volatile("dmfc0 %0, $27, 0;" : "=r"(cache_err_i));
94 1.2 matt asm volatile("dmfc0 %0, $27, 1;" : "=r"(cache_err_d));
95 1.2 matt asm volatile("dmfc0 %0, $27, 3;" : "=r"(cache_err_dpa));
96 1.2 matt
97 1.2 matt printf("bus_err_status=%#x\n", bus_err_status);
98 1.2 matt printf("l2_errors=%#x\n", l2_errors);
99 1.2 matt printf("mem_io_errors=%#x\n", mem_io_errors);
100 1.2 matt printf("err_ctl=%#"PRIx64"\n", err_ctl);
101 1.2 matt printf("bus_err_dpa=%#"PRIx64"\n", bus_err_dpa);
102 1.2 matt printf("cache_err_i=%#"PRIx64"\n", cache_err_i);
103 1.2 matt printf("cache_err_d=%#"PRIx64"\n", cache_err_d);
104 1.2 matt printf("cache_err_dpa=%#"PRIx64"\n", cache_err_dpa);
105 1.2 matt
106 1.2 matt return -1;
107 1.2 matt }
108 1.2 matt
109 1.2 matt static void
110 1.2 matt sibyte_bus_watch_intr(void *arg, uint32_t status, vaddr_t pc)
111 1.2 matt {
112 1.2 matt printf("%s: %p\n", __func__, arg);
113 1.2 matt (void)sibyte_bus_watch_check(0);
114 1.2 matt }
115