| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- /* Kernel-state info for the info commands (meminfo/mouseinfo/storage).
- * Small, read-only snapshots; storage additionally refreshes the mount cache,
- * which reads disks and therefore runs under the fs-busy gate (see sys_fs.c). */
- #include "syscall.h"
- #include "ahci.h"
- #include "blkdev.h"
- #include "cros_ec.h"
- #include "it87.h"
- #include "mm.h"
- #include "mouse.h"
- #include "power_src.h"
- #include "sched.h"
- #include "sys_fs.h"
- #include "thermal.h"
- #include "touchpad.h"
- #include "tpec.h"
- #include "usb.h"
- #include "usbhid.h"
- #include "vfs.h"
- _Static_assert(TPEC_TEMP_COUNT == SYS_TPEC_TEMP_MAX,
- "sys_tpec_sensors.temp_c and tpec_info.temp_c must match");
- _Static_assert(POWER_BATT_MAX == SYS_POWER_BATT_MAX,
- "sys_powerinfo.battery and power_info.battery must match");
- _Static_assert(CROS_EC_TEMP_MAX == SYS_CROS_TEMP_MAX,
- "sys_cros_sensors.temp_c and cros_ec_sensors.temp_c must match");
- _Static_assert(CROS_EC_FAN_MAX == SYS_CROS_FAN_MAX,
- "sys_cros_sensors.fan_rpm and cros_ec_sensors.fan_rpm must match");
- static void copy_str(char *dst, const char *src, unsigned int size)
- {
- unsigned int i = 0;
- while (i + 1 < size && src[i]) {
- dst[i] = src[i];
- i++;
- }
- dst[i] = '\0';
- }
- int sys_meminfo(struct sys_meminfo *out)
- {
- out->total_kb = mm_total_ram_kb();
- out->free_pages = mm_free_pages();
- out->page_size = PAGE_SIZE;
- out->e820_count = mm_e820_count();
- return 0;
- }
- int sys_e820(unsigned int index, struct sys_e820 *out)
- {
- const struct e820_entry *e = mm_e820_entry(index);
- if (!e)
- return 0;
- out->base = (unsigned int)e->base;
- out->length = (unsigned int)e->length;
- out->type = e->type;
- return 1;
- }
- int sys_mouseinfo(struct sys_mouseinfo *out)
- {
- unsigned int i;
- for (i = 0; i < sizeof(*out); i++)
- ((unsigned char *)out)[i] = 0;
- out->present = mouse_is_present() ? 1 : 0;
- out->cursor_visible = mouse_cursor_visible() ? 1 : 0;
- copy_str(out->backend, mouse_cursor_backend_name(), sizeof(out->backend));
- if (!out->present)
- return 0;
- out->ps2 = mouse_ps2_present() ? 1 : 0;
- if (out->ps2) {
- out->ps2_id = mouse_device_id() & 0xFFu;
- out->ps2_packet_size = mouse_packet_size();
- out->ps2_streaming = mouse_streaming_enabled() ? 1 : 0;
- }
- out->usb = usbhid_mouse_attached() ? 1 : 0;
- if (out->usb) {
- unsigned int ep, mps;
- int low;
- usbhid_get_info(&out->usb_ctrl, &out->usb_addr, &ep, &mps, &low);
- out->usb_ep = ep;
- out->usb_mps = mps;
- out->usb_low = (unsigned int)low;
- copy_str(out->hcd, usb_hcd_name_ctrl(out->usb_ctrl),
- sizeof(out->hcd));
- }
- out->usb_keyboard = usbhid_keyboard_attached() ? 1 : 0;
- out->touchpad = touchpad_present() ? 1 : 0;
- if (out->touchpad) {
- out->tp_vendor = touchpad_vendor();
- out->tp_product = touchpad_product();
- }
- return 1;
- }
- int sys_storage_info(struct sys_storage_info *out)
- {
- sys_fs_scan(); /* rescan; sleeps in the probes */
- out->ahci_present = ahci_controller_present() ? 1 : 0;
- out->blkdev_count = blk_dev_count;
- return 0;
- }
- int sys_blkdev(unsigned int index, struct sys_blkdev *out)
- {
- const blk_dev_t *d;
- if (index >= blk_dev_count)
- return 0;
- d = &blk_devs[index];
- copy_str(out->name, d->name, sizeof(out->name));
- copy_str(out->model, d->model, sizeof(out->model));
- out->kind = (unsigned int)d->kind;
- out->present = d->present ? 1 : 0;
- out->total_sectors = d->total_sectors;
- return 1;
- }
- int sys_cputemp(struct sys_cputemp *out)
- {
- unsigned int i;
- _Static_assert(MAX_CPUS <= SYS_CPU_MAX,
- "sys_cputemp.cpu_temp_c is too small");
- if (!out)
- return -1;
- out->temp_c = thermal_max_c();
- out->tjmax_c = thermal_tjmax();
- out->delta_c = -1;
- out->status = 0;
- if (thermal_status_this_cpu(&out->status) == 0)
- out->delta_c = (int)((out->status >> 16) & 0x7F);
- out->ncpus = cpu_count;
- for (i = 0; i < SYS_CPU_MAX; i++)
- out->cpu_temp_c[i] = cpus[i].temp_c;
- return 0;
- }
- int sys_sensors(struct sys_sensors *out)
- {
- struct it87_info info;
- unsigned int i;
- if (!out)
- return -1;
- it87_read(&info);
- out->present = info.present ? 1u : 0u;
- out->chip_id = info.chip_id;
- out->base = info.base;
- out->temp_enable = info.temp_enable;
- out->temp_extra = info.temp_extra;
- for (i = 0; i < 3; i++) {
- out->temp_c[i] = info.temp_c[i];
- out->fan_rpm[i] = info.fan_rpm[i];
- }
- return 0;
- }
- int sys_tpec_sensors(struct sys_tpec_sensors *out)
- {
- struct tpec_info info;
- unsigned int i;
- if (!out)
- return -1;
- tpec_read(&info);
- out->present = info.present ? 1u : 0u;
- copy_str(out->vendor, info.vendor, sizeof(out->vendor));
- copy_str(out->product, info.product, sizeof(out->product));
- copy_str(out->version, info.version, sizeof(out->version));
- for (i = 0; i < SYS_TPEC_TEMP_MAX; i++)
- out->temp_c[i] = info.temp_c[i];
- out->fan_rpm = info.fan_rpm;
- out->fan_level = info.fan_level;
- return 0;
- }
- int sys_powerinfo(struct sys_powerinfo *out, unsigned int flags)
- {
- struct power_info p;
- unsigned int i;
- if (!out)
- return -1;
- power_source_read(&p, (flags & SYS_POWER_F_DETAIL) != 0);
- for (i = 0; i < sizeof(*out); i++)
- ((unsigned char *)out)[i] = 0;
- out->present = p.present ? 1u : 0u;
- out->source = (unsigned int)p.source;
- out->ac_online = p.ac_online;
- out->ec_rev = p.ec_rev;
- copy_str(out->vendor, p.vendor, sizeof(out->vendor));
- copy_str(out->product, p.product, sizeof(out->product));
- copy_str(out->version, p.version, sizeof(out->version));
- out->battery_count = p.battery_count;
- for (i = 0; i < SYS_POWER_BATT_MAX; i++) {
- struct sys_battery *d = &out->battery[i];
- const struct power_battery *s = &p.battery[i];
- d->present = s->present ? 1u : 0u;
- d->error = s->error ? 1u : 0u;
- d->status = s->status;
- d->charging = s->charging ? 1u : 0u;
- d->discharging = s->discharging ? 1u : 0u;
- d->percent = s->percent > 0 ? (unsigned int)s->percent : 0u;
- d->percent_valid = s->percent_valid ? 1u : 0u;
- d->remaining = s->remaining;
- d->full = s->full;
- d->design = s->design;
- d->voltage_mv = s->voltage_mv;
- d->rate = s->rate;
- d->unit_known = s->unit_known ? 1u : 0u;
- d->unit_mwh = s->unit_mwh ? 1u : 0u;
- d->cycle_count = s->cycle_count;
- copy_str(d->manufacturer, s->manufacturer,
- sizeof(d->manufacturer));
- copy_str(d->model, s->model, sizeof(d->model));
- copy_str(d->serial, s->serial, sizeof(d->serial));
- }
- return 0;
- }
- int sys_cros_sensors(struct sys_cros_sensors *out)
- {
- struct cros_ec_sensors info;
- unsigned int i;
- if (!out)
- return -1;
- cros_ec_sensors_read(&info);
- out->present = info.present ? 1u : 0u;
- out->acpi_version = info.acpi_version;
- out->battery_version = info.battery_version;
- out->thermal_version = info.thermal_version;
- for (i = 0; i < SYS_CROS_TEMP_MAX; i++)
- out->temp_c[i] = info.temp_c[i];
- for (i = 0; i < SYS_CROS_FAN_MAX; i++)
- out->fan_rpm[i] = info.fan_rpm[i];
- out->fan_present = info.fan_present;
- out->fan_duty = info.fan_duty;
- out->switches = info.switches;
- return 0;
- }
|