From 2e6662efc3ecfb1f7255046a4ba6166b56b49f7b Mon Sep 17 00:00:00 2001 From: tnn Date: Thu, 5 Aug 2021 22:31:20 +0000 Subject: [PATCH] ssdfb: revert rev 1.14 Can't run the worker thread MPSAFE with spi(4) yet because most controller drivers still lack MP safety. Cause issues when using multiple displays. --- sys/dev/i2c/ssdfb_i2c.c | 5 +++-- sys/dev/ic/ssdfb.c | 17 +++++++++++------ sys/dev/ic/ssdfbvar.h | 3 ++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/sys/dev/i2c/ssdfb_i2c.c b/sys/dev/i2c/ssdfb_i2c.c index f05bb1462d22..90d4ba76ed60 100644 --- a/sys/dev/i2c/ssdfb_i2c.c +++ b/sys/dev/i2c/ssdfb_i2c.c @@ -1,4 +1,4 @@ -/* $NetBSD: ssdfb_i2c.c,v 1.10 2021/07/30 13:44:09 tnn Exp $ */ +/* $NetBSD: ssdfb_i2c.c,v 1.11 2021/08/05 22:31:20 tnn Exp $ */ /* * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ssdfb_i2c.c,v 1.10 2021/07/30 13:44:09 tnn Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ssdfb_i2c.c,v 1.11 2021/08/05 22:31:20 tnn Exp $"); #include #include @@ -112,6 +112,7 @@ ssdfb_i2c_attach(device_t parent, device_t self, void *aux) if ((flags & SSDFB_ATTACH_FLAG_PRODUCT_MASK) == SSDFB_PRODUCT_UNKNOWN) flags |= SSDFB_PRODUCT_SSD1306_GENERIC; + flags |= SSDFB_ATTACH_FLAG_MPSAFE; sc->sc.sc_dev = self; sc->sc_i2c_tag = ia->ia_tag; sc->sc_i2c_addr = ia->ia_addr; diff --git a/sys/dev/ic/ssdfb.c b/sys/dev/ic/ssdfb.c index 0bfcd881c159..e172889daf8c 100644 --- a/sys/dev/ic/ssdfb.c +++ b/sys/dev/ic/ssdfb.c @@ -1,4 +1,4 @@ -/* $NetBSD: ssdfb.c,v 1.18 2021/08/05 19:07:09 tnn Exp $ */ +/* $NetBSD: ssdfb.c,v 1.19 2021/08/05 22:31:20 tnn Exp $ */ /* * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ssdfb.c,v 1.18 2021/08/05 19:07:09 tnn Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ssdfb.c,v 1.19 2021/08/05 22:31:20 tnn Exp $"); #include "opt_ddb.h" @@ -268,6 +268,7 @@ ssdfb_attach(struct ssdfb_softc *sc, int flags) int error = 0; long defattr; const struct ssdfb_product *p; + int kt_flags; p = ssdfb_lookup_product(flags & SSDFB_ATTACH_FLAG_PRODUCT_MASK); if (p == NULL) { @@ -393,11 +394,15 @@ ssdfb_attach(struct ssdfb_softc *sc, int flags) if (sc->sc_is_console) ssdfb_set_usepoll(sc, true); - mutex_init(&sc->sc_cond_mtx, MUTEX_DEFAULT, IPL_SCHED); + mutex_init(&sc->sc_cond_mtx, MUTEX_DEFAULT, + ISSET(flags, SSDFB_ATTACH_FLAG_MPSAFE) ? IPL_SCHED : IPL_BIO); cv_init(&sc->sc_cond, "ssdfb"); - error = kthread_create(PRI_SOFTCLOCK, KTHREAD_MUSTJOIN | KTHREAD_MPSAFE, - NULL, ssdfb_thread, sc, &sc->sc_thread, "%s", - device_xname(sc->sc_dev)); + kt_flags = KTHREAD_MUSTJOIN; + /* XXX spi(4) is not MPSAFE yet. */ + if (ISSET(flags, SSDFB_ATTACH_FLAG_MPSAFE)) + kt_flags |= KTHREAD_MPSAFE; + error = kthread_create(PRI_SOFTCLOCK, kt_flags, NULL, ssdfb_thread, sc, + &sc->sc_thread, "%s", device_xname(sc->sc_dev)); if (error) { cv_destroy(&sc->sc_cond); mutex_destroy(&sc->sc_cond_mtx); diff --git a/sys/dev/ic/ssdfbvar.h b/sys/dev/ic/ssdfbvar.h index 9d5f244f9a9a..c37740fbc147 100644 --- a/sys/dev/ic/ssdfbvar.h +++ b/sys/dev/ic/ssdfbvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: ssdfbvar.h,v 1.9 2021/08/05 19:07:09 tnn Exp $ */ +/* $NetBSD: ssdfbvar.h,v 1.10 2021/08/05 22:31:20 tnn Exp $ */ /* * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -36,6 +36,7 @@ #define SSDFB_ATTACH_FLAG_UPSIDEDOWN 0x00000100 #define SSDFB_ATTACH_FLAG_INVERSE 0x00000200 #define SSDFB_ATTACH_FLAG_CONSOLE 0x00000400 +#define SSDFB_ATTACH_FLAG_MPSAFE 0x00000800 /* * Fundamental commands