From 0823162211c1f13342183bcbfe322638e9a0e8d3 Mon Sep 17 00:00:00 2001 From: kettenis Date: Fri, 12 Nov 2021 17:04:32 +0000 Subject: [PATCH] Use a mutex to lock the bus such that we can safely access the bus from interrupt handlers and process context. ok patrick@ --- sys/arch/arm64/dev/aplspi.c | 13 +++++++++++-- 1 file 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 * @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include @@ -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 -- 2.20.1