Chameleon

Chameleon Commit Details

Date:2014-01-20 13:59:39 (5 years 9 months ago)
Author:ErmaC
Commit:2341
Parents: 2340
Message:Fix error introduced with rev 2327. Add lzss compression. Merge latest Bungo's SMBIOS improvements. Typos...
Changes:
M/branches/ErmaC/Enoch/i386/libsaio/smbios.c
M/branches/ErmaC/Enoch/i386/boot2/lzss.c
M/branches/ErmaC/Enoch/i386/libsa/prf.c
M/branches/ErmaC/Enoch/i386/libsaio/smbios_decode.c
M/branches/ErmaC/Enoch/i386/libsaio/hpet.c
M/branches/ErmaC/Enoch/i386/libsaio/smbios.h
M/branches/ErmaC/Enoch/i386/boot2/graphics.c
M/branches/ErmaC/Enoch/i386/libsa/libsa.h
M/branches/ErmaC/Enoch/CHANGES
M/branches/ErmaC/Enoch/i386/libsaio/biosfn.c
M/branches/ErmaC/Enoch/i386/libsaio/convert.c
M/branches/ErmaC/Enoch/i386/boot2/modules.h
M/branches/ErmaC/Enoch/i386/libsaio/pci.h
M/branches/ErmaC/Enoch/i386/libsaio/msdos.c
M/branches/ErmaC/Enoch/i386/boot2/gui.c
M/branches/ErmaC/Enoch/i386/libsaio/md5c.c
M/branches/ErmaC/Enoch/i386/libsaio/smbios_getters.c
M/branches/ErmaC/Enoch/i386/libsaio/fake_efi.c
M/branches/ErmaC/Enoch/i386/config/nconf.h
M/branches/ErmaC/Enoch/i386/libsaio/device_inject.c
M/branches/ErmaC/Enoch/i386/libsa/zalloc.c
M/branches/ErmaC/Enoch/i386/libsaio/smbios_getters.h
M/branches/ErmaC/Enoch/i386/boot2/options.c
M/branches/ErmaC/Enoch/i386/libsa/strtol.c
M/branches/ErmaC/Enoch/i386/libsaio/device_inject.h
M/branches/ErmaC/Enoch/i386/libsaio/xml.c
M/branches/ErmaC/Enoch/i386/config/confdata.c
M/branches/ErmaC/Enoch/doc/BootHelp.txt
M/branches/ErmaC/Enoch/i386/boot2/resume.c
M/branches/ErmaC/Enoch/i386/libsaio/xml.h
M/branches/ErmaC/Enoch/i386/boot2/boot.c
M/branches/ErmaC/Enoch/i386/libsaio/dram_controllers.c
M/branches/ErmaC/Enoch/i386/libsaio/nvidia.c
M/branches/ErmaC/Enoch/i386/libsaio/ext2fs.c
M/branches/ErmaC/Enoch/i386/boot2/boot.h
M/branches/ErmaC/Enoch/i386/include/string.h
M/branches/ErmaC/Enoch/i386/libsaio/sys.c
M/branches/ErmaC/Enoch/i386/libsaio/device_tree.c
M/branches/ErmaC/Enoch/i386/libsa/string.c
M/branches/ErmaC/Enoch/i386/libsaio/load.c
M/branches/ErmaC/Enoch/i386/boot2/drivers.c
M/branches/ErmaC/Enoch/i386/libsaio/acpi_patcher.c
M/branches/ErmaC/Enoch/i386/libsaio/spd.c
M/branches/ErmaC/Enoch/i386/libsaio/cpu.c
M/branches/ErmaC/Enoch/i386/libsaio/platform.h
M/branches/ErmaC/Enoch/i386/libsaio/disk.c
M/branches/ErmaC/Enoch/i386/libsaio/pci_setup.c

File differences

