xref: /netbsd-src/sys/arch/mips/cavium/dev/octeon_ciu.c (revision 03dcb730d46d34d85c9f496c1f5a3a6a43f2b7b3)
1 /*	$NetBSD: octeon_ciu.c,v 1.1 2015/04/29 08:32:01 hikaru Exp $	*/
2 
3 /*
4  * Copyright (c) 2008 Internet Initiative Japan, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: octeon_ciu.c,v 1.1 2015/04/29 08:32:01 hikaru Exp $");
31 
32 #include "opt_octeon.h"
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/types.h>
37 #include <sys/malloc.h>
38 
39 #include <sys/bus.h>
40 #include <machine/locore.h>
41 #include <machine/vmparam.h>
42 
43 #include <mips/cavium/octeonvar.h>
44 #include <mips/cavium/dev/octeon_ciureg.h>
45 
46 #ifdef CIUDEBUG
47 #define	DPRINTF(x)	printf x
48 #else
49 #define	DPRINTF(x)
50 #endif
51 
52 #ifdef OCTEON_ETH_DEBUG
53 void		octeon_ciu_dump(void);
54 void		octeon_ciu_dump_regs(void);
55 
56 #define	_ENTRY(x)	{ #x, x##_BITS, x }
57 
58 struct octeon_ciu_dump_reg_entry {
59 	const char *name;
60 	const char *format;
61 	paddr_t address;
62 };
63 
64 static const struct octeon_ciu_dump_reg_entry octeon_ciu_dump_regs_entries[] = {
65 	_ENTRY(CIU_INT0_SUM0),
66 	_ENTRY(CIU_INT1_SUM0),
67 	_ENTRY(CIU_INT2_SUM0),
68 	_ENTRY(CIU_INT3_SUM0),
69 	_ENTRY(CIU_INT32_SUM0),
70 	_ENTRY(CIU_INT_SUM1),
71 	_ENTRY(CIU_INT0_EN0),
72 	_ENTRY(CIU_INT1_EN0),
73 	_ENTRY(CIU_INT2_EN0),
74 	_ENTRY(CIU_INT3_EN0),
75 	_ENTRY(CIU_INT32_EN0),
76 	_ENTRY(CIU_INT0_EN1),
77 	_ENTRY(CIU_INT1_EN1),
78 	_ENTRY(CIU_INT2_EN1),
79 	_ENTRY(CIU_INT3_EN1),
80 	_ENTRY(CIU_INT32_EN1),
81 	_ENTRY(CIU_TIM0),
82 	_ENTRY(CIU_TIM1),
83 	_ENTRY(CIU_TIM2),
84 	_ENTRY(CIU_TIM3),
85 	_ENTRY(CIU_WDOG0),
86 	_ENTRY(CIU_WDOG1),
87 	/* _ENTRY(CIU_PP_POKE0), */
88 	/* _ENTRY(CIU_PP_POKE1), */
89 	_ENTRY(CIU_MBOX_SET0),
90 	_ENTRY(CIU_MBOX_SET1),
91 	_ENTRY(CIU_MBOX_CLR0),
92 	_ENTRY(CIU_MBOX_CLR1),
93 	_ENTRY(CIU_PP_RST),
94 	_ENTRY(CIU_PP_DBG),
95 	_ENTRY(CIU_GSTOP),
96 	_ENTRY(CIU_NMI),
97 	_ENTRY(CIU_DINT),
98 	_ENTRY(CIU_FUSE),
99 	_ENTRY(CIU_BIST),
100 	_ENTRY(CIU_SOFT_BIST),
101 	_ENTRY(CIU_SOFT_RST),
102 	_ENTRY(CIU_SOFT_PRST),
103 	_ENTRY(CIU_PCI_INTA)
104 };
105 
106 void
107 octeon_ciu_dump(void)
108 {
109 	octeon_ciu_dump_regs();
110 }
111 
112 void
113 octeon_ciu_dump_regs(void)
114 {
115 	const struct octeon_ciu_dump_reg_entry *reg;
116 	uint64_t tmp;
117 	char buf[512];
118 	int i;
119 
120 	for (i = 0; i < (int)__arraycount(octeon_ciu_dump_regs_entries); i++) {
121 		reg = &octeon_ciu_dump_regs_entries[i];
122 		tmp = octeon_xkphys_read_8(reg->address);
123 		if (reg->format == NULL) {
124 			snprintf(buf, sizeof(buf), "%16" PRIx64, tmp);
125 		} else {
126 			snprintb(buf, sizeof(buf), reg->format, tmp);
127 		}
128 		printf("\t%-24s: %s\n", reg->name, buf);
129 	}
130 }
131 #endif
132