162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *  cx18 mailbox functions
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci *  Copyright (C) 2007  Hans Verkuil <hverkuil@xs4all.nl>
662306a36Sopenharmony_ci *  Copyright (C) 2008  Andy Walls <awalls@md.metrocast.net>
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef _CX18_MAILBOX_H_
1062306a36Sopenharmony_ci#define _CX18_MAILBOX_H_
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci/* mailbox max args */
1362306a36Sopenharmony_ci#define MAX_MB_ARGUMENTS 6
1462306a36Sopenharmony_ci/* compatibility, should be same as the define in cx2341x.h */
1562306a36Sopenharmony_ci#define CX2341X_MBOX_MAX_DATA 16
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#define MB_RESERVED_HANDLE_0 0
1862306a36Sopenharmony_ci#define MB_RESERVED_HANDLE_1 0xFFFFFFFF
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#define APU 0
2162306a36Sopenharmony_ci#define CPU 1
2262306a36Sopenharmony_ci#define EPU 2
2362306a36Sopenharmony_ci#define HPU 3
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_cistruct cx18;
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci/*
2862306a36Sopenharmony_ci * This structure is used by CPU to provide completed MDL & buffers information.
2962306a36Sopenharmony_ci * Its structure is dictated by the layout of the SCB, required by the
3062306a36Sopenharmony_ci * firmware, but its definition needs to be here, instead of in cx18-scb.h,
3162306a36Sopenharmony_ci * for mailbox work order scheduling
3262306a36Sopenharmony_ci */
3362306a36Sopenharmony_cistruct cx18_mdl_ack {
3462306a36Sopenharmony_ci    u32 id;        /* ID of a completed MDL */
3562306a36Sopenharmony_ci    u32 data_used; /* Total data filled in the MDL with 'id' */
3662306a36Sopenharmony_ci};
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci/* The cx18_mailbox struct is the mailbox structure which is used for passing
3962306a36Sopenharmony_ci   messages between processors */
4062306a36Sopenharmony_cistruct cx18_mailbox {
4162306a36Sopenharmony_ci    /* The sender sets a handle in 'request' after he fills the command. The
4262306a36Sopenharmony_ci       'request' should be different than 'ack'. The sender, also, generates
4362306a36Sopenharmony_ci       an interrupt on XPU2YPU_irq where XPU is the sender and YPU is the
4462306a36Sopenharmony_ci       receiver. */
4562306a36Sopenharmony_ci    u32       request;
4662306a36Sopenharmony_ci    /* The receiver detects a new command when 'req' is different than 'ack'.
4762306a36Sopenharmony_ci       He sets 'ack' to the same value as 'req' to clear the command. He, also,
4862306a36Sopenharmony_ci       generates an interrupt on YPU2XPU_irq where XPU is the sender and YPU
4962306a36Sopenharmony_ci       is the receiver. */
5062306a36Sopenharmony_ci    u32       ack;
5162306a36Sopenharmony_ci    u32       reserved[6];
5262306a36Sopenharmony_ci    /* 'cmd' identifies the command. The list of these commands are in
5362306a36Sopenharmony_ci       cx23418.h */
5462306a36Sopenharmony_ci    u32       cmd;
5562306a36Sopenharmony_ci    /* Each command can have up to 6 arguments */
5662306a36Sopenharmony_ci    u32       args[MAX_MB_ARGUMENTS];
5762306a36Sopenharmony_ci    /* The return code can be one of the codes in the file cx23418.h. If the
5862306a36Sopenharmony_ci       command is completed successfully, the error will be ERR_SYS_SUCCESS.
5962306a36Sopenharmony_ci       If it is pending, the code is ERR_SYS_PENDING. If it failed, the error
6062306a36Sopenharmony_ci       code would indicate the task from which the error originated and will
6162306a36Sopenharmony_ci       be one of the errors in cx23418.h. In that case, the following
6262306a36Sopenharmony_ci       applies ((error & 0xff) != 0).
6362306a36Sopenharmony_ci       If the command is pending, the return will be passed in a MB from the
6462306a36Sopenharmony_ci       receiver to the sender. 'req' will be returned in args[0] */
6562306a36Sopenharmony_ci    u32       error;
6662306a36Sopenharmony_ci};
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_cistruct cx18_stream;
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ciint cx18_api(struct cx18 *cx, u32 cmd, int args, u32 data[]);
7162306a36Sopenharmony_ciint cx18_vapi_result(struct cx18 *cx, u32 data[MAX_MB_ARGUMENTS], u32 cmd,
7262306a36Sopenharmony_ci		int args, ...);
7362306a36Sopenharmony_ciint cx18_vapi(struct cx18 *cx, u32 cmd, int args, ...);
7462306a36Sopenharmony_ciint cx18_api_func(void *priv, u32 cmd, int in, int out,
7562306a36Sopenharmony_ci		u32 data[CX2341X_MBOX_MAX_DATA]);
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_civoid cx18_api_epu_cmd_irq(struct cx18 *cx, int rpu);
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_civoid cx18_in_work_handler(struct work_struct *work);
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#endif
82