From patchwork Mon Mar 5 16:03:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 130660 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp2853626lja; Mon, 5 Mar 2018 08:07:02 -0800 (PST) X-Google-Smtp-Source: AG47ELsv8PHBAH0iEjHFacheCtKROxlU+MxMDA4BN3ID4fsoPM2CVRteB24vpNYkiF9A4OIaGIso X-Received: by 10.36.71.68 with SMTP id t65mr14756138itb.88.1520266022685; Mon, 05 Mar 2018 08:07:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520266022; cv=none; d=google.com; s=arc-20160816; b=iJ0kAqmrWG66o1I3ZpJATMpBtB+fk7/6I4Xg2H1YIs1mBczLXoSpazG1DBlD9MrtZV YMaW5RWjRmrfJGVlMiQTABkpN/ht5jtLfJQ4Ypgv0VQOID9mO6OoJ3/Akd6rHFb3RKi8 +txI3pj8PXSqUuKlhRXSv51ptZNtPjC+iwGpSUmzSxC9IK/xzLhXodvvsxq8jsF0CUhm qJLyteotmjcS2DIj79KVtvDn6LzrL5jpWVclPdJYLzWg/Ja9WuDj0c87OL1bu35OltD5 iLrBPaXT9YkgQ1F34exYwG+tZam42eKyybnW3C/ztC39+/edQD3FIeKrgYWq9eSlN54c 3kvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=v4MzLef74sNC5rBQc3FyGvmVuFKk7GmDIhnpOXsdz08=; b=oVKdI6p2hSgx3Vwm3UTU9uQfYMPOcUZwBJx+uRQGYEDKizBcdV0Ee4mUA0QPTj4vuF rSiYqk31EkJWcbLGObbaQm4/2IZ85cZ+naChi+AyESJKXoiVS/ee1TBh8seUZCADzHOQ O3MlJw7zdZBm3uWpaVhKB5J/Ae2CdLdYzx6meJ3rswHnR5MhCONmrTqEaOkVP64OP0Ji CHPpMHbL051Sq1ErGkGrxoXS7mVJ6Yq+J2P0QIfENuPeyTzasCsd+kynsx1sMkfhvQpQ FL4714SepGsEMePS+euZ6XaAsdH66x+kiYPYSfLoSRcC4krvs96RWHzXsHejHp/2rNFW V5dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KLxStyjQ; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id x5si5917654itg.162.2018.03.05.08.07.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Mar 2018 08:07:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KLxStyjQ; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1essbn-0008IN-7p; Mon, 05 Mar 2018 16:05:03 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1essbl-0008Dv-NV for xen-devel@lists.xenproject.org; Mon, 05 Mar 2018 16:05:01 +0000 X-Inumbo-ID: cd76e7b3-208e-11e8-ba59-bc764e045a96 Received: from mail-wr0-x242.google.com (unknown [2a00:1450:400c:c0c::242]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id cd76e7b3-208e-11e8-ba59-bc764e045a96; Mon, 05 Mar 2018 17:03:54 +0100 (CET) Received: by mail-wr0-x242.google.com with SMTP id v18so17184802wrv.0 for ; Mon, 05 Mar 2018 08:05:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5qsL0uhpwbjeVrZ9xeFHiFqNlNmS28Fur0CQo/2i9Ck=; b=KLxStyjQ0h4Ma2yXe+iHLxAY9ss50FCnKWN/Q1HspsH5muTSNYTWj8mR1PE/rbGEGz 8YSr83L36/UPiSvwzEef6eO+bCFAVbnYoGa5mpUhnWbytprrIVztHucaSd5h4jnpGyJV CWzsqAlHa+TfoOgMdwTm3oC1pqwAVvAKtWFO4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5qsL0uhpwbjeVrZ9xeFHiFqNlNmS28Fur0CQo/2i9Ck=; b=sknYsZ96hMCVcoV2JssGih3k7VLlNuS9UC8nZBekcILoClulHoGazBfoFbxiV+9I3j vrG+TmMs959PFpDdawR/kNiD0wUz6JZxp5jHCvZqGNoSnFKpsIsowRhGmhTt+LXPd8jA Pjhwpk0x17RgGWr0mBOZFzJ2NcxAKztW93GJLsUVj9/fp8NtK5F9PAWryDY4nOaV6Nmg QKRmnntX3GajZ50ut8SBEnF0exTUKziS8ZLNjmePL7L8clnYlBySxcF0oVurJUKeFeT9 wG/oW6Qb29hm3KwdpxAvUxjUkhExsY+tnbft0y0fM5TFaeaUGAVVJoecpBhdP02Uvy7r xH6g== X-Gm-Message-State: APf1xPC/LugWXEzlusYs/O6w44NNkDiIfTnb0EgBV+iAnlX9sM4WWCPo m7fKf4gut6CerY65VE+Y2L3seg== X-Received: by 10.223.156.208 with SMTP id h16mr14045527wre.123.1520265899130; Mon, 05 Mar 2018 08:04:59 -0800 (PST) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id y6sm6574381wmy.14.2018.03.05.08.04.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Mar 2018 08:04:58 -0800 (PST) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Mon, 5 Mar 2018 16:03:54 +0000 Message-Id: <20180305160415.16760-37-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180305160415.16760-1-andre.przywara@linaro.org> References: <20180305160415.16760-1-andre.przywara@linaro.org> Cc: xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH 36/57] ARM: new VGIC: Add CTLR, TYPER and IIDR handlers X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Those three registers are v2 emulation specific, so their implementation lives entirely in vgic-mmio-v2.c. Also they are handled in one function, as their implementation is pretty simple. When the guest enables the distributor, we kick all VCPUs to get potentially pending interrupts serviced. This is based on Linux commit 2b0cda878965, written by Marc Zyngier. Signed-off-by: Andre Przywara --- Changelog RFC ... v1: - use PRODUCT_ID_XEN - use proper locking on enabling VGIC - use kick_vcpu() xen/arch/arm/vgic/vgic-mmio-v2.c | 54 +++++++++++++++++++++++++++++++++++++++- xen/arch/arm/vgic/vgic.c | 15 +++++++++++ xen/arch/arm/vgic/vgic.h | 4 +++ 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/vgic/vgic-mmio-v2.c b/xen/arch/arm/vgic/vgic-mmio-v2.c index 6f10cf16ca..2e015ed0b1 100644 --- a/xen/arch/arm/vgic/vgic-mmio-v2.c +++ b/xen/arch/arm/vgic/vgic-mmio-v2.c @@ -20,9 +20,61 @@ #include "vgic.h" #include "vgic-mmio.h" +static unsigned long vgic_mmio_read_v2_misc(struct vcpu *vcpu, + paddr_t addr, unsigned int len) +{ + uint32_t value; + + switch ( addr & 0x0c ) /* filter for the 4 registers handled here */ + { + case GICD_CTLR: + value = vcpu->domain->arch.vgic.enabled ? GICD_CTL_ENABLE : 0; + break; + case GICD_TYPER: + value = vcpu->domain->arch.vgic.nr_spis + VGIC_NR_PRIVATE_IRQS; + value = (value >> 5) - 1; + value |= (vcpu->domain->max_vcpus - 1) << 5; + break; + case GICD_IIDR: + value = (PRODUCT_ID_XEN << 24) | (IMPLEMENTER_ARM << 0); + break; + default: + return 0; + } + + return value; +} + +static void vgic_mmio_write_v2_misc(struct vcpu *vcpu, + paddr_t addr, unsigned int len, + unsigned long val) +{ + struct vgic_dist *dist = &vcpu->domain->arch.vgic; + bool enabled; + + switch ( addr & 0x0c ) /* filter for the 4 registers handled here */ + { + case GICD_CTLR: + domain_lock(vcpu->domain); + enabled = dist->enabled; + dist->enabled = val & GICD_CTL_ENABLE; + enabled = !enabled && dist->enabled; + domain_unlock(vcpu->domain); + + if (enabled) + vgic_kick_vcpus(vcpu->domain); + + break; + case GICD_TYPER: + case GICD_IIDR: + /* read-only, writes ignored */ + return; + } +} + static const struct vgic_register_region vgic_v2_dist_registers[] = { REGISTER_DESC_WITH_LENGTH(GICD_CTLR, - vgic_mmio_read_raz, vgic_mmio_write_wi, 12, + vgic_mmio_read_v2_misc, vgic_mmio_write_v2_misc, 12, VGIC_ACCESS_32bit), REGISTER_DESC_WITH_BITS_PER_IRQ(GICD_IGROUPR, vgic_mmio_read_rao, vgic_mmio_write_wi, 1, diff --git a/xen/arch/arm/vgic/vgic.c b/xen/arch/arm/vgic/vgic.c index 66a366176a..465a95f415 100644 --- a/xen/arch/arm/vgic/vgic.c +++ b/xen/arch/arm/vgic/vgic.c @@ -683,6 +683,21 @@ int vgic_pending_irq(void) return vgic_vcpu_pending_irq(current); } +void vgic_kick_vcpus(struct domain *d) +{ + struct vcpu *vcpu; + + /* + * We've injected an interrupt, time to find out who deserves + * a good kick... + */ + for_each_vcpu( d, vcpu ) + { + if ( vgic_vcpu_pending_irq(vcpu) ) + kick_vcpu(vcpu); + } +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/vgic/vgic.h b/xen/arch/arm/vgic/vgic.h index 632b246e93..588bd067b7 100644 --- a/xen/arch/arm/vgic/vgic.h +++ b/xen/arch/arm/vgic/vgic.h @@ -17,6 +17,9 @@ #ifndef __XEN_ARM_VGIC_VGIC_H__ #define __XEN_ARM_VGIC_VGIC_H__ +#define PRODUCT_ID_XEN 0x58 /* ASCII code X */ +#define IMPLEMENTER_ARM 0x43b + #define vgic_irq_is_sgi(intid) ((intid) < VGIC_NR_SGIS) static inline bool irq_is_pending(struct vgic_irq *irq) @@ -37,6 +40,7 @@ struct vgic_irq *vgic_get_irq(struct domain *d, struct vcpu *vcpu, void vgic_put_irq(struct domain *d, struct vgic_irq *irq); void vgic_queue_irq_unlock(struct domain *d, struct vgic_irq *irq, unsigned long flags); +void vgic_kick_vcpus(struct domain *d); static inline void vgic_get_irq_kref(struct vgic_irq *irq) {