linux/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h

/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
/* Copyright (c) 2010-2012 Broadcom. All rights reserved. */

#ifndef VCHIQ_CORE_H
#define VCHIQ_CORE_H

#include <linux/mutex.h>
#include <linux/completion.h>
#include <linux/debugfs.h>
#include <linux/dev_printk.h>
#include <linux/kthread.h>
#include <linux/kref.h>
#include <linux/rcupdate.h>
#include <linux/spinlock_types.h>
#include <linux/wait.h>

#include "../../include/linux/raspberrypi/vchiq.h"
#include "vchiq_cfg.h"

/* Do this so that we can test-build the code on non-rpi systems */
#if IS_ENABLED(CONFIG_RASPBERRYPI_FIRMWARE)

#else

#ifndef dsb
#define dsb(a)
#endif

#endif	/* IS_ENABLED(CONFIG_RASPBERRYPI_FIRMWARE) */

#define VCHIQ_SERVICE_HANDLE_INVALID

#define VCHIQ_SLOT_SIZE
#define VCHIQ_MAX_MSG_SIZE

#define VCHIQ_SLOT_MASK
#define VCHIQ_SLOT_QUEUE_MASK
#define VCHIQ_SLOT_ZERO_SLOTS

#define BITSET_SIZE(b)
#define BITSET_WORD(b)
#define BITSET_BIT(b)
#define BITSET_IS_SET(bs, b)
#define BITSET_SET(bs, b)

enum {};

#if VCHIQ_ENABLE_DEBUG

#define DEBUG_INITIALISE(local)
#define DEBUG_TRACE(d)
#define DEBUG_VALUE(d, v)
#define DEBUG_COUNT(d)

#else /* VCHIQ_ENABLE_DEBUG */

#define DEBUG_INITIALISE
#define DEBUG_TRACE
#define DEBUG_VALUE
#define DEBUG_COUNT

#endif /* VCHIQ_ENABLE_DEBUG */

enum vchiq_connstate {};

enum {};

enum vchiq_bulk_dir {};

struct vchiq_bulk {};

struct vchiq_bulk_queue {};

/*
 * Remote events provide a way of presenting several virtual doorbells to a
 * peer (ARM host to VPU) using only one physical doorbell. They can be thought
 * of as a way for the peer to signal a semaphore, in this case implemented as
 * a workqueue.
 *
 * Remote events remain signalled until acknowledged by the receiver, and they
 * are non-counting. They are designed in such a way as to minimise the number
 * of interrupts and avoid unnecessary waiting.
 *
 * A remote_event is as small data structures that live in shared memory. It
 * comprises two booleans - armed and fired:
 *
 * The sender sets fired when they signal the receiver.
 * If fired is set, the receiver has been signalled and need not wait.
 * The receiver sets the armed field before they begin to wait.
 * If armed is set, the receiver is waiting and wishes to be woken by interrupt.
 */
struct remote_event {};

struct opaque_platform_state;

struct vchiq_slot {};

struct vchiq_slot_info {};

struct vchiq_service {};

/*
 * The quota information is outside struct vchiq_service so that it can
 * be statically allocated, since for accounting reasons a service's slot
 * usage is carried over between users of the same port number.
 */
struct vchiq_service_quota {};

struct vchiq_shared_state {};

struct vchiq_slot_zero {};

struct vchiq_state {};

static inline bool vchiq_remote_initialised(const struct vchiq_state *state)
{}

struct bulk_waiter {};

struct vchiq_config {};

extern spinlock_t bulk_waiter_spinlock;

extern const char *
get_conn_state_name(enum vchiq_connstate conn_state);

extern struct vchiq_slot_zero *
vchiq_init_slots(struct device *dev, void *mem_base, int mem_size);

extern int
vchiq_init_state(struct vchiq_state *state, struct vchiq_slot_zero *slot_zero, struct device *dev);

extern int
vchiq_connect_internal(struct vchiq_state *state, struct vchiq_instance *instance);

struct vchiq_service *
vchiq_add_service_internal(struct vchiq_state *state,
			   const struct vchiq_service_params_kernel *params,
			   int srvstate, struct vchiq_instance *instance,
			   void (*userdata_term)(void *userdata));

extern int
vchiq_open_service_internal(struct vchiq_service *service, int client_id);

