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 0B1E9425C9; Mon, 18 Sep 2023 04:49:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 81E37410FD; Mon, 18 Sep 2023 04:47:43 +0200 (CEST) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2110.outbound.protection.outlook.com [40.107.244.110]) by mails.dpdk.org (Postfix) with ESMTP id D016A40EF0 for ; Mon, 18 Sep 2023 04:47:37 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GB9kUQp6ddhW4bU80R7IlzVznPlywnGfXKxnX2LH2OvEwKCHZ2Ef07sCqTlg1cofNvXLhUEd+FkfkK3FwBz7jjwyvFWso+dZSyiRp6hlaEmGPiqn6ivtSZ/5tSARYbIlYp+lsH7vDweAxnOvWq+2kNguDu1Dm2Hz7NtW2mL4v0HgajAJ6C9fZcOv0ZrD7P+2rY/EPjCvEyohpr2ChtoTOCyhF7rg9xL35SNZlkcVRGzJfZ6IfCUEcGoJTG1rfB4KDo5UFjy/5joQ/nsGV09URO8Gubdqax/XKmaJiqbqcgEz4iek6wKK3fwJBESCPuQcKhBy/Y1+fzG0ih1sZt9MfA== 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=l7Qsyfqub5hXF4fwLc4a2XNdglaq/2V5GE13C+Wm86crmYZQ8YJsNpEyD15pIhXCJHiEpaSSy+0exerDZKnZ3lAWfxo4HNWNR7r3DKjCTtnVJXxGbJb6FYCyf8gLGopW5D1PL6I1Hd4EwftdPxSvcW3Z+rZVK7sVMHLIkdsngBo6sjRqe5tjChmyDFcz44Jd4N80XIF3cUbQsAv8PR7sbfJE+d9fgLVndacByxPOc/gj4Ov643FrZVKIeqaYs0JYAJeXETlKDF9WJWmT2Mkz+AuuaKANl2PG70kcHmxhrKckAadCz0/4T7N8Hkv4k5nWO9/2u510afVnufoP3jkS5g== 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=mwFBVC+G2ErjLmmTxMCY2hyDgZ808/GYAQ0v72rZ7LzSyL/LprCBJdqIrNy3lEqHLFUCc4Tw27fYzrVzkDdKYYK7KaozBzW2nLtjS4uVsIzBe0KxpB6ALWXbzWkP6Pnr41N5l1eeOfGzLT+HyFyxdCu4ZWgdxJ/xBqYncDU5Moo= 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 PH7PR13MB6435.namprd13.prod.outlook.com (2603:10b6:510:2ea::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Mon, 18 Sep 2023 02:47:36 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::7a1c:2887:348a:84bd]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::7a1c:2887:348a:84bd%6]) with mapi id 15.20.6792.026; Mon, 18 Sep 2023 02:47:36 +0000 From: Chaoyong He To: dev@dpdk.org Cc: Chaoyong He , =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCH v4 14/26] net/nfp: refact the rtsym module Date: Mon, 18 Sep 2023 10:46:00 +0800 Message-Id: <20230918024612.1600536-15-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230918024612.1600536-1-chaoyong.he@corigine.com> References: <20230915091551.1459606-1-chaoyong.he@corigine.com> <20230918024612.1600536-1-chaoyong.he@corigine.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SE2P216CA0016.KORP216.PROD.OUTLOOK.COM (2603:1096:101:114::20) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|PH7PR13MB6435:EE_ X-MS-Office365-Filtering-Correlation-Id: 7467605a-7ae9-4b41-eaf3-08dbb7f19d61 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mtSPadIZdvzK/9IMW0OKh0Y3neP11g5fK0fkYMUQgi9oaCr1HNCZVAtc/cpm7t83zGw917UAFyPNvO+MwmpAoducYKizkpgDldI6ImurvxeepNh4pfRh6260IYGvJqk/6W7ZC5FJb9MgA7e3YJa0A/QSYFCUUUXPPZYkjRX1Ip7JpufD639pE1CzGjmCZxQuR4wCFxizoAOSMsXHSkAYrEP81UQrvnb6iUi01pZWdrGxD7JHdKBu54O4yfJpvoOhmsCNefkNihNegzaDA3y/OgEiTaTfnhbJYseg1JcYuy4+Smi9aqcL062IirMPi3BPq5VZvrFNqohpFTD+8bmqD0G44cDsPjZczP+7gYco2vy1WRCg8tHyrN04sMlu/AjseXSPh2GGS3qOu3QaJL7W03MgYASqAA9Urt8TrfpuAE6ulIEKMZtPcQG6vHdljUxiRRfg8HZCvw2Hu2WO5lUxifM7lAGZzJqZcFlWRXsrYGENq0i2qd/2r4e65t+4A1/29GG4ODHj39PGHvRKiZI6d7fYI37viLKg/I9HgkqKzKUgdZc4GLS3moi7/Zs1QB8snFBgn7kl0EISTcbZUaX+tkWSNa/kjR2q0MHQIwdyxggdb25beOfyBL3m/yqAojfWSRzeiBZYqv3ijufK156sR0apWYbUMU3wIyZkG6JHnFM= 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)(39830400003)(136003)(346002)(366004)(376002)(396003)(1800799009)(451199024)(186009)(54906003)(66476007)(66946007)(66574015)(41300700001)(6916009)(316002)(8676002)(4326008)(8936002)(52116002)(6506007)(6486002)(6512007)(478600001)(6666004)(83380400001)(26005)(1076003)(2616005)(107886003)(86362001)(2906002)(30864003)(44832011)(38100700002)(38350700002)(5660300002)(36756003)(66556008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?OWRaU1ZpMmZFU0pkekVFZG1tMEVZRTNvU3psQU1DakRXZGhzWXpjTVp2WkhL?= =?utf-8?B?RnVGaFl0V1I1THdQc3hkWlFEMlFtRlQ2THJoY0pjZUVZekcxQ0xqMHVacGNx?= =?utf-8?B?Tm4xVG43YWJPcHBoZDdtbTQ4VGJmcWdhSGhUeXV1TDhFSktlSFk1VHJ2UmlZ?= =?utf-8?B?OCtRcXhPSVh6eWxSTTJYaXkwNkhhcDg1ZVNtcWtyVjMzL2VtQnBML0l1SEt6?= =?utf-8?B?ZGtzN3JoMmhsQXdlMlJpKzJ4ZXovdWkrR0pFMnNETUpKejliUGpycFJvUDVW?= =?utf-8?B?OFU4ZGN4N0Jqb1RzS0J4YllUTEZ2MDlnVDhZTDR6Z3FKeUtWS0M3bFpLZkE5?= =?utf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pPbUxXRUE4WUJqbmlRdzRQK3VGVU5zRHFT?= =?utf-8?B?TXc9PQ==?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7467605a-7ae9-4b41-eaf3-08dbb7f19d61 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 02:47:36.1198 (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: Cw9hS1TDiHgpnjiEK2LwE6+SVcfjcs5cvr1y2H8yFIZiv97/nN5ezsxPUpRJy3subZKUXJpSijAF2lgauM8JnNaZ4Tuwh91tqsDRm7E5m7k= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR13MB6435 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