Chameleon

Chameleon Svn Source Tree

Root/branches/slice/i386/libsaio/pci_root.c

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

Archive Download this file

Revision: 689