From patchwork Fri Oct 25 21:50:33 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: 13851874 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 00E04D149F3 for ; Fri, 25 Oct 2024 21:51:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6D3A410EB8F; Fri, 25 Oct 2024 21:51:14 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="BHGaNp9q"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2E80510EB8F; Fri, 25 Oct 2024 21:51:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729893073; x=1761429073; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=b+AcW5z+LhuxH8S4a6rgeC+p3lNIPIrjSHwqh1CNDKg=; b=BHGaNp9qqdquQObATcqdnWzmLwZ8smUgdlDB7FJsOssS2dDkAQpG/KPG TAGJA43oYxmiOt56UTlX6V/Sq47kKPZ0uYH685f7OrTF8UjwHl9dtoWI2 in4tKgXPDa2pEJ3cOd+X9GrifDRDqnLy5G8PgBf+FQtsUCqbOM93ffEa4 3EHYET+cX5MHfvLRkU4I4O6DAKSoY002paYEcJcB3fABU+/viC+dmC1kt LrTDx75wKHDHzczBzKajqZaeyJOrZJc9Bkx4xjepie8rWE4jBgJ8pemDn f41JKkhKDkohHwPEx3urHSmWJJnvv4bVZ21BjBZtyDiYQ0fwBAAE36iyY Q==; X-CSE-ConnectionGUID: osKvl+eXR3eM6/Blh5xjaw== X-CSE-MsgGUID: Knfmof7rTcarcSPxUiIxAQ== X-IronPort-AV: E=McAfee;i="6700,10204,11236"; a="29683411" X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="29683411" 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:13 -0700 X-CSE-ConnectionGUID: xOA1yq0DSQuWWn7xj0d1og== X-CSE-MsgGUID: XlM93+VVRRGLe77MUcIwiw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,233,1725346800"; d="scan'208";a="81492888" 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:13 -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:12 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) 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:12 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.168) by edgegateway.intel.com (134.134.137.100) 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:11 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=l1hSppBsaAQsTI8Ht+jNgyTfLeZIlgY5anTt19GT9VJ3Fw1+ZTIZ5d8ZqC0nUUjgM58Un7ywqy0fE5JWwJGooqTQXUARw4n+lagwux27sRw/4PaPkHprlTAIPdcEw8t24c0Y4AtRmfSWt3vK/QZO+QFOlYaG5rLfzm+QSevP6+hPsDQszfTep/jC8BmvRyJ6ukZhOg3yDAl8teZDXdQakbbdC4P8mvouUhp7zn9kHxvr/rx9SqE7zHqEmF211+1EzZIZ+Z8jJ5ebm1IGan5vFKGl6RG6URUmRPwZJnotT2CX4JJHmSA97sXxGnnugNdkltQW8sUodlqA2Ip2CYPlIg== 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=w0eyaZpCfnN0MwjPBmAOWVxef3FSGSOq9l1UFOMvkO4=; b=arirohtlEk6yOaCxEvqUEb5nCLZImSi/PsXsi25ijEyHwifjJUhoBEExZ6EYBlZrx7JwnCia/tE6OI7NjfUbYLVOkR0FIfMpPrfWnHdbyu8viZ6Zpx4hwbRFCLoty3B4+r7rqpG5gZ5nbkOBZMtkLgq8Xpn/CzTObSYsqT4q2SqXqcukWKSeBayBc4cI8sR57bQn22LxaejsJQgIwTqdVg0qFfTfKI5k5Nt/T7dPDBi6wSzrGu4DJGBApHGWQkKsdkv46dMERYn3uEFl/yX41cswKFwz001KhQpKXJemsV/hbOGkKk1Csh2WpbBVmwbqnYvw9E3cS1hEMnOiP2LwBw== 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 DS0PR11MB7682.namprd11.prod.outlook.com (2603:10b6:8:dc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.21; Fri, 25 Oct 2024 21:51:09 +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:09 +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 2/7] PCI: Add a helper to identify IOV resources Date: Fri, 25 Oct 2024 23:50:33 +0200 Message-ID: <20241025215038.3125626-3-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: MI1P293CA0017.ITAP293.PROD.OUTLOOK.COM (2603:10a6:290:3::13) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|DS0PR11MB7682:EE_ X-MS-Office365-Filtering-Correlation-Id: 78d1cde8-6918-44f5-4c6f-08dcf53f2279 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|366016; X-Microsoft-Antispam-Message-Info: =?utf-8?q?zgQ8KvapuBqXQ/5X7UWVIPS1XSYpZR7?= =?utf-8?q?Zbe1QGNSJRkMgXYMtCb42yuRKZ1wkR6OGGij/6fg9kMZEcdKeOsJax4lEBw9EQIUf?= =?utf-8?q?3SxU7bWZOUs4UU7hmY5HNxM0F64bxQwcfxsUEva3bZP6849r0sq2BhgUtCHjRdU8f?= =?utf-8?q?1PaKlm9m5hhEyEvgaib2TMKkJrUlC/oIfMz1KNzi0mLhhTIAaqa4TfqYS5xPV12FU?= =?utf-8?q?fv/laHDYAf+F5LtHos1yXweAW1ND0VrZGN0tpVPRyyIrKOgCTIzN7jq7YaPTk/N8U?= =?utf-8?q?5hb2b96dW6OMxT20IaMxP/9BiI9zzdGB1bml2QuXkv/G5zxbMNT/19w2kCMZq2z8z?= =?utf-8?q?uGeFrfy7tkxxFBaRtrVGJThSbtuwE79D+3l03oHtqNC7MWKrUYVPm9HZp/UDRgerp?= =?utf-8?q?8tLMQPBqO4CjhR2p99Pee3vlBcJWNogSwxBV3EbN3XODyKAtsZbLQZahFUDZEZziv?= =?utf-8?q?KSri7pv4XySISLv7AqUBD2sHbVhVlkNX7OYJ9WHxE/Vhf30C9I3covG+UGg9IycbE?= =?utf-8?q?VwWB8goypkBlkmMkw8kViFm3jWgNkYCTd1OtS/Vj940wbHbPMVqBhl3AWjoiFi332?= =?utf-8?q?bzSkc1gA/2wDHclf4dfeMaT3i2m/XAqc19xY3QyFmmW61rt+eItPOAeVTT1m78R71?= =?utf-8?q?ECPRsyXib3cZ8NVEhN4YOa8Ipnf9MOwu9qjiJr947ih1p7iqsRcM8bqFQ5zdbAYJn?= =?utf-8?q?KVzuYiCnYyeDOp8nT2opDW4u4kSANoLu7HBiUJQh45Y5BBj4b8C+/Mp03MzUbknrs?= =?utf-8?q?3sUTIa2OoYrZ2NyLdswNWKy4K4UllMabdF5rNIZSsrEcGiMzjpJ6cLeaAhvdk5Khp?= =?utf-8?q?u/RXsNBi++x6hK98Jkq0Zq500lFCSxDK/9Hnx5RTmY5ST0Fs9E6qnKYY1zud+5fqM?= =?utf-8?q?dLm4O0cYp69d8/EgC+fMbm5UYT3B6bSL59mkBB5A8XFEgh9wKDEgQYkdv/dL4iiWc?= =?utf-8?q?EL+SAizFCMM10PiO0fW3FF8L2YC6i/pHcphBGlpHVu1SV8YwTAu8W1cJFB281poaq?= =?utf-8?q?H7DKdp7yNEg7GHNpUh+2Yjm5oKUFdjrZPlrYIdmVglLjsQVhG186jjfc9DSRGPa12?= =?utf-8?q?4gSWUC3P6maCcW5zXOrzSYGKmJIbUeRM5sj+pFIp+DdSbL0aKttraqy3AWNZzIZut?= =?utf-8?q?sNEEgKVOfQXIHQWLjF6zqQ4eX4M8EXgc2rqhL/IaKPYdCjqjweARGeFtO1zGTJP//?= =?utf-8?q?TFIypQ4ptn6+tc0gwi1xrAoHoL1AmB9UZrZiy0eyomBOsHKE903d4anfxDqXCnI8Q?= =?utf-8?q?qGDaTfFYsVFlr?= 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)(1800799024)(376014)(7416014)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?mDggQFZWAS9TBfWe71YVj8LDMNoy?= =?utf-8?q?IDzQo9jT7Vg0x9sqtnZ4eUNRJW94mtLY0bOF/aLO+DNIXKo/SfQQtd12LR86Hb5u4?= =?utf-8?q?7vsyCbM2czw4GfIw55NQ+N+Jv9ltTxDUkNdXX4vTZNxc2IiPyAh6heV0xEhKyfCgi?= =?utf-8?q?4sWGOqa+FMqhMKXyQ9TTpxO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bnxlWEVkom8i8ZwGC3kzNy/rFG/U39OQMV7CmBUoYuI5V?= =?utf-8?q?YwiglLNZ59INbz9UJfwGDzRzMtTK1SsYGmKMra4nyznpClQpo6PXlNNNiklBdDEqx?= =?utf-8?q?QiSuprwrEWc808UTLjxt3gQz7a2NGafBnsvylNOdr9VfaXGSunOkZtyGa1vscGb93?= =?utf-8?q?p3yamZskbi9EL3x177RYFqHfzqlIIXMoMEaR3igv/ngIUEPl/xSumzjed0I5uJ/86?= =?utf-8?q?sGt0QpRqr58YDQB1VxTw30YiGVRJ5qS3xqGdN5nHt1zcGf5ArTi0kXPxMHxso0MQd?= =?utf-8?q?WQXfTqPg40TytryNVGlITnm/tJWFWUIsu0JIceZAJHJDcZa0KnmOzI2GHOIs4hrh/?= =?utf-8?q?cHS00joGfewf+/LU+ompRf6r47RU0Y4A9jhLZ0W8sjPSILJ8jZx5XY0EeG+bxBWCw?= =?utf-8?q?NxG4CPDyrofnqKsDg4yBSNmOYrEVihbpiCMV4hTRhYOvuSFJWT9DkOEydKTWg/tJ6?= =?utf-8?q?HlOmBE9GW2xi0YfLkyJ0L//u6wnei3GjCA=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 78d1cde8-6918-44f5-4c6f-08dcf53f2279 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:09.1120 (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: fBvm5R8mZf0qTqPDAYKDqz4HtL1XLnNlVt/HkO//D1iTsggTKnsm2nXhMLy5lS9QxQj0jXW5clHg3rcF+5SzUlP/Bd9fJN9OkKYRc97MMnI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR11MB7682 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 special handling is required for IOV resources. Extract it to pci_resource_is_iov() helper and drop a few ifdefs. Signed-off-by: Michał Winiarski Reviewed-by: Ilpo Järvinen Reviewed-by: Christian König --- drivers/pci/pci.h | 19 +++++++++++++++---- drivers/pci/setup-bus.c | 7 +++---- drivers/pci/setup-res.c | 4 +--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 14d00ce45bfa9..48d345607e57e 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -580,6 +580,10 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno); resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno); void pci_restore_iov_state(struct pci_dev *dev); int pci_iov_bus_range(struct pci_bus *bus); +static inline bool pci_resource_is_iov(int resno) +{ + return resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END; +} extern const struct attribute_group sriov_pf_dev_attr_group; extern const struct attribute_group sriov_vf_dev_attr_group; #else @@ -589,12 +593,21 @@ static inline int pci_iov_init(struct pci_dev *dev) } static inline void pci_iov_release(struct pci_dev *dev) { } static inline void pci_iov_remove(struct pci_dev *dev) { } +static inline void pci_iov_update_resource(struct pci_dev *dev, int resno) { } +static inline resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, + int resno) +{ + return 0; +} static inline void pci_restore_iov_state(struct pci_dev *dev) { } static inline int pci_iov_bus_range(struct pci_bus *bus) { return 0; } - +static inline bool pci_resource_is_iov(int resno) +{ + return false; +} #endif /* CONFIG_PCI_IOV */ #ifdef CONFIG_PCIE_PTM @@ -616,12 +629,10 @@ unsigned long pci_cardbus_resource_alignment(struct resource *); static inline resource_size_t pci_resource_alignment(struct pci_dev *dev, struct resource *res) { -#ifdef CONFIG_PCI_IOV int resno = res - dev->resource; - if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END) + if (pci_resource_is_iov(resno)) return pci_sriov_resource_alignment(dev, resno); -#endif if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS) return pci_cardbus_resource_alignment(res); return resource_alignment(res); diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 23082bc0ca37a..ba293df10c050 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1093,17 +1093,16 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, (r->flags & mask) != type3)) continue; r_size = resource_size(r); -#ifdef CONFIG_PCI_IOV + /* Put SRIOV requested res to the optional list */ - if (realloc_head && i >= PCI_IOV_RESOURCES && - i <= PCI_IOV_RESOURCE_END) { + if (realloc_head && pci_resource_is_iov(i)) { add_align = max(pci_resource_alignment(dev, r), add_align); r->end = r->start - 1; add_to_list(realloc_head, dev, r, r_size, 0 /* Don't care */); children_add_size += r_size; continue; } -#endif + /* * aligns[0] is for 1MB (since bridge memory * windows are always at least 1MB aligned), so diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index c6d933ddfd464..e2cf79253ebda 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -127,10 +127,8 @@ void pci_update_resource(struct pci_dev *dev, int resno) { if (resno <= PCI_ROM_RESOURCE) pci_std_update_resource(dev, resno); -#ifdef CONFIG_PCI_IOV - else if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END) + else if (pci_resource_is_iov(resno)) pci_iov_update_resource(dev, resno); -#endif } int pci_claim_resource(struct pci_dev *dev, int resource)