1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _CHRE_API_H_
18 #define _CHRE_API_H_
19 
20 #include <stdarg.h>
21 #include <stdint.h>
22 
23 #include "util.h"
24 
25 /* if va_list is passed by value it must fit in 32-bit register */
26 #if !defined(SYSCALL_PARAMS_PASSED_AS_PTRS) || !defined(SYSCALL_VARARGS_PARAMS_PASSED_AS_PTRS)
27 C_STATIC_ASSERT(va_list_size, sizeof(va_list) == sizeof(uint32_t));
28 #endif
29 
30 /*
31  *  many syscalls rely on the property that uintptr_t can hold uint32_t without data loss
32  * This is enforced by static assertion below.
33  */
34 C_STATIC_ASSERT(uintptr_size, sizeof(uintptr_t) >= sizeof(uint32_t));
35 
36 //EXTERNAL API
37 //level 1 indices in the CHRE table
38 #define SYSCALL_CHRE_MAIN                 0
39 #define SYSCALL_CHRE_DRIVERS              1
40 #define SYSCALL_CHRE_LAST                 2 // always last. holes are allowed, but not immediately before this
41 
42 //level 2 indices in the CHRE.main table
43 #define SYSCALL_CHRE_MAIN_API             0
44 #define SYSCALL_CHRE_MAIN_EVENT           1
45 #define SYSCALL_CHRE_MAIN_LAST            2 // always last. holes are allowed, but not immediately before this
46 
47 //level 3 indices in the CHRE.main.api table
48 #define SYSCALL_CHRE_MAIN_API_GET_APP_ID             0 // (void) -> uint64_t
49 #define SYSCALL_CHRE_MAIN_API_GET_INST_ID            1 // (void) -> uint32_t
50 #define SYSCALL_CHRE_MAIN_API_LOG_OLD                2 // (enum LogLevel, const char *, uintptr_t) -> void
51 #define SYSCALL_CHRE_MAIN_API_GET_TIME               3 // (void) -> uint64_t
52 #define SYSCALL_CHRE_MAIN_API_TIMER_SET              4 // (uint64_t, const void *, bool) -> uint32_t
53 #define SYSCALL_CHRE_MAIN_API_TIMER_CANCEL           5 // (uint32_t) -> bool
54 #define SYSCALL_CHRE_MAIN_API_ABORT                  6 // (uint32_t) -> void
55 #define SYSCALL_CHRE_MAIN_API_HEAP_ALLOC             7 // (uint32_t) -> void *
56 #define SYSCALL_CHRE_MAIN_API_HEAP_FREE              8 // (void *) -> void
57 #define SYSCALL_CHRE_MAIN_API_SEND_EVENT             9 // (uint32_t, void *, chreEventCompleteFunction*, uint32_t) -> bool
58 #define SYSCALL_CHRE_MAIN_API_SEND_MSG              10 // (void *, uint32_t, uint32_t, chreMessageFreeFunction *) -> bool
59 #define SYSCALL_CHRE_MAIN_API_SENSOR_FIND_DEFAULT   11 //
60 #define SYSCALL_CHRE_MAIN_API_SENSOR_GET_INFO_OLD   12 //
61 #define SYSCALL_CHRE_MAIN_API_SENSOR_GET_STATUS     13 //
62 #define SYSCALL_CHRE_MAIN_API_SENSOR_CONFIG         14 //
63 #define SYSCALL_CHRE_MAIN_API_GET_OS_API_VERSION    15 //
64 #define SYSCALL_CHRE_MAIN_API_GET_OS_VERSION        16 //
65 #define SYSCALL_CHRE_MAIN_API_GET_PLATFORM_ID       17 //
66 #define SYSCALL_CHRE_MAIN_API_LOG                   18 // (enum LogLevel, const char *, uintptr_t) -> void
67 #define SYSCALL_CHRE_MAIN_API_SENSOR_GET_INFO       19 //
68 #define SYSCALL_CHRE_MAIN_API_GET_HOST_TIME_OFFSET  20 // (void) -> int64_t
69 #define SYSCALL_CHRE_MAIN_API_LAST                  21 // always last. holes are allowed, but not immediately before this
70 
71 //level 3 indices in the CHRE.main.event table
72 #define SYSCALL_CHRE_MAIN_EVENT_SEND_EVENT           0 // (uint32_t, void *, chreEventCompleteFunction*, uint32_t) -> bool
73 #define SYSCALL_CHRE_MAIN_EVENT_SEND_MSG             1 // (void *, size_t, uint32_t, uint16_t, chreMessageFreeFunction *) -> bool
74 #define SYSCALL_CHRE_MAIN_EVENT_INFO_BY_APP_ID       2 // (uint64_t, struct chreNanoappInfo *) -> bool
75 #define SYSCALL_CHRE_MAIN_EVENT_INFO_BY_INST_ID      3 // (uint32_t, struct chreNanoappInfo *) -> bool
76 #define SYSCALL_CHRE_MAIN_EVENT_CFG_INFO             4 // (bool) -> void
77 #define SYSCALL_CHRE_MAIN_EVENT_HOST_SLEEP           5 // (bool) -> void
78 #define SYSCALL_CHRE_MAIN_EVENT_IS_HOST_AWAKE        6 // (void) -> bool
79 #define SYSCALL_CHRE_MAIN_EVENT_LAST                 7 // always last. holes are allowed, but not immediately before this
80 
81 //level 2 indices in the CHRE.drivers table
82 #define SYSCALL_CHRE_DRV_GNSS             0
83 #define SYSCALL_CHRE_DRV_WIFI             1
84 #define SYSCALL_CHRE_DRV_WWAN             2
85 #define SYSCALL_CHRE_DRV_AUDIO            3
86 #define SYSCALL_CHRE_DRV_LAST             4 // always last. holes are allowed, but not immediately before this
87 
88 //level 3 indices in the CHRE.drivers.gnss table
89 #define SYSCALL_CHRE_DRV_GNSS_GET_CAP               0 // (void) -> uint32_t
90 #define SYSCALL_CHRE_DRV_GNSS_LOC_START_ASYNC       1 // (uint32_t, uint32_t const void *) -> bool
91 #define SYSCALL_CHRE_DRV_GNSS_LOC_STOP_ASYNC        2 // (const void *) -> bool
92 #define SYSCALL_CHRE_DRV_GNSS_MEAS_START_ASYNC      3 // (uint32_t, const void *) -> bool
93 #define SYSCALL_CHRE_DRV_GNSS_MEAS_STOP_ASYNC       4 // (const void *) -> bool
94 #define SYSCALL_CHRE_DRV_GNSS_CONF_PASV_LOC_LIS     5 // (bool) -> bool
95 #define SYSCALL_CHRE_DRV_GNSS_LAST                  6 // always last. holes are allowed, but not immediately before this
96 
97 //level 3 indices in the CHRE.drivers.wifi table
98 #define SYSCALL_CHRE_DRV_WIFI_GET_CAP               0 // (void) -> uint32_t
99 #define SYSCALL_CHRE_DRV_WIFI_CONF_SCAN_MON_ASYNC   1 // (bool, const void *) -> bool
100 #define SYSCALL_CHRE_DRV_WIFI_REQ_SCAN_ASYNC        2 // (const struct chreWifiScanParams *, const void *) -> bool
101 #define SYSCALL_CHRE_DRV_WIFI_LAST                  3 // always last. holes are allowed, but not immediately before this
102 
103 //level 3 indices in the CHRE.drivers.wwan table
104 #define SYSCALL_CHRE_DRV_WWAN_GET_CAP               0 // (void) -> uint32_t
105 #define SYSCALL_CHRE_DRV_WWAN_GET_CELL_INFO_ASYNC   1 // (const void *) -> bool
106 #define SYSCALL_CHRE_DRV_WWAN_LAST                  2 // always last. holes are allowed, but not immediately before this
107 
108 //level 3 indicies in the CHRE.drivers.audio table
109 #define SYSCALL_CHRE_DRV_AUDIO_GET_SRC              0 // (uint32_t, struct chreAudioSource *) -> bool
110 #define SYSCALL_CHRE_DRV_AUDIO_CONF_SRC             1 // (uint32_t, bool, uint64_t, uint64_t) -> bool
111 #define SYSCALL_CHRE_DRV_AUDIO_GET_STATUS           2 // (uint32_t, struct chreAudioSourceStatus *) -> bool
112 #define SYSCALL_CHRE_DRV_AUDIO_LAST                 3 // always last. holes are allowed, but not immediately before this
113 
114 //called by os entry point to export the api
115 void osChreApiExport(void);
116 // release CHRE event and optionally call completion callback
117 void osChreFreeEvent(uint32_t tid, void (*free_info)(uint16_t, void *), uint32_t evtType, void * evtData);
118 
119 #endif
120