1 | /*␊ |
2 | * Copyright 2009 netkas␊ |
3 | */␊ |
4 | ␊ |
5 | #include "libsaio.h"␊ |
6 | #include "boot.h"␊ |
7 | #include "bootstruct.h"␊ |
8 | //#include "acpi_patcher.h"␊ |
9 | ␊ |
10 | #ifndef DEBUG_PCIROOT␊ |
11 | #define DEBUG_PCIROOT 0␊ |
12 | #endif␊ |
13 | ␊ |
14 | #if DEBUG_PCIROOT␊ |
15 | #define DBG(x...) verbose(x)␊ |
16 | #else␊ |
17 | #define DBG(x...) msglog(x)␊ |
18 | #endif␊ |
19 | ␊ |
20 | static int rootuid = 10; //value means function wasnt ran yet␊ |
21 | #if NOTYET //it present in ACPIPatcher␊ |
22 | static unsigned int findrootuid(unsigned char * dsdt, int len)␊ |
23 | {␊ |
24 | ␉int i;␊ |
25 | ␉for (i=0; i<64 && i<len-5; i++) //not far than 64 symbols from pci root ␊ |
26 | ␉{␊ |
27 | ␉␉if(dsdt[i] == '_' && dsdt[i+1] == 'U' && dsdt[i+2] == 'I' && dsdt[i+3] == 'D' && dsdt[i+5] == 0x08)␊ |
28 | ␉␉{␊ |
29 | ␉␉␉return dsdt[i+4];␊ |
30 | ␉␉}␊ |
31 | ␉}␊ |
32 | ␉return 11;␊ |
33 | }␊ |
34 | ␊ |
35 | static unsigned int findpciroot(unsigned char * dsdt,int len)␊ |
36 | {␊ |
37 | ␉int i;␊ |
38 | ␊ |
39 | ␉for (i=0; i<len-4; i++) {␊ |
40 | ␉␉if(dsdt[i] == 'P' && dsdt[i+1] == 'C' && dsdt[i+2] == 'I' && (dsdt[i+3] == 0x08 || dsdt [i+4] == 0x08)) {␊ |
41 | ␉␉␉return findrootuid(dsdt+i, len-i);␊ |
42 | ␉␉}␊ |
43 | ␉}␊ |
44 | ␉return 10;␊ |
45 | }␊ |
46 | #endif␊ |
47 | int getPciRootUID(void)␊ |
48 | {␊ |
49 | //␉void *new_dsdt;␊ |
50 | ␉const char *val;␊ |
51 | ␉int len; //,fsize;␊ |
52 | //␉const char * dsdt_filename=NULL;␊ |
53 | //␉extern int search_and_get_acpi_fd(const char *, const char **);␊ |
54 | ␊ |
55 | ␉if (rootuid < 10) return rootuid;␊ |
56 | ␉rootuid = 0;␉/* default uid = 0 */␊ |
57 | ␊ |
58 | ␉if (getValueForKey(kPCIRootUID, &val, &len, &bootInfo->bootConfig)) {␊ |
59 | ␉␉if (isdigit(val[0])) rootuid = val[0] - '0';␊ |
60 | ␉␉goto out;␊ |
61 | ␉}␊ |
62 | ␉/* Chameleon compatibility */␊ |
63 | ␉else if (getValueForKey("PciRoot", &val, &len, &bootInfo->bootConfig)) {␊ |
64 | ␉␉if (isdigit(val[0])) rootuid = val[0] - '0';␊ |
65 | ␉␉goto out;␊ |
66 | ␉}␊ |
67 | ␉/* PCEFI compatibility */␊ |
68 | ␉else if (getValueForKey("-pci0", &val, &len, &bootInfo->bootConfig)) {␊ |
69 | ␉␉rootuid = 0;␊ |
70 | ␉␉goto out;␊ |
71 | ␉}␊ |
72 | ␉else if (getValueForKey("-pci1", &val, &len, &bootInfo->bootConfig)) {␊ |
73 | ␉␉rootuid = 1;␊ |
74 | ␉␉goto out;␊ |
75 | ␉}␊ |
76 | //Slice - as in Meklort␊ |
77 | #if NOTNOW␉␊ |
78 | ␉int fd = search_and_get_acpi_fd("DSDT.aml", &dsdt_filename);␊ |
79 | ␊ |
80 | ␉// Check booting partition␊ |
81 | ␉if (fd<0)␊ |
82 | ␉{␉ ␊ |
83 | ␉ verbose("No DSDT found, using 0 as uid value.\n");␊ |
84 | ␉ rootuid = 0;␊ |
85 | ␉ goto out;␊ |
86 | ␉}␊ |
87 | ␉␊ |
88 | ␉fsize = file_size(fd);␊ |
89 | ␊ |
90 | ␉if ((new_dsdt = malloc(fsize)) == NULL) {␊ |
91 | ␉␉verbose("[ERROR] alloc DSDT memory failed\n");␊ |
92 | ␉␉close (fd);␊ |
93 | ␉␉goto out;␊ |
94 | ␉}␊ |
95 | ␉if (read (fd, new_dsdt, fsize) != fsize) {␊ |
96 | ␉␉verbose("[ERROR] read %s failed\n", dsdt_filename);␊ |
97 | ␉␉close (fd);␊ |
98 | ␉␉goto out;␊ |
99 | ␉}␊ |
100 | ␉close (fd);␊ |
101 | ␊ |
102 | ␉rootuid = findpciroot(new_dsdt, fsize);␊ |
103 | ␉free(new_dsdt);␊ |
104 | ␊ |
105 | ␉// make sure it really works: ␊ |
106 | ␉if (rootuid == 11) rootuid=0; //usually when _UID isnt present, it means uid is zero␊ |
107 | ␉else if (rootuid < 0 || rootuid > 9) ␊ |
108 | ␉{␊ |
109 | ␉␉verbose("PciRoot uid value wasnt found, using 0, if you want it to be 1, use -PciRootUID flag");␊ |
110 | ␉␉rootuid = 0;␊ |
111 | ␉}␊ |
112 | #endif␉␊ |
113 | out:␊ |
114 | ␉verbose("Using PCI-Root-UID value: %d\n", rootuid);␊ |
115 | ␉return rootuid;␊ |
116 | }␊ |
117 | |