Skip to content

[DM/FEATURE] Support hardware mailbox #9599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ rsource "touch/Kconfig"
rsource "graphic/Kconfig"
rsource "hwcrypto/Kconfig"
rsource "wlan/Kconfig"
rsource "mailbox/Kconfig"
rsource "phye/Kconfig"
rsource "block/Kconfig"
rsource "nvme/Kconfig"
Expand Down
77 changes: 77 additions & 0 deletions components/drivers/include/drivers/mailbox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-09-23 GuEe-GUI first version
*/

#ifndef __MAILBOX_H__
#define __MAILBOX_H__

#include <rtdef.h>
#include <drivers/ofw.h>

struct rt_mbox_chan;
struct rt_mbox_client;
struct rt_mbox_controller_ops;

struct rt_mbox_controller
{
rt_list_t list;

struct rt_device *dev;

const struct rt_mbox_controller_ops *ops;

rt_size_t num_chans;
struct rt_mbox_chan *chans;
};

struct rt_mbox_controller_ops
{
rt_err_t (*request)(struct rt_mbox_chan *);
void (*release)(struct rt_mbox_chan *);
rt_err_t (*send)(struct rt_mbox_chan *, const void *data);
rt_bool_t (*peek)(struct rt_mbox_chan *);
int (*ofw_parse)(struct rt_mbox_controller *, struct rt_ofw_cell_args *);
};

struct rt_mbox_chan
{
struct rt_mbox_controller *ctrl;
struct rt_mbox_client *client;

void *data;
rt_bool_t complete;
struct rt_timer timer;
struct rt_spinlock lock;

void *priv;
};

struct rt_mbox_client
{
struct rt_device *dev;

void (*rx_callback)(struct rt_mbox_client *, void *data);
void (*tx_prepare)(struct rt_mbox_client *, const void *data);
void (*tx_done)(struct rt_mbox_client *, const void *data, rt_err_t err);
};

rt_err_t rt_mbox_controller_register(struct rt_mbox_controller *ctrl);
rt_err_t rt_mbox_controller_unregister(struct rt_mbox_controller *ctrl);

rt_err_t rt_mbox_send(struct rt_mbox_chan *chan, const void *data,
rt_uint32_t timeout_ms);
void rt_mbox_send_done(struct rt_mbox_chan *chan, rt_err_t err);
rt_bool_t rt_mbox_peek(struct rt_mbox_chan *chan);
rt_err_t rt_mbox_recv(struct rt_mbox_chan *chan, void *data);

struct rt_mbox_chan *rt_mbox_request_by_index(struct rt_mbox_client *client, int index);
struct rt_mbox_chan *rt_mbox_request_by_name(struct rt_mbox_client *client, char *name);
rt_err_t rt_mbox_release(struct rt_mbox_chan *chan);

#endif /* __MAILBOX_H__ */
20 changes: 12 additions & 8 deletions components/drivers/include/rtdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,23 @@ extern "C" {
#include "drivers/core/power_domain.h"
#include "drivers/platform.h"

#ifdef RT_USING_MBOX
#include "drivers/mailbox.h"
#endif /* RT_USING_MBOX */

#ifdef RT_USING_BLK
#include "drivers/blk.h"
#endif
#endif /* RT_USING_BLK */

#ifdef RT_USING_DMA
#include "drivers/dma.h"
#endif
#endif /* RT_USING_DMA */

#include "drivers/iio.h"

#ifdef RT_USING_NVME
#include "drivers/nvme.h"
#endif
#endif /* RT_USING_NVME */

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

#ifdef RT_USING_PHYE
#include "drivers/phye.h"
#endif
#endif /* RT_USING_PHYE */

#ifdef RT_USING_PIC
#include "drivers/pic.h"
#endif
#endif /* RT_USING_PIC */

#ifdef RT_USING_SCSI
#include "drivers/scsi.h"
#endif
#endif /* RT_USING_SCSI */

#ifdef RT_MFD_SYSCON
#include "drivers/syscon.h"
#endif
#endif /* RT_MFD_SYSCON */
#endif /* RT_USING_DM */

#ifdef RT_USING_RTC
#include "drivers/dev_rtc.h"
#ifdef RT_USING_ALARM
#include "drivers/dev_alarm.h"
#endif
#endif /* RT_USING_ALARM */
#endif /* RT_USING_RTC */

#ifdef RT_USING_SPI
Expand Down
14 changes: 14 additions & 0 deletions components/drivers/mailbox/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
menuconfig RT_USING_MBOX
bool "Using Hardware Mailbox device drivers"
depends on RT_USING_DM
depends on RT_USING_OFW
default n

config RT_MBOX_PIC
bool "RT-Thread PIC Mailbox"
depends on RT_USING_MBOX
default y

if RT_USING_MBOX
osource "$(SOC_DM_MBOX_DIR)/Kconfig"
endif
18 changes: 18 additions & 0 deletions components/drivers/mailbox/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from building import *

group = []

if not GetDepend(['RT_USING_MBOX']):
Return('group')

cwd = GetCurrentDir()
CPPPATH = [cwd + '/../include']

src = ['mailbox.c']

if GetDepend(['RT_MBOX_PIC']):
src += ['mailbox-pic.c']

group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)

Return('group')
Loading
Loading