/*
 * maestro_probe.c - environment probe for DF-4156 / DF-4157.
 *
 * Both findings live in sys/dev/sound/pci/maestro.c and require an
 * ESS Maestro-1/2/2E PCI audio function (PCI IDs 0x01001285 / 0x1968125d /
 * 0x1978125d) to be attached as pcmN. This probe documents, on the live
 * guest, whether that precondition exists (it does not on the audit guest),
 * and would otherwise be the entry point for the triggers:
 *
 *   DF-4156: open /dev/mixerN (0666) and issue SOUND_MIXER_WRITE_VOLUME;
 *            the trigger precondition is an agg_attach() that failed in
 *            pcm_register() AFTER mixer_init() succeeded (boot-time
 *            anomaly: pcm_veto_load stuck at 1, or unit > PCMMAXUNIT).
 *   DF-4157: open /dev/dspN O_RDONLY, set AFMT_S16_LE/stereo/8000Hz,
 *            read() in a loop (forces PCMTRIG_START/EMLDMARD feeds)
 *            while the machine suspends/resumes (agg_power D3 walk races
 *            the lockless ess->curpwr check in agg_intr()).
 */
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>

int
main(void)
{
	static const char *ds[] = {"/dev/dsp0", "/dev/dsp", "/dev/mixer0",
				   "/dev/mixer", NULL};
	int i, fd;

	for (i = 0; ds[i]; i++) {
		fd = open(ds[i], O_RDONLY);
		if (fd >= 0) {
			printf("%s: OPENABLE - pcm audio present\n", ds[i]);
			close(fd);
		} else {
			printf("%s: %s\n", ds[i], strerror(errno));
		}
	}
	printf("check pciconf for 0x125d:1968 / 0x125d:1978 / 0x1285:0100\n");
	return (0);
}
