From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53891) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnwNS-00011L-Tz for qemu-devel@nongnu.org; Thu, 30 Apr 2015 17:52:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnwNR-0002hP-Ec for qemu-devel@nongnu.org; Thu, 30 Apr 2015 17:52:14 -0400 Received: from mail-pd0-x22f.google.com ([2607:f8b0:400e:c02::22f]:33601) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnwNR-0002hL-8A for qemu-devel@nongnu.org; Thu, 30 Apr 2015 17:52:13 -0400 Received: by pdbnk13 with SMTP id nk13so73278949pdb.0 for ; Thu, 30 Apr 2015 14:52:12 -0700 (PDT) From: James Sullivan Date: Thu, 30 Apr 2015 15:49:13 -0600 Message-Id: <1430430556-21869-2-git-send-email-sullivan.james.f@gmail.com> In-Reply-To: <1430430556-21869-1-git-send-email-sullivan.james.f@gmail.com> References: <1430430556-21869-1-git-send-email-sullivan.james.f@gmail.com> Subject: [Qemu-devel] [PATCH v3 1/4] apic: Implement LAPIC low priority arbitration functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, James Sullivan , jan.kiszka@siemens.com Currently, apic_get_arb_pri() is unimplemented and returns 0. Implemented apic_get_arb_pri() and added helper function apic_compare_prio() to be used for LAPIC arbitration. Signed-off-by: James Sullivan --- Changes in v3: * Fixed apic_get_arb_pri to use AMD's algorithm vs. Intel's (incorrect?) algorithm * Removed apic_lowest_prio() in favour of arbitration while setting up the delivery bitmask (added in 4/4) hw/intc/apic.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/hw/intc/apic.c b/hw/intc/apic.c index 0f97b47..8f6cdd2 100644 --- a/hw/intc/apic.c +++ b/hw/intc/apic.c @@ -38,6 +38,7 @@ static void apic_set_irq(APICCommonState *s, int vector_num, int trigger_mode); static void apic_update_irq(APICCommonState *s); static void apic_get_delivery_bitmask(uint32_t *deliver_bitmask, uint8_t dest, uint8_t dest_mode); +static int apic_get_arb_pri(APICCommonState *s); /* Find first bit starting from msb */ static int apic_fls_bit(uint32_t value) @@ -217,6 +218,12 @@ static void apic_external_nmi(APICCommonState *s) }\ } +static int apic_compare_prio(struct APICCommonState *cpu1, + struct APICCommonState *cpu2) +{ + return apic_get_arb_pri(cpu1) - apic_get_arb_pri(cpu2); +} + static void apic_bus_deliver(const uint32_t *deliver_bitmask, uint8_t delivery_mode, uint8_t vector_num, uint8_t trigger_mode) @@ -336,8 +343,27 @@ static int apic_get_ppr(APICCommonState *s) static int apic_get_arb_pri(APICCommonState *s) { - /* XXX: arbitration */ - return 0; + int tpr, isrv, irrv, apr; + + tpr = apic_get_tpr(s); + isrv = get_highest_priority_int(s->isr); + if (isrv < 0) { + isrv = 0; + } + isrv >>= 4; + irrv = get_highest_priority_int(s->irr); + if (irrv < 0) { + irrv = 0; + } + irrv >>= 4; + + if ((tpr >= irrv) && (tpr > isrv)) { + apr = s->tpr & 0xff; + } else { + apr = (isrv > irrv) ? isrv : irrv; + apr <<= 4; + } + return apr; } -- 2.3.5