18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 38c2ecf20Sopenharmony_ci * License. See the file "COPYING" in the main directory of this archive 48c2ecf20Sopenharmony_ci * for more details. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (c) 2004-2009 Silicon Graphics, Inc. All Rights Reserved. 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci/* 108c2ecf20Sopenharmony_ci * Cross Partition Communication (XPC) structures and macros. 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#ifndef _DRIVERS_MISC_SGIXP_XPC_H 148c2ecf20Sopenharmony_ci#define _DRIVERS_MISC_SGIXP_XPC_H 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include <linux/wait.h> 178c2ecf20Sopenharmony_ci#include <linux/completion.h> 188c2ecf20Sopenharmony_ci#include <linux/timer.h> 198c2ecf20Sopenharmony_ci#include <linux/sched.h> 208c2ecf20Sopenharmony_ci#include "xp.h" 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* 238c2ecf20Sopenharmony_ci * XPC Version numbers consist of a major and minor number. XPC can always 248c2ecf20Sopenharmony_ci * talk to versions with same major #, and never talk to versions with a 258c2ecf20Sopenharmony_ci * different major #. 268c2ecf20Sopenharmony_ci */ 278c2ecf20Sopenharmony_ci#define _XPC_VERSION(_maj, _min) (((_maj) << 4) | ((_min) & 0xf)) 288c2ecf20Sopenharmony_ci#define XPC_VERSION_MAJOR(_v) ((_v) >> 4) 298c2ecf20Sopenharmony_ci#define XPC_VERSION_MINOR(_v) ((_v) & 0xf) 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/* define frequency of the heartbeat and frequency how often it's checked */ 328c2ecf20Sopenharmony_ci#define XPC_HB_DEFAULT_INTERVAL 5 /* incr HB every x secs */ 338c2ecf20Sopenharmony_ci#define XPC_HB_CHECK_DEFAULT_INTERVAL 20 /* check HB every x secs */ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* define the process name of HB checker and the CPU it is pinned to */ 368c2ecf20Sopenharmony_ci#define XPC_HB_CHECK_THREAD_NAME "xpc_hb" 378c2ecf20Sopenharmony_ci#define XPC_HB_CHECK_CPU 0 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/* define the process name of the discovery thread */ 408c2ecf20Sopenharmony_ci#define XPC_DISCOVERY_THREAD_NAME "xpc_discovery" 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/* 438c2ecf20Sopenharmony_ci * the reserved page 448c2ecf20Sopenharmony_ci * 458c2ecf20Sopenharmony_ci * SAL reserves one page of memory per partition for XPC. Though a full page 468c2ecf20Sopenharmony_ci * in length (16384 bytes), its starting address is not page aligned, but it 478c2ecf20Sopenharmony_ci * is cacheline aligned. The reserved page consists of the following: 488c2ecf20Sopenharmony_ci * 498c2ecf20Sopenharmony_ci * reserved page header 508c2ecf20Sopenharmony_ci * 518c2ecf20Sopenharmony_ci * The first two 64-byte cachelines of the reserved page contain the 528c2ecf20Sopenharmony_ci * header (struct xpc_rsvd_page). Before SAL initialization has completed, 538c2ecf20Sopenharmony_ci * SAL has set up the following fields of the reserved page header: 548c2ecf20Sopenharmony_ci * SAL_signature, SAL_version, SAL_partid, and SAL_nasids_size. The 558c2ecf20Sopenharmony_ci * other fields are set up by XPC. (xpc_rsvd_page points to the local 568c2ecf20Sopenharmony_ci * partition's reserved page.) 578c2ecf20Sopenharmony_ci * 588c2ecf20Sopenharmony_ci * part_nasids mask 598c2ecf20Sopenharmony_ci * mach_nasids mask 608c2ecf20Sopenharmony_ci * 618c2ecf20Sopenharmony_ci * SAL also sets up two bitmaps (or masks), one that reflects the actual 628c2ecf20Sopenharmony_ci * nasids in this partition (part_nasids), and the other that reflects 638c2ecf20Sopenharmony_ci * the actual nasids in the entire machine (mach_nasids). We're only 648c2ecf20Sopenharmony_ci * interested in the even numbered nasids (which contain the processors 658c2ecf20Sopenharmony_ci * and/or memory), so we only need half as many bits to represent the 668c2ecf20Sopenharmony_ci * nasids. When mapping nasid to bit in a mask (or bit to nasid) be sure 678c2ecf20Sopenharmony_ci * to either divide or multiply by 2. The part_nasids mask is located 688c2ecf20Sopenharmony_ci * starting at the first cacheline following the reserved page header. The 698c2ecf20Sopenharmony_ci * mach_nasids mask follows right after the part_nasids mask. The size in 708c2ecf20Sopenharmony_ci * bytes of each mask is reflected by the reserved page header field 718c2ecf20Sopenharmony_ci * 'SAL_nasids_size'. (Local partition's mask pointers are xpc_part_nasids 728c2ecf20Sopenharmony_ci * and xpc_mach_nasids.) 738c2ecf20Sopenharmony_ci * 748c2ecf20Sopenharmony_ci * Immediately following the mach_nasids mask are the XPC variables 758c2ecf20Sopenharmony_ci * required by other partitions. First are those that are generic to all 768c2ecf20Sopenharmony_ci * partitions (vars), followed on the next available cacheline by those 778c2ecf20Sopenharmony_ci * which are partition specific (vars part). These are setup by XPC. 788c2ecf20Sopenharmony_ci * 798c2ecf20Sopenharmony_ci * Note: Until 'ts_jiffies' is set non-zero, the partition XPC code has not been 808c2ecf20Sopenharmony_ci * initialized. 818c2ecf20Sopenharmony_ci */ 828c2ecf20Sopenharmony_cistruct xpc_rsvd_page { 838c2ecf20Sopenharmony_ci u64 SAL_signature; /* SAL: unique signature */ 848c2ecf20Sopenharmony_ci u64 SAL_version; /* SAL: version */ 858c2ecf20Sopenharmony_ci short SAL_partid; /* SAL: partition ID */ 868c2ecf20Sopenharmony_ci short max_npartitions; /* value of XPC_MAX_PARTITIONS */ 878c2ecf20Sopenharmony_ci u8 version; 888c2ecf20Sopenharmony_ci u8 pad1[3]; /* align to next u64 in 1st 64-byte cacheline */ 898c2ecf20Sopenharmony_ci unsigned long ts_jiffies; /* timestamp when rsvd pg was setup by XPC */ 908c2ecf20Sopenharmony_ci union { 918c2ecf20Sopenharmony_ci struct { 928c2ecf20Sopenharmony_ci unsigned long heartbeat_gpa; /* phys addr */ 938c2ecf20Sopenharmony_ci unsigned long activate_gru_mq_desc_gpa; /* phys addr */ 948c2ecf20Sopenharmony_ci } uv; 958c2ecf20Sopenharmony_ci } sn; 968c2ecf20Sopenharmony_ci u64 pad2[9]; /* align to last u64 in 2nd 64-byte cacheline */ 978c2ecf20Sopenharmony_ci u64 SAL_nasids_size; /* SAL: size of each nasid mask in bytes */ 988c2ecf20Sopenharmony_ci}; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci#define XPC_RP_VERSION _XPC_VERSION(3, 0) /* version 3.0 of the reserved page */ 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci/* the reserved page sizes and offsets */ 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci#define XPC_RP_HEADER_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page)) 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci#define XPC_RP_PART_NASIDS(_rp) ((unsigned long *)((u8 *)(_rp) + \ 1078c2ecf20Sopenharmony_ci XPC_RP_HEADER_SIZE)) 1088c2ecf20Sopenharmony_ci#define XPC_RP_MACH_NASIDS(_rp) (XPC_RP_PART_NASIDS(_rp) + \ 1098c2ecf20Sopenharmony_ci xpc_nasid_mask_nlongs) 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci/* 1138c2ecf20Sopenharmony_ci * The following structure describes the partition's heartbeat info which 1148c2ecf20Sopenharmony_ci * will be periodically read by other partitions to determine whether this 1158c2ecf20Sopenharmony_ci * XPC is still 'alive'. 1168c2ecf20Sopenharmony_ci */ 1178c2ecf20Sopenharmony_cistruct xpc_heartbeat_uv { 1188c2ecf20Sopenharmony_ci unsigned long value; 1198c2ecf20Sopenharmony_ci unsigned long offline; /* if 0, heartbeat should be changing */ 1208c2ecf20Sopenharmony_ci}; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/* 1238c2ecf20Sopenharmony_ci * Info pertinent to a GRU message queue using a watch list for irq generation. 1248c2ecf20Sopenharmony_ci */ 1258c2ecf20Sopenharmony_cistruct xpc_gru_mq_uv { 1268c2ecf20Sopenharmony_ci void *address; /* address of GRU message queue */ 1278c2ecf20Sopenharmony_ci unsigned int order; /* size of GRU message queue as a power of 2 */ 1288c2ecf20Sopenharmony_ci int irq; /* irq raised when message is received in mq */ 1298c2ecf20Sopenharmony_ci int mmr_blade; /* blade where watchlist was allocated from */ 1308c2ecf20Sopenharmony_ci unsigned long mmr_offset; /* offset of irq mmr located on mmr_blade */ 1318c2ecf20Sopenharmony_ci unsigned long mmr_value; /* value of irq mmr located on mmr_blade */ 1328c2ecf20Sopenharmony_ci int watchlist_num; /* number of watchlist allocatd by BIOS */ 1338c2ecf20Sopenharmony_ci void *gru_mq_desc; /* opaque structure used by the GRU driver */ 1348c2ecf20Sopenharmony_ci}; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci/* 1378c2ecf20Sopenharmony_ci * The activate_mq is used to send/receive GRU messages that affect XPC's 1388c2ecf20Sopenharmony_ci * partition active state and channel state. This is uv only. 1398c2ecf20Sopenharmony_ci */ 1408c2ecf20Sopenharmony_cistruct xpc_activate_mq_msghdr_uv { 1418c2ecf20Sopenharmony_ci unsigned int gru_msg_hdr; /* FOR GRU INTERNAL USE ONLY */ 1428c2ecf20Sopenharmony_ci short partid; /* sender's partid */ 1438c2ecf20Sopenharmony_ci u8 act_state; /* sender's act_state at time msg sent */ 1448c2ecf20Sopenharmony_ci u8 type; /* message's type */ 1458c2ecf20Sopenharmony_ci unsigned long rp_ts_jiffies; /* timestamp of sender's rp setup by XPC */ 1468c2ecf20Sopenharmony_ci}; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci/* activate_mq defined message types */ 1498c2ecf20Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_SYNC_ACT_STATE_UV 0 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_ACTIVATE_REQ_UV 1 1528c2ecf20Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_DEACTIVATE_REQ_UV 2 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREQUEST_UV 3 1558c2ecf20Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREPLY_UV 4 1568c2ecf20Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREQUEST_UV 5 1578c2ecf20Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREPLY_UV 6 1588c2ecf20Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENCOMPLETE_UV 7 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_MARK_ENGAGED_UV 8 1618c2ecf20Sopenharmony_ci#define XPC_ACTIVATE_MQ_MSG_MARK_DISENGAGED_UV 9 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_cistruct xpc_activate_mq_msg_uv { 1648c2ecf20Sopenharmony_ci struct xpc_activate_mq_msghdr_uv hdr; 1658c2ecf20Sopenharmony_ci}; 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cistruct xpc_activate_mq_msg_activate_req_uv { 1688c2ecf20Sopenharmony_ci struct xpc_activate_mq_msghdr_uv hdr; 1698c2ecf20Sopenharmony_ci unsigned long rp_gpa; 1708c2ecf20Sopenharmony_ci unsigned long heartbeat_gpa; 1718c2ecf20Sopenharmony_ci unsigned long activate_gru_mq_desc_gpa; 1728c2ecf20Sopenharmony_ci}; 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_cistruct xpc_activate_mq_msg_deactivate_req_uv { 1758c2ecf20Sopenharmony_ci struct xpc_activate_mq_msghdr_uv hdr; 1768c2ecf20Sopenharmony_ci enum xp_retval reason; 1778c2ecf20Sopenharmony_ci}; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_cistruct xpc_activate_mq_msg_chctl_closerequest_uv { 1808c2ecf20Sopenharmony_ci struct xpc_activate_mq_msghdr_uv hdr; 1818c2ecf20Sopenharmony_ci short ch_number; 1828c2ecf20Sopenharmony_ci enum xp_retval reason; 1838c2ecf20Sopenharmony_ci}; 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_cistruct xpc_activate_mq_msg_chctl_closereply_uv { 1868c2ecf20Sopenharmony_ci struct xpc_activate_mq_msghdr_uv hdr; 1878c2ecf20Sopenharmony_ci short ch_number; 1888c2ecf20Sopenharmony_ci}; 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_cistruct xpc_activate_mq_msg_chctl_openrequest_uv { 1918c2ecf20Sopenharmony_ci struct xpc_activate_mq_msghdr_uv hdr; 1928c2ecf20Sopenharmony_ci short ch_number; 1938c2ecf20Sopenharmony_ci short entry_size; /* size of notify_mq's GRU messages */ 1948c2ecf20Sopenharmony_ci short local_nentries; /* ??? Is this needed? What is? */ 1958c2ecf20Sopenharmony_ci}; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_cistruct xpc_activate_mq_msg_chctl_openreply_uv { 1988c2ecf20Sopenharmony_ci struct xpc_activate_mq_msghdr_uv hdr; 1998c2ecf20Sopenharmony_ci short ch_number; 2008c2ecf20Sopenharmony_ci short remote_nentries; /* ??? Is this needed? What is? */ 2018c2ecf20Sopenharmony_ci short local_nentries; /* ??? Is this needed? What is? */ 2028c2ecf20Sopenharmony_ci unsigned long notify_gru_mq_desc_gpa; 2038c2ecf20Sopenharmony_ci}; 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_cistruct xpc_activate_mq_msg_chctl_opencomplete_uv { 2068c2ecf20Sopenharmony_ci struct xpc_activate_mq_msghdr_uv hdr; 2078c2ecf20Sopenharmony_ci short ch_number; 2088c2ecf20Sopenharmony_ci}; 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci/* 2118c2ecf20Sopenharmony_ci * Functions registered by add_timer() or called by kernel_thread() only 2128c2ecf20Sopenharmony_ci * allow for a single 64-bit argument. The following macros can be used to 2138c2ecf20Sopenharmony_ci * pack and unpack two (32-bit, 16-bit or 8-bit) arguments into or out from 2148c2ecf20Sopenharmony_ci * the passed argument. 2158c2ecf20Sopenharmony_ci */ 2168c2ecf20Sopenharmony_ci#define XPC_PACK_ARGS(_arg1, _arg2) \ 2178c2ecf20Sopenharmony_ci ((((u64)_arg1) & 0xffffffff) | \ 2188c2ecf20Sopenharmony_ci ((((u64)_arg2) & 0xffffffff) << 32)) 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci#define XPC_UNPACK_ARG1(_args) (((u64)_args) & 0xffffffff) 2218c2ecf20Sopenharmony_ci#define XPC_UNPACK_ARG2(_args) ((((u64)_args) >> 32) & 0xffffffff) 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci/* 2248c2ecf20Sopenharmony_ci * Define a structure that contains arguments associated with opening and 2258c2ecf20Sopenharmony_ci * closing a channel. 2268c2ecf20Sopenharmony_ci */ 2278c2ecf20Sopenharmony_cistruct xpc_openclose_args { 2288c2ecf20Sopenharmony_ci u16 reason; /* reason why channel is closing */ 2298c2ecf20Sopenharmony_ci u16 entry_size; /* sizeof each message entry */ 2308c2ecf20Sopenharmony_ci u16 remote_nentries; /* #of message entries in remote msg queue */ 2318c2ecf20Sopenharmony_ci u16 local_nentries; /* #of message entries in local msg queue */ 2328c2ecf20Sopenharmony_ci unsigned long local_msgqueue_pa; /* phys addr of local message queue */ 2338c2ecf20Sopenharmony_ci}; 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci#define XPC_OPENCLOSE_ARGS_SIZE \ 2368c2ecf20Sopenharmony_ci L1_CACHE_ALIGN(sizeof(struct xpc_openclose_args) * \ 2378c2ecf20Sopenharmony_ci XPC_MAX_NCHANNELS) 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci/* 2418c2ecf20Sopenharmony_ci * Structures to define a fifo singly-linked list. 2428c2ecf20Sopenharmony_ci */ 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_cistruct xpc_fifo_entry_uv { 2458c2ecf20Sopenharmony_ci struct xpc_fifo_entry_uv *next; 2468c2ecf20Sopenharmony_ci}; 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_cistruct xpc_fifo_head_uv { 2498c2ecf20Sopenharmony_ci struct xpc_fifo_entry_uv *first; 2508c2ecf20Sopenharmony_ci struct xpc_fifo_entry_uv *last; 2518c2ecf20Sopenharmony_ci spinlock_t lock; 2528c2ecf20Sopenharmony_ci int n_entries; 2538c2ecf20Sopenharmony_ci}; 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci/* 2568c2ecf20Sopenharmony_ci * The format of a uv XPC notify_mq GRU message is as follows: 2578c2ecf20Sopenharmony_ci * 2588c2ecf20Sopenharmony_ci * A user-defined message resides in the payload area. The max size of the 2598c2ecf20Sopenharmony_ci * payload is defined by the user via xpc_connect(). 2608c2ecf20Sopenharmony_ci * 2618c2ecf20Sopenharmony_ci * The size of a message (payload and header) sent via the GRU must be either 1 2628c2ecf20Sopenharmony_ci * or 2 GRU_CACHE_LINE_BYTES in length. 2638c2ecf20Sopenharmony_ci */ 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_cistruct xpc_notify_mq_msghdr_uv { 2668c2ecf20Sopenharmony_ci union { 2678c2ecf20Sopenharmony_ci unsigned int gru_msg_hdr; /* FOR GRU INTERNAL USE ONLY */ 2688c2ecf20Sopenharmony_ci struct xpc_fifo_entry_uv next; /* FOR XPC INTERNAL USE ONLY */ 2698c2ecf20Sopenharmony_ci } u; 2708c2ecf20Sopenharmony_ci short partid; /* FOR XPC INTERNAL USE ONLY */ 2718c2ecf20Sopenharmony_ci u8 ch_number; /* FOR XPC INTERNAL USE ONLY */ 2728c2ecf20Sopenharmony_ci u8 size; /* FOR XPC INTERNAL USE ONLY */ 2738c2ecf20Sopenharmony_ci unsigned int msg_slot_number; /* FOR XPC INTERNAL USE ONLY */ 2748c2ecf20Sopenharmony_ci}; 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_cistruct xpc_notify_mq_msg_uv { 2778c2ecf20Sopenharmony_ci struct xpc_notify_mq_msghdr_uv hdr; 2788c2ecf20Sopenharmony_ci unsigned long payload; 2798c2ecf20Sopenharmony_ci}; 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci/* struct xpc_notify_sn2 type of notification */ 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci#define XPC_N_CALL 0x01 /* notify function provided by user */ 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci/* 2868c2ecf20Sopenharmony_ci * Define uv's version of the notify entry. It additionally is used to allocate 2878c2ecf20Sopenharmony_ci * a msg slot on the remote partition into which is copied a sent message. 2888c2ecf20Sopenharmony_ci */ 2898c2ecf20Sopenharmony_cistruct xpc_send_msg_slot_uv { 2908c2ecf20Sopenharmony_ci struct xpc_fifo_entry_uv next; 2918c2ecf20Sopenharmony_ci unsigned int msg_slot_number; 2928c2ecf20Sopenharmony_ci xpc_notify_func func; /* user's notify function */ 2938c2ecf20Sopenharmony_ci void *key; /* pointer to user's key */ 2948c2ecf20Sopenharmony_ci}; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci/* 2978c2ecf20Sopenharmony_ci * Define the structure that manages all the stuff required by a channel. In 2988c2ecf20Sopenharmony_ci * particular, they are used to manage the messages sent across the channel. 2998c2ecf20Sopenharmony_ci * 3008c2ecf20Sopenharmony_ci * This structure is private to a partition, and is NOT shared across the 3018c2ecf20Sopenharmony_ci * partition boundary. 3028c2ecf20Sopenharmony_ci * 3038c2ecf20Sopenharmony_ci * There is an array of these structures for each remote partition. It is 3048c2ecf20Sopenharmony_ci * allocated at the time a partition becomes active. The array contains one 3058c2ecf20Sopenharmony_ci * of these structures for each potential channel connection to that partition. 3068c2ecf20Sopenharmony_ci */ 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_cistruct xpc_channel_uv { 3098c2ecf20Sopenharmony_ci void *cached_notify_gru_mq_desc; /* remote partition's notify mq's */ 3108c2ecf20Sopenharmony_ci /* gru mq descriptor */ 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci struct xpc_send_msg_slot_uv *send_msg_slots; 3138c2ecf20Sopenharmony_ci void *recv_msg_slots; /* each slot will hold a xpc_notify_mq_msg_uv */ 3148c2ecf20Sopenharmony_ci /* structure plus the user's payload */ 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci struct xpc_fifo_head_uv msg_slot_free_list; 3178c2ecf20Sopenharmony_ci struct xpc_fifo_head_uv recv_msg_list; /* deliverable payloads */ 3188c2ecf20Sopenharmony_ci}; 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_cistruct xpc_channel { 3218c2ecf20Sopenharmony_ci short partid; /* ID of remote partition connected */ 3228c2ecf20Sopenharmony_ci spinlock_t lock; /* lock for updating this structure */ 3238c2ecf20Sopenharmony_ci unsigned int flags; /* general flags */ 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci enum xp_retval reason; /* reason why channel is disconnect'g */ 3268c2ecf20Sopenharmony_ci int reason_line; /* line# disconnect initiated from */ 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci u16 number; /* channel # */ 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci u16 entry_size; /* sizeof each msg entry */ 3318c2ecf20Sopenharmony_ci u16 local_nentries; /* #of msg entries in local msg queue */ 3328c2ecf20Sopenharmony_ci u16 remote_nentries; /* #of msg entries in remote msg queue */ 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci atomic_t references; /* #of external references to queues */ 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci atomic_t n_on_msg_allocate_wq; /* #on msg allocation wait queue */ 3378c2ecf20Sopenharmony_ci wait_queue_head_t msg_allocate_wq; /* msg allocation wait queue */ 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_ci u8 delayed_chctl_flags; /* chctl flags received, but delayed */ 3408c2ecf20Sopenharmony_ci /* action until channel disconnected */ 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci atomic_t n_to_notify; /* #of msg senders to notify */ 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci xpc_channel_func func; /* user's channel function */ 3458c2ecf20Sopenharmony_ci void *key; /* pointer to user's key */ 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci struct completion wdisconnect_wait; /* wait for channel disconnect */ 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci /* kthread management related fields */ 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci atomic_t kthreads_assigned; /* #of kthreads assigned to channel */ 3528c2ecf20Sopenharmony_ci u32 kthreads_assigned_limit; /* limit on #of kthreads assigned */ 3538c2ecf20Sopenharmony_ci atomic_t kthreads_idle; /* #of kthreads idle waiting for work */ 3548c2ecf20Sopenharmony_ci u32 kthreads_idle_limit; /* limit on #of kthreads idle */ 3558c2ecf20Sopenharmony_ci atomic_t kthreads_active; /* #of kthreads actively working */ 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci wait_queue_head_t idle_wq; /* idle kthread wait queue */ 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci union { 3608c2ecf20Sopenharmony_ci struct xpc_channel_uv uv; 3618c2ecf20Sopenharmony_ci } sn; 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci} ____cacheline_aligned; 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci/* struct xpc_channel flags */ 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci#define XPC_C_WASCONNECTED 0x00000001 /* channel was connected */ 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci#define XPC_C_ROPENCOMPLETE 0x00000002 /* remote open channel complete */ 3708c2ecf20Sopenharmony_ci#define XPC_C_OPENCOMPLETE 0x00000004 /* local open channel complete */ 3718c2ecf20Sopenharmony_ci#define XPC_C_ROPENREPLY 0x00000008 /* remote open channel reply */ 3728c2ecf20Sopenharmony_ci#define XPC_C_OPENREPLY 0x00000010 /* local open channel reply */ 3738c2ecf20Sopenharmony_ci#define XPC_C_ROPENREQUEST 0x00000020 /* remote open channel request */ 3748c2ecf20Sopenharmony_ci#define XPC_C_OPENREQUEST 0x00000040 /* local open channel request */ 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci#define XPC_C_SETUP 0x00000080 /* channel's msgqueues are alloc'd */ 3778c2ecf20Sopenharmony_ci#define XPC_C_CONNECTEDCALLOUT 0x00000100 /* connected callout initiated */ 3788c2ecf20Sopenharmony_ci#define XPC_C_CONNECTEDCALLOUT_MADE \ 3798c2ecf20Sopenharmony_ci 0x00000200 /* connected callout completed */ 3808c2ecf20Sopenharmony_ci#define XPC_C_CONNECTED 0x00000400 /* local channel is connected */ 3818c2ecf20Sopenharmony_ci#define XPC_C_CONNECTING 0x00000800 /* channel is being connected */ 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci#define XPC_C_RCLOSEREPLY 0x00001000 /* remote close channel reply */ 3848c2ecf20Sopenharmony_ci#define XPC_C_CLOSEREPLY 0x00002000 /* local close channel reply */ 3858c2ecf20Sopenharmony_ci#define XPC_C_RCLOSEREQUEST 0x00004000 /* remote close channel request */ 3868c2ecf20Sopenharmony_ci#define XPC_C_CLOSEREQUEST 0x00008000 /* local close channel request */ 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci#define XPC_C_DISCONNECTED 0x00010000 /* channel is disconnected */ 3898c2ecf20Sopenharmony_ci#define XPC_C_DISCONNECTING 0x00020000 /* channel is being disconnected */ 3908c2ecf20Sopenharmony_ci#define XPC_C_DISCONNECTINGCALLOUT \ 3918c2ecf20Sopenharmony_ci 0x00040000 /* disconnecting callout initiated */ 3928c2ecf20Sopenharmony_ci#define XPC_C_DISCONNECTINGCALLOUT_MADE \ 3938c2ecf20Sopenharmony_ci 0x00080000 /* disconnecting callout completed */ 3948c2ecf20Sopenharmony_ci#define XPC_C_WDISCONNECT 0x00100000 /* waiting for channel disconnect */ 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci/* 3978c2ecf20Sopenharmony_ci * The channel control flags (chctl) union consists of a 64-bit variable which 3988c2ecf20Sopenharmony_ci * is divided up into eight bytes, ordered from right to left. Byte zero 3998c2ecf20Sopenharmony_ci * pertains to channel 0, byte one to channel 1, and so on. Each channel's byte 4008c2ecf20Sopenharmony_ci * can have one or more of the chctl flags set in it. 4018c2ecf20Sopenharmony_ci */ 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ciunion xpc_channel_ctl_flags { 4048c2ecf20Sopenharmony_ci u64 all_flags; 4058c2ecf20Sopenharmony_ci u8 flags[XPC_MAX_NCHANNELS]; 4068c2ecf20Sopenharmony_ci}; 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci/* chctl flags */ 4098c2ecf20Sopenharmony_ci#define XPC_CHCTL_CLOSEREQUEST 0x01 4108c2ecf20Sopenharmony_ci#define XPC_CHCTL_CLOSEREPLY 0x02 4118c2ecf20Sopenharmony_ci#define XPC_CHCTL_OPENREQUEST 0x04 4128c2ecf20Sopenharmony_ci#define XPC_CHCTL_OPENREPLY 0x08 4138c2ecf20Sopenharmony_ci#define XPC_CHCTL_OPENCOMPLETE 0x10 4148c2ecf20Sopenharmony_ci#define XPC_CHCTL_MSGREQUEST 0x20 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci#define XPC_OPENCLOSE_CHCTL_FLAGS \ 4178c2ecf20Sopenharmony_ci (XPC_CHCTL_CLOSEREQUEST | XPC_CHCTL_CLOSEREPLY | \ 4188c2ecf20Sopenharmony_ci XPC_CHCTL_OPENREQUEST | XPC_CHCTL_OPENREPLY | \ 4198c2ecf20Sopenharmony_ci XPC_CHCTL_OPENCOMPLETE) 4208c2ecf20Sopenharmony_ci#define XPC_MSG_CHCTL_FLAGS XPC_CHCTL_MSGREQUEST 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_cistatic inline int 4238c2ecf20Sopenharmony_cixpc_any_openclose_chctl_flags_set(union xpc_channel_ctl_flags *chctl) 4248c2ecf20Sopenharmony_ci{ 4258c2ecf20Sopenharmony_ci int ch_number; 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) { 4288c2ecf20Sopenharmony_ci if (chctl->flags[ch_number] & XPC_OPENCLOSE_CHCTL_FLAGS) 4298c2ecf20Sopenharmony_ci return 1; 4308c2ecf20Sopenharmony_ci } 4318c2ecf20Sopenharmony_ci return 0; 4328c2ecf20Sopenharmony_ci} 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_cistatic inline int 4358c2ecf20Sopenharmony_cixpc_any_msg_chctl_flags_set(union xpc_channel_ctl_flags *chctl) 4368c2ecf20Sopenharmony_ci{ 4378c2ecf20Sopenharmony_ci int ch_number; 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) { 4408c2ecf20Sopenharmony_ci if (chctl->flags[ch_number] & XPC_MSG_CHCTL_FLAGS) 4418c2ecf20Sopenharmony_ci return 1; 4428c2ecf20Sopenharmony_ci } 4438c2ecf20Sopenharmony_ci return 0; 4448c2ecf20Sopenharmony_ci} 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_cistruct xpc_partition_uv { 4478c2ecf20Sopenharmony_ci unsigned long heartbeat_gpa; /* phys addr of partition's heartbeat */ 4488c2ecf20Sopenharmony_ci struct xpc_heartbeat_uv cached_heartbeat; /* cached copy of */ 4498c2ecf20Sopenharmony_ci /* partition's heartbeat */ 4508c2ecf20Sopenharmony_ci unsigned long activate_gru_mq_desc_gpa; /* phys addr of parititon's */ 4518c2ecf20Sopenharmony_ci /* activate mq's gru mq */ 4528c2ecf20Sopenharmony_ci /* descriptor */ 4538c2ecf20Sopenharmony_ci void *cached_activate_gru_mq_desc; /* cached copy of partition's */ 4548c2ecf20Sopenharmony_ci /* activate mq's gru mq descriptor */ 4558c2ecf20Sopenharmony_ci struct mutex cached_activate_gru_mq_desc_mutex; 4568c2ecf20Sopenharmony_ci spinlock_t flags_lock; /* protect updating of flags */ 4578c2ecf20Sopenharmony_ci unsigned int flags; /* general flags */ 4588c2ecf20Sopenharmony_ci u8 remote_act_state; /* remote partition's act_state */ 4598c2ecf20Sopenharmony_ci u8 act_state_req; /* act_state request from remote partition */ 4608c2ecf20Sopenharmony_ci enum xp_retval reason; /* reason for deactivate act_state request */ 4618c2ecf20Sopenharmony_ci}; 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci/* struct xpc_partition_uv flags */ 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci#define XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV 0x00000001 4668c2ecf20Sopenharmony_ci#define XPC_P_ENGAGED_UV 0x00000002 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ci/* struct xpc_partition_uv act_state change requests */ 4698c2ecf20Sopenharmony_ci 4708c2ecf20Sopenharmony_ci#define XPC_P_ASR_ACTIVATE_UV 0x01 4718c2ecf20Sopenharmony_ci#define XPC_P_ASR_REACTIVATE_UV 0x02 4728c2ecf20Sopenharmony_ci#define XPC_P_ASR_DEACTIVATE_UV 0x03 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_cistruct xpc_partition { 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci /* XPC HB infrastructure */ 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci u8 remote_rp_version; /* version# of partition's rsvd pg */ 4798c2ecf20Sopenharmony_ci unsigned long remote_rp_ts_jiffies; /* timestamp when rsvd pg setup */ 4808c2ecf20Sopenharmony_ci unsigned long remote_rp_pa; /* phys addr of partition's rsvd pg */ 4818c2ecf20Sopenharmony_ci u64 last_heartbeat; /* HB at last read */ 4828c2ecf20Sopenharmony_ci u32 activate_IRQ_rcvd; /* IRQs since activation */ 4838c2ecf20Sopenharmony_ci spinlock_t act_lock; /* protect updating of act_state */ 4848c2ecf20Sopenharmony_ci u8 act_state; /* from XPC HB viewpoint */ 4858c2ecf20Sopenharmony_ci enum xp_retval reason; /* reason partition is deactivating */ 4868c2ecf20Sopenharmony_ci int reason_line; /* line# deactivation initiated from */ 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci unsigned long disengage_timeout; /* timeout in jiffies */ 4898c2ecf20Sopenharmony_ci struct timer_list disengage_timer; 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci /* XPC infrastructure referencing and teardown control */ 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci u8 setup_state; /* infrastructure setup state */ 4948c2ecf20Sopenharmony_ci wait_queue_head_t teardown_wq; /* kthread waiting to teardown infra */ 4958c2ecf20Sopenharmony_ci atomic_t references; /* #of references to infrastructure */ 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci u8 nchannels; /* #of defined channels supported */ 4988c2ecf20Sopenharmony_ci atomic_t nchannels_active; /* #of channels that are not DISCONNECTED */ 4998c2ecf20Sopenharmony_ci atomic_t nchannels_engaged; /* #of channels engaged with remote part */ 5008c2ecf20Sopenharmony_ci struct xpc_channel *channels; /* array of channel structures */ 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci /* fields used for managing channel avialability and activity */ 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci union xpc_channel_ctl_flags chctl; /* chctl flags yet to be processed */ 5058c2ecf20Sopenharmony_ci spinlock_t chctl_lock; /* chctl flags lock */ 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci void *remote_openclose_args_base; /* base address of kmalloc'd space */ 5088c2ecf20Sopenharmony_ci struct xpc_openclose_args *remote_openclose_args; /* copy of remote's */ 5098c2ecf20Sopenharmony_ci /* args */ 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_ci /* channel manager related fields */ 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci atomic_t channel_mgr_requests; /* #of requests to activate chan mgr */ 5148c2ecf20Sopenharmony_ci wait_queue_head_t channel_mgr_wq; /* channel mgr's wait queue */ 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci union { 5178c2ecf20Sopenharmony_ci struct xpc_partition_uv uv; 5188c2ecf20Sopenharmony_ci } sn; 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci} ____cacheline_aligned; 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_cistruct xpc_arch_operations { 5238c2ecf20Sopenharmony_ci int (*setup_partitions) (void); 5248c2ecf20Sopenharmony_ci void (*teardown_partitions) (void); 5258c2ecf20Sopenharmony_ci void (*process_activate_IRQ_rcvd) (void); 5268c2ecf20Sopenharmony_ci enum xp_retval (*get_partition_rsvd_page_pa) 5278c2ecf20Sopenharmony_ci (void *, u64 *, unsigned long *, size_t *); 5288c2ecf20Sopenharmony_ci int (*setup_rsvd_page) (struct xpc_rsvd_page *); 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_ci void (*allow_hb) (short); 5318c2ecf20Sopenharmony_ci void (*disallow_hb) (short); 5328c2ecf20Sopenharmony_ci void (*disallow_all_hbs) (void); 5338c2ecf20Sopenharmony_ci void (*increment_heartbeat) (void); 5348c2ecf20Sopenharmony_ci void (*offline_heartbeat) (void); 5358c2ecf20Sopenharmony_ci void (*online_heartbeat) (void); 5368c2ecf20Sopenharmony_ci void (*heartbeat_init) (void); 5378c2ecf20Sopenharmony_ci void (*heartbeat_exit) (void); 5388c2ecf20Sopenharmony_ci enum xp_retval (*get_remote_heartbeat) (struct xpc_partition *); 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci void (*request_partition_activation) (struct xpc_rsvd_page *, 5418c2ecf20Sopenharmony_ci unsigned long, int); 5428c2ecf20Sopenharmony_ci void (*request_partition_reactivation) (struct xpc_partition *); 5438c2ecf20Sopenharmony_ci void (*request_partition_deactivation) (struct xpc_partition *); 5448c2ecf20Sopenharmony_ci void (*cancel_partition_deactivation_request) (struct xpc_partition *); 5458c2ecf20Sopenharmony_ci enum xp_retval (*setup_ch_structures) (struct xpc_partition *); 5468c2ecf20Sopenharmony_ci void (*teardown_ch_structures) (struct xpc_partition *); 5478c2ecf20Sopenharmony_ci 5488c2ecf20Sopenharmony_ci enum xp_retval (*make_first_contact) (struct xpc_partition *); 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci u64 (*get_chctl_all_flags) (struct xpc_partition *); 5518c2ecf20Sopenharmony_ci void (*send_chctl_closerequest) (struct xpc_channel *, unsigned long *); 5528c2ecf20Sopenharmony_ci void (*send_chctl_closereply) (struct xpc_channel *, unsigned long *); 5538c2ecf20Sopenharmony_ci void (*send_chctl_openrequest) (struct xpc_channel *, unsigned long *); 5548c2ecf20Sopenharmony_ci void (*send_chctl_openreply) (struct xpc_channel *, unsigned long *); 5558c2ecf20Sopenharmony_ci void (*send_chctl_opencomplete) (struct xpc_channel *, unsigned long *); 5568c2ecf20Sopenharmony_ci void (*process_msg_chctl_flags) (struct xpc_partition *, int); 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci enum xp_retval (*save_remote_msgqueue_pa) (struct xpc_channel *, 5598c2ecf20Sopenharmony_ci unsigned long); 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci enum xp_retval (*setup_msg_structures) (struct xpc_channel *); 5628c2ecf20Sopenharmony_ci void (*teardown_msg_structures) (struct xpc_channel *); 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci void (*indicate_partition_engaged) (struct xpc_partition *); 5658c2ecf20Sopenharmony_ci void (*indicate_partition_disengaged) (struct xpc_partition *); 5668c2ecf20Sopenharmony_ci void (*assume_partition_disengaged) (short); 5678c2ecf20Sopenharmony_ci int (*partition_engaged) (short); 5688c2ecf20Sopenharmony_ci int (*any_partition_engaged) (void); 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci int (*n_of_deliverable_payloads) (struct xpc_channel *); 5718c2ecf20Sopenharmony_ci enum xp_retval (*send_payload) (struct xpc_channel *, u32, void *, 5728c2ecf20Sopenharmony_ci u16, u8, xpc_notify_func, void *); 5738c2ecf20Sopenharmony_ci void *(*get_deliverable_payload) (struct xpc_channel *); 5748c2ecf20Sopenharmony_ci void (*received_payload) (struct xpc_channel *, void *); 5758c2ecf20Sopenharmony_ci void (*notify_senders_of_disconnect) (struct xpc_channel *); 5768c2ecf20Sopenharmony_ci}; 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci/* struct xpc_partition act_state values (for XPC HB) */ 5798c2ecf20Sopenharmony_ci 5808c2ecf20Sopenharmony_ci#define XPC_P_AS_INACTIVE 0x00 /* partition is not active */ 5818c2ecf20Sopenharmony_ci#define XPC_P_AS_ACTIVATION_REQ 0x01 /* created thread to activate */ 5828c2ecf20Sopenharmony_ci#define XPC_P_AS_ACTIVATING 0x02 /* activation thread started */ 5838c2ecf20Sopenharmony_ci#define XPC_P_AS_ACTIVE 0x03 /* xpc_partition_up() was called */ 5848c2ecf20Sopenharmony_ci#define XPC_P_AS_DEACTIVATING 0x04 /* partition deactivation initiated */ 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci#define XPC_DEACTIVATE_PARTITION(_p, _reason) \ 5878c2ecf20Sopenharmony_ci xpc_deactivate_partition(__LINE__, (_p), (_reason)) 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_ci/* struct xpc_partition setup_state values */ 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ci#define XPC_P_SS_UNSET 0x00 /* infrastructure was never setup */ 5928c2ecf20Sopenharmony_ci#define XPC_P_SS_SETUP 0x01 /* infrastructure is setup */ 5938c2ecf20Sopenharmony_ci#define XPC_P_SS_WTEARDOWN 0x02 /* waiting to teardown infrastructure */ 5948c2ecf20Sopenharmony_ci#define XPC_P_SS_TORNDOWN 0x03 /* infrastructure is torndown */ 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci/* number of seconds to wait for other partitions to disengage */ 5978c2ecf20Sopenharmony_ci#define XPC_DISENGAGE_DEFAULT_TIMELIMIT 90 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci/* interval in seconds to print 'waiting deactivation' messages */ 6008c2ecf20Sopenharmony_ci#define XPC_DEACTIVATE_PRINTMSG_INTERVAL 10 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci#define XPC_PARTID(_p) ((short)((_p) - &xpc_partitions[0])) 6038c2ecf20Sopenharmony_ci 6048c2ecf20Sopenharmony_ci/* found in xp_main.c */ 6058c2ecf20Sopenharmony_ciextern struct xpc_registration xpc_registrations[]; 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci/* found in xpc_main.c */ 6088c2ecf20Sopenharmony_ciextern struct device *xpc_part; 6098c2ecf20Sopenharmony_ciextern struct device *xpc_chan; 6108c2ecf20Sopenharmony_ciextern struct xpc_arch_operations xpc_arch_ops; 6118c2ecf20Sopenharmony_ciextern int xpc_disengage_timelimit; 6128c2ecf20Sopenharmony_ciextern int xpc_disengage_timedout; 6138c2ecf20Sopenharmony_ciextern int xpc_activate_IRQ_rcvd; 6148c2ecf20Sopenharmony_ciextern spinlock_t xpc_activate_IRQ_rcvd_lock; 6158c2ecf20Sopenharmony_ciextern wait_queue_head_t xpc_activate_IRQ_wq; 6168c2ecf20Sopenharmony_ciextern void *xpc_kzalloc_cacheline_aligned(size_t, gfp_t, void **); 6178c2ecf20Sopenharmony_ciextern void xpc_activate_partition(struct xpc_partition *); 6188c2ecf20Sopenharmony_ciextern void xpc_activate_kthreads(struct xpc_channel *, int); 6198c2ecf20Sopenharmony_ciextern void xpc_create_kthreads(struct xpc_channel *, int, int); 6208c2ecf20Sopenharmony_ciextern void xpc_disconnect_wait(int); 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_ci/* found in xpc_uv.c */ 6238c2ecf20Sopenharmony_ciextern int xpc_init_uv(void); 6248c2ecf20Sopenharmony_ciextern void xpc_exit_uv(void); 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_ci/* found in xpc_partition.c */ 6278c2ecf20Sopenharmony_ciextern int xpc_exiting; 6288c2ecf20Sopenharmony_ciextern int xpc_nasid_mask_nlongs; 6298c2ecf20Sopenharmony_ciextern struct xpc_rsvd_page *xpc_rsvd_page; 6308c2ecf20Sopenharmony_ciextern unsigned long *xpc_mach_nasids; 6318c2ecf20Sopenharmony_ciextern struct xpc_partition *xpc_partitions; 6328c2ecf20Sopenharmony_ciextern void *xpc_kmalloc_cacheline_aligned(size_t, gfp_t, void **); 6338c2ecf20Sopenharmony_ciextern int xpc_setup_rsvd_page(void); 6348c2ecf20Sopenharmony_ciextern void xpc_teardown_rsvd_page(void); 6358c2ecf20Sopenharmony_ciextern int xpc_identify_activate_IRQ_sender(void); 6368c2ecf20Sopenharmony_ciextern int xpc_partition_disengaged(struct xpc_partition *); 6378c2ecf20Sopenharmony_ciextern enum xp_retval xpc_mark_partition_active(struct xpc_partition *); 6388c2ecf20Sopenharmony_ciextern void xpc_mark_partition_inactive(struct xpc_partition *); 6398c2ecf20Sopenharmony_ciextern void xpc_discovery(void); 6408c2ecf20Sopenharmony_ciextern enum xp_retval xpc_get_remote_rp(int, unsigned long *, 6418c2ecf20Sopenharmony_ci struct xpc_rsvd_page *, 6428c2ecf20Sopenharmony_ci unsigned long *); 6438c2ecf20Sopenharmony_ciextern void xpc_deactivate_partition(const int, struct xpc_partition *, 6448c2ecf20Sopenharmony_ci enum xp_retval); 6458c2ecf20Sopenharmony_ciextern enum xp_retval xpc_initiate_partid_to_nasids(short, void *); 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci/* found in xpc_channel.c */ 6488c2ecf20Sopenharmony_ciextern void xpc_initiate_connect(int); 6498c2ecf20Sopenharmony_ciextern void xpc_initiate_disconnect(int); 6508c2ecf20Sopenharmony_ciextern enum xp_retval xpc_allocate_msg_wait(struct xpc_channel *); 6518c2ecf20Sopenharmony_ciextern enum xp_retval xpc_initiate_send(short, int, u32, void *, u16); 6528c2ecf20Sopenharmony_ciextern enum xp_retval xpc_initiate_send_notify(short, int, u32, void *, u16, 6538c2ecf20Sopenharmony_ci xpc_notify_func, void *); 6548c2ecf20Sopenharmony_ciextern void xpc_initiate_received(short, int, void *); 6558c2ecf20Sopenharmony_ciextern void xpc_process_sent_chctl_flags(struct xpc_partition *); 6568c2ecf20Sopenharmony_ciextern void xpc_connected_callout(struct xpc_channel *); 6578c2ecf20Sopenharmony_ciextern void xpc_deliver_payload(struct xpc_channel *); 6588c2ecf20Sopenharmony_ciextern void xpc_disconnect_channel(const int, struct xpc_channel *, 6598c2ecf20Sopenharmony_ci enum xp_retval, unsigned long *); 6608c2ecf20Sopenharmony_ciextern void xpc_disconnect_callout(struct xpc_channel *, enum xp_retval); 6618c2ecf20Sopenharmony_ciextern void xpc_partition_going_down(struct xpc_partition *, enum xp_retval); 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_cistatic inline void 6648c2ecf20Sopenharmony_cixpc_wakeup_channel_mgr(struct xpc_partition *part) 6658c2ecf20Sopenharmony_ci{ 6668c2ecf20Sopenharmony_ci if (atomic_inc_return(&part->channel_mgr_requests) == 1) 6678c2ecf20Sopenharmony_ci wake_up(&part->channel_mgr_wq); 6688c2ecf20Sopenharmony_ci} 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_ci/* 6718c2ecf20Sopenharmony_ci * These next two inlines are used to keep us from tearing down a channel's 6728c2ecf20Sopenharmony_ci * msg queues while a thread may be referencing them. 6738c2ecf20Sopenharmony_ci */ 6748c2ecf20Sopenharmony_cistatic inline void 6758c2ecf20Sopenharmony_cixpc_msgqueue_ref(struct xpc_channel *ch) 6768c2ecf20Sopenharmony_ci{ 6778c2ecf20Sopenharmony_ci atomic_inc(&ch->references); 6788c2ecf20Sopenharmony_ci} 6798c2ecf20Sopenharmony_ci 6808c2ecf20Sopenharmony_cistatic inline void 6818c2ecf20Sopenharmony_cixpc_msgqueue_deref(struct xpc_channel *ch) 6828c2ecf20Sopenharmony_ci{ 6838c2ecf20Sopenharmony_ci s32 refs = atomic_dec_return(&ch->references); 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_ci DBUG_ON(refs < 0); 6868c2ecf20Sopenharmony_ci if (refs == 0) 6878c2ecf20Sopenharmony_ci xpc_wakeup_channel_mgr(&xpc_partitions[ch->partid]); 6888c2ecf20Sopenharmony_ci} 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ci#define XPC_DISCONNECT_CHANNEL(_ch, _reason, _irqflgs) \ 6918c2ecf20Sopenharmony_ci xpc_disconnect_channel(__LINE__, _ch, _reason, _irqflgs) 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ci/* 6948c2ecf20Sopenharmony_ci * These two inlines are used to keep us from tearing down a partition's 6958c2ecf20Sopenharmony_ci * setup infrastructure while a thread may be referencing it. 6968c2ecf20Sopenharmony_ci */ 6978c2ecf20Sopenharmony_cistatic inline void 6988c2ecf20Sopenharmony_cixpc_part_deref(struct xpc_partition *part) 6998c2ecf20Sopenharmony_ci{ 7008c2ecf20Sopenharmony_ci s32 refs = atomic_dec_return(&part->references); 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_ci DBUG_ON(refs < 0); 7038c2ecf20Sopenharmony_ci if (refs == 0 && part->setup_state == XPC_P_SS_WTEARDOWN) 7048c2ecf20Sopenharmony_ci wake_up(&part->teardown_wq); 7058c2ecf20Sopenharmony_ci} 7068c2ecf20Sopenharmony_ci 7078c2ecf20Sopenharmony_cistatic inline int 7088c2ecf20Sopenharmony_cixpc_part_ref(struct xpc_partition *part) 7098c2ecf20Sopenharmony_ci{ 7108c2ecf20Sopenharmony_ci int setup; 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_ci atomic_inc(&part->references); 7138c2ecf20Sopenharmony_ci setup = (part->setup_state == XPC_P_SS_SETUP); 7148c2ecf20Sopenharmony_ci if (!setup) 7158c2ecf20Sopenharmony_ci xpc_part_deref(part); 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci return setup; 7188c2ecf20Sopenharmony_ci} 7198c2ecf20Sopenharmony_ci 7208c2ecf20Sopenharmony_ci/* 7218c2ecf20Sopenharmony_ci * The following macro is to be used for the setting of the reason and 7228c2ecf20Sopenharmony_ci * reason_line fields in both the struct xpc_channel and struct xpc_partition 7238c2ecf20Sopenharmony_ci * structures. 7248c2ecf20Sopenharmony_ci */ 7258c2ecf20Sopenharmony_ci#define XPC_SET_REASON(_p, _reason, _line) \ 7268c2ecf20Sopenharmony_ci { \ 7278c2ecf20Sopenharmony_ci (_p)->reason = _reason; \ 7288c2ecf20Sopenharmony_ci (_p)->reason_line = _line; \ 7298c2ecf20Sopenharmony_ci } 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_ci#endif /* _DRIVERS_MISC_SGIXP_XPC_H */ 732