From patchwork Thu Mar 19 19:29:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 46090 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0D76521580 for ; Thu, 19 Mar 2015 19:32:03 +0000 (UTC) Received: by wghb13 with SMTP id b13sf5500454wgh.3 for ; Thu, 19 Mar 2015 12:32:02 -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:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=BLN/SpYw2zssdXpfca7yLQbq7ih/uXuOddHGJNKsoZ4=; b=jrNoSNt96lg1fcd0oROZqsjVqX/k366SnoeX8cBNPcDHene3jZbfae7ChGRyJEg69i PJbvG1cu2gplCWMUiSuEQFBhHJkHBxg87aJXPmW7nqU5DYi7jobSlpqLKbRzdDlUmM8S KlCu10qoY41WTyQecWYxbgLL4Je5Xch632aExbz354IQNKwIjrN6+J/oHRUgWnfZG1iu 3h/SA+CWIoMxKj1q5UPR64YHsjN8JOVSq/F+0vKn5Cn7XX9lrgE/gRHg2Ko2mAG0BQT3 MamHe2SaDkdoTnD9jN4xyo9aaCqLQMLzPhFzIw00WIH1AzvcEUC62aSI8rLBZcnJw4eu EIzQ== X-Gm-Message-State: ALoCoQk4gTsRkLNk8rn9AXqiqk+1Ir/wq2TI2xsztw5QggczO2q7o5pa2r5IWYRPop9SsdJ2v07o X-Received: by 10.112.44.167 with SMTP id f7mr10052428lbm.9.1426793522386; Thu, 19 Mar 2015 12:32:02 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.246.38 with SMTP id xt6ls314780lac.102.gmail; Thu, 19 Mar 2015 12:32:02 -0700 (PDT) X-Received: by 10.152.19.9 with SMTP id a9mr71054936lae.80.1426793522171; Thu, 19 Mar 2015 12:32:02 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id jp2si1700375lab.7.2015.03.19.12.32.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 12:32:02 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by lamx15 with SMTP id x15so70761491lam.3 for ; Thu, 19 Mar 2015 12:32:02 -0700 (PDT) X-Received: by 10.112.212.106 with SMTP id nj10mr51233747lbc.36.1426793522069; Thu, 19 Mar 2015 12:32:02 -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.35.133 with SMTP id h5csp597354lbj; Thu, 19 Mar 2015 12:32:01 -0700 (PDT) X-Received: by 10.140.232.15 with SMTP id d15mr100484402qhc.52.1426793519688; Thu, 19 Mar 2015 12:31:59 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id 64si2215952qhe.36.2015.03.19.12.31.59 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 19 Mar 2015 12:31:59 -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 1YYg9v-0004pD-0R; Thu, 19 Mar 2015 19:31:11 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YYg9t-0004lz-NS for xen-devel@lists.xenproject.org; Thu, 19 Mar 2015 19:31:09 +0000 Received: from [85.158.137.68] by server-16.bemta-3.messagelabs.com id 5D/6C-01563-CF32B055; Thu, 19 Mar 2015 19:31:08 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-4.tower-31.messagelabs.com!1426793468!13770953!1 X-Originating-IP: [74.125.82.175] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.13.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 13829 invoked from network); 19 Mar 2015 19:31:08 -0000 Received: from mail-we0-f175.google.com (HELO mail-we0-f175.google.com) (74.125.82.175) by server-4.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 19 Mar 2015 19:31:08 -0000 Received: by wetk59 with SMTP id k59so65625097wet.3 for ; Thu, 19 Mar 2015 12:31:07 -0700 (PDT) X-Received: by 10.194.122.196 with SMTP id lu4mr156434918wjb.154.1426793467933; Thu, 19 Mar 2015 12:31:07 -0700 (PDT) Received: from chilopoda.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id hl8sm3203005wjb.38.2015.03.19.12.31.06 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2015 12:31:07 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 19 Mar 2015 19:29:46 +0000 Message-Id: <1426793399-6283-21-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1426793399-6283-1-git-send-email-julien.grall@linaro.org> References: <1426793399-6283-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 v4 20/33] 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.215.48 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 maximum size of the copied string has been chosen based on the value use by XSM in similar case. Furthermore, Linux seems to allow path up to 4096 characters. Though this could vary from one OS to another. Signed-off-by: Julien Grall --- Changes in v4: - Drop DEVICE_TREE_MAX_PATHLEN - Bump the value to PAGE_SIZE (i.e 4096). It's used in XSM and this value seems sensible for Linux - Clarify how the maximum size has been chosen 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 | 18 ++++++++++++++++++ xen/include/xen/device_tree.h | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 02cae91..31f169b 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,22 @@ 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, PAGE_SIZE); + 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 57eb3ee..e187780 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -456,6 +456,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