From patchwork Tue Apr 28 14:32:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 47682 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C68C02121F for ; Tue, 28 Apr 2015 14:49:35 +0000 (UTC) Received: by wiun10 with SMTP id n10sf6499015wiu.1 for ; Tue, 28 Apr 2015 07:49:35 -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:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=l03xyshsdT8rTP0YdY/LqZU3M/rU5UhTIZoUutBk8qI=; b=G35ggXFIKNX463jziSBT20f/wDayWAKR1VlFIYXgtNNwVmnshrmzDzr4dz8utrXR+J 7Krx1/zhScxL789s79avNiTIviM8RuaELGUWv6pBXDIOHnZBctFNKuB+GGm1/ziIotNY ge6x29ZX83LfeiQnFIDeVPL4Jqo/bCLcM6r8uK6WTXKPySG1pIQCfEVQWeKQWYXVmm1a sYYRCuJY+LGX4VjboNroV9j9eGxq+gVgPlBD0Gk7IfDvSR6a2306dBY+zwtDMv1gqti4 PYGXzIXW4PJI2SaWzBZe/ZyrqnOSXoFHB3OQmi6ZB2c1mBGVX/xhpZPnLaQfKKj4NStF /97w== X-Gm-Message-State: ALoCoQlE8nggM5UT6Zh6oCoK8OndwU48T6nNzg3u9VZ1mhFEg/OMOjuEzLHSQ5P328t3vg3WJFuZ X-Received: by 10.152.43.116 with SMTP id v20mr7618368lal.3.1430232574997; Tue, 28 Apr 2015 07:49:34 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.198.229 with SMTP id jf5ls83175lac.56.gmail; Tue, 28 Apr 2015 07:49:34 -0700 (PDT) X-Received: by 10.112.134.167 with SMTP id pl7mr14762882lbb.50.1430232574924; Tue, 28 Apr 2015 07:49:34 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id rb8si17231109lbb.34.2015.04.28.07.49.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Apr 2015 07:49:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbbzk7 with SMTP id zk7so109290702lbb.0 for ; Tue, 28 Apr 2015 07:49:34 -0700 (PDT) X-Received: by 10.112.198.74 with SMTP id ja10mr14943915lbc.19.1430232574793; Tue, 28 Apr 2015 07:49: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.112.67.65 with SMTP id l1csp1932282lbt; Tue, 28 Apr 2015 07:49:33 -0700 (PDT) X-Received: by 10.52.100.103 with SMTP id ex7mr36289450vdb.71.1430232568997; Tue, 28 Apr 2015 07:49:28 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id fw9si35343920vdc.10.2015.04.28.07.49.28 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 28 Apr 2015 07:49:28 -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 1Yn6oC-00013R-HE; Tue, 28 Apr 2015 14:48:24 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yn6oB-00013F-El for xen-devel@lists.xenproject.org; Tue, 28 Apr 2015 14:48:23 +0000 Received: from [193.109.254.147] by server-16.bemta-14.messagelabs.com id 2B/A0-06072-6BD9F355; Tue, 28 Apr 2015 14:48:22 +0000 X-Env-Sender: julien.grall@citrix.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1430232499!12833102!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 6.13.14; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10418 invoked from network); 28 Apr 2015 14:48:21 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-3.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 28 Apr 2015 14:48:21 -0000 X-IronPort-AV: E=Sophos;i="5.11,664,1422921600"; d="scan'208";a="257352064" From: Julien Grall To: Date: Tue, 28 Apr 2015 15:32:41 +0100 Message-ID: <1430231563-25648-18-git-send-email-julien.grall@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1430231563-25648-1-git-send-email-julien.grall@citrix.com> References: <1430231563-25648-1-git-send-email-julien.grall@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Wei Liu , ian.campbell@citrix.com, tim@xen.org, Julien Grall , Ian Jackson , stefano.stabellini@citrix.com Subject: [Xen-devel] [PATCH v6 17/19] libxl: Add support for Device Tree passthrough 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: , 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: patch@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.217.178 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: From: Julien Grall On ARM, every non-PCI device are described in the device tree. Each of them can be found via a path. This patch introduces a very basic support, only the IOMMU will be set up correctly. The user will have to: - Describe the device in the partial device tree - Map manually MMIO/IRQ This is a first approach, that will allow to have a basic Device Tree passthrough support in Xen. This could be improved later. Furthermore add LIBXL_HAVE_DEVICETREE_PASSTHROUGH to indicate we support Device Tree passthrough and partial device tree (introduced by a previous patch). Signed-off-by: Julien Grall Acked-by: Ian Jackson Acked-by: Ian Campbell Cc: Wei Liu --- Changes in v6: - Add Ian C. and Ian J.'s ack Changes in v5: - Replace some "non-PCI" to "Device Tree" Changes in v4: - Add LIBXL_HAVE_DEVICTREE_PASSTHROUGH to indicate we support non-PCI passthrough. This is also used in order to indicate partial device tree is supported - Remove libxl_dtdev.c as it contains only a 2 lines functions and call directly xc_* from libxl_create.c - Introduce domcreate_attach_dtdev Changes in v3: - Dynamic allocation has been dropped - Rework the commit message in accordance with the previous item Changes in v2: - Get DT infos earlier - Allocate/map IRQ in libxl__arch_domain_create rather than in libxl__device_dt_add - Use VIRQ rather than the PIRQ to construct the interrupts properties of the device tree - Correct cpumask in make_dtdev_node. We allow the interrupt to be used on the 8 CPUs - Fix LOGE when we map the MMIO region in the guest in libxl__device_dt_add. The domain and the IRQ were inverted - Calculate the number of SPIs to configure the VGIC - xc_physdev_dtdev_* helpers has been renamed to xc_dtdev_* - Rename libxl_device_dt to libxl_device_dtdev --- tools/libxl/libxl.h | 7 +++++++ tools/libxl/libxl_create.c | 32 ++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 5 +++++ tools/libxl/libxl_types.idl | 5 +++++ 4 files changed, 49 insertions(+) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 44bd8e2..f3f107b 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -192,6 +192,13 @@ * is not present, instead of ERROR_INVAL. */ #define LIBXL_HAVE_ERROR_DOMAIN_NOTFOUND 1 + +/* + * libxl_domain_build_info has device_tree and libxl_device_dtdev + * exists. This mean Device Tree passthrough is supported for ARM + */ +#define LIBXL_HAVE_DEVICETREE_PASSTHROUGH 1 + /* * libxl ABI compatibility * diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 15b464e..39c828b 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -751,6 +751,8 @@ static void domcreate_attach_vtpms(libxl__egc *egc, libxl__multidev *multidev, int ret); static void domcreate_attach_pci(libxl__egc *egc, libxl__multidev *aodevs, int ret); +static void domcreate_attach_dtdev(libxl__egc *egc, + libxl__domain_create_state *dcs); static void domcreate_console_available(libxl__egc *egc, libxl__domain_create_state *dcs); @@ -1444,6 +1446,36 @@ static void domcreate_attach_pci(libxl__egc *egc, libxl__multidev *multidev, } } + domcreate_attach_dtdev(egc, dcs); + return; + +error_out: + assert(ret); + domcreate_complete(egc, dcs, ret); +} + +static void domcreate_attach_dtdev(libxl__egc *egc, + libxl__domain_create_state *dcs) +{ + STATE_AO_GC(dcs->ao); + int i; + int ret; + int domid = dcs->guest_domid; + + /* convenience aliases */ + libxl_domain_config *const d_config = dcs->guest_config; + + for (i = 0; i < d_config->num_dtdevs; i++) { + const libxl_device_dtdev *dtdev = &d_config->dtdevs[i]; + + LOG(DEBUG, "Assign device \"%s\" to dom%u", dtdev->path, domid); + ret = xc_assign_dt_device(CTX->xch, domid, dtdev->path); + if (ret < 0) { + LOG(ERROR, "xc_assign_dtdevice failed: %d\n", ret); + goto error_out; + } + } + domcreate_console_available(egc, dcs); domcreate_complete(egc, dcs, 0); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 8eb38aa..2826925 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1203,6 +1203,11 @@ _hidden int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int num); _hidden int libxl__device_pci_destroy_all(libxl__gc *gc, uint32_t domid); +/* from libxl_dtdev */ + +_hidden int libxl__device_dt_add(libxl__gc *gc, uint32_t domid, + const libxl_device_dtdev *dtdev); + /*----- xswait: wait for a xenstore node to be suitable -----*/ typedef struct libxl__xswait_state libxl__xswait_state; diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index 5f9e6ae..364c9af 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -540,6 +540,10 @@ libxl_device_pci = Struct("device_pci", [ ("seize", bool), ]) +libxl_device_dtdev = Struct("device_dtdev", [ + ("path", string), + ]) + libxl_device_vtpm = Struct("device_vtpm", [ ("backend_domid", libxl_domid), ("backend_domname", string), @@ -566,6 +570,7 @@ libxl_domain_config = Struct("domain_config", [ ("disks", Array(libxl_device_disk, "num_disks")), ("nics", Array(libxl_device_nic, "num_nics")), ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), + ("dtdevs", Array(libxl_device_dtdev, "num_dtdevs")), ("vfbs", Array(libxl_device_vfb, "num_vfbs")), ("vkbs", Array(libxl_device_vkb, "num_vkbs")), ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),