From patchwork Thu Sep 19 22:35:55 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: 13808031 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 CDFDBCF3975 for ; Thu, 19 Sep 2024 22:38:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 54A8E10E779; Thu, 19 Sep 2024 22:38:34 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="heMFLgIN"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0E18710E779; Thu, 19 Sep 2024 22:38:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726785513; x=1758321513; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=SkkbXRnm25tgMF0IgRVj3Ttc412D7UDre1mtD2GNklU=; b=heMFLgINP3NtORu8SbJ39oDhXZm9Awc9Tm7VM9vpaKEmxQzz3L2qyBoM d9QumfS+2XIT0c0divgOJPYsMesmTkHDA8AJq9EAfXuy9fv4ZGp9k6ZcY BXEmUhFEgKMIVUUhsdScrxGo8oFbntElpwxZZxunFSZk+BLX1362n05Gp +0dIK1Fvta40X35GKHscO+5DYia683F5KOBJgvv1wxuydxd6k9te9eBen V5eE1v1Nq8OhEjTa8Ek1H5gIU3UIOH7slNDjzLw0E5fdoc/zan3U7W1LD RNblDZx66SSqD8tehNXkLRhPDq3ulDTMduoQr2dMlwqqVxtXJNO5feRHN A==; X-CSE-ConnectionGUID: K7piS6gLQseWIi7Xfl3Fjw== X-CSE-MsgGUID: opVTMw/lQtiNofDnj1Zu2w== X-IronPort-AV: E=McAfee;i="6700,10204,11200"; a="48309521" X-IronPort-AV: E=Sophos;i="6.10,243,1719903600"; d="scan'208";a="48309521" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2024 15:38:32 -0700 X-CSE-ConnectionGUID: ZnsHlbloRSaMJra4DysVTQ== X-CSE-MsgGUID: UKmxLiyNT4eHnlS21sS9iQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,243,1719903600"; d="scan'208";a="70334039" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by fmviesa010.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 19 Sep 2024 15:38:32 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 19 Sep 2024 15:38:31 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 19 Sep 2024 15:38:31 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Thu, 19 Sep 2024 15:38:31 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.41) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 19 Sep 2024 15:38:31 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=N9z7AdkOajGTE1de+aWqASh7i9Zk4oHzqVzTq/V0S7iRvsNpUR6tR7Ub98yK1iEv1FL4TZrY7jerq89hPl971KQ1syWigzZJfMMUvbS0XgoQlATvbtjCT9j42uB2mCaISyKzGQZ0AQg+8eHsxOFmDQIwber9sypTklwIKxnMTb472TL3dk0df71lO4DB/AWINnCxHvALCc4f6rV4YnFxkDvbFCvkQdzLDpWSrNQZaMwGYIUplDqKydkCRXj2PRWBDqm1qOAv1FCKhM9hHbfuK9aCKeAhSLysFBqEPr/fOVr/kL4RFOkUN59uO1MxtbrLtnZ3l60dJzSAhm0UuxhuRQ== 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=O2e8pnCVWF9f5NxGXVDREsXbrrXkrB+voyNQz3045ag=; b=WUIJvilPVKYbG+DeqbGtIOsTxLiwqLBxiMLHfgfIxRH2GqNUmR73UFc9nO0za66opAELBSHXWFKYZcG/XAKd6ZwO9/wYX2HEVWHjM2aIw8/g8ec8GgJehdoEwsTfZThIdGx3Gmvs46mU1b9WPPSO0dWY5Qb0de8FaBK2U7lXYDVvbNIecMSv4iMpeKfZp8De/PyEebt8hijyWuG41S+FCxU2Lx/SJ5Nmd2d29yugxI1QTZf8XKjFoLAedkRurRtsWzIHRqB8QaBH9KmYkGiJanJzO0Z5KVItDuCFei+/hdL7AoXWrz+gmHtdnpZRO21zftPD4/7JH+35YbEDsRtpHg== 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 MW4PR11MB5824.namprd11.prod.outlook.com (2603:10b6:303:187::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.26; Thu, 19 Sep 2024 22:38:27 +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.7982.018; Thu, 19 Sep 2024 22:38:27 +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?= 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 v2 1/3] PCI: Add support for VF Resizable Bar extended cap Date: Fri, 20 Sep 2024 00:35:55 +0200 Message-ID: <20240919223557.1897608-2-michal.winiarski@intel.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240919223557.1897608-1-michal.winiarski@intel.com> References: <20240919223557.1897608-1-michal.winiarski@intel.com> X-ClientProxiedBy: MI2P293CA0014.ITAP293.PROD.OUTLOOK.COM (2603:10a6:290:45::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_|MW4PR11MB5824:EE_ X-MS-Office365-Filtering-Correlation-Id: f1b8401a-a19d-45d2-61af-08dcd8fbc72e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?8UtKPVCZqpHgW42gLogpKe80LHie1oe?= =?utf-8?q?9PZTyAzjQfN0erkQ5wOK7WhfzF+WCk19CJFde6bzB9dHI//rmhDGE0DbGLE54Z2q/?= =?utf-8?q?7lgsb5s4tZlgdnyyQGysemSO0gez/SEkBZK+EbIVAQ77GJvRtt3KjewveJryGDjFc?= =?utf-8?q?/d2jbZc+X+FrTrQsDeNlPpJO+ZnSbUP4faXD7h83X/Dg9Kzf0SNvdaKVJru0/dDpd?= =?utf-8?q?St8FSIQN+WaKxAnyUlXpNszGCkX8fiicH2IHDxi/tCUu+jZCnQBpLsMQ9zgw9Ae6X?= =?utf-8?q?sqcdJI2dxwB4GNA95MWtUEuOAx3bdmzf5hMSLReJkIXekgKOtLSTt93iIEUYU1mWN?= =?utf-8?q?D7nb5Jpof6j9OnerlIPYfd4x6Pr5Hzd8K3JRcjbwC/33dmbj3a8mOgBpOrQcNnebf?= =?utf-8?q?0nwzvXTRLaOQi/Iw48Z56lxNOst3uQNqRoD86AWBdRwcOQzKTwPsUj/Zb18n187Pp?= =?utf-8?q?APJ744nld+VhJ12/R6yQ+pOHTMnz70I+poImVF+u2q1t/SMvALUpGy0+NUmVFrLra?= =?utf-8?q?eepM2NbT1sB6kZ057pU+/68KPLmcO8ws0W2kSdEHVn5adVI9SUnkL3PzUlyeKIF8m?= =?utf-8?q?YecpvmeVLNvu9U/bo+qDGYtgIqT8cdH8wcblAcWC1NCDV2XctzHJnJk4R+n3hj9wa?= =?utf-8?q?yqER2sq1+QA9wrGKcWlfDPowJYNQi/dRmZiLDAGIWHX+0sMLOMFEO9EvVYvS55Hfa?= =?utf-8?q?Fk44l3KE8cNEDdbkFzkBOCnk/4mItJ9B8O9Ld0pdYh+yIRnSUZP3MtRuBPFJksie8?= =?utf-8?q?sA3pGuSI28btOBFfWuaiF4aSggRr2TD8jQ/Z3hFhlzCDijMcfp8L6TYpPydERVt16?= =?utf-8?q?EJy5SRq9JIZpxA4yweE83hxA+fvJg9WxqXL0yK0P9/YUfsq/CqoraCChde/lEbWxd?= =?utf-8?q?CZhqvHys4eukDZ0H5kh/au9Jwo7H6BQtOT02Pxj5Rd1Wle5g7u4St7YD8pyTM0Ex5?= =?utf-8?q?BZxthCzDOMcy4vCJxVW3cjZ0xWtArtDclsfC/NTuONXG/6N7M6bzmlkV9s/wmj6+T?= =?utf-8?q?0fJNaXCoAsurSz+DwQlvwBbS/a67zvUBu+zgycUc+wr3A2xEGqkSl1uhTOisoq4j9?= =?utf-8?q?BLy1tyEwmIsXphv0vccPBlPt+2Cgw1YdzWDNvp+hDe1T/tSoEKz1DnW/kUxw3ztOj?= =?utf-8?q?JqjeRHO4IUHKSJ/RHlaQPy/pZe7WHMkOtU1Co5oW9LwqdbgH5cMnh6ROUeKHfYAZf?= =?utf-8?q?uZjbFZSTeooAdNuj+y5MP4OXTRqefSvz2+shVlbeUWXZzklSOtL9mXQnMwZbWZnvd?= =?utf-8?q?pDt+5VEF8vSQOIOtqZQidg5xro6LcwQ154g=3D=3D?= 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)(366016)(376014)(7416014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?XOfSWvttxg8chJmpwHb59EfEiibq?= =?utf-8?q?mYzgJPx4R1DAo92eLFrecsGiN3TElQ2oKMeF7qUhv9n1J3vlE5XMnpMJLDuTT306o?= =?utf-8?q?zF9iyMmr5sy6j4HP2ObRhPzs6MbSHAtjFy6b3QWWzBWMHoJrx2CrVNcJxxkUxcE0I?= =?utf-8?q?hWr2GliLpb3gkdF0ujCpfCXeKGFR9YFRx0QuyO4eQeEKOkFTp0+kUCbVz/ywLB0ob?= =?utf-8?q?Hm+cbAjPlQ2lhg6zTBJmXEJFaIekRCYsXIX1PlLKbl/zJ/NRy0f8UT1+SOQ5Ckh4s?= =?utf-8?q?7NhABhLeMLL8Hgbr5Whjlrvv2X6g+Ul7unxqvMYq8o1dlFwrJlXCu7qtIiREWhHoj?= =?utf-8?q?W+1+TPECDm4LI/MEPuL/n+vpIxnoawEMTwXERZ8dY52na43sNP+FVl5Eku1BCiRf4?= =?utf-8?q?BRWmmdwwd27plKBAVwpIa7vyLGME9q6L/aRH4PfFB62+pAapr1cVP2WErCgiw4/G2?= =?utf-8?q?FMdF+Ov5BDmCjglHBN+G1ttC2Udo8HTYmaJ9ZuKH7J1tHHnUr+6l/wTpIW7b8hOBd?= =?utf-8?q?omPpBNnoxKovbdefriclmr//zJUrKe4iVYJ6oKsVhIjejvcyPcR+XD+0aQwVdBASN?= =?utf-8?q?tFmFSkkVMLQkMaURwysiTLvEJpFOrVC+Rk9ZPp221/QEIpEkquOJLBy2k6UXSYica?= =?utf-8?q?53Y6zluQt8AnT1hW+17qZcPPKTMv2Uwc+7m8NeAhsSJ+TUS+8pNvQWBEbWGymXpvR?= =?utf-8?q?FAsFWXueVeHdGUDKW3I26df5yIlXBE695RI+11342RC48phEke53d71V1oMnrDHem?= =?utf-8?q?B5oJk1g+kAywB8ME4V4d6eIw+rN+0X2YFmWA0yE3vHy1TiLTemcfKGzsRUjHMTVeo?= =?utf-8?q?Olx6wWD6oT7c0ZazYmeKCUa8w5ui5/YMWJh6Fuy+C1ipV+BCh16xSq+c6n6NaStJW?= =?utf-8?q?6RO8LMQn23dKtSvSHluvYAg8fiBkk9AWtfZO0Jx/uN8WWdQSz0gvhUhMLng3Kderv?= =?utf-8?q?QFH3J7r1sHeYH9iwnaeyTF+50uxJ9nb2F1+vtAORySDm4oaarO0tDNiECz6j+g8rI?= =?utf-8?q?adzE2g4lDmfXw4XX6LF4abmjVxGAR75fEINiYrt38QuplLnZ2tu5w3S47QihinOU+?= =?utf-8?q?Hi3OZwRVUxLC6vhrMnq9crfeTcfBNRfw0PjmjFbE9l+eL4zTSdkjHOS/kegSBEjTO?= =?utf-8?q?TDNTi3lTkU0OITtjym3qyO3BexV55dfcni5IwTb1teGuI8iuSBtgf+R/+Ntqa7Wd6?= =?utf-8?q?be7VHzD+mJ8kzmqtHaSBEf+woA44u33QbFgV3J4Uz8c7IdHFXhDTp6+Up+Q6dcvYw?= =?utf-8?q?i3KysVibEJfdJhOj1yAWUiszLQaKAWNVZCRl+gBmDdqsklafHqRBxIBU4FQ+vqUHH?= =?utf-8?q?yv84elIuxi5ArmeZS4sXPPZuHhhbzouOXdutcZlejxwtKvb32DOdO7bdFcCAfdsl7?= =?utf-8?q?412XrPCmVOcQId4rSRvLbrp/TQLvGihC2Xwf6lJ1xny8lQuSq7vTgyQERpAfTZoKq?= =?utf-8?q?eH83gRtEuldUA8Q7psXFRInGpI9QLZsqDgcN7x3Kb1LhGqCdUZLLGek9/XCkNtXFt?= =?utf-8?q?fMQ9D3igEYsl4fKy9a9/XZb/zCcbDxFR+Q=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: f1b8401a-a19d-45d2-61af-08dcd8fbc72e X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2024 22:38:27.1217 (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: 8nN6RGIhfIcjCHQUXm1MGlxK9aKqfeAMdCMsnWrP/ObMNU0HjKuzlZfCSkprk1EOLS1Z6ha/uoxgNmtTLrXCbkXg2FaqS19ORtpTY8iBPjg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR11MB5824 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" Similar to regular resizable BAR, VF BAR can also be resized. The structures are very similar, which means we can reuse most of the implementation. See PCIe r4.0, sec 9.3.7.4. Signed-off-by: Michał Winiarski --- drivers/pci/iov.c | 28 ++++++++++++++++++++++ drivers/pci/pci.c | 40 ++++++++++++++++++++++++++++++- drivers/pci/pci.h | 14 ++++++++++- drivers/pci/setup-res.c | 44 ++++++++++++++++++++++++++++++----- include/uapi/linux/pci_regs.h | 1 + 5 files changed, 119 insertions(+), 8 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index aaa33e8dc4c97..e8ccd2ae0f024 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -153,6 +153,34 @@ resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno) return dev->sriov->barsz[resno - PCI_IOV_RESOURCES]; } +bool pci_resource_is_iov(struct pci_dev *dev, int resno) +{ + if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END) + return true; + + return false; +} + +void pci_iov_resource_set_size(struct pci_dev *dev, int resno, resource_size_t size) +{ + if (!pci_resource_is_iov(dev, resno)) { + dev_WARN(&dev->dev, "%s is not an IOV resource\n", + pci_resource_name(dev, resno)); + return; + } + + dev->sriov->barsz[resno - PCI_IOV_RESOURCES] = size; +} + +bool pci_iov_memory_decoding_enabled(struct pci_dev *dev) +{ + u16 cmd; + + pci_read_config_word(dev, dev->sriov->pos + PCI_SRIOV_CTRL, &cmd); + + return cmd & PCI_SRIOV_CTRL_MSE; +} + static void pci_read_vf_config_common(struct pci_dev *virtfn) { struct pci_dev *physfn = virtfn->physfn; diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index ffaaca0978cbc..d4522e365e7ba 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1901,6 +1901,35 @@ static void pci_restore_rebar_state(struct pci_dev *pdev) } } +static void pci_restore_vf_rebar_state(struct pci_dev *pdev) +{ + unsigned int pos, nbars, i; + u32 ctrl; + + if (!pdev->is_physfn) + return; + + pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_VF_REBAR); + if (!pos) + return; + + pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl); + nbars = FIELD_GET(PCI_REBAR_CTRL_NBAR_MASK, ctrl); + + for (i = 0; i < nbars; i++, pos += 8) { + struct resource *res; + int bar_idx, size; + + pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl); + bar_idx = ctrl & PCI_REBAR_CTRL_BAR_IDX; + res = pdev->resource + bar_idx; + size = pci_rebar_bytes_to_size(pdev->sriov->barsz[bar_idx]); + ctrl &= ~PCI_REBAR_CTRL_BAR_SIZE; + ctrl |= FIELD_PREP(PCI_REBAR_CTRL_BAR_SIZE, size); + pci_write_config_dword(pdev, pos + PCI_REBAR_CTRL, ctrl); + } +} + /** * pci_restore_state - Restore the saved state of a PCI device * @dev: PCI device that we're dealing with @@ -1916,6 +1945,7 @@ void pci_restore_state(struct pci_dev *dev) pci_restore_ats_state(dev); pci_restore_vc_state(dev); pci_restore_rebar_state(dev); + pci_restore_vf_rebar_state(dev); pci_restore_dpc_state(dev); pci_restore_ptm_state(dev); @@ -3703,10 +3733,18 @@ void pci_acs_init(struct pci_dev *dev) */ static int pci_rebar_find_pos(struct pci_dev *pdev, int bar) { + int cap = PCI_EXT_CAP_ID_REBAR; unsigned int pos, nbars, i; u32 ctrl; - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_REBAR); +#ifdef CONFIG_PCI_IOV + if (pci_resource_is_iov(pdev, bar)) { + cap = PCI_EXT_CAP_ID_VF_REBAR; + bar -= PCI_IOV_RESOURCES; + } +#endif + + pos = pci_find_ext_capability(pdev, cap); if (!pos) return -ENOTSUPP; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 79c8398f39384..e763b3fd4c7a2 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -556,6 +556,9 @@ void pci_restore_iov_state(struct pci_dev *dev); int pci_iov_bus_range(struct pci_bus *bus); extern const struct attribute_group sriov_pf_dev_attr_group; extern const struct attribute_group sriov_vf_dev_attr_group; +bool pci_resource_is_iov(struct pci_dev *dev, int resno); +bool pci_iov_memory_decoding_enabled(struct pci_dev *dev); +void pci_iov_resource_set_size(struct pci_dev *dev, int resno, resource_size_t size); #else static inline int pci_iov_init(struct pci_dev *dev) { @@ -568,7 +571,16 @@ static inline int pci_iov_bus_range(struct pci_bus *bus) { return 0; } - +static inline bool pci_iov_memory_decoding_enabled(struct pci_dev *dev) +{ + return false; +} +static inline bool pci_resource_is_iov(struct pci_dev *dev, int resno) +{ + return false; +} +static inline void pci_iov_resource_set_size(struct pci_dev *dev, int resno, + resource_size_t size) { } #endif /* CONFIG_PCI_IOV */ #ifdef CONFIG_PCIE_PTM diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index c6d933ddfd464..87a952a114f38 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -427,13 +427,44 @@ void pci_release_resource(struct pci_dev *dev, int resno) } EXPORT_SYMBOL(pci_release_resource); +static bool pci_memory_decoding_enabled(struct pci_dev *dev) +{ + u16 cmd; + + pci_read_config_word(dev, PCI_COMMAND, &cmd); + + return cmd & PCI_COMMAND_MEMORY; +} + +static int pci_resize_check_memory_decoding(struct pci_dev *dev, int resno) +{ + if (!pci_resource_is_iov(dev, resno) && pci_memory_decoding_enabled(dev)) + return -EBUSY; + else if (pci_resource_is_iov(dev, resno) && pci_iov_memory_decoding_enabled(dev)) + return -EBUSY; + + return 0; +} + +static void pci_resize_resource_set_size(struct pci_dev *dev, int resno, int size) +{ + resource_size_t res_size = pci_rebar_size_to_bytes(size); + struct resource *res = dev->resource + resno; + + if (!pci_resource_is_iov(dev, resno)) { + res->end = res->start + res_size - 1; + } else { + res->end = res->start + res_size * pci_sriov_get_totalvfs(dev) - 1; + pci_iov_resource_set_size(dev, resno, res_size); + } +} + int pci_resize_resource(struct pci_dev *dev, int resno, int size) { struct resource *res = dev->resource + resno; struct pci_host_bridge *host; int old, ret; u32 sizes; - u16 cmd; /* Check if we must preserve the firmware's resource assignment */ host = pci_find_host_bridge(dev->bus); @@ -444,9 +475,9 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size) if (!(res->flags & IORESOURCE_UNSET)) return -EBUSY; - pci_read_config_word(dev, PCI_COMMAND, &cmd); - if (cmd & PCI_COMMAND_MEMORY) - return -EBUSY; + ret = pci_resize_check_memory_decoding(dev, resno); + if (ret) + return ret; sizes = pci_rebar_get_possible_sizes(dev, resno); if (!sizes) @@ -463,7 +494,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size) if (ret) return ret; - res->end = res->start + pci_rebar_size_to_bytes(size) - 1; + pci_resize_resource_set_size(dev, resno, size); /* Check if the new config works by trying to assign everything. */ if (dev->bus->self) { @@ -475,7 +506,8 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size) error_resize: pci_rebar_set_size(dev, resno, old); - res->end = res->start + pci_rebar_size_to_bytes(old) - 1; + pci_resize_resource_set_size(dev, resno, old); + return ret; } EXPORT_SYMBOL(pci_resize_resource); diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h index 94c00996e633e..cb010008c6bb3 100644 --- a/include/uapi/linux/pci_regs.h +++ b/include/uapi/linux/pci_regs.h @@ -738,6 +738,7 @@ #define PCI_EXT_CAP_ID_L1SS 0x1E /* L1 PM Substates */ #define PCI_EXT_CAP_ID_PTM 0x1F /* Precision Time Measurement */ #define PCI_EXT_CAP_ID_DVSEC 0x23 /* Designated Vendor-Specific */ +#define PCI_EXT_CAP_ID_VF_REBAR 0x24 /* VF Resizable BAR */ #define PCI_EXT_CAP_ID_DLF 0x25 /* Data Link Feature */ #define PCI_EXT_CAP_ID_PL_16GT 0x26 /* Physical Layer 16.0 GT/s */ #define PCI_EXT_CAP_ID_PL_32GT 0x2A /* Physical Layer 32.0 GT/s */ From patchwork Thu Sep 19 22:35:56 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: 13808032 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 1D488CF3977 for ; Thu, 19 Sep 2024 22:38:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 77DE310E77C; Thu, 19 Sep 2024 22:38:36 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="TS/bhKeo"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id 350CD10E77C; Thu, 19 Sep 2024 22:38:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726785515; x=1758321515; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=eS0E31whnXBKSFMFJ0GVHUtUktaU8XpFULlAzs0+1qs=; b=TS/bhKeoeUVNxukKbIk5xM0qEOrUS7qgOruiovNQXKo37zdRzypdNt1f 3KmwVvZmTW3mhTiSY56rjVsyD74yAJRcSPQfFHixhPxQblpmBvlkg+mwH 9tJQf3FI4kU8cVhtkOvTbYiHFb82PGyFPjOwuHWZGJCQkEAYG9RfqXnbU 4Tui6h3oCnz0FofTk9xuE0T9680crVy58BpG6mIe4B6wxMNucu/DiHWDf FF8J1avV//kQ6BStPpyHmGClKHUQxid3h0OYxK63GsBu/0qAkpBxDu82X WY2Akef6hHers+iNovgchEURVtYabqcydyE/5xbajARysZmAivd5guz2u w==; X-CSE-ConnectionGUID: getiAQ2kR6Sgce1xUAIcLQ== X-CSE-MsgGUID: hylMvGaQRl+PubsR0TmroA== X-IronPort-AV: E=McAfee;i="6700,10204,11200"; a="48309534" X-IronPort-AV: E=Sophos;i="6.10,243,1719903600"; d="scan'208";a="48309534" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2024 15:38:34 -0700 X-CSE-ConnectionGUID: qcem5oLwTEmbzkSEh7/y0Q== X-CSE-MsgGUID: stq0zOzkRlmHJO3pxXanxQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,243,1719903600"; d="scan'208";a="70334048" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by fmviesa010.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 19 Sep 2024 15:38:35 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 19 Sep 2024 15:38:34 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Thu, 19 Sep 2024 15:38:34 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.48) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 19 Sep 2024 15:38:34 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xJ5Olot3dg8zmkzdnhJkMwWCwnqGvnmPKgbc8uy12jnqtarRUQVyMDawVxLo3D9zMiV5SWeZI9w+xoubLCKCcPVjZVEZTpyJwhW2ALDM0bhH8m5QVoBKo+4RAJaI5wqWuToWq4CH1OibwiMBuyEM2qKWgPpId5na3wmF+zeuasN8nqPG+sGmYg/uqf/XlddsdrgaarL+cRs+BqU0pm4ITa0yc9si2Nw2ohh4iAb+a2H53TxM0tImaDdkbydGjOYvjc47ykf2gxtqJyJDO43oAQ2u2/eSeVN57V5P8eMuIeuNy3rNqWNGFLv1vv8Ww7SkNH0K/qGzFGVuojy1sNNp0w== 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=TJfy8lBMZwBLNA92nEEFy/avPdhG6w929Ib94qVf9QE=; b=I546VOKCIAyv50qQv6i4zik8cJqz70wxaAFA2iHa6U2W9UUCKMTPvL6sSDXHz+uLyMBjVgQNe+EVrHMhg4ru1YcwP7Bcqxm0frNQ5wNLWvzGy6kabAvIjFNrd1wT+TCF+XuJkaK2vdSsSDdzqFA/OGxV9/A/JpNUnDZEE1UVyQGMH4u9kDBZIlAdC0p0eWlcN6KDC0NYrcwVxc3tyQp2iuDHUGVTcuOHEOgvlpECyWDY3ymG3ziYBROouuDU76lmIaNI/pmpYTiEXQzaciuFJngOdNlmLQorRqfVKh8Pi8SuB4gfuB70j5jnOuappp+E2DFHRceVAr7/AUp+EX9S5Q== 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 MW4PR11MB5824.namprd11.prod.outlook.com (2603:10b6:303:187::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.26; Thu, 19 Sep 2024 22:38:31 +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.7982.018; Thu, 19 Sep 2024 22:38:31 +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?= 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 v2 2/3] PCI: Allow extending VF BAR within original resource boundary Date: Fri, 20 Sep 2024 00:35:56 +0200 Message-ID: <20240919223557.1897608-3-michal.winiarski@intel.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240919223557.1897608-1-michal.winiarski@intel.com> References: <20240919223557.1897608-1-michal.winiarski@intel.com> X-ClientProxiedBy: WA1P291CA0003.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:19::6) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|MW4PR11MB5824:EE_ X-MS-Office365-Filtering-Correlation-Id: 86993122-d4e1-46ea-e425-08dcd8fbc9dc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?q1LOytLE0CiXcuRs+LdpY24Y/sxfMv1?= =?utf-8?q?9/r5XYNblpUgbUq5KOFjK79Nx1z9ayGgiiQL2lfrybmHAROLzHdB5T6Jnb067emxJ?= =?utf-8?q?jpmJ4MFVavZ6G/+EuXiBBo3okHdcbFvqbLT3kxguQXe7X1fI711/wEZVqLB+Qnj7t?= =?utf-8?q?ipSLLq3Mjz72qoXaApbowmrx//f7kowyoxEexIno83loUm4oWmAAThi3bjnjW1V+8?= =?utf-8?q?pZJTJYjoJ0IDZY2fY14r+ArwEhUDbpK5+fe7owdHjTYBKwBjoAuyLQ3sWE3D8co4c?= =?utf-8?q?cMk8uAQxQwoI6fUUxzyzWeGNtoBkTkd29WvKvb238Z0DE9bkU5xhTzZX5rKu4anRN?= =?utf-8?q?9VwDZGFPzj9BC9hvTqmfjC/j0tE+LwYxY7fAYU13XsQ3TV/JZYGh2BeXrrbVOZEo5?= =?utf-8?q?hbWUyVdqD0z5GrkCVSeggLRxuYoBchBJMcAzABpVw+zvwi2F9DvUokrfNpXu3vN1c?= =?utf-8?q?wyp5GHBzCTuFFy+4VtcE7r9bERkK4a+WlDZbzZbz7Rv9E0+JtOOxliB7EP/NUmsij?= =?utf-8?q?B8N5hIyx/SLYf4AbVWpUhYH/z3Evva74oVc5ISyn1t/Xf1ZujHNzIl9aI4bsIrbJZ?= =?utf-8?q?wG7gRxerOkCoE/cPmsAbSgS+IFX7By5nHWMgzkoGRIIUE5QthzUh4EwaCxaS5N4Om?= =?utf-8?q?l6QPaVJIi5aSGv3LPrt9zphvaa5sLi76JrO6EEitB7fQtPp2LAIbotJs9s2aiDmhv?= =?utf-8?q?rgXU40C351L582vXbWSuwYiJo9r8+pSd7vk46l5VForc2BURI8wlbb+r1HZLUZbzm?= =?utf-8?q?XpbifuQroLZNikJFfOyynjIl1ix0p5kXeyQSZQQjisivBa31b5J06+a9+ZYIxOKKs?= =?utf-8?q?kaMSB5wokBHbp6bxIOZPj6ztzD1ye2CzRRzwOx0otwHkfI36cwwDTumQxigjosYE5?= =?utf-8?q?4GYRJVBZrtmg358mTZaRPn6Q5ZjIXML4YTsq/tEDc/x7ulCbWLOQYRfdWe8vIOdOj?= =?utf-8?q?HATUMyFz9h5J/ZH3RUbOC/yYjOV671xXsIxuQ5JG3fG19UqQAmyRfrSj/Pc2sMYdD?= =?utf-8?q?w4C8p86OMCf61HKrPurR0eOiWqLhcMzR9Q4/xjjp0OPIpKt2fQSXty7oAaTjlnE1b?= =?utf-8?q?zZct94EKcl6uOrOzi1nFSZSes7JxqDtWI8K249uTGTLihkfFZ5Wi2qrlgiIWb18mX?= =?utf-8?q?DNJTFDExDolScmNnkFhA4Td618+DlqKfgmgdFi3fOA5mD0BZR3EnXxHNtgDnsFEuq?= =?utf-8?q?0VEQK6uD8VJ2CEksuBFwkYUOoAVFnxZlzhBj4ZqR//MDSxtqMZwxIb6mIAtyYvNox?= =?utf-8?q?PZH0Dijds+H4avnNn/GjVdsdBZUMgr3FvXg=3D=3D?= 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)(366016)(376014)(7416014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?hp0/NeXEl4pRAgZj+IwaxD85fpsn?= =?utf-8?q?Md1VBLQrs7Xfc2wXi/jM4VJ1me5u9yGPjG2xf6TQzkiYrH4uQWOce68CyWhtUCMuT?= =?utf-8?q?jCD9UpVgQP4shSCnMX+WSlY5K3jiyF0NZl5XkpcmPWtY4iKf1/Olx5zCvODkJEiB8?= =?utf-8?q?ELQGg+YT1Xmt9vOhIibylyYHPyI9g36I062jSmIruSAVzZNyw3g4qYqYqXIIovIj7?= =?utf-8?q?vBAwDAIiDwuK+P3j9UbusHvhAfT838LXi/T3Y91JCqUHCYam2Y8B14gnQEQ2R511H?= =?utf-8?q?2v6bS2KrCFzjKiHC9FAbNhzWZtNI7lDV1lXFoxwsS0EOktgiiRf5cK29x9mBK3sEs?= =?utf-8?q?aMv3eHGU7Qm58hCZtAzXdBG2AU4dIQnQWhCmx8hkKh950f8eQekz8/xV0nTkQxWI7?= =?utf-8?q?hFggLJDHEjJiWc3dADVvBze00UREL5YJieVRjwvS0JI4UR3els3fGCKxwDpAWsmJz?= =?utf-8?q?gclqvZ8K91B738F/2YTAzj9Le65WYeGPgOC5CNU7JquUyBxfciVPx6IiN4/TkqY7L?= =?utf-8?q?36cuGp1FI/gkUAgW3MyVud7NIz/ipTV7E2pTEEgV2nqKRzgTbvVN2jn0hVqW6rH4B?= =?utf-8?q?Jxl6QxXMoMaHyt4hxDtUIMwSW1B31wZY4FZaRyCfhvZr4uvSEL1gX9h58GoQ8I8Yh?= =?utf-8?q?sgbfSykRIVeFGl/ZxU9qFg0mR5xtN9LN3ji32crbtiL0hgFO/srBuQYG0sBoYwrf0?= =?utf-8?q?SnbTn2QR+vAHag7ZM7eLR6FlcXI6VK/tmQv5Ut6M1dzZV/jTUxG0+UdVj1I40Xe5v?= =?utf-8?q?Ja2BvzscYYRo/WzL4I5MuYZFjkYaqKl4qae8BZ+9xv0MHuyr6q4Qkh0WAPaYW/u20?= =?utf-8?q?2vvhEKPV9kTC5Hqx6pfsOZoHjQ78Qa5dxCk1YMZ9n/PDUHjCXu2VKwKRUJijWYTJj?= =?utf-8?q?BMU+PVVx4XbJm38TxeK7+lA4GCTUzCQ8A4EGQi6wMTcFwB/FE2n8/qysLi5wjpZIy?= =?utf-8?q?f6W56Q84F3KQetDun2JHEQbI/nU9/ZbCFoL3/1/cRZEOEPNHGXoCKTJk34WfInifv?= =?utf-8?q?3W0E84R1Pw6J505EpWn23Ngt/wYCe/bh5W027CUv76g9hw39ExfYCsp1o88HcLOF8?= =?utf-8?q?pjvDBzLabXqiMKQTaclF6J/kINMei9Qnx9KCe4Qs5bQRBnVXjHaNkuqNVw0Uz5yeW?= =?utf-8?q?THPm6Dq+cm/SIpTLNEswXqfg2OVWJzUjxN+POvIij9eBjzMCB8tQIPDOAXgnROclt?= =?utf-8?q?Mkuzniy6mP0ukWPk7wYcSnsBkwFs/Ibk2E6oUeH2iCiqpAIAs5U2PchNPRaBJeEjI?= =?utf-8?q?PF5oFuTmPCVO43yRE+XCcE9C+UY/4qDgoJSs/BRys0+VgLDisSM6BxcKHxIGRltlP?= =?utf-8?q?phxzZumCMSDsdjuxjDeKPXXm+w3YG92yk1LfUw1WtRl8HPneS8RjF3aLXYCamZ75Q?= =?utf-8?q?qrAzDIyKiWynBpS1Ry0vnAPLUggoNM9zrZH2jqPJcVNEnEL6zhe30pcLeZ3WfnfL2?= =?utf-8?q?HQoznfJlwDZOApM6bz+x3Ip4xNbaHky9hMxQoWWj/+DAkYBXNJ2noVfva7ErScIWt?= =?utf-8?q?xDRfphUx9ArCfljNYCFtxb1OL9XbsSYXpQ=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 86993122-d4e1-46ea-e425-08dcd8fbc9dc X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2024 22:38:31.5983 (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: n3Wp5liD2i8R32ApDb99e3sRLSB6qxSrZc2OQYwamFNNwsiY93RONpHg7OGp5MB62Pye+Q52bB+LngG8FNAa8xIVi8cNLcSledAn0lQi1RY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR11MB5824 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" VF MMIO resource reservation, either created by system firmware and inherited by Linux PCI subsystem or created by the subsystem itself, contains enough space to fit the BAR of all SR-IOV Virtual Functions that can potentially be created (total VFs supported by the device). This can be leveraged when the device is exposing lower than optimal BAR size as a default, allowing access to the entire resource when lower number of VFs are created. It is achieved by dynamically resizing the BAR to largest possible value that allows to fit all newly created VFs within the original resource boundary. Signed-off-by: Michał Winiarski --- drivers/pci/iov.c | 92 ++++++++++++++++++++++++++++++++++++++++++++- drivers/pci/pci.h | 1 + include/linux/pci.h | 3 ++ 3 files changed, 95 insertions(+), 1 deletion(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index e8ccd2ae0f024..d88efbfa70e42 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -181,6 +181,86 @@ bool pci_iov_memory_decoding_enabled(struct pci_dev *dev) return cmd & PCI_SRIOV_CTRL_MSE; } +static void pci_iov_resource_do_extend(struct pci_dev *dev, int resno, u16 num_vfs) +{ + resource_size_t size; + int ret, old, i; + u32 sizes; + + pci_config_pm_runtime_get(dev); + + if (pci_iov_memory_decoding_enabled(dev)) { + ret = -EBUSY; + goto err; + } + + sizes = pci_rebar_get_possible_sizes(dev, resno); + if (!sizes) { + ret = -ENOTSUPP; + goto err; + } + + old = pci_rebar_get_current_size(dev, resno); + if (old < 0) { + ret = old; + goto err; + } + + while (sizes > 0) { + i = __fls(sizes); + size = pci_rebar_size_to_bytes(i); + if (size * num_vfs <= pci_resource_len(dev, resno)) { + if (i != old) { + ret = pci_rebar_set_size(dev, resno, size); + if (ret) + goto err; + + pci_iov_resource_set_size(dev, resno, size); + pci_iov_update_resource(dev, resno); + } + break; + } + sizes &= ~BIT(i); + } + + pci_config_pm_runtime_put(dev); + + return; + +err: + dev_WARN(&dev->dev, "Failed to extend %s: %d\n", + pci_resource_name(dev, resno), ret); + + pci_config_pm_runtime_put(dev); +} + +static void pci_iov_resource_do_restore(struct pci_dev *dev, int resno) +{ + if (dev->sriov->rebar_extend[resno - PCI_IOV_RESOURCES]) + pci_iov_resource_do_extend(dev, resno, dev->sriov->total_VFs); +} + +int pci_iov_resource_extend(struct pci_dev *dev, int resno, bool enable) +{ + if (!pci_resource_is_iov(dev, resno)) { + dev_WARN(&dev->dev, "%s is not an IOV resource\n", + pci_resource_name(dev, resno)); + + return -ENODEV; + } + + if (!pci_rebar_get_possible_sizes(dev, resno)) + return -ENOTSUPP; + + if (!enable) + pci_iov_resource_do_restore(dev, resno); + + dev->sriov->rebar_extend[resno - PCI_IOV_RESOURCES] = enable; + + return 0; +} +EXPORT_SYMBOL_GPL(pci_iov_resource_extend); + static void pci_read_vf_config_common(struct pci_dev *virtfn) { struct pci_dev *physfn = virtfn->physfn; @@ -445,7 +525,7 @@ static ssize_t sriov_numvfs_store(struct device *dev, const char *buf, size_t count) { struct pci_dev *pdev = to_pci_dev(dev); - int ret = 0; + int i, ret = 0; u16 num_vfs; if (kstrtou16(buf, 0, &num_vfs) < 0) @@ -487,6 +567,11 @@ static ssize_t sriov_numvfs_store(struct device *dev, goto exit; } + for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { + if (pdev->sriov->rebar_extend[i]) + pci_iov_resource_do_extend(pdev, i + PCI_IOV_RESOURCES, num_vfs); + } + ret = pdev->driver->sriov_configure(pdev, num_vfs); if (ret < 0) goto exit; @@ -881,8 +966,13 @@ static int sriov_init(struct pci_dev *dev, int pos) static void sriov_release(struct pci_dev *dev) { + int i; + BUG_ON(dev->sriov->num_VFs); + for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) + pci_iov_resource_do_restore(dev, i + PCI_IOV_RESOURCES); + if (dev != dev->sriov->dev) pci_dev_put(dev->sriov->dev); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index e763b3fd4c7a2..47ed2633232aa 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -385,6 +385,7 @@ struct pci_sriov { u16 subsystem_vendor; /* VF subsystem vendor */ u16 subsystem_device; /* VF subsystem device */ resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */ + bool rebar_extend[PCI_SRIOV_NUM_BARS]; /* Resize VF BAR */ bool drivers_autoprobe; /* Auto probing of VFs by driver */ }; diff --git a/include/linux/pci.h b/include/linux/pci.h index 4cf89a4b4cbcf..c007119da7b3d 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2364,6 +2364,7 @@ int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs); int pci_sriov_get_totalvfs(struct pci_dev *dev); int pci_sriov_configure_simple(struct pci_dev *dev, int nr_virtfn); resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno); +int pci_iov_resource_extend(struct pci_dev *dev, int resno, bool enable); void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool probe); /* Arch may override these (weak) */ @@ -2416,6 +2417,8 @@ static inline int pci_sriov_get_totalvfs(struct pci_dev *dev) #define pci_sriov_configure_simple NULL static inline resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno) { return 0; } +static inline void pci_iov_resource_extend(struct pci_dev *dev, int resno, bool enable) +{ return -ENODEV; } static inline void pci_vf_drivers_autoprobe(struct pci_dev *dev, bool probe) { } #endif From patchwork Thu Sep 19 22:35:57 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: 13808033 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 5E583CF3973 for ; Thu, 19 Sep 2024 22:38:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DD2EA10E77D; Thu, 19 Sep 2024 22:38:40 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="XoZV4y5E"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8FB4210E77D; Thu, 19 Sep 2024 22:38:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726785520; x=1758321520; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=MSeyN4wI4jVrwrpXPBfwNiYCVHjQ+Ol9ePL96RONo8M=; b=XoZV4y5E4X4FmJYMer6hJKyjc/h3/+RqQ9aM3WR5Ey8iBBB0D+37RL8v lVvbYL56mq8GxzJi8s0l7AUGXmSjrTbZ3CoyUb0QlamOoY+I9r/RM0dvL oRdYFAGJ0NQXBpZUAybu7qe6D8awgKmkeaMBHzK+zLGydcs9nuqr6zLHx fO2cezOzMpfzHb0aSipkoM1SHDJ4AtsvGsz4LwsGaBAUnVojpjz4/4mUl 6K3dk0PfJ0GkVb7s/yH+Zr/uQrOttnL1qQMRVf9OL2Z5Z/dN7+hFHTCll lfXTL/CgCOPDp1AXc32MJ4RGVZHVWWZNWPiD7HcXjL7fCwrYE92ECHmJf A==; X-CSE-ConnectionGUID: OQuv7upzQq2j6XA5quA0nw== X-CSE-MsgGUID: ctEPQxzJSwy/tztpZ7T30A== X-IronPort-AV: E=McAfee;i="6700,10204,11200"; a="29514956" X-IronPort-AV: E=Sophos;i="6.10,243,1719903600"; d="scan'208";a="29514956" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2024 15:38:39 -0700 X-CSE-ConnectionGUID: Pn8z3yzwQTKH9IJ/iNg+wg== X-CSE-MsgGUID: byCZeJhwRsKEo/WHBH5olw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,243,1719903600"; d="scan'208";a="75061372" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orviesa004.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 19 Sep 2024 15:38:39 -0700 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 19 Sep 2024 15:38:38 -0700 Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Thu, 19 Sep 2024 15:38:37 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) 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; Thu, 19 Sep 2024 15:38:37 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.47) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 19 Sep 2024 15:38:37 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lRDtmc3qxEDj/GP5TG9fMRsl31OcYAPGAbSBHgiVAH7wP3x26yByo9BA9JDuXPXo+K8MODehFEOH0mLsekdzzcIxDzGXZL271G2LbkgX/51+enOAqxhSL2vyzy00KYVRtTGJU1HrLGAxWceOl27pqmY2fBY3N9SCTvqrB0lF2LXsEQhxEuaJuZ/lgqcKwFWAXXd4+lf7h1ZswBIIDSKDWpE/9tTcMvoUCUZKE6EEcSBCCb+5VTeIylp8AQbqnp+9I2ips+2NunCM5S/302lOXuioGyOvGYfSdPU4teC3M5fuHyGHjzdfJdJJa7UfDOEfYB+i+5tZuDzajceArZAY2A== 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=jdvethQQmrLnacOS1BtlWoV6+5D4782RcFBDMX3Og/8=; b=kJClbz9HiqsBHGHhbxBmZ1xY49D8s1w7+QvpsrMXpTIusdoDR1vNwR3aB6G6vyp+idXLKMcqn387VOTFWxf+UuBWgTgGQ0tpoBLWHaawdQHkFkDNpPiEdhNiRhLccQrwgzh8ZB1xEj82sq8ocO4j79Om6N54oATz8kcbNsA9hCA91P0a0N48RfSzkXaZ3vJ674sKbZpXnT/3QBdTLImoTsZYLmr7h7Uaiy/8mLyLjpXPIve+TRkBecUMgXNELKD+2DVoOuBgWeTgcDNtgfh8ossWH4jls7tJKWQQ3nual6mcBxZrVinWB0Jx4tWduIortOl2tuxizgnJHjG731AXwg== 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 MW4PR11MB5824.namprd11.prod.outlook.com (2603:10b6:303:187::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.26; Thu, 19 Sep 2024 22:38:35 +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.7982.018; Thu, 19 Sep 2024 22:38:35 +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?= 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 v2 3/3] drm/xe/pf: Extend the VF LMEM BAR Date: Fri, 20 Sep 2024 00:35:57 +0200 Message-ID: <20240919223557.1897608-4-michal.winiarski@intel.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240919223557.1897608-1-michal.winiarski@intel.com> References: <20240919223557.1897608-1-michal.winiarski@intel.com> X-ClientProxiedBy: WA2P291CA0039.POLP291.PROD.OUTLOOK.COM (2603:10a6:1d0:1f::25) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|MW4PR11MB5824:EE_ X-MS-Office365-Filtering-Correlation-Id: fbc9c587-ab64-4b4a-0a05-08dcd8fbcc2a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?13AhXtBIarNb6faSDOGIE6sasDzhSiX?= =?utf-8?q?ko/K9BNIpiIK0C+LuGLX/ogmpfS7HUOYthPnh/+Wu9I8YVl3gMAJ602ypaAgz41WD?= =?utf-8?q?uhisJ4P3r36uVz+lJHd3lT+OEk/9OhUCDYf6ART5cthlChipdCCyYglW4qquCWdsu?= =?utf-8?q?E9p/vWqfIH2lY5llBaIvj0nZGeU+EH2whjNy7HlYB7TBpJEL/hkbb8usvaqbccfOX?= =?utf-8?q?Rkxb2BWIH0NdlXHtBwZ9f6sikOALdifOsdP5NYarl/ESTCjJEYWIraFS0WKfJU/rN?= =?utf-8?q?mUHFg7oJRue/xAK4NEuxCsQ+MYe8tcSBw/sisD29tvueSkAhOsuwCowbhr3wvxeht?= =?utf-8?q?D45NhlmPBaDpZQLqccu8Ln16B52Ah+4bm0kPO0Aj9lDeElMGDJ8Tbtwbi069+By8I?= =?utf-8?q?GyTbcB4gufHeS50i5RtHeUwQwe8DmvuxezOu4+kaJTB6XI3Zb7MXXD1XJkxhCRaQ8?= =?utf-8?q?10VxHBo24jAwWe81G0j0UwKGQEoF5Pw4Sd4EmEB8k1X7Heu2yrVS9rw4UQR+Y53Qr?= =?utf-8?q?jQdrrBU8S4DwdiDw1psoyuU3D6XqZJrFYqOQAccdU3kjItw9yeKb34jZVW5RQKS2R?= =?utf-8?q?y5GWU90IOJG91D8qOvN6K7g4aqN5wVt7ywbxDMymFKC6HCHC61+5VBlZdjGWVyLZn?= =?utf-8?q?13QUI8hDXD6rDhbieCic/dL5AOxGKvGnKHIXDUAyzdJX5tfP7zBE7YIModJwXRSeA?= =?utf-8?q?r/Ml9Ryz/Ilzjqa7wCcud9bo423dZoDt+qf0fD4tR8GRowAIYJPmVeR9Z1+655xG/?= =?utf-8?q?xAtLZZwr7FxzU6bBBqi2dz8mvYT8hNUiJwqF/2UJ5ofusqXGwGEC6U2mGjSoUYZOc?= =?utf-8?q?4vk7S7dQCNtb79hJJWBQZSjurQkslZneFb13C9pFHnsm65EzfF+C2xrUlyo99cwOe?= =?utf-8?q?HPM4uXBCXMhkHgtwj9MEsJqhcLNrDPJrPuh7pWaxqF986yEd5iQVT8hLE8DUA3Xnz?= =?utf-8?q?YvZOI1vn9LS86o2h+FBdRob7OBcbXOuVxkHysLCGw1ImmlL4/DrRSWuA+EM01Ghdj?= =?utf-8?q?nJEpJqZuU70blf3Z7sa3v0+HouYeAkD431QdrMhvc3hLkjvCrNSjvW3vwuX4dfGhA?= =?utf-8?q?SwK3hUOw8NLmcYKYnhikHmT+y1EQPEimMLjTZvw7tavH4uk5sauR84JWiM1vyvY5l?= =?utf-8?q?D3LG+0x01pLioBNqkEatE8/XF69NzNGGXPQs4RYy6ox1sjlTh8czkoHx3sXndQnep?= =?utf-8?q?qi2Rtiv9SSrxvfDIwlplPxjuJOKQq9V79G1gdJF3nwMl7jpNLDUUIzKiKWnVBwaR+?= =?utf-8?q?bzLfYusafM6pPWrLjPpmaqckXVtfEcgfF3Q=3D=3D?= 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)(366016)(376014)(7416014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?rbKadKxXg3Amtv3hG4mefS3Kho5m?= =?utf-8?q?4zH5zgp8zqpbwoKZztV3Q+cHKuzfXwhdqDwn3ZwQIA4gIG9G19I757oXczRaMYka4?= =?utf-8?q?Dtb9FoFcS2Jj53jHnGIKcg7PeyTZDqMyuGz9TjySunQS8YWJwfNvseVjAoq2Roo25?= =?utf-8?q?Mh6HNssLI5Ms9gU42bYyeV9gGg1xevVdbk/NjOVCJwDS793nkNa/vlp/p8H/TU5j1?= =?utf-8?q?5sJKbtuO7tYUM0owkVHFkyh+MzAoW1u8KNLByXZVtD3bx2KxHNjuC4bL/w0Io5J7I?= =?utf-8?q?3Gp7suaLB+bT15OyAbsD1s1Xr98P2uzSNRWFaQLoPSxpzUSmWDDs1KSHObQ8w4XQ7?= =?utf-8?q?WewcYBf8rIVpJGVS6xknnK8I0Y0VTLCTIn0RsH+WGPWwIpjAJU5m4wqGmoYOjytKg?= =?utf-8?q?a1Eh3jDXXuc9nclHDGmUFsZ9gNJuaiWJOUlbdmi7HdHjN6NxRd/WAiREWys0Om7oW?= =?utf-8?q?npqdP2ZSaLjBpAMgD1erJQ27UkAW/2dcHbcVkWl/nwDdlbInefwebGqJhhQdDPzJM?= =?utf-8?q?GAaR/2+IardWPbP3tXBowywPB7kEHAqzn1WckBCS7saPWVqtEip+z5A/HyBJVZzn6?= =?utf-8?q?4tlHw2GI/62lk3jceZEjlFcNZKi36wGV2luOzyCf+yuNU01swsesCXzvAIApMVOiN?= =?utf-8?q?zvbItzfIcIk10OZDHNWPk6LrQGQCkPh1M3blfntQi6/4yRPMvbXO7v6+SxSbPc5mD?= =?utf-8?q?+ZQ5XdC9JDwwTrZ5725RPCgV0Kna4WDaLKGoDhK03nXPOajq04BD4NlgRwZ0W2N8F?= =?utf-8?q?UIMXGbv3mLiN1eHsoJDodJQExJpQGkWiG5V1+msAUXlfeOwaZrnGc5l8wazOZ8mdi?= =?utf-8?q?6NmFXd5w/gsFoO/Go+ea2ejo6+m/FP6RCT9n5K7NnP4B4zUN7QHZJE0keXXVZUNat?= =?utf-8?q?e8APYwy/gapsDEWuLWR7E3+OUlAjf+OgfRxhTOlPLGeEQw+vF2eZuQzgg92sLA3ZQ?= =?utf-8?q?Jcm6yK+EG0cbztWW3EbDlDaBCs/sPqEfjubzLPXOge8pSfJ+H36ehHz+Q2noBZmq8?= =?utf-8?q?ZWz/V/lXom939rJTYTk/DYDbqvsNGNcD+tl3wsYHtacXjVL5yyWOirvpVN+RLriuF?= =?utf-8?q?8sLbOdg0B/IpqsO4BGCW75wsQe17fAGEiVnbYRVnz8VZlK8+fDieCYJDGUd1m3kUv?= =?utf-8?q?YLRAPk7f82V3T9rWgEGzWyNbYcCMfyPr8S1GKv2aAB3+DWF90R0nnqqkyI3B3VDyH?= =?utf-8?q?jAkQ+Qx5G9ij9ZG98F0wVizWTKZkRry8RWPmoAia/tAppDEID7EH5BNudI0lDyjCb?= =?utf-8?q?1wgwy4zUiaM2xHpl56IF35aimdBI9RLHB7aRKkGT3kYplwtePkoXL/lBvlAFjqsPH?= =?utf-8?q?VcqxtwJ+34J2ANrTYITKT3Qpln4WbCM6UC9PhR0hnTgptGthN1o00o6F//ppied9b?= =?utf-8?q?oklRwyXzodz1pFCmrDLXozYip0i3AAN/701oQyr+G7rLw+aTEqXh50iq77zJCZTGv?= =?utf-8?q?7D3bqz2GX6Vz69p69DRKqn81ZxxlpMgDQ9FNVTUuXHrGoWj8M+6+m60tDbRMvrlA6?= =?utf-8?q?vZfosWsRq0hbzc/JgzZueq3RAVT+4Kie3Q=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: fbc9c587-ab64-4b4a-0a05-08dcd8fbcc2a X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2024 22:38:35.4541 (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: BhWq5Ou/S9pCrLSw6dk7TVZ/fARnnh93WZuppRqFE6dsLQxQ3EBE9jFZ/CNj7knqx6gFj/dp8iZvvdalqbRRZg7gP8n6imqbziPbczEg950= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR11MB5824 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" Opt into extending the VF BAR. LMEM is partitioned between multiple VFs, and we expect that the more VFs we have, the less LMEM is assigned to each VF. This means that we can achieve full LMEM BAR access without the need to attempt full VF LMEM BAR resize via pci_resize_resource(). Signed-off-by: Michał Winiarski --- drivers/gpu/drm/xe/regs/xe_bars.h | 1 + drivers/gpu/drm/xe/xe_sriov_pf.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/drivers/gpu/drm/xe/regs/xe_bars.h b/drivers/gpu/drm/xe/regs/xe_bars.h index ce05b6ae832f1..880140d6ccdca 100644 --- a/drivers/gpu/drm/xe/regs/xe_bars.h +++ b/drivers/gpu/drm/xe/regs/xe_bars.h @@ -7,5 +7,6 @@ #define GTTMMADR_BAR 0 /* MMIO + GTT */ #define LMEM_BAR 2 /* VRAM */ +#define VF_LMEM_BAR 9 /* VF VRAM */ #endif diff --git a/drivers/gpu/drm/xe/xe_sriov_pf.c b/drivers/gpu/drm/xe/xe_sriov_pf.c index 0f721ae17b266..a26719b87ac1e 100644 --- a/drivers/gpu/drm/xe/xe_sriov_pf.c +++ b/drivers/gpu/drm/xe/xe_sriov_pf.c @@ -4,7 +4,9 @@ */ #include +#include +#include "regs/xe_bars.h" #include "xe_assert.h" #include "xe_device.h" #include "xe_module.h" @@ -80,8 +82,14 @@ bool xe_sriov_pf_readiness(struct xe_device *xe) */ int xe_sriov_pf_init_early(struct xe_device *xe) { + int err; + xe_assert(xe, IS_SRIOV_PF(xe)); + err = pci_iov_resource_extend(to_pci_dev(xe->drm.dev), VF_LMEM_BAR, true); + if (err) + xe_sriov_info(xe, "Failed to extend VF LMEM BAR: %d", err); + return drmm_mutex_init(&xe->drm, &xe->sriov.pf.master_lock); }