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