FreeBSD/sys/dev/kbd/kbd.c
/* register a keyboard and associate it with a function table */
register a keyboard and associate it with a function table
register a keyboard and associate it with a function table
int
kbd_register(keyboard_t *kbd)
{
	const keyboard_driver_t **list;
	const keyboard_driver_t *p;
	keyboard_t *mux;
	keyboard_info_t ki;
	int index;
	mux = kbd_get_keyboard(kbd_find_keyboard("kbdmux", -1));
	for (index = 0; index < keyboards; ++index) {
		if (keyboard[index] == NULL)
			break;
	}
	if (index >= keyboards) {
		if (kbd_realloc_array())
			return (-1);
	}
	kbd->kb_index = index;
	KBD_UNBUSY(kbd);
	KBD_VALID(kbd);
	kbd->kb_active = 0;	
	kbd->kb_token = NULL;
	kbd->kb_callback.kc_func = NULL;
	kbd->kb_callback.kc_arg = NULL;
	SLIST_FOREACH(p, &keyboard_drivers, link) {
		if (strcmp(p->name, kbd->kb_name) == 0) {
			keyboard[index] = kbd;
			kbdsw[index] = p->kbdsw;
			if (mux != NULL) {
				bzero(&ki, sizeof(ki));
				strcpy(ki.kb_name, kbd->kb_name);
				ki.kb_unit = kbd->kb_unit;
				(void)kbdd_ioctl(mux, KBADDKBD, (caddr_t) &ki);
			}
			return (index);
		}
	}
	SET_FOREACH(list, kbddriver_set) {
		p = *list;
		if (strcmp(p->name, kbd->kb_name) == 0) {
			keyboard[index] = kbd;
			kbdsw[index] = p->kbdsw;
			if (mux != NULL) {
				bzero(&ki, sizeof(ki));
				strcpy(ki.kb_name, kbd->kb_name);
				ki.kb_unit = kbd->kb_unit;
				(void)kbdd_ioctl(mux, KBADDKBD, (caddr_t) &ki);
			}
			return (index);
		}
	}
	return (-1);
}
int kbd_register ( keyboard_t * kbd ) { const keyboard_driver_t * * list ; const keyboard_driver_t * p ; keyboard_t * mux ; keyboard_info_t ki ; int index ; mux = kbd_get_keyboard ( kbd_find_keyboard ( " " , -1 ) ) ; for ( index = 0 ; index < keyboards ; ++ index ) { if ( keyboard [ index ] == NULL ) break ; } if ( index >= keyboards ) { if ( kbd_realloc_array ( ) ) return ( -1 ) ; } kbd -> kb_index = index ; KBD_UNBUSY ( kbd ) ; KBD_VALID ( kbd ) ; kbd -> kb_active = 0 ; kbd -> kb_token = NULL ; kbd -> kb_callback . kc_func = NULL ; kbd -> kb_callback . kc_arg = NULL ; SLIST_FOREACH ( p , & keyboard_drivers , link ) { if ( strcmp ( p -> name , kbd -> kb_name ) == 0 ) { keyboard [ index ] = kbd ; kbdsw [ index ] = p -> kbdsw ; if ( mux != NULL ) { bzero ( & ki , sizeof ( ki ) ) ; strcpy ( ki . kb_name , kbd -> kb_name ) ; ki . kb_unit = kbd -> kb_unit ; ( void ) kbdd_ioctl ( mux , KBADDKBD , ( caddr_t ) & ki ) ; } return ( index ) ; } } SET_FOREACH ( list , kbddriver_set ) { p = * list ; if ( strcmp ( p -> name , kbd -> kb_name ) == 0 ) { keyboard [ index ] = kbd ; kbdsw [ index ] = p -> kbdsw ; if ( mux != NULL ) { bzero ( & ki , sizeof ( ki ) ) ; strcpy ( ki . kb_name , kbd -> kb_name ) ; ki . kb_unit = kbd -> kb_unit ; ( void ) kbdd_ioctl ( mux , KBADDKBD , ( caddr_t ) & ki ) ; } return ( index ) ; } } return ( -1 ) ; }
register a keyboard and associate it with a function table
register a keyboard and associate it with a function table
/* disabled until someone calls kbd_enable() */