summaryrefslogtreecommitdiff
path: root/gxp-mb-notification.c
blob: 31989843bfb92882904419278ed207f4a1d358b8 (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
// SPDX-License-Identifier: GPL-2.0
/*
 * GXP notification implementation on top of the mailbox driver.
 *
 * Copyright (C) 2021 Google LLC
 */

#include <linux/bitops.h>

#include "gxp-mailbox.h"
#include "gxp-mailbox-driver.h"
#include "gxp-notification.h"

int gxp_notification_register_handler(struct gxp_dev *gxp, uint core,
				      enum gxp_notification_to_host_type type,
				      struct work_struct *handler)
{
	struct gxp_mailbox *mailbox;

	if (core >= GXP_NUM_CORES || type >= HOST_NOTIF_MAX)
		return -EINVAL;

	mailbox = gxp->mailbox_mgr->mailboxes[core];
	if (!mailbox)
		return -ENODEV;

	return gxp_mailbox_register_interrupt_handler(mailbox, type, handler);
}

int gxp_notification_unregister_handler(struct gxp_dev *gxp, uint core,
					enum gxp_notification_to_host_type type)
{
	struct gxp_mailbox *mailbox;

	if (core >= GXP_NUM_CORES || type >= HOST_NOTIF_MAX)
		return -EINVAL;

	mailbox = gxp->mailbox_mgr->mailboxes[core];
	if (!mailbox)
		return-ENODEV;

	return gxp_mailbox_unregister_interrupt_handler(mailbox, type);
}

int gxp_notification_send(struct gxp_dev *gxp, uint core,
			  enum gxp_notification_to_core_type type)
{
	struct gxp_mailbox *mailbox;

	/*
	 * The mailbox submodule handles outgoing command interrupts directly
	 * so `CORE_NOTIF_MAILBOX_COMMAND` is not a valid input for this
	 * implementation.
	 */
	if (core >= GXP_NUM_CORES || type == CORE_NOTIF_MAILBOX_COMMAND ||
	    type >= GXP_MAILBOX_INT_BIT_COUNT || type >= CORE_NOTIF_MAX)
		return -EINVAL;

	mailbox = gxp->mailbox_mgr->mailboxes[core];
	if (!mailbox)
		return -ENODEV;

	gxp_mailbox_generate_device_interrupt(mailbox, BIT(type));

	return 0;
}