4 * Copyright (C) 1998/1999 R.E.Wolff@BitWizard.nl
6 * written for the SX serial driver.
7 * Contains the code that should be shared over all the serial drivers.
9 * Credit for the idea to do it this way might go to Alan Cox.
12 * Version 0.1 -- December, 1998. Initial version.
13 * Version 0.2 -- March, 1999. Some more routines. Bugfixes. Etc.
14 * Version 0.5 -- August, 1999. Some more fixes. Reformat for Linus.
16 * BitWizard is actively maintaining this file. We sometimes find
17 * that someone submitted changes to this file. We really appreciate
18 * your help, but please submit changes through us. We're doing our
19 * best to be responsive. -- REW
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/tty.h>
25 #include <linux/serial.h>
27 #include <linux/generic_serial.h>
28 #include <linux/interrupt.h>
29 #include <asm/semaphore.h>
30 #include <asm/uaccess.h>
34 static char * tmp_buf
;
35 static DECLARE_MUTEX(tmp_buf_sem
);
40 #define gs_dprintk(f, str...) if (gs_debug & f) printk (str)
42 #define gs_dprintk(f, str...) /* nothing */
45 #define func_enter() gs_dprintk (GS_DEBUG_FLOW, "gs: enter %s\n", __FUNCTION__)
46 #define func_exit() gs_dprintk (GS_DEBUG_FLOW, "gs: exit %s\n", __FUNCTION__)
49 #define DECL /* Nothing */
50 #define LOCKIT down (& port->port_write_sem);
51 #define RELEASEIT up (&port->port_write_sem);
53 #define DECL unsigned long flags;
54 #define LOCKIT save_flags (flags);cli ()
55 #define RELEASEIT restore_flags (flags)
58 #define RS_EVENT_WRITE_WAKEUP 1
60 MODULE_PARM(gs_debug
, "i");
63 void gs_put_char(struct tty_struct
* tty
, unsigned char ch
)
72 port
= tty
->driver_data
;
76 if (! (port
->flags
& ASYNC_INITIALIZED
)) return;
78 /* Take a lock on the serial tranmit buffer! */
81 if (port
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
82 /* Sorry, buffer is full, drop character. Update statistics???? -- REW */
87 port
->xmit_buf
[port
->xmit_head
++] = ch
;
88 port
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
89 port
->xmit_cnt
++; /* Characters in buffer */
96 #ifdef NEW_WRITE_LOCKING
99 > Problems to take into account are:
100 > -1- Interrupts that empty part of the buffer.
101 > -2- page faults on the access to userspace.
102 > -3- Other processes that are also trying to do a "write".
105 int gs_write(struct tty_struct
* tty
, int from_user
,
106 const unsigned char *buf
, int count
)
108 struct gs_port
*port
;
116 port
= tty
->driver_data
;
120 if (! (port
->flags
& ASYNC_INITIALIZED
))
123 /* get exclusive "write" access to this port (problem 3) */
124 /* This is not a spinlock because we can have a disk access (page
125 fault) in copy_from_user */
126 down (& port
->port_write_sem
);
132 /* This is safe because we "OWN" the "head". Noone else can
133 change the "head": we own the port_write_sem. */
134 /* Don't overrun the end of the buffer */
135 t
= SERIAL_XMIT_SIZE
- port
->xmit_head
;
138 /* This is safe because the xmit_cnt can only decrease. This
139 would increase "t", so we might copy too little chars. */
140 /* Don't copy past the "head" of the buffer */
141 t
= SERIAL_XMIT_SIZE
- 1 - port
->xmit_cnt
;
144 /* Can't copy more? break out! */
147 if (copy_from_user (port
->xmit_buf
+ port
->xmit_head
,
149 up (& port
->port_write_sem
);
154 memcpy (port
->xmit_buf
+ port
->xmit_head
, buf
, c
);
156 port
-> xmit_cnt
+= c
;
157 port
-> xmit_head
= (port
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
162 up (& port
->port_write_sem
);
164 gs_dprintk (GS_DEBUG_WRITE
, "write: interrupts are %s\n",
165 (port
->flags
& GS_TX_INTEN
)?"enabled": "disabled");
167 if (port
->xmit_cnt
&&
170 !(port
->flags
& GS_TX_INTEN
)) {
171 port
->flags
|= GS_TX_INTEN
;
172 port
->rd
->enable_tx_interrupts (port
);
179 > Problems to take into account are:
180 > -1- Interrupts that empty part of the buffer.
181 > -2- page faults on the access to userspace.
182 > -3- Other processes that are also trying to do a "write".
185 int gs_write(struct tty_struct
* tty
, int from_user
,
186 const unsigned char *buf
, int count
)
188 struct gs_port
*port
;
195 /* The standard serial driver returns 0 in this case.
196 That sounds to me as "No error, I just didn't get to writing any
197 bytes. Feel free to try again."
198 The "official" way to write n bytes from buf is:
200 for (nwritten = 0;nwritten < n;nwritten += rv) {
201 rv = write (fd, buf+nwritten, n-nwritten);
202 if (rv < 0) break; // Error: bail out. //
205 which will loop endlessly in this case. The manual page for write
206 agrees with me. In practise almost everybody writes
207 "write (fd, buf,n);" but some people might have had to deal with
208 incomplete writes in the past and correctly implemented it by now...
211 if (!tty
) return -EIO
;
213 port
= tty
->driver_data
;
214 if (!port
|| !port
->xmit_buf
|| !tmp_buf
)
223 /* This is safe because we "OWN" the "head". Noone else can
224 change the "head": we own the port_write_sem. */
225 /* Don't overrun the end of the buffer */
226 t
= SERIAL_XMIT_SIZE
- port
->xmit_head
;
229 /* This is safe because the xmit_cnt can only decrease. This
230 would increase "t", so we might copy too little chars. */
231 /* Don't copy past the "head" of the buffer */
232 t
= SERIAL_XMIT_SIZE
- 1 - port
->xmit_cnt
;
235 /* Can't copy more? break out! */
238 c
-= copy_from_user(tmp_buf
, buf
, c
);
245 t
= SERIAL_XMIT_SIZE
- port
->xmit_head
;
247 t
= SERIAL_XMIT_SIZE
- 1 - port
->xmit_cnt
;
250 memcpy(port
->xmit_buf
+ port
->xmit_head
, tmp_buf
, c
);
251 port
->xmit_head
= ((port
->xmit_head
+ c
) &
252 (SERIAL_XMIT_SIZE
-1));
254 restore_flags(flags
);
265 /* This is safe because we "OWN" the "head". Noone else can
266 change the "head": we own the port_write_sem. */
267 /* Don't overrun the end of the buffer */
268 t
= SERIAL_XMIT_SIZE
- port
->xmit_head
;
271 /* This is safe because the xmit_cnt can only decrease. This
272 would increase "t", so we might copy too little chars. */
273 /* Don't copy past the "head" of the buffer */
274 t
= SERIAL_XMIT_SIZE
- 1 - port
->xmit_cnt
;
277 /* Can't copy more? break out! */
279 restore_flags(flags
);
282 memcpy(port
->xmit_buf
+ port
->xmit_head
, buf
, c
);
283 port
->xmit_head
= ((port
->xmit_head
+ c
) &
284 (SERIAL_XMIT_SIZE
-1));
286 restore_flags(flags
);
293 if (port
->xmit_cnt
&&
296 !(port
->flags
& GS_TX_INTEN
)) {
297 port
->flags
|= GS_TX_INTEN
;
298 port
->rd
->enable_tx_interrupts (port
);
308 int gs_write_room(struct tty_struct
* tty
)
310 struct gs_port
*port
= tty
->driver_data
;
314 ret
= SERIAL_XMIT_SIZE
- port
->xmit_cnt
- 1;
322 int gs_chars_in_buffer(struct tty_struct
*tty
)
324 struct gs_port
*port
= tty
->driver_data
;
328 return port
->xmit_cnt
;
332 int gs_real_chars_in_buffer(struct tty_struct
*tty
)
334 struct gs_port
*port
;
338 port
= tty
->driver_data
;
340 if (!port
->rd
) return 0;
341 if (!port
->rd
->chars_in_buffer
) return 0;
344 return port
->xmit_cnt
+ port
->rd
->chars_in_buffer (port
);
348 static int gs_wait_tx_flushed (void * ptr
, int timeout
)
350 struct gs_port
*port
= ptr
;
351 unsigned long end_jiffies
;
352 int jiffies_to_transmit
, charsleft
= 0, rv
= 0;
357 gs_dprintk (GS_DEBUG_FLUSH
, "port=%p.\n", port
);
359 gs_dprintk (GS_DEBUG_FLUSH
, "xmit_cnt=%x, xmit_buf=%p, tty=%p.\n",
360 port
->xmit_cnt
, port
->xmit_buf
, port
->tty
);
363 if (!port
|| port
->xmit_cnt
< 0 || !port
->xmit_buf
) {
364 gs_dprintk (GS_DEBUG_FLUSH
, "ERROR: !port, !port->xmit_buf or prot->xmit_cnt < 0.\n");
366 return -EINVAL
; /* This is an error which we don't know how to handle. */
369 rcib
= gs_real_chars_in_buffer(port
->tty
);
372 gs_dprintk (GS_DEBUG_FLUSH
, "nothing to wait for.\n");
376 /* stop trying: now + twice the time it would normally take + seconds */
377 if (timeout
== 0) timeout
= MAX_SCHEDULE_TIMEOUT
;
378 end_jiffies
= jiffies
;
379 if (timeout
!= MAX_SCHEDULE_TIMEOUT
)
380 end_jiffies
+= port
->baud
?(2 * rcib
* 10 * HZ
/ port
->baud
):0;
381 end_jiffies
+= timeout
;
383 gs_dprintk (GS_DEBUG_FLUSH
, "now=%lx, end=%lx (%ld).\n",
384 jiffies
, end_jiffies
, end_jiffies
-jiffies
);
386 /* the expression is actually jiffies < end_jiffies, but that won't
387 work around the wraparound. Tricky eh? */
388 while ((charsleft
= gs_real_chars_in_buffer (port
->tty
)) &&
389 time_after (end_jiffies
, jiffies
)) {
391 chars * (bits/char) * (jiffies /sec) / (bits/sec) = jiffies!
394 charsleft
+= 16; /* Allow 16 chars more to be transmitted ... */
395 jiffies_to_transmit
= port
->baud
?(1 + charsleft
* 10 * HZ
/ port
->baud
):0;
396 /* ^^^ Round up.... */
397 if (jiffies_to_transmit
<= 0) jiffies_to_transmit
= 1;
399 gs_dprintk (GS_DEBUG_FLUSH
, "Expect to finish in %d jiffies "
400 "(%d chars).\n", jiffies_to_transmit
, charsleft
);
402 set_current_state (TASK_INTERRUPTIBLE
);
403 schedule_timeout(jiffies_to_transmit
);
404 if (signal_pending (current
)) {
405 gs_dprintk (GS_DEBUG_FLUSH
, "Signal pending. Bombing out: ");
411 gs_dprintk (GS_DEBUG_FLUSH
, "charsleft = %d.\n", charsleft
);
412 set_current_state (TASK_RUNNING
);
420 void gs_flush_buffer(struct tty_struct
*tty
)
422 struct gs_port
*port
;
429 port
= tty
->driver_data
;
433 /* XXX Would the write semaphore do? */
434 save_flags(flags
); cli();
435 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
436 restore_flags(flags
);
438 wake_up_interruptible(&tty
->write_wait
);
439 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
440 tty
->ldisc
.write_wakeup
)
441 (tty
->ldisc
.write_wakeup
)(tty
);
446 void gs_flush_chars(struct tty_struct
* tty
)
448 struct gs_port
*port
;
454 port
= tty
->driver_data
;
458 if (port
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
464 /* Beats me -- REW */
465 port
->flags
|= GS_TX_INTEN
;
466 port
->rd
->enable_tx_interrupts (port
);
471 void gs_stop(struct tty_struct
* tty
)
473 struct gs_port
*port
;
479 port
= tty
->driver_data
;
483 if (port
->xmit_cnt
&&
485 (port
->flags
& GS_TX_INTEN
) ) {
486 port
->flags
&= ~GS_TX_INTEN
;
487 port
->rd
->disable_tx_interrupts (port
);
493 void gs_start(struct tty_struct
* tty
)
495 struct gs_port
*port
;
499 port
= tty
->driver_data
;
503 if (port
->xmit_cnt
&&
505 !(port
->flags
& GS_TX_INTEN
) ) {
506 port
->flags
|= GS_TX_INTEN
;
507 port
->rd
->enable_tx_interrupts (port
);
513 void gs_shutdown_port (struct gs_port
*port
)
521 if (!(port
->flags
& ASYNC_INITIALIZED
))
527 if (port
->xmit_buf
) {
528 free_page((unsigned long) port
->xmit_buf
);
533 set_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
535 port
->rd
->shutdown_port (port
);
537 port
->flags
&= ~ASYNC_INITIALIZED
;
538 restore_flags (flags
);
544 void gs_hangup(struct tty_struct
*tty
)
546 struct gs_port
*port
;
552 port
= tty
->driver_data
;
557 gs_shutdown_port (port
);
558 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|GS_ACTIVE
);
562 wake_up_interruptible(&port
->open_wait
);
567 void gs_do_softint(void *private_
)
569 struct gs_port
*port
= private_
;
570 struct tty_struct
*tty
;
580 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &port
->event
)) {
581 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
582 tty
->ldisc
.write_wakeup
)
583 (tty
->ldisc
.write_wakeup
)(tty
);
584 wake_up_interruptible(&tty
->write_wait
);
590 int gs_block_til_ready(void *port_
, struct file
* filp
)
592 struct gs_port
*port
= port_
;
593 DECLARE_WAITQUEUE(wait
, current
);
597 struct tty_struct
*tty
;
607 gs_dprintk (GS_DEBUG_BTR
, "Entering gs_block_till_ready.\n");
609 * If the device is in the middle of being closed, then block
610 * until it's done, and then try again.
612 if (tty_hung_up_p(filp
) || port
->flags
& ASYNC_CLOSING
) {
613 interruptible_sleep_on(&port
->close_wait
);
614 if (port
->flags
& ASYNC_HUP_NOTIFY
)
620 gs_dprintk (GS_DEBUG_BTR
, "after hung up\n");
623 * If non-blocking mode is set, or the port is not enabled,
624 * then make the check up front and then exit.
626 if ((filp
->f_flags
& O_NONBLOCK
) ||
627 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
628 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
632 gs_dprintk (GS_DEBUG_BTR
, "after nonblock\n");
638 * Block waiting for the carrier detect and the line to become
639 * free (i.e., not in use by the callout). While we are in
640 * this loop, port->count is dropped by one, so that
641 * rs_close() knows when to free things. We restore it upon
642 * exit, either normal or abnormal.
646 add_wait_queue(&port
->open_wait
, &wait
);
648 gs_dprintk (GS_DEBUG_BTR
, "after add waitq.\n");
650 if (!tty_hung_up_p(filp
))
653 port
->blocked_open
++;
655 CD
= port
->rd
->get_CD (port
);
656 gs_dprintk (GS_DEBUG_BTR
, "CD is now %d.\n", CD
);
657 set_current_state (TASK_INTERRUPTIBLE
);
658 if (tty_hung_up_p(filp
) ||
659 !(port
->flags
& ASYNC_INITIALIZED
)) {
660 if (port
->flags
& ASYNC_HUP_NOTIFY
)
663 retval
= -ERESTARTSYS
;
666 if (!(port
->flags
& ASYNC_CLOSING
) &&
669 gs_dprintk (GS_DEBUG_BTR
, "signal_pending is now: %d (%lx)\n",
670 (int)signal_pending (current
), *(long*)(¤t
->blocked
));
671 if (signal_pending(current
)) {
672 retval
= -ERESTARTSYS
;
677 gs_dprintk (GS_DEBUG_BTR
, "Got out of the loop. (%d)\n",
679 set_current_state (TASK_RUNNING
);
680 remove_wait_queue(&port
->open_wait
, &wait
);
681 if (!tty_hung_up_p(filp
))
683 port
->blocked_open
--;
687 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
693 void gs_close(struct tty_struct
* tty
, struct file
* filp
)
696 struct gs_port
*port
;
702 port
= (struct gs_port
*) tty
->driver_data
;
707 /* This seems to happen when this is called from vhangup. */
708 gs_dprintk (GS_DEBUG_CLOSE
, "gs: Odd: port->tty is NULL\n");
712 save_flags(flags
); cli();
714 if (tty_hung_up_p(filp
)) {
715 restore_flags(flags
);
716 port
->rd
->hungup (port
);
721 if ((tty
->count
== 1) && (port
->count
!= 1)) {
722 printk(KERN_ERR
"gs: gs_close: bad port count;"
723 " tty->count is 1, port count is %d\n", port
->count
);
726 if (--port
->count
< 0) {
727 printk(KERN_ERR
"gs: gs_close: bad port count: %d\n", port
->count
);
731 gs_dprintk(GS_DEBUG_CLOSE
, "gs_close: count: %d\n", port
->count
);
732 restore_flags(flags
);
736 port
->flags
|= ASYNC_CLOSING
;
739 * Now we wait for the transmit buffer to clear; and we notify
740 * the line discipline to only process XON/XOFF characters.
743 /* if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
744 tty_wait_until_sent(tty, port->closing_wait); */
747 * At this point we stop accepting input. To do this, we
748 * disable the receive line status interrupts, and tell the
749 * interrupt driver to stop checking the data ready bit in the
750 * line status register.
753 port
->rd
->disable_rx_interrupts (port
);
755 /* close has no way of returning "EINTR", so discard return value */
756 if (port
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
757 gs_wait_tx_flushed (port
, port
->closing_wait
);
759 port
->flags
&= ~GS_ACTIVE
;
761 if (tty
->driver
->flush_buffer
)
762 tty
->driver
->flush_buffer(tty
);
763 if (tty
->ldisc
.flush_buffer
)
764 tty
->ldisc
.flush_buffer(tty
);
768 port
->rd
->close (port
);
769 port
->rd
->shutdown_port (port
);
772 if (port
->blocked_open
) {
773 if (port
->close_delay
) {
774 set_current_state (TASK_INTERRUPTIBLE
);
775 schedule_timeout(port
->close_delay
);
777 wake_up_interruptible(&port
->open_wait
);
779 port
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
| ASYNC_INITIALIZED
);
780 wake_up_interruptible(&port
->close_wait
);
782 restore_flags(flags
);
787 static unsigned int gs_baudrates
[] = {
788 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
789 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
793 void gs_set_termios (struct tty_struct
* tty
,
794 struct termios
* old_termios
)
796 struct gs_port
*port
;
797 int baudrate
, tmp
, rv
;
798 struct termios
*tiosp
;
804 port
= tty
->driver_data
;
808 tiosp
= tty
->termios
;
810 if (gs_debug
& GS_DEBUG_TERMIOS
) {
811 gs_dprintk (GS_DEBUG_TERMIOS
, "termios structure (%p):\n", tiosp
);
815 /* This is an optimization that is only allowed for dumb cards */
816 /* Smart cards require knowledge of iflags and oflags too: that
817 might change hardware cooking mode.... */
820 if( (tiosp
->c_iflag
== old_termios
->c_iflag
)
821 && (tiosp
->c_oflag
== old_termios
->c_oflag
)
822 && (tiosp
->c_cflag
== old_termios
->c_cflag
)
823 && (tiosp
->c_lflag
== old_termios
->c_lflag
)
824 && (tiosp
->c_line
== old_termios
->c_line
)
825 && (memcmp(tiosp
->c_cc
, old_termios
->c_cc
, NCC
) == 0)) {
826 gs_dprintk(GS_DEBUG_TERMIOS
, "gs_set_termios: optimized away\n");
830 gs_dprintk(GS_DEBUG_TERMIOS
, "gs_set_termios: no old_termios: "
831 "no optimization\n");
833 if(old_termios
&& (gs_debug
& GS_DEBUG_TERMIOS
)) {
834 if(tiosp
->c_iflag
!= old_termios
->c_iflag
) printk("c_iflag changed\n");
835 if(tiosp
->c_oflag
!= old_termios
->c_oflag
) printk("c_oflag changed\n");
836 if(tiosp
->c_cflag
!= old_termios
->c_cflag
) printk("c_cflag changed\n");
837 if(tiosp
->c_lflag
!= old_termios
->c_lflag
) printk("c_lflag changed\n");
838 if(tiosp
->c_line
!= old_termios
->c_line
) printk("c_line changed\n");
839 if(!memcmp(tiosp
->c_cc
, old_termios
->c_cc
, NCC
)) printk("c_cc changed\n");
842 baudrate
= tiosp
->c_cflag
& CBAUD
;
843 if (baudrate
& CBAUDEX
) {
844 baudrate
&= ~CBAUDEX
;
845 if ((baudrate
< 1) || (baudrate
> 4))
846 tiosp
->c_cflag
&= ~CBAUDEX
;
851 baudrate
= gs_baudrates
[baudrate
];
852 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
853 if ( (port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
855 else if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
857 else if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
859 else if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
861 else if ((port
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
862 baudrate
= (port
->baud_base
/ port
->custom_divisor
);
865 /* I recommend using THIS instead of the mess in termios (and
866 duplicating the above code). Next we should create a clean
867 interface towards this variable. If your card supports arbitrary
868 baud rates, (e.g. CD1400 or 16550 based cards) then everything
869 will be very easy..... */
870 port
->baud
= baudrate
;
872 /* Two timer ticks seems enough to wakeup something like SLIP driver */
873 /* Baudrate/10 is cps. Divide by HZ to get chars per tick. */
874 tmp
= (baudrate
/ 10 / HZ
) * 2;
876 if (tmp
< 0) tmp
= 0;
877 if (tmp
>= SERIAL_XMIT_SIZE
) tmp
= SERIAL_XMIT_SIZE
-1;
879 port
->wakeup_chars
= tmp
;
881 /* We should really wait for the characters to be all sent before
882 changing the settings. -- CAL */
883 rv
= gs_wait_tx_flushed (port
, MAX_SCHEDULE_TIMEOUT
);
884 if (rv
< 0) return /* rv */;
886 rv
= port
->rd
->set_real_termios(port
);
887 if (rv
< 0) return /* rv */;
890 (old_termios
->c_cflag
& CRTSCTS
)) &&
891 !( tiosp
->c_cflag
& CRTSCTS
)) {
896 #ifdef tytso_patch_94Nov25_1726
897 /* This "makes sense", Why is it commented out? */
899 if (!(old_termios
->c_cflag
& CLOCAL
) &&
900 (tty
->termios
->c_cflag
& CLOCAL
))
901 wake_up_interruptible(&info
->open_wait
);
910 /* Must be called with interrupts enabled */
911 int gs_init_port(struct gs_port
*port
)
918 page
= get_zeroed_page(GFP_KERNEL
);
920 cli (); /* Don't expect this to make a difference. */
924 tmp_buf
= (unsigned char *) page
;
925 restore_flags (flags
);
932 if (port
->flags
& ASYNC_INITIALIZED
)
935 if (!port
->xmit_buf
) {
936 /* We may sleep in get_zeroed_page() */
939 tmp
= get_zeroed_page(GFP_KERNEL
);
946 port
->xmit_buf
= (unsigned char *) tmp
;
947 restore_flags (flags
);
956 clear_bit(TTY_IO_ERROR
, &port
->tty
->flags
);
958 port
->xmit_cnt
= port
->xmit_head
= port
->xmit_tail
= 0;
960 gs_set_termios(port
->tty
, NULL
);
962 port
->flags
|= ASYNC_INITIALIZED
;
963 port
->flags
&= ~GS_TX_INTEN
;
965 restore_flags(flags
);
970 int gs_setserial(struct gs_port
*port
, struct serial_struct
*sp
)
972 struct serial_struct sio
;
974 if (copy_from_user(&sio
, sp
, sizeof(struct serial_struct
)))
977 if (!capable(CAP_SYS_ADMIN
)) {
978 if ((sio
.baud_base
!= port
->baud_base
) ||
979 (sio
.close_delay
!= port
->close_delay
) ||
980 ((sio
.flags
& ~ASYNC_USR_MASK
) !=
981 (port
->flags
& ~ASYNC_USR_MASK
)))
985 port
->flags
= (port
->flags
& ~ASYNC_USR_MASK
) |
986 (sio
.flags
& ASYNC_USR_MASK
);
988 port
->baud_base
= sio
.baud_base
;
989 port
->close_delay
= sio
.close_delay
;
990 port
->closing_wait
= sio
.closing_wait
;
991 port
->custom_divisor
= sio
.custom_divisor
;
993 gs_set_termios (port
->tty
, NULL
);
999 /*****************************************************************************/
1002 * Generate the serial struct info.
1005 int gs_getserial(struct gs_port
*port
, struct serial_struct
*sp
)
1007 struct serial_struct sio
;
1009 memset(&sio
, 0, sizeof(struct serial_struct
));
1010 sio
.flags
= port
->flags
;
1011 sio
.baud_base
= port
->baud_base
;
1012 sio
.close_delay
= port
->close_delay
;
1013 sio
.closing_wait
= port
->closing_wait
;
1014 sio
.custom_divisor
= port
->custom_divisor
;
1017 /* If you want you can override these. */
1018 sio
.type
= PORT_UNKNOWN
;
1019 sio
.xmit_fifo_size
= -1;
1024 if (port
->rd
->getserial
)
1025 port
->rd
->getserial (port
, &sio
);
1027 if (copy_to_user(sp
, &sio
, sizeof(struct serial_struct
)))
1034 void gs_got_break(struct gs_port
*port
)
1036 if (port
->flags
& ASYNC_SAK
) {
1039 *(port
->tty
->flip
.flag_buf_ptr
) = TTY_BREAK
;
1040 port
->tty
->flip
.flag_buf_ptr
++;
1041 port
->tty
->flip
.char_buf_ptr
++;
1042 port
->tty
->flip
.count
++;
1046 EXPORT_SYMBOL(gs_put_char
);
1047 EXPORT_SYMBOL(gs_write
);
1048 EXPORT_SYMBOL(gs_write_room
);
1049 EXPORT_SYMBOL(gs_chars_in_buffer
);
1050 EXPORT_SYMBOL(gs_flush_buffer
);
1051 EXPORT_SYMBOL(gs_flush_chars
);
1052 EXPORT_SYMBOL(gs_stop
);
1053 EXPORT_SYMBOL(gs_start
);
1054 EXPORT_SYMBOL(gs_hangup
);
1055 EXPORT_SYMBOL(gs_do_softint
);
1056 EXPORT_SYMBOL(gs_block_til_ready
);
1057 EXPORT_SYMBOL(gs_close
);
1058 EXPORT_SYMBOL(gs_set_termios
);
1059 EXPORT_SYMBOL(gs_init_port
);
1060 EXPORT_SYMBOL(gs_setserial
);
1061 EXPORT_SYMBOL(gs_getserial
);
1062 EXPORT_SYMBOL(gs_got_break
);
1064 MODULE_LICENSE("GPL");