// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2016-2017, Linaro Ltd
*/
#include <linux/idr.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/list.h>
#include <linux/mfd/syscon.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/rpmsg.h>
#include <linux/sizes.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <linux/mailbox_client.h>
#include "rpmsg_internal.h"
#include "qcom_glink_native.h"
#define GLINK_NAME_SIZE 32
#define GLINK_VERSION_1 1
#define RPM_GLINK_CID_MIN 1
#define RPM_GLINK_CID_MAX 65536
struct glink_msg {
__le16 cmd;
__le16 param1;
__le32 param2;
u8 data[];
} __packed;
/**
* struct glink_defer_cmd - deferred incoming control message
* @node: list node
* @msg: message header
* @data: payload of the message
*
* Copy of a received control message, to be added to @rx_queue and processed
* by @rx_work of @qcom_glink.
*/
struct glink_defer_cmd {
struct list_head node;
struct glink_msg msg;
u8 data[];
};
/**
* struct glink_core_rx_intent - RX intent
* RX intent
*
* @data: pointer to the data (may be NULL for zero-copy)
* @id: remote or local intent ID
* @size: size of the original intent (do not modify)
* @reuse: To mark if the intent can be reused after first use
* @in_use: To mark if intent is already in use for the channel
* @offset: next write offset (initially 0)
* @node: list node
*/
struct glink_core_rx_intent {
void *data;
u32 id;
size_t size;
bool reuse;
bool in_use;
u32 offset;
struct list_head node;
};
/**
* struct qcom_glink - driver context, relates to one remote subsystem
* @dev: reference to the associated struct device
* @mbox_client: mailbox client
* @mbox_chan: mailbox channel
* @rx_pipe: pipe object for receive FIFO
* @tx_pipe: pipe object for transmit FIFO
* @irq: IRQ for signaling incoming events
* @rx_work: worker for handling received control messages
* @rx_lock: protects the @rx_queue
* @rx_queue: queue of received control messages to be processed in @rx_work
* @tx_lock: synchronizes operations on the tx fifo
* @idr_lock: synchronizes @lcids and @rcids modifications
* @lcids: idr of all channels with a known local channel id
* @rcids: idr of all channels with a known remote channel id
* @features: remote features
* @intentless: flag to indicate that there is no intent
*/
struct qcom_glink {
struct device *dev;
const char *name;
struct mbox_client mbox_client;
struct mbox_chan *mbox_chan;
struct qcom_glink_pipe *rx_pipe;
struct qcom_glink_pipe *tx_pipe;
int irq;
struct work_struct rx_work;
spinlock_t rx_lock;
struct list_head rx_queue;
spinlock_t tx_lock;
spinlock_t idr_lock;
struct idr lcids;
struct idr rcids;
unsigned long features;
bool intentless;
};
enum {
GLINK_STATE_CLOSED,
GLINK_STATE_OPENING,
GLINK_STATE_OPEN,
GLINK_STATE_C