From patchwork Mon Oct 12 16:48:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 54808 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 patches.linaro.org (Postfix) with ESMTPS id 3C04523001 for ; Mon, 12 Oct 2015 16:49:06 +0000 (UTC) Received: by wijq8 with SMTP id q8sf36762329wij.1 for ; Mon, 12 Oct 2015 09:49:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=RFwsUFcAvSapdlWmsYdPF07ZwDy9X+zmCOYlhI+oBX8=; b=GLuU5OZcVlo012kD8cRB03U0OM/wkwAfko9GGiSp+gh0RH2m2KYhp0QfEUNMP5DB/y IuWVCDKPCfK+eAItD5gSZh+b1dBNo0AYqDjMDlyXj3wQVH8Jw+QVvwSOVTrPkMmcrDo2 gMIqHrs0R5HSaEsa3IuFGcjCg7vItK7Rk6dSE1ZAOFMWH0heEu6pC1Y0OqZsJPuUR+qU WHUt/NlmIA4RwANkUGVktokREXgeQTDJ32yL3qK6RUS83vcj+2FseEFW77kfo5urLOiF wMKR01D2K+u4+yuAEIt0+PPmpiiBNWCl/lCH+SHNvYwETFeGZt/SQZwYyKvCEuc61jpE g37Q== X-Gm-Message-State: ALoCoQnJfz0VEaJY+y/6N2umLRuO4js8I9qc5ShVNiFafW4aB6Tn5YqEc8v09KEP8XDDCj2fygw5 X-Received: by 10.112.12.132 with SMTP id y4mr5840668lbb.0.1444668545555; Mon, 12 Oct 2015 09:49:05 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.25.67 with SMTP id 64ls580321lfz.41.gmail; Mon, 12 Oct 2015 09:49:05 -0700 (PDT) X-Received: by 10.25.153.147 with SMTP id b141mr8722539lfe.59.1444668545419; Mon, 12 Oct 2015 09:49:05 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id p192si11810095lfd.147.2015.10.12.09.49.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Oct 2015 09:49:05 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbbk10 with SMTP id k10so36803862lbb.0 for ; Mon, 12 Oct 2015 09:49:05 -0700 (PDT) X-Received: by 10.25.28.81 with SMTP id c78mr4494974lfc.29.1444668545306; Mon, 12 Oct 2015 09:49:05 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1650609lbq; Mon, 12 Oct 2015 09:49:04 -0700 (PDT) X-Received: by 10.194.175.104 with SMTP id bz8mr31538715wjc.42.1444668542064; Mon, 12 Oct 2015 09:49:02 -0700 (PDT) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com. [209.85.212.181]) by mx.google.com with ESMTPS id hp14si17079371wib.63.2015.10.12.09.49.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Oct 2015 09:49:02 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.181 as permitted sender) client-ip=209.85.212.181; Received: by wicgb1 with SMTP id gb1so57675824wic.1 for ; Mon, 12 Oct 2015 09:49:01 -0700 (PDT) X-Received: by 10.194.84.42 with SMTP id v10mr35185429wjy.1.1444668541893; Mon, 12 Oct 2015 09:49:01 -0700 (PDT) Received: from localhost.localdomain.home (LCaen-156-56-7-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id xt1sm20805130wjb.32.2015.10.12.09.48.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Oct 2015 09:49:01 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, alex.williamson@redhat.com Cc: patches@linaro.org, christoffer.dall@linaro.org, pbonzini@redhat.com, b.reynal@virtualopensystems.com, suravee.suthikulpanit@amd.com, thomas.lendacky@amd.com Subject: [RFC 5/6] hw/arm/sysbus-fdt: helpers for clock node generation Date: Mon, 12 Oct 2015 16:48:42 +0000 Message-Id: <1444668523-2252-6-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1444668523-2252-1-git-send-email-eric.auger@linaro.org> References: <1444668523-2252-1-git-send-email-eric.auger@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@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.172 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Some passthrough'ed devices depend on clock nodes. Those need to be generated in the guest device tree. This patch introduces some helpers to build a clock node from information retrieved from host device tree. - inherit_properties copies properties from a host device tree node to a guest device tree node - fdt_build_clock_node builds a guest clock node and checks the host fellow clock is a fixed one. fdt_build_clock_node will become static as soon as a they get used Signed-off-by: Eric Auger --- hw/arm/sysbus-fdt.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c index 9d28797..22e5801 100644 --- a/hw/arm/sysbus-fdt.c +++ b/hw/arm/sysbus-fdt.c @@ -21,6 +21,7 @@ * */ +#include #include "hw/arm/sysbus-fdt.h" #include "qemu/error-report.h" #include "sysemu/device_tree.h" @@ -56,6 +57,115 @@ typedef struct NodeCreationPair { int (*add_fdt_node_fn)(SysBusDevice *sbdev, void *opaque); } NodeCreationPair; +/* helpers */ + +struct HostProperty { + const char *name; + bool optional; +}; + +typedef struct HostProperty HostProperty; + +/** + * inherit_properties + * + * copies properties listed in an array from host device tree to + * guest device tree. If a non optional property is not found, the + * function exits. Not found optional ones are ignored. + * props: array of HostProperty to copy + * nb_props: number of properties in the array + * host_dt: host device tree blob + * guest_dt: guest device tree blob + * node_path: host dt node path where the property is supposed to be + found + * nodename: guest node name the properties should be added to + * + */ +static void inherit_properties(HostProperty *props, int nb_props, + void *host_fdt, void *guest_fdt, + char *node_path, char *nodename) +{ + int i, prop_len; + const void *r; + + for (i = 0; i < nb_props; i++) { + r = qemu_fdt_getprop_optional(host_fdt, node_path, + props[i].name, + props[i].optional, + &prop_len); + if (r) { + qemu_fdt_setprop(guest_fdt, nodename, + props[i].name, r, prop_len); + } + } +} + +/* clock properties whose values are copied/pasted from host */ +static HostProperty clock_inherited_properties[] = { + {"compatible", 0}, + {"#clock-cells", 0}, + {"clock-frequency", 1}, + {"clock-output-names", 1}, +}; + +/** + * fdt_build_clock_node + * + * Build a guest clock node, used as a dependency from a passthrough'ed + * device. Most information are retrieved from the host fellow node. + * Also check the host clock is a fixed one. + * + * host_fdt: host device tree blob from which info are retrieved + * guest_fdt: guest device tree blob where the clock node is added + * host_phandle: phandle of the clock in host device tree + * guest_phandle: phandle to assign to the guest node + */ +int fdt_build_clock_node(void *host_fdt, void *guest_fdt, + uint32_t host_phandle, + uint32_t guest_phandle); +int fdt_build_clock_node(void *host_fdt, void *guest_fdt, + uint32_t host_phandle, + uint32_t guest_phandle) +{ + char node_path[256]; + char *nodename; + const void *r; + int ret, prop_len; + + ret = fdt_node_offset_by_phandle(host_fdt, host_phandle); + if (ret <= 0) { + error_report("not able to locate clock handle %d in host device tree\n", + host_phandle); + goto out; + } + ret = fdt_get_path(host_fdt, ret, node_path, 256); + if (ret < 0) { + error_report("not able to retrieve node path for clock handle %d\n", + host_phandle); + goto out; + } + + r = qemu_fdt_getprop(host_fdt, node_path, "compatible", &prop_len); + if (strcmp(r, "fixed-clock")) { + error_report("clock handle %d is not a fixed clock\n", host_phandle); + ret = -1; + goto out; + } + + nodename = strrchr(node_path, '/'); + qemu_fdt_add_subnode(guest_fdt, nodename); + + inherit_properties(clock_inherited_properties, + ARRAY_SIZE(clock_inherited_properties), + host_fdt, guest_fdt, + node_path, nodename); + + qemu_fdt_setprop_cell(guest_fdt, nodename, "phandle", guest_phandle); + +out: + return ret; +} + /* Device Specific Code */ /**