From patchwork Thu May 2 14:13:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 10926921 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 6245713AD for ; Thu, 2 May 2019 14:16:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51A4A24BFE for ; Thu, 2 May 2019 14:16:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 456062640A; Thu, 2 May 2019 14:16:02 +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 C8DC924BFE for ; Thu, 2 May 2019 14:16:01 +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 1hMCTx-0001VN-EZ; Thu, 02 May 2019 14:14:41 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hMCTv-0001V5-J6 for xen-devel@lists.xenproject.org; Thu, 02 May 2019 14:14:39 +0000 X-Inumbo-ID: 9e8fce8e-6ce4-11e9-843c-bc764e045a96 Received: from mail-lj1-x244.google.com (unknown [2a00:1450:4864:20::244]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 9e8fce8e-6ce4-11e9-843c-bc764e045a96; Thu, 02 May 2019 14:14:38 +0000 (UTC) Received: by mail-lj1-x244.google.com with SMTP id h21so2291458ljk.13 for ; Thu, 02 May 2019 07:14:38 -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=czcrQJ4ZOkigVhUXJ1PqpCqEbSt+PWnfNBwK7rAOIVo=; b=HggtKAWincswp8O2AwNnv0IVbVU+lVSKShIk/+ZJ2A0UTcX0jEe6Vhm0LjSN+pLA+6 fIaiIsxyTfR3npN1xPsqALFShEJkMz0KnlsF7rPVPspQ5rMrScdnmB/Dchi1Vh7pFRTU R1et7HwuOCihJm9kH60eAHq3H9/n00o6bb04GmwMAw7ECj4Sx2EC5JxJ3UbmVKPQSWaH 9ucgdRQ0wsANIQDArMgdZNxFk5YuOod015U5nJEQyxkIK/yb0VdVkmivFgpxyDeke/3j d82w55+qdb2KejIfP/SEOc0P8wwVrFnZf9pmOsGqjjNBlXtmMSqRzOBny1oROHqXHwj2 rphA== 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=czcrQJ4ZOkigVhUXJ1PqpCqEbSt+PWnfNBwK7rAOIVo=; b=DLptbDWtA79EExGtI6XH2PFzDntwMY1Gfe9TZ41E45PK3DM8O7SsOf83e9jDYZkqOq lNRL15mce7U2dTkJWgsxahVf78KEPAaCxwj7H9XBLjsM9V4xVSyFZS8aUHmWxDIWqEo/ pKkW6gdrAPOvAvZXgnKCa7096hWVPq0n7osJarHURlQXB0b4H4zAvNRug9Ayh3riL4Z0 rmSWicQkWEkhJkR89JIcfNqIB4bBDwn1kYSOLqsjv+ZUljSzgTE+eDsAgTT9u2IdUmK/ X5caeiTIseDW7ucTvazMyRKnK+KN8kmMOA/rlmmEj5NvfioInMm/j/7cZ9X32uHrGX6P AYTg== X-Gm-Message-State: APjAAAU/56npV+qTGLAFgT7csiNefy0/AxbBSTog7N8+6EuUVbU+WL4R UYdHg+lapkYcp9onoPP1jlSFKq21DqA= X-Google-Smtp-Source: APXvYqxwvUq+coxxlISjHlNCZ3dkTi2eTt9o3LlhLai1hthYE5COmHJ43XZFMVCDMJTuwrIKKi55Yg== X-Received: by 2002:a2e:5c49:: with SMTP id q70mr2092746ljb.16.1556806477373; Thu, 02 May 2019 07:14:37 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-22.209.223.85.sovam.net.ua. [85.223.209.22]) by smtp.gmail.com with ESMTPSA id v11sm9447761lfb.68.2019.05.02.07.14.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 May 2019 07:14:36 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Thu, 2 May 2019 17:13:55 +0300 Message-Id: <1556806436-26283-2-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556806436-26283-1-git-send-email-olekstysh@gmail.com> References: <1556806436-26283-1-git-send-email-olekstysh@gmail.com> Subject: [Xen-devel] [RFC PATCH 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. Signed-off-by: Oleksandr Tyshchenko --- 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 Thu May 2 14:13:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Tyshchenko X-Patchwork-Id: 10926923 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 5D11714B6 for ; Thu, 2 May 2019 14:16:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CBBE223B3 for ; Thu, 2 May 2019 14:16:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 414A423B34; Thu, 2 May 2019 14:16:28 +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 BAA46223B3 for ; Thu, 2 May 2019 14:16:27 +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 1hMCTy-0001Vd-Na; Thu, 02 May 2019 14:14:42 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hMCTw-0001VI-QA for xen-devel@lists.xenproject.org; Thu, 02 May 2019 14:14:40 +0000 X-Inumbo-ID: 9f4075ee-6ce4-11e9-843c-bc764e045a96 Received: from mail-lj1-x243.google.com (unknown [2a00:1450:4864:20::243]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 9f4075ee-6ce4-11e9-843c-bc764e045a96; Thu, 02 May 2019 14:14:40 +0000 (UTC) Received: by mail-lj1-x243.google.com with SMTP id s7so2354647ljh.1 for ; Thu, 02 May 2019 07:14:39 -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=Bhy8ERTYdfSjiRGGOCL7/5SLLcwd2wNxUdxXkfyMshc=; b=oL7gET7CqS0nwJMPi9sVDkudmZ6vHVbWK4OxvW9b1QuKabOXthovk/BTUqFv1zIgL9 jCiDBY6pQfRVE2ZhC05l/kLlug3xDaor35IPKkfSmfpClpPxr4uOaUNDIFq05MR7LCHi TF6wGnnacoc0KbXs88InyJtXhpaKirStL53ZDW3DVk4MzKBKacGVD8xZDPXLHhsuAe48 lluUKExaXou/9mRZSRPR8lIsU7hFbz12uuH/hDy5AWmIhfoanSm2AGSYRDi3posP8o63 N+kBWh9IXVqZHb8COgB3DIypyOtKyox19W3qvdr4B0+jBcbYqfIscqdlmY/ILX7ggTZF vfpA== 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=Bhy8ERTYdfSjiRGGOCL7/5SLLcwd2wNxUdxXkfyMshc=; b=mnm6eF72kODH3Mv2dj2zbxHo64qsK8vSWKNW93hpo46+x9nn3sEcVUP5XjF0Kc6bIN cQ079WIquTxo+9y2YLNrAAC24Ytlgy+Bi0cMxK2Ps3LNHoY+1U2Y7Q7O6YvTyRPiwhza LpI+1uacNsnHoFG+BdWpdK0AbNYdqyTqzuESsnq89AQ5A6Iu5NUC32h5st+bnvU4RDF5 FP1xe6J4QURin739Kig/P5FpvFD7ot87jcuFVqMoPKVfm5CaIrDhPEh/uUR3TCCMVU/G rYSm3rYfaML/DmZ9NBeicPu+rw4Rwp6FhX37XguZSUGX9SL1bpnGcuQgPUgCSmJoXq3z 9ZwQ== X-Gm-Message-State: APjAAAXsJmy2CLtgzEsD7jm3vt5BvAMlCm/VxfEeKRQjEH6uo+xNGgcu oqaviR9Qu78OW4jaCOdXiP73BOofRo0= X-Google-Smtp-Source: APXvYqzkfAPQBzM3yV+K++/uKYeax21hyP5PpNdsLi4HIMAENkQK/EK2uervWNIe2rf6A8k1HGYaLg== X-Received: by 2002:a2e:428c:: with SMTP id h12mr2047959ljf.26.1556806478511; Thu, 02 May 2019 07:14:38 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-22.209.223.85.sovam.net.ua. [85.223.209.22]) by smtp.gmail.com with ESMTPSA id v11sm9447761lfb.68.2019.05.02.07.14.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 May 2019 07:14:37 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Thu, 2 May 2019 17:13:56 +0300 Message-Id: <1556806436-26283-3-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556806436-26283-1-git-send-email-olekstysh@gmail.com> References: <1556806436-26283-1-git-send-email-olekstysh@gmail.com> Subject: [Xen-devel] [RFC PATCH 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 Xen expects to see "interrupts" property when parsing host device-tree. But, there are cases when some device nodes contain "interrupts-extended" property instead. 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: (XEN) **************************************** (XEN) Panic on CPU 0: (XEN) Timer: Unable to retrieve IRQ 0 from the device tree (XEN) **************************************** Signed-off-by: Oleksandr Tyshchenko --- xen/common/device_tree.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 65862b5..00ada6e 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -987,9 +987,19 @@ 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(" intnum=%d\n", intnum); + return intnum; + } + /* Get the interrupts property */ intspec = dt_get_property(device, "interrupts", &intlen); if ( intspec == NULL ) @@ -1420,10 +1430,29 @@ 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(" 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 ) @@ -1432,9 +1461,6 @@ int dt_device_get_raw_irq(const struct dt_device_node *device, 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 )