Index: trunk/i386/libsaio/pci_root.c =================================================================== --- trunk/i386/libsaio/pci_root.c (revision 59) +++ trunk/i386/libsaio/pci_root.c (revision 60) @@ -7,7 +7,7 @@ #include "bootstruct.h" #ifndef DEBUG_PCIROOT -#define DEBUG_PCIROOT 0 +#define DEBUG_PCIROOT 1 #endif #if DEBUG_PCIROOT @@ -46,50 +46,43 @@ int getPciRootUID(void) { void *new_dsdt; - const char *dsdt_filename; const char *val; - int fd; - int dsdt_uid; int len,fsize; + const char * dsdt_filename=NULL; + extern int search_and_get_acpi_fd(const char *, const char **); - if (rootuid < 10) { - return rootuid; - } + if (rootuid < 10) return rootuid; rootuid = 0; /* default uid = 0 */ if (getValueForKey(kPCIRootUID, &val, &len, &bootInfo->bootConfig)) { - if (isdigit(val[0])) { - rootuid = val[0] - '0'; - } + if (isdigit(val[0])) rootuid = val[0] - '0'; goto out; } -#if 1 /* Chameleon compatibility */ - if (getValueForKey("PciRoot", &val, &len, &bootInfo->bootConfig)) { - if (isdigit(val[0])) { - rootuid = val[0] - '0'; - } + else if (getValueForKey("PciRoot", &val, &len, &bootInfo->bootConfig)) { + if (isdigit(val[0])) rootuid = val[0] - '0'; goto out; } - /* PCEFI compatibility */ - if (getValueForKey("-pci0", &val, &len, &bootInfo->bootConfig)) { + else if (getValueForKey("-pci0", &val, &len, &bootInfo->bootConfig)) { rootuid = 0; goto out; } - if (getValueForKey("-pci1", &val, &len, &bootInfo->bootConfig)) { + else if (getValueForKey("-pci1", &val, &len, &bootInfo->bootConfig)) { rootuid = 1; goto out; } -#endif - if (!getValueForKey(kDSDT, &dsdt_filename, &len, &bootInfo->bootConfig)) { - dsdt_filename="/Extra/DSDT.aml"; - } - if ((fd = open_bvdev("bt(0,0)", dsdt_filename, 0)) < 0) { - verbose("[WARNING] %s not found\n", dsdt_filename); - goto out; + int fd = search_and_get_acpi_fd("DSDT.aml", &dsdt_filename); + + // Check booting partition + if (fd<0) + { + verbose("No DSDT found, using 0 as uid value.\n"); + rootuid = 0; + return rootuid; } + fsize = file_size(fd); if ((new_dsdt = malloc(fsize)) == NULL) { @@ -104,15 +97,15 @@ } close (fd); - dsdt_uid = findpciroot(new_dsdt, fsize); + rootuid = findpciroot(new_dsdt, fsize); free(new_dsdt); - if(dsdt_uid == 11) dsdt_uid=0; //usually when _UID isnt present, it means uid is zero - else if (dsdt_uid < 0 || dsdt_uid > 9) + // 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"); - dsdt_uid = 0; - //if(dsdt_uid == 10) //algo failed, PCI0 wasnt found + rootuid = 0; } out: verbose("Using PCI-Root-UID value: %d\n", rootuid); Index: trunk/i386/libsaio/dsdt_patcher.c =================================================================== --- trunk/i386/libsaio/dsdt_patcher.c (revision 59) +++ trunk/i386/libsaio/dsdt_patcher.c (revision 60) @@ -72,66 +72,78 @@ } return NULL; } - -void *loadACPITable () +/** The folowing ACPI Table search algo. should be reused anywhere needed:*/ +int search_and_get_acpi_fd(const char * filename, const char ** outDirspec) { - void *tableAddr; - int fd = -1; - char dirspec[512]; - const char * const filename = "DSDT.aml"; - const char * overriden_pathname=NULL; - int len=0; + int fd=0; + const char * overriden_pathname=NULL; + static char dirspec[512]=""; + int len=0; - // Check booting partition - - // Rek: if user specified a full path name then take it in consideration - if (getValueForKey(kDSDT, &overriden_pathname, &len, + /// Take in accound user overriding if it's DSDT only + if (strstr(filename, "DSDT") && + getValueForKey(kDSDT, &overriden_pathname, &len, &bootInfo->bootConfig)) - { - sprintf(dirspec, "%s", overriden_pathname); // start searching root - //printf("Using custom DSDT path %s\n", dirspec); - //getc(); - } - else - sprintf(dirspec, "/%s", filename); // start searching root + { + sprintf(dirspec, "%s", overriden_pathname); // start searching root + fd=open (dirspec,0); + if (fd>=0) goto success_fd; + } - fd=open (dirspec,0); + // Start searching any potential location for ACPI Table + sprintf(dirspec, "/%s", filename); // start searching root + fd=open (dirspec,0); + if (fd>=0) goto success_fd; - if (fd<0) - { // Check Extra on booting partition - //verbose("Searching for DSDT.aml file ...\n"); - sprintf(dirspec,"/Extra/%s",filename); - fd=open (dirspec,0); - if (fd<0) - { // Fall back to booter partition - sprintf(dirspec,"bt(0,0)/Extra/%s",filename); - fd=open (dirspec,0); - if (fd<0) - { - verbose("ACPI Table not found: %s\n", filename); - return NULL; - } - } - } + sprintf(dirspec, "%s", filename); // start current dir + fd=open (dirspec,0); + if (fd>=0) goto success_fd; - tableAddr=(void*)AllocateKernelMemory(file_size (fd)); - if (tableAddr) - { - if (read (fd, tableAddr, file_size (fd))!=file_size (fd)) - { - printf("Couldn't read table %s\n",dirspec); - free (tableAddr); - close (fd); - return NULL; - } + sprintf(dirspec,"/Extra/%s",filename); + fd=open (dirspec,0); + if (fd>=0) goto success_fd; - DBG("Table %s read and stored at: %x\n", dirspec, tableAddr); - close (fd); - return tableAddr; - } + sprintf(dirspec,"bt(0,0)/Extra/%s",filename); + fd=open (dirspec,0); + if (fd>=0) goto success_fd; + // NOT FOUND: + verbose("ACPI Table not found: %s\n", filename); + if (outDirspec) *outDirspec = ""; + return -1; + // FOUND +success_fd: + if (outDirspec) *outDirspec = dirspec; + return fd; +} + +void *loadACPITable (const char * filename) +{ + void *tableAddr; + const char * dirspec=NULL; + + int fd = search_and_get_acpi_fd(filename, &dirspec); + + if (fd>=0) + { + tableAddr=(void*)AllocateKernelMemory(file_size (fd)); + if (tableAddr) + { + if (read (fd, tableAddr, file_size (fd))!=file_size (fd)) + { + printf("Couldn't read table %s\n",dirspec); + free (tableAddr); + close (fd); + return NULL; + } + + DBG("Table %s read and stored at: %x\n", dirspec, tableAddr); + close (fd); + return tableAddr; + } + close (fd); + } printf("Couldn't allocate memory for table %s\n", dirspec); - close (fd); return NULL; } @@ -253,7 +265,7 @@ bool drop_ssdt; // Load replacement DSDT - new_dsdt=loadACPITable(); + new_dsdt=loadACPITable("DSDT.aml"); if (!new_dsdt) { return setupAcpiNoMod(); Index: trunk/i386/libsaio/pci.c =================================================================== --- trunk/i386/libsaio/pci.c (revision 59) +++ trunk/i386/libsaio/pci.c (revision 60) @@ -10,7 +10,7 @@ #include "pci_root.h" #ifndef DEBUG_PCI -#define DEBUG_PCI 0 +#define DEBUG_PCI 1 #endif #if DEBUG_PCI @@ -150,14 +150,22 @@ dev_path[0] = 0; end = root_pci_dev; - while (end != pci_dt) { + + int uid = getPciRootUID(); + while (end != pci_dt) + { current = pci_dt; - while (current->parent != end) current = current->parent; + while (current->parent != end) + current = current->parent; end = current; - if (current->parent == root_pci_dev) - sprintf(tmp, "PciRoot(0x%x)/Pci(0x%x,0x%x)", getPciRootUID(), current->dev.bits.dev, current->dev.bits.func); - else - sprintf(tmp, "/Pci(0x%x,0x%x)", current->dev.bits.dev, current->dev.bits.func); + if (current->parent == root_pci_dev) + { + sprintf(tmp, "PciRoot(0x%x)/Pci(0x%x,0x%x)", uid, + current->dev.bits.dev, current->dev.bits.func); + } else { + sprintf(tmp, "/Pci(0x%x,0x%x)", + current->dev.bits.dev, current->dev.bits.func); + } strcat(dev_path, tmp); } return dev_path; Index: trunk/i386/libsaio/biosfn.c =================================================================== --- trunk/i386/libsaio/biosfn.c (revision 59) +++ trunk/i386/libsaio/biosfn.c (revision 60) @@ -168,7 +168,7 @@ MemoryRange * range = (MemoryRange *)BIOS_ADDR; unsigned long count = 0; - unsigned long rerangedCount; + // unsigned long rerangedCount; unsigned long long conMemSize = 0; unsigned long long extMemSize = 0;