# SDEI學習筆記
## Introduction
Software Delegated Exception Interface (SDEI) is an Arm specification for Non-secure
world to register handlers with firmware to receive notifications about system events.
SDEI是ARM做的一種system events的通知方式。Firmware收到system events後,使用SDEI通知Non-secure world,
並執行註冊好的handler。
經典應用場景
System Error handling (RAS)
Software Watchdog timer
Kernel Debugging
Sample Profiling
詳細介紹,請參考ARM的以下文檔。
https://github.com/ARM-software/arm-trusted-firmware/blob/master/docs/sdei.rst
http://infocenter.arm.com/help/topic/com.arm.doc.den0054a/ARM_DEN0054A_Software_Delegated_Exception_Interface.pdf
## APEI對SDEI的支持
ACPI-v6.2開始增加對SDEI的支持,作爲一種Hardware Error Notification方式。
這樣,APEI表就包含以下11中Notification類型:
0 – Polled
1 – External Interrupt
2 – Local Interrupt
3 – SCI
4 – NMI
5 - CMCI
6 - MCE
7 - GPIO-Signal
8 - ARMv8 SEA
9 - ARMv8 SEI
10 - External Interrupt - GSIV
11 - Software Delegated Exception – See Links to ACPI-Related Documents (http://uefi.org/acpi) under the heading, “SDEI Specification.”
## TF對SDEI的支持
./include/services/sdei.h
sdei_dispatch_event()應該是在BIOS的RAS driver裏面調用。
void begin_sdei_synchronous_dispatch(struct jmpbuf *buffer);
./services/std_svc/sdei/sdei_dispatch.S
彙編實現的dispatch函數,同步dispatch
int setjmp(struct jmpbuf *buf);
./lib/aarch64/setjmp.S
## UEFI對SDEI的支持
Trust firmware需要升級到TF1.5。
UEFI增加一個SDEI表,用來與OS對齊版本信息。
UEFI使能TF中的SDEI功能,需要做什麼還沒搞清楚
UEFI收到system event之後,比如RAS中斷,調用TF提供的以下API,通知SDEI Client。
int sdei_dispatch_event(int ev_num);
## OS對SDEI的支持
HEST中定義了vector,作爲event_num用於sdei_event_register()
sdei_event_create()添加到sdei_list
_sdei_event_register() --> _local_event_register() --> invoke_sdei_fn() --> sdei_firmware_call()
sdei_firmware_call有兩種實現方式,HVC和SMC,通過acpi或者DTS表選擇。
sdei_event_enable --> sdei_api_event_enable() --> invoke_sdei_fn
bios還需要定義一個SDEI表,./drivers/firmware/arm_sdei.c驅動初始化的時候會解析。