From patchwork Fri Feb 9 14:39:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 127840 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp679834ljc; Fri, 9 Feb 2018 06:42:12 -0800 (PST) X-Google-Smtp-Source: AH8x226nS0tz6/Av3yupzta/DdjBzg70jyscPsocohkM9cXVlOhpYEIgL4aNcVh3/GkoRMnlY95c X-Received: by 10.36.181.93 with SMTP id j29mr3587650iti.99.1518187332505; Fri, 09 Feb 2018 06:42:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518187332; cv=none; d=google.com; s=arc-20160816; b=bxiQSPZRNih83CCkPhWkolYcWuVukNEon3THl019FxXql67zFmPP174R3q8RYP7ESk 4ym12r3LF2s7qpPWh/KuywvUpubssgc4Rrjd5rTBEBm4zTj4HEkSGT4OS9aDbulPfBqP 3UcsFLuiHirzaofdUnma3Vnej6Vstur3YhyiMIBd6mBL34iPlHLRZiyUZ65EWKsr4Ve1 ygsmypCcL45x4/Ee4BBLtVwcIbWYSXqJj3NMNJ3307ftoHq8NZDEvIILsOihdNPo47WW R5VeWl4Lpd8r7rF/wvEvw1WUBU16RKGl3XhbDacQJg9a9sK5NN100yoaJ+dhJjRbpqKX JBqg== 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:references:in-reply-to:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=zHjwfdeAB/o0eM/tQpKj/eiHT7/zgqbgFsRBFrOcAS4=; b=HYjiLprH+0CAu+lwrH1p8iQCEB0emdP3c25VUcai0p8PJQK62poOhS23+AWAw5D51d Q4qdA3me+YESQ69l/QA4bUqZkk/jWhPHkp4OElK4GyAwF0iH6Ml7hvI81UnlHwotluL2 ytGUL4gbxOXkPOwbbOpLEXmB3KpwqHx3P11spzBxrLy5sHUoVKRhhxE8O4VLa5/oOE/Y mHg+A5ZZvdBLw7SknzuxBSvsMBABJfCexiBk60ktOrepkigqNFkK+jb9ctZf3kV+d2fX botMoIwAUc3wUTIdeExwnPDZj0gYDBEfj6SK5Dyl6Pyx0KPN5uAYh4gjWaZI109CA+GH omRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Nbv9Log0; 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 r22si1623519iod.154.2018.02.09.06.42.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Feb 2018 06:42:12 -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=Nbv9Log0; 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 1ek9qc-00011F-Iz; Fri, 09 Feb 2018 14:40:18 +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 1ek9qb-0000yG-KS for xen-devel@lists.xenproject.org; Fri, 09 Feb 2018 14:40:17 +0000 X-Inumbo-ID: 13f46fb8-0da7-11e8-ba59-bc764e045a96 Received: from mail-wr0-x241.google.com (unknown [2a00:1450:400c:c0c::241]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 13f46fb8-0da7-11e8-ba59-bc764e045a96; Fri, 09 Feb 2018 15:39:48 +0100 (CET) Received: by mail-wr0-x241.google.com with SMTP id v65so1678776wrc.11 for ; Fri, 09 Feb 2018 06:40:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=EaguL9bdyPHtckpUHr5KVKvWPfGvs7Xp78K73WQjarE=; b=Nbv9Log0ay4V0lb4tELJAc7LToQgfFS+FOoRIzGDwmpn6dMDg9VhKa1IcSS3qqtL0t rojd3zNnVblG9qAeUP3kXuLquB24WUZky6wCREuBXRd0RH6G7MpIV8jRYa65lThL8bQ3 QlmbUDoabcs1pAljHEvLowotImwqoVGsuycaw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=EaguL9bdyPHtckpUHr5KVKvWPfGvs7Xp78K73WQjarE=; b=rqspc4eDpkwNiBZcpg+njffWUYejb6jDeSOosiPR+0PCMnW90tgIl3V1AScrksyw04 nNKnAvcnKgL85PNxxInXwdkxtRuRVl3gDAn2RhkMCTnxCociRWu7U62UgGfwFuNj8xtc TeALDfMQtkSptuEVjaKKnymsUGm7+x9WW9zNvFdr0++QjOH2LwGQGWcgo/oHR/ou406z K3TKQNiIUiEYSdqnKiCsHeOYMzooAhzBpVWbSxkFmKG4O3fSmzqNvbJ/5dGeoYPyNH3c kuMqxsjilDymB7XI0+Qz/BI+vib0z41kPZ9ptaLd/R9KGvQ434KNotQ3/WtkSoxIMEtf xmYg== X-Gm-Message-State: APf1xPAMxySvIPvJ4CEn8iF/aKF2IwajtsHl1xQzCoLLcCBKIS1u/Rdc 4DoFNmw42qtolqK1rS8RCyNwFw== X-Received: by 10.223.163.6 with SMTP id c6mr2877822wrb.265.1518187215826; Fri, 09 Feb 2018 06:40:15 -0800 (PST) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id b35sm2552229wra.13.2018.02.09.06.40.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Feb 2018 06:40:15 -0800 (PST) From: Andre Przywara To: Stefano Stabellini , Julien Grall , xen-devel@lists.xenproject.org Date: Fri, 9 Feb 2018 14:39:17 +0000 Message-Id: <20180209143937.28866-30-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180209143937.28866-1-andre.przywara@linaro.org> References: <20180209143937.28866-1-andre.przywara@linaro.org> Subject: [Xen-devel] [RFC PATCH 29/49] 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 --- xen/arch/arm/vgic/vgic-mmio-v2.c | 48 +++++++++++++++++++++++++++++++++++++++- xen/arch/arm/vgic/vgic.c | 15 +++++++++++++ xen/arch/arm/vgic/vgic.h | 4 ++++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/vgic/vgic-mmio-v2.c b/xen/arch/arm/vgic/vgic-mmio-v2.c index ee685a5a07..0926b3243e 100644 --- a/xen/arch/arm/vgic/vgic-mmio-v2.c +++ b/xen/arch/arm/vgic/vgic-mmio-v2.c @@ -20,9 +20,55 @@ #include "vgic.h" #include "vgic-mmio.h" +static unsigned long vgic_mmio_read_v2_misc(struct vcpu *vcpu, + paddr_t addr, unsigned int len) +{ + u32 value; + + switch (addr & 0x0c) + { + 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_KVM << 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 was_enabled = dist->enabled; + + switch (addr & 0x0c) + { + case GICD_CTLR: + dist->enabled = val & GICD_CTL_ENABLE; + if ( !was_enabled && dist->enabled ) + vgic_kick_vcpus(vcpu->domain); + break; + case GICD_TYPER: + case GICD_IIDR: + /* Nothing to do */ + 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, NULL, NULL, 1, diff --git a/xen/arch/arm/vgic/vgic.c b/xen/arch/arm/vgic/vgic.c index 9e7fb1edcb..dc5e011fa3 100644 --- a/xen/arch/arm/vgic/vgic.c +++ b/xen/arch/arm/vgic/vgic.c @@ -678,6 +678,21 @@ int gic_events_need_delivery(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) ) + vcpu_unblock(vcpu); + } +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/vgic/vgic.h b/xen/arch/arm/vgic/vgic.h index 7747d3f3e0..82fe902e26 100644 --- a/xen/arch/arm/vgic/vgic.h +++ b/xen/arch/arm/vgic/vgic.h @@ -17,6 +17,9 @@ #ifndef __XEN_ARM_VGIC_NEW_H__ #define __XEN_ARM_VGIC_NEW_H__ +#define PRODUCT_ID_KVM 0x4b /* ASCII code K */ +#define IMPLEMENTER_ARM 0x43b + #define vgic_irq_is_sgi(intid) ((intid) < VGIC_NR_SGIS) static inline bool irq_is_pending(struct vgic_irq *irq) @@ -36,6 +39,7 @@ struct vgic_irq *vgic_get_irq(struct domain *d, struct vcpu *vcpu, void vgic_put_irq(struct domain *d, struct vgic_irq *irq); bool 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) {