static int rs_open(struct tty_struct *tty, struct file * filp)
{
	struct async_struct	*info;
	int 			retval, line;

	line = tty->index;
	if ((line < 0) || (line >= NR_PORTS)) {
		return -ENODEV;
	}
	retval = get_async_struct(line, &info);
	if (retval) {
		return retval;
	}
	tty->driver_data = info;
	info->tty = tty;
	if (serial_paranoia_check(info, tty->name, "rs_open"))
		return -ENODEV;

#ifdef SERIAL_DEBUG_OPEN
	printk("rs_open %s, count = %d\n", tty->name, info->state->count);
#endif
	info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;

	/*
	 * If the port is the middle of closing, bail out now
	 */
	if (tty_hung_up_p(filp) ||
	    (info->flags & ASYNC_CLOSING)) {
		if (info->flags & ASYNC_CLOSING)
			interruptible_sleep_on(&info->close_wait);
#ifdef SERIAL_DO_RESTART
		return ((info->flags & ASYNC_HUP_NOTIFY) ?
			-EAGAIN : -ERESTARTSYS);
#else
		return -EAGAIN;
#endif
	}

	/*
	 * Start up serial port
	 */
	retval = startup(info);
	if (retval) {
		return retval;
	}

	retval = block_til_ready(tty, filp, info);
	if (retval) {
#ifdef SERIAL_DEBUG_OPEN
		printk("rs_open returning after block_til_ready with %d\n",
		       retval);
#endif
		return retval;
	}

#ifdef SERIAL_DEBUG_OPEN
	printk("rs_open %s successful...", tty->name);
#endif
	return 0;
}
Exemple #2
0
/*
 * This routine is called whenever a serial port is opened.  It
 * enables interrupts for a serial port, linking in its async structure into
 * the IRQ chain.   It also performs the serial-specific
 * initialization for the tty structure.
 */
static int
pdc_open(struct tty_struct *tty, struct file *filp)
{
    struct async_struct *info;
    int retval, line;
    unsigned long page;

    MOD_INC_USE_COUNT;
    line = MINOR(tty->device) - tty->driver.minor_start;
    if ((line < 0) || (line >= NR_PORTS)) {
        MOD_DEC_USE_COUNT;
        return -ENODEV;
    }
    retval = get_async_struct(line, &info);
    if (retval) {
        MOD_DEC_USE_COUNT;
        return retval;
    }
    tty->driver_data = info;
    info->tty = tty;
    pdc_drv_info = info;

#ifdef PDC_DEBUG_OPEN
    printk("pdc_open %s%d, count = %d\n", tty->driver.name, info->line,
           info->state->count);
#endif
    info->tty->low_latency = 0;
    if (!tmp_buf) {
        page = get_zeroed_page(GFP_KERNEL);
        if (!page) {
            MOD_DEC_USE_COUNT;
            return -ENOMEM;
        }
        if (tmp_buf)
            free_page(page);
        else
            tmp_buf = (unsigned char *) page;
    }

    info->session = current->session;
    info->pgrp = current->pgrp;

#ifdef PDC_DEBUG_OPEN
    printk("pdc_open ttyB%d successful...", info->line);
#endif
    pdc_drv_refcount++;
    return 0;
}
Exemple #3
0
/*
 * This routine is called whenever a serial port is opened.  It
 * enables interrupts for a serial port, linking in its async structure into
 * the IRQ chain.   It also performs the serial-specific
 * initialization for the tty structure.
 */
static int rs_open(struct tty_struct *tty, struct file * filp)
{
    struct async_struct	*info;
    int			retval, line;
    unsigned long		page;

    line = tty->index;
    if ((line < 0) || (line >= NR_PORTS))
        return -ENODEV;
    retval = get_async_struct(line, &info);
    if (retval)
        return retval;
    tty->driver_data = info;
    info->tty = tty;

#ifdef SIMSERIAL_DEBUG
    printk("rs_open %s, count = %d\n", tty->name, info->state->count);
#endif
    info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;

    if (!tmp_buf) {
        page = get_zeroed_page(GFP_KERNEL);
        if (!page)
            return -ENOMEM;
        if (tmp_buf)
            free_page(page);
        else
            tmp_buf = (unsigned char *) page;
    }

    /*
     * If the port is the middle of closing, bail out now
     */
    if (tty_hung_up_p(filp) ||
            (info->flags & ASYNC_CLOSING)) {
        if (info->flags & ASYNC_CLOSING)
            interruptible_sleep_on(&info->close_wait);
#ifdef SERIAL_DO_RESTART
        return ((info->flags & ASYNC_HUP_NOTIFY) ?
                -EAGAIN : -ERESTARTSYS);
#else
        return -EAGAIN;
#endif
    }

    /*
     * Start up serial port
     */
    retval = startup(info);
    if (retval) {
        return retval;
    }

    /*
     * figure out which console to use (should be one already)
     */
    console = console_drivers;
    while (console) {
        if ((console->flags & CON_ENABLED) && console->write) break;
        console = console->next;
    }

#ifdef SIMSERIAL_DEBUG
    printk("rs_open ttys%d successful\n", info->line);
#endif
    return 0;
}