From patchwork Thu Jul 31 15:00:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 34669 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A459E20540 for ; Thu, 31 Jul 2014 15:02:51 +0000 (UTC) Received: by mail-la0-f69.google.com with SMTP id s18sf1880564lam.0 for ; Thu, 31 Jul 2014 08:02:49 -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=R/ebvA+0QdUW6MBPD2yDmu2STV5/xgSTr8TdZK79oXY=; b=USvAWQ/LPDJymSnabWBInmE12QBFPDVbyx6dNX2rBUV4+XqNlitz9DL8DXv2Zr81V7 mHZnu2ct3pKgrHNequ0Ko1rWKdQGjZj6yrJeKzML0/B0HYEDFxOpT3NQKjQTeMNzD5k+ rCtlCNzFIzsdYoiZHgOO6VfTtMuplMLgUU1nPjhc/UuF0lKdFR2bj5ng1HO/rs1Mwh+X Ne92L26lR2Zh0aijTwq+xoUKfLDr9ZBvG1jkq7r/2C7g5xNA7g46LuPz/osrn5l7Cn3s /BM08lHiSIc+eE/0NNbHjGRLmo7lP4vqlH9M623dV73Qxpo3NSdoqkQ/gTM4eb6snCEZ i5cQ== X-Gm-Message-State: ALoCoQnTvaPBa4+je81+Aw2cyQbrXNNlEF00RSnvEJNdQhsF6BoWocZnAOoZETeYE4iNn9Pi88h0 X-Received: by 10.112.168.230 with SMTP id zz6mr1180738lbb.10.1406818969544; Thu, 31 Jul 2014 08:02:49 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.84.35 with SMTP id k32ls988623qgd.73.gmail; Thu, 31 Jul 2014 08:02:49 -0700 (PDT) X-Received: by 10.221.64.80 with SMTP id xh16mr13435763vcb.35.1406818969380; Thu, 31 Jul 2014 08:02:49 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id ts6si4602576vdc.84.2014.07.31.08.02.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 31 Jul 2014 08:02:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id im17so4400246vcb.31 for ; Thu, 31 Jul 2014 08:02:48 -0700 (PDT) X-Received: by 10.220.131.207 with SMTP id y15mr3013981vcs.71.1406818968896; Thu, 31 Jul 2014 08:02:48 -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.37.5 with SMTP id tc5csp25106vcb; Thu, 31 Jul 2014 08:02:48 -0700 (PDT) X-Received: by 10.43.159.67 with SMTP id lx3mr15961231icc.58.1406818968288; Thu, 31 Jul 2014 08:02:48 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id h16si41174500igt.43.2014.07.31.08.02.45 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 31 Jul 2014 08:02:48 -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 1XCrr4-0000d9-02; Thu, 31 Jul 2014 15:01:18 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XCrr2-0000b2-57 for xen-devel@lists.xenproject.org; Thu, 31 Jul 2014 15:01:16 +0000 Received: from [85.158.137.68:42077] by server-5.bemta-3.messagelabs.com id 47/35-30889-B3A5AD35; Thu, 31 Jul 2014 15:01:15 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-16.tower-31.messagelabs.com!1406818868!11123559!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 13535 invoked from network); 31 Jul 2014 15:01:08 -0000 Received: from mail-wi0-f179.google.com (HELO mail-wi0-f179.google.com) (209.85.212.179) by server-16.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 31 Jul 2014 15:01:08 -0000 Received: by mail-wi0-f179.google.com with SMTP id f8so4308684wiw.6 for ; Thu, 31 Jul 2014 08:01:07 -0700 (PDT) X-Received: by 10.194.63.37 with SMTP id d5mr18005535wjs.92.1406818867012; Thu, 31 Jul 2014 08:01:07 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id r20sm67128337wik.0.2014.07.31.08.01.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Jul 2014 08:01:06 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 31 Jul 2014 16:00:36 +0100 Message-Id: <1406818852-31856-6-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1406818852-31856-1-git-send-email-julien.grall@linaro.org> References: <1406818852-31856-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] [PATCH v2 05/21] xen/arm: follow-up to allow DOM0 manage IRQ and MMIO 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.220.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 commit 33233c2 "arch/arm: domain build: let dom0 access I/O memory of mapped series" fill the iomem_caps to allow DOM0 managing MMIO of mapped device. A device can be disabled (i.e by adding a property status="disabled" in the device tree) because the user may want to passthrough this device to a guest. This will avoid DOM0 loading (and few minutes after unloading) the driver to handle this device. Even though, we don't want to let DOM0 using this device, the domain needs to be able to manage the MMIO/IRQ range. This will allow the toolstack to map MMIO/IRQ to a guest explicitly via "iomem" and "irqs" VM config property or implicitly by passthrough a device. Rework the function map_device (renamed into handle_device) to: * For a given device node: - Give permission to manage IRQ/MMIO for this device - Retrieve the IRQ configuration (i.e edge/level) from the device tree * For available device (i.e status != disabled in the DT) - Assign the device to the guest if it's protected by an IOMMU - Map the IRQs and MMIOs regions to the guest Signed-off-by: Julien Grall --- Changes in v2: - Improve commit message - Remove the third parameter of handle_device and get the status of the device directly in the function. --- xen/arch/arm/domain_build.c | 71 +++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 867dfd4..47d114f 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -929,8 +929,14 @@ static int make_timer_node(const struct domain *d, void *fdt, return res; } -/* Map the device in the domain */ -static int map_device(struct domain *d, struct dt_device_node *dev) +/* For a given device node: + * - Give permission to the guest to manage IRQ and MMIO range + * - Retrieve the IRQ configuration (i.e edge/level) from device tree + * When the device is available: + * - Assign the device to the guest if it's protected by an IOMMU + * - Map the IRQs and iomem regions to DOM0 + */ +static int handle_device(struct domain *d, struct dt_device_node *dev) { unsigned int nirq; unsigned int naddr; @@ -939,13 +945,15 @@ static int map_device(struct domain *d, struct dt_device_node *dev) unsigned int irq; struct dt_raw_irq rirq; u64 addr, size; + bool_t available = dt_device_is_available(dev); nirq = dt_number_of_irq(dev); naddr = dt_number_of_address(dev); - DPRINT("%s nirq = %d naddr = %u\n", dt_node_full_name(dev), nirq, naddr); + DPRINT("%s available = %d nirq = %d naddr = %u\n", dt_node_full_name(dev), + available, nirq, naddr); - if ( dt_device_is_protected(dev) ) + if ( dt_device_is_protected(dev) && available ) { DPRINT("%s setup iommu\n", dt_node_full_name(dev)); res = iommu_assign_dt_device(d, dev); @@ -957,7 +965,7 @@ static int map_device(struct domain *d, struct dt_device_node *dev) } } - /* Map IRQs */ + /* Give permission and map IRQs */ for ( i = 0; i < nirq; i++ ) { res = dt_device_get_raw_irq(dev, i, &rirq); @@ -990,16 +998,28 @@ static int map_device(struct domain *d, struct dt_device_node *dev) irq = res; DPRINT("irq %u = %u\n", i, irq); - res = route_irq_to_guest(d, irq, dt_node_name(dev)); + + res = irq_permit_access(d, irq); if ( res ) { - printk(XENLOG_ERR "Unable to route IRQ %u to domain %u\n", - irq, d->domain_id); + printk(XENLOG_ERR "Unable to permit to dom%u access to IRQ %u\n", + d->domain_id, irq); return res; } + + if ( available ) + { + res = route_irq_to_guest(d, irq, dt_node_name(dev)); + if ( res ) + { + printk(XENLOG_ERR "Unable to route IRQ %u to domain %u\n", + irq, d->domain_id); + return res; + } + } } - /* Map the address ranges */ + /* Give permission and map MMIOs */ for ( i = 0; i < naddr; i++ ) { res = dt_device_get_address(dev, i, &addr, &size); @@ -1023,17 +1043,21 @@ static int map_device(struct domain *d, struct dt_device_node *dev) addr & PAGE_MASK, PAGE_ALIGN(addr + size) - 1); return res; } - res = map_mmio_regions(d, - paddr_to_pfn(addr & PAGE_MASK), - DIV_ROUND_UP(size, PAGE_SIZE), - paddr_to_pfn(addr & PAGE_MASK)); - if ( res ) + + if ( available ) { - printk(XENLOG_ERR "Unable to map 0x%"PRIx64 - " - 0x%"PRIx64" in domain %d\n", - addr & PAGE_MASK, PAGE_ALIGN(addr + size) - 1, - d->domain_id); - return res; + res = map_mmio_regions(d, + paddr_to_pfn(addr & PAGE_MASK), + DIV_ROUND_UP(size, PAGE_SIZE), + paddr_to_pfn(addr & PAGE_MASK)); + if ( res ) + { + printk(XENLOG_ERR "Unable to map 0x%"PRIx64 + " - 0x%"PRIx64" in domain %d\n", + addr & PAGE_MASK, PAGE_ALIGN(addr + size) - 1, + d->domain_id); + return res; + } } } @@ -1110,15 +1134,10 @@ static int handle_node(struct domain *d, struct kernel_info *kinfo, * Some device doesn't need to be mapped in Xen: * - Memory: the guest will see a different view of memory. It will * be allocated later. - * - Disabled device: Linux is able to cope with status="disabled" - * property. Therefore these device doesn't need to be mapped. This - * solution can be use later for pass through. */ - if ( !dt_device_type_is_equal(node, "memory") && - dt_device_is_available(node) ) + if ( !dt_device_type_is_equal(node, "memory") ) { - res = map_device(d, node); - + res = handle_device(d, node); if ( res ) return res; }