From patchwork Thu Aug 13 17:57:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 251755 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=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, 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 7CB5CC433DF for ; Thu, 13 Aug 2020 17:57:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6967520829 for ; Thu, 13 Aug 2020 17:57:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726522AbgHMR5j (ORCPT ); Thu, 13 Aug 2020 13:57:39 -0400 Received: from mga01.intel.com ([192.55.52.88]:59185 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726174AbgHMR5h (ORCPT ); Thu, 13 Aug 2020 13:57:37 -0400 IronPort-SDR: UkzOc6y4E1e8l5s2gQYx8odCpcP50qwtNHvGEkD3iaa6Jva7VmQGYaQf0okeR7dq3UBWdlzWtX Gyy4Uy8omxbA== X-IronPort-AV: E=McAfee;i="6000,8403,9712"; a="172337144" X-IronPort-AV: E=Sophos;i="5.76,309,1592895600"; d="scan'208";a="172337144" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2020 10:57:33 -0700 IronPort-SDR: 2uxO2NsFaBBl8UnqRQ3frtd2J8wYnbcBIczkZXRbjyHLznc7M/vxd4Snc6Lnzd1s4ccsKmhLsa aMbgVL9Qfb7g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,309,1592895600"; d="scan'208";a="278195282" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 13 Aug 2020 10:57:31 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 49CF2190; Thu, 13 Aug 2020 20:57:30 +0300 (EEST) From: Andy Shevchenko To: "Rafael J. Wysocki" , Len Brown , linux-acpi@vger.kernel.org Cc: Andy Shevchenko Subject: [PATCH v1 1/7] resource: Simplify region_intersects() by reducing conditionals Date: Thu, 13 Aug 2020 20:57:23 +0300 Message-Id: <20200813175729.15088-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Now we have for 'other' and 'type' variables other type return 0 0 REGION_DISJOINT 0 x REGION_INTERSECTS x 0 REGION_DISJOINT x x REGION_MIXED Obviously it's easier to check 'type' for 0 first instead of currently checked 'other'. Signed-off-by: Andy Shevchenko --- kernel/resource.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index 841737bbda9e..70575a61bf20 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -554,13 +554,10 @@ int region_intersects(resource_size_t start, size_t size, unsigned long flags, } read_unlock(&resource_lock); - if (other == 0) - return type ? REGION_INTERSECTS : REGION_DISJOINT; + if (type == 0) + return REGION_DISJOINT; - if (type) - return REGION_MIXED; - - return REGION_DISJOINT; + return (other == 0) ? REGION_INTERSECTS : REGION_MIXED; } EXPORT_SYMBOL_GPL(region_intersects); From patchwork Thu Aug 13 17:57:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 251757 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=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, 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 EF7EAC433E4 for ; Thu, 13 Aug 2020 17:57:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D361420866 for ; Thu, 13 Aug 2020 17:57:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726167AbgHMR5e (ORCPT ); Thu, 13 Aug 2020 13:57:34 -0400 Received: from mga03.intel.com ([134.134.136.65]:39968 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726174AbgHMR5d (ORCPT ); Thu, 13 Aug 2020 13:57:33 -0400 IronPort-SDR: TqGGyF+naqm5Vn+QdiDAXeyZsd3K4wZv8NCjzdDufYpx/Ln9UnuW4F20wzyMMaq6Eyjzoyltkt lBtg+8x0Sjew== X-IronPort-AV: E=McAfee;i="6000,8403,9712"; a="154257234" X-IronPort-AV: E=Sophos;i="5.76,309,1592895600"; d="scan'208";a="154257234" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2020 10:57:32 -0700 IronPort-SDR: YMKk51Vgro667vDwnJ9Krrmqfc2347QxKDJgtaP0PVMR1NFDXL03nm7sxWlbPduZuNTaNty487 C4GJNm2Cxc9w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,309,1592895600"; d="scan'208";a="495943934" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 13 Aug 2020 10:57:31 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 55815163; Thu, 13 Aug 2020 20:57:30 +0300 (EEST) From: Andy Shevchenko To: "Rafael J. Wysocki" , Len Brown , linux-acpi@vger.kernel.org Cc: Andy Shevchenko Subject: [PATCH v1 2/7] resource: Group resource_overlaps() with other inline helpers Date: Thu, 13 Aug 2020 20:57:24 +0300 Message-Id: <20200813175729.15088-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200813175729.15088-1-andriy.shevchenko@linux.intel.com> References: <20200813175729.15088-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org For better maintenance group resource_overlaps() with other inline helpers. Signed-off-by: Andy Shevchenko --- include/linux/ioport.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 6c2b06fe8beb..0193987b9968 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -226,6 +226,11 @@ static inline bool resource_contains(struct resource *r1, struct resource *r2) return r1->start <= r2->start && r1->end >= r2->end; } +/* True if any part of r1 overlaps r2 */ +static inline bool resource_overlaps(struct resource *r1, struct resource *r2) +{ + return (r1->start <= r2->end && r1->end >= r2->start); +} /* Convenience shorthand with allocation */ #define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), 0) @@ -291,12 +296,6 @@ extern int walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start, u64 end, void *arg, int (*func)(struct resource *, void *)); -/* True if any part of r1 overlaps r2 */ -static inline bool resource_overlaps(struct resource *r1, struct resource *r2) -{ - return (r1->start <= r2->end && r1->end >= r2->start); -} - struct resource *devm_request_free_mem_region(struct device *dev, struct resource *base, unsigned long size); struct resource *request_free_mem_region(struct resource *base, From patchwork Thu Aug 13 17:57:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 251758 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=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, 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 45EF7C433DF for ; Thu, 13 Aug 2020 17:57:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 203DD20838 for ; Thu, 13 Aug 2020 17:57:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726192AbgHMR5d (ORCPT ); Thu, 13 Aug 2020 13:57:33 -0400 Received: from mga12.intel.com ([192.55.52.136]:7942 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726167AbgHMR5d (ORCPT ); Thu, 13 Aug 2020 13:57:33 -0400 IronPort-SDR: ezOJPpHTdLrGnVkaaUJHpWqcFDzZSHGcSF2IvY8NyMHHCPSowe9NaOVYOzFaVLvqvE4NuZcY0K PNwcetBt7gXg== X-IronPort-AV: E=McAfee;i="6000,8403,9712"; a="133815475" X-IronPort-AV: E=Sophos;i="5.76,309,1592895600"; d="scan'208";a="133815475" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2020 10:57:32 -0700 IronPort-SDR: 8SejSHGFkAMGV2hia6m0PHuYzTYxatw34lyB72LdUBimHJmhvJV4hcTZyTG3JZm3oxPEa/eHU5 u1YAFycxiDVQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,309,1592895600"; d="scan'208";a="470308891" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 13 Aug 2020 10:57:31 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 6609536B; Thu, 13 Aug 2020 20:57:30 +0300 (EEST) From: Andy Shevchenko To: "Rafael J. Wysocki" , Len Brown , linux-acpi@vger.kernel.org Cc: Andy Shevchenko Subject: [PATCH v1 4/7] resource: Introduce resource_intersection() for overlapping resources Date: Thu, 13 Aug 2020 20:57:26 +0300 Message-Id: <20200813175729.15088-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200813175729.15088-1-andriy.shevchenko@linux.intel.com> References: <20200813175729.15088-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org There will be at least one user that can utilize new helper. Provide the helper for future user and for wider use. Deliberately avoid min()/max() macro as they are still parts of kernel.h which is quite a burden to be included here in order to avoid circular dependencies. Signed-off-by: Andy Shevchenko --- include/linux/ioport.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/ioport.h b/include/linux/ioport.h index c98df0ec7422..1d5ab2e7f9eb 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -232,6 +232,16 @@ static inline bool resource_overlaps(struct resource *r1, struct resource *r2) return (r1->start <= r2->end && r1->end >= r2->start); } +static inline bool +resource_intersection(struct resource *r1, struct resource *r2, struct resource *r) +{ + if (!resource_overlaps(r1, r2)) + return false; + r->start = r1->start > r2->start ? r1->start : r2->start; + r->end = r1->end < r2->end ? r1->end : r2->end; + return true; +} + static inline bool resource_union(struct resource *r1, struct resource *r2, struct resource *r) { From patchwork Thu Aug 13 17:57:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 251756 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=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, 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 4767EC433E1 for ; Thu, 13 Aug 2020 17:57:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 33BCE2078D for ; Thu, 13 Aug 2020 17:57:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726499AbgHMR5g (ORCPT ); Thu, 13 Aug 2020 13:57:36 -0400 Received: from mga07.intel.com ([134.134.136.100]:1402 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726384AbgHMR5g (ORCPT ); Thu, 13 Aug 2020 13:57:36 -0400 IronPort-SDR: qiK9AznEIyJbFTHmf2Wr7tauM96GUGkevC/20QaLtykLUr0MntlCgCC+YJiV5u4/Nw5W2/dwyt Mj0ItwOiuhrQ== X-IronPort-AV: E=McAfee;i="6000,8403,9712"; a="218626203" X-IronPort-AV: E=Sophos;i="5.76,309,1592895600"; d="scan'208";a="218626203" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2020 10:57:33 -0700 IronPort-SDR: zVhLbiZLkjhAVad+77Sb2uU6sXPPgozGcXziqIxeesSRpm+feFgpTH3fbiixC0Tiaell1MOLK8 O+O5C9X4v2wQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,309,1592895600"; d="scan'208";a="295510386" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 13 Aug 2020 10:57:31 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 74D633D7; Thu, 13 Aug 2020 20:57:30 +0300 (EEST) From: Andy Shevchenko To: "Rafael J. Wysocki" , Len Brown , linux-acpi@vger.kernel.org Cc: Andy Shevchenko , Kuppuswamy Sathyanarayanan , Bjorn Helgaas , linux-pci@vger.kernel.org Subject: [PATCH v1 5/7] PCI/ACPI: Replace open coded variant of resource_union() Date: Thu, 13 Aug 2020 20:57:27 +0300 Message-Id: <20200813175729.15088-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200813175729.15088-1-andriy.shevchenko@linux.intel.com> References: <20200813175729.15088-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Since we have resource_union() helper, let's utilize it here. Signed-off-by: Andy Shevchenko Cc: Kuppuswamy Sathyanarayanan Cc: Bjorn Helgaas Cc: linux-pci@vger.kernel.org --- drivers/acpi/pci_root.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c index f90e841c59f5..2a6a741896de 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -724,9 +724,7 @@ static void acpi_pci_root_validate_resources(struct device *dev, * our resources no longer match the ACPI _CRS, but * the kernel resource tree doesn't allow overlaps. */ - if (resource_overlaps(res1, res2)) { - res2->start = min(res1->start, res2->start); - res2->end = max(res1->end, res2->end); + if (resource_union(res1, res2, res2)) { dev_info(dev, "host bridge window expanded to %pR; %pR ignored\n", res2, res1); free = true;