1 /* SPDX-License-Identifier: GPL-2.0-or-later * 1 2 /* 3 * Copyright 2016-17 IBM Corp. 4 */ 5 6 #ifndef _ASM_POWERPC_VAS_H 7 #define _ASM_POWERPC_VAS_H 8 #include <linux/sched/mm.h> 9 #include <linux/mmu_context.h> 10 #include <asm/icswx.h> 11 #include <uapi/asm/vas-api.h> 12 13 /* 14 * Min and max FIFO sizes are based on Version 15 * (Local FIFO Size Register) of the VAS workb 16 */ 17 #define VAS_RX_FIFO_SIZE_MIN (1 << 10) 18 #define VAS_RX_FIFO_SIZE_MAX (8 << 20) 19 20 /* 21 * Threshold Control Mode: Have paste operatio 22 * requests in receive FIFO exceeds a threshol 23 * 24 * NOTE: No special error code yet if paste is 25 * limits. So users can't distinguish be 26 */ 27 #define VAS_THRESH_DISABLED 0 28 #define VAS_THRESH_FIFO_GT_HALF_FULL 1 29 #define VAS_THRESH_FIFO_GT_QTR_FULL 2 30 #define VAS_THRESH_FIFO_GT_EIGHTH_FULL 3 31 32 /* 33 * VAS window Linux status bits 34 */ 35 #define VAS_WIN_ACTIVE 0x0 /* Use 36 /* vas 37 /* Window is closed in the hypervisor due to l 38 #define VAS_WIN_NO_CRED_CLOSE 0x00000001 39 /* Window is closed due to migration */ 40 #define VAS_WIN_MIGRATE_CLOSE 0x00000002 41 42 /* 43 * Get/Set bit fields 44 */ 45 #define GET_FIELD(m, v) (((v) & 46 #define MASK_LSH(m) (__builtin_ffsl 47 #define SET_FIELD(m, v, val) \ 48 (((v) & ~(m)) | ((((typeof(v)) 49 50 /* 51 * Co-processor Engine type. 52 */ 53 enum vas_cop_type { 54 VAS_COP_TYPE_FAULT, 55 VAS_COP_TYPE_842, 56 VAS_COP_TYPE_842_HIPRI, 57 VAS_COP_TYPE_GZIP, 58 VAS_COP_TYPE_GZIP_HIPRI, 59 VAS_COP_TYPE_FTW, 60 VAS_COP_TYPE_MAX, 61 }; 62 63 /* 64 * User space VAS windows are opened by tasks 65 * to pid and mm until windows are closed. 66 * Stores pid, mm, and tgid for each window. 67 */ 68 struct vas_user_win_ref { 69 struct pid *pid; /* PID of owne 70 struct pid *tgid; /* Thread grou 71 struct mm_struct *mm; /* Linux proce 72 struct mutex mmap_mutex; /* pro 73 /* wit 74 struct vm_area_struct *vma; /* Sav 75 }; 76 77 /* 78 * Common VAS window struct on PowerNV and Pow 79 */ 80 struct vas_window { 81 u32 winid; 82 u32 wcreds_max; /* Window credits */ 83 u32 status; /* Window status used 84 enum vas_cop_type cop; 85 struct vas_user_win_ref task_ref; 86 char *dbgname; 87 struct dentry *dbgdir; 88 }; 89 90 /* 91 * User space window operations used for power 92 */ 93 struct vas_user_win_ops { 94 struct vas_window * (*open_win)(int va 95 enum vas_cop_t 96 u64 (*paste_addr)(struct vas_window *) 97 int (*close_win)(struct vas_window *); 98 }; 99 100 static inline void put_vas_user_win_ref(struct 101 { 102 /* Drop references to pid, tgid, and m 103 put_pid(ref->pid); 104 put_pid(ref->tgid); 105 if (ref->mm) 106 mmdrop(ref->mm); 107 } 108 109 static inline void vas_user_win_add_mm_context 110 { 111 mm_context_add_vas_window(ref->mm); 112 /* 113 * Even a process that has no foreign 114 * use an unpaired COPY instruction (t 115 * CP_ABORT to clear any pending COPY 116 * channel. 117 * 118 * __switch_to() will issue CP_ABORT o 119 * if process / thread has any open VA 120 * current->mm->context.vas_windows). 121 */ 122 asm volatile(PPC_CP_ABORT); 123 } 124 125 /* 126 * Receive window attributes specified by the 127 */ 128 struct vas_rx_win_attr { 129 u64 rx_fifo; 130 int rx_fifo_size; 131 int wcreds_max; 132 133 bool pin_win; 134 bool rej_no_credit; 135 bool tx_wcred_mode; 136 bool rx_wcred_mode; 137 bool tx_win_ord_mode; 138 bool rx_win_ord_mode; 139 bool data_stamp; 140 bool nx_win; 141 bool fault_win; 142 bool user_win; 143 bool notify_disable; 144 bool intr_disable; 145 bool notify_early; 146 147 int lnotify_lpid; 148 int lnotify_pid; 149 int lnotify_tid; 150 u32 pswid; 151 152 int tc_mode; 153 }; 154 155 /* 156 * Window attributes specified by the in-kerne 157 */ 158 struct vas_tx_win_attr { 159 enum vas_cop_type cop; 160 int wcreds_max; 161 int lpid; 162 int pidr; /* hardware PI 163 int pswid; 164 int rsvd_txbuf_count; 165 int tc_mode; 166 167 bool user_win; 168 bool pin_win; 169 bool rej_no_credit; 170 bool rsvd_txbuf_enable; 171 bool tx_wcred_mode; 172 bool rx_wcred_mode; 173 bool tx_win_ord_mode; 174 bool rx_win_ord_mode; 175 }; 176 177 #ifdef CONFIG_PPC_POWERNV 178 /* 179 * Helper to map a chip id to VAS id. 180 * For POWER9, this is a 1:1 mapping. In the f 181 * mapping in which case, we will need to upda 182 * 183 * Return the VAS id or -1 if no matching vasi 184 */ 185 int chip_to_vas_id(int chipid); 186 187 /* 188 * Helper to initialize receive window attribu 189 * NX window. 190 */ 191 void vas_init_rx_win_attr(struct vas_rx_win_at 192 193 /* 194 * Open a VAS receive window for the instance 195 * Use @attr to initialize the attributes of t 196 * 197 * Return a handle to the window or ERR_PTR() 198 */ 199 struct vas_window *vas_rx_win_open(int vasid, 200 struct vas_ 201 202 /* 203 * Helper to initialize send window attributes 204 */ 205 extern void vas_init_tx_win_attr(struct vas_tx 206 enum vas_cop_type cop) 207 208 /* 209 * Open a VAS send window for the instance of 210 * and the co-processor type @cop. Use @attr t 211 * of the window. 212 * 213 * Note: The instance of VAS must already have 214 * the coprocessor type @cop. 215 * 216 * Return a handle to the send window or ERR_P 217 */ 218 struct vas_window *vas_tx_win_open(int vasid, 219 struct vas_tx_win_attr 220 221 /* 222 * Close the send or receive window identified 223 * return -EAGAIN if there are active send win 224 * window. 225 */ 226 int vas_win_close(struct vas_window *win); 227 228 /* 229 * Copy the co-processor request block (CRB) @ 230 */ 231 int vas_copy_crb(void *crb, int offset); 232 233 /* 234 * Paste a previously copied CRB (see vas_copy 235 * the hardware address associated with the wi 236 * assumed to be true for NX windows. 237 */ 238 int vas_paste_crb(struct vas_window *win, int 239 240 int vas_register_api_powernv(struct module *mo 241 const char *name) 242 void vas_unregister_api_powernv(void); 243 #endif 244 245 #ifdef CONFIG_PPC_PSERIES 246 247 /* VAS Capabilities */ 248 #define VAS_GZIP_QOS_FEAT 0x1 249 #define VAS_GZIP_DEF_FEAT 0x2 250 #define VAS_GZIP_QOS_FEAT_BIT PPC_BIT(VAS_GZ 251 #define VAS_GZIP_DEF_FEAT_BIT PPC_BIT(VAS_GZ 252 253 /* NX Capabilities */ 254 #define VAS_NX_GZIP_FEAT 0x1 255 #define VAS_NX_GZIP_FEAT_BIT PPC_BIT(VAS_NX 256 257 /* 258 * These structs are used to retrieve overall 259 * the hypervisor provides. 260 */ 261 struct hv_vas_all_caps { 262 __be64 descriptor; 263 __be64 feat_type; 264 } __packed __aligned(0x1000); 265 266 struct vas_all_caps { 267 u64 descriptor; 268 u64 feat_type; 269 }; 270 271 int h_query_vas_capabilities(const u64 hcall, 272 int vas_register_api_pseries(struct module *mo 273 enum vas_cop_type 274 void vas_unregister_api_pseries(void); 275 #endif 276 277 /* 278 * Register / unregister coprocessor type to V 279 * to user space. Applications can use this AP 280 * which can be used to send / receive request 281 * 282 * Only NX GZIP coprocessor type is supported 283 * used for others in future. 284 */ 285 int vas_register_coproc_api(struct module *mod 286 const char *name, 287 const struct vas_u 288 void vas_unregister_coproc_api(void); 289 290 int get_vas_user_win_ref(struct vas_user_win_r 291 void vas_update_csb(struct coprocessor_request 292 struct vas_user_win_ref *t 293 void vas_dump_crb(struct coprocessor_request_b 294 #endif /* __ASM_POWERPC_VAS_H */ 295
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.