summaryrefslogtreecommitdiff
path: root/gxp-notification.h
blob: 6f43b70bcc8c6088103b84446a5bfadd58e34dbc (plain)
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
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * GXP notification interface.
 *
 * Copyright (C) 2021 Google LLC
 */
#ifndef __GXP_NOTIFICATION_H__
#define __GXP_NOTIFICATION_H__

#include <linux/workqueue.h>

#include "gxp-internal.h"

enum gxp_notification_to_host_type {
	HOST_NOTIF_MAILBOX_RESPONSE = 0,
	HOST_NOTIF_DEBUG_DUMP_READY = 1,
	HOST_NOTIF_CORE_TELEMETRY_STATUS = 2,
	HOST_NOTIF_MAX
};

enum gxp_notification_to_core_type {
	CORE_NOTIF_MAILBOX_COMMAND = 0,
	CORE_NOTIF_GENERATE_DEBUG_DUMP = 1,
	CORE_NOTIF_TELEMETRY_STATUS = 2,
	CORE_NOTIF_SUSPEND_REQUEST = 3,
	CORE_NOTIF_MAX
};

/**
 * gxp_notification_register_handler() - Register a work_struct to be called
 *                                       when the specified @core sends a
 *                                       notification of the specified @type.
 * @gxp: The GXP device to register the handler for
 * @core: The core inside the GXP device to receive notifications from
 * @type: The `gxp_notification_to_host_type` of notification to handle
 * @handler: A callback to be invoked via `schedule_work()` when a notification
 *           of @type arrives.
 *
 * This function requires the specified @core has its firmware loaded and
 * initialized before this function is called.
 *
 * If the callback requires additional context, such as the core number or a
 * pointer to @gxp, the caller should allocate @handler as part of wrapper
 * struct containing any context, then obtain that wrapping struct with
 * `container_of()` inside the handler's callback.
 *
 * Return:
 * * 0       - Success
 * * -EINVAL - The specified @core or @type is not valid
 * * -ENODEV - The specified @core is not running firmware
 */
int gxp_notification_register_handler(struct gxp_dev *gxp, uint core,
				      enum gxp_notification_to_host_type type,
				      struct work_struct *handler);

/**
 * gxp_notification_unregister_handler() - Unregister the work for handling
 *                                         notifications of type @type from core
 *                                         @core.
 * @gxp: The GXP device to unregister the handler for
 * @core: The core inside the GXP device to remove the notifications handler for
 * @type: The `gxp_notification_to_host_type` of notification to unregister
 *
 * This function requires the specified @core has its firmware loaded and
 * initialized before this function is called.
 *
 * Return:
 * * 0       - Success
 * * -EINVAL - The specified @core or @type is not valid
 * * -ENODEV - The specified @core is not running firmware
 */
int gxp_notification_unregister_handler(
	struct gxp_dev *gxp, uint core,
	enum gxp_notification_to_host_type type);

/**
 * gxp_notification_send() - Send a notification of @type to @core.
 * @gxp: The GXP device to send a notification to
 * @core: The core inside the GXP device to route the notification to
 * @type:The `gxp_notification_to_core_type` of notification to send
 *
 * This function requires the specified @core has its firmware loaded and
 * initialized before this function is called.
 *
 * The caller must also hold gxp->vd_semaphore for reading, to ensure firmware
 * continues running until this call completes.
 *
 * Return:
 * * 0       - Success
 * * -EINVAL - The specified @core or @type is not valid
 * * -ENODEV - The specified @core is not running firmware
 */
int gxp_notification_send(struct gxp_dev *gxp, uint core,
			  enum gxp_notification_to_core_type type);

#endif /* __GXP_NOTIFICATION_H__ */