Ejemplo n.º 1
0
status_t
init_driver()
{
    status_t status = get_module(B_PCI_MODULE_NAME, (module_info**)&gPCIModule);
    if (status < B_OK) {
        return ENOSYS;
    }

    load_settings();

    TRACE_ALWAYS("%s\n", kVersion);

    pci_info info = {0};
    for (long i = 0; B_OK == (*gPCIModule->get_nth_pci_info)(i, &info); i++) {
        for (size_t idx = 0; idx < _countof(cardInfos); idx++) {
            if (info.vendor_id == cardInfos[idx].VendorId()
                    && info.device_id == cardInfos[idx].DeviceId())
            {
                TRACE_ALWAYS("Found:%s %#010x\n",
                             cardInfos[idx].Description(), cardInfos[idx].Id());

                if (numCards == MAX_DEVICES) {
                    break;
                }

                Device* device = new Device(cardInfos[idx], info);
                if (device == 0) {
                    return ENODEV;
                }

                status_t status = device->InitCheck();
                if (status < B_OK) {
                    delete device;
                    break;
                }

                status = device->SetupDevice();
                if (status < B_OK) {
                    delete device;
                    break;
                }

                char name[DEVNAME_LEN] = {0};
                sprintf(name, "net/%s/%ld", cardInfos[idx].Name(), numCards);
                gDeviceNames[numCards] = strdup(name);
                gDevices[numCards++] = device;
            }
        }
    }

    if (numCards == 0) {
        put_module(B_PCI_MODULE_NAME);
        return ENODEV;
    }

    add_debugger_command(DRIVER_NAME, SiS19X_DebuggerCommand,
                         "SiS190/191 Ethernet driver info");

    return B_OK;
}
Ejemplo n.º 2
0
static status_t
publish_device(device_node *node, const char *path, const char *moduleName)
{
	if (path == NULL || !path[0] || moduleName == NULL || !moduleName[0])
		return B_BAD_VALUE;

	RecursiveLocker _(sLock);
	dprintf("publish device: node %p, path %s, module %s\n", node, path,
		moduleName);

	Device* device = new(std::nothrow) Device(node, moduleName);
	if (device == NULL)
		return B_NO_MEMORY;

	status_t status = device->InitCheck();
	if (status == B_OK)
		status = devfs_publish_device(path, device);
	if (status != B_OK) {
		delete device;
		return status;
	}

	node->AddDevice(device);
	return B_OK;
}
Ejemplo n.º 3
0
status_t
init_driver()
{
	status_t status = get_module(B_PCI_MODULE_NAME, (module_info **)&gPCI);
	if (status < B_OK) {
		return ENOSYS;
	}

	load_settings();

	pci_info info = { 0 };
	for (long i = 0; B_OK == (*gPCI->get_nth_pci_info)(i, &info); i++) {
		for (size_t idx = 0; idx < _countof(cardInfos); idx++) {
			if (info.vendor_id == cardInfos[idx].VendorId() &&
				info.device_id == cardInfos[idx].DeviceId())
			{
				if (gNumCards == MAX_DEVICES) {
					ERROR("Skipped:%s [%#06x:%#06x]\n", cardInfos[idx].Name(),
						cardInfos[idx].VendorId(), cardInfos[idx].DeviceId());
					break;
				}

				Device* device = new Device(cardInfos[idx], info);
				if (device == 0) {
					return ENODEV;
				}

				status_t status = device->InitCheck();
				if (status < B_OK) {
					delete device;
					break;
				}

				status = device->Setup();
				if (status < B_OK) {
					delete device;
					break;
				}

				char name[32] = {0};
				sprintf(name, "audio/hmulti/%s/%ld",
								cardInfos[idx].Name(), gNumCards);
				gDeviceNames[gNumCards] = strdup(name);
				gDevices[gNumCards++] = device;

				TRACE("Found:%s [%#06x:%#06x]\n", cardInfos[idx].Name(),
						cardInfos[idx].VendorId(), cardInfos[idx].DeviceId());
			}
		}
	}

	if (gNumCards == 0) {
		put_module(B_PCI_MODULE_NAME);
		return ENODEV;
	}

	return B_OK;
}
Ejemplo n.º 4
0
status_t
usb_audio_device_added(usb_device device, void **cookie)
{
	*cookie = NULL;

	DriverSmartLock driverLock; // released on exit

	// check if this is a replug of an existing device first
	for (int32 i = 0; i < MAX_DEVICES; i++) {
		if (gDevices[i] == NULL)
			continue;

		if (gDevices[i]->CompareAndReattach(device) != B_OK)
			continue;

		TRACE("The device is plugged back. Use entry at %ld.\n", i);
		*cookie = gDevices[i];
		return B_OK;
	}

	// no such device yet, create a new one
	Device *audioDevice = new Device(device);
	if (audioDevice == 0) {
		return ENODEV;
	}

	status_t status = audioDevice->InitCheck();
	if (status < B_OK) {
		delete audioDevice;
		return status;
	}

	status = audioDevice->SetupDevice(false);
	if (status < B_OK) {
		delete audioDevice;
		return status;
	}

	for (int32 i = 0; i < MAX_DEVICES; i++) {
		if (gDevices[i] != NULL)
			continue;

		gDevices[i] = audioDevice;
		*cookie = audioDevice;

		TRACE("New device is added at %ld.\n", i);
		return B_OK;
	}

	// no space for the device
	TRACE_ALWAYS("Error: no more device entries availble.\n");

	delete audioDevice;
	return B_ERROR;
}