QUESTION
GIC의 group 선택과 EL3의 interrupt dispatch는 어디서 만나는가?
gicv3_driver_init()는 플랫폼 데이터의 전제 조건을 검사하고, gicr_base가 주어졌을 때 Redistributor 주소를 탐색한다. gicv3_distif_init()는 SPI group을, 각 PE의 gicv3_rdistif_init()는 SGI/PPI group을 설정한다. gicv3_cpuif_enable()은 ICC system-register interface와 Group 0/1 Secure enable을 설정한다.
BL31의 register_interrupt_type_handler()는 별도의 경로에서 interrupt type별 handler와 SCR_EL3 IRQ/FIQ routing model을 등록한다. EL3 예외가 발생했을 때만 platform pending type 조회 → 등록 handler 조회 → handler 호출이 이어진다. Group 0과 Group 1 Secure를 한 가지 “secure handler”로 묶지 않는다.
GIC driver 100–337 · type mapping 76–99 · 등록 193–233 · dispatch 528–598
STRUCTURE
하드웨어 설정과 BL31 routing model의 두 층
GIC 하드웨어 · interrupt별/PE별 상태
gicv3_driver_data_t플랫폼 GICD/GICR 주소·Redistributor 배열·secure interrupt property.BL31 interrupt framework · type별 상태
intr_type_descs[type]등록된 handler, routing flags, security state별 SCR IRQ/FIQ bit 사본.SCR_EL3 contextset_routing_model()이 각 security state의 IRQ/FIQ routing 값을 계산.gicv3_cpuif_enable()은 ICC를 설정하는 중 SCR_NS를 일시 전환·복원하지만, 이 함수가 handler 등록이나 IRQ/FIQ routing model을 확정하는 것은 아니다.
CALL PATH
소스가 보장하는 초기화 의존 관계
driver_initEL3·주소·배열 검사; GIC version 확인; gicr_base != 0이면 GICR 탐색; driver data 연결.distif_initGroup enable clear → ARE_S/NS → 기본 SPI G1NS → secure SPI property → 필요한 group enable.rdistif_initrdistif_on() hook → 기본 SGI/PPI G1NS → secure property → 필요한 group enable.cpuif_enable해당 PE awake → ICC_SRE → secure/NS SRE bank → PMR → G0/G1S enable.함수들은 각각 void이며 자체적으로 다음 함수를 호출하는 단일 체인이 아니다. 플랫폼이 호출 순서를 정한다. 코드상 rdistif_init()은 Distributor의 ARE_S가 이미 설정되었다고 assert한다. 기본 rdistif_on() 본문은 비어 있으므로 이 단계가 항상 하드웨어를 깨운다고 가정하지 않는다. handler 등록과 SCR routing 설정은 아래 별도 BL31 경로다.
STATE LEDGER
한 단계의 출력이 다음 단계에 뜻하는 것
| 단계 | 실제 전제 | 바뀌는 상태 | 그 이후의 판단 |
|---|---|---|---|
driver_init | EL3; GICD 주소·Redistributor 수·주소 배열; property 수가 양수면 pointer 필요 | 선택적으로 GICR 주소 탐색, 전역 driver data pointer | 배열 slot과 platform 데이터 수명이 유효한지 확인 |
distif_init | driver data 및 GICD 주소 | GICD ARE_S/NS, SPI 기본 G1NS, 지정한 secure SPI의 group·priority·route | GICD group enable bitmap 확인 |
rdistif_init | 해당 PE slot·GICR 주소; GICD ARE_S set | GICR SGI/PPI 기본 G1NS와 secure property | PE별 GICR 설정 확인 |
cpuif_enable | EL3와 해당 PE의 GICR 주소 | ICC SRE/PMR/G0·G1S enable; 임시 SCR_NS는 복원 | SCR IRQ/FIQ routing model은 여기서 생성되지 않음 |
register_interrupt_type_handler | 유효 type·handler·flags; 중복 등록 아님 | type별 handler와 security state별 SCR routing bit | EL3 exception이 이 type을 받을 때 handler lookup |
각 단계는 별도 API다. 그림의 분석 범위와 실제 플랫폼 호출자를 함께 보아야 전체 부팅 순서를 확정할 수 있다.
VISUAL WALKTHROUGH
Group bit, target type, EL3 dispatch를 나누어 읽기
Group 0 Secure
INTR_TYPE_EL3; secure Group 0. 기본 GICv3 플랫폼 함수에서 양 security state 모두 FIQ line.Group 1 Secure
INTR_TYPE_S_EL1; Secure context에선 IRQ, Non-secure context에선 FIQ line.Group 1 Non-secure
INTR_TYPE_NS; Secure context에선 FIQ, Non-secure context에선 IRQ line.SPI의 두 bit는 GICD, SGI/PPI의 두 bit는 해당 GICR에서 읽는다. 이 표는 TF-A의 plat_gicv3.c 기본(weak) 구현이며 플랫폼 override가 있으면 그 구현을 먼저 확인한다.
handle_interrupt_exception으로 분기.plat_ic_get_pending_interrupt_type(): 1020→S-EL1, 1021→NS, 1023→invalid, 그 외→EL3.get_interrupt_type_handler(type). invalid 또는 미등록이면 exception 복귀.x0=INTR_ID_UNAVAILABLE, x1=현재 security state, x2=context handle; handler가 필요한 ID/EOI를 처리.예외 진입 시점의 type 판정은 pending group 표시값이다. EL3 vector 자체가 interrupt ID를 acknowledge하거나 EOI하는 그림으로 해석하지 않는다.
UPSTREAM SOURCE
원본 코드
원문 Trusted Firmware-A LTS 2.14.3 · drivers/arm/gic/v3/gicv3_main.c의 227–260행입니다.
227void gicv3_rdistif_init(unsigned int proc_num)
228{
229 uintptr_t gicr_base;
230 unsigned int bitmap;
231 uint32_t ctlr;
232
233 assert(gicv3_driver_data != NULL);
234 assert(proc_num < gicv3_driver_data->rdistif_num);
235 assert(gicv3_driver_data->rdistif_base_addrs != NULL);
236 assert(gicv3_driver_data->gicd_base != 0U);
237
238 ctlr = gicd_read_ctlr(gicv3_driver_data->gicd_base);
239 assert((ctlr & CTLR_ARE_S_BIT) != 0U);
240
241 assert(IS_IN_EL3());
242
243 /* Power on redistributor */
244 gicv3_rdistif_on(proc_num);
245
246 gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num];
247 assert(gicr_base != 0U);
248
249 /* Set the default attribute of all SGIs and (E)PPIs */
250 gicv3_ppi_sgi_config_defaults(gicr_base);
251
252 bitmap = gicv3_secure_ppi_sgi_config_props(gicr_base,
253 gicv3_driver_data->interrupt_props,
254 gicv3_driver_data->interrupt_props_num);
255
256 /* Enable interrupt groups as required, if not already */
257 if ((ctlr & bitmap) != bitmap) {
258 gicd_set_ctlr(gicv3_driver_data->gicd_base, bitmap, RWP_TRUE);
259 }
260}
READING CONTRACT
발췌 범위와 실제 함수 경계
원문 227–260행의 gicv3_rdistif_init()은 현재 PE의 Redistributor에서 SGI/PPI 설정을 적용합니다. 앞선 GICR 주소 탐색과 드라이버 데이터 연결은 100–180행 전체에서 확인합니다. 아래 관련 발췌에는 ICC system-register interface를 설정하는 gicv3_cpuif_enable()이 있습니다. 핸들러 등록과 dispatch의 근거는 interrupt_mgmt.c와 runtime_exceptions.S입니다.
RELATED SOURCE
함께 읽어야 하는 원본 코드
두 발췌 모두 같은 기준 commit의 gicv3_main.c다. 첫 발췌는 CPU interface, 둘째는 Redistributor 초기화와 CPU interface 앞부분을 보여준다. EL3 handler 등록·dispatch는 별도 BL31 파일에서 확인한다.
01. 한 CPU의 GIC system-register interface 활성화
drivers/arm/gic/v3/gicv3_main.c 265-355줄이다.
265void gicv3_rdistif_off(unsigned int proc_num)
266{
267}
268
269void gicv3_rdistif_on(unsigned int proc_num)
270{
271}
272
273/*******************************************************************************
274 * This function enables the GIC CPU interface of the calling CPU using only
275 * system register accesses.
276 ******************************************************************************/
277void gicv3_cpuif_enable(unsigned int proc_num)
278{
279 uintptr_t gicr_base;
280 u_register_t scr_el3;
281 unsigned int icc_sre_el3;
282
283 assert(gicv3_driver_data != NULL);
284 assert(proc_num < gicv3_driver_data->rdistif_num);
285 assert(gicv3_driver_data->rdistif_base_addrs != NULL);
286 assert(IS_IN_EL3());
287
288 /* Mark the connected core as awake */
289 gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num];
290 gicv3_rdistif_mark_core_awake(gicr_base);
291
292 /* Disable the legacy interrupt bypass */
293 icc_sre_el3 = ICC_SRE_DIB_BIT | ICC_SRE_DFB_BIT;
294
295 /*
296 * Enable system register access for EL3 and allow lower exception
297 * levels to configure the same for themselves. If the legacy mode is
298 * not supported, the SRE bit is RAO/WI
299 */
300 icc_sre_el3 |= (ICC_SRE_EN_BIT | ICC_SRE_SRE_BIT);
301 write_icc_sre_el3(read_icc_sre_el3() | icc_sre_el3);
302
303 scr_el3 = read_scr_el3();
304
305 /*
306 * Switch to NS state to write Non secure ICC_SRE_EL1 and
307 * ICC_SRE_EL2 registers.
308 */
309 write_scr_el3(scr_el3 | SCR_NS_BIT);
310 isb();
311
312 write_icc_sre_el2(read_icc_sre_el2() | icc_sre_el3);
313 write_icc_sre_el1(ICC_SRE_SRE_BIT);
314 isb();
315
316 /* Switch to secure state. */
317 write_scr_el3(scr_el3 & (~SCR_NS_BIT));
318 isb();
319
320 /* Write the secure ICC_SRE_EL1 register */
321 write_icc_sre_el1(ICC_SRE_SRE_BIT);
322 isb();
323
324 /* Program the idle priority in the PMR */
325 write_icc_pmr_el1(GIC_PRI_MASK);
326
327 /* Enable Group0 interrupts */
328 write_icc_igrpen0_el1(IGRPEN1_EL1_ENABLE_G0_BIT);
329
330 /* Enable Group1 Secure interrupts */
331 write_icc_igrpen1_el3(read_icc_igrpen1_el3() |
332 IGRPEN1_EL3_ENABLE_G1S_BIT);
333 /* and restore the original */
334 write_scr_el3(scr_el3);
335 isb();
336 /* Add DSB to ensure visibility of System register writes */
337 dsb();
338}
339
340/*******************************************************************************
341 * This function disables the GIC CPU interface of the calling CPU using
342 * only system register accesses.
343 ******************************************************************************/
344void gicv3_cpuif_disable(unsigned int proc_num)
345{
346 uintptr_t gicr_base;
347
348 assert(gicv3_driver_data != NULL);
349 assert(proc_num < gicv3_driver_data->rdistif_num);
350 assert(gicv3_driver_data->rdistif_base_addrs != NULL);
351
352 assert(IS_IN_EL3());
353
354 /* Disable legacy interrupt bypass */
355 write_icc_sre_el3(read_icc_sre_el3() |
02. 현재 CPU의 Redistributor와 SGI/PPI 초기화
drivers/arm/gic/v3/gicv3_main.c 217-303줄이다.
217
218 /* Enable the secure (E)SPIs now that they have been configured */
219 gicd_set_ctlr(gicv3_driver_data->gicd_base, bitmap, RWP_TRUE);
220}
221
222/*******************************************************************************
223 * This function initialises the GIC Redistributor interface of the calling CPU
224 * (identified by the 'proc_num' parameter) based upon the data provided by the
225 * platform while initialising the driver.
226 ******************************************************************************/
227void gicv3_rdistif_init(unsigned int proc_num)
228{
229 uintptr_t gicr_base;
230 unsigned int bitmap;
231 uint32_t ctlr;
232
233 assert(gicv3_driver_data != NULL);
234 assert(proc_num < gicv3_driver_data->rdistif_num);
235 assert(gicv3_driver_data->rdistif_base_addrs != NULL);
236 assert(gicv3_driver_data->gicd_base != 0U);
237
238 ctlr = gicd_read_ctlr(gicv3_driver_data->gicd_base);
239 assert((ctlr & CTLR_ARE_S_BIT) != 0U);
240
241 assert(IS_IN_EL3());
242
243 /* Power on redistributor */
244 gicv3_rdistif_on(proc_num);
245
246 gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num];
247 assert(gicr_base != 0U);
248
249 /* Set the default attribute of all SGIs and (E)PPIs */
250 gicv3_ppi_sgi_config_defaults(gicr_base);
251
252 bitmap = gicv3_secure_ppi_sgi_config_props(gicr_base,
253 gicv3_driver_data->interrupt_props,
254 gicv3_driver_data->interrupt_props_num);
255
256 /* Enable interrupt groups as required, if not already */
257 if ((ctlr & bitmap) != bitmap) {
258 gicd_set_ctlr(gicv3_driver_data->gicd_base, bitmap, RWP_TRUE);
259 }
260}
261
262/*******************************************************************************
263 * Functions to perform power operations on GIC Redistributor
264 ******************************************************************************/
265void gicv3_rdistif_off(unsigned int proc_num)
266{
267}
268
269void gicv3_rdistif_on(unsigned int proc_num)
270{
271}
272
273/*******************************************************************************
274 * This function enables the GIC CPU interface of the calling CPU using only
275 * system register accesses.
276 ******************************************************************************/
277void gicv3_cpuif_enable(unsigned int proc_num)
278{
279 uintptr_t gicr_base;
280 u_register_t scr_el3;
281 unsigned int icc_sre_el3;
282
283 assert(gicv3_driver_data != NULL);
284 assert(proc_num < gicv3_driver_data->rdistif_num);
285 assert(gicv3_driver_data->rdistif_base_addrs != NULL);
286 assert(IS_IN_EL3());
287
288 /* Mark the connected core as awake */
289 gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num];
290 gicv3_rdistif_mark_core_awake(gicr_base);
291
292 /* Disable the legacy interrupt bypass */
293 icc_sre_el3 = ICC_SRE_DIB_BIT | ICC_SRE_DFB_BIT;
294
295 /*
296 * Enable system register access for EL3 and allow lower exception
297 * levels to configure the same for themselves. If the legacy mode is
298 * not supported, the SRE bit is RAO/WI
299 */
300 icc_sre_el3 |= (ICC_SRE_EN_BIT | ICC_SRE_SRE_BIT);
301 write_icc_sre_el3(read_icc_sre_el3() | icc_sre_el3);
302
303 scr_el3 = read_scr_el3();
DETAILS
각 함수가 실제로 쓰는 레지스터
driver init은 Redistributor 주소를 먼저 찾는다
gicr_base가 0이 아닐 때 gicv3_rdistif_base_addrs_probe()가 플랫폼 배열을 채운다. 0이면 caller가 이미 유효한 배열을 제공해야 한다. 이 함수 자체는 GICD group이나 SCR routing bit를 설정하지 않는다.
default G1NS 뒤 secure property를 덮어쓴다
Distributor는 SPI, Redistributor는 SGI/PPI를 G1NS로 시작한다. 플랫폼 property에 명시한 secure interrupt에 대해 IGROUPR을 지우고 IGRPMODR로 G0 또는 G1S를 고른다. SPI는 기본 helper에서 primary CPU로 route한다.
CPU interface의 SCR_NS 변경은 임시다
gicv3_cpuif_enable()은 Non-secure ICC_SRE_EL1/EL2 bank를 쓰기 위해 SCR_NS를 set한 뒤 Secure bank로 전환하고, 끝에서 원래 SCR을 복원한다. PMR, Group 0 및 Group 1 Secure enable은 ICC 쪽에 기록된다.
handler 등록이 SCR IRQ/FIQ 모델을 만든다
register_interrupt_type_handler()가 type·flags를 검증한 뒤 set_routing_model()을 호출한다. 이 함수는 type/security-state별 line을 선택해 SCR bit 사본과 이미 존재하는 CPU context를 갱신한다.
IMPLEMENTATION NOTES
Group과 handler를 같은 객체로 취급하면 놓치는 조건
Group 분류는 interrupt ID의 설정이다
gicv3_get_interrupt_group()는 SGI/PPI면 GICR, SPI면 GICD의 IGROUPR·IGRPMODR를 읽는다. LPI는 별도로 Group 1 Non-secure로 간주한다. type handler는 ID마다 등록하지 않고 BL31의 type별 배열에 등록한다.
pending type과 실제 interrupt ID는 구별된다
EL3 exception path는 처음부터 IAR을 읽어 interrupt ID를 넘기지 않는다. ICC_HPPIR0_EL1의 1020/1021 sentinel을 S-EL1/NS type으로 매핑하고 handler에 INTR_ID_UNAVAILABLE을 전달한다. handler 구현의 acknowledge·EOI 책임은 각 서비스 코드에서 따로 확인한다.
SCR 라우팅은 현재 security state에 따라 line이 달라진다
기본 GICv3 platform mapping에서 S-EL1은 Secure context의 IRQ, NS context의 FIQ다. NS type은 반대다. EL3 type은 양쪽 FIQ다. 등록 flags가 이 line을 EL3에 trap할지 결정하며, 그 자체가 GIC group bit를 바꾸지는 않는다.
pending/group · type/line · dispatch
등록 API의 type 전제: register_interrupt_type_handler()는 NULL handler와 flags mask를 검사한 뒤, type을 검증하는 set_routing_model()보다 먼저 intr_type_descs[type]를 읽는다. 따라서 caller는 유효한 type을 넘겨야 한다. 임의의 범위 밖 type까지 안전하게 -EINVAL로 거부한다고 해석하면 안 된다. 고정 원문 193–220행.
DEEP ANALYSIS
설정과 예외 처리의 검증 표
아래는 TF-A LTS 2.14.3의 기본 GICv3 platform glue를 기준으로 한다. weak 함수를 플랫폼이 바꿨다면 대상 빌드의 정의를 우선한다.
| 조건 | 고정 소스의 반응 | 읽을 위치 |
|---|---|---|
| driver data NULL, GICD 0, rdistif 수 0, 주소 배열 NULL, EL3 아님 | gicv3_driver_init()의 assert. 반환 error code가 아님 | gicv3_main.c 100–113 |
| GICD ARE_S가 꺼진 채 PE Redistributor init | gicv3_rdistif_init() assert | gicv3_main.c 227–241 |
| secure SPI/SGI/PPI property가 G0·G1S 이외 | helper의 group assert; G1NS는 기본값으로 설정 | gicv3_helpers.c 219–280, 337–386 |
| handler가 NULL·flags 부적합·동일 type 재등록 | -EINVAL 또는 -EALREADY; 성공 후 type별 handler 저장 | interrupt_mgmt.c 193–220 |
| pending type invalid·지원되지 않거나 미등록 handler | EL3 exception path가 handler 호출 없이 복귀 | runtime_exceptions.S 546–598 |
GIC driver · property helper · handler registry · EL3 vector
OBJECT LIFETIME
값이 보관되는 곳과 범위
| 상태 | 저장 위치·생산자 | 읽는 주체 |
|---|---|---|
| GICD/GICR 주소 배열 | 플랫폼이 제공; 조건부 GICR probe가 배열 내용을 채움 | GIC driver와 각 PE 초기화 |
| GICD SPI group/route | distif_init 및 후속 명시적 API의 MMIO write | Distributor delivery |
| PE별 GICR·ICC state | rdistif_init, cpuif_enable | 그 PE의 SGI/PPI 및 CPU interface |
| handler·routing flags | BL31 정적 intr_type_descs[type] | SCR context 설정과 EL3 exception dispatch |
FAILURE PATH
증상에서 첫 확인 지점까지
| 증상 | 먼저 확인할 값 | 소스상 경계 |
|---|---|---|
| secondary PE에서 SGI/PPI가 오지 않음 | MPIDR→core slot, 해당 GICR 주소·wake·group·enable | driver probe / rdistif_init |
| secure SPI가 기대한 type으로 분류되지 않음 | GICD IGROUPR·IGRPMODR, platform property, route MPIDR | secure_spis_config_props / type mapping |
| EL3 vector까지 왔으나 handler가 불리지 않음 | pending type 1020/1021/1023, 등록 handler, routing flags | runtime_exceptions.S lookup |
| 한 번 처리한 interrupt가 재진입 | 선택된 handler의 acknowledge·EOI/active 처리 | 서비스별 handler; vector만으로 결론 불가 |
드라이버의 void init 함수를 일반적인 오류 반환·cleanup 단계로 그리지 않는다. 여러 실패 전제는 assert이고, MMIO/하드웨어 관찰은 대상 보드에서 검증해야 한다.
EVIDENCE
고정 원문과 보드에서 확인할 증거
이 검토는 공식 소스 대조와 브라우저 QA까지 수행했다. TF-A 빌드와 보드 실행은 하지 않았다.
| 자료 | 확인할 값 | 판정 범위 |
|---|---|---|
| GIC driver + helper | GICD/GICR/ICC 쓰기와 init 전제 | 소스상 그룹 설정 |
| platform GICv3 glue + 공식 API | G0/G1S/G1NS의 type·IRQ/FIQ mapping | 기본 weak 구현; 플랫폼 override 확인 |
| BL31 registry + vector | handler 등록 실패값·pending type·NULL 경로 | EL3 dispatch 계약 |
| 대상 보드 register dump / 허용된 trace | GICD·GICR group, ICC enable, SCR bit, handler entry | 실제 플랫폼 동작 |
LAB
대상 보드에서 분리해 확인할 세 질문
- 01group bit가 의도한 type인가?
한 SPI와 한 PPI를 골라 IGROUPR·IGRPMODR와
plat_ic_get_interrupt_type()결과를 비교한다. PPI는 실행 PE의 GICR을 읽는다. - 02SCR routing은 어느 security state의 line인가?
등록 type과 flags, Secure/Non-secure context의 SCR IRQ/FIQ bit를 함께 기록한다. ICC_SRE만 보고 routing을 판단하지 않는다.
- 03EL3 handler가 실제 호출·완료됐는가?
pending type, handler pointer, handler 내부의 acknowledge ID와 EOI를 같은 interrupt에 대해 기록한다. 실제 보드의 예외 처리기와 충돌하지 않는 시험 설정에서 수행한다.
GIC 그룹, 예외 라우팅, 최종 처리자를 나눠 봅니다
조회 시 2.15.0인 TF-A 문서에서 GICv3의 Group 0, Group 1 Secure, Group 1 Non-secure는 각각 EL3·Secure-EL1·Non-secure interrupt 유형과 연결됩니다. 그러나 interrupt 유형의 이름이 CPU가 처음 진입하는 EL을 항상 결정하지는 않습니다. Secure-EL1 interrupt가 EL3를 거쳐 전달되더라도 최종 처리는 Secure-EL1이 담당할 수 있습니다. 플랫폼 interrupt-controller API
현재 실행 보안 상태, 플랫폼의 FIQ/IRQ 신호 매핑, SCR_EL3.FIQ/IRQ와 SPD의 routing model을 함께 확인합니다. 같은 신호를 쓰는 유형들은 독립적으로 라우팅할 수 없습니다. 예를 들어 Secure-EL1/EL0 실행 중 EL3·Non-secure 유형이 FIQ를 공유하면 한 유형의 EL3 라우팅 설정이 다른 유형에도 영향을 줍니다. 라우팅 모델은 EL3 아래에서 실행 중인 경우의 규칙입니다. Interrupt Management Framework
위의 LTS 2.14.3 발췌에서 ICC_SRE_EL3를 설정하는 과정은 CPU interface의 system-register 접근을 여는 단계입니다. 이것만으로 모든 IRQ/FIQ가 EL3로 향하거나 EL3에서 최종 처리된다고 결론 내리지 않습니다. 보드의 group 설정과 실제 수신 EL·최종 handler를 별도로 대조해야 합니다.
PRIMARY REFERENCES