Wed Oct 26 23:50:28 2022 UTC ()
ucycom(4): Convert to ttylock/ttyunlock.


(riastradh)
diff -r1.55 -r1.56 src/sys/dev/usb/ucycom.c

cvs diff -r1.55 -r1.56 src/sys/dev/usb/ucycom.c (expand / switch to unified diff)

--- src/sys/dev/usb/ucycom.c 2022/03/28 12:44:17 1.55
+++ src/sys/dev/usb/ucycom.c 2022/10/26 23:50:28 1.56
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ucycom.c,v 1.55 2022/03/28 12:44:17 riastradh Exp $ */ 1/* $NetBSD: ucycom.c,v 1.56 2022/10/26 23:50:28 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2005 The NetBSD Foundation, Inc. 4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nick Hudson 8 * by Nick Hudson
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31/* 31/*
32 * This code is based on the ucom driver. 32 * This code is based on the ucom driver.
33 */ 33 */
34 34
35/* 35/*
36 * Device driver for Cypress CY7C637xx and CY7C640/1xx series USB to 36 * Device driver for Cypress CY7C637xx and CY7C640/1xx series USB to
37 * RS232 bridges. 37 * RS232 bridges.
38 */ 38 */
39 39
40#include <sys/cdefs.h> 40#include <sys/cdefs.h>
41__KERNEL_RCSID(0, "$NetBSD: ucycom.c,v 1.55 2022/03/28 12:44:17 riastradh Exp $"); 41__KERNEL_RCSID(0, "$NetBSD: ucycom.c,v 1.56 2022/10/26 23:50:28 riastradh Exp $");
42 42
43#ifdef _KERNEL_OPT 43#ifdef _KERNEL_OPT
44#include "opt_usb.h" 44#include "opt_usb.h"
45#endif 45#endif
46 46
47#include <sys/param.h> 47#include <sys/param.h>
48#include <sys/systm.h> 48#include <sys/systm.h>
49#include <sys/conf.h> 49#include <sys/conf.h>
50#include <sys/kernel.h> 50#include <sys/kernel.h>
51#include <sys/kmem.h> 51#include <sys/kmem.h>
52#include <sys/device.h> 52#include <sys/device.h>
53#include <sys/sysctl.h> 53#include <sys/sysctl.h>
54#include <sys/tty.h> 54#include <sys/tty.h>
@@ -262,31 +262,31 @@ static int @@ -262,31 +262,31 @@ static int
262ucycom_detach(device_t self, int flags) 262ucycom_detach(device_t self, int flags)
263{ 263{
264 struct ucycom_softc *sc = device_private(self); 264 struct ucycom_softc *sc = device_private(self);
265 struct tty *tp = sc->sc_tty; 265 struct tty *tp = sc->sc_tty;
266 int maj, mn; 266 int maj, mn;
267 int s; 267 int s;
268 268
269 DPRINTF(("ucycom_detach: sc=%p flags=%d tp=%p\n", sc, flags, tp)); 269 DPRINTF(("ucycom_detach: sc=%p flags=%d tp=%p\n", sc, flags, tp));
270 270
271 sc->sc_dying = 1; 271 sc->sc_dying = 1;
272 272
273 s = splusb(); 273 s = splusb();
274 if (tp != NULL) { 274 if (tp != NULL) {
275 mutex_spin_enter(&tty_lock); 275 ttylock(tp);
276 CLR(tp->t_state, TS_CARR_ON); 276 CLR(tp->t_state, TS_CARR_ON);
277 CLR(tp->t_cflag, CLOCAL | MDMBUF); 277 CLR(tp->t_cflag, CLOCAL | MDMBUF);
278 ttyflush(tp, FREAD|FWRITE); 278 ttyflush(tp, FREAD|FWRITE);
279 mutex_spin_exit(&tty_lock); 279 ttyunlock(tp);
280 } 280 }
281 /* Wait for processes to go away. */ 281 /* Wait for processes to go away. */
282 usb_detach_waitold(sc->sc_dev); 282 usb_detach_waitold(sc->sc_dev);
283 splx(s); 283 splx(s);
284 284
285 /* locate the major number */ 285 /* locate the major number */
286 maj = cdevsw_lookup_major(&ucycom_cdevsw); 286 maj = cdevsw_lookup_major(&ucycom_cdevsw);
287 287
288 /* Nuke the vnodes for any open instances. */ 288 /* Nuke the vnodes for any open instances. */
289 mn = device_unit(self); 289 mn = device_unit(self);
290 290
291 DPRINTFN(2, ("ucycom_detach: maj=%d mn=%d\n", maj, mn)); 291 DPRINTFN(2, ("ucycom_detach: maj=%d mn=%d\n", maj, mn));
292 vdevgone(maj, mn, mn, VCHR); 292 vdevgone(maj, mn, mn, VCHR);
@@ -480,27 +480,27 @@ ucycomclose(dev_t dev, int flag, int mod @@ -480,27 +480,27 @@ ucycomclose(dev_t dev, int flag, int mod
480 480
481 return 0; 481 return 0;
482} 482}
483 483
484Static void 484Static void
485ucycomstart(struct tty *tp) 485ucycomstart(struct tty *tp)
486{ 486{
487 struct ucycom_softc *sc = 487 struct ucycom_softc *sc =
488 device_lookup_private(&ucycom_cd, UCYCOMUNIT(tp->t_dev)); 488 device_lookup_private(&ucycom_cd, UCYCOMUNIT(tp->t_dev));
489 usbd_status err __unused; 489 usbd_status err __unused;
490 u_char *data; 490 u_char *data;
491 int cnt, len, s; 491 int cnt, len, s;
492 492
493 KASSERT(mutex_owned(&tty_lock)); 493 KASSERT(ttylocked(tp));
494 494
495 if (sc->sc_dying) 495 if (sc->sc_dying)
496 return; 496 return;
497 497
498 s = spltty(); 498 s = spltty();
499 if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP)) { 499 if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP)) {
500 DPRINTFN(4,("ucycomstart: no go, state=%#x\n", tp->t_state)); 500 DPRINTFN(4,("ucycomstart: no go, state=%#x\n", tp->t_state));
501 goto out; 501 goto out;
502 } 502 }
503 503
504#if 0 504#if 0
505 /* HW FLOW CTL */ 505 /* HW FLOW CTL */
506 if (sc->sc_tx_stopped) 506 if (sc->sc_tx_stopped)