From patchwork Tue Mar 12 10:51:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13589830 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 8CCDD69D19 for ; Tue, 12 Mar 2024 10:52: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=1710240749; cv=none; b=PLiEXSyNHAUd8Bn62ZxZI+5RwYghFcN72DtpGXrLnZ2m4wIrKM0tieg15LIxS7xkRfAcoPCjeVjmLwZm2XMPgIsy+8rVUoyuKx9r5LzZDtfRf92vnclSf7wyxzprhOh2nT/8bGL4JQzHhZu0XIsHEPcvnKye1yyEOhn6koFZpWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710240749; c=relaxed/simple; bh=FRR3ONvC1dTDtzKK4rr212hrCcCfCZS60W/bKB4hdjw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EG5agNgtYJ6mcOava+Hu4+ipnWpMTu+4T0IX4IcZSnLeGE9nIyX73ITvtzqFZoZpfz70637RjakHTFuYQyuv0HLl/sO0lpO35vmyk6+5Plc3dSJwJ3GqzVL6h/FyCPHDadVoYbuLHNE4PBzapbtd6y3cFO7npst4/YSZStlEjto= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=heMEk8x+; 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="heMEk8x+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14CEFC43394; Tue, 12 Mar 2024 10:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710240749; bh=FRR3ONvC1dTDtzKK4rr212hrCcCfCZS60W/bKB4hdjw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=heMEk8x+GdHa1asvZzZAGoBX9mvUQUkazS5POCefykPY7Fu3JDAZQQg62EZAJCcCO JsMerhgGhKocH53CbLLCn/tBVUUhgPECNtr1rrs98bSkJeHWcTqX49JUWYLLeZ8RzB uC8DfNNKf59dr+2q5xuSxdo4j18Vfccx/5PBc9YFTMoOkdOa/ytTgbcUwxqOhTN/G2 txU0RoAKqI5VEsY4230BWvZCO80QconzfYPxQI3IDZ+UcCCv8CTrRp3XdwfcsuVAm4 yRnzwgsAO6+Sfb9IYtq792arP9ANHQvSFnyOJI7HBG/3uXmrBej7tKp51hD1aqqb9W bPQlyVRM3LANQ== 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 v2 1/9] PCI: endpoint: pci-epf-test: Fix incorrect loop increment Date: Tue, 12 Mar 2024 11:51:41 +0100 Message-ID: <20240312105152.3457899-2-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312105152.3457899-1-cassel@kernel.org> References: <20240312105152.3457899-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 Tue Mar 12 10:51:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13589831 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 0FE1A78292 for ; Tue, 12 Mar 2024 10:52: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=1710240752; cv=none; b=CdnbJF7cYC3MchXfHNZRWPG870MkQESAAdSRqSiX43ujs6XTtE2AwhdReOVAXTsBYUIPyA7NIRM8SCLLjIdOv4BfobvP5gDI5UBm46mGTkwsNE7h3+aGQrTiDu3pr1x3a8cvBY4MKSTBdmGlGWtstz96zHMKxD2d7miGSMcfmjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710240752; c=relaxed/simple; bh=+5dCeZi10/u3RMlvjT4oH8IBPzU4bcYd+CsEmIgXsME=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fFucZTxEnAewTHZxoCj0CkUgCuMKZaGmNf2c+0QWgjE1+VlWOZCVL4CNwgKmoiUzI6CVMYgCZibdZLjAMTWfxf1rvaW9LBt3r6oGH7aVHxa+00Nyt7h7OwioV37OJdhxz28vWyclXGI506TyTYcUhBi9f8elxPILF1WRc4tT+Qk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oMmjwdiu; 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="oMmjwdiu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D69E7C43390; Tue, 12 Mar 2024 10:52:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710240751; bh=+5dCeZi10/u3RMlvjT4oH8IBPzU4bcYd+CsEmIgXsME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oMmjwdiulXfNKuGy87L81k+OLhk5IxuypqfMJaHpqa1voG1Rvtus+BMgyR+Y4G5ij fFYmrAswW0873Z7cZXVyHkalLjzN9AKzWAqukDNNnppsvXzzkdmHvTbY4cF+v/1xA1 l6s4kVYjsggZV7FqtOI3mN3ERx8Ze/14x5jOas0rjLFamMHYk1cJV5bjd27QqjycFF bfsFBoOKV5ds7WNUhtqevkNsZISAARITiZD445j4eVVmD6SXsxJXtbNwGJGEQKI7GZ GUHbf65C826U7m8fsN4y2R4ku0fwNkcI3RekIFqyOfUNUXWHBU6UKwbspchyoDYYUl vCP+V5DXS77Ww== 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 v2 2/9] PCI: endpoint: Allocate a 64-bit BAR if that is the only option Date: Tue, 12 Mar 2024 11:51:42 +0100 Message-ID: <20240312105152.3457899-3-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312105152.3457899-1-cassel@kernel.org> References: <20240312105152.3457899-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 --- 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 Tue Mar 12 10:51:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13589832 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 2511D59160 for ; Tue, 12 Mar 2024 10:52:34 +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=1710240755; cv=none; b=i6ISOwrv9IE3pNn61uVtWBAD8veG/P4t2r7AuyEl0OYGmfmrwYQEagQUTFUOC48svMjKLDkFYqr6HFL8wmY558Brsl8jU7N+JJ+Bke1sknElBbpAs/m4lFLNZC298VimcwTpbtbiqwKm5RcHolwO8sVD5xr1TaPJL+QLii9rKQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710240755; c=relaxed/simple; bh=e/qH9cmUPYUotD/eAIW0sRrL9XefNgAmZxzo/zRfOXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C9XCE+AsAEiX7x8mv6n3JmIPQo9n0SYOl8+4xLhzhlUZK5gEZN8Qt0IvonE67b2CV7P9BRJdjbkiLcykb0vhBLOJWIEryxpjl8ep+rfjvdUZa/R4AoYQagJCpX4CFvABxcHuZ+hPrf1tCjHxSA9gf4ZP7srH6SxwleW3Nj2mPPo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FcTY8tgH; 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="FcTY8tgH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 935A2C433C7; Tue, 12 Mar 2024 10:52:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710240754; bh=e/qH9cmUPYUotD/eAIW0sRrL9XefNgAmZxzo/zRfOXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FcTY8tgHFmhfs63xzdwx1ePs1/NjxuUWXvWj8mxl3GPDdVr5XG8USjcCJ22YJeyOA MJjGmfBTOmcMCWhG6ITu1wKoXy8RnCujPNABYCnoWQDE5WvI7MTUqUzDzrCn5HCsH1 EM5dmEdA1QKTheq1vhIoiN/P5+WPRxeRq7H8ZL1OKTUBMnFqS7y5zgeAW5bXuouN7V gs2EHkqXWA/onHgxvNYTcON+bg4aY6Ni0h9TGdy56RUzb7EM9VsDdgsrXCsasD0DF5 3PgZbQQXgPvVF9f4S1JQvKzqZB6OsR/e5Ks89t3qbSewS6fbfThNR057WA7m2HqNul oDqsR1PaCnDyw== 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 v2 3/9] PCI: endpoint: pci-epf-test: Remove superfluous code Date: Tue, 12 Mar 2024 11:51:43 +0100 Message-ID: <20240312105152.3457899-4-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312105152.3457899-1-cassel@kernel.org> References: <20240312105152.3457899-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 --- 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 Tue Mar 12 10:51:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13589833 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 C58C278288 for ; Tue, 12 Mar 2024 10:52: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=1710240757; cv=none; b=Oqv7fGEKN5XMl3n4Zlyy6nXceEfEoKMKOPZ632Kw9VO6feyslC3A0RfO1TNT93Btto3JB2kOs+55vt8gONtry86pon9RTO6FG6ziFA1ob22tq+elPQfLqNYRFQGJ+kncTVIliOzjcMSWDLk+DtwocrnAZDD04oad+PTO2x0AKv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710240757; c=relaxed/simple; bh=VqxAnMdNBCPq0LcAygy6XAAssDYODbeSUV3wclX9NVA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O6WC1Xh+QJwrXa3kp7KhfgXL+b/Krk3UyFahXBivMr5F1tpZMM6Y4grOIN7T9oGRhdURaCGOP2v9JXbsjA7eogaXvb0nN2ws7db1nJ1bZkyGxDM6MJW04VJSL0guwosG3UlTciuiMJpx0Idud9bH1VtvevVDK7D8w8sBDS55+Gs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bF46aNex; 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="bF46aNex" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51FCAC43390; Tue, 12 Mar 2024 10:52:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710240757; bh=VqxAnMdNBCPq0LcAygy6XAAssDYODbeSUV3wclX9NVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bF46aNex5rM0tcBGNmilpgoaIGb4d7GgCYhrA9sLwIYAqn47oA+prnWvaybwD1/ms AH/OZRYm9Q/7QYRFWBsJjldc9fi7YEowYqj+9sTq4TntKTIL+kBEU2vHnvyO0aN56B AK7dpIVDz03EhPc9PIA8yV5NLLSOoZMnr1G9QssZ8w6aDN6khrND+Fx+yRz2nA8vYh db4kTMsujSetDJhzXZCuZRUr8u6Qhgkvfb/SChWGr6tPlQxmtuXYnTdvQZQKYFoNGn t9xJBCLfhy/t4sQ+jm1GH58U+kZ0K0J5RJJobEmtJx0JOXYrB0L6+FU/KzXdgsmMYA 8KWWevuJ8QFXw== 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 v2 4/9] PCI: endpoint: pci-epf-test: Simplify pci_epf_test_alloc_space() loop Date: Tue, 12 Mar 2024 11:51:44 +0100 Message-ID: <20240312105152.3457899-5-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312105152.3457899-1-cassel@kernel.org> References: <20240312105152.3457899-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 --- 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 Tue Mar 12 10:51:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13589834 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 3512F2572 for ; Tue, 12 Mar 2024 10:52: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=1710240760; cv=none; b=NRUdbZNZDrZ2LtlrYCAQxzcvwQezyvcuf0zw81ad80qUhrQaV4+RNDe9oGjm14ThBoIzfcCQooh2VcinGu1EB/bJpNwOOVu3BVWnxzQuvcpGHiTmMkLdX71CQuSgR2AYIEHgZ5ReQpAzI37Oh48sv0QSIugzHZgSN2jiEGodeE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710240760; c=relaxed/simple; bh=CZP1SmJ3NdT7dYuSrBTvbK/1KoVHf+6io4nxAOt3bXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rkOQNHhmxKyom2MD+5wNP+KgZc2JkDmoEsNFJvIFhjEjgVgFfkBR8lr4e3MHawr1cxNyvIuktztG4rzUzxoT0pOHiKV/fgiUjLL+LuiqNy0k/WNQVApwW0qPppl2X/dXPzWXelFNgLlcL3jFMkC02jpCAdb8pIWQW+vFfOmda5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TO8vaneg; 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="TO8vaneg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F223C433F1; Tue, 12 Mar 2024 10:52:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710240760; bh=CZP1SmJ3NdT7dYuSrBTvbK/1KoVHf+6io4nxAOt3bXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TO8vanegyFZd1VGw5/xkeiYSRHLwP3ESs4VER92PLoMINQWVEArcPEiDB3c0zmxFT bGVqs+K4JA8MDUEnw9I7exhN7c/H2+Nwnc3X9EELy1uFkSkXUlt7cdIqCT4u/fq3NV vNFRv0VxRTB7mt14k4MAMw+NJkJZh3DYynRW0gqJP+L+Pm8HRQTP13PE6a7JmHce0q 1pmENCSrTJJaw7Ysgr4hchFKrVGob3jNK74ZZze7aT6gKkmFJSChJ3EaKYymDbJYS9 bo4+zSEFhFxf7DvQDkv/P5P9FAJzMQQwyWEY6cWmOOvoH6oovkxxoCy3JG36SYuYDT CYO859pep44JQ== 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 v2 5/9] PCI: endpoint: pci-epf-test: Simplify pci_epf_test_set_bar() loop Date: Tue, 12 Mar 2024 11:51:45 +0100 Message-ID: <20240312105152.3457899-6-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312105152.3457899-1-cassel@kernel.org> References: <20240312105152.3457899-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 | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 20c79610712d..05b9bc1e89cd 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -709,9 +709,7 @@ 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); @@ -720,20 +718,12 @@ static int pci_epf_test_set_bar(struct pci_epf *epf) 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 Tue Mar 12 10:51:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13589835 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 539842572 for ; Tue, 12 Mar 2024 10:52:42 +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=1710240763; cv=none; b=rH+lP4VkI8ra+bRksyACH5FdKg1dXuLQJBlkZ9LxMxQfhJPkHzdBcUpQFkMA0np4EYIUyQ/E37jK5/PK4TREJOf9JNJyI9iLYIbmW0v6foUcYhfFLBytrua+g+3RSMVlHwlW6gSTMODqfYF+IgRyZRbUhEFqiPp7UiYJ1VNAwiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710240763; c=relaxed/simple; bh=G1N/c3EO3NoutU+UHBk1yIOjocdyugM1oztq12+z1ZQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NYUJic8uRITRsFUstk/lZRavg9a7iHdioycUT4ILfYeGcaaijAlHLiKHJhtD2ZbJMsMMubeTTD7iDFmsMCM6s641xQVByPBATor3ZMFBOB5+8bDadNGGISbed3fezcMfuH5eX2zYQZFVy3MIvl6nYCGapMHzSyxYYItJX1Crm2I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=psl+/qzz; 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="psl+/qzz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1C02C43394; Tue, 12 Mar 2024 10:52:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710240762; bh=G1N/c3EO3NoutU+UHBk1yIOjocdyugM1oztq12+z1ZQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=psl+/qzzwpM7rCGIt+TeNU3qqfwoTRux7MnVC+8PJiquCIQPiBI4KqzB/FQJr77oj yYI1bbsmArua5Wmom4YGckKa3FiFDK0an6htA2Cr67i/Cv4QBNSllRJ05Z1Whkedh0 +T/nQxPxuotK4ShpRDdPyr4J/5jK5EvmkXDrW3YgvLcY6gJyUDDiYwpwW1sHsLgAQK BnELLuyfWM+Wt6ku1nn1fWC0hpvqdcFMPwhU2YInHbqTksyW9O5Jj9FREB6IGPqa+D wsunjDcR7pRfEsb1R5pgTmoPynvDur1gqvVWSPGTEqfWXjv/HLsiKMQR97ClFrTvNf PgkVsleayC6/w== 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 v2 6/9] PCI: endpoint: pci-epf-test: Clean up pci_epf_test_unbind() Date: Tue, 12 Mar 2024 11:51:46 +0100 Message-ID: <20240312105152.3457899-7-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312105152.3457899-1-cassel@kernel.org> References: <20240312105152.3457899-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 05b9bc1e89cd..2c1d10afb1ae 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 Tue Mar 12 10:51:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13589836 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 A6E3C2572 for ; Tue, 12 Mar 2024 10:52:45 +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=1710240765; cv=none; b=Nb46bKrhvmvyXLSoVgAdk8xKlgH/7jMowB+ndpoH4/T0a0vfFew3+aFPu/YyCY7/UFsEcML/8Jg1MA6dOCZHQ+9YoNK47PBkrC0hDI9XZD3bECsMRKudaiRPP1yImKfxcvqfQjxNUwzT7b8r6PlePqt0wp21FQCduxvFyp/u4gQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710240765; c=relaxed/simple; bh=dGFFmN2l74ZRPdhvtM1elVvNv6B/6afZhy1KjLAVKI4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K+eIKSbiOb6Ed0HPSXyMCgSwkAAYzKy6wU8RqKl1xuWjZmAK4NCTgS+nhtuGMsMqkvf4r1qyZH9S/y8HkhBQAixnI55LT0CVvvj+FJvzscBtNP2dzawkFgeO7pGDApH9qu89N32A2Cu70EOCXQm4TgrUjPWJUuJ7C3hVW98h29A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CC2hvPJv; 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="CC2hvPJv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D9F0C43399; Tue, 12 Mar 2024 10:52:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710240765; bh=dGFFmN2l74ZRPdhvtM1elVvNv6B/6afZhy1KjLAVKI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CC2hvPJvR7rycjcZq7kK7yUdwuhk2Ziq7YDKKllT24mB8/cYI45uGcUdVkAN/k9JS TsTjCue/CjzSHJXtNBl2JWBADMgIKlnEGyuVNGeVnbK1JdjTFdVIngcRn2RdFPjlER SSLgwnG8tVKgq+kKUSgmR7qr0t22buNwJKZ0Q9Mm+XtHuxruOccth8lp9kRujOzMeV D3r7DPR/G+/h/TB/Lhh2nPidU7FSTr6rVYnz9AQ+p7YRJK8988F4ddxGVHIodD6Eux C98kkDYy/FJELFA14Mqr/RXfmgqeRqX1saC23E2/ggwfps1CCTIeNKLGg3JT8+AJ19 fTvDiy6+o72ww== 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 v2 7/9] PCI: cadence: Set a 64-bit BAR if requested Date: Tue, 12 Mar 2024 11:51:47 +0100 Message-ID: <20240312105152.3457899-8-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312105152.3457899-1-cassel@kernel.org> References: <20240312105152.3457899-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 --- 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 Tue Mar 12 10:51:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13589837 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 250A759160 for ; Tue, 12 Mar 2024 10:52:49 +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=1710240769; cv=none; b=hDEW6gzZxXdvcdbNy0MghGFhY9uE8SefOnmVKdrY4Q5W1FkusDCsSzREDby0Q0uY2DxAdMXITcCGiafqn64LklS8HK/TyiJcmrtRZq8VAlbugPu5SveNp+R0Lu4XAjB/zp8JRZzrjLikU7JP81OjiKP7JRrRs75oDR9EhCOCGNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710240769; c=relaxed/simple; bh=fjgTQUcExh1iJN93AN1TOYbTttNnPvt1KtONXArKbVU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gu48yqSTfsGYwOV5CVpHsdBI/c9jxoyhtsT7OQ7MMXeB2tePNHQdWzuAeoNK8P7meN3i8R4szFCHNc29eraovRqlSdwR3xaq9ReQz6zJ+7/JA9S7RxS75hJDALqpgXGp7BKb2/R95NI6qnW0WPXpmLejGc5rV3HJFMIO64+zGOM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kAsP5egw; 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="kAsP5egw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AC6CC43394; Tue, 12 Mar 2024 10:52:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710240769; bh=fjgTQUcExh1iJN93AN1TOYbTttNnPvt1KtONXArKbVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kAsP5egwKN40NjrnJhDP0W3+HObFATvnEt3jC0BzqO3W2sFcu0m3iLBnos5xWobu7 VCre9dtEf/uQYi9jIxNggTdfvpnyjsy+IFlp9nm0E5bU0eqtaqPVuOhECKstdRsFW0 ZOapTVEAoIa+9jAkHCmht5nRxudsygtbFRmYbCp9sGxMkliCzgGHj4lCGjn8qzjkeJ 0KNKjJ8/Cc+HMl3TAqJAc+04p7G13lys5nBmS1p6JLG0wax+bK4NpYyOHvhf9tZyFM icHK7xnI0DtglTFq5uoWJj/oNlyxPsJPHosNPwmEi1w5QiOACJSEcAZlnjanFmcDC6 z1h101eQCX8tw== 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 v2 8/9] PCI: rockchip-ep: Set a 64-bit BAR if requested Date: Tue, 12 Mar 2024 11:51:48 +0100 Message-ID: <20240312105152.3457899-9-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312105152.3457899-1-cassel@kernel.org> References: <20240312105152.3457899-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 --- 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 Tue Mar 12 10:51:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13589838 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 D3E3B59160 for ; Tue, 12 Mar 2024 10:52:51 +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=1710240771; cv=none; b=TQ1sKCTi/0u7MksjFx5HXxLiEZYtpczW6k5wz03mLUWThpbeBzmhHKpXTuFkfaYFVFNsua2mn88zExqO1WSGh14I5OccYtVLrE+BrI009t3LQyGu4IzOd4hQO7gRcQkohdoix2/6CoTg+XGhsVqYHCYb0KETAYPFjXoT16DqiOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710240771; c=relaxed/simple; bh=zBUxZx9SQIn/bGrmtUc2kf8i/Kt0fwEJho9Hy745O9Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jRfhhdLvd48G65Yh8in4RFnJuAXRZIB/kzOtvnLCeakAaZphelrkZbAynT8K2OYvCLaCTCwSP9EaorKUby9jsDok4p+Enmm+Bdbgua56PFg/+CLsZYBMPGv8yLvsLalillPaK3tZukw7Sb+c81sdoBXeBPmEL2ndN2NFDF885qk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cD9yF2z8; 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="cD9yF2z8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC78FC43394; Tue, 12 Mar 2024 10:52:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710240771; bh=zBUxZx9SQIn/bGrmtUc2kf8i/Kt0fwEJho9Hy745O9Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cD9yF2z8F+FsWRP2fw8WJ3fvnJIOEzSih5x1rHD01TE3YAFuFrotbfAqLrPxqlLob EmQ8LqTFe7mznO/c8O4YrIJMlxHdma0Uwio702QnWV/UGNj2GzcnpEcyDejc+8qMXX A/jqo6I9KSl//lyvCjUJPg4OWUe9drk0h7aeaxFENmOVssP2B8UwtJnkIyFRvpp3U6 aoU9KN+TD1y0m+OHJrrFa1dseLV4gvYEIq2xcTDLWgpcCDfPGqZ6qGTjFUMZFA7Xc2 V4cTkdxyE8aF04k/X0xgLsJCAuQSfYMKJDJchSeKQfTMtDCZxIdx7Lo3qmc+uUvTGt OLg0DUf201wvQ== 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 v2 9/9] PCI: endpoint: Set prefetch when allocating memory for 64-bit BARs Date: Tue, 12 Mar 2024 11:51:49 +0100 Message-ID: <20240312105152.3457899-10-cassel@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240312105152.3457899-1-cassel@kernel.org> References: <20240312105152.3457899-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);