Skip to content

Commit 1bea99c

Browse files
committed
[DM/FEATURE] Support hardware mailbox
Communication in AMP. Signed-off-by: GuEe-GUI <[email protected]>
1 parent fed7c9a commit 1bea99c

File tree

6 files changed

+457
-0
lines changed

6 files changed

+457
-0
lines changed

components/drivers/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rsource "touch/Kconfig"
2121
rsource "graphic/Kconfig"
2222
rsource "hwcrypto/Kconfig"
2323
rsource "wlan/Kconfig"
24+
rsource "mailbox/Kconfig"
2425
rsource "virtio/Kconfig"
2526
rsource "ofw/Kconfig"
2627
rsource "pci/Kconfig"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2006-2023, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2023-09-23 GuEe-GUI first version
9+
*/
10+
11+
#ifndef __MAILBOX_H__
12+
#define __MAILBOX_H__
13+
14+
#include <rtdef.h>
15+
#include <drivers/ofw.h>
16+
17+
struct rt_mbox_chan;
18+
struct rt_mbox_client;
19+
struct rt_mbox_controller_ops;
20+
21+
struct rt_mbox_controller
22+
{
23+
rt_list_t list;
24+
25+
struct rt_device *dev;
26+
27+
const struct rt_mbox_controller_ops *ops;
28+
29+
rt_size_t num_chans;
30+
struct rt_mbox_chan *chans;
31+
};
32+
33+
struct rt_mbox_controller_ops
34+
{
35+
rt_err_t (*request)(struct rt_mbox_chan *);
36+
void (*release)(struct rt_mbox_chan *);
37+
rt_err_t (*send)(struct rt_mbox_chan *, const void *data);
38+
rt_bool_t (*peek)(struct rt_mbox_chan *);
39+
int (*ofw_parse)(struct rt_mbox_controller *, struct rt_ofw_cell_args *);
40+
};
41+
42+
struct rt_mbox_chan
43+
{
44+
struct rt_mbox_controller *ctrl;
45+
struct rt_mbox_client *client;
46+
47+
void *data;
48+
rt_bool_t complete;
49+
struct rt_timer timer;
50+
struct rt_spinlock lock;
51+
52+
void *priv;
53+
};
54+
55+
struct rt_mbox_client
56+
{
57+
struct rt_device *dev;
58+
59+
void (*rx_callback)(struct rt_mbox_client *, void *data);
60+
void (*tx_prepare)(struct rt_mbox_client *, const void *data);
61+
void (*tx_done)(struct rt_mbox_client *, const void *data, rt_err_t err);
62+
};
63+
64+
rt_err_t rt_mbox_controller_register(struct rt_mbox_controller *ctrl);
65+
rt_err_t rt_mbox_controller_unregister(struct rt_mbox_controller *ctrl);
66+
67+
rt_err_t rt_mbox_send(struct rt_mbox_chan *chan, const void *data,
68+
rt_uint32_t timeout_ms);
69+
void rt_mbox_send_done(struct rt_mbox_chan *chan, rt_err_t err);
70+
rt_bool_t rt_mbox_peek(struct rt_mbox_chan *chan);
71+
rt_err_t rt_mbox_recv(struct rt_mbox_chan *chan, void *data);
72+
73+
struct rt_mbox_chan *rt_mbox_request_by_index(struct rt_mbox_client *client, int index);
74+
struct rt_mbox_chan *rt_mbox_request_by_name(struct rt_mbox_client *client, char *name);
75+
rt_err_t rt_mbox_release(struct rt_mbox_chan *chan);
76+
77+
#endif /* __MAILBOX_H__ */

components/drivers/include/rtdevice.h

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ extern "C" {
4545
#include "drivers/core/power_domain.h"
4646
#include "drivers/platform.h"
4747

48+
#ifdef RT_USING_MBOX
49+
#include "drivers/mailbox.h"
50+
#endif
51+
4852
#ifdef RT_USING_OFW
4953
#include "drivers/ofw.h"
5054
#include "drivers/ofw_fdt.h"

components/drivers/mailbox/Kconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
menuconfig RT_USING_MBOX
2+
bool "Using Hardware Mailbox device drivers"
3+
depends on RT_USING_DM
4+
depends on RT_USING_OFW
5+
default n
6+
7+
if RT_USING_MBOX && SOC_DM_MBOX
8+
comment "SoC Device Drivers"
9+
source "$(SOC_DM_DIR)/mailbox/Kconfig"
10+
endif

components/drivers/mailbox/SConscript

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from building import *
2+
3+
group = []
4+
5+
if not GetDepend(['RT_USING_MBOX']):
6+
Return('group')
7+
8+
cwd = GetCurrentDir()
9+
CPPPATH = [cwd + '/../include']
10+
11+
src = ['mailbox.c']
12+
13+
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
14+
15+
Return('group')

0 commit comments

Comments
 (0)