Skip to content

Commit f849afb

Browse files
authored
[DM/FEATURE] Support hardware mailbox (#9599)
* [DM/FEATURE] Support hardware mailbox * [MAILBOX/PIC] Add PIC Mailbox drivers. The mailbox device(s) may be instantiated in one of three equivalent way: Device Tree node, eg.: ```dts interrupt-controller@0 { interrupt-controller; #interrupt-cells = <1>; }; pic_mailbox@10000 { compatible = "rt-thread,pic-mailbox"; reg = <0x10000 0x100>; position = <0>; interrupts = <34>; peer-interrupts = <35>; uid = <0>; #mbox-cells = <1>; }; ``` Signed-off-by: GuEe-GUI <[email protected]>
1 parent 8ed4ae1 commit f849afb

File tree

7 files changed

+750
-8
lines changed

7 files changed

+750
-8
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 "phye/Kconfig"
2526
rsource "block/Kconfig"
2627
rsource "nvme/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

+12-8
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,23 @@ 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 /* RT_USING_MBOX */
51+
4852
#ifdef RT_USING_BLK
4953
#include "drivers/blk.h"
50-
#endif
54+
#endif /* RT_USING_BLK */
5155

5256
#ifdef RT_USING_DMA
5357
#include "drivers/dma.h"
54-
#endif
58+
#endif /* RT_USING_DMA */
5559

5660
#include "drivers/iio.h"
5761

5862
#ifdef RT_USING_NVME
5963
#include "drivers/nvme.h"
60-
#endif
64+
#endif /* RT_USING_NVME */
6165

6266
#ifdef RT_USING_OFW
6367
#include "drivers/ofw.h"
@@ -69,26 +73,26 @@ extern "C" {
6973

7074
#ifdef RT_USING_PHYE
7175
#include "drivers/phye.h"
72-
#endif
76+
#endif /* RT_USING_PHYE */
7377

7478
#ifdef RT_USING_PIC
7579
#include "drivers/pic.h"
76-
#endif
80+
#endif /* RT_USING_PIC */
7781

7882
#ifdef RT_USING_SCSI
7983
#include "drivers/scsi.h"
80-
#endif
84+
#endif /* RT_USING_SCSI */
8185

8286
#ifdef RT_MFD_SYSCON
8387
#include "drivers/syscon.h"
84-
#endif
88+
#endif /* RT_MFD_SYSCON */
8589
#endif /* RT_USING_DM */
8690

8791
#ifdef RT_USING_RTC
8892
#include "drivers/dev_rtc.h"
8993
#ifdef RT_USING_ALARM
9094
#include "drivers/dev_alarm.h"
91-
#endif
95+
#endif /* RT_USING_ALARM */
9296
#endif /* RT_USING_RTC */
9397

9498
#ifdef RT_USING_SPI

components/drivers/mailbox/Kconfig

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
config RT_MBOX_PIC
8+
bool "RT-Thread PIC Mailbox"
9+
depends on RT_USING_MBOX
10+
default y
11+
12+
if RT_USING_MBOX
13+
osource "$(SOC_DM_MBOX_DIR)/Kconfig"
14+
endif

components/drivers/mailbox/SConscript

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
if GetDepend(['RT_MBOX_PIC']):
14+
src += ['mailbox-pic.c']
15+
16+
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
17+
18+
Return('group')

0 commit comments

Comments
 (0)