int felica_uart_open(void) { struct termios newtio; mm_segment_t old_fs = get_fs(); #ifdef FEATURE_DEBUG_LOW FELICA_DEBUG_MSG("[FELICA_UART] open_hs_uart - start \n"); #endif if(FELICA_UART_NOTAVAILABLE == get_felica_uart_status()) { #ifdef FEATURE_DEBUG_HIGH FELICA_DEBUG_MSG("[FELICA_UART] collision!! uart is used by other device \n"); #endif return -1; } if (uart_f != NULL) { #ifdef FEATURE_DEBUG_HIGH FELICA_DEBUG_MSG("[FELICA_UART] felica_uart is already opened\n"); #endif return 0; } set_fs(KERNEL_DS); uart_f = filp_open(FELICA_UART_NAME, O_RDWR | O_NOCTTY | O_NONBLOCK, 0); #ifdef FEATURE_DEBUG_LOW FELICA_DEBUG_MSG("[FELICA_UART] open UART\n"); #endif if (uart_f == NULL) { #ifdef FEATURE_DEBUG_HIGH FELICA_DEBUG_MSG("[FELICA_UART] ERROR - can not sys_open \n"); #endif set_fs(old_fs); return -1; } set_felica_uart_status(UART_STATUS_FOR_FELICA); memset(&newtio, 0, sizeof(newtio)); newtio.c_cflag = B460800 | CS8 | CLOCAL | CREAD; newtio.c_cc[VMIN] = 1; newtio.c_cc[VTIME] = 5; do_vfs_ioctl(uart_f, -1, TCFLSH, TCIOFLUSH); do_vfs_ioctl(uart_f, -1, TCSETSF, (unsigned long)&newtio); set_fs(old_fs); #ifdef FEATURE_DEBUG_LOW FELICA_DEBUG_MSG("[FELICA_UART] open_hs_uart - end \n"); #endif return 0; }
/* * Description : get size of remaing data * Input : none * Output : success : data length fail : 0 */ int felica_uart_ioctrl(int *count) { mm_segment_t old_fs = get_fs(); int n; #ifdef FEATURE_DEBUG_LOW FELICA_DEBUG_MSG("[FELICA_UART] felica_uart_ioctrl - start \n"); #endif if (uart_f == NULL) { FELICA_DEBUG_MSG("[FELICA_UART] felica_uart is not opened\n"); return 0; } set_fs(KERNEL_DS); n = do_vfs_ioctl(uart_f, -1, TIOCINQ, (unsigned long)count); #ifdef FEATURE_DEBUG_LOW FELICA_DEBUG_MSG("[FELICA_UART] do_vfs_ioctl return %d, count=%d\n", n, *count); #endif set_fs(old_fs); #ifdef FEATURE_DEBUG_LOW FELICA_DEBUG_MSG("[FELICA_UART] felica_uart_ioctrl - end \n"); #endif return n; }
/***************************************************************************** * 函 数 名 : bsp_acm_ioctl * * 功能描述 : 数据通道属性配置 * * 输入参数 : handle: 设备的handle * u32Cmd: IOCTL命令码 * pParam: 操作参数 * 输出参数 : * * 返 回 值 : 成功/失败 *****************************************************************************/ s32 bsp_acm_ioctl(void* handle, u32 cmd, void *para) { mm_segment_t old_fs; struct file* filp = (struct file*)handle; struct adp_acm_context* ctx; int status; if (unlikely(ADP_ACM_FILP_INVALID(filp))) { stat_invalid_filp++; return -EINVAL; } ctx = (struct adp_acm_context*)filp->private_data; atomic_inc(&ctx->opt_cnt); if (unlikely(!ctx->is_open || !(filp->f_path.dentry))) { status = -ENXIO; goto ioctl_ret; } old_fs = get_fs(); set_fs(KERNEL_DS); status = do_vfs_ioctl(filp, 0, (unsigned int)cmd, (unsigned long)para); set_fs(old_fs); ioctl_ret: atomic_dec(&ctx->opt_cnt); if (status < 0) { ctx->stat.stat_ioctl_err++; ctx->stat.stat_ioctl_last_err = status; } return status; }
SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) { struct file *filp; int error = -EBADF; int fput_needed; filp = fget_light(fd, &fput_needed); if (!filp) goto out; #ifdef CONFIG_KRG_FAF if ((filp->f_flags & O_FAF_CLT) && (cmd != FIOCLEX) && (cmd != FIONCLEX)) { error = krg_faf_ioctl(filp, cmd, arg); goto out_fput; } #endif error = security_file_ioctl(filp, cmd, arg); if (error) goto out_fput; error = do_vfs_ioctl(filp, fd, cmd, arg); out_fput: fput_light(filp, fput_needed); out: return error; }
int expressos_ipc_ioctl(int helper_pid, int fd, unsigned cmd, int arg0) { int ret; mm_segment_t fs_save; struct expressos_venus_proc *proc; struct file *file; switch (cmd) { case FIONREAD: arg0 = (int)expressos_ipc_shm_buf; break; default: return -ENOTTY; } if (!(proc = expressos_venus_find_proc(helper_pid))) return -EINVAL; if (!(file = expressos_venus_fget(proc, fd))) return -EBADF; fs_save = get_fs(); set_fs(get_ds()); ret = do_vfs_ioctl(file, -1, cmd, arg0); set_fs(fs_save); fput(file); return ret; }
/* * Description : open uart * Input : None * Output : success : 0 fail : others */ int ffu_uart_open(void) { struct termios newtio; mm_segment_t old_fs = get_fs(); #ifdef FFU_DEBUG_LOW FFU_DEBUG_MSG("[FFU_UART] open_hs_uart - start \n"); #endif if (uart_f != NULL) { FFU_DEBUG_MSG("[FFU_UART] ffu_uart is already opened\n"); return 0; } set_fs(KERNEL_DS); uart_f = filp_open("/dev/ttyHSL1", O_RDWR | O_NOCTTY | O_NONBLOCK, 0); FFU_DEBUG_MSG("[FFU_UART] open UART\n"); if (uart_f == NULL) { FFU_DEBUG_MSG("[FFU_UART] ERROR - can not sys_open \n"); set_fs(old_fs); return -1; } memset(&newtio, 0, sizeof(newtio)); newtio.c_cflag = B460800 | CS8 | CLOCAL | CREAD; newtio.c_cc[VMIN] = 1; newtio.c_cc[VTIME] = 5; do_vfs_ioctl(uart_f, -1, TCFLSH, TCIOFLUSH); do_vfs_ioctl(uart_f, -1, TCSETSF, (unsigned long)&newtio); set_fs(old_fs); #ifdef FFU_DEBUG_LOW FFU_DEBUG_MSG("[FFU_UART] open_hs_uart - end \n"); #endif return 0; }
SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) { int error; struct fd f = fdget(fd); if (!f.file) return -EBADF; error = security_file_ioctl(f.file, cmd, arg); if (!error) error = do_vfs_ioctl(f.file, fd, cmd, arg); fdput(f); return error; }
int ksys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) { int error; struct fd f = fdget(fd); if (!f.file) return -EBADF; error = security_file_ioctl(f.file, cmd, arg); if (!error) error = do_vfs_ioctl(f.file, fd, cmd, arg); fdput(f); return error; }
int expressos_ipc_ashmem_ioctl(int helper_pid, int fd, unsigned cmd, int arg0) { int ret; mm_segment_t fs_save; struct expressos_venus_proc *proc; struct file *file; switch (cmd) { case ASHMEM_PIN: case ASHMEM_UNPIN: case ASHMEM_SET_NAME: case ASHMEM_GET_NAME: arg0 = (int)expressos_ipc_shm_buf; break; case ASHMEM_SET_SIZE: case ASHMEM_GET_SIZE: case ASHMEM_SET_PROT_MASK: case ASHMEM_GET_PROT_MASK: case ASHMEM_GET_PIN_STATUS: case ASHMEM_PURGE_ALL_CACHES: break; default: return -ENOSYS; } if (!(proc = expressos_venus_find_proc(helper_pid))) return -EINVAL; if (!(file = expressos_venus_fget(proc, fd))) return -EBADF; fs_save = get_fs(); set_fs(get_ds()); ret = do_vfs_ioctl(file, -1, cmd, arg0); set_fs(fs_save); fput(file); return ret; }
SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) { struct file *filp; int error = -EBADF; int fput_needed; filp = fget_light(fd, &fput_needed); if (!filp) goto out; error = security_file_ioctl(filp, cmd, arg); if (error) goto out_fput; error = do_vfs_ioctl(filp, fd, cmd, arg); out_fput: fput_light(filp, fput_needed); out: return error; }
asmlinkage long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) { struct file *filp; int error = -EBADF; int fput_needed; filp = fget_light(fd, &fput_needed); if (!filp) goto out; error = security_file_ioctl(filp, cmd, arg); if (error) goto out_fput; error = do_vfs_ioctl(filp, fd, cmd, arg); out_fput: fput_light(filp, fput_needed); out: return error; }
/* * Description : get size of remaing data * Input : none * Output : success : data length fail : 0 */ int felica_uart_ioctrl(int *count) { mm_segment_t old_fs = get_fs(); int n; FELICA_DEBUG_MSG_LOW("[FELICA_UART] felica_uart_ioctrl - start \n"); if (uart_f == NULL) { FELICA_DEBUG_MSG_HIGH("[FELICA_UART] felica_uart is not opened\n"); return 0; } set_fs(KERNEL_DS); n = do_vfs_ioctl(uart_f, -1, TIOCINQ, (unsigned long)count); FELICA_DEBUG_MSG_MED("[FELICA_UART] do_vfs_ioctl return(%d), count(%d) \n", n, *count); set_fs(old_fs); FELICA_DEBUG_MSG_LOW("[FELICA_UART] felica_uart_ioctrl - end \n"); return n; }