From patchwork Wed Mar 13 10:57:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13591233 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 628833B798 for ; Wed, 13 Mar 2024 10:58:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327505; cv=none; b=UrtmcWXUNEE2XEU6wr9hegEUjvP+BCF4pp5CkB+a6A1ltSu9N3MEmQP82GbE417kaGtL0WjEF8YEIjU6yQ6TnZKKWYjrfEKd9pN1zUuihaqdACJfYcoeelCC81WD+idNfn4KvoLzI8S445NawJaIPIMYnnW2jv+yGoFlHEX3TRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327505; c=relaxed/simple; bh=FRR3ONvC1dTDtzKK4rr212hrCcCfCZS60W/bKB4hdjw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JzAGIkV4cD1ueNE+MvfnLzB6+dRvIZLre891Ql+zl5g1vrp3mJhAmdb/H6/L0J1xO8tvfxsW8jKyhN5DA4cj/ONlxrQ3g8SVz9VJwlIcsRQ2O1rokOw3QCUZJl86/myfeBDvyLXEKcSbHCZjcYKRUYKKmPlRzdlQRk5MxRbAX+w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WYwnLDIB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WYwnLDIB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED64FC433C7; Wed, 13 Mar 2024 10:58:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710327504; bh=FRR3ONvC1dTDtzKK4rr212hrCcCfCZS60W/bKB4hdjw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WYwnLDIBY9JOV1/TfeZ9YlL4LjzvjgZQsxrjZu/zroz6lKlmpfmqfVFTR/3vcdFWD ySpmuaVfg3YRLzgAtuUNQ9hDONsnLFQZzVdv8dw7LU/86O/OlK8NFukbShbt+tPzX4 Ac1OGaV0lVx1KukI2SXnZOn8S6y/KepaHwNpb0RHH3uCJ0sm0sd4e+RdWqwtSf8A8O ICFscIDCG0IX3NXuKQGW8ZDUa98f7vbVGuL3N4X9/+WcUl4h99TT70ocjJ1JhtWQN9 TsjxuEgze7XG8D1tJFWqrqEvb0cEEBzQ5GYcvRO50AIVggixXPexYSiAhQIW/lWVW6 Suts2kUgntjBw== From: Niklas Cassel To: Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Kishon Vijay Abraham I , Bjorn Helgaas Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH v3 1/9] PCI: endpoint: pci-epf-test: Fix incorrect loop increment Date: Wed, 13 Mar 2024 11:57:53 +0100 Message-ID: <20240313105804.100168-2-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240313105804.100168-1-cassel@kernel.org> References: <20240313105804.100168-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 pci_epf_test_alloc_space() currently skips the BAR succeeding a 64-bit BAR if the 64-bit flag is set, before calling pci_epf_alloc_space(). However, pci_epf_alloc_space() will set the 64-bit flag if we request an allocation of 4 GB or larger, even if it wasn't set before the allocation. Thus, we need to check the flag also after pci_epf_alloc_space(). Signed-off-by: Niklas Cassel --- drivers/pci/endpoint/functions/pci-epf-test.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index cd4ffb39dcdc..01ba088849cc 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -865,6 +865,12 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) dev_err(dev, "Failed to allocate space for BAR%d\n", bar); epf_test->reg[bar] = base; + + /* + * pci_epf_alloc_space() might have given us a 64-bit BAR, + * if we requested a size larger than 4 GB. + */ + add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1; } return 0; From patchwork Wed Mar 13 10:57:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13591234 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A8263B798 for ; Wed, 13 Mar 2024 10:58:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327507; cv=none; b=ZDZrAf165PNegMmbwM0zS6zJdS6n/Skxc0Qs0rcxJtsCNoWSNHC6R8kuwBro45wwjhEMUOF1hJyJJAoBkVzD/fFoyCkSzJaAvIT8IbsPQPXcW0JmsrOTEZNBgymwxHOpWdl6iMt4gkxU+d1+UpVv5Kt0+WjKILXBZEgHvBjOsww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327507; c=relaxed/simple; bh=+5dCeZi10/u3RMlvjT4oH8IBPzU4bcYd+CsEmIgXsME=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n2WoQwgRisGOEa5kUMCyQubBg5T/UMTraoDQ5Z2dtmwphxhCTYW855MLsvIM9Yc72gC4TnNX6nhLp/5PHlJ4tGMrj1IjxGHYCTeB/4vkEg5MTrqxKsW11quBQJnSHAKhgAZ7X97pAoTeZargshagUmUqxF/b8mZLT3tVDR7G7hY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iE+jIP8x; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iE+jIP8x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD834C43394; Wed, 13 Mar 2024 10:58:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710327506; bh=+5dCeZi10/u3RMlvjT4oH8IBPzU4bcYd+CsEmIgXsME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iE+jIP8x5HwLMf541YDHUs/osZ5PUTPOTU7GUPYUNAU/Gyb0R2ERGcbw3xpPRFLRj 5PF2K+ez0/QIvXpGjpUXCHmSuTEq2Z4ywfw/qdph//Q39F3jjBP/1Hyyjb/SEY4ObO ZUhDLngfoNjLgYyVY+YZCwssNuDqAKp5llpl9cWOE4lovKQcfAPefU4Rrb2PzYdLAd J3W9vo8m4/DUZ9AvTOLDdoO6lIFUCJpcUZOVjRlqkJIhba/0HoJsYtsdWA3rn5Kjyp 2Vw3cq23FqcrKon48HC49wxGQTNJ2p97sQGFg1ZYdzJp+VIQh0f5C0p4+06aoVmzjz PGqhoJKhQldYQ== From: Niklas Cassel To: Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Kishon Vijay Abraham I , Bjorn Helgaas Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH v3 2/9] PCI: endpoint: Allocate a 64-bit BAR if that is the only option Date: Wed, 13 Mar 2024 11:57:54 +0100 Message-ID: <20240313105804.100168-3-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240313105804.100168-1-cassel@kernel.org> References: <20240313105804.100168-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 pci_epf_alloc_space() already sets the 64-bit flag if the BAR size is larger than 4GB, even if the caller did not explicitly request a 64-bit BAR. Thus, let pci_epf_alloc_space() also set the 64-bit flag if the hardware description says that the specific BAR can only be 64-bit. Signed-off-by: Niklas Cassel Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 3 ++- drivers/pci/endpoint/pci-epf-core.c | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 01ba088849cc..8c9802b9b835 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -868,7 +868,8 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) /* * pci_epf_alloc_space() might have given us a 64-bit BAR, - * if we requested a size larger than 4 GB. + * either because the BAR can only be a 64-bit BAR, or if + * we requested a size larger than 4 GB. */ add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1; } diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index 0a28a0b0911b..e7dbbeb1f0de 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -304,9 +304,10 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar, epf_bar[bar].addr = space; epf_bar[bar].size = size; epf_bar[bar].barno = bar; - epf_bar[bar].flags |= upper_32_bits(size) ? - PCI_BASE_ADDRESS_MEM_TYPE_64 : - PCI_BASE_ADDRESS_MEM_TYPE_32; + if (upper_32_bits(size) || epc_features->bar[bar].only_64bit) + epf_bar[bar].flags |= PCI_BASE_ADDRESS_MEM_TYPE_64; + else + epf_bar[bar].flags |= PCI_BASE_ADDRESS_MEM_TYPE_32; return space; } From patchwork Wed Mar 13 10:57:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13591235 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEA633B798 for ; Wed, 13 Mar 2024 10:58:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327510; cv=none; b=qrmcXv/clc1q6RX6FWhvuXpIkDUHJOYXV0sB0CZF9ek2X+WYcE/VYpovoJJJ093kWYHHSUm63Vxshvjl70PnAYckjgCa6fWP0HwsbnbLDWqeRgXef/bOhov1d7leorexQbAde6Sz/wVPy1X/J1SM/kxrhoxxmqn28JOd/jn71xE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327510; c=relaxed/simple; bh=e/qH9cmUPYUotD/eAIW0sRrL9XefNgAmZxzo/zRfOXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HQpsJLkGoscOZ9YU8O9pZhPASq/sHqSShLX+T9513BJ5lDX8pZ+TgMPNvU7t8Fzcaiqn7gvoBVOkrUB20k0l033Ir61nB1sPh7KaAC2vUIxYzv5Qj1HkhKWeHrO9f/gxPNh+ef4n4r7LTAS0S6pKq5zBiSdRX16CzvrZGg7o4ZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Fu3+czTo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Fu3+czTo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BBB4C433F1; Wed, 13 Mar 2024 10:58:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710327509; bh=e/qH9cmUPYUotD/eAIW0sRrL9XefNgAmZxzo/zRfOXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fu3+czTooeb804z147E3W506+97krqEewiftTgCtigByMb8eJnlXMVO3g0lkansuK nax4DLoZPK/iCD38iiUiXlE2oDrZptg4vth7yg2yi02I6frm1bPPuRsk6vh3Py+p1o mCfQYyvu/fJgz4RwPhMGS8WCLF+i8CaiEi8+yqNKwXgJIcTtaBM/AeQz1TL/5uL4IT 9ZQRRquh216LaqiOt1o/2lyf+1Lw841uc0Kv2bx0NsY95iCusWLrIfswnW2z/NlCpx H9ScHXUrW45/CSKiv6JTDoWj7BRZxJb9W8GFXuRLCyT+1x0Lo64KpAu818Nr0ANwAV OUXMqCb63o/cg== From: Niklas Cassel To: Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Kishon Vijay Abraham I , Bjorn Helgaas Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH v3 3/9] PCI: endpoint: pci-epf-test: Remove superfluous code Date: Wed, 13 Mar 2024 11:57:55 +0100 Message-ID: <20240313105804.100168-4-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240313105804.100168-1-cassel@kernel.org> References: <20240313105804.100168-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The pci-epf-test does no special configuration at all, it simply requests a 64-bit BAR if the hardware requires it. However, this flag is now automatically set when allocating a BAR that can only be a 64-bit BAR, so we can drop pci_epf_configure_bar() completely. Signed-off-by: Niklas Cassel Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 8c9802b9b835..7dc9704128dc 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -877,19 +877,6 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) return 0; } -static void pci_epf_configure_bar(struct pci_epf *epf, - const struct pci_epc_features *epc_features) -{ - struct pci_epf_bar *epf_bar; - int i; - - for (i = 0; i < PCI_STD_NUM_BARS; i++) { - epf_bar = &epf->bar[i]; - if (epc_features->bar[i].only_64bit) - epf_bar->flags |= PCI_BASE_ADDRESS_MEM_TYPE_64; - } -} - static int pci_epf_test_bind(struct pci_epf *epf) { int ret; @@ -914,7 +901,6 @@ static int pci_epf_test_bind(struct pci_epf *epf) test_reg_bar = pci_epc_get_first_free_bar(epc_features); if (test_reg_bar < 0) return -EINVAL; - pci_epf_configure_bar(epf, epc_features); epf_test->test_reg_bar = test_reg_bar; epf_test->epc_features = epc_features; From patchwork Wed Mar 13 10:57:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13591236 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62CF33D38F for ; Wed, 13 Mar 2024 10:58:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327512; cv=none; b=L1thTL2TIx1cHEMZH8iIld1pjShbJyuqw5LI+/SIBCRyeF0EaQn0HxZXLVP0gpvr/CrTMnOYkA/XkoElb2K+MDIypc1Q+ZUAG4zwFOPflFegyJabdCCtfkOR3/OirCORbiatxaWBitGtWAKfxbS/tatqH4dS8g5FlHjwdEWY71M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327512; c=relaxed/simple; bh=VqxAnMdNBCPq0LcAygy6XAAssDYODbeSUV3wclX9NVA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EpqmgDKiQhc4jjZwmBAOS4m+r+QMuLwF0rUissMf9eWmhdNKkGzMGBXPblDsQXqNrvfQgnQl7hMp1WcB9Es2Vgi5aeC35vMynlNKJRSxKjfhlmEErmopXS7tbUWzW+CoXQ8g/aEsWLv4Rp1cKPsGzjcax/Odn7d5p1QgrJfFaRE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ulpOr27T; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ulpOr27T" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BF15C433C7; Wed, 13 Mar 2024 10:58:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710327512; bh=VqxAnMdNBCPq0LcAygy6XAAssDYODbeSUV3wclX9NVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ulpOr27ThfXzlr/o3EAx3AUq5KHXjCvFW365/7ePdl0jCFSt3SmP1wZWqiua9QjqP 5lETzoeBm09HpxFtatvFBIevQ6tonsy5o7GtOY2ABKOGo0fvXPtR0xiqbHgfFsWjvk MEoLtO5aVlw4AskAxoyTrcMx0C+VcdaTsx26OeIdAYvAmRTjogYEROMsf4cudY1TuP 0fatvStapjxPxmIX70a10fz1xnfomCGuNAQlsaZxno7Nwl9vXjy9y37ss5kRGkx3Ba 80HpZIxB6Hl9S+2gb0NwHS9ic6wVkd4EnZwFyezUf32mB/0k/FUkZ0Obcf2e9syB1y +sZP6xNIXkJxQ== From: Niklas Cassel To: Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Kishon Vijay Abraham I , Bjorn Helgaas Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH v3 4/9] PCI: endpoint: pci-epf-test: Simplify pci_epf_test_alloc_space() loop Date: Wed, 13 Mar 2024 11:57:56 +0100 Message-ID: <20240313105804.100168-5-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240313105804.100168-1-cassel@kernel.org> References: <20240313105804.100168-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make pci-epf-test use pci_epc_get_next_free_bar() just like pci-epf-ntb.c and pci-epf-vntb.c. Using pci_epc_get_next_free_bar() also makes it more obvious that pci-epf-test does no special configuration at all. This way, the code is more consistent between EPF drivers, and pci-epf-test does not need to explicitly check if the BAR is reserved, or if the index belongs to a BAR succeeding a 64-bit only BAR. Signed-off-by: Niklas Cassel Reviewed-by: Manivannan Sadhasivam --- drivers/pci/endpoint/functions/pci-epf-test.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 7dc9704128dc..20c79610712d 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -823,8 +823,8 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) size_t pba_size = 0; bool msix_capable; void *base; - int bar, add; enum pci_barno test_reg_bar = epf_test->test_reg_bar; + enum pci_barno bar; const struct pci_epc_features *epc_features; size_t test_reg_size; @@ -849,16 +849,14 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) } epf_test->reg[test_reg_bar] = base; - for (bar = 0; bar < PCI_STD_NUM_BARS; bar += add) { - epf_bar = &epf->bar[bar]; - add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1; + for (bar = BAR_0; bar < PCI_STD_NUM_BARS; bar++) { + bar = pci_epc_get_next_free_bar(epc_features, bar); + if (bar == NO_BAR) + break; if (bar == test_reg_bar) continue; - if (epc_features->bar[bar].type == BAR_RESERVED) - continue; - base = pci_epf_alloc_space(epf, bar_size[bar], bar, epc_features, PRIMARY_INTERFACE); if (!base) @@ -871,7 +869,9 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) * either because the BAR can only be a 64-bit BAR, or if * we requested a size larger than 4 GB. */ - add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1; + epf_bar = &epf->bar[bar]; + if (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) + bar++; } return 0; From patchwork Wed Mar 13 10:57:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13591237 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C14B3E49C for ; Wed, 13 Mar 2024 10:58:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327515; cv=none; b=j0LwRIhk9NaEZTEzxlp3ANCau2ERhQgb4x4xUzUCitpSRXQQuvz03JGIGycZLn+HXsIT+9soSm1IcF8UZuT+HZVUz/JWYdRMfQlptAMr7iRTGWi6lGBsEOkV0/6d+igBcMTv3Li6A0vVkKKMN+voI1PIn4H6kgoLViebC3qjkXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327515; c=relaxed/simple; bh=Vqj8+GnBzaE6qzFK9gXIlH1ngsSVLxJdaREWh9jJJa4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZdXTGVdC+CT/Y9aYB0UetAgVnl5DzLDoTrCSEdjyWdXXiPsAOqIn6qknm9IZiFSGtxCXu6O+9wS2Yi7gRFbZM4HFFK+0tH3pP7hQT4tJnsS6o5aXP9KbtrL/z1v9heT5/Xm+J+ukG3moA8eS0KdkqByJ1oxWm9EIGCV/+KA67GQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pjmfze8K; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pjmfze8K" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F02DFC43330; Wed, 13 Mar 2024 10:58:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710327515; bh=Vqj8+GnBzaE6qzFK9gXIlH1ngsSVLxJdaREWh9jJJa4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pjmfze8K0EL1StHxQdnU7UilpynDQKLy9jrueD6zoy/xRfWpyHJRuvmMR7Sc5imne Xx+OjEJtEb6bGeqMDZ5t+AibL66nhbECZCb7ZdgO5+8euXX2NyjGz7eVud6srE3kl0 DbJ+2zDr62Ivd+JOIOOJ7m26G2+sN6Qb6Ngu4MZBsE6H2IV7IWGEdgf8m0yxYM9HdR jfoWZpVtvZ0QuNDgCu6VV41MnYkFJAH/qEO4kyk2X7rl2UWdBYe4bxR7QpS8nnCeVN GoRYg5ei0B70jGkXFxcB9twVvtSmRXiagKMTnhuGFM7MGO20WbPGM1V0OmcZ2bi3Pk 3t1HXx7/AgmvQ== From: Niklas Cassel To: Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Kishon Vijay Abraham I , Bjorn Helgaas Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH v3 5/9] PCI: endpoint: pci-epf-test: Simplify pci_epf_test_set_bar() loop Date: Wed, 13 Mar 2024 11:57:57 +0100 Message-ID: <20240313105804.100168-6-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240313105804.100168-1-cassel@kernel.org> References: <20240313105804.100168-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Simplify the loop in pci_epf_test_set_bar(). If we allocated memory for the BAR, we need to call set_bar() for that BAR, if we did not allocated memory for that BAR, we need to skip. It is as simple as that. This also matches the logic in pci_epf_test_unbind(). A 64-bit BAR will still only be one allocation, with the BAR succeeding the 64-bit BAR being null. While at it, remove the misleading comment. A EPC .set_bar() callback should never change the epf_bar->flags. (E.g. to set a 64-bit BAR if we requested a 32-bit BAR.) A .set_bar() callback should do what we request it to do. If it can't satisfy the request, it should return an error. If platform has a specific requirement, e.g. that a certain BAR has to be a 64-bit BAR, then it should specify that by setting the .only_64bit flag for that specific BAR in epc_features->bar[], such that pci_epf_alloc_space() will return a epf_bar with the 64-bit flag set. (Such that .set_bar() will receive a request to set a 64-bit BAR.) Signed-off-by: Niklas Cassel --- drivers/pci/endpoint/functions/pci-epf-test.c | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 20c79610712d..91bbfcb1b3ed 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -709,31 +709,18 @@ static void pci_epf_test_unbind(struct pci_epf *epf) static int pci_epf_test_set_bar(struct pci_epf *epf) { - int bar, add; - int ret; - struct pci_epf_bar *epf_bar; + int bar, ret; struct pci_epc *epc = epf->epc; struct device *dev = &epf->dev; struct pci_epf_test *epf_test = epf_get_drvdata(epf); enum pci_barno test_reg_bar = epf_test->test_reg_bar; - const struct pci_epc_features *epc_features; - - epc_features = epf_test->epc_features; - for (bar = 0; bar < PCI_STD_NUM_BARS; bar += add) { - epf_bar = &epf->bar[bar]; - /* - * pci_epc_set_bar() sets PCI_BASE_ADDRESS_MEM_TYPE_64 - * if the specific implementation required a 64-bit BAR, - * even if we only requested a 32-bit BAR. - */ - add = (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ? 2 : 1; - - if (epc_features->bar[bar].type == BAR_RESERVED) + for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { + if (!epf_test->reg[bar]) continue; ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, - epf_bar); + &epf->bar[bar]); if (ret) { pci_epf_free_space(epf, epf_test->reg[bar], bar, PRIMARY_INTERFACE); From patchwork Wed Mar 13 10:57:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13591238 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 377DE3F9C3 for ; Wed, 13 Mar 2024 10:58:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327518; cv=none; b=a3EbuZ5RChwxRzDf50pfT5ZReb/ewkfsMoD+fm+70Df0X1b1449vLivOoT7SzemQilGC9juq/Rx1skAtKIWXMqN/Z2EhLuZLzsgtxUO65tWwg1eMK13oalgO7JvYl1fMBtTl4CLM+qzhYBwEWj4MHvsk/qA5RQQH8EDgAx8tvMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327518; c=relaxed/simple; bh=u3NEnQH3hbpbvPQy3Ae5HxD+/6PFY6jbiy6uI31gAxk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pULZdY+arzJd+nds+MiL2rkmuwgDHtIFg//Qsh4C/x2YM3srlII+7BS1bPvCaJdCONB3hiNOwRI2C5Uw4F5pPiuZpxvG6l1G6B6ID1gapdHs819cahgDJ363AK23rpi1byHqUoT4uIxYbX/ekuhXfyCjuwcTW7a4FVA1STDAX0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DdlbhBQw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DdlbhBQw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B22C5C433B1; Wed, 13 Mar 2024 10:58:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710327517; bh=u3NEnQH3hbpbvPQy3Ae5HxD+/6PFY6jbiy6uI31gAxk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DdlbhBQwV11Rd8XygsrCQy6TeNiaGppG5MGN6uXR3KZKnqbPN1n/LescPH2zVV/q6 MT7SJbyRgEmrDLwE6YcGXHn8DTUEGrODfxmGhCnYqYtLyPWJm4BNaogWlbZImYK0uB EAcDJeVVswx+wV9oAMgxKdnc6DThKFASTGbHgJtEfocSH1Opa54JGaL/pYDdUgAZ/I a2wx2HVMBFY9lXqQnDlugUXD0ySP6eFbiueMg7u9Qs6nLNs0eI95GFaii9HjECcXR3 esZa6FxF8LWC5Ob44n41My4Dj4UkXsBO/mztgg540DilD7/LrQ1Kf5357tSmR8yVUZ 3Vk/RxXS9ZWfw== From: Niklas Cassel To: Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Kishon Vijay Abraham I , Bjorn Helgaas Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH v3 6/9] PCI: endpoint: pci-epf-test: Clean up pci_epf_test_unbind() Date: Wed, 13 Mar 2024 11:57:58 +0100 Message-ID: <20240313105804.100168-7-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240313105804.100168-1-cassel@kernel.org> References: <20240313105804.100168-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Clean up pci_epf_test_unbind() by using a continue if we did not allocate memory for the BAR index. This reduces the indentation level by one. This makes pci_epf_test_unbind() more similar to pci_epf_test_set_bar(). Signed-off-by: Niklas Cassel --- drivers/pci/endpoint/functions/pci-epf-test.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 91bbfcb1b3ed..fbe14c7232c7 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -690,20 +690,18 @@ static void pci_epf_test_unbind(struct pci_epf *epf) { struct pci_epf_test *epf_test = epf_get_drvdata(epf); struct pci_epc *epc = epf->epc; - struct pci_epf_bar *epf_bar; int bar; cancel_delayed_work(&epf_test->cmd_handler); pci_epf_test_clean_dma_chan(epf_test); for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) { - epf_bar = &epf->bar[bar]; + if (!epf_test->reg[bar]) + continue; - if (epf_test->reg[bar]) { - pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no, - epf_bar); - pci_epf_free_space(epf, epf_test->reg[bar], bar, - PRIMARY_INTERFACE); - } + pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no, + &epf->bar[bar]); + pci_epf_free_space(epf, epf_test->reg[bar], bar, + PRIMARY_INTERFACE); } } From patchwork Wed Mar 13 10:57:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13591239 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99CD53FB01 for ; Wed, 13 Mar 2024 10:58:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327520; cv=none; b=npUl25e39VGuA9uLMoPn2jgBrBc49TAjT1J4BMp61hGaZYB5OwrSEdz5NLz0Gs7W9aCbEYByOpDmjBaHKYpfYRPo1vPSjUGMI9L2KjvHoqz6ftcCz9yw85Ty6tCs7aUGRV2sKM4lDq8phjXJFfyVsPA91Bqp2SO7or/tupou1WY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327520; c=relaxed/simple; bh=dGFFmN2l74ZRPdhvtM1elVvNv6B/6afZhy1KjLAVKI4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gQEwcaTgPwQN3/cHHijuHnWsDo5GzypWX2aUGIaF26bS5w9Q8BlZqrA31Cs9tnYb+6ftlNHFCqn21evjYYtqoC43v0us2X4H6RTUOJ7Mu39EiRtxd9qGFGRirfoWbhxiztitQ9H3ERgR3B6GJnJEOfigK7XErtIYSbDWjUP4/jY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JDLz/RXD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JDLz/RXD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FE5EC433F1; Wed, 13 Mar 2024 10:58:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710327520; bh=dGFFmN2l74ZRPdhvtM1elVvNv6B/6afZhy1KjLAVKI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JDLz/RXDwDBDHx2XJTYwXG9zFbREf1z4sGQrFRo6kx9AQThsTkN9OBPtCnAqgkfSj qiLBxQ+7tiz/DgFjVchMzkacQ+RD31tNIm4NImHc0mRsAecXHBum7F52hAHdIO8tx0 FTPTn296JSkEewDtVwtOim4nlOdBuGxK+Tr+J4b9ZReiAPoKg5tlvbjB02PMZpHDR7 Y8rTBfoCRVo6olNlGBpMKDf8owvLRARDiY5Ke81wfSoZsRpoL+2WAtJD8mexzxn+rD t/iY/jXHSP8ejHJci9CH0GtFXywW2j+F5Ot/gwOVSm5BDokH+n51tBd1lpEHNEHfYT xWsQzwiVJAxeA== From: Niklas Cassel To: Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Rob Herring , Bjorn Helgaas Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH v3 7/9] PCI: cadence: Set a 64-bit BAR if requested Date: Wed, 13 Mar 2024 11:57:59 +0100 Message-ID: <20240313105804.100168-8-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240313105804.100168-1-cassel@kernel.org> References: <20240313105804.100168-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Ever since commit f25b5fae29d4 ("PCI: endpoint: Setting a BAR size > 4 GB is invalid if 64-bit flag is not set") it has been impossible to get the .set_bar() callback with a BAR size > 4 GB, if the BAR was also not requested to be configured as a 64-bit BAR. Thus, forcing setting the 64-bit flag for BARs larger than 4 GB in the lower level driver is dead code and can be removed. It is however possible that an EPF driver configures a BAR as 64-bit, even if the requested size is < 4 GB. Respect the requested BAR configuration, just like how it is already repected with regards to the prefetchable bit. Signed-off-by: Niklas Cassel Reviewed-by: Manivannan Sadhasivam --- drivers/pci/controller/cadence/pcie-cadence-ep.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/pci/controller/cadence/pcie-cadence-ep.c b/drivers/pci/controller/cadence/pcie-cadence-ep.c index 2d0a8d78bffb..de10e5edd1b0 100644 --- a/drivers/pci/controller/cadence/pcie-cadence-ep.c +++ b/drivers/pci/controller/cadence/pcie-cadence-ep.c @@ -99,14 +99,11 @@ static int cdns_pcie_ep_set_bar(struct pci_epc *epc, u8 fn, u8 vfn, ctrl = CDNS_PCIE_LM_BAR_CFG_CTRL_IO_32BITS; } else { bool is_prefetch = !!(flags & PCI_BASE_ADDRESS_MEM_PREFETCH); - bool is_64bits = sz > SZ_2G; + bool is_64bits = !!(flags & PCI_BASE_ADDRESS_MEM_TYPE_64); if (is_64bits && (bar & 1)) return -EINVAL; - if (is_64bits && !(flags & PCI_BASE_ADDRESS_MEM_TYPE_64)) - epf_bar->flags |= PCI_BASE_ADDRESS_MEM_TYPE_64; - if (is_64bits && is_prefetch) ctrl = CDNS_PCIE_LM_BAR_CFG_CTRL_PREFETCH_MEM_64BITS; else if (is_prefetch) From patchwork Wed Mar 13 10:58:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13591240 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68EFC3D552 for ; Wed, 13 Mar 2024 10:58:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327524; cv=none; b=Mtg0JowSIjynG6JAVLEo7dw03okTkVIU/NkrUO5XLt3aJn0nlLC19ZqaQk+kDfnG4zQo/olyz4q9Mb9GWbh1YY3+Zs0BH2xSYfwiLu4LTNWNYEyJZXDMnIOLGFsco067xZ83Oa4dtD3NPOm+osl7UPZQ27MYwqeXRLljZo0EIZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327524; c=relaxed/simple; bh=fjgTQUcExh1iJN93AN1TOYbTttNnPvt1KtONXArKbVU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uJFkcREPI9i18lKkjIP9I2LG42HxFtX+Kd6lto0hV9RIfXxZ7u3c2UKMkAXyP7TInhxgyzKbsb1BafzlJkNxfon8ypVY8fUT7bVTBCEkXLYyZs6ZnIOTOsX42RmgJzow1j7+0RtykZkizGGJWaqNqbhcg9FmFpfbjtIG3fwtF5Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NDE403aY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NDE403aY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F2FBC433A6; Wed, 13 Mar 2024 10:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710327524; bh=fjgTQUcExh1iJN93AN1TOYbTttNnPvt1KtONXArKbVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NDE403aYJxTfmtcvNmGiBxyYVhAWw4vBrWslmk+SQgqAFAnpqWDh3JAjdAK4pi23x Ijzds15pTvw6eUlaFZiCqYCf/BeBaRgkG/5bM4ezJqh6H2xv2FDy2yUTMeiIOUMcGK d7u0V+OdeNzM9RiYy/t/cX+nEIe7UD1XZ4Q4dWZIKOeg1pXOerZOFcliE63+e/4Pyb uAh4Qf9fI8ZL24pZuzU+Qh0uf6ZipBG1DnPOs3Ib++1ptoVP4qD478v81MEmMZzvU/ +g4W/6YNby72nF11givw9j0rbW5OOxFQNEHN3dhTowmWF+ywGVyN66pBfM9eolWwQw 6nPRWMiksknSA== From: Niklas Cassel To: Manivannan Sadhasivam , Shawn Lin , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Rob Herring , Bjorn Helgaas , Heiko Stuebner Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 8/9] PCI: rockchip-ep: Set a 64-bit BAR if requested Date: Wed, 13 Mar 2024 11:58:00 +0100 Message-ID: <20240313105804.100168-9-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240313105804.100168-1-cassel@kernel.org> References: <20240313105804.100168-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Ever since commit f25b5fae29d4 ("PCI: endpoint: Setting a BAR size > 4 GB is invalid if 64-bit flag is not set") it has been impossible to get the .set_bar() callback with a BAR size > 4 GB, if the BAR was also not requested to be configured as a 64-bit BAR. It is however possible that an EPF driver configures a BAR as 64-bit, even if the requested size is < 4 GB. Respect the requested BAR configuration, just like how it is already repected with regards to the prefetchable bit. Signed-off-by: Niklas Cassel Reviewed-by: Manivannan Sadhasivam --- drivers/pci/controller/pcie-rockchip-ep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/controller/pcie-rockchip-ep.c b/drivers/pci/controller/pcie-rockchip-ep.c index c9046e97a1d2..57472cf48997 100644 --- a/drivers/pci/controller/pcie-rockchip-ep.c +++ b/drivers/pci/controller/pcie-rockchip-ep.c @@ -153,7 +153,7 @@ static int rockchip_pcie_ep_set_bar(struct pci_epc *epc, u8 fn, u8 vfn, ctrl = ROCKCHIP_PCIE_CORE_BAR_CFG_CTRL_IO_32BITS; } else { bool is_prefetch = !!(flags & PCI_BASE_ADDRESS_MEM_PREFETCH); - bool is_64bits = sz > SZ_2G; + bool is_64bits = !!(flags & PCI_BASE_ADDRESS_MEM_TYPE_64); if (is_64bits && (bar & 1)) return -EINVAL; From patchwork Wed Mar 13 10:58:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13591241 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9D5B39867 for ; Wed, 13 Mar 2024 10:58:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327526; cv=none; b=QGBmUemWQhPteXhX1roiDSo3bK38TpEDRD/8hmZlCFKLj+lQQyfa+0imMi/pGUbDtAMVo4sUB1btrcAs9ybopvOiyEdW5dtfEkVPBn9GF5Zec9zXNTTNvXIw+7DROJmRB1m6g+wcuikBVQW6uUlNpU7U993Fg8B529nN0XK0dNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710327526; c=relaxed/simple; bh=zBUxZx9SQIn/bGrmtUc2kf8i/Kt0fwEJho9Hy745O9Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BbZ3QrXJcB9wHzIRqHClYxFZMuXmZuBF4OZqQtlvi3j+YQUBUdGzlUtMjwlkzc34NXvbg5AZyYtYUHLNbwh0CTIEIHVl4b8j87vdp8C+PKiCcf80tGZXt5KVoJ+QvTh6oxBiZBidYwWFAGgV6S1MpU0lFqP/Vg8+emQ5QfgskiA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Uq7wGPoy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Uq7wGPoy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3C8BC433F1; Wed, 13 Mar 2024 10:58:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710327526; bh=zBUxZx9SQIn/bGrmtUc2kf8i/Kt0fwEJho9Hy745O9Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uq7wGPoyCC0E7ZIE3jK6p1Ly+SlPr4602efaen77BKkKCQfPV6SkSS9WKT/nMqnqq /sTQ7No/NgWe5pn1Ez5pQCe8oT+GokRFHekxMQQQTMqPHcn8rXlfH1+Ibi+jYiZiQf KRdaL73nRBb21fY8/17MrxO9BWNtJAAnp8hxUup75bn/dT8FbKEmf0ob5L46S8ihVV zdgqMrI4XjawlDh4m/CTZBwHMD+EbRXs68OfnO4lpTgzlBsOmWHsrkk0VDcSktmPN4 X8odhfp6680P5Za6tDhuen3z21phsuWGGhx8e0bHpwSG0hlvgM36xBqLAcvOWHtKFw +DK9+3MTjuDBw== From: Niklas Cassel To: Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Kishon Vijay Abraham I , Bjorn Helgaas Cc: Shradha Todi , Damien Le Moal , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH v3 9/9] PCI: endpoint: Set prefetch when allocating memory for 64-bit BARs Date: Wed, 13 Mar 2024 11:58:01 +0100 Message-ID: <20240313105804.100168-10-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240313105804.100168-1-cassel@kernel.org> References: <20240313105804.100168-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From the PCIe 6.0 base spec: "Generally only 64-bit BARs are good candidates, since only Legacy Endpoints are permitted to set the Prefetchable bit in 32-bit BARs, and most scalable platforms map all 32-bit Memory BARs into non-prefetchable Memory Space regardless of the Prefetchable bit value." "For a PCI Express Endpoint, 64-bit addressing must be supported for all BARs that have the Prefetchable bit Set. 32-bit addressing is permitted for all BARs that do not have the Prefetchable bit Set." "Any device that has a range that behaves like normal memory should mark the range as prefetchable. A linear frame buffer in a graphics device is an example of a range that should be marked prefetchable." The PCIe spec tells us that we should have the prefetchable bit set for 64-bit BARs backed by "normal memory". The backing memory that we allocate for a 64-bit BAR using pci_epf_alloc_space() (which calls dma_alloc_coherent()) is obviously "normal memory". Thus, set the prefetchable bit when allocating backing memory for a 64-bit BAR. Signed-off-by: Niklas Cassel --- drivers/pci/endpoint/pci-epf-core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index e7dbbeb1f0de..20d2bde0747c 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -309,6 +309,9 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar, else epf_bar[bar].flags |= PCI_BASE_ADDRESS_MEM_TYPE_32; + if (epf_bar[bar].flags & PCI_BASE_ADDRESS_MEM_TYPE_64) + epf_bar[bar].flags |= PCI_BASE_ADDRESS_MEM_PREFETCH; + return space; } EXPORT_SYMBOL_GPL(pci_epf_alloc_space);