Example #1
0
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 \n", dirspec);
	}  
	//printf("Couldn't find table %s\n", filename);
	return NULL;
}
Example #2
0
int getPciRootUID(void)
{
//	void *new_dsdt;
	const char *val;
	int len; //,fsize;
//	const char * dsdt_filename=NULL;
//	extern int search_and_get_acpi_fd(const char *, const char **);

	if (rootuid < 10) return rootuid;
	rootuid = 0;	/* default uid = 0 */

	if (getValueForKey(kPCIRootUID, &val, &len, &bootInfo->chameleonConfig)) {
		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;
	}
//Slice - as in Meklort
#if NOTNOW	
	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;
	  goto out;
	}
	
	fsize = file_size(fd);

	if ((new_dsdt = malloc(fsize)) == NULL) {
		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);
		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) 
	{
		verbose("PciRoot uid value wasnt found, using 0, if you want it to be 1, use -PciRootUID flag");
		rootuid = 0;
	}
#endif	
out:
	verbose("Using PCI-Root-UID value: %d\n", rootuid);
	return rootuid;
}