syscall.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. /* Syscall interface (int 0x80), shared by the kernel and ring-3 commands. */
  2. #ifndef SYSCALL_H
  3. #define SYSCALL_H
  4. #define SYS_PUTSTR 1
  5. #define SYS_GET_TICKS_MS 2
  6. #define SYS_SLEEP_MS 3
  7. #define SYS_EXIT 4
  8. /* File service (see sys_fs.c). Paths are absolute VFS paths; buffers live in
  9. * the calling process's address space (the kernel runs on its CR3, so no copy
  10. * in/out is needed). */
  11. #define SYS_READ_FILE 5 /* (const char *path, void *buf, unsigned int max)
  12. -> bytes read, or <0 (SYS_E*) */
  13. #define SYS_WRITE_FILE 6 /* (const char *path, const void *buf, unsigned int len)
  14. -> 0, or <0 */
  15. #define SYS_LIST_DIR 7 /* (const char *path, unsigned int index,
  16. struct sys_dirent *out) -> 1 entry, 0 end, <0 */
  17. #define SYS_UNLINK 8 /* (const char *path) -> 0, or <0 */
  18. #define SYS_MKDIR 9 /* (const char *path) -> 0, or <0 */
  19. #define SYS_RMDIR 10 /* (const char *path) -> 0, or <0 */
  20. #define SYS_LIST_MOUNTS 11 /* (unsigned int index, struct sys_mount *out)
  21. -> 1 mount, 0 end */
  22. /* Kernel-state info for the info commands (see sys_info.c). */
  23. #define SYS_MEMINFO 12 /* (struct sys_meminfo *out) -> 0 */
  24. #define SYS_E820 13 /* (unsigned int index, struct sys_e820 *out)-> 1, 0 */
  25. #define SYS_MOUSEINFO 14 /* (struct sys_mouseinfo *out) -> 1 when present */
  26. #define SYS_STORAGE_INFO 15 /* (struct sys_storage_info *out) -> 0;
  27. refreshes the mount cache like `storage` did */
  28. #define SYS_BLKDEV 16 /* (unsigned int index, struct sys_blkdev *out) */
  29. /* Network service (see sys_net.c): the stack and NIC drivers stay in the
  30. * kernel; user commands get the configuration, the DNS/DHCP clients and the
  31. * raw frame paths (so the packet-level commands port unchanged). */
  32. #define SYS_NET_INFO 17 /* (struct sys_netinfo *out) -> 1 = NIC present */
  33. #define SYS_NET_PRINT_INFO 18 /* the driver's status lines */
  34. #define SYS_NET_ACQUIRE 19 /* take the receiver for this process (0/-1) */
  35. #define SYS_NET_RELEASE 20
  36. #define SYS_NET_MAC 21 /* (unsigned char mac[6]) -> 0/-1 */
  37. #define SYS_NET_GET_IP 22 /* (unsigned char ip[4]) */
  38. #define SYS_NET_SET_IP 23 /* (const unsigned char ip[4]) */
  39. #define SYS_NET_GET_MASK 24
  40. #define SYS_NET_GET_GW 25
  41. #define SYS_NET_GET_DNS 26
  42. #define SYS_NET_SET_DNS 27
  43. #define SYS_NET_TX 28 /* (const void *buf, unsigned len) -> 0/-1 */
  44. #define SYS_NET_RX 29 /* (void *buf, unsigned max) -> len/-1 */
  45. #define SYS_NET_DECODE 30 /* (const void *buf, unsigned len): one line */
  46. #define SYS_NET_REPLY 31 /* (in, len, out, max) -> reply length / 0 */
  47. #define SYS_NET_LOOPBACK 32 /* (int on) -> 0/-1 */
  48. #define SYS_NET_REGS 33 /* the driver's register dump */
  49. #define SYS_NET_RESET 34 /* driver re-init */
  50. #define SYS_DHCP_RUN 35 /* (timeout_ms) -> dhcp_run() result */
  51. #define SYS_DHCP_INFO 36 /* (unsigned char ip[4], unsigned *lease) -> 1 */
  52. #define SYS_DNS_RESOLVE 37 /* (name, unsigned char ip[4]) -> 0; caller owns */
  53. #define SYS_NETLOG 38 /* (const char *text) -> 0/-1 */
  54. #define SYS_NETLOG_CONF 39 /* (int enabled_or_-1, const ip[4] or NULL) */
  55. /* TCP client (see sys_net.c/tcp.c): one connection at a time; the caller
  56. * must own the NIC (SYS_NET_ACQUIRE). */
  57. #define SYS_TCP_CONNECT 40 /* (mac[6], ip[4], port) -> 0/-1/-2/-3 */
  58. #define SYS_TCP_PEER_MSS 41 /* () -> the peer's MSS of the current conn */
  59. #define SYS_TCP_SEND 42 /* (buf, len) -> 0/-1/-2/-3 */
  60. #define SYS_TCP_RECV 43 /* (buf, max, timeout_ms) -> >0/0/-1/-2 */
  61. #define SYS_TCP_CLOSE 44 /* () */
  62. #define SYS_NET_NEXT_HOP 45 /* (dst[4], hop[4]) */
  63. #define SYS_NET_ARP 46 /* (ip[4], mac[6]) -> 0/-1/-2 (net_arp_resolve) */
  64. #define SYS_NET_CONFIGURED 47 /* () -> 1 when an IP address is set */
  65. #define SYS_GETCWD 48 /* (char *buf, unsigned max) -> 0; the caller's cwd */
  66. /* Process snapshot for the `top` command (see process.c). */
  67. #define SYS_PROCINFO 49 /* (unsigned int index, struct sys_procinfo *out)
  68. -> 1 when found, 0 at the end of the table */
  69. #define SYS_KEY_POLL 55 /* () -> 0 none, ASCII, or IO_KEY_* for the caller's window */
  70. #define SYS_RTC_HMS 56 /* (struct sys_time *out) -> 0/-1 */
  71. #define SYS_RTC_GET 104 /* (struct sys_datetime *out) -> 0/-1 */
  72. #define SYS_RTC_SET 105 /* (const struct sys_datetime *in) -> 0/-1 */
  73. #define SYS_NTP_SYNC 106 /* (const char *server, unsigned timeout_ms,
  74. struct sys_datetime *out) -> SYS_NTP_*;
  75. the service owns the NIC for the duration */
  76. /* SYS_NTP_SYNC results. */
  77. #define SYS_NTP_OK 0
  78. #define SYS_NTP_ENONIC (-1) /* no NIC */
  79. #define SYS_NTP_ENAME (-2) /* server name could not be resolved */
  80. #define SYS_NTP_EARP (-3) /* no ARP reply for the next hop */
  81. #define SYS_NTP_ETX (-4) /* NIC transmit failed */
  82. #define SYS_NTP_ETIMEOUT (-5) /* no NTP reply */
  83. #define SYS_NTP_EREPLY (-6) /* malformed, unsynchronised or KoD reply */
  84. #define SYS_NTP_EBUSY (-7) /* another process owns the receiver */
  85. /* Window-manager service (see wm_abi.h). Only the kernel-spawned WM process
  86. * may call the WM_* entries; ordinary commands get -1. */
  87. #define SYS_WM_ATTACH 57 /* (struct wm_screen_info *out) -> 0/-1 */
  88. #define SYS_WM_INFO 58 /* (index, struct wm_window_info *out) -> 1/0/-1 */
  89. #define SYS_WM_MAP 59 /* (index, struct wm_map_info *out) -> 0/-1 */
  90. #define SYS_WM_ACK 60 /* (index, dirty_seq) -> 0/-1 */
  91. #define SYS_WM_FOCUS 61 /* (index) -> 0/-1 */
  92. #define SYS_WM_SET_GEOM 62 /* (index, struct wm_geom *in) -> 0/-1 */
  93. #define SYS_WM_CREATE_TERM 63 /* () -> index / -1 */
  94. #define SYS_WM_CLOSE 64 /* (index) -> 0/-1 */
  95. #define SYS_WM_POLL 65 /* (struct wm_status *out) -> 0/-1 */
  96. #define SYS_WM_BEGIN 66 /* () -> 0/-1; erase cursor, frame active */
  97. #define SYS_WM_PRESENT 67 /* (struct wm_present_info *in) -> 0/-1 */
  98. #define SYS_WM_SYNC 68 /* () -> 0/-1; run deferred gfx cleanup */
  99. #define SYS_RTC_DATETIME 69 /* (char *buf, unsigned max) -> 0/-1 */
  100. #define SYS_WIN_CREATE 70 /* (struct win_create *in, struct win_info *out) */
  101. #define SYS_WIN_PRESENT 71 /* (const struct wm_win_present *in) -> 0/-1;
  102. NULL or w/h 0 publishes the whole canvas */
  103. #define SYS_WIN_CLOSE 72 /* () -> 0/-1; close the caller's window */
  104. #define SYS_WM_RESIZE 83 /* (index, struct wm_size *content) -> 0/-1 */
  105. #define SYS_WIN_INFO 84 /* (struct win_info *out) -> 0/-1 */
  106. #define SYS_WIN_ACK_RESIZE 85 /* () -> 0/-1; swap in the pending canvas */
  107. #define SYS_WIN_POINTER 86 /* (struct win_pointer *out) -> 0/-1 */
  108. #define SYS_WIN_EVENT 87 /* (struct win_event *out) -> 1 event, 0 none */
  109. #define SYS_WIN_SCROLL 109 /* (struct win_scroll *out) -> 1 delta, 0 none, -1 */
  110. #define SYS_WIN_RESIZE_SELF 115 /* (int w, int h) -> 0/-1; resize the caller's canvas */
  111. #define SYS_SCREEN_INFO 116 /* (struct sys_screen *out) -> 0/-1 */
  112. #define SYS_WIN_SET_CURSOR 117 /* (int shape) -> 0/-1; the caller's content
  113. cursor (enum cursor_shape, cursor_abi.h) */
  114. #define SYS_WM_SET_CURSOR 118 /* (int shape | CURSOR_NO_OVERRIDE) -> 0/-1;
  115. WM only: cursor for its chrome/drags */
  116. #define SYS_WM_MOUSE_CAPTURE 121 /* (int on) -> 0/-1; WM only: own the pointer
  117. while it drags or resizes a window */
  118. #define SYS_WM_WALLPAPER 123 /* (int op) -> 0/<0; op 1 = a client installed a
  119. new wallpaper, bump wm_status.wallpaper_seq */
  120. /* Storage management (see sys_fs.c, the `disks` app). SYS_BLK_READ reads one
  121. * raw 512-byte sector of block device `index` (SYS_BLKDEV order) so ring 3
  122. * can show the partition table; it waits for a format/rescan like a file
  123. * operation. SYS_MOUNT_CTL sets the per-volume mount policy (mount point
  124. * name, read-only, not mounted) and remounts the device at once. Policies
  125. * live in RAM; the boot scan loads SYS_MOUNT_CFG_PATH from /data. */
  126. #define SYS_BLK_READ 119 /* (index, lba, void *buf512) -> 0/<0 */
  127. #define SYS_MOUNT_CTL 120 /* (op, a2, a3) */
  128. /* Boot storage-scan log (the `bootscan` kernel thread's serial output,
  129. * captured while it runs). STAT fills struct sys_bootlog, READ copies from
  130. * absolute byte offset a2 into the caller's SYS_BOOTLOG_CHUNK buffer at a3
  131. * and returns the number of bytes (0 at the end, <0 on a bad range). The
  132. * producer is a ring: `start` is the oldest byte still available. */
  133. #define SYS_BOOTLOG 122
  134. #define SYS_BOOTLOG_STAT 0
  135. #define SYS_BOOTLOG_READ 1
  136. #define SYS_BOOTLOG_CHUNK 1024
  137. struct sys_bootlog {
  138. unsigned int total; /* bytes ever written */
  139. unsigned int start; /* absolute offset of the oldest available byte */
  140. unsigned int capacity; /* ring size in bytes (0: no log) */
  141. unsigned int active; /* the scan thread is still producing */
  142. };
  143. #define SYS_MOUNT_POLICY_SET 0 /* (const struct sys_mount_policy *) -> 0/<0 */
  144. #define SYS_MOUNT_POLICY_GET 1 /* (index, struct sys_mount_policy *out) -> 1/0 */
  145. #define SYS_BACKLIGHT 113 /* (int op, int value) -> percent / -1.
  146. op 0 = get, 1 = set (5..100), 2 = step */
  147. #define SYS_BACKLIGHT_GET 0
  148. #define SYS_BACKLIGHT_SET 1
  149. #define SYS_BACKLIGHT_STEP 2
  150. #define SYS_CPUFREQ 114 /* (int mode) -> mode / -1.
  151. -1 = get; AUTO/MIN/MAX/OFF set the
  152. race-to-idle P-state governor. */
  153. #define SYS_CPUFREQ_GET (-1)
  154. #define SYS_CPUFREQ_AUTO 0
  155. #define SYS_CPUFREQ_MIN 1
  156. #define SYS_CPUFREQ_MAX 2
  157. #define SYS_CPUFREQ_FIXED 3
  158. #define SYS_CPUFREQ_OFF 4
  159. /* Per-process anonymous heap (see sys_mem.c). One growable arena at
  160. * USER_HEAP_BASE (0x60000000), at most USER_HEAP_MAX (64 MB), freed when the
  161. * process exits. SYS_MEM_ALLOC returns the base address, or <0. Ring-3
  162. * commands use malloc/free (libc/malloc.c); these syscalls are the libc
  163. * backend (libc/ucmd_mem.c) and are not called by application code. */
  164. #define SYS_MEM_ALLOC 88 /* (unsigned bytes) -> VA or <0 */
  165. #define SYS_MEM_GROW 89 /* (unsigned total_bytes) -> 0/-1; new pages not zeroed */
  166. #define SYS_MEM_FREE 90 /* () -> 0/-1 */
  167. /* CPU temperature (see thermal.c): the hottest core's DTS reading. */
  168. #define SYS_CPU_TEMP 91 /* (struct sys_cputemp *out) -> 0/-1 */
  169. /* IT87xx Super I/O hardware monitor (see it87.c); read-only. */
  170. #define SYS_SENSORS 92 /* (struct sys_sensors *out) -> 0/-1 */
  171. /* TCP server (WebDAV listener). The caller must own the NIC (SYS_NET_ACQUIRE).
  172. * SYS_TCP_ACCEPT polls a few frames and returns 1 once a connection is ready,
  173. * 0 when nothing arrived, or -3 when a netkexec header was captured (the
  174. * command should exit and let the kworker take over). */
  175. #define SYS_TCP_LISTEN 93 /* (port) -> 0/-1 */
  176. #define SYS_TCP_ACCEPT 94 /* () -> 1/0/-2/-3 */
  177. #define SYS_TCP_SRV_RECV 95 /* (buf, max, timeout_ms) -> >0/0/-1/-2 */
  178. #define SYS_TCP_SRV_SEND 96 /* (buf, len) -> 0/-1/-2/-3 */
  179. #define SYS_TCP_SRV_CLOSE 97
  180. #define SYS_TCP_PEER 99 /* (ip[4], unsigned *port) -> 0/-1 (debug log) */
  181. #define SYS_NET_SPEED 100 /* (mbps) -> 0; 0 = auto, 100 = force 100M */
  182. #define SYS_NET_MAC_SET 101 /* (const mac[6]) -> 0/-1/-2 */
  183. /* ThinkPad embedded-controller sensors (see tpec.c); read-only. */
  184. #define SYS_TPEC_SENSORS 102 /* (struct sys_tpec_sensors *out) -> 0/-1 */
  185. /* AC/battery snapshot from the board EC (see power_src.c, tpec.c and
  186. * cros_ec.c). SYS_POWER_F_DETAIL also reads design capacity, the capacity
  187. * unit and the manufacturer/model/serial strings. */
  188. #define SYS_POWER_INFO 103 /* (struct sys_powerinfo *out, flags) -> 0/-1 */
  189. #define SYS_POWER_F_DETAIL 0x1
  190. #define SYS_POWER_SRC_NONE 0
  191. #define SYS_POWER_SRC_TPEC 1 /* ThinkPad H8 EC */
  192. #define SYS_POWER_SRC_CROS 2 /* Chrome OS EC */
  193. /* Chrome OS EC temperature/fan/switch snapshot (see cros_ec.c). */
  194. #define SYS_CROS_EC_SENSORS 107 /* (struct sys_cros_sensors *out) -> 0/-1 */
  195. /* Current process id (used for per-process temporary paths). */
  196. #define SYS_GETPID 108 /* () -> pid */
  197. /* Intel 7265D/3165 and 6200/6300 WiFi (wifi.c). One multiplexed call: (op, a2, a3). */
  198. #define SYS_WIFI 110
  199. #define SYS_WIFI_UP 0 /* () -> 0 / -1: load firmware, read NVM */
  200. #define SYS_WIFI_STATUS 1 /* (struct sys_wifi_status *out) -> 0/-1 */
  201. #define SYS_WIFI_SCAN 2 /* () -> 0 / -1: start a scan */
  202. #define SYS_WIFI_RESULTS 3 /* (struct sys_wifi_bss *out, max) -> n,
  203. -2 while the scan is still running */
  204. #define SYS_WIFI_CONNECT 4 /* (const struct sys_wifi_connect *) ->
  205. 0 associated, -1 failed (auth/assoc) */
  206. #define SYS_WIFI_DISCONNECT 5 /* () -> 0 */
  207. #define SYS_WIFI_EAPOL_RX 6 /* (buf, max) -> len, 0 none, -1 */
  208. #define SYS_WIFI_EAPOL_TX 7 /* (buf, len) -> 0/-1 (EAPOL PDU) */
  209. #define SYS_WIFI_SET_KEY 8 /* (const struct sys_wifi_key *) -> 0/-1 */
  210. #define SYS_WIFI_AUTHORIZE 9 /* () -> 0/-1: open the data port and make
  211. the WiFi card the active netdev */
  212. #define SYS_WIFI_SET_PTK 10 /* (const struct sys_wifi_ptk *) -> 0/-1 */
  213. #define SYS_WIFI_GET_PTK 11 /* (struct sys_wifi_ptk *out, conn_id) ->
  214. 0/-1: the background rekey helper */
  215. #define SYS_WIFI_SEC_OPEN 0
  216. #define SYS_WIFI_SEC_PSK 1 /* RSN, PSK AKM, CCMP pairwise + group */
  217. #define SYS_WIFI_SEC_OTHER 2 /* WEP/WPA1/TKIP/802.1X/SAE: unsupported */
  218. /* NIC list and selection for the ring-3 network menu. The list probes every
  219. * registered driver, so only devices that are actually present are returned;
  220. * `kind` picks the menu icon (wired, WiFi, USB tethering). */
  221. #define SYS_NET_DEVLIST 111 /* (struct sys_netdev *out, max) -> count */
  222. #define SYS_NET_SELECT 112 /* (const char *name) -> 0/-1 */
  223. #define SYS_NETDEV_WIRED 0
  224. #define SYS_NETDEV_WIFI 1
  225. #define SYS_NETDEV_USB 2
  226. #define SYS_WIFI_ST_DOWN 0
  227. #define SYS_WIFI_ST_IDLE 1 /* firmware up, not associated */
  228. #define SYS_WIFI_ST_ASSOC 2 /* associated, port closed */
  229. #define SYS_WIFI_ST_LINK 3 /* associated, data port open */
  230. /* Stat one path (the file service has no open handle). */
  231. #define SYS_FS_STAT 98 /* (path, struct sys_stat *out) -> 0/<0 */
  232. /* Terminal / process services used by the ring-3 shell. */
  233. #define SYS_TTY_CREATE 73 /* () -> tty id 1..TTY_MAX / -1 */
  234. #define SYS_TTY_READ 74 /* (id, buf, max) -> bytes / 0 / -1 */
  235. #define SYS_SPAWN 75 /* (path, arg, tty, cwd) -> pid / <0 */
  236. #define SYS_SPAWN_KCMD 76 /* (name, arg, tty) -> pid / <0 */
  237. #define SYS_ALIVE 77 /* (pid) -> 1/0 */
  238. #define SYS_KILL 78 /* (pid) -> 0/-1 */
  239. #define SYS_CHDIR 79 /* (path) -> 0/-1 */
  240. #define SYS_WIN_KEY_WAIT 80 /* (timeout_ms) -> key / 0 timeout / -1 */
  241. #define SYS_SCHEDINFO 81 /* (struct sys_schedinfo *out) -> 0/-1 */
  242. struct sys_spawn {
  243. const char *path;
  244. const char *arg;
  245. const char *cwd;
  246. unsigned int tty;
  247. };
  248. struct sys_netinfo {
  249. unsigned int present;
  250. unsigned char mac[6];
  251. unsigned char ip[4];
  252. unsigned char mask[4];
  253. unsigned char gw[4];
  254. unsigned char dns[4];
  255. unsigned int mirror_on;
  256. unsigned char mirror_host[4];
  257. char name[8];
  258. char chip[16];
  259. unsigned int link; /* active netdev reports a usable link */
  260. unsigned int rx_bytes; /* frame bytes received since boot (wraps) */
  261. unsigned int tx_bytes; /* frame bytes sent since boot (wraps) */
  262. };
  263. /* One selectable NIC (see SYS_NET_DEVLIST). */
  264. struct sys_netdev {
  265. char name[8];
  266. char chip[24];
  267. unsigned int kind; /* SYS_NETDEV_* */
  268. unsigned int active;
  269. unsigned int link;
  270. };
  271. /* Framebuffer dimensions for popover sizing (see SYS_SCREEN_INFO). */
  272. struct sys_screen {
  273. unsigned int width;
  274. unsigned int height;
  275. };
  276. /* Error codes returned by the file syscalls. */
  277. #define SYS_EIO (-1) /* disk I/O error */
  278. #define SYS_ENODEV (-2) /* no such device / unusable path prefix */
  279. #define SYS_ENOFS (-3) /* device exists but has no mounted filesystem */
  280. #define SYS_ENOENT (-4) /* file/directory not found */
  281. #define SYS_EINVAL (-5) /* path is not valid for this operation */
  282. #define SYS_EWRITE (-6) /* write refused (full, or FAT rejected it) */
  283. #define SYS_EROFS (-7) /* read-only filesystem (ramfs) */
  284. #define SYS_ENOSPC (-8) /* no space left on the filesystem */
  285. /* One directory entry. `name` is a display name: raw 8.3 for FAT mounts
  286. * (space padded, `raw_83` set) or the plain name for name-string filesystems
  287. * such as ramfs and /share. */
  288. struct sys_dirent {
  289. char name[64];
  290. unsigned int size;
  291. unsigned int is_dir;
  292. unsigned int raw_83;
  293. };
  294. /* One mounted filesystem (for `ls /`). */
  295. struct sys_mount {
  296. char name[16];
  297. char type[8]; /* "FAT12", "FAT16", "FAT32", "ramfs", "share" */
  298. unsigned int total_sectors;
  299. char label[12];
  300. unsigned int ro;
  301. char dev[16]; /* source block device ("" for ramfs/share) */
  302. char key[16]; /* default name of the volume ("ide0p1"); the
  303. mount-policy key */
  304. };
  305. /* Mount policy of one volume, keyed by its default mount name: "ide0p1" for
  306. * MBR partition 1 of ide0, "floppy0"/"usb0" for a whole-device volume. A
  307. * policy with no name and no flags is removed. */
  308. #define SYS_MOUNT_NOAUTO 0x1 /* do not mount this volume */
  309. #define SYS_MOUNT_RO 0x2 /* mount read-only */
  310. #define SYS_MOUNT_POLICY_MAX 16
  311. struct sys_mount_policy {
  312. char key[16];
  313. char name[16]; /* mount point override; "" = default */
  314. unsigned int flags; /* SYS_MOUNT_* */
  315. };
  316. /* Saved policies: an 8-byte "NBMNT1\n\0" header and up to
  317. * SYS_MOUNT_POLICY_MAX struct sys_mount_policy records. */
  318. #define SYS_MOUNT_CFG_PATH "/data/MOUNTS.CFG"
  319. #define SYS_MOUNT_CFG_MAGIC "NBMNT1\n"
  320. /* Result of SYS_FS_STAT. */
  321. struct sys_stat {
  322. unsigned int size;
  323. unsigned int is_dir;
  324. unsigned int ro;
  325. };
  326. struct sys_meminfo {
  327. unsigned int total_kb;
  328. unsigned int free_pages;
  329. unsigned int page_size;
  330. unsigned int e820_count;
  331. unsigned int high_free_pages; /* free frames above 1 GB */
  332. unsigned int uncached_high_mb; /* highmem the MTRRs leave non-WB
  333. * (withheld from the allocator) */
  334. unsigned int uncached_low_mb; /* lowmem RAM the MTRRs leave non-WB */
  335. };
  336. /* One live process, for `top`/`process` (PROC_NAME_LEN = 12).
  337. * cpu_ticks/life_ticks are PIT ticks (1 kHz), so lifecycle percentages can be
  338. * derived. */
  339. struct sys_procinfo {
  340. unsigned int pid;
  341. unsigned int state; /* PROC_*: 1 ready, 2 running, 4 sleep, 5 block */
  342. unsigned int cpu_ticks; /* ticks spent as the running process */
  343. unsigned int life_ticks; /* ticks since creation, >= 1 */
  344. unsigned int pages; /* resident 4 KB pages (stack + dir + user) */
  345. unsigned int weight; /* CFS weight, 1..SCHED_WEIGHT_MAX */
  346. unsigned int cpu; /* CPU id, or 0xFFFFFFFF when not running */
  347. char name[12];
  348. unsigned int kernel_thread; /* 1 = kernel thread (not a ring-3 program) */
  349. };
  350. /* Scheduler counters for `top` and the `sched` command. */
  351. struct sys_schedinfo {
  352. unsigned int ncpus;
  353. unsigned int runnable;
  354. unsigned int sleeping;
  355. unsigned int blocked;
  356. unsigned int zombies;
  357. unsigned int switches;
  358. unsigned int wakeups;
  359. unsigned int idle_ticks;
  360. unsigned int slice_ticks;
  361. };
  362. /* CPU temperature snapshot (see thermal.c). temp_c is the hottest core's
  363. * last DTS sample; a negative value means no Intel DTS is available. delta_c
  364. * and status are from the CPU that serviced the syscall (for diagnostics).
  365. * cpu_temp_c[] holds the per-logical-CPU cached samples. */
  366. #define SYS_CPU_MAX 8
  367. struct sys_cputemp {
  368. int temp_c;
  369. int tjmax_c;
  370. int delta_c;
  371. unsigned int status;
  372. int cpu_temp_c[SYS_CPU_MAX];
  373. unsigned int ncpus;
  374. };
  375. /* IT87xx hardware monitor snapshot (temps are signed; -128 = unconnected). */
  376. struct sys_sensors {
  377. unsigned int present;
  378. unsigned int chip_id;
  379. unsigned int base;
  380. unsigned int temp_enable;
  381. unsigned int temp_extra;
  382. int temp_c[3];
  383. unsigned int fan_rpm[3];
  384. };
  385. /* ThinkPad embedded-controller snapshot (see tpec.c). temp_c[] follows
  386. * thinkpad_acpi's temp1..temp16 (EC 0x78..0x7F, then 0xC0..0xC7); -128 means
  387. * the sensor is not present. fan_level is the raw EC 0x2F value. */
  388. #define SYS_TPEC_TEMP_MAX 16
  389. struct sys_tpec_sensors {
  390. unsigned int present;
  391. char vendor[16];
  392. char product[32];
  393. char version[32];
  394. int temp_c[SYS_TPEC_TEMP_MAX];
  395. unsigned int fan_rpm;
  396. unsigned int fan_level;
  397. };
  398. /* AC/battery snapshot. rate is the signed present rate in the same unit as
  399. * the capacities; unit_mwh (when unit_known) selects mWh/mW vs mAh/mA.
  400. * percent is valid only when percent_valid is set. cycle_count/serial are
  401. * zero/empty when the backend does not provide them. */
  402. #define SYS_POWER_BATT_MAX 2
  403. struct sys_battery {
  404. unsigned int present;
  405. unsigned int error;
  406. unsigned int status; /* raw EC status/flags byte */
  407. unsigned int charging;
  408. unsigned int discharging;
  409. unsigned int percent;
  410. unsigned int percent_valid;
  411. unsigned int remaining;
  412. unsigned int full;
  413. unsigned int design;
  414. unsigned int voltage_mv;
  415. int rate;
  416. unsigned int unit_known;
  417. unsigned int unit_mwh;
  418. char manufacturer[16];
  419. char model[16];
  420. unsigned int cycle_count;
  421. char serial[16];
  422. };
  423. struct sys_powerinfo {
  424. unsigned int present; /* a supported EC was found */
  425. unsigned int source; /* SYS_POWER_SRC_* */
  426. int ac_online; /* -1 unknown, 0 offline, 1 online */
  427. unsigned int ec_rev;
  428. char vendor[16];
  429. char product[32];
  430. char version[32];
  431. unsigned int battery_count;
  432. struct sys_battery battery[SYS_POWER_BATT_MAX];
  433. };
  434. /* Chrome OS EC board sensors (see cros_ec.c). temp_c[] is -128 when the
  435. * sensor is absent/unavailable; fan_present is a bitmask over fan_rpm[].
  436. * switches follows EC_MEMMAP_SWITCHES (bit 0 lid open, bit 1 power button). */
  437. #define SYS_CROS_TEMP_MAX 24
  438. #define SYS_CROS_FAN_MAX 4
  439. struct sys_cros_sensors {
  440. unsigned int present;
  441. unsigned int acpi_version;
  442. unsigned int battery_version;
  443. unsigned int thermal_version;
  444. int temp_c[SYS_CROS_TEMP_MAX];
  445. unsigned int fan_rpm[SYS_CROS_FAN_MAX];
  446. unsigned int fan_present;
  447. unsigned int fan_duty; /* 0xff = automatic */
  448. unsigned int switches;
  449. };
  450. /* Wall clock for the ring-3 clock (see rtc.c). */
  451. struct sys_time {
  452. unsigned int hour; /* 0-23 */
  453. unsigned int minute; /* 0-59 */
  454. unsigned int second; /* 0-59 */
  455. };
  456. /* Full RTC wall clock for `date` and the Date & Time app. The CMOS RTC
  457. * stores a two-digit year; the kernel expands it with a 1970-2069 window
  458. * (70-99 -> 1900s, 00-69 -> 2000s), so a dead-battery default such as 1980
  459. * or 1990 reads correctly. SYS_RTC_SET accepts the same range. */
  460. struct sys_datetime {
  461. unsigned int year; /* 1970-2069 */
  462. unsigned int month; /* 1-12 */
  463. unsigned int day; /* 1-31 */
  464. unsigned int hour; /* 0-23 */
  465. unsigned int minute; /* 0-59 */
  466. unsigned int second; /* 0-59 */
  467. unsigned int wday; /* 0 = Sunday */
  468. };
  469. struct sys_e820 {
  470. unsigned int base; /* low 32 bits, as meminfo always printed */
  471. unsigned int length;
  472. unsigned int type;
  473. };
  474. struct sys_mouseinfo {
  475. unsigned int present;
  476. unsigned int ps2;
  477. unsigned int ps2_id;
  478. unsigned int ps2_packet_size;
  479. unsigned int ps2_streaming;
  480. unsigned int usb;
  481. unsigned int usb_ctrl;
  482. unsigned int usb_addr;
  483. unsigned int usb_ep;
  484. unsigned int usb_mps;
  485. unsigned int usb_low;
  486. unsigned int usb_keyboard;
  487. unsigned int cursor_visible;
  488. char hcd[8];
  489. char backend[16];
  490. unsigned int touchpad;
  491. unsigned int tp_vendor;
  492. unsigned int tp_product;
  493. };
  494. struct sys_storage_info {
  495. unsigned int ahci_present;
  496. unsigned int blkdev_count;
  497. };
  498. struct sys_blkdev {
  499. char name[8];
  500. char model[41];
  501. unsigned int kind; /* 0 = floppy, 1 = IDE, 2 = SATA, 3 = MMC, 4 = USB */
  502. unsigned int present;
  503. unsigned int total_sectors;
  504. };
  505. struct sys_wifi_bss {
  506. unsigned char bssid[6];
  507. unsigned char channel;
  508. signed char rssi; /* dBm */
  509. unsigned short beacon_int; /* TU */
  510. unsigned short capab;
  511. unsigned char dtim;
  512. unsigned char security; /* SYS_WIFI_SEC_* */
  513. unsigned char ssid_len;
  514. unsigned char rsn_len; /* AP's RSN IE (id/len included) */
  515. unsigned char ssid[32];
  516. unsigned char rsn[64];
  517. };
  518. struct sys_wifi_status {
  519. int state; /* SYS_WIFI_ST_* */
  520. unsigned char mac[6];
  521. unsigned char bssid[6];
  522. unsigned char channel;
  523. signed char rssi;
  524. unsigned char ssid_len;
  525. unsigned char present; /* card found on PCI */
  526. unsigned char ssid[32];
  527. char chip[24];
  528. char fw[24];
  529. char detail[24]; /* firmware state / last error */
  530. unsigned int rx_frames, tx_frames, rx_dropped;
  531. unsigned int conn_id; /* bumped by every SYS_WIFI_CONNECT */
  532. };
  533. struct sys_wifi_connect {
  534. unsigned char bssid[6];
  535. unsigned char channel;
  536. unsigned char ssid_len;
  537. unsigned short beacon_int;
  538. unsigned char dtim;
  539. unsigned char ie_len; /* our RSN IE for the assoc request */
  540. unsigned char ssid[32];
  541. unsigned char ie[64];
  542. };
  543. struct sys_wifi_key {
  544. int pairwise; /* 1 = TK, 0 = GTK */
  545. int keyidx; /* GTK key id 1..3 */
  546. unsigned char key[16];
  547. unsigned char rsc[8]; /* GTK receive sequence counter */
  548. };
  549. /* The PTK and EAPOL replay counter kept for the `wifi __keep` helper. */
  550. struct sys_wifi_ptk {
  551. unsigned int conn_id;
  552. unsigned char ptk[48];
  553. unsigned char replay[8];
  554. };
  555. int syscall_dispatch(int num, int a1, int a2, int a3);
  556. #endif