diff --git a/NetBSD/9.0/usr/src/sys/dev/sbus/sbusfpga_stat.c b/NetBSD/9.0/usr/src/sys/dev/sbus/sbusfpga_stat.c index 00be73e..c63dd02 100644 --- a/NetBSD/9.0/usr/src/sys/dev/sbus/sbusfpga_stat.c +++ b/NetBSD/9.0/usr/src/sys/dev/sbus/sbusfpga_stat.c @@ -58,7 +58,7 @@ CFATTACH_DECL_NEW(sbusfpga_stat, sizeof(struct sbusfpga_sbus_bus_stat_softc), dev_type_open(sbusfpga_stat_open); dev_type_close(sbusfpga_stat_close); - +dev_type_ioctl(sbusfpga_stat_ioctl); const struct cdevsw sbusfpga_stat_cdevsw = { @@ -66,7 +66,7 @@ const struct cdevsw sbusfpga_stat_cdevsw = { .d_close = sbusfpga_stat_close, .d_read = noread, .d_write = nowrite, - .d_ioctl = noioctl, + .d_ioctl = sbusfpga_stat_ioctl, .d_stop = nostop, .d_tty = notty, .d_poll = nopoll, @@ -187,9 +187,42 @@ sbusfpga_stat_attach(device_t parent, device_t self, void *aux) callout_init(&sc->sc_display, CALLOUT_MPSAFE); callout_setfunc(&sc->sc_display, sbusfpga_stat_display, sc); + /* disable by default */ + sc->sc_enable = 0; + /* do it once during boot*/ callout_schedule(&sc->sc_display, sc->sc_delay); } +#define SBUSFPGA_STAT_ON _IO(0, 1) +#define SBUSFPGA_STAT_OFF _IO(0, 0) + +int +sbusfpga_stat_ioctl (dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) +{ + struct sbusfpga_sbus_bus_stat_softc *sc = device_lookup_private(&sbusfpga_stat_cd, minor(dev)); + int err = 0; + + switch (cmd) { + case SBUSFPGA_STAT_ON: + if (!sc->sc_enable) { + sc->sc_enable = 1; + callout_schedule(&sc->sc_display, sc->sc_delay); + } + break; + case SBUSFPGA_STAT_OFF: + if (sc->sc_enable) { + callout_stop(&sc->sc_display); + sc->sc_enable = 0; + } + break; + default: + err = ENOTTY; + break; + } + + return err; +} + static void sbusfpga_stat_display(void *args) { struct sbusfpga_sbus_bus_stat_softc *sc = args; unsigned int c = sbus_bus_stat_stat_cycle_counter_read(sc), c2; @@ -219,5 +252,6 @@ static void sbusfpga_stat_display(void *args) { sbus_bus_stat_sbus_master_error_virtual_read(sc)); } sbus_bus_stat_stat_ctrl_write(sc, 0); - callout_schedule(&sc->sc_display, sc->sc_delay); + if (sc->sc_enable) + callout_schedule(&sc->sc_display, sc->sc_delay); } diff --git a/NetBSD/9.0/usr/src/sys/dev/sbus/sbusfpga_stat.h b/NetBSD/9.0/usr/src/sys/dev/sbus/sbusfpga_stat.h index 2ab4c48..1a6699f 100644 --- a/NetBSD/9.0/usr/src/sys/dev/sbus/sbusfpga_stat.h +++ b/NetBSD/9.0/usr/src/sys/dev/sbus/sbusfpga_stat.h @@ -39,6 +39,7 @@ struct sbusfpga_sbus_bus_stat_softc { int sc_bufsiz; /* Size of buffer */ callout_t sc_display; int sc_delay; + int sc_enable; }; #endif /* _SBUSFPGA_STAT_H_ */ diff --git a/sbus-to-ztex-gateware-migen/sbusfpga_stat_ctl.c b/sbus-to-ztex-gateware-migen/sbusfpga_stat_ctl.c new file mode 100644 index 0000000..fe9d08b --- /dev/null +++ b/sbus-to-ztex-gateware-migen/sbusfpga_stat_ctl.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#define SBUSFPGA_STAT_ON _IO(0, 1) +#define SBUSFPGA_STAT_OFF _IO(0, 0) + +int main(int argc, char **argv) { + const char const * device = "/dev/sbusfpga_stat0"; + int devfd; + int onoff; + + if (argc != 2) { + fprintf(stderr, "Usage: %s on|off\n", argv[0]); + return -1; + } + + if (strncmp("on", argv[1], 2) == 0) { + onoff = 1; + } else if (strncmp("off", argv[1], 3) == 0) { + onoff = 0; + } else { + fprintf(stderr, "Usage: %s on|off\n", argv[0]); + return -1; + } + + if ( (devfd = open(device, O_RDWR)) == -1) { + perror("can't open device file"); + return -1; + } + + switch (onoff) { + case 0: + if (ioctl(devfd, SBUSFPGA_STAT_OFF, NULL)) { + perror("Turning statistics off failed."); + close(devfd); + return -1; + } + break; + case 1: + if (ioctl(devfd, SBUSFPGA_STAT_ON, NULL)) { + perror("Turning statistics on failed."); + close(devfd); + return -1; + } + break; + } + + return 0; +}