Пример #1
0
void
apply_boot_settings()
{
	void* kernelSettings = load_driver_settings("kernel");
	void* safemodeSettings = load_driver_settings(B_SAFEMODE_DRIVER_SETTINGS);

	apply_boot_settings(kernelSettings, safemodeSettings);

	if (safemodeSettings != NULL)
		unload_driver_settings(safemodeSettings);
	if (kernelSettings)
		unload_driver_settings(kernelSettings);
}
Пример #2
0
void
load_settings()
{
	void *handle = load_driver_settings(DRIVER_NAME);
	if (handle == 0)
		return;

	gTraceOn = get_driver_boolean_parameter(handle, "trace", gTraceOn, true);
	gTraceState = get_driver_boolean_parameter(handle,
				"trace_state", gTraceState, true);
	gTraceRX = get_driver_boolean_parameter(handle, "trace_rx", gTraceRX, true);
	gTraceTX = get_driver_boolean_parameter(handle, "trace_tx", gTraceTX, true);
	gTraceStats = get_driver_boolean_parameter(handle,
				"trace_stats", gTraceStats, true);
	gTruncateLogFile = get_driver_boolean_parameter(handle,
				"reset_logfile", gTruncateLogFile, true);
	gAddTimeStamp = get_driver_boolean_parameter(handle,
				"add_timestamp", gAddTimeStamp, true);
	const char * logFilePath = get_driver_parameter(handle,
				"logfile", NULL, "/var/log/" DRIVER_NAME ".log");
	if (logFilePath != NULL) {
		gLogFilePath = strdup(logFilePath);
	}

	unload_driver_settings(handle);

	create_log();
}
Пример #3
0
static status_t
std_ops(int32 op, ...)
{
	void *handle;
	bool load = false;

	switch (op) {
	case B_MODULE_INIT:
		handle = load_driver_settings("kernel");
		if (handle) {
			load = get_driver_boolean_parameter(handle,
				"bochs_debug_output", load, true);
			unload_driver_settings(handle);
		}
		if (load) {
			if (get_module(B_ISA_MODULE_NAME, (module_info **)&sISAModule) < B_OK)
				return B_ERROR;
		}
		return load ? B_OK : B_ERROR;
	case B_MODULE_UNINIT:
		put_module(B_ISA_MODULE_NAME);
		return B_OK;
	}
	return B_BAD_VALUE;
}
bool
ReadMessageDriverSettings(const char *name, BMessage *message)
{
	if(!name || !message)
		return false;
	
	void *handle = load_driver_settings(name);
	if(!handle)
		return false;
	const driver_settings *settings = get_driver_settings(handle);
	if(!settings) {
		unload_driver_settings(handle);
		return false;
	}
	
	for(int32 index = 0; index < settings->parameter_count; index++) {
		BMessage parameter;
		AddParameter(&settings->parameters[index], &parameter);
		message->AddMessage(MDSU_PARAMETERS, &parameter);
	}
	
	unload_driver_settings(handle);
	
	return true;
}
Пример #5
0
static void
readSettings(struct sis_info *info)
{
	const char *parameter;

	void *handle = load_driver_settings("sis900");
	if (handle == NULL)
		return;

	parameter = get_driver_parameter(handle, "duplex", "auto", "auto");
	if (!strcasecmp(parameter, "full"))
		info->fixedMode = LINK_FULL_DUPLEX;
	else if (!strcasecmp(parameter, "half"))
		info->fixedMode = LINK_HALF_DUPLEX;

	parameter = get_driver_parameter(handle, "speed", "auto", "auto");
	if (!strcasecmp(parameter, "100"))
		info->fixedMode |= LINK_SPEED_100_MBIT;
	else if (!strcasecmp(parameter, "10"))
		info->fixedMode |= LINK_SPEED_10_MBIT;
	else if (!strcasecmp(parameter, "1"))
		info->fixedMode |= LINK_SPEED_HOME;

	// it's either all or nothing

	if ((info->fixedMode & LINK_DUPLEX_MASK) == 0
		|| (info->fixedMode & LINK_SPEED_MASK) == 0)
		info->fixedMode = 0;
	
	unload_driver_settings(handle);
}
Пример #6
0
status_t
read_midi_settings(struct midi_settings* settings)
{
	if (settings == NULL)
		return B_ERROR;

	BPath path;
	status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
	if (status != B_OK)
		return status;

	path.Append(SETTINGS_FILE);
	void* handle = load_driver_settings(path.Path());
	if (handle == NULL)
		return B_ERROR;

	const char* soundfont = get_driver_parameter(handle, "soundfont", NULL,
		NULL);
	if (soundfont == NULL)
		return B_ERROR;
	strlcpy(settings->soundfont_file, soundfont,
		sizeof(settings->soundfont_file));

	unload_driver_settings(handle);
	return B_OK;
}
Пример #7
0
status_t
arch_debug_console_init_settings(kernel_args *args)
{
	uint32 baudRate = kSerialBaudRate;
	uint16 basePort = sSerialBasePort;
	uint16 divisor;
	void *handle;

	// get debug settings
	handle = load_driver_settings("kernel");
	if (handle != NULL) {
		const char *value = get_driver_parameter(handle, "serial_debug_port",
			NULL, NULL);
		if (value != NULL) {
			int32 number = strtol(value, NULL, 0);
			if (number >= MAX_SERIAL_PORTS) {
				// use as port number directly
				basePort = number;
			} else if (number >= 0) {
				// use as index into port array
				if (args->platform_args.serial_base_ports[number] != 0)
					basePort = args->platform_args.serial_base_ports[number];
			} else {
				// ignore value and use default
			}
		}

		value = get_driver_parameter(handle, "serial_debug_speed", NULL, NULL);
		if (value != NULL) {
			int32 number = strtol(value, NULL, 0);
			switch (number) {
				case 9600:
				case 19200:
				case 38400:
				case 57600:
				case 115200:
				//case 230400:
					baudRate = number;
			}
		}

		unload_driver_settings(handle);
	}

	if (sSerialBasePort == basePort && baudRate == kSerialBaudRate)
		return B_OK;

	sSerialBasePort = basePort;
	divisor = (uint16)(115200 / baudRate);

	out8(0x80, sSerialBasePort + SERIAL_LINE_CONTROL);	/* set divisor latch access bit */
	out8(divisor & 0xf, sSerialBasePort + SERIAL_DIVISOR_LATCH_LOW);
	out8(divisor >> 8, sSerialBasePort + SERIAL_DIVISOR_LATCH_HIGH);
	out8(3, sSerialBasePort + SERIAL_LINE_CONTROL);		/* 8N1 */

	return B_OK;
}
Пример #8
0
status_t
PackageSettings::Load(dev_t mountPointDeviceID, ino_t mountPointNodeID,
	PackageFSMountType mountType)
{
	status_t error = fPackageItems.Init();
	if (error != B_OK)
		RETURN_ERROR(error);

	// get the mount point relative settings file path
	const char* settingsFilePath = mountType == PACKAGE_FS_MOUNT_TYPE_HOME
		? kUserSettingsGlobalDirectory "/packages"
			+ strlen(kUserConfigDirectory) + 1
		: kSystemSettingsDirectory "/packages" + strlen(kSystemDirectory) + 1;

	// get an absolute path
	KPath path;
	if (path.InitCheck() != B_OK)
		RETURN_ERROR(path.InitCheck());

	error = vfs_entry_ref_to_path(mountPointDeviceID, mountPointNodeID,
		NULL, true, path.LockBuffer(), path.BufferSize());
	if (error != B_OK)
		return error;
	path.UnlockBuffer();

	error = path.Append(settingsFilePath);
	if (error != B_OK)
		return error;

	// load the driver settings
	void* settingsHandle = load_driver_settings(path.Path());
	if (settingsHandle == NULL)
		return B_ENTRY_NOT_FOUND;
	CObjectDeleter<void, status_t> settingsDeleter(settingsHandle,
		&unload_driver_settings);

	const driver_settings* settings = get_driver_settings(settingsHandle);
	for (int i = 0; i < settings->parameter_count; i++) {
		const driver_parameter& parameter = settings->parameters[i];
		if (strcmp(parameter.name, "Package") != 0
			|| parameter.value_count < 1) {
			continue;
		}

		error = _AddPackageSettingsItem(parameter);
		// abort only in case of serious issues (memory shortage)
		if (error == B_NO_MEMORY)
			return error;
	}

	return B_OK;
}
Пример #9
0
static void
read_settings(bool &hardwareCursor)
{
    hardwareCursor = false;

    void* settings = load_driver_settings("intel_extreme");
    if (settings != NULL) {
        hardwareCursor = get_driver_boolean_parameter(settings,
                         "hardware_cursor", true, true);

        unload_driver_settings(settings);
    }
}
Пример #10
0
status_t
arch_debug_console_init_settings(kernel_args *args)
{
    uint32 baudRate = kSerialBaudRate;
    uint16 basePort = sSerialBasePort;
    void *handle;

    // get debug settings
    handle = load_driver_settings("kernel");
    if (handle != NULL) {
        const char *value = get_driver_parameter(handle, "serial_debug_port",
                            NULL, NULL);
        if (value != NULL) {
            int32 number = strtol(value, NULL, 0);
            if (number >= MAX_SERIAL_PORTS) {
                // use as port number directly
                basePort = number;
            } else if (number >= 0) {
                // use as index into port array
                if (args->platform_args.serial_base_ports[number] != 0)
                    basePort = args->platform_args.serial_base_ports[number];
            } else {
                // ignore value and use default
            }
        }

        value = get_driver_parameter(handle, "serial_debug_speed", NULL, NULL);
        if (value != NULL) {
            int32 number = strtol(value, NULL, 0);
            switch (number) {
            case 9600:
            case 19200:
            case 38400:
            case 57600:
            case 115200:
                //case 230400:
                baudRate = number;
            }
        }

        unload_driver_settings(handle);
    }

    if (sSerialBasePort == basePort && baudRate == kSerialBaudRate)
        return B_OK;

    init_serial_port(sSerialBasePort, kSerialBaudRate);

    return B_OK;
}
Пример #11
0
// Load
status_t
DriverSettings::Load(const char* driverName)
{
	Unset();
	fSettingsHandle = load_driver_settings(driverName);
	if (!fSettingsHandle)
		return B_ENTRY_NOT_FOUND;
	fSettings = get_driver_settings(fSettingsHandle);
	if (!fSettings) {
		Unset();
		return B_ERROR;
	}
	return B_OK;
}
Пример #12
0
void
elf_init()
{
// TODO: This cannot work, since the driver settings are loaded *after* the
// kernel has been loaded successfully.
#if 0
	void *settings = load_driver_settings("kernel");
	if (settings == NULL)
		return;

	sLoadElfSymbols = !get_driver_boolean_parameter(settings, "load_symbols",
		false, false);
	unload_driver_settings(settings);
#endif
}
Пример #13
0
void load_settings()
{
	void* handle = load_driver_settings(DRIVER_NAME);
	if (handle == 0)
		return;

	gTraceMask = strtoul(get_driver_parameter(handle, "trace", "1", "0"), 0, 0);
	gTruncateLogFile = get_driver_boolean_parameter(handle,	"truncate_logfile",
						gTruncateLogFile, true);
	gAddTimeStamp = get_driver_boolean_parameter(handle, "add_timestamp",
						gAddTimeStamp, true);
	const char* logFilePath = get_driver_parameter(handle, "logfile",
						NULL, "/var/log/" DRIVER_NAME ".log");
	if (logFilePath != NULL)
		gLogFilePath = strdup(logFilePath);

	unload_driver_settings(handle);

	create_log();
}
Пример #14
0
status_t load_settings(void)
{
	void *handle;
	const char *val;
	handle = load_driver_settings("googlefs");
	if (!handle)
		return ENOENT;

	dprintf("googlefs: loaded settings\n");

	val = get_driver_parameter(handle, "server", \
			DEFAULT_GOOGLE_SERVER, DEFAULT_GOOGLE_SERVER);
	strncpy(google_server, val, 20);
	google_server[20-1] = '\0';

	val = get_driver_parameter(handle, "port", "80", "80");
	google_server_port = strtoul(val, NULL, 10);

	val = get_driver_parameter(handle, "max_nodes", "5000", "5000");
	max_vnodes = strtoul(val, NULL, 10);
	max_vnodes = MIN(max_vnodes, 1000000);
	max_vnodes = MAX(max_vnodes, 10);

	val = get_driver_parameter(handle, "max_results", "50", "50");
	max_results = strtoul(val, NULL, 10);
	max_results = MIN(max_results, 1000);
	max_results = MAX(max_results, 5);

	sync_unlink_queries = get_driver_boolean_parameter(handle, "sync_unlink", false, true);

	dprintf("googlefs: settings: server = %s\n", google_server);
	dprintf("googlefs: settings: max_nodes = %lu\n", max_vnodes);
	dprintf("googlefs: settings: max_results = %lu\n", max_results);
	dprintf("googlefs: settings: sync_unlink = %c\n", sync_unlink_queries?'t':'f');
	unload_driver_settings(handle);
	return B_OK;
}
Пример #15
0
void
load_settings()
{
	void *settingsHandle;
	settingsHandle = load_driver_settings(DRIVER_NAME);

#if !DEBUG
	gLogEnabled = get_driver_boolean_parameter(settingsHandle,
		"debug_output", gLogEnabled, true);
#endif

	gLogToFile = get_driver_boolean_parameter(settingsHandle,
		"debug_output_in_file", gLogToFile, true);
	gLogAppend = !get_driver_boolean_parameter(settingsHandle,
		"debug_output_file_rewrite", !gLogAppend, true);
	gLogFunctionCalls = get_driver_boolean_parameter(settingsHandle,
		"debug_trace_func_calls", gLogFunctionCalls, false);
	gLogFunctionReturns = get_driver_boolean_parameter(settingsHandle,
		"debug_trace_func_returns", gLogFunctionReturns, false);
	gLogFunctionResults = get_driver_boolean_parameter(settingsHandle,
		"debug_trace_func_results", gLogFunctionResults, false);

	unload_driver_settings(settingsHandle);
}
Пример #16
0
extern "C" int
main(stage2_args *args)
{
	TRACE(("boot(): enter\n"));

	if (heap_init(args) < B_OK)
		panic("Could not initialize heap!\n");

	TRACE(("boot(): heap initialized...\n"));

	// set debug syslog default
#if KDEBUG_ENABLE_DEBUG_SYSLOG
	gKernelArgs.keep_debug_output_buffer = true;
#endif

	add_stage2_driver_settings(args);

	platform_init_video();

	// the main platform dependent initialisation
	// has already taken place at this point.

	if (vfs_init(args) < B_OK)
		panic("Could not initialize VFS!\n");

	dprintf("Welcome to the Haiku boot loader!\n");

	bool mountedAllVolumes = false;

	Directory *volume = get_boot_file_system(args);

	if (volume == NULL || (platform_boot_options() & BOOT_OPTION_MENU) != 0) {
		if (volume == NULL)
			puts("\tno boot path found, scan for all partitions...\n");

		if (mount_file_systems(args) < B_OK) {
			// That's unfortunate, but we still give the user the possibility
			// to insert a CD-ROM or just rescan the available devices
			puts("Could not locate any supported boot devices!\n");
		}

		// ToDo: check if there is only one bootable volume!

		mountedAllVolumes = true;

		if (user_menu(&volume) < B_OK) {
			// user requested to quit the loader
			goto out;
		}
	}

	if (volume != NULL) {
		// we got a volume to boot from!
		status_t status;
		while ((status = load_kernel(args, volume)) < B_OK) {
			// loading the kernel failed, so let the user choose another
			// volume to boot from until it works
			volume = NULL;

			if (!mountedAllVolumes) {
				// mount all other file systems, if not already happened
				if (mount_file_systems(args) < B_OK)
					panic("Could not locate any supported boot devices!\n");

				mountedAllVolumes = true;
			}

			if (user_menu(&volume) < B_OK || volume == NULL) {
				// user requested to quit the loader
				goto out;
			}
		}

		// if everything is okay, continue booting; the kernel
		// is already loaded at this point and we definitely
		// know our boot volume, too
		if (status == B_OK) {
			register_boot_file_system(volume);

			if ((platform_boot_options() & BOOT_OPTION_DEBUG_OUTPUT) == 0)
				platform_switch_to_logo();

			load_modules(args, volume);
			load_driver_settings(args, volume);

			// apply boot settings
			apply_boot_settings();

			// set up kernel args version info
			gKernelArgs.kernel_args_size = sizeof(kernel_args);
			gKernelArgs.version = CURRENT_KERNEL_ARGS_VERSION;

			// clone the boot_volume KMessage into kernel accessible memory
			// note, that we need to 4 byte align the buffer and thus allocate
			// 3 more bytes
			void* buffer = kernel_args_malloc(gBootVolume.ContentSize() + 3);
			if (!buffer) {
				panic("Could not allocate memory for the boot volume kernel "
					"arguments");
			}

			buffer = (void*)(((addr_t)buffer + 3) & ~(addr_t)0x3);
			memcpy(buffer, gBootVolume.Buffer(), gBootVolume.ContentSize());
			gKernelArgs.boot_volume = buffer;
			gKernelArgs.boot_volume_size = gBootVolume.ContentSize();

			// ToDo: cleanup, heap_release() etc.
			platform_start_kernel();
		}
	}

out:
	heap_release(args);
	return 0;
}
Пример #17
0
static void
GetDriverSettings(void)
{
	void *settings_handle = NULL;

	SHOW_FLOW0( 1, "" );
	
	// init settings to defaults;
	current_settings = def_settings;
	
	// get driver/accelerant settings, apsed
	settings_handle  = load_driver_settings ("radeon.settings");
	if (settings_handle != NULL) {
		const char *item;
		char       *end;
		uint32      value;

		item = get_driver_parameter (settings_handle, "loginfo", "2", "2");
		value = strtoul (item, &end, 0);
		if (*end == '\0' && value <= 4) {
			current_settings.loginfo = value;
			SHOW_INFO( 1, "Log Info Level now %ld/4", value );
		}
		
		item = get_driver_parameter (settings_handle, "logflow", "2", "2");
		value = strtoul (item, &end, 0);
		if (*end == '\0' && value <= 4) {
			current_settings.logflow = value;
			SHOW_INFO( 1, "Log Flow Level now %ld/4", value );
		}

		item = get_driver_parameter (settings_handle, "logerror", "2", "2");
		value = strtoul (item, &end, 0);
		if (*end == '\0' && value <= 4) {
			current_settings.logerror = value;
			SHOW_INFO( 1, "Log Error Level now %ld/4", value );
		}
		
		current_settings.switchhead = get_driver_boolean_parameter (settings_handle, "switchhead", false, false);
		current_settings.force_lcd = get_driver_boolean_parameter (settings_handle, "force_lcd", false, false);
		current_settings.dynamic_clocks = get_driver_boolean_parameter (settings_handle, "dynamic_clocks", true, true);
		current_settings.force_pci = get_driver_boolean_parameter (settings_handle, "force_pci", true, true);
		current_settings.unhide_fastwrites = get_driver_boolean_parameter (settings_handle, "unhide_fw", false, false);
		current_settings.force_acc_dma = get_driver_boolean_parameter (settings_handle, "force_acc_dma", false, false);
		current_settings.force_acc_mmio = get_driver_boolean_parameter (settings_handle, "force_acc_mmio", false, false);
		current_settings.acc_writeback = get_driver_boolean_parameter (settings_handle, "acc_writeback", false, false);

		if ( current_settings.switchhead != def_settings.switchhead )
			SHOW_INFO0( 1, "Switch Head = True" );
		if ( current_settings.force_lcd != def_settings.force_lcd )
			SHOW_INFO0( 1, "Force LCD ON" );
		if ( current_settings.dynamic_clocks != def_settings.dynamic_clocks )
			SHOW_INFO0( 1, "Mobility Power Saving Disabled (Dynamic Clocks)" );
		if ( current_settings.force_pci != def_settings.force_pci )
			SHOW_INFO0( 1, "Force PCI = True" );
		if ( current_settings.unhide_fastwrites != def_settings.unhide_fastwrites )
			SHOW_INFO0( 1, "use Fastwrites ON" );
		if ( current_settings.force_acc_dma != def_settings.force_acc_dma )
			SHOW_INFO0( 1, "DMA ACC Enabled" );
		if ( current_settings.force_acc_mmio != def_settings.force_acc_mmio )
			SHOW_INFO0( 1, "DMA ACC Disabled" );
		if ( current_settings.acc_writeback != def_settings.acc_writeback )
			SHOW_INFO0( 1, "DMA WriteBack Disabled" );
			
		unload_driver_settings (settings_handle);
	}
}
Пример #18
0
static status_t
acpi_std_ops(int32 op,...)
{
    switch (op) {
    case B_MODULE_INIT:
    {
        ACPI_OBJECT arg;
        ACPI_OBJECT_LIST parameter;
        void *settings;
        bool acpiDisabled = false;
        AcpiGbl_CopyDsdtLocally = true;

        settings = load_driver_settings("kernel");
        if (settings != NULL) {
            acpiDisabled = !get_driver_boolean_parameter(settings, "acpi",
                           true, true);
            unload_driver_settings(settings);
        }

        if (!acpiDisabled) {
            // check if safemode settings disable ACPI
            settings = load_driver_settings(B_SAFEMODE_DRIVER_SETTINGS);
            if (settings != NULL) {
                acpiDisabled = get_driver_boolean_parameter(settings,
                               B_SAFEMODE_DISABLE_ACPI, false, false);
                unload_driver_settings(settings);
            }
        }

        if (acpiDisabled) {
            ERROR("ACPI disabled\n");
            return ENOSYS;
        }

        if (gDPC->new_dpc_queue(&gDPCHandle, "acpi_task",
                                B_URGENT_DISPLAY_PRIORITY + 1) != B_OK) {
            ERROR("failed to create os execution queue\n");
            return B_ERROR;
        }

#ifdef ACPI_DEBUG_OUTPUT
        AcpiDbgLevel = ACPI_DEBUG_ALL | ACPI_LV_VERBOSE;
        AcpiDbgLayer = ACPI_ALL_COMPONENTS;
#endif

        if (checkAndLogFailure(AcpiInitializeSubsystem(),
                               "AcpiInitializeSubsystem failed"))
            goto err;

        if (checkAndLogFailure(AcpiInitializeTables(NULL, 0, TRUE),
                               "AcpiInitializeTables failed"))
            goto err;

        if (checkAndLogFailure(AcpiLoadTables(),
                               "AcpiLoadTables failed"))
            goto err;

        /* Install the default address space handlers. */
        if (checkAndLogFailure(AcpiInstallAddressSpaceHandler(
                                   ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_SYSTEM_MEMORY,
                                   ACPI_DEFAULT_HANDLER, NULL, NULL),
                               "Could not initialise SystemMemory handler:"))
            goto err;

        if (checkAndLogFailure(AcpiInstallAddressSpaceHandler(
                                   ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_SYSTEM_IO,
                                   ACPI_DEFAULT_HANDLER, NULL, NULL),
                               "Could not initialise SystemIO handler:"))
            goto err;

        if (checkAndLogFailure(AcpiInstallAddressSpaceHandler(
                                   ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_PCI_CONFIG,
                                   ACPI_DEFAULT_HANDLER, NULL, NULL),
                               "Could not initialise PciConfig handler:"))
            goto err;

        arg.Integer.Type = ACPI_TYPE_INTEGER;
        arg.Integer.Value = apic_available() ? APIC_MODE : PIC_MODE;

        parameter.Count = 1;
        parameter.Pointer = &arg;

        AcpiEvaluateObject(NULL, "\\_PIC", &parameter, NULL);

        if (checkAndLogFailure(AcpiEnableSubsystem(
                                   ACPI_FULL_INITIALIZATION),
                               "AcpiEnableSubsystem failed"))
            goto err;

        if (checkAndLogFailure(AcpiInitializeObjects(
                                   ACPI_FULL_INITIALIZATION),
                               "AcpiInitializeObjects failed"))
            goto err;

        //TODO: Walk namespace init ALL _PRW's

#ifdef ACPI_DEBUG_OUTPUT
        checkAndLogFailure(
            AcpiInstallGlobalEventHandler(globalGPEHandler, NULL),
            "Failed to install global GPE-handler.");

        checkAndLogFailure(AcpiInstallNotifyHandler(ACPI_ROOT_OBJECT,
                           ACPI_ALL_NOTIFY, globalNotifyHandler, NULL),
                           "Failed to install global Notify-handler.");
#endif
        checkAndLogFailure(AcpiEnableAllRuntimeGpes(),
                           "Failed to enable all runtime Gpes");

        checkAndLogFailure(AcpiUpdateAllGpes(),
                           "Failed to update all Gpes");

        TRACE("ACPI initialized\n");
        return B_OK;

err:
        return B_ERROR;
    }

    case B_MODULE_UNINIT:
    {
        if (checkAndLogFailure(AcpiTerminate(),
                               "Could not bring system out of ACPI mode. Oh well."));

        gDPC->delete_dpc_queue(gDPCHandle);
        gDPCHandle = NULL;
        break;
    }

    default:
        return B_ERROR;
    }
    return B_OK;
}
Пример #19
0
status_t
Settings::ReadSwapSettings()
{
	void* settings = load_driver_settings(kVirtualMemorySettings);
	if (settings == NULL)
		return kErrorSettingsNotFound;
	CObjectDeleter<void, status_t> settingDeleter(settings,
		&unload_driver_settings);

	const char* enabled = get_driver_parameter(settings, "vm", NULL, NULL);
	const char* automatic = get_driver_parameter(settings, "swap_auto",
		NULL, NULL);
	const char* size = get_driver_parameter(settings, "swap_size", NULL, NULL);
	const char* volume = get_driver_parameter(settings, "swap_volume_name",
		NULL, NULL);
	const char* device = get_driver_parameter(settings,
		"swap_volume_device", NULL, NULL);
	const char* filesystem = get_driver_parameter(settings,
		"swap_volume_filesystem", NULL, NULL);
	const char* capacity = get_driver_parameter(settings,
		"swap_volume_capacity", NULL, NULL);

	if (enabled == NULL	|| automatic == NULL || size == NULL || device == NULL
		|| volume == NULL || capacity == NULL || filesystem == NULL)
		return kErrorSettingsInvalid;

	off_t volCapacity = atoll(capacity);

	SetSwapEnabled(get_driver_boolean_parameter(settings,
		"vm", true, false));
	SetSwapAutomatic(get_driver_boolean_parameter(settings,
		"swap_auto", true, false));
	SetSwapSize(atoll(size));

	int32 bestScore = -1;
	dev_t bestVol = -1;

	BVolume vol;
	fs_info volStat;
	BVolumeRoster roster;
	while (roster.GetNextVolume(&vol) == B_OK) {
		if (!vol.IsPersistent() || vol.IsReadOnly() || vol.IsRemovable()
			|| vol.IsShared())
			continue;
		if (fs_stat_dev(vol.Device(), &volStat) == 0) {
			int32 score = 0;
			if (strcmp(volume, volStat.volume_name) == 0)
				score += 4;
			if (strcmp(device, volStat.device_name) == 0)
				score += 3;
			if (volCapacity == volStat.total_blocks * volStat.block_size)
				score += 2;
			if (strcmp(filesystem, volStat.fsh_name) == 0)
				score += 1;
			if (score >= 4 && score > bestScore) {
				bestVol = vol.Device();
				bestScore = score;
			}
		}
	}

	SetSwapVolume(bestVol);
	fInitialSettings = fCurrentSettings;

	if (bestVol < 0)
		return kErrorVolumeNotFound;

	return B_OK;
}
Пример #20
0
status_t
fs_mount(fs_volume *_vol, const char *device, ulong flags, const char *args,
	ino_t *_rootID)
{
	nspace *ns;
	vnode *newNode = NULL;
	char lockname[32];
	void *handle;
	unsigned long mountFlags = 0;
	status_t result = B_NO_ERROR;

	ERRPRINT("fs_mount - ENTER\n");

	ns = ntfs_malloc(sizeof(nspace));
	if (!ns) {
		result = ENOMEM;
		goto exit;
	}

	*ns = (nspace) {
		.state = NF_FreeClustersOutdate | NF_FreeMFTOutdate,
		.show_sys_files = false,
		.ro = false,
		.flags = 0
	};

	strcpy(ns->devicePath,device);

	sprintf(lockname, "ntfs_lock %lx", ns->id);
	recursive_lock_init_etc(&(ns->vlock), lockname, MUTEX_FLAG_CLONE_NAME);

	handle = load_driver_settings("ntfs");
	ns->show_sys_files = ! (strcasecmp(get_driver_parameter(handle,
		"hide_sys_files", "true", "true"), "true") == 0);
	ns->ro = strcasecmp(get_driver_parameter(handle, "read_only", "false",
		"false"), "false") != 0;
	ns->noatime = strcasecmp(get_driver_parameter(handle, "no_atime", "true",
		"true"), "true") == 0;
	unload_driver_settings(handle);

	if (ns->ro || (flags & B_MOUNT_READ_ONLY) != 0) {
		mountFlags |= MS_RDONLY;
		ns->flags |= B_FS_IS_READONLY;
	}

	// TODO: this does not take read-only volumes into account!
	ns->ntvol = utils_mount_volume(device, mountFlags, true);
	if (ns->ntvol != NULL)
		result = B_NO_ERROR;
	else
		result = errno;

	if (result == B_NO_ERROR) {
		*_rootID = FILE_root;
		ns->id = _vol->id;
		_vol->private_volume = (void *)ns;
		_vol->ops = &gNTFSVolumeOps;

		newNode = (vnode*)ntfs_calloc(sizeof(vnode));
		if (newNode == NULL)
			result = ENOMEM;
		else {
			newNode->vnid = *_rootID;
			newNode->parent_vnid = -1;

			result = publish_vnode(_vol, *_rootID, (void*)newNode,
				&gNTFSVnodeOps, S_IFDIR, 0);
			if (result != B_NO_ERROR) {
				free(ns);
				result = EINVAL;
				goto exit;
			} else {
				result = B_NO_ERROR;
				ntfs_mark_free_space_outdated(ns);
				ntfs_calc_free_space(ns);
			}
		}
	}

exit:
	ERRPRINT("fs_mount - EXIT, result code is %s\n", strerror(result));

	return result;
}


