common/cnxk: support TIM device
[dpdk.git] / drivers / common / cnxk / roc_platform.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #include <rte_log.h>
6
7 #include "roc_api.h"
8
9 #define PLT_INIT_CB_MAX 8
10
11 static int plt_init_cb_num;
12 static roc_plt_init_cb_t plt_init_cbs[PLT_INIT_CB_MAX];
13
14 int
15 roc_plt_init_cb_register(roc_plt_init_cb_t cb)
16 {
17         if (plt_init_cb_num >= PLT_INIT_CB_MAX)
18                 return -ERANGE;
19
20         plt_init_cbs[plt_init_cb_num++] = cb;
21         return 0;
22 }
23
24 int
25 roc_plt_init(void)
26 {
27         const struct rte_memzone *mz;
28         int i, rc;
29
30         mz = rte_memzone_lookup(PLT_MODEL_MZ_NAME);
31         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
32                 if (mz == NULL) {
33                         mz = rte_memzone_reserve(PLT_MODEL_MZ_NAME,
34                                                  sizeof(struct roc_model),
35                                                  SOCKET_ID_ANY, 0);
36                         if (mz == NULL) {
37                                 plt_err("Failed to reserve mem for roc_model");
38                                 return -ENOMEM;
39                         }
40                         roc_model_init(mz->addr);
41                 }
42         } else {
43                 if (mz == NULL) {
44                         plt_err("Failed to lookup mem for roc_model");
45                         return -ENOMEM;
46                 }
47                 roc_model = mz->addr;
48         }
49
50         for (i = 0; i < plt_init_cb_num; i++) {
51                 rc = (*plt_init_cbs[i])();
52                 if (rc)
53                         return rc;
54         }
55
56         return 0;
57 }
58
59 RTE_LOG_REGISTER(cnxk_logtype_base, pmd.cnxk.base, NOTICE);
60 RTE_LOG_REGISTER(cnxk_logtype_mbox, pmd.cnxk.mbox, NOTICE);
61 RTE_LOG_REGISTER(cnxk_logtype_npa, pmd.mempool.cnxk, NOTICE);
62 RTE_LOG_REGISTER(cnxk_logtype_nix, pmd.net.cnxk, NOTICE);
63 RTE_LOG_REGISTER(cnxk_logtype_npc, pmd.net.cnxk.flow, NOTICE);
64 RTE_LOG_REGISTER(cnxk_logtype_sso, pmd.event.cnxk, NOTICE);
65 RTE_LOG_REGISTER(cnxk_logtype_tim, pmd.event.cnxk.timer, NOTICE);
66 RTE_LOG_REGISTER(cnxk_logtype_tm, pmd.net.cnxk.tm, NOTICE);