136fe4a92Segillett /*
236fe4a92Segillett * CDDL HEADER START
336fe4a92Segillett *
436fe4a92Segillett * The contents of this file are subject to the terms of the
5abf601c9Sanish * Common Development and Distribution License (the "License").
6abf601c9Sanish * You may not use this file except in compliance with the License.
736fe4a92Segillett *
836fe4a92Segillett * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
936fe4a92Segillett * or http://www.opensolaris.org/os/licensing.
1036fe4a92Segillett * See the License for the specific language governing permissions
1136fe4a92Segillett * and limitations under the License.
1236fe4a92Segillett *
1336fe4a92Segillett * When distributing Covered Code, include this CDDL HEADER in each
1436fe4a92Segillett * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1536fe4a92Segillett * If applicable, add the following below this CDDL HEADER, with the
1636fe4a92Segillett * fields enclosed by brackets "[]" replaced with your own identifying
1736fe4a92Segillett * information: Portions Copyright [yyyy] [name of copyright owner]
1836fe4a92Segillett *
1936fe4a92Segillett * CDDL HEADER END
2036fe4a92Segillett */
2136fe4a92Segillett /*
227ff178cdSJimmy Vetayases * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2336fe4a92Segillett */
2436fe4a92Segillett
25d7b41ca4Sanish #include "intr_common.h"
2636fe4a92Segillett
27*5cd376e8SJimmy Vetayases #ifdef _KMDB
2836fe4a92Segillett
292df1fe9cSrandyf /* Macros for reading/writing the IOAPIC RDT entries */
307ff178cdSJimmy Vetayases #define APIC_READ_IOAPIC_RDT_ENTRY_LOW_DWORD(ioapic_ix, ipin) \
317ff178cdSJimmy Vetayases apic_ioapic_read(ioapic_ix, APIC_RDT_CMD + (2 * (ipin)))
322df1fe9cSrandyf
337ff178cdSJimmy Vetayases #define APIC_READ_IOAPIC_RDT_ENTRY_HIGH_DWORD(ioapic_ix, ipin) \
347ff178cdSJimmy Vetayases apic_ioapic_read(ioapic_ix, APIC_RDT_CMD2 + (2 * (ipin)))
352df1fe9cSrandyf
362df1fe9cSrandyf static uint32_t *ioapic_adr[MAX_IO_APIC];
372df1fe9cSrandyf
387ff178cdSJimmy Vetayases static uint32_t
apic_ioapic_read(int ioapic_ix,uint32_t reg)397ff178cdSJimmy Vetayases apic_ioapic_read(int ioapic_ix, uint32_t reg)
402df1fe9cSrandyf {
412df1fe9cSrandyf volatile uint32_t *ioapic;
422df1fe9cSrandyf
432df1fe9cSrandyf ioapic = ioapic_adr[ioapic_ix];
442df1fe9cSrandyf ioapic[APIC_IO_REG] = reg;
452df1fe9cSrandyf return (ioapic[APIC_IO_DATA]);
462df1fe9cSrandyf }
472df1fe9cSrandyf
482df1fe9cSrandyf /*
492df1fe9cSrandyf * ioapic dcmd - Print out the ioapic registers, nicely formatted.
502df1fe9cSrandyf */
512df1fe9cSrandyf /*ARGSUSED*/
527ff178cdSJimmy Vetayases int
ioapic(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)532df1fe9cSrandyf ioapic(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
542df1fe9cSrandyf {
552df1fe9cSrandyf uint32_t apic_io_max;
562df1fe9cSrandyf int reg;
572df1fe9cSrandyf int reg_max;
582df1fe9cSrandyf int i;
592df1fe9cSrandyf
602df1fe9cSrandyf
612df1fe9cSrandyf if ((flags & DCMD_ADDRSPEC) || argc != 0)
622df1fe9cSrandyf return (DCMD_USAGE);
632df1fe9cSrandyf
642df1fe9cSrandyf if (mdb_readvar(&ioapic_adr, "apicioadr") == -1) {
652df1fe9cSrandyf /*
662df1fe9cSrandyf * If the mdb_warn string does not end in a \n, mdb will
672df1fe9cSrandyf * automatically append the reason for the failure.
682df1fe9cSrandyf */
692df1fe9cSrandyf mdb_warn("failed to read ioapicadr");
702df1fe9cSrandyf return (DCMD_ERR);
712df1fe9cSrandyf }
722df1fe9cSrandyf
732df1fe9cSrandyf if (mdb_readvar(&apic_io_max, "apic_io_max") == -1) {
742df1fe9cSrandyf /*
752df1fe9cSrandyf * If the mdb_warn string does not end in a \n, mdb will
762df1fe9cSrandyf * automatically append the reason for the failure.
772df1fe9cSrandyf */
782df1fe9cSrandyf mdb_warn("failed to read apic_io_max");
792df1fe9cSrandyf return (DCMD_ERR);
802df1fe9cSrandyf }
812df1fe9cSrandyf
822df1fe9cSrandyf mdb_printf("ioapicadr\t%p\n", ioapic_adr);
832df1fe9cSrandyf
842df1fe9cSrandyf for (i = 0; i < apic_io_max; i++) {
852df1fe9cSrandyf /* Bits 23-16 define the maximum redirection entries */
867ff178cdSJimmy Vetayases reg_max = apic_ioapic_read(i, APIC_VERS_CMD);
872df1fe9cSrandyf reg_max = (reg_max >> 16) & 0xff;
882df1fe9cSrandyf
892df1fe9cSrandyf mdb_printf("%4s %8s %8s\n", "reg", "high", " low");
902df1fe9cSrandyf for (reg = 0; reg <= reg_max; reg++) {
912df1fe9cSrandyf uint32_t high, low;
922df1fe9cSrandyf
937ff178cdSJimmy Vetayases high = APIC_READ_IOAPIC_RDT_ENTRY_HIGH_DWORD(i, reg);
947ff178cdSJimmy Vetayases low = APIC_READ_IOAPIC_RDT_ENTRY_LOW_DWORD(i, reg);
952df1fe9cSrandyf
962df1fe9cSrandyf mdb_printf("%2d %8x %8x\n", reg, high, low);
972df1fe9cSrandyf }
982df1fe9cSrandyf
992df1fe9cSrandyf mdb_printf("\n");
1002df1fe9cSrandyf
1012df1fe9cSrandyf }
1022df1fe9cSrandyf
1032df1fe9cSrandyf return (DCMD_OK);
1042df1fe9cSrandyf }
1052df1fe9cSrandyf
1062df1fe9cSrandyf
1072df1fe9cSrandyf /*
1082df1fe9cSrandyf * apic dcmd - Print out the apic registers, nicely formatted.
1092df1fe9cSrandyf */
1102df1fe9cSrandyf /*ARGSUSED*/
1117ff178cdSJimmy Vetayases int
apic(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1122df1fe9cSrandyf apic(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1132df1fe9cSrandyf {
1142df1fe9cSrandyf uint32_t *papic;
1152df1fe9cSrandyf
1162df1fe9cSrandyf if ((flags & DCMD_ADDRSPEC) || argc != 0)
1172df1fe9cSrandyf return (DCMD_USAGE);
1182df1fe9cSrandyf
1192df1fe9cSrandyf if (mdb_readvar(&papic, "apicadr") == -1) {
1202df1fe9cSrandyf /*
1212df1fe9cSrandyf * If the mdb_warn string does not end in a \n, mdb will
1222df1fe9cSrandyf * automatically append the reason for the failure.
1232df1fe9cSrandyf */
1242df1fe9cSrandyf mdb_warn("failed to read apicadr");
1252df1fe9cSrandyf return (DCMD_ERR);
1262df1fe9cSrandyf }
1272df1fe9cSrandyf
1282df1fe9cSrandyf mdb_printf("apicadr\t%p\n", papic);
1292df1fe9cSrandyf mdb_printf("as_task_reg\t%x\n", papic[APIC_TASK_REG]);
1302df1fe9cSrandyf mdb_printf("as_dest_reg\t%x\n", papic[APIC_DEST_REG]);
1312df1fe9cSrandyf mdb_printf("as_format_reg\t%x\n", papic[APIC_FORMAT_REG]);
1322df1fe9cSrandyf mdb_printf("as_local_timer\t%x\n", papic[APIC_LOCAL_TIMER]);
1332df1fe9cSrandyf mdb_printf("as_pcint_vect\t%x\n", papic[APIC_PCINT_VECT]);
1342df1fe9cSrandyf mdb_printf("as_int_vect0\t%x\n", papic[APIC_INT_VECT0]);
1352df1fe9cSrandyf mdb_printf("as_int_vect1\t%x\n", papic[APIC_INT_VECT1]);
1362df1fe9cSrandyf mdb_printf("as_err_vect\t%x\n", papic[APIC_ERR_VECT]);
1372df1fe9cSrandyf mdb_printf("as_init_count\t%x\n", papic[APIC_INIT_COUNT]);
1382df1fe9cSrandyf mdb_printf("as_divide_reg\t%x\n", papic[APIC_DIVIDE_REG]);
1392df1fe9cSrandyf mdb_printf("as_spur_int_reg\t%x\n", papic[APIC_SPUR_INT_REG]);
1402df1fe9cSrandyf
1412df1fe9cSrandyf return (DCMD_OK);
1422df1fe9cSrandyf }
143*5cd376e8SJimmy Vetayases
144*5cd376e8SJimmy Vetayases #endif /* _KMDB */
145