Chameleon

Chameleon Svn Source Tree

Root/branches/meklort/i386/modules/ACPIPatcher/ACPIPatcher.c

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

Archive Download this file

Revision: 537