1 /* SPDX-License-Identifier: GPL-2.0 */ 1 2 /* 3 * Adjunct processor (AP) interfaces 4 * 5 * Copyright IBM Corp. 2017 6 * 7 * Author(s): Tony Krowiak <akrowia@linux.vnet 8 * Martin Schwidefsky <schwidefsky@ 9 * Harald Freudenberger <freude@de. 10 */ 11 12 #ifndef _ASM_S390_AP_H_ 13 #define _ASM_S390_AP_H_ 14 15 #include <linux/io.h> 16 #include <asm/asm-extable.h> 17 18 /** 19 * The ap_qid_t identifier of an ap queue. 20 * If the AP facilities test (APFT) facility i 21 * card and queue index are 8 bit values, othe 22 * card index is 6 bit and queue index a 4 bit 23 */ 24 typedef unsigned int ap_qid_t; 25 26 #define AP_MKQID(_card, _queue) (((_card) & 0x 27 #define AP_QID_CARD(_qid) (((_qid) >> 8) & 0xf 28 #define AP_QID_QUEUE(_qid) ((_qid) & 0xff) 29 30 /** 31 * struct ap_queue_status - Holds the AP queue 32 * @queue_empty: Shows if queue is empty 33 * @replies_waiting: Waiting replies 34 * @queue_full: Is 1 if the queue is full 35 * @irq_enabled: Shows if interrupts are enabl 36 * @response_code: Holds the 8 bit response co 37 * 38 * The ap queue status word is returned by all 39 * (PQAP, NQAP and DQAP). There's a set of fl 40 * byte, followed by a 1 byte response code. 41 */ 42 struct ap_queue_status { 43 unsigned int queue_empty : 1; 44 unsigned int replies_waiting : 1; 45 unsigned int queue_full : 1; 46 unsigned int : 3; 47 unsigned int async : 1; 48 unsigned int irq_enabled : 1; 49 unsigned int response_code : 8; 50 unsigned int : 16; 51 }; 52 53 /* 54 * AP queue status reg union to access the reg 55 * register with the lower 32 bits comprising 56 * ap queue status. 57 */ 58 union ap_queue_status_reg { 59 unsigned long value; 60 struct { 61 u32 _pad; 62 struct ap_queue_status status; 63 }; 64 }; 65 66 /** 67 * ap_intructions_available() - Test if AP ins 68 * 69 * Returns true if the AP instructions are ins 70 */ 71 static inline bool ap_instructions_available(v 72 { 73 unsigned long reg0 = AP_MKQID(0, 0); 74 unsigned long reg1 = 0; 75 76 asm volatile( 77 " lgr 0,%[reg0]\n" 78 " lghi 1,0\n" 79 " lghi 2,0\n" 80 " .insn rre,0xb2af0000 81 "0: la %[reg1],1\n" 82 "1:\n" 83 EX_TABLE(0b, 1b) 84 : [reg1] "+&d" (reg1) 85 : [reg0] "d" (reg0) 86 : "cc", "", "1", "2"); 87 return reg1 != 0; 88 } 89 90 /* TAPQ register GR2 response struct */ 91 struct ap_tapq_hwinfo { 92 union { 93 unsigned long value; 94 struct { 95 unsigned int fac : 96 unsigned int apinfo : 97 }; 98 struct { 99 unsigned int apsc : 100 unsigned int mex4k : 101 unsigned int crt4k : 102 unsigned int cca : 103 unsigned int accel : 104 unsigned int ep11 : 105 unsigned int apxa : 106 unsigned int : 107 unsigned int class : 108 unsigned int bs : 109 unsigned int : 1 110 unsigned int at : 111 unsigned int nd : 112 unsigned int : 113 unsigned int ml : 114 unsigned int : 115 unsigned int qd : 116 }; 117 }; 118 }; 119 120 /* 121 * Convenience defines to be used with the bs 122 */ 123 #define AP_BS_Q_USABLE 0 124 #define AP_BS_Q_USABLE_NO_SECURE_KEY 1 125 #define AP_BS_Q_AVAIL_FOR_BINDING 2 126 #define AP_BS_Q_UNUSABLE 3 127 128 /** 129 * ap_tapq(): Test adjunct processor queue. 130 * @qid: The AP queue number 131 * @info: Pointer to tapq hwinfo struct 132 * 133 * Returns AP queue status structure. 134 */ 135 static inline struct ap_queue_status ap_tapq(a 136 s 137 { 138 union ap_queue_status_reg reg1; 139 unsigned long reg2; 140 141 asm volatile( 142 " lgr 0,%[qid]\n" 143 " lghi 2,0\n" 144 " .insn rre,0xb2af0000 145 " lgr %[reg1],1\n" 146 " lgr %[reg2],2\n" 147 : [reg1] "=&d" (reg1.value), [ 148 : [qid] "d" (qid) 149 : "cc", "", "1", "2"); 150 if (info) 151 info->value = reg2; 152 return reg1.status; 153 } 154 155 /** 156 * ap_test_queue(): Test adjunct processor que 157 * @qid: The AP queue number 158 * @tbit: Test facilities bit 159 * @info: Ptr to tapq gr2 struct 160 * 161 * Returns AP queue status structure. 162 */ 163 static inline struct ap_queue_status ap_test_q 164 165 { 166 if (tbit) 167 qid |= 1UL << 23; /* set T bit 168 return ap_tapq(qid, info); 169 } 170 171 /** 172 * ap_pqap_rapq(): Reset adjunct processor que 173 * @qid: The AP queue number 174 * @fbit: if != 0 set F bit 175 * 176 * Returns AP queue status structure. 177 */ 178 static inline struct ap_queue_status ap_rapq(a 179 { 180 unsigned long reg0 = qid | (1UL << 24) 181 union ap_queue_status_reg reg1; 182 183 if (fbit) 184 reg0 |= 1UL << 22; 185 186 asm volatile( 187 " lgr 0,%[reg0]\n" 188 " .insn rre,0xb2af0000 189 " lgr %[reg1],1\n" 190 : [reg1] "=&d" (reg1.value) 191 : [reg0] "d" (reg0) 192 : "cc", "", "1"); 193 return reg1.status; 194 } 195 196 /** 197 * ap_pqap_zapq(): Reset and zeroize adjunct p 198 * @qid: The AP queue number 199 * @fbit: if != 0 set F bit 200 * 201 * Returns AP queue status structure. 202 */ 203 static inline struct ap_queue_status ap_zapq(a 204 { 205 unsigned long reg0 = qid | (2UL << 24) 206 union ap_queue_status_reg reg1; 207 208 if (fbit) 209 reg0 |= 1UL << 22; 210 211 asm volatile( 212 " lgr 0,%[reg0]\n" 213 " .insn rre,0xb2af0000 214 " lgr %[reg1],1\n" 215 : [reg1] "=&d" (reg1.value) 216 : [reg0] "d" (reg0) 217 : "cc", "", "1"); 218 return reg1.status; 219 } 220 221 /** 222 * struct ap_config_info - convenience struct 223 * config info as returned by the ap_qci() fun 224 */ 225 struct ap_config_info { 226 union { 227 unsigned int flags; 228 struct { 229 unsigned int apsc 230 unsigned int apxa 231 unsigned int qact 232 unsigned int rc8a 233 unsigned int 234 unsigned int apsb 235 unsigned int 236 }; 237 }; 238 unsigned char na; /* max 239 unsigned char nd; /* max 240 unsigned char _reserved0[10]; 241 unsigned int apm[8]; /* AP 242 unsigned int aqm[8]; /* AP 243 unsigned int adm[8]; /* AP 244 unsigned char _reserved1[16]; 245 } __aligned(8); 246 247 /** 248 * ap_qci(): Get AP configuration data 249 * 250 * Returns 0 on success, or -EOPNOTSUPP. 251 */ 252 static inline int ap_qci(struct ap_config_info 253 { 254 unsigned long reg0 = 4UL << 24; /* fc 255 unsigned long reg1 = -EOPNOTSUPP; 256 struct ap_config_info *reg2 = config; 257 258 asm volatile( 259 " lgr 0,%[reg0]\n" 260 " lgr 2,%[reg2]\n" 261 " .insn rre,0xb2af0000 262 "0: la %[reg1],0\n" 263 "1:\n" 264 EX_TABLE(0b, 1b) 265 : [reg1] "+&d" (reg1) 266 : [reg0] "d" (reg0), [reg2] "d 267 : "cc", "memory", "", "2"); 268 269 return reg1; 270 } 271 272 /* 273 * struct ap_qirq_ctrl - convenient struct for 274 * of the ap_aqic() function. This struct is p 275 * parameter to the PQAP(AQIC) instruction. Fo 276 * see the AR documentation. 277 */ 278 union ap_qirq_ctrl { 279 unsigned long value; 280 struct { 281 unsigned int : 8; 282 unsigned int zone : 8; /* zon 283 unsigned int ir : 1; /* ir 284 unsigned int : 4; 285 unsigned int gisc : 3; /* gue 286 unsigned int : 6; 287 unsigned int gf : 2; /* gis 288 unsigned int : 1; 289 unsigned int gisa : 27; 290 unsigned int : 1; 291 unsigned int isc : 3; /* irq 292 }; 293 }; 294 295 /** 296 * ap_aqic(): Control interruption for a speci 297 * @qid: The AP queue number 298 * @qirqctrl: struct ap_qirq_ctrl (64 bit valu 299 * @pa_ind: Physical address of the notificati 300 * 301 * Returns AP queue status. 302 */ 303 static inline struct ap_queue_status ap_aqic(a 304 u 305 p 306 { 307 unsigned long reg0 = qid | (3UL << 24) 308 union ap_queue_status_reg reg1; 309 unsigned long reg2 = pa_ind; 310 311 reg1.value = qirqctrl.value; 312 313 asm volatile( 314 " lgr 0,%[reg0]\n" 315 " lgr 1,%[reg1]\n" 316 " lgr 2,%[reg2]\n" 317 " .insn rre,0xb2af0000 318 " lgr %[reg1],1\n" 319 : [reg1] "+&d" (reg1.value) 320 : [reg0] "d" (reg0), [reg2] "d 321 : "cc", "memory", "", "1", "2" 322 323 return reg1.status; 324 } 325 326 /* 327 * union ap_qact_ap_info - used together with 328 * ap_aqic() function to provide a convenient 329 * to handle the ap info needed by the qact fu 330 */ 331 union ap_qact_ap_info { 332 unsigned long val; 333 struct { 334 unsigned int : 3; 335 unsigned int mode : 3; 336 unsigned int : 26; 337 unsigned int cat : 8; 338 unsigned int : 8; 339 unsigned char ver[2]; 340 }; 341 }; 342 343 /** 344 * ap_qact(): Query AP compatibility type. 345 * @qid: The AP queue number 346 * @apinfo: On input the info about the AP que 347 * alternate AP queue info provided b 348 * in GR2 is stored in. 349 * 350 * Returns AP queue status. Check response_cod 351 */ 352 static inline struct ap_queue_status ap_qact(a 353 u 354 { 355 unsigned long reg0 = qid | (5UL << 24) 356 union ap_queue_status_reg reg1; 357 unsigned long reg2; 358 359 reg1.value = apinfo->val; 360 361 asm volatile( 362 " lgr 0,%[reg0]\n" 363 " lgr 1,%[reg1]\n" 364 " .insn rre,0xb2af0000 365 " lgr %[reg1],1\n" 366 " lgr %[reg2],2\n" 367 : [reg1] "+&d" (reg1.value), [ 368 : [reg0] "d" (reg0) 369 : "cc", "", "1", "2"); 370 apinfo->val = reg2; 371 return reg1.status; 372 } 373 374 /* 375 * ap_bapq(): SE bind AP queue. 376 * @qid: The AP queue number 377 * 378 * Returns AP queue status structure. 379 * 380 * Invoking this function in a non-SE environm 381 * may case a specification exception. 382 */ 383 static inline struct ap_queue_status ap_bapq(a 384 { 385 unsigned long reg0 = qid | (7UL << 24) 386 union ap_queue_status_reg reg1; 387 388 asm volatile( 389 " lgr 0,%[reg0]\n" 390 " .insn rre,0xb2af0000 391 " lgr %[reg1],1\n" 392 : [reg1] "=&d" (reg1.value) 393 : [reg0] "d" (reg0) 394 : "cc", "", "1"); 395 396 return reg1.status; 397 } 398 399 /* 400 * ap_aapq(): SE associate AP queue. 401 * @qid: The AP queue number 402 * @sec_idx: The secret index 403 * 404 * Returns AP queue status structure. 405 * 406 * Invoking this function in a non-SE environm 407 * may case a specification exception. 408 */ 409 static inline struct ap_queue_status ap_aapq(a 410 { 411 unsigned long reg0 = qid | (8UL << 24) 412 unsigned long reg2 = sec_idx; 413 union ap_queue_status_reg reg1; 414 415 asm volatile( 416 " lgr 0,%[reg0]\n" 417 " lgr 2,%[reg2]\n" 418 " .insn rre,0xb2af0000 419 " lgr %[reg1],1\n" 420 : [reg1] "=&d" (reg1.value) 421 : [reg0] "d" (reg0), [reg2] "d 422 : "cc", "", "1", "2"); 423 424 return reg1.status; 425 } 426 427 /** 428 * ap_nqap(): Send message to adjunct processo 429 * @qid: The AP queue number 430 * @psmid: The program supplied message identi 431 * @msg: The message text 432 * @length: The message length 433 * 434 * Returns AP queue status structure. 435 * Condition code 1 on NQAP can't happen becau 436 * Condition code 2 on NQAP also means the sen 437 * because a segment boundary was reached. The 438 */ 439 static inline struct ap_queue_status ap_nqap(a 440 u 441 v 442 { 443 unsigned long reg0 = qid | 0x40000000U 444 union register_pair nqap_r1, nqap_r2; 445 union ap_queue_status_reg reg1; 446 447 nqap_r1.even = (unsigned int)(psmid >> 448 nqap_r1.odd = psmid & 0xffffffff; 449 nqap_r2.even = (unsigned long)msg; 450 nqap_r2.odd = (unsigned long)length; 451 452 asm volatile ( 453 " lgr 0,%[reg0]\n" 454 "0: .insn rre,0xb2ad0000 455 " brc 2,0b\n" 456 " lgr %[reg1],1\n" 457 : [reg0] "+&d" (reg0), [reg1] 458 [nqap_r2] "+&d" (nqap_r2.pai 459 : [nqap_r1] "d" (nqap_r1.pair) 460 : "cc", "memory", "", "1"); 461 return reg1.status; 462 } 463 464 /** 465 * ap_dqap(): Receive message from adjunct pro 466 * @qid: The AP queue number 467 * @psmid: Pointer to program supplied message 468 * @msg: Pointer to message buffer 469 * @msglen: Message buffer size 470 * @length: Pointer to length of actually writ 471 * @reslength: Residual length on return 472 * @resgr0: input: gr0 value (only used if != 473 * 474 * Returns AP queue status structure. 475 * Condition code 1 on DQAP means the receive 476 * but only partially. The response is incomp 477 * DQAP is repeated. 478 * Condition code 2 on DQAP also means the rec 479 * this time because a segment boundary was re 480 * DQAP is repeated. 481 * Note that gpr2 is used by the DQAP instruct 482 * any 'residual' length, in case the instruct 483 * Hence it gets zeroed before the instruction 484 * If the message does not fit into the buffer 485 * return with a truncated message and the rep 486 * is not removed. This is indicated to the ca 487 * ap_queue_status response_code value of all 488 * the reslength ptr is given) the remaining l 489 * *reslength and (if the resgr0 ptr is given) 490 * for further processing of this msg entry is 491 * caller needs to detect this situation and s 492 * with a valid resgr0 ptr and a value in ther 493 * *resgr0 is to be used instead of qid to fur 494 */ 495 static inline struct ap_queue_status ap_dqap(a 496 u 497 v 498 s 499 s 500 u 501 { 502 unsigned long reg0 = resgr0 && *resgr0 503 union ap_queue_status_reg reg1; 504 unsigned long reg2; 505 union register_pair rp1, rp2; 506 507 rp1.even = 0UL; 508 rp1.odd = 0UL; 509 rp2.even = (unsigned long)msg; 510 rp2.odd = (unsigned long)msglen; 511 512 asm volatile( 513 " lgr 0,%[reg0]\n" 514 " lghi 2,0\n" 515 "0: ltgr %N[rp2],%N[rp2 516 " jz 2f\n" 517 "1: .insn rre,0xb2ae0000 518 " brc 6,0b\n" 519 "2: lgr %[reg0],0\n" 520 " lgr %[reg1],1\n" 521 " lgr %[reg2],2\n" 522 : [reg0] "+&d" (reg0), [reg1] 523 [reg2] "=&d" (reg2), [rp1] " 524 [rp2] "+&d" (rp2.pair) 525 : 526 : "cc", "memory", "", "1", "2" 527 528 if (reslength) 529 *reslength = reg2; 530 if (reg2 != 0 && rp2.odd == 0) { 531 /* 532 * Partially complete, status 533 * Signal the caller that this 534 * with a special status respo 535 */ 536 reg1.status.response_code = 0x 537 if (resgr0) 538 *resgr0 = reg0; 539 } else { 540 *psmid = (rp1.even << 32) + rp 541 if (resgr0) 542 *resgr0 = 0; 543 } 544 545 /* update *length with the nr of bytes 546 if (length) 547 *length = msglen - rp2.odd; 548 549 return reg1.status; 550 } 551 552 #endif /* _ASM_S390_AP_H_ */ 553
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.