^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * License. See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2004-2009 Silicon Graphics, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Cross Partition Communication (XPC) structures and macros.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #ifndef _DRIVERS_MISC_SGIXP_XPC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define _DRIVERS_MISC_SGIXP_XPC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "xp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * XPC Version numbers consist of a major and minor number. XPC can always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * talk to versions with same major #, and never talk to versions with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * different major #.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define _XPC_VERSION(_maj, _min) (((_maj) << 4) | ((_min) & 0xf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define XPC_VERSION_MAJOR(_v) ((_v) >> 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define XPC_VERSION_MINOR(_v) ((_v) & 0xf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /* define frequency of the heartbeat and frequency how often it's checked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define XPC_HB_DEFAULT_INTERVAL 5 /* incr HB every x secs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define XPC_HB_CHECK_DEFAULT_INTERVAL 20 /* check HB every x secs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* define the process name of HB checker and the CPU it is pinned to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define XPC_HB_CHECK_THREAD_NAME "xpc_hb"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define XPC_HB_CHECK_CPU 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* define the process name of the discovery thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define XPC_DISCOVERY_THREAD_NAME "xpc_discovery"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * the reserved page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * SAL reserves one page of memory per partition for XPC. Though a full page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * in length (16384 bytes), its starting address is not page aligned, but it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * is cacheline aligned. The reserved page consists of the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * reserved page header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * The first two 64-byte cachelines of the reserved page contain the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * header (struct xpc_rsvd_page). Before SAL initialization has completed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * SAL has set up the following fields of the reserved page header:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * SAL_signature, SAL_version, SAL_partid, and SAL_nasids_size. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * other fields are set up by XPC. (xpc_rsvd_page points to the local
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * partition's reserved page.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * part_nasids mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * mach_nasids mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * SAL also sets up two bitmaps (or masks), one that reflects the actual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * nasids in this partition (part_nasids), and the other that reflects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * the actual nasids in the entire machine (mach_nasids). We're only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * interested in the even numbered nasids (which contain the processors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * and/or memory), so we only need half as many bits to represent the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * nasids. When mapping nasid to bit in a mask (or bit to nasid) be sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * to either divide or multiply by 2. The part_nasids mask is located
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * starting at the first cacheline following the reserved page header. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * mach_nasids mask follows right after the part_nasids mask. The size in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * bytes of each mask is reflected by the reserved page header field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * 'SAL_nasids_size'. (Local partition's mask pointers are xpc_part_nasids
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * and xpc_mach_nasids.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * Immediately following the mach_nasids mask are the XPC variables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * required by other partitions. First are those that are generic to all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * partitions (vars), followed on the next available cacheline by those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * which are partition specific (vars part). These are setup by XPC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * Note: Until 'ts_jiffies' is set non-zero, the partition XPC code has not been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct xpc_rsvd_page {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) u64 SAL_signature; /* SAL: unique signature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) u64 SAL_version; /* SAL: version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) short SAL_partid; /* SAL: partition ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) short max_npartitions; /* value of XPC_MAX_PARTITIONS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u8 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u8 pad1[3]; /* align to next u64 in 1st 64-byte cacheline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) unsigned long ts_jiffies; /* timestamp when rsvd pg was setup by XPC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) unsigned long heartbeat_gpa; /* phys addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) unsigned long activate_gru_mq_desc_gpa; /* phys addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) } uv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) } sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) u64 pad2[9]; /* align to last u64 in 2nd 64-byte cacheline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) u64 SAL_nasids_size; /* SAL: size of each nasid mask in bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define XPC_RP_VERSION _XPC_VERSION(3, 0) /* version 3.0 of the reserved page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* the reserved page sizes and offsets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define XPC_RP_HEADER_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define XPC_RP_PART_NASIDS(_rp) ((unsigned long *)((u8 *)(_rp) + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) XPC_RP_HEADER_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define XPC_RP_MACH_NASIDS(_rp) (XPC_RP_PART_NASIDS(_rp) + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) xpc_nasid_mask_nlongs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * The following structure describes the partition's heartbeat info which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * will be periodically read by other partitions to determine whether this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * XPC is still 'alive'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct xpc_heartbeat_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) unsigned long offline; /* if 0, heartbeat should be changing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * Info pertinent to a GRU message queue using a watch list for irq generation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct xpc_gru_mq_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) void *address; /* address of GRU message queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) unsigned int order; /* size of GRU message queue as a power of 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) int irq; /* irq raised when message is received in mq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int mmr_blade; /* blade where watchlist was allocated from */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) unsigned long mmr_offset; /* offset of irq mmr located on mmr_blade */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) unsigned long mmr_value; /* value of irq mmr located on mmr_blade */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int watchlist_num; /* number of watchlist allocatd by BIOS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) void *gru_mq_desc; /* opaque structure used by the GRU driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * The activate_mq is used to send/receive GRU messages that affect XPC's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * partition active state and channel state. This is uv only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct xpc_activate_mq_msghdr_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) unsigned int gru_msg_hdr; /* FOR GRU INTERNAL USE ONLY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) short partid; /* sender's partid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) u8 act_state; /* sender's act_state at time msg sent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) u8 type; /* message's type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) unsigned long rp_ts_jiffies; /* timestamp of sender's rp setup by XPC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /* activate_mq defined message types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #define XPC_ACTIVATE_MQ_MSG_SYNC_ACT_STATE_UV 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #define XPC_ACTIVATE_MQ_MSG_ACTIVATE_REQ_UV 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #define XPC_ACTIVATE_MQ_MSG_DEACTIVATE_REQ_UV 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #define XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREQUEST_UV 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #define XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREPLY_UV 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREQUEST_UV 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREPLY_UV 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENCOMPLETE_UV 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #define XPC_ACTIVATE_MQ_MSG_MARK_ENGAGED_UV 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #define XPC_ACTIVATE_MQ_MSG_MARK_DISENGAGED_UV 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct xpc_activate_mq_msg_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct xpc_activate_mq_msghdr_uv hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct xpc_activate_mq_msg_activate_req_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct xpc_activate_mq_msghdr_uv hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) unsigned long rp_gpa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) unsigned long heartbeat_gpa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) unsigned long activate_gru_mq_desc_gpa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct xpc_activate_mq_msg_deactivate_req_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct xpc_activate_mq_msghdr_uv hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) enum xp_retval reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct xpc_activate_mq_msg_chctl_closerequest_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct xpc_activate_mq_msghdr_uv hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) short ch_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) enum xp_retval reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct xpc_activate_mq_msg_chctl_closereply_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct xpc_activate_mq_msghdr_uv hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) short ch_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct xpc_activate_mq_msg_chctl_openrequest_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct xpc_activate_mq_msghdr_uv hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) short ch_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) short entry_size; /* size of notify_mq's GRU messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) short local_nentries; /* ??? Is this needed? What is? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct xpc_activate_mq_msg_chctl_openreply_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct xpc_activate_mq_msghdr_uv hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) short ch_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) short remote_nentries; /* ??? Is this needed? What is? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) short local_nentries; /* ??? Is this needed? What is? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) unsigned long notify_gru_mq_desc_gpa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct xpc_activate_mq_msg_chctl_opencomplete_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct xpc_activate_mq_msghdr_uv hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) short ch_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * Functions registered by add_timer() or called by kernel_thread() only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * allow for a single 64-bit argument. The following macros can be used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * pack and unpack two (32-bit, 16-bit or 8-bit) arguments into or out from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * the passed argument.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) #define XPC_PACK_ARGS(_arg1, _arg2) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) ((((u64)_arg1) & 0xffffffff) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) ((((u64)_arg2) & 0xffffffff) << 32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) #define XPC_UNPACK_ARG1(_args) (((u64)_args) & 0xffffffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #define XPC_UNPACK_ARG2(_args) ((((u64)_args) >> 32) & 0xffffffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * Define a structure that contains arguments associated with opening and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * closing a channel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct xpc_openclose_args {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) u16 reason; /* reason why channel is closing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) u16 entry_size; /* sizeof each message entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) u16 remote_nentries; /* #of message entries in remote msg queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) u16 local_nentries; /* #of message entries in local msg queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) unsigned long local_msgqueue_pa; /* phys addr of local message queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #define XPC_OPENCLOSE_ARGS_SIZE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) L1_CACHE_ALIGN(sizeof(struct xpc_openclose_args) * \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) XPC_MAX_NCHANNELS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * Structures to define a fifo singly-linked list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct xpc_fifo_entry_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct xpc_fifo_entry_uv *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct xpc_fifo_head_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct xpc_fifo_entry_uv *first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct xpc_fifo_entry_uv *last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int n_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * The format of a uv XPC notify_mq GRU message is as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * A user-defined message resides in the payload area. The max size of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * payload is defined by the user via xpc_connect().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * The size of a message (payload and header) sent via the GRU must be either 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * or 2 GRU_CACHE_LINE_BYTES in length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct xpc_notify_mq_msghdr_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) unsigned int gru_msg_hdr; /* FOR GRU INTERNAL USE ONLY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct xpc_fifo_entry_uv next; /* FOR XPC INTERNAL USE ONLY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) } u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) short partid; /* FOR XPC INTERNAL USE ONLY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) u8 ch_number; /* FOR XPC INTERNAL USE ONLY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) u8 size; /* FOR XPC INTERNAL USE ONLY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) unsigned int msg_slot_number; /* FOR XPC INTERNAL USE ONLY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct xpc_notify_mq_msg_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct xpc_notify_mq_msghdr_uv hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) unsigned long payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) /* struct xpc_notify_sn2 type of notification */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) #define XPC_N_CALL 0x01 /* notify function provided by user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * Define uv's version of the notify entry. It additionally is used to allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * a msg slot on the remote partition into which is copied a sent message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct xpc_send_msg_slot_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct xpc_fifo_entry_uv next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) unsigned int msg_slot_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) xpc_notify_func func; /* user's notify function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) void *key; /* pointer to user's key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * Define the structure that manages all the stuff required by a channel. In
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * particular, they are used to manage the messages sent across the channel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * This structure is private to a partition, and is NOT shared across the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * partition boundary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * There is an array of these structures for each remote partition. It is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * allocated at the time a partition becomes active. The array contains one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * of these structures for each potential channel connection to that partition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct xpc_channel_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) void *cached_notify_gru_mq_desc; /* remote partition's notify mq's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) /* gru mq descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct xpc_send_msg_slot_uv *send_msg_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) void *recv_msg_slots; /* each slot will hold a xpc_notify_mq_msg_uv */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) /* structure plus the user's payload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) struct xpc_fifo_head_uv msg_slot_free_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) struct xpc_fifo_head_uv recv_msg_list; /* deliverable payloads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct xpc_channel {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) short partid; /* ID of remote partition connected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) spinlock_t lock; /* lock for updating this structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) unsigned int flags; /* general flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) enum xp_retval reason; /* reason why channel is disconnect'g */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) int reason_line; /* line# disconnect initiated from */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) u16 number; /* channel # */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) u16 entry_size; /* sizeof each msg entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) u16 local_nentries; /* #of msg entries in local msg queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) u16 remote_nentries; /* #of msg entries in remote msg queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) atomic_t references; /* #of external references to queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) atomic_t n_on_msg_allocate_wq; /* #on msg allocation wait queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) wait_queue_head_t msg_allocate_wq; /* msg allocation wait queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) u8 delayed_chctl_flags; /* chctl flags received, but delayed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /* action until channel disconnected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) atomic_t n_to_notify; /* #of msg senders to notify */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) xpc_channel_func func; /* user's channel function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) void *key; /* pointer to user's key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct completion wdisconnect_wait; /* wait for channel disconnect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /* kthread management related fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) atomic_t kthreads_assigned; /* #of kthreads assigned to channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) u32 kthreads_assigned_limit; /* limit on #of kthreads assigned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) atomic_t kthreads_idle; /* #of kthreads idle waiting for work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) u32 kthreads_idle_limit; /* limit on #of kthreads idle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) atomic_t kthreads_active; /* #of kthreads actively working */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) wait_queue_head_t idle_wq; /* idle kthread wait queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) struct xpc_channel_uv uv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) } sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) } ____cacheline_aligned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /* struct xpc_channel flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) #define XPC_C_WASCONNECTED 0x00000001 /* channel was connected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) #define XPC_C_ROPENCOMPLETE 0x00000002 /* remote open channel complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) #define XPC_C_OPENCOMPLETE 0x00000004 /* local open channel complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) #define XPC_C_ROPENREPLY 0x00000008 /* remote open channel reply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) #define XPC_C_OPENREPLY 0x00000010 /* local open channel reply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) #define XPC_C_ROPENREQUEST 0x00000020 /* remote open channel request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) #define XPC_C_OPENREQUEST 0x00000040 /* local open channel request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) #define XPC_C_SETUP 0x00000080 /* channel's msgqueues are alloc'd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) #define XPC_C_CONNECTEDCALLOUT 0x00000100 /* connected callout initiated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) #define XPC_C_CONNECTEDCALLOUT_MADE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 0x00000200 /* connected callout completed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) #define XPC_C_CONNECTED 0x00000400 /* local channel is connected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) #define XPC_C_CONNECTING 0x00000800 /* channel is being connected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) #define XPC_C_RCLOSEREPLY 0x00001000 /* remote close channel reply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) #define XPC_C_CLOSEREPLY 0x00002000 /* local close channel reply */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) #define XPC_C_RCLOSEREQUEST 0x00004000 /* remote close channel request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) #define XPC_C_CLOSEREQUEST 0x00008000 /* local close channel request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) #define XPC_C_DISCONNECTED 0x00010000 /* channel is disconnected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) #define XPC_C_DISCONNECTING 0x00020000 /* channel is being disconnected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) #define XPC_C_DISCONNECTINGCALLOUT \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 0x00040000 /* disconnecting callout initiated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) #define XPC_C_DISCONNECTINGCALLOUT_MADE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 0x00080000 /* disconnecting callout completed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) #define XPC_C_WDISCONNECT 0x00100000 /* waiting for channel disconnect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * The channel control flags (chctl) union consists of a 64-bit variable which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * is divided up into eight bytes, ordered from right to left. Byte zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) * pertains to channel 0, byte one to channel 1, and so on. Each channel's byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) * can have one or more of the chctl flags set in it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) union xpc_channel_ctl_flags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) u64 all_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) u8 flags[XPC_MAX_NCHANNELS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) /* chctl flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) #define XPC_CHCTL_CLOSEREQUEST 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) #define XPC_CHCTL_CLOSEREPLY 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) #define XPC_CHCTL_OPENREQUEST 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) #define XPC_CHCTL_OPENREPLY 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) #define XPC_CHCTL_OPENCOMPLETE 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) #define XPC_CHCTL_MSGREQUEST 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) #define XPC_OPENCLOSE_CHCTL_FLAGS \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) (XPC_CHCTL_CLOSEREQUEST | XPC_CHCTL_CLOSEREPLY | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) XPC_CHCTL_OPENREQUEST | XPC_CHCTL_OPENREPLY | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) XPC_CHCTL_OPENCOMPLETE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) #define XPC_MSG_CHCTL_FLAGS XPC_CHCTL_MSGREQUEST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) xpc_any_openclose_chctl_flags_set(union xpc_channel_ctl_flags *chctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) int ch_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (chctl->flags[ch_number] & XPC_OPENCLOSE_CHCTL_FLAGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) xpc_any_msg_chctl_flags_set(union xpc_channel_ctl_flags *chctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) int ch_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (chctl->flags[ch_number] & XPC_MSG_CHCTL_FLAGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct xpc_partition_uv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) unsigned long heartbeat_gpa; /* phys addr of partition's heartbeat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) struct xpc_heartbeat_uv cached_heartbeat; /* cached copy of */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) /* partition's heartbeat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) unsigned long activate_gru_mq_desc_gpa; /* phys addr of parititon's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) /* activate mq's gru mq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) void *cached_activate_gru_mq_desc; /* cached copy of partition's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) /* activate mq's gru mq descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) struct mutex cached_activate_gru_mq_desc_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) spinlock_t flags_lock; /* protect updating of flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) unsigned int flags; /* general flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) u8 remote_act_state; /* remote partition's act_state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) u8 act_state_req; /* act_state request from remote partition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) enum xp_retval reason; /* reason for deactivate act_state request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) /* struct xpc_partition_uv flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) #define XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV 0x00000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) #define XPC_P_ENGAGED_UV 0x00000002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) /* struct xpc_partition_uv act_state change requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) #define XPC_P_ASR_ACTIVATE_UV 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) #define XPC_P_ASR_REACTIVATE_UV 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) #define XPC_P_ASR_DEACTIVATE_UV 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) struct xpc_partition {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) /* XPC HB infrastructure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) u8 remote_rp_version; /* version# of partition's rsvd pg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) unsigned long remote_rp_ts_jiffies; /* timestamp when rsvd pg setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) unsigned long remote_rp_pa; /* phys addr of partition's rsvd pg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) u64 last_heartbeat; /* HB at last read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) u32 activate_IRQ_rcvd; /* IRQs since activation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) spinlock_t act_lock; /* protect updating of act_state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) u8 act_state; /* from XPC HB viewpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) enum xp_retval reason; /* reason partition is deactivating */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) int reason_line; /* line# deactivation initiated from */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) unsigned long disengage_timeout; /* timeout in jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) struct timer_list disengage_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) /* XPC infrastructure referencing and teardown control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) u8 setup_state; /* infrastructure setup state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) wait_queue_head_t teardown_wq; /* kthread waiting to teardown infra */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) atomic_t references; /* #of references to infrastructure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) u8 nchannels; /* #of defined channels supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) atomic_t nchannels_active; /* #of channels that are not DISCONNECTED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) atomic_t nchannels_engaged; /* #of channels engaged with remote part */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) struct xpc_channel *channels; /* array of channel structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) /* fields used for managing channel avialability and activity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) union xpc_channel_ctl_flags chctl; /* chctl flags yet to be processed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) spinlock_t chctl_lock; /* chctl flags lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) void *remote_openclose_args_base; /* base address of kmalloc'd space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct xpc_openclose_args *remote_openclose_args; /* copy of remote's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) /* args */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) /* channel manager related fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) atomic_t channel_mgr_requests; /* #of requests to activate chan mgr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) wait_queue_head_t channel_mgr_wq; /* channel mgr's wait queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) struct xpc_partition_uv uv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) } sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) } ____cacheline_aligned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) struct xpc_arch_operations {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) int (*setup_partitions) (void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) void (*teardown_partitions) (void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) void (*process_activate_IRQ_rcvd) (void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) enum xp_retval (*get_partition_rsvd_page_pa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) (void *, u64 *, unsigned long *, size_t *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) int (*setup_rsvd_page) (struct xpc_rsvd_page *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) void (*allow_hb) (short);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) void (*disallow_hb) (short);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) void (*disallow_all_hbs) (void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) void (*increment_heartbeat) (void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) void (*offline_heartbeat) (void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) void (*online_heartbeat) (void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) void (*heartbeat_init) (void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) void (*heartbeat_exit) (void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) enum xp_retval (*get_remote_heartbeat) (struct xpc_partition *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) void (*request_partition_activation) (struct xpc_rsvd_page *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) unsigned long, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) void (*request_partition_reactivation) (struct xpc_partition *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) void (*request_partition_deactivation) (struct xpc_partition *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) void (*cancel_partition_deactivation_request) (struct xpc_partition *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) enum xp_retval (*setup_ch_structures) (struct xpc_partition *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) void (*teardown_ch_structures) (struct xpc_partition *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) enum xp_retval (*make_first_contact) (struct xpc_partition *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) u64 (*get_chctl_all_flags) (struct xpc_partition *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) void (*send_chctl_closerequest) (struct xpc_channel *, unsigned long *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) void (*send_chctl_closereply) (struct xpc_channel *, unsigned long *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) void (*send_chctl_openrequest) (struct xpc_channel *, unsigned long *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) void (*send_chctl_openreply) (struct xpc_channel *, unsigned long *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) void (*send_chctl_opencomplete) (struct xpc_channel *, unsigned long *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) void (*process_msg_chctl_flags) (struct xpc_partition *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) enum xp_retval (*save_remote_msgqueue_pa) (struct xpc_channel *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) enum xp_retval (*setup_msg_structures) (struct xpc_channel *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) void (*teardown_msg_structures) (struct xpc_channel *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) void (*indicate_partition_engaged) (struct xpc_partition *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) void (*indicate_partition_disengaged) (struct xpc_partition *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) void (*assume_partition_disengaged) (short);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) int (*partition_engaged) (short);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) int (*any_partition_engaged) (void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) int (*n_of_deliverable_payloads) (struct xpc_channel *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) enum xp_retval (*send_payload) (struct xpc_channel *, u32, void *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) u16, u8, xpc_notify_func, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) void *(*get_deliverable_payload) (struct xpc_channel *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) void (*received_payload) (struct xpc_channel *, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) void (*notify_senders_of_disconnect) (struct xpc_channel *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) /* struct xpc_partition act_state values (for XPC HB) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) #define XPC_P_AS_INACTIVE 0x00 /* partition is not active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) #define XPC_P_AS_ACTIVATION_REQ 0x01 /* created thread to activate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) #define XPC_P_AS_ACTIVATING 0x02 /* activation thread started */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) #define XPC_P_AS_ACTIVE 0x03 /* xpc_partition_up() was called */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) #define XPC_P_AS_DEACTIVATING 0x04 /* partition deactivation initiated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) #define XPC_DEACTIVATE_PARTITION(_p, _reason) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) xpc_deactivate_partition(__LINE__, (_p), (_reason))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) /* struct xpc_partition setup_state values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) #define XPC_P_SS_UNSET 0x00 /* infrastructure was never setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) #define XPC_P_SS_SETUP 0x01 /* infrastructure is setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) #define XPC_P_SS_WTEARDOWN 0x02 /* waiting to teardown infrastructure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) #define XPC_P_SS_TORNDOWN 0x03 /* infrastructure is torndown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) /* number of seconds to wait for other partitions to disengage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) #define XPC_DISENGAGE_DEFAULT_TIMELIMIT 90
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) /* interval in seconds to print 'waiting deactivation' messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) #define XPC_DEACTIVATE_PRINTMSG_INTERVAL 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) #define XPC_PARTID(_p) ((short)((_p) - &xpc_partitions[0]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) /* found in xp_main.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) extern struct xpc_registration xpc_registrations[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) /* found in xpc_main.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) extern struct device *xpc_part;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) extern struct device *xpc_chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) extern struct xpc_arch_operations xpc_arch_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) extern int xpc_disengage_timelimit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) extern int xpc_disengage_timedout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) extern int xpc_activate_IRQ_rcvd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) extern spinlock_t xpc_activate_IRQ_rcvd_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) extern wait_queue_head_t xpc_activate_IRQ_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) extern void *xpc_kzalloc_cacheline_aligned(size_t, gfp_t, void **);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) extern void xpc_activate_partition(struct xpc_partition *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) extern void xpc_activate_kthreads(struct xpc_channel *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) extern void xpc_create_kthreads(struct xpc_channel *, int, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) extern void xpc_disconnect_wait(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) /* found in xpc_uv.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) extern int xpc_init_uv(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) extern void xpc_exit_uv(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) /* found in xpc_partition.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) extern int xpc_exiting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) extern int xpc_nasid_mask_nlongs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) extern struct xpc_rsvd_page *xpc_rsvd_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) extern unsigned long *xpc_mach_nasids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) extern struct xpc_partition *xpc_partitions;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) extern void *xpc_kmalloc_cacheline_aligned(size_t, gfp_t, void **);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) extern int xpc_setup_rsvd_page(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) extern void xpc_teardown_rsvd_page(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) extern int xpc_identify_activate_IRQ_sender(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) extern int xpc_partition_disengaged(struct xpc_partition *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) extern enum xp_retval xpc_mark_partition_active(struct xpc_partition *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) extern void xpc_mark_partition_inactive(struct xpc_partition *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) extern void xpc_discovery(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) extern enum xp_retval xpc_get_remote_rp(int, unsigned long *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) struct xpc_rsvd_page *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) unsigned long *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) extern void xpc_deactivate_partition(const int, struct xpc_partition *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) enum xp_retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) extern enum xp_retval xpc_initiate_partid_to_nasids(short, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) /* found in xpc_channel.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) extern void xpc_initiate_connect(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) extern void xpc_initiate_disconnect(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) extern enum xp_retval xpc_allocate_msg_wait(struct xpc_channel *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) extern enum xp_retval xpc_initiate_send(short, int, u32, void *, u16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) extern enum xp_retval xpc_initiate_send_notify(short, int, u32, void *, u16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) xpc_notify_func, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) extern void xpc_initiate_received(short, int, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) extern void xpc_process_sent_chctl_flags(struct xpc_partition *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) extern void xpc_connected_callout(struct xpc_channel *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) extern void xpc_deliver_payload(struct xpc_channel *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) extern void xpc_disconnect_channel(const int, struct xpc_channel *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) enum xp_retval, unsigned long *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) extern void xpc_disconnect_callout(struct xpc_channel *, enum xp_retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) extern void xpc_partition_going_down(struct xpc_partition *, enum xp_retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) xpc_wakeup_channel_mgr(struct xpc_partition *part)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) if (atomic_inc_return(&part->channel_mgr_requests) == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) wake_up(&part->channel_mgr_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) * These next two inlines are used to keep us from tearing down a channel's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) * msg queues while a thread may be referencing them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) xpc_msgqueue_ref(struct xpc_channel *ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) atomic_inc(&ch->references);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) xpc_msgqueue_deref(struct xpc_channel *ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) s32 refs = atomic_dec_return(&ch->references);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) DBUG_ON(refs < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) if (refs == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) xpc_wakeup_channel_mgr(&xpc_partitions[ch->partid]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) #define XPC_DISCONNECT_CHANNEL(_ch, _reason, _irqflgs) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) xpc_disconnect_channel(__LINE__, _ch, _reason, _irqflgs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) * These two inlines are used to keep us from tearing down a partition's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) * setup infrastructure while a thread may be referencing it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) xpc_part_deref(struct xpc_partition *part)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) s32 refs = atomic_dec_return(&part->references);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) DBUG_ON(refs < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) if (refs == 0 && part->setup_state == XPC_P_SS_WTEARDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) wake_up(&part->teardown_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) xpc_part_ref(struct xpc_partition *part)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) int setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) atomic_inc(&part->references);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) setup = (part->setup_state == XPC_P_SS_SETUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (!setup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) xpc_part_deref(part);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) return setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) * The following macro is to be used for the setting of the reason and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) * reason_line fields in both the struct xpc_channel and struct xpc_partition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) * structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) #define XPC_SET_REASON(_p, _reason, _line) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) (_p)->reason = _reason; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) (_p)->reason_line = _line; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) #endif /* _DRIVERS_MISC_SGIXP_XPC_H */