Trusted Firmware-A · source analysis

GICv3 Group 0/1 interrupt routing

Distributor, Redistributor와 CPU interface를 초기화하고 secure interrupt를 EL3 또는 S-EL1로 라우팅하는 경로를 읽습니다.

표의 버전은 소스 분석 기준이며 최신 보안 버전 권고가 아닙니다. TF-A LTS 2.14.3 이후에는 보안 수정이 있습니다. 제품 적용 시 공식 변경 기록과 사용 플랫폼의 errata를 확인하세요.

Series
10 / 12
Baseline
LTS 2.14.3
Commit
f5e765a3443f
Source
drivers/arm/gic/v3/gicv3_main.c:76-164 (발췌 범위)

GICv3 Group 0/1 interrupt routing 단계에서 실제로 바뀌는 상태는 무엇인가?

interrupt ID만 보지 말고 group, priority, security state, route target과 EOI/deactivate 책임을 함께 본다.

secure interrupt는 설정된 group과 routing model에 따라 한 security state의 handler로만 전달되고 CPU interface enable 순서가 지켜져야 한다. 이 문장을 기준으로 코드를 위에서 아래로 읽으면, 함수 이름을 외우는 대신 어느 시점에 어떤 상태를 신뢰할 수 있는지 판단할 수 있다.

객체와 주소가 놓이는 구조

그림 1. GICv3 Group 0/1 interrupt routing에서 입력, 내부 상태, 출력의 경계
입력과 전제내부 상태외부로 공개되는 결과
01gicv3_driver_data_t
02GICD/GICR frames
03interrupt group
04SCR routing bits

GICv3 distributor/redistributor state를 중심에 놓고 왼쪽의 입력이 어떤 검사를 거쳐 오른쪽 결과로 공개되는지 표시했다. 실제 디버깅에서는 각 블록의 주소와 크기를 로그에 대입한다.

실행 흐름

그림 2. 정상 경로의 주요 호출과 상태 전달
platform GIC data
Distributor init
Redistributor discover
CPU interface
interrupt routing

화살표는 단순 호출 순서만 뜻하지 않는다. 각 단계가 성공을 반환할 때 다음 단계가 읽을 수 있는 상태가 무엇인지 함께 확인한다. 오류 반환이 발생하면 바로 다음 화살표로 진행하지 않고 해당 단계의 정리 경로를 따라간다.

단계별 입력과 출력

각 단계의 입력과 처리 후 바뀌는 상태를 정리한 표다. 사용 중인 소스 버전에서 다른 필드를 변경한다면 그에 맞춰 표도 수정한다.

#단계진입 시 신뢰할 상태성공 뒤 남아야 할 상태다음 소비자
01platform GIC dataEL3 initialization and interrupt contextgicv3_driver_data_tDistributor init
02Distributor initplatform GIC data 완료 상태GICD/GICR framesRedistributor discover
03Redistributor discoverDistributor init 완료 상태interrupt groupCPU interface
04CPU interfaceRedistributor discover 완료 상태SCR routing bitsinterrupt routing
05interrupt routingCPU interface 완료 상태SCR routing bits이 단계의 처리 결과를 사용하는 코드

분석 범위의 전제와 비교해, 다음 단계에 잘못된 입력을 넘긴 부분부터 조사한다.

주소와 객체의 이동을 그림으로 읽기

아래 그림은 주소, 객체를 사용하는 기간, 제어권을 넘기는 시점을 중심으로 정리했다. 실제 주소와 크기는 사용 중인 보드의 bdinfo, 맵 파일과 링커 심벌로 확인한다.

그림 3. GICv3 Group 0/1 interrupt routing의 실행 순서

각 칸은 제어권이 다음 단계로 넘어가기 전에 확정되어야 하는 상태를 나타낸다.

01platform GIC data
02Distributor init
03Redistributor discover
04CPU interface
05interrupt routing
그림 4. GIC interrupt group과 실행 world

