From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53917) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnwNU-00013q-Nc for qemu-devel@nongnu.org; Thu, 30 Apr 2015 17:52:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnwNT-0002i2-IA for qemu-devel@nongnu.org; Thu, 30 Apr 2015 17:52:16 -0400 Received: from mail-pa0-x235.google.com ([2607:f8b0:400e:c03::235]:33187) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnwNT-0002hw-Bu for qemu-devel@nongnu.org; Thu, 30 Apr 2015 17:52:15 -0400 Received: by pacwv17 with SMTP id wv17so72210005pac.0 for ; Thu, 30 Apr 2015 14:52:14 -0700 (PDT) From: James Sullivan Date: Thu, 30 Apr 2015 15:49:15 -0600 Message-Id: <1430430556-21869-4-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 3/4] apic: Add helper functions apic_match_dest, apic_match_[physical, logical]_dest 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 Added three helper functions apic_match_dest(), apic_match_physical_dest(), and apic_match_logical_dest() which can be used to determine if a logical or physical APIC ID match a given LAPIC under a given dest_mode. This does not account for shorthand. Signed-off-by: James Sullivan --- hw/intc/apic.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hw/intc/apic.c b/hw/intc/apic.c index a25efa1..9dd27b2 100644 --- a/hw/intc/apic.c +++ b/hw/intc/apic.c @@ -224,6 +224,32 @@ static int apic_compare_prio(struct APICCommonState *cpu1, return apic_get_arb_pri(cpu1) - apic_get_arb_pri(cpu2); } +static bool apic_match_physical_dest(struct APICCommonState *apic, uint8_t dest) +{ + return (dest == 0xff || apic->id == dest); +} + +static bool apic_match_logical_dest(struct APICCommonState *apic, uint8_t dest) +{ + if (apic->dest_mode == 0xf) { + return (dest & apic->log_dest) > 0; + } else if (apic->dest_mode == 0) { + return ((dest & 0xf0) == (apic->log_dest & 0xf0)) && + (dest & apic->log_dest & 0x0f) > 0; + } + return false; +} + +static bool apic_match_dest(struct APICCommonState *apic, uint8_t dest_mode, + uint8_t dest) +{ + if (dest_mode == 0) { + return apic_match_physical_dest(apic, dest); + } else { + return apic_match_logical_dest(apic, dest); + } +} + static void apic_bus_deliver(const uint32_t *deliver_bitmask, uint8_t delivery_mode, uint8_t vector_num, uint8_t trigger_mode) -- 2.3.5