1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HDF_AUDIO_PNP_SERVER_H
17 #define HDF_AUDIO_PNP_SERVER_H
18 
19 #include "v4_0/audio_types.h"
20 #include "hdf_types.h"
21 
22 #define FFRT_TASK_ATTR_STORAGE_SIZE 128
23 #define FFRT_AUTO_MANAGED_FUNCTION_STORAGE_SIZE (64 + sizeof(FfrtFunctionHeader))
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 typedef struct {
30     uint32_t storage[(FFRT_TASK_ATTR_STORAGE_SIZE + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
31 } FfrtTaskAttr;
32 
33 typedef void(*FfrtFunctionT)(void*);
34 
35 typedef enum {
36     FFRT_FUNCTION_KIND_GENERAL,
37     FFRT_FUNCTION_KIND_QUEUE,
38 #ifdef FFRT_IO_TASK_SCHEDULER
39     FFRT_FUNCTION_KIND_IO,
40 #endif
41 } FfrtFunctionKind;
42 
43 typedef enum {
44     FFRT_QOS_INHERIT = -1,
45     FFRT_QOS_BACKGROUND,
46     FFRT_QOS_UTILITY,
47     FFRT_QOS_DEFAULT,
48     FFRT_QOS_USER_INITIATED,
49 } FfrtQosDefault;
50 
51 typedef enum {
52     FFRT_DEPENDENCE_DATA,
53     FFRT_DEPENDENCE_TASK,
54 } FfrtDependenceType;
55 
56 typedef struct {
57     FfrtDependenceType type;
58     const void *ptr;
59 } FfrtDependence;
60 
61 typedef struct {
62     uint32_t len;
63     const FfrtDependence *items;
64 } FfrtDeps;
65 
66 typedef struct {
67     FfrtFunctionT exec;
68     FfrtFunctionT destroy;
69     uint64_t reserve[2];
70 } FfrtFunctionHeader;
71 
72 typedef struct {
73     FfrtFunctionHeader header;
74     FfrtFunctionT func;
75     FfrtFunctionT afterFunc;
76     void *arg;
77 } FfrtFunction;
78 
79 typedef void*(*FfrtAllocBase)(FfrtFunctionKind);
80 typedef int(*FfrtTaskAttrInit)(FfrtTaskAttr*);
81 typedef void(*FfrtTaskAttrSetQos)(FfrtTaskAttr*, int);
82 typedef void(*FfrtTaskAttrSetName)(FfrtTaskAttr*, const char*);
83 typedef void(*FfrtSubmitBase)(
84     FfrtFunctionHeader*, const FfrtDeps*, const FfrtDeps*, const FfrtTaskAttr*);
85 FfrtTaskAttrInit FfrtAttrInitFunc(void);
86 FfrtTaskAttrSetQos FfrtAttrSetQosFunc(void);
87 FfrtTaskAttrSetName FfrtAttrSetNameFunc(void);
88 FfrtSubmitBase FfrtSubmitBaseFunc(void);
89 
90 /* statusInfo is update new info */
91 int32_t AudioPnpUpdateInfo(const char *statusInfo);
92 int32_t AudioPnpUpdateInfoOnly(struct AudioEvent audioEvent);
93 int32_t AudioUhdfUnloadDriver(const char *driverName);
94 int32_t AudioUhdfLoadDriver(const char *driverName);
95 FfrtFunctionHeader* FfrtCreateFunctionWrapper(const FfrtFunctionT func,
96     const FfrtFunctionT afterFunc, void* arg);
97 #ifdef __cplusplus
98 }
99 #endif
100 #endif
101