From patchwork Mon Mar 5 16:04:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 130693 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp2854540lja; Mon, 5 Mar 2018 08:07:44 -0800 (PST) X-Google-Smtp-Source: AG47ELsDe6ucqe/8/A1mDzD8xZHXT/ttCuWQn1EDCTLa33nYVyMpG1SfExbaneCyfTWdrSWOz692 X-Received: by 10.107.22.1 with SMTP id 1mr18414599iow.238.1520266064744; Mon, 05 Mar 2018 08:07:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520266064; cv=none; d=google.com; s=arc-20160816; b=QelkPgylye9AsXAIXTToJ/1CyOLlk3n9W4SeWm9j23mVEGeWXHWWCCOtz3KvIqZ2yA NyYzwr6Z0/R0Mc2J36WDQF0oJn8JOcblDf2tDB2RiP45tio7JxSg+mAu7LZRF47jGYPF +2dPXed/f23Twsq+8dbhn0Et+LO6sTZWEmC4CDGQtZgJbdNNAklotU96kRIvsaH3YNBZ cUdWYEfbFnpR8qN2Nw1LUFIZBRtxZK42xsiRXiAHfuuTdPqccuVj5M04h3zR+je7yf5s WE1BAO+N2Sv3HUsIbr76Nu1DPht6yhvPCLBJeIU8icbt7JgLcZ6Yo5KtcObYo5YKLLg9 7nyg== 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=Vx1rX7UQIWllo21zxKR0t8G3vbfvw4CKJmWtb+FYMAA=; b=pnLXgzxBjsOgXln6XEkbkzMb3sgS7quDovewegms0KC6PT2I5ZzocVzUMmqzrv12U0 TQOoKb9YpVZaew0Ds7aoQZl5RcVuMpFQ6QZT/kR8MwhjLArEHs/fspd6MKCou5sadM25 k2IrL+P7ZaPLXeAtbUXB4WZ4pB/PBJgVoRlxPcOuMOm1/Afm+XgikQuhHO445STF3bUN C5+fjlqJBh5KYHiG1VGDV2iQcnsC0I0NkAa0wNfr+wFErVlSifj1IoNGdBRyoIHanKiC 6mzz8SabXqXsMa1CUA8oXkd2vA9QtKTPb9xBEReaNMv3cFURZ7rnk5mgBcgU7eUvXGhl A/5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ddqDt3ra; 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 b8si5901161itc.50.2018.03.05.08.07.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Mar 2018 08:07:44 -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=ddqDt3ra; 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 1essc5-0000tL-8g; Mon, 05 Mar 2018 16:05:21 +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 1essc3-0000mD-MK for xen-devel@lists.xenproject.org; Mon, 05 Mar 2018 16:05:19 +0000 X-Inumbo-ID: d7d520bf-208e-11e8-ba59-bc764e045a96 Received: from mail-wr0-x243.google.com (unknown [2a00:1450:400c:c0c::243]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id d7d520bf-208e-11e8-ba59-bc764e045a96; Mon, 05 Mar 2018 17:04:12 +0100 (CET) Received: by mail-wr0-x243.google.com with SMTP id f14so17817130wre.8 for ; Mon, 05 Mar 2018 08:05:17 -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=P8+kfLLBD9r0HCt93DFzR3BUE01AUCnUuuhgspufzAc=; b=ddqDt3ranTtyprB7hS7R5AfH3t/+qBHMNtEymQbQKQm9FcHgYtuZiXOvi67pSA1UF8 8n7j/UFoK1XKri9qXz5GCLf676oDx9E2RnoDhvyes4M5Q3PdmpvbBHa2O5mHe9gJ1+SA fjfO3tv619hJPT5ld4tBJoYQicsuvEtBk6eOk= 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=P8+kfLLBD9r0HCt93DFzR3BUE01AUCnUuuhgspufzAc=; b=lQek8lkgsJbg/JHjdPujayTK9MTO1qWORQ9ogkzNwOn+uMSiRn0zxuCXVqBICo1MJt HWjeFSvWqmhoYGdcjy1hDYhv+CtbXOMvM40OL7a8bW52cb+840KYPqqJpO3R/ooe761g PPt6/JUcuBPMKwiVwGe+CDK3cwBI4Fyfx/IZzeQ1IbwIboRF1M5h6pk/nXxTeE9U5oBF 4WmQe7TYXBW3GbUnblo4aacClJ/raYEA0xvryTW5DDw3ZeVfsiJGmH4tGaOJdNAGAA1H M+wOa0ZSgMlist6dIJZTbUqiNH0W8PmL5Pho6O72sbf9tZIcmLIUNEMohakAibjuUk0P /T+A== X-Gm-Message-State: APf1xPCVieWmv3rSotbVLzfAP4RyIOMiPupZWZmNsEEeL/yz8kE7U+/8 rHG0Ik28PawRjQr6+zjcNiwohQ== X-Received: by 10.223.178.206 with SMTP id g72mr12340675wrd.135.1520265916451; Mon, 05 Mar 2018 08:05:16 -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.05.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Mar 2018 08:05:16 -0800 (PST) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Mon, 5 Mar 2018 16:04:11 +0000 Message-Id: <20180305160415.16760-54-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 53/57] 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 RFC ... v1: - adapt to former changes - add missing comment line - extend commit message xen/arch/arm/vgic/vgic-init.c | 196 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) diff --git a/xen/arch/arm/vgic/vgic-init.c b/xen/arch/arm/vgic/vgic-init.c index d091c92ed0..8bc83f677b 100644 --- a/xen/arch/arm/vgic/vgic-init.c +++ b/xen/arch/arm/vgic/vgic-init.c @@ -20,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; + 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 +121,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; + + INIT_LIST_HEAD(&vgic_cpu->ap_list_head); + + return 0; +} + /* * Local variables: * mode: C