diff options
author | 2015-12-27 20:42:33 +0000 | |
---|---|---|
committer | 2015-12-27 20:42:33 +0000 | |
commit | fa0b85b6f7b5093f56ef3a6252e801c0689acc0f (patch) | |
tree | eec0506af9d1c298324f8010c810ae10360b4faa | |
parent | Use 'standard' gpt_chk_mbr() to check for protective MBR. (diff) | |
download | wireguard-openbsd-fa0b85b6f7b5093f56ef3a6252e801c0689acc0f.tar.xz wireguard-openbsd-fa0b85b6f7b5093f56ef3a6252e801c0689acc0f.zip |
fold for loops back into a wait function in a similar manner as acpiec does
-rw-r--r-- | sys/dev/isa/asmc.c | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/sys/dev/isa/asmc.c b/sys/dev/isa/asmc.c index c84f3d5b519..5117bd772c6 100644 --- a/sys/dev/isa/asmc.c +++ b/sys/dev/isa/asmc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asmc.c,v 1.26 2015/12/27 20:26:55 jung Exp $ */ +/* $OpenBSD: asmc.c,v 1.27 2015/12/27 20:42:33 jung Exp $ */ /* * Copyright (c) 2015 Joerg Jung <jung@openbsd.org> * @@ -405,49 +405,35 @@ asmc_status(struct asmc_softc *sc) } static int -asmc_write(struct asmc_softc *sc, uint8_t off, uint8_t val) +asmc_wait(struct asmc_softc *sc, uint8_t mask, uint8_t val) { - uint8_t str; int i; - for (i = 500; i > 0; i--) { - str = bus_space_read_1(sc->sc_iot, sc->sc_ioh, ASMC_COMMAND); - if ((str & ASMC_IBF) == 0) - break; + for (i = 0; i < 500; i++) { /* wait up to 5 ms */ + if ((bus_space_read_1(sc->sc_iot, sc->sc_ioh, ASMC_COMMAND) & + mask) == val) + return 0; delay(10); } - if (i == 0) - return ETIMEDOUT; + return ETIMEDOUT; +} +static int +asmc_write(struct asmc_softc *sc, uint8_t off, uint8_t val) +{ + if (asmc_wait(sc, ASMC_IBF, 0)) + return 1; bus_space_write_1(sc->sc_iot, sc->sc_ioh, off, val); - - for (i = 500; i > 0; i--) { - str = bus_space_read_1(sc->sc_iot, sc->sc_ioh, ASMC_COMMAND); - if (str & ASMC_ACCEPT) - break; - delay(10); - } - if (i == 0) - return ETIMEDOUT; - + if (asmc_wait(sc, ASMC_ACCEPT, ASMC_ACCEPT)) + return 1; return 0; } static int asmc_read(struct asmc_softc *sc, uint8_t off, uint8_t *buf) { - uint8_t str; - int i; - - for (i = 500; i > 0; i--) { - str = bus_space_read_1(sc->sc_iot, sc->sc_ioh, ASMC_COMMAND); - if (str & ASMC_OBF) - break; - delay(10); - } - if (i == 0) - return ETIMEDOUT; - + if (asmc_wait(sc, ASMC_OBF, ASMC_OBF)) + return 1; *buf = bus_space_read_1(sc->sc_iot, sc->sc_ioh, off); return 0; } |