From patchwork Fri Sep 17 22:32:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 189232 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o8HMXB7Q003030 for ; Fri, 17 Sep 2010 22:33:11 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755238Ab0IQWcU (ORCPT ); Fri, 17 Sep 2010 18:32:20 -0400 Received: from g5t0006.atlanta.hp.com ([15.192.0.43]:43426 "EHLO g5t0006.atlanta.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755226Ab0IQWcS (ORCPT ); Fri, 17 Sep 2010 18:32:18 -0400 Received: from g5t0030.atlanta.hp.com (g5t0030.atlanta.hp.com [16.228.8.142]) by g5t0006.atlanta.hp.com (Postfix) with ESMTP id 4AFA1C4FD; Fri, 17 Sep 2010 22:32:18 +0000 (UTC) Received: from ldl (ldl.fc.hp.com [15.11.146.30]) by g5t0030.atlanta.hp.com (Postfix) with ESMTP id 26F2C1404F; Fri, 17 Sep 2010 22:32:18 +0000 (UTC) Received: from localhost (ldl.fc.hp.com [127.0.0.1]) by ldl (Postfix) with ESMTP id EE2E0CF004E; Fri, 17 Sep 2010 16:32:17 -0600 (MDT) Received: from ldl ([127.0.0.1]) by localhost (ldl.fc.hp.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XHx-sba14V5h; Fri, 17 Sep 2010 16:32:17 -0600 (MDT) Received: from eh.fc.hp.com (eh.fc.hp.com [15.11.146.105]) by ldl (Postfix) with ESMTP id D4E0FCF004A; Fri, 17 Sep 2010 16:32:17 -0600 (MDT) Received: from bob.kio (localhost [127.0.0.1]) by eh.fc.hp.com (Postfix) with ESMTP id C7AA12618A; Fri, 17 Sep 2010 16:32:17 -0600 (MDT) Subject: [PATCH v2 2/4] x86/PCI: allocate space from the end of a region, not the beginning To: Jesse Barnes From: Bjorn Helgaas Cc: Brian Bloniarz , Charles Butterfield , Denys Vlasenko , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Becker , "H. Peter Anvin" , Yinghai Lu , Thomas Gleixner , Linus Torvalds , Ingo Molnar Date: Fri, 17 Sep 2010 16:32:17 -0600 Message-ID: <20100917223217.24687.21265.stgit@bob.kio> In-Reply-To: <20100917223109.24687.17697.stgit@bob.kio> References: <20100917223109.24687.17697.stgit@bob.kio> User-Agent: StGit/0.15 MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Fri, 17 Sep 2010 22:33:11 +0000 (UTC) diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c index 5525309..fe866c8 100644 --- a/arch/x86/pci/i386.c +++ b/arch/x86/pci/i386.c @@ -37,6 +37,7 @@ #include #include +#define ALIGN_DOWN(x, a) ((x) & ~(a - 1)) static int skip_isa_ioresource_align(struct pci_dev *dev) { @@ -65,16 +66,21 @@ pcibios_align_resource(void *data, const struct resource *res, resource_size_t size, resource_size_t align) { struct pci_dev *dev = data; - resource_size_t start = res->start; + resource_size_t start = ALIGN_DOWN(res->end - size + 1, align); if (res->flags & IORESOURCE_IO) { - if (skip_isa_ioresource_align(dev)) - return start; - if (start & 0x300) - start = (start + 0x3ff) & ~0x3ff; + + /* + * If we're avoiding ISA aliases, the largest contiguous I/O + * port space is 256 bytes. Clearing bits 9 and 10 preserves + * all 256-byte and smaller alignments, so the result will + * still be correctly aligned. + */ + if (!skip_isa_ioresource_align(dev)) + start &= ~0x300; } else if (res->flags & IORESOURCE_MEM) { if (start < BIOS_END) - start = BIOS_END; + start = res->end; /* fail; no space */ } return start; }