Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/spi Use mutex for lwp/interrupt coordination. using ...
details: https://anonhg.NetBSD.org/src/rev/5f4d502b7955
branches: trunk
changeset: 937001:5f4d502b7955
user: kardel <kardel%NetBSD.org@localhost>
date: Tue Aug 04 13:20:45 2020 +0000
description:
Use mutex for lwp/interrupt coordination. using splX() simply does not work
on multiprocessor systems.
fixes PR kern/55506
diffstat:
sys/arch/arm/broadcom/bcm2835_spi.c | 17 ++++++++++-------
sys/dev/spi/spi.c | 8 ++++----
sys/dev/spi/spivar.h | 4 ++--
3 files changed, 16 insertions(+), 13 deletions(-)
diffs (136 lines):
diff -r 19003a0a980e -r 5f4d502b7955 sys/arch/arm/broadcom/bcm2835_spi.c
--- a/sys/arch/arm/broadcom/bcm2835_spi.c Tue Aug 04 06:23:46 2020 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_spi.c Tue Aug 04 13:20:45 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcm2835_spi.c,v 1.6 2019/08/13 17:03:10 tnn Exp $ */
+/* $NetBSD: bcm2835_spi.c,v 1.7 2020/08/04 13:20:45 kardel Exp $ */
/*
* Copyright (c) 2012 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_spi.c,v 1.6 2019/08/13 17:03:10 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_spi.c,v 1.7 2020/08/04 13:20:45 kardel Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -53,6 +53,7 @@
bus_space_handle_t sc_ioh;
void *sc_intrh;
struct spi_controller sc_spi;
+ kmutex_t sc_mutex;
SIMPLEQ_HEAD(,spi_transfer) sc_q;
struct spi_transfer *sc_transfer;
struct spi_chunk *sc_wchunk;
@@ -131,6 +132,7 @@
aprint_normal_dev(self, "interrupting on %s\n", intrstr);
sc->sc_spi.sct_cookie = sc;
+ mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_VM);
sc->sc_spi.sct_configure = bcmspi_configure;
sc->sc_spi.sct_transfer = bcmspi_transfer;
sc->sc_spi.sct_nslaves = 3;
@@ -189,14 +191,13 @@
bcmspi_transfer(void *cookie, struct spi_transfer *st)
{
struct bcmspi_softc * const sc = cookie;
- int s;
- s = splbio();
+ mutex_enter(&sc->sc_mutex);
spi_transq_enqueue(&sc->sc_q, st);
if (sc->sc_running == false) {
bcmspi_start(sc);
}
- splx(s);
+ mutex_exit(&sc->sc_mutex);
return 0;
}
@@ -226,13 +227,13 @@
if (!cold)
return;
- int s = splbio();
for (;;) {
+ mutex_exit(&sc->sc_mutex);
bcmspi_intr(sc);
+ mutex_enter(&sc->sc_mutex);
if (ISSET(st->st_flags, SPI_F_DONE))
break;
}
- splx(s);
}
sc->sc_running = false;
@@ -291,6 +292,7 @@
struct spi_transfer *st;
uint32_t cs;
+ mutex_enter(&sc->sc_mutex);
cs = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SPI_CS);
if (ISSET(cs, SPI_CS_DONE)) {
if (sc->sc_wchunk != NULL) {
@@ -314,5 +316,6 @@
}
end:
+ mutex_exit(&sc->sc_mutex);
return ISSET(cs, SPI_CS_DONE|SPI_CS_RXR);
}
diff -r 19003a0a980e -r 5f4d502b7955 sys/dev/spi/spi.c
--- a/sys/dev/spi/spi.c Tue Aug 04 06:23:46 2020 +0000
+++ b/sys/dev/spi/spi.c Tue Aug 04 13:20:45 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: spi.c,v 1.14 2020/06/11 02:39:30 thorpej Exp $ */
+/* $NetBSD: spi.c,v 1.15 2020/08/04 13:20:45 kardel Exp $ */
/*-
* Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.14 2020/06/11 02:39:30 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.15 2020/08/04 13:20:45 kardel Exp $");
#include "locators.h"
@@ -287,7 +287,7 @@
aprint_naive(": SPI bus\n");
aprint_normal(": SPI bus\n");
- mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_BIO);
+ mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_VM);
cv_init(&sc->sc_cv, "spictl");
sc->sc_controller = *sba->sba_controller;
@@ -463,7 +463,7 @@
spi_transfer_init(struct spi_transfer *st)
{
- mutex_init(&st->st_lock, MUTEX_DEFAULT, IPL_BIO);
+ mutex_init(&st->st_lock, MUTEX_DEFAULT, IPL_VM);
cv_init(&st->st_cv, "spixfr");
st->st_flags = 0;
diff -r 19003a0a980e -r 5f4d502b7955 sys/dev/spi/spivar.h
--- a/sys/dev/spi/spivar.h Tue Aug 04 06:23:46 2020 +0000
+++ b/sys/dev/spi/spivar.h Tue Aug 04 13:20:45 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: spivar.h,v 1.9 2019/11/27 07:26:08 hkenken Exp $ */
+/* $NetBSD: spivar.h,v 1.10 2020/08/04 13:20:45 kardel Exp $ */
/*-
* Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -111,7 +111,7 @@
struct spi_transfer {
struct spi_chunk *st_chunks; /* chained bufs */
SIMPLEQ_ENTRY(spi_transfer) st_chain; /* chain of submitted jobs */
- int st_flags;
+ volatile int st_flags;
int st_errno;
int st_slave;
void *st_private;
Home |
Main Index |
Thread Index |
Old Index