extern int
vchiq_close_service_internal(struct vchiq_service *service, int close_recvd);

extern void
vchiq_terminate_service_internal(struct vchiq_service *service);

extern void
vchiq_free_service_internal(struct vchiq_service *service);

extern void
vchiq_shutdown_internal(struct vchiq_state *state, struct vchiq_instance *instance);

extern void
remote_event_pollall(struct vchiq_state *state);

extern int
vchiq_bulk_xfer_waiting_interruptible(struct vchiq_instance *instance,
				      unsigned int handle, struct bulk_waiter *userdata);

extern int
vchiq_bulk_xfer_blocking_interruptible(struct vchiq_instance *instance, unsigned int handle,
				       void *offset, void __user *uoffset, int size,
				       void __user *userdata, enum vchiq_bulk_dir dir);

extern int
vchiq_bulk_xfer_callback_interruptible(struct vchiq_instance *instance, unsigned int handle,
				       void *offset, void __user *uoffset, int size,
				       enum vchiq_bulk_mode mode, void *userdata,
				       enum vchiq_bulk_dir dir);

extern void
vchiq_dump_state(struct seq_file *f, struct vchiq_state *state);

extern void
request_poll(struct vchiq_state *state, struct vchiq_service *service,
	     int poll_type);

struct vchiq_service *handle_to_service(struct vchiq_instance *instance, unsigned int handle);

extern struct vchiq_service *
find_service_by_handle(struct vchiq_instance *instance, unsigned int handle);

extern struct vchiq_service *
find_service_by_port(struct vchiq_state *state, unsigned int localport);

extern struct vchiq_service *
find_service_for_instance(struct vchiq_instance *instance, unsigned int handle);

extern struct vchiq_service *
find_closed_service_for_instance(struct vchiq_instance *instance, unsigned int handle);

extern struct vchiq_service *
__next_service_by_instance(struct vchiq_state *state,
			   struct vchiq_instance *instance,
			   int *pidx);

extern struct vchiq_service *
next_service_by_instance(struct vchiq_state *state,
			 struct vchiq_instance *instance,
			 int *pidx);

extern void
vchiq_service_get(struct vchiq_service *service);

extern void
vchiq_service_put(struct vchiq_service *service);

extern int
vchiq_queue_message(struct vchiq_instance *instance, unsigned int handle,
		    ssize_t (*copy_callback)(void *context, void *dest,
					     size_t offset, size_t maxsize),
		    void *context,
		    size_t size);

int vchiq_prepare_bulk_data(struct vchiq_instance *instance, struct vchiq_bulk *bulk, void *offset,
			    void __user *uoffset, int size, int dir);

void vchiq_complete_bulk(struct vchiq_instance *instance, struct vchiq_bulk *bulk);

void remote_event_signal(struct vchiq_state *state, struct remote_event *event);

void vchiq_dump_platform_state(struct seq_file *f);

void vchiq_dump_platform_instances(struct vchiq_state *state, struct seq_file *f);

void vchiq_dump_platform_service_state(struct seq_file *f, struct vchiq_service *service);

int vchiq_use_service_internal(struct vchiq_service *service);

int vchiq_release_service_internal(struct vchiq_service *service);

void vchiq_on_remote_use(struct vchiq_state *state);

void vchiq_on_remote_release(struct vchiq_state *state);

int vchiq_platform_init_state(struct vchiq_state *state);

int vchiq_check_service(struct vchiq_service *service);

int vchiq_send_remote_use(struct vchiq_state *state);

int vchiq_send_remote_use_active(struct vchiq_state *state);

void vchiq_platform_conn_state_changed(struct vchiq_state *state,
				       enum vchiq_connstate oldstate,
				  enum vchiq_connstate newstate);

void vchiq_set_conn_state(struct vchiq_state *state, enum vchiq_connstate newstate);

void vchiq_log_dump_mem(struct device *dev, const char *label, u32 addr,
			const void *void_mem, size_t num_bytes);

int vchiq_remove_service(struct vchiq_instance *instance, unsigned int service);

int vchiq_get_client_id(struct vchiq_instance *instance, unsigned int service);

void vchiq_get_config(struct vchiq_config *config);

int vchiq_set_service_option(struct vchiq_instance *instance, unsigned int service,
			     enum vchiq_service_option option, int value);

#endif