From patchwork Tue Jan 13 14:25:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 43016 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 57D0920DE8 for ; Tue, 13 Jan 2015 14:28:51 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id ex7sf2096053wid.3 for ; Tue, 13 Jan 2015 06:28:50 -0800 (PST) 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:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=gZA9RvrewMvAzF5ppse1zyr2JsVsQaFVeYXGn7ygjM4=; b=eEhvzaw4fu38WKtDo7fYC4RH+vWv6O3xj/K2aENa6S52mwOlLqQYAMuOdF1EmoOmNq YybjhCLrKT3ppHH/6+TWvMjcLNXD6zUyNEp6tpzIZCGVDspZkoK3v83gWEuWJ85T+SGS cNZM2E5NU3jpK7SCphthpmJ078JUyjQ9KLg9omd0ziKY0zrc2DN+vWHHXrCkrz9jZQgO /qvDaOM8Cr8Fb1/0YRagkPEg5qK2jTtrJ5Fp0ubKKf5AL+HkgSkK2JRxJEH/K5cjQy7P lmHQK/qJciix2Kr8ExeidR9XY4phuc5smQQOQOVL7wJIP7NjoF2W/MZ51wy7/ZMBEIo2 Wu9Q== X-Gm-Message-State: ALoCoQlkp4FxhuWyQLYeaH4XwChAUm/DfG5UCOwzP6YZNUc9qMd2YW1mm0Im51iSFX09AJJ80VDk X-Received: by 10.152.2.40 with SMTP id 8mr326753lar.7.1421159330537; Tue, 13 Jan 2015 06:28:50 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.66 with SMTP id x2ls696379laa.88.gmail; Tue, 13 Jan 2015 06:28:50 -0800 (PST) X-Received: by 10.112.205.231 with SMTP id lj7mr42209020lbc.86.1421159330327; Tue, 13 Jan 2015 06:28:50 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id dd4si3119379lad.13.2015.01.13.06.28.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 Jan 2015 06:28:50 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id 10so2826119lbg.5 for ; Tue, 13 Jan 2015 06:28:50 -0800 (PST) X-Received: by 10.112.26.135 with SMTP id l7mr33359292lbg.56.1421159330205; Tue, 13 Jan 2015 06:28:50 -0800 (PST) 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.9.200 with SMTP id c8csp1398997lbb; Tue, 13 Jan 2015 06:28:49 -0800 (PST) X-Received: by 10.220.95.132 with SMTP id d4mr21520196vcn.67.1421159309432; Tue, 13 Jan 2015 06:28:29 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id fb9si8109350vcb.14.2015.01.13.06.28.28 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 13 Jan 2015 06:28:29 -0800 (PST) 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 1YB2Qk-0001Tu-Sp; Tue, 13 Jan 2015 14:26:50 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YB2Qh-0001MU-IT for xen-devel@lists.xenproject.org; Tue, 13 Jan 2015 14:26:47 +0000 Received: from [85.158.143.35] by server-2.bemta-4.messagelabs.com id EA/64-25276-62B25B45; Tue, 13 Jan 2015 14:26:46 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-6.tower-21.messagelabs.com!1421159206!21101526!1 X-Originating-IP: [74.125.82.170] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.12.5; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7790 invoked from network); 13 Jan 2015 14:26:46 -0000 Received: from mail-we0-f170.google.com (HELO mail-we0-f170.google.com) (74.125.82.170) by server-6.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 13 Jan 2015 14:26:46 -0000 Received: by mail-we0-f170.google.com with SMTP id w61so3225774wes.1 for ; Tue, 13 Jan 2015 06:26:46 -0800 (PST) X-Received: by 10.194.76.73 with SMTP id i9mr5450526wjw.93.1421159206036; Tue, 13 Jan 2015 06:26:46 -0800 (PST) Received: from chilopoda.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id ni15sm14513482wic.18.2015.01.13.06.26.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Jan 2015 06:26:45 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 13 Jan 2015 14:25:24 +0000 Message-Id: <1421159133-31526-16-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1421159133-31526-1-git-send-email-julien.grall@linaro.org> References: <1421159133-31526-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 v3 15/24] xen/dts: Provide an helper to get a DT node from a path provided by a guest 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.217.174 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: Signed-off-by: Julien Grall --- Changes in v3: - Use the new prototype of safe_copy_string_from_guest Changes in v2: - guest_copy_string_from_guest has been renamed into safe_copy_string_from_guest --- xen/common/device_tree.c | 19 +++++++++++++++++++ xen/include/xen/device_tree.h | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index af73b3b..4c9daea 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,7 @@ #include #include #include +#include const void *device_tree_flattened; dt_irq_xlate_func dt_irq_xlate; @@ -277,6 +279,23 @@ struct dt_device_node *dt_find_node_by_path(const char *path) return np; } +int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen, + struct dt_device_node **node) +{ + char *path; + + path = safe_copy_string_from_guest(u_path, u_plen, + DEVICE_TREE_MAX_PATHLEN); + if ( IS_ERR(path) ) + return PTR_ERR(path); + + *node = dt_find_node_by_path(path); + + xfree(path); + + return (*node == NULL) ? -ESRCH : 0; +} + struct dt_device_node *dt_find_node_by_alias(const char *alias) { const struct dt_alias_prop *app; diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 19d0e45..9b0ed00 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -22,6 +22,9 @@ #define DEVICE_TREE_MAX_DEPTH 16 +/* This limit is used by the hypercalls to restrict the size of the path */ +#define DEVICE_TREE_MAX_PATHLEN 1024 + /* * Struct used for matching a device */ @@ -456,6 +459,20 @@ struct dt_device_node *dt_find_node_by_alias(const char *alias); */ struct dt_device_node *dt_find_node_by_path(const char *path); + +/** + * dt_find_node_by_gpath - Same as dt_find_node_by_path but retrieve the + * path from the guest + * + * @u_path: Xen Guest handle to the buffer containing the path + * @u_plen: Length of the buffer + * @node: TODO + * + * Return 0 if succeed otherwise -errno + */ +int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen, + struct dt_device_node **node); + /** * dt_get_parent - Get a node's parent if any * @node: Node to get parent