Root/
Source at commit 534 created 13 years 6 months ago. By meklort, ACPI Pather is now a module. untested. | |
---|---|
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 | ␊ |
15 | void ACPIPatcher_setupEfiConfigurationTable_hook(void* binary, void* arg2, void* arg3, void* arg4)␊ |
16 | {␊ |
17 | ␉// Setup ACPI with DSDT overrides (mackerintel's patch)␊ |
18 | ␉setupAcpi();␊ |
19 | }␊ |
20 | ␊ |
21 | void ACPIPatcher_start()␊ |
22 | {␊ |
23 | ␉replace_function("getPciRootUID", &ACPIPatcher_getPciRootUID);␊ |
24 | ␉register_hook_callback("setupEfiConfigurationTable", &ACPIPatcher_setupEfiConfigurationTable_hook);␊ |
25 | }␊ |
26 | ␊ |
27 | int ACPIPatcher_rootuid = 10; //value means function wasnt ran yet␊ |
28 | ␊ |
29 | int ACPIPatcher_getPciRootUID(void)␊ |
30 | {␊ |
31 | ␉void *new_dsdt;␊ |
32 | ␉const char *val;␊ |
33 | ␉int len,fsize;␊ |
34 | ␉const char * dsdt_filename=NULL;␊ |
35 | ␉extern int search_and_get_acpi_fd(const char *, const char **);␊ |
36 | ␉␊ |
37 | ␉if (ACPIPatcher_rootuid < 10) return ACPIPatcher_rootuid;␊ |
38 | ␉ACPIPatcher_rootuid = 0;␉/* default uid = 0 */␊ |
39 | ␉␊ |
40 | ␉if (getValueForKey(kPCIRootUID, &val, &len, &bootInfo->bootConfig)) {␊ |
41 | ␉␉if (isdigit(val[0])) ACPIPatcher_rootuid = val[0] - '0';␊ |
42 | ␉␉goto out;␊ |
43 | ␉}␊ |
44 | ␉/* Chameleon compatibility */␊ |
45 | ␉else if (getValueForKey("PciRoot", &val, &len, &bootInfo->bootConfig)) {␊ |
46 | ␉␉if (isdigit(val[0])) ACPIPatcher_rootuid = val[0] - '0';␊ |
47 | ␉␉goto out;␊ |
48 | ␉}␊ |
49 | ␉/* PCEFI compatibility */␊ |
50 | ␉else if (getValueForKey("-pci0", &val, &len, &bootInfo->bootConfig)) {␊ |
51 | ␉␉ACPIPatcher_rootuid = 0;␊ |
52 | ␉␉goto out;␊ |
53 | ␉}␊ |
54 | ␉else if (getValueForKey("-pci1", &val, &len, &bootInfo->bootConfig)) {␊ |
55 | ␉␉ACPIPatcher_rootuid = 1;␊ |
56 | ␉␉goto out;␊ |
57 | ␉}␊ |
58 | ␉␊ |
59 | ␉int fd = search_and_get_acpi_fd("DSDT.aml", &dsdt_filename);␊ |
60 | ␉␊ |
61 | ␉// Check booting partition␊ |
62 | ␉if (fd<0)␊ |
63 | ␉{␉ ␊ |
64 | ␉␉verbose("No DSDT found, using 0 as uid value.\n");␊ |
65 | ␉␉ACPIPatcher_rootuid = 0;␊ |
66 | ␉␉goto out;␊ |
67 | ␉}␊ |
68 | ␉␊ |
69 | ␉fsize = file_size(fd);␊ |
70 | ␉␊ |
71 | ␉if ((new_dsdt = malloc(fsize)) == NULL) {␊ |
72 | ␉␉verbose("[ERROR] alloc DSDT memory failed\n");␊ |
73 | ␉␉close (fd);␊ |
74 | ␉␉goto out;␊ |
75 | ␉}␊ |
76 | ␉if (read (fd, new_dsdt, fsize) != fsize) {␊ |
77 | ␉␉verbose("[ERROR] read %s failed\n", dsdt_filename);␊ |
78 | ␉␉close (fd);␊ |
79 | ␉␉goto out;␊ |
80 | ␉}␊ |
81 | ␉close (fd);␊ |
82 | ␉␊ |
83 | ␉ACPIPatcher_rootuid = findpciroot(new_dsdt, fsize);␊ |
84 | ␉free(new_dsdt);␊ |
85 | ␉␊ |
86 | ␉// make sure it really works: ␊ |
87 | ␉if (ACPIPatcher_rootuid == 11) ACPIPatcher_rootuid=0; //usually when _UID isnt present, it means uid is zero␊ |
88 | ␉else if (ACPIPatcher_rootuid < 0 || ACPIPatcher_rootuid > 9) ␊ |
89 | ␉{␊ |
90 | ␉␉printf("PciRoot uid value wasnt found, using 0, if you want it to be 1, use -PciRootUID flag");␊ |
91 | ␉␉ACPIPatcher_rootuid = 0;␊ |
92 | ␉}␊ |
93 | out:␊ |
94 | ␉verbose("Using PCI-Root-UID value: %d\n", ACPIPatcher_rootuid);␊ |
95 | ␉return ACPIPatcher_rootuid;␊ |
96 | }␊ |
97 |