-
Notifications
You must be signed in to change notification settings - Fork 11
/
ssdtPRGen.sh
executable file
·4155 lines (3716 loc) · 127 KB
/
ssdtPRGen.sh
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
#!/bin/bash
#
# Script (ssdtPRGen.sh) to create ssdt-pr.dsl for Apple Power Management Support.
#
# Version 0.9 - Copyright (c) 2012 by RevoGirl
#
# Version 15.6 - Copyright (c) 2014 by Pike <[email protected]>
#
# Readme......: https://github.com/Piker-Alpha/ssdtPRGen.sh/blob/master/README.md
#
# Change log..: https://github.com/Piker-Alpha/ssdtPRGen.sh/blob/master/CHANGELOG.md
#
# Contributors: https://github.com/Piker-Alpha/ssdtPRGen.sh/blob/master/CONTRIBUTORS.md
#
# Bug reports.: https://github.com/Piker-Alpha/ssdtPRGen.sh/issues
#
# Please provide clear steps to reproduce the bug, the terminal output
# of the script (the log data) and the resulting SSDT.dsl Thank you!
#
# set -x # Used for tracing errors (can be used anywhere in the script).
#================================= GLOBAL VARS ==================================
#
# Script version info.
#
gScriptVersion=15.6
#
# The script expects '0.5' but non-US localizations use '0,5' so we export
# LC_NUMERIC here (for the duration of the ssdtPRGen.sh) to prevent errors.
#
export LC_NUMERIC="en_US.UTF-8"
#
# Initial xcpm mode. Default value is -1 (uninitialised).
#
let gXcpm=-1
#
# Change this when your CPU is stuck in Low Frequency Mode!
#
# 1 - Injects one extra Turbo P-State at he top with max-Turbo frequency + 1 MHz.
# 2 - Injects N extra Turbo P-States at the bottom.
# 3 - Injects both of them.
#
# Note: Will be changed to 0 in _checkForXCPM() when XCPM mode is detected.
#
let gIvyWorkAround=-1
#
# Ask for confirmation before copying the new SSDT to the target location.
#
let gAutoCopy=1
#
# This is the target location that ssdt.aml will be copied to.
#
# Note: Do no change this - will be updated automatically for Clover/RevoBoot!
#
gDestinationPath="/Extra/"
#
# This is the filename used for the copy process
#
gDestinationFile="ssdt.aml"
#
# A value of 1 will make this script call iasl (compiles ssdt_pr.dsl)
#
# Note: Will be set to 0 when we failed to locate a copy of iasl!
#
let gCallIasl=1
#
# Open generated SSDT on request (default value is 2).
#
# 0 = don't open the generated SSDT.
# 1 = open the generated SSDT in the editor of your choice.
# 2 = ask for confirmation before opening the generated SSDT in the editor of your choice.
#
let gCallOpen=2
# 0 = no debug injection/debug statements executed.
# 1 = inject debug data.
# 3 = inject debug data and execute _debugPrint statements.
#
let gDebug=1
#
# Get user id
#
let gID=$(id -u)
#
# Lowest possible idle frequency (user configurable). Also known as Low Frequency Mode.
#
let gBaseFrequency=1600
#
# This is the default processor label (verified by _setProcessorLabel).
#
gProcLabel="CPU0"
#
# The Processor scope will be initialised by _initProcessorScope).
#
gScope=""
#
# Legacy RevoBoot status (default value is 0).
#
let gIsLegacyRevoBoot=0
#
# Change this to 0 if you don't want additional styling (bold/underlined).
#
let gExtraStyling=1
#
# Global variable used by some functions to return a value to the callee.
#
let gFunctionReturn=0
#
# Global variable used for the used/target board-id.
#
gBoardID=""
#
# Global variable used for the used/target board-id.
#
gModelID=""
#
# Number of logical processors.
#
let gLogicalCPUs=0
#
# Clock frequency (uninitialised).
#
let gFrequency=-1
#
# Set to 1 if _PR scope is found in the DSDT.
#
let gScopePRFound=0
#
# For future use!
#
# Note: Set this to 0 when you want to inject ACPI Processor (...) {} declarations intead of External () objects.
#
let gInjectExternalObjects=1
#
# Output styling.
#
STYLE_RESET="[0m"
STYLE_BOLD="[1m"
STYLE_UNDERLINED="[4m"
#
# Other global variables.
#
gRevision='0x000'${gScriptVersion:0:2}${gScriptVersion:3:1}'00'
#
# Path and filename setup.
#
gHome=$(echo $HOME)
gPath="${gHome}/Library"
gScriptPath="${gPath}/ssdtPRGen"
gDataPath="${gScriptPath}/Data"
gToolPath="${gScriptPath}/Tools"
gSsdtID="ssdt"
gSsdtPR="${gScriptPath}/${gSsdtID}.dsl"
let gDesktopCPU=1
let gMobileCPU=2
let gServerCPU=3
let gSystemType=0
let gACST_CPU0=13
let gACST_CPU1=7
gTargetMacModel=""
let SANDY_BRIDGE=2
let IVY_BRIDGE=4
let HASWELL=8
let BROADWELL=16
#
# Global variable used as target cpu/bridge type.
#
let gBridgeType=-1
let gTypeCPU=0
let gProcessorStartIndex=0
gProcessorData="Unknown CPU"
gProcessorNumber=""
gBusFrequency=100
#
# Set to 1 after _setDestinationPath mounted the EFI partition.
#
let gUnmountEFIPartition=0
gProductName=$(sw_vers -productName)
gProductVersion="$(sw_vers -productVersion)"
gBuildVersion=$(sw_vers -buildVersion)
let gOSVersion=$(echo $gProductVersion | tr -d '.')
#
# Maximum Turbo Clock Speed (user configurable)
#
let gMaxOCFrequency=6300
let MAX_TURBO_FREQUENCY_ERROR=2
let MAX_TDP_ERROR=3
let TARGET_CPU_ERROR=4
let PROCESSOR_NUMBER_ERROR=5
let PROCESSOR_LABEL_LENGTH_ERROR=6
let PROCESSOR_NAMES_ERROR=7
let PROCESSOR_DECLARATION_ERROR=8
let FILE_NOT_FOUND_ERROR=9
#
# First OS version number that no longer requires extra Low Frequency Mode P-States.
#
# Note: For future use (when we figured out what we need).
#
let LFM_REQUIRED_OS=1091
#
# Setup supported byte encodings
#
# Note: value is number of characters that we read.
#
let AML_SINGLE_BYTE_ENCODING=2
let AML_DUAL_BYTE_ENCODING=4
let AML_TRIPLE_BYTE_ENCODING=6
let AML_QUAD_BYTE_ENCODING=8
#
# Setup used AML encoding values.
#
AML_SCOPE_OPCODE=10
AML_DEVICE_OPCODE=5b82
AML_PROCESSOR_SCOPE_OPCODE=5b83
#
#--------------------------------------------------------------------------------
#
function _PRINT_MSG()
{
local message=$1
if [[ $gExtraStyling -eq 1 ]];
then
if [[ $message =~ 'Aborting ...' ]];
then
local message=$(echo $message | sed -e 's/^Aborting ...//')
local messageType='Aborting ...'
else
local messageType=$(echo $message | sed -e 's/:.*//g')
if [[ $messageType =~ ^"\n" ]];
then
local messageTypeStripped=$(echo $messageType | sed -e 's/^[\n]*//')
else
local messageTypeStripped=$messageType
fi
local message=":"$(echo $message | sed -e "s/^[\n]*${messageTypeStripped}://")
fi
printf "${STYLE_BOLD}${messageType}${STYLE_RESET}$message\n"
else
printf "${message}\n"
fi
}
#
#--------------------------------------------------------------------------------
#
function _ABORT()
{
_PRINT_MSG "Aborting ...\nDone.\n\n"
exit $1
}
#
#--------------------------------------------------------------------------------
#
function _printHeader()
{
echo '/*' > "$gSsdtPR"
echo ' * Intel ACPI Component Architecture' >> "$gSsdtPR"
echo ' * AML Disassembler version 20140210-00 [Feb 10 2014]' >> "$gSsdtPR"
echo ' * Copyright (c) 2000 - 2014 Intel Corporation' >> "$gSsdtPR"
echo ' * ' >> "$gSsdtPR"
echo ' * Original Table Header:' >> "$gSsdtPR"
echo ' * Signature "SSDT"' >> "$gSsdtPR"
echo ' * Length 0x0000036A (874)' >> "$gSsdtPR"
echo ' * Revision 0x01' >> "$gSsdtPR"
echo ' * Checksum 0x00' >> "$gSsdtPR"
echo ' * OEM ID "APPLE "' >> "$gSsdtPR"
echo ' * OEM Table ID "CpuPm"' >> "$gSsdtPR"
printf ' * OEM Revision '$gRevision' (%d)\n' $gRevision >> "$gSsdtPR"
echo ' * Compiler ID "INTL"' >> "$gSsdtPR"
echo ' * Compiler Version 0x20140210 (538182160)' >> "$gSsdtPR"
echo ' */' >> "$gSsdtPR"
echo '' >> "$gSsdtPR"
echo 'DefinitionBlock ("'$gSsdtID'.aml", "SSDT", 1, "APPLE ", "CpuPm", '$gRevision')' >> "$gSsdtPR"
echo '{' >> "$gSsdtPR"
}
#
#--------------------------------------------------------------------------------
#
function _printExternalObjects()
{
#
# Local variable definition.
#
local index
local scopeIndex
local maxCoresPerScope
local numberOfLogicalCPUsPerScope
#
# Local variable initialisation.
#
let index=0
let scopeIndex=1
let logicalCPUsPerScope=$gLogicalCPUs/${#gScope[@]}
#
# Loop through all processor scopes.
#
for scope in "${gScope[@]}"
do
let maxCoresPerScope=($logicalCPUsPerScope*$scopeIndex)
#
# Inject External () object for each logical processor in this processor scope.
#
while [ $index -lt $maxCoresPerScope ];
do
echo ' External ('${scope}'.'${gProcessorNames[$index]}', DeviceObj)' >> "$gSsdtPR"
#
# Next logical processor.
#
let index+=1
done
#
# Next processor scope.
#
let scopeIndex+=1
done
}
#
#--------------------------------------------------------------------------------
#
function _getPBlockAddress()
{
#
# Get Processor Control Block (P_BLK) address from offset: 152/0x98 in facp.aml
#
local data=$(xxd -s 152 -l 4 -ps "${gScriptPath}/facp.aml")
#
# Convert data to Little Endian
#
local pblockAddress="0x${data:6:2}${data:4:2}${data:2:2}${data:0:2}"
#
# Increase P_BLK address with 16
#
let pblockAddress+=0x10
#
# Return P_BLK address + 16
#
echo $(printf "0x%08x" $pblockAddress)
}
#
#--------------------------------------------------------------------------------
#
function _printProcessorDefinitions()
{
#
# Local variable definition.
#
local index
local scopeIndex
local maxCoresPerScope
local numberOfLogicalCPUsPerScope
local pBlockAddress=$(_getPBlockAddress)
#
# Local variable initialisation.
#
let index=0
let scopeIndex=1
let logicalCPUsPerScope=$gLogicalCPUs/${#gScope[@]}
#
# Loop through all processor scopes.
#
for scope in "${gScope[@]}"
do
let maxCoresPerScope=($logicalCPUsPerScope*$scopeIndex)
#
# Do we have a device name?
#
if [[ $scope =~ ^"\_SB_." ]];
then
local scopeName=$(echo $scope | sed -e 's/^\\_SB_\.//')
echo ' Scope(\_SB_)' >> "$gSsdtPR"
echo ' {' >> "$gSsdtPR"
echo ' Device ('$scopeName')' >> "$gSsdtPR"
echo ' {' >> "$gSsdtPR"
echo ' Name (_HID, "ACPI0004")' >> "$gSsdtPR"
else
echo ' {' >> "$gSsdtPR"
echo ' Scope('$scope')' >> "$gSsdtPR"
fi
#
# Inject Processor () object for each logical processor in this processor scope.
#
while [ $index -lt $maxCoresPerScope ];
do
if [[ $scope =~ ^"\_SB_." ]];
then
echo '' >> "$gSsdtPR"
echo ' Processor ('${gProcessorNames[$index]}', '$index', '$pBlockAddress', Zero)' >> "$gSsdtPR"
echo ' {' >> "$gSsdtPR"
echo ' Name (_HID, "ACPI0007")' >> "$gSsdtPR"
echo ' Name (_STA, 0x0F)' >> "$gSsdtPR"
echo ' }' >> "$gSsdtPR"
else
echo ' Processor ('${gProcessorNames[$index]}', '$index', '$pBlockAddress', 0x06) {}' >> "$gSsdtPR"
fi
#
# Next logical processor.
#
let index+=1
done
if [[ $scope =~ ^"\_SB_." ]];
then
echo ' }' >> "$gSsdtPR"
fi
echo ' }' >> "$gSsdtPR"
#
#
#
if [[ $scopeIndex -lt ${#gScope[@]} ]];
then
echo '' >> "$gSsdtPR"
fi
#
# Next processor scope.
#
let scopeIndex+=1
done
#
# Done.
#
}
#
#--------------------------------------------------------------------------------
#
function _injectDebugInfo()
{
#
# Local variable definitions/initialisation.
#
local turboStates=$1
local maxTurboFrequency=$2
local packageLength=$3
echo ' Method (_INI, 0, NotSerialized)' >> "$gSsdtPR"
echo ' {' >> "$gSsdtPR"
echo ' Store ("ssdtPRGen version....: '$gScriptVersion' / '$gProductName' '$gProductVersion' ('$gBuildVersion')", Debug)' >> "$gSsdtPR"
echo ' Store ("target processor.....: '$gProcessorNumber'", Debug)' >> "$gSsdtPR"
echo ' Store ("running processor....: '$gBrandString'", Debug)' >> "$gSsdtPR"
echo ' Store ("baseFrequency........: '$gBaseFrequency'", Debug)' >> "$gSsdtPR"
echo ' Store ("frequency............: '$frequency'", Debug)' >> "$gSsdtPR"
echo ' Store ("busFrequency.........: '$gBusFrequency'", Debug)' >> "$gSsdtPR"
echo ' Store ("logicalCPUs..........: '$gLogicalCPUs'", Debug)' >> "$gSsdtPR"
echo ' Store ("maximum TDP..........: '$gTdp'", Debug)' >> "$gSsdtPR"
echo ' Store ("packageLength........: '$packageLength'", Debug)' >> "$gSsdtPR"
echo ' Store ("turboStates..........: '$turboStates'", Debug)' >> "$gSsdtPR"
echo ' Store ("maxTurboFrequency....: '$maxTurboFrequency'", Debug)' >> "$gSsdtPR"
#
# Ivy Bridge workarounds requested?
#
if [[ $gIvyWorkAround -gt 0 ]];
then
echo ' Store ("IvyWorkArounds.......: '$gIvyWorkAround'", Debug)' >> "$gSsdtPR"
fi
#
# XCPM mode initialised?
#
if [[ $gXcpm -ne -1 ]];
then
echo ' Store ("machdep.xcpm.mode....: '$gXcpm'", Debug)' >> "$gSsdtPR"
fi
#
# Do we have more than one ACPI processor scope?
#
if [[ "${#gScope[@]}" -gt 1 ]];
then
echo ' Store ("number of ACPI scopes: '${#gScope[@]}'", Debug)' >> "$gSsdtPR"
fi
echo ' }' >> "$gSsdtPR"
echo '' >> "$gSsdtPR"
}
#
#--------------------------------------------------------------------------------
#
function _printScopeStart()
{
#
# Local variable definitions.
#
local turboStates
local packageLength
local maxTurboFrequency
local lowFrequencyPStates
local useWorkArounds
local maxTDP
local extraR
local extraF
#
# Local variable initialisation.
#
let scopeIndex=$1
let turboStates=$2
let packageLength=$3
let maxTurboFrequency=$4
let useWorkArounds=0
let logicalCPUsPerScope=$gLogicalCPUs/${#gScope[@]}
let index=($logicalCPUsPerScope*$scopeIndex)
#
# Have we injected External () objects?
#
if [[ $scopeIndex -eq 0 && $gInjectExternalObjects -ne 1 ]];
then
#
# No. Inject ACPI Processor (...) {} declarations.
#
_printProcessorDefinitions
fi
echo '' >> "$gSsdtPR"
echo ' Scope ('${gScope[${scopeIndex}]}'.'${gProcessorNames[$index]}')' >> "$gSsdtPR"
echo ' {' >> "$gSsdtPR"
if (( $scopeIndex == 0 && $gDebug & 1 ))
then
_injectDebugInfo $turboStates $maxTurboFrequency $packageLength
fi
#
# Do we need to create additional (Low Frequency) P-States?
#
if [ $gBridgeType -ne $SANDY_BRIDGE ];
then
let lowFrequencyPStates=0
#
# Do we need to add additional (Low Frequency) P-States for Ivy Bridge?
#
if (( $gBridgeType == $IVY_BRIDGE && $gIvyWorkAround & 2 ));
then
let lowFrequencyPStates=($gBaseFrequency/100)-8
if [[ $lowFrequencyPStates -lt 0 ]];
then
let lowFrequencyPStates=$(echo ${lowFrequencyPStates#-})
printf "lowFrequencyPStates: $lowFrequencyPStates\n"
fi
fi
let packageLength=($packageLength+$lowFrequencyPStates)
if [[ $lowFrequencyPStates -gt 0 ]];
then
printf " Name (APLF, 0x%02x)\n" $lowFrequencyPStates >> "$gSsdtPR"
else
# Prevent optimization warning.
echo " Name (APLF, Zero)" >> "$gSsdtPR"
fi
# TODO: Remove this when CPUPM for IB works properly!
if (( $gBridgeType == $IVY_BRIDGE && $gIvyWorkAround & 1 ));
then
let useWorkArounds=1
fi
fi
#
# Check number of Turbo states (for IASL optimization).
#
if [ $turboStates -eq 0 ];
then
# TODO: Remove this when CPUPM for IB works properly!
if (( $useWorkArounds ));
then
echo ' Name (APSN, One)' >> "$gSsdtPR"
else
echo ' Name (APSN, Zero)' >> "$gSsdtPR"
fi
else
# TODO: Remove this when CPUPM for IB works properly!
if (( $useWorkArounds ));
then
let turboStates+=1
fi
printf " Name (APSN, 0x%02X)\n" $turboStates >> "$gSsdtPR"
fi
# TODO: Remove this when CPUPM for IB works properly!
if (( $useWorkArounds ));
then
let packageLength+=1
fi
printf " Name (APSS, Package (0x%02X)\n" $packageLength >> "$gSsdtPR"
echo ' {' >> "$gSsdtPR"
# TODO: Remove this when CPUPM for IB works properly!
if (( $useWorkArounds ));
then
let extraF=($maxTurboFrequency+1)
#
# Is the global TDP a floating-point number?
#
if [[ $gTdp =~ "." ]];
then
#
# Yes, convert it and calculate maximum TDP.
#
let tdp=$(echo "$gTdp" | sed -e 's/\.//g')
let maxTDP=($tdp*100)
else
#
# No. Calculate maximum TDP.
#
let maxTDP=($gTdp*1000)
fi
let extraR=($maxTurboFrequency/100)+1
echo " /* Workaround for the Ivy Bridge PM 'bug' */" >> "$gSsdtPR"
printf " Package (0x06) { 0x%04X, 0x%06X, 0x0A, 0x0A, 0x%02X00, 0x%02X00 },\n" $extraF $maxTDP $extraR $extraR >> "$gSsdtPR"
fi
}
#
#--------------------------------------------------------------------------------
#
function _printPackages()
{
#
# Local variable definitions/initialisation.
#
local maxNonTurboFrequency=$1
local turboStates=$2
local frequency=$3
#
# Local variable definitions.
#
local tdp
local maxTDP
local minRatio
local p1Ratio
local ratio
local powerRatio
local multipliedBusFrequency
#
# Is the global TDP a floating-point number?
#
if [[ $gTdp =~ "." ]];
then
#
# Yes, convert it and calculate maximum TDP.
#
let tdp=$(echo "$gTdp" | sed -e 's/\.//g')
let maxTDP=($tdp*100)
else
#
# No. Calculate maximum TDP.
#
let tdp=$gTdp
let maxTDP=(tdp*1000)
fi
#
# Local variable initialisation.
#
let minRatio=($gBaseFrequency/$gBusFrequency)
let p0Ratio=($maxNonTurboFrequency/$gBusFrequency)
let ratio=($frequency/$gBusFrequency)
let powerRatio=($p0Ratio-1)
let multipliedBusFrequency=($gBusFrequency*10)
case "$gBusFrequency" in
133) let multipliedBusFrequency+=3
;;
166) let multipliedBusFrequency+=6
;;
esac
#
# Do we need to add additional (Low Frequency) P-States for Ivy Bridge?
#
if (( $gBridgeType == $IVY_BRIDGE && $gIvyWorkAround & 2 ));
then
let minRatio=8
fi
if (( $turboStates ));
then
echo ' /* High Frequency Modes (turbo) */' >> "$gSsdtPR"
fi
while [ $ratio -ge $minRatio ];
do
if [ $frequency -eq $gBaseFrequency ];
then
echo ' /* Low Frequency Mode */' >> "$gSsdtPR"
fi
if [ $frequency -eq $maxNonTurboFrequency ];
then
echo ' /* High Frequency Modes (non-turbo) */' >> "$gSsdtPR"
fi
printf " Package (0x06) { 0x%04X, " $frequency >> "$gSsdtPR"
if [ $frequency -lt $maxNonTurboFrequency ];
then
if [ $gBusFrequency -eq 100 ];
then
power=$(echo "scale=6;m=((1.1-(($p0Ratio-$powerRatio)*0.00625))/1.1);(($powerRatio/$p0Ratio)*(m*m)*$maxTDP);" | bc | sed -e 's/.[0-9A-F]*$//')
let powerRatio-=1
else
let ratioFactor=($ratio*30)/$p0Ratio;
power=$(echo "scale=6;(($ratioFactor*$ratioFactor*$ratioFactor*$maxTDP)/27000);" | bc | sed -e 's/.[0-9A-F]*$//')
let powerRatio-=1
fi
else
power=$maxTDP
fi
if [ $frequency -ge $gBaseFrequency ];
then
printf "0x%06X, " $power >> "$gSsdtPR"
else
printf ' Zero, ' >> "$gSsdtPR"
fi
if [ $gBusFrequency -eq 100 ];
then
printf "0x0A, 0x0A, 0x%02X00, 0x%02X00 }" $ratio $ratio >> "$gSsdtPR"
else
printf "0x0A, 0x0A, 0x00%02X, 0x00%02X }" $ratio $ratio >> "$gSsdtPR"
fi
let ratio-=1
let frequency=$(printf "%.f\n" $(echo "scale=1;((($multipliedBusFrequency/10)*$ratio)+0.5)" | bc))
if [ $ratio -ge $minRatio ];
then
echo ',' >> "$gSsdtPR"
else
echo '' >> "$gSsdtPR"
fi
done
echo ' })' >> "$gSsdtPR"
}
#
#--------------------------------------------------------------------------------
#
function _printMethodDSM()
{
if [[ $gBridgeType -ge $IVY_BRIDGE || $gXcpm -eq 1 ]];
then
#
# New stand-alone version of Method _DSM - Copyright (c) 2009 by Master Chief
#
echo '' >> "$gSsdtPR"
echo ' Method (_DSM, 4, NotSerialized)' >> "$gSsdtPR"
echo ' {' >> "$gSsdtPR"
if [[ $gDebug -eq 1 ]];
then
#
# Note: This will be called twice!
#
echo ' Store ("Method '${gProcessorNames[0]}'._DSM Called", Debug)' >> "$gSsdtPR"
echo '' >> "$gSsdtPR"
fi
echo ' If (LEqual (Arg2, Zero))' >> "$gSsdtPR"
echo ' {' >> "$gSsdtPR"
echo ' Return (Buffer (One)' >> "$gSsdtPR"
echo ' {' >> "$gSsdtPR"
echo ' 0x03' >> "$gSsdtPR"
echo ' })' >> "$gSsdtPR"
echo ' }' >> "$gSsdtPR"
echo '' >> "$gSsdtPR"
#
# This property is required to get X86Platform[Plugin/Shim].kext loaded.
#
echo ' Return (Package (0x02)' >> "$gSsdtPR"
echo ' {' >> "$gSsdtPR"
echo ' "plugin-type",' >> "$gSsdtPR"
echo ' One' >> "$gSsdtPR"
echo ' })' >> "$gSsdtPR"
echo ' }' >> "$gSsdtPR"
echo ' }' >> "$gSsdtPR"
fi
}
#
#--------------------------------------------------------------------------------
#
function _debugPrint()
{
if (( $gDebug & 2 ));
then
printf "$@"
fi
}
#
#--------------------------------------------------------------------------------
#
function _printScopeACST()
{
#
# Local variable definition.
#
local C1 C2 C3 C6 C7
local hintCode
local pkgLength
local targetCPU
local numberOfCStates
local targetCStates
#
# Intel values for Sandy / Ivy Bridge processors
#
# C-state : Power : SB Latency : IB Latency
#---------:---------:------------:------------
# C1 : 0x3e8 : 0x01 : 0x03
# C3 : 0x1f4 : 0x50 : 0xcd
# C6 : 0x15e : 0x68 : 0xf5
# C7 : 0xc8 : 0x6d : 0xf5
#
# Note: C-state latency in uS and C-state power in mW.
#
local latency_C1=Zero
local latency_C2=0x43
local latency_C3=0xCD
local latency_C6=0xF5
local latency_C7=0xF5
#
# Local variable initialisation.
#
let C1=0
let C2=0
let C3=0
let C6=0
let C7=0
let pkgLength=2
let numberOfCStates=0
#
# Are we injecting C-States for CPU1?
#
if [ $1 -eq 1 ];
then
let targetCPU=1
else
let targetCPU=0
fi
echo '' >> "$gSsdtPR"
echo ' Method (ACST, 0, NotSerialized)' >> "$gSsdtPR"
echo ' {' >> "$gSsdtPR"
if (( $gDebug ));
then
echo ' Store ("Method '${gProcessorNames[$targetCPU]}'.ACST Called", Debug)' >> "$gSsdtPR"
fi
#
# Are we injecting C-States for CPU1?
#
if [ $targetCPU -eq 1 ];
then
# Yes (also used by CPU2, CPU3 and greater).
let targetCStates=$gACST_CPU1
latency_C1=0x03E8
latency_C2=0x94
latency_C3=0xC6
else
#
# C-States override for Mobile processors (CPU0 only)
#
if (($gTypeCPU == $gMobileCPU));
then
echo 'Adjusting C-States for detected (mobile) processor'
let gACST_CPU0=29
fi
let targetCStates=$gACST_CPU0
latency_C1=Zero
latency_C2=0x43
latency_C3=0xCD
latency_C6=0xF5
latency_C7=0xF5
fi
if (( $gDebug ));
then
echo ' Store ("'${gProcessorNames[$targetCPU]}' C-States : '$targetCStates'", Debug)' >> "$gSsdtPR"
echo '' >> "$gSsdtPR"
fi
_debugPrint "targetCStates: $targetCStates\n"
#
# Checks to determine which C-State(s) we should inject.
#
if (($targetCStates & 1));
then
_debugPrint "Adding C1\n"
let C1=1
let numberOfCStates+=1
let pkgLength+=1
fi
if (($targetCStates & 2));
then
_debugPrint "Adding C2\n"
let C2=1
let numberOfCStates+=1
let pkgLength+=1
fi
if (($targetCStates & 4));
then
_debugPrint "Adding C3\n"
let C3=1
let numberOfCStates+=1
let pkgLength+=1
fi
if (($targetCStates & 8));
then
_debugPrint "Adding C6\n"
let C6=1
let numberOfCStates+=1
let pkgLength+=1