From patchwork Wed Dec 30 11:50:43 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 41905 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E05111007D2 for ; Wed, 30 Dec 2009 22:51:30 +1100 (EST) Received: from localhost ([127.0.0.1]:46049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NPx5K-00063e-F7 for incoming@patchwork.ozlabs.org; Wed, 30 Dec 2009 06:51:26 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NPx4o-00063D-3Y for qemu-devel@nongnu.org; Wed, 30 Dec 2009 06:50:54 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NPx4j-00060l-E4 for qemu-devel@nongnu.org; Wed, 30 Dec 2009 06:50:53 -0500 Received: from [199.232.76.173] (port=35137 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NPx4j-00060i-8F for qemu-devel@nongnu.org; Wed, 30 Dec 2009 06:50:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:17505) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NPx4i-0007D5-MO for qemu-devel@nongnu.org; Wed, 30 Dec 2009 06:50:48 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBUBoitg014271 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 30 Dec 2009 06:50:47 -0500 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBUBohS0021237; Wed, 30 Dec 2009 06:50:44 -0500 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id 4EB5418D450; Wed, 30 Dec 2009 13:50:43 +0200 (IST) Date: Wed, 30 Dec 2009 13:50:43 +0200 From: Gleb Natapov To: qemu-devel@nongnu.org Message-ID: <20091230115043.GD26899@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: lcapitulino@redhat.com Subject: [Qemu-devel] [PATCHv2] add "info ioapic" monitor command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Knowing ioapic configuration is very useful for the poor soles how need to debug guest occasionally. Signed-off-by: Gleb Natapov --- I am starring to learn this QObject kung-fu. One question: Why qlist_iter(..., func, ...) and not FOREACH_QOBJ() { do things } -- Gleb. diff --git a/hw/ioapic.c b/hw/ioapic.c index b0ad78f..efb9744 100644 --- a/hw/ioapic.c +++ b/hw/ioapic.c @@ -24,6 +24,12 @@ #include "pc.h" #include "qemu-timer.h" #include "host-utils.h" +#include "monitor.h" +#include "qint.h" +#include "qlist.h" +#include "qdict.h" +#include "qstring.h" +#include "qjson.h" //#define DEBUG_IOAPIC @@ -50,6 +56,8 @@ struct IOAPICState { uint64_t ioredtbl[IOAPIC_NUM_PINS]; }; +static struct IOAPICState *ioapic; + static void ioapic_service(IOAPICState *s) { uint8_t i; @@ -232,7 +240,7 @@ qemu_irq *ioapic_init(void) qemu_irq *irq; int io_memory; - s = qemu_mallocz(sizeof(IOAPICState)); + ioapic = s = qemu_mallocz(sizeof(IOAPICState)); ioapic_reset(s); io_memory = cpu_register_io_memory(ioapic_mem_read, @@ -245,3 +253,70 @@ qemu_irq *ioapic_init(void) return irq; } + +static void qemu_ioapic_qlist_iter(QObject *data, void *opaque) +{ + QDict *qdict = qobject_to_qdict(data); + Monitor *mon = opaque; + + monitor_printf(mon, "%2"PRId64": ", qdict_get_int(qdict, "index")); + if (qdict_haskey(qdict, "masked")) { + monitor_printf(mon, "masked\n"); + } else { + monitor_printf(mon, "vec=%3"PRId64" %s %s acive-%s %s dest=%"PRId64"\n", + qdict_get_int(qdict, "vector"), + qdict_get_str(qdict, "delivery_mode"), + qdict_get_str(qdict, "dest_mode"), + qdict_get_str(qdict, "polarity"), + qdict_get_str(qdict, "trig_mode"), + qdict_get_int(qdict, "destination")); + } +} + +void monitor_print_ioapic(Monitor *mon, const QObject *ret_data) +{ + qlist_iter(qobject_to_qlist(ret_data), qemu_ioapic_qlist_iter, mon); +} + +static const char *delivery_mode_string[] = {"fixed", "lowprio", "smi", "res", + "nmi", "init", "res", "extint"}; + +void do_info_ioapic(Monitor *mon, QObject **ret_data) +{ + int i; + QList *list; + + *ret_data = NULL; + + if (!ioapic) + return; + + list = qlist_new(); + + for (i = 0; i < IOAPIC_NUM_PINS; i++) { + QObject *obj; + uint64 e = ioapic->ioredtbl[i]; + if (e & IOAPIC_LVT_MASKED) { + obj = qobject_from_jsonf("{'index': %d, 'masked': 1}", i); + } else { + uint8_t vec = e & 0xff; + uint8_t trig_mode = ((e >> 15) & 1); + uint8_t dest = e >> 56; + uint8_t dest_mode = (e >> 11) & 1; + uint8_t delivery_mode = (e >> 8) & 7; + uint8_t polarity = (e >> 13) & 1; + obj = qobject_from_jsonf("{'index': %d, 'vector': %d," + "'delivery_mode': %s, 'dest_mode': %s," + "'polarity': %s, 'trig_mode': %s," + "'destination': %d}", + i, vec, + delivery_mode_string[delivery_mode], + dest_mode ? "logical":"physical", + polarity ? "low" : "high", + trig_mode ? "level": "edge", + dest); + } + qlist_append_obj(list, obj); + } + *ret_data = QOBJECT(list); +} diff --git a/hw/pc.h b/hw/pc.h index 03ffc91..3e39444 100644 --- a/hw/pc.h +++ b/hw/pc.h @@ -2,6 +2,7 @@ #define HW_PC_H #include "qemu-common.h" +#include "qobject.h" /* PC-style peripherals (also used by other machines). */ @@ -45,6 +46,8 @@ int apic_accept_pic_intr(CPUState *env); void apic_deliver_pic_intr(CPUState *env, int level); int apic_get_interrupt(CPUState *env); qemu_irq *ioapic_init(void); +void do_info_ioapic(Monitor *mon, QObject **ret_data); +void monitor_print_ioapic(Monitor *mon, const QObject *data); void ioapic_set_irq(void *opaque, int vector, int level); void apic_reset_irq_delivered(void); int apic_get_irq_delivered(void); diff --git a/monitor.c b/monitor.c index c0dc48e..367e330 100644 --- a/monitor.c +++ b/monitor.c @@ -2625,6 +2625,14 @@ static const mon_cmd_t info_cmds[] = { .mhandler.info = do_info_roms, }, { + .name = "ioapic", + .args_type = "", + .params = "", + .help = "show ioapic config", + .user_print = monitor_print_ioapic, + .mhandler.info_new = do_info_ioapic, + }, + { .name = NULL, }, };