From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 350FD430EF; Thu, 24 Aug 2023 13:13:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 32C2A432A7; Thu, 24 Aug 2023 13:11:17 +0200 (CEST) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2119.outbound.protection.outlook.com [40.107.93.119]) by mails.dpdk.org (Postfix) with ESMTP id D9788432AD for ; Thu, 24 Aug 2023 13:11:14 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cen0XiRSctzqqgcmYr3YWGO5H8PJ+s7O6jVH+FIL2S/wOZa6wR9dOtejW9Sc3VajSmwqZ+v7kMXxLPUC8qu1XXXFccZQFg4jRJ+DKaQUsenen3n3jexHcgqzclPlEcbDnpN5hwhlnGdmFaLQsO9iRopK3ziLfW63Tjrxtqay1WdIIBnEhzWdlL5qeMHHk5IZ7Z6NUh2OGaVvCSLjc/JcqHQ1ykC3WcSfk1SpjVc2FsCLUBnx+1Cq0F7CivMXd23PXJH74IMamXEH5xOeiDAgKNheHOBL5kAZLuy7hutCfpQ6Gxnis4tMX2QZ1r+FLdH7s/h9jltdDuCJQI8bJZyMSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OdpEP/UyAGqz4oxHPFVDbYOKsAIafOJKB5CG4krDax0=; b=KB5JquPibr+A8Pe4RBMm+hhKvtrXrvPeueaf4MfR5+3wSoYBP64w4L6wwIQwrmYvn4ZAlFMY3Wv0I8Vxo2Lhm7lWPFtfnyQzJiQUR8W4eYmbGiTJvkCfml0KYQbY4JmGYDXy/2N1G/q93pPNY0yt/b/WKLS63+73v9CJdbSFh8Svzi4nZ9FMgzV8IWO5gvwMMStVbgx/fU1zZpe5JUeNk6xAjXTZ19rX5mrBZlDq5DYlzqk53R6FY72vhrfLLXNBKsjibwXK5vnKGPUxN733kzGTQXiikkCj+DefwWn/9O/KLObMKOuwXUOtZQ9zj2wnq/HPeG/2Bo1gCrYLo2VXBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OdpEP/UyAGqz4oxHPFVDbYOKsAIafOJKB5CG4krDax0=; b=Hgkd9DH2WGrqnJNcOqfpXK1YN6qQhAmotz1xko1TKusoT2Zr2nwdHKS1MjIzAIJbdTF5cNzqygzksx7JiUaJSma0EXhfoZghz411WaPNXa2cD8EyR42HC6dQkYzcNRmlVL86S4+1gTtfI0/cXoZbCHCmc9LeEHKsEYbUbiknu6E= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) by PH7PR13MB6116.namprd13.prod.outlook.com (2603:10b6:510:2b7::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.20; Thu, 24 Aug 2023 11:11:13 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::51fe:5846:af8b:bace]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::51fe:5846:af8b:bace%3]) with mapi id 15.20.6699.020; Thu, 24 Aug 2023 11:11:13 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, niklas.soderlund@corigine.com, Chaoyong He Subject: [PATCH 15/27] net/nfp: refact the rtsym module Date: Thu, 24 Aug 2023 19:09:44 +0800 Message-Id: <20230824110956.1943559-16-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230824110956.1943559-1-chaoyong.he@corigine.com> References: <20230824110956.1943559-1-chaoyong.he@corigine.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SJ0PR05CA0005.namprd05.prod.outlook.com (2603:10b6:a03:33b::10) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|PH7PR13MB6116:EE_ X-MS-Office365-Filtering-Correlation-Id: c0f4240a-d0b8-4cfd-8d68-08dba492d3aa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /CyzT+6fzOLCMyglNNjbIAm1GfZ7GpUnt8ldkyQAzW8mL4bTwOjqxOoHbD4wl+lYOoX46IoDyl1nminpm3xhaCS6u0yLvU+HG9Vg2KVvEo6WG7qNOM7rTL0cyPi6rq//6oT2X34Vs2zsgOtZdGcT8/8pMb2KQqwo5/pju2ePsZw5o1ywL9RWWd3XiV/1A8bgzJJtFcY8WtPqfR2QZLU6hABK0GR/tgVGRvmA1YRBcrxVV39ipleD19aOl46yniNegAbnOQo+uGw+hEby2g83R/vhpy6SLqgOvmCdMg/BW/le8t92/5LAiUzZQOeu1ICpCLz4KyVmqDMyNuH6N2v672tXtC8G8TYzjd4QiqFxqAwGR6SeAm06BjL0L6WSc6o/Hwu6oURM1CBLyymtidxyDwxMhCql6YrgdTdl/cd6CiqqGOEHXn0s8otxIpGawlkVkMuV2g2wXYxltwkzFhnMEvB7WSiZhsMGamJ6yg2XT1zkdpoa4yqxeUHetJQC8SIUXxOmYG4zA5U1J7dFJs5wIR9+zIIRYTp/BFtAKDVZQXOgB701AvBgzDEvyU61D5vmLG/8fmrq9J0YenaFIVXq7pjr5ImXybD9suyoLkrcgLriym2MOqIK3xolLCK8xhy4WIgj//9Vcf01FcBkjr9y3C08uU4Su/pule8OPUKBITsUbc7aPyUWqnarEr9MmLO0J7mSgYt9cLMx2SsgiOae/g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR13MB5545.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(366004)(39830400003)(346002)(396003)(136003)(376002)(1800799009)(186009)(451199024)(6506007)(26005)(1076003)(2616005)(107886003)(52116002)(12101799020)(6512007)(66574015)(6486002)(83380400001)(38100700002)(8676002)(8936002)(36756003)(316002)(4326008)(41300700001)(30864003)(2906002)(86362001)(5660300002)(44832011)(38350700002)(6666004)(6916009)(478600001)(66476007)(66946007)(66556008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?RkkwVnVXUW9yS1k4L0k3cGJtUG9LV1duZ0FJdDdwSkRxQUV0WHJMOHRKMVlL?= =?utf-8?B?R2tTRUtzcmo2U1dkMmU5WDJBK0xEclE3dlhkZEowakNVOUI5RWsxcmtqK29O?= =?utf-8?B?Q2JIUlE2UGFRb1FGd295eGNiNnVHQXhzNWlWZm9IeHUzc0VPRW5zUTltd3dy?= =?utf-8?B?NkRmZ2ozekJ3NFE0WkhSZTNqRXY5SmgrRVUwWXd5bTA4RlpFbmRaRnNDbUFM?= =?utf-8?B?U1pLVU1ZTGM2SmtoZ3FFVThlTjE3OHh5TnNQYUhOd0xLTHdDZVhORzUrWmpo?= =?utf-8?B?YjRBZENleU1UY1lZbUF5cm9jS2xuVmoyOGNlRnBxVWowdmNWaUFoMTdzZ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FCdG9HUHJ3bzVNdnhyaUFCVHVqUkZwQVc1?= =?utf-8?B?NkE9PQ==?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: c0f4240a-d0b8-4cfd-8d68-08dba492d3aa X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2023 11:11:12.9865 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PE5CHTm0gWvG1N360G5nE76xkbcuPF9Y7aTWOKiSL907cSiaAmFQiaLATLT2J7BcYFUg1s8+H3VmtxMJbN414rhQFc/Y+thbpaAIR1j6Sww= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR13MB6116 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add several read/write APIs and remove the unneeded header file include statements. Signed-off-by: Chaoyong He Reviewed-by: Niklas Söderlund --- drivers/net/nfp/nfpcore/nfp_rtsym.c | 305 +++++++++++++++++++++++++--- drivers/net/nfp/nfpcore/nfp_rtsym.h | 53 ++--- 2 files changed, 299 insertions(+), 59 deletions(-) diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.c b/drivers/net/nfp/nfpcore/nfp_rtsym.c index 37811ceaeb..2d4100dda2 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.c +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.c @@ -8,14 +8,25 @@ * Interface for accessing run-time symbol table */ -#include +#include "nfp_rtsym.h" + #include -#include "nfp_cpp.h" + #include "nfp_logs.h" #include "nfp_mip.h" -#include "nfp_rtsym.h" #include "nfp6000/nfp6000.h" +enum nfp_rtsym_type { + NFP_RTSYM_TYPE_NONE, + NFP_RTSYM_TYPE_OBJECT, + NFP_RTSYM_TYPE_FUNCTION, + NFP_RTSYM_TYPE_ABS, +}; + +#define NFP_RTSYM_TARGET_NONE 0 +#define NFP_RTSYM_TARGET_LMEM -1 +#define NFP_RTSYM_TARGET_EMU_CACHE -7 + /* These need to match the linker */ #define SYM_TGT_LMEM 0 #define SYM_TGT_EMU_CACHE 0x17 @@ -32,6 +43,30 @@ struct nfp_rtsym_entry { uint32_t size_lo; }; +/* + * Structure describing a run-time NFP symbol. + * + * The memory target of the symbol is generally the CPP target number and can be + * used directly by the nfp_cpp API calls. However, in some cases (i.e., for + * local memory or control store) the target is encoded using a negative number. + * + * When the target type can not be used to fully describe the location of a + * symbol the domain field is used to further specify the location (i.e., the + * specific ME or island number). + * + * For ME target resources, 'domain' is an MEID. + * For Island target resources, 'domain' is an island ID, with the one exception + * of "sram" symbols for backward compatibility, which are viewed as global. + */ +struct nfp_rtsym { + const char *name; /**< Symbol name */ + uint64_t addr; /**< Address in the domain/target's address space */ + uint64_t size; /**< Size (in bytes) of the symbol */ + enum nfp_rtsym_type type; /**< NFP_RTSYM_TYPE_* of the symbol */ + int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ + int domain; /**< CPP target domain */ +}; + struct nfp_rtsym_table { struct nfp_cpp *cpp; int num; @@ -80,21 +115,8 @@ nfp_rtsym_sw_entry_init(struct nfp_rtsym_table *cache, sw->domain = -1; } -struct nfp_rtsym_table * -nfp_rtsym_table_read(struct nfp_cpp *cpp) -{ - struct nfp_mip *mip; - struct nfp_rtsym_table *rtbl; - - mip = nfp_mip_open(cpp); - rtbl = __nfp_rtsym_table_read(cpp, mip); - nfp_mip_close(mip); - - return rtbl; -} - -struct nfp_rtsym_table * -__nfp_rtsym_table_read(struct nfp_cpp *cpp, +static struct nfp_rtsym_table * +nfp_rtsym_table_read_real(struct nfp_cpp *cpp, const struct nfp_mip *mip) { int n; @@ -162,6 +184,19 @@ __nfp_rtsym_table_read(struct nfp_cpp *cpp, return NULL; } +struct nfp_rtsym_table * +nfp_rtsym_table_read(struct nfp_cpp *cpp) +{ + struct nfp_mip *mip; + struct nfp_rtsym_table *rtbl; + + mip = nfp_mip_open(cpp); + rtbl = nfp_rtsym_table_read_real(cpp, mip); + nfp_mip_close(mip); + + return rtbl; +} + /** * Get the number of RTSYM descriptors * @@ -287,7 +322,59 @@ nfp_rtsym_to_dest(struct nfp_cpp *cpp, } static int -nfp_rtsym_readl(struct nfp_cpp *cpp, +nfp_rtsym_read_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + void *buf, + size_t len) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + size_t length = len; + uint64_t sym_size = nfp_rtsym_size(sym); + + if (offset > sym_size) { + PMD_DRV_LOG(ERR, "rtsym '%s' read out of bounds", sym->name); + return -ENXIO; + } + + if (length > sym_size - offset) + length = sym_size - offset; + + if (sym->type == NFP_RTSYM_TYPE_ABS) { + union { + uint64_t value_64; + uint8_t value_8[8]; + } tmp; + + tmp.value_64 = sym->addr; + memcpy(buf, &tmp.value_8[offset], length); + + return length; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_read(cpp, cpp_id, addr, buf, length); +} + +int +nfp_rtsym_read(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + void *buf, + size_t len) +{ + return nfp_rtsym_read_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, buf, len); +} + +static int +nfp_rtsym_readl_real(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, uint8_t action, uint8_t token, @@ -310,8 +397,17 @@ nfp_rtsym_readl(struct nfp_cpp *cpp, return nfp_cpp_readl(cpp, cpp_id, addr, value); } +int +nfp_rtsym_readl(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint32_t *value) +{ + return nfp_rtsym_readl_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + static int -nfp_rtsym_readq(struct nfp_cpp *cpp, +nfp_rtsym_readq_real(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, uint8_t action, uint8_t token, @@ -339,6 +435,121 @@ nfp_rtsym_readq(struct nfp_cpp *cpp, return nfp_cpp_readq(cpp, cpp_id, addr, value); } +int +nfp_rtsym_readq(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint64_t *value) +{ + return nfp_rtsym_readq_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + +static int +nfp_rtsym_write_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + void *buf, + size_t len) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + size_t length = len; + uint64_t sym_size = nfp_rtsym_size(sym); + + if (offset > sym_size) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + if (length > sym_size - offset) + length = sym_size - offset; + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_write(cpp, cpp_id, addr, buf, length); +} + +int +nfp_rtsym_write(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + void *buf, + size_t len) +{ + return nfp_rtsym_write_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, buf, len); +} + +static int +nfp_rtsym_writel_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + uint32_t value) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + + if (offset + 4 > nfp_rtsym_size(sym)) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_writel(cpp, cpp_id, addr, value); +} + +int +nfp_rtsym_writel(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint32_t value) +{ + return nfp_rtsym_writel_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + +static int +nfp_rtsym_writeq_real(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint8_t action, + uint8_t token, + uint64_t offset, + uint64_t value) +{ + int err; + uint64_t addr; + uint32_t cpp_id; + + if (offset + 8 > nfp_rtsym_size(sym)) { + PMD_DRV_LOG(ERR, "rtsym '%s' write out of bounds", sym->name); + return -ENXIO; + } + + err = nfp_rtsym_to_dest(cpp, sym, action, token, offset, &cpp_id, &addr); + if (err != 0) + return err; + + return nfp_cpp_writeq(cpp, cpp_id, addr, value); +} + +int +nfp_rtsym_writeq(struct nfp_cpp *cpp, + const struct nfp_rtsym *sym, + uint64_t offset, + uint64_t value) +{ + return nfp_rtsym_writeq_real(cpp, sym, NFP_CPP_ACTION_RW, 0, offset, value); +} + /** * Read a simple unsigned scalar value from symbol * @@ -374,11 +585,11 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, switch (sym->size) { case 4: - err = nfp_rtsym_readl(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val32); + err = nfp_rtsym_readl(rtbl->cpp, sym, 0, &val32); val = val32; break; case 8: - err = nfp_rtsym_readq(rtbl->cpp, sym, NFP_CPP_ACTION_RW, 0, 0, &val); + err = nfp_rtsym_readq(rtbl->cpp, sym, 0, &val); break; default: PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", @@ -387,8 +598,6 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, break; } - if (err) - err = -EIO; exit: if (error != NULL) *error = err; @@ -399,6 +608,54 @@ nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, return val; } +/** + * Write an unsigned scalar value to a symbol + * + * Lookup a symbol and write a value to it. Symbol can be 4 or 8 bytes in size. + * If 4 bytes then the lower 32-bits of 'value' are used. Value will be + * written as simple little-endian unsigned value. + * + * @param rtbl + * NFP RTSYM table + * @param name + * Symbol name + * @param value + * Value to write + * + * @return + * 0 on success or error code. + */ +int +nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, + const char *name, + uint64_t value) +{ + int err; + uint64_t sym_size; + const struct nfp_rtsym *sym; + + sym = nfp_rtsym_lookup(rtbl, name); + if (sym == NULL) + return -ENOENT; + + sym_size = nfp_rtsym_size(sym); + switch (sym_size) { + case 4: + err = nfp_rtsym_writel(rtbl->cpp, sym, 0, value); + break; + case 8: + err = nfp_rtsym_writeq(rtbl->cpp, sym, 0, value); + break; + default: + PMD_DRV_LOG(ERR, "rtsym '%s' unsupported size: %#lx", + name, sym_size); + err = -EINVAL; + break; + } + + return err; +} + uint8_t * nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, diff --git a/drivers/net/nfp/nfpcore/nfp_rtsym.h b/drivers/net/nfp/nfpcore/nfp_rtsym.h index fdde1eb75b..f79637ac50 100644 --- a/drivers/net/nfp/nfpcore/nfp_rtsym.h +++ b/drivers/net/nfp/nfpcore/nfp_rtsym.h @@ -6,46 +6,13 @@ #ifndef __NFP_RTSYM_H__ #define __NFP_RTSYM_H__ -#define NFP_RTSYM_TYPE_NONE 0 -#define NFP_RTSYM_TYPE_OBJECT 1 -#define NFP_RTSYM_TYPE_FUNCTION 2 -#define NFP_RTSYM_TYPE_ABS 3 - -#define NFP_RTSYM_TARGET_NONE 0 -#define NFP_RTSYM_TARGET_LMEM -1 -#define NFP_RTSYM_TARGET_EMU_CACHE -7 - -/* - * Structure describing a run-time NFP symbol. - * - * The memory target of the symbol is generally the CPP target number and can be - * used directly by the nfp_cpp API calls. However, in some cases (i.e., for - * local memory or control store) the target is encoded using a negative number. - * - * When the target type can not be used to fully describe the location of a - * symbol the domain field is used to further specify the location (i.e., the - * specific ME or island number). - * - * For ME target resources, 'domain' is an MEID. - * For Island target resources, 'domain' is an island ID, with the one exception - * of "sram" symbols for backward compatibility, which are viewed as global. - */ -struct nfp_rtsym { - const char *name; /**< Symbol name */ - uint64_t addr; /**< Address in the domain/target's address space */ - uint64_t size; /**< Size (in bytes) of the symbol */ - int type; /**< NFP_RTSYM_TYPE_* of the symbol */ - int target; /**< CPP target identifier, or NFP_RTSYM_TARGET_* */ - int domain; /**< CPP target domain */ -}; +#include "nfp_cpp.h" +struct nfp_rtsym; struct nfp_rtsym_table; struct nfp_rtsym_table *nfp_rtsym_table_read(struct nfp_cpp *cpp); -struct nfp_rtsym_table *__nfp_rtsym_table_read(struct nfp_cpp *cpp, - const struct nfp_mip *mip); - int nfp_rtsym_count(struct nfp_rtsym_table *rtbl); const struct nfp_rtsym *nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx); @@ -53,8 +20,24 @@ const struct nfp_rtsym *nfp_rtsym_get(struct nfp_rtsym_table *rtbl, int idx); const struct nfp_rtsym *nfp_rtsym_lookup(struct nfp_rtsym_table *rtbl, const char *name); +int nfp_rtsym_read(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, void *buf, size_t len); +int nfp_rtsym_readl(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint32_t *value); +int nfp_rtsym_readq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint64_t *value); + +int nfp_rtsym_write(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, void *buf, size_t len); +int nfp_rtsym_writel(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint32_t value); +int nfp_rtsym_writeq(struct nfp_cpp *cpp, const struct nfp_rtsym *sym, + uint64_t offset, uint64_t value); + uint64_t nfp_rtsym_read_le(struct nfp_rtsym_table *rtbl, const char *name, int *error); +int nfp_rtsym_write_le(struct nfp_rtsym_table *rtbl, const char *name, + uint64_t value); uint8_t *nfp_rtsym_map(struct nfp_rtsym_table *rtbl, const char *name, uint32_t min_size, struct nfp_cpp_area **area); -- 2.39.1