From patchwork Thu Oct 14 15:57:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lombard X-Patchwork-Id: 1540992 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=NlwWwkQB; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HVYwH2Bprz9sNH for ; Fri, 15 Oct 2021 02:58:23 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HVYwG4NVZz3bYD for ; Fri, 15 Oct 2021 02:58:22 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=NlwWwkQB; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=clombard@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=NlwWwkQB; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4HVYtz2dn6z2yPk for ; Fri, 15 Oct 2021 02:57:14 +1100 (AEDT) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19EFlFrM025131 for ; Thu, 14 Oct 2021 11:57:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=AaGxUxE4IR8oPylRMfVEupMm9SQZQnsNiZI+JoTiUXQ=; b=NlwWwkQBw8FnjHYVtF9HG9NfZQNkowPq1sfVhwscSdqgiwz5bKmGxm5JXtQd9iU158X/ /VyAcxp6rnWYpVFiFdrlzYItrScJFbroyUt+SbjTU8Oi6PTFFprXV5V2bo02343EK4fY gGqSsxFQLyj+kHBiT4GXWHUZO6njofbqeTCAX5Zah1u/r1WvgwpCUAVPnlEk6/lMObXM TKQqFVoRDD4N179QILHIjtf2ixDcBzeSNSl9Hg+Ik0qJ3SJmy9TdwivMOEL/xAMkWp54 sR4FoI+CamdCWBi+w4iDGp1CKe5YjiWsv7nd2ekx6I/8lLoWPTPu+8hmxXJyMOaRMV6m Ng== Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com with ESMTP id 3bnprkde4a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Oct 2021 11:57:12 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 19EFXW11029887 for ; Thu, 14 Oct 2021 15:57:10 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma03ams.nl.ibm.com with ESMTP id 3bk2qa6ysy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Oct 2021 15:57:10 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 19EFv8rF7209618 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 14 Oct 2021 15:57:08 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3C58011C04C for ; Thu, 14 Oct 2021 15:57:08 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 18A3E11C04A for ; Thu, 14 Oct 2021 15:57:08 +0000 (GMT) Received: from li-ed209401-43e8-11cb-8043-c0c0b85d70f7.biot.fr.ibm.com (unknown [9.144.57.15]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Thu, 14 Oct 2021 15:57:08 +0000 (GMT) From: Christophe Lombard To: skiboot@lists.ozlabs.org Date: Thu, 14 Oct 2021 17:57:04 +0200 Message-Id: <20211014155704.46441-16-clombard@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211014155704.46441-1-clombard@linux.vnet.ibm.com> References: <20211014155704.46441-1-clombard@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: sal_gq29GHTofX4WQ4Nbxy23Ab7Z2WCI X-Proofpoint-ORIG-GUID: sal_gq29GHTofX4WQ4Nbxy23Ab7Z2WCI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-10-14_08,2021-10-14_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 adultscore=0 impostorscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 priorityscore=1501 spamscore=0 clxscore=1015 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110140093 Subject: [Skiboot] [PATCH V3 15/15] pau: Add support for OpenCAPI Persistent Memory devices. X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Lowest Point of Coherency (LPC) memory allows the host to access memory on an OpenCAPI device. When the P10 chip accesses memory addresses on the AFU, the Real Address on the PowerBus must hit a BAR in the PAU such as GPU-Memory BAR. The BAR defines the range of Real Addresses that represent AFU memory. The two existing OPAL calls, OPAL_NPU_MEM_ALLOC and OPAL_NPU_MEM_RELEASE are used to manage the AFU momory. Signed-off-by: Christophe Lombard --- hw/npu-opal.c | 35 +++++++++++++++++ hw/npu2-opencapi.c | 18 ++------- hw/pau.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++ hw/phys-map.c | 7 +++- include/npu2.h | 3 ++ include/pau-regs.h | 8 ++++ include/pau.h | 4 ++ 7 files changed, 152 insertions(+), 16 deletions(-) diff --git a/hw/npu-opal.c b/hw/npu-opal.c index 2e455dc9..1b66857f 100644 --- a/hw/npu-opal.c +++ b/hw/npu-opal.c @@ -239,3 +239,38 @@ static int64_t opal_npu_tl_set(uint64_t phb_id, uint32_t bdfn, return OPAL_PARAMETER; } opal_call(OPAL_NPU_TL_SET, opal_npu_tl_set, 5); + +static int64_t opal_npu_mem_alloc(uint64_t phb_id, uint32_t bdfn, + uint64_t size, uint64_t *bar) +{ + struct phb *phb = pci_get_phb(phb_id); + + if (!phb) + return OPAL_PARAMETER; + + if (phb->phb_type == phb_type_npu_v2_opencapi) + return npu2_opencapi_mem_alloc(phb, bdfn, size, bar); + + if (phb->phb_type == phb_type_pau_opencapi) + return pau_opencapi_mem_alloc(phb, bdfn, size, bar); + + return OPAL_PARAMETER; +} +opal_call(OPAL_NPU_MEM_ALLOC, opal_npu_mem_alloc, 4); + +static int64_t opal_npu_mem_release(uint64_t phb_id, uint32_t bdfn) +{ + struct phb *phb = pci_get_phb(phb_id);; + + if (!phb) + return OPAL_PARAMETER; + + if (phb->phb_type == phb_type_npu_v2_opencapi) + return npu2_opencapi_mem_release(phb, bdfn); + + if (phb->phb_type == phb_type_pau_opencapi) + return pau_opencapi_mem_release(phb, bdfn); + + return OPAL_PARAMETER; +} +opal_call(OPAL_NPU_MEM_RELEASE, opal_npu_mem_release, 2); diff --git a/hw/npu2-opencapi.c b/hw/npu2-opencapi.c index 272f924b..8e7bcca9 100644 --- a/hw/npu2-opencapi.c +++ b/hw/npu2-opencapi.c @@ -2295,18 +2295,13 @@ out: return rc; } -static int64_t opal_npu_mem_alloc(uint64_t phb_id, uint32_t __unused bdfn, - uint64_t size, __be64 *__bar) +int64_t npu2_opencapi_mem_alloc(struct phb *phb, uint32_t __unused bdfn, + uint64_t size, uint64_t *__bar) { - struct phb *phb = pci_get_phb(phb_id); struct npu2_dev *dev; uint64_t bar; int64_t rc; - - if (!phb || phb->phb_type != phb_type_npu_v2_opencapi) - return OPAL_PARAMETER; - dev = phb_to_npu2_dev_ocapi(phb); if (!dev) return OPAL_PARAMETER; @@ -2320,21 +2315,14 @@ static int64_t opal_npu_mem_alloc(uint64_t phb_id, uint32_t __unused bdfn, return rc; } -opal_call(OPAL_NPU_MEM_ALLOC, opal_npu_mem_alloc, 4); -static int64_t opal_npu_mem_release(uint64_t phb_id, uint32_t __unused bdfn) +int64_t npu2_opencapi_mem_release(struct phb *phb, uint32_t __unused bdfn) { - struct phb *phb = pci_get_phb(phb_id); struct npu2_dev *dev; - - if (!phb || phb->phb_type != phb_type_npu_v2_opencapi) - return OPAL_PARAMETER; - dev = phb_to_npu2_dev_ocapi(phb); if (!dev) return OPAL_PARAMETER; return release_mem_bar(dev); } -opal_call(OPAL_NPU_MEM_RELEASE, opal_npu_mem_release, 2); diff --git a/hw/pau.c b/hw/pau.c index 9f6a7092..a34d6dab 100644 --- a/hw/pau.c +++ b/hw/pau.c @@ -442,6 +442,99 @@ int64_t pau_opencapi_tl_set(struct phb *phb, uint32_t __unused bdfn, return OPAL_SUCCESS; } +static int64_t pau_opencapi_afu_memory_bars(struct pau_dev *dev, + uint64_t size, + uint64_t *bar) +{ + struct pau *pau = dev->pau; + uint64_t addr, psize; + uint64_t reg, val; + + PAUDEVDBG(dev, "Setup AFU Memory BARs\n"); + + if (dev->memory_bar.enable) { + PAUDEVERR(dev, "AFU memory allocation failed - BAR already in use\n"); + return OPAL_RESOURCE; + } + + phys_map_get(pau->chip_id, OCAPI_MEM, + dev->index, + &addr, &psize); + + if (size > psize) { + PAUDEVERR(dev, "Invalid AFU memory BAR allocation size " + "requested: 0x%llx bytes (limit 0x%llx)\n", + size, psize); + return OPAL_PARAMETER; + } + + if (size < (1 << 30)) + size = 1 << 30; + + dev->memory_bar.enable = true; + dev->memory_bar.addr = addr; + dev->memory_bar.size = size; + + reg = PAU_GPU_MEM_BAR(dev->index); + val = PAU_GPU_MEM_BAR_ENABLE | + PAU_GPU_MEM_BAR_POISON; + val = SETFIELD(PAU_GPU_MEM_BAR_ADDR, val, addr >> 30); + if (!is_pow2(size)) + size = 1ull << (ilog2(size) + 1); + + size = (size >> 30) - 1; + val = SETFIELD(PAU_GPU_MEM_BAR_SIZE, val, size); + pau_write(pau, reg, val); + + reg = PAU_CTL_MISC_GPU_MEM_BAR(dev->index); + pau_write(pau, reg, val); + + reg = PAU_XSL_GPU_MEM_BAR(dev->index); + pau_write(pau, reg, val); + + *bar = addr; + return OPAL_SUCCESS; +} + +int64_t pau_opencapi_mem_alloc(struct phb *phb, uint32_t __unused bdfn, + uint64_t size, uint64_t *bar) +{ + struct pau_dev *dev = pau_phb_to_opencapi_dev(phb); + int64_t rc; + + if (!dev) + return OPAL_PARAMETER; + + if (!opal_addr_valid(bar)) + return OPAL_PARAMETER; + + lock(&dev->pau->lock); + rc = pau_opencapi_afu_memory_bars(dev, size, bar); + + unlock(&dev->pau->lock); + return rc; +} + +int64_t pau_opencapi_mem_release(struct phb *phb, uint32_t __unused bdfn) +{ + struct pau_dev *dev = pau_phb_to_opencapi_dev(phb); + + if (!dev) + return OPAL_PARAMETER; + + lock(&dev->pau->lock); + pau_write(dev->pau, PAU_GPU_MEM_BAR(dev->index), 0ull); + pau_write(dev->pau, PAU_CTL_MISC_GPU_MEM_BAR(dev->index), 0ull); + pau_write(dev->pau, PAU_XSL_GPU_MEM_BAR(dev->index), 0ull); + + dev->memory_bar.enable = false; + dev->memory_bar.addr = 0ull; + dev->memory_bar.size = 0ull; + unlock(&dev->pau->lock); + + return OPAL_SUCCESS; +} + #define CQ_CTL_STATUS_TIMEOUT 10 /* milliseconds */ static int pau_opencapi_set_fence_control(struct pau_dev *dev, diff --git a/hw/phys-map.c b/hw/phys-map.c index 711d626e..cfce4ab5 100644 --- a/hw/phys-map.c +++ b/hw/phys-map.c @@ -30,7 +30,12 @@ static const struct phys_map_entry phys_map_table_p10[] = { /* System memory upto 4TB minus GPU memory */ { SYSTEM_MEM, 0, 0x0000000000000000ull, 0x0000034000000000ull }, - /* TODO: Figure out GPU memory */ + /* Configure OpenCapi memory as before with the old chips. + * Keep in mind that we would need to rework this by allocating + * a new topology id. + */ + { OCAPI_MEM, 0, 0x0002000000000000ull, 0x0000040000000000ull }, + { OCAPI_MEM, 1, 0x0002040000000000ull, 0x0000040000000000ull }, /* 0 TB offset @ MMIO 0x0006000000000000ull */ { PHB5_64BIT_MMIO, 0, 0x0006000000000000ull, 0x0000004000000000ull }, diff --git a/include/npu2.h b/include/npu2.h index a12bf98a..b302108b 100644 --- a/include/npu2.h +++ b/include/npu2.h @@ -277,5 +277,8 @@ int64_t npu2_opencapi_spa_clear_cache(struct phb *phb, uint32_t __unused bdfn, uint64_t PE_handle); int64_t npu2_opencapi_tl_set(struct phb *phb, uint32_t __unused bdfn, long capabilities, char *rate); +int64_t npu2_opencapi_mem_alloc(struct phb *phb, uint32_t __unused bdfn, + uint64_t size, uint64_t *bar); +int64_t npu2_opencapi_mem_release(struct phb *phb, uint32_t __unused bdfn); #endif /* __NPU2_H */ diff --git a/include/pau-regs.h b/include/pau-regs.h index da83ad44..45c36037 100644 --- a/include/pau-regs.h +++ b/include/pau-regs.h @@ -64,6 +64,12 @@ #define PAU_SNP_MISC_CFG0_ENABLE_PBUS PPC_BIT(2) #define PAU_SNP_MISC_CFG0_OCAPI_MODE PPC_BITMASK(32, 36) #define PAU_SNP_MISC_CFG0_OCAPI_C2 PPC_BITMASK(45, 49) +#define PAU_GPU_MEM_BAR(brk) (PAU_BLOCK_CQ_SM(0) + 0x190 + (brk) * 8) +#define PAU_GPU_MEM_BAR_ENABLE PPC_BIT(0) +#define PAU_GPU_MEM_BAR_ADDR_MASK PPC_BITMASK(1, 35) +#define PAU_GPU_MEM_BAR_ADDR PPC_BITMASK(1, 21) +#define PAU_GPU_MEM_BAR_SIZE PPC_BITMASK(22, 35) +#define PAU_GPU_MEM_BAR_POISON PPC_BIT(45) #define PAU_NTL_BAR(brk) (PAU_BLOCK_CQ_SM(0) + 0x1b8 + (brk) * 8) #define PAU_NTL_BAR_ENABLE PPC_BIT(0) #define PAU_NTL_BAR_ADDR PPC_BITMASK(3, 35) @@ -88,6 +94,7 @@ #define PAU_CTL_MISC_CFG2_OCAPI_MEM_OS_BIT PPC_BITMASK(25, 29) #define PAU_CTL_MISC_STATUS(brk) (PAU_BLOCK_CQ_CTL + 0x060 + (brk) * 8) #define PAU_CTL_MISC_STATUS_AM_FENCED(brk) (PPC_BITMASK(41, 42) << ((brk)*32)) +#define PAU_CTL_MISC_GPU_MEM_BAR(brk) (PAU_BLOCK_CQ_CTL + 0x070 + (brk) * 8) #define PAU_CTL_MISC_MMIOPA_CONFIG(brk) (PAU_BLOCK_CQ_CTL + 0x098 + (brk) * 8) #define PAU_CTL_MISC_MMIOPA_CONFIG_BAR_ADDR PPC_BITMASK(1, 35) #define PAU_CTL_MISC_MMIOPA_CONFIG_BAR_SIZE PPC_BITMASK(39, 43) @@ -159,6 +166,7 @@ /* XSL block registers */ #define PAU_XSL_OSL_SPAP_AN(brk) (PAU_BLOCK_XSL + 0x000 + (brk) * 8) #define PAU_XSL_OSL_SPAP_AN_EN PPC_BIT(63) +#define PAU_XSL_GPU_MEM_BAR(brk) (PAU_BLOCK_XSL + 0x0D0 + (brk) * 8) #define PAU_XSL_WRAP_CFG (PAU_BLOCK_XSL + 0x100) #define PAU_XSL_WRAP_CFG_CLOCK_ENABLE PPC_BIT(0) #define PAU_XSL_OSL_XLATE_CFG(brk) (PAU_BLOCK_XSL + 0x040 + (brk) * 8) diff --git a/include/pau.h b/include/pau.h index a70058f2..4a6087cb 100644 --- a/include/pau.h +++ b/include/pau.h @@ -45,6 +45,7 @@ struct pau_dev { struct pau_bar ntl_bar; struct pau_bar genid_bar; + struct pau_bar memory_bar; /* Associated I2C information */ uint8_t i2c_bus_id; @@ -209,6 +210,9 @@ int64_t pau_opencapi_spa_clear_cache(struct phb *phb, uint64_t PE_handle); int64_t pau_opencapi_tl_set(struct phb *phb, uint32_t __unused bdfn, long capabilities, char *rate_buf); +int64_t pau_opencapi_mem_alloc(struct phb *phb, uint32_t __unused bdfn, + uint64_t size, uint64_t *bar); +int64_t pau_opencapi_mem_release(struct phb *phb, uint32_t __unused bdfn); /* PHY */ int pau_dev_phy_reset(struct pau_dev *dev);