Chameleon

Chameleon Svn Source Tree

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

1/*
2 * Copyright 2009 netkas
3 */
4
5#include "libsaio.h"
6#include "bootstruct.h"
7
8#ifndef DEBUG_PCIROOT
9#define DEBUG_PCIROOT 0
10#endif
11
12#if DEBUG_PCIROOT==1
13#define DBG(x...) printf(x)
14#else
15#define DBG(x...)
16#endif
17
18int rootuid = 10; //value means function wasnt ran yet
19
20unsigned int findrootuid(unsigned char * dsdt)
21{
22int i;
23for (i=0; i<64; i++) //not far than 64 symbols from pci root
24{
25if(dsdt[i] == '_' && dsdt[i+1] == 'U' && dsdt[i+2] == 'I' && dsdt[i+3] == 'D' && dsdt[i+5] == 0x08)
26{
27return dsdt[i+4];
28}
29}
30printf("pci root uid not found\n");
31return 11;
32}
33
34unsigned int findpciroot(unsigned char * dsdt,int size)
35{
36int i;
37for (i=0; i<size; i++)
38{
39if(dsdt[i] == 'P' && dsdt[i+1] == 'C' && dsdt[i+2] == 'I' && (dsdt[i+3] == 0x08 || dsdt [i+4] == 0x08))
40{
41return findrootuid(dsdt+i);
42}
43}
44
45printf("pci root not found\n");
46return 10;
47}
48
49
50/* Setup ACPI. Replace DSDT if DSDT.aml is found */
51int getPciRootUID()
52{
53int fd, version;
54void *new_dsdt;
55const char *dsdt_filename;
56const char *val;
57int user_uid_value;
58char dirspec[512];
59int len,fsize;
60
61if(rootuid < 10) return rootuid;
62
63if (!getValueForKey("DSDT", &dsdt_filename, &len, &bootInfo->bootConfig))
64dsdt_filename="DSDT.aml";
65
66if (getValueForKey("-pci1", &val, &len, &bootInfo->bootConfig)) //fallback
67{
68user_uid_value = 1;
69rootuid = user_uid_value;
70return rootuid;
71}
72 else user_uid_value = 0;
73
74
75// Check booting partition
76sprintf(dirspec,"%s",dsdt_filename);
77fd=open (dirspec,0);
78if (fd<0)
79{// Check Extra on booting partition
80sprintf(dirspec,"/Extra/%s",dsdt_filename);
81fd=open (dirspec,0);
82if (fd<0)
83{// Fall back to booter partition
84sprintf(dirspec,"bt(0,0)/Extra/%s",dsdt_filename);
85fd=open (dirspec,0);
86if (fd<0)
87{
88verbose("No DSDT found, using 0 as uid value.\n");
89rootuid = user_uid_value;
90return rootuid;
91}
92}
93}
94
95// Load replacement DSDT
96new_dsdt=(void*)MALLOC(file_size (fd));
97if (!new_dsdt)
98{
99printf("Couldn't allocate memory for DSDT\n");
100rootuid = user_uid_value;
101return rootuid;
102}
103fsize = file_size(fd);
104if (read (fd, new_dsdt, file_size (fd))!=file_size (fd))
105{
106printf("Couldn't read file\n");
107rootuid = user_uid_value;
108return rootuid;
109}
110close (fd);
111rootuid=findpciroot(new_dsdt, fsize);
112if(rootuid == 11)rootuid=0; //usualy when _UID isnt present, it means uid is zero
113if(rootuid == 10) //algo failed, PCI0 wasnt found;
114{
115printf("pci root uid value wasnt found, using zero, if you want it to be 1, use -pci1 flag");
116rootuid = user_uid_value;
117}
118free(new_dsdt);
119return rootuid;
120}
121
122

Archive Download this file

Revision: 4