-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathconfig.c
2135 lines (1850 loc) · 63.4 KB
/
config.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
/* CONFIG.C (c) Copyright Jan Jaeger, 2000-2012 */
/* Device configuration functions */
/*-------------------------------------------------------------------*/
/* The original configuration builder is now called bldcfg.c */
/*-------------------------------------------------------------------*/
#include "hstdinc.h"
DISABLE_GCC_WARNING( "-Wunused-function" )
#ifndef _CONFIG_C_
#define _CONFIG_C_
#endif
#ifndef _HENGINE_DLL_
#define _HENGINE_DLL_
#endif
#include "hercules.h"
#include "opcode.h"
#include "chsc.h"
#if !defined(_GEN_ARCH)
#if defined(_ARCHMODE3)
#define _GEN_ARCH _ARCHMODE3
#include "config.c"
#undef _GEN_ARCH
#endif
#if defined(_ARCHMODE2)
#define _GEN_ARCH _ARCHMODE2
#include "config.c"
#undef _GEN_ARCH
#endif
#if defined(HAVE_MLOCKALL)
int configure_memlock(int flags)
{
int rc;
if(flags)
rc = mlockall(MCL_CURRENT | MCL_FUTURE);
else
rc = munlockall();
return rc ? errno : 0;
}
#endif /*defined(HAVE_MLOCKALL)*/
static void configure_region_reloc()
{
DEVBLK *dev;
int i;
#if defined(_FEATURE_REGION_RELOCATE)
/* Initialize base zone storage view (SIE compat) */
for(i = 0; i < FEATURE_SIE_MAXZONES; i++)
{
sysblk.zpb[i].mso = 0;
sysblk.zpb[i].msl = (sysblk.mainsize - 1) >> 20;
if(sysblk.xpndsize)
{
sysblk.zpb[i].eso = 0;
sysblk.zpb[i].esl = ((size_t)sysblk.xpndsize * XSTORE_PAGESIZE - 1) >> 20;
}
else
{
sysblk.zpb[i].eso = -1;
sysblk.zpb[i].esl = -1;
}
}
#endif
/* Relocate storage for all devices */
for (dev = sysblk.firstdev; dev; dev = dev->nextdev)
{
dev->mainstor = sysblk.mainstor;
dev->storkeys = sysblk.storkeys;
dev->mainlim = sysblk.mainsize ? (sysblk.mainsize - 1) : 0;
}
/* Relocate storage for all online cpus */
for (i = 0; i < sysblk.maxcpu; i++)
if (IS_CPU_ONLINE(i))
{
sysblk.regs[i]->storkeys = sysblk.storkeys;
sysblk.regs[i]->mainstor = sysblk.mainstor;
sysblk.regs[i]->mainlim = sysblk.mainsize ? (sysblk.mainsize - 1) : 0;
}
}
static U64 config_mfree = 200 << SHIFT_MEGABYTE;
int configure_memfree(int mfree)
{
if (mfree < 0)
return config_mfree >> SHIFT_MEGABYTE;
config_mfree = (RADR)mfree << SHIFT_MEGABYTE;
return 0;
}
PUSH_GCC_WARNINGS()
DISABLE_GCC_WARNING( "-Wpointer-to-int-cast" )
DISABLE_GCC_WARNING( "-Wint-to-pointer-cast" )
/* storage configuration */
static U64 config_allocmsize = 0;
static BYTE *config_allocmaddr = NULL;
int configure_storage(U64 mainsize)
{
BYTE *mainstor;
BYTE *storkeys;
BYTE *dofree = NULL;
char *mfree = NULL;
REGS *regs;
U64 storsize;
U32 skeysize;
int cpu;
/* Ensure all CPUs have been stopped */
if (are_any_cpus_started())
return HERRCPUONL;
/* Release storage and return if deconfiguring */
if (mainsize == ~0ULL)
{
if (config_allocmaddr)
free(config_allocmaddr);
sysblk.storkeys = 0;
sysblk.mainstor = 0;
sysblk.mainsize = 0;
config_allocmsize = 0;
config_allocmaddr = NULL;
return 0;
}
/* Round requested storage size to architectural segment boundaries
* ARCH_370 1 4K page
* ARCH_390 256 4K pages (or 1M)
* ARCH_900 256 4K pages (or 1M)
*/
if (mainsize)
{
#if 0
if (mainsize <= (16 << (SHIFT_MEGABYTE - 12)))
storsize = MAX((sysblk.arch_mode <= ARCH_390) ? 1 : 2,
mainsize);
/* The side effect of this for values less than 256 is to establish
* zones with a memory size of zero megabytes. Channel subsystem I/O
* (see MSCH instruction) drives I/O address checks via the memory size
* established in zones, not mainsize. A zero megabyte zone memory
* size causes all channel subsystem I/O to fail with a program check
* channel status.
*/
#else
if (sysblk.arch_mode == ARCH_370)
storsize = MAX(1,mainsize);
else
#endif
storsize = (mainsize + 255) & ~255ULL;
mainsize = storsize;
}
else
{
/* Adjust zero storage case for a subsystem/device server
* (MAXCPU 0), allocating minimum storage of 4K.
*/
storsize = 1;
}
/* Storage key array size rounded to next page boundary */
switch (_STORKEY_ARRAY_UNITSIZE)
{
case 2048:
skeysize = storsize << 1;
break;
case 4096:
skeysize = storsize;
break;
}
skeysize += 4095;
skeysize >>= 12;
/* Add Storage key array size */
storsize += skeysize;
/* New memory is obtained only if the requested and calculated size
* is larger than the last allocated size, or if the request is for
* less than 2M of memory.
*
* Note: Using the current algorithm, storage on a 32-bit host OS
* is normally limited to a guest total of 1326M, split
* between main and expanded storage. The most either may
* specify is 919M. For example, one may specify MAINSIZE
* 919M and XPNDSIZE 407M, for a total of 1326M.
*
* Please understand that the results on any individual
* 32-bit host OS may vary from the note above, and the note
* does not apply to any 64-bit host OS.
*
*/
if (storsize > config_allocmsize ||
(mainsize <= (2 * ONE_MEGABYTE) &&
storsize < config_allocmsize))
{
if (config_mfree &&
mainsize > (2* ONE_MEGABYTE))
mfree = malloc(config_mfree);
/* Obtain storage with hint to page size for cleanest allocation
*/
storkeys = calloc((size_t)storsize + 1, 4096);
if (mfree)
free(mfree);
if (storkeys == NULL)
{
char buf[64];
sysblk.main_clear = 0;
MSGBUF( buf, "configure_storage(%s)",
fmt_memsize_KB((U64)mainsize << 2) );
WRMSG( HHC01430, "S", buf, strerror(errno) );
return -1;
}
/* Previously allocated storage to be freed, update actual
* storage pointers and adjust new storage to page boundary.
*/
dofree = config_allocmaddr,
config_allocmsize = storsize,
config_allocmaddr = storkeys,
sysblk.main_clear = 1,
storkeys = (BYTE*)(((U64)storkeys + 4095) & ~0x0FFFULL);
}
else
{
storkeys = sysblk.storkeys;
sysblk.main_clear = 0;
dofree = NULL;
}
/* Mainstor is located beyond the storage key array on a page boundary */
/* Isn't the storage key array already at a page boundary? jph */
mainstor = (BYTE*)((U64)(storkeys + (skeysize << 12)));
/* Set in sysblk */
sysblk.storkeys = storkeys;
sysblk.mainstor = mainstor;
sysblk.mainsize = mainsize << 12;
/*
* Free prior storage in use
*
* FIXME: The storage ordering further limits the amount of storage
* that may be allocated following the initial storage
* allocation.
*
*/
if (dofree)
free(dofree);
/* Initial power-on reset for main storage */
storage_clear();
#if 0 /*DEBUG-JJ-20/03/2000*/
/* Mark selected frames invalid for debugging purposes */
for (i = 64 ; i < (sysblk.mainsize / _STORKEY_ARRAY_UNITSIZE); i += 2)
if (i < (sysblk.mainsize / _STORKEY_ARRAY_UNITSIZE) - 64)
sysblk.storkeys[i] = STORKEY_BADFRM;
else
sysblk.storkeys[i++] = STORKEY_BADFRM;
#endif
#if 1 // The below is a kludge that will need to be cleaned up at some point in time
/* Initialize dummy regs.
* Dummy regs are used by the panel or gui when the target cpu
* (sysblk.pcpu) is not configured (ie cpu_thread not started).
*/
sysblk.dummyregs.mainstor = sysblk.mainstor;
sysblk.dummyregs.psa = (PSA_3XX*)sysblk.mainstor;
sysblk.dummyregs.storkeys = sysblk.storkeys;
sysblk.dummyregs.mainlim = sysblk.mainsize ? (sysblk.mainsize - 1) : 0;
sysblk.dummyregs.dummy = 1;
initial_cpu_reset (&sysblk.dummyregs);
sysblk.dummyregs.arch_mode = sysblk.arch_mode;
sysblk.dummyregs.hostregs = &sysblk.dummyregs;
#endif
configure_region_reloc();
/* Call initial_cpu_reset for every online processor */
if (sysblk.cpus)
{
for (cpu = 0; cpu < sysblk.maxcpu; cpu++)
{
if (IS_CPU_ONLINE(cpu))
{
regs=sysblk.regs[cpu];
ARCH_DEP(initial_cpu_reset) (regs) ;
}
}
}
return 0;
}
static U64 config_allocxsize = 0;
static BYTE *config_allocxaddr = NULL;
int configure_xstorage(U64 xpndsize)
{
#ifdef _FEATURE_EXPANDED_STORAGE
BYTE *xpndstor;
BYTE *dofree = NULL;
char *mfree = NULL;
REGS *regs;
int cpu;
/* Ensure all CPUs have been stopped */
if (are_any_cpus_started())
return HERRCPUONL;
/* Release storage and return if zero or deconfiguring */
if (!xpndsize ||
xpndsize == ~0ULL)
{
if (config_allocxaddr)
free(config_allocxaddr);
sysblk.xpndsize = 0,
sysblk.xpndstor = 0,
config_allocxsize = 0,
config_allocxaddr = NULL;
return 0;
}
/* New memory is obtained only if the requested and calculated size
* is larger than the last allocated size.
*
* Note: Using the current algorithm, storage on a 32-bit host OS
* is normally limited to a guest total of 1326M, split
* between main and expanded storage. The most either may
* specify is 919M. For example, one may specify MAINSIZE
* 407M and XPNDSIZE 919M, for a total of 1326M.
*
* Please understand that the results on any individual
* 32-bit host OS may vary from the note above, and the note
* does not apply to any 64-bit host OS.
*
*/
if (xpndsize > config_allocxsize)
{
if (config_mfree)
mfree = malloc(config_mfree);
/* Obtain expanded storage, hinting to megabyte boundary */
xpndstor = calloc((size_t)xpndsize + 1, ONE_MEGABYTE);
if (mfree)
free(mfree);
if (xpndstor == NULL)
{
char buf[64];
sysblk.xpnd_clear = 0;
MSGBUF( buf, "configure_xstorage(%s)",
fmt_memsize_MB((U64)xpndsize));
WRMSG( HHC01430, "S", buf, strerror(errno) );
return -1;
}
/* Previously allocated storage to be freed, update actual
* storage pointers and adjust new storage to megabyte boundary.
*/
dofree = config_allocxaddr,
config_allocxsize = xpndsize,
config_allocxaddr = xpndstor,
sysblk.xpnd_clear = 1,
xpndstor = (BYTE*)(((U64)xpndstor + (ONE_MEGABYTE - 1)) &
~((U64)ONE_MEGABYTE - 1)),
sysblk.xpndstor = xpndstor;
}
else
{
xpndstor = sysblk.xpndstor;
sysblk.xpnd_clear = 0;
dofree = NULL;
}
sysblk.xpndstor = xpndstor;
sysblk.xpndsize = xpndsize << (SHIFT_MEBIBYTE - XSTORE_PAGESHIFT);
/*
* Free prior storage in use
*
* FIXME: The storage ordering further limits the amount of storage
* that may be allocated following the initial storage
* allocation.
*
*/
if (dofree)
free(dofree);
/* Initial power-on reset for expanded storage */
xstorage_clear();
configure_region_reloc();
/* Call initial_cpu_reset for every online processor */
if (sysblk.cpus)
{
for (cpu = 0; cpu < sysblk.maxcpu; cpu++)
{
if (IS_CPU_ONLINE(cpu))
{
regs=sysblk.regs[cpu];
ARCH_DEP(initial_cpu_reset) (regs) ;
}
}
}
#else /*!_FEATURE_EXPANDED_STORAGE*/
UNREFERENCED(xpndsize);
WRMSG(HHC01431, "I");
#endif /*!_FEATURE_EXPANDED_STORAGE*/
return 0;
}
POP_GCC_WARNINGS()
/* 4 next functions used for fast device lookup cache management */
static void AddDevnumFastLookup( DEVBLK *dev, U16 lcss, U16 devnum )
{
unsigned int Channel;
BYTE bAlreadyHadLock = try_obtain_lock( &sysblk.config );
if (sysblk.devnum_fl == NULL)
sysblk.devnum_fl = (DEVBLK***)
calloc( 256 * FEATURE_LCSS_MAX, sizeof( DEVBLK** ));
Channel = (devnum >> 8) | ((lcss & (FEATURE_LCSS_MAX-1)) << 8);
if (sysblk.devnum_fl[Channel] == NULL)
sysblk.devnum_fl[Channel] = (DEVBLK**)
calloc( 256, sizeof( DEVBLK* ));
sysblk.devnum_fl[Channel][devnum & 0xff] = dev;
if (!bAlreadyHadLock)
release_lock( &sysblk.config );
}
static void AddSubchanFastLookup( DEVBLK *dev, U16 ssid, U16 subchan )
{
unsigned int schw;
BYTE bAlreadyHadLock = try_obtain_lock( &sysblk.config );
if (sysblk.subchan_fl == NULL)
sysblk.subchan_fl = (DEVBLK***)
calloc( 256 * FEATURE_LCSS_MAX, sizeof( DEVBLK** ));
schw = (subchan >> 8) | (SSID_TO_LCSS( ssid ) << 8);
if (sysblk.subchan_fl[schw] == NULL)
sysblk.subchan_fl[schw] = (DEVBLK**)
calloc( 256, sizeof( DEVBLK* ));
sysblk.subchan_fl[schw][subchan & 0xff] = dev;
if (!bAlreadyHadLock)
release_lock( &sysblk.config );
}
static void DelDevnumFastLookup(U16 lcss,U16 devnum)
{
unsigned int Channel;
if(sysblk.devnum_fl==NULL)
{
return;
}
Channel=(devnum & 0xff00)>>8 | ((lcss & (FEATURE_LCSS_MAX-1))<<8);
if(sysblk.devnum_fl[Channel]==NULL)
{
return;
}
sysblk.devnum_fl[Channel][devnum & 0xff]=NULL;
}
static void DelSubchanFastLookup(U16 ssid, U16 subchan)
{
unsigned int schw;
#if 0
logmsg(_("DEBUG : DSFL Removing %d\n"),subchan);
#endif
if(sysblk.subchan_fl==NULL)
{
return;
}
schw=((subchan & 0xff00)>>8)|(SSID_TO_LCSS(ssid) << 8);
if(sysblk.subchan_fl[schw]==NULL)
{
return;
}
sysblk.subchan_fl[schw][subchan & 0xff]=NULL;
}
#ifdef NEED_FND_CHPBLK
static
CHPBLK *fnd_chpblk(U16 css, BYTE chpid)
{
CHPBLK *chp;
for (chp = sysblk.firstchp; chp != NULL; chp = chp->nextchp)
if (chp->chpid == chpid && chp->css == css)
return chp;
return NULL;
}
#endif
#ifdef NEED_GET_CHPBLK
static
CHPBLK *get_chpblk(U16 css, BYTE chpid, BYTE chptype)
{
CHPBLK *chp;
CHPBLK**chpp;
if((chp = fnd_chpblk(css, chpid)))
return chp;
else
{
if (!(chp = (CHPBLK*)malloc(sizeof(CHPBLK))))
{
logmsg("malloc(chpblk) failed: %s\n",strerror(errno));
return NULL;
}
memset (chp, 0, sizeof(CHPBLK));
chp->css = css;
chp->chpid = chpid;
chp->chptype = chptype;
/* Search for the last channel path block on the chain */
for (chpp = &(sysblk.firstchp); *chpp != NULL;
chpp = &((*chpp)->nextchp));
/* Add the new channel path block to the end of the chain */
*chpp = chp;
}
}
#endif
/* NOTE: also does obtain_lock(&dev->lock); */
static DEVBLK *get_devblk(U16 lcss, U16 devnum)
{
DEVBLK *dev;
DEVBLK**dvpp;
if(lcss >= FEATURE_LCSS_MAX)
lcss = 0;
for (dev = sysblk.firstdev; dev != NULL; dev = dev->nextdev)
if (!(dev->allocated) && dev->ssid == LCSS_TO_SSID(lcss)) break;
if(!dev)
{
if (!(dev = (DEVBLK*)calloc_aligned((sizeof(DEVBLK)+4095) & ~4095,4096)))
{
char buf[64];
MSGBUF(buf, "calloc(%d)", (int)sizeof(DEVBLK));
WRMSG (HHC01460, "E", lcss, devnum, buf, strerror(errno));
return NULL;
}
/* Clear device block and initialize header */
strncpy((char*)dev->blknam, HDL_NAME_DEVBLK, sizeof(dev->blknam));
strncpy((char*)dev->blkver, HDL_VERS_DEVBLK, sizeof(dev->blkver));
dev->blkloc = (U64)(size_t)dev;
dev->blksiz = HDL_SIZE_DEVBLK;
strncpy((char*)dev->blkend, HDL_NAME_DEVBLK, sizeof(dev->blknam));
/* Initialize the device lock and conditions */
initialize_lock ( &dev->lock );
initialize_condition ( &dev->kbcond );
#if defined( OPTION_SHARED_DEVICES )
initialize_condition ( &dev->shiocond );
#endif // defined( OPTION_SHARED_DEVICES )
#if defined(OPTION_SCSI_TAPE)
initialize_condition ( &dev->stape_sstat_cond );
InitializeListLink ( &dev->stape_statrq.link );
InitializeListLink ( &dev->stape_mntdrq.link );
dev->stape_statrq.dev = dev;
dev->stape_mntdrq.dev = dev;
#endif
/* Search for the last device block on the chain */
for (dvpp = &(sysblk.firstdev); *dvpp != NULL;
dvpp = &((*dvpp)->nextdev));
/* Add the new device block to the end of the chain */
*dvpp = dev;
dev->ssid = LCSS_TO_SSID(lcss);
dev->subchan = sysblk.highsubchan[lcss]++;
}
/* Obtain the device lock. Caller will release it. */
obtain_lock (&dev->lock);
dev->group = NULL;
dev->member = 0;
memset(dev->filename, 0, sizeof(dev->filename));
dev->cpuprio = sysblk.cpuprio;
dev->devprio = sysblk.devprio;
dev->hnd = NULL;
dev->devnum = devnum;
dev->chanset = lcss;
dev->chptype[0] = CHP_TYPE_EIO; /* Interim - default to emulated */
dev->fd = -1;
#ifdef OPTION_SYNCIO
dev->syncio = 0;
#endif // OPTION_SYNCIO
dev->ioint.dev = dev;
dev->ioint.pending = 1;
dev->ioint.priority = -1;
dev->pciioint.dev = dev;
dev->pciioint.pcipending = 1;
dev->pciioint.priority = -1;
dev->attnioint.dev = dev;
dev->attnioint.attnpending = 1;
dev->attnioint.priority = -1;
dev->oslinux = sysblk.pgminttr == OS_LINUX;
/* Initialize storage view */
dev->mainstor = sysblk.mainstor;
dev->storkeys = sysblk.storkeys;
dev->mainlim = sysblk.mainsize - 1;
/* Initialize the path management control word */
memset (&dev->pmcw, 0, sizeof(PMCW));
dev->pmcw.devnum[0] = dev->devnum >> 8;
dev->pmcw.devnum[1] = dev->devnum & 0xFF;
dev->pmcw.lpm = 0x80;
dev->pmcw.pim = 0x80;
dev->pmcw.pom = 0xFF;
dev->pmcw.pam = 0x80;
dev->pmcw.chpid[0] = dev->devnum >> 8;
#if defined(OPTION_SHARED_DEVICES)
dev->shrdwait = -1;
#endif /*defined(OPTION_SHARED_DEVICES)*/
#ifdef EXTERNALGUI
if ( !dev->pGUIStat )
{
dev->pGUIStat = malloc( sizeof(GUISTAT) );
dev->pGUIStat->pszOldStatStr = dev->pGUIStat->szStatStrBuff1;
dev->pGUIStat->pszNewStatStr = dev->pGUIStat->szStatStrBuff2;
*dev->pGUIStat->pszOldStatStr = 0;
*dev->pGUIStat->pszNewStatStr = 0;
}
#endif /*EXTERNALGUI*/
/* Mark device valid */
dev->pmcw.flag5 |= PMCW5_V;
dev->allocated = 1;
return dev;
}
/* NOTE: also does release_lock(&dev->lock);*/
static void ret_devblk(DEVBLK *dev)
{
/* PROGRAMMING NOTE: the device buffer will be freed by the
'attach_device' function whenever it gets reused and not
here where you would normally expect it to be done since
doing it here might cause Hercules to crash due to poorly
written device handlers that still access the buffer for
a brief period after the device has been detached.
*/
/* Mark device invalid */
dev->allocated = 0;
dev->pmcw.flag5 &= ~PMCW5_V;
release_lock(&dev->lock);
}
/*-------------------------------------------------------------------*/
/* Function to delete a device configuration block */
/*-------------------------------------------------------------------*/
static int detach_devblk (DEVBLK *dev, int locked, const char *msg,
DEVBLK *errdev, DEVGRP *group)
{
int i; /* Loop index */
/* Free the entire group if this is a grouped device */
if (free_group( dev->group, locked, msg, errdev ))
{
/* Group successfully freed. All devices in the group
have been detached. Nothing remains for us to do.
All work has been completed. Return to caller.
*/
return 0;
}
/* Restore group ptr that that 'free_group' may have set to NULL */
dev->group = group;
/* Obtain the device lock. ret_devblk will release it */
if (!locked)
obtain_lock(&dev->lock);
DelSubchanFastLookup(dev->ssid, dev->subchan);
if(dev->pmcw.flag5 & PMCW5_V)
DelDevnumFastLookup(SSID_TO_LCSS(dev->ssid),dev->devnum);
/* Close file or socket */
if ((dev->fd > 2) || dev->console)
/* Call the device close handler */
(dev->hnd->close)(dev);
/* Issue device detached message and build channel report */
if (dev != errdev)
{
if (MLVL(DEBUG))
{
// "%1d:%04X %s detached"
WRMSG (HHC01465, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, msg);
}
#ifdef _FEATURE_CHANNEL_SUBSYSTEM
/* Don't bother with channel report if we're shutting down */
if (!sysblk.shutdown)
{
#if defined(_370)
if (sysblk.arch_mode != ARCH_370)
#endif
build_detach_chrpt( dev );
#endif /*_FEATURE_CHANNEL_SUBSYSTEM*/
}
}
/* Free the argv array */
for (i = 0; i < dev->argc; i++)
if (dev->argv[i])
free(dev->argv[i]);
if (dev->argv)
free(dev->argv);
/* Free the device type name */
free(dev->typname);
/* Release lock and return the device to the DEVBLK pool */
ret_devblk( dev ); /* also does release_lock(&dev->lock);*/
return 0;
} /* end function detach_devblk */
/*-------------------------------------------------------------------*/
/* Function to delete a device configuration block by subchannel */
/*-------------------------------------------------------------------*/
static int detach_subchan (U16 lcss, U16 subchan, U16 devnum)
{
DEVBLK *dev; /* -> Device block */
int rc;
char str[64];
/* Find the device block */
dev = find_device_by_subchan ((LCSS_TO_SSID(lcss)<<16)|subchan);
MSGBUF( str, "subchannel %1d:%04X", lcss, subchan);
if (dev == NULL)
{
// "%1d:%04X %s does not exist"
WRMSG (HHC01464, "E", lcss, devnum, str);
return 1;
}
obtain_lock(&sysblk.config);
if (dev->group)
MSGBUF( str, "group subchannel %1d:%04X", lcss, subchan);
rc = detach_devblk( dev, FALSE, str, NULL, dev->group );
release_lock(&sysblk.config);
return rc;
}
/*-------------------------------------------------------------------*/
/* Function to terminate all CPUs and devices */
/*-------------------------------------------------------------------*/
void release_config()
{
DEVBLK *dev;
int cpu;
/* Deconfigure all CPU's */
OBTAIN_INTLOCK(NULL);
for (cpu = 0; cpu < sysblk.maxcpu; cpu++)
if(IS_CPU_ONLINE(cpu))
deconfigure_cpu(cpu);
RELEASE_INTLOCK(NULL);
/* Detach all devices */
for (dev = sysblk.firstdev; dev != NULL; dev = dev->nextdev)
if (dev->allocated)
{
if (sysblk.arch_mode == ARCH_370)
detach_device(SSID_TO_LCSS(dev->ssid), dev->devnum);
else
detach_subchan(SSID_TO_LCSS(dev->ssid), dev->subchan, dev->devnum);
}
/* Terminate device threads */
obtain_lock (&sysblk.ioqlock);
sysblk.devtwait=0;
broadcast_condition (&sysblk.ioqcond);
release_lock (&sysblk.ioqlock);
/* release storage */
sysblk.lock_mainstor = 0;
WRMSG( HHC01427, "I", "Main", !configure_storage(~0ULL) ? "" : "not " );
/* release expanded storage */
sysblk.lock_xpndstor = 0;
WRMSG( HHC01427, "I", "Expanded", !configure_xstorage(~0ULL) ? "" : "not ");
WRMSG(HHC01422, "I");
} /* end function release_config */
int configure_capping(U32 value)
{
if(sysblk.capvalue)
sysblk.capvalue = value;
else
{
int cnt;
for (cnt = 100; cnt > 0; cnt-- )
{
if ( sysblk.captid != 0 )
{
sysblk.capvalue = 0;
usleep(10000); // give the thread a chance to wake
}
else
break;
}
if ( cnt == 0 )
{
WRMSG( HHC00105, "E", (u_long)sysblk.captid, "Capping manager" );
return HERRTHREADACT;
}
if((sysblk.capvalue = value))
{
int rc;
rc = create_thread(&sysblk.captid, DETACHED, capping_manager_thread, NULL, "Capping manager");
if ( rc )
{
WRMSG(HHC00102, "E", strerror(rc));
return HERROR;
}
}
}
return HNOERROR;
}
#ifdef OPTION_SHARED_DEVICES
static void* shrdport_connecting_thread(void* arg)
{
DEVBLK* dev = (DEVBLK*) arg;
dev->hnd->init( dev, 0, NULL );
return NULL;
}
int configure_shrdport(U16 shrdport)
{
int rc;
if(sysblk.shrdport && shrdport)
{
WRMSG(HHC00744, "E");
return -1;
}
/* Start the shared server */
if ((sysblk.shrdport = shrdport))
{
rc = create_thread (&sysblk.shrdtid, DETACHED,
shared_server, NULL, "shared_server");
if (rc)
{
WRMSG(HHC00102, "E", strerror(rc));
sysblk.shrdport = 0;
return(1);
}
}
else
{
/* Terminate the shared device listener thread */
if (sysblk.shrdtid)
signal_thread (sysblk.shrdtid, SIGUSR2);
return 0;
}
/* Retry pending connections */
{
DEVBLK *dev;
TID tid;
for (dev = sysblk.firstdev; dev != NULL; dev = dev->nextdev)
if (dev->connecting)
{
rc = create_thread (&tid, DETACHED,
shrdport_connecting_thread, dev, "device connecting thread");
if (rc)
{
WRMSG(HHC00102, "E", strerror(rc));
return(1);
}
}
}
return 0;
}
#endif
int configure_herc_priority(int prio)
{
int rc;
/* Set root mode in order to set priority */
SETMODE(ROOT);
/* Set Hercules base priority */
rc = setpriority(PRIO_PROCESS, 0, (sysblk.hercprio = prio));
/* Back to user mode */
SETMODE(USER);
return rc;
}
int configure_cpu_priority(int prio)
{
int cpu;
sysblk.cpuprio = prio;
for(cpu = 0; cpu < MAX_CPU_ENGINES; cpu++)
if(sysblk.cputid[cpu])
set_thread_priority(sysblk.cputid[cpu], prio);
return 0;
}
int configure_dev_priority(int prio)
{
sysblk.devprio = prio;
return 0;
}
int configure_tod_priority(int prio)
{
sysblk.todprio = prio;
if(sysblk.todtid)
set_thread_priority(sysblk.todtid, prio);
return 0;
}
int configure_srv_priority(int prio)
{
sysblk.srvprio = prio;
return 0;
}
/*-------------------------------------------------------------------*/
/* Function to start a new CPU thread */
/* Caller MUST own the intlock */
/*-------------------------------------------------------------------*/
int configure_cpu(int cpu)
{
int i;