Chameleon

Chameleon Commit Details

Date:2015-04-17 15:19:28 (2 years 9 months ago)
Author:ErmaC
Commit:2656
Parents: 2655
Message:Move get_acpi_cpu_names to proper location.
Changes:
M/trunk/i386/libsaio/acpi.h
M/trunk/i386/libsaio/acpi_patcher.c
M/trunk/i386/libsaio/state_generator.c
M/trunk/i386/libsaio/state_generator.h

File differences

trunk/i386/libsaio/acpi_patcher.c
3333
3434
3535
36
36
3737
3838
3939
......
5353
5454
5555
56
56
5757
5858
5959
......
135135
136136
137137
138
138
139139
140140
141141
142142
143
143
144144
145145
146146
......
151151
152152
153153
154
155
154
155
156156
157157
158158
159159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218160
219161
220162
......
241183
242184
243185
244
186
245187
246188
247189
......
251193
252194
253195
254
196
255197
256198
257199
258200
259
201
260202
261203
262204
......
302244
303245
304246
305
247
306248
307249
308250
......
314256
315257
316258
317
259
318260
319261
320262
......
325267
326268
327269
328
270
329271
330272
331273
332274
333275
334
276
335277
336
278
337279
338280
339281
......
502444
503445
504446
505
447
506448
507449
508450
......
510452
511453
512454
513
455
514456
515457
516458
......
535477
536478
537479
538
480
539481
540482
541483
......
560502
561503
562504
563
505
564506
565507
566508
......
568510
569511
570512
571
513
572514
573515
574516
......
594536
595537
596538
597
539
598540
599541
600542
......
629571
630572
631573
632
574
633575
634576
635
577
636578
637579
638580
639581
640582
641
583
642584
643585
644586
......
660602
661603
662604
663
605
664606
665607
666608
......
682624
683625
684626
685
627
686628
687629
688630
689631
690632
691633
692
634
693635
694636
695637
......
697639
698640
699641
700
642
701643
702644
703645
......
725667
726668
727669
728
670
729671
730672
731673
......
784726
785727
786728
787
729
788730
789731
790732
int i;
for (i = 0; i < 4; i++)
{
if ((table[i] &~0x20) != (sgn[i] &~0x20))
if ((table[i] & ~0x20) != (sgn[i] & ~0x20))
{
return false;
}
if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)
{
uint8_t csum = checksum8(acpi_addr, 20);
if(csum == 0)
if (csum == 0)
{
// Only return the table if it is a true version 1.0 table (Revision 0)
if(((struct acpi_2_rsdp*)acpi_addr)->Revision == 0)
if (fd >= 0)
{
void *tableAddr = (void*)AllocateKernelMemory(file_size(fd));
void *tableAddr = (void *)AllocateKernelMemory(file_size(fd));
if (tableAddr)
{
if (read(fd, tableAddr, file_size(fd)) != file_size(fd))
{
DBG("Couldn't read table %s\n",dirspec);
DBG("Couldn't read table %s\n", dirspec);
free(tableAddr);
close(fd);
return NULL;
return tableAddr;
}
close(fd);
DBG("Couldn't allocate memory for table \n", dirspec);
}
DBG("Couldn't allocate memory for table: %s.\n", dirspec);
}
//printf("Couldn't find table %s\n", filename);
return NULL;
}
uint8_t acpi_cpu_count= 0;
uint32_t acpi_cpu_p_blk= 0;
char *acpi_cpu_name[32];
void get_acpi_cpu_names(unsigned char *dsdt, uint32_t length)
{
uint32_t i;
DBG("ACPIpatcher: start finding cpu names. Length %d\n", length);
for (i=0; i<length-7; i++)
{
if (dsdt[i] == 0x5B && dsdt[i+1] == 0x83) // ProcessorOP
{
DBG("ACPIpatcher: DSDT[%X%X]\n", dsdt[i], dsdt[i+1]);
uint32_t offset = i + 3 + (dsdt[i+2] >> 6);
bool add_name = true;
uint8_t j;
for (j=0; j<4; j++)
{
char c = dsdt[offset+j];
if (!aml_isvalidchar(c))
{
add_name = false;
DBG("ACPIpatcher: invalid character found in ProcessorOP '0x%X'!\n", c);
break;
}
}
if (add_name)
{
acpi_cpu_name[acpi_cpu_count] = malloc(4);
memcpy(acpi_cpu_name[acpi_cpu_count], dsdt+offset, 4);
i = offset + 5;
if (acpi_cpu_count == 0)
{
acpi_cpu_p_blk = dsdt[i] | (dsdt[i+1] << 8);
}
DBG("ACPIpatcher: found ACPI CPU [%c%c%c%c]\n", acpi_cpu_name[acpi_cpu_count][0], acpi_cpu_name[acpi_cpu_count][1], acpi_cpu_name[acpi_cpu_count][2], acpi_cpu_name[acpi_cpu_count][3]);
if (++acpi_cpu_count == 32)
{
return;
}
}
}
}
DBG("ACPIpatcher: finished finding cpu names. Found: %d.\n", acpi_cpu_count);
}
struct acpi_2_fadt *patch_fadt(struct acpi_2_fadt *fadt, struct acpi_2_dsdt *new_dsdt)
{
extern void setupSystemType();
}
else
{
DBG("Not an Intel platform: Restart Fix not applied !!!\n");
DBG("\tNot an Intel platform, FACP Restart Fix will not be applied!\n");
fix_restart = false;
}
}
// Allocate new fadt table
if (fadt->Length < 0x84 && fadt_rev2_needed)
if ((fadt->Length < 0x84) && fadt_rev2_needed)
{
fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(0x84);
memcpy(fadt_mod, fadt, fadt->Length);
fadt_mod->Length = 0x84;
fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)
fadt_mod->Revision = 0x02; // FACP rev 2 (ACPI 1.0B MS extensions)
}
else
{
// because we need to take care of FACP original content, if it is correct.
setupSystemType();
// Patch FADT to fix restart
// Patch FACP to fix restart
if (fix_restart)
{
if (fix_restart_ps2)
fadt_mod->Reset_AccessWidth= 0x01; // Byte access
fadt_mod->Reset_Address= 0x64; // Address of the register
fadt_mod->Reset_Value= 0xfe; // Value to write to reset the system
DBG("FADT: PS2 Restart Fix applied!\n");
DBG("\tFACP PS2 Restart Fix applied!\n");
}
else
{
fadt_mod->Reset_AccessWidth= 0x01; // Byte access
fadt_mod->Reset_Address= 0x0cf9; // Address of the register
fadt_mod->Reset_Value= 0x06; // Value to write to reset the system
DBG("FADT: ACPI Restart Fix applied!\n");
DBG("\tFACP Restart Fix applied!\n");
}
}
// Bungo: Save Hardware Signature (machine-signature)
if ((fadt_mod->FIRMWARE_CTRL > 0) && (fadt_mod->FIRMWARE_CTRL < 0xFFFFFFFF) && (((struct acpi_2_facs *)fadt_mod->FIRMWARE_CTRL)->Length >= 64))
if ((fadt_mod->FACS > 0) && (fadt_mod->FACS < 0xFFFFFFFF) && (((struct acpi_2_facs *)fadt_mod->FACS)->Length >= 64))
{
Platform.HWSignature = ((struct acpi_2_facs *)fadt_mod->FIRMWARE_CTRL)->HWSignature;
Platform.HWSignature = ((struct acpi_2_facs *)fadt_mod->FACS)->HWSignature;
DBG("\tHardware Signature=0x%08X: using.\n", Platform.HWSignature);
}
else
{
uint32_t *rsdt_entries;
int rsdt_entries_num;
int dropoffset=0, i;
int dropoffset = 0, i;
// mozo: using malloc cos I didn't found how to free already allocated kernel memory
rsdt_mod = (struct acpi_2_rsdt *)malloc(rsdt->Length);
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)
DBG("Custom DSDT table was found\n");
if(new_dsdt)
{
rsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;
rsdt_entries[i-dropoffset] = (uint32_t)new_dsdt;
}
continue;
// Generate _CST SSDT
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
{
DBG("C-States generated\n");
DBG("\tC-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)))
{
DBG("P-States generated\n");
DBG("\tP-States generated.\n");
generate_pstates = false; // Generate SSDT only once!
ssdt_count++;
}
for (j=0; j<ssdt_count; j++)
{
rsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
rsdt_entries[i-dropoffset+j] = (uint32_t)new_ssdt[j];
}
DBG("RSDT: Added %d SSDT table(s)\n", ssdt_count);
{
uint64_t *xsdt_entries;
int xsdt_entries_num, i;
int dropoffset=0;
int dropoffset = 0;
// mozo: using malloc cos I didn't found how to free already allocated kernel memory
xsdt_mod=(struct acpi_2_xsdt*)malloc(xsdt->Length);
xsdt_mod = (struct acpi_2_xsdt *)malloc(xsdt->Length);
memcpy(xsdt_mod, xsdt, xsdt->Length);
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 (new_dsdt)
{
xsdt_entries[i-dropoffset] = (uint32_t)new_dsdt;
DBG("custom table added\n");
DBG("custom table added.\n");
}
DBG("TABLE %c%c%c%c@%x \n", table[0],table[1],table[2],table[3],xsdt_entries[i]);
}
fadt_mod = patch_fadt(fadt, new_dsdt);
xsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;
xsdt_entries[i - dropoffset] = (uint32_t)fadt_mod;
// DBG("TABLE %c%c%c%c@%x \n", 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)))
{
DBG("C-States generated\n");
DBG("\tC-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)))
{
DBG("P-States generated\n");
DBG("\tP-States generated.\n");
generate_pstates = false; // Generate SSDT only once!
ssdt_count++;
}
for (j=0; j<ssdt_count; j++)
{
xsdt_entries[i-dropoffset+j]=(uint32_t)new_ssdt[j];
xsdt_entries[i - dropoffset + j] = (uint32_t)new_ssdt[j];
}
verbose("Added %d SSDT table(s) into XSDT\n", ssdt_count);
acpi10_p = (uint64_t)(uint32_t)rsdp_mod;
addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI");
}
DBG("ACPI version %d patching finished\n\n", version+1);
DBG("ACPI version %d patching finished\n\n", version + 1);
}
#if DEBUG_ACPI
printf("Press a key to continue... (DEBUG_ACPI)\n");
trunk/i386/libsaio/acpi.h
33
44
55
6
7
8
69
710
811
......
1720
1821
1922
23
24
25
26
27
28
29
30
2031
2132
2233
......
3546
3647
3748
49
50
51
52
53
54
55
56
57
58
59
60
61
3862
3963
4064
......
77101
78102
79103
104
105
106
107
108
109
110
111
112
113
80114
81115
82116
......
103137
104138
105139
106
140
107141
108142
109143
......
152186
153187
154188
155
189
156190
157191
158192
#define ACPI_RANGE_START (0x0E0000)
#define ACPI_RANGE_END (0x0FFFFF)
#define EBDA_RANGE_MIN (0x080000)
#define EBDA_RANGE_END (0x09FFFF)
#define BDA_EBDA_START (0x00040E)
#define UINT64_LE_FROM_CHARS(a,b,c,d,e,f,g,h) \
( ((uint64_t)h << 56) \
#define ACPI_SIGNATURE_UINT64_LE UINT64_LE_FROM_CHARS('R','S','D',' ','P','T','R',' ')
#define swapUint16(x) ((((uint16_t)x & 0xFF00) >> 8) | \
(((uint16_t)x & 0x00FF) << 8))
#define swapUint32(x) ((((uint32_t)x & 0xFF000000) >> 24) | \
(((uint32_t)x & 0x00FF0000) >> 16) | \
(((uint32_t)x & 0x0000FF00) >> 8) | \
(((uint32_t)x & 0x000000FF) << 24))
/* Per ACPI 3.0a spec */
// TODO Migrate
charReserved[3];
} __attribute__((packed));
struct acpi_2_header
{
charSignature[4];
uint32_tLength;
uint8_tRevision;
uint8_tChecksum;
charOEMID[6];
charOEMTableId[8];
uint32_tOEMRevision;
uint32_tCreatorId;
uint32_tCreatorRevision;
} __attribute__((packed));
// TODO Migrate
struct acpi_2_rsdt
{
uint32_tCreatorRevision;
} __attribute__((packed));
struct ssdt_pmref
{
char oemTabID[9];
char byte1;
uint32_t addr;
char byte2;
uint32_t length;
char byte3;
} __attribute__((packed));
// TODO Migrate
struct acpi_2_dsdt
{
uint32_tOEMRevision;
uint32_tCreatorId;
uint32_tCreatorRevision;
uint32_tFIRMWARE_CTRL;
uint32_tFACS;
uint32_tDSDT;
uint8_tModel;// JrCs
uint8_tPM_Profile;// JrCs
uint8_t Reset_Value;
uint8_t Reserved[3];
uint64_t X_FIRMWARE_CTRL;
uint64_t X_FACS;
uint64_t X_DSDT;
/* End Asere */
/*We absolutely don't care about theese fields*/
trunk/i386/libsaio/state_generator.c
3333
3434
3535
36
37
38
36
37
38
3939
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
4094
4195
4296
#define DBG(x...) msglog(x)
#endif
extern uint8_t acpi_cpu_count;
extern uint32_t acpi_cpu_p_blk;
extern char* acpi_cpu_name[32];
uint8_t acpi_cpu_count= 0;
uint32_t acpi_cpu_p_blk= 0;
char *acpi_cpu_name[32];
void get_acpi_cpu_names(unsigned char *dsdt, uint32_t length)
{
uint32_t i;
DBG("ACPIpatcher: start finding cpu names. Length %d\n", length);
for (i=0; i<length-7; i++)
{
if (dsdt[i] == 0x5B && dsdt[i+1] == 0x83) // ProcessorOP
{
DBG("ACPIpatcher: DSDT[%X%X]\n", dsdt[i], dsdt[i+1]);
uint32_t offset = i + 3 + (dsdt[i+2] >> 6);
bool add_name = true;
uint8_t j;
for (j=0; j<4; j++)
{
char c = dsdt[offset+j];
if (!aml_isvalidchar(c))
{
add_name = false;
DBG("ACPIpatcher: invalid character found in ProcessorOP '0x%X'!\n", c);
break;
}
}
if (add_name)
{
acpi_cpu_name[acpi_cpu_count] = malloc(4);
memcpy(acpi_cpu_name[acpi_cpu_count], dsdt+offset, 4);
i = offset + 5;
if (acpi_cpu_count == 0)
{
acpi_cpu_p_blk = dsdt[i] | (dsdt[i+1] << 8);
}
DBG("ACPIpatcher: found ACPI CPU [%c%c%c%c]\n", acpi_cpu_name[acpi_cpu_count][0], acpi_cpu_name[acpi_cpu_count][1], acpi_cpu_name[acpi_cpu_count][2], acpi_cpu_name[acpi_cpu_count][3]);
if (++acpi_cpu_count == 32)
{
return;
}
}
}
}
DBG("ACPIpatcher: finished finding cpu names. Found: %d.\n", acpi_cpu_count);
}
static char const pss_ssdt_header[] =
{
0x53, 0x53, 0x44, 0x54, 0x7E, 0x00, 0x00, 0x00, /* SSDT.... */
trunk/i386/libsaio/state_generator.h
1515
1616
1717
18
19
20
21
1822
1923
2024
#include "aml_generator.h"
#include "libsaio.h"
externuint8_t acpi_cpu_count;
externuint32_t acpi_cpu_p_blk;
externchar *acpi_cpu_name[32];
voidget_acpi_cpu_names(uint8_t *dsdt, uint32_t length);
structacpi_2_ssdt *generate_cst_ssdt(struct acpi_2_fadt *fadt);
structacpi_2_ssdt *generate_pss_ssdt(struct acpi_2_dsdt *dsdt);

Archive Download the corresponding diff file

Revision: 2656