summaryrefslogtreecommitdiff
path: root/usr/src/cmd/mdb/i86pc/modules/pcplusmp/apic.c
blob: 2e048223ea4140e1fadd140e2359e3d126a36b00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include "intr_common.h"

/*
 * Globals
 */
static struct av_head	avec_tbl[APIC_MAX_VECTOR+1];
static apic_irq_t	*irq_tbl[APIC_MAX_VECTOR+1], airq;
static char		level_tbl[APIC_MAX_VECTOR+1];

/*
 * interrupt_dump:
 *
 *	Dump interrupt information.
 */
/* ARGSUSED */
int
interrupt_dump(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	int		i;

	option_flags = 0;
	if (mdb_getopts(argc, argv,
	    'd', MDB_OPT_SETBITS, INTR_DISPLAY_DRVR_INST, &option_flags,
	    'i', MDB_OPT_SETBITS, INTR_DISPLAY_INTRSTAT, &option_flags,
	    NULL) != argc)
		return (DCMD_USAGE);

	if (mdb_readvar(&irq_tbl, "apic_irq_table") == -1) {
		mdb_warn("failed to read apic_irq_table");
		return (DCMD_ERR);
	}

	if (mdb_readvar(&level_tbl, "apic_level_intr") == -1) {
		mdb_warn("failed to read apic_level_intr");
		return (DCMD_ERR);
	}

	if (mdb_readvar(&avec_tbl, "autovect") == -1) {
		mdb_warn("failed to read autovect");
		return (DCMD_ERR);
	}

	/* Print the header first */
	if (option_flags & INTR_DISPLAY_INTRSTAT)
		mdb_printf("%<u>CPU ");
	else
		mdb_printf(
		    "%<u>IRQ  Vect IPL Bus    Trg Type   CPU Share APIC/INT# ");
	mdb_printf("%s %</u>\n", option_flags & INTR_DISPLAY_DRVR_INST ?
	    "Driver Name(s)" : "ISR(s)");

	/* Walk all the entries */
	for (i = 0; i < APIC_MAX_VECTOR + 1; i++) {
		/* Read the entry */
		if (mdb_vread(&airq, sizeof (apic_irq_t),
		    (uintptr_t)irq_tbl[i]) == -1)
			continue;

		apic_interrupt_dump(&airq, &avec_tbl[i], i, NULL, level_tbl[i]);
	}

	return (DCMD_OK);
}

/* Macros for reading/writing the IOAPIC RDT entries */
#define	READ_IOAPIC_RDT_ENTRY_LOW_DWORD(ioapic_ix, ipin) \
	ioapic_read(ioapic_ix, APIC_RDT_CMD + (2 * (ipin)))

#define	READ_IOAPIC_RDT_ENTRY_HIGH_DWORD(ioapic_ix, ipin) \
	ioapic_read(ioapic_ix, APIC_RDT_CMD2 + (2 * (ipin)))

static uint32_t *ioapic_adr[MAX_IO_APIC];

uint32_t
ioapic_read(int ioapic_ix, uint32_t reg)
{
	volatile uint32_t *ioapic;

	ioapic = ioapic_adr[ioapic_ix];
	ioapic[APIC_IO_REG] = reg;
	return (ioapic[APIC_IO_DATA]);
}

/*
 * ioapic dcmd - Print out the ioapic registers, nicely formatted.
 */
/*ARGSUSED*/
static int
ioapic(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	uint32_t apic_io_max;
	int	reg;
	int	reg_max;
	int	i;


	if ((flags & DCMD_ADDRSPEC) || argc != 0)
		return (DCMD_USAGE);

	if (mdb_readvar(&ioapic_adr, "apicioadr") == -1) {
		/*
		 * If the mdb_warn string does not end in a \n, mdb will
		 * automatically append the reason for the failure.
		 */
		mdb_warn("failed to read ioapicadr");
		return (DCMD_ERR);
	}

	if (mdb_readvar(&apic_io_max, "apic_io_max") == -1) {
		/*
		 * If the mdb_warn string does not end in a \n, mdb will
		 * automatically append the reason for the failure.
		 */
		mdb_warn("failed to read apic_io_max");
		return (DCMD_ERR);
	}

	mdb_printf("ioapicadr\t%p\n", ioapic_adr);

	for (i = 0; i < apic_io_max; i++) {
		/* Bits 23-16 define the maximum redirection entries */
		reg_max = ioapic_read(i, APIC_VERS_CMD);
		reg_max = (reg_max >> 16) & 0xff;

		mdb_printf("%4s %8s %8s\n", "reg", "high", " low");
		for (reg = 0; reg <= reg_max; reg++) {
			uint32_t high, low;

			high = READ_IOAPIC_RDT_ENTRY_HIGH_DWORD(i, reg);
			low = READ_IOAPIC_RDT_ENTRY_LOW_DWORD(i, reg);

			mdb_printf("%2d   %8x %8x\n", reg, high, low);
		}

		mdb_printf("\n");

	}

	return (DCMD_OK);
}


/*
 * apic dcmd - Print out the apic registers, nicely formatted.
 */
/*ARGSUSED*/
static int
apic(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	uint32_t *papic;

	if ((flags & DCMD_ADDRSPEC) || argc != 0)
		return (DCMD_USAGE);

	if (mdb_readvar(&papic, "apicadr") == -1) {
		/*
		 * If the mdb_warn string does not end in a \n, mdb will
		 * automatically append the reason for the failure.
		 */
		mdb_warn("failed to read apicadr");
		return (DCMD_ERR);
	}

	mdb_printf("apicadr\t%p\n", papic);
	mdb_printf("as_task_reg\t%x\n", papic[APIC_TASK_REG]);
	mdb_printf("as_dest_reg\t%x\n", papic[APIC_DEST_REG]);
	mdb_printf("as_format_reg\t%x\n", papic[APIC_FORMAT_REG]);
	mdb_printf("as_local_timer\t%x\n", papic[APIC_LOCAL_TIMER]);
	mdb_printf("as_pcint_vect\t%x\n", papic[APIC_PCINT_VECT]);
	mdb_printf("as_int_vect0\t%x\n", papic[APIC_INT_VECT0]);
	mdb_printf("as_int_vect1\t%x\n", papic[APIC_INT_VECT1]);
	mdb_printf("as_err_vect\t%x\n", papic[APIC_ERR_VECT]);
	mdb_printf("as_init_count\t%x\n", papic[APIC_INIT_COUNT]);
	mdb_printf("as_divide_reg\t%x\n", papic[APIC_DIVIDE_REG]);
	mdb_printf("as_spur_int_reg\t%x\n", papic[APIC_SPUR_INT_REG]);

	return (DCMD_OK);
}


/*
 * MDB module linkage information:
 *
 * We declare a list of structures describing our dcmds, and a function
 * named _mdb_init to return a pointer to our module information.
 */
static const mdb_dcmd_t dcmds[] = {
	{ "interrupts", "?[-di]", "print interrupts", interrupt_dump,
	    interrupt_help},
	{ "softint", "?[-d]", "print soft interrupts", soft_interrupt_dump,
	    soft_interrupt_help},
	{ "apic", NULL, "print apic register contents", apic },
	{ "ioapic", NULL, "print ioapic register contents", ioapic },
	{ NULL }
};

static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, NULL };

const mdb_modinfo_t *
_mdb_init(void)
{
	GElf_Sym	sym;

	if (mdb_lookup_by_name("gld_intr", &sym) != -1)
		if (GELF_ST_TYPE(sym.st_info) == STT_FUNC)
			gld_intr_addr = (uintptr_t)sym.st_value;

	return (&modinfo);
}