[Skiboot] [PATCH 01/16] [PATCH 01/16] opencapi5: move opal api

Christophe Lombard clombard at linux.vnet.ibm.com
Fri Aug 20 19:45:42 AEST 2021


Move the OPAL entry points for npu2 opencapi to the common opal NPU
file. This prepares us to add same entries for PAU opencapi in this common
file.

No functional change.

Signed-off-by: Christophe Lombard <clombard at linux.vnet.ibm.com>
---
 hw/npu-opal.c      | 67 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/npu2-opencapi.c | 35 ++++--------------------
 include/npu2.h     |  7 +++++
 3 files changed, 79 insertions(+), 30 deletions(-)

diff --git a/hw/npu-opal.c b/hw/npu-opal.c
index 412ea460..64e36852 100644
--- a/hw/npu-opal.c
+++ b/hw/npu-opal.c
@@ -174,3 +174,70 @@ static int64_t opal_npu_get_relaxed_order(uint64_t phb_id,
 	return phb4->ro_state;
 }
 opal_call(OPAL_NPU_GET_RELAXED_ORDER, opal_npu_get_relaxed_order, 2);
+
+#define MAX_PE_HANDLE	((1 << 15) - 1)
+
+static int64_t opal_npu_spa_setup(uint64_t phb_id, uint32_t bdfn,
+				  uint64_t addr, uint64_t PE_mask)
+{
+	struct phb *phb = pci_get_phb(phb_id);
+	int64_t rc = OPAL_SUCCESS;
+
+	if (!phb)
+		return OPAL_PARAMETER;
+
+	/* 4k aligned */
+	if (addr & 0xFFF)
+		return OPAL_PARAMETER;
+
+	if (PE_mask > 15)
+		return OPAL_PARAMETER;
+
+	if (phb->phb_type == phb_type_npu_v2_opencapi)
+		rc = npu2_opencapi_spa_setup(phb, bdfn, addr, PE_mask);
+	else
+		return OPAL_PARAMETER;
+
+	return rc;
+}
+opal_call(OPAL_NPU_SPA_SETUP, opal_npu_spa_setup, 4);
+
+static int64_t opal_npu_spa_clear_cache(uint64_t phb_id, uint32_t bdfn,
+					uint64_t PE_handle)
+{
+	struct phb *phb = pci_get_phb(phb_id);
+	int64_t rc = OPAL_SUCCESS;
+
+	if (!phb)
+		return OPAL_PARAMETER;
+
+	if (PE_handle > MAX_PE_HANDLE)
+		return OPAL_PARAMETER;
+
+	if (phb->phb_type == phb_type_npu_v2_opencapi)
+		rc = npu2_opencapi_spa_clear_cache(phb, bdfn, PE_handle);
+	else
+		return OPAL_PARAMETER;
+
+	return rc;
+}
+opal_call(OPAL_NPU_SPA_CLEAR_CACHE, opal_npu_spa_clear_cache, 3);
+
+static int64_t opal_npu_tl_set(uint64_t phb_id, uint32_t bdfn,
+		    long capabilities, uint64_t rate_phys, int rate_sz)
+{
+	struct phb *phb = pci_get_phb(phb_id);
+	int64_t rc = OPAL_SUCCESS;
+
+	if (!phb)
+		return OPAL_PARAMETER;
+
+	if (phb->phb_type == phb_type_npu_v2_opencapi)
+		rc = npu2_opencapi_tl_set(phb, bdfn, capabilities,
+					  rate_phys, rate_sz);
+	else
+		return OPAL_PARAMETER;
+
+	return rc;
+}
+opal_call(OPAL_NPU_TL_SET, opal_npu_tl_set, 5);
diff --git a/hw/npu2-opencapi.c b/hw/npu2-opencapi.c
index 035c6cdc..686f2e22 100644
--- a/hw/npu2-opencapi.c
+++ b/hw/npu2-opencapi.c
@@ -1957,24 +1957,13 @@ void npu2_opencapi_set_broken(struct npu2 *npu, int brick)
 	}
 }
 
