sys_info.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Kernel-state info for the info commands (meminfo/mouseinfo/storage).
  2. * Small, read-only snapshots; storage additionally refreshes the mount cache,
  3. * which reads disks and therefore runs under the fs-busy gate (see sys_fs.c). */
  4. #include "syscall.h"
  5. #include "ahci.h"
  6. #include "blkdev.h"
  7. #include "mm.h"
  8. #include "mouse.h"
  9. #include "sys_fs.h"
  10. #include "usb.h"
  11. #include "usbhid.h"
  12. #include "vfs.h"
  13. static void copy_str(char *dst, const char *src, unsigned int size)
  14. {
  15. unsigned int i = 0;
  16. while (i + 1 < size && src[i]) {
  17. dst[i] = src[i];
  18. i++;
  19. }
  20. dst[i] = '\0';
  21. }
  22. int sys_meminfo(struct sys_meminfo *out)
  23. {
  24. out->total_kb = mm_total_ram_kb();
  25. out->free_pages = mm_free_pages();
  26. out->page_size = PAGE_SIZE;
  27. out->e820_count = mm_e820_count();
  28. return 0;
  29. }
  30. int sys_e820(unsigned int index, struct sys_e820 *out)
  31. {
  32. const struct e820_entry *e = mm_e820_entry(index);
  33. if (!e)
  34. return 0;
  35. out->base = (unsigned int)e->base;
  36. out->length = (unsigned int)e->length;
  37. out->type = e->type;
  38. return 1;
  39. }
  40. int sys_mouseinfo(struct sys_mouseinfo *out)
  41. {
  42. unsigned int i;
  43. for (i = 0; i < sizeof(*out); i++)
  44. ((unsigned char *)out)[i] = 0;
  45. out->present = mouse_is_present() ? 1 : 0;
  46. out->cursor_visible = mouse_cursor_visible() ? 1 : 0;
  47. copy_str(out->backend, mouse_cursor_backend_name(), sizeof(out->backend));
  48. if (!out->present)
  49. return 0;
  50. out->ps2 = mouse_ps2_present() ? 1 : 0;
  51. if (out->ps2) {
  52. out->ps2_id = mouse_device_id() & 0xFFu;
  53. out->ps2_packet_size = mouse_packet_size();
  54. out->ps2_streaming = mouse_streaming_enabled() ? 1 : 0;
  55. }
  56. out->usb = usbhid_mouse_attached() ? 1 : 0;
  57. if (out->usb) {
  58. unsigned int ep, mps;
  59. int low;
  60. usbhid_get_info(&out->usb_ctrl, &out->usb_addr, &ep, &mps, &low);
  61. out->usb_ep = ep;
  62. out->usb_mps = mps;
  63. out->usb_low = (unsigned int)low;
  64. copy_str(out->hcd, usb_hcd_name(), sizeof(out->hcd));
  65. }
  66. out->usb_keyboard = usbhid_keyboard_attached() ? 1 : 0;
  67. return 1;
  68. }
  69. int sys_storage_info(struct sys_storage_info *out)
  70. {
  71. sys_fs_enter(); /* vfs_mount_all() reads disks */
  72. vfs_mount_all();
  73. sys_fs_exit();
  74. out->ahci_present = ahci_controller_present() ? 1 : 0;
  75. out->blkdev_count = blk_dev_count;
  76. return 0;
  77. }
  78. int sys_blkdev(unsigned int index, struct sys_blkdev *out)
  79. {
  80. const blk_dev_t *d;
  81. if (index >= blk_dev_count)
  82. return 0;
  83. d = &blk_devs[index];
  84. copy_str(out->name, d->name, sizeof(out->name));
  85. copy_str(out->model, d->model, sizeof(out->model));
  86. out->kind = (unsigned int)d->kind;
  87. out->present = d->present ? 1 : 0;
  88. out->total_sectors = d->total_sectors;
  89. return 1;
  90. }