From patchwork Fri May 11 00:49:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Derrick X-Patchwork-Id: 911650 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40hs125mbmz9rxs for ; Fri, 11 May 2018 10:49:10 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750830AbeEKAtI (ORCPT ); Thu, 10 May 2018 20:49:08 -0400 Received: from mga07.intel.com ([134.134.136.100]:30051 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750758AbeEKAtH (ORCPT ); Thu, 10 May 2018 20:49:07 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 May 2018 17:49:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,387,1520924400"; d="scan'208";a="54205129" Received: from jderrick-mobl.amr.corp.intel.com ([10.255.1.85]) by fmsmga001.fm.intel.com with ESMTP; 10 May 2018 17:49:06 -0700 From: Jon Derrick To: Bjorn Helgaas , Keith Busch , Cc: Joerg Roedel , Myron Stowe , Dave Fugate , Scott Bauer , Jon Derrick Subject: [RFC PATCH 2/4] PCI/VMD: Add offset to bus numbers if necessary Date: Thu, 10 May 2018 18:49:01 -0600 Message-Id: <20180511004903.19892-3-jonathan.derrick@intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180511004903.19892-1-jonathan.derrick@intel.com> References: <20180511004903.19892-1-jonathan.derrick@intel.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Depending on platform configuration, the new VMD device's bus numbers may require being offset by 128. We determine this requirement by checking the value of two vendor specific capability registers in the VMD endpoint: VMCAP[0] | VMCONFIG[9:8] | Bus Numbers ---------------------------------------- 0 | * | 0-255 1 | 00 | 0-127 1 | 01 | 128-255 1 | 10 | 0-255 Signed-off-by: Jon Derrick --- drivers/pci/host/vmd.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/pci/host/vmd.c b/drivers/pci/host/vmd.c index 62270aeb7a2e..fdfc286a1c9e 100644 --- a/drivers/pci/host/vmd.c +++ b/drivers/pci/host/vmd.c @@ -24,6 +24,10 @@ #define VMD_MEMBAR1 2 #define VMD_MEMBAR2 4 +#define PCI_REG_VMCAP 0x40 +#define BUS_RESTRICT_CAP(vmcap) (vmcap & 0x1) +#define PCI_REG_VMCONFIG 0x44 +#define BUS_RESTRICT_CFG(vmcfg) ((vmcfg >> 8) & 0x3) #define PCI_REG_VMLOCK 0x70 #define MB2_SHADOW_EN(vmlock) (vmlock & 0x2) @@ -556,13 +560,27 @@ static int vmd_enable_domain(struct vmd_dev *vmd) struct resource *res; unsigned long flags; LIST_HEAD(resources); - resource_size_t start, end, membar2_offset; + resource_size_t start, end, membar2_offset, busn_start = 0; + + /* + * Depending on the root port configuration, VMD may assign bus numbers + * between 0-127 or 128-255 + */ + if (vmd->dev->device == 0x28c0) { + u32 vmcap, vmconfig; + + pci_read_config_dword(vmd->dev, PCI_REG_VMCAP, &vmcap); + pci_read_config_dword(vmd->dev, PCI_REG_VMCONFIG, &vmconfig); + if (BUS_RESTRICT_CAP(vmcap) && + (BUS_RESTRICT_CFG(vmconfig) == 0x1)) + busn_start = 128; + } res = &vmd->dev->resource[VMD_CFGBAR]; vmd->resources[0] = (struct resource) { .name = "VMD CFGBAR", - .start = 0, - .end = (resource_size(res) >> 20) - 1, + .start = busn_start, + .end = busn_start + (resource_size(res) >> 20) - 1, .flags = IORESOURCE_BUS | IORESOURCE_PCI_FIXED, }; @@ -636,8 +654,8 @@ static int vmd_enable_domain(struct vmd_dev *vmd) pci_add_resource(&resources, &vmd->resources[0]); pci_add_resource(&resources, &vmd->resources[1]); pci_add_resource(&resources, &vmd->resources[2]); - vmd->bus = pci_create_root_bus(&vmd->dev->dev, 0, &vmd_ops, sd, - &resources); + vmd->bus = pci_create_root_bus(&vmd->dev->dev, busn_start, &vmd_ops, + sd, &resources); if (!vmd->bus) { pci_free_resource_list(&resources); irq_domain_remove(vmd->irq_domain);