/*
 * This file is part of the Trezor project, https://trezor.io/
 *
 * Copyright (c) SatoshiLabs
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

// All syscalls with SYSCALL_THREAD_MODE flag are executed
// in kernel thread mode
#define SYSCALL_THREAD_MODE 0x80000000

// Syscall identifiers
typedef enum {

  // ------------------------------------------------------
  // Following syscalls are executed in kernel handler mode

  SYSCALL_RETURN_FROM_CALLBACK = 1,

  SYSCALL_SYSTEM_EXIT,
  SYSCALL_SYSTEM_EXIT_ERROR,
  SYSCALL_SYSTEM_EXIT_FATAL,

  SYSCALL_SYSTICK_CYCLES,
  SYSCALL_SYSTICK_MS,
  SYSCALL_SYSTICK_US,
  SYSCALL_SYSTICK_US_TO_CYCLES,

  SYSCALL_SYSEVENTS_POLL,
  SYSCALL_SYSHANDLE_READ,
  SYSCALL_SYSHANDLE_WRITE,

  SYSCALL_DBG_CONSOLE_READ,
  SYSCALL_DBG_CONSOLE_WRITE,

  SYSCALL_SYSLOG_START_RECORD,
  SYSCALL_SYSLOG_WRITE_CHUNK,
  SYSCALL_SYSLOG_SET_FILTER,

  SYSCALL_IPC_REGISTER,
  SYSCALL_IPC_UNREGISTER,
  SYSCALL_IPC_TRY_RECEIVE,
  SYSCALL_IPC_FREE_MESSAGE,
  SYSCALL_IPC_SEND,

  SYSCALL_BOOT_IMAGE_CHECK,
  SYSCALL_BOOT_IMAGE_REPLACE,

  SYSCALL_REBOOT_DEVICE,
  SYSCALL_REBOOT_TO_BOOTLOADER,
  SYSCALL_REBOOT_AND_UPGRADE,

  SYSCALL_NOTIFY_SEND,

  SYSCALL_DISPLAY_SET_BACKLIGHT,
  SYSCALL_DISPLAY_GET_BACKLIGHT,
  SYSCALL_DISPLAY_SET_ORIENTATION,
  SYSCALL_DISPLAY_GET_ORIENTATION,
  SYSCALL_DISPLAY_GET_FB_INFO,
  SYSCALL_DISPLAY_WAIT_FOR_SYNC,
  SYSCALL_DISPLAY_REFRESH,
  SYSCALL_DISPLAY_FILL,
  SYSCALL_DISPLAY_COPY_RGB565,

  SYSCALL_USB_START,
  SYSCALL_USB_STOP,
  SYSCALL_USB_GET_EVENT,
  SYSCALL_USB_GET_STATE,

  SYSCALL_SDCARD_POWER_ON,
  SYSCALL_SDCARD_POWER_OFF,
  SYSCALL_SDCARD_IS_PRESENT,
  SYSCALL_SDCARD_GET_CAPACITY,
  SYSCALL_SDCARD_READ_BLOCKS,
  SYSCALL_SDCARD_WRITE_BLOCKS,

  SYSCALL_UNIT_PROPERTIES_GET,
  SYSCALL_UNIT_PROPERTIES_GET_SN,

  SYSCALL_SECRET_BOOTLOADER_LOCKED,

  SYSCALL_BUTTON_GET_EVENT,

  SYSCALL_TOUCH_GET_EVENT,

  SYSCALL_RGB_LED_SET_ENABLED,
  SYSCALL_RGB_LED_GET_ENABLED,
  SYSCALL_RGB_LED_SET_COLOR,
  SYSCALL_RGB_LED_EFFECT_START,
  SYSCALL_RGB_LED_EFFECT_STOP,
  SYSCALL_RGB_LED_EFFECT_ONGOING,
  SYSCALL_RGB_LED_EFFECT_GET_TYPE,

  SYSCALL_HAPTIC_SET_ENABLED,
  SYSCALL_HAPTIC_GET_ENABLED,
  SYSCALL_HAPTIC_PLAY,
  SYSCALL_HAPTIC_PLAY_CUSTOM,

  SYSCALL_OPTIGA_SIGN,
  SYSCALL_OPTIGA_CERT_SIZE,
  SYSCALL_OPTIGA_READ_CERT,
  SYSCALL_OPTIGA_READ_SEC,
  SYSCALL_OPTIGA_SET_SEC_MAX,

  SYSCALL_TRANSLATIONS_WRITE,
  SYSCALL_TRANSLATIONS_READ,
  SYSCALL_TRANSLATIONS_ERASE,
  SYSCALL_TRANSLATIONS_AREA_BYTESIZE,

  SYSCALL_RNG_FILL_BUFFER,
  SYSCALL_RNG_FILL_BUFFER_STRONG,

  SYSCALL_FIRMWARE_GET_VENDOR,
  SYSCALL_FIRMWARE_HASH_START,
  SYSCALL_FIRMWARE_HASH_CONTINUE,

  SYSCALL_BLE_START,
  SYSCALL_BLE_SWITCH_ON,
  SYSCALL_BLE_SWITCH_OFF,
  SYSCALL_BLE_ENTER_PAIRING_MODE,
  SYSCALL_BLE_DISCONNECT,
  SYSCALL_BLE_ERASE_BONDS,
  SYSCALL_BLE_ALLOW_PAIRING,
  SYSCALL_BLE_REJECT_PAIRING,
  SYSCALL_BLE_GET_EVENT,
  SYSCALL_BLE_GET_STATE,
  SYSCALL_BLE_CAN_WRITE,
  SYSCALL_BLE_WRITE,
  SYSCALL_BLE_CAN_READ,
  SYSCALL_BLE_READ,
  SYSCALL_BLE_SET_NAME,
  SYSCALL_BLE_UNPAIR,
  SYSCALL_BLE_GET_BOND_LIST,
  SYSCALL_BLE_SET_HIGH_SPEED,
  SYSCALL_BLE_SET_ENABLED,
  SYSCALL_BLE_GET_ENABLED,

  SYSCALL_NRF_UPDATE_REQUIRED,
  SYSCALL_NRF_UPDATE,
  SYSCALL_NRF_GET_VERSION,
  SYSCALL_NRF_AUTHENTICATE,
  SYSCALL_NRF_REBOOT,

  SYSCALL_POWER_MANAGER_SUSPEND,
  SYSCALL_POWER_MANAGER_HIBERNATE,
  SYSCALL_POWER_MANAGER_CHARGING_ENABLE,
  SYSCALL_POWER_MANAGER_CHARGING_DISABLE,
  SYSCALL_POWER_MANAGER_GET_STATE,
  SYSCALL_POWER_MANAGER_GET_EVENTS,

  SYSCALL_JPEGDEC_OPEN,
  SYSCALL_JPEGDEC_CLOSE,
  SYSCALL_JPEGDEC_PROCESS,
  SYSCALL_JPEGDEC_GET_INFO,
  SYSCALL_JPEGDEC_GET_SLICE_RGBA8888,
  SYSCALL_JPEGDEC_GET_SLICE_MONO8,

  SYSCALL_DMA2D_WAIT,
  SYSCALL_DMA2D_RGB565_FILL,
  SYSCALL_DMA2D_RGB565_COPY_MONO4,
  SYSCALL_DMA2D_RGB565_COPY_RGB565,
  SYSCALL_DMA2D_RGB565_BLEND_MONO4,
  SYSCALL_DMA2D_RGB565_BLEND_MONO8,
  SYSCALL_DMA2D_RGBA8888_FILL,
  SYSCALL_DMA2D_RGBA8888_COPY_MONO4,
  SYSCALL_DMA2D_RGBA8888_COPY_RGB565,
  SYSCALL_DMA2D_RGBA8888_COPY_RGBA8888,
  SYSCALL_DMA2D_RGBA8888_BLEND_MONO4,
  SYSCALL_DMA2D_RGBA8888_BLEND_MONO8,

  SYSCALL_TROPIC_PING,
  SYSCALL_TROPIC_ECC_KEY_GENERATE,
  SYSCALL_TROPIC_ECC_SIGN,
  SYSCALL_TROPIC_DATA_READ,

  SYSCALL_APP_TASK_SPAWN,
  SYSCALL_APP_TASK_IS_RUNNING,
  SYSCALL_APP_TASK_GET_PMINFO,
  SYSCALL_APP_TASK_UNLOAD,

  SYSCALL_APP_CACHE_CREATE_IMAGE,
  SYSCALL_APP_CACHE_WRITE_IMAGE,
  SYSCALL_APP_CACHE_FINALIZE_IMAGE,

  SYSCALL_STORAGE_GET,

  SYSCALL_SECRET_KEYS_GET_DELEGATED_IDENTITY_KEY,

  SYSCALL_TELEMETRY_GET,
  // ------------------------------------------------------
  // Following syscalls are executed in kernel thread mode

  SYSCALL_STORAGE_SETUP = SYSCALL_THREAD_MODE,
  SYSCALL_STORAGE_WIPE,
  SYSCALL_STORAGE_IS_UNLOCKED,
  SYSCALL_STORAGE_LOCK,
  SYSCALL_STORAGE_UNLOCK,
  SYSCALL_STORAGE_HAS_PIN,
  SYSCALL_STORAGE_PIN_FAILS_INCREASE,
  SYSCALL_STORAGE_GET_PIN_REM,
  SYSCALL_STORAGE_CHANGE_PIN,
  SYSCALL_STORAGE_ENSURE_NOT_WIPE_CODE,
  SYSCALL_STORAGE_HAS_WIPE_CODE,
  SYSCALL_STORAGE_CHANGE_WIPE_CODE,
  SYSCALL_STORAGE_HAS,
  // SYSCALL_STORAGE_GET,
  SYSCALL_STORAGE_SET,
  SYSCALL_STORAGE_DELETE,
  SYSCALL_STORAGE_SET_COUNTER,
  SYSCALL_STORAGE_NEXT_COUNTER,

} syscall_number_t;
