static void revert(void) { int size[3]; ioctl(0, VT_ACTIVATE, cur_info.active_vty); fprintf(stderr, "\033[=%dA", cur_info.console_info.mv_ovscan); fprintf(stderr, "\033[=%dF", cur_info.console_info.mv_norm.fore); fprintf(stderr, "\033[=%dG", cur_info.console_info.mv_norm.back); fprintf(stderr, "\033[=%dH", cur_info.console_info.mv_rev.fore); fprintf(stderr, "\033[=%dI", cur_info.console_info.mv_rev.back); if (vt4_mode == 0) ioctl(0, PIO_SCRNMAP, &cur_info.screen_map); if (cur_info.video_mode_number >= M_VESA_BASE) ioctl(0, _IO('V', cur_info.video_mode_number - M_VESA_BASE), NULL); else ioctl(0, _IO('S', cur_info.video_mode_number), NULL); if (cur_info.video_mode_info.vi_flags & V_INFO_GRAPHICS) { size[0] = cur_info.video_mode_info.vi_width / 8; size[1] = cur_info.video_mode_info.vi_height / cur_info.console_info.font_size; size[2] = cur_info.console_info.font_size; ioctl(0, KDRASTER, size); } }
// Get the SDA line state int i2c_getbit(void) { unsigned int value; value=ioctl(i2c_fd, _IO(ETRAXGPIO_IOCTYPE, IO_READBITS)); if ((value&(I2C_DATA_LINE))==0) return 0; else return 1; }
//------------------------------------------------------------------------------- // 설명: 프레임에서 색상으로 특정 영역을 투명하게 처리 시작 // 인수: a_fb : 화면에 출력할 프레임 버퍼 int gx_start_frame_trans( frame_buffer_t *a_fb) { if ( 0 > wait_v_sync( a_fb->fd) ){ printf( "wait v sync error\n"); return -1; } ioctl( a_fb->fd, _IO( 'F', 300), NULL); // Color Key Stop return 0; }
//------------------------------------------------------------------------------- // 설명: 프레임을 화면에서 감춤 // 인수: a_fb : 화면에 출력할 프레임 버퍼 int gx_hide_frame( frame_buffer_t *a_fb) { if ( 0 > wait_v_sync( a_fb->fd) ){ printf( "wait v sync error\n"); return -1; } ioctl(a_fb->fd, _IO('F', 202), NULL); // OSD Stop return 0; }
int main(int argc, char **argv) { int power_fd; if ((power_fd = open("/dev/empeg_power", O_RDONLY)) != -1) { ioctl( power_fd, _IO('p', 0), 0 ); } return 0; }
static long hififo_ioctl (struct file *file, unsigned int command, unsigned long arg) { struct hififo_fifo *fifo = file->private_data; long status = mutex_lock_interruptible(&fifo->sem); if (status) return status; status = -ENOTTY; if(command == _IO(HIFIFO_IOC_MAGIC, IOC_TIMEOUT)) { /* 1 extra jiffy so we round up rather than down */ fifo->timeout = 1 + (arg * HZ) / 1000; status = 0; } if(command == _IO(HIFIFO_IOC_MAGIC, IOC_BUILD)) status = (long) fifo->build; mutex_unlock(&fifo->sem); return status; }
void VGLEnd(void) { struct vt_mode smode; if (!VGLInitDone) return; VGLInitDone = 0; VGLSwitchPending = 0; VGLAbortPending = 0; signal(SIGUSR1, SIG_IGN); if (VGLMem != MAP_FAILED) { VGLClear(VGLDisplay, 0); munmap(VGLMem, VGLAdpInfo.va_window_size); } if (VGLOldMode >= M_VESA_BASE) { /* ugly, but necessary */ ioctl(0, _IO('V', VGLOldMode - M_VESA_BASE), 0); if (VGLOldMode == M_VESA_800x600) { int size[3]; size[0] = VGLOldWSize.ws_col; size[1] = VGLOldWSize.ws_row; size[2] = 16; ioctl(0, KDRASTER, size); } } else { ioctl(0, _IO('S', VGLOldMode), 0); } ioctl(0, KDDISABIO, 0); ioctl(0, KDSETMODE, KD_TEXT); smode.mode = VT_AUTO; ioctl(0, VT_SETMODE, &smode); if (VGLBuf) free(VGLBuf); VGLBuf = NULL; free(VGLDisplay); VGLDisplay = NULL; VGLKeyboardEnd(); }
static void revert(void) { int save_errno, size[3]; save_errno = errno; ioctl(0, VT_ACTIVATE, cur_info.active_vty); ioctl(0, KDSBORDER, cur_info.console_info.mv_ovscan); fprintf(stderr, "\033[=%dH", cur_info.console_info.mv_rev.fore); fprintf(stderr, "\033[=%dI", cur_info.console_info.mv_rev.back); if (vt4_mode == 0) ioctl(0, PIO_SCRNMAP, &cur_info.screen_map); if (video_mode_changed) { if (cur_info.video_mode_number >= M_VESA_BASE) ioctl(0, _IO('V', cur_info.video_mode_number - M_VESA_BASE), NULL); else ioctl(0, _IO('S', cur_info.video_mode_number), NULL); if (cur_info.video_mode_info.vi_flags & V_INFO_GRAPHICS) { size[0] = cur_info.console_info.mv_csz; size[1] = cur_info.console_info.mv_rsz; size[2] = cur_info.console_info.font_size; ioctl(0, KDRASTER, size); } } /* Restore some colors last since mode setting forgets some. */ fprintf(stderr, "\033[=%dF", cur_info.console_info.mv_norm.fore); fprintf(stderr, "\033[=%dG", cur_info.console_info.mv_norm.back); errno = save_errno; }
*/ #include "timer_local.h" #ifndef PIC /* entry for static linking */ const char *_snd_module_timer_hw = ""; #endif #define SNDRV_FILE_TIMER ALSA_DEVICE_DIRECTORY "timer" #define SNDRV_TIMER_VERSION_MAX SNDRV_PROTOCOL_VERSION(2, 0, 5) #define SNDRV_TIMER_IOCTL_STATUS_OLD _IOW('T', 0x14, struct snd_timer_status) enum { SNDRV_TIMER_IOCTL_START_OLD = _IO('T', 0x20), SNDRV_TIMER_IOCTL_STOP_OLD = _IO('T', 0x21), SNDRV_TIMER_IOCTL_CONTINUE_OLD = _IO('T', 0x22), SNDRV_TIMER_IOCTL_PAUSE_OLD = _IO('T', 0x23), }; static int snd_timer_hw_close(snd_timer_t *handle) { snd_timer_t *tmr = handle; int res; if (!tmr) return -EINVAL; res = close(tmr->poll_fd) < 0 ? -errno : 0; return res; }
void test_invalid_ioctl_4() { do_invalid_ioctl(get_video_fd(), _IO('V', 0xFF)); }
void test_invalid_ioctl_2() { do_invalid_ioctl(get_video_fd(), _IO(0xFF, 0xFF)); }
void test_invalid_ioctl_1() { do_invalid_ioctl(get_video_fd(), _IO(0, 0)); }
/* some useful control functions */ static int kmi_ioctl_locked(keyboard_t *kbd, u_long cmd, caddr_t arg) { struct kmi_softc *sc = kbd->kb_data; int i; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) int ival; #endif KMI_LOCK_ASSERT(); switch (cmd) { case KDGKBMODE: /* get keyboard mode */ *(int *)arg = sc->sc_mode; break; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 7): ival = IOCPARM_IVAL(arg); arg = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSKBMODE: /* set keyboard mode */ switch (*(int *)arg) { case K_XLATE: if (sc->sc_mode != K_XLATE) { /* make lock key state and LED state match */ sc->sc_state &= ~LOCK_MASK; sc->sc_state |= KBD_LED_VAL(kbd); } /* FALLTHROUGH */ case K_RAW: case K_CODE: if (sc->sc_mode != *(int *)arg) { if ((sc->sc_flags & KMI_FLAG_POLLING) == 0) kmi_clear_state(kbd); sc->sc_mode = *(int *)arg; } break; default: return (EINVAL); } break; case KDGETLED: /* get keyboard LED */ *(int *)arg = KBD_LED_VAL(kbd); break; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 66): ival = IOCPARM_IVAL(arg); arg = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSETLED: /* set keyboard LED */ /* NOTE: lock key state in "sc_state" won't be changed */ if (*(int *)arg & ~LOCK_MASK) return (EINVAL); i = *(int *)arg; /* replace CAPS LED with ALTGR LED for ALTGR keyboards */ if (sc->sc_mode == K_XLATE && kbd->kb_keymap->n_keys > ALTGR_OFFSET) { if (i & ALKED) i |= CLKED; else i &= ~CLKED; } if (KBD_HAS_DEVICE(kbd)) kmi_set_leds(sc, i); KBD_LED_VAL(kbd) = *(int *)arg; break; case KDGKBSTATE: /* get lock key state */ *(int *)arg = sc->sc_state & LOCK_MASK; break; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 20): ival = IOCPARM_IVAL(arg); arg = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSKBSTATE: /* set lock key state */ if (*(int *)arg & ~LOCK_MASK) { return (EINVAL); } sc->sc_state &= ~LOCK_MASK; sc->sc_state |= *(int *)arg; /* set LEDs and quit */ return (kmi_ioctl(kbd, KDSETLED, arg)); case KDSETREPEAT: /* set keyboard repeat rate (new * interface) */ if (!KBD_HAS_DEVICE(kbd)) { return (0); } if (((int *)arg)[1] < 0) { return (EINVAL); } if (((int *)arg)[0] < 0) { return (EINVAL); } if (((int *)arg)[0] < 200) /* fastest possible value */ kbd->kb_delay1 = 200; else kbd->kb_delay1 = ((int *)arg)[0]; kbd->kb_delay2 = ((int *)arg)[1]; return (0); #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 67): ival = IOCPARM_IVAL(arg); arg = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSETRAD: /* set keyboard repeat rate (old * interface) */ return (kmi_set_typematic(kbd, *(int *)arg)); case PIO_KEYMAP: /* set keyboard translation table */ case OPIO_KEYMAP: /* set keyboard translation table * (compat) */ case PIO_KEYMAPENT: /* set keyboard translation table * entry */ case PIO_DEADKEYMAP: /* set accent key translation table */ sc->sc_accents = 0; /* FALLTHROUGH */ default: return (genkbd_commonioctl(kbd, cmd, arg)); } return (0); }
static u_int sunkbd_read_char(keyboard_t *kbd, int wait) { struct sunkbd_softc *sc; int key, release, repeated, suncode; sc = (struct sunkbd_softc *)kbd; #if defined(SUNKBD_EMULATE_ATKBD) if (sc->sc_mode == K_RAW && sc->sc_buffered_char[0]) { key = sc->sc_buffered_char[0]; if (key & SCAN_PREFIX) { sc->sc_buffered_char[0] = key & ~SCAN_PREFIX; return ((key & SCAN_PREFIX_E0) ? 0xe0 : 0xe1); } else { sc->sc_buffered_char[0] = sc->sc_buffered_char[1]; sc->sc_buffered_char[1] = 0; return (key); } } #endif repeated = 0; if (sc->sc_repeating) { repeated = 1; sc->sc_repeating = 0; callout_reset(&sc->sc_repeat_callout, hz / 10, sunkbd_repeat, sc); suncode = sc->sc_repeat_key; goto process_code; } for (;;) { next_code: if (!(sc->sc_flags & KPCOMPOSE) && (sc->sc_composed_char > 0)) { key = sc->sc_composed_char; sc->sc_composed_char = 0; if (key > UCHAR_MAX) return (ERRKEY); return (key); } if (sc->sc_uart != NULL && !uart_rx_empty(sc->sc_uart)) { suncode = uart_rx_get(sc->sc_uart); } else if (sc->sc_polling != 0 && sc->sc_sysdev != NULL) { if (wait) suncode = uart_getc(sc->sc_sysdev); else if ((suncode = uart_poll(sc->sc_sysdev)) == -1) return (NOKEY); } else { return (NOKEY); } switch (suncode) { case SKBD_RSP_IDLE: break; default: process_code: ++kbd->kb_count; key = SKBD_KEY_CHAR(suncode); release = suncode & SKBD_KEY_RELEASE; if (!repeated) { if (release == 0) { callout_reset(&sc->sc_repeat_callout, hz / 2, sunkbd_repeat, sc); sc->sc_repeat_key = suncode; } else if (sc->sc_repeat_key == key) { callout_stop(&sc->sc_repeat_callout); sc->sc_repeat_key = -1; } } #if defined(SUNKBD_EMULATE_ATKBD) key = sunkbd_trtab[key]; if (key == NOTR) return (NOKEY); if (!repeated) { switch (key) { case 0x1d: /* ctrl */ if (release != 0) sc->sc_flags &= ~CTLS; else sc->sc_flags |= CTLS; break; case 0x2a: /* left shift */ case 0x36: /* right shift */ if (release != 0) sc->sc_flags &= ~SHIFTS; else sc->sc_flags |= SHIFTS; break; case 0x38: /* alt */ case 0x5d: /* altgr */ if (release != 0) sc->sc_flags &= ~ALTS; else sc->sc_flags |= ALTS; break; } } if (sc->sc_mode == K_RAW) { key = keycode2scancode(key, sc->sc_flags, release); if (key & SCAN_PREFIX) { if (key & SCAN_PREFIX_CTL) { sc->sc_buffered_char[0] = 0x1d | (key & SCAN_RELEASE); sc->sc_buffered_char[1] = key & ~SCAN_PREFIX; } else if (key & SCAN_PREFIX_SHIFT) { sc->sc_buffered_char[0] = 0x2a | (key & SCAN_RELEASE); sc->sc_buffered_char[1] = key & ~SCAN_PREFIX_SHIFT; } else { sc->sc_buffered_char[0] = key & ~SCAN_PREFIX; sc->sc_buffered_char[1] = 0; } return ((key & SCAN_PREFIX_E0) ? 0xe0 : 0xe1); } return (key); } switch (key) { case 0x5c: /* print screen */ if (sc->sc_flags & ALTS) key = 0x54; /* sysrq */ break; case 0x68: /* pause/break */ if (sc->sc_flags & CTLS) key = 0x6c; /* break */ break; } if (sc->sc_mode == K_CODE) return (key | release); #else if (sc->sc_mode == K_RAW || sc->sc_mode == K_CODE) return (suncode); #endif #if defined(SUNKBD_EMULATE_ATKBD) if (key == 0x38) { /* left alt (KP compose key) */ #else if (key == 0x13) { /* left alt (KP compose key) */ #endif if (release != 0) { if (sc->sc_flags & KPCOMPOSE) { sc->sc_flags &= ~KPCOMPOSE; if (sc->sc_composed_char > UCHAR_MAX) sc->sc_composed_char = 0; } } else { if (!(sc->sc_flags & KPCOMPOSE)) { sc->sc_flags |= KPCOMPOSE; sc->sc_composed_char = 0; } } } if (sc->sc_flags & KPCOMPOSE) { switch (suncode) { case 0x44: /* KP 7 */ case 0x45: /* KP 8 */ case 0x46: /* KP 9 */ sc->sc_composed_char *= 10; sc->sc_composed_char += suncode - 0x3d; if (sc->sc_composed_char > UCHAR_MAX) return (ERRKEY); goto next_code; case 0x5b: /* KP 4 */ case 0x5c: /* KP 5 */ case 0x5d: /* KP 6 */ sc->sc_composed_char *= 10; sc->sc_composed_char += suncode - 0x58; if (sc->sc_composed_char > UCHAR_MAX) return (ERRKEY); goto next_code; case 0x70: /* KP 1 */ case 0x71: /* KP 2 */ case 0x72: /* KP 3 */ sc->sc_composed_char *= 10; sc->sc_composed_char += suncode - 0x6f; if (sc->sc_composed_char > UCHAR_MAX) return (ERRKEY); goto next_code; case 0x5e: /* KP 0 */ sc->sc_composed_char *= 10; if (sc->sc_composed_char > UCHAR_MAX) return (ERRKEY); goto next_code; case 0x44 | SKBD_KEY_RELEASE: /* KP 7 */ case 0x45 | SKBD_KEY_RELEASE: /* KP 8 */ case 0x46 | SKBD_KEY_RELEASE: /* KP 9 */ case 0x5b | SKBD_KEY_RELEASE: /* KP 4 */ case 0x5c | SKBD_KEY_RELEASE: /* KP 5 */ case 0x5d | SKBD_KEY_RELEASE: /* KP 6 */ case 0x70 | SKBD_KEY_RELEASE: /* KP 1 */ case 0x71 | SKBD_KEY_RELEASE: /* KP 2 */ case 0x72 | SKBD_KEY_RELEASE: /* KP 3 */ case 0x5e | SKBD_KEY_RELEASE: /* KP 0 */ goto next_code; default: if (sc->sc_composed_char > 0) { sc->sc_flags &= ~KPCOMPOSE; sc->sc_composed_char = 0; return (ERRKEY); } } } key = genkbd_keyaction(kbd, key, release, &sc->sc_state, &sc->sc_accents); if (key != NOKEY || repeated) return (key); } } return (0); } static int sunkbd_check_char(keyboard_t *kbd) { struct sunkbd_softc *sc; if (!KBD_IS_ACTIVE(kbd)) return (FALSE); sc = (struct sunkbd_softc *)kbd; if (!(sc->sc_flags & KPCOMPOSE) && (sc->sc_composed_char > 0)) return (TRUE); return (sunkbd_check(kbd)); } static int sunkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t data) { struct sunkbd_softc *sc; int c, error; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) int ival; #endif sc = (struct sunkbd_softc *)kbd; error = 0; switch (cmd) { case KDGKBMODE: *(int *)data = sc->sc_mode; break; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) case _IO('K', 7): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSKBMODE: switch (*(int *)data) { case K_XLATE: if (sc->sc_mode != K_XLATE) { /* make lock key state and LED state match */ sc->sc_state &= ~LOCK_MASK; sc->sc_state |= KBD_LED_VAL(kbd); } /* FALLTHROUGH */ case K_RAW: case K_CODE: if (sc->sc_mode != *(int *)data) { sunkbd_clear_state(kbd); sc->sc_mode = *(int *)data; } break; default: error = EINVAL; break; } break; case KDGETLED: *(int *)data = KBD_LED_VAL(kbd); break; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) case _IO('K', 66): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSETLED: if (*(int *)data & ~LOCK_MASK) { error = EINVAL; break; } if (sc->sc_sysdev == NULL) break; c = 0; if (*(int *)data & CLKED) c |= SKBD_LED_CAPSLOCK; if (*(int *)data & NLKED) c |= SKBD_LED_NUMLOCK; if (*(int *)data & SLKED) c |= SKBD_LED_SCROLLLOCK; uart_lock(sc->sc_sysdev->hwmtx); sc->sc_sysdev->ops->putc(&sc->sc_sysdev->bas, SKBD_CMD_SETLED); sc->sc_sysdev->ops->putc(&sc->sc_sysdev->bas, c); uart_unlock(sc->sc_sysdev->hwmtx); KBD_LED_VAL(kbd) = *(int *)data; break; case KDGKBSTATE: *(int *)data = sc->sc_state & LOCK_MASK; break; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) case _IO('K', 20): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSKBSTATE: if (*(int *)data & ~LOCK_MASK) { error = EINVAL; break; } sc->sc_state &= ~LOCK_MASK; sc->sc_state |= *(int *)data; /* set LEDs and quit */ return (sunkbd_ioctl(kbd, KDSETLED, data)); case KDSETREPEAT: case KDSETRAD: break; case PIO_KEYMAP: case OPIO_KEYMAP: case PIO_KEYMAPENT: case PIO_DEADKEYMAP: default: return (genkbd_commonioctl(kbd, cmd, data)); } return (error); } static int sunkbd_lock(keyboard_t *kbd, int lock) { TODO; return (0); }
int main(void) { const unsigned int size = get_page_size(); void *const page = tail_alloc(size); init_magic(page, size); struct rtc_time *rt = tail_alloc(sizeof(*rt)); init_magic(rt, sizeof(*rt)); struct rtc_wkalrm *wk = tail_alloc(sizeof(*wk)); init_magic(wk, sizeof(*wk)); struct rtc_pll_info *pll = tail_alloc(sizeof(*pll)); init_magic(pll, sizeof(*pll)); /* RTC_ALM_READ */ ioctl(-1, RTC_ALM_READ, 0); printf("ioctl(-1, RTC_ALM_READ, NULL) = -1 EBADF (%m)\n"); ioctl(-1, RTC_ALM_READ, page); printf("ioctl(-1, RTC_ALM_READ, %p) = -1 EBADF (%m)\n", page); /* RTC_RD_TIME */ ioctl(-1, RTC_RD_TIME, 0); printf("ioctl(-1, RTC_RD_TIME, NULL) = -1 EBADF (%m)\n"); ioctl(-1, RTC_RD_TIME, page); printf("ioctl(-1, RTC_RD_TIME, %p) = -1 EBADF (%m)\n", page); /* RTC_ALM_SET */ ioctl(-1, RTC_ALM_SET, 0); printf("ioctl(-1, RTC_ALM_SET, NULL) = -1 EBADF (%m)\n"); ioctl(-1, RTC_ALM_SET, rt); printf("ioctl(-1, RTC_ALM_SET, "); print_rtc_time(rt); errno = EBADF; printf(") = -1 EBADF (%m)\n"); /* RTC_SET_TIME */ ioctl(-1, RTC_SET_TIME, 0); printf("ioctl(-1, RTC_SET_TIME, NULL) = -1 EBADF (%m)\n"); ioctl(-1, RTC_SET_TIME, rt); printf("ioctl(-1, RTC_SET_TIME, "); print_rtc_time(rt); errno = EBADF; printf(") = -1 EBADF (%m)\n"); /* RTC_IRQP_SET */ ioctl(-1, RTC_IRQP_SET, lmagic); printf("ioctl(-1, RTC_IRQP_SET, %lu) = -1 EBADF (%m)\n", lmagic); /* RTC_EPOCH_SET */ ioctl(-1, RTC_EPOCH_SET, lmagic); printf("ioctl(-1, RTC_EPOCH_SET, %lu) = -1 EBADF (%m)\n", lmagic); /* RTC_IRQP_READ */ ioctl(-1, RTC_IRQP_READ, 0); printf("ioctl(-1, RTC_IRQP_READ, NULL) = -1 EBADF (%m)\n"); ioctl(-1, RTC_IRQP_READ, page); printf("ioctl(-1, RTC_IRQP_READ, %p) = -1 EBADF (%m)\n", page); /* RTC_EPOCH_READ */ ioctl(-1, RTC_EPOCH_READ, 0); printf("ioctl(-1, RTC_EPOCH_READ, NULL) = -1 EBADF (%m)\n"); ioctl(-1, RTC_EPOCH_READ, page); printf("ioctl(-1, RTC_EPOCH_READ, %p) = -1 EBADF (%m)\n", page); /* RTC_WKALM_RD */ ioctl(-1, RTC_WKALM_RD, 0); printf("ioctl(-1, RTC_WKALM_RD, NULL) = -1 EBADF (%m)\n"); ioctl(-1, RTC_WKALM_RD, page); printf("ioctl(-1, RTC_WKALM_RD, %p) = -1 EBADF (%m)\n", page); /* RTC_WKALM_SET */ ioctl(-1, RTC_WKALM_SET, 0); printf("ioctl(-1, RTC_WKALM_SET, NULL) = -1 EBADF (%m)\n"); ioctl(-1, RTC_WKALM_SET, wk); printf("ioctl(-1, RTC_WKALM_SET, {enabled=%u, pending=%u, time=", (unsigned) wk->enabled, (unsigned) wk->pending); print_rtc_time(&wk->time); errno = EBADF; printf("}) = -1 EBADF (%m)\n"); /* RTC_PLL_GET */ ioctl(-1, RTC_PLL_GET, 0); printf("ioctl(-1, RTC_PLL_GET, NULL) = -1 EBADF (%m)\n"); ioctl(-1, RTC_PLL_GET, page); printf("ioctl(-1, RTC_PLL_GET, %p) = -1 EBADF (%m)\n", page); /* RTC_PLL_SET */ ioctl(-1, RTC_PLL_SET, 0); printf("ioctl(-1, RTC_PLL_SET, NULL) = -1 EBADF (%m)\n"); ioctl(-1, RTC_PLL_SET, pll); printf("ioctl(-1, RTC_PLL_SET, {pll_ctrl=%d, pll_value=%d" ", pll_max=%d, pll_min=%d, pll_posmult=%d, pll_negmult=%d" ", pll_clock=%ld}) = -1 EBADF (%m)\n", pll->pll_ctrl, pll->pll_value, pll->pll_max, pll->pll_min, pll->pll_posmult, pll->pll_negmult, pll->pll_clock); #ifdef RTC_VL_READ /* RTC_VL_READ */ ioctl(-1, RTC_VL_READ, 0); printf("ioctl(-1, RTC_VL_READ, NULL) = -1 EBADF (%m)\n"); ioctl(-1, RTC_VL_READ, page); printf("ioctl(-1, RTC_VL_READ, %p) = -1 EBADF (%m)\n", page); #endif unsigned int i; for (i = 0; i < ARRAY_SIZE(rtc_argless); ++i) { ioctl(-1, (unsigned long) rtc_argless[i].val, lmagic); printf("ioctl(-1, %s) = -1 EBADF (%m)\n", rtc_argless[i].str); } ioctl(-1, RTC_UIE_OFF, lmagic); printf("ioctl(-1, %s) = -1 EBADF (%m)\n", "PHN_NOT_OH or RTC_UIE_OFF"); ioctl(-1, RTC_AIE_ON, lmagic); #ifdef HPPA printf("ioctl(-1, %s) = -1 EBADF (%m)\n", "PA_PERF_ON or RTC_AIE_ON"); #else printf("ioctl(-1, %s) = -1 EBADF (%m)\n", "RTC_AIE_ON"); #endif ioctl(-1, _IO(0x70, 0x40), lmagic); printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n", "NVRAM_INIT", lmagic); puts("+++ exited with 0 +++"); return 0; }
int main() { int fd; char buffer[4097]; int ret; int error; printf("Opening %s\n", TARGET_PATH); fd = open(TARGET_PATH, O_CLOEXEC | O_RDWR); if (fd > 0) { printf("%s was opened\n", TARGET_PATH); printf("------------------\n"); printf("Testing ioctl ...\n"); ret = ioctl(fd, VERSION_MODIFIED); printf("Version modified : %s\n", ret == 0 ? "Non" : "Oui"); ret = ioctl(fd, VERSION_RESET); printf("Version reset : %d\n", ret); ret = ioctl(fd, _IO(0, 1)); // Au hasard (Enfin pas trop non plus) printf("ioctl invalide : %d\n", ret); printf("ioctl testing over.\n"); printf("------------------\n"); printf("Testing read/write ...\n"); getVersion(fd, buffer, &ret); printf("Version is '%s' | Number of characters read : %d\n", buffer, ret); ret = write(fd, TEST_STRING_1, strlen(TEST_STRING_1)); error = errno; printf("Writing : New version is '%s' | Number of characters writed : %d\n", TEST_STRING_1, ret); if (ret < 0) printf("\tError while writing : %s\n", strerror(error)); else printf("\tTesting : version = '%s'\n", getVersion(fd, buffer, NULL)); printf("\nWriting : Sending invalid ptr\n"); error = 0; ret = write(fd, NULL, 87); error = errno; printf("\tWriting : return value = %d | errno = %s\n", ret, strerror(error)); getVersion(fd, buffer, &ret); printf("Version is '%s' | Number of characters read : %d\n", buffer, ret); { char miniBuf[10]; memset(miniBuf, 0, 10); printf("\nReading with small buffer\n"); ret = read(fd, miniBuf, 9); printf("\tVersion is '%s' | ret = %d\n", miniBuf, ret); } { char *maxiBuf = malloc(9000); int i = 0; while (i < 9000) { maxiBuf[i] = ((i % ('z' - 'a' + 1)) + 'a'); i++; } ret = write(fd, maxiBuf, 9000); printf("Write (ret:%d)\n", ret); getVersion(fd, buffer, &ret); printf("Version is '%s' (ret:%d)\n", buffer, ret); free(maxiBuf); } { char *maxiBuf = malloc(9001); memset(maxiBuf, 0, 9001); ret = read(fd, maxiBuf, 9000); printf("'%s' (ret:%d)\n", maxiBuf, ret); free(maxiBuf); } ioctl(fd, VERSION_RESET); ret = write(fd, TEST_STRING_1, strlen(TEST_STRING_1)); printf("Rewriting new version '%s' (ret:%d)\n", getVersion(fd, buffer, NULL), ret); printf("------------------\n"); printf("Re-testing ioctl\n"); printf("Version actuelle '%s'\n", getVersion(fd, buffer, NULL)); printf("Version modifiée ? %s\n", ioctl(fd, VERSION_MODIFIED) ? "Oui" : "Non"); ioctl(fd, VERSION_RESET); printf("Version actuelle '%s'\n", getVersion(fd, buffer, NULL)); printf("Version modifiée ? %s\n", ioctl(fd, VERSION_MODIFIED) ? "Oui" : "Non"); printf("------------------\n"); printf("Un dernier test pour la forme :\n'%s'\n", getVersion(fd, buffer, NULL)); ioctl(fd, VERSION_RESET); printf("'%s'\n", getVersion(fd, buffer, NULL)); close(fd); return 0; } else { error = errno; printf("Impossible d'ouvrir %s, %s\n", TARGET_PATH, strerror(error)); if (error == EACCES) printf("Avez-vous les accès lecture/écriture ?\n"); return -1; } }
/* some useful control functions */ static int atkbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) { /* translate LED_XXX bits into the device specific bits */ static u_char ledmap[8] = { 0, 4, 2, 6, 1, 5, 3, 7, }; atkbd_state_t *state = kbd->kb_data; int error; int s; int i; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) int ival; #endif s = spltty(); switch (cmd) { case KDGKBMODE: /* get keyboard mode */ *(int *)arg = state->ks_mode; break; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 7): ival = IOCPARM_IVAL(arg); arg = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSKBMODE: /* set keyboard mode */ switch (*(int *)arg) { case K_XLATE: if (state->ks_mode != K_XLATE) { /* make lock key state and LED state match */ state->ks_state &= ~LOCK_MASK; state->ks_state |= KBD_LED_VAL(kbd); } /* FALLTHROUGH */ case K_RAW: case K_CODE: if (state->ks_mode != *(int *)arg) { atkbd_clear_state(kbd); state->ks_mode = *(int *)arg; } break; default: splx(s); return EINVAL; } break; case KDGETLED: /* get keyboard LED */ *(int *)arg = KBD_LED_VAL(kbd); break; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 66): ival = IOCPARM_IVAL(arg); arg = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSETLED: /* set keyboard LED */ /* NOTE: lock key state in ks_state won't be changed */ if (*(int *)arg & ~LOCK_MASK) { splx(s); return EINVAL; } i = *(int *)arg; /* replace CAPS LED with ALTGR LED for ALTGR keyboards */ if (state->ks_mode == K_XLATE && kbd->kb_keymap->n_keys > ALTGR_OFFSET) { if (i & ALKED) i |= CLKED; else i &= ~CLKED; } if (KBD_HAS_DEVICE(kbd)) { error = write_kbd(state->kbdc, KBDC_SET_LEDS, ledmap[i & LED_MASK]); if (error) { splx(s); return error; } } KBD_LED_VAL(kbd) = *(int *)arg; break; case KDGKBSTATE: /* get lock key state */ *(int *)arg = state->ks_state & LOCK_MASK; break; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 20): ival = IOCPARM_IVAL(arg); arg = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSKBSTATE: /* set lock key state */ if (*(int *)arg & ~LOCK_MASK) { splx(s); return EINVAL; } state->ks_state &= ~LOCK_MASK; state->ks_state |= *(int *)arg; splx(s); /* set LEDs and quit */ return atkbd_ioctl(kbd, KDSETLED, arg); case KDSETREPEAT: /* set keyboard repeat rate (new interface) */ splx(s); if (!KBD_HAS_DEVICE(kbd)) return 0; i = typematic(((int *)arg)[0], ((int *)arg)[1]); error = write_kbd(state->kbdc, KBDC_SET_TYPEMATIC, i); if (error == 0) { kbd->kb_delay1 = typematic_delay(i); kbd->kb_delay2 = typematic_rate(i); } return error; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 67): ival = IOCPARM_IVAL(arg); arg = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSETRAD: /* set keyboard repeat rate (old interface) */ splx(s); if (!KBD_HAS_DEVICE(kbd)) return 0; error = write_kbd(state->kbdc, KBDC_SET_TYPEMATIC, *(int *)arg); if (error == 0) { kbd->kb_delay1 = typematic_delay(*(int *)arg); kbd->kb_delay2 = typematic_rate(*(int *)arg); } return error; case PIO_KEYMAP: /* set keyboard translation table */ case PIO_KEYMAPENT: /* set keyboard translation table entry */ case PIO_DEADKEYMAP: /* set accent key translation table */ state->ks_accents = 0; /* FALLTHROUGH */ default: splx(s); return genkbd_commonioctl(kbd, cmd, arg); } splx(s); return 0; }
int GGI_vgl_setmode(ggi_visual *vis, ggi_mode *tm) { struct vgl_priv *priv = VGL_PRIV(vis); ggi_graphtype gt = tm->graphtype; video_info_t modeinfo; unsigned long modenum = 0; char sugname[GGI_MAX_APILEN]; char args[GGI_MAX_APILEN]; int err = 0; int id, i; int pixelBytes; err = GGI_vgl_checkmode(vis, tm); if (err) return err; /* reset the modeinfo structure as expected by query_mode */ memset(&modeinfo, 0, sizeof(modeinfo)); switch(gt) { case GT_1BIT : modeinfo.vi_depth = 1; pixelBytes = 1; break; case GT_4BIT : modeinfo.vi_depth = 4; pixelBytes = 1; break; case GT_8BIT : modeinfo.vi_depth = 8; pixelBytes = 1; break; case GT_16BIT: modeinfo.vi_depth = 16; pixelBytes = 2; break; case GT_32BIT: modeinfo.vi_depth = 32; pixelBytes = 4; break; /* Unsupported mode depths */ case GT_15BIT: case GT_24BIT: default: return GGI_ENOMATCH; } modeinfo.vi_width = tm->visible.x; modeinfo.vi_height = tm->visible.y; /* XXX should be added to libvgl */ if (ioctl(0, FBIO_FINDMODE, &modeinfo)) return -1; DPRINT("Setting VGLlib mode %d (0x%x)\n", modeinfo.vi_mode, modeinfo.vi_mode); /* Terminate any current mode before initialising another */ if (priv->vgl_init_done) { priv->vgl_init_done = 0; VGLEnd(); } /* XXX should be in VGL */ if ((modeinfo.vi_mode >= M_B40x25) && (modeinfo.vi_mode <= M_VGA_M90x60)) modenum = _IO('S', modeinfo.vi_mode); if ((modeinfo.vi_mode >= M_TEXT_80x25) && (modeinfo.vi_mode <= M_TEXT_132x60)) modenum = _IO('S', modeinfo.vi_mode); if ((modeinfo.vi_mode >= M_VESA_CG640x400) && (modeinfo.vi_mode <= M_VESA_FULL_1280)) modenum = _IO('V', modeinfo.vi_mode - M_VESA_BASE); if ((err = VGLInit(modenum)) != 0) { DPRINT("display-vgl: setting mode 0x%x failed with error %d\n", modeinfo.vi_mode, err); return GGI_EFATAL; } priv->vgl_init_done = 1; if (priv->vgl_use_db) { _GGI_vgl_freedbs(vis); /* Set up DirectBuffer(s) */ for (i = 0; i<tm->frames; i++) { if (LIBGGI_FB_SIZE(tm) > (unsigned)(VGLDisplay->Xsize*VGLDisplay->Ysize* pixelBytes)) { fprintf(stderr, "display-vgl: framebuffer too large! (%d > %d*%d*%d)\n", LIBGGI_FB_SIZE(tm), VGLDisplay->Xsize, VGLDisplay->Ysize, pixelBytes); return GGI_ENOMEM; } _ggi_db_add_buffer(LIBGGI_APPLIST(vis), _ggi_db_get_new()); LIBGGI_APPBUFS(vis)[i]->frame = i; LIBGGI_APPBUFS(vis)[i]->type = GGI_DB_NORMAL | GGI_DB_SIMPLE_PLB; LIBGGI_APPBUFS(vis)[i]->read = VGLDisplay->Bitmap; LIBGGI_APPBUFS(vis)[i]->write = VGLDisplay->Bitmap; LIBGGI_APPBUFS(vis)[i]->layout = blPixelLinearBuffer; LIBGGI_APPBUFS(vis)[i]->buffer.plb.stride = GT_ByPPP(tm->virt.x, tm->graphtype); } } /* Save mode info returned by the VESA driver */ bcopy(&modeinfo, &priv->modeinfo, sizeof(priv->modeinfo)); /* Palette */ if (vis->palette) { free(vis->palette); vis->palette = NULL; } if (priv->savepalette) { free(priv->savepalette); priv->savepalette = NULL; } if (GT_SCHEME(tm->graphtype) == GT_PALETTE) { int len = 1 << GT_DEPTH(tm->graphtype); vis->palette = malloc(len * sizeof(ggi_color)); if (vis->palette == NULL) return GGI_EFATAL; priv->savepalette = malloc(sizeof(int) * (len*3)); if (priv->savepalette == NULL) return GGI_EFATAL; /* Set an initial palette */ ggiSetColorfulPalette(vis); } /* Set up pixel format */ memset(LIBGGI_PIXFMT(vis), 0, sizeof(ggi_pixelformat)); LIBGGI_PIXFMT(vis)->size = GT_SIZE(gt); LIBGGI_PIXFMT(vis)->depth = GT_DEPTH(gt); switch (GT_SCHEME(gt)) { case GT_PALETTE: case GT_GREYSCALE: LIBGGI_PIXFMT(vis)->clut_mask = (1 << GT_DEPTH(gt)) - 1; break; case GT_TRUECOLOR: DPRINT_MODE("display-vgl: RGB %d:%d:%d offsets %d:%d:%d\n", priv->modeinfo.vi_pixel_fsizes[VGL_RED_INDEX], priv->modeinfo.vi_pixel_fsizes[VGL_GREEN_INDEX], priv->modeinfo.vi_pixel_fsizes[VGL_BLUE_INDEX], priv->modeinfo.vi_pixel_fields[VGL_RED_INDEX], priv->modeinfo.vi_pixel_fields[VGL_GREEN_INDEX], priv->modeinfo.vi_pixel_fields[VGL_BLUE_INDEX]); LIBGGI_PIXFMT(vis)->red_mask = ((1 << priv->modeinfo.vi_pixel_fsizes[VGL_RED_INDEX]) - 1) << priv->modeinfo.vi_pixel_fields[VGL_RED_INDEX]; LIBGGI_PIXFMT(vis)->green_mask = ((1 << priv->modeinfo.vi_pixel_fsizes[VGL_GREEN_INDEX]) - 1) << priv->modeinfo.vi_pixel_fields[VGL_GREEN_INDEX]; LIBGGI_PIXFMT(vis)->blue_mask = ((1 << priv->modeinfo.vi_pixel_fsizes[VGL_BLUE_INDEX]) - 1) << priv->modeinfo.vi_pixel_fields[VGL_BLUE_INDEX]; break; case GT_TEXT: /* Assumes VGA text */ LIBGGI_PIXFMT(vis)->texture_mask = 0x00ff; LIBGGI_PIXFMT(vis)->fg_mask = 0x0f00; LIBGGI_PIXFMT(vis)->bg_mask = 0xf000; break; } _ggi_build_pixfmt(LIBGGI_PIXFMT(vis)); memcpy(LIBGGI_MODE(vis),tm,sizeof(ggi_mode)); _ggiZapMode(vis, 0); for(id = 1; 0 == GGI_vgl_getapi(vis, id, sugname, args); id++) { if (_ggiOpenDL(vis, _ggiGetConfigHandle(), sugname, args, NULL)) { fprintf(stderr,"display-vgl: Can't open the %s (%s) library.\n", sugname, args); return GGI_EFATAL; } else { DPRINT("Success in loading %s (%s)\n", sugname, args); } } if (!priv->vgl_use_db) { vis->opdraw->putpixel = GGI_vgl_putpixel; vis->opdraw->putpixel_nc = GGI_vgl_putpixel_nc; vis->opdraw->getpixel = GGI_vgl_getpixel; vis->opdraw->drawpixel = GGI_vgl_drawpixel; vis->opdraw->drawpixel_nc = GGI_vgl_drawpixel_nc; vis->opdraw->drawhline = GGI_vgl_drawhline; vis->opdraw->drawhline_nc = GGI_vgl_drawhline_nc; vis->opdraw->drawvline = GGI_vgl_drawvline; vis->opdraw->drawvline_nc = GGI_vgl_drawvline_nc; vis->opdraw->drawbox = GGI_vgl_drawbox; vis->opdraw->drawline = GGI_vgl_drawline; vis->opdraw->puthline = GGI_vgl_puthline; vis->opdraw->putbox = GGI_vgl_putbox; } else { vis->opdraw->setorigin = GGI_vgl_setorigin; } if (GT_SCHEME(tm->graphtype) == GT_PALETTE) { vis->opcolor->setpalvec = GGI_vgl_setpalvec; } if(priv->vgl_use_db) { for(i = 0; i<tm->frames; i++) LIBGGI_APPBUFS(vis)[i]->buffer.plb.pixelformat = LIBGGI_PIXFMT(vis); } ggiIndicateChange(vis, GGI_CHG_APILIST); return 0; }
// Set the SDA line as input void i2c_dir_in(void) { int iomask; iomask = I2C_DATA_LINE; ioctl(i2c_fd, _IO(ETRAXGPIO_IOCTYPE, IO_SETGET_INPUT), &iomask); }
/* * Process ioctls */ int procfs_ioctl(PFS_IOCTL_ARGS) { struct procfs_status *ps; #ifdef COMPAT_FREEBSD32 struct procfs_status32 *ps32; #endif int error, flags, sig; #ifdef COMPAT_FREEBSD6 int ival; #endif KASSERT(p != NULL, ("%s() called without a process", __func__)); PROC_LOCK_ASSERT(p, MA_OWNED); error = 0; switch (cmd) { #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IOC(IOC_IN, 'p', 1, 0): #endif #ifdef COMPAT_FREEBSD6 case _IO('p', 1): ival = IOCPARM_IVAL(data); data = &ival; #endif case PIOCBIS: p->p_stops |= *(unsigned int *)data; break; #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IOC(IOC_IN, 'p', 2, 0): #endif #ifdef COMPAT_FREEBSD6 case _IO('p', 2): ival = IOCPARM_IVAL(data); data = &ival; #endif case PIOCBIC: p->p_stops &= ~*(unsigned int *)data; break; #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IOC(IOC_IN, 'p', 3, 0): #endif #ifdef COMPAT_FREEBSD6 case _IO('p', 3): ival = IOCPARM_IVAL(data); data = &ival; #endif case PIOCSFL: flags = *(unsigned int *)data; if (flags & PF_ISUGID) { /* * XXXRW: Is this specific check required here, as * p_candebug() should implement it, or other checks * are missing. */ error = priv_check(td, PRIV_DEBUG_SUGID); if (error) break; } p->p_pfsflags = flags; break; case PIOCGFL: *(unsigned int *)data = p->p_pfsflags; break; case PIOCWAIT: while (p->p_step == 0 && (p->p_flag & P_WEXIT) == 0) { /* sleep until p stops */ _PHOLD(p); error = msleep(&p->p_stype, &p->p_mtx, PWAIT|PCATCH, "pioctl", 0); _PRELE(p); if (error != 0) break; } /* fall through to PIOCSTATUS */ case PIOCSTATUS: ps = (struct procfs_status *)data; ps->state = (p->p_step == 0); ps->flags = 0; /* nope */ ps->events = p->p_stops; ps->why = p->p_step ? p->p_stype : 0; ps->val = p->p_step ? p->p_xstat : 0; break; #ifdef COMPAT_FREEBSD32 case PIOCWAIT32: while (p->p_step == 0 && (p->p_flag & P_WEXIT) == 0) { /* sleep until p stops */ _PHOLD(p); error = msleep(&p->p_stype, &p->p_mtx, PWAIT|PCATCH, "pioctl", 0); _PRELE(p); if (error != 0) break; } /* fall through to PIOCSTATUS32 */ case PIOCSTATUS32: ps32 = (struct procfs_status32 *)data; ps32->state = (p->p_step == 0); ps32->flags = 0; /* nope */ ps32->events = p->p_stops; ps32->why = p->p_step ? p->p_stype : 0; ps32->val = p->p_step ? p->p_xstat : 0; break; #endif #if defined(COMPAT_FREEBSD5) || defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IOC(IOC_IN, 'p', 5, 0): #endif #ifdef COMPAT_FREEBSD6 case _IO('p', 5): ival = IOCPARM_IVAL(data); data = &ival; #endif case PIOCCONT: if (p->p_step == 0) break; sig = *(unsigned int *)data; if (sig != 0 && !_SIG_VALID(sig)) { error = EINVAL; break; } #if 0 p->p_step = 0; if (P_SHOULDSTOP(p)) { p->p_xstat = sig; p->p_flag &= ~(P_STOPPED_TRACE|P_STOPPED_SIG); PROC_SLOCK(p); thread_unsuspend(p); PROC_SUNLOCK(p); } else if (sig) kern_psignal(p, sig); #else if (sig) kern_psignal(p, sig); p->p_step = 0; wakeup(&p->p_step); #endif break; default: error = (ENOTTY); } return (error); }
static void video_mode(int argc, char **argv, int *mode_index) { static struct { const char *name; unsigned long mode; unsigned long mode_num; } modes[] = { { "80x25", SW_TEXT_80x25, M_TEXT_80x25 }, { "80x30", SW_TEXT_80x30, M_TEXT_80x30 }, { "80x43", SW_TEXT_80x43, M_TEXT_80x43 }, { "80x50", SW_TEXT_80x50, M_TEXT_80x50 }, { "80x60", SW_TEXT_80x60, M_TEXT_80x60 }, { "132x25", SW_TEXT_132x25, M_TEXT_132x25 }, { "132x30", SW_TEXT_132x30, M_TEXT_132x30 }, { "132x43", SW_TEXT_132x43, M_TEXT_132x43 }, { "132x50", SW_TEXT_132x50, M_TEXT_132x50 }, { "132x60", SW_TEXT_132x60, M_TEXT_132x60 }, { "VGA_40x25", SW_VGA_C40x25, M_VGA_C40x25 }, { "VGA_80x25", SW_VGA_C80x25, M_VGA_C80x25 }, { "VGA_80x30", SW_VGA_C80x30, M_VGA_C80x30 }, { "VGA_80x50", SW_VGA_C80x50, M_VGA_C80x50 }, { "VGA_80x60", SW_VGA_C80x60, M_VGA_C80x60 }, #ifdef SW_VGA_C90x25 { "VGA_90x25", SW_VGA_C90x25, M_VGA_C90x25 }, { "VGA_90x30", SW_VGA_C90x30, M_VGA_C90x30 }, { "VGA_90x43", SW_VGA_C90x43, M_VGA_C90x43 }, { "VGA_90x50", SW_VGA_C90x50, M_VGA_C90x50 }, { "VGA_90x60", SW_VGA_C90x60, M_VGA_C90x60 }, #endif { "VGA_320x200", SW_VGA_CG320, M_CG320 }, { "EGA_80x25", SW_ENH_C80x25, M_ENH_C80x25 }, { "EGA_80x43", SW_ENH_C80x43, M_ENH_C80x43 }, { "VESA_132x25", SW_VESA_C132x25,M_VESA_C132x25 }, { "VESA_132x43", SW_VESA_C132x43,M_VESA_C132x43 }, { "VESA_132x50", SW_VESA_C132x50,M_VESA_C132x50 }, { "VESA_132x60", SW_VESA_C132x60,M_VESA_C132x60 }, { "VESA_800x600", SW_VESA_800x600,M_VESA_800x600 }, { NULL, 0, 0 }, }; int new_mode_num = 0; unsigned long mode = 0; int cur_mode; int save_errno; int size[3]; int i; if (ioctl(0, CONS_GET, &cur_mode) < 0) err(1, "cannot get the current video mode"); /* * Parse the video mode argument... */ if (*mode_index < argc) { if (!strncmp(argv[*mode_index], "MODE_", 5)) { if (!isdigit(argv[*mode_index][5])) errx(1, "invalid video mode number"); new_mode_num = atoi(&argv[*mode_index][5]); } else { for (i = 0; modes[i].name != NULL; ++i) { if (!strcmp(argv[*mode_index], modes[i].name)) { mode = modes[i].mode; new_mode_num = modes[i].mode_num; break; } } if (modes[i].name == NULL) return; if (ioctl(0, mode, NULL) < 0) { revert(); err(1, "cannot set videomode"); } video_mode_changed = 1; } /* * Collect enough information about the new video mode... */ new_mode_info.vi_mode = new_mode_num; if (ioctl(0, CONS_MODEINFO, &new_mode_info) == -1) { revert(); err(1, "obtaining new video mode parameters"); } if (mode == 0) { if (new_mode_num >= M_VESA_BASE) mode = _IO('V', new_mode_num - M_VESA_BASE); else mode = _IO('S', new_mode_num); } /* * Try setting the new mode. */ if (ioctl(0, mode, NULL) == -1) { revert(); err(1, "setting video mode"); } video_mode_changed = 1; /* * For raster modes it's not enough to just set the mode. * We also need to explicitly set the raster mode. */ if (new_mode_info.vi_flags & V_INFO_GRAPHICS) { /* font size */ if (font_height == 0) font_height = cur_info.console_info.font_size; size[2] = font_height; /* adjust columns */ if ((vesa_cols * 8 > new_mode_info.vi_width) || (vesa_cols <= 0)) { size[0] = new_mode_info.vi_width / 8; } else { size[0] = vesa_cols; } /* adjust rows */ if ((vesa_rows * font_height > new_mode_info.vi_height) || (vesa_rows <= 0)) { size[1] = new_mode_info.vi_height / font_height; } else { size[1] = vesa_rows; } /* set raster mode */ if (ioctl(0, KDRASTER, size)) { save_errno = errno; if (cur_mode >= M_VESA_BASE) ioctl(0, _IO('V', cur_mode - M_VESA_BASE), NULL); else ioctl(0, _IO('S', cur_mode), NULL); revert(); errno = save_errno; err(1, "cannot activate raster display"); } } /* Recover from mode setting forgetting colors. */ fprintf(stderr, "\033[=%dF", cur_info.console_info.mv_norm.fore); fprintf(stderr, "\033[=%dG", cur_info.console_info.mv_norm.back); (*mode_index)++; } }
// Set the SDA line state void i2c_data(int state) { if (state==1) ioctl(i2c_fd, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), I2C_DATA_LINE); else ioctl(i2c_fd, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS), I2C_DATA_LINE); }
int sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td) { scr_stat *scp; video_adapter_t *adp; video_info_t info; video_adapter_info_t adp_info; int error; int s; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) int ival; #endif scp = SC_STAT(tp); if (scp == NULL) /* tp == SC_MOUSE */ return ENOIOCTL; adp = scp->sc->adp; if (adp == NULL) /* shouldn't happen??? */ return ENODEV; switch (cmd) { case CONS_CURRENTADP: /* get current adapter index */ case FBIO_ADAPTER: return fb_ioctl(adp, FBIO_ADAPTER, data); case CONS_CURRENT: /* get current adapter type */ case FBIO_ADPTYPE: return fb_ioctl(adp, FBIO_ADPTYPE, data); case OLD_CONS_ADPINFO: /* adapter information (old interface) */ if (((old_video_adapter_t *)data)->va_index >= 0) { adp = vid_get_adapter(((old_video_adapter_t *)data)->va_index); if (adp == NULL) return ENODEV; } ((old_video_adapter_t *)data)->va_index = adp->va_index; ((old_video_adapter_t *)data)->va_type = adp->va_type; ((old_video_adapter_t *)data)->va_flags = adp->va_flags; ((old_video_adapter_t *)data)->va_crtc_addr = adp->va_crtc_addr; ((old_video_adapter_t *)data)->va_window = adp->va_window; ((old_video_adapter_t *)data)->va_window_size = adp->va_window_size; ((old_video_adapter_t *)data)->va_window_gran = adp->va_window_gran; ((old_video_adapter_t *)data)->va_buffer = adp->va_buffer; ((old_video_adapter_t *)data)->va_buffer_size = adp->va_buffer_size; ((old_video_adapter_t *)data)->va_mode = adp->va_mode; ((old_video_adapter_t *)data)->va_initial_mode = adp->va_initial_mode; ((old_video_adapter_t *)data)->va_initial_bios_mode = adp->va_initial_bios_mode; return 0; case OLD_CONS_ADPINFO2: /* adapter information (yet another old I/F) */ adp_info.va_index = ((old_video_adapter_info_t *)data)->va_index; if (adp_info.va_index >= 0) { adp = vid_get_adapter(adp_info.va_index); if (adp == NULL) return ENODEV; } error = fb_ioctl(adp, FBIO_ADPINFO, &adp_info); if (error == 0) bcopy(&adp_info, data, sizeof(old_video_adapter_info_t)); return error; case CONS_ADPINFO: /* adapter information */ case FBIO_ADPINFO: if (((video_adapter_info_t *)data)->va_index >= 0) { adp = vid_get_adapter(((video_adapter_info_t *)data)->va_index); if (adp == NULL) return ENODEV; } return fb_ioctl(adp, FBIO_ADPINFO, data); case CONS_GET: /* get current video mode */ case FBIO_GETMODE: *(int *)data = scp->mode; return 0; #ifndef SC_NO_MODE_CHANGE case FBIO_SETMODE: /* set video mode */ if (!(adp->va_flags & V_ADP_MODECHANGE)) return ENODEV; info.vi_mode = *(int *)data; error = fb_ioctl(adp, FBIO_MODEINFO, &info); if (error) return error; if (info.vi_flags & V_INFO_GRAPHICS) return sc_set_graphics_mode(scp, tp, *(int *)data); else return sc_set_text_mode(scp, tp, *(int *)data, 0, 0, 0, 0); #endif /* SC_NO_MODE_CHANGE */ case OLD_CONS_MODEINFO: /* get mode information (old infterface) */ info.vi_mode = ((old_video_info_t *)data)->vi_mode; error = fb_ioctl(adp, FBIO_MODEINFO, &info); if (error == 0) bcopy(&info, (old_video_info_t *)data, sizeof(old_video_info_t)); return error; case CONS_MODEINFO: /* get mode information */ case FBIO_MODEINFO: return fb_ioctl(adp, FBIO_MODEINFO, data); case OLD_CONS_FINDMODE: /* find a matching video mode (old interface) */ bzero(&info, sizeof(info)); bcopy((old_video_info_t *)data, &info, sizeof(old_video_info_t)); error = fb_ioctl(adp, FBIO_FINDMODE, &info); if (error == 0) bcopy(&info, (old_video_info_t *)data, sizeof(old_video_info_t)); return error; case CONS_FINDMODE: /* find a matching video mode */ case FBIO_FINDMODE: return fb_ioctl(adp, FBIO_FINDMODE, data); #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('c', 104): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case CONS_SETWINORG: /* set frame buffer window origin */ case FBIO_SETWINORG: if (scp != scp->sc->cur_scp) return ENODEV; /* XXX */ return fb_ioctl(adp, FBIO_SETWINORG, data); case FBIO_GETWINORG: /* get frame buffer window origin */ if (scp != scp->sc->cur_scp) return ENODEV; /* XXX */ return fb_ioctl(adp, FBIO_GETWINORG, data); case FBIO_GETDISPSTART: case FBIO_SETDISPSTART: case FBIO_GETLINEWIDTH: case FBIO_SETLINEWIDTH: if (scp != scp->sc->cur_scp) return ENODEV; /* XXX */ return fb_ioctl(adp, cmd, data); case FBIO_GETPALETTE: case FBIO_SETPALETTE: case FBIOPUTCMAP: case FBIOGETCMAP: case FBIOGTYPE: case FBIOGATTR: case FBIOSVIDEO: case FBIOGVIDEO: case FBIOSCURSOR: case FBIOGCURSOR: case FBIOSCURPOS: case FBIOGCURPOS: case FBIOGCURMAX: if (scp != scp->sc->cur_scp) return ENODEV; /* XXX */ return fb_ioctl(adp, cmd, data); case FBIO_BLANK: if (scp != scp->sc->cur_scp) return ENODEV; /* XXX */ return fb_ioctl(adp, cmd, data); #ifndef SC_NO_MODE_CHANGE /* generic text modes */ case SW_TEXT_80x25: case SW_TEXT_80x30: case SW_TEXT_80x43: case SW_TEXT_80x50: case SW_TEXT_80x60: /* FALLTHROUGH */ /* VGA TEXT MODES */ case SW_VGA_C40x25: case SW_VGA_C80x25: case SW_VGA_M80x25: case SW_VGA_C80x30: case SW_VGA_M80x30: case SW_VGA_C80x50: case SW_VGA_M80x50: case SW_VGA_C80x60: case SW_VGA_M80x60: case SW_VGA_C90x25: case SW_VGA_M90x25: case SW_VGA_C90x30: case SW_VGA_M90x30: case SW_VGA_C90x43: case SW_VGA_M90x43: case SW_VGA_C90x50: case SW_VGA_M90x50: case SW_VGA_C90x60: case SW_VGA_M90x60: case SW_B40x25: case SW_C40x25: case SW_B80x25: case SW_C80x25: case SW_ENH_B40x25: case SW_ENH_C40x25: case SW_ENH_B80x25: case SW_ENH_C80x25: case SW_ENH_B80x43: case SW_ENH_C80x43: case SW_EGAMONO80x25: #ifdef PC98 /* PC98 TEXT MODES */ case SW_PC98_80x25: case SW_PC98_80x30: #endif if (!(adp->va_flags & V_ADP_MODECHANGE)) return ENODEV; return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0, 0); /* GRAPHICS MODES */ case SW_BG320: case SW_BG640: case SW_CG320: case SW_CG320_D: case SW_CG640_E: case SW_CG640x350: case SW_ENH_CG640: case SW_BG640x480: case SW_CG640x480: case SW_VGA_CG320: case SW_VGA_MODEX: #ifdef PC98 /* PC98 GRAPHICS MODES */ case SW_PC98_EGC640x400: case SW_PC98_PEGC640x400: case SW_PC98_PEGC640x480: #endif if (!(adp->va_flags & V_ADP_MODECHANGE)) return ENODEV; return sc_set_graphics_mode(scp, tp, cmd & 0xff); #endif /* SC_NO_MODE_CHANGE */ #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 10): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSETMODE: /* set current mode of this (virtual) console */ switch (*(int *)data) { case KD_TEXT: /* switch to TEXT (known) mode */ /* * If scp->mode is of graphics modes, we don't know which * text mode to switch back to... */ if (scp->status & GRAPHICS_MODE) return EINVAL; /* restore fonts & palette ! */ #if 0 #ifndef SC_NO_FONT_LOADING if (ISFONTAVAIL(adp->va_flags) && !(scp->status & (GRAPHICS_MODE | PIXEL_MODE))) /* * FONT KLUDGE * Don't load fonts for now... XXX */ if (scp->sc->fonts_loaded & FONT_8) sc_load_font(scp, 0, 8, 8, scp->sc->font_8, 0, 256); if (scp->sc->fonts_loaded & FONT_14) sc_load_font(scp, 0, 14, 8, scp->sc->font_14, 0, 256); if (scp->sc->fonts_loaded & FONT_16) sc_load_font(scp, 0, 16, 8, scp->sc->font_16, 0, 256); } #endif /* SC_NO_FONT_LOADING */ #endif #ifndef SC_NO_PALETTE_LOADING vidd_load_palette(adp, scp->sc->palette); #endif #ifndef PC98 /* move hardware cursor out of the way */ vidd_set_hw_cursor(adp, -1, -1); #endif /* FALLTHROUGH */ case KD_TEXT1: /* switch to TEXT (known) mode */ /* * If scp->mode is of graphics modes, we don't know which * text/pixel mode to switch back to... */ if (scp->status & GRAPHICS_MODE) return EINVAL; s = spltty(); if ((error = sc_clean_up(scp))) { splx(s); return error; } #ifndef PC98 scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN; splx(s); /* no restore fonts & palette */ if (scp == scp->sc->cur_scp) set_mode(scp); sc_clear_screen(scp); scp->status &= ~UNKNOWN_MODE; #else /* PC98 */ scp->status &= ~UNKNOWN_MODE; /* no restore fonts & palette */ if (scp == scp->sc->cur_scp) set_mode(scp); sc_clear_screen(scp); splx(s); #endif /* PC98 */ return 0; #ifdef SC_PIXEL_MODE case KD_PIXEL: /* pixel (raster) display */ if (!(scp->status & (GRAPHICS_MODE | PIXEL_MODE))) return EINVAL; if (scp->status & GRAPHICS_MODE) return sc_set_pixel_mode(scp, tp, scp->xsize, scp->ysize, scp->font_size, scp->font_width); s = spltty(); if ((error = sc_clean_up(scp))) { splx(s); return error; } scp->status |= (UNKNOWN_MODE | PIXEL_MODE | MOUSE_HIDDEN); splx(s); if (scp == scp->sc->cur_scp) { set_mode(scp); #ifndef SC_NO_PALETTE_LOADING vidd_load_palette(adp, scp->sc->palette); #endif } sc_clear_screen(scp); scp->status &= ~UNKNOWN_MODE; return 0; #endif /* SC_PIXEL_MODE */ case KD_GRAPHICS: /* switch to GRAPHICS (unknown) mode */ s = spltty(); if ((error = sc_clean_up(scp))) { splx(s); return error; } scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN; splx(s); #ifdef PC98 if (scp == scp->sc->cur_scp) set_mode(scp); #endif return 0; default: return EINVAL; } /* NOT REACHED */ #ifdef SC_PIXEL_MODE case KDRASTER: /* set pixel (raster) display mode */ if (ISUNKNOWNSC(scp) || ISTEXTSC(scp)) return ENODEV; return sc_set_pixel_mode(scp, tp, ((int *)data)[0], ((int *)data)[1], ((int *)data)[2], 8); #endif /* SC_PIXEL_MODE */ case KDGETMODE: /* get current mode of this (virtual) console */ /* * From the user program's point of view, KD_PIXEL is the same * as KD_TEXT... */ *data = ISGRAPHSC(scp) ? KD_GRAPHICS : KD_TEXT; return 0; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 13): ival = IOCPARM_IVAL(data); data = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSBORDER: /* set border color of this (virtual) console */ scp->border = *(int *)data; if (scp == scp->sc->cur_scp) sc_set_border(scp, scp->border); return 0; }
// Set the SCL line state void i2c_clk(int state) { if (state==1) ioctl(i2c_fd, _IO(ETRAXGPIO_IOCTYPE, IO_SETBITS), I2C_CLOCK_LINE); else ioctl(i2c_fd, _IO(ETRAXGPIO_IOCTYPE, IO_CLRBITS), I2C_CLOCK_LINE); }
bool FBDev::TryOpen(int xres, int yres, int depth) { #if defined(__FreeBSD__) video_info_t mode = {0}; mode.vi_width = xres; mode.vi_height = yres; mode.vi_depth = depth; if (ioctl(0, FBIO_FINDMODE, &mode)) { return false; throw(runtime_error("Cannot find graphics mode. Check your zhcon.conf please.\n")); } if ((mode.vi_mode >= M_B40x25) && (mode.vi_mode <= M_VGA_M90x60)) mCurrentMode = _IO('S', mode.vi_mode); if ((mode.vi_mode >= M_TEXT_80x25) && (mode.vi_mode <= M_TEXT_132x60)) mCurrentMode = _IO('S', mode.vi_mode); if ((mode.vi_mode >= M_VESA_CG640x400) && (mode.vi_mode <= M_VESA_FULL_1280)) mCurrentMode = _IO('V', mode.vi_mode - M_VESA_BASE); // FreeBSD mode query bug workaround -- Rick if (depth == 4 && mCurrentMode == SW_VGA11) mCurrentMode = SW_VGA12; if (ioctl(0, mCurrentMode, 0) != 0) { throw(runtime_error("Cannot switch to graphics mode. Refer to README/FAQ" " and check your zhcon.cfg please!\n")); } mXres = mode.vi_width; mYres = mode.vi_height; mpBufLen = mode.vi_buffer_size; if (mode.vi_mem_model == V_INFO_MM_PLANAR) { mpBufLen = mode.vi_width * mode.vi_height / 8; } // printf ("len %d\n", mpBufLen); // use /dev/mem crash in Virtual PC //#if (__FreeBSD__ <= 3) if ((mFd = open("/dev/vga", O_RDWR | O_NDELAY)) < 0) { //#else // if ((mFd = open("/dev/mem", O_RDWR | O_NDELAY)) < 0) { //#endif throw(runtime_error("Can not open vga device.\n")); } switch (depth) { case 4: #ifdef USING_VGA mpGraphDev = new FBVgaPlanes; #else throw(runtime_error("color depth unsupported in this version\n" "use 8bpp instead!")); #endif break; case 8: mpGraphDev = new FBLinear8; break; case 15: mpGraphDev = new FBLinear15; break; case 16: mpGraphDev = new FBLinear16; break; case 24: mpGraphDev = new FBLinear24; break; case 32: mpGraphDev = new FBLinear32; break; default: throw(runtime_error("color depth unsupported in this version\n" "use 8bpp instead!")); } //#if (__FreeBSD__ <= 3) #define GRAPH_BASE 0x0 //#else //#define GRAPH_BASE 0xA0000 //#endif mpBuf = static_cast<char *>(mmap(0, mpBufLen, PROT_READ | PROT_WRITE, MAP_FILE|MAP_SHARED|MAP_FIXED, mFd, GRAPH_BASE)); if (mpBuf == MAP_FAILED) throw(runtime_error("mmap() failed!")); // undefine mNextLine, checked by low level #endif return true; }
/* some useful control functions */ static int pckbd_ioctl(keyboard_t *kbd, u_long cmd, caddr_t arg) { pckbd_state_t *state = kbd->kb_data; int s; int i; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) int ival; #endif s = spltty(); switch (cmd) { case KDGKBMODE: /* get keyboard mode */ *(int *)arg = state->ks_mode; break; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 7): ival = IOCPARM_IVAL(arg); arg = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSKBMODE: /* set keyboard mode */ switch (*(int *)arg) { case K_XLATE: if (state->ks_mode != K_XLATE) { /* make lock key state and LED state match */ state->ks_state &= ~LOCK_MASK; state->ks_state |= KBD_LED_VAL(kbd); } /* FALLTHROUGH */ case K_RAW: case K_CODE: if (state->ks_mode != *(int *)arg) { pckbd_clear_state(kbd); state->ks_mode = *(int *)arg; } break; default: splx(s); return EINVAL; } break; case KDGETLED: /* get keyboard LED */ *(int *)arg = KBD_LED_VAL(kbd); break; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 66): ival = IOCPARM_IVAL(arg); arg = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSETLED: /* set keyboard LED */ /* NOTE: lock key state in ks_state won't be changed */ if (*(int *)arg & ~LOCK_MASK) { splx(s); return EINVAL; } i = *(int *)arg; /* replace CAPS LED with ALTGR LED for ALTGR keyboards */ if (kbd->kb_keymap->n_keys > ALTGR_OFFSET) { if (i & ALKED) i |= CLKED; else i &= ~CLKED; } KBD_LED_VAL(kbd) = *(int *)arg; break; case KDGKBSTATE: /* get lock key state */ *(int *)arg = state->ks_state & LOCK_MASK; break; #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD4) || defined(COMPAT_43) case _IO('K', 20): ival = IOCPARM_IVAL(arg); arg = (caddr_t)&ival; /* FALLTHROUGH */ #endif case KDSKBSTATE: /* set lock key state */ if (*(int *)arg & ~LOCK_MASK) { splx(s); return EINVAL; } state->ks_state &= ~LOCK_MASK; state->ks_state |= *(int *)arg; splx(s); /* set LEDs and quit */ return pckbd_ioctl(kbd, KDSETLED, arg); case KDSETRAD: /* set keyboard repeat rate (old interface)*/ break; case KDSETREPEAT: /* set keyboard repeat rate (new interface) */ break; case PIO_KEYMAP: /* set keyboard translation table */ case OPIO_KEYMAP: /* set keyboard translation table (compat) */ case PIO_KEYMAPENT: /* set keyboard translation table entry */ case PIO_DEADKEYMAP: /* set accent key translation table */ state->ks_accents = 0; /* FALLTHROUGH */ default: splx(s); return genkbd_commonioctl(kbd, cmd, arg); } splx(s); return 0; }
int sunos_sys_ioctl(struct lwp *l, const struct sunos_sys_ioctl_args *uap, register_t *retval) { /* { int fd; u_long com; void * data; } */ file_t *fp; int (*ctl)(struct file *, u_long, void *); struct sys_ioctl_args pass_ua; int error; if ((fp = fd_getfile(SCARG(uap, fd))) == NULL) return EBADF; if ((fp->f_flag & (FREAD|FWRITE)) == 0) { error = EBADF; goto out; } error = EPASSTHROUGH; SCARG(&pass_ua, com) = SCARG(uap, com); ctl = fp->f_ops->fo_ioctl; switch (SCARG(uap, com)) { case _IOR('t', 0, int): SCARG(&pass_ua, com) = TIOCGETD; break; case _IOW('t', 1, int): { int disc; if ((error = copyin(SCARG(uap, data), (void *)&disc, sizeof disc)) != 0) break; /* map SunOS NTTYDISC into our termios discipline */ if (disc == 2) disc = 0; /* all other disciplines are not supported by NetBSD */ if (disc) { error = ENXIO; break; } error = (*ctl)(fp, TIOCSETD, &disc); } case _IOW('t', 101, int): /* sun SUNOS_TIOCSSOFTCAR */ { int x; /* unused */ error = copyin(SCARG(uap, data), (void *)&x, sizeof x); break; } case _IOR('t', 100, int): /* sun SUNOS_TIOCSSOFTCAR */ { int x = 0; error = copyout((void *)&x, SCARG(uap, data), sizeof x); break; } case _IO('t', 36): /* sun TIOCCONS, no parameters */ { int on = 1; error = (*ctl)(fp, TIOCCONS, &on); break; } case _IOW('t', 37, struct sunos_ttysize): { struct winsize ws; struct sunos_ttysize ss; if ((error = (*ctl)(fp, TIOCGWINSZ, &ws)) != 0) break; if ((error = copyin (SCARG(uap, data), &ss, sizeof (ss))) != 0) break; ws.ws_row = ss.ts_row; ws.ws_col = ss.ts_col; error = (*ctl)(fp, TIOCSWINSZ, &ws); break; } case _IOW('t', 38, struct sunos_ttysize): { struct winsize ws; struct sunos_ttysize ss; if ((error = (*ctl)(fp, TIOCGWINSZ, &ws)) != 0) break; ss.ts_row = ws.ws_row; ss.ts_col = ws.ws_col; error = copyout((void *)&ss, SCARG(uap, data), sizeof (ss)); break; } case _IOR('t', 119, int): /* TIOCGPGRP */ { int pgrp; error = (*ctl)(fp, TIOCGPGRP, &pgrp); if (error == 0 && pgrp == 0) error = EIO; if (error) break; error = copyout((void *)&pgrp, SCARG(uap, data), sizeof(pgrp)); break; } case _IOW('t', 130, int): /* TIOCSETPGRP: posix variant */ SCARG(&pass_ua, com) = TIOCSPGRP; break; case _IOR('t', 131, int): /* TIOCGETPGRP: posix variant */ { /* * sigh, must do error translation on pty devices. if the pgrp * returned is 0 (and no error), we convert this to EIO, if it * is on a pty. */ int pgrp; struct vnode *vp = NULL; error = (*ctl)(fp, TIOCGPGRP, &pgrp); if (error) { if (fp->f_type == DTYPE_VNODE) vp = fp->f_vnode; if ((error == EIO || (error == 0 && pgrp == 0)) && vp != NULL && vp->v_type == VCHR && major(vp->v_rdev) == 21) error = ENOTTY; break; } error = copyout((void *)&pgrp, SCARG(uap, data), sizeof(pgrp)); break; } case _IO('t', 132): SCARG(&pass_ua, com) = TIOCSCTTY; break; case SUNOS_TCGETA: case SUNOS_TCGETS: { struct termios bts; struct sunos_termios sts; struct sunos_termio st; if ((error = (*ctl)(fp, TIOCGETA, &bts)) != 0) break; btios2stios (&bts, &sts); if (SCARG(uap, com) == SUNOS_TCGETA) { stios2stio (&sts, &st); error = copyout((void *)&st, SCARG(uap, data), sizeof (st)); } else error = copyout((void *)&sts, SCARG(uap, data), sizeof (sts)); break; } case SUNOS_TCSETA: case SUNOS_TCSETAW: case SUNOS_TCSETAF: { struct termios bts; struct sunos_termios sts; struct sunos_termio st; if ((error = copyin(SCARG(uap, data), &st, sizeof (st))) != 0) break; /* get full BSD termios so we don't lose information */ if ((error = (*ctl)(fp, TIOCGETA, &bts)) != 0) break; /* * convert to sun termios, copy in information from * termio, and convert back, then set new values. */ btios2stios(&bts, &sts); stio2stios(&st, &sts); stios2btios(&sts, &bts); error = (*ctl)(fp, SCARG(uap, com) - SUNOS_TCSETA + TIOCSETA, &bts); break; } case SUNOS_TCSETS: case SUNOS_TCSETSW: case SUNOS_TCSETSF: { struct termios bts; struct sunos_termios sts; if ((error = copyin (SCARG(uap, data), (void *)&sts, sizeof (sts))) != 0) break; stios2btios (&sts, &bts); error = (*ctl)(fp, SCARG(uap, com) - SUNOS_TCSETS + TIOCSETA, &bts); break; } /* * Pseudo-tty ioctl translations. */ case _IOW('t', 32, int): { /* TIOCTCNTL */ int on; error = copyin (SCARG(uap, data), (void *)&on, sizeof (on)); if (error) break; error = (*ctl)(fp, TIOCUCNTL, &on); break; } case _IOW('t', 33, int): { /* TIOCSIGNAL */ int sig; error = copyin (SCARG(uap, data), (void *)&sig, sizeof (sig)); if (error) break; error = (*ctl)(fp, TIOCSIG, &sig); break; } /* * Socket ioctl translations. */ #define IFREQ_IN(a) { \ struct oifreq ifreq; \ error = copyin (SCARG(uap, data), (void *)&ifreq, sizeof (ifreq)); \ if (error) \ break; \ error = (*ctl)(fp, a, &ifreq); \ break; \ } #define IFREQ_INOUT(a) { \ struct oifreq ifreq; \ error = copyin (SCARG(uap, data), (void *)&ifreq, sizeof (ifreq)); \ if (error) \ break; \ if ((error = (*ctl)(fp, a, &ifreq)) != 0) \ break; \ error = copyout ((void *)&ifreq, SCARG(uap, data), sizeof (ifreq)); \ break; \ } case _IOW('i', 12, struct oifreq): /* SIOCSIFADDR */ case _IOW('i', 14, struct oifreq): /* SIOCSIFDSTADDR */ case _IOW('i', 16, struct oifreq): /* SIOCSIFFLAGS */ case _IOWR('i', 17, struct oifreq): /* SIOCGIFFLAGS */ case _IOW('i', 30, struct arpreq): /* SIOCSARP */ case _IOWR('i', 31, struct arpreq): /* SIOCGARP */ case _IOW('i', 32, struct arpreq): /* SIOCDARP */ break; case _IOWR('i', 13, struct oifreq): IFREQ_INOUT(OOSIOCGIFADDR); case _IOWR('i', 15, struct oifreq): IFREQ_INOUT(OOSIOCGIFDSTADDR); case _IOW('i', 21, struct oifreq): IFREQ_IN(SIOCSIFMTU); case _IOWR('i', 22, struct oifreq): IFREQ_INOUT(SIOCGIFMTU); case _IOWR('i', 23, struct oifreq): IFREQ_INOUT(SIOCGIFBRDADDR); case _IOW('i', 24, struct oifreq): IFREQ_IN(SIOCSIFBRDADDR); case _IOWR('i', 25, struct oifreq): IFREQ_INOUT(OOSIOCGIFNETMASK); case _IOW('i', 26, struct oifreq): IFREQ_IN(SIOCSIFNETMASK); case _IOWR('i', 27, struct oifreq): IFREQ_INOUT(SIOCGIFMETRIC); case _IOWR('i', 28, struct oifreq): IFREQ_IN(SIOCSIFMETRIC); case _IOW('i', 18, struct oifreq): /* SIOCSIFMEM */ case _IOWR('i', 19, struct oifreq): /* SIOCGIFMEM */ case _IOW('i', 40, struct oifreq): /* SIOCUPPER */ case _IOW('i', 41, struct oifreq): /* SIOCLOWER */ case _IOW('i', 44, struct oifreq): /* SIOCSETSYNC */ case _IOWR('i', 45, struct oifreq): /* SIOCGETSYNC */ case _IOWR('i', 46, struct oifreq): /* SIOCSDSTATS */ case _IOWR('i', 47, struct oifreq): /* SIOCSESTATS */ case _IOW('i', 48, int): /* SIOCSPROMISC */ case _IOW('i', 49, struct oifreq): /* SIOCADDMULTI */ case _IOW('i', 50, struct oifreq): /* SIOCDELMULTI */ error = EOPNOTSUPP; break; case _IOWR('i', 20, struct oifconf): /* SIOCGIFCONF */ { struct oifconf ifc; /* * XXX: two more problems * 1. our sockaddr's are variable length, not always sizeof(sockaddr) * 2. this returns a name per protocol, ie. it returns two "lo0"'s */ error = copyin (SCARG(uap, data), &ifc, sizeof (ifc)); if (error) break; error = (*ctl)(fp, OOSIOCGIFCONF, &ifc); if (error) break; error = copyout ((void *)&ifc, SCARG(uap, data), sizeof (ifc)); break; } /* * Audio ioctl translations. */ case _IOR('A', 1, struct sunos_audio_info): /* AUDIO_GETINFO */ sunos_au_getinfo: { struct audio_info aui; struct sunos_audio_info sunos_aui; error = (*ctl)(fp, AUDIO_GETINFO, &aui); if (error) break; sunos_aui.play = *(struct sunos_audio_prinfo *)&aui.play; sunos_aui.record = *(struct sunos_audio_prinfo *)&aui.record; /* `avail_ports' is `seek' in BSD */ sunos_aui.play.avail_ports = AUDIO_SPEAKER | AUDIO_HEADPHONE; sunos_aui.record.avail_ports = AUDIO_SPEAKER | AUDIO_HEADPHONE; sunos_aui.play.waiting = 0; sunos_aui.record.waiting = 0; sunos_aui.play.eof = 0; sunos_aui.record.eof = 0; sunos_aui.monitor_gain = 0; /* aui.__spare; XXX */ /*XXXsunos_aui.output_muted = 0;*/ /*XXX*/sunos_aui.reserved[0] = 0; /*XXX*/sunos_aui.reserved[1] = 0; /*XXX*/sunos_aui.reserved[2] = 0; /*XXX*/sunos_aui.reserved[3] = 0; error = copyout ((void *)&sunos_aui, SCARG(uap, data), sizeof (sunos_aui)); break; } case _IOWR('A', 2, struct sunos_audio_info): /* AUDIO_SETINFO */ { struct audio_info aui; struct sunos_audio_info sunos_aui; error = copyin (SCARG(uap, data), (void *)&sunos_aui, sizeof (sunos_aui)); if (error) break; aui.play = *(struct audio_prinfo *)&sunos_aui.play; aui.record = *(struct audio_prinfo *)&sunos_aui.record; /* aui.__spare = sunos_aui.monitor_gain; */ aui.blocksize = ~0; aui.hiwat = ~0; aui.lowat = ~0; /* XXX somebody check this please. - is: aui.backlog = ~0; */ aui.mode = ~0; /* * The bsd driver does not distinguish between paused and * active. (In the sun driver, not active means samples are * not output at all, but paused means the last streams buffer * is drained and then output stops.) If either are 0, then * when stop output. Otherwise, if either are non-zero, * we resume. */ if (sunos_aui.play.pause == 0 || sunos_aui.play.active == 0) aui.play.pause = 0; else if (sunos_aui.play.pause != (u_char)~0 || sunos_aui.play.active != (u_char)~0) aui.play.pause = 1; if (sunos_aui.record.pause == 0 || sunos_aui.record.active == 0) aui.record.pause = 0; else if (sunos_aui.record.pause != (u_char)~0 || sunos_aui.record.active != (u_char)~0) aui.record.pause = 1; error = (*ctl)(fp, AUDIO_SETINFO, &aui); if (error) break; /* Return new state */ goto sunos_au_getinfo; } case _IO('A', 3): /* AUDIO_DRAIN */ error = (*ctl)(fp, AUDIO_DRAIN, NULL); break; case _IOR('A', 4, int): /* AUDIO_GETDEV */ { int devtype = SUNOS_AUDIO_DEV_AMD; error = copyout ((void *)&devtype, SCARG(uap, data), sizeof (devtype)); break; } /* * Selected streams ioctls. */ #define SUNOS_S_FLUSHR 1 #define SUNOS_S_FLUSHW 2 #define SUNOS_S_FLUSHRW 3 #define SUNOS_S_INPUT 1 #define SUNOS_S_HIPRI 2 #define SUNOS_S_OUTPUT 4 #define SUNOS_S_MSG 8 case _IO('S', 5): /* I_FLUSH */ { int tmp = 0; switch ((int)(u_long)SCARG(uap, data)) { case SUNOS_S_FLUSHR: tmp = FREAD; break; case SUNOS_S_FLUSHW: tmp = FWRITE; break; case SUNOS_S_FLUSHRW: tmp = FREAD|FWRITE; break; } error = (*ctl)(fp, TIOCFLUSH, &tmp); break; } case _IO('S', 9): /* I_SETSIG */ { int on = 1; if (((int)(u_long)SCARG(uap, data) & (SUNOS_S_HIPRI|SUNOS_S_INPUT)) == SUNOS_S_HIPRI) { error = EOPNOTSUPP; break; } error = (*ctl)(fp, FIOASYNC, &on); break; } /* * SunOS disk ioctls, taken from arch/sparc/sparc/disksubr.c * (which was from the old sparc/scsi/sun_disklabel.c), and * modified to suite. */ case SUN_DKIOCGGEOM: { struct disklabel dl; error = (*ctl)(fp, DIOCGDINFO, &dl); if (error) break; #define datageom ((struct sun_dkgeom *)SCARG(uap, data)) memset(SCARG(uap, data), 0, sizeof(*datageom)); datageom->sdkc_ncylinders = dl.d_ncylinders; datageom->sdkc_acylinders = dl.d_acylinders; datageom->sdkc_ntracks = dl.d_ntracks; datageom->sdkc_nsectors = dl.d_nsectors; datageom->sdkc_interleave = dl.d_interleave; datageom->sdkc_sparespercyl = dl.d_sparespercyl; datageom->sdkc_rpm = dl.d_rpm; datageom->sdkc_pcylinders = dl.d_ncylinders + dl.d_acylinders; #undef datageom break; } case SUN_DKIOCINFO: /* Homey don't do DKIOCINFO */ memset(SCARG(uap, data), 0, sizeof(struct sun_dkctlr)); break; case SUN_DKIOCGPART: { struct partinfo pi; struct disklabel label; error = (*ctl)(fp, DIOCGDINFO, &label); if (error) break; error = (*ctl)(fp, DIOCGPARTINFO, &pi); if (error) break; if (label.d_secpercyl == 0) { error = ERANGE; /* XXX */ break; } if (pi.pi_offset % label.d_secpercyl != 0) { error = ERANGE; /* XXX */ break; } #define datapart ((struct sun_dkpart *)SCARG(uap, data)) datapart->sdkp_cyloffset = pi.pi_offset / label.d_secpercyl; datapart->sdkp_nsectors = pi.pi_size; #undef datapart break; } } out: fd_putfile(SCARG(uap, fd)); if (error == EPASSTHROUGH) { SCARG(&pass_ua, fd) = SCARG(uap, fd); SCARG(&pass_ua, data) = SCARG(uap, data); error = sys_ioctl(l, &pass_ua, retval); } return (error); }