1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2018 Joyent, Inc.
24  */
25 
26 #include "intr_common.h"
27 #include <sys/apic_timer.h>
28 
29 /*
30  * Globals
31  */
32 static struct av_head	avec_tbl[APIC_MAX_VECTOR+1];
33 static apic_irq_t	*irq_tbl[APIC_MAX_VECTOR+1], airq;
34 static char		level_tbl[APIC_MAX_VECTOR+1];
35 
36 /*
37  * Dump interrupt information for pcplusmp PSM.
38  */
39 /* ARGSUSED */
40 int
interrupt_dump_apic(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)41 interrupt_dump_apic(uintptr_t addr, uint_t flags, int argc,
42     const mdb_arg_t *argv)
43 {
44 	int		i;
45 
46 	option_flags = 0;
47 	if (mdb_getopts(argc, argv,
48 	    'd', MDB_OPT_SETBITS, INTR_DISPLAY_DRVR_INST, &option_flags,
49 	    'i', MDB_OPT_SETBITS, INTR_DISPLAY_INTRSTAT, &option_flags,
50 	    NULL) != argc)
51 		return (DCMD_USAGE);
52 
53 	if (mdb_readvar(&irq_tbl, "apic_irq_table") == -1) {
54 		mdb_warn("failed to read apic_irq_table");
55 		return (DCMD_ERR);
56 	}
57 
58 	if (mdb_readvar(&level_tbl, "apic_level_intr") == -1) {
59 		mdb_warn("failed to read apic_level_intr");
60 		return (DCMD_ERR);
61 	}
62 
63 	if (mdb_readvar(&avec_tbl, "autovect") == -1) {
64 		mdb_warn("failed to read autovect");
65 		return (DCMD_ERR);
66 	}
67 
68 	/* Print the header first */
69 	if (option_flags & INTR_DISPLAY_INTRSTAT)
70 		mdb_printf("%<u>CPU ");
71 	else
72 		mdb_printf(
73 		    "%<u>IRQ  Vect IPL Bus    Trg Type   CPU Share APIC/INT# ");
74 	mdb_printf("%s %</u>\n", option_flags & INTR_DISPLAY_DRVR_INST ?
75 	    "Driver Name(s)" : "ISR(s)");
76 
77 	/* Walk all the entries */
78 	for (i = 0; i < APIC_MAX_VECTOR + 1; i++) {
79 		/* Read the entry */
80 		if (mdb_vread(&airq, sizeof (apic_irq_t),
81 		    (uintptr_t)irq_tbl[i]) == -1)
82 			continue;
83 
84 		apic_interrupt_dump(&airq, &avec_tbl[i], i, NULL, level_tbl[i]);
85 	}
86 
87 	return (DCMD_OK);
88 }
89 
90 
91 /*
92  * MDB module linkage information:
93  *
94  * We declare a list of structures describing our dcmds, and a function
95  * named _mdb_init to return a pointer to our module information.
96  */
97 static const mdb_dcmd_t dcmds[] = {
98 	{ "interrupts", "?[-di]", "print interrupts", interrupt_dump_apic,
99 	    interrupt_help},
100 	{ "softint", "?[-d]", "print soft interrupts", soft_interrupt_dump,
101 	    soft_interrupt_help},
102 #ifdef _KMDB
103 	{ "apic", NULL, "print apic register contents", apic },
104 	{ "ioapic", NULL, "print ioapic register contents", ioapic },
105 #endif /* _KMDB */
106 	{ NULL }
107 };
108 
109 static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, NULL };
110 
111 const mdb_modinfo_t *
_mdb_init(void)112 _mdb_init(void)
113 {
114 	GElf_Sym	sym;
115 
116 	if (mdb_lookup_by_name("gld_intr", &sym) != -1)
117 		if (GELF_ST_TYPE(sym.st_info) == STT_FUNC)
118 			gld_intr_addr = (uintptr_t)sym.st_value;
119 
120 	if (mdb_readvar(&apic_pir_vect, "apic_pir_vect") == -1) {
121 		apic_pir_vect = -1;
122 	}
123 
124 	return (&modinfo);
125 }
126