~funderscore blog cgit wiki get in touch
aboutsummaryrefslogtreecommitdiff
blob: 87d38de0cb612afaf971e47434298f4bb2448e28 (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
97
98
99
100
101
102
103
104
105
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2016, NVIDIA CORPORATION.
 */

#include <common.h>
#include <dm.h>
#include <log.h>
#include <mailbox-uclass.h>
#include <malloc.h>
#include <asm/io.h>
#include <asm/mbox.h>

#define SANDBOX_MBOX_CHANNELS 2

struct sandbox_mbox_chan {
	bool rx_msg_valid;
	uint32_t rx_msg;
};

struct sandbox_mbox {
	struct sandbox_mbox_chan chans[SANDBOX_MBOX_CHANNELS];
};

static int sandbox_mbox_request(struct mbox_chan *chan)
{
	debug("%s(chan=%p)\n", __func__, chan);

	if (chan->id >= SANDBOX_MBOX_CHANNELS)
		return -EINVAL;

	return 0;
}

static int sandbox_mbox_free(struct mbox_chan *chan)
{
	debug("%s(chan=%p)\n", __func__, chan);

	return 0;
}

static int sandbox_mbox_send(struct mbox_chan *chan, const void *data)
{
	struct sandbox_mbox *sbm = dev_get_priv(chan->dev);
	const uint32_t *pmsg = data;

	debug("%s(chan=%p, data=%p)\n", __func__, chan, data);

	sbm->chans[chan->id].rx_msg = *pmsg ^ SANDBOX_MBOX_PING_XOR;
	sbm->chans[chan->id].rx_msg_valid = true;

	return 0;
}

static int sandbox_mbox_recv(struct mbox_chan *chan, void *data)
{
	struct sandbox_mbox *sbm = dev_get_priv(chan->dev);
	uint32_t *pmsg = data;

	debug("%s(chan=%p, data=%p)\n", __func__, chan, data);

	if (!sbm->chans[chan->id].rx_msg_valid)
		return -ENODATA;

	*pmsg = sbm->chans[chan->id].rx_msg;
	sbm->chans[chan->id].rx_msg_valid = false;

	return 0;
}

static int sandbox_mbox_bind(struct udevice *dev)
{
	debug("%s(dev=%p)\n", __func__, dev);

	return 0;
}

static int sandbox_mbox_probe(struct udevice *dev)
{
	debug("%s(dev=%p)\n", __func__, dev);

	return 0;
}

static const struct udevice_id sandbox_mbox_ids[] = {
	{ .compatible = "sandbox,mbox" },
	{ }
};

struct mbox_ops sandbox_mbox_mbox_ops = {
	.request = sandbox_mbox_request,
	.rfree = sandbox_mbox_free,
	.send = sandbox_mbox_send,
	.recv = sandbox_mbox_recv,
};

U_BOOT_DRIVER(sandbox_mbox) = {
	.name = "sandbox_mbox",
	.id = UCLASS_MAILBOX,
	.of_match = sandbox_mbox_ids,
	.bind = sandbox_mbox_bind,
	.probe = sandbox_mbox_probe,
	.priv_auto	= sizeof(struct sandbox_mbox),
	.ops = &sandbox_mbox_mbox_ops,
};