Пример #1
0
int create_device_partition( int fd, const char* device, int index, off_t offset, uint64_t size ) {
    int error;
    char path[ 128 ];
    partition_node_t* node;

    node = ( partition_node_t* )kmalloc( sizeof( partition_node_t ) );

    if ( node == NULL ) {
        return -ENOMEM;
    }

    snprintf( path, sizeof( path ), "storage/partition/%s%d", device, index );

    node->fd = fd;
    node->offset = offset;
    node->size = size;

    error = create_device_node( path, &partition_calls, ( void* )node );

    if ( error < 0 ) {
        return error;
    }

    kprintf( INFO, "/device/%s, size: %u Mb\n", path, node->size / 1000000 );

    return 0;
}
Пример #2
0
Файл: kbd.c Проект: PyroOS/Pyro
status_t device_init( int nDeviceID )
{
    int nError;
    int nHandle;
    printk( "Keyboard device: device_init() called\n" );

    g_sVolume.hWaitThread    = -1;
    atomic_set( &g_sVolume.nInPos, 0 );
    atomic_set( &g_sVolume.nOutPos, 0 );
    atomic_set( &g_sVolume.nBytesReceived, 0 );
    atomic_set( &g_sVolume.nOpenCount, 0 );
    g_sVolume.nIrqHandle	   = request_irq( 1, kbd_irq, NULL, 0, "keyboard_device", NULL );

    g_nKbdLedStatus = 0;
  
    if ( g_sVolume.nIrqHandle < 0 ) {
	printk( "ERROR : Failed to initiate keyboard interrupt handler\n" );
	return( g_sVolume.nIrqHandle );
    }
    
	nHandle = register_device( "", "system" );
	claim_device( nDeviceID, nHandle , "Keyboard", DEVICE_INPUT );
    nError = create_device_node( nDeviceID, nHandle, "keybd", &g_sOperations, NULL );
    
    return( nError );
}
Пример #3
0
status_t device_init( int nDeviceID )
{
    int nError;
    nError = create_device_node( nDeviceID, -1, "devices", &g_sOperations, NULL );
    if ( nError < 0 ) {
	return( nError );
    }
    
    return( 0 );
}
Пример #4
0
Файл: ps2.c Проект: PyroOS/Pyro
/* Initializes the controller and the keyboard part */
static status_t ps2_keyboard_init()
{
	int nError = 0;
	g_nKbdLedStatus = 0;
	
	memset( &g_sKbdPort, 0, sizeof( g_sKbdPort ) );
	
	/* Flush buffer */
	ps2_flush();
	
	/* Read control register */
	uint8 nControl = 0;
	nError = ps2_read_command( PS2_CMD_RCTR, &nControl );
	
	if( nError < 0 ) {
		printk( "PS2 I/O error\n" );
		return( -EIO );
	}
	
	/* TODO: Disable keyboard */
	nControl |= PS2_CTR_KBDDIS;
	nControl &= ~PS2_CTR_KBDINT;
	
	/* Check if translated mode is enabled */
	if( !( nControl & PS2_CTR_XLATE ) )
	{
		printk( "Keyboard is in non-translated mode. This is not supported\n" );
		return( -ENOENT );
	}
	
	/* Write control register */
	nError = ps2_write_command( PS2_CMD_WCTR, nControl );
	if( nError < 0 ) {
		printk( "PS2 I/O error\n" );
		return( -EIO );
	}
	
	g_sKbdPort.bPresent = true;
	g_sKbdPort.hWait = create_semaphore( "ps2_wait", 0, 0 );
	g_sKbdPort.nIrq = 1;
	g_sKbdPort.nDevHandle = register_device( "", "isa" );
	claim_device( g_nDevNum, g_sKbdPort.nDevHandle, "PS/2 or AT keyboard", DEVICE_INPUT );
	set_device_data( g_sKbdPort.nDevHandle, &g_sKbdPort );
	nError = create_device_node( g_nDevNum, g_sKbdPort.nDevHandle, "keybd", &g_sOperations, &g_sKbdPort );
	
	printk( "PS2 or AT Keyboard detected\n" );
	return( 0 );
}
Пример #5
0
/*
 * The 'divecomputerid' is a bit harder to parse than some other things, because
 * it can have multiple strings (but see the tag parsing for another example of
 * that) in addition to the non-string entries.
 *
 * We keep the "next" string in "id.cstr" and update it as we use it.
 */
