From patchwork Fri Feb 9 14:39:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 127854 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp680090ljc; Fri, 9 Feb 2018 06:42:31 -0800 (PST) X-Google-Smtp-Source: AH8x227t1n7MCbpXEnhc2l6PePonYedkU50jc3JdExLbCpthbUYhdIVYeLaimoQqDuMhOI9fPumn X-Received: by 10.107.212.24 with SMTP id l24mr3549919iog.40.1518187351166; Fri, 09 Feb 2018 06:42:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518187351; cv=none; d=google.com; s=arc-20160816; b=rChquNU5wFh7Kzk+7DcU9kocBfmiPRe2z2Lde/avduQs4F8lWFyfW0t7os1yLKNxKC p0JG8G6ZtDfqR1JDOAsq/5dV4mmKcO53iH9fp7zOZ9Lfr3mrueSrxS30k4m3Fvy+iiYQ 7ciAgNbBNdDdUoKxJN50wiPp+Xp2h0DoE4velZqmoexaaD3+GCpYDHtPuzSBIPAi8hiE pysv2jckQSmpZ6FMj9BW6+Ww0gt1tvXPFhzjAtCflssBnHO9q8p/TgKfhH4op/PoNrkF 96BmdBjicKsJh6zaSkl8jg/89gS/ipFYHlppi0Cc5lCNMX61ts9OTA1CyXDlNBV7L+L7 Cj1w== 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=ov1MnCRFrxIFRTLrxDfMI17qFhO/2AlaqQ65lgAfI+I=; b=yMm+dxGTgQhiE1wzcCYcK4WNAZNPbc66BLnD/sCtcmMg2UsvUNG3Y6Ty+bHBydf8zU heyq6Lb1W1nk7YmjRgMZwAP6jvelZAWY4e723QOk9xwhdxHwiqlkkNWBaRW35F8QEPjJ UsNd+0tiari9LCPX2RY3WuLumk8UFU11O15OdupL8JE+kER4Qq6GqlM0UVL2sqI8oMYu cua4Rzn/TOPc4jNYkicghi1D4I17sRtNfS/ZHVofwWgY5uxHlmqk431OnKIpW8d7Fh20 BWySBFjebh1v+/PI/vcH5s/yLX/qbpGIXN1dD1dkxEoqwLYh3W6dcfpmfBHMaCdRSxLk n7bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=XO6mS0f+; 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 v11si1622293itf.94.2018.02.09.06.42.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Feb 2018 06:42:31 -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=XO6mS0f+; 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-0002CE-PW; 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 1ek9qv-000279-Iw for xen-devel@lists.xenproject.org; Fri, 09 Feb 2018 14:40:37 +0000 X-Inumbo-ID: 1ea3aa9f-0da7-11e8-ba59-bc764e045a96 Received: from mail-wm0-x243.google.com (unknown [2a00:1450:400c:c09::243]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 1ea3aa9f-0da7-11e8-ba59-bc764e045a96; Fri, 09 Feb 2018 15:40:06 +0100 (CET) Received: by mail-wm0-x243.google.com with SMTP id g1so15784855wmg.2 for ; Fri, 09 Feb 2018 06:40:34 -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=rWYP3bJJQnf1syaBdarbmjRBmnA3VhYwNl74VtTc5Sg=; b=XO6mS0f+Ex2UWMKTZfGRgiCZTKnmSm5R2urPQeg56wvVkEaSsC3RU0z7QmsmHD4imR +3T0CE1kDF/tsK4qvJW5kGncKzCbRIPiWUX20Wy+KLHtIK43aQTmZ6jc5O5QQw/zC6jZ d3FAQEgSFyA7Dms4BHAGn/3/HV2xQP5/LnOlc= 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=rWYP3bJJQnf1syaBdarbmjRBmnA3VhYwNl74VtTc5Sg=; b=jjGhRZHPzZn+y0MrgwbKfQ9WiQL7C3y7/V0pqHooeVldx8yXN2/xv4Am8m5lmkMo92 j0QPCWI88G3rPZqKWXIitUP334MduATEAqknMwBQZuVAUD2qZA3HcKisJCLxclOWdMN4 HsH3lcYZk2crZuPUnT7e6HmHwKpmrtangZZ4M14nJ9lTRhQpzbBt75iVbpW0n9GKeWun YETMBKncw4VTmRfgqZqUeDby5tmUZ+TNUfvkKfzR+dveLqmbHH+CLqpDmAlk+jWC11b0 0qEenYssws62VAZ3UCuTCuyHbAfRVUuzcI59mZdOG9Apu4FQWNICmUylBtWBwlHftcTl 6Iqw== X-Gm-Message-State: APf1xPBgvrfNqBgz+s1TADqhELIODh+0FIcg2jHaX/2o/b3XZ5v5RW/l NLPc+YZYNhQYlYjo/zvIeoy13jc5ung= X-Received: by 10.28.158.77 with SMTP id h74mr2141903wme.38.1518187233622; Fri, 09 Feb 2018 06:40:33 -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.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Feb 2018 06:40:33 -0800 (PST) From: Andre Przywara To: Stefano Stabellini , Julien Grall , xen-devel@lists.xenproject.org Date: Fri, 9 Feb 2018 14:39:34 +0000 Message-Id: <20180209143937.28866-47-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 46/49] 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 --- xen/arch/arm/vgic/vgic-v2.c | 65 +++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/vgic/vgic.h | 1 + 2 files changed, 66 insertions(+) diff --git a/xen/arch/arm/vgic/vgic-v2.c b/xen/arch/arm/vgic/vgic-v2.c index 10fc467ffa..b5026bb050 100644 --- a/xen/arch/arm/vgic/vgic-v2.c +++ b/xen/arch/arm/vgic/vgic-v2.c @@ -202,6 +202,71 @@ void vgic_v2_clear_lr(struct vcpu *vcpu, int lr) vcpu->arch.vgic_cpu.vgic_v2.vgic_lr[lr] = 0; } +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, 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; +} + static void save_lrs(struct vcpu *vcpu, void __iomem *base) { struct vgic_v2_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v2; diff --git a/xen/arch/arm/vgic/vgic.h b/xen/arch/arm/vgic/vgic.h index 205ce10ffa..adb04f2f52 100644 --- a/xen/arch/arm/vgic/vgic.h +++ b/xen/arch/arm/vgic/vgic.h @@ -58,6 +58,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_clear_lr(struct vcpu *vcpu, int lr); void vgic_v2_set_underflow(struct vcpu *vcpu); +int vgic_v2_map_resources(struct domain *d); int vgic_register_dist_iodev(struct domain *d, paddr_t dist_base_address, enum vgic_type);