branches/ErmaC/Enoch/i386/libsaio/smbios_getters.h
1010
1111
1212
13
13
1414
1515
1616
#define SMBIOS_RANGE_START 0x000F0000
#define SMBIOS_RANGE_END 0x000FFFFF
#define NOT_AVAILABLE"N/A"
#define NOT_AVAILABLE"N/A"
typedef enum
{
branches/ErmaC/Enoch/i386/libsaio/xml.c
2727
2828
2929
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
3058
3159
3260
......
130158
131159
132160
133
161
134162
135
136
137
138
139
140
141
142
143
163
164
165
166
167
168
169
170
171
172
144173
145174
146175
......
149178
150179
151180
152
153181
154182
155183
......
362390
363391
364392
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
393
394
395
384396
385
386
397
387398
388399
389400
390401
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
402
403
419404
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
436423
437
438
439
440
441
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442442
443
444
443
445444
446
447
448
449
450
451
452
453
445
446
447
448
449
450
451
452
453
454
455
456
457
454458
455
456459
457460
458461
459462
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
463
464
487465
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
504482
505
506
507
508
509
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
510501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
511517
512
513
514
515
516
517
518
519
520
521
522
518
519
523520
524
525521
526
527
528
529
530522
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545523
546
547
548
549
550
551524
552525
553
554
526
555527
556528
529
557530
558
559
531
560532
561533
562534
563
564
565
566
535
536
537
567538
568
569
570
539
540
541
542
543
544
545
546
547
548
549
571550
572
573
574
551
552
553
554
555
556
575557
576558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
577579
578
579
580
580
581581
582582
583583
......
601601
602602
603603
604
605
606
607
604
605
608606
609607
610608
......
620618
621619
622620
623
624
621
625622
626623
627624
628625
629626
630627
631
632
628
633629
634630
635631
......
735731
736732
737733
738
734
739735
740736
741737
......
753749
754750
755751
756
752
753
754
757755
758756
759
760757
758
759
760
761761
762762
763
764
763
765764
766
767
768
769
765
766
767
770768
771
772
773
769
774770
775
776
777
778
779
780
781
771
772
773
782774
783775
784776
785777
786778
787779
788
789
790
791
792
780
781
793782
794783
795784
796785
797786
798
799
800
801
802
803
787
788
789
804790
805791
806792
807793
808
794
809795
810796
811797
812798
813
799
814800
801
815802
816803
817804
......
914901
915902
916903
917
904
905
906
918907
919
908
909
910
920911
921
922
923
924
925
926
927
928
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
929934
930
931
932
933
935
936
937
938
934939
935
940
941
942
943
944
945
946
936947
937948
938949
......
10061017
10071018
10081019
1009
1010
1020
10111021
10121022
10131023
1014
1015
1024
10161025
10171026
10181027
......
10591068
10601069
10611070
1062
1063
1071
10641072
1065
1066
1073
10671074
10681075
10691076
......
10791086
10801087
10811088
1082
1083
1089
10841090
10851091
10861092
......
10991105
11001106
11011107
1102
1103
1108
11041109
11051110
11061111
11071112
11081113
11091114
1110
1111
1115
11121116
11131117
11141118
11151119
1116
1117
1120
11181121
1119
1120
1121
1122
11221123
11231124
11241125
......
11381139
11391140
11401141
1141
1142
1143
1144
1142
1143
11451144
11461145
11471146
......
11491148
11501149
11511150
1152
1153
1151
11541152
11551153
11561154
......
11591157
11601158
11611159
1162
1163
1160
11641161
11651162
11661163
......
11741171
11751172
11761173
1177
1178
1174
11791175
11801176
1181
1182
1183
1177
11841178
1185
1186
1187
1179
11881180
11891181
11901182
......
12011193
12021194
12031195
1204
1205
1196
12061197
12071198
1208
1209
1210
1199
12111200
1212
1213
1214
1201
12151202
12161203
12171204
......
12231210
12241211
12251212
1226
1227
1213
12281214
12291215
12301216
1231
1232
1217
12331218
12341219
12351220
......
12381223
12391224
12401225
1241
1242
1226
12431227
12441228
12451229
1246
1247
1230
12481231
12491232
12501233
......
12551238
12561239
12571240
1258
1259
1241
12601242
1261
1262
1263
1243
12641244
12651245
12661246
......
12721252
12731253
12741254
1275
1276
1255
12771256
12781257
1279
1280
1281
1258
12821259
12831260
1284
12851261
12861262
12871263
......
12921268
12931269
12941270
1295
1296
1271
12971272
12981273
12991274
1300
1301
1275
13021276
13031277
1304
13051278
13061279
13071280
13081281
13091282
1310
1311
1283
13121284
13131285
13141286
......
13161288
13171289
13181290
1319
1320
1291
13211292
13221293
13231294
13241295
1325
1326
1296
13271297
13281298
13291299
......
13351305
13361306
13371307
1338
1339
1308
13401309
13411310
13421311
13431312
13441313
1345
1346
1314
13471315
13481316
13491317
#include "sl.h"
#include "xml.h"
#define kXMLTagPList "plist "
#define kXMLTagPListLen (sizeof(kXMLTagPList) - 1)
#define kXMLTagDict "dict"
#define kXMLTagDictLen (sizeof(kXMLTagDict) - 1)
#define kXMLTagKey "key"
#define kXMLTagKeyLen (sizeof(kXMLTagKey) - 1)
#define kXMLTagString "string"
#define kXMLTagStringLen (sizeof(kXMLTagString) - 1)
#define kXMLTagInteger "integer"
#define kXMLTagIntegerLen (sizeof(kXMLTagInteger) - 1)
#define kXMLTagData "data"
#define kXMLTagDataLen (sizeof(kXMLTagData) - 1)
#define kXMLTagDate "date"
#define kXMLTagDateLen (sizeof(kXMLTagDate) - 1)
#define kXMLTagFalse "false/"
#define kXMLTagFalseLen (sizeof(kXMLTagFalse) - 1)
#define kXMLTagTrue "true/"
#define kXMLTagTrueLen (sizeof(kXMLTagTrue) - 1)
#define kXMLTagArray "array"
#define kXMLTagArrayLen (sizeof(kXMLTagArray) - 1)
// for back-references used by libkern serializer
#define kXMLTagReference "reference"
#define kXMLTagReferenceLen (sizeof(kXMLTagReference) - 1)
#define kXMLStringID "ID="
#define kXMLStringIDLen (sizeof(kXMLStringID) - 1)
#define kXMLStringIDRef "IDREF="
#define kXMLStringIDRefLen (sizeof(kXMLStringIDRef) - 1)
string_ref *ref_strings = NULL;
/// TODO: remove below
TagPtr
XMLGetProperty(TagPtr dict, const char * key)
{
TagPtr tagList, tag;
TagPtr tagList, tag;
if (dict->type != kTagTypeDict) return 0;
tag = 0;
tagList = dict->tag;
while (tagList)
{
tag = tagList;
tagList = tag->tagNext;
if (dict->type != kTagTypeDict) {
return 0;
}
tag = 0;
tagList = dict->tag;
while (tagList) {
tag = tagList;
tagList = tag->tagNext;
if ((tag->type != kTagTypeKey) || (tag->string == 0)) {
continue;
}
return tag->tag;
}
}
return 0;
}
}
pos = length;
if (!strncmp(tagName, kXMLTagPList, 6))
{
length = 0;
// just a header; nothing to parse
// return-via-reference tag should be left alone
}
/***** dict ****/
else if (!strcmp(tagName, kXMLTagDict))
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
}
else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/')
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1);
}
else if (!strncmp(tagName, kXMLTagDict " ", strlen(kXMLTagDict " ")))
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
}
/* Check most common cases first, make them fast */
/***** key ****/
else if (!strcmp(tagName, kXMLTagKey))
{
if (!strcmp(tagName, kXMLTagKey)) {
length = ParseTagKey(buffer + pos, tag);
}
/***** string ****/
else if (!strcmp(tagName, kXMLTagString))
{
length = ParseTagString(buffer + pos, tag);
}
else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " ")))
{
// TODO: save tag if if found
if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID)))
{
// ID=
int id = 0;
int cnt = strlen(kXMLTagString " " kXMLStringID "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagString " " kXMLStringID "\"");
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
id = (id * 10) + (*val++ - '0');
}
else
{
printf("ParseStringID error (0x%x)\n", *val);
getchar();
return -1;
}
}
else if (!strncmp(tagName, kXMLTagString, kXMLTagStringLen)) {
if (!tagName[kXMLTagStringLen]) { /* <string> */
length = ParseTagString(buffer + pos, tag);
SaveRefString(buffer + pos, id);
}
else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef)))
{
// IDREF=
int id = 0;
int cnt = strlen(kXMLTagString " " kXMLStringIDRef "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagString " " kXMLStringIDRef "\"");
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
id = (id * 10) + (*val++ - '0');
} else if (' ' == tagName[kXMLTagStringLen]) { /* <string ...> */
// TODO: save tag if if found
if(!strncmp(tagName + kXMLTagStringLen + 1, (kXMLStringID "\""), kXMLStringIDLen + 1)) { /* <string ID="...> */
// ID=
int id = 0;
/* find end of ID string */
int cnt = kXMLTagStringLen + 1 + kXMLStringIDLen + 2;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + kXMLTagStringLen + 1 + kXMLStringIDLen + 1;
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
id = (id * 10) + (*val++ - '0');
} else {
printf("ParseStringID error (0x%x)\n", *val);
getchar();
return -1;
}
}
else
{
printf("ParseStringIDREF error (0x%x)\n", *val);
getchar();
return -1;
length = ParseTagString(buffer + pos, tag);
SaveRefString(buffer + pos, id);
} else if(!strncmp(tagName + kXMLTagStringLen + 1, kXMLStringIDRef, kXMLStringIDRefLen)) { /* <string IDREF= ...> */
// IDREF=
int id = 0;
int cnt = strlen(kXMLTagString " " kXMLStringIDRef "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagString " " kXMLStringIDRef "\"");
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
id = (id * 10) + (*val++ - '0');
} else {
printf("ParseStringIDREF error (0x%x)\n", *val);
getchar();
return -1;
}
}
}
char* str = GetRefString(id);
char* str = GetRefString(id);
TagPtr tmpTag = NewTag();
tmpTag->type = kTagTypeString;
tmpTag->string = str;
tmpTag->tag = 0;
tmpTag->tagNext = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0;
*tag = tmpTag;
TagPtr tmpTag = NewTag();
tmpTag->type = kTagTypeString;
tmpTag->string = str;
tmpTag->tag = 0;
tmpTag->tagNext = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0;
*tag = tmpTag;
length = 0;
//printf("Located IDREF, id = %d, string = %s\n", id, str);
}
} else { /* unrecognized <string...> */
*tag = 0;
length = 0;
//printf("Located IDREF, id = %d, string = %s\n", id, str);
}
}
/***** integer ****/
else if (!strcmp(tagName, kXMLTagInteger))
{
length = ParseTagInteger(buffer + pos, tag);
}
else if (!strncmp(tagName, kXMLTagInteger " ", strlen(kXMLTagInteger " ")))
{
if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID)))
{
// ID=
int id = 0;
int cnt = strlen(kXMLTagInteger " " kXMLStringID "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagInteger " " kXMLStringID "\"");
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
id = (id * 10) + (*val++ - '0');
}
else
{
printf("ParseIntegerID error (0x%x)\n", *val);
getchar();
return -1;
}
}
else if (!strncmp(tagName, kXMLTagInteger, kXMLTagIntegerLen)) {
if (!tagName[kXMLTagIntegerLen]) { /* <integer> */
length = ParseTagInteger(buffer + pos, tag);
SaveRefString((*tag)->string, id);
}
else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef)))
{
// IDREF=
int id = 0;
int cnt = strlen(kXMLTagInteger " " kXMLStringIDRef "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagInteger " " kXMLStringIDRef "\"");
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
id = (id * 10) + (*val++ - '0');
} else if (' ' == tagName[kXMLTagIntegerLen]) { /* <integer ...> */
if(!strncmp(tagName + kXMLTagIntegerLen + 1, kXMLStringID, kXMLStringIDLen)) { /* <integer ID=...> */
// ID=
int id = 0;
int cnt = strlen(kXMLTagInteger " " kXMLStringID "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagInteger " " kXMLStringID "\"");
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
id = (id * 10) + (*val++ - '0');
} else {
printf("ParseIntegerID error (0x%x)\n", *val);
getchar();
return -1;
}
}
else
{
printf("ParseStringIDREF error (0x%x)\n", *val);
getchar();
return -1;
length = ParseTagInteger(buffer + pos, tag);
SaveRefString((*tag)->string, id);
} else if(!strncmp(tagName + kXMLTagIntegerLen + 1, kXMLStringIDRef, kXMLStringIDRefLen)) { /* <integer IDREF=...> */
// IDREF=
int id = 0;
int cnt = strlen(kXMLTagInteger " " kXMLStringIDRef "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagInteger " " kXMLStringIDRef "\"");
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
id = (id * 10) + (*val++ - '0');
} else {
printf("ParseStringIDREF error (0x%x)\n", *val);
getchar();
return -1;
}
}
int integer = (int)GetRefString(id);
TagPtr tmpTag = NewTag();
tmpTag->type = kTagTypeInteger;
tmpTag->string = (char*) integer;
tmpTag->tag = 0;
tmpTag->tagNext = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0;
*tag = tmpTag;
length = 0;
//printf("Located IDREF, id = %d, string = %s\n", id, str);
} else {
length = ParseTagInteger(buffer + pos, tag);
}
int integer = (int)GetRefString(id);
TagPtr tmpTag = NewTag();
tmpTag->type = kTagTypeInteger;
tmpTag->string = (char*) integer;
tmpTag->tag = 0;
tmpTag->tagNext = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0;
*tag = tmpTag;
} else { /* unrecognized <integer...> */
*tag = 0;
length = 0;
//printf("Located IDREF, id = %d, string = %s\n", id, str);
}
else
{
length = ParseTagInteger(buffer + pos, tag);
}
}
/***** data ****/
else if (!strcmp(tagName, kXMLTagData))
{
length = ParseTagData(buffer + pos, tag);
}
else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " ")))
{
length = ParseTagData(buffer + pos, tag);
}
else if (!strcmp(tagName, kXMLTagDate))
{
length = ParseTagDate(buffer + pos, tag);
}
/***** date ****/
else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " ")))
{
length = ParseTagDate(buffer + pos, tag);
}
/***** false ****/
else if (!strcmp(tagName, kXMLTagFalse))
{
else if (!strcmp(tagName, kXMLTagFalse)) {
length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse);
}
/***** true ****/
else if (!strcmp(tagName, kXMLTagTrue))
{
else if (!strcmp(tagName, kXMLTagTrue)) {
length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue);
}
/***** array ****/
else if (!strcmp(tagName, kXMLTagArray))
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
/***** plist ****/
else if (!strncmp(tagName, kXMLTagPList, kXMLTagPListLen)) {
length = 0;
}
else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " ")))
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
/***** dict ****/
else if (!strncmp(tagName, kXMLTagDict, kXMLTagDictLen)) {
if (!strncmp(tagName, kXMLTagDict, kXMLTagDictLen) && tagName[strlen(tagName)-1] == '/') { /* <dict.../> */
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1);
} else if (!tagName[kXMLTagDictLen] || ' ' == tagName[kXMLTagDictLen]) { /* <dict> or<dict ...> */
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
} else { /* unrecognized <dict...> */
*tag = 0;
length = 0;
}
}
else if (!strcmp(tagName, kXMLTagArray "/"))
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1);
/***** data ****/
else if ((!strncmp(tagName, kXMLTagData, kXMLTagDataLen))
&& (!tagName[kXMLTagDataLen] /* <data> */
|| ' ' == tagName[kXMLTagDataLen])) { /* <data ...> */
length = ParseTagData(buffer + pos, tag);
}
/***** date ****/
else if ((!strncmp(tagName, kXMLTagDate, kXMLTagDateLen))
&& (!tagName[kXMLTagDateLen] /* <date> */
|| ' ' == tagName[kXMLTagDateLen])) { /* <date ...> */
length = ParseTagDate(buffer + pos, tag);
}
/***** array ****/
else if (!strncmp(tagName, kXMLTagArray, kXMLTagArrayLen)) { /* <array...> */
char c = tagName[kXMLTagArrayLen];
if ('/' == c) { /* <array/> */
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1);
}
else if ('\0' == c || ' ' == c) { /* <array> or <array ...> */
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
} else { /* unrecognized <array...> */
*tag = 0;
length = 0;
}
}
/***** unknown ****/
else
{
// it wasn't parsed so we consumed no additional characters
else {
*tag = 0;
length = 0;
}
tagList = 0;
pos = 0;
if (!empty)
{
while (1)
{
if (!empty) {
while (1) {
length = XMLParseNextTag(buffer + pos, &tmpTag);
if (length == -1) {
break;
tagList = tmpTag;
}
if (length == -1)
{
if (length == -1) {
XMLFreeTag(tagList);
return -1;
}
}
tmpTag = NewTag();
if (tmpTag == 0)
{
if (tmpTag == 0) {
XMLFreeTag(tagList);
return -1;
}
TagPtr tmpTag;
char* val = buffer;
int size;
if(buffer[0] == '<')
{
printf("Warning integer is non existant\n");
}
size = length = FixDataMatchingTag(buffer, kXMLTagInteger);
if (length == -1) return -1;
if (length == -1) {
return -1;
}
tmpTag = NewTag();
if (tmpTag == 0) return -1;
if (tmpTag == 0) {
return -1;
}
integer = 0;
if(size > 1 && (val[1] == 'x' || val[1] == 'X'))// Hex value
{
if(size > 1 && (val[1] == 'x' || val[1] == 'X')) { // Hex value
val += 2;
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
integer = (integer * 16) + (*val++ - '0');
}
else if ((*val >= 'a' && *val <= 'f'))// a - f
{
} else if ((*val >= 'a' && *val <= 'f')) { // a - f
integer = (integer * 16) + (*val++ - 'a' + 10);
}
else if ((*val >= 'A' && *val <= 'F'))// A - F
{
integer = (integer * 16) + (*val++ - 'a' + 10);
}
else
{
} else if ((*val >= 'A' && *val <= 'F')) { // A - F
integer = (integer * 16) + (*val++ - 'A' + 10);
} else {
printf("ParseTagInteger hex error (0x%x) in buffer %s\n", *val, buffer);
getchar();
XMLFreeTag(tmpTag);
return -1;
}
}
}
else if ( size )// Decimal value
{
if (*val == '-')
{
} else if ( size ) { // Decimal value
if (*val == '-') {
negative = true;
val++;
size--;
}
for (integer = 0; size > 0; size--)
{
if(*val) // UGLY HACK, fix me.
{
if (*val < '0' || *val > '9')
{
for (integer = 0; size > 0; size--) {
if(*val) { // UGLY HACK, fix me.
if (*val < '0' || *val > '9') {
printf("ParseTagInteger decimal error (0x%x) in buffer %s\n", *val, buffer);
getchar();
return -1;
}
integer = (integer * 10) + (*val++ - '0');
}
}
if (negative)
if (negative) {
integer = -integer;
}
}
tmpTag->type = kTagTypeInteger;
static long
GetNextTag( char * buffer, char ** tag, long * start )
{
long cnt, cnt2;
char* tagStart = buffer;
char* tagEnd;
char c;
if (tag == 0) return -1;
if (!tag) {
return -1;
}
// Find the start of the tag.
cnt = 0;
while ((buffer[cnt] != '\0') && (buffer[cnt] != '<')) cnt++;
if (buffer[cnt] == '\0') return -1;
// Find the end of the tag.
cnt2 = cnt + 1;
while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>')) cnt2++;
if (buffer[cnt2] == '\0') return -1;
/* Find the start of the tag. */
do {
c = *tagStart++;
if (c == '<') {
break;
}
} while (c);
if (!c) {
return -1;
}
/* tagStart points just past the '<' */
/* Find the end of the tag. */
tagEnd = tagStart;
do {
c = *tagEnd++;
if (c == '>') {
break;
}
} while (c);
if (!c) {
return -1;
}
// Fix the tag data.
*tag = buffer + cnt + 1;
buffer[cnt2] = '\0';
if (start) *start = cnt;
/* tagEnd points just past the '>' */
/* Fix up tag data by nulling out the '>' */
--tagEnd;
*tagEnd = '\0';
return cnt2 + 1;
*tag = tagStart; /* first char after initial '<' */
if (start) {
*start = (long) (tagStart - buffer) - 1; /* offset of the initial '<' itself */
}
/* Return offset to the char after '>' */
return (long) (tagEnd - buffer) + 1;
}
//==========================================================================
XMLFreeTag( TagPtr tag )
{
#if DOFREE
if (tag == 0)
{
if (tag == 0) {
return;
}
if (!XMLIsInteger(tag) && tag->string)
{
if (!XMLIsInteger(tag) && tag->string) {
FreeSymbol(tag->string);
}
symbol = FindSymbol(string, 0);
// Add the new symbol.
if (symbol == 0)
{
if (symbol == 0) {
symbol = (SymbolPtr)malloc(sizeof(Symbol) + 1 + strlen(string));
if (symbol == 0) //return 0;
{
if (symbol == 0) { //return 0;
stop("NULL symbol!");
}
// Update the refCount and return the string.
symbol->refCount++;
if (lastGuy && lastGuy->next != 0)
{
if (lastGuy && lastGuy->next != 0) {
stop("last guy not last!");
}
// Look for string in the list of symbols.
symbol = FindSymbol(string, &prev);
if (symbol == 0)
{
if (symbol == 0) {
return;
}
// Update the refCount.
symbol->refCount--;
if (symbol->refCount != 0)
{
if (symbol->refCount != 0) {
return;
}
// Remove the symbol from the list.
if (prev != 0)
{
if (prev != 0) {
prev->next = symbol->next;
}
else
{
} else {
gSymbolsHead = symbol->next;
}
symbol = gSymbolsHead;
prev = 0;
while (symbol != 0)
{
if (!strcmp(symbol->string, string))
{
while (symbol != 0) {
if (!strcmp(symbol->string, string)) {
break;
}
symbol = symbol->next;
}
if ((symbol != 0) && (prevSymbol != 0))
{
if ((symbol != 0) && (prevSymbol != 0)) {
*prevSymbol = prev;
}
bool XMLIsType(TagPtr dict, enum xmltype type)
{
if(!dict)
{
if(!dict) {
return (type == kTagTypeNone);
}
return (dict->type == type);
TagPtr XMLCastArray(TagPtr dict)
{
if(!dict)
{
if(!dict) {
return NULL;
}
if(dict->type == kTagTypeArray)
{
if(dict->type == kTagTypeArray) {
return dict;
}
else
{
} else {
return NULL;
}
}
TagPtr XMLCastDict(TagPtr dict)
{
if(!dict)
{
if(!dict) {
return NULL;
}
if(dict->type == kTagTypeDict)
{
if(dict->type == kTagTypeDict) {
return dict;
}
else
{
} else {
return NULL;
}
}
char* XMLCastString(TagPtr dict)
{
if(!dict)
{
if(!dict) {
return NULL;
}
if((dict->type == kTagTypeString) || (dict->type == kTagTypeKey))
{
if((dict->type == kTagTypeString) || (dict->type == kTagTypeKey)) {
return dict->string;
}
char* XMLCastData(TagPtr dict, int* length)
{
if(!dict)
{
if(!dict) {
return NULL;
}
if((dict->type == kTagTypeData) || (dict->type == kTagTypeKey))
{
if((dict->type == kTagTypeData) || (dict->type == kTagTypeKey)) {
*length = dict->offset;
return dict->string;
}
long XMLCastStringOffset(TagPtr dict)
{
if(dict && ((dict->type == kTagTypeString) || (dict->type == kTagTypeKey)))
{
if(dict && ((dict->type == kTagTypeString) || (dict->type == kTagTypeKey))) {
return dict->offset;
}
else
{
} else {
return -1;
}
}
bool XMLCastBoolean(TagPtr dict)
{
if(!dict)
{
if(!dict) {
return false;
}
if(dict->type == kTagTypeTrue)
{
if(dict->type == kTagTypeTrue) {
return true;
}
return false;
}
int XMLCastInteger(TagPtr dict)
{
if(!dict)
{
if(!dict) {
//printf("XMLCastInteger: null dict\n");
return 0;
}
if(dict->type == kTagTypeInteger)
{
if(dict->type == kTagTypeInteger) {
return (int)(dict->string);
}
return 0;
}
bool XMLAddTagToDictionary(TagPtr dict, char* key, TagPtr value)
{
if (!dict || dict->type != kTagTypeDict)
{
if (!dict || dict->type != kTagTypeDict) {
return false;
}
char* string;
tmpTag = NewTag();
if (tmpTag == 0)
{
if (tmpTag == 0) {
return false;
}
string = NewSymbol(key);
if (string == 0)
{
if (string == 0) {
XMLFreeTag(tmpTag);
return false;
}
tmpTag->tagNext = 0;
TagPtr tagList = dict->tag;
if(!tagList)
{
if(!tagList) {
// First tag
dict->tag = tmpTag;
return true;
}
while(tagList && tagList->tagNext) tagList = tagList->tagNext;
if(tagList)
{
if(tagList) {
tagList->tagNext = tmpTag;
return true;
}
branches/ErmaC/Enoch/i386/libsaio/xml.h
4848
4949
5050
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
6651
6752
6853
extern string_ref* ref_strings;
#define kXMLTagPList "plist "
#define kXMLTagDict "dict"
#define kXMLTagKey "key"
#define kXMLTagString "string"
#define kXMLTagInteger "integer"
#define kXMLTagData "data"
#define kXMLTagDate "date"
#define kXMLTagFalse "false/"
#define kXMLTagTrue "true/"
#define kXMLTagArray "array"
// for back-references used by libkern serializer
#define kXMLTagReference "reference"
#define kXMLStringID "ID="
#define kXMLStringIDRef "IDREF="
#define kPropCFBundleIdentifier ("CFBundleIdentifier")
#define kPropCFBundleExecutable ("CFBundleExecutable")
#define kPropOSBundleRequired ("OSBundleRequired")
branches/ErmaC/Enoch/i386/libsaio/ext2fs.c
1818
1919
2020
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
2143
2244
2345
24
46
2547
48
2649
2750
28
29
51
3052
3153
3254
33
34
55
3556
3657
3758
......
4667
4768
4869
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
return (OSReadLittleInt16(buf+0x438,0)==0xEF53);
}
void EX2GetDescription(CICell ih, char *str, long strMaxLen)
{
char * buf=malloc (EX2ProbeSize);
str[0]=0;
if (!buf) {
return;
}
Seek(ih, 0);
Read(ih, (long)buf, EX2ProbeSize);
if (!EX2Probe (buf)) {
free (buf);
return;
}
if (OSReadLittleInt32 (buf+0x44c,0)<1) {
free (buf);
return;
}
str[strMaxLen]=0;
strncpy (str, buf+0x478, MIN(strMaxLen, 16));
free (buf);
}
long EX2GetUUID(CICell ih, char *uuidStr)
{
uint8_t *b, *buf=malloc (EX2ProbeSize);
if (!buf)
if (!buf) {
return -1;
}
Seek(ih, 0);
Read(ih, (long)buf, EX2ProbeSize);
if (!EX2Probe (buf))
{
if (!EX2Probe (buf)) {
free (buf);
return -1;
}
if (OSReadLittleInt32 (buf+0x44c,0)<1)
{
if (OSReadLittleInt32 (buf+0x44c,0)<1) {
free (buf);
return -1;
}
free (buf);
return 0;
}
void EX2GetDescription(CICell ih, char *str, long strMaxLen)
{
char * buf=malloc (EX2ProbeSize);
str[0]=0;
if (!buf)
return;
Seek(ih, 0);
Read(ih, (long)buf, EX2ProbeSize);
if (!EX2Probe (buf))
{
free (buf);
return;
}
if (OSReadLittleInt32 (buf+0x44c,0)<1)
{
free (buf);
return;
}
str[strMaxLen]=0;
strncpy (str, buf+0x478, MIN(strMaxLen, 16));
free (buf);
}
branches/ErmaC/Enoch/i386/libsaio/device_tree.c
297297
298298
299299
300
300
301301
302302
303303
for (count = 0, prop = node->properties; prop != 0; count++, prop = prop->next)
{
flatProp = (DeviceTreeNodeProperty *)buffer;
strcpy(flatProp->name, prop->name);
strncpy(flatProp->name, prop->name, kPropNameLength);
flatProp->length = prop->length;
buffer += sizeof(DeviceTreeNodeProperty);
bcopy(prop->value, buffer, prop->length);
branches/ErmaC/Enoch/i386/libsaio/acpi_patcher.c
516516
517517
518518
519
520
519
521520
522521
523
524
525
522
526523
527524
528525
529526
530
527
531528
529
532530
533531
534532
535533
536534
537535
538
539
536
540537
541538
542539
543540
544541
545
546
547
542
543
548544
549
550
551
545
546
552547
553548
554549
555
550
556551
552
557553
558554
559555
......
596592
597593
598594
599
600
601
595
602596
603597
604598
......
607601
608602
609603
610
611
604
612605
613606
614
615
616
607
617608
618609
619610
620
621
611
622612
623613
624614
625615
626616
627617
628
618
629619
630620
631621
......
636626
637627
638628
639
640
629
641630
642631
643632
......
647636
648637
649638
650
651
639
652640
653641
654642
......
660648
661649
662650
663
664
651
665652
666653
667654
......
687674
688675
689676
690
691
692
677
693678
694679
695680
......
707692
708693
709694
710
711
695
712696
713697
714
715
698
716699
717
718
719
700
720701
721702
722
723
724
703
725704
726705
727706
728707
729
730
708
731709
732710
733711
......
738716
739717
740718
741
742
743
719
744720
745721
746722
747723
748724
749725
750
751
752
753
726
727
754728
755
756
757
729
758730
759731
760732
761
762
763
733
764734
765735
766736
767737
768
769
770
771
738
739
772740
773741
774742
775
776
777
743
778744
779745
780746
......
784750
785751
786752
787
788
789
790
753
754
791755
792756
793757
......
796760
797761
798762
799
800
801
763
802764
803765
804766
......
812774
813775
814776
815
816
777
817778
818779
819780
820
821
781
822782
823783
824784
......
868828
869829
870830
871
872
831
873832
874
875
876
833
877834
878835
879836
......
882839
883840
884841
885
886
842
887843
888
889
890
844
891845
892846
893847
894848
895849
896850
897
898
851
899852
900
901
902
853
903854
904855
905856
906857
907858
908859
909
910
860
911861
912
913
914
862
915863
916864
917865
918866
919867
920868
921
922
869
923870
924
925
926
871
927872
928873
929874
930875
931876
932877
933
934
878
935879
936
937
938
880
939881
940882
941883
942884
943885
944886
945
946
887
947888
948
949
950
889
951890
952891
953892
954893
955894
956895
957
958
896
959897
960
961
962
898
963899
964900
965901
......
998934
999935
1000936
1001
1002
937
1003938
1004939
1005940
1006941
1007
1008
942
1009943
1010
1011
1012
944
1013945
1014946
1015947
......
1023955
1024956
1025957
1026
1027
958
1028959
1029
1030
960
1031961
1032
1033
1034
962
1035963
1036964
1037965
......
1052980
1053981
1054982
1055
1056
983
1057984
1058985
1059986
......
1064991
1065992
1066993
1067
1068
994
1069995
1070
1071
996
1072997
1073998
1074999
......
10761001
10771002
10781003
1079
1080
1004
10811005
10821006
10831007
10841008
10851009
1086
1087
1010
10881011
10891012
10901013
10911014
10921015
1093
1094
1016
10951017
10961018
10971019
10981020
10991021
1100
1101
1022
11021023
11031024
11041025
11051026
11061027
1107
1108
1028
11091029
11101030
11111031
11121032
11131033
1114
1115
1034
11161035
11171036
11181037
11191038
11201039
1121
1122
1040
11231041
11241042
11251043
11261044
11271045
1128
1129
1046
11301047
11311048
1132
1133
1049
11341050
11351051
11361052
11371053
11381054
1139
1140
1055
11411056
11421057
1143
1144
1058
11451059
11461060
11471061
11481062
11491063
1150
1151
1064
11521065
11531066
1154
1155
1067
11561068
11571069
11581070
11591071
11601072
1161
1162
1073
11631074
11641075
1165
1166
1076
11671077
11681078
11691079
11701080
11711081
1172
1173
1082
11741083
11751084
1176
1177
1085
11781086
11791087
11801088
11811089
11821090
1183
1184
1091
11851092
11861093
1187
1188
1094
11891095
11901096
11911097
11921098
11931099
1194
1195
1100
11961101
11971102
1198
1199
1103
12001104
12011105
12021106
12031107
12041108
1205
1206
1109
12071110
12081111
1209
1210
1112
12111113
12121114
12131115
12141116
12151117
12161118
1217
1218
1119
12191120
12201121
12211122
12221123
12231124
1224
1225
1125
12261126
12271127
12281128
......
12311131
12321132
12331133
1234
1235
1134
12361135
12371136
12381137
12391138
12401139
12411140
1242
1243
1141
12441142
12451143
12461144
......
12611159
12621160
12631161
1264
1265
1162
12661163
12671164
1268
1165
12691166
1167
12701168
12711169
12721170
......
12791177
12801178
12811179
1282
1283
1284
1180
12851181
12861182
12871183
12881184
1289
1290
1185
12911186
12921187
12931188
......
12951190
12961191
12971192
1298
1299
1193
13001194
13011195
13021196
......
13081202
13091203
13101204
1311
1312
1205
13131206
1314
1315
1207
13161208
13171209
13181210
13191211
1320
1321
1212
13221213
13231214
13241215
13251216
13261217
1327
1328
1218
13291219
13301220
13311221
13321222
13331223
1334
1335
1224
13361225
13371226
13381227
13391228
13401229
1341
1342
1230
13431231
13441232
13451233
13461234
13471235
1348
1349
1236
13501237
13511238
13521239
1353
1240
13541241
1355
1356
1242
13571243
13581244
13591245
13601246
13611247
1362
1363
1248
13641249
13651250
13661251
13671252
13681253
1369
1370
1254
13711255
13721256
1373
1374
1257
13751258
13761259
13771260
......
13801263
13811264
13821265
1383
1384
1266
13851267
13861268
1387
1388
1269
13891270
13901271
13911272
......
13941275
13951276
13961277
1397
1398
1278
13991279
14001280
1401
1402
1281
14031282
14041283
14051284
......
14081287
14091288
14101289
1411
1412
1290
14131291
14141292
1415
1416
1293
14171294
14181295
14191296
......
14221299
14231300
14241301
1425
1426
1302
14271303
1428
1429
1430
1304
1305
14311306
14321307
14331308
......
14361311
14371312
14381313
1439
1440
1314
14411315
14421316
1443
1444
1317
14451318
14461319
14471320
......
14501323
14511324
14521325
1453
1454
1326
14551327
14561328
1457
1458
1329
14591330
14601331
14611332
......
14641335
14651336
14661337
1467
1468
1338
14691339
14701340
1471
1472
1341
14731342
14741343
14751344
......
14781347
14791348
14801349
1481
1482
1350
14831351
14841352
14851353
14861354
14871355
14881356
1489
1490
1357
14911358
14921359
14931360
......
14981365
14991366
15001367
1501
1502
1368
15031369
15041370
15051371
15061372
15071373
1508
1509
1374
15101375
15111376
15121377
......
15341399
15351400
15361401
1537
1538
1402
15391403
15401404
1541
1405
15421406
1407
15431408
15441409
1545
15461410
15471411
15481412
15491413
15501414
1551
1552
1553
1415
15541416
15551417
15561418
......
15731435
15741436
15751437
1576
1577
1438
15781439
15791440
15801441
15811442
15821443
15831444
1584
15851445
15861446
15871447
1588
1589
1448
15901449
15911450
15921451
1593
1594
1595
1452
15961453
15971454
15981455
minimum.CID = ((minimum.FID & 0x1F) << 1) >> cpu_dynamic_fsb;
// Sanity check
if (maximum.CID < minimum.CID)
{
if (maximum.CID < minimum.CID) {
DBG("P-States: Insane FID values!");
p_states_count = 0;
}
else
{
} else {
// Finalize P-States
// Find how many P-States machine supports
p_states_count = maximum.CID - minimum.CID + 1;
if (p_states_count > 32)
if (p_states_count > 32) {
p_states_count = 32;
}
uint8_t vidstep;
uint8_t i = 0, u, invalid = 0;
vidstep = ((maximum.VID << 2) - (minimum.VID << 2)) / (p_states_count - 1);
for (u = 0; u < p_states_count; u++)
{
for (u = 0; u < p_states_count; u++) {
i = u - invalid;
p_states[i].CID = maximum.CID - u;
p_states[i].FID = (p_states[i].CID >> 1);
if (p_states[i].FID < 0x6)
{
if (cpu_dynamic_fsb)
if (p_states[i].FID < 0x6) {
if (cpu_dynamic_fsb) {
p_states[i].FID = (p_states[i].FID << 1) | 0x80;
}
else if (cpu_noninteger_bus_ratio)
{
}
} else if (cpu_noninteger_bus_ratio) {
p_states[i].FID = p_states[i].FID | (0x40 * (p_states[i].CID & 0x1));
}
if (i && p_states[i].FID == p_states[i-1].FID)
if (i && p_states[i].FID == p_states[i-1].FID) {
invalid++;
}
p_states[i].VID = ((maximum.VID << 2) - (vidstep * u)) >> 2;
(Platform.CPU.Model == CPU_MODEL_HASWELL_ULT) || (Platform.CPU.Model == CPU_MODEL_CRYSTALWELL))
{
maximum.Control = (rdmsr64(MSR_IA32_PERF_STATUS) >> 8) & 0xff;
}
else
{
} else {
maximum.Control = rdmsr64(MSR_IA32_PERF_STATUS) & 0xff;
}
verbose("P-States: min 0x%x, max 0x%x\n", minimum.Control, maximum.Control);
// Sanity check
if (maximum.Control < minimum.Control)
{
if (maximum.Control < minimum.Control) {
DBG("Insane control values!");
p_states_count = 0;
}
else
{
} else {
uint8_t i;
p_states_count = 0;
for (i = maximum.Control; i >= minimum.Control; i--)
{
for (i = maximum.Control; i >= minimum.Control; i--) {
p_states[p_states_count].Control = i;
p_states[p_states_count].CID = p_states[p_states_count].Control << 1;
p_states[p_states_count].Frequency = (Platform.CPU.FSBFrequency / 1000000) * i;
p_states_count++;
}
}
break;
}
default:
}
// Generating SSDT
if (p_states_count > 0)
{
if (p_states_count > 0) {
int i;
AML_CHUNK* root = aml_create_node(NULL);
AML_CHUNK* name = aml_add_name(scop, "PSS_");
AML_CHUNK* pack = aml_add_package(name);
for (i = 0; i < p_states_count; i++)
{
for (i = 0; i < p_states_count; i++) {
AML_CHUNK* pstt = aml_add_package(pack);
aml_add_dword(pstt, p_states[i].Frequency);
}
// Add aliaces
for (i = 0; i < acpi_cpu_count; i++)
{
for (i = 0; i < acpi_cpu_count; i++) {
char name[9];
sprintf(name, "_PR_%c%c%c%c", acpi_cpu_name[i][0], acpi_cpu_name[i][1], acpi_cpu_name[i][2], acpi_cpu_name[i][3]);
return ssdt;
}
}
else
{
} else {
verbose ("ACPI CPUs not found: P-States not generated !!!\n");
}
const char * value;
// Restart Fix
if (Platform.CPU.Vendor == 0x756E6547)
{/* Intel */
if (Platform.CPU.Vendor == 0x756E6547) { /* Intel */
fix_restart = true;
fix_restart_ps2 = false;
if ( getBoolForKey(kPS2RestartFix, &fix_restart_ps2, &bootInfo->chameleonConfig) && fix_restart_ps2)
{
if ( getBoolForKey(kPS2RestartFix, &fix_restart_ps2, &bootInfo->chameleonConfig) && fix_restart_ps2) {
fix_restart = true;
}
else
{
} else {
getBoolForKey(kRestartFix, &fix_restart, &bootInfo->chameleonConfig);
}
}
else
{
} else {
verbose ("Not an Intel platform: Restart Fix not applied !!!\n");
fix_restart = false;
}
if (fix_restart)
{
if (fix_restart) {
fadt_rev2_needed = true;
}
memcpy(fadt_mod, fadt, fadt->Length);
fadt_mod->Length = 0x84;
fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)
}
else
{
} else {
fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);
memcpy(fadt_mod, fadt, fadt->Length);
}
// Determine system type / PM_Model
if ( (value=getStringForKey(kSystemType, &bootInfo->chameleonConfig))!=NULL)
{
if (Platform.Type > 6)
{
if(fadt_mod->PM_Profile<=6)
{
if (Platform.Type > 6) {
if(fadt_mod->PM_Profile<=6) {
Platform.Type = fadt_mod->PM_Profile; // get the fadt if correct
}
else
{
} else {
Platform.Type = 1;/* Set a fixed value (Desktop) */
}
verbose("Error: system-type must be 0..6. Defaulting to %d !\n", Platform.Type);
}
else
{
} else {
Platform.Type = (unsigned char) strtoul(value, NULL, 10);
}
}
// Set PM_Profile from System-type if only user wanted this value to be forced
if (fadt_mod->PM_Profile != Platform.Type)
{
if (value)
{
if (fadt_mod->PM_Profile != Platform.Type) {
if (value) {
// user has overriden the SystemType so take care of it in FACP
verbose("FADT: changing PM_Profile from 0x%02x to 0x%02x\n", fadt_mod->PM_Profile, Platform.Type);
fadt_mod->PM_Profile = Platform.Type;
}
else
{
} else {
// PM_Profile has a different value and no override has been set, so reflect the user value to ioregs
Platform.Type = fadt_mod->PM_Profile <= 6 ? fadt_mod->PM_Profile : 1;
}
setupSystemType();
// Patch FADT to fix restart
if (fix_restart)
{
if (fix_restart_ps2)
{
if (fix_restart) {
if (fix_restart_ps2) {
fadt_mod->Flags|= 0x400;
fadt_mod->Reset_SpaceID= 0x01; // System I/O
fadt_mod->Reset_BitWidth= 0x08; // 1 byte
fadt_mod->Reset_Address= 0x64; // Address of the register
fadt_mod->Reset_Value= 0xfe; // Value to write to reset the system
msglog("FADT: PS2 Restart Fix applied!\n");
}
else
{
} else {
fadt_mod->Flags|= 0x400;
fadt_mod->Reset_SpaceID= 0x01; // System I/O
fadt_mod->Reset_BitWidth= 0x08; // 1 byte
}
// Patch DSDT Address if we have loaded DSDT.aml
if(new_dsdt)
{
if(new_dsdt) {
DBG("DSDT: Old @%x,%x, ",fadt_mod->DSDT,fadt_mod->X_DSDT);
fadt_mod->DSDT=(uint32_t)new_dsdt;
if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length)
{
if ((uint32_t)(&(fadt_mod->X_DSDT))-(uint32_t)fadt_mod+8<=fadt_mod->Length) {
fadt_mod->X_DSDT=(uint32_t)new_dsdt;
}
acpi_cpu_count = 0;
/* Try using the file specified with the DSDT option */
if (getValueForKey(kDSDT, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kDSDT, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "DSDT.aml");
//verbose("dirSpec, DSDT.aml");
}
new_dsdt = loadACPITable(dirSpec);
/* Try using the file specified with the HPET option */
if (getValueForKey(kHPET, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kHPET, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "HPET.aml");
}
// Load replacement HPET
new_hpet = loadACPITable(dirSpec);
/* Try using the file specified with the SBST option */
if (getValueForKey(kSBST, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kSBST, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "SBST.aml");
}
// Load replacement SBST
new_sbst = loadACPITable(dirSpec);
/* Try using the file specified with the ECDT option */
if (getValueForKey(kECDT, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kECDT, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "ECDT.aml");
}
// Load replacement ECDT
new_ecdt = loadACPITable(dirSpec);
/* Try using the file specified with the ASF! option */
if (getValueForKey(kASFT, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kASFT, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "ASFT.aml");
}
// Load replacement ASF!
new_asft = loadACPITable(dirSpec);
/* Try using the file specified with the DMAR option */
if (getValueForKey(kDMAR, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kDMAR, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "DMAR.aml");
}
// Load replacement DMAR
new_dmar = loadACPITable(dirSpec);
/* Try using the file specified with the APIC option */
if (getValueForKey(kAPIC, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kAPIC, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "APIC.aml");
}
// Load replacement APIC
new_apic = loadACPITable(dirSpec);
// Try using the file specified with the MCFG option */
if (getValueForKey(kMCFG, &filename, &len, &bootInfo->chameleonConfig))
{
if (getValueForKey(kMCFG, &filename, &len, &bootInfo->chameleonConfig)) {
snprintf(dirSpec, sizeof(dirSpec), filename);
}
else
{
} else {
sprintf(dirSpec, "MCFG.aml");
}
// Load replacement MCFG
{
int i;
for (i = 0; i < 30; i++)
{
for (i = 0; i < 30; i++) {
char filename[512];
sprintf(filename, i > 0?"SSDT-%d.aml":"SSDT.aml", i);
if ( (new_ssdt[ssdt_count] = loadACPITable(filename)) )
{
if ( (new_ssdt[ssdt_count] = loadACPITable(filename)) ) {
ssdt_count++;
}
else
{
} else {
break;
}
}
// Find original rsdp
rsdp=(struct acpi_2_rsdp *)(version?getAddressOfAcpi20Table():getAddressOfAcpiTable());
if (!rsdp)
{
if (!rsdp) {
DBG("No ACPI version %d found. Ignoring\n", version+1);
if (version)
{
if (version) {
addConfigurationTable(&gEfiAcpi20TableGuid, NULL, "ACPI_20");
}
else
{
} else {
addConfigurationTable(&gEfiAcpiTableGuid, NULL, "ACPI");
}
continue;
DBG("RSDT @%x, Length %d\n",rsdt, rsdt->Length);
if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000)
{
if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000) {
uint32_t *rsdt_entries;
int rsdt_entries_num;
int dropoffset=0, i;
rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;
rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;
rsdt_entries=(uint32_t *)(rsdt_mod+1);
for (i=0;i<rsdt_entries_num;i++)
{
for (i=0;i<rsdt_entries_num;i++) {
char *table=(char *)(rsdt_entries[i]);
if (!table)
{
if (!table) {
continue;
}
rsdt_entries[i-dropoffset]=rsdt_entries[i];
if (drop_ssdt && tableSign(table, "SSDT"))
{
if (drop_ssdt && tableSign(table, "SSDT")) {
verbose("OEM SSDT tables was dropped\n");
dropoffset++;
continue;
}
if (drop_hpet && tableSign(table, "HPET"))
{
if (drop_hpet && tableSign(table, "HPET")) {
verbose("OEM HPET table was dropped\n");
dropoffset++;
continue;
}
if (drop_slic && tableSign(table, "SLIC"))
{
if (drop_slic && tableSign(table, "SLIC")) {
verbose("OEM SLIC table was dropped\n");
dropoffset++;
continue;
}
if (drop_sbst && tableSign(table, "SBST"))
{
if (drop_sbst && tableSign(table, "SBST")) {
verbose("OEM SBST table was dropped\n");
dropoffset++;
continue;
}
if (drop_ecdt && tableSign(table, "ECDT"))
{
if (drop_ecdt && tableSign(table, "ECDT")) {
verbose("OEM ECDT table was dropped\n");
dropoffset++;
continue;
}
if (drop_asft && tableSign(table, "ASF!"))
{
if (drop_asft && tableSign(table, "ASF!")) {
verbose("OEM ASF! table was dropped\n");
dropoffset++;
continue;
}
if (drop_dmar && tableSign(table, "DMAR"))
{
if (drop_dmar && tableSign(table, "DMAR")) {
verbose("OEM DMAR table was dropped\n");
dropoffset++;
continue;
}
if (tableSign(table, "HPET"))
{
if (tableSign(table, "HPET")) {
DBG("HPET found\n");
verbose("Custom HPET table was found\n");
if(new_hpet)
{
if(new_hpet) {
rsdt_entries[i-dropoffset]=(uint32_t)new_hpet;
}
continue;
}
if (tableSign(table, "SBST"))
{
if (tableSign(table, "SBST")) {
DBG("SBST found\n");
verbose("Custom SBST table was found\n");
if(new_sbst)
{
if(new_sbst) {
rsdt_entries[i-dropoffset]=(uint32_t)new_sbst;
}
continue;
}
if (tableSign(table, "ECDT"))
{
if (tableSign(table, "ECDT")) {
DBG("ECDT found\n");
verbose("Custom ECDT table was found\n");
if(new_ecdt)
{
if(new_ecdt) {
rsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;
}
continue;
}
if (tableSign(table, "ASF!"))
{
if (tableSign(table, "ASF!")) {
DBG("ASF! found\n");
verbose("Custom ASF! table was found\n");
if(new_asft)
{
if(new_asft) {
rsdt_entries[i-dropoffset]=(uint32_t)new_asft;
}
continue;
}
if (tableSign(table, "DMAR"))
{
if (tableSign(table, "DMAR")) {
DBG("DMAR found\n");
verbose("Custom DMAR table was found\n");
if(new_dmar)
{
if(new_dmar) {
rsdt_entries[i-dropoffset]=(uint32_t)new_dmar;
}
continue;
}
if (tableSign(table, "APIC"))
{
if (tableSign(table, "APIC")) {
DBG("APIC found\n");
verbose("Custom APIC table was found\n");
if(new_apic)
{
if(new_apic) {
rsdt_entries[i-dropoffset]=(uint32_t)new_apic;
}
continue;
}
if (tableSign(table, "MCFG"))
{
if (tableSign(table, "MCFG")) {
DBG("MCFG found\n");
verbose("Custom MCFG table was found\n");
if(new_mcfg)
{
if(new_mcfg) {
rsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;
}
continue;
}
if (tableSign(table, "DSDT"))
{
if (tableSign(table, "DSDT")) {
DBG("DSDT found\n");
verbose("Custom DSDT table was found\n");
if(new_dsdt)
{
if(new_dsdt) {
rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;
}
continue;
}
if (tableSign(table, "FACP"))
{
if (tableSign(table, "FACP")) {
struct acpi_2_fadt *fadt, *fadt_mod;
fadt=(struct acpi_2_fadt *)rsdt_entries[i];
DBG("FADT found @%x, Length %d\n",fadt, fadt->Length);
if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000)
{
if (!fadt || (uint32_t)fadt == 0xffffffff || fadt->Length>0x10000) {
printf("FADT incorrect. Not modified\n");
continue;
}
rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;
// Generate _CST SSDT
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
{
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod))) {
DBG("C-States generated\n");
generate_cstates = false; // Generate SSDT only once!
ssdt_count++;
}
// Generating _PSS SSDT
if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))
{
if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT))) {
DBG("P-States generated\n");
generate_pstates = false; // Generate SSDT only once!
ssdt_count++;
rsdt_entries=(uint32_t *)(rsdt_mod+1);
// Mozodojo: Insert additional SSDTs into RSDT
if(ssdt_count>0)
{
if(ssdt_count>0) {
int j;
for (j=0; j<ssdt_count; j++)
for (j=0; j<ssdt_count; j++) {
rsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
}
verbose("RSDT: Added %d SSDT table(s)\n", ssdt_count);
rsdt_mod->Checksum=256-checksum8(rsdt_mod,rsdt_mod->Length);
DBG("New checksum %d at %x\n", rsdt_mod->Checksum,rsdt_mod);
}
else
{
} else {
rsdp_mod->RsdtAddress=0;
printf("RSDT not found or incorrect\n");
}
if (version)
{
if (version) {
struct acpi_2_xsdt *xsdt, *xsdt_mod;
// FIXME: handle 64-bit address correctly
xsdt=(struct acpi_2_xsdt*) ((uint32_t)rsdp->XsdtAddress);
DBG("XSDT @%x;%x, Length=%d\n", (uint32_t)(rsdp->XsdtAddress>>32),(uint32_t)rsdp->XsdtAddress, xsdt->Length);
if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000)
{
if (xsdt && (uint64_t)rsdp->XsdtAddress<0xffffffff && xsdt->Length<0x10000) {
uint64_t *xsdt_entries;
int xsdt_entries_num, i;
int dropoffset=0;
rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;
xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;
xsdt_entries=(uint64_t *)(xsdt_mod+1);
for (i=0;i<xsdt_entries_num;i++)
{
for (i=0;i<xsdt_entries_num;i++) {
char *table=(char *)((uint32_t)(xsdt_entries[i]));
if (!table)
{
if (!table) {
continue;
}
xsdt_entries[i-dropoffset]=xsdt_entries[i];
if (drop_ssdt && tableSign(table, "SSDT"))
{
if (drop_ssdt && tableSign(table, "SSDT")) {
verbose("OEM SSDT tables was dropped\n");
dropoffset++;
continue;
}
if (drop_hpet && tableSign(table, "HPET"))
{
if (drop_hpet && tableSign(table, "HPET")) {
verbose("OEM HPET table was dropped\n");
dropoffset++;
continue;
}
if (drop_slic && tableSign(table, "SLIC"))
{
if (drop_slic && tableSign(table, "SLIC")) {
verbose("OEM SLIC table was dropped\n");
dropoffset++;
continue;
}
if (drop_sbst && tableSign(table, "SBST"))
{
if (drop_sbst && tableSign(table, "SBST")) {
verbose("OEM SBST table was dropped\n");
dropoffset++;
continue;
}
if (drop_ecdt && tableSign(table, "ECDT"))
{
if (drop_ecdt && tableSign(table, "ECDT")) {
verbose("OEM ECDT table was dropped\n");
dropoffset++;
continue;
}
}
if (drop_asft && tableSign(table, "ASF!"))
{
if (drop_asft && tableSign(table, "ASF!")) {
verbose("OEM ASF! table was dropped\n");
dropoffset++;
continue;
}
if (drop_dmar && tableSign(table, "DMAR"))
{
if (drop_dmar && tableSign(table, "DMAR")) {
verbose("OEM DMAR table was dropped\n");
dropoffset++;
continue;
}
if (tableSign(table, "DSDT"))
{
if (tableSign(table, "DSDT")) {
DBG("DSDT found\n");
if (new_dsdt)
{
if (new_dsdt) {
xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;
}
continue;
}
if (tableSign(table, "HPET"))
{
if (tableSign(table, "HPET")) {
DBG("HPET found\n");
if (new_hpet)
{
if (new_hpet) {
xsdt_entries[i-dropoffset]=(uint32_t)new_hpet;
}
continue;
}
if (tableSign(table, "SBST"))
{
if (tableSign(table, "SBST")) {
DBG("SBST found\n");
if (new_sbst)
{
if (new_sbst) {
xsdt_entries[i-dropoffset]=(uint32_t)new_sbst;
}
continue;
}
if (tableSign(table, "ECDT"))
{
if (tableSign(table, "ECDT")) {
DBG("ECDT found\n");
if (new_ecdt)
{
if (new_ecdt) {
xsdt_entries[i-dropoffset]=(uint32_t)new_ecdt;
}
continue;
}
if (tableSign(table, "ASF!"))
{
if (tableSign(table, "ASF!")) {
DBG("ASF! found\n");
;
if (new_asft)
{
if (new_asft) {
xsdt_entries[i-dropoffset]=(uint32_t)new_asft;
}
continue;
}
if (tableSign(table, "DMAR"))
{
if (tableSign(table, "DMAR")) {
DBG("DMAR found\n");
if (new_dmar)
{
if (new_dmar) {
xsdt_entries[i-dropoffset]=(uint32_t)new_dmar;
}
continue;
}
if (tableSign(table, "APIC"))
{
if (tableSign(table, "APIC")) {
DBG("APIC found\n");
if (new_apic)
{
if (new_apic) {
xsdt_entries[i-dropoffset]=(uint32_t)new_apic;
}
continue;
}
if (tableSign(table, "MCFG"))
{
if (tableSign(table, "MCFG")) {
DBG("MCFG found\n");
if (new_mcfg)
{
if (new_mcfg) {
xsdt_entries[i-dropoffset]=(uint32_t)new_mcfg;
}
continue;
}
if (tableSign(table, "FACP"))
{
if (tableSign(table, "FACP")) {
struct acpi_2_fadt *fadt, *fadt_mod;
fadt=(struct acpi_2_fadt *)(uint32_t)xsdt_entries[i];
DBG("FADT found @%x,%x, Length %d\n",(uint32_t)(xsdt_entries[i]>>32),fadt,
fadt->Length);
if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000)
{
if (!fadt || (uint64_t)xsdt_entries[i] >= 0xffffffff || fadt->Length>0x10000) {
verbose("FADT incorrect or after 4GB. Dropping XSDT\n");
goto drop_xsdt;
}
DBG("TABLE %c%c%c%c@%x,",table[0],table[1],table[2],table[3],xsdt_entries[i]);
// Generate _CST SSDT
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
{
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod))) {
generate_cstates = false; // Generate SSDT only once!
ssdt_count++;
}
// Generating _PSS SSDT
if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT)))
{
if (generate_pstates && (new_ssdt[ssdt_count] = generate_pss_ssdt((void*)fadt_mod->DSDT))) {
generate_pstates = false; // Generate SSDT only once!
ssdt_count++;
}
xsdt_entries=(uint64_t *)(xsdt_mod+1);
// Mozodojo: Insert additional SSDTs into XSDT
if(ssdt_count > 0)
{
if(ssdt_count > 0) {
int j;
for (j=0; j<ssdt_count; j++)
for (j=0; j<ssdt_count; j++) {
xsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
}
verbose("Added %d SSDT table(s) into XSDT\n", ssdt_count);
}
// Correct the checksum of XSDT
xsdt_mod->Checksum=0;
xsdt_mod->Checksum=256-checksum8(xsdt_mod,xsdt_mod->Length);
}
else
{
} else {
drop_xsdt:
DBG("About to drop XSDT\n");
DBG("New checksum %d\n", rsdp_mod->Checksum);
if (version)
{
if (version) {
DBG("RSDP: Original extended checksum %d", rsdp_mod->ExtendedChecksum);
rsdp_mod->ExtendedChecksum=0;
rsdp_mod->ExtendedChecksum=256-checksum8(rsdp_mod,rsdp_mod->Length);
DBG("New extended checksum %d\n", rsdp_mod->ExtendedChecksum);
}
//verbose("Patched ACPI version %d DSDT\n", version+1);
if (version)
{
if (version) {
/* XXX aserebln why uint32 cast if pointer is uint64 ? */
acpi20_p = (uint32_t)rsdp_mod;
addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20");
}
else
{
} else {
/* XXX aserebln why uint32 cast if pointer is uint64 ? */
acpi10_p = (uint32_t)rsdp_mod;
addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");
branches/ErmaC/Enoch/i386/libsaio/spd.c
3030
3131
3232
33
33
3434
35
35
3636
3737
3838
39
40
39
40
4141
4242
4343
......
6969
7070
7171
72
73
74
75
76
77
78
79
80
81
82
83
84
8572
8673
8774
......
124111
125112
126113
114
115
116
117
118
119
120
121
122
123
124
125
127126
128127
129128
......
147146
148147
149148
150
151
152
153
149
150
154151
155152
156153
157
158
159
160
161
162
163
154
155
156
164157
165158
166159
167160
168161
169
170
171
162
172163
173164
174165
175
176
177
178
166
167
179168
180169
181170
182171
183172
184
185
173
186174
187175
188176
......
191179
192180
193181
194
195
196
197
182
183
198184
199185
200186
......
205191
206192
207193
208
209
210
211
212
194
195
213196
214197
215198
......
233216
234217
235218
236
219
237220
238221
239
222
240223
241224
242225
243
226
244227
245
228
246229
247230
248231
......
254237
255238
256239
257
258
240
259241
260
261
262
242
263243
264244
265245
266246
267247
268248
269
270
249
271250
272251
273
274
252
275253
276254
277
278
279
255
280256
281257
282258
283
259
284260
285261
286262
......
288264
289265
290266
291
292
293
294
267
268
269
295270
296271
297272
......
313288
314289
315290
316
317
318
291
319292
320293
321
294
322295
323
324
296
325297
326298
327
328299
329300
330301
......
334305
335306
336307
337
338
308
339309
340
310
341311
342312
343313
......
346316
347317
348318
349
350
319
320
351321
352322
353323
......
361331
362332
363333
364
365
334
366335
367336
368337
......
371340
372341
373342
374
375
343
376344
377345
378
346
379347
380
381
348
382349
383350
384351
385
386
352
387353
388354
389355
......
394360
395361
396362
397
363
398364
399365
400366
......
407373
408374
409375
410
376
411377
412378
413379
......
452418
453419
454420
455
456
421
457422
458423
459424
460425
461426
462427
463
464
465
466
428
429
467430
468431
469432
"RAM", /* 00h Undefined */
"FPM", /* 01h FPM */
"EDO", /* 02h EDO */
"",/* 03h PIPELINE NIBBLE */
"",/* 03h PIPELINE NIBBLE */
"SDRAM", /* 04h SDRAM */
"",/* 05h MULTIPLEXED ROM */
"",/* 05h MULTIPLEXED ROM */
"DDR SGRAM",/* 06h SGRAM DDR */
"DDR SDRAM",/* 07h SDRAM DDR */
"DDR2 SDRAM", /* 08h SDRAM DDR 2 */
"",/* 09h Undefined */
"",/* 0Ah Undefined */
"",/* 09h Undefined */
"",/* 0Ah Undefined */
"DDR3 SDRAM"/* 0Bh SDRAM DDR 3 */
};
#define SMBHSTDAT 5
#define SBMBLKDAT 7
int spd_indexes[] = {
SPD_MEMORY_TYPE,
SPD_DDR3_MEMORY_BANK,
SPD_DDR3_MEMORY_CODE,
SPD_NUM_ROWS,
SPD_NUM_COLUMNS,
SPD_NUM_DIMM_BANKS,
SPD_NUM_BANKS_PER_SDRAM,
4,7,8,9,12,64, /* TODO: give names to these values */
95,96,97,98, 122,123,124,125 /* UIS */
};
#define SPD_INDEXES_SIZE (sizeof(spd_indexes) / sizeof(int))
/** Read one byte from the intel i2c, used for reading SPD on intel chipsets only. */
unsigned char smb_read_byte_intel(uint32_t base, uint8_t adr, uint8_t cmd)
/* SPD i2c read optimization: prefetch only what we need, read non prefetcheable bytes on the fly */
#define READ_SPD(spd, base, slot, x) spd[x] = smb_read_byte_intel(base, 0x50 + slot, x)
int spd_indexes[] = {
SPD_MEMORY_TYPE,
SPD_DDR3_MEMORY_BANK,
SPD_DDR3_MEMORY_CODE,
SPD_NUM_ROWS,
SPD_NUM_COLUMNS,
SPD_NUM_DIMM_BANKS,
SPD_NUM_BANKS_PER_SDRAM,
4,7,8,9,12,64, /* TODO: give names to these values */
95,96,97,98, 122,123,124,125 /* UIS */
};
#define SPD_INDEXES_SIZE (sizeof(spd_indexes) / sizeof(int))
/** Read from spd *used* values only*/
static void init_spd(char * spd, uint32_t base, int slot)
{ // DDR3
bank = (spd[SPD_DDR3_MEMORY_BANK] & 0x07f); // constructors like Patriot use b7=1
code = spd[SPD_DDR3_MEMORY_CODE];
for (i=0; i < VEN_MAP_SIZE; i++)
{
if (bank==vendorMap[i].bank && code==vendorMap[i].code)
{
for (i=0; i < VEN_MAP_SIZE; i++) {
if (bank==vendorMap[i].bank && code==vendorMap[i].code) {
return vendorMap[i].name;
}
}
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR)
{
if(spd[64]==0x7f)
{
for (i=64; i<72 && spd[i]==0x7f;i++)
{
} else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) {
if(spd[64]==0x7f) {
for (i=64; i<72 && spd[i]==0x7f;i++) {
bank++;
READ_SPD(spd, base, slot_num, (uint8_t)(i+1)); // prefetch next spd byte to read for next loop
}
READ_SPD(spd, base, slot_num,(uint8_t)i);
code = spd[i];
}
else
{
} else {
code = spd[64];
bank = 0;
}
for (i=0; i < VEN_MAP_SIZE; i++)
{
if (bank==vendorMap[i].bank && code==vendorMap[i].code)
{
for (i=0; i < VEN_MAP_SIZE; i++) {
if (bank==vendorMap[i].bank && code==vendorMap[i].code) {
return vendorMap[i].name;
}
}
}
/* OK there is no vendor id here lets try to match the partnum if it exists */
if (strstr(slot->PartNo,"GU332") == slot->PartNo) // Unifosa fingerprint
{
if (strstr(slot->PartNo,"GU332") == slot->PartNo) { // Unifosa fingerprint
return "Unifosa";
}
return "NoName";
/* Get Default Memory Module Speed (no overclocking handled) */
int getDDRspeedMhz(const char * spd)
{
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3)
{
switch(spd[12])
{
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) {
switch(spd[12]) {
case 0x0f:
return 1066;
case 0x0c:
default:
return 800;
}
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR)
{
switch(spd[9])
{
} else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) {
switch(spd[9]) {
case 0x50:
return 400;
case 0x3d:
const char *getDDRSerial(const char* spd)
{
static char asciiSerial[16];
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) // DDR3
{
sprintf(asciiSerial, "%X%X%X%X%X%X%X%X", SMST(122) /*& 0x7*/, SLST(122), SMST(123), SLST(123), SMST(124), SLST(124), SMST(125), SLST(125));
snprintf(asciiSerial, sizeof(asciiSerial), "%X%X%X%X%X%X%X%X", SMST(122) /*& 0x7*/, SLST(122), SMST(123), SLST(123), SMST(124), SLST(124), SMST(125), SLST(125));
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) // DDR2 or DDR
{
sprintf(asciiSerial, "%X%X%X%X%X%X%X%X", SMST(95) /*& 0x7*/, SLST(95), SMST(96), SLST(96), SMST(97), SLST(97), SMST(98), SLST(98));
snprintf(asciiSerial, sizeof(asciiSerial), "%X%X%X%X%X%X%X%X", SMST(95) /*& 0x7*/, SLST(95), SMST(96), SLST(96), SMST(97), SLST(97), SMST(98), SLST(98));
} else {
sprintf(asciiSerial, "0000000000000000");
sprintf(asciiSerial, "000000000000000");
}
return strdup(asciiSerial);
static char asciiPartNo[32];
int i, start=0, index = 0;
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3)
{
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) {
start = 128;
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR)
{
} else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) {
start = 73;
}
// Check that the spd part name is zero terminated and that it is ascii:
bzero(asciiPartNo, sizeof(asciiPartNo));
char c;
for (i=start; i < start + sizeof(asciiPartNo); i++)
{
for (i=start; i < start + sizeof(asciiPartNo); i++) {
READ_SPD(spd, base, slot, i); // only read once the corresponding model part (ddr3 or ddr2)
c = spd[i];
if (isalpha(c) || isdigit(c) || ispunct(c))
{
if (isalpha(c) || isdigit(c) || ispunct(c)) {
// It seems that System Profiler likes only letters and digits...
asciiPartNo[index++] = c;
}
else if (!isascii(c))
{
} else if (!isascii(c)) {
break;
}
}
return strdup(asciiPartNo);
}
/* Read from smbus the SPD content and interpret it for detecting memory attributes */
static void read_smb_intel(pci_dt_t *smbus_dev)
{
uint16_t speed;
uint8_t i, spd_size, spd_type;
static void read_smb_intel(pci_dt_t *smbus_dev) {
int i, speed;
uint8_t spd_size, spd_type;
uint32_t base, mmio, hostc;
//bool dump = false;
RamSlotInfo_t* slot;
char spdbuf[MAX_SPD_SIZE];
// Search MAX_RAM_SLOTS slots
for (i = 0; i < MAX_RAM_SLOTS; i++)
{
// ----
for (i = 0; i < MAX_RAM_SLOTS; i++) {
slot = &Platform.RAM.DIMM[i];
spd_size = smb_read_byte_intel(base, 0x50 + i, 0);
DBG("SPD[0] (size): 0x%02x @0x%x\n", spd_size, 0x50 + i);
DBG("SPD[0] (size): %d @0x%x\n", spd_size, 0x50 + i);
// Check spd is present
if (spd_size && (spd_size != 0xff))
{
if (spd_size && (spd_size != 0xff)) {
slot->spd = spdbuf;
// -----
slot->InUse = true;
bzero(slot->spd, spd_size);
//for (x = 0; x < spd_size; x++) slot->spd[x] = smb_read_byte_intel(base, 0x50 + i, x);
init_spd(slot->spd, base, i);
switch (slot->spd[SPD_MEMORY_TYPE])
{
switch (slot->spd[SPD_MEMORY_TYPE]) {
case SPD_MEMORY_TYPE_SDRAM_DDR:
slot->ModuleSize = (((1 << ((slot->spd[SPD_NUM_ROWS] & 0x0f)
+ (slot->spd[SPD_NUM_COLUMNS] & 0x0f) - 17)) *
((slot->spd[SPD_NUM_DIMM_BANKS] & 0x7) + 1) *
case SPD_MEMORY_TYPE_SDRAM_DDR2:
slot->ModuleSize = ((1 << ((slot->spd[SPD_NUM_ROWS] & 0x0f) + (slot->spd[SPD_NUM_COLUMNS] & 0x0f) - 17)) *
((slot->spd[SPD_NUM_DIMM_BANKS] & 0x7) + 1) * slot->spd[SPD_NUM_BANKS_PER_SDRAM]);
slot->ModuleSize = ((1 << ((slot->spd[SPD_NUM_ROWS] & 0x0f) + (slot->spd[SPD_NUM_COLUMNS] & 0x0f) - 17)) *
((slot->spd[SPD_NUM_DIMM_BANKS] & 0x7) + 1) * slot->spd[SPD_NUM_BANKS_PER_SDRAM]);
break;
case SPD_MEMORY_TYPE_SDRAM_DDR3:
spd_type = (slot->spd[SPD_MEMORY_TYPE] < ((char) 12) ? slot->spd[SPD_MEMORY_TYPE] : 0);
slot->Type = spd_mem_to_smbios[spd_type];
if (slot->Type == UNKNOWN_MEM_TYPE)
{
if (slot->Type == UNKNOWN_MEM_TYPE) {
continue;
}
slot->PartNo = getDDRPartNum(slot->spd, base, i);
// determine spd speed
speed = getDDRspeedMhz(slot->spd);
if (slot->Frequency<speed)
{
if (slot->Frequency < speed) {
slot->Frequency = speed;
}
// pci memory controller if available, is more reliable
if (Platform.RAM.Frequency > 0)
{
if (Platform.RAM.Frequency > 0) {
uint32_t freq = (uint32_t)Platform.RAM.Frequency / 500000;
// now round off special cases
uint32_t fmod100 = freq %100;
switch(fmod100)
{
switch(fmod100) {
case 1:freq--;break;
case 32:freq++;break;
case 65:freq++; break;
}
verbose("Slot: %d Type %d %dMB (%s) %dMHz Vendor=%s\n PartNo=%s SerialNo=%s\n",
i,
i,
(int)slot->Type,
slot->ModuleSize,
spd_memory_types[spd_type],
// laptops sometimes show slot 0 and 2 with slot 1 empty when only 2 slots are presents so:
Platform.DMI.DIMM[i]=
(uint32_t)((i>0 && Platform.RAM.DIMM[1].InUse==false && !fullBanks && Platform.DMI.CntMemorySlots == 2) ?
(uint32_t)((i>0 && Platform.RAM.DIMM[1].InUse==false && fullBanks && Platform.DMI.CntMemorySlots == 2) ?
mapping[i] : i); // for laptops case, mapping setup would need to be more generic than this
slot->spd = NULL;
pci_dt_t*current = pci_dt;
int i;
while (current)
{
while (current) {
#if 0
printf("%02x:%02x.%x [%04x] [%04x:%04x] :: %s\n",
current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func,
current->class_id, current->vendor_id, current->device_id,
get_pci_dev_path(current));
#endif
for ( i = 0; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ )
{
if (current->vendor_id == smbus_controllers[i].vendor && current->device_id == smbus_controllers[i].device)
{
for ( i = 0; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ ) {
if (current->vendor_id == smbus_controllers[i].vendor && current->device_id == smbus_controllers[i].device) {
smbus_controllers[i].read_smb(current); // read smb
return true;
}
branches/ErmaC/Enoch/i386/libsaio/device_inject.c
159159
160160
161161
162
163
162
164163
165164
166165
......
196195
197196
198197
199
200
201
202
203
204198
205
206
207
208
209
210
211
212
213
214
215
199
200
201
216202
217
218
219
220
221
222
223
224
225
203
204
205
206
207
208
209
210
211
226212
213
214
215
216
217
218
219
220
221
227222
228223
229224
230225
231
232
226
233227
234228
235
236
237
238
229
230
239231
240232
241233
......
246238
247239
248240
249
250
241
251242
252
253
254
243
255244
256245
257246
......
318307
319308
320309
321
322
310
323311
324312
325313
326314
327
328
329
330
331
332
315
316
317
333318
334319
335320
......
355340
356341
357342
358
359
343
360344
361345
362346
......
364348
365349
366350
367
368
369
370
351
352
371353
372354
373355
inti;
for(i = 0; i < numpaths; i++)
{
for(i = 0; i < numpaths; i++) {
device->pci_dev_path[i].length = 0x06;
device->pci_dev_path[i].type = 0x01;
device->pci_dev_path[i].subtype = 0x01;
}
uint32_t length = ((strlen(nm) * 2) + len + (2 * sizeof(uint32_t)) + 2);
uint8_t *data = (uint8_t*)malloc(length);
{
if(!data)
{
return 0;
}
memset(data, 0, length);
uint32_t off= 0;
data[off+1] = ((strlen(nm) * 2) + 6) >> 8;
data[off] = ((strlen(nm) * 2) + 6) & 0x00FF;
off += 4;
uint32_t i=0, l = strlen(nm);
for(i = 0 ; i < l ; i++, off += 2)
{
data[off] = *nm++;
}
if(!data) {
return 0;
}
off += 2;
l = len;
uint32_t *datalength = (uint32_t*)&data[off];
*datalength = (uint32_t)(l + 4);
off += 4;
for(i = 0 ; i < l ; i++, off++)
{
data[off] = *vl++;
}
memset(data, 0, length);
uint32_t off= 0;
data[off+1] = ((strlen(nm) * 2) + 6) >> 8;
data[off] = ((strlen(nm) * 2) + 6) & 0x00FF;
off += 4;
uint32_t i=0, l = strlen(nm);
for(i = 0 ; i < l ; i++, off += 2) {
data[off] = *nm++;
}
off += 2;
l = len;
uint32_t *datalength = (uint32_t*)&data[off];
*datalength = (uint32_t)(l + 4);
off += 4;
for(i = 0 ; i < l ; i++, off++) {
data[off] = *vl++;
}
uint32_t offset = device->length - (24 + (6 * device->num_pci_devpaths));
uint8_t *newdata = (uint8_t*)malloc((length + offset));
if(!newdata)
{
if(!newdata) {
return 0;
}
if(device->data)
{
if(offset > 1)
{
if(device->data) {
if(offset > 1) {
memcpy(newdata, device->data, offset);
}
}
device->string->length += length;
device->numentries++;
if(!device->data)
{
if(!device->data) {
device->data = (uint8_t*)malloc(sizeof(uint8_t));
}
else
{
} else {
free(device->data);
}
void devprop_free_string(DevPropString *string)
{
if(!string)
{
if(!string) {
return;
}
int i;
for(i = 0; i < string->numentries; i++)
{
if(string->entries[i])
{
if(string->entries[i]->data)
{
for(i = 0; i < string->numentries; i++) {
if(string->entries[i]) {
if(string->entries[i]->data) {
free(string->entries[i]->data);
string->entries[i]->data = NULL;
}
inti;
charbuf[3];
if (hex == NULL || bin == NULL || len <= 0 || strlen(hex) != len * 2)
{
if (hex == NULL || bin == NULL || len <= 0 || strlen(hex) != len * 2) {
printf("[ERROR] bin2hex input error\n");
return -1;
}
buf[2] = '\0';
p = (char *) hex;
for (i = 0; i < len; i++)
{
if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1]))
{
for (i = 0; i < len; i++) {
if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1])) {
printf("[ERROR] bin2hex '%s' syntax error\n", hex);
return -2;
}
branches/ErmaC/Enoch/i386/libsaio/device_inject.h
8080
8181
8282
83
8384
intdevprop_add_network_template(DevPropDevice *device, uint16_t vendor_id);
inthex2bin(const char *hex, uint8_t *bin, int len);
#endif /* !__LIBSAIO_DEVICE_INJECT_H */
branches/ErmaC/Enoch/i386/libsaio/dram_controllers.c
3737
3838
3939
40
40
4141
4242
43
44
43
4544
4645
4746
......
5756
5857
5958
60
61
59
6260
6361
6462
6563
66
67
68
64
65
6966
7067
7168
......
8279
8380
8481
85
82
8683
8784
8885
8986
9087
91
88
9289
93
94
95
90
91
9692
9793
98
94
9995
100
96
10197
102
98
10399
104
100
105101
106
107
108
102
103
109104
110
111
105
112106
113107
114108
115109
116110
117
111
118112
119113
120
121
114
122115
123116
124117
......
127120
128121
129122
130
123
131124
132
133
125
134126
135127
136128
......
138130
139131
140132
141
133
142134
143
144
135
145136
146137
147138
148139
149140
150141
151
142
152143
153144
154145
......
159150
160151
161152
162
153
163154
164155
165156
166157
167
158
168159
169160
170161
......
175166
176167
177168
178
169
179170
180171
181172
182173
183174
184
175
185176
186
187
188
177
178
189179
190180
191181
192
193
182
183
194184
195
196
197
185
186
198187
199
200
188
201189
202190
203191
204192
205193
206
194
207195
208
209
196
210197
211198
212199
......
214201
215202
216203
217
204
218205
219206
220
221
207
222208
223209
224210
......
227213
228214
229215
230
231
216
232217
233218
234219
235
220
236221
237
222
238223
239224
225
226
240227
241228
242229
......
244231
245232
246233
247
234
248235
249236
250237
251
238
252239
253240
241
254242
255243
256244
......
259247
260248
261249
262
250
263251
264252
265253
266254
267255
268
256
269257
270258
271259
272
260
273261
274262
275
263
276264
277265
278
266
279267
280268
281
269
282270
283271
284
272
285273
286274
287
275
288276
289277
290
278
291279
292280
293
281
294282
295283
296
284
297285
298286
299
287
300288
301289
302
290
303291
304292
305
293
306294
307295
308
296
309297
310298
311
299
312300
313301
314302
......
322310
323311
324312
325
313
326314
327315
328316
329
317
330318
331319
332
320
333321
334322
335
323
336324
337325
338
326
339327
340328
341
329
342330
343331
344
332
345333
346334
347
335
348336
349337
350
338
351339
352340
353
341
354342
355343
356
344
357345
358346
359
347
360348
361349
362350
......
366354
367355
368356
369
357
370358
371359
372360
373361
374
362
375363
376364
377
365
378366
379367
380368
381
369
382370
383
384
371
372
385373
386374
387
375
388376
389377
390
378
391379
392380
393
394
381
382
395383
396
384
397385
398386
399
387
400388
401389
402
390
403391
404392
405
393
406394
407
408
395
396
409397
410398
411399
412
400
413401
414402
415403
416404
417405
418
406
419407
420
408
421409
422410
423411
......
434422
435423
436424
437
425
438426
439427
440
428
441429
442430
443
431
444432
445433
446434
......
454442
455443
456444
457
445
458446
459447
460448
461
449
462450
463451
464
452
465453
466454
467455
......
474462
475463
476464
477
465
478466
479467
480
468
481469
482470
483
471
484472
485473
486
474
487475
488476
489
477
490478
491479
492480
......
564552
565553
566554
567
555
568556
569557
570558
571559
572
573
574
575
560
561
576562
577563
578564
579565
580
566
581567
582568
583569
......
596582
597583
598584
599
585
600586
601587
602588
static void setup_p35(pci_dt_t *dram_dev)
{
uint32_t dev0;
// Activate MMR I/O
dev0 = pci_config_read32(dram_dev->dev.addr, 0x48);
if (!(dev0 & 0x1))
{
if (!(dev0 & 0x1)) {
pci_config_write8(dram_dev->dev.addr, 0x48, (dev0 | 1));
}
}
// Nehalem supports Scrubbing
// First, locate the PCI bus where the MCH is located
for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++)
{
for(i = 0; i < (sizeof(possible_nhm_bus)/sizeof(possible_nhm_bus[0])); i++) {
vid = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), PCI_VENDOR_ID);
did = pci_config_read16(PCIADDR(possible_nhm_bus[i], 3, 4), PCI_DEVICE_ID);
vid &= 0xFFFF;
did &= 0xFF00;
if(vid == 0x8086 && did >= 0x2C00)
{
if(vid == 0x8086 && did >= 0x2C00) {
nhm_bus = possible_nhm_bus[i];
}
}
uint32_t dev0, mch_ratio, mch_cfg, mch_fsb;
long *ptr;
// Find Ratio
dev0 = pci_config_read32(dram_dev->dev.addr, 0x48);
dev0 &= 0xFFFFC000;
ptr = (long*)(dev0 + 0xC00);
mch_cfg = *ptr & 0xFFFF;
mch_ratio = 100000;
switch (mch_cfg & 7)
{
switch (mch_cfg & 7) {
case 0: mch_fsb = 1066; break;
case 1: mch_fsb = 533; break;
default:
default:
case 2: mch_fsb = 800; break;
case 3: mch_fsb = 667; break;
case 3: mch_fsb = 667; break;
case 4: mch_fsb = 1333; break;
case 6: mch_fsb = 1600; break;
case 6: mch_fsb = 1600; break;
}
DBG("mch_fsb %d\n", mch_fsb);
switch (mch_fsb)
{
switch (mch_fsb) {
case 533:
switch ((mch_cfg >> 4) & 7)
{
switch ((mch_cfg >> 4) & 7) {
case 1:mch_ratio = 200000; break;
case 2:mch_ratio = 250000; break;
case 3:mch_ratio = 300000; break;
}
break;
default:
case 800:
switch ((mch_cfg >> 4) & 7)
{
switch ((mch_cfg >> 4) & 7) {
case 0:mch_ratio = 100000; break;
case 1:mch_ratio = 125000; break;
case 2:mch_ratio = 166667; break; // 1.666666667
case 5:mch_ratio = 333333; break; // 3.333333333
}
break;
case 1066:
switch ((mch_cfg >> 4) & 7)
{
switch ((mch_cfg >> 4) & 7) {
case 1:mch_ratio = 100000; break;
case 2:mch_ratio = 125000; break;
case 3:mch_ratio = 150000; break;
case 5:mch_ratio = 250000; break;
}
break;
case 1333:
switch ((mch_cfg >> 4) & 7)
{
switch ((mch_cfg >> 4) & 7) {
case 2:mch_ratio = 100000; break;
case 3:mch_ratio = 120000; break;
case 4:mch_ratio = 160000; break;
case 5:mch_ratio = 200000; break;
}
break;
case 1600:
switch ((mch_cfg >> 4) & 7)
{
}
break;
}
DBG("mch_ratio %d\n", mch_ratio);
// Compute RAM Frequency
Platform.RAM.Frequency = (Platform.CPU.FSBFrequency * mch_ratio) / 100000;
DBG("ram_fsb %d\n", Platform.RAM.Frequency);
}
uint32_t dev0, mch_ratio, mch_cfg, mch_fsb;
long *ptr;
// Find Ratio
dev0 = pci_config_read32(dram_dev->dev.addr, 0x48);
dev0 &= 0xFFFFC000;
ptr = (long*)(dev0 + 0xC00);
mch_cfg = *ptr & 0xFFFF;
mch_ratio = 100000;
switch (mch_cfg & 7)
{
switch (mch_cfg & 7) {
case 1: mch_fsb = 533; break;
default:
case 2:mch_fsb = 800; break;
case 3:mch_fsb = 667; break;
case 6:mch_fsb = 1066; break;
case 3:mch_fsb = 667; break;
case 6:mch_fsb = 1066; break;
}
switch (mch_fsb)
{
switch (mch_fsb) {
case 533:
switch ((mch_cfg >> 4) & 7)
{
switch ((mch_cfg >> 4) & 7) {
case 1:mch_ratio = 125000; break;
case 2:mch_ratio = 150000; break;
case 3:mch_ratio = 200000; break;
}
break;
case 667:
switch ((mch_cfg >> 4)& 7)
{
switch ((mch_cfg >> 4)& 7) {
case 1:mch_ratio = 100000; break;
case 2:mch_ratio = 120000; break;
case 3:mch_ratio = 160000; break;
case 5:mch_ratio = 240000; break;
}
break;
default:
case 800:
switch ((mch_cfg >> 4) & 7)
{
switch ((mch_cfg >> 4) & 7) {
case 1:mch_ratio = 83333; break; // 0.833333333
case 2:mch_ratio = 100000; break;
case 3:mch_ratio = 133333; break; // 1.333333333
}
break;
case 1066:
switch ((mch_cfg >> 4)&7)
{
switch ((mch_cfg >> 4)&7) {
case 5:mch_ratio = 150000; break;
case 6:mch_ratio = 200000; break;
}
}
// Compute RAM Frequency
Platform.RAM.Frequency = (Platform.CPU.FSBFrequency * mch_ratio) / 100000;
DBG("ram_fsb %d\n", Platform.RAM.Frequency);
}
static void get_fsb_nhm(pci_dt_t *dram_dev)
{
uint32_t mch_ratio, mc_dimm_clk_ratio;
// Get the clock ratio
mc_dimm_clk_ratio = pci_config_read16(PCIADDR(nhm_bus, 3, 4), 0x54 );
mch_ratio = (mc_dimm_clk_ratio & 0x1F);
// Compute RAM Frequency
Platform.RAM.Frequency = Platform.CPU.FSBFrequency * mch_ratio / 2;
DBG("ram_fsb %d\n", Platform.RAM.Frequency);
}
/*
// Get i965 Memory Timings
static void get_timings_i965(pci_dt_t *dram_dev)
{
{
// Thanks for CDH optis
uint32_t dev0, c0ckectrl, c1ckectrl, offset;
uint32_t ODT_Control_Register, Precharge_Register, ACT_Register, Read_Register, Misc_Register;
long *ptr;
// Read MMR Base Address
dev0 = pci_config_read32(dram_dev->dev.addr, 0x48);
dev0 &= 0xFFFFC000;
ptr = (long*)(dev0 + 0x260);
c0ckectrl = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + 0x660);
c1ckectrl = *ptr & 0xFFFFFFFF;
// If DIMM 0 not populated, check DIMM 1
((c0ckectrl) >> 20 & 0xF) ? (offset = 0) : (offset = 0x400);
ptr = (long*)(dev0 + offset + 0x29C);
ODT_Control_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x250);
Precharge_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x252);
ACT_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x258);
Read_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x244);
Misc_Register = *ptr & 0xFFFFFFFF;
// 965 Series only support DDR2
Platform.RAM.Type = SMB_MEM_TYPE_DDR2;
// CAS Latency (tCAS)
Platform.RAM.CAS = ((ODT_Control_Register >> 17) & 7) + 3;
// RAS-To-CAS (tRCD)
Platform.RAM.TRC = (Read_Register >> 16) & 0xF;
// RAS Precharge (tRP)
Platform.RAM.TRP = (ACT_Register >> 13) & 0xF;
// RAS Active to precharge (tRAS)
Platform.RAM.RAS = (Precharge_Register >> 11) & 0x1F;
if ((c0ckectrl >> 20 & 0xF) && (c1ckectrl >> 20 & 0xF)) {
Platform.RAM.Channels = SMB_MEM_CHANNEL_DUAL;
} else {
// Thanks for CDH optis
uint32_t dev0, c0ckectrl, c1ckectrl, offset, ODT_Control_Register, Precharge_Register;
long *ptr;
// Read MMR Base Address
dev0 = pci_config_read32(dram_dev->dev.addr, 0x48);
dev0 &= 0xFFFFC000;
ptr = (long*)(dev0 + 0x1200);
c0ckectrl = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + 0x1300);
c1ckectrl = *ptr & 0xFFFFFFFF;
// If DIMM 0 not populated, check DIMM 1
((c0ckectrl) >> 20 & 0xF) ? (offset = 0) : (offset = 0x100);
ptr = (long*)(dev0 + offset + 0x121C);
ODT_Control_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x1214);
Precharge_Register = *ptr & 0xFFFFFFFF;
// Series only support DDR2
Platform.RAM.Type = SMB_MEM_TYPE_DDR2;
// CAS Latency (tCAS)
Platform.RAM.CAS = ((ODT_Control_Register >> 23) & 7) + 3;
// RAS-To-CAS (tRCD)
Platform.RAM.TRC = ((Precharge_Register >> 5) & 7) + 2;
// RAS Precharge (tRP)
Platform.RAM.TRP= (Precharge_Register & 7) + 2;
// RAS Active to precharge (tRAS)
Platform.RAM.RAS = (Precharge_Register >> 21) & 0x1F;
if ((c0ckectrl >> 20 & 0xF) && (c1ckectrl >> 20 & 0xF)) {
Platform.RAM.Channels = SMB_MEM_CHANNEL_DUAL;
} else {
// Get P35 Memory Timings
static void get_timings_p35(pci_dt_t *dram_dev)
{
{
// Thanks for CDH optis
unsigned long dev0, Memory_Check, c0ckectrl, c1ckectrl, offset;
unsigned long ODT_Control_Register, Precharge_Register, ACT_Register, Read_Register, Misc_Register;
long *ptr;
//Device_ID = pci_config_read16(dram_dev->dev.addr, 0x02);
//Device_ID &= 0xFFFF;
// Now, read MMR Base Address
dev0 = pci_config_read32(dram_dev->dev.addr, 0x48);
dev0 &= 0xFFFFC000;
ptr = (long*)(dev0 + 0x260);
c0ckectrl = *ptr & 0xFFFFFFFF;
c0ckectrl = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + 0x660);
c1ckectrl = *ptr & 0xFFFFFFFF;
// If DIMM 0 not populated, check DIMM 1
((c0ckectrl) >> 20 & 0xF) ? (offset = 0) : (offset = 0x400);
ptr = (long*)(dev0 + offset + 0x265);
ODT_Control_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x25D);
ptr = (long*)(dev0 + offset + 0x25D);
Precharge_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x252);
ACT_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x258);
Read_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x244);
Misc_Register = *ptr & 0xFFFFFFFF;
ptr = (long*)(dev0 + offset + 0x1E8);
Memory_Check = *ptr & 0xFFFFFFFF;
Memory_Check = *ptr & 0xFFFFFFFF;
// On P45, check 1A8
if(dram_dev->device_id > 0x2E00) {
ptr = (long*)(dev0 + offset + 0x1A8);
Memory_Check = *ptr & 0xFFFFFFFF;
Memory_Check = *ptr & 0xFFFFFFFF;
Memory_Check >>= 2;
Memory_Check &= 1;
Memory_Check = !Memory_Check;
} else {
ptr = (long*)(dev0 + offset + 0x1E8);
Memory_Check = *ptr & 0xFFFFFFFF;
Memory_Check = *ptr & 0xFFFFFFFF;
}
// Determine DDR-II or DDR-III
if (Memory_Check & 1) {
Platform.RAM.Type = SMB_MEM_TYPE_DDR2;
// RAS-To-CAS (tRCD)
Platform.RAM.TRC = (Read_Register >> 17) & 0xF;
// RAS Precharge (tRP)
Platform.RAM.TRP = (ACT_Register >> 13) & 0xF;
// RAS Active to precharge (tRAS)
Platform.RAM.RAS = Precharge_Register & 0x3F;
// Channel configuration
if (((c0ckectrl >> 20) & 0xF) && ((c1ckectrl >> 20) & 0xF)) {
Platform.RAM.Channels = SMB_MEM_CHANNEL_DUAL;
{
unsigned long mc_channel_bank_timing, mc_control, mc_channel_mrs_value;
int fvc_bn = 4;
// Find which channels are populated
mc_control = pci_config_read16(PCIADDR(nhm_bus, 3, 0), 0x48);
mc_control = (mc_control >> 8) & 0x7;
// DDR-III
Platform.RAM.Type = SMB_MEM_TYPE_DDR3;
// Get the first valid channel
if(mc_control & 1) {
fvc_bn = 4;
// Now, detect timings
mc_channel_bank_timing = pci_config_read32(PCIADDR(nhm_bus, fvc_bn, 0), 0x88);
mc_channel_mrs_value = pci_config_read32(PCIADDR(nhm_bus, fvc_bn, 0), 0x70);
// CAS Latency (tCAS)
Platform.RAM.CAS = ((mc_channel_mrs_value >> 4) & 0xF ) + 4;
// RAS-To-CAS (tRCD)
Platform.RAM.TRC = (mc_channel_bank_timing >> 9) & 0xF;
// RAS Active to precharge (tRAS)
Platform.RAM.RAS = (mc_channel_bank_timing >> 4) & 0x1F;
// RAS Precharge (tRP)
Platform.RAM.TRP = mc_channel_bank_timing & 0xF;
// Single , Dual or Triple Channels
if (mc_control == 1 || mc_control == 2 || mc_control == 4 ) {
Platform.RAM.Channels = SMB_MEM_CHANNEL_SINGLE;
static const char *memory_channel_types[] =
{
"Unknown", "Single", "Dual", "Triple"
};
};
void scan_dram_controller(pci_dt_t *dram_dev)
{
int i;
for(i = 1; i < sizeof(dram_controllers) / sizeof(dram_controllers[0]); i++)
{
if ((dram_controllers[i].vendor == dram_dev->vendor_id) && (dram_controllers[i].device == dram_dev->device_id))
{
for(i = 1; i < sizeof(dram_controllers) / sizeof(dram_controllers[0]); i++) {
if ((dram_controllers[i].vendor == dram_dev->vendor_id) && (dram_controllers[i].device == dram_dev->device_id)) {
verbose("%s%s DRAM Controller [%4x:%4x] at %02x:%02x.%x\n",
(dram_dev->vendor_id == 0x8086) ? "Intel Corporation " : "" ,
dram_controllers[i].name, dram_dev->vendor_id, dram_dev->device_id,
dram_dev->dev.bits.bus, dram_dev->dev.bits.dev, dram_dev->dev.bits.func);
if (dram_controllers[i].initialise != NULL) {
dram_controllers[i].initialise(dram_dev);
}
memory_channel_types[Platform.RAM.Channels]
,Platform.RAM.CAS, Platform.RAM.TRC, Platform.RAM.TRP, Platform.RAM.RAS
,Platform.RAM.CAS, Platform.RAM.TRC, Platform.RAM.TRP, Platform.RAM.RAS);
//getchar();
//getchar();
}
}
}
branches/ErmaC/Enoch/i386/libsaio/nvidia.c
7777
7878
7979
80
8081
8182
8283
......
14581459
14591460
14601461
1461
1462
1462
14631463
14641464
1465
1466
1465
14671466
14681467
14691468
14701469
14711470
1472
1473
1474
1471
14751472
14761473
14771474
14781475
1479
1480
1476
14811477
14821478
14831479
1484
1485
1486
1480
14871481
14881482
14891483
14901484
14911485
1492
1493
1486
14941487
14951488
14961489
1497
1498
1499
1490
15001491
15011492
15021493
......
15071498
15081499
15091500
1510
1511
1501
15121502
15131503
15141504
15151505
15161506
1517
1518
1507
15191508
15201509
15211510
15221511
1523
1524
1512
15251513
15261514
1527
1528
1515
15291516
15301517
1531
1532
1518
15331519
15341520
15351521
......
15421528
15431529
15441530
1545
1546
1547
1548
1531
1532
15491533
15501534
15511535
......
15541538
15551539
15561540
1557
1558
1559
1560
1561
1562
1541
1542
1543
15631544
15641545
15651546
15661547
15671548
15681549
1569
1570
1571
1550
15721551
15731552
1574
1575
1576
1577
1578
1579
1553
1554
1555
15801556
15811557
15821558
15831559
15841560
1585
1586
1587
1588
1561
1562
15891563
15901564
15911565
15921566
15931567
1594
1595
1568
15961569
15971570
15981571
15991572
1600
1601
1573
16021574
16031575
16041576
......
16101582
16111583
16121584
1613
1614
1585
16151586
16161587
16171588
16181589
1619
1620
1590
16211591
16221592
16231593
......
16371607
16381608
16391609
1640
1641
1642
1643
1610
1611
16441612
1645
1646
1613
16471614
16481615
16491616
16501617
16511618
16521619
1653
1654
1620
16551621
16561622
16571623
......
16611627
16621628
16631629
1664
1665
1666
1667
1630
1631
16681632
1669
1670
1671
1633
16721634
16731635
16741636
......
16781640
16791641
16801642
1681
1643
16821644
16831645
16841646
1685
1686
1687
1688
1647
1648
16891649
16901650
16911651
16921652
1653
1654
1655
1656
1657
16931658
1694
1695
1696
1697
1698
1699
1659
1660
1661
17001662
1663
17011664
17021665
17031666
17041667
17051668
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1669
1670
1671
1672
1673
1674
17171675
1718
1676
17191677
17201678
17211679
......
17301688
17311689
17321690
1733
1734
1691
17351692
17361693
17371694
17381695
17391696
1740
1741
1697
17421698
17431699
17441700
......
17661722
17671723
17681724
1769
1770
1725
17711726
17721727
1773
1774
1775
1728
17761729
17771730
17781731
17791732
17801733
17811734
1782
1735
17831736
17841737
17851738
......
18541807
18551808
18561809
1857
1858
1859
1860
1810
1811
18611812
18621813
1863
1864
1865
1814
18661815
18671816
18681817
1869
1870
1871
1818
18721819
18731820
18741821
......
19171864
19181865
19191866
1920
1867
19211868
19221869
19231870
19241871
19251872
19261873
1927
1928
1874
19291875
19301876
1931
1932
1933
1877
19341878
19351879
19361880
19371881
1938
1939
1940
1882
19411883
19421884
19431885
......
19481890
19491891
19501892
1951
1952
1893
19531894
19541895
1955
1956
1957
1896
19581897
19591898
19601899
......
19621901
19631902
19641903
1965
1966
1904
19671905
19681906
1969
1970
1971
1907
19721908
19731909
19741910
19751911
1976
1977
1912
19781913
19791914
1980
1981
1982
1915
19831916
19841917
19851918
19861919
19871920
19881921
1989
1990
1922
19911923
1924
19921925
19931926
19941927
19951928
19961929
19971930
1998
1999
2000
2001
1931
1932
20021933
20031934
20041935
20051936
20061937
20071938
2008
2009
2010
1939
20111940
20121941
20131942
......
20251954
20261955
20271956
2028
2029
1957
20301958
20311959
20321960
......
20451973
20461974
20471975
2048
2049
2050
2051
1976
1977
20521978
20531979
2054
2055
1980
20561981
20571982
2058
2059
1983
20601984
2061
2062
1985
20631986
20641987
20651988
2066
2067
1989
20681990
20691991
20701992
......
20782000
20792001
20802002
2081
2003
20822004
2083
2084
2005
20852006
20862007
2087
2088
2008
20892009
20902010
20912011
20922012
20932013
2094
2095
2014
20962015
20972016
2098
2099
2017
21002018
21012019
21022020
......
21052023
21062024
21072025
2108
2109
2026
21102027
21112028
2112
2113
2029
21142030
21152031
21162032
......
21402056
21412057
21422058
2143
2144
2059
21452060
21462061
21472062
......
21532068
21542069
21552070
2156
2157
2071
21582072
21592073
21602074
......
21632077
21642078
21652079
2166
2167
2080
21682081
21692082
21702083
......
21732086
21742087
21752088
2176
2177
2089
21782090
21792091
21802092
#define WRITE_LE_SHORT(data) (((data) << 8 & 0xff00) | ((data) >> 8 & 0x00ff ))
#define WRITE_LE_INT(data) (WRITE_LE_SHORT(data) << 16 | WRITE_LE_SHORT(data >> 16))
char generic_name[128];
extern uint32_t devices_number;
const char *nvidia_compatible_0[] ={ "@0,compatible","NVDA,NVMac" };
uint8_t numentries = 0;
uint8_t recordlength = 0;
if (dcbtable_version >= 0x20)
{
if (dcbtable_version >= 0x20) {
uint32_t sig;
if (dcbtable_version >= 0x30)
{
if (dcbtable_version >= 0x30) {
headerlength = dcbtable[1];
numentries = dcbtable[2];
recordlength = dcbtable[3];
sig = READ_LE_INT(dcbtable, 6);
}
else
{
} else {
sig = READ_LE_INT(dcbtable, 4);
headerlength = 8;
}
if (sig != 0x4edcbdcb)
{
if (sig != 0x4edcbdcb) {
printf("Bad display config block signature (0x%8x)\n", sig); //Azi: issue #48
return PATCH_ROM_FAILED;
}
}
else if (dcbtable_version >= 0x14) /* some NV15/16, and NV11+ */
{
} else if (dcbtable_version >= 0x14) { /* some NV15/16, and NV11+ */
char sig[8] = { 0 };
strncpy(sig, (char *)&dcbtable[-7], 7);
recordlength = 10;
if (strcmp(sig, "DEV_REC"))
{
if (strcmp(sig, "DEV_REC")) {
printf("Bad Display Configuration Block signature (%s)\n", sig);
return PATCH_ROM_FAILED;
}
}
else
{
} else {
printf("ERROR: dcbtable_version is 0x%X\n", dcbtable_version);
return PATCH_ROM_FAILED;
}
uint8_t num_outputs = 0, i = 0;
struct dcbentry
{
struct dcbentry {
uint8_t type;
uint8_t index;
uint8_t *heads;
} entries[numentries];
for (i = 0; i < numentries; i++)
{
for (i = 0; i < numentries; i++) {
uint32_t connection;
connection = READ_LE_INT(dcbtable,headerlength + recordlength * i);
/* Should we allow discontinuous DCBs? Certainly DCB I2C tables can be discontinuous */
if ((connection & 0x0000000f) == 0x0000000f) /* end of records */
{
if ((connection & 0x0000000f) == 0x0000000f) { /* end of records */
continue;
}
if (connection == 0x00000000) /* seen on an NV11 with DCB v1.5 */
{
if (connection == 0x00000000) { /* seen on an NV11 with DCB v1.5 */
continue;
}
if ((connection & 0xf) == 0x6) /* we skip type 6 as it doesnt appear on macbook nvcaps */
{
if ((connection & 0xf) == 0x6) { /* we skip type 6 as it doesnt appear on macbook nvcaps */
continue;
}
int has_lvds = false;
uint8_t channel1 = 0, channel2 = 0;
for (i = 0; i < num_outputs; i++)
{
if (entries[i].type == 3)
{
for (i = 0; i < num_outputs; i++) {
if (entries[i].type == 3) {
has_lvds = true;
//printf("found LVDS\n");
channel1 |= ( 0x1 << entries[i].index);
}
// if we have a LVDS output, we group the rest to the second channel
if (has_lvds)
{
for (i = 0; i < num_outputs; i++)
{
if (entries[i].type == TYPE_GROUPED)
{
if (has_lvds) {
for (i = 0; i < num_outputs; i++) {
if (entries[i].type == TYPE_GROUPED) {
continue;
}
channel2 |= ( 0x1 << entries[i].index);
entries[i].type = TYPE_GROUPED;
}
}
else
{
} else {
int x;
// we loop twice as we need to generate two channels
for (x = 0; x <= 1; x++)
{
for (i=0; i<num_outputs; i++)
{
if (entries[i].type == TYPE_GROUPED)
{
for (x = 0; x <= 1; x++) {
for (i=0; i<num_outputs; i++) {
if (entries[i].type == TYPE_GROUPED) {
continue;
}
// if type is TMDS, the prior output is ANALOG
// we always group ANALOG and TMDS
// if there is a TV output after TMDS, we group it to that channel as well
if (i && entries[i].type == 0x2)
{
switch (x)
{
if (i && entries[i].type == 0x2) {
switch (x) {
case 0:
//printf("group channel 1\n");
channel1 |= ( 0x1 << entries[i].index);
entries[i].type = TYPE_GROUPED;
if (entries[i-1].type == 0x0)
{
if (entries[i-1].type == 0x0) {
channel1 |= ( 0x1 << entries[i-1].index);
entries[i-1].type = TYPE_GROUPED;
}
// group TV as well if there is one
if ( ((i+1) < num_outputs) && (entries[i+1].type == 0x1) )
{
if ( ((i+1) < num_outputs) && (entries[i+1].type == 0x1) ) {
//printf("group tv1\n");
channel1 |= ( 0x1 << entries[i+1].index);
entries[i+1].type = TYPE_GROUPED;
channel2 |= ( 0x1 << entries[i].index);
entries[i].type = TYPE_GROUPED;
if (entries[i - 1].type == 0x0)
{
if (entries[i - 1].type == 0x0) {
channel2 |= ( 0x1 << entries[i-1].index);
entries[i-1].type = TYPE_GROUPED;
}
// group TV as well if there is one
if ( ((i+1) < num_outputs) && (entries[i+1].type == 0x1) )
{
if ( ((i+1) < num_outputs) && (entries[i+1].type == 0x1) ) {
//printf("group tv2\n");
channel2 |= ( 0x1 << entries[i+1].index);
entries[i+1].type = TYPE_GROUPED;
uint8_t *togroup;// = (channel1 ? (channel2 ? NULL : &channel2) : &channel1);
togroup = &channel2;
for (i = 0; i < num_outputs; i++)
{
if (entries[i].type != TYPE_GROUPED)
{
for (i = 0; i < num_outputs; i++) {
if (entries[i].type != TYPE_GROUPED) {
//printf("%d not grouped\n", i);
if (togroup)
{
if (togroup) {
*togroup |= ( 0x1 << entries[i].index);
}
entries[i].type = TYPE_GROUPED;
}
}
if (channel1 > channel2)
{
if (channel1 > channel2) {
uint8_t buff = channel1;
channel1 = channel2;
channel2 = buff;
default_NVCAP[8] = channel2;
// patching HEADS
for (i = 0; i < num_outputs; i++)
{
if (channel1 & (1 << i))
{
for (i = 0; i < num_outputs; i++) {
if (channel1 & (1 << i)) {
*entries[i].heads = 1;
}
else if(channel2 & (1 << i))
{
} else if(channel2 & (1 << i)) {
*entries[i].heads = 2;
}
}
static char *get_nvidia_model(uint32_t device_id, uint32_t subsys_id)
{
int i, j;
static char name_model[128];
bool showGeneric = false;
// First check in the plist, (for e.g this can override any hardcoded devices)
cardList_t * nvcard = FindCardWithIds(device_id, subsys_id);
if (nvcard)
{
if (nvcard->model)
{
if (nvcard) {
if (nvcard->model) {
return nvcard->model;
}
}
//ErmaC added selector for Chameleon "old" style in System Profiler
if ((getBoolForKey(kNvidiaGeneric, &showGeneric, &bootInfo->chameleonConfig) && showGeneric) == true) {
DBG("- TEST - NOT YET IMPLEMENTED.\n");
}
// Then check the exceptions table
if (subsys_id)
{
for (i = 0; i < (sizeof(nvidia_card_exceptions) / sizeof(nvidia_card_exceptions[0])); i++)
{
if ((nvidia_card_exceptions[i].device == device_id) && (nvidia_card_exceptions[i].subdev == subsys_id))
{
if (subsys_id) {
for (i = 0; i < (sizeof(nvidia_card_exceptions) / sizeof(nvidia_card_exceptions[0])); i++) {
if ((nvidia_card_exceptions[i].device == device_id) && (nvidia_card_exceptions[i].subdev == subsys_id)){
return nvidia_card_exceptions[i].name;
break;
}
}
}
// At last try the generic names
for (i = 1; i < (sizeof(nvidia_card_generic) / sizeof(nvidia_card_generic[0])); i++)
{
if (nvidia_card_generic[i].device == device_id)
{
if (subsys_id)
{
for (j = 0; j < (sizeof(nvidia_card_vendors) / sizeof(nvidia_card_vendors[0])); j++)
{
if (nvidia_card_vendors[j].device == (subsys_id & 0xffff0000))
{
snprintf(name_model, sizeof(name_model), "%s %s",
for (i = 1; i < (sizeof(nvidia_card_generic) / sizeof(nvidia_card_generic[0])); i++) {
if (nvidia_card_generic[i].device == device_id) {
if (subsys_id) {
for (j = 0; j < (sizeof(nvidia_card_vendors) / sizeof(nvidia_card_vendors[0])); j++) {
if (nvidia_card_vendors[j].device == (subsys_id & 0xffff0000)) {
snprintf(generic_name, 128, "%s %s", // sizeof(generic_name), "%s %s",
nvidia_card_vendors[j].name, nvidia_card_generic[i].name);
return name_model;
return &generic_name[0];
}
}
}
int fd;
int size;
if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0)
{
if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) {
return 0;
}
size = file_size(fd);
if (size)
{
if (size) {
*buf = malloc(size);
size = read(fd, (char *)buf, size);
}
return 0;
if (!DP_ADD_TEMP_VAL(device, nvidia_name_1))
return 0;
if (devices_number == 1)
{
if (devices_number == 1) {
if (!DP_ADD_TEMP_VAL(device, nvidia_device_type_parent))
return 0;
}
else
{
} else {
if (!DP_ADD_TEMP_VAL(device, nvidia_device_type_child))
return 0;
}
// Rek : Dont use sprintf return, it does not WORK !! our custom sprintf() always return 0!
// len = sprintf(tmp, "Slot-%x", devices_number);
sprintf(tmp, "Slot-%x",devices_number);
snprintf(tmp, sizeof(tmp), "Slot-%x",devices_number);
devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp));
devices_number++;
break;
}
if (!vram_size)
{ // Finally, if vram_size still not set do the calculation with our own method
if (nvCardType < NV_ARCH_50)
{
if (!vram_size){ // Finally, if vram_size still not set do the calculation with our own method
if (nvCardType < NV_ARCH_50) {
vram_size = REG32(NV04_PFB_FIFO_DATA);
vram_size &= NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_MASK;
}
else if (nvCardType < NV_ARCH_C0)
{
} else if (nvCardType < NV_ARCH_C0) {
vram_size = REG32(NV04_PFB_FIFO_DATA);
vram_size |= (vram_size & 0xff) << 32;
vram_size &= 0xffffffff00ll;
}
else // >= NV_ARCH_C0
{
} else { // >= NV_ARCH_C0
vram_size = REG32(NVC0_MEM_CTRLR_RAM_AMOUNT) << 20;
vram_size *= REG32(NVC0_MEM_CTRLR_COUNT);
}
// Amount of VRAM in kilobytes
videoRam = mem_detect(regs, nvCardType, nvda_dev,((nvda_dev->vendor_id << 16) | nvda_dev->device_id),((nvda_dev->subsys_id.subsys.vendor_id << 16) | nvda_dev->subsys_id.subsys.device_id) );
sprintf(nvFilename, "/Extra/%04x_%04x.rom", (uint16_t)nvda_dev->vendor_id, (uint16_t)nvda_dev->device_id);
snprintf(nvFilename, sizeof(nvFilename), "/Extra/%04x_%04x.rom", (uint16_t)nvda_dev->vendor_id, (uint16_t)nvda_dev->device_id);
if (getBoolForKey(kUseNvidiaROM, &doit, &bootInfo->chameleonConfig) && doit)
{
verbose("Looking for nvidia video bios file %s\n", nvFilename);
nvBiosOveride = load_nvidia_bios_file(nvFilename, &rom);
if (nvBiosOveride > 0)
{
if (nvBiosOveride > 0) {
verbose("Using nVidia Video BIOS File %s (%d Bytes)\n", nvFilename, nvBiosOveride);
DBG("%s Signature 0x%02x%02x %d bytes\n", nvFilename, rom[0], rom[1], nvBiosOveride);
}
else
{
} else {
printf("ERROR: unable to open nVidia Video BIOS File %s\n", nvFilename);
free(rom);
return false;
}
}
else
{
} else {
rom = malloc(NVIDIA_ROM_SIZE);
// Otherwise read bios from card
nvBiosOveride = 0;
nvRom = (uint8_t*)&regs[NV_PROM_OFFSET];
// Valid Signature ?
if (checkNvRomSig(nvRom))
{
if (checkNvRomSig(nvRom)) {
bcopy((uint8_t *)nvRom, rom, NVIDIA_ROM_SIZE);
DBG("PROM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]);
}
else
{
} else {
// disable PROM access
(REG32(NV_PBUS_PCI_NV_20)) = NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED;
//PRAM next
nvRom = (uint8_t*)&regs[NV_PRAMIN_OFFSET];
if(checkNvRomSig(nvRom))
{
if(checkNvRomSig(nvRom)) {
bcopy((uint32_t *)nvRom, rom, NVIDIA_ROM_SIZE);
DBG("PRAM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]);
}
else
{
} else {
// 0xC0000 last
bcopy((char *)0xc0000, rom, NVIDIA_ROM_SIZE);
// Valid Signature ?
if (!checkNvRomSig(rom))
{
if (!checkNvRomSig(rom)) {
printf("ERROR: Unable to locate nVidia Video BIOS\n");
return false;
}
else
{
} else {
DBG("ROM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]);
}
}//end PRAM check
}//end PROM check
}//end load rom from bios
if ((nvPatch = patch_nvidia_rom(rom)) == PATCH_ROM_FAILED)
{
if ((nvPatch = patch_nvidia_rom(rom)) == PATCH_ROM_FAILED) {
printf("ERROR: nVidia ROM Patching Failed!\n");
free(rom);
//return false;
}
rom_pci_header = (option_rom_pci_header_t*)(rom + *(uint16_t *)&rom[24]);
// check for 'PCIR' sig
if (rom_pci_header->signature == 0x50434952)
{
if (rom_pci_header->device_id != nvda_dev->device_id)
{
if (rom_pci_header->signature == 0x50434952) {
if (rom_pci_header->device_id != nvda_dev->device_id) {
// Get Model from the OpROM
model = get_nvidia_model(((rom_pci_header->vendor_id << 16) | rom_pci_header->device_id), 0);
// Get VRAM again
videoRam = mem_detect(regs, nvCardType, nvda_dev, ((rom_pci_header->vendor_id << 16) | rom_pci_header->device_id), 0);
}
else
{
} else {
printf("nVidia incorrect PCI ROM signature: 0x%x\n", rom_pci_header->signature);
}
}
/* FIXME: for primary graphics card only */
boot_display = 1;
if (devices_number == 1)
{
if (devices_number == 1) {
devprop_add_value(device, "@0,AAPL,boot-display", (uint8_t*)&boot_display, 4);
}
int crlf_count = 0;
// only search the first 384 bytes
for (i = 0; i < 0x180; i++)
{
if (rom[i] == 0x0D && rom[i+1] == 0x0A)
{
for (i = 0; i < 0x180; i++) {
if (rom[i] == 0x0D && rom[i+1] == 0x0A) {
crlf_count++;