From patchwork Thu Mar 15 20:30:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 131856 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp1579393ljb; Thu, 15 Mar 2018 13:33:29 -0700 (PDT) X-Google-Smtp-Source: AG47ELs2zO8qebzbkhNkhK55C27/vb49+eLjHW/wI2ASkr92MAP3uvRFDd71QJ8Bu/5vtIeXZThA X-Received: by 10.107.114.18 with SMTP id n18mr10364869ioc.237.1521146009348; Thu, 15 Mar 2018 13:33:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521146009; cv=none; d=google.com; s=arc-20160816; b=T1SFmxQoZKCkOGHALW3YgkIl18SV56bcJFiCbthWsL3TbgslLSEwg6QTqmezV2m8r6 5POBP+ODw6Tq5VPdB+D4TxNTO1ft3yEsxTiC9RNWpGfhRtQ8eycSBa6x1mQpAFoSuTiT Rl6C8mFVDHL+siJ0ptnPUKDiFxD0eQHSDynWvPKlu56hznjVrrcUOx2fj6D1LtXhk2M3 hjI/njoGHy/X3kuDQloWin0CVPy528DQhAukmAfLXc+ryEAfRXzhVaWO9SfyJg0CNnSo B68LhItlKcfeMvuit18Tvvn8/zkNfmxBLaGEfwUQ0kX3uZiIL+wfIqnJLyyHzn60uR1I BZbQ== 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=5GtC1LQOvxmkfOp7Cc7RJa0q2M3hVrNQRh8JF+bUnQQ=; b=iYCUo16Yo3hHLQNKjWUMsKPQZ1IoQ+kt2bmZG16+IoGYenTUnENxY6tiLN0VSjusYV GJju3bFwu4BxI6kteJJXCsEjusaJrCysoBHDt3uXSaIkG2VAqoVuOueC4RbtU6f02n/j 8qc+1R/We8LUR0nHqQV6C3DbyAqoG7amLBIsDZehMrjQaerVGISkIc24j/lJ5q+B+LX8 wa63UPa2cWABhkw84eyaPmQC2ux1/saOiWySUKEl+qXYzZ0iS4FEKKuxsybUXVK1qjyZ noxca4htTWd2GEmnqIYr9CUdAPqE9zNu7WotbLRBWoLMATWB1zXPVeOvE889NMsqTyD9 rqJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=PbHOsUlV; 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 b2si3830223iof.269.2018.03.15.13.33.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Mar 2018 13:33:29 -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=PbHOsUlV; 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 1ewZXZ-0004m4-80; Thu, 15 Mar 2018 20:31:57 +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-0004gX-MO for xen-devel@lists.xenproject.org; Thu, 15 Mar 2018 20:31:55 +0000 X-Inumbo-ID: e2db9a6d-288f-11e8-9728-bc764e045a96 Received: from mail-wm0-x242.google.com (unknown [2a00:1450:400c:c09::242]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id e2db9a6d-288f-11e8-9728-bc764e045a96; Thu, 15 Mar 2018 21:31:49 +0100 (CET) Received: by mail-wm0-x242.google.com with SMTP id w128so12892734wmw.0 for ; Thu, 15 Mar 2018 13:31:54 -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=C0khzIBU9FqXrmQSUKudrilH4Kq3hO/4fW10jLAv9Rs=; b=PbHOsUlVM2fNx+RQOPUY/uApx+2eTfEPArqzOLOM+q/l8zNb391h4boblH5L4Yir5+ Nm1iQTFRYgkFBuU8SJ4HyrrrhIOV+r0n2Xoigid8avVmp98BY97VC3k5kaaWcIz2ONge WvtslIX9qLQt3H6uwTY1K/WL1u/8lEheDJj3A= 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=C0khzIBU9FqXrmQSUKudrilH4Kq3hO/4fW10jLAv9Rs=; b=SgYPnfqk/KkilHR6eU9w0IdW0FzdVvt1Ez8TkXsFdXeNWkdaDTIhwMBtLDkP51f6Gn UwDqNanRHTS4V64dGmupNGdurpiSyvl3dU3P/xVw8JPjyUKVSphpL9R7lO4J0+EK5S8r AIcOE4zuuhUgWgSQXYWq1iC/nSpetH3t8yxQMZ04h5LPCa4pyFANeXT/rnkzuppJxUW3 HcUw1LhlL1PTsHEGyYwuGAglkARK/O/qDmUBhen8iF7e2LXDyCF4GnkMsWValGltJ+wD PWuBBT2ZjDsFY2KoPByDnGagB2Bb2t6k3Sccf/6yEaJfL8TN7CR5CA/Z+0GDtWyzIJgK i4TQ== X-Gm-Message-State: AElRT7F2+xNwHbUXsKAgWHjq0eAfCXSpJdYGbSOjM1qFbObMIfm7VYRl SF9UrJJKM2CCp6Gy+d5LU8lSKg== X-Received: by 10.28.167.151 with SMTP id q145mr6344482wme.64.1521145913670; Thu, 15 Mar 2018 13:31:53 -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.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Mar 2018 13:31:53 -0700 (PDT) From: Andre Przywara To: Stefano Stabellini , Julien Grall Date: Thu, 15 Mar 2018 20:30:48 +0000 Message-Id: <20180315203050.19791-44-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 43/45] ARM: new VGIC: vgic-init: implement map_resources 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" map_resources is the last initialization step needed before the first VCPU is run. At that stage the code stores the MMIO base addresses used. Also it registers the respective register frames with the MMIO framework. This is based on Linux commit cbae53e663ea, written by Eric Auger. Signed-off-by: Andre Przywara Acked-by: Julien Grall --- Changelog v1 ... v2: - whitespace fixes xen/arch/arm/vgic/vgic-v2.c | 66 +++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/vgic/vgic.h | 1 + 2 files changed, 67 insertions(+) diff --git a/xen/arch/arm/vgic/vgic-v2.c b/xen/arch/arm/vgic/vgic-v2.c index 4662346327..c35f406a06 100644 --- a/xen/arch/arm/vgic/vgic-v2.c +++ b/xen/arch/arm/vgic/vgic-v2.c @@ -225,6 +225,72 @@ void vgic_v2_enable(struct vcpu *vcpu) gic_hw_ops->update_hcr_status(GICH_HCR_EN, 1); } +int vgic_v2_map_resources(struct domain *d) +{ + struct vgic_dist *dist = &d->arch.vgic; + paddr_t cbase, csize; + paddr_t vbase; + int ret; + + /* + * The hardware domain gets the hardware address. + * Guests get the virtual platform layout. + */ + if ( is_hardware_domain(d) ) + { + d->arch.vgic.vgic_dist_base = gic_v2_hw_data.dbase; + /* + * For the hardware domain, we always map the whole HW CPU + * interface region in order to match the device tree (the "reg" + * properties is copied as it is). + * Note that we assume the size of the CPU interface is always + * aligned to PAGE_SIZE. + */ + cbase = gic_v2_hw_data.cbase; /* was: dist->vgic_cpu_base */ + csize = gic_v2_hw_data.csize; + vbase = gic_v2_hw_data.vbase; /* was: kvm_vgic_global_state.vcpu_base */ + } + else + { + d->arch.vgic.vgic_dist_base = GUEST_GICD_BASE; + /* + * The CPU interface exposed to the guest is always 8kB. We may + * need to add an offset to the virtual CPU interface base + * address when in the GIC is aliased to get a 8kB contiguous + * region. + */ + BUILD_BUG_ON(GUEST_GICC_SIZE != SZ_8K); + cbase = GUEST_GICC_BASE; + csize = GUEST_GICC_SIZE; + vbase = gic_v2_hw_data.vbase + gic_v2_hw_data.aliased_offset; + } + + + ret = vgic_register_dist_iodev(d, gaddr_to_gfn(dist->vgic_dist_base), + VGIC_V2); + if ( ret ) + { + gdprintk(XENLOG_ERR, "Unable to register VGIC MMIO regions\n"); + return ret; + } + + /* + * Map the gic virtual cpu interface in the gic cpu interface + * region of the guest. + */ + ret = map_mmio_regions(d, gaddr_to_gfn(cbase), csize / PAGE_SIZE, + maddr_to_mfn(vbase)); + if ( ret ) + { + gdprintk(XENLOG_ERR, "Unable to remap VGIC CPU to VCPU\n"); + return ret; + } + + dist->ready = true; + + return 0; +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/vgic/vgic.h b/xen/arch/arm/vgic/vgic.h index def1ac478a..7af982f100 100644 --- a/xen/arch/arm/vgic/vgic.h +++ b/xen/arch/arm/vgic/vgic.h @@ -63,6 +63,7 @@ void vgic_v2_fold_lr_state(struct vcpu *vcpu); void vgic_v2_populate_lr(struct vcpu *vcpu, struct vgic_irq *irq, int lr); void vgic_v2_set_underflow(struct vcpu *vcpu); void vgic_v2_enable(struct vcpu *vcpu); +int vgic_v2_map_resources(struct domain *d); int vgic_register_dist_iodev(struct domain *d, gfn_t dist_base_fn, enum vgic_type);