xref: /rockchip-linux_mpp/osal/inc/mpp_singleton.h (revision 437bfbeb9567cca9cd9080e3f6954aa9d6a94f18)
1 /* SPDX-License-Identifier: Apache-2.0 OR MIT */
2 /*
3  * Copyright (c) 2024 Rockchip Electronics Co., Ltd.
4  */
5 
6 #ifndef __MPP_SINGLETON_H__
7 #define __MPP_SINGLETON_H__
8 
9 #include "rk_type.h"
10 
11 typedef enum MppSingletonId_e {
12     MPP_SGLN_BASE           = 0,
13     /* osal base module */
14     MPP_SGLN_OS_LOG         = MPP_SGLN_BASE,
15     MPP_SGLN_OS_MEM,
16     MPP_SGLN_TRACE,
17     MPP_SGLN_DMABUF,
18     MPP_SGLN_OS_ALLOCATOR,
19     MPP_SGLN_MEM_POOL,
20     /* hardware platform */
21     MPP_SGLN_SOC,
22     MPP_SGLN_PLATFORM,
23     MPP_SGLN_SERVER,
24     MPP_SGLN_CLUSTER,
25     /* software platform */
26     MPP_SGLN_RUNTIME,
27     /* kernel module (MUST before userspace module) */
28     MPP_SGLN_KOBJ,
29     MPP_SGLN_KMPP_IOC,
30     MPP_SGLN_KMPP_BUF_GRP_CFG,
31     MPP_SGLN_KMPP_BUF_GRP,
32     MPP_SGLN_KMPP_BUF_CFG,
33     MPP_SGLN_KMPP_BUFFER,
34     MPP_SGLN_KMPP_META,
35     MPP_SGLN_KMPP_FRAME,
36     MPP_SGLN_KMPP_PACKET,
37     MPP_SGLN_KMPP_VENC_CFG,
38     MPP_SGLN_KMPP_VENC,
39     MPP_SGLN_KMPP_VDEC_CFG,
40     MPP_SGLN_KMPP_VDEC,
41     /* userspace base module */
42     MPP_SGLN_BUFFER,
43     MPP_SGLN_META,
44     MPP_SGLN_FRAME,
45     MPP_SGLN_PACKET,
46     /* userspace system module */
47     MPP_SGLN_SYS_CFG,
48     MPP_SGLN_ENC_CFG,
49     MPP_SGLN_DEC_CFG,
50     MPP_SGLN_ENC_RC_API,
51 
52     /* max count for start init process */
53     MPP_SGLN_MAX_CNT,
54 } MppSingletonId;
55 
56 typedef struct MppSingletonInfo_t {
57     MppSingletonId  id;
58     const char      *name;
59     void            (*init)(void);
60     void            (*deinit)(void);
61 } MppSingletonInfo;
62 
63 #define SNGL_TO_STR(x)  #x
64 #define SNGL_TO_FUNC(x) __mpp_singleton_add_##x
65 /* warning: constructor priorities from 0 to 100 are reserved for the implementation */
66 #define SNGL_BASE_ID    101
67 #define MPP_SINGLETON(id, name, init, deinit) \
68     /* increase id from base id to avoid compiler warning */ \
69     __attribute__((constructor(SNGL_BASE_ID + id))) \
70     static void SNGL_TO_FUNC(name)(void) { \
71         MppSingletonInfo info = { \
72             id, \
73             SNGL_TO_STR(name), \
74             init, \
75             deinit, \
76         }; \
77         mpp_singleton_add(&info, __FUNCTION__); \
78     }
79 
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 
84 rk_s32 mpp_singleton_add(MppSingletonInfo *info, const char *caller);
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif /* __MPP_SINGLETON_H__ */
91