diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2021-11-12 17:04:33 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2021-11-12 17:04:33 +0000 |
commit | 9d96881373a5865feaf23cd5579a941c31821ee3 (patch) | |
tree | 588e5f60aef8f575715d22c552ae4a52c74b0752 /sys | |
parent | b9fa254fd71f7feea50d48bb91a856a516a5f8fc (diff) |
Use a mutex to lock the bus such that we can safely access the bus from
interrupt handlers and process context.
ok patrick@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/arm64/dev/aplspi.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/sys/arch/arm64/dev/aplspi.c b/sys/arch/arm64/dev/aplspi.c index a9075636087..4bd1483adce 100644 --- a/sys/arch/arm64/dev/aplspi.c +++ b/sys/arch/arm64/dev/aplspi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aplspi.c,v 1.1 2021/10/31 16:38:12 kettenis Exp $ */ +/* $OpenBSD: aplspi.c,v 1.2 2021/11/12 17:04:32 kettenis Exp $ */ /* * Copyright (c) 2021 Mark Kettenis <kettenis@openbsd.org> * @@ -20,7 +20,7 @@ #include <sys/kernel.h> #include <sys/device.h> #include <sys/malloc.h> -#include <sys/stdint.h> +#include <sys/mutex.h> #include <machine/bus.h> #include <machine/fdt.h> @@ -63,6 +63,7 @@ struct aplspi_softc { uint32_t sc_pfreq; struct spi_controller sc_tag; + struct mutex sc_mtx; int sc_cs; uint32_t *sc_csgpio; @@ -145,6 +146,8 @@ aplspi_attach(struct device *parent, struct device *self, void *aux) sc->sc_tag.sc_acquire_bus = aplspi_acquire_bus; sc->sc_tag.sc_release_bus = aplspi_release_bus; + mtx_init(&sc->sc_mtx, IPL_TTY); + aplspi_scan(sc); } @@ -245,12 +248,18 @@ aplspi_transfer(void *cookie, char *out, char *in, int len, int flags) int aplspi_acquire_bus(void *cookie, int flags) { + struct aplspi_softc *sc = cookie; + + mtx_enter(&sc->sc_mtx); return 0; } void aplspi_release_bus(void *cookie, int flags) { + struct aplspi_softc *sc = cookie; + + mtx_leave(&sc->sc_mtx); } void |