Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/Chazi/i386/libsaio/pci_root.c

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

Archive Download this file

Revision: 847