From patchwork Tue Jun 7 14:24:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Koehrer Mathias (ETAS/ESW5)" X-Patchwork-Id: 631642 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 3rPDN70tHZz9t2D for ; Wed, 8 Jun 2016 00:24:23 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752606AbcFGOYV (ORCPT ); Tue, 7 Jun 2016 10:24:21 -0400 Received: from smtp6-v.fe.bosch.de ([139.15.237.11]:50898 "EHLO smtp6-v.fe.bosch.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752132AbcFGOYU convert rfc822-to-8bit (ORCPT ); Tue, 7 Jun 2016 10:24:20 -0400 Received: from vsmta11.fe.internet.bosch.com (unknown [10.4.98.51]) by imta24.fe.bosch.de (Postfix) with ESMTP id D6EEDD80079; Tue, 7 Jun 2016 16:24:18 +0200 (CEST) Received: from FE-MBX1012.de.bosch.com (vsgw24.fe.internet.bosch.com [10.4.98.24]) by vsmta11.fe.internet.bosch.com (Postfix) with ESMTP id B9B1123804EA; Tue, 7 Jun 2016 16:24:18 +0200 (CEST) Received: from FE-MBX1012.de.bosch.com (10.3.230.70) by FE-MBX1012.de.bosch.com (10.3.230.70) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Tue, 7 Jun 2016 16:24:18 +0200 Received: from FE-MBX1012.de.bosch.com ([fe80::310c:6b49:1d6e:47a]) by FE-MBX1012.de.bosch.com ([fe80::310c:6b49:1d6e:47a%18]) with mapi id 15.00.1178.000; Tue, 7 Jun 2016 16:24:18 +0200 From: "Koehrer Mathias (ETAS/ESW5)" To: "gregkh@linuxfoundation.org" CC: "linux-pci@vger.kernel.org" , "bhelgaas@google.com" , "hjk@hansjkoch.de" Subject: [PATCH] Extending kernel option pci=resource_alignment to be able to specify PCI device/vendor IDs Thread-Topic: [PATCH] Extending kernel option pci=resource_alignment to be able to specify PCI device/vendor IDs Thread-Index: AdHAx8gaDR+FU6y0QL6adAUxBOH5fA== Date: Tue, 7 Jun 2016 14:24:17 +0000 Message-ID: <22400b8828ad44ddbccb876cc5ca3b11@FE-MBX1012.de.bosch.com> Accept-Language: de-DE, en-US Content-Language: de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.5.145.185] MIME-Version: 1.0 X-TM-AS-MML: disable X-TM-AS-Product-Ver: IMSS-7.1.0.1679-8.0.0.1202-22376.006 X-TMASE-MatchedRID: 5aJpZVhWVXNFsw2Lp+kSuFu4M/xm4KZeO1IfDKON40lBL//DKiVcziLW R2TcjmIxv2B1Wiv+bnvem5jmylDk/deV00rMo+W98YGKGucXIE+BHKTJ+sfXGUENV4Lwnu7BFAx 8b8GXiy3ERx+bb7v/+cGfVvC1EFC2DXVj0zMhpTYVglQa/gMvfPZfafJjZZIJd71AOvz4tNyby3 1RR+vPLS8vrA3c3A0HcpY/M8utm1/HQuauwt+FXISvKOGqLLPK0pVrZbbfikhXU/N8EvfsRCzyb VqWyY2NTdSgxz4EOql4LHI6F5wnnE26Z3ZYh9f3ngIgpj8eDcDYr6U3ZlQkdsRB0bsfrpPIfiAq rjYtFiT3o658kc8r0lr861rtkQyx29sXsEMeZMrC9u1VRvXIkH7cGd19dSFd Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Some uio based PCI drivers (e.g. uio_cif) do not work if the assigned PCI memory resources are not page aligned. By using the kernel option "pci=resource_alignment" it is possible to force single PCI boards to use page alignment for their memory resources. However, this is fairly cumbersome if multiple of these boards are in use as the specification of the cards has to be done via PCI bus/slot/function number which might change e.g. by adding another board. This patch extends the kernel option "pci=resource_alignment" to allow to specify the relevant boards via PCI device/vendor (and subdevice/subvendor) ids. The specification of the devices via device/vendor is indicated by a leading string "pci:" as argument to "pci=resource_alignment". The format of the specification is pci::[::] Signed-off-by: Mathias Koehrer --- Documentation/kernel-parameters.txt | 2 + drivers/pci/pci.c | 66 +++++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 19 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 Index: linux-4.7-rc1/Documentation/kernel-parameters.txt =================================================================== --- linux-4.7-rc1.orig/Documentation/kernel-parameters.txt +++ linux-4.7-rc1/Documentation/kernel-parameters.txt @@ -2998,6 +2998,8 @@ bytes respectively. Such letter suffixes resource_alignment= Format: [@][:]:.[; ...] + [@]pci::\ + [::][; ...] Specifies alignment and device to reassign aligned memory resources. If is not specified, Index: linux-4.7-rc1/drivers/pci/pci.c =================================================================== --- linux-4.7-rc1.orig/drivers/pci/pci.c +++ linux-4.7-rc1/drivers/pci/pci.c @@ -4755,6 +4755,7 @@ static DEFINE_SPINLOCK(resource_alignmen static resource_size_t pci_specified_resource_alignment(struct pci_dev *dev) { int seg, bus, slot, func, align_order, count; + unsigned short vendor, device, subsystem_vendor, subsystem_device; resource_size_t align = 0; char *p; @@ -4768,28 +4769,55 @@ static resource_size_t pci_specified_res } else { align_order = -1; } - if (sscanf(p, "%x:%x:%x.%x%n", - &seg, &bus, &slot, &func, &count) != 4) { - seg = 0; - if (sscanf(p, "%x:%x.%x%n", - &bus, &slot, &func, &count) != 3) { - /* Invalid format */ - printk(KERN_ERR "PCI: Can't parse resource_alignment parameter: %s\n", - p); + if (strncmp(p, "pci:", 4) == 0) { + /* PCI vendor/device (subvendor/subdevice) ids are specified */ + p += 4; + if (sscanf(p, "%hx:%hx:%hx:%hx%n", + &vendor, &device, &subsystem_vendor, &subsystem_device, &count) != 4) { + if (sscanf(p, "%hx:%hx%n", &vendor, &device, &count) != 2) { + printk(KERN_ERR "PCI: Can't parse resource_alignment parameter: pci:%s\n", + p); + break; + } + subsystem_vendor = subsystem_device = 0; + } + p += count; + if ((!vendor || (vendor == dev->vendor)) && + (!device || (device == dev->device)) && + (!subsystem_vendor || (subsystem_vendor == dev->subsystem_vendor)) && + (!subsystem_device || (subsystem_device == dev->subsystem_device))) { + if (align_order == -1) + align = PAGE_SIZE; + else + align = 1 << align_order; + /* Found */ break; } } - p += count; - if (seg == pci_domain_nr(dev->bus) && - bus == dev->bus->number && - slot == PCI_SLOT(dev->devfn) && - func == PCI_FUNC(dev->devfn)) { - if (align_order == -1) - align = PAGE_SIZE; - else - align = 1 << align_order; - /* Found */ - break; + else { + if (sscanf(p, "%x:%x:%x.%x%n", + &seg, &bus, &slot, &func, &count) != 4) { + seg = 0; + if (sscanf(p, "%x:%x.%x%n", + &bus, &slot, &func, &count) != 3) { + /* Invalid format */ + printk(KERN_ERR "PCI: Can't parse resource_alignment parameter: %s\n", + p); + break; + } + } + p += count; + if (seg == pci_domain_nr(dev->bus) && + bus == dev->bus->number && + slot == PCI_SLOT(dev->devfn) && + func == PCI_FUNC(dev->devfn)) { + if (align_order == -1) + align = PAGE_SIZE; + else + align = 1 << align_order; + /* Found */ + break; + } } if (*p != ';' && *p != ',') { /* End of param or invalid format */