-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel.c
6289 lines (5415 loc) · 228 KB
/
channel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* CHANNEL.C (C) Copyright Roger Bowler, 1999-2012 */
/* (C) Copyright Jan Jaeger, 1999-2012 */
/* (C) Copyright Mark L. Gaubatz, 2010, 2013 */
/* ESA/390 Channel Emulator */
/* */
/* Released under "The Q Public License Version 1" */
/* (http://www.hercules-390.org/herclic.html) as modifications to */
/* Hercules. */
/* z/Architecture support - */
/* (C) Copyright Jan Jaeger, 1999-2012 */
/* Rewrite of channel code and associated structures - */
/* (C) Copyright Mark L. Gaubatz, 2010, 2013 */
/*-------------------------------------------------------------------*/
/* This module contains the channel subsystem functions for the */
/* Hercules S/370 and ESA/390 emulator. */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* Additional credits: */
/* Measurement block support by Jan Jaeger */
/* Fix program check on NOP due to addressing - Jan Jaeger */
/* Fix program check on TIC as first ccw on RSCH - Jan Jaeger */
/* Fix PCI intermediate status flags - Jan Jaeger */
/* 64-bit IDAW support - Roger Bowler v209 @IWZ*/
/* Incorrect-length-indication-suppression - Jan Jaeger */
/* Read backward support contributed by Hackules 13jun2002 */
/* Read backward fixes contributed by Jay Jaeger 16sep2003 */
/* MIDAW support - Roger Bowler 03aug2005 @MW*/
/*-------------------------------------------------------------------*/
#include "hstdinc.h"
DISABLE_GCC_UNUSED_FUNCTION_WARNING;
#define _CHANNEL_C_
#define _HENGINE_DLL_
#include "hercules.h"
#include "devtype.h"
#include "opcode.h"
#include "chsc.h"
DISABLE_GCC_UNUSED_SET_WARNING;
/*-------------------------------------------------------------------*/
/* Debug Switches */
/*-------------------------------------------------------------------*/
#ifndef CHANNEL_DEBUG_SWITCHES
#define CHANNEL_DEBUG_SWITCHES
#define DEBUG_SCSW 0
#define DEBUG_PREFETCH 0
#define DEBUG_DUMP 0
#endif
/*-------------------------------------------------------------------*/
/* CCW Tracing helper macros */
/*-------------------------------------------------------------------*/
#ifndef OSTAILOR_QUIET
#define OSTAILOR_QUIET() (!sysblk.pgminttr)
#endif
#ifndef CCW_TRACE_OR_STEP
#define CCW_TRACE_OR_STEP( dev ) ((dev)->ccwtrace || (dev)->ccwstep)
#endif
#ifndef CCW_TRACING_ACTIVE
#define CCW_TRACING_ACTIVE( dev, tracethis ) (CCW_TRACE_OR_STEP( dev ) \
|| ( tracethis ))
#endif
#ifndef SKIP_CH9UC
#define SKIP_CH9UC( dev, chanstat, unitstat ) \
\
(1 \
&& !CCW_TRACE_OR_STEP( dev ) \
&& !CPU_STEPPING_OR_TRACING_ALL \
&& sysblk.noch9oflow \
&& is_ch9oflow( dev, chanstat, unitstat ) \
)
#endif
/*-------------------------------------------------------------------*/
/* helper function to check if printer channel-9 overflow unit check */
/*-------------------------------------------------------------------*/
#ifndef IS_CH9OFLOW
#define IS_CH9OFLOW
static BYTE is_ch9oflow( DEVBLK* dev, BYTE chanstat, BYTE unitstat )
{
static const BYTE unitck = (CSW_CE | CSW_DE | CSW_UC);
if (1
&& 0 == chanstat
&& unitck == unitstat
&& SENSE_CH9 == dev->sense[0]
&& 0 == dev->sense[1]
&& dev->hnd->query
)
{
char* devclass = NULL;
dev->hnd->query( NULL, &devclass, 0, NULL );
if (strcmp( devclass, "PRT" ) == 0)
return TRUE;
}
return FALSE;
}
#endif // IS_CH9OFLOW
/*-------------------------------------------------------------------*/
/* Internal function definitions */
/*-------------------------------------------------------------------*/
void call_execute_ccw_chain (int arch_mode, void* pDevBlk);
DLL_EXPORT void* device_thread (void *arg);
static int schedule_ioq (const REGS* regs, DEVBLK* dev);
static INLINE void subchannel_interrupt_queue_cleanup (DEVBLK*);
int test_subchan_locked (REGS*, DEVBLK*, IRB*, IOINT**, SCSW**);
#ifndef CHANNEL_INLINES
#define CHANNEL_INLINES
static INLINE U8 IS_CCW_IMMEDIATE( const DEVBLK* dev, const BYTE code )
{
return
(0
|| (dev->hnd->immed && dev->hnd->immed[code])
|| (dev->immed && dev->immed[code])
|| IS_CCW_NOP( dev->code )
);
}
static INLINE void
set_subchannel_busy(DEVBLK* dev)
{
dev->busy = 1;
dev->scsw.flag3 |= SCSW3_AC_SCHAC | SCSW3_SC_INTER;
}
static INLINE void
set_device_busy(DEVBLK* dev)
{
set_subchannel_busy(dev);
dev->scsw.flag3 |= SCSW3_AC_DEVAC;
}
static INLINE void
clear_subchannel_busy_scsw(SCSW* scsw)
{
scsw->flag3 &= ~(SCSW3_AC_SCHAC |
SCSW3_AC_DEVAC |
SCSW3_SC_INTER);
}
static INLINE void
clear_subchannel_busy(DEVBLK* dev)
{
clear_subchannel_busy_scsw(&dev->scsw);
dev->startpending = 0;
dev->busy = 0;
}
static INLINE void
clear_device_busy_scsw(SCSW* scsw)
{
scsw->flag3 &= ~SCSW3_AC_DEVAC;
}
static INLINE void
clear_device_busy(DEVBLK* dev)
{
clear_device_busy_scsw(&dev->scsw);
}
#endif /*CHANNEL_INLINES*/
/*-------------------------------------------------------------------*/
/* Internal I/O Buffer Structure and Inline Support Routines */
/*-------------------------------------------------------------------*/
#ifndef IOBUF_STRUCT
#define IOBUF_STRUCT
/* CAUTION: for performance reasons the size of the data portion
of IOBUF (i.e. IOBUF_MINSIZE) should never be less than 64K-1,
and sizes greater than 64K may cause stack overflows to occur.
*/
#define IOBUF_ALIGN 4096 /* Must be a power of 2 */
#define IOBUF_HDRSIZE IOBUF_ALIGN /* Multiple of IOBUF_ALIGN */
#define IOBUF_MINSIZE 65536 /* Multiple of IOBUF_ALIGN */
#define IOBUF_INCREASE 1048576 /* Multiple of IOBUF_ALIGN */
CASSERT( IOBUF_HDRSIZE == ROUND_UP( IOBUF_HDRSIZE, IOBUF_ALIGN ), IOBUF_HDRSIZE );
CASSERT( IOBUF_MINSIZE == ROUND_UP( IOBUF_MINSIZE, IOBUF_ALIGN ), IOBUF_MINSIZE );
CASSERT( IOBUF_INCREASE == ROUND_UP( IOBUF_INCREASE, IOBUF_ALIGN ), IOBUF_INCREASE );
struct IOBUF
{
/* Every IOBUF struct starts with a 4K header the first few
* bytes of which hold the IOBUF control variables defining
* the size of the actual usable channel I/O buffer portion
* of the IOBUF structure, a pointer to the actual channel
* I/O buffer itself, and a second pointer pointing to the
* last logical byte of the channel I/O buffer. The actual
* channel I/O buffer immediately follows the IOBUF header.
*
* Every IOBUF is always aligned on a 4K boundary thus en-
* suring the actual channel I/O buffer itself is as well.
*
* The size of every IOBUF will always be a multiple of 4K.
*
* When an IOBUF is reallocated larger, if the old size is
* larger than IOBUF_MINSIZE bytes, it means the IOBUF was
* malloc'ed on the heap and thus the old IOBUF should then
* be freed. Otherwise if the old size is less or equal to
* IOBUF_MINSIZE, it means the IOBUF was allocated on the
* stack and thus free should not be done.
*/
union
{
struct
{
u_int size; /* Channel I/O buffer size */
BYTE *start; /* Start of data address */
BYTE *end; /* Last byte address */
/* Note: Remaining space from 4K page is reserved
* for debugging and future use. No mapping
* of the space is presently done.
*/
};
BYTE pad[IOBUF_HDRSIZE]; /* Pad to alignment boundary */
};
BYTE data[IOBUF_MINSIZE]; /* Channel I/O buffer itself */
};
typedef struct IOBUF IOBUF;
static INLINE void
iobuf_initialize (IOBUF *iobuf, const u_int size)
{
iobuf->size = size;
iobuf->start = (BYTE *)iobuf->data;
iobuf->end = (BYTE *)iobuf->start + (size - 1);
}
static INLINE IOBUF *
iobuf_create (u_int size)
{
IOBUF *iobuf;
size = ROUND_UP( size, IOBUF_INCREASE );
iobuf = (IOBUF*)malloc_aligned(offsetof(IOBUF,data) + size, IOBUF_ALIGN);
if (iobuf != NULL)
iobuf_initialize(iobuf, size);
return iobuf;
}
static INLINE u_int
iobuf_validate (IOBUF *iobuf)
{
return
((iobuf == NULL ||
iobuf->size < IOBUF_MINSIZE ||
iobuf->start != (BYTE *)iobuf->data ||
iobuf->end != (BYTE *)iobuf->start + (iobuf->size - 1 )) ?
0 : 1);
}
static INLINE void
iobuf_destroy (IOBUF *iobuf)
{
/* PROGRAMMING NOTE: The tests below are purposely neither macros
* or inlined routines. This is to permit breakpoints during
* development and testing. In the future, instead of aborting
* and/or crashing, the code will branch (or longjmp) to a point in
* channel code where the current CCW chain will be terminated,
* cleanup performed, and a Channel Check, and/or a Machine Check,
* will be returned.
*/
if (iobuf == NULL)
return;
if (!iobuf_validate(iobuf))
CRASH();
if (iobuf->size > IOBUF_MINSIZE)
free_aligned(iobuf);
}
static INLINE IOBUF*
iobuf_reallocate (IOBUF *iobuf, const u_int size)
{
IOBUF *iobufnew;
/* PROGRAMMING NOTE: The tests below are purposely neither macros
* or inlined routines. This is to permit breakpoints during
* development and testing. In the future, instead of aborting
* and/or crashing, the code will branch (or longjmp) to a point in
* channel code where the current CCW chain will be terminated,
* cleanup performed, and a Channel Check, and/or a Machine Check,
* will be returned.
*/
if (iobuf == NULL)
return NULL;
if (!iobuf_validate(iobuf))
CRASH();
iobufnew = iobuf_create(size);
if (iobufnew == NULL)
return NULL;
memcpy(iobufnew->start, iobuf->start, MIN(iobuf->size, size));
if (iobuf->size > IOBUF_MINSIZE)
free_aligned(iobuf);
return iobufnew;
}
#endif /* IOBUF_STRUCT */
/*--------------------------------------------------------------------*/
/* CCW prefetch data structure */
/*--------------------------------------------------------------------*/
#ifndef PREFETCH_STRUCT
#define PREFETCH_STRUCT
/* Define 256 entries in the prefetch table */
#define PF_SIZE 256
/* IDAW Types */
enum PF_IDATYPE
{
PF_NO_IDAW = 0,
PF_IDAW1 = 1,
PF_IDAW2 = 2,
PF_MIDAW = 3
};
struct PREFETCH /* Prefetch data structure */
{
u_int seq; /* Counter */
u_int pos; /* Highest valid position */
U32 reqcount; /* Requested count */
U8 prevcode; /* Previous CCW opcode */
U8 opcode; /* CCW opcode */
U16 reserved;
BYTE chanstat[PF_SIZE]; /* Channel status */
U32 ccwaddr[PF_SIZE]; /* CCW address (SCSW CCW) */
U32 datalen[PF_SIZE]; /* Count (length) */
RADR dataaddr[PF_SIZE]; /* Address */
U8 ccwflags[PF_SIZE]; /* CCW flags */
U16 ccwcount[PF_SIZE]; /* Count (length) */
U32 idawaddr[PF_SIZE]; /* IDAW address */
U8 idawtype[PF_SIZE]; /* IDAW type */
U8 idawflag[PF_SIZE]; /* IDAW flags */
};
typedef struct PREFETCH PREFETCH;
#endif /* PREFETCH_STRUCT */
/*--------------------------------------------------------------------*/
/* IODELAY - kludge */
/*--------------------------------------------------------------------*/
#ifdef OPTION_IODELAY_KLUDGE
#define IODELAY(_dev) \
do { \
if (sysblk.iodelay > 0 && (_dev)->devchar[10] == 0x20) \
usleep(sysblk.iodelay); \
} while(0)
#else
#define IODELAY(_dev)
#endif
/*--------------------------------------------------------------------*/
/* CHADDRCHK - validate guest channel i/o subsystem address */
/*--------------------------------------------------------------------*/
#undef CHADDRCHK
#if defined(FEATURE_ADDRESS_LIMIT_CHECKING)
#define CHADDRCHK(_addr,_dev) \
( ((_addr) > (_dev)->mainlim) \
|| (((_dev)->orb.flag5 & ORB5_A) \
&& ((((_dev)->pmcw.flag5 & PMCW5_LM_LOW) \
&& ((_addr) < sysblk.addrlimval)) \
|| (((_dev)->pmcw.flag5 & PMCW5_LM_HIGH) \
&& ((_addr) >= sysblk.addrlimval)) ) ))
#else /* !defined(FEATURE_ADDRESS_LIMIT_CHECKING) */
#define CHADDRCHK(_addr,_dev) \
((_addr) > (_dev)->mainlim)
#endif /* defined(FEATURE_ADDRESS_LIMIT_CHECKING) */
/*--------------------------------------------------------------------*/
/* C H A N N E L P R O C E S S I N G */
/*--------------------------------------------------------------------*/
#ifndef _CHANNEL_C
#define _CHANNEL_C
static INLINE U64
BytesToEndOfStorage( const RADR addr, const DEVBLK* dev )
{
if (dev) return ((addr <= dev->mainlim) ? (dev->mainlim+1 - addr) : 0);
else return ((addr < sysblk.mainsize) ? (sysblk.mainsize - addr) : 0);
}
#define CAPPED_BUFFLEN(_addr,_len,_dev) \
((u_int)MIN((U64)(_len),(U64)BytesToEndOfStorage((_addr),(_dev))))
/*--------------------------------------------------------------------*/
/* Inline routines for Conditions and Indications Cleared at the */
/* Subchannel by TEST SUBCHANNEL; use of the routines keep the */
/* logic flow through the table of conditions clean. */
/* */
/* SA22-7832-09, Figure 14-2, Conditions and Indications Cleared at */
/* the Subchannel by TEST SUBCHANNEL, p. 14-21. */
/* */
/*--------------------------------------------------------------------*/
static INLINE void
scsw_clear_n_C (SCSW* scsw)
{
scsw->flag1 &= ~SCSW1_N;
}
static INLINE void
scsw_clear_q_C (SCSW* scsw)
{
scsw->flag2 &= ~SCSW2_Q;
}
static INLINE void
scsw_clear_fc_C (SCSW* scsw)
{
scsw->flag2 &= ~SCSW2_FC;
}
static INLINE void
scsw_clear_fc_Nc (SCSW* scsw)
{
if (scsw->flag2 & SCSW2_FC_HALT &&
scsw->flag3 & SCSW3_AC_SUSP)
scsw_clear_fc_C(scsw);
}
static INLINE void
scsw_clear_ac_Cp (SCSW* scsw)
{
scsw->flag2 &= ~(SCSW2_AC_RESUM |
SCSW2_AC_START |
SCSW2_AC_HALT |
SCSW2_AC_CLEAR);
scsw->flag3 &= ~SCSW3_AC_SUSP;
}
static INLINE void
scsw_clear_ac_Nr (SCSW* scsw)
{
if (scsw->flag2 & SCSW2_FC_START &&
scsw->flag3 & SCSW3_AC_SUSP)
{
if (scsw->flag2 & SCSW2_FC_HALT)
scsw_clear_ac_Cp(scsw);
else
{
scsw->flag2 &= ~SCSW2_AC_RESUM;
scsw_clear_n_C(scsw);
}
}
}
static INLINE void
scsw_clear_sc_Cs (SCSW* scsw)
{
scsw->flag3 &= ~(SCSW3_SC_ALERT |
SCSW3_SC_INTER |
SCSW3_SC_PRI |
SCSW3_SC_SEC |
SCSW3_SC_PEND);
}
/*--------------------------------------------------------------------*/
/* AIPSX (dev) */
/* */
/* Generates the AIPSX indication for Figure 16-5, the Deferred- */
/* Condition-Code Meaning for Status-Pending Subchannel, Figure */
/* 16-5. */
/*--------------------------------------------------------------------*/
static INLINE U8
AIPSX (const SCSW* scsw)
{
U8 result = (scsw->flag1 & SCSW1_A) /* >> 4 << 4 */
| ((scsw->flag1 & SCSW1_I) >> 2 /* >> 5 << 3 */
| (scsw->flag0 & SCSW0_S) >> 2) /* >> 3 << 1 */
| ((scsw->flag1 & SCSW1_P) >> 4) /* >> 6 << 2 */
| (scsw->flag3 & SCSW3_SC_PEND); /* >> 0 << 0 */
return (result);
}
/*--------------------------------------------------------------------*/
/* Queue I/O interrupt and update status (locked) */
/* */
/* Locks Held on Entry */
/* sysblk.intlock */
/* dev->lock */
/* Locks Held on Return */
/* sysblk.intlock */
/* dev->lock */
/* Locks Used */
/* sysblk.iointqlk */
/*--------------------------------------------------------------------*/
static INLINE void
queue_io_interrupt_and_update_status_locked(DEVBLK* dev, int clrbsy)
{
/* Get the I/O interrupt queue lock */
obtain_lock(&sysblk.iointqlk);
/* Ensure the interrupt is queued/dequeued per pending flag */
if (dev->scsw.flag3 & SCSW3_SC_PEND)
QUEUE_IO_INTERRUPT_QLOCKED(&dev->ioint,clrbsy);
else
DEQUEUE_IO_INTERRUPT_QLOCKED(&dev->ioint);
/* Perform cleanup for DEVBLK flags being deprecated */
subchannel_interrupt_queue_cleanup(dev);
/* Update interrupts */
UPDATE_IC_IOPENDING_QLOCKED();
/* Release the I/O interrupt queue lock */
release_lock(&sysblk.iointqlk);
#if defined( OPTION_SHARED_DEVICES )
/* Wake up any waiters if the device isn't active or reserved */
if (!(dev->scsw.flag3 & (SCSW3_AC_SCHAC | SCSW3_AC_DEVAC)) &&
!dev->reserved)
{
dev->shioactive = DEV_SYS_NONE;
if (dev->shiowaiters)
signal_condition (&dev->shiocond);
}
#endif // defined( OPTION_SHARED_DEVICES )
}
/*--------------------------------------------------------------------*/
/* Queue I/O interrupt and update status */
/* */
/* Locks Held on Entry */
/* None */
/* Locks Held on Return */
/* None */
/* Locks Used */
/* dev->lock */
/* sysblk.intlock */
/* sysblk.iointqlk */
/*--------------------------------------------------------------------*/
static INLINE void
queue_io_interrupt_and_update_status(DEVBLK* dev, int clrbsy)
{
if (likely(dev->scsw.flag3 & SCSW3_SC_PEND))
{
OBTAIN_INTLOCK(NULL);
obtain_lock(&dev->lock);
queue_io_interrupt_and_update_status_locked(dev,clrbsy);
/* Finish releasing locks */
release_lock(&dev->lock);
RELEASE_INTLOCK(NULL);
}
#if defined( OPTION_SHARED_DEVICES )
else /* No interrupt pending */
{
/* Wake up any waiters if the device isn't active or reserved */
if (!(dev->scsw.flag3 & (SCSW3_AC_SCHAC | SCSW3_AC_DEVAC)) &&
!dev->reserved)
{
obtain_lock(&dev->lock);
dev->shioactive = DEV_SYS_NONE;
if (dev->shiowaiters)
signal_condition (&dev->shiocond);
release_lock(&dev->lock);
}
}
#endif // defined( OPTION_SHARED_DEVICES )
}
/*-------------------------------------------------------------------*/
/* Copy memory backwards for READ BACKWARDS */
/* */
/* Note: Routines exist that use READ BACKWARDS and PCI, processing */
/* data as copied. Consequently, memory copying must be done */
/* backwards to ensure that these routines have little chance */
/* of failure. */
/* */
/*-------------------------------------------------------------------*/
static INLINE void
memcpy_backwards ( BYTE *to, BYTE *from, int length )
{
if (length)
{
for (to += length, from += length; length; --length)
*(--to) = *(--from);
}
}
/*-------------------------------------------------------------------*/
/* FORMAT DATA */
/*-------------------------------------------------------------------*/
#if !defined(format_data)
# define format_data(_buffer,_buflen,_data,_datalen) \
_format_data((BYTE *)(_buffer),(u_int)(_buflen), \
(BYTE *)(_data),(u_int)(_datalen))
#endif
static INLINE void
_format_data ( BYTE *buffer, const u_int buflen,
const BYTE *a, const u_int len )
{
u_int i, k; /* Array subscripts */
int j;
k = MIN(len, 16);
if (k)
{
j = snprintf((char *)buffer, buflen,
"%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X "
"%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X",
a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7],
a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15]);
if (j < 0)
*buffer = 0;
else
{
/* Blank out unused data */
if (k != 16)
{
i = (k << 1) + (k >> 2);
memset(buffer + i, ' ', j - i);
}
/* If space is available, add translation */
if ((u_int)j < buflen)
{
/* Insert blank separator */
buffer[j++] = ' ';
/* If space still available, complete translation */
if ((u_int)j < buflen)
{
/* Adjust data display size if necessary */
if ((j + k) > buflen)
k = buflen - j;
/* Append translation */
prt_guest_to_host(a, buffer + j, k);
}
}
}
}
else
*buffer = 0;
} /* end function format_data */
/*-------------------------------------------------------------------*/
/* FORMAT I/O BUFFER DATA */
/*-------------------------------------------------------------------*/
static INLINE void
format_iobuf_data ( const RADR addr, BYTE *dest, const DEVBLK *dev,
const u_int len )
{
u_int k; /* Array subscripts */
BYTE workarea[17]; /* Character string work */
k = MIN(sizeof(workarea)-1,CAPPED_BUFFLEN(addr,len,dev));
if (k)
{
memcpy(workarea, dev->mainstor + addr, k);
memcpy(dest, "=>", 2);
format_data(dest + 2, 52, workarea, k);
}
else
*dest = 0;
} /* end function format_iobuf_data */
#if DEBUG_DUMP
/*-------------------------------------------------------------------*/
/* Dump data block */
/*-------------------------------------------------------------------*/
#define dump(_desc,_addr,_len) \
_dump((char *)(_desc),(BYTE *)(_addr),(u_int)(_len))
static void
_dump ( const char *description, BYTE *addr, const u_int len )
{
int i;
int k = MIN(len, IOBUF_MINSIZE);
BYTE *limit;
char msgbuf[133];
if (k)
{
/* Set limit */
limit = addr + k;
if (description &&
description != NULL &&
description[0])
WRMSG(HHC90000, "I", description);
for (i = 0; addr < limit; addr += 16, i += 16, k -= 16)
{
MSGBUF(msgbuf, "%4.4X => ", i);
format_data(msgbuf+9, sizeof(msgbuf)-9, addr, k);
WRMSG(HHC90000, "I", msgbuf);
}
}
} /* end function dump */
/*-------------------------------------------------------------------*/
/* Dump Storage */
/*-------------------------------------------------------------------*/
#define dump_storage(_desc,_addr,_len) \
_dump_storage \
((char *)(_desc),(RADR)(_addr),(u_int)(_len))
static void
_dump_storage ( const char *description,
RADR addr, const u_int len )
{
u_int k; /* Amount of storage to dump */
BYTE *storage; /* Real storage address */
BYTE *limit; /* Display limit */
char msgbuf[133]; /* Message buffer */
/* Set length to fully reside within defined storage */
k = CAPPED_BUFFLEN(addr,len,NULL);
if (k)
{
k = MIN(k, IOBUF_MINSIZE);
storage = sysblk.mainstor + addr;
limit = storage + k;
if (description &&
description != NULL &&
description[0])
WRMSG(HHC90000, "I", description);
if (sysblk.mainsize > 2*ONE_GIGABYTE)
for (; storage < limit; addr += 16, storage += 16, k -= 16)
{
MSGBUF(msgbuf, "%16.16"PRIX64" => ", addr);
format_data(msgbuf+20, sizeof(msgbuf)-20, storage, k);
WRMSG(HHC90000, "I", msgbuf);
}
else
for (; storage < limit; addr += 16, storage += 16, k -= 16)
{
MSGBUF(msgbuf, "%8.8X => ", (u_int)addr);
format_data(msgbuf+12, sizeof(msgbuf)-12, storage, k);
WRMSG(HHC90000, "I", msgbuf);
}
}
} /* end function dump_storage */
#endif
/*-------------------------------------------------------------------*/
/* Display channel command word and data */
/*-------------------------------------------------------------------*/
static void
display_ccw ( const DEVBLK *dev, const BYTE ccw[], const U32 addr,
const U32 count, const U8 flags )
{
BYTE area[64]; /* Data display area */
UNREFERENCED(flags);
if (IS_CCW_READ(ccw[0]) ||
IS_CCW_IMMEDIATE(dev, ccw[0]) ||
IS_CCW_TIC(ccw[0]) ||
IS_CCW_SENSE(ccw[0]))
area[0] = 0;
else
format_iobuf_data (addr, area, dev, count);
// "%1d:%04X CHAN: ccw %2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X%s"
WRMSG (HHC01315, "I", SSID_TO_LCSS(dev->ssid), dev->devnum,
ccw[0], ccw[1], ccw[2], ccw[3],
ccw[4], ccw[5], ccw[6], ccw[7], area);
} /* end function display_ccw */
/*-------------------------------------------------------------------*/
/* Display interpretation of first two sense bytes */
/*-------------------------------------------------------------------*/
static void display_sense( const DEVBLK* dev )
{
char snsbuf[64];
/* Let the device interpret its own sense bytes if possible */
if (dev->sns)
dev->sns( dev, snsbuf, sizeof( snsbuf ));
else
/* Otherwise we use our default interpretation */
MSGBUF( snsbuf, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"
, (dev->sense[0] & SENSE_CR ) ? "CMDREJ " : ""
, (dev->sense[0] & SENSE_IR ) ? "INTREQ " : ""
, (dev->sense[0] & SENSE_BOC ) ? "BUSCK " : ""
, (dev->sense[0] & SENSE_EC ) ? "EQPCK " : ""
, (dev->sense[0] & SENSE_DC ) ? "DATCK " : ""
, (dev->sense[0] & SENSE_OR ) ? "OVRUN " : ""
, (dev->sense[0] & SENSE_CC ) ? "CTLCK " : ""
, (dev->sense[0] & SENSE_OC ) ? "OPRCK " : ""
, (dev->sense[1] & SENSE1_PER) ? "PERM " : ""
, (dev->sense[1] & SENSE1_ITF) ? "ITF " : ""
, (dev->sense[1] & SENSE1_EOC) ? "EOC " : ""
, (dev->sense[1] & SENSE1_MTO) ? "MSG " : ""
, (dev->sense[1] & SENSE1_NRF) ? "NRF " : ""
, (dev->sense[1] & SENSE1_FP ) ? "FP " : ""
, (dev->sense[1] & SENSE1_WRI) ? "WRI " : ""
, (dev->sense[1] & SENSE1_IE ) ? "IE " : ""
);
// "%1d:%04X CHAN: sense %s"
WRMSG( HHC01314, "I", SSID_TO_LCSS( dev->ssid ), dev->devnum, snsbuf );
}
/*-------------------------------------------------------------------*/
/* Display IDAW and Data */
/*-------------------------------------------------------------------*/
static void
display_idaw ( const DEVBLK *dev, const BYTE type, const BYTE flag,
const RADR addr, const U16 count )
{
BYTE area[64]; /* Data display area */
format_iobuf_data( addr, area, dev, count );
switch(type)
{
case PF_IDAW1:
WRMSG (HHC01302, "I", SSID_TO_LCSS(dev->ssid), dev->devnum,
(U32)addr, count, area);
break;
case PF_IDAW2:
WRMSG (HHC01303, "I", SSID_TO_LCSS(dev->ssid), dev->devnum,
(U64)addr, count, area);
break;
case PF_MIDAW:
WRMSG (HHC01301, "I", SSID_TO_LCSS(dev->ssid), dev->devnum,
flag, count, (U64)addr, area);
}
}
/*-------------------------------------------------------------------*/
/* DISPLAY CHANNEL STATUS WORD */
/*-------------------------------------------------------------------*/
static void
display_csw (const DEVBLK *dev, const BYTE csw[])
{
WRMSG (HHC01316, "I", SSID_TO_LCSS(dev->ssid), dev->devnum,
csw[0],
csw[4], csw[5], csw[6], csw[7],
csw[1], csw[2], csw[3]);
} /* end function display_csw */
/*-------------------------------------------------------------------*/
/* DISPLAY SUBCHANNEL STATUS WORD */
/*-------------------------------------------------------------------*/
static void
display_scsw (const DEVBLK *dev, const SCSW scsw)
{
switch (sysblk.arch_mode)
{
case ARCH_370_IDX:
{
U8 csw[8];
scsw2csw(&scsw, csw);
display_csw (dev, csw);
break;
}
default:
WRMSG (HHC01317, "I", SSID_TO_LCSS(dev->ssid), dev->devnum,
scsw.flag0, scsw.flag1, scsw.flag2, scsw.flag3,
scsw.unitstat, scsw.chanstat,
scsw.count[0], scsw.count[1],
scsw.ccwaddr[0], scsw.ccwaddr[1],
scsw.ccwaddr[2], scsw.ccwaddr[3]);
break;
}
} /* end function display_scsw */
/*-------------------------------------------------------------------*/
/* Display prefetch table */
/*-------------------------------------------------------------------*/
#if DEBUG_PREFETCH
static void
display_prefetch (PREFETCH *prefetch, const u_int ps,
const U32 count, const U32 residual,
const u_int more)
{
u_int limit = MIN(prefetch->seq, PF_SIZE);
u_int ts;
U32 used = count - residual;
char msgbuf[133];
MSGBUF(msgbuf, "Prefetch ps=%d count=%llu (%08.8LLX) "
"residual=%llu (%08.8LLX) more=%d "
"used=%llu (%08.8LLX)",
ps, count, count, residual, residual, more,
used, used);
WRMSG(HHC90000, "I", msgbuf);
MSGBUF(msgbuf, "Prefetch seq=%d req=%d (%04.4X) pos=%d (%04.4X) "
"prevcode=%02.2X code=%02.2X",
prefetch->seq, prefetch->reqcount,
prefetch->reqcount, prefetch->pos, prefetch->pos,
prefetch->prevcode, prefetch->opcode);
WRMSG(HHC90000, "I", msgbuf);
MSGBUF(msgbuf,
"Prefetch "
" n " /* ts */
" " /* Select pointer */
"cs " /* Channel Status */
"scsw-ccw " /* CCW Address */
"data-len " /* Data length */
" data-address " /* Data address */
"fl " /* CCW Flags */
" count " /* CCW Count */
"idawaddr " /* IDAW Address */
"it " /* IDAW Type */
"if" /* IDAW Flag */
);
WRMSG(HHC90000, "I", msgbuf);
for (ts = 0; ts < limit; ts++)
{
MSGBUF(msgbuf,
"Prefetch "
"%3d " /* ts */
"%2s" /* Select pointer (ps) */
"%2.2X " /* Channel Status */
"%8.8X " /* CCW Address (SCSW CCW Address) */
"%8.8X " /* Data length */
"%16.16"PRIX64" " /* Data address */
"%2.2X " /* CCW Flags */
"%8.8X " /* CCW Count */
"%8.8X " /* IDAW Address */
"%2d " /* IDAW Type */
"%2.2X", /* IDAW Flag */
ts, ((ps == ts) ? "->" : " "),
prefetch->chanstat[ts], prefetch->ccwaddr[ts],
prefetch->datalen[ts], prefetch->dataaddr[ts],
prefetch->ccwflags[ts], prefetch->ccwcount[ts],
prefetch->idawaddr[ts], prefetch->idawtype[ts],
prefetch->idawflag[ts]);
WRMSG(HHC90000, "I", msgbuf);
}
}
#else
#define display_prefetch(_prefetch, _ps, _count, _residual, _more)
#endif /* DEBUG_PREFETCH */
/*-------------------------------------------------------------------*/
/* STORE CHANNEL ID */
/*-------------------------------------------------------------------*/
int
stchan_id (REGS *regs, U16 chan)
{
U32 chanid; /* Channel identifier word */
int devcount = 0; /* #of devices on channel */
DEVBLK *dev; /* -> Device control block */
PSA_3XX *psa; /* -> Prefixed storage area */
/* Find a device on specified channel */
for (dev = sysblk.firstdev; dev != NULL; dev = dev->nextdev)
{
/* Skip "devices" that don't actually exist */
if (!IS_DEV(dev))
continue;
/* Skip the device if not on specified channel */
if ((dev->devnum & 0xFF00) != chan