From patchwork Fri Jul 19 11:57:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rick Wertenbroek X-Patchwork-Id: 1962460 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=LCNWCjcv; 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-10547-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) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WQSqs32K5z1ySl for ; Fri, 19 Jul 2024 21:58:33 +1000 (AEST) 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 D8A7528275A for ; Fri, 19 Jul 2024 11:58:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A8F0512C550; Fri, 19 Jul 2024 11:58:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LCNWCjcv" X-Original-To: linux-pci@vger.kernel.org Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B996012C48A; Fri, 19 Jul 2024 11:58:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721390297; cv=none; b=EY7zvyevDGJ2ffgr0Iy05sAoz3ycdIP/shQmI8zKjCxHtLWfL3DWPW/nmwi5BNQ/wZMxAcA7hshB3+sKfY75iLiPlasR71AGWoOuOSazHx3Xu6mIlcCv/+LewCAq6uTx8ck9vkOezdqtgbSTNaFWEPE09q9qwAAngtHKgbNITzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721390297; c=relaxed/simple; bh=nGmCtyaoo/NenZbRAcwq02lmK89X8ME9OviEr2cgy0A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ojx64snooKdgsWC+bhuD8RBNZ7G1gjT2GeDqARlSMSlrMWdUbdcCkIuCr5Cjao42DYm5Uk5JspC3GEXsqTNm10KdL6wu7iH/lJ1dxjifU67j6TPXZgrxcDi0i5wkq8hIwdVhJd+cQuADB+QpIhpKy2s2jhXN3hFC/LWImOaRCRo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LCNWCjcv; arc=none smtp.client-ip=209.85.208.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2eea8ea8bb0so35499671fa.1; Fri, 19 Jul 2024 04:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721390294; x=1721995094; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8ndYd3/BRas2vcGoQPROgeJBUT+iVBkkW19vxoWstj8=; b=LCNWCjcvfR758kQXRcwxWY9hHdUrIqDhuW8DFGFAYsfUCFvPa6pvbDDTknSmc2xqSg di9EJ2S7MUEHJVP+Xl/fIABPa5shmlhwPCTr/FUa4TNyeXKyPvc0LJppbVveKBir/cJU jKPXtDa98Kn4Tr+wQI3m2mP31n85dnSgR2TxD4elPALoCYaVjvNCJ4OK78JXu00ew/zF 7wegWZLhZ6lxXNHIMH4bdqizJXo75/vScP98vHNdAKhhwa83oJgrLxcyeEx3+QUb5uCP GlC6dHvHZ+dfJ08/IGIi7wZXRrOE0lDprXs4GSZoumoYlPCiiIbNeYCoLeh4L83oS/oh diwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721390294; x=1721995094; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8ndYd3/BRas2vcGoQPROgeJBUT+iVBkkW19vxoWstj8=; b=AZftq04DSzVtTMEYHDL0CXDcJDT/iJ5FsL+qQBB5Z8VV0yjr5qYzndKAlaYeApYlEV SD60MLQgnx3Pal1Nfuep8kDvrEDIu7ia7FSVwNEk8uFQ8JgIg76QuJNj2xycFa3WZtof I55c6VKTZmnaRjPA8NA5Z/YP1c9pWygCQEFMgOBaG8aRROq/w0Rc+mw4D1BDC6jBvKQ7 OEDHdcsUl0SdsyjBp89RrAXw9pPrVgvtFYObPHJdmpnTmnsCc+PdkCNJ9N2CqRxzhLR4 lqKVJAErvUOi9OP/Sw22JIiVZBokHXG6D/E66NF1T/vZ0oe3es+UTJjS337E1Wd0gM5h /lrw== X-Forwarded-Encrypted: i=1; AJvYcCV+szmb8Yjhrns9A5ShM3pLw1XeK0sPuzDKXziKsEkHAWCUkDV59E6pgqHdcqfyWp3mRXUE0XSBxvBfjBrnTkclCrBlvYWzSUtT33p0TEi56+36dy8oJIUp9pmTZg73npBarUItuCQB X-Gm-Message-State: AOJu0YynXt3UzBD+V37DxphNSfKgZ0dwxB6viJ8EU69AFTzqdG2wjo/Q kbJQSn5csU25w9Axyx+CQgV7LUEUzyq0fY9Se1Ty3Oe60HX4GIdr X-Google-Smtp-Source: AGHT+IEK7y+j95P+ubpLkTdvJX5WZ7sJ8PWs/Q7ObGPtB2V2NOiCCg/AXRNfHFsMD5z0rFqnKV0wmw== X-Received: by 2002:a2e:3610:0:b0:2ee:87b9:91a8 with SMTP id 38308e7fff4ca-2ef05c7393emr41859111fa.19.1721390293781; Fri, 19 Jul 2024 04:58:13 -0700 (PDT) Received: from A13PC04R.einet.ad.eivd.ch ([193.134.219.72]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5a30c2f869dsm1093824a12.65.2024.07.19.04.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jul 2024 04:58:13 -0700 (PDT) From: Rick Wertenbroek To: rick.wertenbroek@heig-vd.ch Cc: damien.lemoal@kernel.org, alberto.dassatti@heig-vd.ch, Rick Wertenbroek , Manivannan Sadhasivam , =?utf-8?q?Krzyszt?= =?utf-8?q?of_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Niklas Cassel , Frank Li , Damien Le Moal , Lars-Peter Clausen , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] PCI: endpoint: Introduce 'get_bar' to map fixed address BARs in EPC Date: Fri, 19 Jul 2024 13:57:38 +0200 Message-Id: <20240719115741.3694893-2-rick.wertenbroek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240719115741.3694893-1-rick.wertenbroek@gmail.com> References: <20240719115741.3694893-1-rick.wertenbroek@gmail.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The current mechanism for BARs is as follows: The endpoint function allocates memory with 'pci_epf_alloc_space' which calls 'dma_alloc_coherent' to allocate memory for the BAR and fills a 'pci_epf_bar' structure with the physical address, virtual address, size, BAR number and flags. This 'pci_epf_bar' structure is passed to the endpoint controller driver through 'set_bar'. The endpoint controller driver configures the actual endpoint to reroute PCI read/write TLPs to the BAR memory space allocated. The problem with this is that not all PCI endpoint controllers can be configured to reroute read/write TLPs to their BAR to a given address in memory space. Some PCI endpoint controllers e.g., FPGA IPs for Intel/Altera and AMD/Xilinx PCI endpoints. These controllers come with pre-assigned memory for the BARs (e.g., in FPGA BRAM), because of this the endpoint controller driver has no way to tell these controllers to reroute the read/write TLPs to the memory allocated by 'pci_epf_alloc_space' and no way to get access to the memory pre-assigned to the BARs through the current API. Therefore, introduce 'get_bar' which allows to get access to a BAR without calling 'pci_epf_alloc_space'. Controllers with pre-assigned bars can therefore implement 'get_bar' which will assign the BAR pyhsical address, virtual address through ioremap, size, and flags. PCI endpoint functions can query the endpoint controller through the 'fixed_addr' boolean in the 'pci_epc_bar_desc' structure. Similarly to the BAR type, fixed size or fixed 64-bit descriptions. With this information they can either call 'pci_epf_alloc_space' and 'set_bar' as is currently the case, or call the new 'get_bar'. Both will provide a working, memory mapped BAR, that can be used in the endpoint function. Signed-off-by: Rick Wertenbroek --- drivers/pci/endpoint/pci-epc-core.c | 37 +++++++++++++++++++++++++++++ include/linux/pci-epc.h | 7 ++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 84309dfe0c68..fcef848876fe 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -544,6 +544,43 @@ int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no, } EXPORT_SYMBOL_GPL(pci_epc_set_bar); +/** + * pci_epc_get_bar - get BAR configuration from a fixed address BAR + * @epc: the EPC device on which BAR resides + * @func_no: the physical endpoint function number in the EPC device + * @vfunc_no: the virtual endpoint function number in the physical function + * @bar: the BAR number to get + * @epf_bar: the struct epf_bar to fill + * + * Invoke to get the configuration of the endpoint device fixed address BAR + */ +int pci_epc_get_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no, + enum pci_barno bar, struct pci_epf_bar *epf_bar) +{ + int ret; + + if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions) + return -EINVAL; + + if (vfunc_no > 0 && (!epc->max_vfs || vfunc_no > epc->max_vfs[func_no])) + return -EINVAL; + + if (bar < 0 || bar >= PCI_STD_NUM_BARS) + return -EINVAL; + + if (!epc->ops->get_bar) + return -EINVAL; + + epf_bar->barno = bar; + + mutex_lock(&epc->lock); + ret = epc->ops->get_bar(epc, func_no, vfunc_no, bar, epf_bar); + mutex_unlock(&epc->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(pci_epc_get_bar); + /** * pci_epc_write_header() - write standard configuration header * @epc: the EPC device to which the configuration header should be written diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index 85bdf2adb760..a5ea50dd49ba 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -37,6 +37,7 @@ pci_epc_interface_string(enum pci_epc_interface_type type) * @write_header: ops to populate configuration space header * @set_bar: ops to configure the BAR * @clear_bar: ops to reset the BAR + * @get_bar: ops to get a fixed address BAR that cannot be set/cleared * @map_addr: ops to map CPU address to PCI address * @unmap_addr: ops to unmap CPU address and PCI address * @set_msi: ops to set the requested number of MSI interrupts in the MSI @@ -61,6 +62,8 @@ struct pci_epc_ops { struct pci_epf_bar *epf_bar); void (*clear_bar)(struct pci_epc *epc, u8 func_no, u8 vfunc_no, struct pci_epf_bar *epf_bar); + int (*get_bar)(struct pci_epc *epc, u8 func_no, u8 vfunc_no, + enum pci_barno, struct pci_epf_bar *epf_bar); int (*map_addr)(struct pci_epc *epc, u8 func_no, u8 vfunc_no, phys_addr_t addr, u64 pci_addr, size_t size); void (*unmap_addr)(struct pci_epc *epc, u8 func_no, u8 vfunc_no, @@ -163,6 +166,7 @@ enum pci_epc_bar_type { * struct pci_epc_bar_desc - hardware description for a BAR * @type: the type of the BAR * @fixed_size: the fixed size, only applicable if type is BAR_FIXED_MASK. + * @fixed_addr: indicates that the BAR has a fixed address in memory map. * @only_64bit: if true, an EPF driver is not allowed to choose if this BAR * should be configured as 32-bit or 64-bit, the EPF driver must * configure this BAR as 64-bit. Additionally, the BAR succeeding @@ -176,6 +180,7 @@ enum pci_epc_bar_type { struct pci_epc_bar_desc { enum pci_epc_bar_type type; u64 fixed_size; + bool fixed_addr; bool only_64bit; }; @@ -238,6 +243,8 @@ int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no, struct pci_epf_bar *epf_bar); void pci_epc_clear_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no, struct pci_epf_bar *epf_bar); +int pci_epc_get_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no, + enum pci_barno, struct pci_epf_bar *epf_bar); int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no, phys_addr_t phys_addr, u64 pci_addr, size_t size); From patchwork Fri Jul 19 11:57:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rick Wertenbroek X-Patchwork-Id: 1962461 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=eLO0ElYh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-pci+bounces-10548-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (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 4WQSr53s2Hz1ySl for ; Fri, 19 Jul 2024 21:58:45 +1000 (AEST) 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id BF3711C2124C for ; Fri, 19 Jul 2024 11:58:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1FA2C1353FE; Fri, 19 Jul 2024 11:58:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eLO0ElYh" X-Original-To: linux-pci@vger.kernel.org Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5210B12CD96; Fri, 19 Jul 2024 11:58:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721390301; cv=none; b=eHaSGhTyuzjV8+8Dk+y4zhCTvxzLYaPUSKiH5L8ANn7FWTK0dEtW8OzNPjYO2unUIu7cKLQWgS4mwsmboktrBCN0ycN0ckozS5L7xdSJ7wCac2bCYbPqOZ8trkG6yWxxNVUjbfk8X/+iJofCKAzApIPKrIx2SY0HpFFE94JxXyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721390301; c=relaxed/simple; bh=sLHmBEB6uBc7dNYSEPGdj0uIBt0mLK9vw20uIX/LM1U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YUdlfbdGF61zFAujt39+58lt9u/X9aqXMSTztCYC7dWdnSZCdvD8F4nklduZNjHIcPKhBWaW1jchg3S48mOrD6HYvcGMAaytix61B2XZjLco4I3D/H8HnFBB6S9pKK2lR2Aq7WOqo2ASVnpyaJiB20qpmj5xiGS3iMglO2WgQc0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eLO0ElYh; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5a309d1a788so653352a12.3; Fri, 19 Jul 2024 04:58:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721390297; x=1721995097; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rMZ2vwWWPohWA8coYDDEnLa959ZR+LHUBzwjlRfaBv8=; b=eLO0ElYh1jr/ieef6lvjtsz3QBCFGtH+1Cw9cCY6TATpx0X72UVdTj/Im4JqLFR5Rp OhxfQlunlz4rU0z+Ot15IYRstC+bbjCYUueG9ozwCsQBniG0BiZH8vlaqx8R1AudkWfU kPq2VjM8UVRrNvwNsmB2apr1SEmBzdGxbQFvmsuW2XBQz2OZp7leKZTgnSlo3tys2JAo 4tzhByld/lOz6UwOuFoTGvYMrO9V1R77uTjYCpYoRXYokuhXGM5rZ6DRBK86418y2HPd zuuFuDu1YbbVVMN86jpoqIqZpIsX7gQASHudZiuL4N86F1KPyawNTRG3BGtxHc8i/9Tr Xklg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721390297; x=1721995097; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rMZ2vwWWPohWA8coYDDEnLa959ZR+LHUBzwjlRfaBv8=; b=aUdoIOGr42tJHltqXECC1Wuf41yv89TaNi2yRYg7G+kIPlwVf+VTeSHm3pIgbqJo6J bEm6U9Hs7sHBSBwxz8hh/6icqdkVm+O4NrLMbByvn2M4YxebbaUSIlaIQJUID6ErCs+m 7RbB0KeYfQ3ZxEhv1wou85K/kPthU7CzGKZUGZY28EseDUK7uRJEassILLbknZPtnMwh T31c47s5BdbreawVP0FabGt0LhBRjpjl/Thj5ku+vLpYLA9AGlB5OE8RRHbKg7TW9gos UZB9eaQEn02W3CC/6hwUy6ieo+39mw9AfoTJ09i1MaNnWtfkwX/paPLGwf2OYNd7quHj 3j8w== X-Forwarded-Encrypted: i=1; AJvYcCVl4h8dyWiOeDAHQS11copEOD9XXWNAeEDXOPXGjo+Iozy8aE8W4v60swxQThsLnrT5T1uhE5+zdb74Q2VGe3T+Rh76eY1pm3mbf8DyBj7adzIYp519co2teiUUwRjLa5Mx2p42a3KH X-Gm-Message-State: AOJu0Yyw1db4NsDnXruUDMNpivYWsfME/oELPhfD3kJPhxyEpO/MEq4i TQnRepH2VCwdA3d9GFtdZkcw5a0tkxt1UJlaw0X60Wfq7tuiJi3J X-Google-Smtp-Source: AGHT+IGc6hAXUPZQKnBDnc0052YD3WK67HOr4rBNRgcSsKlruuZpUKTx5cO8Zv4m9lxTucgsDtNcBA== X-Received: by 2002:a50:aa98:0:b0:5a1:a447:9f9b with SMTP id 4fb4d7f45d1cf-5a1a447a35bmr2700292a12.27.1721390297463; Fri, 19 Jul 2024 04:58:17 -0700 (PDT) Received: from A13PC04R.einet.ad.eivd.ch ([193.134.219.72]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-5a30c2f869dsm1093824a12.65.2024.07.19.04.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jul 2024 04:58:17 -0700 (PDT) From: Rick Wertenbroek To: rick.wertenbroek@heig-vd.ch Cc: damien.lemoal@kernel.org, alberto.dassatti@heig-vd.ch, Rick Wertenbroek , Manivannan Sadhasivam , =?utf-8?q?Krzyszt?= =?utf-8?q?of_Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Niklas Cassel , Frank Li , Damien Le Moal , Lars-Peter Clausen , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] PCI: endpoint: pci-epf-test: Add support for controller with fixed addr BARs Date: Fri, 19 Jul 2024 13:57:39 +0200 Message-Id: <20240719115741.3694893-3-rick.wertenbroek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240719115741.3694893-1-rick.wertenbroek@gmail.com> References: <20240719115741.3694893-1-rick.wertenbroek@gmail.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch demonstates how the new 'get_bar' API for fixed address PCI BARs is used alongside the previous 'pci_epf_alloa_space' and 'set_bar'. Signed-off-by: Rick Wertenbroek --- drivers/pci/endpoint/functions/pci-epf-test.c | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 7c2ed6eae53a..c6622894091c 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -698,6 +698,9 @@ static int pci_epf_test_set_bar(struct pci_epf *epf) if (!epf_test->reg[bar]) continue; + if (epf_test->epc_features->bar[bar].fixed_addr) + continue; + ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, &epf->bar[bar]); if (ret) { @@ -722,6 +725,9 @@ static void pci_epf_test_clear_bar(struct pci_epf *epf) if (!epf_test->reg[bar]) continue; + if (epf_test->epc_features->bar[bar].fixed_addr) + continue; + pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no, &epf->bar[bar]); } @@ -829,6 +835,7 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) enum pci_barno bar; const struct pci_epc_features *epc_features = epf_test->epc_features; size_t test_reg_size; + int ret; test_reg_bar_size = ALIGN(sizeof(struct pci_epf_test_reg), 128); @@ -840,8 +847,19 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) } test_reg_size = test_reg_bar_size + msix_table_size + pba_size; - base = pci_epf_alloc_space(epf, test_reg_size, test_reg_bar, - epc_features, PRIMARY_INTERFACE); + if (!epc_features->bar[test_reg_bar].fixed_addr) + base = pci_epf_alloc_space(epf, test_reg_size, test_reg_bar, + epc_features, PRIMARY_INTERFACE); + else { + ret = pci_epc_get_bar(epf->epc, epf->func_no, epf->vfunc_no, + test_reg_bar, &epf->bar[test_reg_bar]); + if (ret < 0) { + dev_err(dev, "Failed to get fixed address BAR\n"); + return ret; + } + base = epf->bar[test_reg_bar].addr; + } + if (!base) { dev_err(dev, "Failed to allocated register space\n"); return -ENOMEM; @@ -856,8 +874,20 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) if (bar == test_reg_bar) continue; - base = pci_epf_alloc_space(epf, bar_size[bar], bar, - epc_features, PRIMARY_INTERFACE); + if (!epc_features->bar[bar].fixed_addr) + base = pci_epf_alloc_space(epf, bar_size[bar], bar, + epc_features, + PRIMARY_INTERFACE); + else { + ret = pci_epc_get_bar(epf->epc, epf->func_no, + epf->vfunc_no, bar, + &epf->bar[bar]); + if (ret < 0) + base = NULL; + else + base = epf->bar[bar].addr; + } + if (!base) dev_err(dev, "Failed to allocate space for BAR%d\n", bar);