status_t
fs_unmount(fs_volume *_vol)
{
	nspace *ns = (nspace*)_vol->private_volume;
	status_t result = B_NO_ERROR;

	ERRPRINT("fs_unmount - ENTER\n");

	ntfs_umount(ns->ntvol, true);

	recursive_lock_destroy(&(ns->vlock));

	free(ns);

	ERRPRINT("fs_unmount - EXIT, result is %s\n", strerror(result));

	return result;
}
Пример #21
0
status_t
init_driver(void)
{
	void *settings;

	// get driver/accelerant settings
	settings = load_driver_settings(DRIVER_PREFIX ".settings");
	if (settings != NULL) {
		const char *item;
		char *end;
		uint32 value;

		// for driver
		item = get_driver_parameter(settings, "accelerant", "", "");
		if (item[0] && strlen(item) < sizeof(sSettings.accelerant) - 1)
			strcpy (sSettings.accelerant, item);

		item = get_driver_parameter(settings, "primary", "", "");
		if (item[0] && strlen(item) < sizeof(sSettings.primary) - 1)
			strcpy(sSettings.primary, item);

		sSettings.dumprom = get_driver_boolean_parameter(settings,
			"dumprom", false, false);

		// for accelerant
		item = get_driver_parameter(settings, "logmask",
			"0x00000000", "0x00000000");
		value = strtoul(item, &end, 0);
		if (*end == '\0')
			sSettings.logmask = value;

		item = get_driver_parameter(settings, "memory", "0", "0");
		value = strtoul(item, &end, 0);
		if (*end == '\0')
			sSettings.memory = value;

		sSettings.hardcursor = get_driver_boolean_parameter(settings,
			"hardcursor", false, false);
		sSettings.usebios = get_driver_boolean_parameter(settings,
			"usebios", false, false);
		sSettings.switchhead = get_driver_boolean_parameter(settings,
			"switchhead", false, false);
		sSettings.pgm_panel = get_driver_boolean_parameter(settings,
			"pgm_panel", false, false);
		sSettings.force_sync = get_driver_boolean_parameter(settings,
			"force_sync", false, false);
		sSettings.force_ws = get_driver_boolean_parameter(settings,
			"force_ws", false, false);

		item = get_driver_parameter(settings, "gpu_clk", "0", "0");
		value = strtoul(item, &end, 0);
		if (*end == '\0')
			sSettings.gpu_clk = value;

		item = get_driver_parameter(settings, "ram_clk", "0", "0");
		value = strtoul(item, &end, 0);
		if (*end == '\0')
			sSettings.ram_clk = value;

		unload_driver_settings(settings);
	}

	/* get a handle for the pci bus */
	if (get_module(B_PCI_MODULE_NAME, (module_info **)&pci_bus) != B_OK)
		return B_ERROR;

	/* get a handle for the isa bus */
	if (get_module(B_ISA_MODULE_NAME, (module_info **)&isa_bus) != B_OK) {
		put_module(B_PCI_MODULE_NAME);
		return B_ERROR;
	}

	/* driver private data */
	pd = (DeviceData *)calloc(1, sizeof(DeviceData));
	if (!pd) {
		put_module(B_PCI_MODULE_NAME);
		return B_ERROR;
	}
	/* initialize the benaphore */
	INIT_BEN(pd->kernel);
	/* find all of our supported devices */
	probe_devices();
	return B_OK;
}
Пример #22
0
status_t
init_driver(void) {
	void *settings_handle;

	// get driver/accelerant settings, apsed
	settings_handle  = load_driver_settings (DRIVER_PREFIX ".settings");
	if (settings_handle != NULL) {
		const char *item;
		char       *end;
		uint32      value;

		// for driver
		item = get_driver_parameter (settings_handle, "accelerant", "", "");
		if ((strlen (item) > 0) && (strlen (item) < sizeof (current_settings.accelerant) - 1)) {
			strcpy (current_settings.accelerant, item);
		}
		current_settings.dumprom = get_driver_boolean_parameter (settings_handle, "dumprom", false, false);

		// for accelerant
		item = get_driver_parameter (settings_handle, "logmask", "0x00000000", "0x00000000");
		value = strtoul (item, &end, 0);
		if (*end == '\0') current_settings.logmask = value;

		item = get_driver_parameter (settings_handle, "memory", "0", "0");
		value = strtoul (item, &end, 0);
		if (*end == '\0') current_settings.memory = value;

		current_settings.hardcursor = get_driver_boolean_parameter (settings_handle, "hardcursor", false, false);
		current_settings.usebios = get_driver_boolean_parameter (settings_handle, "usebios", false, false);
		current_settings.switchhead = get_driver_boolean_parameter (settings_handle, "switchhead", false, false);
		current_settings.force_pci = get_driver_boolean_parameter (settings_handle, "force_pci", false, false);
		current_settings.unhide_fw = get_driver_boolean_parameter (settings_handle, "unhide_fw", false, false);
		current_settings.pgm_panel = get_driver_boolean_parameter (settings_handle, "pgm_panel", false, false);

		unload_driver_settings (settings_handle);
	}

	/* get a handle for the pci bus */
	if (get_module(B_PCI_MODULE_NAME, (module_info **)&pci_bus) != B_OK)
		return B_ERROR;

	/* get a handle for the isa bus */
	if (get_module(B_ISA_MODULE_NAME, (module_info **)&isa_bus) != B_OK)
	{
		put_module(B_PCI_MODULE_NAME);
		return B_ERROR;
	}

	/* get a handle for the agp bus if it exists */
	get_module(B_AGP_GART_MODULE_NAME, (module_info **)&agp_bus);

	/* driver private data */
	pd = (DeviceData *)calloc(1, sizeof(DeviceData));
	if (!pd) {
		if (agp_bus)
			put_module(B_AGP_GART_MODULE_NAME);
		put_module(B_ISA_MODULE_NAME);
		put_module(B_PCI_MODULE_NAME);
		return B_ERROR;
	}
	/* initialize the benaphore */
	INIT_BEN(pd->kernel);
	/* find all of our supported devices */
	probe_devices();
	return B_OK;
}
status_t
pci_controller_init(void)
{
	bool search_mech1 = true;
	bool search_mech2 = true;
	bool search_bios = true;
	void *config = NULL;
	status_t status;

	status = pci_x86_irq_init();
	if (status != B_OK)
		return status;

	config = load_driver_settings("pci");
	if (config) {
		const char *mech = get_driver_parameter(config, "mechanism",
			NULL, NULL);
		if (mech) {
			search_mech1 = search_mech2 = search_bios = false;
			if (strcmp(mech, "1") == 0)
				search_mech1 = true;
			else if (strcmp(mech, "2") == 0)
				search_mech2 = true;
			else if (strcmp(mech, "bios") == 0)
				search_bios = true;
			else
				panic("Unknown pci config mechanism setting %s\n", mech);
		}
		unload_driver_settings(config);
	}

	// TODO: check safemode "don't call the BIOS" setting and unset search_bios!

	// PCI configuration mechanism 1 is the preferred one.
	// If it doesn't work, try mechanism 2.
	// Finally, try to fallback to PCI BIOS

	if (search_mech1) {
		// check for mechanism 1
		out32(0x80000000, PCI_MECH1_REQ_PORT);
		if (0x80000000 == in32(PCI_MECH1_REQ_PORT)) {
			dprintf("PCI: mechanism 1 controller found\n");
			return pci_controller_add(&pci_controller_x86_mech1, NULL);
		}
	}

	if (search_mech2) {
		// check for mechanism 2
		out8(0x00, 0xCFB);
		out8(0x00, 0xCF8);
		out8(0x00, 0xCFA);
		if (in8(0xCF8) == 0x00 && in8(0xCFA) == 0x00) {
			dprintf("PCI: mechanism 2 controller found\n");
			return pci_controller_add(&pci_controller_x86_mech2, NULL);
		}
	}

	if (search_bios) {
		// check for PCI BIOS
		if (pci_bios_init() == B_OK) {
			dprintf("PCI: BIOS support found\n");
			return pci_controller_add(&pci_controller_x86_bios, NULL);
		}
	}

	dprintf("PCI: no configuration mechanism found\n");
	return B_ERROR;
}
Пример #24
0
/*!	ReadConfiguration pulls the current interface settings
	from the interfaces via BNetworkInterface and friends
	and populates this classes private settings BAddresses
	with them.
*/
void
NetworkSettings::ReadConfiguration()
{
	fDisabled = (fNetworkInterface->Flags() & IFF_UP) == 0;

	for (int index = 0; index < MAX_PROTOCOLS; index++) {
		int inet_id = fProtocols[index].inet_id;

		if (fProtocols[index].present) {
			// --- Obtain IP Addresses
			int32 zeroAddr = fNetworkInterface->FindFirstAddress(inet_id);
			if (zeroAddr >= 0) {
				fNetworkInterface->GetAddressAt(zeroAddr,
					fInterfaceAddressMap[inet_id]);
				fAddress[inet_id].SetTo(
					fInterfaceAddressMap[inet_id].Address());
				fNetmask[inet_id].SetTo(
					fInterfaceAddressMap[inet_id].Mask());
			}

			// --- Obtain gateway
			// TODO : maybe in the future no ioctls?
			ifconf config;
			config.ifc_len = sizeof(config.ifc_value);
			// Populate config with size of routing table
			if (ioctl(fProtocols[index].socket_id, SIOCGRTSIZE,
				&config, sizeof(config)) < 0)
				return;

			uint32 size = (uint32)config.ifc_value;
			if (size == 0)
				return;

			// Malloc a buffer the size of the routing table
			void* buffer = malloc(size);
			if (buffer == NULL)
				return;

			MemoryDeleter bufferDeleter(buffer);
			config.ifc_len = size;
			config.ifc_buf = buffer;

			if (ioctl(fProtocols[index].socket_id, SIOCGRTTABLE,
				&config, sizeof(config)) < 0)
				return;

			ifreq* interface = (ifreq*)buffer;
			ifreq* end = (ifreq*)((uint8*)buffer + size);

			while (interface < end) {
				route_entry& route = interface->ifr_route;

				if ((route.flags & RTF_GATEWAY) != 0) {
					if (inet_id == AF_INET) {
						char addressOut[INET_ADDRSTRLEN];
						sockaddr_in* socketAddr
							= (sockaddr_in*)route.gateway;

						inet_ntop(inet_id, &socketAddr->sin_addr,
							addressOut, INET_ADDRSTRLEN);

						fGateway[inet_id].SetTo(addressOut);

					} else if (inet_id == AF_INET6) {
						char addressOut[INET6_ADDRSTRLEN];
						sockaddr_in6* socketAddr
							= (sockaddr_in6*)route.gateway;

						inet_ntop(inet_id, &socketAddr->sin6_addr,
							addressOut, INET6_ADDRSTRLEN);

						fGateway[inet_id].SetTo(addressOut);

					} else {
						printf("Cannot pull routes for unknown protocol: %d\n",
							inet_id);
						fGateway[inet_id].SetTo("");
					}

				}

				int32 addressSize = 0;
				if (route.destination != NULL)
					addressSize += route.destination->sa_len;
				if (route.mask != NULL)
					addressSize += route.mask->sa_len;
				if (route.gateway != NULL)
					addressSize += route.gateway->sa_len;

				interface = (ifreq *)((addr_t)interface + IF_NAMESIZE
					+ sizeof(route_entry) + addressSize);
			}

			// --- Obtain selfconfiguration options
			// TODO : This needs to be determined by protocol flags
			//        AutoConfiguration on the IP level doesn't exist yet
			//		  ( fInterfaceAddressMap[AF_INET].Flags() )
			if (fProtocols[index].socket_id >= 0) {
				fAutoConfigure[inet_id] = (fNetworkInterface->Flags()
					& (IFF_AUTO_CONFIGURED | IFF_CONFIGURING)) != 0;
			}
		}
	}

	// Read wireless network from interfaces
	fWirelessNetwork.SetTo(NULL);

	BPath path;
	find_directory(B_SYSTEM_SETTINGS_DIRECTORY, &path);
	path.Append("network");
	path.Append("interfaces");

	void* handle = load_driver_settings(path.Path());
	if (handle != NULL) {
		const driver_settings* settings = get_driver_settings(handle);
		if (settings != NULL) {
			for (int32 i = 0; i < settings->parameter_count; i++) {
				driver_parameter& top = settings->parameters[i];
				if (!strcmp(top.name, "interface")) {
					// The name of the interface can either be the value of
					// the "interface" parameter, or a separate "name" parameter
					const char* name = NULL;
					if (top.value_count > 0) {
						name = top.values[0];
						if (fName != name)
							continue;
					}

					// search "network" parameter
					for (int32 j = 0; j < top.parameter_count; j++) {
						driver_parameter& sub = top.parameters[j];
						if (name == NULL && !strcmp(sub.name, "name")
							&& sub.value_count > 0) {
							name = sub.values[0];
							if (fName != sub.values[0])
								break;
						}

						if (!strcmp(sub.name, "network")
							&& sub.value_count > 0) {
							fWirelessNetwork.SetTo(sub.values[0]);
							break;
						}
					}

					// We found our interface
					if (fName == name)
						break;
				}
			}
		}
		unload_driver_settings(handle);
	}

	// read resolv.conf for the dns.
	fNameServers.MakeEmpty();

	res_init();
	res_state state = __res_state();

	if (state != NULL) {
		for (int i = 0; i < state->nscount; i++) {
			fNameServers.AddItem(
				new BString(inet_ntoa(state->nsaddr_list[i].sin_addr)));
		}
		fDomain = state->dnsrch[0];
	}
}