From patchwork Wed Feb 26 19:37:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 324601 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 998D62C0091 for ; Thu, 27 Feb 2014 06:42:29 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753413AbaBZThR (ORCPT ); Wed, 26 Feb 2014 14:37:17 -0500 Received: from mail-ie0-f178.google.com ([209.85.223.178]:46377 "EHLO mail-ie0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754025AbaBZThN (ORCPT ); Wed, 26 Feb 2014 14:37:13 -0500 Received: by mail-ie0-f178.google.com with SMTP id ar20so1131176iec.9 for ; Wed, 26 Feb 2014 11:37:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:to:from:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding; bh=e+Efsqy+DFxe3gKaS/e0Fh4XSknOH9593Re+xcykIPA=; b=TBpqUp+NY4PA4CH9/jyiVesmE8qvg/ywaK4gJfv2N4enoDtUiqdFECXoHP6zN8c9g6 MEziemjvxLeVnc1BsYlEZDPLtUINOnmOv8pMqQuXf8fL5of0ECGGnh3qOrdFcarfhFqa Ex9TkAkgwJeiP6QlT09bOEkguUVRecUF8lQtMibgmvwLSw5JFlJD/SFP4K1w5gUXqQYk RN0KRReC/mElhaoAZ9vnOTbZh6vS5lkho+kFtd1Qt9wnKi6mnAofWb8xDD5FLE68vEGS VZpSFkmuPIj5owMEb6Q9jrr5waNoGm0HbRS5AYusK+C8RewKE//8G2pFiYc0xpLnfH41 CKtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:from:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-type :content-transfer-encoding; bh=e+Efsqy+DFxe3gKaS/e0Fh4XSknOH9593Re+xcykIPA=; b=NhGa79xfBhnFW+32ad+3AuRofq7GYWsp+EJO/1QZ9J+tdOMYX6KzFYac4ftG4QX+Zd VDJD2FRDiG1WXNBP0fniILMlQ5xE7FWBGA6tGrN7/UBVWq45EEt6//bDOEUHtFBo5g7Z 6JqMuZwow1y3ciJSEiIG0+TvDiY17AoADFL+qBxlw0XpeUi39TFp/S85679GCOXnGOlT Cwap0ACgVuFZwxOQlsSRoh18HJkEGtWfz9wJM5lTv4WIT3QJXdJZEKmy3HDqPD5UwQ5V lE8dlB5XtEtkfLa7+E6xDfXR3VONGaUr7wqbdJ0VznH7ZdPIPOIeA1aUy0afdX6dDOJq M7nA== X-Gm-Message-State: ALoCoQnRiObo7aq6gO7qyJRZd7xffcaqGx0gGhx8vVKRPbN25PmzFHEUn2XGtfvXRNwjyva42Oq4QfRORns5y6hN/0Ei8zFwJ1i/10CrrpNkqbASqi/qdfk288BlHVkLgV3ncrVNDIBQ9984UCiXrBNLw2fFHByR9F+9aoXLQIZ7MQSxZD5vPPH0nYUt2KiGbhOdUt37/saLxS1jw3AKnlbFhCGPkLQTCYbjiBc0ehuiiS6se2CE/44= X-Received: by 10.43.46.2 with SMTP id um2mr1213119icb.46.1393443432449; Wed, 26 Feb 2014 11:37:12 -0800 (PST) Received: from localhost ([172.16.49.60]) by mx.google.com with ESMTPSA id mi2sm1662733igb.3.2014.02.26.11.37.11 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 26 Feb 2014 11:37:12 -0800 (PST) Subject: [PATCH 1/9] resource: Add resource_contains() To: linux-pci@vger.kernel.org From: Bjorn Helgaas Cc: linux-kernel@vger.kernel.org Date: Wed, 26 Feb 2014 12:37:10 -0700 Message-ID: <20140226193710.10125.95477.stgit@bhelgaas-glaptop.roam.corp.google.com> In-Reply-To: <20140226192614.10125.68711.stgit@bhelgaas-glaptop.roam.corp.google.com> References: <20140226192614.10125.68711.stgit@bhelgaas-glaptop.roam.corp.google.com> User-Agent: StGit/0.16 MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org We have two identical copies of resource_contains() already, and more places that could use it. This moves it to ioport.h where it can be shared. resource_contains(struct resource *r1, struct resource *r2) returns true iff r1 and r2 are the same type (most callers already checked this separately) and the r1 address range completely contains r2. In addition, the new resource_contains() checks that both r1 and r2 have addresses assigned to them. If a resource is IORESOURCE_UNSET, it doesn't have a valid address and can't contain or be contained by another resource. Some callers already check this or for res->start. No functional change. Signed-off-by: Bjorn Helgaas --- drivers/pci/host-bridge.c | 8 -------- include/linux/ioport.h | 10 ++++++++++ kernel/resource.c | 8 ++------ 3 files changed, 12 insertions(+), 14 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pci/host-bridge.c b/drivers/pci/host-bridge.c index 06ace6248c61..47aaf22d814e 100644 --- a/drivers/pci/host-bridge.c +++ b/drivers/pci/host-bridge.c @@ -32,11 +32,6 @@ void pci_set_host_bridge_release(struct pci_host_bridge *bridge, bridge->release_data = release_data; } -static bool resource_contains(struct resource *res1, struct resource *res2) -{ - return res1->start <= res2->start && res1->end >= res2->end; -} - void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region, struct resource *res) { @@ -45,9 +40,6 @@ void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region, resource_size_t offset = 0; list_for_each_entry(window, &bridge->windows, list) { - if (resource_type(res) != resource_type(window->res)) - continue; - if (resource_contains(window->res, res)) { offset = window->offset; break; diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 89b7c24a36e9..9fcaac8bc4f6 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -169,6 +169,16 @@ static inline unsigned long resource_type(const struct resource *res) { return res->flags & IORESOURCE_TYPE_BITS; } +/* True iff r1 completely contains r2 */ +static inline bool resource_contains(struct resource *r1, struct resource *r2) +{ + if (resource_type(r1) != resource_type(r2)) + return false; + if (r1->flags & IORESOURCE_UNSET || r2->flags & IORESOURCE_UNSET) + return false; + return r1->start <= r2->start && r1->end >= r2->end; +} + /* Convenience shorthand with allocation */ #define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), 0) diff --git a/kernel/resource.c b/kernel/resource.c index 3f285dce9347..a8344dda7049 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -432,11 +432,6 @@ static void resource_clip(struct resource *res, resource_size_t min, res->end = max; } -static bool resource_contains(struct resource *res1, struct resource *res2) -{ - return res1->start <= res2->start && res1->end >= res2->end; -} - /* * Find empty slot in the resource tree with the given range and * alignment constraints @@ -471,10 +466,11 @@ static int __find_resource(struct resource *root, struct resource *old, arch_remove_reservations(&tmp); /* Check for overflow after ALIGN() */ - avail = *new; avail.start = ALIGN(tmp.start, constraint->align); avail.end = tmp.end; + avail.flags = new->flags & ~IORESOURCE_UNSET; if (avail.start >= tmp.start) { + alloc.flags = avail.flags; alloc.start = constraint->alignf(constraint->alignf_data, &avail, size, constraint->align); alloc.end = alloc.start + size - 1;