From patchwork Thu Mar 15 20:30:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 131849 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp1579237ljb; Thu, 15 Mar 2018 13:33:22 -0700 (PDT) X-Google-Smtp-Source: AG47ELur4WRPztVbTDQU+eexvyPLrtXPfpfi1pwmwj4g9Usky+L2j8o//Q6rBsz3TfBAOnnE0IPQ X-Received: by 10.36.141.130 with SMTP id w124mr4877094itd.100.1521146001993; Thu, 15 Mar 2018 13:33:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521146001; cv=none; d=google.com; s=arc-20160816; b=MJBnO4J0q9UHucQ0IOz9n3ZQaV82DzEAV5QbJhUTaQULuFfXf1bVtOQkTWB4hhmD6n JpoIVJDU1eFq/tZdmNI9xtXgn/3LKLT6OwtwkzcZtSkOZhliYOoKLNcQqZPsJqcytHtM u80tGmre2NpPRImQkQd+qlrtBHtXXUwAByqs/BGYJI/qT5jXP//nF6GwhD6uxpjmDH5S Jivpbx7J73EHFKqIyszJNvs9XTG7pdzB475foQoUv748a6bc0VcfykocCbpXy7vdCxXg WYd4lWRkWdaawhs5PZfqq8Kb19Rk1cpN96mXKZuSg9ZJWNmURP5WktbjBpznukKkj78a nB3Q== 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=11qY1FpGc3fkSy70OSozQImf6M0VFw/E/gfZY6UYHIg=; b=xc5PwwhMlyodszMtNuoD12qOidEkdHfzqUK6VxLXd7shm03cXfoZSFxvdUlUiVHwe+ wA84kQUPMJnzCJhuMP8g42r4l2bIfyk6f9BOCa5LPDJo0svh7HSxuq8/rjtP+npkUV3G dNQlGdtZZ3iY0j07k04ubNNKmuEwGdUuV58adntrQk7TweIRXqT6ygtP/xx+okWnaBae vEGnE2IffSM6drXJ/LAw7m7O6T9YI2tUsbxw1I+bOo4ZvI+dCnjHg4V1dOgemMveMBre iy4ROq70BIHMhNbQHJCNfgGSxDyX6hMTFFxtdY2Z/yPwJBWkOCuPj6lY9RnfaoUAjLML xGMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fSkbasH/; 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 v205si3694615iod.219.2018.03.15.13.33.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Mar 2018 13:33:21 -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=fSkbasH/; 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 1ewZXY-0004kV-Th; Thu, 15 Mar 2018 20:31:56 +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 1ewZXX-0004fO-F5 for xen-devel@lists.xenproject.org; Thu, 15 Mar 2018 20:31:55 +0000 X-Inumbo-ID: e23ec657-288f-11e8-9728-bc764e045a96 Received: from mail-wm0-x244.google.com (unknown [2a00:1450:400c:c09::244]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id e23ec657-288f-11e8-9728-bc764e045a96; Thu, 15 Mar 2018 21:31:48 +0100 (CET) Received: by mail-wm0-x244.google.com with SMTP id e194so12785835wmd.3 for ; Thu, 15 Mar 2018 13:31:53 -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=4WiOOBx6sAxW3le5aoBDLC3I+hMHS+5LeNJeJAXCm/0=; b=fSkbasH/gD5L6BG1lGz2enVLUeHZESuoPghCv5Vm4OImJ6mTYpLaZc8AhkfRDUNOFc eGp2Jqf++3l5F/TeJEEOws9+n11vMI1f53c4GSWFkLGhOTVn1bpGS5eRKyDJ6tqeCBeb CpKrEeIM0oBzTit3wQoGH3HK1Ea4g0C6T5Uy4= 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=4WiOOBx6sAxW3le5aoBDLC3I+hMHS+5LeNJeJAXCm/0=; b=lt65uS6rZwvx+vEYHC5ClQUivwmWBWrETBBPIuYBPrRLUitW9oI9nrfn83zDjxgi1r zmK4hMLm+JL5TaWIGrLXDniKDQknn3A6M2F5NYzXAzQ2NrW9Cy+C0R8WtxOlKryDEvPJ XiLwUiqHGjHYuBVWzppXFaN2ucG2zX5tGxU0oWCqBKP5E0LvVH1aVkCqCeHI2KvXoES6 BNAsBHkPVZ8J/Cc5nGSy0/+c8wJLOaBj0ZhPuQIMcXulTI6Z/mMbLiLusV95kIw6GZwl Ro7JZrTfwv3olPmPQXXllAGVKrxxc+00mZ6+u6NeS1xg/du/9fpdAPJFpkq5/NZtDGnI jKng== X-Gm-Message-State: AElRT7HBHbcqmi1ueGSSvVf23EsbLGRHZzpBIXDn1WpdE8inNu3fH0lX HoCYScK7jaouCFDWQov09/gX6A== X-Received: by 10.28.9.81 with SMTP id 78mr5682936wmj.61.1521145912593; Thu, 15 Mar 2018 13:31:52 -0700 (PDT) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id w125sm3217102wmw.20.2018.03.15.13.31.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Mar 2018 13:31:52 -0700 (PDT) From: Andre Przywara To: Stefano Stabellini , Julien Grall Date: Thu, 15 Mar 2018 20:30:47 +0000 Message-Id: <20180315203050.19791-43-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180315203050.19791-1-andre.przywara@linaro.org> References: <20180315203050.19791-1-andre.przywara@linaro.org> Cc: xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH v2 42/45] ARM: new VGIC: vgic-init: implement vgic_init 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" 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 --- 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 | 199 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/xen/arch/arm/vgic/vgic-init.c b/xen/arch/arm/vgic/vgic-init.c index d091c92ed0..d7695d69bf 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,133 @@ 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; + + /* Limit the number of virtual SPIs supported to (1020 - 32) = 988 */ + if ( nr_spis > (1020 - NR_LOCAL_IRQS) ) + return -EINVAL; + nr_spis = ROUNDUP(nr_spis, 32); + + 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