系列文章 : [6.1810] 跟著 MIT 6.1810 學習基礎作業系統觀念
- PLIC 接受 interrupt source 1 ~ 1023 ( 最多可以接受 1023 個 interrupt source )
- 第 0 個 interrupt source 不存在
-
Interrupt targets 通常指的是 hart contexts。一個 hart context 通常是一個 hart 的特權級。
- 例如有 8 個 hart,每個 hart 都支援 M-mode, S-mode,那現在最大的 hart context 就是 8 * 2 = 16。
- Q: 該怎麼知道這個 PLIC 會接到多少個 context 呢 ?
- 可以借助 device tree source ( dts )
以下面的 dts 範例來說,這個 PLIC 接到了 3 個 context ( 也就是說,總共有三個 target )
- cpu0, 11 ( machine mode )
- cpu1, 11 ( machine mode )
- cpu1, 9 ( supervisor mode )
interrupts-extended = <
&cpu0-intc 11
&cpu1-intc 11 &cpu1-intc 9
>;
- Q: 為什麼 11 是 machine mode, 9 是 supervisor mode ?
- 可以看 local interrupt number 對應到的意義
- 1: Supervisor Software Interrupt
- 3: Machine Software Interrupt
- 5: Supervisor Timer Interrupt
- 7: Machine Timer Interrupt
-
9: Supervisor External Interrupt
-
11: Machine External Interrupt
- CSR
-
Interrupt Priorities
- offset : 0x0
- size : 每個 interrupt source 佔 4 個 bytes。總共支援 1023 ( 1 ~ 1023 ) 個 interrupt source,且需要多加一個空的 interrupt source ( 第 0 個 interrupt source ),所以最多會佔用 4 * 1024 = 0x1000 bytes。
- meaning : 每一個 interrupt source 都可以有一個 priority。當設為 0 的時候,表示關掉這個 interrupt source。
數值越大,優先級越高。假如兩個 interrupt source 的 priority 被設為相同,則 Interrupt ID 越低的 interrupt source,其優先權越高。
-
Interrupt Pending Bits
- offset : 0x1000
- size : 每個 interrupt source ( 包含沒有作用的 interrupt source 0 ),共需要 1024 個 bits,1024 bits / 8 = 128 bytes ( 0x80 bytes )
- meaning : 顯示目前該 interrupt source 是否 pending,該 bit == 1 時候,代表對應的 interrupt source 正在 pending 。 Interrupt ID 為 N 的 interrupt source 的狀態會在第 N 個 bit。而 interrupt ID 為 0 ( 就是那個沒有作用的 interrupt source ),它的 bit 會被 hardwired 成 0。
-
Interrupt Enables
- offset : 0x2000
- size : 每個 interrupt source 都需要有一個 bit ( 1024 bits / 8 = 128 bytes ),且每個 context 都需要有自己的一份,且最多支援 15872 個 context。( 128 * 15872 = 0x1f0000 )
- meaning : 是否要為某一個 context 去 enable 某個 interrupt source 的 interrupt。
-
Priority Thresholds
- offset : 0x200000 + 0x1000 * x
x 代表第幾個 context
- size : register 本身是 4 bytes
- meaning : 當 interrupt 小於等於 threshold 的時候,這個 interrupt 就會被屏蔽。假如 threshold 設為 0,表示接受所有
非零 priority 的 interrupt。
-
Interrupt Claim
- offset : 0x200004 + 0x1000 * x
x 代表第幾個 context
跟 interrupt Completion 的 address 相同。當我們是 read 的時候,會是 interrupt claim register
- size : register 本身是 4 bytes
- meaning : 讀取到的值為 0 時,代表目前沒有任何該 target 可以處理的 interrupt。讀取到的值不為 0 時 ( 令其為 n ),則 n 是該 target 可以處理的最高 priority 的 interrupt ID ( 上面有討論過 interrupt priority 了,假如兩個 interrupt 的 prirority 設為相同,則 interrupt ID 越低的 interrupt source,其權限越高 )。
-
Interrupt Completion
- offset : 0x200004 + 0x1000 * x
x 代表第幾個 context
跟 interrupt claim 的 address 相同,當我們是 write 的時候,會是 interrupt completion。
- size : register 本身是 4 bytes
- meaning : 當我們處理完某個 interrupt ID ( 令其為 n ) 後,可以把該 n 寫入 Completion register,這樣 interrupt ID 為 n 的 interrupt 才可以發下一發 interrupt 給 target 。於此可知,當 interrupt source 就算 interrupt source 不斷保持在 assert 的狀態,在被 claim 並 completion 之前,對 target 來說都算是一發 interrupt 。
Reference