···62626363static struct tty_driver *bfin_jc_driver;6464static struct task_struct *bfin_jc_kthread;6565-static struct tty_struct * volatile bfin_jc_tty;6666-static unsigned long bfin_jc_count;6767-static DEFINE_MUTEX(bfin_jc_tty_mutex);6565+static struct tty_port port;6866static volatile struct circ_buf bfin_jc_write_buf;69677068static int···7173 uint32_t inbound_len = 0, outbound_len = 0;72747375 while (!kthread_should_stop()) {7676+ struct tty_struct *tty = tty_port_tty_get(&port);7477 /* no one left to give data to, so sleep */7575- if (bfin_jc_tty == NULL && circ_empty(&bfin_jc_write_buf)) {7878+ if (tty == NULL && circ_empty(&bfin_jc_write_buf)) {7679 pr_debug("waiting for readers\n");7780 __set_current_state(TASK_UNINTERRUPTIBLE);7881 schedule();7982 __set_current_state(TASK_RUNNING);8383+ continue;8084 }81858286 /* no data available, so just chill */8387 if (!(bfin_read_DBGSTAT() & EMUDIF) && circ_empty(&bfin_jc_write_buf)) {8488 pr_debug("waiting for data (in_len = %i) (circ: %i %i)\n",8589 inbound_len, bfin_jc_write_buf.tail, bfin_jc_write_buf.head);9090+ tty_kref_put(tty);8691 if (inbound_len)8792 schedule();8893 else···95949695 /* if incoming data is ready, eat it */9796 if (bfin_read_DBGSTAT() & EMUDIF) {9898- struct tty_struct *tty;9999- mutex_lock(&bfin_jc_tty_mutex);100100- tty = (struct tty_struct *)bfin_jc_tty;10197 if (tty != NULL) {10298 uint32_t emudat = bfin_read_emudat();10399 if (inbound_len == 0) {···108110 tty_flip_buffer_push(tty);109111 }110112 }111111- mutex_unlock(&bfin_jc_tty_mutex);112113 }113114114115 /* if outgoing data is ready, post it */···117120 bfin_write_emudat(outbound_len);118121 pr_debug("outgoing length: 0x%08x\n", outbound_len);119122 } else {120120- struct tty_struct *tty;121123 int tail = bfin_jc_write_buf.tail;122124 size_t ate = (4 <= outbound_len ? 4 : outbound_len);123125 uint32_t emudat =···128132 );129133 bfin_jc_write_buf.tail += ate;130134 outbound_len -= ate;131131- mutex_lock(&bfin_jc_tty_mutex);132132- tty = (struct tty_struct *)bfin_jc_tty;133135 if (tty)134136 tty_wakeup(tty);135135- mutex_unlock(&bfin_jc_tty_mutex);136137 pr_debug(" outgoing data: 0x%08x (pushing %zu)\n", emudat, ate);137138 }138139 }140140+ tty_kref_put(tty);139141 }140142141143 __set_current_state(TASK_RUNNING);···143149static int144150bfin_jc_open(struct tty_struct *tty, struct file *filp)145151{146146- mutex_lock(&bfin_jc_tty_mutex);147147- pr_debug("open %lu\n", bfin_jc_count);148148- ++bfin_jc_count;149149- bfin_jc_tty = tty;152152+ unsigned long flags;153153+154154+ spin_lock_irqsave(&port.lock, flags);155155+ port.count++;156156+ spin_unlock_irqrestore(&port.lock, flags);157157+ tty_port_tty_set(&port, tty);150158 wake_up_process(bfin_jc_kthread);151151- mutex_unlock(&bfin_jc_tty_mutex);152159 return 0;153160}154161155162static void156163bfin_jc_close(struct tty_struct *tty, struct file *filp)157164{158158- mutex_lock(&bfin_jc_tty_mutex);159159- pr_debug("close %lu\n", bfin_jc_count);160160- if (--bfin_jc_count == 0)161161- bfin_jc_tty = NULL;165165+ unsigned long flags;166166+ bool last;167167+168168+ spin_lock_irqsave(&port.lock, flags);169169+ last = --port.count == 0;170170+ spin_unlock_irqrestore(&port.lock, flags);171171+ if (last)172172+ tty_port_tty_set(&port, NULL);162173 wake_up_process(bfin_jc_kthread);163163- mutex_unlock(&bfin_jc_tty_mutex);164174}165175166176/* XXX: we dont handle the put_char() case where we must handle count = 1 */···239241static int __init bfin_jc_init(void)240242{241243 int ret;244244+245245+ tty_port_init(&port);242246243247 bfin_jc_kthread = kthread_create(bfin_jc_emudat_manager, NULL, DRV_NAME);244248 if (IS_ERR(bfin_jc_kthread))
+46-50
drivers/tty/hvc/hvc_console.c
···107107 list_for_each_entry(hp, &hvc_structs, next) {108108 spin_lock_irqsave(&hp->lock, flags);109109 if (hp->index == index) {110110- kref_get(&hp->kref);110110+ tty_port_get(&hp->port);111111 spin_unlock_irqrestore(&hp->lock, flags);112112 spin_unlock(&hvc_structs_lock);113113 return hp;···229229console_initcall(hvc_console_init);230230231231/* callback when the kboject ref count reaches zero. */232232-static void destroy_hvc_struct(struct kref *kref)232232+static void hvc_port_destruct(struct tty_port *port)233233{234234- struct hvc_struct *hp = container_of(kref, struct hvc_struct, kref);234234+ struct hvc_struct *hp = container_of(port, struct hvc_struct, port);235235 unsigned long flags;236236237237 spin_lock(&hvc_structs_lock);···264264 /* make sure no no tty has been registered in this index */265265 hp = hvc_get_by_index(index);266266 if (hp) {267267- kref_put(&hp->kref, destroy_hvc_struct);267267+ tty_port_put(&hp->port);268268 return -1;269269 }270270···313313 if (!(hp = hvc_get_by_index(tty->index)))314314 return -ENODEV;315315316316- spin_lock_irqsave(&hp->lock, flags);316316+ spin_lock_irqsave(&hp->port.lock, flags);317317 /* Check and then increment for fast path open. */318318- if (hp->count++ > 0) {319319- tty_kref_get(tty);320320- spin_unlock_irqrestore(&hp->lock, flags);318318+ if (hp->port.count++ > 0) {319319+ spin_unlock_irqrestore(&hp->port.lock, flags);321320 hvc_kick();322321 return 0;323322 } /* else count == 0 */323323+ spin_unlock_irqrestore(&hp->port.lock, flags);324324325325 tty->driver_data = hp;326326-327327- hp->tty = tty_kref_get(tty);328328-329329- spin_unlock_irqrestore(&hp->lock, flags);326326+ tty_port_tty_set(&hp->port, tty);330327331328 if (hp->ops->notifier_add)332329 rc = hp->ops->notifier_add(hp, hp->data);···335338 * tty fields and return the kref reference.336339 */337340 if (rc) {338338- spin_lock_irqsave(&hp->lock, flags);339339- hp->tty = NULL;340340- spin_unlock_irqrestore(&hp->lock, flags);341341- tty_kref_put(tty);341341+ tty_port_tty_set(&hp->port, NULL);342342 tty->driver_data = NULL;343343- kref_put(&hp->kref, destroy_hvc_struct);343343+ tty_port_put(&hp->port);344344 printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc);345345 }346346 /* Force wakeup of the polling thread */···364370365371 hp = tty->driver_data;366372367367- spin_lock_irqsave(&hp->lock, flags);373373+ spin_lock_irqsave(&hp->port.lock, flags);368374369369- if (--hp->count == 0) {375375+ if (--hp->port.count == 0) {376376+ spin_unlock_irqrestore(&hp->port.lock, flags);370377 /* We are done with the tty pointer now. */371371- hp->tty = NULL;372372- spin_unlock_irqrestore(&hp->lock, flags);378378+ tty_port_tty_set(&hp->port, NULL);373379374380 if (hp->ops->notifier_del)375381 hp->ops->notifier_del(hp, hp->data);···384390 */385391 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);386392 } else {387387- if (hp->count < 0)393393+ if (hp->port.count < 0)388394 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",389389- hp->vtermno, hp->count);390390- spin_unlock_irqrestore(&hp->lock, flags);395395+ hp->vtermno, hp->port.count);396396+ spin_unlock_irqrestore(&hp->port.lock, flags);391397 }392398393393- tty_kref_put(tty);394394- kref_put(&hp->kref, destroy_hvc_struct);399399+ tty_port_put(&hp->port);395400}396401397402static void hvc_hangup(struct tty_struct *tty)···405412 /* cancel pending tty resize work */406413 cancel_work_sync(&hp->tty_resize);407414408408- spin_lock_irqsave(&hp->lock, flags);415415+ spin_lock_irqsave(&hp->port.lock, flags);409416410417 /*411418 * The N_TTY line discipline has problems such that in a close vs412419 * open->hangup case this can be called after the final close so prevent413420 * that from happening for now.414421 */415415- if (hp->count <= 0) {416416- spin_unlock_irqrestore(&hp->lock, flags);422422+ if (hp->port.count <= 0) {423423+ spin_unlock_irqrestore(&hp->port.lock, flags);417424 return;418425 }419426420420- temp_open_count = hp->count;421421- hp->count = 0;422422- hp->n_outbuf = 0;423423- hp->tty = NULL;427427+ temp_open_count = hp->port.count;428428+ hp->port.count = 0;429429+ spin_unlock_irqrestore(&hp->port.lock, flags);430430+ tty_port_tty_set(&hp->port, NULL);424431425425- spin_unlock_irqrestore(&hp->lock, flags);432432+ hp->n_outbuf = 0;426433427434 if (hp->ops->notifier_hangup)428435 hp->ops->notifier_hangup(hp, hp->data);429436430437 while(temp_open_count) {431438 --temp_open_count;432432- tty_kref_put(tty);433433- kref_put(&hp->kref, destroy_hvc_struct);439439+ tty_port_put(&hp->port);434440 }435441}436442···470478 if (!hp)471479 return -EPIPE;472480473473- if (hp->count <= 0)481481+ /* FIXME what's this (unprotected) check for? */482482+ if (hp->port.count <= 0)474483 return -EIO;475484476485 spin_lock_irqsave(&hp->lock, flags);···519526520527 hp = container_of(work, struct hvc_struct, tty_resize);521528522522- spin_lock_irqsave(&hp->lock, hvc_flags);523523- if (!hp->tty) {524524- spin_unlock_irqrestore(&hp->lock, hvc_flags);529529+ tty = tty_port_tty_get(&hp->port);530530+ if (!tty)525531 return;526526- }527527- ws = hp->ws;528528- tty = tty_kref_get(hp->tty);532532+533533+ spin_lock_irqsave(&hp->lock, hvc_flags);534534+ ws = hp->ws;529535 spin_unlock_irqrestore(&hp->lock, hvc_flags);530536531537 tty_do_resize(tty, &ws);···593601 }594602595603 /* No tty attached, just skip */596596- tty = tty_kref_get(hp->tty);604604+ tty = tty_port_tty_get(&hp->port);597605 if (tty == NULL)598606 goto bail;599607···673681674682 tty_flip_buffer_push(tty);675683 }676676- if (tty)677677- tty_kref_put(tty);684684+ tty_kref_put(tty);678685679686 return poll_mask;680687}···808817#endif809818};810819820820+static const struct tty_port_operations hvc_port_ops = {821821+ .destruct = hvc_port_destruct,822822+};823823+811824struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,812825 const struct hv_ops *ops,813826 int outbuf_size)···837842 hp->outbuf_size = outbuf_size;838843 hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))];839844840840- kref_init(&hp->kref);845845+ tty_port_init(&hp->port);846846+ hp->port.ops = &hvc_port_ops;841847842848 INIT_WORK(&hp->tty_resize, hvc_set_winsz);843849 spin_lock_init(&hp->lock);···871875 unsigned long flags;872876 struct tty_struct *tty;873877874874- spin_lock_irqsave(&hp->lock, flags);875875- tty = tty_kref_get(hp->tty);878878+ tty = tty_port_tty_get(&hp->port);876879880880+ spin_lock_irqsave(&hp->lock, flags);877881 if (hp->index < MAX_NR_HVC_CONSOLES)878882 vtermnos[hp->index] = -1;879883···887891 * kref cause it to be removed, which will probably be the tty_vhangup888892 * below.889893 */890890- kref_put(&hp->kref, destroy_hvc_struct);894894+ tty_port_put(&hp->port);891895892896 /*893897 * This function call will auto chain call hvc_hangup.
+1-3
drivers/tty/hvc/hvc_console.h
···4646#define HVC_ALLOC_TTY_ADAPTERS 847474848struct hvc_struct {4949+ struct tty_port port;4950 spinlock_t lock;5051 int index;5151- struct tty_struct *tty;5252- int count;5352 int do_wakeup;5453 char *outbuf;5554 int outbuf_size;···6061 struct winsize ws;6162 struct work_struct tty_resize;6263 struct list_head next;6363- struct kref kref; /* ref count & hvc_struct lifetime */6464};65656666/* implemented by a low level driver */
+35-39
drivers/tty/hvc/hvcs.c
···261261262262/* One vty-server per hvcs_struct */263263struct hvcs_struct {264264+ struct tty_port port;264265 spinlock_t lock;265266266267 /*···269268 * specific tty index.270269 */271270 unsigned int index;272272-273273- struct tty_struct *tty;274274- int open_count;275271276272 /*277273 * Used to tell the driver kernel_thread what operations need to take···288290 int chars_in_buffer;289291290292 /*291291- * Any variable below the kref is valid before a tty is connected and293293+ * Any variable below is valid before a tty is connected and292294 * stays valid after the tty is disconnected. These shouldn't be293295 * whacked until the kobject refcount reaches zero though some entries294296 * may be changed via sysfs initiatives.295297 */296296- struct kref kref; /* ref count & hvcs_struct lifetime */297298 int connected; /* is the vty-server currently connected to a vty? */298299 uint32_t p_unit_address; /* partner unit address */299300 uint32_t p_partition_ID; /* partner partition ID */···300303 struct list_head next; /* list management */301304 struct vio_dev *vdev;302305};303303-304304-/* Required to back map a kref to its containing object */305305-#define from_kref(k) container_of(k, struct hvcs_struct, kref)306306307307static LIST_HEAD(hvcs_structs);308308static DEFINE_SPINLOCK(hvcs_structs_lock);···416422417423 spin_lock_irqsave(&hvcsd->lock, flags);418424419419- if (hvcsd->open_count > 0) {425425+ if (hvcsd->port.count > 0) {420426 spin_unlock_irqrestore(&hvcsd->lock, flags);421427 printk(KERN_INFO "HVCS: vterm state unchanged. "422428 "The hvcs device node is still in use.\n");···558564static void hvcs_try_write(struct hvcs_struct *hvcsd)559565{560566 uint32_t unit_address = hvcsd->vdev->unit_address;561561- struct tty_struct *tty = hvcsd->tty;567567+ struct tty_struct *tty = hvcsd->port.tty;562568 int sent;563569564570 if (hvcsd->todo_mask & HVCS_TRY_WRITE) {···596602 spin_lock_irqsave(&hvcsd->lock, flags);597603598604 unit_address = hvcsd->vdev->unit_address;599599- tty = hvcsd->tty;605605+ tty = hvcsd->port.tty;600606601607 hvcs_try_write(hvcsd);602608···695701 hvcs_index_list[index] = -1;696702}697703698698-/* callback when the kref ref count reaches zero */699699-static void destroy_hvcs_struct(struct kref *kref)704704+static void hvcs_destruct_port(struct tty_port *p)700705{701701- struct hvcs_struct *hvcsd = from_kref(kref);706706+ struct hvcs_struct *hvcsd = container_of(p, struct hvcs_struct, port);702707 struct vio_dev *vdev;703708 unsigned long flags;704709···733740734741 kfree(hvcsd);735742}743743+744744+static const struct tty_port_operations hvcs_port_ops = {745745+ .destruct = hvcs_destruct_port,746746+};736747737748static int hvcs_get_index(void)738749{···786789 if (!hvcsd)787790 return -ENODEV;788791789789-792792+ tty_port_init(&hvcsd->port);793793+ hvcsd->port.ops = &hvcs_port_ops;790794 spin_lock_init(&hvcsd->lock);791791- /* Automatically incs the refcount the first time */792792- kref_init(&hvcsd->kref);793795794796 hvcsd->vdev = dev;795797 dev_set_drvdata(&dev->dev, hvcsd);···848852849853 spin_lock_irqsave(&hvcsd->lock, flags);850854851851- tty = hvcsd->tty;855855+ tty = hvcsd->port.tty;852856853857 spin_unlock_irqrestore(&hvcsd->lock, flags);854858···856860 * Let the last holder of this object cause it to be removed, which857861 * would probably be tty_hangup below.858862 */859859- kref_put(&hvcsd->kref, destroy_hvcs_struct);863863+ tty_port_put(&hvcsd->port);860864861865 /*862866 * The hangup is a scheduled function which will auto chain call···10901094 list_for_each_entry(hvcsd, &hvcs_structs, next) {10911095 spin_lock_irqsave(&hvcsd->lock, flags);10921096 if (hvcsd->index == index) {10931093- kref_get(&hvcsd->kref);10971097+ tty_port_get(&hvcsd->port);10941098 spin_unlock_irqrestore(&hvcsd->lock, flags);10951099 spin_unlock(&hvcs_structs_lock);10961100 return hvcsd;···11341138 if ((retval = hvcs_partner_connect(hvcsd)))11351139 goto error_release;1136114011371137- hvcsd->open_count = 1;11381138- hvcsd->tty = tty;11411141+ hvcsd->port.count = 1;11421142+ hvcsd->port.tty = tty;11391143 tty->driver_data = hvcsd;1140114411411145 memset(&hvcsd->buffer[0], 0x00, HVCS_BUFF_LEN);···11561160 * and will grab the spinlock and free the connection if it fails.11571161 */11581162 if (((rc = hvcs_enable_device(hvcsd, unit_address, irq, vdev)))) {11591159- kref_put(&hvcsd->kref, destroy_hvcs_struct);11631163+ tty_port_put(&hvcsd->port);11601164 printk(KERN_WARNING "HVCS: enable device failed.\n");11611165 return rc;11621166 }···11671171 hvcsd = tty->driver_data;1168117211691173 spin_lock_irqsave(&hvcsd->lock, flags);11701170- kref_get(&hvcsd->kref);11711171- hvcsd->open_count++;11741174+ tty_port_get(&hvcsd->port);11751175+ hvcsd->port.count++;11721176 hvcsd->todo_mask |= HVCS_SCHED_READ;11731177 spin_unlock_irqrestore(&hvcsd->lock, flags);11741178···1182118611831187error_release:11841188 spin_unlock_irqrestore(&hvcsd->lock, flags);11851185- kref_put(&hvcsd->kref, destroy_hvcs_struct);11891189+ tty_port_put(&hvcsd->port);1186119011871191 printk(KERN_WARNING "HVCS: partner connect failed.\n");11881192 return retval;···12121216 hvcsd = tty->driver_data;1213121712141218 spin_lock_irqsave(&hvcsd->lock, flags);12151215- if (--hvcsd->open_count == 0) {12191219+ if (--hvcsd->port.count == 0) {1216122012171221 vio_disable_interrupts(hvcsd->vdev);12181222···12211225 * execute any operations on the TTY even though it is obligated12221226 * to deliver any pending I/O to the hypervisor.12231227 */12241224- hvcsd->tty = NULL;12281228+ hvcsd->port.tty = NULL;1225122912261230 irq = hvcsd->vdev->irq;12271231 spin_unlock_irqrestore(&hvcsd->lock, flags);···12361240 tty->driver_data = NULL;1237124112381242 free_irq(irq, hvcsd);12391239- kref_put(&hvcsd->kref, destroy_hvcs_struct);12431243+ tty_port_put(&hvcsd->port);12401244 return;12411241- } else if (hvcsd->open_count < 0) {12451245+ } else if (hvcsd->port.count < 0) {12421246 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"12431247 " is missmanaged.\n",12441244- hvcsd->vdev->unit_address, hvcsd->open_count);12481248+ hvcsd->vdev->unit_address, hvcsd->port.count);12451249 }1246125012471251 spin_unlock_irqrestore(&hvcsd->lock, flags);12481248- kref_put(&hvcsd->kref, destroy_hvcs_struct);12521252+ tty_port_put(&hvcsd->port);12491253}1250125412511255static void hvcs_hangup(struct tty_struct * tty)···1257126112581262 spin_lock_irqsave(&hvcsd->lock, flags);12591263 /* Preserve this so that we know how many kref refs to put */12601260- temp_open_count = hvcsd->open_count;12641264+ temp_open_count = hvcsd->port.count;1261126512621266 /*12631267 * Don't kref put inside the spinlock because the destruction···12691273 hvcsd->todo_mask = 0;1270127412711275 /* I don't think the tty needs the hvcs_struct pointer after a hangup */12721272- hvcsd->tty->driver_data = NULL;12731273- hvcsd->tty = NULL;12761276+ tty->driver_data = NULL;12771277+ hvcsd->port.tty = NULL;1274127812751275- hvcsd->open_count = 0;12791279+ hvcsd->port.count = 0;1276128012771281 /* This will drop any buffered data on the floor which is OK in a hangup12781282 * scenario. */···12971301 * NOTE: If this hangup was signaled from user space then the12981302 * final put will never happen.12991303 */13001300- kref_put(&hvcsd->kref, destroy_hvcs_struct);13041304+ tty_port_put(&hvcsd->port);13011305 }13021306}13031307···13431347 * the middle of a write operation? This is a crummy place to do this13441348 * but we want to keep it all in the spinlock.13451349 */13461346- if (hvcsd->open_count <= 0) {13501350+ if (hvcsd->port.count <= 0) {13471351 spin_unlock_irqrestore(&hvcsd->lock, flags);13481352 return -ENODEV;13491353 }···14171421{14181422 struct hvcs_struct *hvcsd = tty->driver_data;1419142314201420- if (!hvcsd || hvcsd->open_count <= 0)14241424+ if (!hvcsd || hvcsd->port.count <= 0)14211425 return 0;1422142614231427 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
+54-74
drivers/tty/hvc/hvsi.c
···6969#define __ALIGNED__ __attribute__((__aligned__(sizeof(long))))70707171struct hvsi_struct {7272+ struct tty_port port;7273 struct delayed_work writer;7374 struct work_struct handshaker;7475 wait_queue_head_t emptyq; /* woken when outbuf is emptied */7576 wait_queue_head_t stateq; /* woken when HVSI state changes */7677 spinlock_t lock;7778 int index;7878- struct tty_struct *tty;7979- int count;8079 uint8_t throttle_buf[128];8180 uint8_t outbuf[N_OUTBUF]; /* to implement write_room and chars_in_buffer */8281 /* inbuf is for packet reassembly. leave a little room for leftovers. */···236237}237238238239static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet,239239- struct tty_struct **to_hangup, struct hvsi_struct **to_handshake)240240+ struct tty_struct *tty, struct hvsi_struct **to_handshake)240241{241242 struct hvsi_control *header = (struct hvsi_control *)packet;242243···246247 /* CD went away; no more connection */247248 pr_debug("hvsi%i: CD dropped\n", hp->index);248249 hp->mctrl &= TIOCM_CD;249249- /* If userland hasn't done an open(2) yet, hp->tty is NULL. */250250- if (hp->tty && !(hp->tty->flags & CLOCAL))251251- *to_hangup = hp->tty;250250+ if (tty && !C_CLOCAL(tty))251251+ tty_hangup(tty);252252 }253253 break;254254 case VSV_CLOSE_PROTOCOL:···329331 }330332}331333332332-static void hvsi_insert_chars(struct hvsi_struct *hp, const char *buf, int len)334334+static void hvsi_insert_chars(struct hvsi_struct *hp, struct tty_struct *tty,335335+ const char *buf, int len)333336{334337 int i;335338···346347 continue;347348 }348349#endif /* CONFIG_MAGIC_SYSRQ */349349- tty_insert_flip_char(hp->tty, c, 0);350350+ tty_insert_flip_char(tty, c, 0);350351 }351352}352353···359360 * revisited.360361 */361362#define TTY_THRESHOLD_THROTTLE 128362362-static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp,363363+static bool hvsi_recv_data(struct hvsi_struct *hp, struct tty_struct *tty,363364 const uint8_t *packet)364365{365366 const struct hvsi_header *header = (const struct hvsi_header *)packet;···370371 pr_debug("queueing %i chars '%.*s'\n", datalen, datalen, data);371372372373 if (datalen == 0)373373- return NULL;374374+ return false;374375375376 if (overflow > 0) {376377 pr_debug("%s: got >TTY_THRESHOLD_THROTTLE bytes\n", __func__);377378 datalen = TTY_THRESHOLD_THROTTLE;378379 }379380380380- hvsi_insert_chars(hp, data, datalen);381381+ hvsi_insert_chars(hp, tty, data, datalen);381382382383 if (overflow > 0) {383384 /*···389390 hp->n_throttle = overflow;390391 }391392392392- return hp->tty;393393+ return true;393394}394395395396/*···398399 * machine during console handshaking (in which case tty = NULL and we ignore399400 * incoming data).400401 */401401-static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip,402402- struct tty_struct **hangup, struct hvsi_struct **handshake)402402+static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct *tty,403403+ struct hvsi_struct **handshake)403404{404405 uint8_t *packet = hp->inbuf;405406 int chunklen;407407+ bool flip = false;406408407407- *flip = NULL;408408- *hangup = NULL;409409 *handshake = NULL;410410411411 chunklen = hvsi_read(hp, hp->inbuf_end, HVSI_MAX_READ);···438440 case VS_DATA_PACKET_HEADER:439441 if (!is_open(hp))440442 break;441441- if (hp->tty == NULL)443443+ if (tty == NULL)442444 break; /* no tty buffer to put data in */443443- *flip = hvsi_recv_data(hp, packet);445445+ flip = hvsi_recv_data(hp, tty, packet);444446 break;445447 case VS_CONTROL_PACKET_HEADER:446446- hvsi_recv_control(hp, packet, hangup, handshake);448448+ hvsi_recv_control(hp, packet, tty, handshake);447449 break;448450 case VS_QUERY_RESPONSE_PACKET_HEADER:449451 hvsi_recv_response(hp, packet);···460462461463 packet += len_packet(packet);462464463463- if (*hangup || *handshake) {464464- pr_debug("%s: hangup or handshake\n", __func__);465465- /*466466- * we need to send the hangup now before receiving any more data.467467- * If we get "data, hangup, data", we can't deliver the second468468- * data before the hangup.469469- */465465+ if (*handshake) {466466+ pr_debug("%s: handshake\n", __func__);470467 break;471468 }472469 }473470474471 compact_inbuf(hp, packet);475472473473+ if (flip)474474+ tty_flip_buffer_push(tty);475475+476476 return 1;477477}478478479479-static void hvsi_send_overflow(struct hvsi_struct *hp)479479+static void hvsi_send_overflow(struct hvsi_struct *hp, struct tty_struct *tty)480480{481481 pr_debug("%s: delivering %i bytes overflow\n", __func__,482482 hp->n_throttle);483483484484- hvsi_insert_chars(hp, hp->throttle_buf, hp->n_throttle);484484+ hvsi_insert_chars(hp, tty, hp->throttle_buf, hp->n_throttle);485485 hp->n_throttle = 0;486486}487487···490494static irqreturn_t hvsi_interrupt(int irq, void *arg)491495{492496 struct hvsi_struct *hp = (struct hvsi_struct *)arg;493493- struct tty_struct *flip;494494- struct tty_struct *hangup;495497 struct hvsi_struct *handshake;498498+ struct tty_struct *tty;496499 unsigned long flags;497500 int again = 1;498501499502 pr_debug("%s\n", __func__);500503504504+ tty = tty_port_tty_get(&hp->port);505505+501506 while (again) {502507 spin_lock_irqsave(&hp->lock, flags);503503- again = hvsi_load_chunk(hp, &flip, &hangup, &handshake);508508+ again = hvsi_load_chunk(hp, tty, &handshake);504509 spin_unlock_irqrestore(&hp->lock, flags);505505-506506- /*507507- * we have to call tty_flip_buffer_push() and tty_hangup() outside our508508- * spinlock. But we also have to keep going until we've read all the509509- * available data.510510- */511511-512512- if (flip) {513513- /* there was data put in the tty flip buffer */514514- tty_flip_buffer_push(flip);515515- flip = NULL;516516- }517517-518518- if (hangup) {519519- tty_hangup(hangup);520520- }521510522511 if (handshake) {523512 pr_debug("hvsi%i: attempting re-handshake\n", handshake->index);···511530 }512531513532 spin_lock_irqsave(&hp->lock, flags);514514- if (hp->tty && hp->n_throttle515515- && (!test_bit(TTY_THROTTLED, &hp->tty->flags))) {516516- /* we weren't hung up and we weren't throttled, so we can deliver the517517- * rest now */518518- flip = hp->tty;519519- hvsi_send_overflow(hp);533533+ if (tty && hp->n_throttle && !test_bit(TTY_THROTTLED, &tty->flags)) {534534+ /* we weren't hung up and we weren't throttled, so we can535535+ * deliver the rest now */536536+ hvsi_send_overflow(hp, tty);537537+ tty_flip_buffer_push(tty);520538 }521539 spin_unlock_irqrestore(&hp->lock, flags);522540523523- if (flip) {524524- tty_flip_buffer_push(flip);525525- }541541+ tty_kref_put(tty);526542527543 return IRQ_HANDLED;528544}···727749 if (hp->state == HVSI_FSP_DIED)728750 return -EIO;729751752752+ tty_port_tty_set(&hp->port, tty);730753 spin_lock_irqsave(&hp->lock, flags);731731- hp->tty = tty;732732- hp->count++;754754+ hp->port.count++;733755 atomic_set(&hp->seqno, 0);734756 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);735757 spin_unlock_irqrestore(&hp->lock, flags);···786808787809 spin_lock_irqsave(&hp->lock, flags);788810789789- if (--hp->count == 0) {790790- hp->tty = NULL;811811+ if (--hp->port.count == 0) {812812+ tty_port_tty_set(&hp->port, NULL);791813 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */792814793815 /* only close down connection if it is not the console */···819841820842 spin_lock_irqsave(&hp->lock, flags);821843 }822822- } else if (hp->count < 0)844844+ } else if (hp->port.count < 0)823845 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",824824- hp - hvsi_ports, hp->count);846846+ hp - hvsi_ports, hp->port.count);825847826848 spin_unlock_irqrestore(&hp->lock, flags);827849}···833855834856 pr_debug("%s\n", __func__);835857858858+ tty_port_tty_set(&hp->port, NULL);859859+836860 spin_lock_irqsave(&hp->lock, flags);837837-838838- hp->count = 0;861861+ hp->port.count = 0;839862 hp->n_outbuf = 0;840840- hp->tty = NULL;841841-842863 spin_unlock_irqrestore(&hp->lock, flags);843864}844865···865888{866889 struct hvsi_struct *hp =867890 container_of(work, struct hvsi_struct, writer.work);891891+ struct tty_struct *tty;868892 unsigned long flags;869893#ifdef DEBUG870894 static long start_j = 0;···899921 start_j = 0;900922#endif /* DEBUG */901923 wake_up_all(&hp->emptyq);902902- tty_wakeup(hp->tty);924924+ tty = tty_port_tty_get(&hp->port);925925+ if (tty) {926926+ tty_wakeup(tty);927927+ tty_kref_put(tty);928928+ }903929 }904930905931out:···948966 * and hvsi_write_worker will be scheduled. subsequent hvsi_write() calls949967 * will see there is no room in outbuf and return.950968 */951951- while ((count > 0) && (hvsi_write_room(hp->tty) > 0)) {952952- int chunksize = min(count, hvsi_write_room(hp->tty));969969+ while ((count > 0) && (hvsi_write_room(tty) > 0)) {970970+ int chunksize = min(count, hvsi_write_room(tty));953971954972 BUG_ON(hp->n_outbuf < 0);955973 memcpy(hp->outbuf + hp->n_outbuf, source, chunksize);···9961014{9971015 struct hvsi_struct *hp = tty->driver_data;9981016 unsigned long flags;999999- int shouldflip = 0;1000101710011018 pr_debug("%s\n", __func__);1002101910031020 spin_lock_irqsave(&hp->lock, flags);10041021 if (hp->n_throttle) {10051005- hvsi_send_overflow(hp);10061006- shouldflip = 1;10221022+ hvsi_send_overflow(hp, tty);10231023+ tty_flip_buffer_push(tty);10071024 }10081025 spin_unlock_irqrestore(&hp->lock, flags);1009102610101010- if (shouldflip)10111011- tty_flip_buffer_push(hp->tty);1012102710131028 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);10141029}···12071228 init_waitqueue_head(&hp->emptyq);12081229 init_waitqueue_head(&hp->stateq);12091230 spin_lock_init(&hp->lock);12311231+ tty_port_init(&hp->port);12101232 hp->index = hvsi_count;12111233 hp->inbuf_end = hp->inbuf;12121234 hp->state = HVSI_CLOSED;
+1-1
drivers/tty/hvc/hvsi_lib.c
···377377 pr_devel("HVSI@%x: open !\n", pv->termno);378378379379 /* Keep track of the tty data structure */380380- pv->tty = tty_kref_get(hp->tty);380380+ pv->tty = tty_port_tty_get(&hp->port);381381382382 hvsilib_establish(pv);383383
+35-46
drivers/tty/ipwireless/tty.c
···4444#define TTYTYPE_RAS_RAW (2)45454646struct ipw_tty {4747+ struct tty_port port;4748 int index;4849 struct ipw_hardware *hardware;4950 unsigned int channel_idx;5051 unsigned int secondary_channel_idx;5152 int tty_type;5253 struct ipw_network *network;5353- struct tty_struct *linux_tty;5454- int open_count;5554 unsigned int control_lines;5655 struct mutex ipw_tty_mutex;5756 int tx_bytes_queued;···7071 };71727273 return channel_names[tty_type];7373-}7474-7575-static void report_registering(struct ipw_tty *tty)7676-{7777- char *iftype = tty_type_name(tty->tty_type);7878-7979- printk(KERN_INFO IPWIRELESS_PCCARD_NAME8080- ": registering %s device ttyIPWp%d\n", iftype, tty->index);8181-}8282-8383-static void report_deregistering(struct ipw_tty *tty)8484-{8585- char *iftype = tty_type_name(tty->tty_type);8686-8787- printk(KERN_INFO IPWIRELESS_PCCARD_NAME8888- ": deregistering %s device ttyIPWp%d\n", iftype,8989- tty->index);9074}91759276static struct ipw_tty *get_tty(int index)···99117 mutex_unlock(&tty->ipw_tty_mutex);100118 return -ENODEV;101119 }102102- if (tty->open_count == 0)120120+ if (tty->port.count == 0)103121 tty->tx_bytes_queued = 0;104122105105- tty->open_count++;123123+ tty->port.count++;106124107107- tty->linux_tty = linux_tty;125125+ tty->port.tty = linux_tty;108126 linux_tty->driver_data = tty;109127 linux_tty->low_latency = 1;110128···118136119137static void do_ipw_close(struct ipw_tty *tty)120138{121121- tty->open_count--;139139+ tty->port.count--;122140123123- if (tty->open_count == 0) {124124- struct tty_struct *linux_tty = tty->linux_tty;141141+ if (tty->port.count == 0) {142142+ struct tty_struct *linux_tty = tty->port.tty;125143126144 if (linux_tty != NULL) {127127- tty->linux_tty = NULL;145145+ tty->port.tty = NULL;128146 linux_tty->driver_data = NULL;129147130148 if (tty->tty_type == TTYTYPE_MODEM)···141159 return;142160143161 mutex_lock(&tty->ipw_tty_mutex);144144- if (tty->open_count == 0) {162162+ if (tty->port.count == 0) {145163 mutex_unlock(&tty->ipw_tty_mutex);146164 return;147165 }···164182 int work = 0;165183166184 mutex_lock(&tty->ipw_tty_mutex);167167- linux_tty = tty->linux_tty;185185+ linux_tty = tty->port.tty;168186 if (linux_tty == NULL) {169187 mutex_unlock(&tty->ipw_tty_mutex);170188 return;171189 }172190173173- if (!tty->open_count) {191191+ if (!tty->port.count) {174192 mutex_unlock(&tty->ipw_tty_mutex);175193 return;176194 }···212230 return -ENODEV;213231214232 mutex_lock(&tty->ipw_tty_mutex);215215- if (!tty->open_count) {233233+ if (!tty->port.count) {216234 mutex_unlock(&tty->ipw_tty_mutex);217235 return -EINVAL;218236 }···252270 if (!tty)253271 return -ENODEV;254272255255- if (!tty->open_count)273273+ if (!tty->port.count)256274 return -EINVAL;257275258276 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;···294312 if (!tty)295313 return 0;296314297297- if (!tty->open_count)315315+ if (!tty->port.count)298316 return 0;299317300318 return tty->tx_bytes_queued;···375393 if (!tty)376394 return -ENODEV;377395378378- if (!tty->open_count)396396+ if (!tty->port.count)379397 return -EINVAL;380398381399 return get_control_lines(tty);···391409 if (!tty)392410 return -ENODEV;393411394394- if (!tty->open_count)412412+ if (!tty->port.count)395413 return -EINVAL;396414397415 return set_control_lines(tty, set, clear);···405423 if (!tty)406424 return -ENODEV;407425408408- if (!tty->open_count)426426+ if (!tty->port.count)409427 return -EINVAL;410428411429 /* FIXME: Exactly how is the tty object locked here .. */···474492 ttys[j]->network = network;475493 ttys[j]->tty_type = tty_type;476494 mutex_init(&ttys[j]->ipw_tty_mutex);495495+ tty_port_init(&ttys[j]->port);477496478497 tty_register_device(ipw_tty_driver, j, NULL);479498 ipwireless_associate_network_tty(network, channel_idx, ttys[j]);···483500 ipwireless_associate_network_tty(network,484501 secondary_channel_idx,485502 ttys[j]);486486- if (get_tty(j) == ttys[j])487487- report_registering(ttys[j]);503503+ /* check if we provide raw device (if loopback is enabled) */504504+ if (get_tty(j))505505+ printk(KERN_INFO IPWIRELESS_PCCARD_NAME506506+ ": registering %s device ttyIPWp%d\n",507507+ tty_type_name(tty_type), j);508508+488509 return 0;489510}490511···547560548561 if (ttyj) {549562 mutex_lock(&ttyj->ipw_tty_mutex);550550- if (get_tty(j) == ttyj)551551- report_deregistering(ttyj);563563+ if (get_tty(j))564564+ printk(KERN_INFO IPWIRELESS_PCCARD_NAME565565+ ": deregistering %s device ttyIPWp%d\n",566566+ tty_type_name(ttyj->tty_type), j);552567 ttyj->closing = 1;553553- if (ttyj->linux_tty != NULL) {568568+ if (ttyj->port.tty != NULL) {554569 mutex_unlock(&ttyj->ipw_tty_mutex);555555- tty_hangup(ttyj->linux_tty);556556- /* Wait till the tty_hangup has completed */557557- flush_work_sync(&ttyj->linux_tty->hangup_work);570570+ tty_vhangup(ttyj->port.tty);558571 /* FIXME: Exactly how is the tty object locked here559572 against a parallel ioctl etc */573573+ /* FIXME2: hangup does not mean all processes574574+ * are gone */560575 mutex_lock(&ttyj->ipw_tty_mutex);561576 }562562- while (ttyj->open_count)577577+ while (ttyj->port.count)563578 do_ipw_close(ttyj);564579 ipwireless_disassociate_network_ttys(network,565580 ttyj->channel_idx);···650661 */651662 if ((old_control_lines & IPW_CONTROL_LINE_DCD)652663 && !(tty->control_lines & IPW_CONTROL_LINE_DCD)653653- && tty->linux_tty) {654654- tty_hangup(tty->linux_tty);664664+ && tty->port.tty) {665665+ tty_hangup(tty->port.tty);655666 }656667}657668
+153-232
drivers/tty/serial/68328serial.c
···1717#include <asm/dbg.h>1818#include <linux/module.h>1919#include <linux/errno.h>2020+#include <linux/serial.h>2021#include <linux/signal.h>2122#include <linux/sched.h>2223#include <linux/timer.h>···5756#endif /* CONFIG_M68VZ328 */5857#endif /* CONFIG_M68EZ328 */59586060-#include "68328serial.h"6161-6259/* Turn off usage of real serial interrupt code, to "support" Copilot */6360#ifdef CONFIG_XCOPILOT_BUGS6461#undef USE_INTS···6465#define USE_INTS6566#endif66676868+/*6969+ * I believe this is the optimal setting that reduces the number of interrupts.7070+ * At high speeds the output might become a little "bursted" (use USTCNT_TXHE7171+ * if that bothers you), but in most cases it will not, since we try to7272+ * transmit characters every time rs_interrupt is called. Thus, quite often7373+ * you'll see that a receive interrupt occures before the transmit one.7474+ * -- Vladimir Gurevich7575+ */7676+#define USTCNT_TX_INTR_MASK (USTCNT_TXEE)7777+7878+/*7979+ * 68328 and 68EZ328 UARTS are a little bit different. EZ328 has special8080+ * "Old data interrupt" which occures whenever the data stay in the FIFO8181+ * longer than 30 bits time. This allows us to use FIFO without compromising8282+ * latency. '328 does not have this feature and without the real 328-based8383+ * board I would assume that RXRE is the safest setting.8484+ *8585+ * For EZ328 I use RXHE (Half empty) interrupt to reduce the number of8686+ * interrupts. RXFE (receive queue full) causes the system to lose data8787+ * at least at 115200 baud8888+ *8989+ * If your board is busy doing other stuff, you might consider to use9090+ * RXRE (data ready intrrupt) instead.9191+ *9292+ * The other option is to make these INTR masks run-time configurable, so9393+ * that people can dynamically adapt them according to the current usage.9494+ * -- Vladimir Gurevich9595+ */9696+9797+/* (es) */9898+#if defined(CONFIG_M68EZ328) || defined(CONFIG_M68VZ328)9999+#define USTCNT_RX_INTR_MASK (USTCNT_RXHE | USTCNT_ODEN)100100+#elif defined(CONFIG_M68328)101101+#define USTCNT_RX_INTR_MASK (USTCNT_RXRE)102102+#else103103+#error Please, define the Rx interrupt events for your CPU104104+#endif105105+/* (/es) */106106+107107+/*108108+ * This is our internal structure for each serial port's state.109109+ */110110+struct m68k_serial {111111+ struct tty_port tport;112112+ char is_cons; /* Is this our console. */113113+ int magic;114114+ int baud_base;115115+ int port;116116+ int irq;117117+ int type; /* UART type */118118+ int custom_divisor;119119+ int x_char; /* xon/xoff character */120120+ int line;121121+ unsigned char *xmit_buf;122122+ int xmit_head;123123+ int xmit_tail;124124+ int xmit_cnt;125125+};126126+127127+#define SERIAL_MAGIC 0x5301128128+129129+/*130130+ * Define the number of ports supported and their irqs.131131+ */132132+#define NR_PORTS 1133133+67134static struct m68k_serial m68k_soft[NR_PORTS];681356969-static unsigned int uart_irqs[NR_PORTS] = UART_IRQ_DEFNS;136136+static unsigned int uart_irqs[NR_PORTS] = { UART_IRQ_NUM };7013771138/* multiple ports are contiguous in memory */72139m68328_uart *uart_addr = (m68328_uart *)USTCNT_ADDR;731407474-struct tty_struct m68k_ttys;7575-struct m68k_serial *m68k_consinfo = 0;7676-7777-#define M68K_CLOCK (16667000) /* FIXME: 16MHz is likely wrong */7878-79141struct tty_driver *serial_driver;801428181-/* number of characters left in xmit buffer before we ask for more */8282-#define WAKEUP_CHARS 2568383-8484-/* Debugging... DEBUG_INTR is bad to use when one of the zs8585- * lines is your console ;(8686- */8787-#undef SERIAL_DEBUG_INTR8888-#undef SERIAL_DEBUG_OPEN8989-#undef SERIAL_DEBUG_FLOW9090-9191-#define RS_ISR_PASS_LIMIT 2569292-9393-static void change_speed(struct m68k_serial *info);143143+static void change_speed(struct m68k_serial *info, struct tty_struct *tty);9414495145/*96146 * Setup for console. Argument comes from the boot command line.···191143 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,192144 9600, 19200, 38400, 57600, 115200, 0 };193145194194-/* Sets or clears DTR/RTS on the requested line */195195-static inline void m68k_rtsdtr(struct m68k_serial *ss, int set)196196-{197197- if (set) {198198- /* set the RTS/CTS line */199199- } else {200200- /* clear it */201201- }202202- return;203203-}204204-205146/* Utility routines */206147static inline int get_baud(struct m68k_serial *ss)207148{···226189227190static int rs_put_char(char ch)228191{229229- int flags, loops = 0;192192+ unsigned long flags;193193+ int loops = 0;230194231195 local_irq_save(flags);232196···262224 local_irq_restore(flags);263225}264226265265-/* Drop into either the boot monitor or kadb upon receiving a break266266- * from keyboard/console input.267267- */268268-static void batten_down_hatches(void)227227+static void receive_chars(struct m68k_serial *info, struct tty_struct *tty,228228+ unsigned short rx)269229{270270- /* Drop into the debugger */271271-}272272-273273-static void status_handle(struct m68k_serial *info, unsigned short status)274274-{275275- /* If this is console input and this is a276276- * 'break asserted' status change interrupt277277- * see if we can drop into the debugger278278- */279279- if((status & URX_BREAK) && info->break_abort)280280- batten_down_hatches();281281- return;282282-}283283-284284-static void receive_chars(struct m68k_serial *info, unsigned short rx)285285-{286286- struct tty_struct *tty = info->tty;287230 m68328_uart *uart = &uart_addr[info->line];288231 unsigned char ch, flag;289232···278259279260 if(info->is_cons) {280261 if(URX_BREAK & rx) { /* whee, break received */281281- status_handle(info, rx);282262 return;283263#ifdef CONFIG_MAGIC_SYSRQ284264 } else if (ch == 0x10) { /* ^P */···298280299281 flag = TTY_NORMAL;300282301301- if(rx & URX_PARITY_ERROR) {283283+ if (rx & URX_PARITY_ERROR)302284 flag = TTY_PARITY;303303- status_handle(info, rx);304304- } else if(rx & URX_OVRUN) {285285+ else if (rx & URX_OVRUN)305286 flag = TTY_OVERRUN;306306- status_handle(info, rx);307307- } else if(rx & URX_FRAME_ERROR) {287287+ else if (rx & URX_FRAME_ERROR)308288 flag = TTY_FRAME;309309- status_handle(info, rx);310310- }289289+311290 tty_insert_flip_char(tty, ch, flag);312291#ifndef CONFIG_XCOPILOT_BUGS313292 } while((rx = uart->urx.w) & URX_DATA_READY);···316301 return;317302}318303319319-static void transmit_chars(struct m68k_serial *info)304304+static void transmit_chars(struct m68k_serial *info, struct tty_struct *tty)320305{321306 m68328_uart *uart = &uart_addr[info->line];322307···327312 goto clear_and_return;328313 }329314330330- if((info->xmit_cnt <= 0) || info->tty->stopped) {315315+ if ((info->xmit_cnt <= 0) || !tty || tty->stopped) {331316 /* That's peculiar... TX ints off */332317 uart->ustcnt &= ~USTCNT_TX_INTR_MASK;333318 goto clear_and_return;···355340irqreturn_t rs_interrupt(int irq, void *dev_id)356341{357342 struct m68k_serial *info = dev_id;343343+ struct tty_struct *tty = tty_port_tty_get(&info->tport);358344 m68328_uart *uart;359345 unsigned short rx;360346 unsigned short tx;···366350#ifdef USE_INTS367351 tx = uart->utx.w;368352369369- if (rx & URX_DATA_READY) receive_chars(info, rx);370370- if (tx & UTX_TX_AVAIL) transmit_chars(info);353353+ if (rx & URX_DATA_READY)354354+ receive_chars(info, tty, rx);355355+ if (tx & UTX_TX_AVAIL)356356+ transmit_chars(info, tty);371357#else372372- receive_chars(info, rx); 358358+ receive_chars(info, tty, rx);373359#endif360360+ tty_kref_put(tty);361361+374362 return IRQ_HANDLED;375363}376364377377-static int startup(struct m68k_serial * info)365365+static int startup(struct m68k_serial *info, struct tty_struct *tty)378366{379367 m68328_uart *uart = &uart_addr[info->line];380368 unsigned long flags;381369382382- if (info->flags & S_INITIALIZED)370370+ if (info->tport.flags & ASYNC_INITIALIZED)383371 return 0;384372385373 if (!info->xmit_buf) {···400380 */401381402382 uart->ustcnt = USTCNT_UEN;403403- info->xmit_fifo_size = 1;404383 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_TXEN;405384 (void)uart->urx.w;406385···413394 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_RX_INTR_MASK;414395#endif415396416416- if (info->tty)417417- clear_bit(TTY_IO_ERROR, &info->tty->flags);397397+ if (tty)398398+ clear_bit(TTY_IO_ERROR, &tty->flags);418399 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;419400420401 /*421402 * and set the speed of the serial port422403 */423404424424- change_speed(info);405405+ change_speed(info, tty);425406426426- info->flags |= S_INITIALIZED;407407+ info->tport.flags |= ASYNC_INITIALIZED;427408 local_irq_restore(flags);428409 return 0;429410}···432413 * This routine will shutdown a serial port; interrupts are disabled, and433414 * DTR is dropped if the hangup on close termio flag is on.434415 */435435-static void shutdown(struct m68k_serial * info)416416+static void shutdown(struct m68k_serial *info, struct tty_struct *tty)436417{437418 m68328_uart *uart = &uart_addr[info->line];438419 unsigned long flags;439420440421 uart->ustcnt = 0; /* All off! */441441- if (!(info->flags & S_INITIALIZED))422422+ if (!(info->tport.flags & ASYNC_INITIALIZED))442423 return;443424444425 local_irq_save(flags);···448429 info->xmit_buf = 0;449430 }450431451451- if (info->tty)452452- set_bit(TTY_IO_ERROR, &info->tty->flags);432432+ if (tty)433433+ set_bit(TTY_IO_ERROR, &tty->flags);453434454454- info->flags &= ~S_INITIALIZED;435435+ info->tport.flags &= ~ASYNC_INITIALIZED;455436 local_irq_restore(flags);456437}457438···507488 * This routine is called to set the UART divisor registers to match508489 * the specified baud rate for a serial port.509490 */510510-static void change_speed(struct m68k_serial *info)491491+static void change_speed(struct m68k_serial *info, struct tty_struct *tty)511492{512493 m68328_uart *uart = &uart_addr[info->line];513494 unsigned short port;···515496 unsigned cflag;516497 int i;517498518518- if (!info->tty || !info->tty->termios)519519- return;520520- cflag = info->tty->termios->c_cflag;499499+ cflag = tty->termios->c_cflag;521500 if (!(port = info->port))522501 return;523502···527510 i = (i & ~CBAUDEX) + B38400;528511 }529512530530- info->baud = baud_table[i];531513 uart->ubaud = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) | 532514 PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale);533515···823807 tmp.line = info->line;824808 tmp.port = info->port;825809 tmp.irq = info->irq;826826- tmp.flags = info->flags;810810+ tmp.flags = info->tport.flags;827811 tmp.baud_base = info->baud_base;828828- tmp.close_delay = info->close_delay;829829- tmp.closing_wait = info->closing_wait;812812+ tmp.close_delay = info->tport.close_delay;813813+ tmp.closing_wait = info->tport.closing_wait;830814 tmp.custom_divisor = info->custom_divisor;831815 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))832816 return -EFAULT;···834818 return 0;835819}836820837837-static int set_serial_info(struct m68k_serial * info,821821+static int set_serial_info(struct m68k_serial *info, struct tty_struct *tty,838822 struct serial_struct * new_info)839823{824824+ struct tty_port *port = &info->tport;840825 struct serial_struct new_serial;841826 struct m68k_serial old_info;842827 int retval = 0;···851834 if (!capable(CAP_SYS_ADMIN)) {852835 if ((new_serial.baud_base != info->baud_base) ||853836 (new_serial.type != info->type) ||854854- (new_serial.close_delay != info->close_delay) ||855855- ((new_serial.flags & ~S_USR_MASK) !=856856- (info->flags & ~S_USR_MASK)))837837+ (new_serial.close_delay != port->close_delay) ||838838+ ((new_serial.flags & ~ASYNC_USR_MASK) !=839839+ (port->flags & ~ASYNC_USR_MASK)))857840 return -EPERM;858858- info->flags = ((info->flags & ~S_USR_MASK) |859859- (new_serial.flags & S_USR_MASK));841841+ port->flags = ((port->flags & ~ASYNC_USR_MASK) |842842+ (new_serial.flags & ASYNC_USR_MASK));860843 info->custom_divisor = new_serial.custom_divisor;861844 goto check_and_exit;862845 }863846864864- if (info->count > 1)847847+ if (port->count > 1)865848 return -EBUSY;866849867850 /*···870853 */871854872855 info->baud_base = new_serial.baud_base;873873- info->flags = ((info->flags & ~S_FLAGS) |874874- (new_serial.flags & S_FLAGS));856856+ port->flags = ((port->flags & ~ASYNC_FLAGS) |857857+ (new_serial.flags & ASYNC_FLAGS));875858 info->type = new_serial.type;876876- info->close_delay = new_serial.close_delay;877877- info->closing_wait = new_serial.closing_wait;859859+ port->close_delay = new_serial.close_delay;860860+ port->closing_wait = new_serial.closing_wait;878861879862check_and_exit:880880- retval = startup(info);863863+ retval = startup(info, tty);881864 return retval;882865}883866···963946 return get_serial_info(info,964947 (struct serial_struct *) arg);965948 case TIOCSSERIAL:966966- return set_serial_info(info,949949+ return set_serial_info(info, tty,967950 (struct serial_struct *) arg);968951 case TIOCSERGETLSR: /* Get line status register */969952 return get_lsr_info(info, (unsigned int *) arg);···982965{983966 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;984967985985- change_speed(info);968968+ change_speed(info, tty);986969987970 if ((old_termios->c_cflag & CRTSCTS) &&988971 !(tty->termios->c_cflag & CRTSCTS)) {···1005988static void rs_close(struct tty_struct *tty, struct file * filp)1006989{1007990 struct m68k_serial * info = (struct m68k_serial *)tty->driver_data;991991+ struct tty_port *port = &info->tport;1008992 m68328_uart *uart = &uart_addr[info->line];1009993 unsigned long flags;1010994···10191001 return;10201002 }1021100310221022- if ((tty->count == 1) && (info->count != 1)) {10041004+ if ((tty->count == 1) && (port->count != 1)) {10231005 /*10241006 * Uh, oh. tty->count is 1, which means that the tty10251007 * structure will be freed. Info->count should always···10281010 * serial port won't be shutdown.10291011 */10301012 printk("rs_close: bad serial port count; tty->count is 1, "10311031- "info->count is %d\n", info->count);10321032- info->count = 1;10131013+ "port->count is %d\n", port->count);10141014+ port->count = 1;10331015 }10341034- if (--info->count < 0) {10161016+ if (--port->count < 0) {10351017 printk("rs_close: bad serial port count for ttyS%d: %d\n",10361036- info->line, info->count);10371037- info->count = 0;10181018+ info->line, port->count);10191019+ port->count = 0;10381020 }10391039- if (info->count) {10211021+ if (port->count) {10401022 local_irq_restore(flags);10411023 return;10421024 }10431043- info->flags |= S_CLOSING;10251025+ port->flags |= ASYNC_CLOSING;10441026 /*10451027 * Now we wait for the transmit buffer to clear; and we notify 10461028 * the line discipline to only process XON/XOFF characters.10471029 */10481030 tty->closing = 1;10491049- if (info->closing_wait != S_CLOSING_WAIT_NONE)10501050- tty_wait_until_sent(tty, info->closing_wait);10311031+ if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)10321032+ tty_wait_until_sent(tty, port->closing_wait);10511033 /*10521034 * At this point we stop accepting input. To do this, we10531035 * disable the receive line status interrupts, and tell the···10581040 uart->ustcnt &= ~USTCNT_RXEN;10591041 uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK);1060104210611061- shutdown(info);10431043+ shutdown(info, tty);10621044 rs_flush_buffer(tty);1063104510641046 tty_ldisc_flush(tty);10651047 tty->closing = 0;10661066- info->event = 0;10671067- info->tty = NULL;10481048+ tty_port_tty_set(&info->tport, NULL);10681049#warning "This is not and has never been valid so fix it" 10691050#if 010701051 if (tty->ldisc.num != ldiscs[N_TTY].num) {···10751058 (tty->ldisc.open)(tty);10761059 }10771060#endif 10781078- if (info->blocked_open) {10791079- if (info->close_delay) {10801080- msleep_interruptible(jiffies_to_msecs(info->close_delay));10811081- }10821082- wake_up_interruptible(&info->open_wait);10611061+ if (port->blocked_open) {10621062+ if (port->close_delay)10631063+ msleep_interruptible(jiffies_to_msecs(port->close_delay));10641064+ wake_up_interruptible(&port->open_wait);10831065 }10841084- info->flags &= ~(S_NORMAL_ACTIVE|S_CLOSING);10851085- wake_up_interruptible(&info->close_wait);10661066+ port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);10671067+ wake_up_interruptible(&port->close_wait);10861068 local_irq_restore(flags);10871069}10881070···10961080 return;1097108110981082 rs_flush_buffer(tty);10991099- shutdown(info);11001100- info->event = 0;11011101- info->count = 0;11021102- info->flags &= ~S_NORMAL_ACTIVE;11031103- info->tty = NULL;11041104- wake_up_interruptible(&info->open_wait);10831083+ shutdown(info, tty);10841084+ info->tport.count = 0;10851085+ info->tport.flags &= ~ASYNC_NORMAL_ACTIVE;10861086+ tty_port_tty_set(&info->tport, NULL);10871087+ wake_up_interruptible(&info->tport.open_wait);11051088}11061106-11071107-/*11081108- * ------------------------------------------------------------11091109- * rs_open() and friends11101110- * ------------------------------------------------------------11111111- */11121112-static int block_til_ready(struct tty_struct *tty, struct file * filp,11131113- struct m68k_serial *info)11141114-{11151115- DECLARE_WAITQUEUE(wait, current);11161116- int retval;11171117- int do_clocal = 0;11181118-11191119- /*11201120- * If the device is in the middle of being closed, then block11211121- * until it's done, and then try again.11221122- */11231123- if (info->flags & S_CLOSING) {11241124- interruptible_sleep_on(&info->close_wait);11251125-#ifdef SERIAL_DO_RESTART11261126- if (info->flags & S_HUP_NOTIFY)11271127- return -EAGAIN;11281128- else11291129- return -ERESTARTSYS;11301130-#else11311131- return -EAGAIN;11321132-#endif11331133- }11341134-11351135- /*11361136- * If non-blocking mode is set, or the port is not enabled,11371137- * then make the check up front and then exit.11381138- */11391139- if ((filp->f_flags & O_NONBLOCK) ||11401140- (tty->flags & (1 << TTY_IO_ERROR))) {11411141- info->flags |= S_NORMAL_ACTIVE;11421142- return 0;11431143- }11441144-11451145- if (tty->termios->c_cflag & CLOCAL)11461146- do_clocal = 1;11471147-11481148- /*11491149- * Block waiting for the carrier detect and the line to become11501150- * free (i.e., not in use by the callout). While we are in11511151- * this loop, info->count is dropped by one, so that11521152- * rs_close() knows when to free things. We restore it upon11531153- * exit, either normal or abnormal.11541154- */11551155- retval = 0;11561156- add_wait_queue(&info->open_wait, &wait);11571157-11581158- info->count--;11591159- info->blocked_open++;11601160- while (1) {11611161- local_irq_disable();11621162- m68k_rtsdtr(info, 1);11631163- local_irq_enable();11641164- current->state = TASK_INTERRUPTIBLE;11651165- if (tty_hung_up_p(filp) ||11661166- !(info->flags & S_INITIALIZED)) {11671167-#ifdef SERIAL_DO_RESTART11681168- if (info->flags & S_HUP_NOTIFY)11691169- retval = -EAGAIN;11701170- else11711171- retval = -ERESTARTSYS; 11721172-#else11731173- retval = -EAGAIN;11741174-#endif11751175- break;11761176- }11771177- if (!(info->flags & S_CLOSING) && do_clocal)11781178- break;11791179- if (signal_pending(current)) {11801180- retval = -ERESTARTSYS;11811181- break;11821182- }11831183- tty_unlock();11841184- schedule();11851185- tty_lock();11861186- }11871187- current->state = TASK_RUNNING;11881188- remove_wait_queue(&info->open_wait, &wait);11891189- if (!tty_hung_up_p(filp))11901190- info->count++;11911191- info->blocked_open--;11921192-11931193- if (retval)11941194- return retval;11951195- info->flags |= S_NORMAL_ACTIVE;11961196- return 0;11971197-} 1198108911991090/*12001091 * This routine is called whenever a serial port is opened. It···11191196 if (serial_paranoia_check(info, tty->name, "rs_open"))11201197 return -ENODEV;1121119811221122- info->count++;11991199+ info->tport.count++;11231200 tty->driver_data = info;11241124- info->tty = tty;12011201+ tty_port_tty_set(&info->tport, tty);1125120211261203 /*11271204 * Start up serial port11281205 */11291129- retval = startup(info);12061206+ retval = startup(info, tty);11301207 if (retval)11311208 return retval;1132120911331133- return block_til_ready(tty, filp, info);12101210+ return tty_port_block_til_ready(&info->tport, tty, filp);11341211}1135121211361213/* Finally, routines used to initialize the serial driver. */···11581235 .set_ldisc = rs_set_ldisc,11591236};1160123712381238+static const struct tty_port_operations rs_port_ops = {12391239+};12401240+11611241/* rs_init inits the driver */11621242static int __init11631243rs68328_init(void)11641244{11651165- int flags, i;12451245+ unsigned long flags;12461246+ int i;11661247 struct m68k_serial *info;1167124811681249 serial_driver = alloc_tty_driver(NR_PORTS);···12001273 for(i=0;i<NR_PORTS;i++) {1201127412021275 info = &m68k_soft[i];12761276+ tty_port_init(&info->tport);12771277+ info->tport.ops = &rs_port_ops;12031278 info->magic = SERIAL_MAGIC;12041279 info->port = (int) &uart_addr[i];12051205- info->tty = NULL;12061280 info->irq = uart_irqs[i];12071281 info->custom_divisor = 16;12081208- info->close_delay = 50;12091209- info->closing_wait = 3000;12101282 info->x_char = 0;12111211- info->event = 0;12121212- info->count = 0;12131213- info->blocked_open = 0;12141214- init_waitqueue_head(&info->open_wait);12151215- init_waitqueue_head(&info->close_wait);12161283 info->line = i;12171284 info->is_cons = 1; /* Means shortcuts work */12181285
-186
drivers/tty/serial/68328serial.h
···11-/* 68328serial.h: Definitions for the mc68328 serial driver.22- *33- * Copyright (C) 1995 David S. Miller <davem@caip.rutgers.edu>44- * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>55- * Copyright (C) 1998, 1999 D. Jeff Dionne <jeff@uclinux.org>66- * Copyright (C) 1999 Vladimir Gurevich <vgurevic@cisco.com>77- *88- * VZ Support/Fixes Evan Stawnyczy <e@lineo.ca>99- */1010-1111-#ifndef _MC683XX_SERIAL_H1212-#define _MC683XX_SERIAL_H1313-1414-1515-struct serial_struct {1616- int type;1717- int line;1818- int port;1919- int irq;2020- int flags;2121- int xmit_fifo_size;2222- int custom_divisor;2323- int baud_base;2424- unsigned short close_delay;2525- char reserved_char[2];2626- int hub6; /* FIXME: We don't have AT&T Hub6 boards! */2727- unsigned short closing_wait; /* time to wait before closing */2828- unsigned short closing_wait2; /* no longer used... */2929- int reserved[4];3030-};3131-3232-/*3333- * For the close wait times, 0 means wait forever for serial port to3434- * flush its output. 65535 means don't wait at all.3535- */3636-#define S_CLOSING_WAIT_INF 03737-#define S_CLOSING_WAIT_NONE 655353838-3939-/*4040- * Definitions for S_struct (and serial_struct) flags field4141- */4242-#define S_HUP_NOTIFY 0x0001 /* Notify getty on hangups and closes 4343- on the callout port */4444-#define S_FOURPORT 0x0002 /* Set OU1, OUT2 per AST Fourport settings */4545-#define S_SAK 0x0004 /* Secure Attention Key (Orange book) */4646-#define S_SPLIT_TERMIOS 0x0008 /* Separate termios for dialin/callout */4747-4848-#define S_SPD_MASK 0x00304949-#define S_SPD_HI 0x0010 /* Use 56000 instead of 38400 bps */5050-5151-#define S_SPD_VHI 0x0020 /* Use 115200 instead of 38400 bps */5252-#define S_SPD_CUST 0x0030 /* Use user-specified divisor */5353-5454-#define S_SKIP_TEST 0x0040 /* Skip UART test during autoconfiguration */5555-#define S_AUTO_IRQ 0x0080 /* Do automatic IRQ during autoconfiguration */5656-#define S_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */5757-#define S_PGRP_LOCKOUT 0x0200 /* Lock out cua opens based on pgrp */5858-#define S_CALLOUT_NOHUP 0x0400 /* Don't do hangups for cua device */5959-6060-#define S_FLAGS 0x0FFF /* Possible legal S flags */6161-#define S_USR_MASK 0x0430 /* Legal flags that non-privileged6262- * users can set or reset */6363-6464-/* Internal flags used only by kernel/chr_drv/serial.c */6565-#define S_INITIALIZED 0x80000000 /* Serial port was initialized */6666-#define S_CALLOUT_ACTIVE 0x40000000 /* Call out device is active */6767-#define S_NORMAL_ACTIVE 0x20000000 /* Normal device is active */6868-#define S_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */6969-#define S_CLOSING 0x08000000 /* Serial port is closing */7070-#define S_CTS_FLOW 0x04000000 /* Do CTS flow control */7171-#define S_CHECK_CD 0x02000000 /* i.e., CLOCAL */7272-7373-/* Software state per channel */7474-7575-#ifdef __KERNEL__7676-7777-/*7878- * I believe this is the optimal setting that reduces the number of interrupts.7979- * At high speeds the output might become a little "bursted" (use USTCNT_TXHE8080- * if that bothers you), but in most cases it will not, since we try to 8181- * transmit characters every time rs_interrupt is called. Thus, quite often8282- * you'll see that a receive interrupt occures before the transmit one.8383- * -- Vladimir Gurevich8484- */8585-#define USTCNT_TX_INTR_MASK (USTCNT_TXEE)8686-8787-/*8888- * 68328 and 68EZ328 UARTS are a little bit different. EZ328 has special8989- * "Old data interrupt" which occures whenever the data stay in the FIFO9090- * longer than 30 bits time. This allows us to use FIFO without compromising9191- * latency. '328 does not have this feature and without the real 328-based9292- * board I would assume that RXRE is the safest setting.9393- *9494- * For EZ328 I use RXHE (Half empty) interrupt to reduce the number of9595- * interrupts. RXFE (receive queue full) causes the system to lose data9696- * at least at 115200 baud9797- *9898- * If your board is busy doing other stuff, you might consider to use9999- * RXRE (data ready intrrupt) instead.100100- *101101- * The other option is to make these INTR masks run-time configurable, so102102- * that people can dynamically adapt them according to the current usage.103103- * -- Vladimir Gurevich104104- */105105-106106-/* (es) */107107-#if defined(CONFIG_M68EZ328) || defined(CONFIG_M68VZ328)108108-#define USTCNT_RX_INTR_MASK (USTCNT_RXHE | USTCNT_ODEN)109109-#elif defined(CONFIG_M68328)110110-#define USTCNT_RX_INTR_MASK (USTCNT_RXRE)111111-#else112112-#error Please, define the Rx interrupt events for your CPU113113-#endif114114-/* (/es) */115115-116116-/*117117- * This is our internal structure for each serial port's state.118118- * 119119- * Many fields are paralleled by the structure used by the serial_struct120120- * structure.121121- *122122- * For definitions of the flags field, see tty.h123123- */124124-125125-struct m68k_serial {126126- char soft_carrier; /* Use soft carrier on this channel */127127- char break_abort; /* Is serial console in, so process brk/abrt */128128- char is_cons; /* Is this our console. */129129-130130- /* We need to know the current clock divisor131131- * to read the bps rate the chip has currently132132- * loaded.133133- */134134- unsigned char clk_divisor; /* May be 1, 16, 32, or 64 */135135- int baud;136136- int magic;137137- int baud_base;138138- int port;139139- int irq;140140- int flags; /* defined in tty.h */141141- int type; /* UART type */142142- struct tty_struct *tty;143143- int read_status_mask;144144- int ignore_status_mask;145145- int timeout;146146- int xmit_fifo_size;147147- int custom_divisor;148148- int x_char; /* xon/xoff character */149149- int close_delay;150150- unsigned short closing_wait;151151- unsigned short closing_wait2;152152- unsigned long event;153153- unsigned long last_active;154154- int line;155155- int count; /* # of fd on device */156156- int blocked_open; /* # of blocked opens */157157- unsigned char *xmit_buf;158158- int xmit_head;159159- int xmit_tail;160160- int xmit_cnt;161161- wait_queue_head_t open_wait;162162- wait_queue_head_t close_wait;163163-};164164-165165-166166-#define SERIAL_MAGIC 0x5301167167-168168-/*169169- * The size of the serial xmit buffer is 1 page, or 4096 bytes170170- */171171-#define SERIAL_XMIT_SIZE 4096172172-173173-/*174174- * Events are used to schedule things to happen at timer-interrupt175175- * time, instead of at rs interrupt time.176176- */177177-#define RS_EVENT_WRITE_WAKEUP 0178178-179179-/* 180180- * Define the number of ports supported and their irqs.181181- */182182-#define NR_PORTS 1183183-#define UART_IRQ_DEFNS {UART_IRQ_NUM}184184-185185-#endif /* __KERNEL__ */186186-#endif /* !(_MC683XX_SERIAL_H) */
+13-31
drivers/tty/serial/8250/8250.c
···568568 }569569}570570571571+void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p)572572+{573573+ unsigned char fcr;574574+575575+ serial8250_clear_fifos(p);576576+ fcr = uart_config[p->port.type].fcr;577577+ serial_out(p, UART_FCR, fcr);578578+}579579+EXPORT_SYMBOL_GPL(serial8250_clear_and_reinit_fifos);580580+571581/*572582 * IER sleep support. UARTs which have EFRs need the "extended573583 * capability" bit enabled. Note that on XR16C850s, we need to···13421332}1343133313441334/*13451345- * Clear the Tegra rx fifo after a break13461346- *13471347- * FIXME: This needs to become a port specific callback once we have a13481348- * framework for this13491349- */13501350-static void clear_rx_fifo(struct uart_8250_port *up)13511351-{13521352- unsigned int status, tmout = 10000;13531353- do {13541354- status = serial_in(up, UART_LSR);13551355- if (status & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS))13561356- status = serial_in(up, UART_RX);13571357- else13581358- break;13591359- if (--tmout == 0)13601360- break;13611361- udelay(1);13621362- } while (1);13631363-}13641364-13651365-/*13661335 * serial8250_rx_chars: processes according to the passed in LSR13671336 * value, and returns the remaining LSR bits not handled13681337 * by this Rx routine.···13751386 up->lsr_saved_flags = 0;1376138713771388 if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) {13781378- /*13791379- * For statistics only13801380- */13811389 if (lsr & UART_LSR_BI) {13821390 lsr &= ~(UART_LSR_FE | UART_LSR_PE);13831391 port->icount.brk++;13841384- /*13851385- * If tegra port then clear the rx fifo to13861386- * accept another break/character.13871387- */13881388- if (port->type == PORT_TEGRA)13891389- clear_rx_fifo(up);13901390-13911392 /*13921393 * We do the SysRQ and SAK checking13931394 * here because otherwise the break···30163037 port.serial_in = p->serial_in;30173038 port.serial_out = p->serial_out;30183039 port.handle_irq = p->handle_irq;30403040+ port.handle_break = p->handle_break;30193041 port.set_termios = p->set_termios;30203042 port.pm = p->pm;30213043 port.dev = &dev->dev;···31893209 uart->port.set_termios = port->set_termios;31903210 if (port->pm)31913211 uart->port.pm = port->pm;32123212+ if (port->handle_break)32133213+ uart->port.handle_break = port->handle_break;3192321431933215 if (serial8250_isa_config != NULL)31943216 serial8250_isa_config(0, &uart->port,
+2
drivers/tty/serial/8250/8250.h
···9696 up->port.serial_out(&up->port, offset, value);9797}98989999+void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p);100100+99101#if defined(__alpha__) && !defined(CONFIG_PCI)100102/*101103 * Digital did something really horribly wrong with the OUT1 and OUT2
+45
drivers/tty/serial/8250/8250_pci.c
···1717#include <linux/slab.h>1818#include <linux/delay.h>1919#include <linux/tty.h>2020+#include <linux/serial_reg.h>2021#include <linux/serial_core.h>2122#include <linux/8250_pci.h>2223#include <linux/bitops.h>···10931092 return pci_default_setup(priv, board, port, idx);10941093}1095109410951095+static void kt_handle_break(struct uart_port *p)10961096+{10971097+ struct uart_8250_port *up =10981098+ container_of(p, struct uart_8250_port, port);10991099+ /*11001100+ * On receipt of a BI, serial device in Intel ME (Intel11011101+ * management engine) needs to have its fifos cleared for sane11021102+ * SOL (Serial Over Lan) output.11031103+ */11041104+ serial8250_clear_and_reinit_fifos(up);11051105+}11061106+11071107+static unsigned int kt_serial_in(struct uart_port *p, int offset)11081108+{11091109+ struct uart_8250_port *up =11101110+ container_of(p, struct uart_8250_port, port);11111111+ unsigned int val;11121112+11131113+ /*11141114+ * When the Intel ME (management engine) gets reset its serial11151115+ * port registers could return 0 momentarily. Functions like11161116+ * serial8250_console_write, read and save the IER, perform11171117+ * some operation and then restore it. In order to avoid11181118+ * setting IER register inadvertently to 0, if the value read11191119+ * is 0, double check with ier value in uart_8250_port and use11201120+ * that instead. up->ier should be the same value as what is11211121+ * currently configured.11221122+ */11231123+ val = inb(p->iobase + offset);11241124+ if (offset == UART_IER) {11251125+ if (val == 0)11261126+ val = up->ier;11271127+ }11281128+ return val;11291129+}11301130+10961131static int kt_serial_setup(struct serial_private *priv,10971132 const struct pciserial_board *board,10981133 struct uart_port *port, int idx)10991134{11001135 port->flags |= UPF_BUG_THRE;11361136+ port->serial_in = kt_serial_in;11371137+ port->handle_break = kt_handle_break;11011138 return skip_tx_en_setup(priv, board, port, idx);11021139}11031140···28142775 for (i = 0; i < priv->nr; i++)28152776 if (priv->line[i] >= 0)28162777 serial8250_suspend_port(priv->line[i]);27782778+27792779+ /*27802780+ * Ensure that every init quirk is properly torn down27812781+ */27822782+ if (priv->quirk->exit)27832783+ priv->quirk->exit(priv->dev);28172784}28182785EXPORT_SYMBOL_GPL(pciserial_suspend_ports);28192786
+18-91
drivers/tty/serial/amba-pl011.c
···6767#define UART_DR_ERROR (UART011_DR_OE|UART011_DR_BE|UART011_DR_PE|UART011_DR_FE)6868#define UART_DUMMY_DR_RX (1 << 16)69697070-7171-#define UART_WA_SAVE_NR 147272-7373-static void pl011_lockup_wa(unsigned long data);7474-static const u32 uart_wa_reg[UART_WA_SAVE_NR] = {7575- ST_UART011_DMAWM,7676- ST_UART011_TIMEOUT,7777- ST_UART011_LCRH_RX,7878- UART011_IBRD,7979- UART011_FBRD,8080- ST_UART011_LCRH_TX,8181- UART011_IFLS,8282- ST_UART011_XFCR,8383- ST_UART011_XON1,8484- ST_UART011_XON2,8585- ST_UART011_XOFF1,8686- ST_UART011_XOFF2,8787- UART011_CR,8888- UART011_IMSC8989-};9090-9191-static u32 uart_wa_regdata[UART_WA_SAVE_NR];9292-static DECLARE_TASKLET(pl011_lockup_tlet, pl011_lockup_wa, 0);9393-9470/* There is by now at least one vendor with differing details, so handle it */9571struct vendor_data {9672 unsigned int ifls;···76100 bool oversampling;77101 bool interrupt_may_hang; /* vendor-specific */78102 bool dma_threshold;103103+ bool cts_event_workaround;79104};8010581106static struct vendor_data vendor_arm = {···86109 .lcrh_rx = UART011_LCRH,87110 .oversampling = false,88111 .dma_threshold = false,112112+ .cts_event_workaround = false,89113};9011491115static struct vendor_data vendor_st = {···97119 .oversampling = true,98120 .interrupt_may_hang = true,99121 .dma_threshold = true,122122+ .cts_event_workaround = true,100123};101124102125static struct uart_amba_port *amba_ports[UART_NR];···10331054#define pl011_dma_flush_buffer NULL10341055#endif1035105610361036-10371037-/*10381038- * pl011_lockup_wa10391039- * This workaround aims to break the deadlock situation10401040- * when after long transfer over uart in hardware flow10411041- * control, uart interrupt registers cannot be cleared.10421042- * Hence uart transfer gets blocked.10431043- *10441044- * It is seen that during such deadlock condition ICR10451045- * don't get cleared even on multiple write. This leads10461046- * pass_counter to decrease and finally reach zero. This10471047- * can be taken as trigger point to run this UART_BT_WA.10481048- *10491049- */10501050-static void pl011_lockup_wa(unsigned long data)10511051-{10521052- struct uart_amba_port *uap = amba_ports[0];10531053- void __iomem *base = uap->port.membase;10541054- struct circ_buf *xmit = &uap->port.state->xmit;10551055- struct tty_struct *tty = uap->port.state->port.tty;10561056- int buf_empty_retries = 200;10571057- int loop;10581058-10591059- /* Stop HCI layer from submitting data for tx */10601060- tty->hw_stopped = 1;10611061- while (!uart_circ_empty(xmit)) {10621062- if (buf_empty_retries-- == 0)10631063- break;10641064- udelay(100);10651065- }10661066-10671067- /* Backup registers */10681068- for (loop = 0; loop < UART_WA_SAVE_NR; loop++)10691069- uart_wa_regdata[loop] = readl(base + uart_wa_reg[loop]);10701070-10711071- /* Disable UART so that FIFO data is flushed out */10721072- writew(0x00, uap->port.membase + UART011_CR);10731073-10741074- /* Soft reset UART module */10751075- if (uap->port.dev->platform_data) {10761076- struct amba_pl011_data *plat;10771077-10781078- plat = uap->port.dev->platform_data;10791079- if (plat->reset)10801080- plat->reset();10811081- }10821082-10831083- /* Restore registers */10841084- for (loop = 0; loop < UART_WA_SAVE_NR; loop++)10851085- writew(uart_wa_regdata[loop] ,10861086- uap->port.membase + uart_wa_reg[loop]);10871087-10881088- /* Initialise the old status of the modem signals */10891089- uap->old_status = readw(uap->port.membase + UART01x_FR) &10901090- UART01x_FR_MODEM_ANY;10911091-10921092- if (readl(base + UART011_MIS) & 0x2)10931093- printk(KERN_EMERG "UART_BT_WA: ***FAILED***\n");10941094-10951095- /* Start Tx/Rx */10961096- tty->hw_stopped = 0;10971097-}10981098-10991057static void pl011_stop_tx(struct uart_port *port)11001058{11011059 struct uart_amba_port *uap = (struct uart_amba_port *)port;···11611245 unsigned long flags;11621246 unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT;11631247 int handled = 0;12481248+ unsigned int dummy_read;1164124911651250 spin_lock_irqsave(&uap->port.lock, flags);1166125111671252 status = readw(uap->port.membase + UART011_MIS);11681253 if (status) {11691254 do {12551255+ if (uap->vendor->cts_event_workaround) {12561256+ /* workaround to make sure that all bits are unlocked.. */12571257+ writew(0x00, uap->port.membase + UART011_ICR);12581258+12591259+ /*12601260+ * WA: introduce 26ns(1 uart clk) delay before W1C;12611261+ * single apb access will incur 2 pclk(133.12Mhz) delay,12621262+ * so add 2 dummy reads12631263+ */12641264+ dummy_read = readw(uap->port.membase + UART011_ICR);12651265+ dummy_read = readw(uap->port.membase + UART011_ICR);12661266+ }12671267+11701268 writew(status & ~(UART011_TXIS|UART011_RTIS|11711269 UART011_RXIS),11721270 uap->port.membase + UART011_ICR);···11971267 if (status & UART011_TXIS)11981268 pl011_tx_chars(uap);1199126912001200- if (pass_counter-- == 0) {12011201- if (uap->interrupt_may_hang)12021202- tasklet_schedule(&pl011_lockup_tlet);12701270+ if (pass_counter-- == 0)12031271 break;12041204- }1205127212061273 status = readw(uap->port.membase + UART011_MIS);12071274 } while (status != 0);
+2-26
drivers/tty/serial/crisv10.c
···952952/* Input */953953#define E100_DSR_GET(info) ((*e100_modem_pins[(info)->line].dsr_port) & e100_modem_pins[(info)->line].dsr_mask)954954955955-956956-/*957957- * tmp_buf is used as a temporary buffer by serial_write. We need to958958- * lock it in case the memcpy_fromfs blocks while swapping in a page,959959- * and some other program tries to do a serial write at the same time.960960- * Since the lock will only come under contention when the system is961961- * swapping and available memory is low, it makes sense to share one962962- * buffer across all the serial ports, since it significantly saves963963- * memory if large numbers of serial ports are open.964964- */965965-static unsigned char *tmp_buf;966966-static DEFINE_MUTEX(tmp_buf_mutex);967967-968955/* Calculate the chartime depending on baudrate, numbor of bits etc. */969956static void update_char_time(struct e100_serial * info)970957{···3137315031383151 /* first some sanity checks */3139315231403140- if (!tty || !info->xmit.buf || !tmp_buf)31533153+ if (!tty || !info->xmit.buf)31413154 return 0;3142315531433156#ifdef SERIAL_DEBUG_DATA···40934106{40944107 struct e100_serial *info;40954108 int retval;40964096- unsigned long page;40974109 int allocated_resources = 0;4098411040994111 info = rs_table + tty->index;···41094123 info->port.tty = tty;4110412441114125 tty->low_latency = !!(info->flags & ASYNC_LOW_LATENCY);41124112-41134113- if (!tmp_buf) {41144114- page = get_zeroed_page(GFP_KERNEL);41154115- if (!page) {41164116- return -ENOMEM;41174117- }41184118- if (tmp_buf)41194119- free_page(page);41204120- else41214121- tmp_buf = (unsigned char *) page;41224122- }4123412641244127 /*41254128 * If the port is in the middle of closing, bail out now···44624487 info->enabled = 0;44634488 }44644489 }44904490+ tty_port_init(&info->port);44654491 info->uses_dma_in = 0;44664492 info->uses_dma_out = 0;44674493 info->line = i;
+26
drivers/tty/serial/of_serial.c
···1212#include <linux/init.h>1313#include <linux/module.h>1414#include <linux/slab.h>1515+#include <linux/delay.h>1516#include <linux/serial_core.h>1617#include <linux/serial_8250.h>1818+#include <linux/serial_reg.h>1719#include <linux/of_address.h>1820#include <linux/of_irq.h>2121+#include <linux/of_serial.h>1922#include <linux/of_platform.h>2023#include <linux/nwpserial.h>2124···2623 int type;2724 int line;2825};2626+2727+#ifdef CONFIG_ARCH_TEGRA2828+void tegra_serial_handle_break(struct uart_port *p)2929+{3030+ unsigned int status, tmout = 10000;3131+3232+ do {3333+ status = p->serial_in(p, UART_LSR);3434+ if (status & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS))3535+ status = p->serial_in(p, UART_RX);3636+ else3737+ break;3838+ if (--tmout == 0)3939+ break;4040+ udelay(1);4141+ } while (1);4242+}4343+/* FIXME remove this export when tegra finishes conversion to open firmware */4444+EXPORT_SYMBOL_GPL(tegra_serial_handle_break);4545+#endif29463047/*3148 * Fill a struct uart_port for a given device node···10683 port->flags = UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF | UPF_IOREMAP10784 | UPF_FIXED_PORT | UPF_FIXED_TYPE;10885 port->dev = &ofdev->dev;8686+8787+ if (type == PORT_TEGRA)8888+ port->handle_break = tegra_serial_handle_break;1098911090 return 0;11191}
···3939 PCH_UART_HANDLED_RX_ERR_INT_SHIFT,4040 PCH_UART_HANDLED_RX_TRG_INT_SHIFT,4141 PCH_UART_HANDLED_MS_INT_SHIFT,4242+ PCH_UART_HANDLED_LS_INT_SHIFT,4243};43444445enum {···6362#define PCH_UART_HANDLED_RX_TRG_INT (1<<((\6463 PCH_UART_HANDLED_RX_TRG_INT_SHIFT)<<1))6564#define PCH_UART_HANDLED_MS_INT (1<<((PCH_UART_HANDLED_MS_INT_SHIFT)<<1))6565+6666+#define PCH_UART_HANDLED_LS_INT (1<<((PCH_UART_HANDLED_LS_INT_SHIFT)<<1))66676768#define PCH_UART_RBR 0x006869#define PCH_UART_THR 0x00···232229 int start_tx;233230 int start_rx;234231 int tx_empty;235235- int int_dis_flag;236232 int trigger;237233 int trigger_level;238234 struct pch_uart_buffer rxbuf;···239237 unsigned int fcr;240238 unsigned int mcr;241239 unsigned int use_dma;242242- unsigned int use_dma_flag;243240 struct dma_async_tx_descriptor *desc_tx;244241 struct dma_async_tx_descriptor *desc_rx;245242 struct pch_dma_slave param_tx;···561560 return i;562561}563562564564-static unsigned int pch_uart_hal_get_iid(struct eg20t_port *priv)563563+static unsigned char pch_uart_hal_get_iid(struct eg20t_port *priv)565564{566566- unsigned int iir;567567- int ret;568568-569569- iir = ioread8(priv->membase + UART_IIR);570570- ret = (iir & (PCH_UART_IIR_IID | PCH_UART_IIR_TOI | PCH_UART_IIR_IP));571571- return ret;565565+ return ioread8(priv->membase + UART_IIR) &\566566+ (PCH_UART_IIR_IID | PCH_UART_IIR_TOI | PCH_UART_IIR_IP);572567}573568574569static u8 pch_uart_hal_get_line_status(struct eg20t_port *priv)···663666 dma_release_channel(priv->chan_rx);664667 priv->chan_rx = NULL;665668 }666666- if (sg_dma_address(&priv->sg_rx))667667- dma_free_coherent(port->dev, port->fifosize,668668- sg_virt(&priv->sg_rx),669669- sg_dma_address(&priv->sg_rx));669669+670670+ if (priv->rx_buf_dma) {671671+ dma_free_coherent(port->dev, port->fifosize, priv->rx_buf_virt,672672+ priv->rx_buf_dma);673673+ priv->rx_buf_virt = NULL;674674+ priv->rx_buf_dma = 0;675675+ }670676671677 return;672678}···10531053 unsigned int handled;10541054 u8 lsr;10551055 int ret = 0;10561056- unsigned int iid;10561056+ unsigned char iid;10571057 unsigned long flags;10581058+ int next = 1;10591059+ u8 msr;1058106010591061 spin_lock_irqsave(&priv->port.lock, flags);10601062 handled = 0;10611061- while ((iid = pch_uart_hal_get_iid(priv)) > 1) {10631063+ while (next) {10641064+ iid = pch_uart_hal_get_iid(priv);10651065+ if (iid & PCH_UART_IIR_IP) /* No Interrupt */10661066+ break;10621067 switch (iid) {10631068 case PCH_UART_IID_RLS: /* Receiver Line Status */10641069 lsr = pch_uart_hal_get_line_status(priv);···10711066 UART_LSR_PE | UART_LSR_OE)) {10721067 pch_uart_err_ir(priv, lsr);10731068 ret = PCH_UART_HANDLED_RX_ERR_INT;10691069+ } else {10701070+ ret = PCH_UART_HANDLED_LS_INT;10741071 }10751072 break;10761073 case PCH_UART_IID_RDR: /* Received Data Ready */···10991092 ret = handle_tx(priv);11001093 break;11011094 case PCH_UART_IID_MS: /* Modem Status */11021102- ret = PCH_UART_HANDLED_MS_INT;10951095+ msr = pch_uart_hal_get_modem(priv);10961096+ next = 0; /* MS ir prioirty is the lowest. So, MS ir10971097+ means final interrupt */10981098+ if ((msr & UART_MSR_ANY_DELTA) == 0)10991099+ break;11001100+ ret |= PCH_UART_HANDLED_MS_INT;11031101 break;11041102 default: /* Never junp to this label */11051105- dev_err(priv->port.dev, "%s:iid=%d (%lu)\n", __func__,11031103+ dev_err(priv->port.dev, "%s:iid=%02x (%lu)\n", __func__,11061104 iid, jiffies);11071105 ret = -1;11061106+ next = 0;11081107 break;11091108 }11101109 handled |= (unsigned int)ret;11111111- }11121112- if (handled == 0 && iid <= 1) {11131113- if (priv->int_dis_flag)11141114- priv->int_dis_flag = 0;11151110 }1116111111171112 spin_unlock_irqrestore(&priv->port.lock, flags);···12091200 priv = container_of(port, struct eg20t_port, port);12101201 priv->start_rx = 0;12111202 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT);12121212- priv->int_dis_flag = 1;12131203}1214120412151205/* Enable the modem status interrupts. */···14551447 __func__);14561448 return -EOPNOTSUPP;14571449#endif14581458- priv->use_dma_flag = 1;14591450 dev_info(priv->port.dev, "PCH UART : Use DMA Mode\n");14601451 if (!priv->use_dma)14611452 pch_request_dma(port);
+65-20
drivers/tty/tty_buffer.c
···185185 /* Should possibly check if this fails for the largest buffer we186186 have queued and recycle that ? */187187}188188-189188/**190190- * tty_buffer_request_room - grow tty buffer if needed189189+ * __tty_buffer_request_room - grow tty buffer if needed191190 * @tty: tty structure192191 * @size: size desired193192 *194193 * Make at least size bytes of linear space available for the tty195194 * buffer. If we fail return the size we managed to find.196196- *197197- * Locking: Takes tty->buf.lock195195+ * Locking: Caller must hold tty->buf.lock198196 */199199-int tty_buffer_request_room(struct tty_struct *tty, size_t size)197197+static int __tty_buffer_request_room(struct tty_struct *tty, size_t size)200198{201199 struct tty_buffer *b, *n;202200 int left;203203- unsigned long flags;204204-205205- spin_lock_irqsave(&tty->buf.lock, flags);206206-207201 /* OPTIMISATION: We could keep a per tty "zero" sized buffer to208202 remove this conditional if its worth it. This would be invisible209203 to the callers */···219225 size = left;220226 }221227222222- spin_unlock_irqrestore(&tty->buf.lock, flags);223228 return size;229229+}230230+231231+232232+/**233233+ * tty_buffer_request_room - grow tty buffer if needed234234+ * @tty: tty structure235235+ * @size: size desired236236+ *237237+ * Make at least size bytes of linear space available for the tty238238+ * buffer. If we fail return the size we managed to find.239239+ *240240+ * Locking: Takes tty->buf.lock241241+ */242242+int tty_buffer_request_room(struct tty_struct *tty, size_t size)243243+{244244+ unsigned long flags;245245+ int length;246246+247247+ spin_lock_irqsave(&tty->buf.lock, flags);248248+ length = __tty_buffer_request_room(tty, size);249249+ spin_unlock_irqrestore(&tty->buf.lock, flags);250250+ return length;224251}225252EXPORT_SYMBOL_GPL(tty_buffer_request_room);226253···264249 int copied = 0;265250 do {266251 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE);267267- int space = tty_buffer_request_room(tty, goal);268268- struct tty_buffer *tb = tty->buf.tail;252252+ int space;253253+ unsigned long flags;254254+ struct tty_buffer *tb;255255+256256+ spin_lock_irqsave(&tty->buf.lock, flags);257257+ space = __tty_buffer_request_room(tty, goal);258258+ tb = tty->buf.tail;269259 /* If there is no space then tb may be NULL */270270- if (unlikely(space == 0))260260+ if (unlikely(space == 0)) {261261+ spin_unlock_irqrestore(&tty->buf.lock, flags);271262 break;263263+ }272264 memcpy(tb->char_buf_ptr + tb->used, chars, space);273265 memset(tb->flag_buf_ptr + tb->used, flag, space);274266 tb->used += space;267267+ spin_unlock_irqrestore(&tty->buf.lock, flags);275268 copied += space;276269 chars += space;277270 /* There is a small chance that we need to split the data over···309286 int copied = 0;310287 do {311288 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE);312312- int space = tty_buffer_request_room(tty, goal);313313- struct tty_buffer *tb = tty->buf.tail;289289+ int space;290290+ unsigned long __flags;291291+ struct tty_buffer *tb;292292+293293+ spin_lock_irqsave(&tty->buf.lock, __flags);294294+ space = __tty_buffer_request_room(tty, goal);295295+ tb = tty->buf.tail;314296 /* If there is no space then tb may be NULL */315315- if (unlikely(space == 0))297297+ if (unlikely(space == 0)) {298298+ spin_unlock_irqrestore(&tty->buf.lock, __flags);316299 break;300300+ }317301 memcpy(tb->char_buf_ptr + tb->used, chars, space);318302 memcpy(tb->flag_buf_ptr + tb->used, flags, space);319303 tb->used += space;304304+ spin_unlock_irqrestore(&tty->buf.lock, __flags);320305 copied += space;321306 chars += space;322307 flags += space;···375344int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars,376345 size_t size)377346{378378- int space = tty_buffer_request_room(tty, size);347347+ int space;348348+ unsigned long flags;349349+ struct tty_buffer *tb;350350+351351+ spin_lock_irqsave(&tty->buf.lock, flags);352352+ space = __tty_buffer_request_room(tty, size);353353+354354+ tb = tty->buf.tail;379355 if (likely(space)) {380380- struct tty_buffer *tb = tty->buf.tail;381356 *chars = tb->char_buf_ptr + tb->used;382357 memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space);383358 tb->used += space;384359 }360360+ spin_unlock_irqrestore(&tty->buf.lock, flags);385361 return space;386362}387363EXPORT_SYMBOL_GPL(tty_prepare_flip_string);···412374int tty_prepare_flip_string_flags(struct tty_struct *tty,413375 unsigned char **chars, char **flags, size_t size)414376{415415- int space = tty_buffer_request_room(tty, size);377377+ int space;378378+ unsigned long __flags;379379+ struct tty_buffer *tb;380380+381381+ spin_lock_irqsave(&tty->buf.lock, __flags);382382+ space = __tty_buffer_request_room(tty, size);383383+384384+ tb = tty->buf.tail;416385 if (likely(space)) {417417- struct tty_buffer *tb = tty->buf.tail;418386 *chars = tb->char_buf_ptr + tb->used;419387 *flags = tb->flag_buf_ptr + tb->used;420388 tb->used += space;421389 }390390+ spin_unlock_irqrestore(&tty->buf.lock, __flags);422391 return space;423392}424393EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
+32-36
drivers/tty/vt/vt.c
···38923892 vc->vc_sw->con_set_palette(vc, color_table);38933893}3894389438953895-static int set_get_cmap(unsigned char __user *arg, int set)38963896-{38973897- int i, j, k;38983898-38993899- WARN_CONSOLE_UNLOCKED();39003900-39013901- for (i = 0; i < 16; i++)39023902- if (set) {39033903- get_user(default_red[i], arg++);39043904- get_user(default_grn[i], arg++);39053905- get_user(default_blu[i], arg++);39063906- } else {39073907- put_user(default_red[i], arg++);39083908- put_user(default_grn[i], arg++);39093909- put_user(default_blu[i], arg++);39103910- }39113911- if (set) {39123912- for (i = 0; i < MAX_NR_CONSOLES; i++)39133913- if (vc_cons_allocated(i)) {39143914- for (j = k = 0; j < 16; j++) {39153915- vc_cons[i].d->vc_palette[k++] = default_red[j];39163916- vc_cons[i].d->vc_palette[k++] = default_grn[j];39173917- vc_cons[i].d->vc_palette[k++] = default_blu[j];39183918- }39193919- set_palette(vc_cons[i].d);39203920- }39213921- }39223922- return 0;39233923-}39243924-39253895/*39263896 * Load palette into the DAC registers. arg points to a colour39273897 * map, 3 bytes per colour, 16 colours, range from 0 to 255.···3899392939003930int con_set_cmap(unsigned char __user *arg)39013931{39023902- int rc;39323932+ int i, j, k;39333933+ unsigned char colormap[3*16];39343934+39353935+ if (copy_from_user(colormap, arg, sizeof(colormap)))39363936+ return -EFAULT;3903393739043938 console_lock();39053905- rc = set_get_cmap (arg,1);39393939+ for (i = k = 0; i < 16; i++) {39403940+ default_red[i] = colormap[k++];39413941+ default_grn[i] = colormap[k++];39423942+ default_blu[i] = colormap[k++];39433943+ }39443944+ for (i = 0; i < MAX_NR_CONSOLES; i++) {39453945+ if (!vc_cons_allocated(i))39463946+ continue;39473947+ for (j = k = 0; j < 16; j++) {39483948+ vc_cons[i].d->vc_palette[k++] = default_red[j];39493949+ vc_cons[i].d->vc_palette[k++] = default_grn[j];39503950+ vc_cons[i].d->vc_palette[k++] = default_blu[j];39513951+ }39523952+ set_palette(vc_cons[i].d);39533953+ }39063954 console_unlock();3907395539083908- return rc;39563956+ return 0;39093957}3910395839113959int con_get_cmap(unsigned char __user *arg)39123960{39133913- int rc;39613961+ int i, k;39623962+ unsigned char colormap[3*16];3914396339153964 console_lock();39163916- rc = set_get_cmap (arg,0);39653965+ for (i = k = 0; i < 16; i++) {39663966+ colormap[k++] = default_red[i];39673967+ colormap[k++] = default_grn[i];39683968+ colormap[k++] = default_blu[i];39693969+ }39173970 console_unlock();3918397139193919- return rc;39723972+ if (copy_to_user(arg, colormap, sizeof(colormap)))39733973+ return -EFAULT;39743974+39753975+ return 0;39203976}3921397739223978void reset_palette(struct vc_data *vc)
+24-27
drivers/usb/gadget/u_serial.c
···9494 * (and thus for each /dev/ node).9595 */9696struct gs_port {9797+ struct tty_port port;9798 spinlock_t port_lock; /* guard port_* access */989999100 struct gserial *port_usb;100100- struct tty_struct *port_tty;101101102102- unsigned open_count;103102 bool openclose; /* open/close in progress */104103 u8 port_num;105105-106106- wait_queue_head_t close_wait; /* wait for last close */107104108105 struct list_head read_pool;109106 int read_started;···409412 break;410413 }411414412412- if (do_tty_wake && port->port_tty)413413- tty_wakeup(port->port_tty);415415+ if (do_tty_wake && port->port.tty)416416+ tty_wakeup(port->port.tty);414417 return status;415418}416419···432435 struct tty_struct *tty;433436434437 /* no more rx if closed */435435- tty = port->port_tty;438438+ tty = port->port.tty;436439 if (!tty)437440 break;438441···485488486489 /* hand any queued data to the tty */487490 spin_lock_irq(&port->port_lock);488488- tty = port->port_tty;491491+ tty = port->port.tty;489492 while (!list_empty(queue)) {490493 struct usb_request *req;491494···696699697700 /* unblock any pending writes into our circular buffer */698701 if (started) {699699- tty_wakeup(port->port_tty);702702+ tty_wakeup(port->port.tty);700703 } else {701704 gs_free_requests(ep, head, &port->read_allocated);702705 gs_free_requests(port->port_usb->in, &port->write_pool,···731734 spin_lock_irq(&port->port_lock);732735733736 /* already open? Great. */734734- if (port->open_count) {737737+ if (port->port.count) {735738 status = 0;736736- port->open_count++;739739+ port->port.count++;737740738741 /* currently opening/closing? wait ... */739742 } else if (port->openclose) {···790793 /* REVISIT maybe wait for "carrier detect" */791794792795 tty->driver_data = port;793793- port->port_tty = tty;796796+ port->port.tty = tty;794797795795- port->open_count = 1;798798+ port->port.count = 1;796799 port->openclose = false;797800798801 /* if connected, start the I/O stream */···834837835838 spin_lock_irq(&port->port_lock);836839837837- if (port->open_count != 1) {838838- if (port->open_count == 0)840840+ if (port->port.count != 1) {841841+ if (port->port.count == 0)839842 WARN_ON(1);840843 else841841- --port->open_count;844844+ --port->port.count;842845 goto exit;843846 }844847···848851 * and sleep if necessary849852 */850853 port->openclose = true;851851- port->open_count = 0;854854+ port->port.count = 0;852855853856 gser = port->port_usb;854857 if (gser && gser->disconnect)···876879 gs_buf_clear(&port->port_write_buf);877880878881 tty->driver_data = NULL;879879- port->port_tty = NULL;882882+ port->port.tty = NULL;880883881884 port->openclose = false;882885883886 pr_debug("gs_close: ttyGS%d (%p,%p) done!\n",884887 port->port_num, tty, file);885888886886- wake_up_interruptible(&port->close_wait);889889+ wake_up_interruptible(&port->port.close_wait);887890exit:888891 spin_unlock_irq(&port->port_lock);889892}···10311034 if (port == NULL)10321035 return -ENOMEM;1033103610371037+ tty_port_init(&port->port);10341038 spin_lock_init(&port->port_lock);10351035- init_waitqueue_head(&port->close_wait);10361039 init_waitqueue_head(&port->drain_wait);1037104010381041 tasklet_init(&port->push, gs_rx_push, (unsigned long) port);···11521155 int cond;1153115611541157 spin_lock_irq(&port->port_lock);11551155- cond = (port->open_count == 0) && !port->openclose;11581158+ cond = (port->port.count == 0) && !port->openclose;11561159 spin_unlock_irq(&port->port_lock);11571160 return cond;11581161}···11911194 tasklet_kill(&port->push);1192119511931196 /* wait for old opens to finish */11941194- wait_event(port->close_wait, gs_closed(port));11971197+ wait_event(port->port.close_wait, gs_closed(port));1195119811961199 WARN_ON(port->port_usb != NULL);11971200···12651268 /* if it's already open, start I/O ... and notify the serial12661269 * protocol about open/close status (connect/disconnect).12671270 */12681268- if (port->open_count) {12711271+ if (port->port.count) {12691272 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);12701273 gs_start_io(port);12711274 if (gser->connect)···1312131513131316 port->port_usb = NULL;13141317 gser->ioport = NULL;13151315- if (port->open_count > 0 || port->openclose) {13181318+ if (port->port.count > 0 || port->openclose) {13161319 wake_up_interruptible(&port->drain_wait);13171317- if (port->port_tty)13181318- tty_hangup(port->port_tty);13201320+ if (port->port.tty)13211321+ tty_hangup(port->port.tty);13191322 }13201323 spin_unlock_irqrestore(&port->port_lock, flags);13211324···1328133113291332 /* finally, free any unused/unusable I/O buffers */13301333 spin_lock_irqsave(&port->port_lock, flags);13311331- if (port->open_count == 0 && !port->openclose)13341334+ if (port->port.count == 0 && !port->openclose)13321335 gs_buf_free(&port->port_write_buf);13331336 gs_free_requests(gser->out, &port->read_pool, NULL);13341337 gs_free_requests(gser->out, &port->read_queue, NULL);
+2-62
include/linux/generic_serial.h
···44 * Copyright (C) 1998 R.E.Wolff@BitWizard.nl55 *66 * written for the SX serial driver.77- * Contains the code that should be shared over all the serial drivers.87 *98 * Version 0.1 -- December, 1998.109 */···1112#ifndef GENERIC_SERIAL_H1213#define GENERIC_SERIAL_H13141414-#ifdef __KERNEL__1515-#include <linux/mutex.h>1616-#include <linux/tty.h>1717-1818-struct real_driver {1919- void (*disable_tx_interrupts) (void *);2020- void (*enable_tx_interrupts) (void *);2121- void (*disable_rx_interrupts) (void *);2222- void (*enable_rx_interrupts) (void *);2323- void (*shutdown_port) (void*);2424- int (*set_real_termios) (void*);2525- int (*chars_in_buffer) (void*);2626- void (*close) (void*);2727- void (*hungup) (void*);2828- void (*getserial) (void*, struct serial_struct *sp);2929-};3030-3131-3232-3333-struct gs_port {3434- int magic;3535- struct tty_port port;3636- unsigned char *xmit_buf; 3737- int xmit_head;3838- int xmit_tail;3939- int xmit_cnt;4040- struct mutex port_write_mutex;4141- unsigned long event;4242- unsigned short closing_wait;4343- int close_delay;4444- struct real_driver *rd;4545- int wakeup_chars;4646- int baud_base;4747- int baud;4848- int custom_divisor;4949- spinlock_t driver_lock;5050-};5151-5252-#endif /* __KERNEL__ */1515+#warning Use of this header is deprecated.1616+#warning Since nobody sets the constants defined here for you, you should not, in any case, use them. Including the header is thus pointless.53175418/* Flags */5519/* Warning: serial.h defines some ASYNC_ flags, they say they are "only"···2159#define GS_TX_INTEN 0x008000002260#define GS_RX_INTEN 0x004000002361#define GS_ACTIVE 0x002000002424-2525-26622763#define GS_TYPE_NORMAL 12864···3272#define GS_DEBUG_FLOW 0x000000203373#define GS_DEBUG_WRITE 0x0000004034743535-#ifdef __KERNEL__3636-int gs_put_char(struct tty_struct *tty, unsigned char ch);3737-int gs_write(struct tty_struct *tty, 3838- const unsigned char *buf, int count);3939-int gs_write_room(struct tty_struct *tty);4040-int gs_chars_in_buffer(struct tty_struct *tty);4141-void gs_flush_buffer(struct tty_struct *tty);4242-void gs_flush_chars(struct tty_struct *tty);4343-void gs_stop(struct tty_struct *tty);4444-void gs_start(struct tty_struct *tty);4545-void gs_hangup(struct tty_struct *tty);4646-int gs_block_til_ready(void *port, struct file *filp);4747-void gs_close(struct tty_struct *tty, struct file *filp);4848-void gs_set_termios (struct tty_struct * tty, 4949- struct ktermios * old_termios);5050-int gs_init_port(struct gs_port *port);5151-int gs_setserial(struct gs_port *port, struct serial_struct __user *sp);5252-int gs_getserial(struct gs_port *port, struct serial_struct __user *sp);5353-void gs_got_break(struct gs_port *port);5454-#endif /* __KERNEL__ */5575#endif
+2-24
include/linux/isdn.h
···1515#define __ISDN_H__16161717#include <linux/ioctl.h>1818+#include <linux/tty.h>18191920#define ISDN_MAX_DRIVERS 322021#define ISDN_MAX_CHANNELS 64···393392/*======================= Start of ISDN-tty stuff ===========================*/394393395394#define ISDN_ASYNC_MAGIC 0x49344C01 /* for paranoia-checking */396396-#define ISDN_ASYNC_INITIALIZED 0x80000000 /* port was initialized */397397-#define ISDN_ASYNC_CALLOUT_ACTIVE 0x40000000 /* Call out device active */398398-#define ISDN_ASYNC_NORMAL_ACTIVE 0x20000000 /* Normal device active */399399-#define ISDN_ASYNC_CLOSING 0x08000000 /* Serial port is closing */400400-#define ISDN_ASYNC_CTS_FLOW 0x04000000 /* Do CTS flow control */401401-#define ISDN_ASYNC_CHECK_CD 0x02000000 /* i.e., CLOCAL */402402-#define ISDN_ASYNC_HUP_NOTIFY 0x0001 /* Notify tty on hangups/closes */403403-#define ISDN_ASYNC_SESSION_LOCKOUT 0x0100 /* Lock cua opens on session */404404-#define ISDN_ASYNC_PGRP_LOCKOUT 0x0200 /* Lock cua opens on pgrp */405405-#define ISDN_ASYNC_CALLOUT_NOHUP 0x0400 /* No hangup for cui */406406-#define ISDN_ASYNC_SPLIT_TERMIOS 0x0008 /* Sep. termios for dialin/out */407395#define ISDN_SERIAL_XMIT_SIZE 1024 /* Default bufsize for write */408396#define ISDN_SERIAL_XMIT_MAX 4000 /* Maximum bufsize for write */409409-#define ISDN_SERIAL_TYPE_NORMAL 1410410-#define ISDN_SERIAL_TYPE_CALLOUT 2411397412398#ifdef CONFIG_ISDN_AUDIO413399/* For using sk_buffs with audio we need some private variables···436448/* Private data (similar to async_struct in <linux/serial.h>) */437449typedef struct modem_info {438450 int magic;439439- struct module *owner;440440- int flags; /* defined in tty.h */451451+ struct tty_port port;441452 int x_char; /* xon/xoff character */442453 int mcr; /* Modem control register */443454 int msr; /* Modem status register */444455 int lsr; /* Line status register */445456 int line;446446- int count; /* # of fd on device */447447- int blocked_open; /* # of blocked opens */448448- long session; /* Session of opening process */449449- long pgrp; /* pgrp of opening process */450457 int online; /* 1 = B-Channel is up, drop data */451458 /* 2 = B-Channel is up, deliver d.*/452459 int dialing; /* Dial in progress or ATA */···461478 int send_outstanding;/* # of outstanding send-requests */462479 int xmit_size; /* max. # of chars in xmit_buf */463480 int xmit_count; /* # of chars in xmit_buf */464464- unsigned char *xmit_buf; /* transmit buffer */465481 struct sk_buff_head xmit_queue; /* transmit queue */466482 atomic_t xmit_lock; /* Semaphore for isdn_tty_write */467483#ifdef CONFIG_ISDN_AUDIO···478496 struct T30_s *fax; /* T30 Fax Group 3 data/interface */479497 int faxonline; /* Fax-channel status */480498#endif481481- struct tty_struct *tty; /* Pointer to corresponding tty */482499 atemu emu; /* AT-emulator data */483483- struct ktermios normal_termios; /* For saving termios structs */484484- struct ktermios callout_termios;485485- wait_queue_head_t open_wait, close_wait;486500 spinlock_t readlock;487501} modem_info;488502
+17
include/linux/of_serial.h
···11+#ifndef __LINUX_OF_SERIAL_H22+#define __LINUX_OF_SERIAL_H33+44+/*55+ * FIXME remove this file when tegra finishes conversion to open firmware,66+ * expectation is that all quirks will then be self-contained in77+ * drivers/tty/serial/of_serial.c.88+ */99+#ifdef CONFIG_ARCH_TEGRA1010+extern void tegra_serial_handle_break(struct uart_port *port);1111+#else1212+static inline void tegra_serial_handle_break(struct uart_port *port)1313+{1414+}1515+#endif1616+1717+#endif /* __LINUX_OF_SERIAL */
+1
include/linux/serial_8250.h
···3838 int (*handle_irq)(struct uart_port *);3939 void (*pm)(struct uart_port *, unsigned int state,4040 unsigned old);4141+ void (*handle_break)(struct uart_port *);4142};42434344/*
+5
include/linux/serial_core.h
···310310 int (*handle_irq)(struct uart_port *);311311 void (*pm)(struct uart_port *, unsigned int state,312312 unsigned int old);313313+ void (*handle_break)(struct uart_port *);313314 unsigned int irq; /* irq number */314315 unsigned long irqflags; /* irq flags */315316 unsigned int uartclk; /* base uart clock */···534533static inline int uart_handle_break(struct uart_port *port)535534{536535 struct uart_state *state = port->state;536536+537537+ if (port->handle_break)538538+ port->handle_break(port);539539+537540#ifdef SUPPORT_SYSRQ538541 if (port->cons && port->cons->index == port->line) {539542 if (!port->sysrq) {
+62-71
net/bluetooth/rfcomm/tty.c
···4848static struct tty_driver *rfcomm_tty_driver;49495050struct rfcomm_dev {5151+ struct tty_port port;5152 struct list_head list;5252- atomic_t refcnt;53535454 char name[12];5555 int id;5656 unsigned long flags;5757- atomic_t opened;5857 int err;59586059 bdaddr_t src;···6364 uint modem_status;64656566 struct rfcomm_dlc *dlc;6666- struct tty_struct *tty;6767 wait_queue_head_t wait;6868- struct work_struct wakeup_task;69687069 struct device *tty_dev;7170···7982static void rfcomm_dev_state_change(struct rfcomm_dlc *dlc, int err);8083static void rfcomm_dev_modem_status(struct rfcomm_dlc *dlc, u8 v24_sig);81848282-static void rfcomm_tty_wakeup(struct work_struct *work);8383-8485/* ---- Device functions ---- */8585-static void rfcomm_dev_destruct(struct rfcomm_dev *dev)8686+8787+/*8888+ * The reason this isn't actually a race, as you no doubt have a little voice8989+ * screaming at you in your head, is that the refcount should never actually9090+ * reach zero unless the device has already been taken off the list, in9191+ * rfcomm_dev_del(). And if that's not true, we'll hit the BUG() in9292+ * rfcomm_dev_destruct() anyway.9393+ */9494+static void rfcomm_dev_destruct(struct tty_port *port)8695{9696+ struct rfcomm_dev *dev = container_of(port, struct rfcomm_dev, port);8797 struct rfcomm_dlc *dlc = dev->dlc;88988999 BT_DBG("dev %p dlc %p", dev, dlc);···117113 module_put(THIS_MODULE);118114}119115120120-static inline void rfcomm_dev_hold(struct rfcomm_dev *dev)121121-{122122- atomic_inc(&dev->refcnt);123123-}124124-125125-static inline void rfcomm_dev_put(struct rfcomm_dev *dev)126126-{127127- /* The reason this isn't actually a race, as you no128128- doubt have a little voice screaming at you in your129129- head, is that the refcount should never actually130130- reach zero unless the device has already been taken131131- off the list, in rfcomm_dev_del(). And if that's not132132- true, we'll hit the BUG() in rfcomm_dev_destruct()133133- anyway. */134134- if (atomic_dec_and_test(&dev->refcnt))135135- rfcomm_dev_destruct(dev);136136-}116116+static const struct tty_port_operations rfcomm_port_ops = {117117+ .destruct = rfcomm_dev_destruct,118118+};137119138120static struct rfcomm_dev *__rfcomm_dev_get(int id)139121{···144154 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags))145155 dev = NULL;146156 else147147- rfcomm_dev_hold(dev);157157+ tty_port_get(&dev->port);148158 }149159150160 spin_unlock(&rfcomm_dev_lock);···231241 sprintf(dev->name, "rfcomm%d", dev->id);232242233243 list_add(&dev->list, head);234234- atomic_set(&dev->refcnt, 1);235244236245 bacpy(&dev->src, &req->src);237246 bacpy(&dev->dst, &req->dst);···239250 dev->flags = req->flags &240251 ((1 << RFCOMM_RELEASE_ONHUP) | (1 << RFCOMM_REUSE_DLC));241252242242- atomic_set(&dev->opened, 0);243243-253253+ tty_port_init(&dev->port);254254+ dev->port.ops = &rfcomm_port_ops;244255 init_waitqueue_head(&dev->wait);245245- INIT_WORK(&dev->wakeup_task, rfcomm_tty_wakeup);246256247257 skb_queue_head_init(&dev->pending);248258···308320309321static void rfcomm_dev_del(struct rfcomm_dev *dev)310322{323323+ unsigned long flags;311324 BT_DBG("dev %p", dev);312325313326 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));314327315315- if (atomic_read(&dev->opened) > 0)328328+ spin_lock_irqsave(&dev->port.lock, flags);329329+ if (dev->port.count > 0) {330330+ spin_unlock_irqrestore(&dev->port.lock, flags);316331 return;332332+ }333333+ spin_unlock_irqrestore(&dev->port.lock, flags);317334318335 spin_lock(&rfcomm_dev_lock);319336 list_del_init(&dev->list);320337 spin_unlock(&rfcomm_dev_lock);321338322322- rfcomm_dev_put(dev);339339+ tty_port_put(&dev->port);323340}324341325342/* ---- Send buffer ---- */···338345static void rfcomm_wfree(struct sk_buff *skb)339346{340347 struct rfcomm_dev *dev = (void *) skb->sk;348348+ struct tty_struct *tty = dev->port.tty;341349 atomic_sub(skb->truesize, &dev->wmem_alloc);342342- if (test_bit(RFCOMM_TTY_ATTACHED, &dev->flags))343343- queue_work(system_nrt_wq, &dev->wakeup_task);344344- rfcomm_dev_put(dev);350350+ if (test_bit(RFCOMM_TTY_ATTACHED, &dev->flags) && tty)351351+ tty_wakeup(tty);352352+ tty_port_put(&dev->port);345353}346354347355static inline void rfcomm_set_owner_w(struct sk_buff *skb, struct rfcomm_dev *dev)348356{349349- rfcomm_dev_hold(dev);357357+ tty_port_get(&dev->port);350358 atomic_add(skb->truesize, &dev->wmem_alloc);351359 skb->sk = (void *) dev;352360 skb->destructor = rfcomm_wfree;···426432 return -ENODEV;427433428434 if (dev->flags != NOCAP_FLAGS && !capable(CAP_NET_ADMIN)) {429429- rfcomm_dev_put(dev);435435+ tty_port_put(&dev->port);430436 return -EPERM;431437 }432438···434440 rfcomm_dlc_close(dev->dlc, 0);435441436442 /* Shut down TTY synchronously before freeing rfcomm_dev */437437- if (dev->tty)438438- tty_vhangup(dev->tty);443443+ if (dev->port.tty)444444+ tty_vhangup(dev->port.tty);439445440446 if (!test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags))441447 rfcomm_dev_del(dev);442442- rfcomm_dev_put(dev);448448+ tty_port_put(&dev->port);443449 return 0;444450}445451···517523 if (copy_to_user(arg, &di, sizeof(di)))518524 err = -EFAULT;519525520520- rfcomm_dev_put(dev);526526+ tty_port_put(&dev->port);521527 return err;522528}523529···553559 return;554560 }555561556556- tty = dev->tty;562562+ tty = dev->port.tty;557563 if (!tty || !skb_queue_empty(&dev->pending)) {558564 skb_queue_tail(&dev->pending, skb);559565 return;···579585 wake_up_interruptible(&dev->wait);580586581587 if (dlc->state == BT_CLOSED) {582582- if (!dev->tty) {588588+ if (!dev->port.tty) {583589 if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags)) {584590 /* Drop DLC lock here to avoid deadlock585591 * 1. rfcomm_dev_get will take rfcomm_dev_lock586592 * but in rfcomm_dev_add there's lock order:587593 * rfcomm_dev_lock -> dlc lock588588- * 2. rfcomm_dev_put will deadlock if it's594594+ * 2. tty_port_put will deadlock if it's589595 * the last reference590596 */591597 rfcomm_dlc_unlock(dlc);···595601 }596602597603 rfcomm_dev_del(dev);598598- rfcomm_dev_put(dev);604604+ tty_port_put(&dev->port);599605 rfcomm_dlc_lock(dlc);600606 }601607 } else602602- tty_hangup(dev->tty);608608+ tty_hangup(dev->port.tty);603609 }604610}605611···612618 BT_DBG("dlc %p dev %p v24_sig 0x%02x", dlc, dev, v24_sig);613619614620 if ((dev->modem_status & TIOCM_CD) && !(v24_sig & RFCOMM_V24_DV)) {615615- if (dev->tty && !C_CLOCAL(dev->tty))616616- tty_hangup(dev->tty);621621+ if (dev->port.tty && !C_CLOCAL(dev->port.tty))622622+ tty_hangup(dev->port.tty);617623 }618624619625 dev->modem_status =···624630}625631626632/* ---- TTY functions ---- */627627-static void rfcomm_tty_wakeup(struct work_struct *work)628628-{629629- struct rfcomm_dev *dev = container_of(work, struct rfcomm_dev,630630- wakeup_task);631631- struct tty_struct *tty = dev->tty;632632- if (!tty)633633- return;634634-635635- BT_DBG("dev %p tty %p", dev, tty);636636- tty_wakeup(tty);637637-}638638-639633static void rfcomm_tty_copy_pending(struct rfcomm_dev *dev)640634{641641- struct tty_struct *tty = dev->tty;635635+ struct tty_struct *tty = dev->port.tty;642636 struct sk_buff *skb;643637 int inserted = 0;644638···653671 DECLARE_WAITQUEUE(wait, current);654672 struct rfcomm_dev *dev;655673 struct rfcomm_dlc *dlc;674674+ unsigned long flags;656675 int err, id;657676658677 id = tty->index;···669686 return -ENODEV;670687671688 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),672672- dev->channel, atomic_read(&dev->opened));689689+ dev->channel, dev->port.count);673690674674- if (atomic_inc_return(&dev->opened) > 1)691691+ spin_lock_irqsave(&dev->port.lock, flags);692692+ if (++dev->port.count > 1) {693693+ spin_unlock_irqrestore(&dev->port.lock, flags);675694 return 0;695695+ }696696+ spin_unlock_irqrestore(&dev->port.lock, flags);676697677698 dlc = dev->dlc;678699···684697685698 rfcomm_dlc_lock(dlc);686699 tty->driver_data = dev;687687- dev->tty = tty;700700+ dev->port.tty = tty;688701 rfcomm_dlc_unlock(dlc);689702 set_bit(RFCOMM_TTY_ATTACHED, &dev->flags);690703···731744static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)732745{733746 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;747747+ unsigned long flags;748748+734749 if (!dev)735750 return;736751737752 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,738738- atomic_read(&dev->opened));753753+ dev->port.count);739754740740- if (atomic_dec_and_test(&dev->opened)) {755755+ spin_lock_irqsave(&dev->port.lock, flags);756756+ if (!--dev->port.count) {757757+ spin_unlock_irqrestore(&dev->port.lock, flags);741758 if (dev->tty_dev->parent)742759 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);743760···749758 rfcomm_dlc_close(dev->dlc, 0);750759751760 clear_bit(RFCOMM_TTY_ATTACHED, &dev->flags);752752- cancel_work_sync(&dev->wakeup_task);753761754762 rfcomm_dlc_lock(dev->dlc);755763 tty->driver_data = NULL;756756- dev->tty = NULL;764764+ dev->port.tty = NULL;757765 rfcomm_dlc_unlock(dev->dlc);758766759767 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) {···760770 list_del_init(&dev->list);761771 spin_unlock(&rfcomm_dev_lock);762772763763- rfcomm_dev_put(dev);773773+ tty_port_put(&dev->port);764774 }765765- }775775+ } else776776+ spin_unlock_irqrestore(&dev->port.lock, flags);766777767767- rfcomm_dev_put(dev);778778+ tty_port_put(&dev->port);768779}769780770781static int rfcomm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)···10741083 if (rfcomm_dev_get(dev->id) == NULL)10751084 return;10761085 rfcomm_dev_del(dev);10771077- rfcomm_dev_put(dev);10861086+ tty_port_put(&dev->port);10781087 }10791088}10801089