2 * Copyright (c) 2018 VMware, Inc. All Rights Reserved.
4 * SPDX-License-Identifier: (BSD-2-Clause OR GPL-2.0)
9 /* This file defines helper functions */
11 #ifndef _VMCI_KERNEL_IF_H_
12 #define _VMCI_KERNEL_IF_H_
14 #include <sys/param.h>
16 #include <sys/mutex.h>
17 #include <sys/queue.h>
20 #include "vmci_defs.h"
22 #define VMCI_MEMORY_NORMAL 0x0
23 #define VMCI_MEMORY_ATOMIC 0x1
25 #define vmci_list(_l) LIST_HEAD(, _l)
26 #define vmci_list_item(_l) LIST_ENTRY(_l)
27 #define vmci_list_init(_l) LIST_INIT(_l)
28 #define vmci_list_empty(_l) LIST_EMPTY(_l)
29 #define vmci_list_first(_l) LIST_FIRST(_l)
30 #define vmci_list_next(e, f) LIST_NEXT(e, f)
31 #define vmci_list_insert(_l, _e, n) LIST_INSERT_HEAD(_l, _e, n)
32 #define vmci_list_remove(_e, n) LIST_REMOVE(_e, n)
33 #define vmci_list_scan(v, _l, n) LIST_FOREACH(v, _l, n)
34 #define vmci_list_scan_safe(_e, _l, n, t) \
35 LIST_FOREACH_SAFE(_e, _l, n, t)
36 #define vmci_list_swap(_l1, _l2, t, f) LIST_SWAP(_l1, _l2, t, f)
38 typedef unsigned short int vmci_io_port;
39 typedef int vmci_io_handle;
41 void vmci_read_port_bytes(vmci_io_handle handle, vmci_io_port port,
42 uint8_t *buffer, size_t buffer_length);
44 typedef struct mtx vmci_lock;
45 int vmci_init_lock(vmci_lock *lock, char *name);
46 void vmci_cleanup_lock(vmci_lock *lock);
47 void vmci_grab_lock(vmci_lock *lock);
48 void vmci_release_lock(vmci_lock *lock);
49 void vmci_grab_lock_bh(vmci_lock *lock);
50 void vmci_release_lock_bh(vmci_lock *lock);
52 void *vmci_alloc_kernel_mem(size_t size, int flags);
53 void vmci_free_kernel_mem(void *ptr, size_t size);
55 typedef struct sema vmci_event;
56 typedef int (*vmci_event_release_cb)(void *client_data);
57 void vmci_create_event(vmci_event *event);
58 void vmci_destroy_event(vmci_event *event);
59 void vmci_signal_event(vmci_event *event);
60 void vmci_wait_on_event(vmci_event *event, vmci_event_release_cb release_cb,
62 bool vmci_wait_on_event_interruptible(vmci_event *event,
63 vmci_event_release_cb release_cb, void *client_data);
65 typedef void (vmci_work_fn)(void *data);
66 bool vmci_can_schedule_delayed_work(void);
67 int vmci_schedule_delayed_work(vmci_work_fn *work_fn, void *data);
68 void vmci_delayed_work_cb(void *context, int data);
70 typedef struct mtx vmci_mutex;
71 int vmci_mutex_init(vmci_mutex *mutex, char *name);
72 void vmci_mutex_destroy(vmci_mutex *mutex);
73 void vmci_mutex_acquire(vmci_mutex *mutex);
74 void vmci_mutex_release(vmci_mutex *mutex);
76 void *vmci_alloc_queue(uint64_t size, uint32_t flags);
77 void vmci_free_queue(void *q, uint64_t size);
79 typedef PPN *vmci_ppn_list;
81 uint64_t num_produce_pages;
82 uint64_t num_consume_pages;
83 vmci_ppn_list produce_ppns;
84 vmci_ppn_list consume_ppns;
88 int vmci_alloc_ppn_set(void *produce_q, uint64_t num_produce_pages,
89 void *consume_q, uint64_t num_consume_pages,
90 struct ppn_set *ppn_set);
91 void vmci_free_ppn_set(struct ppn_set *ppn_set);
92 int vmci_populate_ppn_list(uint8_t *call_buf, const struct ppn_set *ppnset);
94 #endif /* !_VMCI_KERNEL_IF_H_ */