From patchwork Mon Nov 2 21:00:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11875343 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C45D697 for ; Mon, 2 Nov 2020 21:00:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 030602225B for ; Mon, 2 Nov 2020 21:00:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726754AbgKBVAa (ORCPT ); Mon, 2 Nov 2020 16:00:30 -0500 Received: from mga07.intel.com ([134.134.136.100]:25781 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726716AbgKBVA3 (ORCPT ); Mon, 2 Nov 2020 16:00:29 -0500 IronPort-SDR: RB7ZG/uibV6U7WNEtyMic9nVvVzo7PhwyFC3IfZ/Jt7J/Qjam0vN5H0sY5I5VJUao8Pa2oR8y8 NQPDDGZrbyLg== X-IronPort-AV: E=McAfee;i="6000,8403,9793"; a="233120548" X-IronPort-AV: E=Sophos;i="5.77,445,1596524400"; d="scan'208";a="233120548" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Nov 2020 13:00:28 -0800 IronPort-SDR: eeQi/Tb5/a/sUOAM/OYV9X9kk9zNjzMAhw2OgzYzxKHTwDF44oAZMhWNpCay2OB23X6CxeCKz/ JrJeBDODzDOw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,445,1596524400"; d="scan'208";a="362734825" Received: from black.fi.intel.com ([10.237.72.28]) by FMSMGA003.fm.intel.com with ESMTP; 02 Nov 2020 13:00:26 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id D38261EF; Mon, 2 Nov 2020 23:00:25 +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 v4 3/6] resource: Introduce resource_union() for overlapping resources Date: Mon, 2 Nov 2020 23:00:22 +0200 Message-Id: <20201102210025.53520-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102210025.53520-1-andriy.shevchenko@linux.intel.com> References: <20201102210025.53520-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@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)