From patchwork Mon Jun 16 16:17:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 31993 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f71.google.com (mail-qa0-f71.google.com [209.85.216.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0AA3A20E7A for ; Mon, 16 Jun 2014 16:20:35 +0000 (UTC) Received: by mail-qa0-f71.google.com with SMTP id m5sf15911699qaj.2 for ; Mon, 16 Jun 2014 09:20:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=DBuMYjNweJ0rcP1XWeSM7m7DGFiGFOXNqJHyedeN1zE=; b=Po2t4x94vOwxGFwQrXtDbde+WHhEltRPKior5FB6tF5uXTbU5n4cgThQFskOQUttIv NJAXlGFdD+fND8MMwbpWgKAw+zFJxbmTsuyjVhhlkfrAW0/Ta2MKqgeVroEgN+W3+DQ+ hmGpHLyQKR0zWAGoMOiXBKtNRGWX5ldy/qAnb+j6/3Ii8NbcmpOe9jCCYnu66Q5uIKME oWXfW/JFhKCaz6Ohi/1qAQ/zj2HCGkM4fixEVQLFnHfye/ycORltWm3dO7Z1IPvxOiIl 3rZ3X3Tvb+H0rWfckB4+Dt28CTujuu1QgZZhDJmXcBQ1tvBzPVZzHCtjyBpEETNGwK3P ggRw== X-Gm-Message-State: ALoCoQml9JoKZPQlpwEybt2ieMx0LLN12VFbRd/XYRE8DcPaQ+emWExoLhLWfl8obwV5qlu9yWu+ X-Received: by 10.52.170.145 with SMTP id am17mr10766vdc.2.1402935634890; Mon, 16 Jun 2014 09:20:34 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.88.80 with SMTP id s74ls173123qgd.50.gmail; Mon, 16 Jun 2014 09:20:34 -0700 (PDT) X-Received: by 10.52.121.112 with SMTP id lj16mr2912687vdb.29.1402935634678; Mon, 16 Jun 2014 09:20:34 -0700 (PDT) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id s5si4292166vcu.2.2014.06.16.09.20.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Jun 2014 09:20:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.172 as permitted sender) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id jz11so6283181veb.17 for ; Mon, 16 Jun 2014 09:20:34 -0700 (PDT) X-Received: by 10.58.220.230 with SMTP id pz6mr16784671vec.9.1402935634594; Mon, 16 Jun 2014 09:20:34 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.54.6 with SMTP id vs6csp146213vcb; Mon, 16 Jun 2014 09:20:34 -0700 (PDT) X-Received: by 10.140.108.163 with SMTP id j32mr26580241qgf.56.1402935634122; Mon, 16 Jun 2014 09:20:34 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id b3si13800419qak.97.2014.06.16.09.20.33 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 16 Jun 2014 09:20:34 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WwZc2-0006ja-KA; Mon, 16 Jun 2014 16:18:26 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WwZc0-0006iu-PJ for xen-devel@lists.xenproject.org; Mon, 16 Jun 2014 16:18:24 +0000 Received: from [85.158.143.35:43259] by server-3.bemta-4.messagelabs.com id CF/A6-16194-0D81F935; Mon, 16 Jun 2014 16:18:24 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-16.tower-21.messagelabs.com!1402935503!8265704!1 X-Originating-IP: [209.85.212.179] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30760 invoked from network); 16 Jun 2014 16:18:23 -0000 Received: from mail-wi0-f179.google.com (HELO mail-wi0-f179.google.com) (209.85.212.179) by server-16.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 16 Jun 2014 16:18:23 -0000 Received: by mail-wi0-f179.google.com with SMTP id cc10so4381350wib.0 for ; Mon, 16 Jun 2014 09:18:23 -0700 (PDT) X-Received: by 10.194.62.104 with SMTP id x8mr29750946wjr.15.1402935502969; Mon, 16 Jun 2014 09:18:22 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id l45sm34836161eep.25.2014.06.16.09.18.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Jun 2014 09:18:22 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 16 Jun 2014 17:17:53 +0100 Message-Id: <1402935486-29136-7-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1402935486-29136-1-git-send-email-julien.grall@linaro.org> References: <1402935486-29136-1-git-send-email-julien.grall@linaro.org> Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com Subject: [Xen-devel] [RFC 06/19] xen/arm: Implement hypercall PHYSDEVOP_map_pirq X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: The physdev sub-hypercall PHYSDEVOP_map_pirq allow the toolstack to route a physical IRQ to the guest (via the config options "irqs" for xl). For now, we allow only SPIs to be mapped to the guest. The type MAP_PIRQ_TYPE_GSI is used for this purpose. The virtual IRQ number is equal to the physical one. This will avoid adding logic in Xen to allocate the vIRQ number. The drawbacks is we allocated unconditionally the same amount of SPIs as the host. This value will never be more than 1024 with GICv2. Signed-off-by: Julien Grall --- I'm wondering if we should introduce an alias of MAP_PIRQ_TYPE_GSI for ARM. It's will be less confuse for the user. --- xen/arch/arm/physdev.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++-- xen/arch/arm/vgic.c | 5 +--- 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/physdev.c b/xen/arch/arm/physdev.c index 61b4a18..d17589c 100644 --- a/xen/arch/arm/physdev.c +++ b/xen/arch/arm/physdev.c @@ -8,13 +8,86 @@ #include #include #include +#include +#include +#include +#include #include +#include + +static int physdev_map_pirq(domid_t domid, int type, int index, int *pirq_p) +{ + struct domain *d; + int ret; + int irq = index; + + d = rcu_lock_domain_by_any_id(domid); + if ( d == NULL ) + return -ESRCH; + + ret = xsm_map_domain_pirq(XSM_TARGET, d); + if ( ret ) + goto free_domain; + + /* For now we only suport GSI */ + if ( type != MAP_PIRQ_TYPE_GSI ) + { + ret = -EINVAL; + dprintk(XENLOG_G_ERR, "dom%u: wrong map_pirq type 0x%x\n", + d->domain_id, type); + goto free_domain; + } + + if ( !is_routable_irq(irq) ) + { + ret = -EINVAL; + dprintk(XENLOG_G_ERR, "IRQ%u is not routable to a guest\n", irq); + goto free_domain; + } + + ret = -EPERM; + if ( !irq_access_permitted(current->domain, irq) ) + goto free_domain; + + ret = route_irq_to_guest(d, irq, "routed IRQ"); + + /* GSIs are mapped 1:1 to the guest */ + if ( !ret ) + *pirq_p = irq; + +free_domain: + rcu_unlock_domain(d); + + return ret; +} int do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { - printk("%s %d cmd=%d: not implemented yet\n", __func__, __LINE__, cmd); - return -ENOSYS; + int ret; + + switch ( cmd ) + { + case PHYSDEVOP_map_pirq: + { + physdev_map_pirq_t map; + + ret = -EFAULT; + if ( copy_from_guest(&map, arg, 1) != 0 ) + break; + + ret = physdev_map_pirq(map.domid, map.type, map.index, &map.pirq); + + if ( __copy_to_guest(arg, &map, 1) ) + ret = -EFAULT; + } + break; + default: + ret = -ENOSYS; + break; + } + + return ret; } /* diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c index e451324..c18b2ca 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -82,10 +82,7 @@ int domain_vgic_init(struct domain *d) /* Currently nr_lines in vgic and gic doesn't have the same meanings * Here nr_lines = number of SPIs */ - if ( is_hardware_domain(d) ) - d->arch.vgic.nr_lines = gic_number_lines() - 32; - else - d->arch.vgic.nr_lines = 0; /* We don't need SPIs for the guest */ + d->arch.vgic.nr_lines = gic_number_lines() - 32; d->arch.vgic.shared_irqs = xzalloc_array(struct vgic_irq_rank, DOMAIN_NR_RANKS(d));