/* * Copyright 2009 netkas */ #include "config.h" #include "libsaio.h" #include "boot.h" #include "bootstruct.h" #if DEBUG_PCIROOT #define DBG(x...) printf(x) #else #define DBG(x...) #endif static int rootuid = 10; //value means function wasnt ran yet static unsigned int findrootuid(unsigned char * dsdt, int len) { int i; for (i=0; i<64 && ichameleonConfig)) { if (isdigit(val[0])) { rootuid = val[0] - '0'; } goto out; } /* Chameleon compatibility */ else if (getValueForKey("PciRoot", &val, &len, &bootInfo->chameleonConfig)) { if (isdigit(val[0])) { rootuid = val[0] - '0'; } goto out; } /* PCEFI compatibility */ else if (getValueForKey("-pci0", &val, &len, &bootInfo->chameleonConfig)) { rootuid = 0; goto out; } else if (getValueForKey("-pci1", &val, &len, &bootInfo->chameleonConfig)) { rootuid = 1; goto out; } // Try using the file specified with the DSDT option if (getValueForKey(kDSDT, &dsdt_filename, &len, &bootInfo->chameleonConfig)) { strncpy(dsdt_dirSpec, dsdt_filename, sizeof(dsdt_dirSpec) ); } else { strcpy(dsdt_dirSpec, "DSDT.aml"); } int fd = search_and_get_acpi_fd(dsdt_dirSpec, &dsdt_filename); // Check booting partition if (fd<0) { verbose("No DSDT found, using 0 as uid value.\n"); rootuid = 0; goto out; } fsize = file_size(fd); if (!(new_dsdt = malloc(fsize))) { verbose("[ERROR] alloc DSDT memory failed\n"); close (fd); goto out; } if (read (fd, new_dsdt, fsize) != fsize) { verbose("[ERROR] read %s failed\n", dsdt_filename); free(new_dsdt); close (fd); goto out; } close (fd); rootuid = findpciroot(new_dsdt, fsize); free(new_dsdt); // make sure it really works: if (rootuid == 11) { rootuid=0; //usually when _UID isnt present, it means uid is zero } else if (rootuid < 0 || rootuid > 9) { printf("PciRoot uid value wasnt found, using 0, if you want it to be 1, use -PciRootUID flag"); rootuid = 0; } out: verbose("Using PCI-Root-UID value: %d\n", rootuid); return rootuid; }