static u_int abtn_receive_packet(device_t dev, u_char status, u_char command, u_char reg, int len, u_char *data) { u_int cmd; cmd = data[0]; switch (cmd) { case 0x0a: /* decrease brightness */ if (devctl_process_running()) devctl_notify("PMU", "keys", "brightness", "notify=down"); break; case 0x09: /* increase brightness */ if (devctl_process_running()) devctl_notify("PMU", "keys", "brightness", "notify=up"); break; case 0x08: /* mute */ case 0x01: /* mute, AV hardware */ if (devctl_process_running()) devctl_notify("PMU", "keys", "mute", NULL); break; case 0x07: /* decrease volume */ case 0x02: /* decrease volume, AV hardware */ if (devctl_process_running()) devctl_notify("PMU", "keys", "volume", "notify=down"); break; case 0x06: /* increase volume */ case 0x03: /* increase volume, AV hardware */ if (devctl_process_running()) devctl_notify("PMU", "keys", "volume", "notify=up"); break; case 0x0c: /* mirror display key */ /* Need callback to do something with this */ break; case 0x0b: /* eject tray */ if (devctl_process_running()) devctl_notify("PMU", "keys", "eject", NULL); case 0x7f: /* numlock */ /* Need callback to do something with this */ break; default: #ifdef DEBUG if ((cmd & ~0x7f) == 0) device_printf(dev, "unknown ADB button 0x%x\n", cmd); #endif break; } return 0; }
static int sysctl_hostname(SYSCTL_HANDLER_ARGS) { struct prison *pr, *cpr; size_t pr_offset; char tmpname[MAXHOSTNAMELEN]; char buf[MAXHOSTNAMELEN + 16]; int descend, error, len; /* * This function can set: hostname domainname hostuuid. * Keep that in mind when comments say "hostname". */ pr_offset = (size_t)arg1; len = arg2; KASSERT(len <= sizeof(tmpname), ("length %d too long for %s", len, __func__)); pr = req->td->td_ucred->cr_prison; if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr) return (EPERM); /* * Make a local copy of hostname to get/set so we don't have to hold * the jail mutex during the sysctl copyin/copyout activities. */ mtx_lock(&pr->pr_mtx); bcopy((char *)pr + pr_offset, tmpname, len); mtx_unlock(&pr->pr_mtx); error = sysctl_handle_string(oidp, tmpname, len, req); if (req->newptr != NULL && error == 0) { /* * Copy the locally set hostname to all jails that share * this host info. */ sx_slock(&allprison_lock); while (!(pr->pr_flags & PR_HOST)) pr = pr->pr_parent; mtx_lock(&pr->pr_mtx); bcopy(tmpname, (char *)pr + pr_offset, len); FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend) if (cpr->pr_flags & PR_HOST) descend = 0; else bcopy(tmpname, (char *)cpr + pr_offset, len); mtx_unlock(&pr->pr_mtx); sx_sunlock(&allprison_lock); /* Notify userland about hostname change */ switch (pr_offset) { case offsetof(struct prison, pr_hostname): snprintf(buf, sizeof(buf), "hostname=%s", tmpname); break; case offsetof(struct prison, pr_domainname): snprintf(buf, sizeof(buf), "domainname=%s", tmpname); break; case offsetof(struct prison, pr_hostuuid): snprintf(buf, sizeof(buf), "hostuuid=%s", tmpname); break; default: return (EINVAL); } devctl_notify("SYSTEM", "HOSTNAME", "CHANGE", buf); }
static int coretemp_get_val_sysctl(SYSCTL_HANDLER_ARGS) { device_t dev; int val, temp, rv; struct tegra124_coretemp_softc *sc; enum therm_info type; char stemp[16]; dev = (device_t) arg1; sc = device_get_softc(dev); type = arg2; rv = TEGRA_SOCTHERM_GET_TEMPERATURE(sc->tsens_dev, sc->dev, sc->tsens_id, &temp); if (rv != 0) { device_printf(sc->dev, "Cannot read temperature sensor %d: %d\n", sc->tsens_id, rv); return (rv); } switch (type) { case CORETEMP_TEMP: val = temp / 100; val += 2731; break; case CORETEMP_DELTA: val = (sc->core_max_temp - temp) / 1000; break; case CORETEMP_RESOLUTION: val = 1; break; case CORETEMP_TJMAX: val = sc->core_max_temp / 100; val += 2731; break; } if ((temp > sc->core_max_temp) && !sc->overheat_log) { sc->overheat_log = 1; /* * Check for Critical Temperature Status and Critical * Temperature Log. It doesn't really matter if the * current temperature is invalid because the "Critical * Temperature Log" bit will tell us if the Critical * Temperature has * been reached in past. It's not * directly related to the current temperature. * * If we reach a critical level, allow devctl(4) * to catch this and shutdown the system. */ device_printf(dev, "critical temperature detected, " "suggest system shutdown\n"); snprintf(stemp, sizeof(stemp), "%d", val); devctl_notify("coretemp", "Thermal", stemp, "notify=0xcc"); } else { sc->overheat_log = 0; } return (sysctl_handle_int(oidp, 0, val, req)); }
static u_int adb_kbd_receive_packet(device_t dev, u_char status, u_char command, u_char reg, int len, u_char *data) { struct adb_kbd_softc *sc; sc = device_get_softc(dev); if (command != ADB_COMMAND_TALK) return 0; if (reg != 0 || len != 2) return (0); mtx_lock(&sc->sc_mutex); /* 0x7f is always the power button */ if (data[0] == 0x7f && devctl_process_running()) { devctl_notify("PMU", "Button", "pressed", NULL); mtx_unlock(&sc->sc_mutex); return (0); } else if (data[0] == 0xff) { mtx_unlock(&sc->sc_mutex); return (0); /* Ignore power button release. */ } if ((data[0] & 0x7f) == 57 && sc->buffers < 7) { /* Fake the down/up cycle for caps lock */ sc->buffer[sc->buffers++] = data[0] & 0x7f; sc->buffer[sc->buffers++] = (data[0] & 0x7f) | (1 << 7); } else { sc->buffer[sc->buffers++] = data[0]; } if (sc->buffer[sc->buffers-1] < 0xff) sc->last_press = sc->buffer[sc->buffers-1]; if ((data[1] & 0x7f) == 57 && sc->buffers < 7) { /* Fake the down/up cycle for caps lock */ sc->buffer[sc->buffers++] = data[1] & 0x7f; sc->buffer[sc->buffers++] = (data[1] & 0x7f) | (1 << 7); } else { sc->buffer[sc->buffers++] = data[1]; } if (sc->buffer[sc->buffers-1] < 0xff) sc->last_press = sc->buffer[sc->buffers-1]; /* Stop any existing key repeating */ callout_stop(&sc->sc_repeater); /* Schedule a repeat callback on keydown */ if (!(sc->last_press & (1 << 7))) { callout_reset(&sc->sc_repeater, ms_to_ticks(sc->sc_kbd.kb_delay1), akbd_repeat, sc); } mtx_unlock(&sc->sc_mutex); cv_broadcast(&sc->sc_cv); if (KBD_IS_ACTIVE(&sc->sc_kbd) && KBD_IS_BUSY(&sc->sc_kbd)) { sc->sc_kbd.kb_callback.kc_func(&sc->sc_kbd, KBDIO_KEYINPUT, sc->sc_kbd.kb_callback.kc_arg); } return (0); }