2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-05-16 23:41:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016, NVIDIA CORPORATION.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2016-06-17 15:43:56 +00:00
|
|
|
#include <mailbox-uclass.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2016-05-16 23:41:37 +00:00
|
|
|
#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,
|
2020-02-03 14:35:50 +00:00
|
|
|
.rfree = sandbox_mbox_free,
|
2016-05-16 23:41:37 +00:00
|
|
|
.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_alloc_size = sizeof(struct sandbox_mbox),
|
|
|
|
.ops = &sandbox_mbox_mbox_ops,
|
|
|
|
};
|