FreeBSD/usr.sbin/acpi/acpidb/acpidb.c
/*
 * Load DSDT data file and invoke debugger
 */
Load DSDT data file and invoke debugger
Load DSDT data file and invoke debugger
static int
load_dsdt(const char *dsdtfile)
{
	char			filetmp[PATH_MAX];
	ACPI_NEW_TABLE_DESC	*list;
	u_int8_t		*code;
	struct stat		sb;
	int			dounlink, error, fd;
	fd = open(dsdtfile, O_RDONLY, 0);
	if (fd == -1) {
		perror("open");
		return (-1);
	}
	if (fstat(fd, &sb) == -1) {
		perror("fstat");
		close(fd);
		return (-1);
	}
	code = mmap(NULL, (size_t)sb.st_size, PROT_READ, MAP_PRIVATE, fd, (off_t)0);
	close(fd);
	if (code == NULL) {
		perror("mmap");
		return (-1);
	}
	if ((error = AcpiInitializeSubsystem()) != AE_OK) {
		munmap(code, (size_t)sb.st_size);
		return (-1);
	}
	if (strncmp((char *)code, "DSDT", 4) == 0) {
		dounlink = 0;
		strlcpy(filetmp, dsdtfile, sizeof(filetmp));
	} else {
		dounlink = 1;
		mode_t	mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
		dummy_dsdt_table.Length = sizeof(ACPI_TABLE_HEADER) + sb.st_size;
		if ((size_t)snprintf(filetmp, sizeof(filetmp), "%s.tmp",
		    dsdtfile) > sizeof(filetmp) - 1) {
			fprintf(stderr, "file name too long\n");
			munmap(code, (size_t)sb.st_size);
			return (-1);
		}
		fd = open(filetmp, O_WRONLY | O_CREAT | O_TRUNC, mode);
		if (fd == -1) {
			perror("open");
			munmap(code, (size_t)sb.st_size);
			return (-1);
		}
		write(fd, &dummy_dsdt_table, sizeof(ACPI_TABLE_HEADER));
		write(fd, code, sb.st_size);
		close(fd);
	}
	munmap(code, (size_t)sb.st_size);
	if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
			ACPI_ADR_SPACE_SYSTEM_MEMORY,
			(ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_system_memory,
			NULL, NULL)) != AE_OK) {
		fprintf(stderr, "could not initialise SystemMemory handler: %d\n", error);
		return (-1);
	}
	if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
			ACPI_ADR_SPACE_SYSTEM_IO,
			(ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_system_io,
			NULL, NULL)) != AE_OK) {
		fprintf(stderr, "could not initialise SystemIO handler: %d\n", error);
		return (-1);
	}
	if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
			ACPI_ADR_SPACE_PCI_CONFIG,
			(ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_pci_config,
			NULL, NULL)) != AE_OK) {
		fprintf(stderr, "could not initialise PciConfig handler: %d\n", error);
		return (-1);
	}
	if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
			ACPI_ADR_SPACE_EC,
			(ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_ec,
			NULL, NULL)) != AE_OK) {
		fprintf(stderr, "could not initialise EC handler: %d\n", error);
		return (-1);
	}
	if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
			ACPI_ADR_SPACE_SMBUS,
			(ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_smbus,
			NULL, NULL)) != AE_OK) {
		fprintf(stderr, "could not initialise SMBUS handler: %d\n", error);
		return (-1);
	}
	if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
			ACPI_ADR_SPACE_CMOS,
			(ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_cmos,
			NULL, NULL)) != AE_OK) {
		fprintf(stderr, "could not initialise CMOS handler: %d\n", error);
		return (-1);
	}
	if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
			ACPI_ADR_SPACE_PCI_BAR_TARGET,
			(ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_pci_bar_target,
			NULL, NULL)) != AE_OK) {
		fprintf(stderr, "could not initialise PCI BAR TARGET handler: %d\n", error);
		return (-1);
	}
	list = NULL;
	AcGetAllTablesFromFile(filetmp, TRUE, &list);
	AcpiInitializeDebugger();
	AcpiGbl_DebuggerConfiguration = 0;
	AcpiDbUserCommands(':', NULL);
	if (dounlink) {
		unlink(filetmp);
	}
	return (0);
}
static int load_dsdt ( const char * dsdtfile ) { char filetmp [ PATH_MAX ] ; ACPI_NEW_TABLE_DESC * list ; u_int8_t * code ; struct stat sb ; int dounlink , error , fd ; fd = open ( dsdtfile , O_RDONLY , 0 ) ; if ( fd == -1 ) { perror ( " " ) ; return ( -1 ) ; } if ( fstat ( fd , & sb ) == -1 ) { perror ( " " ) ; close ( fd ) ; return ( -1 ) ; } code = mmap ( NULL , ( size_t ) sb . st_size , PROT_READ , MAP_PRIVATE , fd , ( off_t ) 0 ) ; close ( fd ) ; if ( code == NULL ) { perror ( " " ) ; return ( -1 ) ; } if ( ( error = AcpiInitializeSubsystem ( ) ) != AE_OK ) { munmap ( code , ( size_t ) sb . st_size ) ; return ( -1 ) ; } if ( strncmp ( ( char * ) code , " " , 4 ) == 0 ) { dounlink = 0 ; strlcpy ( filetmp , dsdtfile , sizeof ( filetmp ) ) ; } else { dounlink = 1 ; mode_t mode = ( S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ) ; dummy_dsdt_table . Length = sizeof ( ACPI_TABLE_HEADER ) + sb . st_size ; if ( ( size_t ) snprintf ( filetmp , sizeof ( filetmp ) , " " , dsdtfile ) > sizeof ( filetmp ) - 1 ) { fprintf ( stderr , " \n " ) ; munmap ( code , ( size_t ) sb . st_size ) ; return ( -1 ) ; } fd = open ( filetmp , O_WRONLY | O_CREAT | O_TRUNC , mode ) ; if ( fd == -1 ) { perror ( " " ) ; munmap ( code , ( size_t ) sb . st_size ) ; return ( -1 ) ; } write ( fd , & dummy_dsdt_table , sizeof ( ACPI_TABLE_HEADER ) ) ; write ( fd , code , sb . st_size ) ; close ( fd ) ; } munmap ( code , ( size_t ) sb . st_size ) ; if ( ( error = AcpiInstallAddressSpaceHandler ( ACPI_ROOT_OBJECT , ACPI_ADR_SPACE_SYSTEM_MEMORY , ( ACPI_ADR_SPACE_HANDLER ) aml_vm_space_handler_system_memory , NULL , NULL ) ) != AE_OK ) { fprintf ( stderr , " \n " , error ) ; return ( -1 ) ; } if ( ( error = AcpiInstallAddressSpaceHandler ( ACPI_ROOT_OBJECT , ACPI_ADR_SPACE_SYSTEM_IO , ( ACPI_ADR_SPACE_HANDLER ) aml_vm_space_handler_system_io , NULL , NULL ) ) != AE_OK ) { fprintf ( stderr , " \n " , error ) ; return ( -1 ) ; } if ( ( error = AcpiInstallAddressSpaceHandler ( ACPI_ROOT_OBJECT , ACPI_ADR_SPACE_PCI_CONFIG , ( ACPI_ADR_SPACE_HANDLER ) aml_vm_space_handler_pci_config , NULL , NULL ) ) != AE_OK ) { fprintf ( stderr , " \n " , error ) ; return ( -1 ) ; } if ( ( error = AcpiInstallAddressSpaceHandler ( ACPI_ROOT_OBJECT , ACPI_ADR_SPACE_EC , ( ACPI_ADR_SPACE_HANDLER ) aml_vm_space_handler_ec , NULL , NULL ) ) != AE_OK ) { fprintf ( stderr , " \n " , error ) ; return ( -1 ) ; } if ( ( error = AcpiInstallAddressSpaceHandler ( ACPI_ROOT_OBJECT , ACPI_ADR_SPACE_SMBUS , ( ACPI_ADR_SPACE_HANDLER ) aml_vm_space_handler_smbus , NULL , NULL ) ) != AE_OK ) { fprintf ( stderr , " \n " , error ) ; return ( -1 ) ; } if ( ( error = AcpiInstallAddressSpaceHandler ( ACPI_ROOT_OBJECT , ACPI_ADR_SPACE_CMOS , ( ACPI_ADR_SPACE_HANDLER ) aml_vm_space_handler_cmos , NULL , NULL ) ) != AE_OK ) { fprintf ( stderr , " \n " , error ) ; return ( -1 ) ; } if ( ( error = AcpiInstallAddressSpaceHandler ( ACPI_ROOT_OBJECT , ACPI_ADR_SPACE_PCI_BAR_TARGET , ( ACPI_ADR_SPACE_HANDLER ) aml_vm_space_handler_pci_bar_target , NULL , NULL ) ) != AE_OK ) { fprintf ( stderr , " \n " , error ) ; return ( -1 ) ; } list = NULL ; AcGetAllTablesFromFile ( filetmp , TRUE , & list ) ; AcpiInitializeDebugger ( ) ; AcpiGbl_DebuggerConfiguration = 0 ; AcpiDbUserCommands ( ' ' , NULL ) ; if ( dounlink ) { unlink ( filetmp ) ; } return ( 0 ) ; }
Load DSDT data file and invoke debugger
Load DSDT data file and invoke debugger
/*
	 * make sure DSDT data contains table header or not.
	 */ /*
	 * Install the virtual machine version of address space handlers.
	 */