From patchwork Tue Nov 3 20:36:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11879209 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=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 5CE72C388F7 for ; Tue, 3 Nov 2020 22:10:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 255C92080D for ; Tue, 3 Nov 2020 22:10:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729723AbgKCUhc (ORCPT ); Tue, 3 Nov 2020 15:37:32 -0500 Received: from mga18.intel.com ([134.134.136.126]:55780 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729447AbgKCUg7 (ORCPT ); Tue, 3 Nov 2020 15:36:59 -0500 IronPort-SDR: ai4HFeNoj4yAxv7GHJnvmrYNgl+j1xPn8G0Z/1V3drTvmLl3tmjYsP2KKn8hMBL4bRQA4RmWna RcmVjBKTknYw== X-IronPort-AV: E=McAfee;i="6000,8403,9794"; a="156898586" X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="156898586" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 12:36:58 -0800 IronPort-SDR: e5PDvl26kLk85maj16Uz1egsPA5EMIrn5wj6JkUk196w8F0tKQ7GHWiDWtf0+Ox8i7Wuwq29YJ 0a3Snq+9AdNg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="352454753" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 03 Nov 2020 12:36:56 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id E32A376; Tue, 3 Nov 2020 22:36:55 +0200 (EET) From: Andy Shevchenko To: linux-acpi@vger.kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: Andy Shevchenko , "Rafael J . Wysocki" Subject: [PATCH v5 1/7] resource: Simplify region_intersects() by reducing conditionals Date: Tue, 3 Nov 2020 22:36:49 +0200 Message-Id: <20201103203655.17701-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103203655.17701-1-andriy.shevchenko@linux.intel.com> References: <20201103203655.17701-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 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 Reviewed-by: Rafael J. Wysocki --- kernel/resource.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index 3ae2f56cc79d..82df80417489 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -557,13 +557,13 @@ 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; + if (other == 0) + return REGION_INTERSECTS; - return REGION_DISJOINT; + return REGION_MIXED; } EXPORT_SYMBOL_GPL(region_intersects); From patchwork Tue Nov 3 20:36:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11879005 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=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 A64E1C2D0A3 for ; Tue, 3 Nov 2020 20:36:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B82322226 for ; Tue, 3 Nov 2020 20:36:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729456AbgKCUg6 (ORCPT ); Tue, 3 Nov 2020 15:36:58 -0500 Received: from mga02.intel.com ([134.134.136.20]:3225 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727688AbgKCUg6 (ORCPT ); Tue, 3 Nov 2020 15:36:58 -0500 IronPort-SDR: uconx7GRyKJPlbgDfn6ihfp3fre53Z66aFxoV85jMCandYNXfrIUd0bhcNYK+arMpqD7pwNVLO au1xz2WBjJXg== X-IronPort-AV: E=McAfee;i="6000,8403,9794"; a="156109917" X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="156109917" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 12:36:58 -0800 IronPort-SDR: q0g52e2lnB/nJwdiRTUCayl9LWOadnBdXywzAtb5X7PQR6lNht0PKAM0DhxtLAcCMiJ5N/+5S9 7TfamrgW9Wvg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="538627243" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 03 Nov 2020 12:36:56 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id EBF0B15E; Tue, 3 Nov 2020 22:36:55 +0200 (EET) From: Andy Shevchenko To: linux-acpi@vger.kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: Andy Shevchenko , "Rafael J . Wysocki" Subject: [PATCH v5 2/7] resource: Group resource_overlaps() with other inline helpers Date: Tue, 3 Nov 2020 22:36:50 +0200 Message-Id: <20201103203655.17701-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103203655.17701-1-andriy.shevchenko@linux.intel.com> References: <20201103203655.17701-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org For better maintenance group resource_overlaps() with other inline helpers. While at it, drop extra parentheses. Signed-off-by: Andy Shevchenko Reviewed-by: Rafael J. Wysocki --- 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 5135d4b86cd6..df4581107536 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -229,6 +229,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) @@ -296,12 +301,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 Tue Nov 3 20:36:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11879009 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=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 E94E9C2D0A3 for ; Tue, 3 Nov 2020 20:37:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BBEFA223EA for ; Tue, 3 Nov 2020 20:37:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726709AbgKCUhX (ORCPT ); Tue, 3 Nov 2020 15:37:23 -0500 Received: from mga18.intel.com ([134.134.136.126]:55780 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729514AbgKCUhA (ORCPT ); Tue, 3 Nov 2020 15:37:00 -0500 IronPort-SDR: uV3G+aGdLIf9CS8OuW0d4m5qlXpNg1t1lW9bIarva1rjlgdgMTvs8fGPI9JzR6O26HCc1WFqQ6 3XgBczZO/rMQ== X-IronPort-AV: E=McAfee;i="6000,8403,9794"; a="156898591" X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="156898591" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 12:36:59 -0800 IronPort-SDR: GnU+YJTcRz8e3y329eR++YhYogh2HbcxGGE6nKNpZPCGWaVfcpKw30Gq41/7uqCngY1OL9mgVY 9A9H/BSA6vWg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="352454768" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 03 Nov 2020 12:36:56 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 0133B1C5; Tue, 3 Nov 2020 22:36:55 +0200 (EET) From: Andy Shevchenko To: linux-acpi@vger.kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: Andy Shevchenko , "Rafael J . Wysocki" , Mika Westerberg , Kuppuswamy Sathyanarayanan , Bjorn Helgaas , linux-pci@vger.kernel.org Subject: [PATCH v5 3/7] resource: Introduce resource_union() for overlapping resources Date: Tue, 3 Nov 2020 22:36:51 +0200 Message-Id: <20201103203655.17701-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103203655.17701-1-andriy.shevchenko@linux.intel.com> References: <20201103203655.17701-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Some already present users may utilize resource_union() helper. Provide it for them and for wider use in the future. Signed-off-by: Andy Shevchenko Reviewed-by: Rafael J. Wysocki Cc: Mika Westerberg Cc: Kuppuswamy Sathyanarayanan Cc: Bjorn Helgaas Cc: linux-pci@vger.kernel.org --- include/linux/ioport.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/linux/ioport.h b/include/linux/ioport.h index df4581107536..40320eb5bc0e 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -10,9 +10,10 @@ #define _LINUX_IOPORT_H #ifndef __ASSEMBLY__ +#include #include +#include #include -#include /* * Resources are tree-like, allowing * nesting etc.. @@ -235,6 +236,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_union(struct resource *r1, struct resource *r2, struct resource *r) +{ + if (!resource_overlaps(r1, r2)) + return false; + r->start = min(r1->start, r2->start); + r->end = max(r1->end, r2->end); + return true; +} + /* Convenience shorthand with allocation */ #define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), 0) #define request_muxed_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), IORESOURCE_MUXED) From patchwork Tue Nov 3 20:36:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11879211 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=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 49AE8C388F9 for ; Tue, 3 Nov 2020 22:10:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 083F621556 for ; Tue, 3 Nov 2020 22:10:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729472AbgKCUg7 (ORCPT ); Tue, 3 Nov 2020 15:36:59 -0500 Received: from mga01.intel.com ([192.55.52.88]:31599 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728157AbgKCUg6 (ORCPT ); Tue, 3 Nov 2020 15:36:58 -0500 IronPort-SDR: CjOr+K3mXbTTEig1S85CO6eTGg+kpf5HwZZSUzBdENAVdYRc1exXE0grppqmY4cW4LDOU4+caZ OscEfhUjE40Q== X-IronPort-AV: E=McAfee;i="6000,8403,9794"; a="186975402" X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="186975402" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 12:36:58 -0800 IronPort-SDR: cPGHEBvfWT/62Ywrzyig03g4sRQ7dp6XW3ON3OCflXkHi1eR1XUHm1Mgkde1flinCx4l4GdvZZ HBGUYDPSMFUA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="325355848" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 03 Nov 2020 12:36:56 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 097D15C2; Tue, 3 Nov 2020 22:36:56 +0200 (EET) From: Andy Shevchenko To: linux-acpi@vger.kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: Andy Shevchenko , "Rafael J . Wysocki" Subject: [PATCH v5 4/7] resource: Introduce resource_intersection() for overlapping resources Date: Tue, 3 Nov 2020 22:36:52 +0200 Message-Id: <20201103203655.17701-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103203655.17701-1-andriy.shevchenko@linux.intel.com> References: <20201103203655.17701-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 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. Signed-off-by: Andy Shevchenko Reviewed-by: Rafael J. Wysocki --- include/linux/ioport.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 40320eb5bc0e..ece1a8db309c 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -236,6 +236,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 = max(r1->start, r2->start); + r->end = min(r1->end, r2->end); + return true; +} + static inline bool resource_union(struct resource *r1, struct resource *r2, struct resource *r) { From patchwork Tue Nov 3 20:36:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11879013 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=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 6159EC388F7 for ; Tue, 3 Nov 2020 20:37:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2579D2224E for ; Tue, 3 Nov 2020 20:37:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729572AbgKCUhB (ORCPT ); Tue, 3 Nov 2020 15:37:01 -0500 Received: from mga18.intel.com ([134.134.136.126]:55780 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728157AbgKCUhA (ORCPT ); Tue, 3 Nov 2020 15:37:00 -0500 IronPort-SDR: 86qM8s9lziwD6JfrEIcE7RpXjoM7iw8vDhJP+0g76HMsoFhXs1b1wWCx+dJhtPGKdJg2khsu9j iamIOA4OeMCQ== X-IronPort-AV: E=McAfee;i="6000,8403,9794"; a="156898593" X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="156898593" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 12:37:00 -0800 IronPort-SDR: bBVUxlKg63ESgzPtszszhEl/LUUYJ98jT773/7tEGqR4BQpJD8EkTe3whc4gwWhBIPm23ZqUAl j9AEyuWVY/+A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="352454772" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 03 Nov 2020 12:36:59 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 11940646; Tue, 3 Nov 2020 22:36:56 +0200 (EET) From: Andy Shevchenko To: linux-acpi@vger.kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: Andy Shevchenko Subject: [PATCH v5 5/7] resource: Add test cases for new resource API Date: Tue, 3 Nov 2020 22:36:53 +0200 Message-Id: <20201103203655.17701-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103203655.17701-1-andriy.shevchenko@linux.intel.com> References: <20201103203655.17701-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add test cases for newly added resource APIs. Signed-off-by: Andy Shevchenko --- kernel/Makefile | 1 + kernel/resource_kunit.c | 150 ++++++++++++++++++++++++++++++++++++++++ lib/Kconfig.debug | 11 +++ 3 files changed, 162 insertions(+) create mode 100644 kernel/resource_kunit.c diff --git a/kernel/Makefile b/kernel/Makefile index af601b9bda0e..aac15aeb9d69 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -123,6 +123,7 @@ obj-$(CONFIG_HAS_IOMEM) += iomem.o obj-$(CONFIG_RSEQ) += rseq.o obj-$(CONFIG_WATCH_QUEUE) += watch_queue.o +obj-$(CONFIG_RESOURCE_KUNIT_TEST) += resource_kunit.o obj-$(CONFIG_SYSCTL_KUNIT_TEST) += sysctl-test.o CFLAGS_stackleak.o += $(DISABLE_STACKLEAK_PLUGIN) diff --git a/kernel/resource_kunit.c b/kernel/resource_kunit.c new file mode 100644 index 000000000000..9fdbca8426f1 --- /dev/null +++ b/kernel/resource_kunit.c @@ -0,0 +1,150 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test cases for API provided by resource.c and ioport.h + */ + +#include +#include +#include +#include + +#define R0_START 0x0000 +#define R0_END 0xffff +#define R1_START 0x1234 +#define R1_END 0x2345 +#define R2_START 0x4567 +#define R2_END 0x5678 +#define R3_START 0x6789 +#define R3_END 0x789a +#define R4_START 0x2000 +#define R4_END 0x7000 + +static struct resource r0 = { .start = R0_START, .end = R0_END }; +static struct resource r1 = { .start = R1_START, .end = R1_END }; +static struct resource r2 = { .start = R2_START, .end = R2_END }; +static struct resource r3 = { .start = R3_START, .end = R3_END }; +static struct resource r4 = { .start = R4_START, .end = R4_END }; + +struct result { + struct resource *r1; + struct resource *r2; + struct resource r; + bool ret; +}; + +static struct result results_for_union[] = { + { + .r1 = &r1, .r2 = &r0, .r.start = R0_START, .r.end = R0_END, .ret = true, + }, { + .r1 = &r2, .r2 = &r0, .r.start = R0_START, .r.end = R0_END, .ret = true, + }, { + .r1 = &r3, .r2 = &r0, .r.start = R0_START, .r.end = R0_END, .ret = true, + }, { + .r1 = &r4, .r2 = &r0, .r.start = R0_START, .r.end = R0_END, .ret = true, + }, { + .r1 = &r2, .r2 = &r1, .ret = false, + }, { + .r1 = &r3, .r2 = &r1, .ret = false, + }, { + .r1 = &r4, .r2 = &r1, .r.start = R1_START, .r.end = R4_END, .ret = true, + }, { + .r1 = &r2, .r2 = &r3, .ret = false, + }, { + .r1 = &r2, .r2 = &r4, .r.start = R4_START, .r.end = R4_END, .ret = true, + }, { + .r1 = &r3, .r2 = &r4, .r.start = R4_START, .r.end = R3_END, .ret = true, + }, +}; + +static struct result results_for_intersection[] = { + { + .r1 = &r1, .r2 = &r0, .r.start = R1_START, .r.end = R1_END, .ret = true, + }, { + .r1 = &r2, .r2 = &r0, .r.start = R2_START, .r.end = R2_END, .ret = true, + }, { + .r1 = &r3, .r2 = &r0, .r.start = R3_START, .r.end = R3_END, .ret = true, + }, { + .r1 = &r4, .r2 = &r0, .r.start = R4_START, .r.end = R4_END, .ret = true, + }, { + .r1 = &r2, .r2 = &r1, .ret = false, + }, { + .r1 = &r3, .r2 = &r1, .ret = false, + }, { + .r1 = &r4, .r2 = &r1, .r.start = R4_START, .r.end = R1_END, .ret = true, + }, { + .r1 = &r2, .r2 = &r3, .ret = false, + }, { + .r1 = &r2, .r2 = &r4, .r.start = R2_START, .r.end = R2_END, .ret = true, + }, { + .r1 = &r3, .r2 = &r4, .r.start = R3_START, .r.end = R4_END, .ret = true, + }, +}; + +static void resource_do_test(struct kunit *test, bool ret, struct resource *r, + bool exp_ret, struct resource *exp_r, + struct resource *r1, struct resource *r2) +{ + KUNIT_EXPECT_EQ_MSG(test, ret, exp_ret, "Resources %pR %pR", r1, r2); + KUNIT_EXPECT_EQ_MSG(test, r->start, exp_r->start, "Start elements are not equal"); + KUNIT_EXPECT_EQ_MSG(test, r->end, exp_r->end, "End elements are not equal"); +} + +static void resource_do_union_test(struct kunit *test, struct result *r) +{ + struct resource result; + bool ret; + + memset(&result, 0, sizeof(result)); + ret = resource_union(r->r1, r->r2, &result); + resource_do_test(test, ret, &result, r->ret, &r->r, r->r1, r->r2); + + memset(&result, 0, sizeof(result)); + ret = resource_union(r->r2, r->r1, &result); + resource_do_test(test, ret, &result, r->ret, &r->r, r->r2, r->r1); +} + +static void resource_test_union(struct kunit *test) +{ + struct result *r = results_for_union; + unsigned int i = 0; + + do { + resource_do_union_test(test, &r[i]); + } while (++i < ARRAY_SIZE(results_for_union)); +} + +static void resource_do_intersection_test(struct kunit *test, struct result *r) +{ + struct resource result; + bool ret; + + memset(&result, 0, sizeof(result)); + ret = resource_intersection(r->r1, r->r2, &result); + resource_do_test(test, ret, &result, r->ret, &r->r, r->r1, r->r2); + + memset(&result, 0, sizeof(result)); + ret = resource_intersection(r->r2, r->r1, &result); + resource_do_test(test, ret, &result, r->ret, &r->r, r->r2, r->r1); +} + +static void resource_test_intersection(struct kunit *test) +{ + struct result *r = results_for_intersection; + unsigned int i = 0; + + do { + resource_do_intersection_test(test, &r[i]); + } while (++i < ARRAY_SIZE(results_for_intersection)); +} + +static struct kunit_case resource_test_cases[] = { + KUNIT_CASE(resource_test_union), + KUNIT_CASE(resource_test_intersection), + {} +}; + +static struct kunit_suite resource_test_suite = { + .name = "resource", + .test_cases = resource_test_cases, +}; +kunit_test_suite(resource_test_suite); diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 8596989423bf..663e7238a56e 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2232,6 +2232,17 @@ config BITFIELD_KUNIT If unsure, say N. +config RESOURCE_KUNIT_TEST + tristate "KUnit test for resource API" + depends on KUNIT + help + This builds the resource API unit test. + Tests the logic of API provided by resource.c and ioport.h. + For more information on KUnit and unit tests in general please refer + to the KUnit documentation in Documentation/dev-tools/kunit/. + + If unsure, say N. + config SYSCTL_KUNIT_TEST tristate "KUnit test for sysctl" if !KUNIT_ALL_TESTS depends on KUNIT From patchwork Tue Nov 3 20:36:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11879003 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=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 D0B70C388F9 for ; Tue, 3 Nov 2020 20:37:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D5F82224E for ; Tue, 3 Nov 2020 20:37:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729610AbgKCUhD (ORCPT ); Tue, 3 Nov 2020 15:37:03 -0500 Received: from mga14.intel.com ([192.55.52.115]:43072 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729585AbgKCUhC (ORCPT ); Tue, 3 Nov 2020 15:37:02 -0500 IronPort-SDR: 94Kk2mYrv18X6qDMOqRq2i2n5qi6U+pVocgGW8Je74GJrY/ooNaNOLX8kQijBJlj+xhgw9LW6Z GlVwKVooFYtw== X-IronPort-AV: E=McAfee;i="6000,8403,9794"; a="168335730" X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="168335730" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 12:37:01 -0800 IronPort-SDR: EHvYHLukS0D03UUpC/qD2N7PKwqkcpo49siycse5WSH9eerqoxyJ074+xbRnzMh3YCPEGRMeHJ Qj/ws4DxzFdA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="320565288" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 03 Nov 2020 12:36:59 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 1A46A89F; Tue, 3 Nov 2020 22:36:56 +0200 (EET) From: Andy Shevchenko To: linux-acpi@vger.kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: Andy Shevchenko , Kuppuswamy Sathyanarayanan , Bjorn Helgaas , linux-pci@vger.kernel.org, "Rafael J . Wysocki" Subject: [PATCH v5 6/7] PCI/ACPI: Replace open coded variant of resource_union() Date: Tue, 3 Nov 2020 22:36:54 +0200 Message-Id: <20201103203655.17701-7-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103203655.17701-1-andriy.shevchenko@linux.intel.com> References: <20201103203655.17701-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 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 Reviewed-by: Rafael J. Wysocki --- 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 c12b5fb3e8fb..0bf072cef6cf 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -722,9 +722,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; From patchwork Tue Nov 3 20:36:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11879007 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=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 E8F59C2D0A3 for ; Tue, 3 Nov 2020 20:37:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABD872224E for ; Tue, 3 Nov 2020 20:37:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729591AbgKCUhC (ORCPT ); Tue, 3 Nov 2020 15:37:02 -0500 Received: from mga14.intel.com ([192.55.52.115]:43072 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729575AbgKCUhB (ORCPT ); Tue, 3 Nov 2020 15:37:01 -0500 IronPort-SDR: E+UDx1ttGSq0yksSXvOfzPa3bRh4uuUJ1COZWm0IStlsDnIqoM4MEYxEHaWm6lJPP3nzN/3/2E t1/h6505f54w== X-IronPort-AV: E=McAfee;i="6000,8403,9794"; a="168335729" X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="168335729" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 12:37:01 -0800 IronPort-SDR: K6GmmocQ/lDykcUWMwpHFkz80CKl7H/MdI3BBcT8o7q7ghvRIWH3ohXyTEErK0CEa4DccPagDA BoIoYLdM0apQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="320565285" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 03 Nov 2020 12:36:59 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 239E494B; Tue, 3 Nov 2020 22:36:56 +0200 (EET) From: Andy Shevchenko To: linux-acpi@vger.kernel.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: Andy Shevchenko , Mika Westerberg , "Rafael J . Wysocki" Subject: [PATCH v5 7/7] ACPI: watchdog: Replace open coded variant of resource_union() Date: Tue, 3 Nov 2020 22:36:55 +0200 Message-Id: <20201103203655.17701-8-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103203655.17701-1-andriy.shevchenko@linux.intel.com> References: <20201103203655.17701-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 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 Reviewed-by: Mika Westerberg Reviewed-by: Rafael J. Wysocki --- drivers/acpi/acpi_watchdog.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/acpi/acpi_watchdog.c b/drivers/acpi/acpi_watchdog.c index 5c1e9ea43123..ca28183f4d13 100644 --- a/drivers/acpi/acpi_watchdog.c +++ b/drivers/acpi/acpi_watchdog.c @@ -151,11 +151,7 @@ void __init acpi_watchdog_init(void) found = false; resource_list_for_each_entry(rentry, &resource_list) { if (rentry->res->flags == res.flags && - resource_overlaps(rentry->res, &res)) { - if (res.start < rentry->res->start) - rentry->res->start = res.start; - if (res.end > rentry->res->end) - rentry->res->end = res.end; + resource_union(rentry->res, &res, rentry->res)) { found = true; break; }