Index: sys/conf/options =================================================================== --- sys/conf/options +++ sys/conf/options @@ -178,6 +178,7 @@ NO_ADAPTIVE_RWLOCKS NO_ADAPTIVE_SX NO_EVENTTIMERS opt_timer.h +NO_OBSOLETE_CODE opt_global.h NO_SYSCTL_DESCR opt_global.h NSWBUF_MIN opt_swap.h MBUF_PACKET_ZONE_DISABLE opt_global.h Index: sys/dev/advansys/advansys.c =================================================================== --- sys/dev/advansys/advansys.c +++ sys/dev/advansys/advansys.c @@ -1399,6 +1399,8 @@ csa.callback_arg = adv; xpt_action((union ccb *)&csa); mtx_unlock(&adv->lock); + gone_in_dev(adv->adv, 12, "adv(4) driver"); + return (0); } MODULE_DEPEND(adv, cam, 1, 1, 1); Index: sys/dev/advansys/adwcam.c =================================================================== --- sys/dev/advansys/adwcam.c +++ sys/dev/advansys/adwcam.c @@ -1173,6 +1173,7 @@ xpt_action((union ccb *)&csa); } + gone_in_dev(adv->adv, 12, "adw(4) driver"); fail: mtx_unlock(&adw->lock); return (error); Index: sys/dev/aha/aha.c =================================================================== --- sys/dev/aha/aha.c +++ sys/dev/aha/aha.c @@ -620,6 +620,7 @@ return (ENXIO); } mtx_unlock(&aha->lock); + gone_in_dev(aha->dev, 12, "aha(4) driver"); return (0); } Index: sys/dev/aic/aic.c =================================================================== --- sys/dev/aic/aic.c +++ sys/dev/aic/aic.c @@ -1577,6 +1577,7 @@ printf(", fast SCSI"); printf("\n"); mtx_unlock(&aic->lock); + gone_in_dev(aic->dev, 12, "aic(4) driver"); return (0); } Index: sys/dev/buslogic/bt.c =================================================================== --- sys/dev/buslogic/bt.c +++ sys/dev/buslogic/bt.c @@ -905,6 +905,7 @@ device_printf(dev, "bus_setup_intr() failed: %d\n", error); return (error); } + gone_in_dev(dev, 12, "bt(4) driver"); return (0); } Index: sys/dev/dpt/dpt_pci.c =================================================================== --- sys/dev/dpt/dpt_pci.c +++ sys/dev/dpt/dpt_pci.c @@ -157,6 +157,7 @@ error = ENXIO; goto bad; } + gone_in_dev(dev, 12, "dpt(4) driver"); return (error); Index: sys/dev/joy/joy.c =================================================================== --- sys/dev/joy/joy.c +++ sys/dev/joy/joy.c @@ -110,6 +110,8 @@ joy->timeout[0] = joy->timeout[1] = 0; joy->d = make_dev(&joy_cdevsw, unit, 0, 0, 0600, "joy%d", unit); joy->d->si_drv1 = joy; + gone_in_dev(dev, 12, "joy(4) driver"); + return (0); } Index: sys/dev/mse/mse.c =================================================================== --- sys/dev/mse/mse.c +++ sys/dev/mse/mse.c @@ -153,6 +153,8 @@ sc->sc_ndev = make_dev(&mse_cdevsw, 1, UID_ROOT, GID_WHEEL, 0600, "nmse%d", unit); sc->sc_ndev->si_drv1 = sc; + gone_in_dev(dev, 12, "mse(4) driver"); + return 0; } Index: sys/dev/ncv/ncr53c500_pccard.c =================================================================== --- sys/dev/ncv/ncr53c500_pccard.c +++ sys/dev/ncv/ncr53c500_pccard.c @@ -263,6 +263,7 @@ ncv_release_resource(dev); return(ENXIO); } + gone_in_dev(dev, 12, "ncv(4) driver"); return(0); } Index: sys/dev/nsp/nsp_pccard.c =================================================================== --- sys/dev/nsp/nsp_pccard.c +++ sys/dev/nsp/nsp_pccard.c @@ -205,6 +205,7 @@ nsp_release_resource(dev); return(ENXIO); } + gone_in_dev(dev, 12, "nsp(4) driver"); return(0); } Index: sys/dev/stg/tmc18c30.c =================================================================== --- sys/dev/stg/tmc18c30.c +++ sys/dev/stg/tmc18c30.c @@ -423,6 +423,7 @@ (void) scsi_low_attach(slp, 0, STG_NTARGETS, STG_NLUNS, sizeof(struct stg_targ_info), 0); + gone_in(12, "stg(4) driver"); } /************************************************************** Index: sys/kern/subr_bus.c =================================================================== --- sys/kern/subr_bus.c +++ sys/kern/subr_bus.c @@ -5604,6 +5604,54 @@ UID_ROOT, GID_WHEEL, 0600, "devctl2"); } +/* + * Obsolete management stuff. + */ +static int obsolete_panic = 0; +/* 0 - don't panic, 1 - panic if already obsolete, 2 - panic if deprecated */ +static void +gone_panic(int major, int running, const char *msg) +{ + + switch (obsolete_panic) + { + case 0: + return; + case 1: + if (running < major) + return; + /* FALLTHROUGH */ + default: + panic("%s", msg); + } +} + +void +_gone_in(int major, const char *msg) +{ + + gone_panic(major, P_OSREL_MAJOR(__FreeBSD_version), msg); + if (P_OSREL_MAJOR(__FreeBSD_version) >= major) + printf("Obsolete code will removed soon: %s\n", msg); + else if (P_OSREL_MAJOR(__FreeBSD_version) + 1 == major) + printf("Deprecated code (to be removed in FreeBSD %d): %s\n", + major, msg); +} + +void +_gone_in_dev(device_t dev, int major, const char *msg) +{ + + gone_panic(major, P_OSREL_MAJOR(__FreeBSD_version), msg); + if (P_OSREL_MAJOR(__FreeBSD_version) >= major) + device_printf(dev, + "Obsolete code will removed soon: %s\n", msg); + else if (P_OSREL_MAJOR(__FreeBSD_version) + 1 == major) + device_printf(dev, + "Deprecated code (to be removed in FreeBSD %d): %s\n", + major, msg); +} + #ifdef DDB DB_SHOW_COMMAND(device, db_show_device) { Index: sys/sys/systm.h =================================================================== --- sys/sys/systm.h +++ sys/sys/systm.h @@ -464,6 +464,22 @@ void counted_warning(unsigned *counter, const char *msg); +/* + * APIs to manage deprecation and obsolescence. + */ +struct device; +void _gone_in(int major, const char *msg); +void _gone_in_dev(struct device *dev, int major, const char *msg); +#ifdef NO_OBSOLETE_CODE +#define __gone_ok(m, msg) \ + _Static_assert(m < P_OSREL_MAJOR(__FreeBSD_version)), \ + "Obsolete code" msg); +#else +#define __gone_ok(m, msg) +#endif +#define gone_in(major, msg) __gone_ok(major, msg) _gone_in(major, msg) +#define gone_in_dev(dev, major, msg) __gone_ok(major, msg) _gone_in_dev(dev, major, msg) + __NULLABILITY_PRAGMA_POP #endif /* !_SYS_SYSTM_H_ */