From: kettenis Date: Sat, 3 Sep 2022 15:29:43 +0000 (+0000) Subject: Allow suspend with root on sdmmc(4). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=3119f858d97ff996617c24554c4c4f6a0a47ac0c;p=openbsd Allow suspend with root on sdmmc(4). ok deraadt@ --- diff --git a/sys/dev/sdmmc/sdmmc.c b/sys/dev/sdmmc/sdmmc.c index 16225fcde3c..751e9d15021 100644 --- a/sys/dev/sdmmc/sdmmc.c +++ b/sys/dev/sdmmc/sdmmc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sdmmc.c,v 1.59 2022/04/06 18:59:30 naddy Exp $ */ +/* $OpenBSD: sdmmc.c,v 1.60 2022/09/03 15:29:43 kettenis Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler @@ -56,6 +56,7 @@ void sdmmc_attach(struct device *, struct device *, void *); int sdmmc_detach(struct device *, int); int sdmmc_activate(struct device *, int); +int sdmmc_holds_root_device(struct sdmmc_softc *); void sdmmc_create_thread(void *); void sdmmc_task_thread(void *); void sdmmc_discover_task(void *); @@ -195,7 +196,8 @@ sdmmc_activate(struct device *self, int act) rv = config_activate_children(self, act); /* If card in slot, cause a detach/re-attach */ if (ISSET(sc->sc_flags, SMF_CARD_PRESENT) && - !ISSET(sc->sc_caps, SMC_CAPS_NONREMOVABLE)) + !ISSET(sc->sc_caps, SMC_CAPS_NONREMOVABLE) && + !sdmmc_holds_root_device(sc)) sc->sc_dying = -1; break; case DVACT_RESUME: @@ -209,6 +211,16 @@ sdmmc_activate(struct device *self, int act) return (rv); } +int +sdmmc_holds_root_device(struct sdmmc_softc *sc) +{ + if (rootdv && rootdv->dv_parent && + rootdv->dv_parent->dv_parent == &sc->sc_dev) + return 1; + + return 0; +} + void sdmmc_create_thread(void *arg) { diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index 71eb77c0000..b35cbb4e052 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.259 2022/09/02 20:06:56 miod Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.260 2022/09/03 15:29:43 kettenis Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -88,6 +88,8 @@ int disk_change; /* set if a disk has been attached/detached u_char bootduid[DUID_SIZE]; /* DUID of boot disk. */ u_char rootduid[DUID_SIZE]; /* DUID of root disk. */ +struct device *rootdv; + /* softraid callback, do not use! */ void (*softraid_disk_attach)(struct disk *, int); @@ -1407,7 +1409,7 @@ setroot(struct device *bootdv, int part, int exitflags) { int majdev, unit, len, s, slept = 0; struct swdevt *swp; - struct device *rootdv, *dv; + struct device *dv; dev_t nrootdev, nswapdev = NODEV, temp = NODEV; struct ifnet *ifp = NULL; struct disk *dk; diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 828812e3dd3..75c99a6dd9b 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: systm.h,v 1.158 2022/08/06 15:57:59 bluhm Exp $ */ +/* $OpenBSD: systm.h,v 1.159 2022/09/03 15:29:44 kettenis Exp $ */ /* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */ /*- @@ -101,6 +101,7 @@ extern dev_t rootdev; /* root device */ extern u_char bootduid[8]; /* boot device disklabel uid */ extern u_char rootduid[8]; /* root device disklabel uid */ extern struct vnode *rootvp; /* vnode equivalent to above */ +extern struct device *rootdv; /* device equivalent to above */ extern dev_t swapdev; /* swapping device */ extern struct vnode *swapdev_vp;/* vnode equivalent to above */