From patchwork Thu Feb 29 10:48: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: 1906256 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=nYuYvNMs; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-pci+bounces-4239-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TlnzH38T1z1yX7 for ; Thu, 29 Feb 2024 21:49:31 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0EF6628AE4E for ; Thu, 29 Feb 2024 10:49:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2DD6C7A703; Thu, 29 Feb 2024 10:49:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nYuYvNMs" X-Original-To: linux-pci@vger.kernel.org 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 061167A700 for ; Thu, 29 Feb 2024 10:49: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=1709203765; cv=none; b=nvScKaC0wi/lNhqCruw65eBjqxe3NsYJGjbtr2UnYTpwb4u9K7lioqjTtz6CkQuaJVXKnSqF/iVWZzActL7jK6clTYufY7lB/L28EsjRhx5gR5yT2iCucZU4wQ+zTvNdAvjPmHix0Zf4X4dk+uqQLY/IPlnVnYXDosYyzzz1OqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709203765; c=relaxed/simple; bh=roKdtuLhwaJZnyD6Vz3K9fl9O1TAHQM3ub5kVhHjXdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hwis6jU04W+655qRjDEjlAp1NtRfXM78LpP7rhgRXcS6OCMYKnJNkFH4v1IgIBqLl2HgXA2q9kdbEFyuaBbR1NZEfajXUTbSOeJH+FGnpRSMV85SvGExX1pHQO84eeReDRP7RmH7ew+hdxHDMMz0wKLrZ3HelmQtn9mZ1r8TK9E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nYuYvNMs; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78B47C43390; Thu, 29 Feb 2024 10:49:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709203764; bh=roKdtuLhwaJZnyD6Vz3K9fl9O1TAHQM3ub5kVhHjXdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nYuYvNMsKBppWh1u4QdpXurCsqoWMSiVyyPk1jg4p91OTsgU0YjOtUy1/ZZqtZEyJ tk2OykIvsENx76UNIl5k2q6jgdRgk/Ow9Wo1Ez0y83+aTqIbXmPaaDEi3MqvoMK+hK RiYeOuhOufQdbYYd7ZaGiukIQxPUmGSalCVdNNuswbAMcKUhWfnc6edPFmmF4Znz28 B3vFepTFk1aRCUyTt9SFOWRNRqDW9K4mUgEQ0YRDETh4kV/gjgR3CufjbypUVKZEXT Km/lKkOsuBqLj7A9gPRL+xHonRSYudSZ3PllCBh/jeTNurWeBNoLqSu5B4dM2MAI1A BzwwSYAhHjRVA== From: Niklas Cassel To: Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Bjorn Helgaas Cc: Shradha Todi , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH 1/2] PCI: endpoint: Move .only_64bit check to core Date: Thu, 29 Feb 2024 11:48:58 +0100 Message-ID: <20240229104900.894695-2-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240229104900.894695-1-cassel@kernel.org> References: <20240229104900.894695-1-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move the .only_64bit check to pci-epf-core, such that this check does not need to be duplicated in all endpoint function drivers. Signed-off-by: Niklas Cassel --- drivers/pci/endpoint/functions/pci-epf-test.c | 14 -------------- drivers/pci/endpoint/pci-epf-core.c | 7 ++++--- 2 files 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 cd4ffb39dcdc..a7f0b5ebc1e8 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -870,19 +870,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; @@ -907,7 +894,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; 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 Thu Feb 29 10:48: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: 1906257 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=upJ5fMwu; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-pci+bounces-4240-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TlnzM4lM7z1yX7 for ; Thu, 29 Feb 2024 21:49:35 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 969F01F231F9 for ; Thu, 29 Feb 2024 10:49:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 00C0A65194; Thu, 29 Feb 2024 10:49:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="upJ5fMwu" X-Original-To: linux-pci@vger.kernel.org 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 D1D19657AF for ; Thu, 29 Feb 2024 10:49:27 +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=1709203767; cv=none; b=YvdndIvXjMjJVxeRnOtFsdDEZpMSKoLL2aAJOZYPwyULbd+mkvYbOPnyIZpky9KSsJl3wg5AYguFhPyS3JmyOGNdLICExMesFc76Hj9P99jWPb/uk4EswlUgnE5bwDWwEw7ysVH8o8IVe2GBGRqkQosqitK/12yt7LuGLGVqxb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709203767; c=relaxed/simple; bh=q7/juh58Ish9tN+cyfUjNXSuZK6Dq95jqNb6zEzMQTM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L8eFZE/LZ1mYA7rVX1y1WwMWEqp1S1PimyeIQg2p9b8KMJdQW/tjRbK+xHHyombwluyeP4ajvKZHFzFOnpwf48cwMefYpO+5+aZzKKVyOMZoPrJEuaAW7LJTnYbidziysiXCXlnOQNM1+/EpoEoEn4Pb+NfA7pnwXK81exNYU2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=upJ5fMwu; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37EB1C433F1; Thu, 29 Feb 2024 10:49:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709203767; bh=q7/juh58Ish9tN+cyfUjNXSuZK6Dq95jqNb6zEzMQTM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=upJ5fMwuG6zs2FPP5/fbjSh370+MA0TJ+d8Gz3vzkIgyb6MQ1aZhgXjEN3pr1lnbH Sgn6J9ZJ2735smWUUlyJ8EuODqE9RS1krQksxse6w+Tbkh3Ne3kvcmXgJyRwF4D/H7 KylJa5n58rS+DUHbn9tlyR8emR+ifq3L03dB3j+1pS8LzRGeW7N6CL9YqgcNyoZjhC 0XIxBRXaQ1Y1jSb9k1E+kcZ/VU8Nk7RwF3Tx/W00L0b2sspQk4wv6RrzNKj4FzHd8K hwnj+UUmN+6/uUzFullhjF/1goa2jZGlDdmet1HbYgthzbjmiwTI3vygfaIKczTePL WbBIMJOinAtFg== From: Niklas Cassel To: Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Manivannan Sadhasivam , Kishon Vijay Abraham I , Bjorn Helgaas Cc: Shradha Todi , Niklas Cassel , linux-pci@vger.kernel.org Subject: [PATCH 2/2] PCI: endpoint: Set prefetch when allocating memory for 64-bit BARs Date: Thu, 29 Feb 2024 11:48:59 +0100 Message-ID: <20240229104900.894695-3-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240229104900.894695-1-cassel@kernel.org> References: <20240229104900.894695-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, 2 insertions(+), 1 deletion(-) diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c index e7dbbeb1f0de..10264d662abf 100644 --- a/drivers/pci/endpoint/pci-epf-core.c +++ b/drivers/pci/endpoint/pci-epf-core.c @@ -305,7 +305,8 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar, epf_bar[bar].size = size; epf_bar[bar].barno = bar; if (upper_32_bits(size) || epc_features->bar[bar].only_64bit) - epf_bar[bar].flags |= PCI_BASE_ADDRESS_MEM_TYPE_64; + epf_bar[bar].flags |= PCI_BASE_ADDRESS_MEM_TYPE_64 | + PCI_BASE_ADDRESS_MEM_PREFETCH; else epf_bar[bar].flags |= PCI_BASE_ADDRESS_MEM_TYPE_32;