From patchwork Fri Oct 25 21:50:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 13851875 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E6DD9D149F4 for ; Fri, 25 Oct 2024 21:51:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7246D10E121; Fri, 25 Oct 2024 21:51:18 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="AFs4lS4t"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id 838B410EB8E; Fri, 25 Oct 2024 21:51:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729893077; x=1761429077; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=qJltdOa9zzHaE43rZDoTUvvQPNmAf3k66aRnLSDP5W8=; b=AFs4lS4tLl6VpuQwFI+cFbDLNt6snfaRtaGUVFQ3dLqJ4SeAf29v4mV2 NyzLBtGsoRJSuQUpgAKvtXiTLI1Ie+5DXg++iqDw/uX/VmTf/tzU9r50o b1n0mDH/he/PzjSyMM4n0ueEY6K4/ENy1FCXFuohCl+UIrOGEwEjhJxXa O29c51i4akni1ZVlBD6sbVq+s9vK/ckU8FbFv8GmrdiuacQLX5+uZ0jZP JZi85YbcpzLT53qHi2gdqLpa6KfBK6FYy/55evpRAHu3FVouL6+Yocalb UCYAt6K/sIz9JQ6Gf18DHozfq/knWPAqeEQVJLHDsi1u2aUN5gbqXIgcv g==; X-CSE-ConnectionGUID: UtVfjJd6TLm5Joy0pmXy0w== X-CSE-MsgGUID: /LKRNZEbRTunsc5t15TioQ== X-IronPort-AV: E=McAfee;i="6700,10204,11236"; a="29683426" X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="29683426" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2024 14:51:17 -0700 X-CSE-ConnectionGUID: oDl29PNyT9SimuKdfx/5Yg== X-CSE-MsgGUID: XY2ml2VoTZySHarOGi7chg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="81492900" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orviesa007.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 25 Oct 2024 14:51:16 -0700 Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 25 Oct 2024 14:51:15 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Fri, 25 Oct 2024 14:51:15 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.176) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 25 Oct 2024 14:51:15 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nXa+T0crMxRVfD+POB1wX1tzkQVUFVzJoXQw/mrbwMSeIpIkXf2eNr2tumtqAYenTglHXtn/r2zuA2IH72XkFVCzOPEMV0OeQbHsU2piyl8Y92hWHWpuB/wDYb22xQHXXZpd1Z3XbAappPSSlrFTbOjjJNIWsztQRhOLQ/DrqCxtxgsYXI9XWb28HCHR64jzOgP6UmPJTWll1pYsV/zwAXkhNH52kmfsDBDu76z+XMz9qhIiJw3cXJEnsdAhQCNsMaWkbVRNQaSq9ehqXGfQAFYkxdRWsxmpFPbnrKpYsd2iYyGMg1hThXJ/kw+LivLS7B80k/ghzZnNwEQU4SDRgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ROterculxntEPzXGkt8YiHRCMcU9C2S0nxZB0C13n5I=; b=lDLPKTqIaVtmFV0E8YaN6mw0ibn6OJWSwz//DvnmZ8u8SlKbF887Qx6YGey24QdHpmxRnQaRogV9pK2CBUS1+UDsszYPbZs0nky9T2R2tphJMYst+hxSTuh3Ds0GkT5FZaNCbkijQGh46byVx8+txBRI5fxxGtuMnKNbg5qcIcfBqKrS6OYj+heYIc7OX4Idpy0AywdkWTVxO0MUP4G5ZKwIIwWiKF/h8BG+QPDU8UoYBJwx5aUk0wlAjgfz6N624Ns9dNwl3b/Z8uFBLuCsfITWkbgCarRTWnRZc+YA2F4/JYplCVeuZwTfZC+Ekcnrr34nXukcY6lVTjnIcleBOA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by CY8PR11MB7745.namprd11.prod.outlook.com (2603:10b6:930:90::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16; Fri, 25 Oct 2024 21:51:13 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::927a:9c08:26f7:5b39]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::927a:9c08:26f7:5b39%5]) with mapi id 15.20.8093.018; Fri, 25 Oct 2024 21:51:13 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , , , , "Bjorn Helgaas" , =?utf-8?q?Christian_K=C3=B6nig?= , =?utf-8?q?Krzy?= =?utf-8?q?sztof_Wilczy=C5=84ski?= , =?utf-8?q?Ilpo_J=C3=A4rvi?= =?utf-8?q?nen?= CC: Rodrigo Vivi , Michal Wajdeczko , Lucas De Marchi , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Matt Roper , =?utf-8?q?Micha=C5=82_Winiarski?= Subject: [PATCH v4 3/7] PCI: Add a helper to convert between standard and IOV resources Date: Fri, 25 Oct 2024 23:50:34 +0200 Message-ID: <20241025215038.3125626-4-michal.winiarski@intel.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241025215038.3125626-1-michal.winiarski@intel.com> References: <20241025215038.3125626-1-michal.winiarski@intel.com> X-ClientProxiedBy: WA2P291CA0035.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:1f::11) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|CY8PR11MB7745:EE_ X-MS-Office365-Filtering-Correlation-Id: 51f4a631-28cf-4329-26c2-08dcf53f2538 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?7HVHlATwIoffjkNsybpR88C2SDf6AKb?= =?utf-8?q?PFK9tUGSSUmT9GX1G0qeV65t9KQSHN8Ba+aO69zLYFVH4XTRjSXzj+mKnWqVguoCl?= =?utf-8?q?26ASy9eyGZ8r3AuKpd+vJ1jex7jR8y8Bpu9QN9QTRPoQP6UAYtgxJI5BYdsOCp91f?= =?utf-8?q?9/Fx0/wlYJ9WvwihKV/SELGE6PKRanAL2Tg6KvgOFLf0lku+C7I9c5+VZbrtCLaHr?= =?utf-8?q?y6UpSOdKx/Bef4qihkvwd45FBnwzvLNCpPf/3TTfsFMwA3cKcrDQp9Ht6D8pu9UoT?= =?utf-8?q?U6OnYkYloIgOtvSv5ldDcWaG+97QzSLqKcJSfnEeDUuFo8dms8Da7rJd9MWhwSJhU?= =?utf-8?q?QEEBOUlxX1sZqcvKme6xOlbiax9SukJTQtHRYC6vfFv+bWOjWFQsukyO+QzEvlG+f?= =?utf-8?q?UAva5hoKomNCXPDfwkCjg2/ZbLaXRX7WMg/9JKrRO4TYVN77XGNbj/wWk19qG7dg7?= =?utf-8?q?J9e1W0Fm3jMyfEBqqEL715vYRMMrik0qJPv+JuGI26c8XCuZMHmHmpCQVpxsCx2+x?= =?utf-8?q?MNIhbun3WSaLCiIDRVrwqSv4GbPWOaET+Zjk3UooOW+H1RAi6flSZsoXXgRbbU1UP?= =?utf-8?q?s8LtXyjSAQV/pVGUQ+VTp9Tv5CTcjisVFaPawoEV3PBz1ouvQKi4n2QYPTiqp/TGk?= =?utf-8?q?U7BkBRvKyk7T5g9DAj+6rtMgbCskDFYKQbztyKTralt/xAYDeeayuf8t3Huye5sEc?= =?utf-8?q?CMhpew27mOholroYrRrq+Ao1wxc/LL+W1F9OMDEbU757+LJt3H9NwvRVHJr7TEbND?= =?utf-8?q?wEXkKfcICF/AT9hjSF+Q2zmRyNrfU1l6wnwmUerU0t4NAiX0X/TcoW2Izyqu5BXE5?= =?utf-8?q?Qq+XUqKgiYFRHbbzRURaopgJJJXs0Blnuyx8uhElMGzcBVjHPfV7lgIFoqPDGyFU0?= =?utf-8?q?OVF0CCb8e/O/f1KBRNyzbSBRoXppQ2CZhLjeTBE0Fa8e2Z8qBMj9SxZceFXfBVazk?= =?utf-8?q?c1gzfQsliqhPgLEeK4uDDbzp4zHYQ/CApnC2lUpLjFHWGDVHzKNh4g4vVi+DHi0Dk?= =?utf-8?q?WjFT8PMGxU3RwjUYPBNFjJ7WBt+11U1FP/IabelCWB2wqZTGCgWiVgdOmfWzq2lW7?= =?utf-8?q?atb7DB3WkCPjN04zEBGxTbDz2ow0QF16XN6Gt0zbYcHxUx7rAWCo78VE9d8Bd5Qfw?= =?utf-8?q?w5ID6jJ65reW1tKWEcOXF5cH+kxsLNMIbqqqpeCjyQvVU1PfrgluXHWoFEEq+DLpa?= =?utf-8?q?YjDaZ9LLFMUsyHTyXrEvRfKBd5PIQZNbzYQMUllK42aBJIZKSmB1OM6H49CiHg0BG?= =?utf-8?q?zjf8QSB67Wm1F?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(7416014)(366016)(1800799024)(376014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?xkeJfcRE4tfe2ze9pE3Ml+BAaJuM?= =?utf-8?q?9YPWoRtz5J+kdTN/kDvGq/ZhIBOw6xyobebqtaaaQ4VAi2oHa1UDn+OfeXk3TfhEO?= =?utf-8?q?vFj2Z3bakPSrHGhRMWMmVWlE8y6dra+F8xuHxMRDh4wVnPIOEIuuhsdPHrVExxdaB?= =?utf-8?q?Pc/t+YK68XUNc+ZWq2xDQdHZ07Fs7LGLK0k55YwgJUhqUYAQmS3YHp0fa7mODTAuD?= =?utf-8?q?kKz4N8LdrcpIwmxhF/2/SOn8DvIhundeA2bLEN3wN56U97+iHQ1qnNqZuWTBRjJaQ?= =?utf-8?q?eWkeSscdwsqndt+Ov7n9USVOG+yW2cEvvPMenSE7vMvXe7YUo3ESkSrVh3dIbolbY?= =?utf-8?q?dXJ9IoCpQH8tZOZjgtw+dEcTyXxjbholkeTazE5UcZ1XkEc5h3lzfVJYoZPKqiov1?= =?utf-8?q?7u2+MUf6z1pxJ9plzaBao8h1B9ZRxu4CbqNaJnqWw6bTbvLc0NMnTZ9+Zkf3BzOPG?= =?utf-8?q?Ftq5d3b24kaY9K6FzoSwiCd5i8/bvBKOzWJ+NSEUvjztBkxDjMNbGljC85Z82GlM8?= =?utf-8?q?M0bwDV6mP1ij3K6/PR+q1p1618kkeFV6U0v0Oj7aeaulwi2vs9/M+YPJG403XbAaT?= =?utf-8?q?BK8BJA75N6onjBBKjtEJrRnL5g+LODttVXsNEhb13jOSdbeq7WByQjElbs61psHo+?= =?utf-8?q?yZ9u0TLi5+vbHobD/bAMkWUebb0Tg/7gKDK5cSU1uuFxG7AcKjTkzGLRZv7ZEovX7?= =?utf-8?q?jzWNgZ0Yr8361GmHDKdjBDI0oY56S+hYDvNv6PYiH9e2XfYK20vCtADnHHgohJhge?= =?utf-8?q?ZSzroe7SyOvn4PkEl/gUHbIg6+9PGnRWTEJBfM2OxhStum5lPa2+D+UIYmOUBM3iP?= =?utf-8?q?4AcDVFea6iQy+Rm4iw6b64uWgEVSz7EY9mVbCatZQBm+88OHl2Zcnjk4FTrGM288I?= =?utf-8?q?PdaW1mybOrS7l0m0UUArGgKa/BxasOKO05aEOkmkDdJRAeipw+DQUtH/27V1KxMkN?= =?utf-8?q?sk1EFi3O4U4/2gY80Gt6ZSMIsUNJopU9f5ZnCBY6D07TmSaUrQ00kNaH2B79cxaVx?= =?utf-8?q?pQ5YpDn0s2t8WMGsN/8AkNwNFLGeSIE25MzVBRW6fT0Y7XlBJO0Fx82ZM0DsiyBu5?= =?utf-8?q?95r7shnc5h8aM/mjPV8xX345Wz5dCC27Q+HKLOLXjZT8Ab13k6PRmts1WK1RCidAS?= =?utf-8?q?5WZqr4GUWhnuCXQHgv9bsLUb5Sr5vNsUVTNw/xVps7u5/XztNpxiWaSPzyo/7KiFS?= =?utf-8?q?y/ua+8T4lfIA8rb2Am/Uk+oi1tUruYhuf+HrLUOMqVdZF2Wp4A1i4DWo2XFGu6can?= =?utf-8?q?M/PcewRBLzLL/42MlamBte38XHI/++m5wijbCV0f3wF+ZpOh2rK05ZYiNJBCrUbrW?= =?utf-8?q?PntS12+c7Pe5Bi+sP3YNASrzDKhAH3eChPwALpjscGvkbe58n803dPfPF5iZSk8Gh?= =?utf-8?q?LE5/ST6zbcmrIylGlIcRsaARr3DwP3mugGB8OEFYyWLsSVMbQQqjMThS5rB73K9cv?= =?utf-8?q?Y15d2lpKxtGNlM0nXy93qjGlM7Cj35pucKTxWtJxTUqf2SNx/0FzIYKd8wvCu3hXn?= =?utf-8?q?SgT6L48zrAxKUjMXh64I1TL/sNvDBRxhzw=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 51f4a631-28cf-4329-26c2-08dcf53f2538 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2024 21:51:13.7509 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: pIvcSHyDkYMQq+stL701h7HPja+aXIvpo4ZnY9Yz3FbS/dPMhxx5mPo4lOvtbcEpLcYIBfOrewX26zSZfGHW6haPEIKg19tKSwrO0Rgu/GQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR11MB7745 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" There are multiple places where conversions between IOV resources and standard resources are done. Extract the logic to pci_resource_to_iov() and pci_resource_from_iov() helpers. Suggested-by: Ilpo Järvinen Signed-off-by: Michał Winiarski --- drivers/pci/iov.c | 20 ++++++++++---------- drivers/pci/pci.h | 18 ++++++++++++++++++ drivers/pci/setup-bus.c | 2 +- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 6bdc9950b9787..eedc1df56c49e 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -151,7 +151,7 @@ resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno) if (!dev->is_physfn) return 0; - return dev->sriov->barsz[resno - PCI_IOV_RESOURCES]; + return dev->sriov->barsz[pci_resource_from_iov(resno)]; } static void pci_read_vf_config_common(struct pci_dev *virtfn) @@ -322,12 +322,12 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id) virtfn->multifunction = 0; for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - res = &dev->resource[i + PCI_IOV_RESOURCES]; + res = &dev->resource[pci_resource_to_iov(i)]; if (!res->parent) continue; virtfn->resource[i].name = pci_name(virtfn); virtfn->resource[i].flags = res->flags; - size = pci_iov_resource_size(dev, i + PCI_IOV_RESOURCES); + size = pci_iov_resource_size(dev, pci_resource_to_iov(i)); virtfn->resource[i].start = res->start + size * id; virtfn->resource[i].end = virtfn->resource[i].start + size - 1; rc = request_resource(res, &virtfn->resource[i]); @@ -624,8 +624,8 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) nres = 0; for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - bars |= (1 << (i + PCI_IOV_RESOURCES)); - res = &dev->resource[i + PCI_IOV_RESOURCES]; + bars |= (1 << pci_resource_to_iov(i)); + res = &dev->resource[pci_resource_to_iov(i)]; if (res->parent) nres++; } @@ -786,8 +786,8 @@ static int sriov_init(struct pci_dev *dev, int pos) nres = 0; for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - res = &dev->resource[i + PCI_IOV_RESOURCES]; - res_name = pci_resource_name(dev, i + PCI_IOV_RESOURCES); + res = &dev->resource[pci_resource_to_iov(i)]; + res_name = pci_resource_name(dev, pci_resource_to_iov(i)); /* * If it is already FIXED, don't change it, something @@ -844,7 +844,7 @@ static int sriov_init(struct pci_dev *dev, int pos) dev->is_physfn = 0; failed: for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - res = &dev->resource[i + PCI_IOV_RESOURCES]; + res = &dev->resource[pci_resource_to_iov(i)]; res->flags = 0; } @@ -906,7 +906,7 @@ static void sriov_restore_state(struct pci_dev *dev) pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, ctrl); for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) - pci_update_resource(dev, i + PCI_IOV_RESOURCES); + pci_update_resource(dev, pci_resource_to_iov(i)); pci_write_config_dword(dev, iov->pos + PCI_SRIOV_SYS_PGSIZE, iov->pgsz); pci_iov_set_numvfs(dev, iov->num_VFs); @@ -972,7 +972,7 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno) { struct pci_sriov *iov = dev->is_physfn ? dev->sriov : NULL; struct resource *res = dev->resource + resno; - int vf_bar = resno - PCI_IOV_RESOURCES; + int vf_bar = pci_resource_from_iov(resno); struct pci_bus_region region; u16 cmd; u32 new; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 48d345607e57e..1f8d88f0243b7 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -584,6 +584,15 @@ static inline bool pci_resource_is_iov(int resno) { return resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END; } +static inline int pci_resource_to_iov(int resno) +{ + return resno + PCI_IOV_RESOURCES; +} + +static inline int pci_resource_from_iov(int resno) +{ + return resno - PCI_IOV_RESOURCES; +} extern const struct attribute_group sriov_pf_dev_attr_group; extern const struct attribute_group sriov_vf_dev_attr_group; #else @@ -608,6 +617,15 @@ static inline bool pci_resource_is_iov(int resno) { return false; } +static inline int pci_resource_to_iov(int resno) +{ + return -ENODEV; +} + +static inline int pci_resource_from_iov(int resno) +{ + return -ENODEV; +} #endif /* CONFIG_PCI_IOV */ #ifdef CONFIG_PCIE_PTM diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index ba293df10c050..c5ad7c4ad6eb1 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1778,7 +1778,7 @@ static int iov_resources_unassigned(struct pci_dev *dev, void *data) bool *unassigned = data; for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - struct resource *r = &dev->resource[i + PCI_IOV_RESOURCES]; + struct resource *r = &dev->resource[pci_resource_to_iov(i)]; struct pci_bus_region region; /* Not assigned or rejected by kernel? */