From patchwork Tue Jan 7 00:56:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 307497 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 856032C0096 for ; Tue, 7 Jan 2014 11:57:28 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757964AbaAGA5E (ORCPT ); Mon, 6 Jan 2014 19:57:04 -0500 Received: from mail-ie0-f177.google.com ([209.85.223.177]:59399 "EHLO mail-ie0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757963AbaAGA5B (ORCPT ); Mon, 6 Jan 2014 19:57:01 -0500 Received: by mail-ie0-f177.google.com with SMTP id tp5so18620340ieb.8 for ; Mon, 06 Jan 2014 16:57:00 -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=XqyOY9lOGKehIfCD8CyA1mOVfMu94j5CKThrfIRxeYY=; b=FLIL0kGudX5r9vn3Neeqz/MXiOYQuCQyotl1o7j/MmsLN7SxCAWfV50/6W6Xs1fw0k cBAj3NsNdi7whxAMseD5cmZPjZqnBCwOEICg46P5fnZk44q7cFRvFTvRhe7A/207yBsF tuyTiL5RXEMW/2XjUJwb+pYYDICXPUKb0N0NKL41obZJmATj2EIvCRqw+rbgVu3Sem4c vUXceWdnzdDjAGQqcnh2JUYJftlbarDGS5tajr4ecuID1KWh/pJpLV5qMB9SKrs8A4hN +BVpkWQqCBq9V5NPZ2n30UbOsJLo2jQEKWH6XTe54SCq7OCOzUryEajbQT7KNKcFGjwe 7cUw== 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=XqyOY9lOGKehIfCD8CyA1mOVfMu94j5CKThrfIRxeYY=; b=ZbmtBNyWQDJXq6I3aeHGgoUlykkPmBChcanvb+6SftcUe8Ot5+lY9pu4adrHO0BtFI tj4MLJtk+m8l/kXyfFdmlAkCU4NJK2zYaGqVRhmXHjoATzyD1oujED8YUwErzc/W/0oR LcBWvIRBJrlBzUSWrKRkIpAr9oYC3sSmTj+ROkJbPiLiXlxQBqb1XbrtmIwFixf/fboS 7aN+EOgvDhUU/I6yjpGPyphiM3AE2tN/jWryfw2ZhYk2SRuBLemchud+a2fLbW1eX3JW j2yOmE5VLBNi8V1UnWQ4IuU+Cfn/bYGHIzjk8QONjuazstRhKH/COCd7Ax9VWKqbhtEV 2nsA== X-Gm-Message-State: ALoCoQkzV2ZdYJQw4BLR2lyWlz37fBGLSkQFYKWU40Zu+0t/wQD46Ln2poR88BnFHMzRtAxFTHNbVm0jmSv2pvxEszyB9PjxjgRleqKgU/qm/mSdu3Uqbt9rgbdPg1rSQy2pwGcWIVrWbaN7BuQFLbA8AT+UX7QLra7MUhiqzN5IsKbHaHtvIWB7KmBasp1FUWe24IDo6lG6anGxVLiDwVjigsjmBp1mVVEYtpqCgN48igH4mIdDK3M= X-Received: by 10.42.147.66 with SMTP id m2mr5850598icv.59.1389056220611; Mon, 06 Jan 2014 16:57:00 -0800 (PST) Received: from localhost ([172.29.127.26]) by mx.google.com with ESMTPSA id ml2sm887061igb.10.2014.01.06.16.56.59 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 06 Jan 2014 16:56:59 -0800 (PST) Subject: [PATCH v7 15/15] PCI: Allocate 64-bit BARs above 4G when possible To: linux-pci@vger.kernel.org, Daniel Vetter From: Bjorn Helgaas Cc: David Airlie , Yinghai Lu , Guo Chao , linux-kernel@vger.kernel.org Date: Mon, 06 Jan 2014 17:56:58 -0700 Message-ID: <20140107005658.10786.98616.stgit@bhelgaas-glaptop.roam.corp.google.com> In-Reply-To: <20140107005003.10786.85164.stgit@bhelgaas-glaptop.roam.corp.google.com> References: <20140107005003.10786.85164.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 From: Yinghai Lu Try to allocate space for 64-bit BARs above 4G first, to preserve the space below 4G for 32-bit BARs. If there's no space above 4G available, fall back to allocating anywhere. [bhelgaas: reworked starting from http://lkml.kernel.org/r/1387485843-17403-2-git-send-email-yinghai@kernel.org] Signed-off-by: Yinghai Lu Signed-off-by: Bjorn Helgaas --- drivers/pci/bus.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 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/bus.c b/drivers/pci/bus.c index 58beaaba50ee..107ad9a5b8aa 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -101,6 +101,8 @@ void pci_bus_remove_resources(struct pci_bus *bus) static struct pci_bus_region pci_32_bit = {0, 0xffffffffULL}; static struct pci_bus_region pci_64_bit = {0, (resource_size_t) 0xffffffffffffffffULL}; +static struct pci_bus_region pci_high = {(resource_size_t) 0x100000000ULL, + (resource_size_t) 0xffffffffffffffffULL}; /* * @res contains CPU addresses. Clip it so the corresponding bus addresses @@ -196,8 +198,7 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res, * alignment and type, try to find an acceptable resource allocation * for a specific device resource. */ -int -pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, +int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, resource_size_t size, resource_size_t align, resource_size_t min, unsigned int type_mask, resource_size_t (*alignf)(void *, @@ -206,10 +207,19 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, resource_size_t), void *alignf_data) { - if (res->flags & IORESOURCE_MEM_64) + int rc; + + if (res->flags & IORESOURCE_MEM_64) { + rc = pci_bus_alloc_from_region(bus, res, size, align, min, + type_mask, alignf, alignf_data, + &pci_high); + if (rc == 0) + return 0; + return pci_bus_alloc_from_region(bus, res, size, align, min, type_mask, alignf, alignf_data, &pci_64_bit); + } return pci_bus_alloc_from_region(bus, res, size, align, min, type_mask, alignf, alignf_data,