/*
 * DF-0003 CONTROL module -- the valid-unit counterpart to poc_negunit.c.
 *
 * Calls device_add_child(root_bus, "df3ctrl", 0): a non-negative unit takes
 * the normal newbus path (devclass_alloc_unit extends dc->devices and the
 * store dc->devices[0]=dev is in-bounds).  This module MUST load cleanly and
 * print its marker -- proving the trigger panic is caused specifically by the
 * negative unit, not by the module infrastructure.
 */
#include <sys/param.h>
#include <sys/module.h>
#include <sys/kernel.h>
#include <sys/systm.h>

struct bsd_device;
typedef struct bsd_device *device_t;
extern device_t root_bus;
extern device_t device_add_child(device_t, const char *, int);

static int
ctrl_modev(module_t m, int what, void *arg)
{
	device_t child;
	(void)m; (void)arg;

	if (what == MOD_LOAD) {
		child = device_add_child(root_bus, "df3ctrl", 0);
		kprintf("DF0003-CTRL: unit=0 -> %s (child=%p)  [valid unit: no crash]\n",
		    child ? "OK" : "FAIL", child);
	}
	return 0;
}

static moduledata_t ctrl_mod = { "poc_ctrl", ctrl_modev, 0 };
DECLARE_MODULE(poc_ctrl, ctrl_mod, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE);
MODULE_VERSION(poc_ctrl, 1);
