From patchwork Tue May 21 17:37:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 10954367 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A4F8313AD for ; Tue, 21 May 2019 17:39:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AED9288C7 for ; Tue, 21 May 2019 17:39:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79EF328A85; Tue, 21 May 2019 17:39:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1A7A9288C7 for ; Tue, 21 May 2019 17:39:25 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hT8i5-0007Z0-73; Tue, 21 May 2019 17:37:57 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hT8i4-0007Yf-59 for xen-devel@lists.xenproject.org; Tue, 21 May 2019 17:37:56 +0000 X-Inumbo-ID: 29ba55bd-7bef-11e9-8980-bc764e045a96 Received: from mail-lf1-x144.google.com (unknown [2a00:1450:4864:20::144]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 29ba55bd-7bef-11e9-8980-bc764e045a96; Tue, 21 May 2019 17:37:54 +0000 (UTC) Received: by mail-lf1-x144.google.com with SMTP id f1so13766714lfl.6 for ; Tue, 21 May 2019 10:37:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tSMA8QyqFc8QL3sLZnnhSEVNYV9FEcTYvBxJXAcykl8=; b=n3Is9VcDyA737g+CrDnIYIbQ7Jq+Tw5EmQh3+9yhQlQzslfXLIV2sdP8c1QMIG2+f8 k/5uUXiaZ5mr7tZyKpaIhiO/5AD59lpqax67SRX/AQLJY25Bi1xpiNbJe9AGEBckSE7L 62Aa6hEzAGj46kZSGvWIhJq/fZCCAmof193hqr1FtUUI0RGTzqf1GzMTtVheVdzIe6uk Eu5caUa2AFhOHZH2YsoFQYF5W7FeMpG2++glXYcLAGURlQA+LCu6ajK4YIgBnaGj/jKg siM8DppmJXjLbISsAeXFPtISgBbQ8542w8SdeNifn3bJWrUWoeXAbjX3wOgBe8vYEPPR 7Slw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tSMA8QyqFc8QL3sLZnnhSEVNYV9FEcTYvBxJXAcykl8=; b=B+yOYubMbHZOFyptQgTshcUcZKY76aIrz4ZoWQ64VGjcHb8IE8xoLa9C88inZ7ENbb J/BiwCPNnXsfKAfwtMhCkHSb7u81+ASn6dpbAJ/pq6jPcjjyAMjV3UsZHwboiGi3rErW vFq3eVZQ61/MCGsebQMwRJMgIj9ebIhH1l3dslTteEYa5DueRLOgn5FSoZj6vMb+4gvX gvTJOKQH1CCC/jST0Ks87H+9EcuYni2cy3FnTUDfmYOAzAz7KORGNmeJiCDyiuFzBY0c kF34hG6NBhrRcldkr4y36tJyrEL777TnsXfJ1ECmJqxQvN5Cseh6phSDasjMKluGrjcx hI2Q== X-Gm-Message-State: APjAAAW++fxck970OcZ+1vICQ5PaPRU9lKDAm4J0SFICIOMQ+CGvpGeK +3fbq1XfrTQAf9v2LmV0K6395iEmdcg= X-Google-Smtp-Source: APXvYqx4gtZ5kbgyjl8OcA6itnnfJtEp+CA0vz4g7b5FiN6uQ52b28IPSE2RRFhunb0qWjMalh2/Zw== X-Received: by 2002:ac2:510b:: with SMTP id q11mr39598394lfb.11.1558460273136; Tue, 21 May 2019 10:37:53 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id w19sm4827807lfk.56.2019.05.21.10.37.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 May 2019 10:37:52 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Tue, 21 May 2019 20:37:33 +0300 Message-Id: <1558460254-7127-2-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1558460254-7127-1-git-send-email-olekstysh@gmail.com> References: <1558460254-7127-1-git-send-email-olekstysh@gmail.com> Subject: [Xen-devel] [PATCH V1 1/2] xen/device-tree: Add dt_count_phandle_with_args helper X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Oleksandr Tyshchenko , julien.grall@arm.com, sstabellini@kernel.org MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Tyshchenko Port Linux helper of_count_phandle_with_args for counting number of phandles in a property. Please note, this helper is ported from Linux v4.6. Signed-off-by: Oleksandr Tyshchenko Acked-by: Julien Grall --- Changes RFC -> V1: - Add Linux version which is used as the base. --- xen/common/device_tree.c | 7 +++++++ xen/include/xen/device_tree.h | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 8fc401d..65862b5 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -1663,6 +1663,13 @@ int dt_parse_phandle_with_args(const struct dt_device_node *np, index, out_args); } +int dt_count_phandle_with_args(const struct dt_device_node *np, + const char *list_name, + const char *cells_name) +{ + return __dt_parse_phandle_with_args(np, list_name, cells_name, 0, -1, NULL); +} + /** * unflatten_dt_node - Alloc and populate a device_node from the flat tree * @fdt: The parent device tree blob diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 7408a6c..8315629 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -738,6 +738,25 @@ int dt_parse_phandle_with_args(const struct dt_device_node *np, const char *cells_name, int index, struct dt_phandle_args *out_args); +/** + * dt_count_phandle_with_args() - Find the number of phandles references in a property + * @np: pointer to a device tree node containing a list + * @list_name: property name that contains a list + * @cells_name: property name that specifies phandles' arguments count + * + * Returns the number of phandle + argument tuples within a property. It + * is a typical pattern to encode a list of phandle and variable + * arguments into a single property. The number of arguments is encoded + * by a property in the phandle-target node. For example, a gpios + * property would contain a list of GPIO specifies consisting of a + * phandle and 1 or more arguments. The number of arguments are + * determined by the #gpio-cells property in the node pointed to by the + * phandle. + */ +int dt_count_phandle_with_args(const struct dt_device_node *np, + const char *list_name, + const char *cells_name); + #ifdef CONFIG_DEVICE_TREE_DEBUG #define dt_dprintk(fmt, args...) \ printk(XENLOG_DEBUG fmt, ## args) From patchwork Tue May 21 17:37:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 10954369 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 349F8912 for ; Tue, 21 May 2019 17:39:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D255288C7 for ; Tue, 21 May 2019 17:39:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0EB2228A85; Tue, 21 May 2019 17:39:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 96A93288C7 for ; Tue, 21 May 2019 17:39:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hT8i6-0007ZG-H6; Tue, 21 May 2019 17:37:58 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hT8i5-0007Z3-F4 for xen-devel@lists.xenproject.org; Tue, 21 May 2019 17:37:57 +0000 X-Inumbo-ID: 2a6c73fb-7bef-11e9-8980-bc764e045a96 Received: from mail-lj1-x244.google.com (unknown [2a00:1450:4864:20::244]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2a6c73fb-7bef-11e9-8980-bc764e045a96; Tue, 21 May 2019 17:37:55 +0000 (UTC) Received: by mail-lj1-x244.google.com with SMTP id 14so589432ljj.5 for ; Tue, 21 May 2019 10:37:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8leobNo8c5zJn8nea1I3vKHELw8YOlIeOp8aiTKA0Y4=; b=QN+b2YPpag8Z1tfdsbHtSEYxbm+SV0AUNM0CWP+HbsBS7P3b6khyAK5iGQdHJXYzO/ 3nVLZsyl0YL5TSOnw6ca2tQzac97J0RqbvwcOnt0LcM3J5uxvBiSuwgJ7kFj3EbpbInr Co+wc1pQ1ie33qBJqCfMj63BlkepeDyRtO12TPXKv5cbMsbvj6522nddF02kk0CNGMLN K0KmZ+rXjJPynjoTan8mMbrMxCinVtUQWITB9RyoSCmEqxcdCJPKgbPo2owUCK1cLPZa ACe8zl9V9iVPCh2AQuDGe74KNZDDAnUS/A9BNqEPcKq4ZmC1YichQDJPZimPHdstghlE hqPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8leobNo8c5zJn8nea1I3vKHELw8YOlIeOp8aiTKA0Y4=; b=p2zWhntkvxVRLOiNKXDerhJUKTTLyj1SjGiCaNMIM8KYIYnfjdvuMj/pTD+MSWuyFK dUBOAQsB1Wtjxn6p2JhjrnZV4mxC/gTIZNd2ux0TS0OqhyqB3GQSm0hsVk713dymhNpI SmRZ9bWmZSnv7/1xa0xwzA2lEcIl3BRyMXOgbBoKxD0/knZL28tiMhTwZSdnYJyCa0ni 2CeRtuq4PtRoNwQJtfL+p3DZgh6rj6zwGHSRJiSjYUGVH60WeEz+g9RmxqcsCZeRbpyp 87vPjnA2XbbjzzGfNFMk2e2uynCLAfjycq7nRL62i1i1607a6BJRNsseM5FrpEd88udO LSyQ== X-Gm-Message-State: APjAAAXBxOdhfT6vPUTbh3+Rm8dfTajT2EjWChj3FPCeFoqgIvF2xU1e HqIX+wl4BWqhdlRdFMhbzmKWmwfnLB0= X-Google-Smtp-Source: APXvYqz0NpZ5kbWUvh/STWlpfeuve8l+qwDnEVqqHJRQ2fBYdHSUxflMTDO3eVvKfBqbsrj+IJJClA== X-Received: by 2002:a2e:81cf:: with SMTP id s15mr41552994ljg.193.1558460274285; Tue, 21 May 2019 10:37:54 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id w19sm4827807lfk.56.2019.05.21.10.37.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 May 2019 10:37:53 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Tue, 21 May 2019 20:37:34 +0300 Message-Id: <1558460254-7127-3-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1558460254-7127-1-git-send-email-olekstysh@gmail.com> References: <1558460254-7127-1-git-send-email-olekstysh@gmail.com> Subject: [Xen-devel] [PATCH V1 2/2] xen/device-tree: Add ability to handle nodes with interrupts-extended prop X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Oleksandr Tyshchenko , julien.grall@arm.com, sstabellini@kernel.org MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Tyshchenko The "interrupts-extended" property is a special form for use when a node needs to reference multiple interrupt parents. According to the: Linux/Documentation/devicetree/bindings/interrupt-controller/interrupts.txt But, there are cases when "interrupts-extended" property is used for "outside /soc node" with a single interrupt parent as an equivalent of pairs ("interrupt-parent" + "interrupts"). The good example here is ARCH timer node for R-Car Gen3/Gen2 family, which is mandatory device for Xen usage on ARM. And without ability to handle such nodes, Xen fails to operate. So, this patch adds required support for Xen to be able to handle nodes with that property. Signed-off-by: Oleksandr Tyshchenko Reviewed-by: Stefano Stabellini --- Changes RFC -> V1: - Explain in the commit message regarding property usage, add a link to the bindings. - Don't try to look for "interrupts" property if "interrupts-extended" property is present, but doesn't contain any interrupts (dt_count_phandle_with_args returns 0). - Add messages to tell which property is used. --- xen/common/device_tree.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 65862b5..e107c6f 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -987,15 +987,27 @@ unsigned int dt_number_of_irq(const struct dt_device_node *device) const struct dt_device_node *p; const __be32 *intspec, *tmp; u32 intsize, intlen; + int intnum; dt_dprintk("dt_irq_number: dev=%s\n", device->full_name); + /* Try the new-style interrupts-extended first */ + intnum = dt_count_phandle_with_args(device, "interrupts-extended", + "#interrupt-cells"); + if ( intnum >= 0 ) + { + dt_dprintk(" using 'interrupts-extended' property\n"); + dt_dprintk(" intnum=%d\n", intnum); + return intnum; + } + /* Get the interrupts property */ intspec = dt_get_property(device, "interrupts", &intlen); if ( intspec == NULL ) return 0; intlen /= sizeof(*intspec); + dt_dprintk(" using 'interrupts' property\n"); dt_dprintk(" intspec=%d intlen=%d\n", be32_to_cpup(intspec), intlen); /* Look for the interrupt parent. */ @@ -1420,21 +1432,39 @@ int dt_device_get_raw_irq(const struct dt_device_node *device, const __be32 *intspec, *tmp, *addr; u32 intsize, intlen; int res = -EINVAL; + struct dt_phandle_args args; + int i; dt_dprintk("dt_device_get_raw_irq: dev=%s, index=%u\n", device->full_name, index); + /* Get the reg property (if any) */ + addr = dt_get_property(device, "reg", NULL); + + /* Try the new-style interrupts-extended first */ + res = dt_parse_phandle_with_args(device, "interrupts-extended", + "#interrupt-cells", index, &args); + if ( !res ) + { + dt_dprintk(" using 'interrupts-extended' property\n"); + dt_dprintk(" intspec=%d intsize=%d\n", args.args[0], args.args_count); + + for ( i = 0; i < args.args_count; i++ ) + args.args[i] = cpu_to_be32(args.args[i]); + + return dt_irq_map_raw(args.np, args.args, args.args_count, + addr, out_irq); + } + /* Get the interrupts property */ intspec = dt_get_property(device, "interrupts", &intlen); if ( intspec == NULL ) return -EINVAL; intlen /= sizeof(*intspec); + dt_dprintk(" using 'interrupts' property\n"); dt_dprintk(" intspec=%d intlen=%d\n", be32_to_cpup(intspec), intlen); - /* Get the reg property (if any) */ - addr = dt_get_property(device, "reg", NULL); - /* Look for the interrupt parent. */ p = dt_irq_find_parent(device); if ( p == NULL )