From patchwork Thu May 27 19:45:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 12285207 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86CCFC47089 for ; Thu, 27 May 2021 19:45:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 61083613E2 for ; Thu, 27 May 2021 19:45:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235610AbhE0Tra (ORCPT ); Thu, 27 May 2021 15:47:30 -0400 Received: from mail-ot1-f50.google.com ([209.85.210.50]:44882 "EHLO mail-ot1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235580AbhE0Tr1 (ORCPT ); Thu, 27 May 2021 15:47:27 -0400 Received: by mail-ot1-f50.google.com with SMTP id r26-20020a056830121ab02902a5ff1c9b81so1305451otp.11; Thu, 27 May 2021 12:45:52 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=68t16l/dJX8qwP/jSm8KvVZZuN7st3omJGcvkjXgwLg=; b=H7UFJUEpiTJY8aF+3j89y9nL8al1p4ixoggkqDWg20okGE3dDit0W9y2zG6vskbErW NICm5jhDqqMLXdeDafN5YVeLOFKcntcTCM2lICN9uv/njVxtdZBAqVYUevNOyYwn4m5F qswaZ+cmrHWuFDHct3AhiVymDOt9tPoICQl4GQZWnPIs6N6pJInzm6/ndb0NF8cOw+lF oI4EH94ZprKq0sC6VKaNJ55RpxdAiQZ04am5xF6Dvfg5KVy52rM/Wl+hRE+/42JScZ3y qGCMdhJdnVgTKtmabU2xEM2fCIxiDmdMJK9YQSwRd3b6xWDdsSw/lmmDTvL+xWFQMmlG ji6w== X-Gm-Message-State: AOAM5311RHXUigbq0otf+FSQEfq70kimMaDPSWKlpFkRFfVnPSEU7Bht YYSKwIHGLEiKjAZHJjCPdROe/+biIA== X-Google-Smtp-Source: ABdhPJwpa9J1YIavtkMQ/XIxRGd/oD4XK0/YAu9s1s+yjaawXnmRb0JNQ0azt198SPfINVzh7aumig== X-Received: by 2002:a05:6830:2248:: with SMTP id t8mr4078086otd.156.1622144751692; Thu, 27 May 2021 12:45:51 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id m74sm665162oig.33.2021.05.27.12.45.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 12:45:50 -0700 (PDT) From: Rob Herring To: devicetree@vger.kernel.org, Frank Rowand Cc: linux-kernel@vger.kernel.org, Bjorn Helgaas , linux-pci@vger.kernel.org, Randy Dunlap Subject: [PATCH 1/4] PCI: Add empty stub for pci_register_io_range() Date: Thu, 27 May 2021 14:45:44 -0500 Message-Id: <20210527194547.1287934-2-robh@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210527194547.1287934-1-robh@kernel.org> References: <20210527194547.1287934-1-robh@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Add an empty stub for pci_register_io_range() when !CONFIG_PCI. It's needed to convert of_pci_range_to_resource() to use IS_ENABLED(CONFIG_PCI). Cc: Bjorn Helgaas Cc: linux-pci@vger.kernel.org Signed-off-by: Rob Herring Acked-by: Bjorn Helgaas --- include/linux/pci.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/pci.h b/include/linux/pci.h index c20211e59a57..29da7598f8d0 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1772,6 +1772,10 @@ static inline int pci_request_regions(struct pci_dev *dev, const char *res_name) { return -EIO; } static inline void pci_release_regions(struct pci_dev *dev) { } +static inline int pci_register_io_range(struct fwnode_handle *fwnode, + phys_addr_t addr, resource_size_t size) +{ return -EINVAL; } + static inline unsigned long pci_address_to_pio(phys_addr_t addr) { return -1; } static inline struct pci_bus *pci_find_next_bus(const struct pci_bus *from) From patchwork Thu May 27 19:45:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 12285209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D92AC47089 for ; Thu, 27 May 2021 19:46:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1141F613E2 for ; Thu, 27 May 2021 19:46:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235598AbhE0Trc (ORCPT ); Thu, 27 May 2021 15:47:32 -0400 Received: from mail-ot1-f54.google.com ([209.85.210.54]:36858 "EHLO mail-ot1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235583AbhE0Tra (ORCPT ); Thu, 27 May 2021 15:47:30 -0400 Received: by mail-ot1-f54.google.com with SMTP id h24-20020a9d64180000b029036edcf8f9a6so1347853otl.3; Thu, 27 May 2021 12:45:55 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=Pi/H1lXjgfAQTnfvqaLMcay9EXPe4HtbT57LknC592A=; b=LOqQgyU+uLyzYhNxOUcw3+QZe23my2Jp0Pbu2dd96TcUNMpZH2UsfwHSclTQiNJ2Rv 83V9Ic1h9h3Mi6XA1vEwBKVaKAnOBxYgCX6hYYY0no5EmTF5i7PFOFF8RH5kAdQqHKPl A7FuXWRnb9FykZS1Je6L8+HA5Q0j/0HjcjculxyjQrCezod6lIz/33JxK8OIq34rBmPg 4sLxOalzBIqMiOCWDgc2HbVZv0qGypSuP6wWea+kZ8x74leZCfu3jkXK1GgFh67sweF1 jtIgcm5gXSTlVsNh7u08NV2L2rNxJPJ/7VOa+VSenQSW9/dKFqQnvrTQLYpjwaZoyGD3 zX4Q== X-Gm-Message-State: AOAM531FtpfTs+riQOMImwaCKELO9omUyJNXLdwRIszVv+eA1M8Dm0Xz z2s/eINDkJX0AiryzpkAR14WP3NdLQ== X-Google-Smtp-Source: ABdhPJz8d7lXTCrm2c6ZH6WV0tiVxOdbyZOY3H5VzgeePbJTR9Xe6fIUxTihiQ/NFNlp5svXmJjaUA== X-Received: by 2002:a05:6830:1256:: with SMTP id s22mr3918924otp.333.1622144754150; Thu, 27 May 2021 12:45:54 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id m74sm665162oig.33.2021.05.27.12.45.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 12:45:52 -0700 (PDT) From: Rob Herring To: devicetree@vger.kernel.org, Frank Rowand Cc: linux-kernel@vger.kernel.org, Bjorn Helgaas , linux-pci@vger.kernel.org, Randy Dunlap Subject: [PATCH 2/4] of: Merge of_get_address() and of_get_pci_address() implementations Date: Thu, 27 May 2021 14:45:45 -0500 Message-Id: <20210527194547.1287934-3-robh@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210527194547.1287934-1-robh@kernel.org> References: <20210527194547.1287934-1-robh@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org of_get_address() and of_get_pci_address() are the same implementation except of_get_pci_address() takes the PCI BAR number rather than an index. Modify the of_get_address() implementation to work on either index or BAR and provide wrapper functions for the existing functions. Cc: Frank Rowand Signed-off-by: Rob Herring --- drivers/of/address.c | 62 ++++++++------------------------------ include/linux/of_address.h | 27 ++++++++++------- 2 files changed, 29 insertions(+), 60 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index aca94c348bd4..aa766437995c 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -199,50 +199,6 @@ static int of_bus_pci_translate(__be32 *addr, u64 offset, int na) return of_bus_default_translate(addr + 1, offset, na - 1); } -const __be32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size, - unsigned int *flags) -{ - const __be32 *prop; - unsigned int psize; - struct device_node *parent; - struct of_bus *bus; - int onesize, i, na, ns; - - /* Get parent & match bus type */ - parent = of_get_parent(dev); - if (parent == NULL) - return NULL; - bus = of_match_bus(parent); - if (strcmp(bus->name, "pci")) { - of_node_put(parent); - return NULL; - } - bus->count_cells(dev, &na, &ns); - of_node_put(parent); - if (!OF_CHECK_ADDR_COUNT(na)) - return NULL; - - /* Get "reg" or "assigned-addresses" property */ - prop = of_get_property(dev, bus->addresses, &psize); - if (prop == NULL) - return NULL; - psize /= 4; - - onesize = na + ns; - for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) { - u32 val = be32_to_cpu(prop[0]); - if ((val & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) { - if (size) - *size = of_read_number(prop + na, ns); - if (flags) - *flags = bus->get_flags(prop); - return prop; - } - } - return NULL; -} -EXPORT_SYMBOL(of_get_pci_address); - int of_pci_address_to_resource(struct device_node *dev, int bar, struct resource *r) { @@ -675,8 +631,8 @@ u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr) } EXPORT_SYMBOL(of_translate_dma_address); -const __be32 *of_get_address(struct device_node *dev, int index, u64 *size, - unsigned int *flags) +const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no, + u64 *size, unsigned int *flags) { const __be32 *prop; unsigned int psize; @@ -689,6 +645,10 @@ const __be32 *of_get_address(struct device_node *dev, int index, u64 *size, if (parent == NULL) return NULL; bus = of_match_bus(parent); + if (strcmp(bus->name, "pci") && (bar_no >= 0)) { + of_node_put(parent); + return NULL; + } bus->count_cells(dev, &na, &ns); of_node_put(parent); if (!OF_CHECK_ADDR_COUNT(na)) @@ -701,17 +661,21 @@ const __be32 *of_get_address(struct device_node *dev, int index, u64 *size, psize /= 4; onesize = na + ns; - for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) - if (i == index) { + for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) { + u32 val = be32_to_cpu(prop[0]); + /* PCI bus matches on BAR number instead of index */ + if (((bar_no >= 0) && ((val & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0))) || + ((index >= 0) && (i == index))) { if (size) *size = of_read_number(prop + na, ns); if (flags) *flags = bus->get_flags(prop); return prop; } + } return NULL; } -EXPORT_SYMBOL(of_get_address); +EXPORT_SYMBOL(__of_get_address); static int parser_init(struct of_pci_range_parser *parser, struct device_node *node, const char *name) diff --git a/include/linux/of_address.h b/include/linux/of_address.h index 88bc943405cd..b72807faf037 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -51,8 +51,8 @@ void __iomem *of_io_request_and_map(struct device_node *device, * the address space flags too. The PCI version uses a BAR number * instead of an absolute index */ -extern const __be32 *of_get_address(struct device_node *dev, int index, - u64 *size, unsigned int *flags); +extern const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no, + u64 *size, unsigned int *flags); extern int of_pci_range_parser_init(struct of_pci_range_parser *parser, struct device_node *node); @@ -75,8 +75,8 @@ static inline u64 of_translate_address(struct device_node *np, return OF_BAD_ADDR; } -static inline const __be32 *of_get_address(struct device_node *dev, int index, - u64 *size, unsigned int *flags) +static inline const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no, + u64 *size, unsigned int *flags) { return NULL; } @@ -125,8 +125,6 @@ static inline void __iomem *of_iomap(struct device_node *device, int index) #define of_range_parser_init of_pci_range_parser_init #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI) -extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no, - u64 *size, unsigned int *flags); extern int of_pci_address_to_resource(struct device_node *dev, int bar, struct resource *r); extern int of_pci_range_to_resource(struct of_pci_range *range, @@ -139,11 +137,6 @@ static inline int of_pci_address_to_resource(struct device_node *dev, int bar, return -ENOSYS; } -static inline const __be32 *of_get_pci_address(struct device_node *dev, - int bar_no, u64 *size, unsigned int *flags) -{ - return NULL; -} static inline int of_pci_range_to_resource(struct of_pci_range *range, struct device_node *np, struct resource *res) @@ -152,4 +145,16 @@ static inline int of_pci_range_to_resource(struct of_pci_range *range, } #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */ +static inline const __be32 *of_get_address(struct device_node *dev, int index, + u64 *size, unsigned int *flags) +{ + return __of_get_address(dev, index, -1, size, flags); +} + +static inline const __be32 *of_get_pci_address(struct device_node *dev, int bar_no, + u64 *size, unsigned int *flags) +{ + return __of_get_address(dev, -1, bar_no, size, flags); +} + #endif /* __OF_ADDRESS_H */ From patchwork Thu May 27 19:45:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 12285211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2949C4708A for ; Thu, 27 May 2021 19:46:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 88CD56124C for ; Thu, 27 May 2021 19:46:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235580AbhE0Trg (ORCPT ); Thu, 27 May 2021 15:47:36 -0400 Received: from mail-ot1-f45.google.com ([209.85.210.45]:39758 "EHLO mail-ot1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235602AbhE0Trd (ORCPT ); Thu, 27 May 2021 15:47:33 -0400 Received: by mail-ot1-f45.google.com with SMTP id d25-20020a0568300459b02902f886f7dd43so1325313otc.6; Thu, 27 May 2021 12:45:58 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=ymrb9ey0Xq/bAo/fEanTrmIhj8wD4Qny297we0IGR+o=; b=dc8ibMbJwNkiRj0CPbUNvuLH5I2khZUGb2VXMSOVlijYN4yVwzcVxs2PliL0aByEPR YJLE08snnArf6qXLeKRkR7Ll//lkOt8bdBhAx++3L7AFPI+7M+yUY1ndNXqZz+ehxfXF 6A2Ou5GPkJhwkhvTgNMhjI7boey5BYcOUfYjuv81CteCH1y3VbAne6+Fo3zymAWEvTrX XSgm5pQgFyWvtfIPnY2FPFgmZqFOn3Yi9ZQRFH9Uk5NooN31QDQFZZOCQqdJLKw7uDEw MMedoM8RxABrqAGItyuUv1GWp8JnzPgmkwdC12+9ofnnkE5nUXylTodbXgCrdnc/jnoo z95Q== X-Gm-Message-State: AOAM531S+admJZOxcSoFe2bCEHNdf1LKH5mAYO4IJ6anUFJxDhi16E7r MlJ6QQZe/MMucuRzmIhUpzu1Y5mDvg== X-Google-Smtp-Source: ABdhPJw4oeb+tN2H6lYx9/h31oeKD5pF9Jfu3cVA44eH0KolP67ge4kWoHArhWwmYTk9lwET2Fqx8g== X-Received: by 2002:a9d:4b9c:: with SMTP id k28mr4269155otf.183.1622144757056; Thu, 27 May 2021 12:45:57 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id m74sm665162oig.33.2021.05.27.12.45.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 12:45:55 -0700 (PDT) From: Rob Herring To: devicetree@vger.kernel.org, Frank Rowand Cc: linux-kernel@vger.kernel.org, Bjorn Helgaas , linux-pci@vger.kernel.org, Randy Dunlap Subject: [PATCH 3/4] of: address: Use IS_ENABLED() for !CONFIG_PCI Date: Thu, 27 May 2021 14:45:46 -0500 Message-Id: <20210527194547.1287934-4-robh@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210527194547.1287934-1-robh@kernel.org> References: <20210527194547.1287934-1-robh@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Convert address.c to use IS_ENABLED() instead of ifdefs for the public PCI functions. This simplifies the ifdefs in of_address.h. Cc: Frank Rowand Signed-off-by: Rob Herring --- drivers/of/address.c | 8 +++++++- include/linux/of_address.h | 39 ++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index aa766437995c..e643f999743a 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -198,6 +198,7 @@ static int of_bus_pci_translate(__be32 *addr, u64 offset, int na) { return of_bus_default_translate(addr + 1, offset, na - 1); } +#endif /* CONFIG_PCI */ int of_pci_address_to_resource(struct device_node *dev, int bar, struct resource *r) @@ -206,6 +207,9 @@ int of_pci_address_to_resource(struct device_node *dev, int bar, u64 size; unsigned int flags; + if (!IS_ENABLED(CONFIG_PCI)) + return -ENOSYS; + addrp = of_get_pci_address(dev, bar, &size, &flags); if (addrp == NULL) return -EINVAL; @@ -236,6 +240,9 @@ int of_pci_range_to_resource(struct of_pci_range *range, res->parent = res->child = res->sibling = NULL; res->name = np->full_name; + if (!IS_ENABLED(CONFIG_PCI)) + return -ENOSYS; + if (res->flags & IORESOURCE_IO) { unsigned long port; err = pci_register_io_range(&np->fwnode, range->cpu_addr, @@ -266,7 +273,6 @@ int of_pci_range_to_resource(struct of_pci_range *range, return err; } EXPORT_SYMBOL(of_pci_range_to_resource); -#endif /* CONFIG_PCI */ /* * ISA bus specific translator diff --git a/include/linux/of_address.h b/include/linux/of_address.h index b72807faf037..45598dbec269 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -61,6 +61,11 @@ extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser, extern struct of_pci_range *of_pci_range_parser_one( struct of_pci_range_parser *parser, struct of_pci_range *range); +extern int of_pci_address_to_resource(struct device_node *dev, int bar, + struct resource *r); +extern int of_pci_range_to_resource(struct of_pci_range *range, + struct device_node *np, + struct resource *res); extern bool of_dma_is_coherent(struct device_node *np); #else /* CONFIG_OF_ADDRESS */ static inline void __iomem *of_io_request_and_map(struct device_node *device, @@ -100,6 +105,19 @@ static inline struct of_pci_range *of_pci_range_parser_one( return NULL; } +static inline int of_pci_address_to_resource(struct device_node *dev, int bar, + struct resource *r) +{ + return -ENOSYS; +} + +static inline int of_pci_range_to_resource(struct of_pci_range *range, + struct device_node *np, + struct resource *res) +{ + return -ENOSYS; +} + static inline bool of_dma_is_coherent(struct device_node *np) { return false; @@ -124,27 +142,6 @@ static inline void __iomem *of_iomap(struct device_node *device, int index) #endif #define of_range_parser_init of_pci_range_parser_init -#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI) -extern int of_pci_address_to_resource(struct device_node *dev, int bar, - struct resource *r); -extern int of_pci_range_to_resource(struct of_pci_range *range, - struct device_node *np, - struct resource *res); -#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */ -static inline int of_pci_address_to_resource(struct device_node *dev, int bar, - struct resource *r) -{ - return -ENOSYS; -} - -static inline int of_pci_range_to_resource(struct of_pci_range *range, - struct device_node *np, - struct resource *res) -{ - return -ENOSYS; -} -#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */ - static inline const __be32 *of_get_address(struct device_node *dev, int index, u64 *size, unsigned int *flags) { From patchwork Thu May 27 19:45:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 12285213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74A96C4708B for ; Thu, 27 May 2021 19:46:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 561FB613E2 for ; Thu, 27 May 2021 19:46:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235753AbhE0Trj (ORCPT ); Thu, 27 May 2021 15:47:39 -0400 Received: from mail-ot1-f54.google.com ([209.85.210.54]:35463 "EHLO mail-ot1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235710AbhE0Trf (ORCPT ); Thu, 27 May 2021 15:47:35 -0400 Received: by mail-ot1-f54.google.com with SMTP id 69-20020a9d0a4b0000b02902ed42f141e1so1345185otg.2; Thu, 27 May 2021 12:46:00 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=aaVILIIQRpAt4fcQqCQzkC7Wo1WpArLqF54tXrfeHEk=; b=iA38o8+DaGlZxZIptoJ4OEV7oS9tMKSdQmoE7mYbptLt+EXcqusE/C8WrvDLfOBBMq O8DZygsI1p7R2drzwalspn2vsjCWHoQxazf4SYkg3/weC0dybRAYXDtUr4mmd5shdYz0 sA+CbA6ImLGYCQ9w6uUPzYShJkeUoVQTXUnUgSMhHsc0S5JPBsWfFtx1/1q1roYqVITA LVzCoiwhzNPeb1d0EydOG5Grag27YfUzJY0jEMtM8iKrk6Ii0zndBwZegmxH2QJb32Qb vlwPPd1lMdv1GVYS38U4A2TghVR/5OjPrVl5Jwjqy8g/8qYsUy3aoQNMn/SJrrbYQqd+ YimA== X-Gm-Message-State: AOAM532U8rt1TKiveEwl6zRh94NiwmV6luE+G2MEJQG/ttkKTRo0Ykh5 bVAYSOFlW0rM+cC5pVrQayHpuvYPxw== X-Google-Smtp-Source: ABdhPJxsAV9DnsZkTkzog9FHmjg+bEejEyf9p9gCoy4QJ0+VWzhuApSAzpE0JKzM+T7GVe6yF2qOIg== X-Received: by 2002:a05:6830:1013:: with SMTP id a19mr4045932otp.21.1622144759587; Thu, 27 May 2021 12:45:59 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id m74sm665162oig.33.2021.05.27.12.45.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 12:45:58 -0700 (PDT) From: Rob Herring To: devicetree@vger.kernel.org, Frank Rowand Cc: linux-kernel@vger.kernel.org, Bjorn Helgaas , linux-pci@vger.kernel.org, Randy Dunlap Subject: [PATCH 4/4] of: Merge of_address_to_resource() and of_pci_address_to_resource() implementations Date: Thu, 27 May 2021 14:45:47 -0500 Message-Id: <20210527194547.1287934-5-robh@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210527194547.1287934-1-robh@kernel.org> References: <20210527194547.1287934-1-robh@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org of_address_to_resource() and of_pci_address_to_resource() are almost the same except the former takes an index and the latter takes a BAR number. Now that __of_get_address() can take either one, refactor the functions to use a common implementation. Cc: Frank Rowand Signed-off-by: Rob Herring --- drivers/of/address.c | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index e643f999743a..3b2acca7e363 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -23,9 +23,8 @@ #define OF_CHECK_COUNTS(na, ns) (OF_CHECK_ADDR_COUNT(na) && (ns) > 0) static struct of_bus *of_match_bus(struct device_node *np); -static int __of_address_to_resource(struct device_node *dev, - const __be32 *addrp, u64 size, unsigned int flags, - const char *name, struct resource *r); +static int __of_address_to_resource(struct device_node *dev, int index, + int bar_no, struct resource *r); static bool of_mmio_is_nonposted(struct device_node *np); /* Debug utility */ @@ -203,17 +202,11 @@ static int of_bus_pci_translate(__be32 *addr, u64 offset, int na) int of_pci_address_to_resource(struct device_node *dev, int bar, struct resource *r) { - const __be32 *addrp; - u64 size; - unsigned int flags; if (!IS_ENABLED(CONFIG_PCI)) return -ENOSYS; - addrp = of_get_pci_address(dev, bar, &size, &flags); - if (addrp == NULL) - return -EINVAL; - return __of_address_to_resource(dev, addrp, size, flags, NULL, r); + return __of_address_to_resource(dev, -1, bar, r); } EXPORT_SYMBOL_GPL(of_pci_address_to_resource); @@ -804,11 +797,22 @@ static u64 of_translate_ioport(struct device_node *dev, const __be32 *in_addr, return port; } -static int __of_address_to_resource(struct device_node *dev, - const __be32 *addrp, u64 size, unsigned int flags, - const char *name, struct resource *r) +static int __of_address_to_resource(struct device_node *dev, int index, int bar_no, + struct resource *r) { u64 taddr; + const __be32 *addrp; + u64 size; + unsigned int flags; + const char *name = NULL; + + addrp = __of_get_address(dev, index, bar_no, &size, &flags); + if (addrp == NULL) + return -EINVAL; + + /* Get optional "reg-names" property to add a name to a resource */ + if (index >= 0) + of_property_read_string_index(dev, "reg-names", index, &name); if (flags & IORESOURCE_MEM) taddr = of_translate_address(dev, addrp); @@ -846,19 +850,7 @@ static int __of_address_to_resource(struct device_node *dev, int of_address_to_resource(struct device_node *dev, int index, struct resource *r) { - const __be32 *addrp; - u64 size; - unsigned int flags; - const char *name = NULL; - - addrp = of_get_address(dev, index, &size, &flags); - if (addrp == NULL) - return -EINVAL; - - /* Get optional "reg-names" property to add a name to a resource */ - of_property_read_string_index(dev, "reg-names", index, &name); - - return __of_address_to_resource(dev, addrp, size, flags, name, r); + return __of_address_to_resource(dev, index, -1, r); } EXPORT_SYMBOL_GPL(of_address_to_resource);