From patchwork Wed Mar 21 16:32:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 132239 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp2356522ljb; Wed, 21 Mar 2018 09:35:23 -0700 (PDT) X-Google-Smtp-Source: AG47ELvoKo/bUQbgBifctxHsjzRq7CqIMjIamgjPiw2UYzC9JX5Of9QUO4MHUo2ea9X+Mo0n73NZ X-Received: by 10.107.130.203 with SMTP id m72mr22410990ioi.250.1521650123536; Wed, 21 Mar 2018 09:35:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521650123; cv=none; d=google.com; s=arc-20160816; b=Hlazc78NjFUYqVIQBMKwkBbUdowrFQYAS5kMx6S1NRfLwo4lRZ98e+kK5NodiQ6/3k Tlm3VrfaUCrSmTzkXPsYxYcRCBwvtU1KkBRSUDlzMwjkjUHlxZEUtqOZi+saWRnhyimi jAjGJ/mH1VQEjmNtTJce4I0EHFVBUvpY5YlaUy/2SzZ9T8ohPO5+OD1HHxv+CB2YaiGj a7qoE7nZl4O8BMGKYgtQEI3D3U5nj5lUYvdesdSkwZsBubTbGcaXhit6g7Iv1hfWV5JW bWKHS6DgMx2fbVpA/egOmvdNwjqEsgKkFuJFb2/5hCGfL4J6+eXRKQCui051KR3TpeVl 2hHA== 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:cc :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=RFeWwYHnQZObvyrYbxCaUVohyyRN4449yreGlE5dSPA=; b=qO7EHHytP0AcbqwkZ1NLpHUf0Gw6RQpLSZpcm2t6agHeY6nUk0HKoK5CNncGbU0Ktj jyOK3xM/WOXgUatDAHT9JiILZpYAI7h4nMfP9feJ0EmCe+rQXC/KSXOyUP7VFFDmNkGb lRrlIg6rQo5L8hFzFigygudmy1UZNJU/yV5msRb2lQvQ9vlnuqeX6SGGu+BI6ucNES0V T/SytFbtAZKO6hY0qGiDGHhqL/j1OlsigPzcL16PX+4iVkMX+3zsE2iWy1IOGOq0FCqI zGy1jrklpRjWoUQXOPaLzivTRTNjrN7B57nKlYr37GEBWZvJL2INlM1D5TWNpATdB2+F Pl7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Dvya1XSS; 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 139-v6si2376523itm.75.2018.03.21.09.35.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Mar 2018 09:35:23 -0700 (PDT) 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=Dvya1XSS; 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.89) (envelope-from ) id 1eyggB-0003Lg-UN; Wed, 21 Mar 2018 16:33:35 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1eygg5-00036T-VL for xen-devel@lists.xenproject.org; Wed, 21 Mar 2018 16:33:29 +0000 X-Inumbo-ID: 8c2dd7fd-2d25-11e8-9728-bc764e045a96 Received: from mail-wr0-x242.google.com (unknown [2a00:1450:400c:c0c::242]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 8c2dd7fd-2d25-11e8-9728-bc764e045a96; Wed, 21 Mar 2018 17:33:13 +0100 (CET) Received: by mail-wr0-x242.google.com with SMTP id d10so5835920wrf.3 for ; Wed, 21 Mar 2018 09:33:27 -0700 (PDT) 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=Vd3VjBv1W13xGFAqTEYdXEqIi1Y4ZX4nKWZeH8PIfwI=; b=Dvya1XSSOSSBHCrhyRCRTcsXfWxsINJgT7Qs2yTdsVdToxrRT3HggPZsMxD/IG092W 83OcXbsk3LNFhR51W42x22tmAvlNss28L7xRv8BKOxeuOVG2Cnx9yL6/cglVV5o2YPH/ i1zoxI305wF7R7tyq5CY4kTRMh0kT74lvrPz4= 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=Vd3VjBv1W13xGFAqTEYdXEqIi1Y4ZX4nKWZeH8PIfwI=; b=sxF8Ndtq2yFcsPjduidPTMNHBlOrQZ3l+Rp/w+t1eN1wBqTlp5UiY2O1K7loPwbrbT g6NjCN7YF4EvZ5w3XCiuxDlS3fCREbrnNcz7AATT+kqO+PE0RpduFhhs2yyIePK+VD7P Qnb04DPDT4YQiCw58HqQkE1ni8PkJ6HHfCdFi9e/tpsb3Vd6ldIKhRQAecksFaZY8wNG aMX7RSBG0/dirCwV3J9xzT0CfKEkur77MsF2MSNh/U0vXj+hgcxaOybOA9PqWw6zrN6A DR1xhIDjItbalvSZyR+uptgXfkznb/2TilkfgJz3ns3Z29UTt9TsEpcR5GW5wbgW7Uwv PHAQ== X-Gm-Message-State: AElRT7HAt7oaK2EoaueM5pQR0mEWGdJM8nzHAot/7V9VEUw9dI5Rq3kE 7K2d0EX9Q1zVgrzKqRm7eDKiQg== X-Received: by 10.223.184.56 with SMTP id h53mr16632118wrf.87.1521650006508; Wed, 21 Mar 2018 09:33:26 -0700 (PDT) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id n64sm4423724wmd.11.2018.03.21.09.33.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Mar 2018 09:33:26 -0700 (PDT) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Wed, 21 Mar 2018 16:32:32 +0000 Message-Id: <20180321163235.12529-37-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180321163235.12529-1-andre.przywara@linaro.org> References: <20180321163235.12529-1-andre.przywara@linaro.org> Subject: [Xen-devel] [PATCH v3 36/39] ARM: new VGIC: vgic-init: implement vgic_init X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: xen-devel@lists.xenproject.org, Andre Przywara MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This patch allocates and initializes the data structures used to model the vgic distributor and virtual cpu interfaces. At that stage the number of IRQs and number of virtual CPUs is frozen. Implement the various functions that the Xen arch code is expecting to call during domain and VCPU setup to initialize the VGIC. Their prototypes are already in existing header files. This is based on Linux commit ad275b8bb1e6, written by Eric Auger. Signed-off-by: Andre Przywara Reviewed-by: Julien Grall Acked-by: Stefano Stabellini --- Changelog v2 ... v3: - move ROUNDUP(nr_spis) call before boundary check Changelog v1 ... v2: - remove stray kvm_ prefix in comment - use unsigned int - ROUNDUP number of SPIs - fix indentation xen/arch/arm/vgic/vgic-init.c | 201 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) diff --git a/xen/arch/arm/vgic/vgic-init.c b/xen/arch/arm/vgic/vgic-init.c index d091c92ed0..bfd3d09edb 100644 --- a/xen/arch/arm/vgic/vgic-init.c +++ b/xen/arch/arm/vgic/vgic-init.c @@ -15,11 +15,83 @@ * along with this program. If not, see . */ +#include #include #include #include "vgic.h" +/* + * Initialization rules: there are multiple stages to the vgic + * initialization, both for the distributor and the CPU interfaces. The basic + * idea is that even though the VGIC is not functional or not requested from + * user space, the critical path of the run loop can still call VGIC functions + * that just won't do anything, without them having to check additional + * initialization flags to ensure they don't look at uninitialized data + * structures. + * + * Distributor: + * + * - vgic_early_init(): initialization of static data that doesn't + * depend on any sizing information or emulation type. No allocation + * is allowed there. + * + * - vgic_init(): allocation and initialization of the generic data + * structures that depend on sizing information (number of CPUs, + * number of interrupts). Also initializes the vcpu specific data + * structures. Can be executed lazily for GICv2. + * + * CPU Interface: + * + * - vgic_vcpu_early_init(): initialization of static data that + * doesn't depend on any sizing information or emulation type. No + * allocation is allowed there. + */ + +/** + * vgic_vcpu_early_init() - Initialize static VGIC VCPU data structures + * @vcpu: The VCPU whose VGIC data structures whould be initialized + * + * Only do initialization, but do not actually enable the VGIC CPU interface + * yet. + */ +static void vgic_vcpu_early_init(struct vcpu *vcpu) +{ + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic; + unsigned int i; + + INIT_LIST_HEAD(&vgic_cpu->ap_list_head); + spin_lock_init(&vgic_cpu->ap_list_lock); + + /* + * Enable and configure all SGIs to be edge-triggered and + * configure all PPIs as level-triggered. + */ + for ( i = 0; i < VGIC_NR_PRIVATE_IRQS; i++ ) + { + struct vgic_irq *irq = &vgic_cpu->private_irqs[i]; + + INIT_LIST_HEAD(&irq->ap_list); + spin_lock_init(&irq->irq_lock); + irq->intid = i; + irq->vcpu = NULL; + irq->target_vcpu = vcpu; + irq->targets = 1U << vcpu->vcpu_id; + atomic_set(&irq->refcount, 0); + if ( vgic_irq_is_sgi(i) ) + { + /* SGIs */ + irq->enabled = 1; + irq->config = VGIC_CONFIG_EDGE; + } + else + { + /* PPIs */ + irq->config = VGIC_CONFIG_LEVEL; + } + } +} + /* CREATION */ /** @@ -50,6 +122,135 @@ int domain_vgic_register(struct domain *d, int *mmio_count) return 0; } +/* INIT/DESTROY */ + +/** + * domain_vgic_init: initialize the dist data structures + * @d: domain pointer + * @nr_spis: number of SPIs + */ +int domain_vgic_init(struct domain *d, unsigned int nr_spis) +{ + struct vgic_dist *dist = &d->arch.vgic; + unsigned int i; + int ret; + + /* The number of SPIs must be a multiple of 32 per the GIC spec. */ + nr_spis = ROUNDUP(nr_spis, 32); + + /* Limit the number of virtual SPIs supported to (1020 - 32) = 988 */ + if ( nr_spis > (1020 - NR_LOCAL_IRQS) ) + return -EINVAL; + + dist->nr_spis = nr_spis; + dist->spis = xzalloc_array(struct vgic_irq, nr_spis); + if ( !dist->spis ) + return -ENOMEM; + + /* + * In the following code we do not take the irq struct lock since + * no other action on irq structs can happen while the VGIC is + * not initialized yet: + * If someone wants to inject an interrupt or does a MMIO access, we + * require prior initialization in case of a virtual GICv3 or trigger + * initialization when using a virtual GICv2. + */ + for ( i = 0; i < nr_spis; i++ ) + { + struct vgic_irq *irq = &dist->spis[i]; + + irq->intid = i + VGIC_NR_PRIVATE_IRQS; + INIT_LIST_HEAD(&irq->ap_list); + spin_lock_init(&irq->irq_lock); + irq->vcpu = NULL; + irq->target_vcpu = NULL; + atomic_set(&irq->refcount, 0); + if ( dist->version == GIC_V2 ) + irq->targets = 0; + else + irq->mpidr = 0; + } + + INIT_LIST_HEAD(&dist->lpi_list_head); + spin_lock_init(&dist->lpi_list_lock); + + if ( dist->version == GIC_V2 ) + ret = vgic_v2_map_resources(d); + else + ret = -ENXIO; + + if ( ret ) + return ret; + + /* allocated_irqs() is used by Xen to find available vIRQs */ + d->arch.vgic.allocated_irqs = + xzalloc_array(unsigned long, BITS_TO_LONGS(vgic_num_irqs(d))); + if ( !d->arch.vgic.allocated_irqs ) + return -ENOMEM; + + /* vIRQ0-15 (SGIs) are reserved */ + for ( i = 0; i < NR_GIC_SGI; i++ ) + set_bit(i, d->arch.vgic.allocated_irqs); + + return 0; +} + +/** + * vcpu_vgic_init() - Register VCPU-specific KVM iodevs + * was: kvm_vgic_vcpu_init() + * Xen: adding vgic_vx_enable() call + * @vcpu: pointer to the VCPU being created and initialized + */ +int vcpu_vgic_init(struct vcpu *vcpu) +{ + int ret = 0; + + vgic_vcpu_early_init(vcpu); + + if ( gic_hw_version() == GIC_V2 ) + vgic_v2_enable(vcpu); + else + ret = -ENXIO; + + return ret; +} + +void domain_vgic_free(struct domain *d) +{ + struct vgic_dist *dist = &d->arch.vgic; + int i, ret; + + for ( i = 0; i < dist->nr_spis; i++ ) + { + struct vgic_irq *irq = vgic_get_irq(d, NULL, 32 + i); + + if ( !irq->hw ) + continue; + + ret = release_guest_irq(d, irq->hwintid); + if ( ret ) + dprintk(XENLOG_G_WARNING, + "d%u: Failed to release virq %u ret = %d\n", + d->domain_id, 32 + i, ret); + } + + dist->ready = false; + dist->initialized = false; + + xfree(dist->spis); + xfree(dist->allocated_irqs); + dist->nr_spis = 0; +} + +int vcpu_vgic_free(struct vcpu *vcpu) +{ + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic; + + INIT_LIST_HEAD(&vgic_cpu->ap_list_head); + + return 0; +} + /* * Local variables: * mode: C