-static int64_t opal_npu_spa_setup(uint64_t phb_id, uint32_t __unused bdfn,
+int64_t npu2_opencapi_spa_setup(struct phb *phb, uint32_t __unused bdfn,
 				uint64_t addr, uint64_t PE_mask)
 {
 	uint64_t stack, block, offset, reg;
-	struct phb *phb = pci_get_phb(phb_id);
 	struct npu2_dev *dev;
 	int rc;
 
-	if (!phb || phb->phb_type != phb_type_npu_v2_opencapi)
-		return OPAL_PARAMETER;
-
-	/* 4k aligned */
-	if (addr & 0xFFF)
-		return OPAL_PARAMETER;
-
-	if (PE_mask > 15)
-		return OPAL_PARAMETER;
-
 	dev = phb_to_npu2_dev_ocapi(phb);
 	if (!dev)
 		return OPAL_PARAMETER;
@@ -1986,7 +1975,6 @@ static int64_t opal_npu_spa_setup(uint64_t phb_id, uint32_t __unused bdfn,
 	else
 		offset = NPU2_XSL_PSL_SPAP_A0;
 
-
 	lock(&dev->npu->lock);
 	/*
 	 * set the SPAP used by the device
@@ -2024,22 +2012,14 @@ out:
 	unlock(&dev->npu->lock);
 	return rc;
 }
-opal_call(OPAL_NPU_SPA_SETUP, opal_npu_spa_setup, 4);
 
-static int64_t opal_npu_spa_clear_cache(uint64_t phb_id, uint32_t __unused bdfn,
-					uint64_t PE_handle)
+int64_t npu2_opencapi_spa_clear_cache(struct phb *phb, uint32_t __unused bdfn,
+				      uint64_t PE_handle)
 {
 	uint64_t cc_inv, stack, block, reg, rc;
 	uint32_t retries = 5;
-	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;
-
-	if (PE_handle > MAX_PE_HANDLE)
-		return OPAL_PARAMETER;
-
 	dev = phb_to_npu2_dev_ocapi(phb);
 	if (!dev)
 		return OPAL_PARAMETER;
@@ -2077,7 +2057,6 @@ out:
 	unlock(&dev->npu->lock);
 	return rc;
 }
-opal_call(OPAL_NPU_SPA_CLEAR_CACHE, opal_npu_spa_clear_cache, 3);
 
 static int get_template_rate(unsigned int templ, char *rate_buf)
 {
@@ -2101,17 +2080,14 @@ static bool is_template_supported(unsigned int templ, long capabilities)
 	return !!(capabilities & (1ull << templ));
 }
 
-static int64_t opal_npu_tl_set(uint64_t phb_id, uint32_t __unused bdfn,
-			long capabilities, uint64_t rate_phys, int rate_sz)
+int64_t npu2_opencapi_tl_set(struct phb *phb, uint32_t __unused bdfn,
+		    long capabilities, uint64_t rate_phys, int rate_sz)
 {
-	struct phb *phb = pci_get_phb(phb_id);
 	struct npu2_dev *dev;
 	uint64_t stack, block, reg, templ_rate;
 	int i, rate_pos;
 	char *rate = (char *) rate_phys;
 
-	if (!phb || phb->phb_type != phb_type_npu_v2_opencapi)
-		return OPAL_PARAMETER;
 	if (!opal_addr_valid(rate) || rate_sz != TL_RATE_BUF_SIZE)
 		return OPAL_PARAMETER;
 
@@ -2157,7 +2133,6 @@ static int64_t opal_npu_tl_set(uint64_t phb_id, uint32_t __unused bdfn,
 	OCAPIDBG(dev, "OTL configuration 1 register set to %llx\n", reg);
 	return OPAL_SUCCESS;
 }
-opal_call(OPAL_NPU_TL_SET, opal_npu_tl_set, 5);
 
 static void set_mem_bar(struct npu2_dev *dev, uint64_t base, uint64_t size)
 {
diff --git a/include/npu2.h b/include/npu2.h
index eb7c4558..f48a68b6 100644
--- a/include/npu2.h
+++ b/include/npu2.h
@@ -271,4 +271,11 @@ static inline int npu2_get_phb_index(unsigned int brick_index)
 	return NPU2_PHB_INDEX_BASE + brick_index;
 }
 
+int64_t npu2_opencapi_spa_setup(struct phb *phb, uint32_t __unused bdfn,
+				uint64_t addr, uint64_t PE_mask);
+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, uint64_t rate_phys, int rate_sz);
+
 #endif /* __NPU2_H */
-- 
2.31.1



More information about the Skiboot mailing list