From patchwork Thu Nov 19 15:22:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 57024 Delivered-To: patches@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp3244855lbb; Thu, 19 Nov 2015 07:22:30 -0800 (PST) X-Received: by 10.28.15.146 with SMTP id 140mr13969760wmp.79.1447946541062; Thu, 19 Nov 2015 07:22:21 -0800 (PST) Return-Path: Received: from mail-wm0-x22f.google.com (mail-wm0-x22f.google.com. [2a00:1450:400c:c09::22f]) by mx.google.com with ESMTPS id bw7si11939750wjb.40.2015.11.19.07.22.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Nov 2015 07:22:21 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22f as permitted sender) client-ip=2a00:1450:400c:c09::22f; Authentication-Results: mx.google.com; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22f as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dkim=pass header.i=@linaro-org.20150623.gappssmtp.com Received: by wmww144 with SMTP id w144so242970825wmw.1 for ; Thu, 19 Nov 2015 07:22:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ibG/X+FCqU88Fa17mVaPwzqjzFflb6oUWsB98AHMVVI=; b=gJ5cCmAQ4KHFQxHDPM/dJTBYKtj4oGcbRzHeFxsgZCJyS6+ckilR/e1HTOrNnBY/E9 K7rDfG6tBSJ7j6243qqWfyITknTU8OtN4Af9sSEtJFxZPEFsW8DiTu2n8BjC3r5XHmP7 Q2pcRsPCuaudTcxGXP/ObBjWddNUvtUqjKv0DyBimI7WDNnpf+8u4Fmu4iI1dFwHm9Kv NUV+jYxp++YcHD6on094vlLRlZuOk/JtnUZsN5jDKC5/rzNX7fg9ym+CTJJxuEwyB6NP nFhRKfiMuPbMHOKbr0LMyPnygn8ASUy1Qaxdpvssz4A/7QZ8IGIuHsnx8GNsl+MLZ5lv lXBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ibG/X+FCqU88Fa17mVaPwzqjzFflb6oUWsB98AHMVVI=; b=EBVQjDivuFqcSnOIsilqXpXTfW2VbiRB9lOpEXflp4TxvGNKwYw5jgu2vsO+DvcC7p wDv6wbDWgQ41E6DhtmAl4QYTn3HZwM7+f6fuBEvs0ChHOVqlekzgZcT18im7lTasTfts 2QFdjOQScn+TP+VfObCzBL8lPKAbt2ig7mPFclQs2WamSTyxRS7nIZ1VOi44ivN8kACV l5f5xj4cVy2Y2TriiNDG/6fEk1YzGY+Y+y7V6M7aH0X+BVGVqxQXkNW6jHbpLy8ghph6 GjTJcIyRXwEF811RY1TV6UUax5/iLHx0hPsdHtZVh2hBqJEAqvdlweqJdu/sjdwhd25b Ac0g== X-Gm-Message-State: ALoCoQmbS8Si1+3cRbF6bQOb+/lbQP+TLwTgF8nCyhVJF8bD+tNiFY7hxT/bVBQIWpWxe4AKfYGb X-Received: by 10.194.243.227 with SMTP id xb3mr9665657wjc.96.1447946540880; Thu, 19 Nov 2015 07:22:20 -0800 (PST) Return-Path: Received: from midway01-04-00.lavalab ([81.128.185.50]) by smtp.gmail.com with ESMTPSA id vr10sm8367221wjc.38.2015.11.19.07.22.19 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Nov 2015 07:22:20 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org, alex.williamson@redhat.com, peter.maydell@linaro.org Cc: patches@linaro.org, christoffer.dall@linaro.org, pbonzini@redhat.com, b.reynal@virtualopensystems.com, suravee.suthikulpanit@amd.com, thomas.lendacky@amd.com Subject: [RESEND RFC 5/6] hw/arm/sysbus-fdt: helpers for clock node generation Date: Thu, 19 Nov 2015 15:22:07 +0000 Message-Id: <1447946528-1533-6-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1447946528-1533-1-git-send-email-eric.auger@linaro.org> References: <1447946528-1533-1-git-send-email-eric.auger@linaro.org> 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(+) -- 1.8.3.2 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 */ /**