From patchwork Fri Feb 9 14:39:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 127852 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp680061ljc; Fri, 9 Feb 2018 06:42:28 -0800 (PST) X-Google-Smtp-Source: AH8x226SSlOp4p4E35arV/CJNtcPUIDNjwbFCkBZ+8PfVNoQOIpkw0Q335MitpAn+rwkBbSzWWlw X-Received: by 10.36.236.134 with SMTP id g128mr3810840ith.38.1518187348464; Fri, 09 Feb 2018 06:42:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518187348; cv=none; d=google.com; s=arc-20160816; b=vMbyiRvSgpWPss6aV0j/piRkArASXgOZR5KGbw+ILjMnsotZeCVAi8w886KgLWP5qf La5iAMS5EZkQBaftGdQZk0tW55ABztCRX+MPPofilbzA1FAsVVV0dSJi307G0mpnhLGD uxVUoyV+w1BVzTH8UxA0R/d+eQ6U2yfex4CVL1OovwK8WqLl2v7B+Hu2mJr/xKBr+C7s wBMrv7iUYfpEbkIWOK0OSJ6zNhCDWU22jrzOzYURFTst8vq3ODYV0ENz5A2+U7aPYjNV bByzB/pMztL7b9xYqolCPKUQjkU/5HPwRsx1Nb7foBdzLTneYqx24TEnJJM6ED6lnoUf zz0A== 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=Qi1cz9NUkTTWt+1SptHS7AwCrSvIE/SZTnhNDsAVuic=; b=iw87j8gQpFLKeqF08LBA1q6kbI36IQXM5MelpeEZcmmvFv9mD9tfKa6xIrGxt46Wzq GKSNKQHrMrDRs1o4FrM1Q7WMidGTf3neJWQ5v5KPGLq+H7s8tX59p2ApiCoGaLFDnE6g dRV9on8quJXmiUOaNtJ5nLUBpYSrscx+/dIoo36k77BA7j0P4cHIEL1J24mQ5TG23ep7 dIt1YS3t24iSK09ayotbFWmHFv8f+nVOSgfmJl3tj3GNcpzUQLupQLgpv+4unSF9cf22 BQ0tsHavaLx/SD7tOiKZLhuZbfZGRJwJx/RsyNveCb53MNe6EUJ9Hp2I3LlGo8I+DU83 09zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=IDoHgdQB; 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 x143si845596iod.74.2018.02.09.06.42.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Feb 2018 06:42:28 -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=IDoHgdQB; 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 1ek9qw-000291-14; Fri, 09 Feb 2018 14:40:38 +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 1ek9qu-00023p-Jb for xen-devel@lists.xenproject.org; Fri, 09 Feb 2018 14:40:36 +0000 X-Inumbo-ID: 1df1200d-0da7-11e8-ba59-bc764e045a96 Received: from mail-wm0-x242.google.com (unknown [2a00:1450:400c:c09::242]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 1df1200d-0da7-11e8-ba59-bc764e045a96; Fri, 09 Feb 2018 15:40:05 +0100 (CET) Received: by mail-wm0-x242.google.com with SMTP id t74so15861137wme.3 for ; Fri, 09 Feb 2018 06:40:33 -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=FQnMffYa6N8IqNhe5Eb1RWxxqeTQHjxrlyXbHpoi/iY=; b=IDoHgdQBllW6Vv8vyS939ehfjveyJMd6DyTeuxg2G7+RaVpF8pCKwp057iH3hONrJZ 060OivC2+hTzbE5ijy68VDfFnStG5MkUE4OWblxwe4v3Klpjquxdkgvc6TizHEZUz5rx 1rj0bT85NQNhnJuQqSFZ9jN2ANVReyMIy6ZZA= 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=FQnMffYa6N8IqNhe5Eb1RWxxqeTQHjxrlyXbHpoi/iY=; b=cmEbM5n9JMLnKpqMnwJnOy2bakOy+fcIes0StAbE6a5OJjKJBYabmFFg4eumBo+O1h trgmS4onYsHWMFy+3oJAGoMzmezsO5MzD+taUQp8FdDeC8wLGoGKws6yYjGeW/NT14ez teFZoCa3cfRGzVO37tZDqXg47ggrAhMe7foHgw5DGJUks4jFu5cutK5q3Ej9vq7ilaJJ v4/c1moW4XFYH69oDA657lTkAgRP7GpO6d3ScFkCaXJxFpMS5eKSB5jPHZt7nmv33Jqe tjnP7vQHdFtEE8IbWuWUtiH/WfeT61OYS/41CGw0mkRVAwEAnhSLq79WW5olwOkIGNtZ YSfA== X-Gm-Message-State: APf1xPDwq9wrj/2Rspp70F3kd0Ha6Z9N9VuusNiR9XUwjNtAQSioagfc 5YbLpGnbMfDon6uXhW2L5af+8g== X-Received: by 10.28.166.20 with SMTP id p20mr2147225wme.85.1518187232497; Fri, 09 Feb 2018 06:40:32 -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.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Feb 2018 06:40:32 -0800 (PST) From: Andre Przywara To: Stefano Stabellini , Julien Grall , xen-devel@lists.xenproject.org Date: Fri, 9 Feb 2018 14:39:33 +0000 Message-Id: <20180209143937.28866-46-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 45/49] 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. This is based on Linux commit ad275b8bb1e6, written by Eric Auger. Signed-off-by: Andre Przywara --- xen/arch/arm/vgic/vgic-init.c | 197 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) diff --git a/xen/arch/arm/vgic/vgic-init.c b/xen/arch/arm/vgic/vgic-init.c index b5f1183a50..0cd2dfc600 100644 --- a/xen/arch/arm/vgic/vgic-init.c +++ b/xen/arch/arm/vgic/vgic-init.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2015, 2016 ARM Ltd. + * Imported from Linux ("new" KVM VGIC) and heavily adapted to Xen. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -19,6 +20,77 @@ #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: + * + * - kvm_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_cpu; + 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 */ /** @@ -52,6 +124,131 @@ 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; + int i, ret; + + /* 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_cpu; + + INIT_LIST_HEAD(&vgic_cpu->ap_list_head); + + return 0; +} + /* * Local variables: * mode: C