Chameleon

Chameleon Svn Source Tree

Root/branches/meklort/i386/modules/ACPIPatcher/ACPIPatcher.c

Source at commit 576 created 10 years 3 months ago.
By meklort, Retrieve and store the machine's smbios product name. Load machin.DSDT.aml file if it exists.
1/*
2 * Copyright (c) 2009 Evan Lojewski. All rights reserved.
3 *
4 */
5
6#include "libsaio.h"
7#include "modules.h"
8#include "boot.h"
9#include "bootstruct.h"
10#include "pci_root.h"
11#include "acpi_patcher.h"
12
13int ACPIPatcher_getPciRootUID(void);
14unsigned int findpciroot(unsigned char * dsdt,int len);
15static unsigned int findrootuid(unsigned char * dsdt, int len);
16
17void ACPIPatcher_setupEfiConfigurationTable_hook(void* binary, void* arg2, void* arg3, void* arg4)
18{
19// Setup ACPI with DSDT overrides (mackerintel's patch)
20setupAcpi();
21}
22
23void ACPIPatcher_start()
24{
25replace_function("_getPciRootUID", &ACPIPatcher_getPciRootUID);
26register_hook_callback("setupEfiConfigurationTable", &ACPIPatcher_setupEfiConfigurationTable_hook);
27}
28
29int ACPIPatcher_rootuid = 10; //value means function wasnt ran yet
30
31int ACPIPatcher_getPciRootUID(void)
32{
33void *new_dsdt;
34const char *val;
35int len,fsize;
36const char * dsdt_filename=NULL;
37extern int search_and_get_acpi_fd(const char *, const char **);
38
39if (ACPIPatcher_rootuid < 10) return ACPIPatcher_rootuid;
40ACPIPatcher_rootuid = 0;/* default uid = 0 */
41
42if (getValueForKey(kPCIRootUID, &val, &len, &bootInfo->bootConfig)) {
43if (isdigit(val[0])) ACPIPatcher_rootuid = val[0] - '0';
44goto out;
45}
46/* Chameleon compatibility */
47else if (getValueForKey("PciRoot", &val, &len, &bootInfo->bootConfig)) {
48if (isdigit(val[0])) ACPIPatcher_rootuid = val[0] - '0';
49goto out;
50}
51/* PCEFI compatibility */
52else if (getValueForKey("-pci0", &val, &len, &bootInfo->bootConfig)) {
53ACPIPatcher_rootuid = 0;
54goto out;
55}
56else if (getValueForKey("-pci1", &val, &len, &bootInfo->bootConfig)) {
57ACPIPatcher_rootuid = 1;
58goto out;
59}
60
61int fd = search_and_get_acpi_fd("DSDT.aml", &dsdt_filename);
62
63// Check booting partition
64if (fd<0)
65{
66verbose("No DSDT found, using 0 as uid value.\n");
67ACPIPatcher_rootuid = 0;
68goto out;
69}
70
71fsize = file_size(fd);
72
73if ((new_dsdt = malloc(fsize)) == NULL) {
74verbose("[ERROR] alloc DSDT memory failed\n");
75close (fd);
76goto out;
77}
78if (read (fd, new_dsdt, fsize) != fsize) {
79verbose("[ERROR] read %s failed\n", dsdt_filename);
80close (fd);
81goto out;
82}
83close (fd);
84
85ACPIPatcher_rootuid = findpciroot(new_dsdt, fsize);
86free(new_dsdt);
87
88// make sure it really works:
89if (ACPIPatcher_rootuid == 11) ACPIPatcher_rootuid=0; //usually when _UID isnt present, it means uid is zero
90else if (ACPIPatcher_rootuid < 0 || ACPIPatcher_rootuid > 9)
91{
92printf("PciRoot uid value wasnt found, using 0, if you want it to be 1, use -PciRootUID flag");
93ACPIPatcher_rootuid = 0;
94}
95out:
96verbose("Using PCI-Root-UID value: %d\n", ACPIPatcher_rootuid);
97return ACPIPatcher_rootuid;
98}
99
100unsigned int findpciroot(unsigned char * dsdt,int len)
101{
102int i;
103
104for (i=0; i<len-4; i++) {
105if(dsdt[i] == 'P' && dsdt[i+1] == 'C' && dsdt[i+2] == 'I' && (dsdt[i+3] == 0x08 || dsdt [i+4] == 0x08)) {
106return findrootuid(dsdt+i, len-i);
107}
108}
109return 10;
110}
111
112static unsigned int findrootuid(unsigned char * dsdt, int len)
113{
114int i;
115for (i=0; i<64 && i<len-5; i++) //not far than 64 symbols from pci root
116{
117if(dsdt[i] == '_' && dsdt[i+1] == 'U' && dsdt[i+2] == 'I' && dsdt[i+3] == 'D' && dsdt[i+5] == 0x08)
118{
119return dsdt[i+4];
120}
121}
122return 11;
123}
124

Archive Download this file

Revision: 576