sbbuswatch.c revision 1.2 1 1.2 matt /* $NetBSD: sbbuswatch.c,v 1.2 2011/02/20 07:47:39 matt 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.2 matt #define READ_REG(rp) (mips3_ld((volatile uint64_t *)(rp)))
42 1.2 matt #define WRITE_REG(rp, val) (mips3_sd((volatile uint64_t *)(rp), (val)))
43 1.2 matt
44 1.2 matt static void sibyte_bus_watch_intr(void *, uint32_t, vaddr_t);
45 1.2 matt
46 1.2 matt void
47 1.2 matt sibyte_bus_watch_init(void)
48 1.2 matt {
49 1.2 matt (void)READ_REG(MIPS_PHYS_TO_KSEG1(A_SCD_BUS_ERR_STATUS));
50 1.2 matt WRITE_REG(MIPS_PHYS_TO_KSEG1(A_BUS_L2_ERRORS), 0);
51 1.2 matt WRITE_REG(MIPS_PHYS_TO_KSEG1(A_BUS_MEM_IO_ERRORS), 0);
52 1.2 matt
53 1.2 matt (void)cpu_intr_establish(K_INT_BAD_ECC, IPL_DDB,
54 1.2 matt sibyte_bus_watch_intr, (void *)K_INT_BAD_ECC);
55 1.2 matt (void)cpu_intr_establish(K_INT_COR_ECC, IPL_DDB,
56 1.2 matt sibyte_bus_watch_intr, (void *)K_INT_COR_ECC);
57 1.2 matt (void)cpu_intr_establish(K_INT_IO_BUS, IPL_DDB,
58 1.2 matt sibyte_bus_watch_intr, (void *)K_INT_IO_BUS);
59 1.2 matt }
60 1.2 matt
61 1.2 matt int
62 1.2 matt sibyte_bus_watch_check(unsigned int cause)
63 1.2 matt {
64 1.2 matt uint64_t err_ctl;
65 1.2 matt uint64_t cache_err_i;
66 1.2 matt uint64_t cache_err_d;
67 1.2 matt uint64_t cache_err_dpa;
68 1.2 matt uint64_t bus_err_dpa;
69 1.2 matt uint32_t bus_err_status;
70 1.2 matt uint32_t l2_errors;
71 1.2 matt uint32_t mem_io_errors;
72 1.2 matt
73 1.2 matt bus_err_status = READ_REG(
74 1.2 matt MIPS_PHYS_TO_KSEG1(A_SCD_BUS_ERR_STATUS));
75 1.2 matt
76 1.2 matt if (bus_err_status == 0)
77 1.2 matt return 0;
78 1.2 matt
79 1.2 matt l2_errors = READ_REG(
80 1.2 matt MIPS_PHYS_TO_KSEG1(A_BUS_L2_ERRORS));
81 1.2 matt if (l2_errors != 0)
82 1.2 matt WRITE_REG(MIPS_PHYS_TO_KSEG1(A_BUS_L2_ERRORS), 0);
83 1.2 matt
84 1.2 matt mem_io_errors = READ_REG(
85 1.2 matt MIPS_PHYS_TO_KSEG1(A_BUS_MEM_IO_ERRORS));
86 1.2 matt if (mem_io_errors != 0)
87 1.2 matt WRITE_REG(MIPS_PHYS_TO_KSEG1(A_BUS_MEM_IO_ERRORS), 0);
88 1.2 matt
89 1.2 matt asm volatile("dmfc0 %0, $26, 0;" : "=r"(err_ctl));
90 1.2 matt asm volatile("dmfc0 %0, $26, 1;" : "=r"(bus_err_dpa));
91 1.2 matt asm volatile("dmfc0 %0, $27, 0;" : "=r"(cache_err_i));
92 1.2 matt asm volatile("dmfc0 %0, $27, 1;" : "=r"(cache_err_d));
93 1.2 matt asm volatile("dmfc0 %0, $27, 3;" : "=r"(cache_err_dpa));
94 1.2 matt
95 1.2 matt printf("bus_err_status=%#x\n", bus_err_status);
96 1.2 matt printf("l2_errors=%#x\n", l2_errors);
97 1.2 matt printf("mem_io_errors=%#x\n", mem_io_errors);
98 1.2 matt printf("err_ctl=%#"PRIx64"\n", err_ctl);
99 1.2 matt printf("bus_err_dpa=%#"PRIx64"\n", bus_err_dpa);
100 1.2 matt printf("cache_err_i=%#"PRIx64"\n", cache_err_i);
101 1.2 matt printf("cache_err_d=%#"PRIx64"\n", cache_err_d);
102 1.2 matt printf("cache_err_dpa=%#"PRIx64"\n", cache_err_dpa);
103 1.2 matt
104 1.2 matt return -1;
105 1.2 matt }
106 1.2 matt
107 1.2 matt static void
108 1.2 matt sibyte_bus_watch_intr(void *arg, uint32_t status, vaddr_t pc)
109 1.2 matt {
110 1.2 matt printf("%s: %p\n", __func__, arg);
111 1.2 matt (void)sibyte_bus_watch_check(0);
112 1.2 matt }
113