Root/
Source at commit HEAD created 5 years 6 days ago. By ifabio, Few update to kernelPatcher (Credits to CrazyBirdy) | |
---|---|
1 | /*␊ |
2 | * Copyright 2009 netkas␊ |
3 | */␊ |
4 | ␊ |
5 | #include "config.h"␊ |
6 | #include "libsaio.h"␊ |
7 | #include "boot.h"␊ |
8 | #include "bootstruct.h"␊ |
9 | ␊ |
10 | #if DEBUG_PCIROOT␊ |
11 | ␉#define DBG(x...) printf(x)␊ |
12 | #else␊ |
13 | ␉#define DBG(x...)␊ |
14 | #endif␊ |
15 | ␊ |
16 | static int rootuid = 10; //value means function wasnt ran yet␊ |
17 | ␊ |
18 | static unsigned int findrootuid(unsigned char * dsdt, int len)␊ |
19 | {␊ |
20 | ␉int i;␊ |
21 | ␉for (i=0; i<64 && i<len-5; i++) //not far than 64 symbols from pci root ␊ |
22 | ␉{␊ |
23 | ␉␉if(dsdt[i] == '_' && dsdt[i+1] == 'U' && dsdt[i+2] == 'I' && dsdt[i+3] == 'D' && dsdt[i+5] == 0x08)␊ |
24 | ␉␉{␊ |
25 | ␉␉␉return dsdt[i+4];␊ |
26 | ␉␉}␊ |
27 | ␉}␊ |
28 | ␉return 11;␊ |
29 | }␊ |
30 | ␊ |
31 | static unsigned int findpciroot(unsigned char * dsdt,int len)␊ |
32 | {␊ |
33 | ␉int i;␊ |
34 | ␊ |
35 | ␉for (i=0; i<len-4; i++) {␊ |
36 | ␉␉if(dsdt[i] == 'P' && dsdt[i+1] == 'C' && dsdt[i+2] == 'I' && (dsdt[i+3] == 0x08 || dsdt [i+4] == 0x08)) {␊ |
37 | ␉␉␉return findrootuid(dsdt+i, len-i);␊ |
38 | ␉␉}␊ |
39 | ␉}␊ |
40 | ␉return 10;␊ |
41 | }␊ |
42 | ␊ |
43 | int getPciRootUID(void)␊ |
44 | {␊ |
45 | ␉char dsdt_dirSpec[128];␊ |
46 | ␊ |
47 | ␉void *new_dsdt;␊ |
48 | ␉const char *val;␊ |
49 | ␉int len, fsize;␊ |
50 | ␉const char * dsdt_filename = NULL;␊ |
51 | ␉extern int search_and_get_acpi_fd(const char *, const char **);␊ |
52 | ␊ |
53 | ␉if (rootuid < 10)␊ |
54 | ␉{␊ |
55 | ␉␉return rootuid;␊ |
56 | ␉}␊ |
57 | ␊ |
58 | ␉rootuid = 0;␉/* default uid = 0 */␊ |
59 | ␊ |
60 | ␉if (getValueForKey(kPCIRootUID, &val, &len, &bootInfo->chameleonConfig))␊ |
61 | ␉{␊ |
62 | ␉␉if (isdigit(val[0]))␊ |
63 | ␉␉{␊ |
64 | ␉␉␉rootuid = val[0] - '0';␊ |
65 | ␉␉}␊ |
66 | ␊ |
67 | ␉␉goto out;␊ |
68 | ␉}␊ |
69 | ␉/* Chameleon compatibility */␊ |
70 | ␉else if (getValueForKey("PciRoot", &val, &len, &bootInfo->chameleonConfig))␊ |
71 | ␉{␊ |
72 | ␉␉if (isdigit(val[0]))␊ |
73 | ␉␉{␊ |
74 | ␉␉␉rootuid = val[0] - '0';␊ |
75 | ␉␉}␊ |
76 | ␊ |
77 | ␉␉goto out;␊ |
78 | ␉}␊ |
79 | ␉/* PCEFI compatibility */␊ |
80 | ␉else if (getValueForKey("-pci0", &val, &len, &bootInfo->chameleonConfig))␊ |
81 | ␉{␊ |
82 | ␉␉rootuid = 0;␊ |
83 | ␉␉goto out;␊ |
84 | ␉}␊ |
85 | ␉else if (getValueForKey("-pci1", &val, &len, &bootInfo->chameleonConfig))␊ |
86 | ␉{␊ |
87 | ␉␉rootuid = 1;␊ |
88 | ␉␉goto out;␊ |
89 | ␉}␊ |
90 | ␊ |
91 | ␉// Try using the file specified with the DSDT option␊ |
92 | ␉if (getValueForKey(kDSDT, &dsdt_filename, &len, &bootInfo->chameleonConfig))␊ |
93 | ␉{␊ |
94 | ␉␉strncpy(dsdt_dirSpec, dsdt_filename, sizeof(dsdt_dirSpec) );␊ |
95 | ␉}␊ |
96 | ␉else␊ |
97 | ␉{␊ |
98 | ␉␉strcpy(dsdt_dirSpec, "DSDT.aml");␊ |
99 | ␉}␊ |
100 | ␊ |
101 | ␉int fd = search_and_get_acpi_fd(dsdt_dirSpec, &dsdt_filename);␊ |
102 | ␊ |
103 | ␉// Check booting partition␊ |
104 | ␉if (fd<0)␊ |
105 | ␉{␉ ␊ |
106 | ␉␉verbose("No DSDT found, using 0 as uid value.\n");␊ |
107 | ␉␉rootuid = 0;␊ |
108 | ␉␉goto out;␊ |
109 | ␉}␊ |
110 | ␊ |
111 | ␉fsize = file_size(fd);␊ |
112 | ␊ |
113 | ␉if (!(new_dsdt = malloc(fsize)))␊ |
114 | ␉{␊ |
115 | ␉␉verbose("[ERROR] alloc DSDT memory failed\n");␊ |
116 | ␉␉close (fd);␊ |
117 | ␉␉goto out;␊ |
118 | ␉}␊ |
119 | ␉if (read (fd, new_dsdt, fsize) != fsize)␊ |
120 | ␉{␊ |
121 | ␉␉verbose("[ERROR] read %s failed\n", dsdt_filename);␊ |
122 | ␉␉free(new_dsdt);␊ |
123 | ␉␉close (fd);␊ |
124 | ␉␉goto out;␊ |
125 | ␉}␊ |
126 | ␉close (fd);␊ |
127 | ␊ |
128 | ␉rootuid = findpciroot(new_dsdt, fsize);␊ |
129 | ␉free(new_dsdt);␊ |
130 | ␊ |
131 | ␉// make sure it really works: ␊ |
132 | ␉if (rootuid == 11)␊ |
133 | ␉{␊ |
134 | ␉␉rootuid=0; //usually when _UID isnt present, it means uid is zero␊ |
135 | ␉}␊ |
136 | ␉else if (rootuid < 0 || rootuid > 9) ␊ |
137 | ␉{␊ |
138 | ␉␉printf("PciRoot uid value wasnt found, using 0, if you want it to be 1, use -PciRootUID flag");␊ |
139 | ␉␉rootuid = 0;␊ |
140 | ␉}␊ |
141 | out:␊ |
142 | ␉verbose("Using PCI-Root-UID value: %d\n", rootuid);␊ |
143 | ␉return rootuid;␊ |
144 | }␊ |
145 |