/* bisect step 2: msix alloc/map/release round trip only (count=1, no
 * count=64 path) -- legal per the ABI contract. */
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/systm.h>
#include <sys/machintr.h>

extern struct machintr_abi MachIntrABI_IOAPIC;

static int
nocrash_modevent(module_t mod __unused, int type, void *data __unused)
{
	uint64_t addr;
	uint32_t mdata;
	int irq = -1, rc;

	switch (type) {
	case MOD_LOAD:
		kprintf("probe_nocrash: loaded\n");
		rc = MachIntrABI_IOAPIC.msix_alloc(&irq, 0);
		kprintf("probe_nocrash: msix_alloc rc=%d irq=%d\n", rc, irq);
		if (rc == 0) {
			MachIntrABI_IOAPIC.msi_map(irq, &addr, &mdata, 0);
			kprintf("probe_nocrash: msi_map addr=0x%llx data=0x%x\n",
			    (unsigned long long)addr, mdata);
			MachIntrABI_IOAPIC.msix_release(irq, 0);
			kprintf("probe_nocrash: msix_release done\n");
		}
		return 0;
	case MOD_UNLOAD:
		return 0;
	default:
		return EOPNOTSUPP;
	}
}
static moduledata_t probe_nocrash_mod = { "probe_nocrash", nocrash_modevent, NULL };
DECLARE_MODULE(probe_nocrash, probe_nocrash_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
