xref: /kernel/linux/linux-6.6/drivers/misc/sgi-xp/xpc.h (revision 62306a36)
162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
362306a36Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
462306a36Sopenharmony_ci * for more details.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright (c) 2004-2009 Silicon Graphics, Inc.  All Rights Reserved.
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci/*
1062306a36Sopenharmony_ci * Cross Partition Communication (XPC) structures and macros.
1162306a36Sopenharmony_ci */
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#ifndef _DRIVERS_MISC_SGIXP_XPC_H
1462306a36Sopenharmony_ci#define _DRIVERS_MISC_SGIXP_XPC_H
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#include <linux/wait.h>
1762306a36Sopenharmony_ci#include <linux/completion.h>
1862306a36Sopenharmony_ci#include <linux/timer.h>
1962306a36Sopenharmony_ci#include <linux/sched.h>
2062306a36Sopenharmony_ci#include "xp.h"
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci/*
2362306a36Sopenharmony_ci * XPC Version numbers consist of a major and minor number. XPC can always
2462306a36Sopenharmony_ci * talk to versions with same major #, and never talk to versions with a
2562306a36Sopenharmony_ci * different major #.
2662306a36Sopenharmony_ci */
2762306a36Sopenharmony_ci#define _XPC_VERSION(_maj, _min)	(((_maj) << 4) | ((_min) & 0xf))
2862306a36Sopenharmony_ci#define XPC_VERSION_MAJOR(_v)		((_v) >> 4)
2962306a36Sopenharmony_ci#define XPC_VERSION_MINOR(_v)		((_v) & 0xf)
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci/* define frequency of the heartbeat and frequency how often it's checked */
3262306a36Sopenharmony_ci#define XPC_HB_DEFAULT_INTERVAL		5	/* incr HB every x secs */
3362306a36Sopenharmony_ci#define XPC_HB_CHECK_DEFAULT_INTERVAL	20	/* check HB every x secs */
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci/* define the process name of HB checker and the CPU it is pinned to */
3662306a36Sopenharmony_ci#define XPC_HB_CHECK_THREAD_NAME	"xpc_hb"
3762306a36Sopenharmony_ci#define XPC_HB_CHECK_CPU		0
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci/* define the process name of the discovery thread */
4062306a36Sopenharmony_ci#define XPC_DISCOVERY_THREAD_NAME	"xpc_discovery"
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/*
4362306a36Sopenharmony_ci * the reserved page
4462306a36Sopenharmony_ci *
4562306a36Sopenharmony_ci *   SAL reserves one page of memory per partition for XPC. Though a full page
4662306a36Sopenharmony_ci *   in length (16384 bytes), its starting address is not page aligned, but it
4762306a36Sopenharmony_ci *   is cacheline aligned. The reserved page consists of the following:
4862306a36Sopenharmony_ci *
4962306a36Sopenharmony_ci *   reserved page header
5062306a36Sopenharmony_ci *
5162306a36Sopenharmony_ci *     The first two 64-byte cachelines of the reserved page contain the
5262306a36Sopenharmony_ci *     header (struct xpc_rsvd_page). Before SAL initialization has completed,
5362306a36Sopenharmony_ci *     SAL has set up the following fields of the reserved page header:
5462306a36Sopenharmony_ci *     SAL_signature, SAL_version, SAL_partid, and SAL_nasids_size. The
5562306a36Sopenharmony_ci *     other fields are set up by XPC. (xpc_rsvd_page points to the local
5662306a36Sopenharmony_ci *     partition's reserved page.)
5762306a36Sopenharmony_ci *
5862306a36Sopenharmony_ci *   part_nasids mask
5962306a36Sopenharmony_ci *   mach_nasids mask
6062306a36Sopenharmony_ci *
6162306a36Sopenharmony_ci *     SAL also sets up two bitmaps (or masks), one that reflects the actual
6262306a36Sopenharmony_ci *     nasids in this partition (part_nasids), and the other that reflects
6362306a36Sopenharmony_ci *     the actual nasids in the entire machine (mach_nasids). We're only
6462306a36Sopenharmony_ci *     interested in the even numbered nasids (which contain the processors
6562306a36Sopenharmony_ci *     and/or memory), so we only need half as many bits to represent the
6662306a36Sopenharmony_ci *     nasids. When mapping nasid to bit in a mask (or bit to nasid) be sure
6762306a36Sopenharmony_ci *     to either divide or multiply by 2. The part_nasids mask is located
6862306a36Sopenharmony_ci *     starting at the first cacheline following the reserved page header. The
6962306a36Sopenharmony_ci *     mach_nasids mask follows right after the part_nasids mask. The size in
7062306a36Sopenharmony_ci *     bytes of each mask is reflected by the reserved page header field
7162306a36Sopenharmony_ci *     'SAL_nasids_size'. (Local partition's mask pointers are xpc_part_nasids
7262306a36Sopenharmony_ci *     and xpc_mach_nasids.)
7362306a36Sopenharmony_ci *
7462306a36Sopenharmony_ci *     Immediately following the mach_nasids mask are the XPC variables
7562306a36Sopenharmony_ci *     required by other partitions. First are those that are generic to all
7662306a36Sopenharmony_ci *     partitions (vars), followed on the next available cacheline by those
7762306a36Sopenharmony_ci *     which are partition specific (vars part). These are setup by XPC.
7862306a36Sopenharmony_ci *
7962306a36Sopenharmony_ci * Note: Until 'ts_jiffies' is set non-zero, the partition XPC code has not been
8062306a36Sopenharmony_ci *       initialized.
8162306a36Sopenharmony_ci */
8262306a36Sopenharmony_cistruct xpc_rsvd_page {
8362306a36Sopenharmony_ci	u64 SAL_signature;	/* SAL: unique signature */
8462306a36Sopenharmony_ci	u64 SAL_version;	/* SAL: version */
8562306a36Sopenharmony_ci	short SAL_partid;	/* SAL: partition ID */
8662306a36Sopenharmony_ci	short max_npartitions;	/* value of XPC_MAX_PARTITIONS */
8762306a36Sopenharmony_ci	u8 version;
8862306a36Sopenharmony_ci	u8 pad1[3];		/* align to next u64 in 1st 64-byte cacheline */
8962306a36Sopenharmony_ci	unsigned long ts_jiffies; /* timestamp when rsvd pg was setup by XPC */
9062306a36Sopenharmony_ci	union {
9162306a36Sopenharmony_ci		struct {
9262306a36Sopenharmony_ci			unsigned long heartbeat_gpa; /* phys addr */
9362306a36Sopenharmony_ci			unsigned long activate_gru_mq_desc_gpa; /* phys addr */
9462306a36Sopenharmony_ci		} uv;
9562306a36Sopenharmony_ci	} sn;
9662306a36Sopenharmony_ci	u64 pad2[9];		/* align to last u64 in 2nd 64-byte cacheline */
9762306a36Sopenharmony_ci	u64 SAL_nasids_size;	/* SAL: size of each nasid mask in bytes */
9862306a36Sopenharmony_ci};
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci#define XPC_RP_VERSION _XPC_VERSION(3, 0) /* version 3.0 of the reserved page */
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci/* the reserved page sizes and offsets */
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci#define XPC_RP_HEADER_SIZE	L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page))
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci#define XPC_RP_PART_NASIDS(_rp) ((unsigned long *)((u8 *)(_rp) + \
10762306a36Sopenharmony_ci				 XPC_RP_HEADER_SIZE))
10862306a36Sopenharmony_ci#define XPC_RP_MACH_NASIDS(_rp) (XPC_RP_PART_NASIDS(_rp) + \
10962306a36Sopenharmony_ci				 xpc_nasid_mask_nlongs)
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci/*
11362306a36Sopenharmony_ci * The following structure describes the partition's heartbeat info which
11462306a36Sopenharmony_ci * will be periodically read by other partitions to determine whether this
11562306a36Sopenharmony_ci * XPC is still 'alive'.
11662306a36Sopenharmony_ci */
11762306a36Sopenharmony_cistruct xpc_heartbeat_uv {
11862306a36Sopenharmony_ci	unsigned long value;
11962306a36Sopenharmony_ci	unsigned long offline;	/* if 0, heartbeat should be changing */
12062306a36Sopenharmony_ci};
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci/*
12362306a36Sopenharmony_ci * Info pertinent to a GRU message queue using a watch list for irq generation.
12462306a36Sopenharmony_ci */
12562306a36Sopenharmony_cistruct xpc_gru_mq_uv {
12662306a36Sopenharmony_ci	void *address;		/* address of GRU message queue */
12762306a36Sopenharmony_ci	unsigned int order;	/* size of GRU message queue as a power of 2 */
12862306a36Sopenharmony_ci	int irq;		/* irq raised when message is received in mq */
12962306a36Sopenharmony_ci	int mmr_blade;		/* blade where watchlist was allocated from */
13062306a36Sopenharmony_ci	unsigned long mmr_offset; /* offset of irq mmr located on mmr_blade */
13162306a36Sopenharmony_ci	unsigned long mmr_value; /* value of irq mmr located on mmr_blade */
13262306a36Sopenharmony_ci	int watchlist_num;	/* number of watchlist allocatd by BIOS */
13362306a36Sopenharmony_ci	void *gru_mq_desc;	/* opaque structure used by the GRU driver */
13462306a36Sopenharmony_ci};
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci/*
13762306a36Sopenharmony_ci * The activate_mq is used to send/receive GRU messages that affect XPC's
13862306a36Sopenharmony_ci * partition active state and channel state. This is uv only.
13962306a36Sopenharmony_ci */
14062306a36Sopenharmony_cistruct xpc_activate_mq_msghdr_uv {
14162306a36Sopenharmony_ci	unsigned int gru_msg_hdr; /* FOR GRU INTERNAL USE ONLY */
14262306a36Sopenharmony_ci	short partid;		/* sender's partid */
14362306a36Sopenharmony_ci	u8 act_state;		/* sender's act_state at time msg sent */
14462306a36Sopenharmony_ci	u8 type;		/* message's type */
14562306a36Sopenharmony_ci	unsigned long rp_ts_jiffies; /* timestamp of sender's rp setup by XPC */
14662306a36Sopenharmony_ci};
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci/* activate_mq defined message types */
14962306a36Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_SYNC_ACT_STATE_UV		0
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_ACTIVATE_REQ_UV		1
15262306a36Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_DEACTIVATE_REQ_UV		2
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREQUEST_UV	3
15562306a36Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREPLY_UV		4
15662306a36Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREQUEST_UV	5
15762306a36Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREPLY_UV		6
15862306a36Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENCOMPLETE_UV	7
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_MARK_ENGAGED_UV		8
16162306a36Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_MARK_DISENGAGED_UV		9
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_cistruct xpc_activate_mq_msg_uv {
16462306a36Sopenharmony_ci	struct xpc_activate_mq_msghdr_uv hdr;
16562306a36Sopenharmony_ci};
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_cistruct xpc_activate_mq_msg_activate_req_uv {
16862306a36Sopenharmony_ci	struct xpc_activate_mq_msghdr_uv hdr;
16962306a36Sopenharmony_ci	unsigned long rp_gpa;
17062306a36Sopenharmony_ci	unsigned long heartbeat_gpa;
17162306a36Sopenharmony_ci	unsigned long activate_gru_mq_desc_gpa;
17262306a36Sopenharmony_ci};
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_cistruct xpc_activate_mq_msg_deactivate_req_uv {
17562306a36Sopenharmony_ci	struct xpc_activate_mq_msghdr_uv hdr;
17662306a36Sopenharmony_ci	enum xp_retval reason;
17762306a36Sopenharmony_ci};
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_cistruct xpc_activate_mq_msg_chctl_closerequest_uv {
18062306a36Sopenharmony_ci	struct xpc_activate_mq_msghdr_uv hdr;
18162306a36Sopenharmony_ci	short ch_number;
18262306a36Sopenharmony_ci	enum xp_retval reason;
18362306a36Sopenharmony_ci};
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_cistruct xpc_activate_mq_msg_chctl_closereply_uv {
18662306a36Sopenharmony_ci	struct xpc_activate_mq_msghdr_uv hdr;
18762306a36Sopenharmony_ci	short ch_number;
18862306a36Sopenharmony_ci};
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_cistruct xpc_activate_mq_msg_chctl_openrequest_uv {
19162306a36Sopenharmony_ci	struct xpc_activate_mq_msghdr_uv hdr;
19262306a36Sopenharmony_ci	short ch_number;
19362306a36Sopenharmony_ci	short entry_size;	/* size of notify_mq's GRU messages */
19462306a36Sopenharmony_ci	short local_nentries;	/* ??? Is this needed? What is? */
19562306a36Sopenharmony_ci};
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_cistruct xpc_activate_mq_msg_chctl_openreply_uv {
19862306a36Sopenharmony_ci	struct xpc_activate_mq_msghdr_uv hdr;
19962306a36Sopenharmony_ci	short ch_number;
20062306a36Sopenharmony_ci	short remote_nentries;	/* ??? Is this needed? What is? */
20162306a36Sopenharmony_ci	short local_nentries;	/* ??? Is this needed? What is? */
20262306a36Sopenharmony_ci	unsigned long notify_gru_mq_desc_gpa;
20362306a36Sopenharmony_ci};
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_cistruct xpc_activate_mq_msg_chctl_opencomplete_uv {
20662306a36Sopenharmony_ci	struct xpc_activate_mq_msghdr_uv hdr;
20762306a36Sopenharmony_ci	short ch_number;
20862306a36Sopenharmony_ci};
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_ci/*
21162306a36Sopenharmony_ci * Functions registered by add_timer() or called by kernel_thread() only
21262306a36Sopenharmony_ci * allow for a single 64-bit argument. The following macros can be used to
21362306a36Sopenharmony_ci * pack and unpack two (32-bit, 16-bit or 8-bit) arguments into or out from
21462306a36Sopenharmony_ci * the passed argument.
21562306a36Sopenharmony_ci */
21662306a36Sopenharmony_ci#define XPC_PACK_ARGS(_arg1, _arg2) \
21762306a36Sopenharmony_ci			((((u64)_arg1) & 0xffffffff) | \
21862306a36Sopenharmony_ci			((((u64)_arg2) & 0xffffffff) << 32))
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ci#define XPC_UNPACK_ARG1(_args)	(((u64)_args) & 0xffffffff)
22162306a36Sopenharmony_ci#define XPC_UNPACK_ARG2(_args)	((((u64)_args) >> 32) & 0xffffffff)
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci/*
22462306a36Sopenharmony_ci * Define a structure that contains arguments associated with opening and
22562306a36Sopenharmony_ci * closing a channel.
22662306a36Sopenharmony_ci */
22762306a36Sopenharmony_cistruct xpc_openclose_args {
22862306a36Sopenharmony_ci	u16 reason;		/* reason why channel is closing */
22962306a36Sopenharmony_ci	u16 entry_size;		/* sizeof each message entry */
23062306a36Sopenharmony_ci	u16 remote_nentries;	/* #of message entries in remote msg queue */
23162306a36Sopenharmony_ci	u16 local_nentries;	/* #of message entries in local msg queue */
23262306a36Sopenharmony_ci	unsigned long local_msgqueue_pa; /* phys addr of local message queue */
23362306a36Sopenharmony_ci};
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_ci#define XPC_OPENCLOSE_ARGS_SIZE \
23662306a36Sopenharmony_ci	      L1_CACHE_ALIGN(sizeof(struct xpc_openclose_args) * \
23762306a36Sopenharmony_ci	      XPC_MAX_NCHANNELS)
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_ci/*
24162306a36Sopenharmony_ci * Structures to define a fifo singly-linked list.
24262306a36Sopenharmony_ci */
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_cistruct xpc_fifo_entry_uv {
24562306a36Sopenharmony_ci	struct xpc_fifo_entry_uv *next;
24662306a36Sopenharmony_ci};
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_cistruct xpc_fifo_head_uv {
24962306a36Sopenharmony_ci	struct xpc_fifo_entry_uv *first;
25062306a36Sopenharmony_ci	struct xpc_fifo_entry_uv *last;
25162306a36Sopenharmony_ci	spinlock_t lock;
25262306a36Sopenharmony_ci	int n_entries;
25362306a36Sopenharmony_ci};
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci/*
25662306a36Sopenharmony_ci * The format of a uv XPC notify_mq GRU message is as follows:
25762306a36Sopenharmony_ci *
25862306a36Sopenharmony_ci * A user-defined message resides in the payload area. The max size of the
25962306a36Sopenharmony_ci * payload is defined by the user via xpc_connect().
26062306a36Sopenharmony_ci *
26162306a36Sopenharmony_ci * The size of a message (payload and header) sent via the GRU must be either 1
26262306a36Sopenharmony_ci * or 2 GRU_CACHE_LINE_BYTES in length.
26362306a36Sopenharmony_ci */
26462306a36Sopenharmony_ci
26562306a36Sopenharmony_cistruct xpc_notify_mq_msghdr_uv {
26662306a36Sopenharmony_ci	union {
26762306a36Sopenharmony_ci		unsigned int gru_msg_hdr;	/* FOR GRU INTERNAL USE ONLY */
26862306a36Sopenharmony_ci		struct xpc_fifo_entry_uv next;	/* FOR XPC INTERNAL USE ONLY */
26962306a36Sopenharmony_ci	} u;
27062306a36Sopenharmony_ci	short partid;		/* FOR XPC INTERNAL USE ONLY */
27162306a36Sopenharmony_ci	u8 ch_number;		/* FOR XPC INTERNAL USE ONLY */
27262306a36Sopenharmony_ci	u8 size;		/* FOR XPC INTERNAL USE ONLY */
27362306a36Sopenharmony_ci	unsigned int msg_slot_number;	/* FOR XPC INTERNAL USE ONLY */
27462306a36Sopenharmony_ci};
27562306a36Sopenharmony_ci
27662306a36Sopenharmony_cistruct xpc_notify_mq_msg_uv {
27762306a36Sopenharmony_ci	struct xpc_notify_mq_msghdr_uv hdr;
27862306a36Sopenharmony_ci	unsigned long payload;
27962306a36Sopenharmony_ci};
28062306a36Sopenharmony_ci
28162306a36Sopenharmony_ci/* struct xpc_notify_sn2 type of notification */
28262306a36Sopenharmony_ci
28362306a36Sopenharmony_ci#define	XPC_N_CALL	0x01	/* notify function provided by user */
28462306a36Sopenharmony_ci
28562306a36Sopenharmony_ci/*
28662306a36Sopenharmony_ci * Define uv's version of the notify entry. It additionally is used to allocate
28762306a36Sopenharmony_ci * a msg slot on the remote partition into which is copied a sent message.
28862306a36Sopenharmony_ci */
28962306a36Sopenharmony_cistruct xpc_send_msg_slot_uv {
29062306a36Sopenharmony_ci	struct xpc_fifo_entry_uv next;
29162306a36Sopenharmony_ci	unsigned int msg_slot_number;
29262306a36Sopenharmony_ci	xpc_notify_func func;	/* user's notify function */
29362306a36Sopenharmony_ci	void *key;		/* pointer to user's key */
29462306a36Sopenharmony_ci};
29562306a36Sopenharmony_ci
29662306a36Sopenharmony_ci/*
29762306a36Sopenharmony_ci * Define the structure that manages all the stuff required by a channel. In
29862306a36Sopenharmony_ci * particular, they are used to manage the messages sent across the channel.
29962306a36Sopenharmony_ci *
30062306a36Sopenharmony_ci * This structure is private to a partition, and is NOT shared across the
30162306a36Sopenharmony_ci * partition boundary.
30262306a36Sopenharmony_ci *
30362306a36Sopenharmony_ci * There is an array of these structures for each remote partition. It is
30462306a36Sopenharmony_ci * allocated at the time a partition becomes active. The array contains one
30562306a36Sopenharmony_ci * of these structures for each potential channel connection to that partition.
30662306a36Sopenharmony_ci */
30762306a36Sopenharmony_ci
30862306a36Sopenharmony_cistruct xpc_channel_uv {
30962306a36Sopenharmony_ci	void *cached_notify_gru_mq_desc; /* remote partition's notify mq's */
31062306a36Sopenharmony_ci					 /* gru mq descriptor */
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_ci	struct xpc_send_msg_slot_uv *send_msg_slots;
31362306a36Sopenharmony_ci	void *recv_msg_slots;	/* each slot will hold a xpc_notify_mq_msg_uv */
31462306a36Sopenharmony_ci				/* structure plus the user's payload */
31562306a36Sopenharmony_ci
31662306a36Sopenharmony_ci	struct xpc_fifo_head_uv msg_slot_free_list;
31762306a36Sopenharmony_ci	struct xpc_fifo_head_uv recv_msg_list;	/* deliverable payloads */
31862306a36Sopenharmony_ci};
31962306a36Sopenharmony_ci
32062306a36Sopenharmony_cistruct xpc_channel {
32162306a36Sopenharmony_ci	short partid;		/* ID of remote partition connected */
32262306a36Sopenharmony_ci	spinlock_t lock;	/* lock for updating this structure */
32362306a36Sopenharmony_ci	unsigned int flags;	/* general flags */
32462306a36Sopenharmony_ci
32562306a36Sopenharmony_ci	enum xp_retval reason;	/* reason why channel is disconnect'g */
32662306a36Sopenharmony_ci	int reason_line;	/* line# disconnect initiated from */
32762306a36Sopenharmony_ci
32862306a36Sopenharmony_ci	u16 number;		/* channel # */
32962306a36Sopenharmony_ci
33062306a36Sopenharmony_ci	u16 entry_size;		/* sizeof each msg entry */
33162306a36Sopenharmony_ci	u16 local_nentries;	/* #of msg entries in local msg queue */
33262306a36Sopenharmony_ci	u16 remote_nentries;	/* #of msg entries in remote msg queue */
33362306a36Sopenharmony_ci
33462306a36Sopenharmony_ci	atomic_t references;	/* #of external references to queues */
33562306a36Sopenharmony_ci
33662306a36Sopenharmony_ci	atomic_t n_on_msg_allocate_wq;	/* #on msg allocation wait queue */
33762306a36Sopenharmony_ci	wait_queue_head_t msg_allocate_wq;	/* msg allocation wait queue */
33862306a36Sopenharmony_ci
33962306a36Sopenharmony_ci	u8 delayed_chctl_flags;	/* chctl flags received, but delayed */
34062306a36Sopenharmony_ci				/* action until channel disconnected */
34162306a36Sopenharmony_ci
34262306a36Sopenharmony_ci	atomic_t n_to_notify;	/* #of msg senders to notify */
34362306a36Sopenharmony_ci
34462306a36Sopenharmony_ci	xpc_channel_func func;	/* user's channel function */
34562306a36Sopenharmony_ci	void *key;		/* pointer to user's key */
34662306a36Sopenharmony_ci
34762306a36Sopenharmony_ci	struct completion wdisconnect_wait;    /* wait for channel disconnect */
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_ci	/* kthread management related fields */
35062306a36Sopenharmony_ci
35162306a36Sopenharmony_ci	atomic_t kthreads_assigned;	/* #of kthreads assigned to channel */
35262306a36Sopenharmony_ci	u32 kthreads_assigned_limit;	/* limit on #of kthreads assigned */
35362306a36Sopenharmony_ci	atomic_t kthreads_idle;	/* #of kthreads idle waiting for work */
35462306a36Sopenharmony_ci	u32 kthreads_idle_limit;	/* limit on #of kthreads idle */
35562306a36Sopenharmony_ci	atomic_t kthreads_active;	/* #of kthreads actively working */
35662306a36Sopenharmony_ci
35762306a36Sopenharmony_ci	wait_queue_head_t idle_wq;	/* idle kthread wait queue */
35862306a36Sopenharmony_ci
35962306a36Sopenharmony_ci	union {
36062306a36Sopenharmony_ci		struct xpc_channel_uv uv;
36162306a36Sopenharmony_ci	} sn;
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_ci} ____cacheline_aligned;
36462306a36Sopenharmony_ci
36562306a36Sopenharmony_ci/* struct xpc_channel flags */
36662306a36Sopenharmony_ci
36762306a36Sopenharmony_ci#define	XPC_C_WASCONNECTED	0x00000001	/* channel was connected */
36862306a36Sopenharmony_ci
36962306a36Sopenharmony_ci#define XPC_C_ROPENCOMPLETE	0x00000002    /* remote open channel complete */
37062306a36Sopenharmony_ci#define XPC_C_OPENCOMPLETE	0x00000004     /* local open channel complete */
37162306a36Sopenharmony_ci#define	XPC_C_ROPENREPLY	0x00000008	/* remote open channel reply */
37262306a36Sopenharmony_ci#define	XPC_C_OPENREPLY		0x00000010	/* local open channel reply */
37362306a36Sopenharmony_ci#define	XPC_C_ROPENREQUEST	0x00000020     /* remote open channel request */
37462306a36Sopenharmony_ci#define	XPC_C_OPENREQUEST	0x00000040	/* local open channel request */
37562306a36Sopenharmony_ci
37662306a36Sopenharmony_ci#define	XPC_C_SETUP		0x00000080 /* channel's msgqueues are alloc'd */
37762306a36Sopenharmony_ci#define	XPC_C_CONNECTEDCALLOUT	0x00000100     /* connected callout initiated */
37862306a36Sopenharmony_ci#define	XPC_C_CONNECTEDCALLOUT_MADE \
37962306a36Sopenharmony_ci				0x00000200     /* connected callout completed */
38062306a36Sopenharmony_ci#define	XPC_C_CONNECTED		0x00000400	/* local channel is connected */
38162306a36Sopenharmony_ci#define	XPC_C_CONNECTING	0x00000800	/* channel is being connected */
38262306a36Sopenharmony_ci
38362306a36Sopenharmony_ci#define	XPC_C_RCLOSEREPLY	0x00001000	/* remote close channel reply */
38462306a36Sopenharmony_ci#define	XPC_C_CLOSEREPLY	0x00002000	/* local close channel reply */
38562306a36Sopenharmony_ci#define	XPC_C_RCLOSEREQUEST	0x00004000    /* remote close channel request */
38662306a36Sopenharmony_ci#define	XPC_C_CLOSEREQUEST	0x00008000     /* local close channel request */
38762306a36Sopenharmony_ci
38862306a36Sopenharmony_ci#define	XPC_C_DISCONNECTED	0x00010000	/* channel is disconnected */
38962306a36Sopenharmony_ci#define	XPC_C_DISCONNECTING	0x00020000   /* channel is being disconnected */
39062306a36Sopenharmony_ci#define	XPC_C_DISCONNECTINGCALLOUT \
39162306a36Sopenharmony_ci				0x00040000 /* disconnecting callout initiated */
39262306a36Sopenharmony_ci#define	XPC_C_DISCONNECTINGCALLOUT_MADE \
39362306a36Sopenharmony_ci				0x00080000 /* disconnecting callout completed */
39462306a36Sopenharmony_ci#define	XPC_C_WDISCONNECT	0x00100000  /* waiting for channel disconnect */
39562306a36Sopenharmony_ci
39662306a36Sopenharmony_ci/*
39762306a36Sopenharmony_ci * The channel control flags (chctl) union consists of a 64-bit variable which
39862306a36Sopenharmony_ci * is divided up into eight bytes, ordered from right to left. Byte zero
39962306a36Sopenharmony_ci * pertains to channel 0, byte one to channel 1, and so on. Each channel's byte
40062306a36Sopenharmony_ci * can have one or more of the chctl flags set in it.
40162306a36Sopenharmony_ci */
40262306a36Sopenharmony_ci
40362306a36Sopenharmony_ciunion xpc_channel_ctl_flags {
40462306a36Sopenharmony_ci	u64 all_flags;
40562306a36Sopenharmony_ci	u8 flags[XPC_MAX_NCHANNELS];
40662306a36Sopenharmony_ci};
40762306a36Sopenharmony_ci
40862306a36Sopenharmony_ci/* chctl flags */
40962306a36Sopenharmony_ci#define	XPC_CHCTL_CLOSEREQUEST	0x01
41062306a36Sopenharmony_ci#define	XPC_CHCTL_CLOSEREPLY	0x02
41162306a36Sopenharmony_ci#define	XPC_CHCTL_OPENREQUEST	0x04
41262306a36Sopenharmony_ci#define	XPC_CHCTL_OPENREPLY	0x08
41362306a36Sopenharmony_ci#define XPC_CHCTL_OPENCOMPLETE	0x10
41462306a36Sopenharmony_ci#define	XPC_CHCTL_MSGREQUEST	0x20
41562306a36Sopenharmony_ci
41662306a36Sopenharmony_ci#define XPC_OPENCLOSE_CHCTL_FLAGS \
41762306a36Sopenharmony_ci			(XPC_CHCTL_CLOSEREQUEST | XPC_CHCTL_CLOSEREPLY | \
41862306a36Sopenharmony_ci			 XPC_CHCTL_OPENREQUEST | XPC_CHCTL_OPENREPLY | \
41962306a36Sopenharmony_ci			 XPC_CHCTL_OPENCOMPLETE)
42062306a36Sopenharmony_ci#define XPC_MSG_CHCTL_FLAGS	XPC_CHCTL_MSGREQUEST
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_cistatic inline int
42362306a36Sopenharmony_cixpc_any_openclose_chctl_flags_set(union xpc_channel_ctl_flags *chctl)
42462306a36Sopenharmony_ci{
42562306a36Sopenharmony_ci	int ch_number;
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_ci	for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) {
42862306a36Sopenharmony_ci		if (chctl->flags[ch_number] & XPC_OPENCLOSE_CHCTL_FLAGS)
42962306a36Sopenharmony_ci			return 1;
43062306a36Sopenharmony_ci	}
43162306a36Sopenharmony_ci	return 0;
43262306a36Sopenharmony_ci}
43362306a36Sopenharmony_ci
43462306a36Sopenharmony_cistatic inline int
43562306a36Sopenharmony_cixpc_any_msg_chctl_flags_set(union xpc_channel_ctl_flags *chctl)
43662306a36Sopenharmony_ci{
43762306a36Sopenharmony_ci	int ch_number;
43862306a36Sopenharmony_ci
43962306a36Sopenharmony_ci	for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) {
44062306a36Sopenharmony_ci		if (chctl->flags[ch_number] & XPC_MSG_CHCTL_FLAGS)
44162306a36Sopenharmony_ci			return 1;
44262306a36Sopenharmony_ci	}
44362306a36Sopenharmony_ci	return 0;
44462306a36Sopenharmony_ci}
44562306a36Sopenharmony_ci
44662306a36Sopenharmony_cistruct xpc_partition_uv {
44762306a36Sopenharmony_ci	unsigned long heartbeat_gpa; /* phys addr of partition's heartbeat */
44862306a36Sopenharmony_ci	struct xpc_heartbeat_uv cached_heartbeat; /* cached copy of */
44962306a36Sopenharmony_ci						  /* partition's heartbeat */
45062306a36Sopenharmony_ci	unsigned long activate_gru_mq_desc_gpa;	/* phys addr of parititon's */
45162306a36Sopenharmony_ci						/* activate mq's gru mq */
45262306a36Sopenharmony_ci						/* descriptor */
45362306a36Sopenharmony_ci	void *cached_activate_gru_mq_desc; /* cached copy of partition's */
45462306a36Sopenharmony_ci					   /* activate mq's gru mq descriptor */
45562306a36Sopenharmony_ci	struct mutex cached_activate_gru_mq_desc_mutex;
45662306a36Sopenharmony_ci	spinlock_t flags_lock;	/* protect updating of flags */
45762306a36Sopenharmony_ci	unsigned int flags;	/* general flags */
45862306a36Sopenharmony_ci	u8 remote_act_state;	/* remote partition's act_state */
45962306a36Sopenharmony_ci	u8 act_state_req;	/* act_state request from remote partition */
46062306a36Sopenharmony_ci	enum xp_retval reason;	/* reason for deactivate act_state request */
46162306a36Sopenharmony_ci};
46262306a36Sopenharmony_ci
46362306a36Sopenharmony_ci/* struct xpc_partition_uv flags */
46462306a36Sopenharmony_ci
46562306a36Sopenharmony_ci#define XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV	0x00000001
46662306a36Sopenharmony_ci#define XPC_P_ENGAGED_UV			0x00000002
46762306a36Sopenharmony_ci
46862306a36Sopenharmony_ci/* struct xpc_partition_uv act_state change requests */
46962306a36Sopenharmony_ci
47062306a36Sopenharmony_ci#define XPC_P_ASR_ACTIVATE_UV		0x01
47162306a36Sopenharmony_ci#define XPC_P_ASR_REACTIVATE_UV		0x02
47262306a36Sopenharmony_ci#define XPC_P_ASR_DEACTIVATE_UV		0x03
47362306a36Sopenharmony_ci
47462306a36Sopenharmony_cistruct xpc_partition {
47562306a36Sopenharmony_ci
47662306a36Sopenharmony_ci	/* XPC HB infrastructure */
47762306a36Sopenharmony_ci
47862306a36Sopenharmony_ci	u8 remote_rp_version;	/* version# of partition's rsvd pg */
47962306a36Sopenharmony_ci	unsigned long remote_rp_ts_jiffies; /* timestamp when rsvd pg setup */
48062306a36Sopenharmony_ci	unsigned long remote_rp_pa;	/* phys addr of partition's rsvd pg */
48162306a36Sopenharmony_ci	u64 last_heartbeat;	/* HB at last read */
48262306a36Sopenharmony_ci	u32 activate_IRQ_rcvd;	/* IRQs since activation */
48362306a36Sopenharmony_ci	spinlock_t act_lock;	/* protect updating of act_state */
48462306a36Sopenharmony_ci	u8 act_state;		/* from XPC HB viewpoint */
48562306a36Sopenharmony_ci	enum xp_retval reason;	/* reason partition is deactivating */
48662306a36Sopenharmony_ci	int reason_line;	/* line# deactivation initiated from */
48762306a36Sopenharmony_ci
48862306a36Sopenharmony_ci	unsigned long disengage_timeout;	/* timeout in jiffies */
48962306a36Sopenharmony_ci	struct timer_list disengage_timer;
49062306a36Sopenharmony_ci
49162306a36Sopenharmony_ci	/* XPC infrastructure referencing and teardown control */
49262306a36Sopenharmony_ci
49362306a36Sopenharmony_ci	u8 setup_state;		/* infrastructure setup state */
49462306a36Sopenharmony_ci	wait_queue_head_t teardown_wq;	/* kthread waiting to teardown infra */
49562306a36Sopenharmony_ci	atomic_t references;	/* #of references to infrastructure */
49662306a36Sopenharmony_ci
49762306a36Sopenharmony_ci	u8 nchannels;		/* #of defined channels supported */
49862306a36Sopenharmony_ci	atomic_t nchannels_active;  /* #of channels that are not DISCONNECTED */
49962306a36Sopenharmony_ci	atomic_t nchannels_engaged;  /* #of channels engaged with remote part */
50062306a36Sopenharmony_ci	struct xpc_channel *channels;	/* array of channel structures */
50162306a36Sopenharmony_ci
50262306a36Sopenharmony_ci	/* fields used for managing channel avialability and activity */
50362306a36Sopenharmony_ci
50462306a36Sopenharmony_ci	union xpc_channel_ctl_flags chctl; /* chctl flags yet to be processed */
50562306a36Sopenharmony_ci	spinlock_t chctl_lock;	/* chctl flags lock */
50662306a36Sopenharmony_ci
50762306a36Sopenharmony_ci	void *remote_openclose_args_base;  /* base address of kmalloc'd space */
50862306a36Sopenharmony_ci	struct xpc_openclose_args *remote_openclose_args; /* copy of remote's */
50962306a36Sopenharmony_ci							  /* args */
51062306a36Sopenharmony_ci
51162306a36Sopenharmony_ci	/* channel manager related fields */
51262306a36Sopenharmony_ci
51362306a36Sopenharmony_ci	atomic_t channel_mgr_requests;	/* #of requests to activate chan mgr */
51462306a36Sopenharmony_ci	wait_queue_head_t channel_mgr_wq;	/* channel mgr's wait queue */
51562306a36Sopenharmony_ci
51662306a36Sopenharmony_ci	union {
51762306a36Sopenharmony_ci		struct xpc_partition_uv uv;
51862306a36Sopenharmony_ci	} sn;
51962306a36Sopenharmony_ci
52062306a36Sopenharmony_ci} ____cacheline_aligned;
52162306a36Sopenharmony_ci
52262306a36Sopenharmony_cistruct xpc_arch_operations {
52362306a36Sopenharmony_ci	int (*setup_partitions) (void);
52462306a36Sopenharmony_ci	void (*teardown_partitions) (void);
52562306a36Sopenharmony_ci	void (*process_activate_IRQ_rcvd) (void);
52662306a36Sopenharmony_ci	enum xp_retval (*get_partition_rsvd_page_pa)
52762306a36Sopenharmony_ci		(void *, u64 *, unsigned long *, size_t *);
52862306a36Sopenharmony_ci	int (*setup_rsvd_page) (struct xpc_rsvd_page *);
52962306a36Sopenharmony_ci
53062306a36Sopenharmony_ci	void (*allow_hb) (short);
53162306a36Sopenharmony_ci	void (*disallow_hb) (short);
53262306a36Sopenharmony_ci	void (*disallow_all_hbs) (void);
53362306a36Sopenharmony_ci	void (*increment_heartbeat) (void);
53462306a36Sopenharmony_ci	void (*offline_heartbeat) (void);
53562306a36Sopenharmony_ci	void (*online_heartbeat) (void);
53662306a36Sopenharmony_ci	void (*heartbeat_init) (void);
53762306a36Sopenharmony_ci	void (*heartbeat_exit) (void);
53862306a36Sopenharmony_ci	enum xp_retval (*get_remote_heartbeat) (struct xpc_partition *);
53962306a36Sopenharmony_ci
54062306a36Sopenharmony_ci	void (*request_partition_activation) (struct xpc_rsvd_page *,
54162306a36Sopenharmony_ci						 unsigned long, int);
54262306a36Sopenharmony_ci	void (*request_partition_reactivation) (struct xpc_partition *);
54362306a36Sopenharmony_ci	void (*request_partition_deactivation) (struct xpc_partition *);
54462306a36Sopenharmony_ci	void (*cancel_partition_deactivation_request) (struct xpc_partition *);
54562306a36Sopenharmony_ci	enum xp_retval (*setup_ch_structures) (struct xpc_partition *);
54662306a36Sopenharmony_ci	void (*teardown_ch_structures) (struct xpc_partition *);
54762306a36Sopenharmony_ci
54862306a36Sopenharmony_ci	enum xp_retval (*make_first_contact) (struct xpc_partition *);
54962306a36Sopenharmony_ci
55062306a36Sopenharmony_ci	u64 (*get_chctl_all_flags) (struct xpc_partition *);
55162306a36Sopenharmony_ci	void (*send_chctl_closerequest) (struct xpc_channel *, unsigned long *);
55262306a36Sopenharmony_ci	void (*send_chctl_closereply) (struct xpc_channel *, unsigned long *);
55362306a36Sopenharmony_ci	void (*send_chctl_openrequest) (struct xpc_channel *, unsigned long *);
55462306a36Sopenharmony_ci	void (*send_chctl_openreply) (struct xpc_channel *, unsigned long *);
55562306a36Sopenharmony_ci	void (*send_chctl_opencomplete) (struct xpc_channel *, unsigned long *);
55662306a36Sopenharmony_ci	void (*process_msg_chctl_flags) (struct xpc_partition *, int);
55762306a36Sopenharmony_ci
55862306a36Sopenharmony_ci	enum xp_retval (*save_remote_msgqueue_pa) (struct xpc_channel *,
55962306a36Sopenharmony_ci						      unsigned long);
56062306a36Sopenharmony_ci
56162306a36Sopenharmony_ci	enum xp_retval (*setup_msg_structures) (struct xpc_channel *);
56262306a36Sopenharmony_ci	void (*teardown_msg_structures) (struct xpc_channel *);
56362306a36Sopenharmony_ci
56462306a36Sopenharmony_ci	void (*indicate_partition_engaged) (struct xpc_partition *);
56562306a36Sopenharmony_ci	void (*indicate_partition_disengaged) (struct xpc_partition *);
56662306a36Sopenharmony_ci	void (*assume_partition_disengaged) (short);
56762306a36Sopenharmony_ci	int (*partition_engaged) (short);
56862306a36Sopenharmony_ci	int (*any_partition_engaged) (void);
56962306a36Sopenharmony_ci
57062306a36Sopenharmony_ci	int (*n_of_deliverable_payloads) (struct xpc_channel *);
57162306a36Sopenharmony_ci	enum xp_retval (*send_payload) (struct xpc_channel *, u32, void *,
57262306a36Sopenharmony_ci					   u16, u8, xpc_notify_func, void *);
57362306a36Sopenharmony_ci	void *(*get_deliverable_payload) (struct xpc_channel *);
57462306a36Sopenharmony_ci	void (*received_payload) (struct xpc_channel *, void *);
57562306a36Sopenharmony_ci	void (*notify_senders_of_disconnect) (struct xpc_channel *);
57662306a36Sopenharmony_ci};
57762306a36Sopenharmony_ci
57862306a36Sopenharmony_ci/* struct xpc_partition act_state values (for XPC HB) */
57962306a36Sopenharmony_ci
58062306a36Sopenharmony_ci#define	XPC_P_AS_INACTIVE	0x00	/* partition is not active */
58162306a36Sopenharmony_ci#define XPC_P_AS_ACTIVATION_REQ	0x01	/* created thread to activate */
58262306a36Sopenharmony_ci#define XPC_P_AS_ACTIVATING	0x02	/* activation thread started */
58362306a36Sopenharmony_ci#define XPC_P_AS_ACTIVE		0x03	/* xpc_partition_up() was called */
58462306a36Sopenharmony_ci#define XPC_P_AS_DEACTIVATING	0x04	/* partition deactivation initiated */
58562306a36Sopenharmony_ci
58662306a36Sopenharmony_ci#define XPC_DEACTIVATE_PARTITION(_p, _reason) \
58762306a36Sopenharmony_ci			xpc_deactivate_partition(__LINE__, (_p), (_reason))
58862306a36Sopenharmony_ci
58962306a36Sopenharmony_ci/* struct xpc_partition setup_state values */
59062306a36Sopenharmony_ci
59162306a36Sopenharmony_ci#define XPC_P_SS_UNSET		0x00	/* infrastructure was never setup */
59262306a36Sopenharmony_ci#define XPC_P_SS_SETUP		0x01	/* infrastructure is setup */
59362306a36Sopenharmony_ci#define XPC_P_SS_WTEARDOWN	0x02	/* waiting to teardown infrastructure */
59462306a36Sopenharmony_ci#define XPC_P_SS_TORNDOWN	0x03	/* infrastructure is torndown */
59562306a36Sopenharmony_ci
59662306a36Sopenharmony_ci/* number of seconds to wait for other partitions to disengage */
59762306a36Sopenharmony_ci#define XPC_DISENGAGE_DEFAULT_TIMELIMIT		90
59862306a36Sopenharmony_ci
59962306a36Sopenharmony_ci/* interval in seconds to print 'waiting deactivation' messages */
60062306a36Sopenharmony_ci#define XPC_DEACTIVATE_PRINTMSG_INTERVAL	10
60162306a36Sopenharmony_ci
60262306a36Sopenharmony_ci#define XPC_PARTID(_p)	((short)((_p) - &xpc_partitions[0]))
60362306a36Sopenharmony_ci
60462306a36Sopenharmony_ci/* found in xp_main.c */
60562306a36Sopenharmony_ciextern struct xpc_registration xpc_registrations[];
60662306a36Sopenharmony_ci
60762306a36Sopenharmony_ci/* found in xpc_main.c */
60862306a36Sopenharmony_ciextern struct device *xpc_part;
60962306a36Sopenharmony_ciextern struct device *xpc_chan;
61062306a36Sopenharmony_ciextern struct xpc_arch_operations xpc_arch_ops;
61162306a36Sopenharmony_ciextern int xpc_disengage_timelimit;
61262306a36Sopenharmony_ciextern int xpc_disengage_timedout;
61362306a36Sopenharmony_ciextern int xpc_activate_IRQ_rcvd;
61462306a36Sopenharmony_ciextern spinlock_t xpc_activate_IRQ_rcvd_lock;
61562306a36Sopenharmony_ciextern wait_queue_head_t xpc_activate_IRQ_wq;
61662306a36Sopenharmony_ciextern void *xpc_kzalloc_cacheline_aligned(size_t, gfp_t, void **);
61762306a36Sopenharmony_ciextern void xpc_activate_partition(struct xpc_partition *);
61862306a36Sopenharmony_ciextern void xpc_activate_kthreads(struct xpc_channel *, int);
61962306a36Sopenharmony_ciextern void xpc_create_kthreads(struct xpc_channel *, int, int);
62062306a36Sopenharmony_ciextern void xpc_disconnect_wait(int);
62162306a36Sopenharmony_ci
62262306a36Sopenharmony_ci/* found in xpc_uv.c */
62362306a36Sopenharmony_ciextern int xpc_init_uv(void);
62462306a36Sopenharmony_ciextern void xpc_exit_uv(void);
62562306a36Sopenharmony_ci
62662306a36Sopenharmony_ci/* found in xpc_partition.c */
62762306a36Sopenharmony_ciextern int xpc_exiting;
62862306a36Sopenharmony_ciextern int xpc_nasid_mask_nlongs;
62962306a36Sopenharmony_ciextern struct xpc_rsvd_page *xpc_rsvd_page;
63062306a36Sopenharmony_ciextern unsigned long *xpc_mach_nasids;
63162306a36Sopenharmony_ciextern struct xpc_partition *xpc_partitions;
63262306a36Sopenharmony_ciextern void *xpc_kmalloc_cacheline_aligned(size_t, gfp_t, void **);
63362306a36Sopenharmony_ciextern int xpc_setup_rsvd_page(void);
63462306a36Sopenharmony_ciextern void xpc_teardown_rsvd_page(void);
63562306a36Sopenharmony_ciextern int xpc_identify_activate_IRQ_sender(void);
63662306a36Sopenharmony_ciextern int xpc_partition_disengaged(struct xpc_partition *);
63762306a36Sopenharmony_ciextern int xpc_partition_disengaged_from_timer(struct xpc_partition *part);
63862306a36Sopenharmony_ciextern enum xp_retval xpc_mark_partition_active(struct xpc_partition *);
63962306a36Sopenharmony_ciextern void xpc_mark_partition_inactive(struct xpc_partition *);
64062306a36Sopenharmony_ciextern void xpc_discovery(void);
64162306a36Sopenharmony_ciextern enum xp_retval xpc_get_remote_rp(int, unsigned long *,
64262306a36Sopenharmony_ci					struct xpc_rsvd_page *,
64362306a36Sopenharmony_ci					unsigned long *);
64462306a36Sopenharmony_ciextern void xpc_deactivate_partition(const int, struct xpc_partition *,
64562306a36Sopenharmony_ci				     enum xp_retval);
64662306a36Sopenharmony_ciextern enum xp_retval xpc_initiate_partid_to_nasids(short, void *);
64762306a36Sopenharmony_ci
64862306a36Sopenharmony_ci/* found in xpc_channel.c */
64962306a36Sopenharmony_ciextern void xpc_initiate_connect(int);
65062306a36Sopenharmony_ciextern void xpc_initiate_disconnect(int);
65162306a36Sopenharmony_ciextern enum xp_retval xpc_allocate_msg_wait(struct xpc_channel *);
65262306a36Sopenharmony_ciextern enum xp_retval xpc_initiate_send(short, int, u32, void *, u16);
65362306a36Sopenharmony_ciextern enum xp_retval xpc_initiate_send_notify(short, int, u32, void *, u16,
65462306a36Sopenharmony_ci					       xpc_notify_func, void *);
65562306a36Sopenharmony_ciextern void xpc_initiate_received(short, int, void *);
65662306a36Sopenharmony_ciextern void xpc_process_sent_chctl_flags(struct xpc_partition *);
65762306a36Sopenharmony_ciextern void xpc_connected_callout(struct xpc_channel *);
65862306a36Sopenharmony_ciextern void xpc_deliver_payload(struct xpc_channel *);
65962306a36Sopenharmony_ciextern void xpc_disconnect_channel(const int, struct xpc_channel *,
66062306a36Sopenharmony_ci				   enum xp_retval, unsigned long *);
66162306a36Sopenharmony_ciextern void xpc_disconnect_callout(struct xpc_channel *, enum xp_retval);
66262306a36Sopenharmony_ciextern void xpc_partition_going_down(struct xpc_partition *, enum xp_retval);
66362306a36Sopenharmony_ci
66462306a36Sopenharmony_cistatic inline void
66562306a36Sopenharmony_cixpc_wakeup_channel_mgr(struct xpc_partition *part)
66662306a36Sopenharmony_ci{
66762306a36Sopenharmony_ci	if (atomic_inc_return(&part->channel_mgr_requests) == 1)
66862306a36Sopenharmony_ci		wake_up(&part->channel_mgr_wq);
66962306a36Sopenharmony_ci}
67062306a36Sopenharmony_ci
67162306a36Sopenharmony_ci/*
67262306a36Sopenharmony_ci * These next two inlines are used to keep us from tearing down a channel's
67362306a36Sopenharmony_ci * msg queues while a thread may be referencing them.
67462306a36Sopenharmony_ci */
67562306a36Sopenharmony_cistatic inline void
67662306a36Sopenharmony_cixpc_msgqueue_ref(struct xpc_channel *ch)
67762306a36Sopenharmony_ci{
67862306a36Sopenharmony_ci	atomic_inc(&ch->references);
67962306a36Sopenharmony_ci}
68062306a36Sopenharmony_ci
68162306a36Sopenharmony_cistatic inline void
68262306a36Sopenharmony_cixpc_msgqueue_deref(struct xpc_channel *ch)
68362306a36Sopenharmony_ci{
68462306a36Sopenharmony_ci	s32 refs = atomic_dec_return(&ch->references);
68562306a36Sopenharmony_ci
68662306a36Sopenharmony_ci	DBUG_ON(refs < 0);
68762306a36Sopenharmony_ci	if (refs == 0)
68862306a36Sopenharmony_ci		xpc_wakeup_channel_mgr(&xpc_partitions[ch->partid]);
68962306a36Sopenharmony_ci}
69062306a36Sopenharmony_ci
69162306a36Sopenharmony_ci#define XPC_DISCONNECT_CHANNEL(_ch, _reason, _irqflgs) \
69262306a36Sopenharmony_ci		xpc_disconnect_channel(__LINE__, _ch, _reason, _irqflgs)
69362306a36Sopenharmony_ci
69462306a36Sopenharmony_ci/*
69562306a36Sopenharmony_ci * These two inlines are used to keep us from tearing down a partition's
69662306a36Sopenharmony_ci * setup infrastructure while a thread may be referencing it.
69762306a36Sopenharmony_ci */
69862306a36Sopenharmony_cistatic inline void
69962306a36Sopenharmony_cixpc_part_deref(struct xpc_partition *part)
70062306a36Sopenharmony_ci{
70162306a36Sopenharmony_ci	s32 refs = atomic_dec_return(&part->references);
70262306a36Sopenharmony_ci
70362306a36Sopenharmony_ci	DBUG_ON(refs < 0);
70462306a36Sopenharmony_ci	if (refs == 0 && part->setup_state == XPC_P_SS_WTEARDOWN)
70562306a36Sopenharmony_ci		wake_up(&part->teardown_wq);
70662306a36Sopenharmony_ci}
70762306a36Sopenharmony_ci
70862306a36Sopenharmony_cistatic inline int
70962306a36Sopenharmony_cixpc_part_ref(struct xpc_partition *part)
71062306a36Sopenharmony_ci{
71162306a36Sopenharmony_ci	int setup;
71262306a36Sopenharmony_ci
71362306a36Sopenharmony_ci	atomic_inc(&part->references);
71462306a36Sopenharmony_ci	setup = (part->setup_state == XPC_P_SS_SETUP);
71562306a36Sopenharmony_ci	if (!setup)
71662306a36Sopenharmony_ci		xpc_part_deref(part);
71762306a36Sopenharmony_ci
71862306a36Sopenharmony_ci	return setup;
71962306a36Sopenharmony_ci}
72062306a36Sopenharmony_ci
72162306a36Sopenharmony_ci/*
72262306a36Sopenharmony_ci * The following macro is to be used for the setting of the reason and
72362306a36Sopenharmony_ci * reason_line fields in both the struct xpc_channel and struct xpc_partition
72462306a36Sopenharmony_ci * structures.
72562306a36Sopenharmony_ci */
72662306a36Sopenharmony_ci#define XPC_SET_REASON(_p, _reason, _line) \
72762306a36Sopenharmony_ci	{ \
72862306a36Sopenharmony_ci		(_p)->reason = _reason; \
72962306a36Sopenharmony_ci		(_p)->reason_line = _line; \
73062306a36Sopenharmony_ci	}
73162306a36Sopenharmony_ci
73262306a36Sopenharmony_ci#endif /* _DRIVERS_MISC_SGIXP_XPC_H */
733