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: 448872 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp816423jac; Thu, 27 May 2021 12:46:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMrkXsfRbbsXpep4GB9+4cbWA0UK2ogzgrKusT8YgMdFMmj0aJjY6J1ipradSmR/U79aUy X-Received: by 2002:a05:6e02:1489:: with SMTP id n9mr4251651ilk.59.1622144761165; Thu, 27 May 2021 12:46:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622144761; cv=none; d=google.com; s=arc-20160816; b=uy7W1179cQ9TZ8bBori6UQWZ2f6N0OR4znaPP8vi7G/ilCsnqAL83INA4vOjukMgbf 9xOmh8Der/banJuKeEACTO3WMZ9FgxuYXrUqfgjhdNKGYEqK3FRjBgHGbhBrIUbjGG8l ptzmnD0ZZDiTkDyVp2vzg3QMuvHc/5A/sFkrR1byIE1VJTN3v1R1EARlWJ0eHJnKbabW P6rBm/vNHfD1OFIhv0yTPldDlErH+Yf572Ei77Zt5ZYG0KnYgHznPA/W2vqkyg7AWZBS mkpH60IxOzs7ZjNGXIpaChwuQUdf9RwZ7RWdyjyi2nUKlLS0oSx5NUPYsVCxA+Yd5iFk +HDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=68t16l/dJX8qwP/jSm8KvVZZuN7st3omJGcvkjXgwLg=; b=oeZd/T3ON/wWh2bI7hb0EDyQoqoK4KzXv34VKliYTufgtqeKSTKI11zpG12wak4dFe cpio4B6vMeuIkvc7pQV3kdozQja4jiWm8AGpwdW0QfWDb4TG3u51tmrhV86+Z5Z09x2H mrsH5pxIC5aPyL4PP84xwAcRLj6Xg9ErK5RvZLctbMz/SbRiw55zwsOXejdsD3FSDjKS GNUfQXtPHvONvtnF+SYtae4PDtAcEUSR8LmLFVp1Z+h0pdzgAChamj7O+SjeBZyKGJtf e8H0/2kmnfunRcUraiBIJmA3QRaTkFNITwdS5EIxOB/JVFnRyzEAbgamtf5Iq069A8QR We8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 13si3977021ilx.46.2021.05.27.12.46.00; Thu, 27 May 2021 12:46:01 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235609AbhE0Tra (ORCPT + 7 others); 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-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: devicetree@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 --- include/linux/pci.h | 4 ++++ 1 file changed, 4 insertions(+) -- 2.27.0 Acked-by: Bjorn Helgaas 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: 448873 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp816435jac; Thu, 27 May 2021 12:46:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjovVw6d6eM3KM/rjYjBsOMXKSW3J/S2vuDneD1BDJ/OTd9T5/xUZh8478HnTGGjqQA+1m X-Received: by 2002:a05:6638:10c4:: with SMTP id q4mr4961097jad.29.1622144762501; Thu, 27 May 2021 12:46:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622144762; cv=none; d=google.com; s=arc-20160816; b=IgSlt1QacN5uZ3kbzUb++tbLiCG4W7KuI3ToRUlsbcd4yze2e8/QSmv7j6m8L5Av4A IJSFdjP7nt03I9oqiuZJVRG0PYgE3Ec9EgaoYAgNHeBPyLJtJBldZNjjVE10eKNtMafJ I0SvT5qJqc9m8VtluAnbKhkUIt1F8sS3Ly4lBYa0qIaweblp4Vx11WL+wg/BCYknfgk8 mjirG02xsI4Ed6R2nN+KOtZeCGmtOVjoTX5ORWfEdXfF2ZJa1D/qWANvVAsB2sDeCqUt yWPPD93sVl/4eoWg88Vk8OZpc3fB5y99bpYo96ks6Pr5Ezs4VtxFClvTWIPVSnV8TIjh JuAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Pi/H1lXjgfAQTnfvqaLMcay9EXPe4HtbT57LknC592A=; b=OSIA4J3ZRJBEjEff2tAA4+qxNzeX9yeQ2I29Utt8ARFHT/X85LXWMs6ePYxRiFuCQs RCsshxh+bZrc54sJNaFMfgQLPTqPIflOmGZSDCdivRu9n3BjHj+XIFgQPftdXoesdmuK WWxU7sq/qPT0uXz4f4IesOH9ING8xyrKkqXIQ8UuNOm9n3PjMVtp4RFR2bWlaXi7hcxK lhqa4eWIpr6B9g2phDyNEDammsorLS+yBj38KnMCsr2w8VC9HaEKgdHOj1pKGo8566yJ 0VKVIbKK6e5dReHqRYrD0dK7i3RprIRnaMKONX2PZj81xlG8qf4ZSy9Dw4OgAemfm58O k/Pg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 13si3977021ilx.46.2021.05.27.12.46.02; Thu, 27 May 2021 12:46:02 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235248AbhE0Trc (ORCPT + 7 others); 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-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: devicetree@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(-) -- 2.27.0 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: 448874 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp816462jac; Thu, 27 May 2021 12:46:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQvzjRDkuAlanJPMR2dFrhnB8gbfk1OTN1qhDcOfOt1pe0M64pdvoEawSx/zCW3iUqXJcJ X-Received: by 2002:a92:ca0a:: with SMTP id j10mr4212594ils.154.1622144767091; Thu, 27 May 2021 12:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622144767; cv=none; d=google.com; s=arc-20160816; b=Xg4P52DQ6ufT/oKopmQab7hwgitk3NujlhIY58VSFgDg6yKs6k6u1cFpIQBeDzVdNj xy3T5ejqDCXkTK8Cej/ZCJCJ33w/Nf/SzOzY8js0YHRXOJNTlqY2U02i8TtdVUm+x+XK LD3R1LHjco+8iYd/y60e6wzNbzLMkOddpor2e++gBEtRTZkkWId7X7Xh/D7hVSinOKBc Yw4X+ciDxHIBS5RYgW64KKx+Y4VA7oXHx2V6MlHJQhtlhD2fz1Bz5oZcJ2DZmEAaLsYp rmqzsn8MLrZACo4REgQidwVY5/xfsh/BboDbQngF5hHHqMFv1PSwbzzie3/k7uT7Mcyj d4Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ymrb9ey0Xq/bAo/fEanTrmIhj8wD4Qny297we0IGR+o=; b=dsrOscqRQmFozP7P4FPuPdK629KhpiMJUxyPRlZwixq/HsfGnB/jzkjYoa3qmLQkaI 4Lk1Kfu1X42G2MaSprycBqx01uXIn64Zqa3S7L81Ah3ozvzvkxnVm19FDCpfN+NNCcwC LLUr+cYN696C5T1e/FGEfp34+muRisZC+ALzyS1bp7zsx3Ubxkz8pMbeZQgtn1ehXZHC IsZmUX4msWgdBjJd0mRacJXB/hXE6Kui8elArDpxbyPtplpO0D5nx3LRwheYEmb/x/p3 6eGK+OY89p003Kqh30K/u5rpJbynD8jxhUaUl8WFLFe0mZ65QcQK25Po8KUYQberFQKD +ZiA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i5si3530147iow.84.2021.05.27.12.46.06; Thu, 27 May 2021 12:46:07 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235620AbhE0Trh (ORCPT + 7 others); Thu, 27 May 2021 15:47:37 -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-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: devicetree@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(-) -- 2.27.0 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: 448875 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp816467jac; Thu, 27 May 2021 12:46:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxR1sV9PcEF9dL8d1m9QpiLVUBwc059auxI7JwXwiVuzyEZHpRnOhSjAso8CD0SoZ5pfDgY X-Received: by 2002:a6b:3b4c:: with SMTP id i73mr4121779ioa.149.1622144767501; Thu, 27 May 2021 12:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622144767; cv=none; d=google.com; s=arc-20160816; b=k3Swnvot6VXCGRLC4wXj/YE8uFhFuB0yCaAl6zrXzD/KWPrdO0o1bHc9/ulltNQAr+ Psydxa2+6dljvhRrb9gpuEitv2RCQoI+9b0f9rJ90yNUOcNgg0caU4l5ekXin2NG3YYQ TErA5kI5p6s1C40n3sq0mHXb2kumSWYyvpf+5M8hlASWYpswUK6e0+IV3xgt0iBayfaD CrzKALob9wy7hoQZ4CIxGXuK80dm8JcDCVjMic0x/eOuceQUOmHBCvxKf31Jc96uXMLU C0uo8D5FM0AUWFRlTsHDGpmypzmoFR7iq2+U4gNo63ucuxsCUK1WUjYALuGOHDNuhmhK 2Y9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=aaVILIIQRpAt4fcQqCQzkC7Wo1WpArLqF54tXrfeHEk=; b=BnEaala63xh5zLgAtdoob5HLbbRidgXbhAt5KQVypk4IeGSWVTvLAnCxuB5UMJbIKo p32NIorFeNuUHNzo96USZXOpZsJQuqyxNQyDN/Y9DimymYDa+9AREyvRKx1XoKoGxxiD Alb3uzi1nT77Ra9BWJ/j77MT7hJR1+tYZMt0EYNXaox0auEfrzLRvjVqyH7OqZDHp1Nn U2jGBUCe7pNDtj6cQIhNsVXmIdUcTcRyQhMrOI5UJ+fXPBdy/NlDSajeCanflwF3no+5 h+oT/TAb3jcKxJgtjk4VWXSuKv5CctYPsx+1uIWTgd3/8eTRw94KtR1f5GfJENgN5316 ISUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i5si3530147iow.84.2021.05.27.12.46.07; Thu, 27 May 2021 12:46:07 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235804AbhE0Trj (ORCPT + 7 others); 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-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: devicetree@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(-) -- 2.27.0 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);