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