static void parse_settings_divecomputerid(char *line, struct membuffer *str, void *_unused)
{
	struct divecomputerid id = { mb_cstring(str) };

	id.cstr = id.model + strlen(id.model) + 1;

	/* Skip the '"' that stood for the model string */
	line++;

	for (;;) {
		char c;
		while (isspace(c = *line))
			line++;
		if (!c)
			break;
		line = parse_keyvalue_entry(parse_divecomputerid_keyvalue, &id, line);
	}
	create_device_node(id.model, id.deviceid, id.serial, id.firmware, id.nickname);
}
Пример #6
0
status_t device_init( int nDeviceID )
{
	PCI_bus_s *psBus;
	int nNumDevices = sizeof( g_sDevices ) / sizeof( struct gfx_device );
	int nDeviceNum;
	PCI_Info_s sInfo;
	int nPCINum;
	char zTemp[255];
	char zNodePath[255];
	struct gfx_node *psNode;
	bool bDevFound = false;

	/* Get PCI busmanager */
	psBus = get_busmanager( PCI_BUS_NAME, PCI_BUS_VERSION );
	if( psBus == NULL )
		return ( -ENODEV );

	/* Look for the device */
	for( nPCINum = 0; psBus->get_pci_info( &sInfo, nPCINum ) == 0; ++nPCINum )
	{
		for( nDeviceNum = 0; nDeviceNum < nNumDevices; ++nDeviceNum )
		{
			/* Compare vendor and device id */
			if( sInfo.nVendorID == g_sDevices[nDeviceNum].nVendorID && sInfo.nDeviceID == g_sDevices[nDeviceNum].nDeviceID )
			{
				sprintf( zTemp, "%s %s", g_sDevices[nDeviceNum].zVendorName, g_sDevices[nDeviceNum].zDeviceName );
				if( claim_device( nDeviceID, sInfo.nHandle, zTemp, DEVICE_VIDEO ) != 0 )
				{
					continue;
				}

				printk( "%s found\n", zTemp );

				/* Create private node */
				psNode = kmalloc( sizeof( struct gfx_node ), MEMF_KERNEL | MEMF_CLEAR | MEMF_NOBLOCK );
				if( psNode == NULL )
				{
					printk( "Error: Out of memory\n" );
					continue;
				}
				memcpy( &psNode->sInfo, &sInfo, sizeof( PCI_Info_s ) );
				strcpy( psNode->zName, zTemp );

				/* Create node path */
				sprintf( zNodePath, "graphics/tdfx_%i_0x%x_0x%x", nPCINum, ( uint )sInfo.nVendorID, ( uint )sInfo.nDeviceID );

				if( create_device_node( nDeviceID, sInfo.nHandle, zNodePath, &g_sOperations, psNode ) < 0 )
				{
					printk( "Error: Failed to create device node %s\n", zNodePath );
					continue;
				}

				bDevFound = true;
			}
		}
	}

	if( !bDevFound )
	{
		disable_device( nDeviceID );
		return ( -ENODEV );
	}

	return ( 0 );
}
Пример #7
0
Файл: ps2.c Проект: PyroOS/Pyro
static status_t ps2_aux_init()
{
	int nError = 0;
	struct RMREGS rm;

	/* TODO: Do this without calling the bios */
	memset( &rm, 0, sizeof( struct RMREGS ) );
	realint( 0x11, &rm );

	if( ( rm.EAX & 0x04 ) == 0 ) {
		printk( "No PS2 mouse present\n" );
		return( -EIO );
    }
	
	memset( &g_sAuxPort, 0, sizeof( g_sAuxPort ) );
	g_sAuxPort.bIsAux = true;
	
	/* Flush buffer */
	ps2_flush();
	
	/* Test loop command */
	uint8 nData = 0x5a;
	
	nError = ps2_write_read_command( PS2_CMD_AUX_LOOP, &nData );
	
	if( nError < 0 || nData != 0x5a )
	{
		/* According to linux driver the loop test fails on some chipsets */
		printk( "PS2 Aux loop test failed (error = %i, data = %x)! Trying test command...\n", nError, (uint)nData );
		if( ps2_read_command( PS2_CMD_AUX_TEST, &nData ) < 0 )
		{
			printk( "Failed -> Aux port not present!\n" );
			return( -ENOENT );
		}
		printk( "Test command returned %x\n", (uint)nData );
		if( nData && nData != 0xfa && nData != 0xff )
		{
			printk( "Invalid return code!\n" );
			return( -ENOENT );
		}
	}
	
	/* Disable and then enable the auxport */
	if( ps2_command( PS2_CMD_AUX_DISABLE ) < 0 )
		return( -ENOENT );
	if( ps2_command( PS2_CMD_AUX_ENABLE ) < 0 )
		return( -ENOENT );
	if( ps2_read_command( PS2_CMD_RCTR, &nData ) < 0 || ( nData & PS2_CTR_AUXDIS ) )
		return( -EIO );
		
	/* Disable aux port */
	nData |= PS2_CTR_AUXDIS;
	nData &= ~PS2_CTR_AUXINT;
	
	/* Write control register */
	nError = ps2_write_command( PS2_CMD_WCTR, nData );
	if( nError < 0 ) {
		printk( "PS2 I/O error\n" );
		return( -EIO );
	}

	printk( "PS2 AUX port detected\n" );
	
	/* Register device */
	
	g_sAuxPort.bPresent = true;
	g_sAuxPort.hWait = create_semaphore( "ps2_wait", 0, 0 );
	g_sAuxPort.nDevHandle = register_device( "", "isa" );
	g_sAuxPort.nIrq = 12;
	claim_device( g_nDevNum, g_sAuxPort.nDevHandle, "PS/2 Aux port", DEVICE_PORT );
	set_device_data( g_sAuxPort.nDevHandle, &g_sAuxPort );
	nError = create_device_node( g_nDevNum, g_sAuxPort.nDevHandle, "misc/ps2aux", &g_sOperations, &g_sAuxPort );
	
	if( nError < 0 )
		return( -EIO );
	
	return( 0 );
}