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 63A06425A3; Fri, 15 Sep 2023 11:18:23 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6AD6C42C24; Fri, 15 Sep 2023 11:16:48 +0200 (CEST) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2133.outbound.protection.outlook.com [40.107.237.133]) by mails.dpdk.org (Postfix) with ESMTP id 74E8E4281D for ; Fri, 15 Sep 2023 11:16:46 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z1pA/F+FY1kNYy3U/MN0/kPqIJsTvqn9g6lIcvx0VsQtj1+dh0bvKz9dnJs/SbRPq79Ow33RSvAbMvxxQMkb486sCRD2sHGb57X6acokqiMb0zeT1QbrPKLOEYfa4iZwMc6gtRqt9ouNz2jWioqcAKoxkcQhRyNicF67XJPgkPXncD25LnheFrbLM0zO7LxTtIfk93RiOQH1iYPRtEf4cqlv/OQPh6nb9UscAVtYI4vdsWzgtSSjsowSjDiHP0DKfgyACBx/sc3r4NkFhWGgBBEr3UGlmMzD2/gOElXAxEr2UoW07bpKTal1441WSGX5tY+Rvls/sM892tQFF0yabA== 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=Ht8KnFdIKTQiuEtWLIErmJpXuOtlTnyTnYS4VcwF3yfYzTK3ueO/gU07UF4JrCpuCf28J0pvUUJ8HW7/ksOtOsYGlr93IOR+nTdoJyG1VjiWnqWw5vG8OE7E3A+Z8ohpmsrCTfLS8sEV+gN/CPOEntdPN6S6DaxSJfo4vAZokIKy6z2pbiWea6wHE+i/MGzL9g/sJGrB4EFAQYK6ZYM02PVIytqFil58moEoeHLF3v13j+JUpaNr7V5YEnsh36BccoBKbh4w/w9idTfhB2eGBXW9n/Vkb5HN7U4OED3tdoFgF7cTnhAUwBFRXPNXKXfhBJ/KYFBTMlRuFls8BAXlsw== 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=W3jcK4Ps7Yq5/1W02pFm2CSjOs6GlkWW7XnAKC26iwl/PK7gWLPI8HSTuEXDQ3EIv5Dj86dQ6Hi6jqHLvTmFcp7PbMeujjYhuccWEFEPwIhjVGDbQK/J00ewE2UhA60QX4ijiG2oGLzMLeTjPmia3kGa9INpBc67HiUrGePc9w4= 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 CO1PR13MB4773.namprd13.prod.outlook.com (2603:10b6:303:fb::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.21; Fri, 15 Sep 2023 09:16:44 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::c05c:6915:1628:70c4]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::c05c:6915:1628:70c4%7]) with mapi id 15.20.6768.029; Fri, 15 Sep 2023 09:16:44 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Chaoyong He , =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCH v3 15/27] net/nfp: refact the rtsym module Date: Fri, 15 Sep 2023 17:15:39 +0800 Message-Id: <20230915091551.1459606-16-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230915091551.1459606-1-chaoyong.he@corigine.com> References: <20230830021457.2064750-1-chaoyong.he@corigine.com> <20230915091551.1459606-1-chaoyong.he@corigine.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: PH7PR10CA0017.namprd10.prod.outlook.com (2603:10b6:510:23d::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_|CO1PR13MB4773:EE_ X-MS-Office365-Filtering-Correlation-Id: 5a7e8689-3467-4d80-6973-08dbb5cc7b0b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5mEvGOJNXVcZiMGI/8yavfcYpP0cp2rb1d1E0h1tQeSl9VvQ9HVfemOWA7LMmVVsspzwT4fCjucxHvTW9q8fM0qH4RqZ/Bu+8/7mW3W+1l6Bp8/0ab61fnc/5/XALBtjsPoRFjpQ26Ced+HJiRK4UKcOum0fOlK7WTDAyl7E/H6nOdFP6icQmtIoQz9cmWau7t/IeEtVBfAG1P8Bxc2v9guFfsePmHW0b6N3hQ1s9IlfTLLCw/n3q3qirjod98f36NjBBa41INXzl/NrlW9ZVBJUeJljkcIY/l3qAh+2mMRrhqQGkgsaHBfvFeGerFl8BeRYJdaa2PR5n1YlQNqTc0LAW1NtB+uhnCTLz/DY0j8cngTXU4N+JSYvZGbPa94NR2fjQDfYNYQwi/X63TOqLpZIlVGU/ErBSVTBlCDUQ3RKCPolJcz5PZbJtHdZutIkmLa44YxNE1WAwW3vmlKP43FoPs1ufctSYwvKeihJFEKhwkZTto8Y6F+d1kEUlL2VaBLKShE9xC5FLJwU2Faz2gsb9jgCSR47K4ziVnXOyBbDTE+apmOMjoBxTuCa7jwqSggWKehoFjEuOFC22QSQeYnRSSRbMMdlXIXAzwTeg+34wT36o1aJjZ5/WASVJcyV4sp89+t77DTT4HqprwgAb4osVvVBNQHsNZO1vvGx7uQ= 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)(39840400004)(346002)(136003)(376002)(396003)(366004)(451199024)(186009)(1800799009)(6512007)(107886003)(1076003)(2616005)(6666004)(52116002)(6506007)(6486002)(66946007)(26005)(316002)(41300700001)(66476007)(66556008)(6916009)(54906003)(5660300002)(4326008)(8676002)(38350700002)(8936002)(38100700002)(478600001)(66574015)(83380400001)(36756003)(44832011)(30864003)(86362001)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bzE2MzBJOHA1TUovQVVaS2UxcXdCUHVSUGU2b3NUMUZWODdVNkRWQ3kyc2Jj?= =?utf-8?B?TjA5cXo5TktDWUxHWEJiSDZXM2Z5dlNOcEdycU16SldBWXNDWFRuNXcxaHcr?= =?utf-8?B?eUF5R3RwMWxLOGU0QmRoWmdvenFvWWo5MUgxcFErZlZQczk5SUpCQkZMdlkz?= =?utf-8?B?MVZDWjdURnIycEhTNmtZckFFT21XSmN1VVVBbXJqakFSVzR5dnlhckU3cDAv?= =?utf-8?B?NnBrd0Y4WG1yMXRTcVJzRWhzVXl3Z0o3UGcva0RidHZiT2ltdUtjcXJiUmo2?= =?utf-8?B?c29wTFNDdStYUnBLeUpvZUd0ZVdKa3dPU1FwYkVES0VoZ1dhMVNFQXppTlJU?= =?utf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3REMVk0UEJVMGl4b2NxckowNVh2U1Arb1JW?= =?utf-8?B?RGc9PQ==?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a7e8689-3467-4d80-6973-08dbb5cc7b0b X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2023 09:16:44.8291 (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: 7QIM5dStcXR++Fyc7PkbIibjDbIPant0N/9CJqOheeOWqQpQ2ptKkaKBJkoSUnXJq1PbXuJzevFCLUl4IDCcqaRuSNUwn44sFCnXc15VnXE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR13MB4773 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