FreeBSD/sys/dev/vkbd/vkbd.c
/* Some useful control functions (stolen from atkbd.c) */
Some useful control functions (stolen from atkbd.c)
Some useful control functions ( stolen from atkbd . c )
static int
vkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg)
{
	vkbd_state_t	*state = (vkbd_state_t *) kbd->kb_data;
	int		 i;
#ifdef COMPAT_FREEBSD6
	int		 ival;
#endif
	VKBD_LOCK(state);
	switch (cmd) {
	case KDGKBMODE:		
		*(int *)arg = state->ks_mode;
		break;
#ifdef COMPAT_FREEBSD6
	case _IO('K', 7):
		ival = IOCPARM_IVAL(arg);
		arg = (caddr_t)&ival;
#endif
	case KDSKBMODE:		
		switch (*(int *)arg) {
		case K_XLATE:
			if (state->ks_mode != K_XLATE) {
				state->ks_state &= ~LOCK_MASK;
				state->ks_state |= KBD_LED_VAL(kbd);
				vkbd_status_changed(state);
			}
		case K_RAW:
		case K_CODE:
			if (state->ks_mode != *(int *)arg) {
				vkbd_clear_state_locked(state);
				state->ks_mode = *(int *)arg;
				vkbd_status_changed(state);
			}
			break;
		default:
			VKBD_UNLOCK(state);
			return (EINVAL);
		}
		break;
	case KDGETLED:		
		*(int *)arg = KBD_LED_VAL(kbd);
		break;
#ifdef COMPAT_FREEBSD6
	case _IO('K', 66):
		ival = IOCPARM_IVAL(arg);
		arg = (caddr_t)&ival;
#endif
	case KDSETLED:		
		if (*(int *)arg & ~LOCK_MASK) {
			VKBD_UNLOCK(state);
			return (EINVAL);
		}
		i = *(int *)arg;
		if (state->ks_mode == K_XLATE &&
		    kbd->kb_keymap->n_keys > ALTGR_OFFSET) {
			if (i & ALKED)
				i |= CLKED;
			else
				i &= ~CLKED;
		}
		KBD_LED_VAL(kbd) = *(int *)arg;
		vkbd_status_changed(state);
		break;
	case KDGKBSTATE:	
		*(int *)arg = state->ks_state & LOCK_MASK;
		break;
#ifdef COMPAT_FREEBSD6
	case _IO('K', 20):
		ival = IOCPARM_IVAL(arg);
		arg = (caddr_t)&ival;
#endif
	case KDSKBSTATE:	
		if (*(int *)arg & ~LOCK_MASK) {
			VKBD_UNLOCK(state);
			return (EINVAL);
		}
		state->ks_state &= ~LOCK_MASK;
		state->ks_state |= *(int *)arg;
		vkbd_status_changed(state);
		VKBD_UNLOCK(state);
		return (vkbd_ioctl(kbd, KDSETLED, arg));
	case KDSETREPEAT:	
		i = typematic(((int *)arg)[0], ((int *)arg)[1]);
		kbd->kb_delay1 = typematic_delay(i);
		kbd->kb_delay2 = typematic_rate(i);
		vkbd_status_changed(state);
		break;
#ifdef COMPAT_FREEBSD6
	case _IO('K', 67):
		ival = IOCPARM_IVAL(arg);
		arg = (caddr_t)&ival;
#endif
	case KDSETRAD:		
		kbd->kb_delay1 = typematic_delay(*(int *)arg);
		kbd->kb_delay2 = typematic_rate(*(int *)arg);
		vkbd_status_changed(state);
		break;
	case PIO_KEYMAP:	
	case OPIO_KEYMAP:	
	case PIO_KEYMAPENT:	
	case PIO_DEADKEYMAP:	
		state->ks_accents = 0;
	default:
		VKBD_UNLOCK(state);
		return (genkbd_commonioctl(kbd, cmd, arg));
	}
	VKBD_UNLOCK(state);
	return (0);
}
static int vkbd_ioctl ( keyboard_t * kbd , u_long cmd , caddr_t arg ) { vkbd_state_t * state = ( vkbd_state_t * ) kbd -> kb_data ; int i ; #ifdef COMPAT_FREEBSD6 int ival ; #endif VKBD_LOCK ( state ) ; switch ( cmd ) { case KDGKBMODE : * ( int * ) arg = state -> ks_mode ; break ; #ifdef COMPAT_FREEBSD6 case _IO ( ' ' , 7 ) : ival = IOCPARM_IVAL ( arg ) ; arg = ( caddr_t ) & ival ; #endif case KDSKBMODE : switch ( * ( int * ) arg ) { case K_XLATE : if ( state -> ks_mode != K_XLATE ) { state -> ks_state &= ~ LOCK_MASK ; state -> ks_state |= KBD_LED_VAL ( kbd ) ; vkbd_status_changed ( state ) ; } case K_RAW : case K_CODE : if ( state -> ks_mode != * ( int * ) arg ) { vkbd_clear_state_locked ( state ) ; state -> ks_mode = * ( int * ) arg ; vkbd_status_changed ( state ) ; } break ; default : VKBD_UNLOCK ( state ) ; return ( EINVAL ) ; } break ; case KDGETLED : * ( int * ) arg = KBD_LED_VAL ( kbd ) ; break ; #ifdef COMPAT_FREEBSD6 case _IO ( ' ' , 66 ) : ival = IOCPARM_IVAL ( arg ) ; arg = ( caddr_t ) & ival ; #endif case KDSETLED : if ( * ( int * ) arg & ~ LOCK_MASK ) { VKBD_UNLOCK ( state ) ; return ( EINVAL ) ; } i = * ( int * ) arg ; if ( state -> ks_mode == K_XLATE && kbd -> kb_keymap -> n_keys > ALTGR_OFFSET ) { if ( i & ALKED ) i |= CLKED ; else i &= ~ CLKED ; } KBD_LED_VAL ( kbd ) = * ( int * ) arg ; vkbd_status_changed ( state ) ; break ; case KDGKBSTATE : * ( int * ) arg = state -> ks_state & LOCK_MASK ; break ; #ifdef COMPAT_FREEBSD6 case _IO ( ' ' , 20 ) : ival = IOCPARM_IVAL ( arg ) ; arg = ( caddr_t ) & ival ; #endif case KDSKBSTATE : if ( * ( int * ) arg & ~ LOCK_MASK ) { VKBD_UNLOCK ( state ) ; return ( EINVAL ) ; } state -> ks_state &= ~ LOCK_MASK ; state -> ks_state |= * ( int * ) arg ; vkbd_status_changed ( state ) ; VKBD_UNLOCK ( state ) ; return ( vkbd_ioctl ( kbd , KDSETLED , arg ) ) ; case KDSETREPEAT : i = typematic ( ( ( int * ) arg ) [ 0 ] , ( ( int * ) arg ) [ 1 ] ) ; kbd -> kb_delay1 = typematic_delay ( i ) ; kbd -> kb_delay2 = typematic_rate ( i ) ; vkbd_status_changed ( state ) ; break ; #ifdef COMPAT_FREEBSD6 case _IO ( ' ' , 67 ) : ival = IOCPARM_IVAL ( arg ) ; arg = ( caddr_t ) & ival ; #endif case KDSETRAD : kbd -> kb_delay1 = typematic_delay ( * ( int * ) arg ) ; kbd -> kb_delay2 = typematic_rate ( * ( int * ) arg ) ; vkbd_status_changed ( state ) ; break ; case PIO_KEYMAP : case OPIO_KEYMAP : case PIO_KEYMAPENT : case PIO_DEADKEYMAP : state -> ks_accents = 0 ; default : VKBD_UNLOCK ( state ) ; return ( genkbd_commonioctl ( kbd , cmd , arg ) ) ; } VKBD_UNLOCK ( state ) ; return ( 0 ) ; }
Some useful control functions (stolen from atkbd.c)
Some useful control functions ( stolen from atkbd . c )
/* get keyboard mode */ /* FALLTHROUGH */ /* set keyboard mode */ /* make lock key state and LED state match */ /* FALLTHROUGH */ /* get keyboard LED */ /* FALLTHROUGH */ /* set keyboard LED */ /* NOTE: lock key state in ks_state won't be changed */ /* replace CAPS LED with ALTGR LED for ALTGR keyboards */ /* get lock key state */ /* FALLTHROUGH */ /* set lock key state */ /* set LEDs and quit */ /* set keyboard repeat rate (new interface) */ /* FALLTHROUGH */ /* set keyboard repeat rate (old interface) */ /* set keyboard translation table */ /* set keyboard translation table (compat) */ /* set keyboard translation table entry */ /* set accent key translation table */ /* FALLTHROUGH */