1 /* SPDX-License-Identifier: (GPL-2.0 OR CDDL-1.0) */
2 /* Copyright (C) 2006-2016 Oracle Corporation */
4 #ifndef __VBOX_UTILS_H__
5 #define __VBOX_UTILS_H__
7 #include <linux/printk.h>
8 #include <linux/vbox_vmmdev_types.h>
13 * vboxguest logging functions, these log both to the backdoor and call
14 * the equivalent kernel pr_foo function.
16 __printf(1, 2) void vbg_info(const char *fmt
, ...);
17 __printf(1, 2) void vbg_warn(const char *fmt
, ...);
18 __printf(1, 2) void vbg_err(const char *fmt
, ...);
20 /* Only use backdoor logging for non-dynamic debug builds */
21 #if defined(DEBUG) && !defined(CONFIG_DYNAMIC_DEBUG)
22 __printf(1, 2) void vbg_debug(const char *fmt
, ...);
24 #define vbg_debug pr_debug
28 * Allocate memory for generic request and initialize the request header.
30 * Return: the allocated memory
31 * @len: Size of memory block required for the request.
32 * @req_type: The generic request type.
34 void *vbg_req_alloc(size_t len
, enum vmmdev_request_type req_type
);
37 * Perform a generic request.
39 * Return: VBox status code
40 * @gdev: The Guest extension device.
41 * @req: Pointer to the request structure.
43 int vbg_req_perform(struct vbg_dev
*gdev
, void *req
);
45 int vbg_hgcm_connect(struct vbg_dev
*gdev
,
46 struct vmmdev_hgcm_service_location
*loc
,
47 u32
*client_id
, int *vbox_status
);
49 int vbg_hgcm_disconnect(struct vbg_dev
*gdev
, u32 client_id
, int *vbox_status
);
51 int vbg_hgcm_call(struct vbg_dev
*gdev
, u32 client_id
, u32 function
,
52 u32 timeout_ms
, struct vmmdev_hgcm_function_parameter
*parms
,
53 u32 parm_count
, int *vbox_status
);
56 struct vbg_dev
*gdev
, u32 client_id
, u32 function
, u32 timeout_ms
,
57 struct vmmdev_hgcm_function_parameter32
*parm32
, u32 parm_count
,
61 * Convert a VirtualBox status code to a standard Linux kernel return value.
62 * Return: 0 or negative errno value.
63 * @rc: VirtualBox status code to convert.
65 int vbg_status_code_to_errno(int rc
);
68 * Helper for the vboxsf driver to get a reference to the guest device.
69 * Return: a pointer to the gdev; or a ERR_PTR value on error.
71 struct vbg_dev
*vbg_get_gdev(void);
74 * Helper for the vboxsf driver to put a guest device reference.
75 * @gdev: Reference returned by vbg_get_gdev to put.
77 void vbg_put_gdev(struct vbg_dev
*gdev
);