1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*
*/
#ifndef __HH_RM_DRV_H
#define __HH_RM_DRV_H
#include <linux/types.h>
#include <linux/notifier.h>
#include "hh_common.h"
/* Notification type Message IDs */
/* Memory APIs */
#define HH_RM_NOTIF_MEM_SHARED 0x51100011
#define HH_RM_NOTIF_MEM_RELEASED 0x51100012
#define HH_RM_NOTIF_MEM_ACCEPTED 0x51100013
#define HH_RM_MEM_TYPE_NORMAL 0
#define HH_RM_MEM_TYPE_IO 1
#define HH_RM_TRANS_TYPE_DONATE 0
#define HH_RM_TRANS_TYPE_LEND 1
#define HH_RM_TRANS_TYPE_SHARE 2
#define HH_RM_ACL_X BIT(0)
#define HH_RM_ACL_W BIT(1)
#define HH_RM_ACL_R BIT(2)
#define HH_RM_MEM_RELEASE_CLEAR BIT(0)
#define HH_RM_MEM_RECLAIM_CLEAR BIT(0)
#define HH_RM_MEM_ACCEPT_VALIDATE_SANITIZED BIT(0)
#define HH_RM_MEM_ACCEPT_VALIDATE_ACL_ATTRS BIT(1)
#define HH_RM_MEM_ACCEPT_VALIDATE_LABEL BIT(2)
#define HH_RM_MEM_ACCEPT_DONE BIT(7)
#define HH_RM_MEM_SHARE_SANITIZE BIT(0)
#define HH_RM_MEM_LEND_SANITIZE BIT(0)
#define HH_RM_MEM_NOTIFY_RECIPIENT_SHARED BIT(0)
#define HH_RM_MEM_NOTIFY_OWNER_RELEASED BIT(1)
#define HH_RM_MEM_NOTIFY_OWNER_ACCEPTED BIT(2)
struct hh_rm_mem_shared_acl_entry;
struct hh_rm_mem_shared_sgl_entry;
struct hh_rm_mem_shared_attr_entry;
struct hh_rm_notif_mem_shared_payload {
u32 mem_handle;
u8 mem_type;
u8 trans_type;
u8 flags;
u8 reserved1;
u16 owner_vmid;
u16 reserved2;
u32 label;
hh_label_t mem_info_tag;
/* TODO: How to arrange multiple variable length struct arrays? */
} __packed;
struct hh_rm_mem_shared_acl_entry {
u16 acl_vmid;
u8 acl_rights;
u8 reserved;
} __packed;
struct hh_rm_mem_shared_sgl_entry {
u32 sgl_size_low;
u32 sgl_size_high;
} __packed;
struct hh_rm_mem_shared_attr_entry {
u16 attributes;
u16 attributes_vmid;
} __packed;
struct hh_rm_notif_mem_released_payload {
u32 mem_handle;
u16 participant_vmid;
u16 reserved;
hh_label_t mem_info_tag;
} __packed;
struct hh_rm_notif_mem_accepted_payload {
u32 mem_handle;
u16 participant_vmid;
u16 reserved;
hh_label_t mem_info_tag;
} __packed;
struct hh_acl_entry {
u16 vmid;
u8 perms;
u8 reserved;
} __packed;
struct hh_sgl_entry {
u64 ipa_base;
u64 size;
} __packed;
struct hh_mem_attr_entry {
u16 attr;
u16 vmid;
} __packed;
struct hh_acl_desc {
u32 n_acl_entries;
struct hh_acl_entry acl_entries[];
} __packed;
struct hh_sgl_desc {
u16 n_sgl_entries;
u16 reserved;
struct hh_sgl_entry sgl_entries[];
} __packed;
struct hh_mem_attr_desc {
u16 n_mem_attr_entries;
u16 reserved;
struct hh_mem_attr_entry attr_entries[];
} __packed;
struct hh_notify_vmid_entry {
u16 vmid;
u16 reserved;
} __packed;
struct hh_notify_vmid_desc {
u16 n_vmid_entries;
u16 reserved;
struct hh_notify_vmid_entry vmid_entries[];
} __packed;
/* VM APIs */
#define HH_RM_NOTIF_VM_STATUS 0x56100008
#define HH_RM_NOTIF_VM_IRQ_LENT 0x56100011
#define HH_RM_NOTIF_VM_IRQ_RELEASED 0x56100012
#define HH_RM_NOTIF_VM_IRQ_ACCEPTED 0x56100013
#define HH_RM_VM_STATUS_NO_STATE 0
#define HH_RM_VM_STATUS_INIT 1
#define HH_RM_VM_STATUS_READY 2
#define HH_RM_VM_STATUS_RUNNING 3
#define HH_RM_VM_STATUS_PAUSED 4
#define HH_RM_VM_STATUS_SHUTDOWN 5
#define HH_RM_VM_STATUS_SHUTOFF 6
#define HH_RM_VM_STATUS_CRASHED 7
#define HH_RM_VM_STATUS_INIT_FAILED 8
#define HH_RM_OS_STATUS_NONE 0
#define HH_RM_OS_STATUS_EARLY_BOOT 1
#define HH_RM_OS_STATUS_BOOT 2
#define HH_RM_OS_STATUS_INIT 3
#define HH_RM_OS_STATUS_RUN 4
struct hh_rm_notif_vm_status_payload {
hh_vmid_t vmid;
u16 reserved;
u8 vm_status;
u8 os_status;
u16 app_status;
} __packed;
struct hh_rm_notif_vm_irq_lent_payload {
hh_vmid_t owner_vmid;
u16 reserved;
hh_virq_handle_t virq_handle;
hh_label_t virq_label;
} __packed;
struct hh_rm_notif_vm_irq_released_payload {
hh_virq_handle_t virq_handle;
} __packed;
struct hh_rm_notif_vm_irq_accepted_payload {
hh_virq_handle_t virq_handle;
} __packed;
/* VM Services */
#define HH_RM_NOTIF_VM_CONSOLE_CHARS 0X56100080
struct hh_rm_notif_vm_console_chars {
hh_vmid_t vmid;
u16 num_bytes;
u8 bytes[0];
} __packed;
struct notifier_block;
#if IS_ENABLED(CONFIG_HH_RM_DRV)
/* RM client registration APIs */
int hh_rm_register_notifier(struct notifier_block *nb);
int hh_rm_unregister_notifier(struct notifier_block *nb);
/* Client APIs for IRQ management */
int hh_rm_virq_to_irq(u32 virq, u32 type);
int hh_rm_irq_to_virq(int irq, u32 *virq);
int hh_rm_vm_irq_lend(hh_vmid_t vmid,
int virq,
int label,
hh_virq_handle_t *virq_handle);
int hh_rm_vm_irq_lend_notify(hh_vmid_t vmid, hh_virq_handle_t virq_handle);
int hh_rm_vm_irq_accept(hh_virq_handle_t virq_handle, int virq);
int hh_rm_vm_irq_accept_notify(hh_vmid_t vmid, hh_virq_handle_t virq_handle);
int hh_rm_vm_irq_release(hh_virq_handle_t virq_handle);
int hh_rm_vm_irq_release_notify(hh_vmid_t vmid, hh_virq_handle_t virq_handle);
int hh_rm_vm_irq_reclaim(hh_virq_handle_t virq_handle);
/* Client APIs for VM management */
int hh_rm_vm_alloc_vmid(enum hh_vm_names vm_name);
int hh_rm_get_vmid(enum hh_vm_names vm_name, hh_vmid_t *vmid);
int hh_rm_get_vm_name(hh_vmid_t vmid, enum hh_vm_names *vm_name);
int hh_rm_vm_start(int vmid);
/* Client APIs for VM query */
int hh_rm_populate_hyp_res(hh_vmid_t vmid);
/* Client APIs for VM Services */
int hh_rm_console_open(hh_vmid_t vmid);
int hh_rm_console_close(hh_vmid_t vmid);
int hh_rm_console_write(hh_vmid_t vmid, const char *buf, size_t size);
int hh_rm_console_flush(hh_vmid_t vmid);
int hh_rm_mem_qcom_lookup_sgl(u8 mem_type, hh_label_t label,
struct hh_acl_desc *acl_desc,
struct hh_sgl_desc *sgl_desc,
struct hh_mem_attr_desc *mem_attr_desc,
hh_memparcel_handle_t *handle);
int hh_rm_mem_release(hh_memparcel_handle_t handle, u8 flags);
int hh_rm_mem_reclaim(hh_memparcel_handle_t handle, u8 flags);
struct hh_sgl_desc *hh_rm_mem_accept(hh_memparcel_handle_t handle, u8 mem_type,
u8 trans_type, u8 flags, hh_label_t label,
struct hh_acl_desc *acl_desc,
struct hh_sgl_desc *sgl_desc,
struct hh_mem_attr_desc *mem_attr_desc,
u16 map_vmid);
int hh_rm_mem_share(u8 mem_type, u8 flags, hh_label_t label,
struct hh_acl_desc *acl_desc, struct hh_sgl_desc *sgl_desc,
struct hh_mem_attr_desc *mem_attr_desc,
hh_memparcel_handle_t *handle);
int hh_rm_mem_lend(u8 mem_type, u8 flags, hh_label_t label,
struct hh_acl_desc *acl_desc, struct hh_sgl_desc *sgl_desc,
struct hh_mem_attr_desc *mem_attr_desc,
hh_memparcel_handle_t *handle);
int hh_rm_mem_notify(hh_memparcel_handle_t handle, u8 flags,
hh_label_t mem_info_tag,
struct hh_notify_vmid_desc *vmid_desc);
#else
/* RM client register notifications APIs */
static inline int hh_rm_register_notifier(struct notifier_block *nb)
{
return -ENODEV;
}
static inline int hh_rm_unregister_notifier(struct notifier_block *nb)
{
return -ENODEV;
}
/* Client APIs for IRQ management */
static inline int hh_rm_virq_to_irq(u32 virq)
{
return -EINVAL;
}
static inline int hh_rm_vm_irq_lend(hh_vmid_t vmid,
int virq,
int label,
hh_virq_handle_t *virq_handle)
{
return -EINVAL;
}
static inline int hh_rm_irq_to_virq(int irq, u32 *virq)
{
return -EINVAL;
}
static inline int hh_rm_vm_irq_lend_notify(hh_vmid_t vmid,
hh_virq_handle_t virq_handle)
{
return -EINVAL;
}
static inline int hh_rm_vm_irq_accept(hh_virq_handle_t virq_handle, int virq)
{
return -EINVAL;
}
static inline int hh_rm_vm_irq_accept_notify(hh_vmid_t vmid,
hh_virq_handle_t virq_handle)
{
return -EINVAL;
}
static inline int hh_rm_vm_irq_release(hh_virq_handle_t virq_handle)
{
return -EINVAL;
}
static inline int hh_rm_vm_irq_release_notify(hh_vmid_t vmid,
hh_virq_handle_t virq_handle)
{
return -EINVAL;
}
static inline int hh_rm_vm_irq_reclaim(hh_virq_handle_t virq_handle)
{
return -EINVAL;
}
/* Client APIs for VM management */
static inline int hh_rm_vm_alloc_vmid(enum hh_vm_names vm_name)
{
return -EINVAL;
}
static inline int hh_rm_get_vmid(enum hh_vm_names vm_name, hh_vmid_t *vmid)
{
return -EINVAL;
}
static inline int hh_rm_get_vm_name(hh_vmid_t vmid, enum hh_vm_names *vm_name)
{
return -EINVAL;
}
static inline int hh_rm_vm_start(int vmid)
{
return -EINVAL;
}
/* Client APIs for VM query */
static inline int hh_rm_populate_hyp_res(hh_vmid_t vmid)
{
return -EINVAL;
}
/* Client APIs for VM Services */
static inline int hh_rm_console_open(hh_vmid_t vmid)
{
return -EINVAL;
}
static inline int hh_rm_console_close(hh_vmid_t vmid)
{
return -EINVAL;
}
static inline int hh_rm_console_write(hh_vmid_t vmid, const char *buf,
size_t size)
{
return -EINVAL;
}
static inline int hh_rm_console_flush(hh_vmid_t vmid)
{
return -EINVAL;
}
static inline int hh_rm_mem_qcom_lookup_sgl(u8 mem_type, hh_label_t label,
struct hh_acl_desc *acl_desc,
struct hh_sgl_desc *sgl_desc,
struct hh_mem_attr_desc *mem_attr_desc,
hh_memparcel_handle_t *handle)
{
return -EINVAL;
}
static inline int hh_rm_mem_release(hh_memparcel_handle_t handle, u8 flags)
{
return -EINVAL;
}
static inline int hh_rm_mem_reclaim(hh_memparcel_handle_t handle, u8 flags)
{
return -EINVAL;
}
static inline struct hh_sgl_desc *hh_rm_mem_accept(hh_memparcel_handle_t handle,
u8 mem_type,
u8 trans_type, u8 flags, hh_label_t label,
struct hh_acl_desc *acl_desc,
struct hh_sgl_desc *sgl_desc,
struct hh_mem_attr_desc *mem_attr_desc,
u16 map_vmid)
{
return ERR_PTR(-EINVAL);
}
static inline int hh_rm_mem_share(u8 mem_type, u8 flags, hh_label_t label,
struct hh_acl_desc *acl_desc, struct hh_sgl_desc *sgl_desc,
struct hh_mem_attr_desc *mem_attr_desc,
hh_memparcel_handle_t *handle)
{
return -EINVAL;
}
static inline int hh_rm_mem_lend(u8 mem_type, u8 flags, hh_label_t label,
struct hh_acl_desc *acl_desc, struct hh_sgl_desc *sgl_desc,
struct hh_mem_attr_desc *mem_attr_desc,
hh_memparcel_handle_t *handle)
{
return -EINVAL;
}
static inline int hh_rm_mem_notify(hh_memparcel_handle_t handle, u8 flags,
hh_label_t mem_info_tag,
struct hh_notify_vmid_desc *vmid_desc)
{
return -EINVAL;
}
#endif
#endif
|