두 열은 실행 주체와 접근 권한, 객체를 해제할 책임이 다른 경계를 비교한다.

Group 0 / Secure

01secure priority

02EL3 또는 S-EL1 routing

03secure handler가 EOI

04NS에서 mask/변경 제한

Group 1NS / Normal

01Linux IRQ

02NS priority mask

03NS handler가 EOI

04EL3 routing 정책 적용

원본 코드

아래 코드는 Trusted Firmware-A LTS 2.14.3의 drivers/arm/gic/v3/gicv3_main.c에서 76-164줄을 그대로 가져온 것이다. 설명을 위해 실제 코드를 가짜 의사 코드로 바꾸지 않았다.

commitf5e765a3443fe21154aa908228e75ee2600085f6anchor · L100void __init gicv3_driver_init(
76			(ctx)->gicd_##reg[(int_id - (MIN_ESPI_ID -	\
77			round_up(TOTAL_SPI_INTR_NUM, 1U << REG##R_SHIFT)))\
78						>> REG##R_SHIFT]);	\
79		}							\
80	} while (false)
81
82#define SAVE_GICD_EREGS(base, ctx, intr_num, reg, REG)			\
83	do {								\
84		for (unsigned int int_id = MIN_ESPI_ID; int_id < (intr_num);\
85				int_id += (1U << REG##R_SHIFT)) {	\
86			(ctx)->gicd_##reg[(int_id - (MIN_ESPI_ID -	\
87			round_up(TOTAL_SPI_INTR_NUM, 1U << REG##R_SHIFT)))\
88			>> REG##R_SHIFT] = gicd_read_##reg((base), int_id);\
89		}							\
90	} while (false)
91#else
92#define SAVE_GICD_EREGS(base, ctx, intr_num, reg, REG)
93#define RESTORE_GICD_EREGS(base, ctx, intr_num, reg, REG)
94#endif /* GIC_EXT_INTID */
95
96/*******************************************************************************
97 * This function initialises the ARM GICv3 driver in EL3 with provided platform
98 * inputs.
99 ******************************************************************************/
100void __init gicv3_driver_init(const gicv3_driver_data_t *plat_driver_data)
101{
102	unsigned int gic_version;
103	unsigned int gicv2_compat;
104
105	assert(plat_driver_data != NULL);
106	assert(plat_driver_data->gicd_base != 0U);
107	assert(plat_driver_data->rdistif_num != 0U);
108	assert(plat_driver_data->rdistif_base_addrs != NULL);
109
110	assert(IS_IN_EL3());
111
112	assert((plat_driver_data->interrupt_props_num == 0U) ||
113			(plat_driver_data->interrupt_props != NULL));
114
115	/* Check for system register support */
116#ifndef __aarch64__
117	assert((read_id_pfr1() &
118			(ID_PFR1_GIC_MASK << ID_PFR1_GIC_SHIFT)) != 0U);
119#else
120	assert((read_id_aa64pfr0_el1() &
121			(ID_AA64PFR0_GIC_MASK << ID_AA64PFR0_GIC_SHIFT)) != 0U);
122#endif /* !__aarch64__ */
123
124	gic_version = gicd_read_pidr2(plat_driver_data->gicd_base);
125	gic_version >>= PIDR2_ARCH_REV_SHIFT;
126	gic_version &= PIDR2_ARCH_REV_MASK;
127
128	/* Check GIC version */
129#if !GIC_ENABLE_V4_EXTN
130	assert(gic_version == ARCH_REV_GICV3);
131#endif
132	/*
133	 * Find out whether the GIC supports the GICv2 compatibility mode.
134	 * The ARE_S bit resets to 0 if supported
135	 */
136	gicv2_compat = gicd_read_ctlr(plat_driver_data->gicd_base);
137	gicv2_compat >>= CTLR_ARE_S_SHIFT;
138	gicv2_compat = gicv2_compat & CTLR_ARE_S_MASK;
139
140	if (plat_driver_data->gicr_base != 0U) {
141		/*
142		 * Find the base address of each implemented Redistributor interface.
143		 * The number of interfaces should be equal to the number of CPUs in the
144		 * system. The memory for saving these addresses has to be allocated by
145		 * the platform port
146		 */
147		gicv3_rdistif_base_addrs_probe(plat_driver_data->rdistif_base_addrs,
148						   plat_driver_data->rdistif_num,
149						   plat_driver_data->gicr_base,
150						   plat_driver_data->mpidr_to_core_pos);
151#if !HW_ASSISTED_COHERENCY
152		/*
153		 * Flush the rdistif_base_addrs[] contents linked to the GICv3 driver.
154		 */
155		flush_dcache_range((uintptr_t)(plat_driver_data->rdistif_base_addrs),
156			plat_driver_data->rdistif_num *
157			sizeof(*(plat_driver_data->rdistif_base_addrs)));
158#endif
159	}
160	gicv3_driver_data = plat_driver_data;
161
162	/*
163	 * The GIC driver data is initialized by the primary CPU with caches
164	 * enabled. When the secondary CPU boots up, it initializes the

발췌 범위와 읽기 기준

원문 76-164줄에는 앞뒤 문맥이 포함됩니다. 기준 구문 void __init gicv3_driver_init(은 L100에 있습니다. 발췌 첫 줄을 함수 정의의 시작으로 해석하지 않습니다.

interrupt ID만 보지 말고 group, priority, security state, route target과 EOI/deactivate 책임을 함께 본다.

함께 읽어야 하는 원본 코드

첫 코드 조각만으로 동작이 완성되지 않는 경우 호출 매크로, 객체 정의와 실제 실행 목록을 같은 페이지에 묶었다. 각 조각은 같은 기준 commit에서 가져왔다.

01. 한 CPU의 GIC system-register interface 활성화

drivers/arm/gic/v3/gicv3_main.c 265-355줄이다.

filedrivers/arm/gic/v3/gicv3_main.canchor · L277void gicv3_cpuif_enable(unsigned int proc_num)
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줄이다.

filedrivers/arm/gic/v3/gicv3_main.canchor · L227void gicv3_rdistif_init(unsigned int proc_num)
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();

내부 동작을 더 깊게 읽기

01

진입 조건을 먼저 고정한다

platform GIC data에서 들어온 실행은 EL3 initialization and interrupt context에 놓여 있다. 이때 interrupt, MMU/cache, stack, heap 중 무엇이 이미 준비되었는지 소스의 호출자까지 올라가 확인한다. 같은 함수라도 SPL, relocation 전후, app thread처럼 호출 문맥이 달라지면 허용되는 API와 지연 시간이 달라진다.

interrupt ID만 보지 말고 group, priority, security state, route target과 EOI/deactivate 책임을 함께 본다.

02

중심 객체의 생성과 공개를 나눈다

이 글의 중심 객체는 GICv3 distributor/redistributor state다. 메모리를 확보한 시점, 필드를 채운 시점, 전역 list나 다른 subsystem에 공개한 시점을 구분한다. 공개 뒤 오류가 발생한다면 목록에서 제거하고 child, buffer, reference를 역순으로 정리하는지 확인한다.

빌드 산출물 관점에서는 최종 부트로더 이미지 안에 해당 symbol과 section이 실제로 포함되었는지도 map과 objdump로 검증한다.

03

주소, 크기와 정렬을 계산한다

부트 코드에서는 주소 계산 오류를 주의해야 한다. 원본과 목적지의 주소 범위, 헤더에 기록된 데이터 크기, 블록·페이지 단위를 표로 정리하고 각 구간의 끝 주소를 계산한다. 끝 주소가 start + size - 1처럼 마지막 바이트를 가리키는지, 구간 바로 다음 주소를 가리키는지는 API 규약에서 확인한다.

04

성공 flag와 실제 완료 시점을 맞춘다

Distributor init → Redistributor discover → CPU interface 구간에서는 부분 초기화 상태가 생길 수 있다. flag, list insertion, callback 등록, storage write 완료 중 무엇이 성공의 기준인지 찾는다. hardware write나 DMA가 포함되면 함수 반환과 장치 완료가 같은 시점인지도 확인한다.

다른 CPU, 인터럽트 처리기, USB 완료 콜백, 셸 명령에서도 이 상태를 읽는다면 메모리 접근 순서와 잠금 범위를 함께 확인한다.

05

제어권을 넘기기 전에 확인할 조건을 정리한다

정상 경로는 interrupt routing에서 끝난다. 이 단계가 함수 반환인지, scheduler 전환인지, 다른 image로의 비복귀 분기인지 구분한다. 비복귀 handoff라면 cache clean/invalidate, interrupt disable, 장치 quiesce, argument register와 FDT 또는 image address가 최종 점검 항목이다.

호출한 함수로 돌아오는 경로라면 오류와 일부 처리만 완료된 상태를 구분하는지 확인한다. 이어서 다음 후보를 시도할지, 복구 절차를 실행할지 살펴본다.

구현을 읽을 때 놓치기 쉬운 부분

01

platform GIC data에서 interrupt routing까지 제어권이 이동하는 조건

Distributor, Redistributor와 CPU interface를 초기화하고 secure interrupt를 EL3 또는 S-EL1로 라우팅하는 경로를 읽습니다. 이 경로는 함수 호출 목록만 외워서는 연결되지 않는다. platform GIC data → Distributor init → Redistributor discover → CPU interface → interrupt routing 순서에서 각 단계가 읽는 입력, 새로 확정하는 상태, 다음 단계에 넘기는 값을 구분해야 한다. 특히 EL3 initialization and interrupt context에서는 이전 단계가 남긴 register와 memory attribute가 C 코드의 전제 조건이 된다.

interrupt ID만 보지 말고 group, priority, security state, route target과 EOI/deactivate 책임을 함께 본다. 따라서 첫 지점에서 GICv3 distributor/redistributor state의 주소와 owner를 기록하고, 마지막 지점에서 같은 값이 그대로 유지되는지 아니면 새 객체로 교체되는지를 확인한다. 중간 함수가 성공을 반환해도 secure interrupt는 설정된 group과 routing model에 따라 한 security state의 handler로만 전달되고 CPU interface enable 순서가 지켜져야 한다.

02

gicv3_driver_data_t와 SCR routing bits의 생성 시점과 수명

이 글에서 함께 나타나는 객체는 gicv3_driver_data_t, GICD/GICR frames, interrupt group, SCR routing bits이다. 이름이 비슷해도 저장 위치와 수명은 다르다. build-time descriptor인지, boot 단계의 임시 객체인지, world switch 뒤에도 남는 runtime 객체인지 나눠야 pointer를 따라가다 다른 단계의 구조체를 같은 것으로 오해하지 않는다.

GICv3 distributor/redistributor state을 기준으로 allocation 또는 정적 배치 위치, list/table에 공개되는 시점, 참조가 끊기는 시점을 적는다. 그 다음 source와 destination 범위, per-CPU 여부, secure/non-secure 접근 권한을 map과 runtime log로 대조한다. 이 절차를 거치면 단순한 호출 순서가 아니라 실제 소유권 이동이 보인다.

03

성공 로그만으로 놓치기 쉬운 오류

대표적인 실패 조건은 GICR affinity 불일치: secondary CPU interrupt 없음; group 오설정: Normal World 노출; EOI 누락: interrupt 재진입/정지이다. 이 문제들은 대개 fault가 발생한 함수보다 앞에서 만들어진 잘못된 주소, size, security state 또는 refcount 때문에 생긴다. 마지막 출력만 보지 말고 각 경계 직전의 상태를 한 줄씩 남겨 최초 불일치 지점을 찾는다.

재현에는 GICD IGROUPR/IGRPMODR dump; secure timer interrupt route 변경; secondary CPU의 GICR base와 MPIDR 대조를 사용한다. 정상 경로와 실패 경로에서 같은 필드를 같은 위치에 출력하고, 실패가 검증 단계에서 차단되는지 아니면 다음 context까지 전파되는지 비교한다. firmware와 secure world에서는 실패 뒤의 cleanup 또는 reset 경로도 정상 경로만큼 중요하다.

레지스터에서 오류 판정까지 상세 분석

GICv3 초기화는 Distributor base를 쓰는 하나의 루틴이 아니다. GICD는 전역 interrupt group과 routing을, 각 GICR frame은 CPU별 SGI/PPI와 redistributor state를, ICC_* system register는 현재 PE의 CPU interface를 담당한다.

write_icc_sre_el3()는 ICC_SRE_EL3의 GIC system-register interface 접근 정책을 설정한다. 이름이 비슷한 SCR_EL3를 쓰는 명령이 아니며, 그 자체로 IRQ/FIQ의 EL3 routing을 설정하지 않는다. CPU interface 활성화와 context management의 SCR 설정을 서로 다른 단계로 추적해야 한다.

secure interrupt 경로를 이해하려면 interrupt group, priority, route target, SCR_EL3의 IRQ/FIQ routing, SPD가 기대하는 secure interrupt model을 동시에 봐야 한다. 한 요소만 맞아도 interrupt가 pending 상태에 머물거나 다른 world에서 acknowledge될 수 있다.

그림 5. 이 경로를 통과하는 다섯 개의 진입 계약
01GICD/GICR base

MMIO 범위와 frame stride가 실제 SoC memory map과 일치해야 한다.

02rdistif_num/MPIDR hash

각 PE가 정확히 하나의 GICR_TYPER affinity와 대응해야 한다.

03interrupt property array

ID, group, priority, configuration이 유효해야 한다.

04ICC_SRE_EL3

system register interface enable bit가 EL3/하위 EL 정책과 맞아야 한다.

05SCR_EL3 routing

FIQ/IRQ routing이 interrupt group과 SPD model을 일관되게 EL3로 보낸다.

각 계약은 앞 단계가 생산하고 현재 단계가 검증한 뒤 다음 소비자에게 넘기는 상태다. 한 항목이라도 확인되지 않으면 뒤 단계의 fault를 그 지점의 문제로 단정하지 않는다.

진입 레지스터와 메모리 계약

함수 첫 줄에 도달했을 때 이미 참이라고 가정하는 값과, 그 값이 틀렸을 때 영향을 받는 범위를 함께 적었다.

#입력 상태생산자정상 조건확인 이유
01GICD/GICR baseplatform gicv3_driver_dataMMIO 범위와 frame stride가 실제 SoC memory map과 일치해야 한다.모든 distributor/redistributor 접근의 기준이다.
02rdistif_num/MPIDR hashplatform topology각 PE가 정확히 하나의 GICR_TYPER affinity와 대응해야 한다.secondary CPU interface 초기화 대상을 찾는다.
03interrupt property arrayplatform secure interrupt listID, group, priority, configuration이 유효해야 한다.Group0/Group1S/Group1NS 분류를 만든다.
04ICC_SRE_EL3CPU interface initsystem register interface enable bit가 EL3/하위 EL 정책과 맞아야 한다.ICC_* register 접근 가능 여부를 결정한다.
05SCR_EL3 routingcontext managementFIQ/IRQ routing이 interrupt group과 SPD model을 일관되게 EL3로 보낸다.어느 vector가 interrupt를 받는지 결정한다.

핵심 구조체 필드의 생산자, 소비자와 수명

구조체 이름만 나열하지 않고 어떤 코드가 값을 쓰고, 어느 코드가 처음 읽으며, 언제까지 주소와 내용이 유지되어야 하는지 구분했다.

#객체 또는 필드생산자소비자수명과 불변 조건
01gicv3_driver_data_tplatform setupGICv3 common driverBL31 runtime 동안 유지되며 base와 callback table이 유효해야 한다.
02GICD group/config/route registersdriver inithardware distributorglobal interrupt policy로 reset 또는 명시적 변경까지 유지된다.
03GICR frame stateper-CPU initlocal SGI/PPI deliveryCPU power cycle마다 sleep/wake와 enable 복원이 필요하다.
04ICC_PMR/BPR/IGRPENCPU interface enablecurrent PE interrupt selectionCPU별 state이며 world switch/power management 정책과 맞아야 한다.
05pending/active interrupthardware acknowledgeEL3/SPD/OS handlerEOI와 deactivate가 완료될 때까지 동일 interrupt owner가 관리한다.
06interrupt property descriptorsplatform constant tabledriver init초기화 때 소비되지만 runtime 재설정이 있으면 resident 수명을 확인한다.

함수 내부 실행 순서

소스의 큰 분기와 side effect를 실행 순서대로 다시 펼쳤다. breakpoint는 이 목록의 경계에 두고, 다음 번호로 넘어갈 때 새로 유효해진 객체를 기록한다.

  1. 01

    platform이 GICD base, GICR region, MPIDR-to-core callback과 secure interrupt property를 등록한다.

  2. 02

    driver가 GIC architecture version과 frame 정보를 검증하고 redistributor를 affinity별로 탐색한다.

  3. 03

    primary CPU가 Distributor를 disable/정규화하고 group, priority, configuration, route를 설정한다.

  4. 04

    각 CPU가 자신의 GICR frame을 wake하고 SGI/PPI group과 enable state를 초기화한다.

  5. 05

    ICC_SRE_EL3와 CPU interface register를 설정하고 priority mask와 binary point를 정한다.

  6. 06

    Group0/Group1S enable과 SCR_EL3 routing을 secure payload dispatcher 모델에 맞춘다.

  7. 07

    interrupt 발생 시 IAR에서 ID를 읽고 group/owner에 따라 EL3 handler 또는 secure payload로 전달한다.

  8. 08

    handler completion 뒤 EOIR과 필요 시 DIR을 올바른 순서로 써 active state를 해제한다.

  9. 09

    CPU suspend/hotplug 경로에서 redistributor와 CPU interface state를 저장·복원한다.

빌드 설정이 바꾸는 실제 코드 경로

동일한 함수 이름이라도 아래 설정에 따라 포함되는 source, 구조체 크기, 인자 의미와 failure path가 달라진다.

#설정바뀌는 동작확인 방법
01GICV3_SUPPORT_GIC600 계열 workaround특정 구현 erratum과 register sequence를 추가한다.SoC GIC revision과 적용 workaround를 기록한다.
02GICV3_IMPL_GIC600_MULTICHIPmulti-chip routing/register 구성이 추가된다.chip address와 SPI route 범위를 확인한다.
03EL3_EXCEPTION_HANDLINGEL3 interrupt framework가 직접 secure interrupt를 처리할 수 있다.등록 handler와 SCR routing을 함께 본다.
04SPD interrupt modelsecure interrupt를 EL3에서 넘기는 방식이 달라진다.Group 설정과 dispatcher의 interrupt entry를 대조한다.

증상에서 최초 불일치 지점까지 추적하기

마지막 panic 메시지가 아니라 어디에서 멈추고 무엇을 읽어 어떤 결론을 내릴지 정리했다. 정상값과 실패값은 같은 build와 같은 위치에서 비교한다.

#관찰 증상중단 위치기록할 값판정
01SPI가 pending인데 CPU에 오지 않음GICD pending/route와 CPU IARgroup, enable, route MPIDR, PMRDistributor routing과 CPU priority mask를 순서대로 확인한다.
02secondary CPU에서 PPI만 없음gicv3_rdistif_initGICR_TYPER affinity, WAKER, PPI enableredistributor frame 매핑 오류를 찾는다.
03secure timer가 Linux IRQ로 보임group configuration과 SCRIGROUPR/IGRPMODR, SCR IRQ/FIQgroup 분류와 EL3 routing 중 불일치 지점을 판정한다.
04한 번 처리한 interrupt가 계속 재진입handler exitIAR ID, EOIR/DIR write, active bitEOI mode와 deactivate 누락을 확인한다.

객체와 수명

대상만들어지는 시점유효 범위확인할 조건
GICv3 distributor/redistributor stateDistributor initinterrupt routing 또는 오류 정리 완료까지진입 전제와 상태 계약
입력 buffer / metadataplatform GIC dataparse와 검증이 끝날 때까지길이, 정렬, 소유권, 변조 가능성
등록된 list / descriptorRedistributor discover하위 시스템을 종료하거나 다음 이미지에 제어권을 넘길 때까지중복 등록, 해제된 객체를 가리키는 포인터, 오류 후 자원 정리
hardware 또는 persistent state실제 write/probe가 완료된 뒤reset 또는 명시적 해제·갱신까지쓰기 완료, 시간 초과, 전원 차단, 이전 상태 복원
최종 부트로더 이미지link/image 생성 시점다음 stage가 새 image로 교체할 때까지적재 주소, 진입점, 섹션, 헤더의 일치 여부

실패 지점과 증상

#조건관찰되는 증상먼저 볼 단계
01GICR affinity 불일치secondary CPU interrupt 없음Distributor init
02group 오설정Normal World 노출Redistributor discover
03EOI 누락interrupt 재진입/정지CPU interface

로그가 끊긴 함수뿐 아니라 그 함수에 주소, 크기, 플래그를 전달한 앞 단계도 조사한다. 오류 처리 후 등록된 객체나 하드웨어 설정이 그대로 남아 있는지도 확인한다.

소스 밖에서 확인할 증거

소스에서 파악한 동작을 실제 빌드 결과와 대상 보드의 로그로 확인한다. 아래 명령의 보드 이름과 툴체인 접두사는 사용 중인 빌드 환경에 맞게 바꾼다.

#목적명령 또는 계측판정 기준
01빌드 산출물make PLAT=<platform> DEBUG=1 all fipBL1, BL2, BL31과 FIP가 같은 설정으로 만들어졌는지 전체 빌드 명령부터 기록한다.
02FIP 구성tools/fiptool/fiptool info build/<platform>/debug/fip.binFIP 안의 BL31, BL32, BL33 UUID와 offset, 크기를 확인해 실제 적재 입력을 고정한다.
03심볼과 주소${CROSS_COMPILE}nm -n build/<platform>/debug/bl31/bl31.elf | grep 'void __init gicv3_driver_init'대상 함수가 BL31의 어느 주소와 섹션에 놓였는지 확인한다.
04EL3 명령 추적${CROSS_COMPILE}objdump -drS build/<platform>/debug/bl31/bl31.elfC 코드가 EL3 system register 접근과 eret 경로로 어떻게 번역됐는지 대조한다.
05실행 시점 증거TF-A DEBUG log + CurrentEL/SCR_EL3/SPSR_EL3/x0-x3 기록어느 exception level에서 어떤 security state와 인자를 다음 이미지에 넘겼는지 serial log로 남긴다.

직접 확인할 실험

  1. 01
    GICD IGROUPR/IGRPMODR dump

    Distributor init 진입 전후에 gicv3_driver_data_t의 주소·크기·반환값과 timestamp를 함께 남긴다.

  2. 02
    secure timer interrupt route 변경

    Redistributor discover 진입 전후에 GICD/GICR frames의 주소·크기·반환값과 timestamp를 함께 남긴다.

  3. 03
    secondary CPU의 GICR base와 MPIDR 대조

    CPU interface 진입 전후에 interrupt group의 주소·크기·반환값과 timestamp를 함께 남긴다.

원문과 다음 글