tick_init()

 

커널 v2.6.21에서 tickless라는 개념이 도입 되기전 커널에서는 각 cpu의 스케쥴러들은 고정된 주기(hz)의 time tick을 받아 태스크들의 스케쥴링을 수행했다. time tick을 줄여서 그냥 tick으로 불리고 있다. 현재는 커널 v3.10에 이르러 다음과 같이 3가지의 커널 옵션을 구분해서 사용한다.

  • CONFIG_HZ_PERIODIC
    • cpu의 idle 상태와 상관 없이 기존 커널과 같이 항상 tick을 발생한다.
    • 커널 버전 및 응용에 따라 다음 중 하나의 hz를 사용한다.
      • 100hz, 200hz, 250hz, 300hz, 500hz, 1000hz
        • rpi2: 100hz
  • CONFIG_NO_HZ_IDLE
    • cpu가 idle 상태로 들어가면 tick을 끈다.
      • 최대 1000hz -> 0hz로 줄여 전력 소모를 대폭 줄인다.
    • rcu callback 처리가 남아 있는 경우 해당 cpu는 no hz 모드로 진입하지 못한다.
    • rpi2: 현재 이 모드를 사용한다.
    • dynticks idle 또는 tickless idle 이라고도 불린다.
    • 참고: Clockevents and dyntick | LWN.net
  •  CONFIG_NO_HZ_FULL
    • cpu가 idle 상태로 들어가면 tick을 끈다.
      • 최대 1000hz -> 0hz로 줄여 전력 소모를 대폭 줄인다.
    • rcu callback 처리가 남아 있는 경우 해당 cpu는 no hz 모드로 진입하지 못한다.
    • single task가 동작중인 경우 tick을 1Hz 로 낮춘다. (많은 경우에 해당한다)
      • 최대 1000hz -> 1hz로 줄여 성능이 빨라지는 효과가 있다.
      • 디버깅 모드에서 1hz가 아니라 no hz로 바꾸어 문제점 분석에 사용할 수 있다.
    • full dynticks 또는 full tickless 라고도 불린다.
    • “nohz_full=” 부트 타임 커널 파라메터를 사용하는 경우에만 동작시킬 수 있다.
      • 설정되지 않는 경우 CONFIG_NO_HZ_IDLE 커널 옵션과 동일하게 동작한다.
      • 예)
        • “nohz_full=0-3”
          • cpu#0~#3까지 적용
        • “nohz_full=4,8-15”
          • cpu#4, #8~#15까지 적용
    • 참고:

 

1 HZ

  • 초당 하나의 타이머 인터럽트

 

NO_HZ

  • 특징
    • 최소한 하나의 cpu는 주기적으로  tick을 받는다.
    • SMP에서 유효하다.
    • 구현을 위해 하드웨어적으로 hr-timer가 필요하다.
  • 장점
    • 전력 소모가 크게 줄어 든다.
  • 단점
    • 시간 계산과 RCU callback 처리를 위해 구현이 복잡해졌다.
    • rcu callback 처리가 남아 있는 경우 해당 cpu는 no hz 모드로 진입하지 못한다.

 

Tick Broadcast

cpu가 깊은 idle 상태에 있을 때 tick broadcast를 수신받아 idle 상태에서 벗어난 후 리스케쥴 여부를 확인하고 진행할 태스크가 있는 경우 수행을 하게 한다.

  • 실행할 task가 없으면 cpu는 cpuidle_idle_call() 함수를 통해 idle loop 상태에 진입한다.
    • bootup을 담당한 첫 번째 cpu는 rest_init() 함수의 마지막 cpu_startup_entry() -> cpu_idle_loop()에서 idle 루프를 돈다.
    • 그 외 cpu 들을 online 상태로 변경하는 경우 secondary_start_kernel() 함수의 마지막 cpu_startup_entry() -> cpu_idle_loop()에서 idle 루프를 돈다.
  • Tick이 발생하여 리스케쥴링이 발생하는 경우 idle 상태를 벗어난다.
    • no hz에서 tick이 없는 경우 tick broadcast에 의해 깨어나 idle 상태를 탈출할 수 있다.
  • tick device 사용
    • 클럭소스는 clock_event_device를 사용한다.
    • tick_device 구조체를 사용하여 표현한다.
    • tick device 모드
      • periodic 모드
        • tick_broadcast_mask cpu 비트맵을 대상으로 tick_broadcast_start_periodic() 함수를 사용해 broadcast tick을 주기적으로 보낼 수 있다.
      • oneshot 모드
    • tick 디바이스의 등록 함수
      • tick_install_broadcast_device(newdev)

 

Generic clock events

  • tick 구현에 대한 generic core 루틴

 

tick_init()

kernel/time/tick-common.c

/**
 * tick_init - initialize the tick control
 */
void __init tick_init(void)
{
        tick_broadcast_init();
        tick_nohz_init();
}

tick broadcast framework 및 full nohz framework을 준비한다.

 

tick_broadcast_init()

kernel/time/tick-broadcast.c

void __init tick_broadcast_init(void)
{
        zalloc_cpumask_var(&tick_broadcast_mask, GFP_NOWAIT);
        zalloc_cpumask_var(&tick_broadcast_on, GFP_NOWAIT);
        zalloc_cpumask_var(&tmpmask, GFP_NOWAIT);
#ifdef CONFIG_TICK_ONESHOT
        zalloc_cpumask_var(&tick_broadcast_oneshot_mask, GFP_NOWAIT);
        zalloc_cpumask_var(&tick_broadcast_pending_mask, GFP_NOWAIT);
        zalloc_cpumask_var(&tick_broadcast_force_mask, GFP_NOWAIT);
#endif
}

tick broadcast framework을 준비한다.

  • tick_broadcast_mask
    • idle(sleep) 모드에 있는 cpu 비트맵
  • tick_broadcast_on
    • 주기적으로 broadcast가 수행되는 cpu 비트맵
  • tick_broadcast_oneshot_mask
    • oneshot으로 broadcast 해야 할 cpu 비트맵
  • tick_broadcast_pending_mask
    • broadcast가 지연된 cpu 비트맵
  • tick_broadcast_force_mask
    • 강제로 broadcast해야 할 cpu 비트맵
  • 참고: The tick broadcast framework | LWN.net

 

tick_nohz_init()

kernel/time/tick-sched.c

void __init tick_nohz_init(void)
{
        int cpu;

        if (!tick_nohz_full_running) {
                if (tick_nohz_init_all() < 0)
                        return;
        }

        if (!alloc_cpumask_var(&housekeeping_mask, GFP_KERNEL)) {
                WARN(1, "NO_HZ: Can't allocate not-full dynticks cpumask\n");
                cpumask_clear(tick_nohz_full_mask);
                tick_nohz_full_running = false; 
                return;
        }

        /*
         * Full dynticks uses irq work to drive the tick rescheduling on safe
         * locking contexts. But then we need irq work to raise its own
         * interrupts to avoid circular dependency on the tick 
         */
        if (!arch_irq_work_has_interrupt()) {
                pr_warning("NO_HZ: Can't run full dynticks because arch doesn't "
                           "support irq work self-IPIs\n");
                cpumask_clear(tick_nohz_full_mask);
                cpumask_copy(housekeeping_mask, cpu_possible_mask);
                tick_nohz_full_running = false;
                return;
        }
        
        cpu = smp_processor_id();

        if (cpumask_test_cpu(cpu, tick_nohz_full_mask)) {
                pr_warning("NO_HZ: Clearing %d from nohz_full range for timekeeping\n", cpu);
                cpumask_clear_cpu(cpu, tick_nohz_full_mask);
        }

        cpumask_andnot(housekeeping_mask,
                       cpu_possible_mask, tick_nohz_full_mask);

        for_each_cpu(cpu, tick_nohz_full_mask)
                context_tracking_cpu_set(cpu);

        cpu_notifier(tick_nohz_cpu_down_callback, 0);
        pr_info("NO_HZ: Full dynticks CPUs: %*pbl.\n",
                cpumask_pr_args(tick_nohz_full_mask));
}

CONFIG_NO_HZ_FULL 커널 옵션을 사용한 경우 full tickless(no hz)로 동작을 하기 위한 framework을 준비한다.

  • 코드 라인 5~8에서 “nohz_full=” 부트 타임 커널 파라메터를 사용하지 않은 경우 처리를 포기한다.
  • 코드 라인 10~15에서 housekeeping_mask에 cpu 마스크를 할당한다. 할당이 실패하는 경우 처리를 포기한다.
  • 코드 라인 22~29에서 SMP 머신이 아닌 경우 처리를 포기한다.
  • 코드 라인 31~36에서 tick_nohz_fullmask에서 현재 cpu에 해당하는 비트를 클리어한다.
  • 코드 라인 38~39에서 housekeeping_mask에 possible cpu들에 대해 nohz full이 설정되지 않은 cpu들만 설정한다.
    • housekeeping_mask <- cpu_possible_mask & ~tick_nohz_full_mask
  • 코드 라인 41~42에서 CONFIG_CONTEXT_TRACKING 커널 옵션을 사용하는 경우 nohz full 설정된 cpu들에 대해서만 context tracking을 허용하도록 설정한다.
  • 코드 라인 44에서 cpu 상태 변화 시 호출되도록 우선 순위를 0으로 cpu notify chain에 tick_nohz_cpu_down_callback() 함수를 추가한다.
  • 코드 라인 45~46에서 “NO_HZ: Full dynticks CPUs:”  정보 메시지를 출력한다.

 

참고

Interrupts -2- (irq chip)

<kernel v5.4>

IRQ Chip

인터럽트 컨트롤러 드라이버를 위해 hw 제어를 담당하는 구현 부분을 가진다.

  • 여러 제조사의 인터럽트 컨트롤러들은 각 인터럽트 라인의 통제 방법이 각각 다르다.
  • 리눅스 IRQ 코어 레이어에서 irq chip은 다양한 인터럽트 컨트롤러의 라인별 제어 액션을 통일하여 처리하도록 구현되었다.
    • 인터럽트 라인마다  마스킹 또는 set/clear 동작을 수행하는 서비스를 제공한다.
    • irq_chip에 있는 여러 개의 후크 포인터에 연결된 콜백 함수를 통해 처리한다.
      • (*irq_mask)
      • (*irq_unmask)
      • (*irq_set_type)
    • 각 제조사의 인터럽트 컨트롤러 디바이스 드라이버에는 irq_chip의 후크에 연결될 처리 함수들을 제공해야 한다.
  • 인터럽트 라인의 마스킹 및 set/clear 처리 유형 등의 처리가 각각 다른 경우 irq_chip을 분리하여 구성할 수 있다.
  • 인터럽트 라인 개개별로 h/w 제어를 담당하는 irq_chip을 다음 함수를 사용하여 지정한다.
    • irq_set_chip()

 

다음 그림은 하나의 인터럽트 컨트롤러가 대응하는 모든 인터럽트들을 하나의 irq_chip에서 제어하는 모습을 보여준다.

 

다음 그림은 하나의 인터럽트 컨트롤러가 대응하는 인터럽트들 중 h/w 제어 기능이 서로 다른 부분(part)들을 나누어 각각의 irq_chip에서 제어하는 모습을 보여준다.

 

다음 그림은 한 개의 디바이스 드라이버는 2 개의 irq_chip 구현을 가지고 있고, 또 다른 한 개의 디바이스 드라이버는 1 개의 irq_chip 구현을 가지고 있는 모습을 자세히 보여준다.

 

hierarchy irq chip 구성

2 개 이상의 인터럽트 컨트롤러를 hierarchy하게 구성하여 사용할 수 있다.

 

다음 그림은 두 개 이상 hierarchy 구성된 인터럽트 컨트롤러들이 연결되어 처리되는 모습을 보여준다.

  • 자식 인터럽트 컨트롤러 A에서 수신한 인터럽트들은 cascade(chained)로 부모 인터럽트 컨트롤러 B에 전달된다.

 

GPIO cascade 인터럽트 연동

인터럽트 컨트롤러 아래에 gpio 등에서 인터럽트의 멀티플렉싱이 가능한 장치들이 추가로 cascade 연결된 경우 이들의 하위 인터럽트 라인을 식별하기 위해 cascade 연동을 한다. 다음 GPIO 글에서 관련 연동 방법을 소개하기로 한다.

 


Device Tree 기반의 인터럽트 컨트롤러 초기화

irqchip_init()

drivers/irqchip/irqchip.c

void __init irqchip_init(void)
{
        of_irq_init(__irqchip_of_table);
        acpi_probe_device_table(irqchip);
}

디바이스 트리 및 ACPI가 지정한 인터럽트 컨트롤러의 초기화 함수를 호출한다.

  • 코드 라인 3에서 __irqchip_of_table 섹션에 있는 of_device_id 구조체들을 검사하여 매치되는 인터럽트 컨트롤러 초기화 함수를 찾아 호출한다.
    • rpi2:
      • 2 개의 인터럽트 컨트롤러 드라이버 호출
        • drivers/irqchip/irq-bcm2836.c – bcm2836_arm_irqchip_l1_intc_of_init()
        • drivers/irqchip/irq-bcm2835.c – bcm2835_armctrl_of_init()
    • rock960
      • 1 개의 인터럽트 컨트롤러 드라이버 호출
        • drivers/irqchip/irq-gic-v3.c – gic_of_init()
  • 코드 라인 4에서 ACPI가 지정한 인터럽트 컨트롤러의 초기화 함수를 호출한다.

 

of_irq_init()

drivers/of/irq.c -1/2-

/**
 * of_irq_init - Scan and init matching interrupt controllers in DT
 * @matches: 0 terminated array of nodes to match and init function to call
 *
 * This function scans the device tree for matching interrupt controller nodes,
 * and calls their initialization functions in order with parents first.
 */
void __init of_irq_init(const struct of_device_id *matches)
{
        const struct of_device_id *match;
        struct device_node *np, *parent = NULL;
        struct of_intc_desc *desc, *temp_desc;
        struct list_head intc_desc_list, intc_parent_list;

        INIT_LIST_HEAD(&intc_desc_list);
        INIT_LIST_HEAD(&intc_parent_list);

        for_each_matching_node_and_match(np, matches, &match) {
                if (!of_property_read_bool(np, "interrupt-controller") ||
                                !of_device_is_available(np))
                        continue;

                if (WARN(!match->data, "of_irq_init: no init function for %s\n",
                         match->compatible))
                        continue;

                /*
                 * Here, we allocate and populate an of_intc_desc with the node
                 * pointer, interrupt-parent device_node etc.
                 */
                desc = kzalloc(sizeof(*desc), GFP_KERNEL);
                if (!desc) {
                        of_node_put(np);
                        goto err;
                }

                desc->irq_init_cb = match->data;
                desc->dev = of_node_get(np);
                desc->interrupt_parent = of_irq_find_parent(np);
                if (desc->interrupt_parent == np)
                        desc->interrupt_parent = NULL;
                list_add_tail(&desc->list, &intc_desc_list);
        }

Device Tree에 있는 인터럽트 컨트롤러와 매치되는 인터럽트 컨트롤러의 초기화 함수를 호출한다. 단 2개 이상의 인터럽트 컨트롤러를 사용하는 경우 상위 인터럽트 컨트롤러부터 초기화한다.

  • 코드 라인 8~9에서 임시로 사용되는 리스트 2개를 초기화한다.
    • intc_desc_list:
      • irqchip 테이블의 이름과 Device Tree의 인터럽트 컨트롤러 드라이버명(compatible)으로 매치되어 구성된 desc 구조체 리스트
        • ARM 임베디드 시스템은 보통 1 ~ 2개의 인터럽트 컨트롤러를 사용한다.
    • intc_parent_list:
      • 초기화 성공한 인터럽트 컨트롤러의 desc 구조체 리스트로 최상위 인터럽트 컨트롤러가 가장 앞으로 구성된다.
  • 코드 라인 11~14에서 DTB 트리의 모든 노드에서 irqchip 테이블의 이름 과 Device Tree의 인터럽트 컨트롤러 드라이버명(compatible)으로 일치한 노드들에서 “interrupt-controller” 속성을 못찾았거나 “status” 속성이 “ok”가 아닌 경우 skip 한다.
  • 코드 라인 24~28에서 of_intc_dest 구조체를 할당받아 온다.
  • 코드 라인 30~34에서 할당받은 구조체를 설정한다.
    • desc->dev에 인터럽트 컨트롤러 노드를 가리키게한다.
    • desc->interrupt_parent에 상위 인터럽트 컨트롤러 노드를 가리키게 한다. 만일 상위 인터럽트 컨트롤러가 자기 자신을 가리키면 null을 대입한다.
    • 참고: 상위 인터럽트 컨트롤러를 찾는 법
      • “interrupt-parent” 속성이 위치한 노드가 가리키는 phandle 값을 알아온 후 그 값으로 노드를 검색하여 알아온다.
  • 코드 라인 35에서 intc_desc_list 임시 리스트의 후미에 할당받은 구조체를 추가한다.

 

drivers/of/irq.c -2/2-

        /*
         * The root irq controller is the one without an interrupt-parent.
         * That one goes first, followed by the controllers that reference it,
         * followed by the ones that reference the 2nd level controllers, etc.
         */
        while (!list_empty(&intc_desc_list)) {
                /*
                 * Process all controllers with the current 'parent'.
                 * First pass will be looking for NULL as the parent.
                 * The assumption is that NULL parent means a root controller.
                 */
                list_for_each_entry_safe(desc, temp_desc, &intc_desc_list, list) {
                        int ret;

                        if (desc->interrupt_parent != parent)
                                continue;

                        list_del(&desc->list);

                        of_node_set_flag(desc->dev, OF_POPULATED);

                        pr_debug("of_irq_init: init %pOF (%p), parent %p\n",
                                 desc->dev,
                                 desc->dev, desc->interrupt_parent);
                        ret = desc->irq_init_cb(desc->dev,
                                                desc->interrupt_parent);
                        if (ret) {
                                of_node_clear_flag(desc->dev, OF_POPULATED);
                                kfree(desc);
                                continue;
                        }

                        /*
                         * This one is now set up; add it to the parent list so
                         * its children can get processed in a subsequent pass.
                         */
                        list_add_tail(&desc->list, &intc_parent_list);
                }

                /* Get the next pending parent that might have children */
                desc = list_first_entry_or_null(&intc_parent_list,
                                                typeof(*desc), list);
                if (!desc) {
                        pr_err("of_irq_init: children remain, but no parents\n");
                        break;
                }
                list_del(&desc->list);
                parent = desc->dev;
                kfree(desc);
        }

        list_for_each_entry_safe(desc, temp_desc, &intc_parent_list, list) {
                list_del(&desc->list);
                kfree(desc);
        }
err:
        list_for_each_entry_safe(desc, temp_desc, &intc_desc_list, list) {
                list_del(&desc->list);
                of_node_put(desc->dev);
                kfree(desc);
        }
}
  • 코드 라인 6에서 intc_desc_list 리스트의 모든 엔트리가 없어질 때까지 루프를 돈다.
  • 코드 라인 12에서 intc_desc_list 리스트의 desc 엔트리에 대해 루프를 돈다.
  • 코드 라인 15~16에서 남은 인터럽트 컨트롤러 중 최상위가 아닌 경우 skip 한다.
  • 코드 라인 18~20에서 initc_desc_list에서 하나를 제거하고, OF_POPULATED 플래그를 설정한다.
  • 코드 라인 22~24에서 매치되어 사용할 인터럽트 컨트롤러 드라이버 이름과 주소 그리고 부모 인터럽트 컨트롤러 주소 정보를 출력한다.
    • “of_irq_init: init <driver_name> @ <addr>, parent <addr>”
  • 코드 라인 25~31에서 매치된 of_device_id 구조체의 data에서 인터럽트 컨트롤러 드라이버 시작 함수를 호출한다.
  • 코드 라인 37에서 초기화 성공한 인터럽트 컨트롤러 디스크립터 구조체 정보를 intc_parent_list 라는 이름의 임시 리스트에 추가한다.
    • 부모 없는 child 인터럽트 컨트롤러가 있는지 오류 체크를 위함
  • 코드 라인 41~46에서 초기화 성공한 인터럽트 컨트롤러가 없으면 “of_irq_init: children remain, but no parents” 메시지를 출력하고 처리를 중단한다.
    • A: 조부모 IC <- B: 부모 IC, C: 아들 IC 구성 시
      • A-> B -> C 순서대로 초기화되어야 한다.
  • 코드 라인 47~49에서 임시 변수 parent에 처리한 인터럽트 컨트롤러 노드를 가리키게 하고 intc_desc_list 라는 이름의 임시 리스트에서 제거한다.
  • 코드 라인 52~61에서 임시로 사용했던 intc_parent_list 및 intc_desc_list에 등록된 desc 구조체를 모두 할당 해제한다.

 

다음 그림은 2개의 인터럽트 컨트롤러에 대해 상위 인터럽트 컨트롤러의 초기화 함수부터 호출되는 것을 보여준다.

 

irqchip 테이블

__irqchip_of_table

  • .init.data 섹션에서 .dtb.init.rodata 바로 뒤에 위치한다.
  • 엔트리들은 of_device_id 구조체로 구성된다.
  • __irqchip_of_table = .; *(__irqchip_of_table) *(__irqchip_of_table_end)
    • arch/arm64/kernel/vmlinux.lds

 

드라이버 내에서 irqchip 초기화 선언

case 1) rock960용 gic-v3 드라이버

gic-v3 드라이버는 다음 기본 드라이버 이외에 시스템 구성에 따라 gic-v3-its, gic-v3-mbi 등 다양한 드라이버가 추가 호출될 수 있다.

drivers/irqchip/irq-gic-v3.c

IRQCHIP_DECLARE(gic_v3, "arm,gic-v3", gic_of_init);
  • __irqchip_of_table 섹션 위치에 of_device_id 구조체가 다음과 같이 정의 된다.
    • .compatible = “arm,gic-v3”
    • .data = gic_of_init()

 

case 2) rpi2용 2 개의 인터럽트 컨트롤러 드라이버

rpi2용 인터럽트 컨트롤러 드라이버는 두 개의 드라이버를 사용한다.

drivers/irqchip/irq-bcm2835.c

IRQCHIP_DECLARE(bcm2835_armctrl_ic, "brcm,bcm2835-armctrl-ic", armctrl_of_init);

 

drivers/irqchip/irq-bcm2836.c

IRQCHIP_DECLARE(bcm2836_arm_irqchip_l1_intc, "brcm,bcm2836-l1-intc",
                bcm2836_arm_irqchip_l1_intc_of_init);

 

IRQCHIP_DECLARE()

drivers/irqchip/irqchip.h

/*
 * This macro must be used by the different irqchip drivers to declare
 * the association between their DT compatible string and their
 * initialization function.
 *      
 * @name: name that must be unique accross all IRQCHIP_DECLARE of the
 * same file.
 * @compstr: compatible string of the irqchip driver
 * @fn: initialization function
 */
#define IRQCHIP_DECLARE(name, compat, fn) OF_DECLARE_2(irqchip, name, compat, fn)

irq_chip 디바이스 드라이버를 구성할 때 사용하는 선언문으로 여기서 만들어진 of_device_id 구조체는 __irqchip_of_table 섹션에 등록된다.

 

include/linux/of.h

#define OF_DECLARE_2(table, name, compat, fn) \
                _OF_DECLARE(table, name, compat, fn, of_init_fn_2)

 

include/linux/of.h

#define _OF_DECLARE(table, name, compat, fn, fn_type)                   \
        static const struct of_device_id __of_table_##name              \
                __used __section(__##table##_of_table)                  \
                 = { .compatible = compat,                              \
                     .data = (fn == (fn_type)NULL) ? fn : fn  }

 


Chip 관련 설정

하나의 irq 디스크립터에 담당 Chip 지정

irq_set_chip()

kernel/irq/chip.c

/**
 *      irq_set_chip - set the irq chip for an irq
 *      @irq:   irq number
 *      @chip:  pointer to irq chip description structure
 */
int irq_set_chip(unsigned int irq, struct irq_chip *chip)
{
        unsigned long flags;
        struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);

        if (!desc)
                return -EINVAL;

        if (!chip)
                chip = &no_irq_chip;

        desc->irq_data.chip = chip;
        irq_put_desc_unlock(desc, flags);
        /*
         * For !CONFIG_SPARSE_IRQ make the irq show up in
         * allocated_irqs.
         */
        irq_mark_irq(irq);
        return 0;
}
EXPORT_SYMBOL(irq_set_chip);

irq 디스크립터에 해당 irq를 마스킹 또는 set/clear 동작을 시킬 수 있는 irq chip 정보를 설정한다.

  • 코드 라인 9~10에서 만일 인터럽트 컨트롤러 chip을 사용하지 않은 경우  no_irq_chip(name=”none”) 구조체 정보를 대신 대입한다.
  • 코드 라인 12에서 irq 디스크립터의 chip_data에 chip 정보를 기록한다.
  • 코드 라인 18에서 Sparse IRQ를 사용하지 않는 경우allocated_irqs 비트맵에 요청 irq에 해당하는 비트를 mark하여 irq가 사용됨을 표시한다.

 

irq_mark_irq()

kernel/irq/irqdesc.c

void irq_mark_irq(unsigned int irq)
{       
        mutex_lock(&sparse_irq_lock);
        bitmap_set(allocated_irqs, irq, 1);
        mutex_unlock(&sparse_irq_lock);
}

Sparse IRQ를 사용하지 않는 경우 전역 allocated_irqs 비트맵을 사용하여 irq 번호에 해당하는 비트를 설정하여 irq가 사용됨을 표시한다.

  • ARM64 시스템은 디폴트로 CONFIG_SPARSE_IRQ를 사용하므로 위의 비트맵 관리를 하지 않는다.

 

 


Generic Core 인터럽트 핸들러

irq 디스크립터 기반으로 핸들러를 지정하고 인터럽트 발생 시 이들이 호출될 수 있는 generic 인터럽트 핸들링을 할 수 있는 API들이 준비되어 있다.

 

다음 4단계의 인터럽트 핸들러 처리 루틴을 알아본다.

  • CPU Exception(or 인터럽트) 벡터
    • 인터럽트 발생 시 cpu에 처음 진입부
  • 인터럽트 Chip 핸들러
    • 인터럽트 발생 시 담당 인터럽트 컨트롤러가 최초 처리할 핸들러
  • Flow Handler
    • 각 인터럽트 번호마다 인터럽트 flow 유형별 처리를 지정하는데, 보통 커널에 마련된 generic default flow 핸들러를 사용하거, custom 핸들러를 등록하여 사용한다.
  • 최종 디바이스의 인터럽트 핸들러
    • 최종 사용자 디바이스 드라이버에서 해당 인터럽트를 처리하기 위한 핸들러

 

다음 그림은 단계별로 나뉜 인터럽트 핸들러가 처리되는 과정을 보여준다.

 

다음 그림은 GIC v3 인터럽트 컨트롤러를 사용하여 단계별로 인터럽트 핸들러가 처리되는 과정을 보여준다.

 

다음 그림은 RPI2용 두 개의 인터럽트 컨트롤러가 cascade 연결 구성하여 단계별로 인터럽트 핸들러가 처리되는 과정을 보여준다.

 

다음 그림은 GIC v3 인터럽트 컨트롤러에서 ppi 중 특정 인터럽트가 irq 파티션으로 cascade 연결 구성하여 단계별로 인터럽트 핸들러가 처리되는 과정을 보여준다.

 

irq별 flow 핸들러 설정

irq_set_handler()

include/linux/irq.h

static inline void
irq_set_handler(unsigned int irq, irq_flow_handler_t handle)
{
        __irq_set_handler(irq, handle, 0, NULL);
}

요청한 @irq에 대해 사용될 인터럽트 핸들러를 설정한다.

 

chained irq flow 핸들러 설정

irq_set_chained_handler()

include/linux/irq.h

/*
 * Set a highlevel chained flow handler for a given IRQ.
 * (a chained handler is automatically enabled and set to
 *  IRQ_NOREQUEST, IRQ_NOPROBE, and IRQ_NOTHREAD) 
 */
static inline void
irq_set_chained_handler(unsigned int irq, irq_flow_handler_t handle)
{
        __irq_set_handler(irq, handle, 1, NULL);
}

요청한 @irq에 대해 하위 cascade 연결된 인터럽트 컨트롤러에게 인터럽트를 전달할 목적으로 사용되는 chained 핸들러를 설정한다.

  • rpi2: 로컬 인터럽트 컨트롤러가 부모이고 hwirq=8에 chained 핸들러를 설정한다.
    • chained handler: bcm2836_chained_handle_irq()

 

__irq_set_handler()

kernel/irq/chip.c

void
__irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
                  const char *name)
{
        unsigned long flags;
        struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, 0);

        if (!desc)
                return;

        __irq_do_set_handler(desc, handle, is_chained, name);
        irq_put_desc_busunlock(desc, flags);
}
EXPORT_SYMBOL_GPL(__irq_set_handler);

@irq에 대해 irq 디스크립터에 대한 lock을 획득한채로 irq flow 핸들러를 지정한다.

  • 코드 라인 6~9에서 irq 디스크립터에 대한 lock을 획득한다.
    • 세 번째 인자에 대해 0을 지정하여 칩에 대한 락은 획득하지 않는다.
  • 코드 라인 11에서 irq 핸들러를 설정하기 위해 호출한다.
  • 코드 라인 12에서 irq 디스크립터에 대한 lock을 해제한다.

 

__irq_do_set_handler()

kernel/irq/chip.c

static void
__irq_do_set_handler(struct irq_desc *desc, irq_flow_handler_t handle,
                     int is_chained, const char *name)
{
        if (!handle) {
                handle = handle_bad_irq;
        } else {
                struct irq_data *irq_data = &desc->irq_data;
#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
                /*
                 * With hierarchical domains we might run into a
                 * situation where the outermost chip is not yet set
                 * up, but the inner chips are there.  Instead of
                 * bailing we install the handler, but obviously we
                 * cannot enable/startup the interrupt at this point.
                 */
                while (irq_data) {
                        if (irq_data->chip != &no_irq_chip)
                                break;
                        /*
                         * Bail out if the outer chip is not set up
                         * and the interrupt supposed to be started
                         * right away.
                         */
                        if (WARN_ON(is_chained))
                                return;
                        /* Try the parent */
                        irq_data = irq_data->parent_data;
                }
#endif
                if (WARN_ON(!irq_data || irq_data->chip == &no_irq_chip))
                        return;
        }

        /* Uninstall? */
        if (handle == handle_bad_irq) {
                if (desc->irq_data.chip != &no_irq_chip)
                        mask_ack_irq(desc);
                irq_state_set_disabled(desc);
                if (is_chained)
                        desc->action = NULL;
                desc->depth = 1;
        }
        desc->handle_irq = handle;
        desc->name = name;

        if (handle != handle_bad_irq && is_chained) {
                unsigned int type = irqd_get_trigger_type(&desc->irq_data);

                /*
                 * We're about to start this interrupt immediately,
                 * hence the need to set the trigger configuration.
                 * But the .set_type callback may have overridden the
                 * flow handler, ignoring that we're dealing with a
                 * chained interrupt. Reset it immediately because we
                 * do know better.
                 */
                if (type != IRQ_TYPE_NONE) {
                        __irq_set_trigger(desc, type);
                        desc->handle_irq = handle;
                }

                irq_settings_set_noprobe(desc);
                irq_settings_set_norequest(desc);
                irq_settings_set_nothread(desc);
                desc->action = &chained_action;
                irq_activate_and_startup(desc, IRQ_RESEND);
        }
}

요청한 irq 디스크립터에 인터럽트 flow 핸들러와 이름을 대입하고 activate 한다.

  • 코드 라인 5~6에서 인자 @handle이 지정되지 않은 경우 인터럽트 핸들러로 handle_bad_irq() 함수를 대신 사용한다.
  • 코드 라인 7~33에서 커널이 irq 도메인 hierarchy를 지원하는 경우 핸들러가 설정되지 않은 최상위 irq 디스크립터를 찾는다.
    • 2 개 이상의 인터럽트 컨트롤러 칩을 거치는 경우 irq_data가 parent irq_data에 연결되어 구성된다.
  • 코드 라인 36~43에서 지정된 핸들러 함수가 없는 경우 irq 상태를 disable로 변경하고 depth=1로 설정한다. 기존에 chip 정보가 지정된 경우 irq를 mask 상태로 바꾼다.
  • 코드 라인 44~45에서 핸들러 함수와 이름을 대입한다.
  • 코드 라인 47~68에서 핸들러 함수가 지정되었고 chain 걸린 경우 irq 상태를 noprobe, norequest, nothread로 바꾸고 irq를 enable하고 activate 한다.
    • irq_desc->irq_data->state_use_accessors에 _IRQ_NOPROBE, _IRQ_NOREQUEST, _IRQ_NOTHREAD 플래그를 추가한다.

 

chip 및 IRQ 핸들러 설정

irq_set_chip_and_handler()

include/linux/irq.h

static inline void irq_set_chip_and_handler(unsigned int irq, struct irq_chip *chip,
                                            irq_flow_handler_t handle)
{
        irq_set_chip_and_handler_name(irq, chip, handle, NULL);
}

irq 디스크립터에 chip, flow handler를 대입한다. 단 이름(name)에는 null을 대입한다.

 

irq_set_chip_and_handler_name()

kernel/irq/chip.c

void
irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
                              irq_flow_handler_t handle, const char *name)
{
        irq_set_chip(irq, chip);
        __irq_set_handler(irq, handle, 0, name);
}
EXPORT_SYMBOL_GPL(irq_set_chip_and_handler_name);

irq 디스크립터에 chip 정보를 대입한다. 그리고 flow 핸들러와 이름을 대입하다.

 

per-cpu 지원  IRQ 설정

irq_set_percpu_devid()

kernel/irq/irqdesc.c

int irq_set_percpu_devid(unsigned int irq)
{
        return irq_set_percpu_devid_partition(irq, NULL);
}

@irq 번호에 대해 per-cpu 인터럽트로 설정한다.

  • GIC 컨트롤러등에서 SGI/PPI 인터럽트들은 같은 번호로 대응하는 모든 cpu에 대해 처리할 수 있다.
  • NULL을 입력하는 경우 모든 cpu들을 대상으로 지정한다.

 

irq_set_percpu_devid_partition()

kernel/irq/irqdesc.c

int irq_set_percpu_devid_partition(unsigned int irq,
                                   const struct cpumask *affinity)
{
        struct irq_desc *desc = irq_to_desc(irq);

        if (!desc)
                return -EINVAL;

        if (desc->percpu_enabled)
                return -EINVAL;

        desc->percpu_enabled = kzalloc(sizeof(*desc->percpu_enabled), GFP_KERNEL);

        if (!desc->percpu_enabled)
                return -ENOMEM;

        if (affinity)
                desc->percpu_affinity = affinity;
        else
                desc->percpu_affinity = cpu_possible_mask;

        irq_set_percpu_devid_flags(irq);
        return 0;
}

요청 irq를 per-cpu(코어별로 라우팅되는) 처리 용도로 준비한다. (@affinity가 null인 경우 모든 possible cpu에 대해 지정한다)

  • 코드 라인 4~7에서 요청 irq번호에 맞는 irq 디스크립터가 없는 경우 -EINVAL 에러를 반환한다.
  • 코드 라인 9~10에서 이미 per-cpu로 설정된 경우 -EINVAL 에러를 반환한다.
  • 코드 라인 12~15에서 cpu 비트맵을 할당하여 percpu_enabled에 대입한다. 할당이 실패한 경우 -ENOMEM 에러를 반환한다.
  • 코드 라인 17~20에서 @affinity 설정이 있으면 해당 affinity cpu들에 대해 지정하고, null인 경우 모든 possible cpu를 대상으로 지정한다.
  • 코드 라인 22에서 irqd에 noautoen, per_cpu, nothread, noprobe, per_cpu_devid 플래그를 설정한다.
  • 코드 라인 23에서 정상 값 0을 반환한다.

참고: genirq: Add support for per-cpu dev_id interrupts 

 

irq_set_percpu_devid_flags()

include/linux/irq.h

static inline void irq_set_percpu_devid_flags(unsigned int irq)
{
        irq_set_status_flags(irq,
                             IRQ_NOAUTOEN | IRQ_PER_CPU | IRQ_NOTHREAD |
                             IRQ_NOPROBE | IRQ_PER_CPU_DEVID);
}

irq 상태로 noautoen, per_cpu, nothread, noprobe, per_cpu_devid 플래그를 설정한다.

 


generic 인터럽트 flow 핸들러 수행

generic_handle_irq()

kernel/irq/irqdesc.c

/**
 * generic_handle_irq - Invoke the handler for a particular irq
 * @irq:        The irq number to handle
 *
 */
int generic_handle_irq(unsigned int irq)
{
        struct irq_desc *desc = irq_to_desc(irq);

        if (!desc)
                return -EINVAL;
        generic_handle_irq_desc(irq, desc);
        return 0;
}
EXPORT_SYMBOL_GPL(generic_handle_irq);

요청한 @irq 번호에 해당하는 generic 핸들러 함수를 호출한다.

 

generic_handle_irq_desc()

include/linux/irqdesc.h

/*
 * Architectures call this to let the generic IRQ layer
 * handle an interrupt.
 */
static inline void generic_handle_irq_desc(unsigned int irq, struct irq_desc *desc)
{
        desc->handle_irq(irq, desc);
}

요청한 @irq 디스크립터에 등록한 generic 핸들러 함수를 호출한다.

 

다양한 generic 인터럽트 flow 핸들러들

generic 인터럽트 핸들러가 각각의 형태별로 미리 준비되어 있다. 이들을 간단히 알아보자.

  • handle_percpu_irq()
    • per-cpu용 인터럽트 핸들러
    • ack -> handle_irq_event_percpu() 호출 -> eoi
  • handle_level_irq()
    • 레벨 타입 트리거 설정된 경우 사용할 인터럽트 핸들러
    • mask_ack -> handle_irq_event() 호출 -> unmask(oneshot 스레드 완료시)
  • handle_simple_irq()
    • 별도의 ack, mask, unmask, eoi 등의 HW 처리가 전혀 필요 없는 핸들러이다.
    • handle_irq_event() 호출
  • handle_fasteoi_irq()
    • transparent 컨트롤러들을 위한 핸들러
    • mask(oneshot 일때) -> preflow 핸들러 호출 -> handle_irq_event() 호출 -> eoiunmask(oneshot 스레드 완료시)
  • handle_edge_irq()
    • 엣지 타입 트리거 설정된 경우 사용할 인터럽트 핸들러
    • handle_level_irq()와 다른 점은 mask/unmask 처리를 하지 않는다.
    • ack -> handle_irq_event() 호출
  • handle_edge_eoi_irq()
    • 엣지 eoi 타입 트리거 설정된 경우 사용할 인터럽트 핸들러
    • powerpc 아키텍처에서만 사용하는 특수한 형태이다.
    • handle_irq_event() 호출 -> eoi
  •  handle_nested_irq()
    •  irq thread로부터의 nested irq 핸들러
    • action->(*thread_fn) 호출
  • handle_percpu_devid_irq()
    • per-cpu용 인터럽트 핸들러
    • ack -> action->(*handler) 호출 -> eoi
  • handle_fasteoi_nmi()
    • Pesudo-NMI로 사용되는 인터럽트 핸들러
    • -> action->(*handler) 호출 -> eoi
  • handle_percpu_devid_fasteoi_nmi()
    • Pesudo-NMI로 사용되는 per-cpu 타입 인터럽트 핸들러
    • -> action->(*handler) 호출 -> eoi

 

다음 그림은 커널에 준비된 generic 인터럽트 핸들러들의 기능을 보여준다.

 

다음 그림은 타이머 인터럽트 핸들러가 호출되는 과정을 보여준다.

  • 1단계: exception vector
  • 2단계: controller 핸들러
  • 3단계: irq 라인(디스크립터)에 설정된 generic core 인터럽트 핸들러 (hierarchy 가능)
  • 4단계: 최종 consumer 디바이스에 위치한 인터럽트 핸들러(action에 등록된)
  • 5단계(option): consumer 디바이스는 별도의 dispatch 이벤트 핸들러를 사용하기도 한다.

 

핸들러 함수 -1- (level)

handle_level_irq()

kernel/irq/chip.c

/**
 *      handle_level_irq - Level type irq handler
 *      @irq:   the interrupt number
 *      @desc:  the interrupt description structure for this irq
 *
 *      Level type interrupts are active as long as the hardware line has
 *      the active level. This may require to mask the interrupt and unmask
 *      it after the associated handler has acknowledged the device, so the
 *      interrupt line is back to inactive.
 */
void    
handle_level_irq(unsigned int irq, struct irq_desc *desc)
{
        raw_spin_lock(&desc->lock);
        mask_ack_irq(desc);

        if (!irq_may_run(desc))
                goto out_unlock;

        desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
        kstat_incr_irqs_this_cpu(irq, desc);

        /*
         * If its disabled or no action available
         * keep it masked and get out of here
         */ 
        if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
                desc->istate |= IRQS_PENDING;
                goto out_unlock;
        }                               
                                        
        handle_irq_event(desc);
                        
        cond_unmask_irq(desc);

out_unlock:                
        raw_spin_unlock(&desc->lock);
}               
EXPORT_SYMBOL_GPL(handle_level_irq);

레벨 타입의 트리거를 가진 인터럽트 핸들러로 인터럽트 처리 전에 mask와 ack 처리를 수행하고 인터럽트 처리 후에 조건부로 unmask를 수행한다.

  • 코드 라인 5에서 인터럽트 컨트롤러를 통해 mask와 ack 처리를 한다.
  • 코드 라인 7~8에서 irq의 실행이 곧 준비되지 않을 것 같으면 인터럽트 처리를 포기하고 빠져나간다.
  • 코드 라인 10에서 istate에서 replay 및 waiting 플래그를 제거한다.
  • 코드 라인 11에서 해당 인터럽트 카운터를 증가시킨다.
  • 코드 라인 17~20에서 irq 디스크립터에 action 핸들러가 없거나 disable 설정된 경우 istate에 pending 플래그를 추가하고 함수를 빠져나간다.
  • 코드 라인 22에서 irq 디스크립터의 istate에서 pending 플래그를 제거하고, 모든 action에 등록한 인터럽트 핸들러들을 호출하여 수행한다. 수행 중인 동안에는 irq 진행중 상태가 유지된다.
  • 코드 라인 24에서 조건에 따라 unmask 처리를 수행한다.

 

핸들러 함수 -2- (percpu, devid)

handle_percpu_devid_irq()

kernel/irq/chip.c

/**
 * handle_percpu_devid_irq - Per CPU local irq handler with per cpu dev ids
 * @desc:       the interrupt description structure for this irq
 *
 * Per CPU interrupts on SMP machines without locking requirements. Same as
 * handle_percpu_irq() above but with the following extras:
 *
 * action->percpu_dev_id is a pointer to percpu variables which
 * contain the real device id for the cpu on which this handler is
 * called
 */
void handle_percpu_devid_irq(struct irq_desc *desc)
{
        struct irq_chip *chip = irq_desc_get_chip(desc);
        struct irqaction *action = desc->action;
        unsigned int irq = irq_desc_get_irq(desc);
        irqreturn_t res;

        /*
         * PER CPU interrupts are not serialized. Do not touch
         * desc->tot_count.
         */
        __kstat_incr_irqs_this_cpu(desc);

        if (chip->irq_ack)
                chip->irq_ack(&desc->irq_data);

        if (likely(action)) {
                trace_irq_handler_entry(irq, action);
                res = action->handler(irq, raw_cpu_ptr(action->percpu_dev_id));
                trace_irq_handler_exit(irq, action, res);
        } else {
                unsigned int cpu = smp_processor_id();
                bool enabled = cpumask_test_cpu(cpu, desc->percpu_enabled);

                if (enabled)
                        irq_percpu_disable(desc, cpu);

                pr_err_once("Spurious%s percpu IRQ%u on CPU%u\n",
                            enabled ? " and unmasked" : "", irq, cpu);
        }

        if (chip->irq_eoi)
                chip->irq_eoi(&desc->irq_data);
}

요청 irq의 generic per-cpu 핸들러로, action에 등록한 핸들러 함수를 호출 시 irq의 현재 cpu에 대한 dev_id를 인수로 전달한다. 핸들러 함수 호출 전후로 ack 및 eoi 처리를 한다.

  • 코드 라인 17에서 요청한 irq 디스크립터의 action에 등록한 per-cpu dev_id 값을 알아온다.
  • 코드 라인 12에서 현재 cpu에 대한 kstat 카운터를 증가시킨다.
  • 코드 라인 14~15에서 핸들러 함수 호출 전에 irq_chip의 irq_ack 콜백이 등록된 경우 호출한다.
  • 코드 라인 17~30에서 등록된 action 핸들러 함수를 호출한다. 호출 시 irq 번호와 dev_id를 인수로 넘겨준다. 현재 cpu에 해당하는 action 핸들러 함수가 없는 경우 disable 한다.
  • 코드 라인 32~33에서 핸들러 함수 호출 후에 irq_chip의 irq_eoi 콜백이 등록된 경우 호출한다.

 

핸들러 함수 -3- (fasteoi)

handle_fasteoi_irq()

kernel/irq/chip.c

/**
 *      handle_fasteoi_irq - irq handler for transparent controllers
 *      @desc:  the interrupt description structure for this irq
 *
 *      Only a single callback will be issued to the chip: an ->eoi()
 *      call when the interrupt has been serviced. This enables support
 *      for modern forms of interrupt handlers, which handle the flow
 *      details in hardware, transparently.
 */
void handle_fasteoi_irq(struct irq_desc *desc)
{
        struct irq_chip *chip = desc->irq_data.chip;

        raw_spin_lock(&desc->lock);

        if (!irq_may_run(desc))
                goto out;

        desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);

        /*
         * If its disabled or no action available
         * then mask it and get out of here:
         */
        if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
                desc->istate |= IRQS_PENDING;
                mask_irq(desc);
                goto out;
        }

        kstat_incr_irqs_this_cpu(desc);
        if (desc->istate & IRQS_ONESHOT)
                mask_irq(desc);

        preflow_handler(desc);
        handle_irq_event(desc);

        cond_unmask_eoi_irq(desc, chip);

        raw_spin_unlock(&desc->lock);
        return;
out:
        if (!(chip->flags & IRQCHIP_EOI_IF_HANDLED))
                chip->irq_eoi(&desc->irq_data);
        raw_spin_unlock(&desc->lock);
}
EXPORT_SYMBOL_GPL(handle_fasteoi_irq);

해당 인터럽트에 등록된 action 핸들러를 수행하고 eoi 처리를 위해 irq_chip 드라이버의 (*irq_eoi) 후크 함수를 호출한다.

  • 코드 라인 7~8에서 인터럽트를 처리할 수 있는 상황이 아닌 경우 out: 레이블로 이동하여 eoi 처리만 수행하고 함수를 빠져나간다.
  • 코드 라인 10에서 인터럽트 state에서 IRQS_REPLAY와 IRQS_WAITING을 제거한다.
  • 코드 라인 16~20에서 action 핸들러가 지정되지 않았거나 인터럽트 설정이 disable된 경우 인터럽트 state에 IRQS_PENDING을 추가하고 컨트롤러에 해당 인터럽트를 mask 한 후 out: 레이블로 이동하여 eoi 처리만 수행하고 함수를 빠져나간다.
  • 코드 라인 22에서 현재 cpu에 대한 kstat 카운터를 증가시킨다.
  • 코드 라인 23~24에서 oneshot 인터럽트인 경우 해당 인터럽트를 mask 한다.
  • 코드 라인 26에서 preflow 핸들러가 설정된 경우 이를 호출한다.
  • 코드 라인 27에서 해당 인터럽트에 등록된 action 핸들러를 호출한다.
  • 코드 라인 29~32에서 몇 가지 조건에 따라 eoi 처리를 위해 irq_chip 드라이버의 (*irq_eoi) 후크 함수를 호출한 후 함수를 정상적으로 완료한다.
  • 코드 라인 33~35에서 out: 레이블이다. IRQCHIP_EOI_IF_HANDLED 플래그 설정이 없는 경우 eoi 처리를 위해 irq_chip 드라이버의 (*irq_eoi) 후크 함수를 호출한다.

 

핸들러 함수 -4- (fasteoi, NMI)

handle_fasteoi_nmi()

kernel/irq/chip.c

/**
 *      handle_fasteoi_nmi - irq handler for NMI interrupt lines
 *      @desc:  the interrupt description structure for this irq
 *
 *      A simple NMI-safe handler, considering the restrictions
 *      from request_nmi.
 *
 *      Only a single callback will be issued to the chip: an ->eoi()
 *      call when the interrupt has been serviced. This enables support
 *      for modern forms of interrupt handlers, which handle the flow
 *      details in hardware, transparently.
 */
void handle_fasteoi_nmi(struct irq_desc *desc)
{
        struct irq_chip *chip = irq_desc_get_chip(desc);
        struct irqaction *action = desc->action;
        unsigned int irq = irq_desc_get_irq(desc);
        irqreturn_t res;

        __kstat_incr_irqs_this_cpu(desc);

        trace_irq_handler_entry(irq, action);
        /*
         * NMIs cannot be shared, there is only one action.
         */
        res = action->handler(irq, action->dev_id);
        trace_irq_handler_exit(irq, action, res);

        if (chip->irq_eoi)
                chip->irq_eoi(&desc->irq_data);
}
EXPORT_SYMBOL_GPL(handle_fasteoi_nmi);

해당 인터럽트에 등록된 action 핸들러를 수행하고 eoi 처리를 위해 irq_chip 드라이버의 (*irq_eoi) 후크 함수를 호출한다.

  • 코드 라인 8에서 현재 cpu에 대한 kstat 카운터를 증가시킨다.
  • 코드 라인 14에서 해당 인터럽트에 등록된 action 핸들러를 호출한다.
  • 코드 라인 17~18에서 eoi 처리를 위해 irq_chip 드라이버의 (*irq_eoi) 후크 함수를 호출한다.

 

핸들러 함수 -5- (percpu, devid, fasteoi, NMI)

handle_percpu_devid_fasteoi_nmi()

kernel/irq/chip.c

/**
 * handle_percpu_devid_fasteoi_nmi - Per CPU local NMI handler with per cpu
 *                                   dev ids
 * @desc:       the interrupt description structure for this irq
 *
 * Similar to handle_fasteoi_nmi, but handling the dev_id cookie
 * as a percpu pointer.
 */
void handle_percpu_devid_fasteoi_nmi(struct irq_desc *desc)
{
        struct irq_chip *chip = irq_desc_get_chip(desc);
        struct irqaction *action = desc->action;
        unsigned int irq = irq_desc_get_irq(desc);
        irqreturn_t res;

        __kstat_incr_irqs_this_cpu(desc);

        trace_irq_handler_entry(irq, action);
        res = action->handler(irq, raw_cpu_ptr(action->percpu_dev_id));
        trace_irq_handler_exit(irq, action, res);

        if (chip->irq_eoi)
                chip->irq_eoi(&desc->irq_data);
}

해당 per-cpu 인터럽트에 등록된 action 핸들러를 수행하고 eoi 처리를 위해 irq_chip 드라이버의 (*irq_eoi) 후크 함수를 호출한다.

  • 코드 라인 8에서 현재 cpu에 대한 kstat 카운터를 증가시킨다.
  • 코드 라인 11에서 해당 인터럽트에 등록된 action 핸들러를 호출한다.
  • 코드 라인 14~15에서 eoi 처리를 위해 irq_chip 드라이버의 (*irq_eoi) 후크 함수를 호출한다.

 

핸들러 함수 -6- (simple)

handle_simple_irq()

kernel/irq/chip.c

/**
 *      handle_simple_irq - Simple and software-decoded IRQs.
 *      @desc:  the interrupt description structure for this irq
 *
 *      Simple interrupts are either sent from a demultiplexing interrupt
 *      handler or come from hardware, where no interrupt hardware control
 *      is necessary.
 *
 *      Note: The caller is expected to handle the ack, clear, mask and
 *      unmask issues if necessary.
 */
void handle_simple_irq(struct irq_desc *desc)
{
        raw_spin_lock(&desc->lock);

        if (!irq_may_run(desc))
                goto out_unlock;

        desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);

        if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
                desc->istate |= IRQS_PENDING;
                goto out_unlock;
        }

        kstat_incr_irqs_this_cpu(desc);
        handle_irq_event(desc);

out_unlock:
        raw_spin_unlock(&desc->lock);
}
EXPORT_SYMBOL_GPL(handle_simple_irq);

해당 인터럽트에 등록된 action 핸들러를 수행한다. 단 ack 및 eoi 등의 hw 제어는 하나도 처리하지 않는다.

  • 코드 라인 5~6에서 인터럽트를 처리할 수 있는 상황이 아닌 경우 out_unlock: 레이블로 이동하여 함수를 빠져나간다.
  • 코드 라인 8에서 인터럽트 state에서 IRQS_REPLAY와 IRQS_WAITING을 제거한다.
  • 코드 라인 10~13에서 action 핸들러가 지정되지 않았거나 인터럽트 설정이 disable된 경우 인터럽트 state에 IRQS_PENDING을 추가하고 out_unlock 레이블로 이동하여 함수를 빠져나간다.
  • 코드 라인 15에서 현재 cpu에 대한 kstat 카운터를 증가시킨다.
  • 코드 라인 16에서 해당 인터럽트에 등록된 action 핸들러를 호출한다.

 

핸들러 함수 -7- (edge)

handle_edge_irq()

kernel/irq/chip.c

/**
 *      handle_edge_irq - edge type IRQ handler
 *      @desc:  the interrupt description structure for this irq
 *
 *      Interrupt occures on the falling and/or rising edge of a hardware
 *      signal. The occurrence is latched into the irq controller hardware
 *      and must be acked in order to be reenabled. After the ack another
 *      interrupt can happen on the same source even before the first one
 *      is handled by the associated event handler. If this happens it
 *      might be necessary to disable (mask) the interrupt depending on the
 *      controller hardware. This requires to reenable the interrupt inside
 *      of the loop which handles the interrupts which have arrived while
 *      the handler was running. If all pending interrupts are handled, the
 *      loop is left.
 */
void handle_edge_irq(struct irq_desc *desc)
{
        raw_spin_lock(&desc->lock);

        desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);

        if (!irq_may_run(desc)) {
                desc->istate |= IRQS_PENDING;
                mask_ack_irq(desc);
                goto out_unlock;
        }

        /*
         * If its disabled or no action available then mask it and get
         * out of here.
         */
        if (irqd_irq_disabled(&desc->irq_data) || !desc->action) {
                desc->istate |= IRQS_PENDING;
                mask_ack_irq(desc);
                goto out_unlock;
        }

        kstat_incr_irqs_this_cpu(desc);

        /* Start handling the irq */
        desc->irq_data.chip->irq_ack(&desc->irq_data);

        do {
                if (unlikely(!desc->action)) {
                        mask_irq(desc);
                        goto out_unlock;
                }

                /*
                 * When another irq arrived while we were handling
                 * one, we could have masked the irq.
                 * Renable it, if it was not disabled in meantime.
                 */
                if (unlikely(desc->istate & IRQS_PENDING)) {
                        if (!irqd_irq_disabled(&desc->irq_data) &&
                            irqd_irq_masked(&desc->irq_data))
                                unmask_irq(desc);
                }

                handle_irq_event(desc);

        } while ((desc->istate & IRQS_PENDING) &&
                 !irqd_irq_disabled(&desc->irq_data));

out_unlock:
        raw_spin_unlock(&desc->lock);
}
EXPORT_SYMBOL(handle_edge_irq);

해당 edge 트리거 타입 인터럽트에 등록된 action 핸들러를 수행한다. action 핸들러 수행 전에 ack를 처리한다.

  • 코드 라인 5에서 인터럽트 state에서 IRQS_REPLAY와 IRQS_WAITING을 제거한다.
  • 코드 라인 7~11에서 인터럽트를 처리할 수 있는 상황이 아닌 경우 인터럽트 state에 IRQS_PENDING을 추가하고, 인터럽트를 mask 처리한 후 out_unlock: 레이블로 이동하여 함수를 빠져나간다.
  • 코드 라인 17~21에서 action 핸들러가 지정되지 않았거나 인터럽트 설정이 disable된 경우 인터럽트 state에 IRQS_PENDING을 추가하고, 인터럽트를 mask 처리한 후 out_unlock: 레이블로 이동하여 함수를 빠져나간다.
  • 코드 라인 23에서 현재 cpu에 대한 kstat 카운터를 증가시킨다.
  • 코드 라인 26에서 ack 처리를 위해 irq_chip 드라이버의 (*irq_ack) 후크 함수를 호출한다.
  • 코드 라인 28~48에서 펜딩된 인터럽트가 있는 경우 반복하며 해당 인터럽트에 등록된 action 핸들러를 호출한다.
    • action 핸들러가 지정되지 않은 경우 인터럽트를 mask 처리한 후 out_unlock: 레이블로 이동하여 함수를 빠져나간다.
    • 펜딩된 irq가 있는데 irq가 mask된 상태인 경우 인터럽트를 unmask 처리한다.

 

핸들러 함수 -8- (nested)

handle_nested_irq()

kernel/irq/chip.c

/*
 *      handle_nested_irq - Handle a nested irq from a irq thread
 *      @irq:   the interrupt number
 *
 *      Handle interrupts which are nested into a threaded interrupt
 *      handler. The handler function is called inside the calling
 *      threads context.
 */
void handle_nested_irq(unsigned int irq)
{
        struct irq_desc *desc = irq_to_desc(irq);
        struct irqaction *action;
        irqreturn_t action_ret;

        might_sleep();

        raw_spin_lock_irq(&desc->lock);

        desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);

        action = desc->action;
        if (unlikely(!action || irqd_irq_disabled(&desc->irq_data))) {
                desc->istate |= IRQS_PENDING;
                goto out_unlock;
        }

        kstat_incr_irqs_this_cpu(desc);
        irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS);
        raw_spin_unlock_irq(&desc->lock);

        action_ret = IRQ_NONE;
        for_each_action_of_desc(desc, action)
                action_ret |= action->thread_fn(action->irq, action->dev_id);

        if (!noirqdebug)
                note_interrupt(desc, action_ret);

        raw_spin_lock_irq(&desc->lock);
        irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS);

out_unlock:
        raw_spin_unlock_irq(&desc->lock);
}
EXPORT_SYMBOL_GPL(handle_nested_irq);

hw interrupt context가 아닌 irq 스레드 context에서 동작하며, 해당 인터럽트에 등록된 모든 action 스레드 핸들러를 수행한다.

  • 코드 라인 7에서 Preemption point를 위해 필요 시 슬립한다.
  • 코드 라인 11에서 인터럽트 state에서 IRQS_REPLAY와 IRQS_WAITING을 제거한다.
  • 코드 라인 13~17에서 action 핸들러가 지정되지 않았거나 인터럽트 설정이 disable된 경우 인터럽트 state에 IRQS_PENDING을 추가하고out_unlock: 레이블로 이동하여 함수를 빠져나간다.
  • 코드 라인 19에서 현재 cpu에 대한 kstat 카운터를 증가시킨다.
  • 코드 라인 20에서 핸들러를 호출하는 동안 IRQD_IRQ_INPROGRESS 플래그를 설정한다.
  • 코드 라인 23~25에서 인터럽트에 등록된 모든 action 스레드 핸들러를 호출한다.
  • 코드 라인31에서 핸들러를 호출하는 동안 사용한 IRQD_IRQ_INPROGRESS 플래그를 클리어한다.

 

핸들러 공용 함수들

irq_may_run()

kernel/irq/chip.c

static bool irq_may_run(struct irq_desc *desc)
{
        unsigned int mask = IRQD_IRQ_INPROGRESS | IRQD_WAKEUP_ARMED;

        /*
         * If the interrupt is not in progress and is not an armed
         * wakeup interrupt, proceed.
         */
        if (!irqd_has_set(&desc->irq_data, mask))
                return true;

        /*
         * If the interrupt is an armed wakeup source, mark it pending
         * and suspended, disable it and notify the pm core about the
         * event.
         */
        if (irq_pm_check_wakeup(desc))
                return false;

        /*
         * Handle a potential concurrent poll on a different core.
         */
        return irq_check_poll(desc);
}

irq의 실행이 곧 준비될 것 같으면 기다린다. 만일 처리가 불가능하면 false를 반환하고, 인터럽트 처리가 가능한 경우 true를 반환한다.

  • 코드 라인 9~10에서 irq 처리가 진행중이거나 armed wakeup 인터럽트가 아닌 경우 true를 반환하여 인터럽트가 계속 진행되게 한다.
  • 코드 라인 17~18에서 CONFIG_PM_SLEEP 커널 옵션을 사용하는 경우 Power Management 기능을 사용할 수 있는데 suspend 하지 않은 경우 true를 반환한다.
    • armed wakeup 인터럽트인 경우 인터럽트 디스크립터의 istate 상태에 suspended 및 pending을 추가하고 깨울 때까지 대기한다.
  • 코드 라인 23에서 irq polling을 중단 설정하지 않은 경우 다른 cpu에서 irq polling을 수행하는 중이면 완료될 때까지 기다린다.

 

핸들러 최종 호출 단계들

handle_irq_event()

kernel/irq/handle.c

irqreturn_t handle_irq_event(struct irq_desc *desc)
{
        irqreturn_t ret;

        desc->istate &= ~IRQS_PENDING;
        irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS);
        raw_spin_unlock(&desc->lock);

        ret = handle_irq_event_percpu(desc, action);

        raw_spin_lock(&desc->lock);
        irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS);
        return ret;
}

percpu 타입이 아닌 일반 irq 디스크립터에 등록된 모든 action 핸들러들을 호출하여 수행한다.

  • irq 디스크립터의 istate에서 pending 플래그를 제거하고 모든 action에 등록한 인터럽트 핸들러들을 호출하여 수행한다.
  • 수행 중인 동안에는 irq 진행중 상태가 유지된다.

 

handle_irq_event_percpu()

kernel/irq/handle.c

irqreturn_t handle_irq_event_percpu(struct irq_desc *desc)
{
        irqreturn_t retval;
        unsigned int flags = 0;

        retval = __handle_irq_event_percpu(desc, &flags);

        add_interrupt_randomness(desc->irq_data.irq, flags);

        if (!noirqdebug)
                note_interrupt(desc, retval);
        return retval;
}

percpu 타입 irq 디스크립터에 등록된 모든 action 핸들러들을 호출하여 수행한다.

 

__handle_irq_event_percpu()

kernel/irq/handle.c

irqreturn_t __handle_irq_event_percpu(struct irq_desc *desc, unsigned int *flags)
{
        irqreturn_t retval = IRQ_NONE;
        unsigned int irq = desc->irq_data.irq;
        struct irqaction *action;

        record_irq_time(desc);

        for_each_action_of_desc(desc, action) {
                irqreturn_t res;

                trace_irq_handler_entry(irq, action);
                res = action->handler(irq, action->dev_id);
                trace_irq_handler_exit(irq, action, res);

                if (WARN_ONCE(!irqs_disabled(),"irq %u handler %pS enabled interrupts\n",
                              irq, action->handler))
                        local_irq_disable();

                switch (res) {
                case IRQ_WAKE_THREAD:
                        /*
                         * Catch drivers which return WAKE_THREAD but
                         * did not set up a thread function
                         */
                        if (unlikely(!action->thread_fn)) {
                                warn_no_thread(irq, action);
                                break;
                        }

                        __irq_wake_thread(desc, action);

                        /* Fall through - to add to randomness */
                case IRQ_HANDLED:
                        *flags |= action->flags;
                        break;

                default:
                        break;
                }

                retval |= res;
        }

        return retval;
}

percpu 타입 irq 디스크립터에 등록된 모든 action 핸들러들을 호출하여 수행한다.

  • 코드 라인 9~14에서 irq 디스크립터에 등록된 모든 action 핸들러를 순회하며 호출한다.
  • 코드 라인 16~18에서 핸들러 수행 후 local irq가 disable 상태를 유지하지 못한 경우 경고 메시지를 출력하고 local irq를 disable 한다.
    • “irq N handler <function> enabled interrupts” 경고 메시지
  • 코드 라인 20~31에서 처리 결과가 IRQ_WAKE_THREAD인 경우 thread를 깨우고 계속 다음 행을 수행한다.
  • 코드 라인 34~40에서 처리 결과가 IRQ_HANDLED인 경우 flags에 action->flags를 추가하고, 그 외의 처리 결과는 skip 한다.
  • 코드 라인 42에서 retval에 처리 결과를 누적시키고 더 처리할 action이 있는 경우 루프를 돈다.

 


IRQ chip Operations

IRQ startup & shutdown

irq_startup()

kernel/irq/chip.c

int irq_startup(struct irq_desc *desc, bool resend, bool force)
{
        struct irq_data *d = irq_desc_get_irq_data(desc);
        struct cpumask *aff = irq_data_get_affinity_mask(d);
        int ret = 0;

        desc->depth = 0;

        if (irqd_is_started(d)) {
                irq_enable(desc);
        } else {
                switch (__irq_startup_managed(desc, aff, force)) {
                case IRQ_STARTUP_NORMAL:
                        ret = __irq_startup(desc);
                        irq_setup_affinity(desc);
                        break;
                case IRQ_STARTUP_MANAGED:
                        irq_do_set_affinity(d, aff, false);
                        ret = __irq_startup(desc);
                        break;
                case IRQ_STARTUP_ABORT:
                        irqd_set_managed_shutdown(d);
                        return 0;
                }
        }
        if (resend)
                check_irq_resend(desc);

        return ret;
}

요청 irq에 대해 enable 시키고 activate 처리를 수행하며 관련 콜백 함수를 호출한다.

  • 코드 라인 9~10에서 이미 startup된 경우 irq만 enable 한다.
  • 코드 라인 11~25에서 managed 상태에 따라 다음과 같이 처리한다.
    • normal 상태로 시작하는 경우 요청 irq의 startup을 수행 후 affinity를 선택 및 처리한다.
    • managed 상태로 시작하는 경우 요청 irq의 affnity 처리 후 startup을 처리한다.
    • abort 인 경우 irqd에 IRQD_MANAGED_SHUTDOWN 플래그를 설정한다.
  • 코드 라인 26~27에서 인자 @resend가 설정된 경우 pending된 irq를 다시 호출하게 tasklet을 리스케쥴하다.

 

__irq_startup()

kernel/irq/chip.c

static int __irq_startup(struct irq_desc *desc)
{
        struct irq_data *d = irq_desc_get_irq_data(desc);
        int ret = 0;

        /* Warn if this interrupt is not activated but try nevertheless */
        WARN_ON_ONCE(!irqd_is_activated(d));

        if (d->chip->irq_startup) {
                ret = d->chip->irq_startup(d);
                irq_state_clr_disabled(desc);
                irq_state_clr_masked(desc);
        } else {
                irq_enable(desc);
        }
        irq_state_set_started(desc);
        return ret;
}

요청 irq의 startup을 처리한다.

  • 코드 라인 9~12에서 irq_startup 후크에 등록된 함수가 있는 경우 이를 호출하고 disabled와 masked 상태를 클리어한다.
  • 코드 라인 13~15에서 irq_startup 후크에 비어 있는 경우 enable 처리한다.
  • 코드 라인 16에서 irqd에 IRQD_IRQ_STARTED 플래그를 설정한다.

 

irq_shutdown()

kernel/irq/chip.c

void irq_shutdown(struct irq_desc *desc)
{
        if (irqd_is_started(&desc->irq_data)) {
                desc->depth = 1;
                if (desc->irq_data.chip->irq_shutdown) {
                        desc->irq_data.chip->irq_shutdown(&desc->irq_data);
                        irq_state_set_disabled(desc);
                        irq_state_set_masked(desc);
                } else {
                        __irq_disable(desc, true);
                }
                irq_state_clr_started(desc);
        }
}

요청 irq에 대해 shutdown 또는 disable 처리한다.

  • 코드 라인 5~8에서 (*irq_shutdonw) 후크가 있으면 shutdown 처리를 수행한 후, irqd에 IRQD_IRQ_DISABLED및 IRQD_IRQ_MASKED플래그를 설정한다.
  • 코드 라인 9~11에서 (*irq_shutdonw) 후크가 있으면 disable 처리를 수행한다.
  • 코드 라인 12에서 irqd에 IRQD_IRQ_STARTED 플래그를 클리어한다.

 

IRQ Enable & Disable

irq_enable()

kernel/irq/chip.c

void irq_enable(struct irq_desc *desc)
{
        if (!irqd_irq_disabled(&desc->irq_data)) {
                unmask_irq(desc);
        } else {
                irq_state_clr_disabled(desc);
                if (desc->irq_data.chip->irq_enable) {
                        desc->irq_data.chip->irq_enable(&desc->irq_data);
                        irq_state_clr_masked(desc);
                } else {
                        unmask_irq(desc);
                }
        }
}

요청 irq를 enable 한다.

  • 코드 라인 3~4에서 irqd가 disable 상태가 아니면 unmask 처리한다.
  • 코드 라인 5~13에서 IRQD_IRQ_DISABLED 플래그를 제거하고, (*irq_enable) 후크를 호출한 후 IRQD_IRQ_MASKED 플래그를 제거한다. 만일 (*irq_enable) 후크가 없는 경우 unmask 처리한다.

 

irq_disable()

kernel/irq/chip.c

/**
 * irq_disable - Mark interrupt disabled
 * @desc:       irq descriptor which should be disabled
 *
 * If the chip does not implement the irq_disable callback, we
 * use a lazy disable approach. That means we mark the interrupt
 * disabled, but leave the hardware unmasked. That's an
 * optimization because we avoid the hardware access for the
 * common case where no interrupt happens after we marked it
 * disabled. If an interrupt happens, then the interrupt flow
 * handler masks the line at the hardware level and marks it
 * pending.
 *
 * If the interrupt chip does not implement the irq_disable callback,
 * a driver can disable the lazy approach for a particular irq line by
 * calling 'irq_set_status_flags(irq, IRQ_DISABLE_UNLAZY)'. This can
 * be used for devices which cannot disable the interrupt at the
 * device level under certain circumstances and have to use
 * disable_irq[_nosync] instead.
 */
void irq_disable(struct irq_desc *desc)
{
        __irq_disable(desc, irq_settings_disable_unlazy(desc));
}

요청 irq를 disable 한다.

 

__irq_disable()

kernel/irq/chip.c

static void __irq_disable(struct irq_desc *desc, bool mask)
{
        if (irqd_irq_disabled(&desc->irq_data)) {
                if (mask)
                        mask_irq(desc);
        } else {
                irq_state_set_disabled(desc);
                if (desc->irq_data.chip->irq_disable) {
                        desc->irq_data.chip->irq_disable(&desc->irq_data);
                        irq_state_set_masked(desc);
                } else if (mask) {
                        mask_irq(desc);
                }
        }
}

요청 irq를 disable 한다.

  • 코드 라인 3~5에서 이미 disable 상태인 경우 @mask 설정이 있으면 mask 처리를 수행한다.
  • 코드 라인 6~14에서 IRQD_IRQ_DISABLED 플래그를 설정하고, (*irq_disable) 후크를 호출한 후 IRQD_IRQ_MASKED 플래그를 설정한다. 만일 (*irq_disable) 후크가 없는 경우 mask 처리한다.

 

IRQ mask & unmask

mask_irq()

kernel/irq/chip.c

void mask_irq(struct irq_desc *desc)
{
        if (irqd_irq_masked(&desc->irq_data))
                return;

        if (desc->irq_data.chip->irq_mask) {
                desc->irq_data.chip->irq_mask(&desc->irq_data);
                irq_state_set_masked(desc);
        }
}

요청 irq를 마스크한다.

  • 코드 라인 3~4에서 이미 인터럽트가 mask되어 있는 경우 함수를 빠져나간다.
  • 코드 라인 6~9에서 chip->irq_mask 후크에 등록된 콜백 함수를 호출하고 masked 플래그를 설정한다.

 

unmask_irq()

kernel/irq/chip.c

void unmask_irq(struct irq_desc *desc)
{
        if (!irqd_irq_masked(&desc->irq_data)) 
                return;

        if (desc->irq_data.chip->irq_unmask) {
                desc->irq_data.chip->irq_unmask(&desc->irq_data);
                irq_state_clr_masked(desc);
        }
}

요청 irq를 언마스크한다.

  • 코드 라인 3~4에서 이미 인터럽트가 unmask되어 있는 경우 함수를 빠져나간다.
  • 코드 라인 6~9에서 chip->irq_unmask 후크에 등록된 콜백 함수를 호출하고 masked 플래그를 클리어한다.

 

cond_unmask_irq()

kernel/irq/chip.c

/*
 * Called unconditionally from handle_level_irq() and only for oneshot
 * interrupts from handle_fasteoi_irq()
 */
static void cond_unmask_irq(struct irq_desc *desc)
{
        /*
         * We need to unmask in the following cases:
         * - Standard level irq (IRQF_ONESHOT is not set)
         * - Oneshot irq which did not wake the thread (caused by a
         *   spurious interrupt or a primary handler handling it
         *   completely).
         */
        if (!irqd_irq_disabled(&desc->irq_data) &&
            irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot)
                unmask_irq(desc);
}

조건에 따라 요청 irq를 언마스크한다.

  • 다음의 조건에서 unmask 처리를 수행하지 않는다.
    • 이미 인터럽트가 disable된 상태
    • 이미 인터럽트가 mask된 상태
    • oneshot 인터럽트의 경우
      • mask 상태를 유지하기 위해 unmask를 수행하지 않는다.

 

IRQ mask_ack & unmask_eoi

mask_ack_irq()

kernel/irq/chip.c

static inline void mask_ack_irq(struct irq_desc *desc)
{
        if (desc->irq_data.chip->irq_mask_ack) {
                desc->irq_data.chip->irq_mask_ack(&desc->irq_data);
                irq_state_set_masked(desc);
        } else {
                mask_irq(desc);
                if (desc->irq_data.chip->irq_ack)
                        desc->irq_data.chip->irq_ack(&desc->irq_data);
        }
}

요청 irq에 대해 mask와 ack 처리를 하고 masked 플래그를 설정한다. 보통 같은 인터럽트에 대해 계속 진입되는 것을 방지가힉 위해 인터럽트 핸들러 초입에서 호출되며  마스크 처리와 응답 처리를 같이 수행하게 한다.

  • 코드 라인 3~5에서 인터럽트 컨트롤러의 irq_mask_ack 후크에 등록한 콜백 함수를 호출하고, irqd를 masked 상태로 설정한다.
  • 코드 라인 6~10에서 등록되지 않은 경우 mask 처리를 수행하고, irq_ack 후크에 등록된 콜백 함수를 연속해서 호출한다.

 

cond_unmask_eoi_irq()

kernel/irq/chip.c

static void cond_unmask_eoi_irq(struct irq_desc *desc, struct irq_chip *chip)
{
        if (!(desc->istate & IRQS_ONESHOT)) {
                chip->irq_eoi(&desc->irq_data);
                return;
        }
        /*
         * We need to unmask in the following cases:
         * - Oneshot irq which did not wake the thread (caused by a
         *   spurious interrupt or a primary handler handling it
         *   completely).
         */
        if (!irqd_irq_disabled(&desc->irq_data) &&
            irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot) {
                chip->irq_eoi(&desc->irq_data);
                unmask_irq(desc);
        } else if (!(chip->flags & IRQCHIP_EOI_THREADED)) {
                chip->irq_eoi(&desc->irq_data);
        }
}

요청 irq의 eoi 처리를 하고 조건에 따라 unmask 처리한다.

  • 코드 라인 3~6에서 인터럽트가 oneshot 설정되지 않은 경우 eoi 처리 후 함수를 빠져나간다.
  • 코드 라인 13~16에서 irq가 enable된 상태에서 mask되었고 oneshot 스레드 처리중이 아닌 경우 eoi 처리 및 unmask 처리를 한다.
    • 스레드가 완료되지 않고 동작중인 경우 unmask 처리하지 않는다.
  • 코드 라인 17~19에서 eoi 스레드 플래그가 설정되지 않은 경우 eoi 처리만 한다.

 

기타

irq_domain_activate_irq()

kernel/irq/irqdomain.c

/**
 * irq_domain_activate_irq - Call domain_ops->activate recursively to activate
 *                           interrupt
 * @irq_data:   Outermost irq_data associated with interrupt
 * @reserve:    If set only reserve an interrupt vector instead of assigning one
 *
 * This is the second step to call domain_ops->activate to program interrupt
 * controllers, so the interrupt could actually get delivered.
 */
int irq_domain_activate_irq(struct irq_data *irq_data, bool reserve)
{
        int ret = 0;

        if (!irqd_is_activated(irq_data))
                ret = __irq_domain_activate_irq(irq_data, reserve);
        if (!ret)
                irqd_set_activated(irq_data);
        return ret;
}

irq domain에 구성된 최상위까지 activate 후크에 등록한 콜백 함수를 호출한다.

  • parent_data가 상위 irq_data를 가리키는 경우 재귀 호출된다.

 

irq_domain_deactivate_irq()

kernel/irq/irqdomain.c

/**
 * irq_domain_deactivate_irq - Call domain_ops->deactivate recursively to
 *                             deactivate interrupt
 * @irq_data: outermost irq_data associated with interrupt
 *
 * It calls domain_ops->deactivate to program interrupt controllers to disable
 * interrupt delivery.
 */
void irq_domain_deactivate_irq(struct irq_data *irq_data)
{
        if (irqd_is_activated(irq_data)) {
                __irq_domain_deactivate_irq(irq_data);
                irqd_clr_activated(irq_data);
        }
}

irq domain에 구성된 최상위까지 deactivate 후크에 등록한 콜백 함수를 호출한다.

  • parent_data가 상위 irq_data를 가리키는 경우 재귀 호출된다.

 

IRQ 설정

각 디바이스 드라이버에서 irq를 설정할 때 사용하는 함수는 다음 그림과 같다.

 

구조체

irq_chip 구조체

include/linux/irq.h

/**
 * struct irq_chip - hardware interrupt chip descriptor
 *
 * @parent_device:      pointer to parent device for irqchip
 * @name:               name for /proc/interrupts
 * @irq_startup:        start up the interrupt (defaults to ->enable if NULL)
 * @irq_shutdown:       shut down the interrupt (defaults to ->disable if NULL)
 * @irq_enable:         enable the interrupt (defaults to chip->unmask if NULL)
 * @irq_disable:        disable the interrupt
 * @irq_ack:            start of a new interrupt
 * @irq_mask:           mask an interrupt source
 * @irq_mask_ack:       ack and mask an interrupt source
 * @irq_unmask:         unmask an interrupt source
 * @irq_eoi:            end of interrupt
 * @irq_set_affinity:   Set the CPU affinity on SMP machines. If the force
 *                      argument is true, it tells the driver to
 *                      unconditionally apply the affinity setting. Sanity
 *                      checks against the supplied affinity mask are not
 *                      required. This is used for CPU hotplug where the
 *                      target CPU is not yet set in the cpu_online_mask.
 * @irq_retrigger:      resend an IRQ to the CPU
 * @irq_set_type:       set the flow type (IRQ_TYPE_LEVEL/etc.) of an IRQ
 * @irq_set_wake:       enable/disable power-management wake-on of an IRQ
 * @irq_bus_lock:       function to lock access to slow bus (i2c) chips
 * @irq_bus_sync_unlock:function to sync and unlock slow bus (i2c) chips
 * @irq_cpu_online:     configure an interrupt source for a secondary CPU
 * @irq_cpu_offline:    un-configure an interrupt source for a secondary CPU
 * @irq_suspend:        function called from core code on suspend once per
 *                      chip, when one or more interrupts are installed
 * @irq_resume:         function called from core code on resume once per chip,
 *                      when one ore more interrupts are installed
 * @irq_pm_shutdown:    function called from core code on shutdown once per chip
 * @irq_calc_mask:      Optional function to set irq_data.mask for special cases
 * @irq_print_chip:     optional to print special chip info in show_interrupts
 * @irq_request_resources:      optional to request resources before calling
 *                              any other callback related to this irq
 * @irq_release_resources:      optional to release resources acquired with
 *                              irq_request_resources
 * @irq_compose_msi_msg:        optional to compose message content for MSI
 * @irq_write_msi_msg:  optional to write message content for MSI
 * @irq_get_irqchip_state:      return the internal state of an interrupt
 * @irq_set_irqchip_state:      set the internal state of a interrupt
 * @irq_set_vcpu_affinity:      optional to target a vCPU in a virtual machine
 * @ipi_send_single:    send a single IPI to destination cpus
 * @ipi_send_mask:      send an IPI to destination cpus in cpumask
 * @irq_nmi_setup:      function called from core code before enabling an NMI
 * @irq_nmi_teardown:   function called from core code after disabling an NMI
 * @flags:              chip specific flags
 */
struct irq_chip {
        struct device   *parent_device;
        const char      *name;
        unsigned int    (*irq_startup)(struct irq_data *data);
        void            (*irq_shutdown)(struct irq_data *data);
        void            (*irq_enable)(struct irq_data *data);
        void            (*irq_disable)(struct irq_data *data);

        void            (*irq_ack)(struct irq_data *data);
        void            (*irq_mask)(struct irq_data *data);
        void            (*irq_mask_ack)(struct irq_data *data);
        void            (*irq_unmask)(struct irq_data *data);
        void            (*irq_eoi)(struct irq_data *data);

        int             (*irq_set_affinity)(struct irq_data *data, const struct cpumask *dest, bool
force);
        int             (*irq_retrigger)(struct irq_data *data);
        int             (*irq_set_type)(struct irq_data *data, unsigned int flow_type);
        int             (*irq_set_wake)(struct irq_data *data, unsigned int on);

        void            (*irq_bus_lock)(struct irq_data *data);
        void            (*irq_bus_sync_unlock)(struct irq_data *data);

        void            (*irq_cpu_online)(struct irq_data *data);
        void            (*irq_cpu_offline)(struct irq_data *data);

        void            (*irq_suspend)(struct irq_data *data);
        void            (*irq_resume)(struct irq_data *data);
        void            (*irq_pm_shutdown)(struct irq_data *data);

        void            (*irq_calc_mask)(struct irq_data *data);

        void            (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
        int             (*irq_request_resources)(struct irq_data *data);
        void            (*irq_release_resources)(struct irq_data *data);

        void            (*irq_compose_msi_msg)(struct irq_data *data, struct msi_msg *msg);
        void            (*irq_write_msi_msg)(struct irq_data *data, struct msi_msg *msg);

        int             (*irq_get_irqchip_state)(struct irq_data *data, enum irqchip_irq_state whichh
, bool *state);
        int             (*irq_set_irqchip_state)(struct irq_data *data, enum irqchip_irq_state whichh
, bool state);

        int             (*irq_set_vcpu_affinity)(struct irq_data *data, void *vcpu_info);

        void            (*ipi_send_single)(struct irq_data *data, unsigned int cpu);
        void            (*ipi_send_mask)(struct irq_data *data, const struct cpumask *dest);

        int             (*irq_nmi_setup)(struct irq_data *data);
        void            (*irq_nmi_teardown)(struct irq_data *data);

        unsigned long   flags;
};

인터럽트 HW 칩에 대한 디스크립터로 대부분의 멤버들은 operation 후크들로 이루어졌다.

  • * name
    • /proc/interrupts에 출력할 이름
  • (*irq_startup)
    • 인터럽트 startup
    • core – irq_startup() 함수에서 호출하는데 이 후크가 지정되지 않으면 core – irq_enable() 함수를 호출한다.
  • (*irq_shutdown)
    • 인터럽트 shutdown
    • core – irq_shutdown() 함수에서 호출하는데 이 후크가 지정되지 않으면 core – irq_disable() 함수를 호출한다.
  • (*irq_enable)
    • 인터럽트 enable
    • core – irq_enable() 함수에서 호출하는데 이 후크가 지정되지 않으면 chip->irq_unmask() 후크를 호출한다.
  • (*irq_disable)
    • 인터럽트 disable
    • core – irq_disable() 함수에서 호출한다.
  • (*irq_ack)
    • 인터럽트 핸들러에서 새 인터럽트가 들어온 경우 호출한다. (새 인터럽트의 시작)
    • ack가 호출되면 eoi가 처리되기 전에 cpu에 새 인터럽트가 진입하지 못한다.
  • (*irq_mask)
    • 인터럽트 소스 마스크
    • c0re – mask_irq() 함수에서 호출한다.
  • (*irq_mask_ack)
    • 인터럽트 핸들러에서 새 인터럽트가 들어온 경우 호출하며 irq 마스크도 같이 수행한다.
    • core – mask_ack_irq() 함수에서 호출하는데 이 후크가 지정되지 않으면 chip->irq_mask() 후크와 chip->irq_ack() 후크를 따로 하나씩 호출한다.
  • (*irq_unmask)
    • 인터럽트 소스 언마스크
    • c0re – unmask_irq() 함수에서 호출한다.
  • (*irq_eoi)
    • 인터럽트 핸들러 처리의 종료 시 호출한다.
  • (*irq_set_affinity)
    • SMP 머신에서 irq 소스를 허용할 cpu affinity를 설정한다.
    • core – irq_do_set_affinity() 함수에서 호출한다.
  • (*irq_retrigger)
    • cpu로 irq를 재 전송
  • (*irq_set_type)
    • irq 라인 트리거 타입을 설정한다.
  • (*irq_set_wake)
    • irq의 pm wake-on의 enable/disable 여부 설정
    • core – irq_set_irq_wake() -> set_irq_kake_real() 함수에서 호출한다.
  • (*irq_bus_lock)
    • slow bus chip에 대한 lock으로 인터럽트를 구성하고 해제할 때 lock을 사용 한다.
      • 사용 함수
        • setup_irq()
        • free_irq()
        • request_threaded_irq()
        • setup_percpu_irq()
        • free_percpu_irq()
        • request_percpu_irq()
        • irq_finalize_oneshot()
  • (*irq_bus_sync_unlock)
    • slow bus chip에 대한 sync와 unlock
  • (*irq_cpu_online)
    • cpu가 online될 때 core – irq_cpu_online() 함수에서 호출한다.
  • (*irq_cpu_offline)
    • cpu가 offline될 때 core – irq_cpu_offline() 함수에서 호출한다.
  • (*irq_suspend)
    • PM(Power Management) 기능을 사용하는 경우 core가 suspend 되는 경우 호출되어 irq chip도같이 suspend 동작을 알려 동작을 멈추게 한다.
  • (*irq_resume)
    • PM(Power Management) 기능을 사용하는 경우 suspend된 irq chip이 깨어나 다시 동작하게 한다.
  • (*irq_pm_shutdown)
    • irq에 대한 전원 소비를 없애기 위해 shutdown 한다.
  • (*irq_calc_mask)
    • irq_data.mask의 설정을 사용한 특별한 옵션 기능
  • (*irq_print_chip)
    • show interruptes 시 추가 옵션 칩 정보를 출력
  • (*irq_request_resources)
    • irq와 관련된 모든 콜백 함수를 호출하기 전에 리소스를 요청하기 위한 옵션
  • (*irq_release_resources)
    • irq_request_resources에서 얻은 리소스를 해제
  • (*irq_compose_msi_msg)
    • MSI를 위한 메시지 구성
  • (*irq_write_msi_msg)
    • MSI를 위한 메시지 기록 옵션
  • (*irq_get_irqchip_state)
    • irqchip 내부 상태를 가져온다.
  • (*irq_set_irqchip_state)
    • irqchip 내부 상태를 저장한다.
  • (*irq_set_vcpu_affinity)
    • 가상 cpu에 대한 affinity를 지정한다.
  • (*ipi_send_single)
    • 하나의 cpu에 IPI를 전달한다.
  • (*ipi_send_mask)
    • mask 지정된 cpu에 IPI를 전달한다.
  • (*irq_nmi_setup)
    • Pesudo-NMI를 설정한다.
  • (*irq_nmi_teardown)
    • Pesudo-NMI를 해제한다.
  • flags
    • chip 관련 플래그들

 

참고

 

Interrupts -3- (irq domain)

<kernel v5.4>

IRQ Domain

각 제조사의 인터럽트 컨트롤러에는 신호 제어 또는 기능이 다른 인터럽트들을 몇 개의 그룹으로 나누어 관리하기도 한다. 리눅스 커널은 전체 인터럽트를 하나의 그룹 또는 기능별로 나뉜 그룹과 동일하게 IRQ 도메인으로 나누어 관리할 수 있다. 즉 인터럽트들을 IRQ 도메인으로 나누어 관리할 수 있다.

 

IRQ 도메인은 다음과 같은 특징이 있다.

  • hwirq는 도메인내에서 중복되지 않는다.
  • 리버스 매핑을 사용하여 구현하였다.

 

정방향 매핑(리눅스 irq -> hwirq)이 아닌 리버스 매핑(hwirq -> 리눅스 irq)을 사용하는 이유는 인터럽트 발생 시 리눅스 irq를 찾는 동작을 더 빨리 지원하기 위함이다.

 

다음 그림은 인터럽트 발생 시 hwirq를 통해  irq 디스크립터를 찾아 연결된 핸들러 함수가 호출되는 과정을 보여준다.

 

도메인 생성 타입

여러 가지 성격의 도메인을 빠르게 구현하기 위해 다음과 같은 방법들을 고려하여 몇 가지의 도메인 생성 방법을 준비하였다.

  • 리버스 맵 할당 방법
    • Linear
      • 연속 할당 매핑 공간
      • 장점: hwirq가 수 백번 이하의 번호를 사용하는 경우에 한하여 부트업 타임에 한꺼번에 리니어 매핑 배열을 만들어도 메모리 부담이 크지 않으므로 구현이 간단하다
    • Tree
      • Radix Tree를 사용한 Dynamic 할당 공간
      • 장점: hwirq 번호가 매우 큰 경우 dynamic 하게 필요한 hwirq에 대해서만 할당 구성하여 메모리를 낭비하지 않게 할 때 사용한다.
    • No-Map
      • 매핑을 위한 공간이 필요 없음 (동일 번호로 자동 매핑)
  • 매핑 조건
    • 매핑 공간 할당 시 같이 매핑하여 사용한다.
    • 매핑 공간 할당 후 추후 매핑하여 사용한다.

 

매핑 구현 방법

다음과 같은 여러 가지 구현 모델에 대해 “irq_domain_add_”로 시작하는 함수를 제공한다.

  • Linear
    • 요청 size 만큼의 리니어 매핑 공간만 만들고 매핑 연결은 하지 않는다.
    • 추후에 매핑 API 등을 사용하여 irq 디스크립터들을 생성하고 hwirq에 매핑하여 사용한다.
    • 구현
      • irq_domain_add_linear() 함수
  • Tree
    • 사이즈 제한 없이 Radix Tree를 초기화 시켜 사용한다. 매핑 공간 및 매핑 연결은 하지 않는다.
    • 추후에 매핑 API 등을 사용하여 irq 디스크립터들을 생성하고 hwirq에 매핑하여 사용한다.
    • 구현
      • irq_domain_add_tree() 함수
  • Nomap
    • irq와 hwirq가 항상 동일하여 매핑을 전혀 필요하지 않는 시스템에서 사용하다.
      • 리니어 매핑 테이블을 만들지도 않고, Radix Tree도 사용하지 않는다.
    • irq domain을 추가하기 전에 irq 디스크립터들이 미리 구성되어 있어야 한다.
    •  구현
      • irq_domain_add_nomap() 함수
  • Legacy
    • 요청 size + first_irq만큼의 리니어 매핑 공간을 만들고, first_hw_irq 매핑 번호부터 first_irq 번부터 자동으로 고정 매핑하여 사용한다.
    • legacy 방식으로 irq domain을 추가하기 전에 irq 디스크립터들이 미리 할당되어 있어야 한다.
    • 구현
      • irq_domain_add_legacy() 함수
  • Legacy ISA
    • Legacy와 동일하나 자동으로 size=16, first_irq=0, first_hw_irq=0과 같이 동작한다. (irq 수가 16개로 제한)
    • 구현
      • irq_domain_add_legacy_isa()  함수
  • Simple
    • 요청 size 만큼의 리니어 매핑 공간을 만들고, hwirq=0번부터, 그리고 irq=first_irq 번부터 irq 디스크립터들을 생성해 연결하고 순서대로 고정 매핑하여 사용한다.
    • 구현
      • irq_domain_add_simple() 함수

 

다음 그림은 여러 유형의 도메인 생성 방법을 보여준다.

 

다음 그림은 도메인 매핑 구현 모델에 따라 매핑에 대한 자료 구조, irq 디스크립터 생성 및 매핑 여부를 보여준다.

 

다음 그림은 3개의 인터럽트 컨트롤러에 대응해 nomap, linear, tree 등 3가지 방법을 섞어서 irq_domain을 구성한 예를 보여준다.

 

IRQ Domain hierarchy

2 개 이상의 인터럽트 컨틀롤러가 PM(파워 블럭 관리) 통제를 받는 경우 상위 인터럽트 컨트롤러에 파워가 공급되지 않는 경우 하위 인터럽트 컨트롤러도 인지하여 대응하는 구조가 필요하다. 이러한 경우를 위해 irq domain 하이라키 구조가 도입되었고 구현 시 기존 irq domain 에 parent 필드를 추가하여 사용할 수 있도록 수정하였다.

다음 그림은 인터럽트 컨트롤러가 2개 이상 중첩되는 경우와 한 개의 컨트롤러만 사용하는 경우를 비교하였다.

  • gic가 parent 인터럽트 컨트롤러이며 먼저 초기화된다.

 


IRQ Domain  생성(추가) 및 삭제

도메인 추가 -1- (linear)

irq_domain_add_linear()

kernel/irq/irqdomain.c

/**
 * irq_domain_add_linear() - Allocate and register a linear revmap irq_domain.
 * @of_node: pointer to interrupt controller's device tree node.
 * @size: Number of interrupts in the domain.
 * @ops: map/unmap domain callbacks
 * @host_data: Controller private data pointer
 */
static inline struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
                                         unsigned int size,
                                         const struct irq_domain_ops *ops,
                                         void *host_data)
{
        return __irq_domain_add(of_node_to_fwnode(of_node), size, size, 0, ops, host_data);
}

size 만큼의 선형 리버스 매핑 블럭을 사용할 계획으로 도메인을 할당한다. 이 함수에서는 매핑을 하지 않으므로, 매핑은 추후 irq_create_mapping() 함수를 사용하여 다이나믹하게 매핑할 수 있다.

  • 연속된 리버스 매핑 공간에서 자유로운 인터럽트 매핑 방식이 필요한 인터럽트 컨트롤러 드라이버에 사용된다.
    • 예) 약 30개 드라이버에서 사용한다.
      • arm,gic
      • arm,nvic
      • bcm,bcm2835
      • bcm,bcm2836
      • exynos-combiner
      • samsung,s3c24xx
      • armada-370-xp

 

도메인 추가 -2- (nomap)

irq_domain_add_nomap()

kernel/irq/irqdomain.c

static inline struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
                                         unsigned int max_irq,
                                         const struct irq_domain_ops *ops,
                                         void *host_data)
{
        return __irq_domain_add(of_node_to_fwnode(of_node), 0, max_irq, max_irq, ops, host_data);
}

리니어 매핑 공간 또는 Radix Tree를 사용한 매핑 공간을 사용하지 않고, max_irq 수 만큼 irq 도메인을 생성한다. 매핑을 하지 않으므로 생성한 개수만큼 hwirq 번호는 irq 번호와 동일하게 사용한다.

  • 대부분의 아키텍처에서 사용하지 않는 방식이다. 현재 4 개의 powerpc 아키텍처용 드라이버에서 사용한다.

 

도메인 추가 -3- (legacy)

irq_domain_add_legacy()

kernel/irq/irqdomain.c

/**
 * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
 * @of_node: pointer to interrupt controller's device tree node.
 * @size: total number of irqs in legacy mapping
 * @first_irq: first number of irq block assigned to the domain
 * @first_hwirq: first hwirq number to use for the translation. Should normally
 *               be '0', but a positive integer can be used if the effective
 *               hwirqs numbering does not begin at zero.
 * @ops: map/unmap domain callbacks
 * @host_data: Controller private data pointer
 *
 * Note: the map() callback will be called before this function returns
 * for all legacy interrupts except 0 (which is always the invalid irq for
 * a legacy controller).
 */
struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
                                         unsigned int size,
                                         unsigned int first_irq,
                                         irq_hw_number_t first_hwirq,
                                         const struct irq_domain_ops *ops,
                                         void *host_data)
{
        struct irq_domain *domain;

        domain = __irq_domain_add(of_node_to_fwnode(of_node), first_hwirq + size,
                                  first_hwirq + size, 0, ops, host_data);
        if (domain)
                irq_domain_associate_many(domain, first_irq, first_hwirq, size);

        return domain;
}
EXPORT_SYMBOL_GPL(irq_domain_add_legacy);

요청 size + first_irq만큼의 리니어 매핑 공간을 만들고, first_hw_irq 매핑 번호부터 first_irq 번호를 자동으로 고정 매핑하여 사용한다. 미리 매핑 후 변경이 필요 없는 구성에서 사용한다.

  • 미리 구성해 놓은 연속된 리버스 매핑 공간을 사용한 인터럽트 매핑 방식이 필요한 인터럽트 컨트롤러 드라이버에 사용된다.
    • 예) 약 10 여개 드라이버에서 사용한다.
      • arm,gic
      • mmp
      • samsung,s3c24xx
      • hip04

 

 

도메인 추가 -4- (legacy, isa)

irq_domain_add_legacy_isa()

kernel/irq/irqdomain.c

static inline struct irq_domain *irq_domain_add_legacy_isa(
                                struct device_node *of_node,
                                const struct irq_domain_ops *ops,
                                void *host_data)
{
        return irq_domain_add_legacy(of_node, NUM_ISA_INTERRUPTS, 0, 0, ops,
                                     host_data);
}

고정된 16(legacy ISA 하드웨어가 사용하는 최대 인터럽트 수)개 인터럽트 수 만큼의 이미 만들어놓은 선형 리버스 매핑 블럭을 사용할 계획으로 도메인을 할당받아 구성한다. 매핑 후 변경이 필요 없는 구성에서 사용한다.

  • 대부분의 아키텍처에서 사용하지 않는 방식이다. 현재 2 개의 powerpc 아키텍처용 드라이버에서 사용한다.

 

도메인 추가 -5- (tree)

irq_domain_add_tree()

kernel/irq/irqdomain.c

static inline struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
                                         const struct irq_domain_ops *ops,
                                         void *host_data)
{
        return __irq_domain_add(of_node_to_fwnode(of_node), 0, ~0, 0, ops, host_data);
}

Radix tree로 관리되는 리버스 매핑 블럭을 사용할 계획으로 도메인을 할당받아 구성한다. 구성된 후 자유롭게 매핑/해제를 할 수 있다.

  • 하드웨어 인터럽트 번호가 매우 큰 시스템에서 메모리 낭비 없이 자유로운 인터럽트 매핑 방식이 필요한 인터럽트 컨트롤러 드라이버에 사용된다.
    • 예) arm에서는 최근 버전의 gic 컨트롤러 드라이버 3개가 사용하고, 다른 몇 개의 아키텍처에서도 사용한다.
      • arm,gic-v2m
      • arm,gic-v3
      • arm,gic-v3-its

 

도메인 추가 -6- (simple)

irq_domain_add_simple()

kernel/irq/irqdomain.c

/**
 * irq_domain_add_simple() - Register an irq_domain and optionally map a range of irqs
 * @of_node: pointer to interrupt controller's device tree node.
 * @size: total number of irqs in mapping
 * @first_irq: first number of irq block assigned to the domain,
 *      pass zero to assign irqs on-the-fly. If first_irq is non-zero, then
 *      pre-map all of the irqs in the domain to virqs starting at first_irq.
 * @ops: domain callbacks
 * @host_data: Controller private data pointer
 *
 * Allocates an irq_domain, and optionally if first_irq is positive then also
 * allocate irq_descs and map all of the hwirqs to virqs starting at first_irq.
 *
 * This is intended to implement the expected behaviour for most
 * interrupt controllers. If device tree is used, then first_irq will be 0 and
 * irqs get mapped dynamically on the fly. However, if the controller requires
 * static virq assignments (non-DT boot) then it will set that up correctly.
 */
struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
                                         unsigned int size,
                                         unsigned int first_irq,
                                         const struct irq_domain_ops *ops,
                                         void *host_data)
{
        struct irq_domain *domain;

        domain = __irq_domain_add(of_node_to_fwnode(of_node), size, size, 0, ops, host_data);
        if (!domain)
                return NULL;

        if (first_irq > 0) {
                if (IS_ENABLED(CONFIG_SPARSE_IRQ)) {
                        /* attempt to allocated irq_descs */
                        int rc = irq_alloc_descs(first_irq, first_irq, size,
                                                 of_node_to_nid(of_node));
                        if (rc < 0)
                                pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
                                        first_irq);
                }
                irq_domain_associate_many(domain, first_irq, 0, size);
        }

        return domain;
}
EXPORT_SYMBOL_GPL(irq_domain_add_simple);

요청 size 만큼의 리니어 매핑 공간을 만들고 hwirq=0번부터, irq=first_irq 번호부터 순서대로 자동으로 고정 매핑하여 사용한다.

  • 간단하게 irq 도메인을 만들고 매핑하기 위한 시스템 드라이버에서 사용하며 약 10여개 드라이버에서 사용한다.
      • arm,vic
      • versatile-fpga
      • sa11x0

 

hierarchy 구성을 위한 도메인 추가

irq_domain_add_hierarchy()

include/linux/irqdomain.h

static inline struct irq_domain *irq_domain_add_hierarchy(struct irq_domain *parent,
                                            unsigned int flags,
                                            unsigned int size,
                                            struct device_node *node,
                                            const struct irq_domain_ops *ops,
                                            void *host_data)
{
        return irq_domain_create_hierarchy(parent, flags, size,
                                           of_node_to_fwnode(node),
                                           ops, host_data);
}

하이라키 irq 도메인을 추가한다.

 

irq_domain_create_hierarchy()

kernel/irq/irqdomain.c

/**
 * irq_domain_create_hierarchy - Add a irqdomain into the hierarchy
 * @parent:     Parent irq domain to associate with the new domain
 * @flags:      Irq domain flags associated to the domain
 * @size:       Size of the domain. See below
 * @node:       Optional device-tree node of the interrupt controller
 * @ops:        Pointer to the interrupt domain callbacks
 * @host_data:  Controller private data pointer
 *
 * If @size is 0 a tree domain is created, otherwise a linear domain.
 *
 * If successful the parent is associated to the new domain and the
 * domain flags are set.
 * Returns pointer to IRQ domain, or NULL on failure.
 */
struct irq_domain *irq_domain_create_hierarchy(struct irq_domain *parent,
                                            unsigned int flags,
                                            unsigned int size,
                                            struct device_node *node,
                                            const struct irq_domain_ops *ops,
                                            void *host_data)
{
        struct irq_domain *domain;

        if (size)
                domain = irq_domain_create_linear(node, size, ops, host_data);
        else
                domain = irq_domain_create_tree(node, ops, host_data);
        if (domain) {
                domain->parent = parent;
                domain->flags |= flags;
        }

        return domain;
}
EXPORT_SYMBOL_GPL(irq_domain_create_hierarchy);

주어진 인수 size에 따라 선형 또는 Radix tree로 관리되는 리버스 매핑 블럭을 사용할 계획으로 하이라키 도메인을 생성 시 사용한다. 구성된 후 자유롭게 매핑/해제를 할 수 있다.

  • domain 간 부모관계를 설정하고자 할 때 사용하며, 현재 몇 개의 arm 및 다른 아키텍처 드라이버에서 사용한다.
      • tegra
      • imx-gpcv2
      • mtk-sysirq
      • vf610-mscm-ir
      • crossbar

 

irq 도메인 추가 공통 함수

__irq_domain_add()

kernel/irq/irqdomain.c -1/2-

/**
 * __irq_domain_add() - Allocate a new irq_domain data structure
 * @of_node: optional device-tree node of the interrupt controller
 * @size: Size of linear map; 0 for radix mapping only
 * @hwirq_max: Maximum number of interrupts supported by controller
 * @direct_max: Maximum value of direct maps; Use ~0 for no limit; 0 for no
 *              direct mapping
 * @ops: domain callbacks
 * @host_data: Controller private data pointer
 *
 * Allocates and initialize and irq_domain structure.
 * Returns pointer to IRQ domain, or NULL on failure.
 */
struct irq_domain *__irq_domain_add(struct fwnode_handle *fwnode, int size,
                                    irq_hw_number_t hwirq_max, int direct_max,
                                    const struct irq_domain_ops *ops,
                                    void *host_data)
{
        struct device_node *of_node = to_of_node(fwnode);
        struct irqchip_fwid *fwid;
        struct irq_domain *domain;

        static atomic_t unknown_domains;

        domain = kzalloc_node(sizeof(*domain) + (sizeof(unsigned int) * size),
                              GFP_KERNEL, of_node_to_nid(of_node));
        if (!domain)
                return NULL;

        if (fwnode && is_fwnode_irqchip(fwnode)) {
                fwid = container_of(fwnode, struct irqchip_fwid, fwnode);

                switch (fwid->type) {
                case IRQCHIP_FWNODE_NAMED:
                case IRQCHIP_FWNODE_NAMED_ID:
                        domain->fwnode = fwnode;
                        domain->name = kstrdup(fwid->name, GFP_KERNEL);
                        if (!domain->name) {
                                kfree(domain);
                                return NULL;
                        }
                        domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
                        break;
                default:
                        domain->fwnode = fwnode;
                        domain->name = fwid->name;
                        break;
                }
#ifdef CONFIG_ACPI
        } else if (is_acpi_device_node(fwnode)) {
                struct acpi_buffer buf = {
                        .length = ACPI_ALLOCATE_BUFFER,
                };
                acpi_handle handle;

                handle = acpi_device_handle(to_acpi_device_node(fwnode));
                if (acpi_get_name(handle, ACPI_FULL_PATHNAME, &buf) == AE_OK) {
                        domain->name = buf.pointer;
                        domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
                }

                domain->fwnode = fwnode;
#endif
        } else if (of_node) {
                char *name;

                /*
                 * DT paths contain '/', which debugfs is legitimately
                 * unhappy about. Replace them with ':', which does
                 * the trick and is not as offensive as '\'...
                 */
                name = kasprintf(GFP_KERNEL, "%pOF", of_node);
                if (!name) {
                        kfree(domain);
                        return NULL;
                }

                strreplace(name, '/', ':');

                domain->name = name;
                domain->fwnode = fwnode;
                domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
        }

하나의 irq 도메인을 추가하고 전달된 인수에 대해 다음과 같이 준비한다.

  • 인자 @size가 주어지는 경우 size 만큼의 리니어 리버스 맵을 준비한다.
  • 인자 @hwirq_max는 현재 도메인에서 최대 처리할 하드웨어 인터럽트 수이다.
  • 인자 @direct_max가 주어지는 경우 해당 범위는 리버스 맵을  사용하지 않는다.
  • 인자 @ops는 리버스 매핑과 변환 함수에 대한 콜백 후크를 제공한다.
  • 인자 @host_data는 private 데이터 포인터를 전달할 수 있다.

 

  • 코드 라인 12~15에서 irq 도메인 구조체를 할당한다. 구조체의 마지막에 위치한 linear_revmap[]을 위해 @size 만큼의 정수 배열이 추가된다.
  • 코드 라인 17~70에서 irq 도메인에 fwnode와 이름 정보를 저장한다. 이름 정보가 저장된 경우 IRQ_DOMAIN_NAME_ALLOCATED 플래그를 설정한다.
    • 디바이스 트리 노드가 주어진 경우 노드명으로 이름을 지정하되 ‘:’ 문자열은 ‘/’로 변경된다.

 

kernel/irq/irqdomain.c -2/2-

        if (!domain->name) {
                if (fwnode)
                        pr_err("Invalid fwnode type for irqdomain\n");
                domain->name = kasprintf(GFP_KERNEL, "unknown-%d",
                                         atomic_inc_return(&unknown_domains));
                if (!domain->name) {
                        kfree(domain);
                        return NULL;
                }
                domain->flags |= IRQ_DOMAIN_NAME_ALLOCATED;
        }

        of_node_get(of_node);

        /* Fill structure */
        INIT_RADIX_TREE(&domain->revmap_tree, GFP_KERNEL);
        mutex_init(&domain->revmap_tree_mutex);
        domain->ops = ops;
        domain->host_data = host_data;
        domain->hwirq_max = hwirq_max;
        domain->revmap_size = size;
        domain->revmap_direct_max_irq = direct_max;
        irq_domain_check_hierarchy(domain);

        mutex_lock(&irq_domain_mutex);
        debugfs_add_domain_dir(domain);
        list_add(&domain->link, &irq_domain_list);
        mutex_unlock(&irq_domain_mutex);

        pr_debug("Added domain %s\n", domain->name);
        return domain;
}
EXPORT_SYMBOL_GPL(__irq_domain_add);
  • 코드 라인 1~11에서 도메인 명이 없는 경우 “unknown-<순번>” 명칭으로 사용한다.
  • 코드 라인 16~17에서 tree 형태로 domain을 사용할 수 있도록 radix tree를 초기화한다.
  • 코드 라인 18~22에서 전달받은 인수를 domain에 설정한다.
  • 코드 라인 23에서 hierarchy 구성인 경우 IRQ_DOMAIN_FLAG_HIERARCHY  플래그를 추가한다.
  • 코드 라인 26에서 debugfs에 도메인 디버깅을 위해 디렉토리를 생성한다.
  • 코드 라인 27에서 전역 irq_domain_list에 생성한 도메인을 추가한다.
  • 코드 라인 30에서 만들어진 도메인 정보를 디버그 출력한다.
  • 코드 라인 31에서 성공적으로 생성한 도메인을 반환한다.

 

irq_domain_check_hierarchy()

kernel/irq/irqdomain.c

static void irq_domain_check_hierarchy(struct irq_domain *domain)
{
        /* Hierarchy irq_domains must implement callback alloc() */
        if (domain->ops->alloc)
                domain->flags |= IRQ_DOMAIN_FLAG_HIERARCHY;
}

도메인이hierarchy 구성인 경우 IRQ_DOMAIN_FLAG_HIERARCHY  플래그를 추가한다.

 

IRQ Domain  제거

irq_domain_remove()

kernel/irq/irqdomain.c

/**
 * irq_domain_remove() - Remove an irq domain.
 * @domain: domain to remove
 *
 * This routine is used to remove an irq domain. The caller must ensure
 * that all mappings within the domain have been disposed of prior to
 * use, depending on the revmap type.
 */
void irq_domain_remove(struct irq_domain *domain)
{
        mutex_lock(&irq_domain_mutex);

        /*
         * radix_tree_delete() takes care of destroying the root
         * node when all entries are removed. Shout if there are
         * any mappings left.
         */
        WARN_ON(domain->revmap_tree.height);

        list_del(&domain->link);

        /*
         * If the going away domain is the default one, reset it.
         */
        if (unlikely(irq_default_domain == domain))
                irq_set_default_host(NULL);

        mutex_unlock(&irq_domain_mutex);

        pr_debug("Removed domain %s\n", domain->name);

        of_node_put(domain->of_node);
        kfree(domain);
}
EXPORT_SYMBOL_GPL(irq_domain_remove);

전역 irq_domain_list에서 요청한 irq domain을 제거하고 할당 해제한다.

  • 코드 라인 12에서 전역 irq_domain_list에서 요청한 irq domain을 제거한다.
  • 코드 라인 17~18에서 낮은 확률로 요청 domain이 irq_default_domain인 경우 irq_default_domain을 null로 설정한다.
    • arm이 아닌 하드 코딩된 몇 개의 아키텍처 드라이버에서 irq domain을 구현하지 않고 인터럽트 번호를 사용할 목적으로 irq_create_mapping() 함수에서 domain 대신 NULL을 인자로 사용한다.
  • 코드 라인 24~25에서 디바이스 노드의 참조를 해제하고 domain을 할당 해제한다.

 


IRQ 매핑 및 해제

다음은 도메인내 매핑 연결 및 해제 API들이다.

  • irq_domain_associate()
    • irq 디스크립터와 <–> hwirq를 매핑한다.
  • irq_domain_associate_many()
    • 위의 API 기능을 복수로 수행한다.
  • irq_domain_disassociate()
    • irq 디스크립터와 <–> hwirq를 매핑 해제한다.

 

매핑 연결 -1- (single)

irq_domain_associate()

kernel/irq/irqdomain.c

int irq_domain_associate(struct irq_domain *domain, unsigned int virq,
                         irq_hw_number_t hwirq)
{
        struct irq_data *irq_data = irq_get_irq_data(virq);
        int ret;

        if (WARN(hwirq >= domain->hwirq_max,
                 "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name))
                return -EINVAL;
        if (WARN(!irq_data, "error: virq%i is not allocated", virq))
                return -EINVAL;
        if (WARN(irq_data->domain, "error: virq%i is already associated", virq))
                return -EINVAL;

        mutex_lock(&irq_domain_mutex);
        irq_data->hwirq = hwirq;
        irq_data->domain = domain;
        if (domain->ops->map) {
                ret = domain->ops->map(domain, virq, hwirq);
                if (ret != 0) {
                        /*
                         * If map() returns -EPERM, this interrupt is protected
                         * by the firmware or some other service and shall not
                         * be mapped. Don't bother telling the user about it.
                         */
                        if (ret != -EPERM) {
                                pr_info("%s didn't like hwirq-0x%lx to VIRQ%i mapping (rc=%d)\n",
                                       domain->name, hwirq, virq, ret);
                        }
                        irq_data->domain = NULL;
                        irq_data->hwirq = 0;
                        mutex_unlock(&irq_domain_mutex);
                        return ret;
                }

                /* If not already assigned, give the domain the chip's name */
                if (!domain->name && irq_data->chip)
                        domain->name = irq_data->chip->name;
        }

        domain->mapcount++;
        irq_domain_set_mapping(domain, hwirq, irq_data);
        mutex_unlock(&irq_domain_mutex);

        irq_clear_status_flags(virq, IRQ_NOREQUEST);

        return 0;
}
EXPORT_SYMBOL_GPL(irq_domain_associate);

irq 디스크립터와 hwirq를 매핑한다. 도메인의 ops->map 후크에 등록한 콜백 함수가 있는 경우 해당 컨트롤러를 통해 매핑을 설정한다.

  • 코드 라인 4에서 irq 디스크립터의 irq_data를 알아온다.
  • 코드 라인 7~13에서 다음과 같이 에러가 있는 경우 경고 메시지를 출력하고 -EINVAL 에러를 반환한다.
    • hwirq 번호가 도메인의 hwirq_max 이상인 경우
    • irq 디스크립터가 할당되어 있지 않은 경우
    • 이미 domain에 연결되어 있는 경우
  • 코드 라인 16~17에서 irq_data의 hwirq와 domain 정보를 설정한다.
  • 코드 라인 18~34에서 irq domain의 map 후크에 핸들러 함수가 연결된 경우 호출하여 컨트롤러로 하여금 매핑을 수행하게 한다. 만일 매핑이 실패한 경우 허가되지 않은 irq인 경우 단순 메시지만 출력하고 irq_data의 domain과 hwirq에 null과 0을 설정후 함수를 빠져나간다.
  • 코드 라인 37~38에서 domain에 이름이 설정되지 않은 경우 컨트롤러 이름을 대입한다.
  • 코드 라인 42에서요청한 도메인에서 @hwirq와 irq 디스크립터를 매핑한다.
  • 코드 라인 45에서 irq 라인 상태에에서 norequest 플래그를 클리어한다.
    • IRQ_NOREQUEST
      • 현재 irq 라인에 요청된 인터럽트가 없다.

 

irq_domain_set_mapping()

kernel/irq/irqdomain.c

static void irq_domain_set_mapping(struct irq_domain *domain,
                                   irq_hw_number_t hwirq,
                                   struct irq_data *irq_data)
{
        if (hwirq < domain->revmap_size) {
                domain->linear_revmap[hwirq] = irq_data->irq;
        } else {
                mutex_lock(&domain->revmap_tree_mutex);
                radix_tree_insert(&domain->revmap_tree, hwirq, irq_data);
                mutex_unlock(&domain->revmap_tree_mutex);
        }
}

요청한 도메인에서 @hwirq와 irq 디스크립터를 매핑한다.

  • 코드 라인 5~6에서 linear 방식에서 사용되는 irq인 경우 리니어용 리버스 맵 테이블에서 hwirq에 대응하는 곳에 irq 디스크립터와 매핑한다.
  • 코드 라인 7~11에서 tree 방식에서 사용되는 irq인 경우 radix tree용 리버스 맵에 hwirq를 추가하고 irq 디스크립터와 매핑한다.

 

매핑 연결 -2- (many)

irq_domain_associate_many()

kernel/irq/irqdomain.c

void irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
                               irq_hw_number_t hwirq_base, int count)
{
        int i;

        pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__,
                of_node_full_name(domain->of_node), irq_base, (int)hwirq_base, count);

        for (i = 0; i < count; i++) {
                irq_domain_associate(domain, irq_base + i, hwirq_base + i);
        }
}
EXPORT_SYMBOL_GPL(irq_domain_associate_many);

@irq_base로 시작하는 irq 디스크립터들을 @count 수 만큼 @hwirq_base 번호부터 매핑한다. 해당 도메인의 ops->map 후크에 등록한 콜백 함수가 있는 경우 해당 컨트롤러를 통해 각각의 매핑을 설정한다.

 

매핑 해제

irq_domain_disassociate()

kernel/irq/irqdomain.c

void irq_domain_disassociate(struct irq_domain *domain, unsigned int irq)
{
        struct irq_data *irq_data = irq_get_irq_data(irq);
        irq_hw_number_t hwirq;

        if (WARN(!irq_data || irq_data->domain != domain,
                 "virq%i doesn't exist; cannot disassociate\n", irq))
                return;

        hwirq = irq_data->hwirq;
        irq_set_status_flags(irq, IRQ_NOREQUEST);

        /* remove chip and handler */
        irq_set_chip_and_handler(irq, NULL, NULL);

        /* Make sure it's completed */
        synchronize_irq(irq);

        /* Tell the PIC about it */
        if (domain->ops->unmap)
                domain->ops->unmap(domain, irq);
        smp_mb();

        irq_data->domain = NULL;
        irq_data->hwirq = 0;

        /* Clear reverse map for this hwirq */
        if (hwirq < domain->revmap_size) {
                domain->linear_revmap[hwirq] = 0;
        } else {
                mutex_lock(&revmap_trees_mutex);
                radix_tree_delete(&domain->revmap_tree, hwirq);
                mutex_unlock(&revmap_trees_mutex);
        }
}

요청 irq에 대해 매핑된 hwirq와의 매핑을 해제한다. 도메인의 ops->unmap 후크에 등록한 콜백 함수가 있는 경우 해당 컨트롤러를 통해 매핑 해제를 설정한다.

 

arch/arm/mach-bcm2709/armctrl.c

static struct irq_domain_ops armctrl_ops = {
        .xlate = armctrl_xlate
};

bcm2708 및 bcm2709는 리눅스 irq와 hw irq의 변환은 인터럽트 컨트롤러에 고정되어 있어 sw로 매핑 구성을 변경할 수 없다. 따라서 매핑 및 언매핑용 함수는 제공되지 않고 argument -> hwirq 변환 함수만 제공한다.

  • argument
    • “interrupts = < x, … > 값

 


IRQ 매핑 생성 및 삭제

 

다음은 도메인내 dynamic하게 매핑을 생성(연결 포함) 및 삭제할 수 있는 API들이다. 이들은 dynamic 매핑 방법을 사용하는 linear, tree 및 hierarchy 방식의 irq domain에서 사용한다.

  • irq_create_mapping()
    • irq 디스크립터를 할당하고 지정한 hwirq에 매핑한다.
  • irq_create_of_mapping()
    • irq 디스크립터를 할당하고 디바이스 트리 노드를 통해 알아온 phandle argument 값을 파싱하여 변환한 hwirq에 매핑한다.
  • irq_create_fwspec_mapping()
    • irq 디스크립터를 할당하고 인자로 전달받은 fwspec 구조체를 통해 변환한 hwirq에 매핑한다.
  • irq_create_identity_mapping()
    • hwirq와 irq가 동일한 irq 디스크립터를 할당하고 hwirq에 매핑한다.
  • irq_create_strict_mapping()
    • 복수개의 irq 디스크립터들을 할당하고 지정한 irq 및 hwirq 번호들에 순서대로 매핑한다.
  • irq_create_direct_mapping()
    • irq 디스크립터를 하나 할당받은 후 hwirq 번호와 동일하게 1:1 직접 매핑 방법으로 매핑한다. (hwirq = irq)
  • irq_dispose_mapping()
    • 매핑을 해제하고 irq 디스크립터를 삭제한다.

 

다음 그림은 irq 도메인내에서 irq <–> hwirq 매핑과 irq 디스크립터와의 연동을 수행하는 몇 가지 API들을 보여준다.

 

매핑 생성 -1- (Dynamic)

irq_create_mapping()

kernel/irq/irqdomain.c

/**
 * irq_create_mapping() - Map a hardware interrupt into linux irq space
 * @domain: domain owning this hardware interrupt or NULL for default domain
 * @hwirq: hardware irq number in that domain space
 *
 * Only one mapping per hardware interrupt is permitted. Returns a linux
 * irq number.
 * If the sense/trigger is to be specified, set_irq_type() should be called
 * on the number returned from that call.
 */
unsigned int irq_create_mapping(struct irq_domain *domain,
                                irq_hw_number_t hwirq)
{
        int virq;

        pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);

        /* Look for default domain if nececssary */
        if (domain == NULL)
                domain = irq_default_domain;
        if (domain == NULL) {
                WARN(1, "%s(, %lx) called with NULL domain\n", __func__, hwirq);
                return 0;
        }
        pr_debug("-> using domain @%p\n", domain);

        of_node = irq_domain_get_of_node(domain);
        /* Check if mapping already exists */
        virq = irq_find_mapping(domain, hwirq);
        if (virq) {
                pr_debug("-> existing mapping on virq %d\n", virq);
                return virq;
        }

        /* Allocate a virtual interrupt number */
        virq = irq_domain_alloc_descs(-1, 1, hwirq, of_node_to_nid(domain->of_node), NULL);
        if (virq <= 0) {
                pr_debug("-> virq allocation failed\n");
                return 0;
        }

        if (irq_domain_associate(domain, virq, hwirq)) {
                irq_free_desc(virq);
                return 0;
        }

        pr_debug("irq %lu on domain %s mapped to virtual irq %u\n",
                hwirq, of_node_full_name(domain->of_node), virq);

        return virq;
}
EXPORT_SYMBOL_GPL(irq_create_mapping);

요청한 hwirq로 리눅스 irq를 배정 받아 매핑하고 그 번호를 반환한다.  hwirq를 음수로 지정하는 경우 리눅스 irq를 배정한다.

  • 코드 라인 9~10에서 domain이 null로 지정된 경우 default domain을 선택한다.
  • 코드 라인 11~14에서 domain이 여전히 null인 경우 경고 메시지 출력과 함께 0을 반환한다.
  • 코드 라인 17에서 도메인에 대한 디바이스 노드 정보를 알아온다.
  • 코드 라인 19~23에서 domain에서 hwirq 에 매핑된 값이 있는지 알아온다. 만일 이미 매핑이 존재하는 경우 디버그 메시지 출력과 함께 0을 반환한다.
  • 코드 라인 26~30에서 irq 디스크립터를 할당한다.
  • 코드 라인 32~35에서 할당한 irq 디스크립터를 hwirq에 매핑한다.
  • 코드 라인 37~40에서 성공한 매핑에 대해 디버그 메시지를 출력하고, virq 값을 반환한다.

 

다음 그림은 irq 디스크립터를 할당하여 hwirq에 매핑을 생성하는 모습을 보여준다.

 

매핑 생성 -2- (Device Tree)

irq_create_of_mapping()

kernel/irq/irqdomain.c

unsigned int irq_create_of_mapping(struct of_phandle_args *irq_data)
{
        struct irq_fwspec fwspec;

        of_phandle_args_to_fwspec(irq_data->np, irq_data->args,
                                  irq_data->args_count, &fwspec);

        return irq_create_fwspec_mapping(&fwspec);
}
EXPORT_SYMBOL_GPL(irq_create_of_mapping);

irq 디스크립터를 할당하고 디바이스 트리 노드를 통해 알아온 phandle argument 값을 파싱하여 변환한 hwirq에 매핑한다.

 

예) irq2의 uart 디바이스

        uart0: uart@7e201000 {
                compatible = "arm,pl011", "arm,primecell";
                reg = <0x7e201000 0x1000>;
                interrupts = <2 25>;
                ...
        };
  • uart의 인터럽트의 인자는 2개로 <2 25> -> bank #2, bit 25 인터럽트
  • hwirq로 변환 -> 57
  • 할당한 irq 디스크립터의 irq=83이라고 가정하면 이 irq(83)과 hwirq(57)을 매핑한다.

 

매핑 생성 -3- (fwspec)

irq_create_fwspec_mapping()

kernel/irq/irqdomain.c -1/2-

unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec)
{
        struct irq_domain *domain;
        struct irq_data *irq_data;
        irq_hw_number_t hwirq;
        unsigned int type = IRQ_TYPE_NONE;
        int virq;

        if (fwspec->fwnode) {
                domain = irq_find_matching_fwspec(fwspec, DOMAIN_BUS_WIRED);
                if (!domain)
                        domain = irq_find_matching_fwspec(fwspec, DOMAIN_BUS_ANY);
        } else {
                domain = irq_default_domain;
        }

        if (!domain) {
                pr_warn("no irq domain found for %s !\n",
                        of_node_full_name(to_of_node(fwspec->fwnode)));
                return 0;
        }

        if (irq_domain_translate(domain, fwspec, &hwirq, &type))
                return 0;

        /*
         * WARN if the irqchip returns a type with bits
         * outside the sense mask set and clear these bits.
         */
        if (WARN_ON(type & ~IRQ_TYPE_SENSE_MASK))
                type &= IRQ_TYPE_SENSE_MASK;

        /*
         * If we've already configured this interrupt,
         * don't do it again, or hell will break loose.
         */
        virq = irq_find_mapping(domain, hwirq);
        if (virq) {
                /*
                 * If the trigger type is not specified or matches the
                 * current trigger type then we are done so return the
                 * interrupt number.
                 */
                if (type == IRQ_TYPE_NONE || type == irq_get_trigger_type(virq))
                        return virq;

                /*
                 * If the trigger type has not been set yet, then set
                 * it now and return the interrupt number.
                 */
                if (irq_get_trigger_type(virq) == IRQ_TYPE_NONE) {
                        irq_data = irq_get_irq_data(virq);
                        if (!irq_data)
                                return 0;

                        irqd_set_trigger_type(irq_data, type);
                        return virq;
                }

                pr_warn("type mismatch, failed to map hwirq-%lu for %s!\n",
                        hwirq, of_node_full_name(to_of_node(fwspec->fwnode)));
                return 0;
        }

Device Tree 스크립트에서 인터럽트 컨르롤러와 연결되는 디바이스에 대해 매핑을 수행한다.

  • 코드 라인 9~15에서 @fwspce을 통해 fwnode가 존재하면 해당 도메인을 알아오고, 찾지 못한 경우 default  domain을 사용한다.
  • 코드 라인 17~21에서 domain이 없는 경우 경고 메시지를 출력하고 함수를 빠져나간다.
  • 코드 라인 23~24에서 도메인에 등록한 변환 함수인 (*xlate) 후크 함수를 호출하여 hwirq 값과 타입을 구해온다.
    • 예) Device Tree의 경우 인터럽트를 사용하는 각 장치의 “interrupts = { a1, a2 }”에서 인수 2 개로 hwirq 값을 알아온다.
  • 코드 라인 30~31에서 IRQ_TYPE_SENSE_MASK에 해당하는 타입만 허용한다.
  • 코드 라인 37에서 도메인 변환을 통해 찾아온 hwirq에 해당하는 매핑을 통해 virq를 알아온다.
  • 코드 라인 38~63에서 virq가 이미 매핑된 경우 함수를 빠져나간다. 단 함수 타입 체크를 수행하여 다른 경우 경고 메시지를 출력한다.

 

kernel/irq/irqdomain.c -2/2-

        if (irq_domain_is_hierarchy(domain)) {
                virq = irq_domain_alloc_irqs(domain, 1, NUMA_NO_NODE, fwspec);
                if (virq <= 0)
                        return 0;
        } else {
                /* Create mapping */
                virq = irq_create_mapping(domain, hwirq);
                if (!virq)
                        return virq;
        }

        irq_data = irq_get_irq_data(virq);
        if (!irq_data) {
                if (irq_domain_is_hierarchy(domain))
                        irq_domain_free_irqs(virq, 1);
                else
                        irq_dispose_mapping(virq);
                return 0;
        }

        /* Store trigger type */
        irqd_set_trigger_type(irq_data, type);

        return virq;
}
EXPORT_SYMBOL_GPL(irq_create_fwspec_mapping);
  • 코드 라인 1~10에서 hierarch를 지원하는 irq domain인 경우 irq 디스크립터만 할당해오고, 그럲지 않은 경우 irq 디스크립터를 할당해서 hwirq에 매핑한다.
  • 코드 라인 12~19에서 irq 디스크립터가 할당되지 않은 경우 매핑을 취소하고 함수를 빠져나간다.
  • 코드 라인 22에서 트리거 타입을 지정한다.
  • 코드 라인 24에서 성공적으로 할당받은 virq를 반환한다.

 

매핑 생성 -4- (Identity)

irq_create_identity_mapping()

kernel/irq/irqdomain.c

static inline int irq_create_identity_mapping(struct irq_domain *host,
                                              irq_hw_number_t hwirq)
{
        return irq_create_strict_mappings(host, hwirq, hwirq, 1);
}

@hwirq 번호와 동일한 irq를 사용하는 irq 디스크립터를 할당받은 후 @hwirq 번호에 매핑 한다.

 

매핑 생성 -5- (Strict)

irq_create_strict_mappings()

kernel/irq/irqdomain.c

/**
 * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs
 * @domain: domain owning the interrupt range
 * @irq_base: beginning of linux IRQ range
 * @hwirq_base: beginning of hardware IRQ range
 * @count: Number of interrupts to map
 *
 * This routine is used for allocating and mapping a range of hardware
 * irqs to linux irqs where the linux irq numbers are at pre-defined
 * locations. For use by controllers that already have static mappings
 * to insert in to the domain.
 *
 * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time
 * domain insertion.
 *
 * 0 is returned upon success, while any failure to establish a static
 * mapping is treated as an error.
 */
int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
                               irq_hw_number_t hwirq_base, int count)
{
        struct device_node *of_node;
        int ret;

        of_node = irq_domain_get_of_node(domain);
        ret = irq_alloc_descs(irq_base, irq_base, count,
                              of_node_to_nid(of_node));
        if (unlikely(ret < 0))
                return ret;

        irq_domain_associate_many(domain, irq_base, hwirq_base, count);
        return 0;
}
EXPORT_SYMBOL_GPL(irq_create_strict_mappings);

@irq_base 번호부터 @count 수 만큼 irq 디스크립터를 할당받은 후 @hwirq_base 부터 @count 수 만큼 매핑 한다.

  • 코드 라인 7~11에서 irq_base 번호부터 count 만큼의 irq 디스크립터를 할당 받아온다.
  • 코드 라인 13에서 irq_base 번호에 해당하는 irq 디스크립터들을 hwirq_base 번호부터 @count 수 만큼 매핑한다.
  • 코드 라인 14에서 성공 값 0을 반환한다.

 

매핑 생성 -6- (Direct)

irq_create_direct_mapping()

kernel/irq/irqdomain.c

/**
 * irq_create_direct_mapping() - Allocate an irq for direct mapping
 * @domain: domain to allocate the irq for or NULL for default domain
 *
 * This routine is used for irq controllers which can choose the hardware
 * interrupt numbers they generate. In such a case it's simplest to use
 * the linux irq as the hardware interrupt number. It still uses the linear
 * or radix tree to store the mapping, but the irq controller can optimize
 * the revmap path by using the hwirq directly.
 */
unsigned int irq_create_direct_mapping(struct irq_domain *domain)
{
        struct device_node *of_node;
        unsigned int virq;

        if (domain == NULL)
                domain = irq_default_domain;

        of_node = irq_domain_get_of_node(domain);
        virq = irq_alloc_desc_from(1, of_node_to_nid(of_node));
        if (!virq) {
                pr_debug("create_direct virq allocation failed\n");
                return 0;
        }
        if (virq >= domain->revmap_direct_max_irq) {
                pr_err("ERROR: no free irqs available below %i maximum\n",
                        domain->revmap_direct_max_irq);
                irq_free_desc(virq);
                return 0;
        }
        pr_debug("create_direct obtained virq %d\n", virq);

        if (irq_domain_associate(domain, virq, virq)) {
                irq_free_desc(virq);
                return 0;
        }

        return virq;
}
EXPORT_SYMBOL_GPL(irq_create_direct_mapping);

irq 디스크립터를 하나 할당받은 후 hwirq 번호와 동일하게 1:1 직접 매핑 방법으로 매핑한다.

  • 코드 라인 6~7에서 domain이 주어지지 않은 경우 default domain을 선택한다.
  • 코드 라인 9~14에서 1개의 irq 디스크립터를 할당 받아온다.
  • 코드 라인 15~20에서 할당 받은 irq가 no 매핑 방법으로 사용할 수 있는 범위를 초과하는 경우 에러 메시지를 출력하고 할당받은 irq 디스크립터를 다시 할당 해제한 후 0을 반환한다.
  • 코드 라인 21에서 매핑한 디버그 정보를 로그로 출력한다.
  • 코드 라인 23~26에서 할당받은 irq 번호로 hwirq 번호를 매핑한다.
  • 코드 라인 28에서 성공한 경우 할당받은 virq 번호를 반환한다.

 

리버스 매핑 검색 (hwirq -> irq)

irq_find_mapping()

kernel/irq/irqdomain.c

/**
 * irq_find_mapping() - Find a linux irq from an hw irq number.
 * @domain: domain owning this hardware interrupt
 * @hwirq: hardware irq number in that domain space
 */
unsigned int irq_find_mapping(struct irq_domain *domain,
                              irq_hw_number_t hwirq)
{
        struct irq_data *data;

        /* Look for default domain if nececssary */
        if (domain == NULL)
                domain = irq_default_domain;
        if (domain == NULL)
                return 0;

        if (hwirq < domain->revmap_direct_max_irq) {
                data = irq_domain_get_irq_data(domain, hwirq);
                if (data && data->hwirq == hwirq)
                        return hwirq;
        }

        /* Check if the hwirq is in the linear revmap. */
        if (hwirq < domain->revmap_size)
                return domain->linear_revmap[hwirq];

        rcu_read_lock();
        data = radix_tree_lookup(&domain->revmap_tree, hwirq);
        rcu_read_unlock();
        return data ? data->irq : 0;
}
EXPORT_SYMBOL_GPL(irq_find_mapping);

irq domain 내에서 hwirq에 매핑된 irq 번호를 검색한다. 매핑되지 않은 경우 0을 반환한다.

  • 코드 라인 7~8에서 domain이 지정되지 않은 경우 default domain을 사용한다.
  • 코드 라인 9~10에서 여전히 domain이 null인 경우 0을 반환한다.
  • 코드 라인 12~16에서 no 매핑 구간에서 irq(=hwirq) 값을 알아온다.
    • hwirq가 리버스 매핑이 필요 없는 구간인 경우 hwirq 값으로 irq_data를 구해온다. 만일 data->hwirq 값과 동일한 경우에 그 대로 hwirq 값을 반환한다.
  • 코드 라인 19~20에서 리니어 매핑 구간에서 hwirq에 해당하는 irq 값을 알아온다.
    • hwirq가 리버스 매핑 범위 이내인 경우 리니어 리버스 매핑된 값을 반환한다.
  • 코드 라인 23~25에서 tree 매핑 구간에서 hwirq로 검색하여 irq 값을 알아온다.
    • radix tree에서 hwirq로 검색하여 irq_data를 알아온 다음 data->irq를 반환한다.

 

다음 그림은 irq_find_mapping() 함수가 hwirq에 매핑된 irq 번호를 찾는 과정 3 가지를 보여준다.

 


도메인용 irq 디스크립터 할당과 해제

도메인용 irq 디스크립터 할당

irq_domain_alloc_descs()

kernel/irq/irqdomain.c

int irq_domain_alloc_descs(int virq, unsigned int cnt, irq_hw_number_t hwirq,
                           int node, const struct irq_affinity_desc *affinity)
{
        unsigned int hint;

        if (virq >= 0) {
                virq = __irq_alloc_descs(virq, virq, cnt, node, THIS_MODULE,
                                         affinity);
        } else {
                hint = hwirq % nr_irqs;
                if (hint == 0)
                        hint++;
                virq = __irq_alloc_descs(-1, hint, cnt, node, THIS_MODULE,
                                         affinity);
                if (virq <= 0 && hint > 1) {
                        virq = __irq_alloc_descs(-1, 1, cnt, node, THIS_MODULE,
                                                 affinity);
                }
        }

        return virq;
}

irq 디스크립터를 @cnt 수만큼 @node에 할당한다. @affinity로 특정 cpu들을 대상으로 지정할 수 있다. @virq를 지정할 수도 있고, 지정하지 않은 경우(-1) 다음과 같은 기준으로 생성한다.

  • hwirq 번호를 irq 번호로 할당 시도한다. 단 hwirq 번호가 0인 경우 hwirq + 1을 irq 번호로 사용한다.
  • 할당이 실패한 경우 hwirq 번호가 2 이상이면 irq 번호를 1부터 다시 한 번 시도한다.

 

  • 코드 라인 6~8에서 @virq 번호를 지정한 경우 그 번호부터 @cnt 수 만큼 irq 디스크립터를 @node에 할당하고 @affinity를 지정한다. 그리고 현재 모듈을 irq 디스크립터의 owner로 설정한다.
  • 코드 라인 9~14에서 @virq 번호를 지정하지 않은 경우 hwirq 번호(0인 경우 1)부터 @cnt 수 만큼 irq 디스크립터를 @node에 할당하고 @affinity를 지정한다. 그리고 현재 모듈을 irq 디스크립터의 owner로 설정한다.
  • 코드 라인 15~18에서 만일 할당이 실패한 경우 hwirq 번호가 2 이상이면 irq 번호를 1부터 다시 한 번 시도한다.
  • 코드 라인 21에서 할당한 irq 디스크립터에 대한 virq 번호를 반환한다.

 


IRQ 도메인 검색

디바이스 노드에 해당하는 도메인 검색

irq_find_host()

include/linux/irqdomain.h

static inline struct irq_domain *irq_find_host(struct device_node *node)
{
        struct irq_domain *d;

        d = irq_find_matching_host(node, DOMAIN_BUS_WIRED);
        if (!d)
                d = irq_find_matching_host(node, DOMAIN_BUS_ANY);

        return d;
}

디바이스 트리의 @node 정보를 사용하여 일치하는 irq domain을 찾아온다.

  • DOMAIN_BUS_WIRED 토큰을 먼저 사용하고, 찾을 수 없는 경우 DOMAIN_BUS_ANY를 사용하여 버스 제한 없이 검색한다.

 

irq_find_matching_host()

include/linux/irqdomain.h

static inline struct irq_domain *irq_find_matching_host(struct device_node *node,
                                                        enum irq_domain_bus_token bus_token)
{
        return irq_find_matching_fwnode(of_node_to_fwnode(node), bus_token);
}

디바이스 트리의 @node와 @bus_token 정보를 사용하여 일치하는 irq domain을 찾아온다.

 

irq_find_matching_fwnode()

include/linux/irqdomain.h

static inline
struct irq_domain *irq_find_matching_fwnode(struct fwnode_handle *fwnode,
                                            enum irq_domain_bus_token bus_token)
{
        struct irq_fwspec fwspec = {
                .fwnode = fwnode,
        };

        return irq_find_matching_fwspec(&fwspec, bus_token);
}

인자 @fwnode와 @bus_token 정보를 사용하여 일치하는 irq domain을 찾아온다.

 

irq_find_matching_fwspec()

kernel/irq/irqdomain.c

/**
 * irq_find_matching_fwspec() - Locates a domain for a given fwspec
 * @fwspec: FW specifier for an interrupt
 * @bus_token: domain-specific data
 */
struct irq_domain *irq_find_matching_fwspec(struct irq_fwspec *fwspec,
                                            enum irq_domain_bus_token bus_token)
{
        struct irq_domain *h, *found = NULL;
        struct fwnode_handle *fwnode = fwspec->fwnode;
        int rc;

        /* We might want to match the legacy controller last since
         * it might potentially be set to match all interrupts in
         * the absence of a device node. This isn't a problem so far
         * yet though...
         *
         * bus_token == DOMAIN_BUS_ANY matches any domain, any other
         * values must generate an exact match for the domain to be
         * selected.
         */
        mutex_lock(&irq_domain_mutex);
        list_for_each_entry(h, &irq_domain_list, link) {
                if (h->ops->select && fwspec->param_count)
                        rc = h->ops->select(h, fwspec, bus_token);
                else if (h->ops->match)
                        rc = h->ops->match(h, to_of_node(fwnode), bus_token);
                else
                        rc = ((fwnode != NULL) && (h->fwnode == fwnode) &&
                              ((bus_token == DOMAIN_BUS_ANY) ||
                               (h->bus_token == bus_token)));

                if (rc) {
                        found = h;
                        break;
                }
        }
        mutex_unlock(&irq_domain_mutex);
        return found;
}
EXPORT_SYMBOL_GPL(irq_find_matching_fwspec);

인자 @fwspce 정보와 @bus_token 정보를 사용하여 일치하는 irq domain을 찾아온다.

  • irq_domain_list에 등록한 모든 엔트리에 대해 루프를 돌며 다음 3가지 중 하나로 도메인을 찾는다.
    • 첫 번째, (*select) 후크에 등록된 함수
    • 두 번째, (*match) 후크에 등록된 함수
    • 세 번째, fwnode가 동일하고, @bus_token이 일치하는 경우

 


기타 함수

주요 APIs

다음은 본문에서 설명한 API들이다.

  • irq_domain_add_linear()
  • irq_domain_add_tree()
  • irq_domain_add_legacy()
  • irq_domain_add_legacy_isa()
  • irq_domain_add_simple()
  • __irq_domain_add()
  • irq_domain_remove()
  • irq_domain_create_hierarchy()
  • irq_find_mapping()
  • irq_find_matching_fwspec()
  • irq_domain_associate()
  • irq_domain_associate_many()
  • irq_domain_disassociate()
  • irq_create_mapping()
  • irq_create_of_mapping()
  • irq_create_fwspec_mapping()
  • irq_create_direct_mapping()
  • irq_create_identity_mapping()
  • irq_create_strict_mappings()
  • irq_dispose_mapping()
  • irq_domain_free_fwnode()
  • irq_domain_set_hwirq_and_chip()
  • irq_domain_alloc_descs()
  • irq_find_matching_fwspec()
  • __irq_domain_alloc_fwnode()

 

기타 APIs

  • irq_set_default_host()
  • irq_get_default_host()
  • irq_domain_insert_irq()
  • irq_domain_remove_irq()
  • irq_domain_insert_irq_data()
  • irq_domain_free_irq_data()
  • irq_domain_alloc_irq_data()
  • irq_linear_revmap()
  • irq_domain_get_irq_data()
  • irq_domain_set_hwirq_and_chip()
  • irq_domain_set_info()
  • irq_domain_reset_irq_data()
  • irq_domain_free_irqs_common()
  • irq_domain_free_irqs_top()
  • irq_domain_is_auto_recursive()
  • irq_domain_free_irqs_recursive()
  • irq_domain_alloc_irqs_recursive()
  • __irq_domain_alloc_irqs()
  • irq_domain_free_irqs()
  • irq_domain_alloc_irqs_parent()
  • irq_domain_free_irqs_parent()
  • irq_domain_activate_irq()
  • irq_domain_deactivate_irq()
  • irq_domain_check_hierarchy()
  • irq_domain_get_irq_data()
  • irq_domain_check_msi_remap()
  • irq_domain_update_bus_token()
  • irq_domain_push_irq()
  • irq_domain_pop_irq()
  • irq_domain_hierarchical_is_msi_remap()
  • irq_domain_xlate_onecell()
  • irq_domain_xlate_twocell()
  • irq_domain_xlate_onetwocell()
  • irq_domain_translate_twocell()

 

인터럽트 목록 확인

다음은 rock960 보드에서 QEMU/KVM을 사용하여 Guest OS를 동작시켜 확인한 인터럽트 목록들이다.

$ cat /proc/interrupts
           CPU0       CPU1
 12:       2653       2704     GICv3  27 Level     arch_timer
 47:       1495          0     GICv3  78 Edge      virtio0
 48:         32          0     GICv3  79 Edge      virtio1
 50:          0          0     GICv3  34 Level     rtc-pl031
 51:        181          0     GICv3  33 Level     uart-pl011
 52:          0          0  GICv3-23   0 Level     arm-pmu
 53:          0          0  GICv3-23   1 Level     arm-pmu
 54:          0          0  9030000.pl061   3 Edge      GPIO Key Poweroff
IPI0:       987       1260       Rescheduling interrupts
IPI1:         5        611       Function call interrupts
IPI2:         0          0       CPU stop interrupts
IPI3:         0          0       CPU stop (for crash dump) interrupts
IPI4:         0          0       Timer broadcast interrupts
IPI5:         0          0       IRQ work interrupts
IPI6:         0          0       CPU wake-up interrupts
Err:          0

 

irq 별 sysfs 속성 확인

arch_timer를 담당하는 인터럽트 번호를 찾고, “cd /sys/kernel/irq/<irq>”를 타이핑하여 해당 인터럽트 디렉토리로 진입하여 다음 속성들을 확인한다.

$ cd /sys/kernel/irq/12
$ ls
actions  chip_name  hwirq  name  per_cpu_count  type  wakeup
$ cat actions
arch_timer
$ cat chip_name
GICv3
$ cat hwirq
27
$ cat per_cpu_count
2390,2251
$ cat type
level
$ cat wakeup
disabled

 

FS 디버깅이 가능한 커널에서 irq domain 구성 참고

$ cd /sys/kernel/debug/irq

$ ls
domains irqs

$ ls domains/
default  gic400@40041000  gpio@7e200000  unknown-1

$ ls irqs/
1   11  13  15  17  19  20  22  24  26  28  3   31  33  35  37  39  5  7  9
10  12  14  16  18  2   21  23  25  27  29  30  32  34  36  38  4   6  8

$ cat /irqs/3
handler:  handle_percpu_devid_irq
device:   (null)
status:   0x00031708
            _IRQ_NOPROBE
            _IRQ_NOTHREAD
            _IRQ_NOAUTOEN
            _IRQ_PER_CPU_DEVID
istate:   0x00000000
ddepth:   1
wdepth:   0
dstate:   0x02032a08
            IRQ_TYPE_LEVEL_LOW
            IRQD_LEVEL
            IRQD_ACTIVATED
            IRQD_IRQ_DISABLED
            IRQD_IRQ_MASKED
            IRQD_PER_CPU
node:     0
affinity: 0-3
effectiv:
domain:  gic400@40041000
 hwirq:   0x1e
 chip:    GICv2
  flags:   0x15
             IRQCHIP_SET_TYPE_MASKED
             IRQCHIP_MASK_ON_SUSPEND
             IRQCHIP_SKIP_SET_WAKE

 

/sys/kernel/debug# cat irq_domain_mapping 
 name              mapped  linear-max  direct-max  devtree-node
 IR-IO-APIC            24          24           0  
 DMAR-MSI               2           0           0  
 IR-PCI-MSI             6           0           0  
 (null)             65563       65536           0  
 IR-PCI-MSI             1           0           0  
 (null)             65536       65536           0  
 (null)                 0           0           0  
 (null)                 0           0           0  
*(null)                31           0           0  
irq    hwirq    chip name        chip data           active  type            domain
    1  0x00001  IR-IO-APIC       0xffff8802158a6f80     *    LINEAR          IR-IO-APIC
    3  0x00003  IR-IO-APIC       0xffff880214972180          LINEAR          IR-IO-APIC
    4  0x00004  IR-IO-APIC       0xffff880214972280          LINEAR          IR-IO-APIC
    5  0x00005  IR-IO-APIC       0xffff880214972380          LINEAR          IR-IO-APIC
    6  0x00006  IR-IO-APIC       0xffff880214972480          LINEAR          IR-IO-APIC
    7  0x00007  IR-IO-APIC       0xffff880214972580          LINEAR          IR-IO-APIC
    8  0x00008  IR-IO-APIC       0xffff880214972680     *    LINEAR          IR-IO-APIC
    9  0x00009  IR-IO-APIC       0xffff880214972780     *    LINEAR          IR-IO-APIC
   10  0x0000a  IR-IO-APIC       0xffff880214972880          LINEAR          IR-IO-APIC
   11  0x0000b  IR-IO-APIC       0xffff880214972980          LINEAR          IR-IO-APIC
   12  0x0000c  IR-IO-APIC       0xffff880214972a80     *    LINEAR          IR-IO-APIC
   13  0x0000d  IR-IO-APIC       0xffff880214972b80          LINEAR          IR-IO-APIC
   14  0x0000e  IR-IO-APIC       0xffff880214972c80          LINEAR          IR-IO-APIC
   15  0x0000f  IR-IO-APIC       0xffff880214972d80          LINEAR          IR-IO-APIC
   16  0x00010  IR-IO-APIC       0xffff8800d3e4d940     *    LINEAR          IR-IO-APIC
   17  0x00011  IR-IO-APIC       0xffff8800d3e4da40          LINEAR          IR-IO-APIC
   18  0x00012  IR-IO-APIC       0xffff8800d3e4db40          LINEAR          IR-IO-APIC
   19  0x00013  IR-IO-APIC       0xffff8802147d3bc0          LINEAR          IR-IO-APIC
   20  0x00014  IR-IO-APIC       0xffff8800350411c0          LINEAR          IR-IO-APIC
   22  0x00016  IR-IO-APIC       0xffff88020f9e8e40          LINEAR          IR-IO-APIC
   23  0x00017  IR-IO-APIC       0xffff880035670000     *    LINEAR          IR-IO-APIC
   24  0x00000  DMAR-MSI                     (null)     *     RADIX          DMAR-MSI
   25  0x00001  DMAR-MSI                     (null)     *     RADIX          DMAR-MSI
   26  0x50000  IR-PCI-MSI                   (null)     *     RADIX          IR-PCI-MSI
   27  0x7d000  IR-PCI-MSI                   (null)     *     RADIX          IR-PCI-MSI
   28  0x58000  IR-PCI-MSI                   (null)     *     RADIX          IR-PCI-MSI
   29  0x08000  IR-PCI-MSI                   (null)     *     RADIX          IR-PCI-MSI
   30  0x6c000  IR-PCI-MSI                   (null)     *     RADIX          IR-PCI-MSI
   31  0x64000  IR-PCI-MSI                   (null)     *     RADIX          IR-PCI-MSI
   32  0x180000 IR-PCI-MSI                   (null)     *     RADIX          IR-PCI-MSI

 


구조체

irq_domain 구조체

include/linux/irqdomain.h

/**
 * struct irq_domain - Hardware interrupt number translation object
 * @link: Element in global irq_domain list.
 * @name: Name of interrupt domain
 * @ops: pointer to irq_domain methods
 * @host_data: private data pointer for use by owner.  Not touched by irq_domain
 *             core code.
 * @flags: host per irq_domain flags
 * @mapcount: The number of mapped interrupts
 *
 * Optional elements
 * @fwnode: Pointer to firmware node associated with the irq_domain. Pretty easy
 *          to swap it for the of_node via the irq_domain_get_of_node accessor
 * @gc: Pointer to a list of generic chips. There is a helper function for
 *      setting up one or more generic chips for interrupt controllers
 *      drivers using the generic chip library which uses this pointer.
 * @parent: Pointer to parent irq_domain to support hierarchy irq_domains
 * @debugfs_file: dentry for the domain debugfs file
 *
 * Revmap data, used internally by irq_domain
 * @revmap_direct_max_irq: The largest hwirq that can be set for controllers that
 *                         support direct mapping
 * @revmap_size: Size of the linear map table @linear_revmap[]
 * @revmap_tree: Radix map tree for hwirqs that don't fit in the linear map
 * @linear_revmap: Linear table of hwirq->virq reverse mappings
 */
struct irq_domain {
        struct list_head link;
        const char *name;
        const struct irq_domain_ops *ops;
        void *host_data;
        unsigned int flags;
        unsigned int mapcount;

        /* Optional data */
        struct fwnode_handle *fwnode;
        enum irq_domain_bus_token bus_token;
        struct irq_domain_chip_generic *gc;
#ifdef  CONFIG_IRQ_DOMAIN_HIERARCHY
        struct irq_domain *parent;
#endif
#ifdef CONFIG_GENERIC_IRQ_DEBUGFS
        struct dentry           *debugfs_file;
#endif

        /* reverse map data. The linear map gets appended to the irq_domain */
        irq_hw_number_t hwirq_max;
        unsigned int revmap_direct_max_irq;
        unsigned int revmap_size;
        struct radix_tree_root revmap_tree;
        struct mutex revmap_tree_mutex;
        unsigned int linear_revmap[];
};

리눅스 인터럽트와 하드웨어 인터럽트 번호를 매핑 및 변환하기 위한 테이블 관리와 함수를 제공한다.

  •  link
    • 전역 irq_domain_list에 연결될 때 사용하다.
  • *name
    • irq domain 명
  • *ops
    • irq domain operations 구조체를 가리킨다.
  • *host_data
    • private data 포인터 주소 (irq domain core 코드에서 사용하지 않는다)
  • flags
    • irq domain의 플래그
      • IRQ_DOMAIN_FLAG_HIERARCHY
        • tree 구조 irq domain
      • IRQ_DOMAIN_FLAG_AUTO_RECURSIVE
        • tree 구조에서 recursive 할당/할당해제를 사용하는 경우
      • IRQ_DOMAIN_FLAG_NONCORE
        • generic 코어 코드를 사용하지 않고 직접 irq domain에 대해 specific한 처리를 한 경우 사용
  • fwnode
    • 연결된 펌에어 노드 핸들 (디바이스 트리, ACPI, …)
  • bus_token
    • 도메인이 사용되는 목적
      • DOMAIN_BUS_ANY (0)
      • DOMAIN_BUS_WIRED (1)
      • DOMAIN_BUS_GENERIC_MSI (2)
      • DOMAIN_BUS_PCI_MSI (3)
      • DOMAIN_BUS_PLATFORM_MSI (4)
      • DOMAIN_BUS_NEXUS (5)
      • DOMAIN_BUS_IPI (6)
      • DOMAIN_BUS_FSL_MC_MSI (7)
      • DOMAIN_BUS_TI_SCI_INTA_MSI (8)
  • *gc
    • 연결된 generic chip 리스트 (인터럽트 컨트롤러 리스트)
  • *parent
    • 상위 irq domain
    • irq domain 하이라키를 지원하는 경우 사용
  • hwirq_max
    • 지원가능한 최대 hwirq 번호
  • revmap_direct_max_irq
    • 직접 매핑을 지원하는 컨트롤러들에서 설정되는 최대 hw irq 번호
  • revmap_size
    • 리니어 맵 테이블 사이즈
  • revmap_tree
    • hwirq를 위한 radix tree 맵
  • linear_revmap[]
    • hwirq -> virq에 리버스 매핑에 대한 리니어 테이블

 

irq_domain_ops 구조체

include/linux/irqdomain.h

/**
 * struct irq_domain_ops - Methods for irq_domain objects
 * @match: Match an interrupt controller device node to a host, returns
 *         1 on a match
 * @map: Create or update a mapping between a virtual irq number and a hw
 *       irq number. This is called only once for a given mapping.
 * @unmap: Dispose of such a mapping
 * @xlate: Given a device tree node and interrupt specifier, decode
 *         the hardware irq number and linux irq type value.
 *
 * Functions below are provided by the driver and called whenever a new mapping
 * is created or an old mapping is disposed. The driver can then proceed to
 * whatever internal data structures management is required. It also needs
 * to setup the irq_desc when returning from map().
 */
struct irq_domain_ops {
        int (*match)(struct irq_domain *d, struct device_node *node,
                     enum irq_domain_bus_token bus_token);
        int (*select)(struct irq_domain *d, struct irq_fwspec *fwspec,
                      enum irq_domain_bus_token bus_token);
        int (*map)(struct irq_domain *d, unsigned int virq, irq_hw_number_t hw);
        void (*unmap)(struct irq_domain *d, unsigned int virq);
        int (*xlate)(struct irq_domain *d, struct device_node *node,
                     const u32 *intspec, unsigned int intsize,
                     unsigned long *out_hwirq, unsigned int *out_type);
#ifdef  CONFIG_IRQ_DOMAIN_HIERARCHY
        /* extended V2 interfaces to support hierarchy irq_domains */
        int (*alloc)(struct irq_domain *d, unsigned int virq,
                     unsigned int nr_irqs, void *arg);
        void (*free)(struct irq_domain *d, unsigned int virq,
                     unsigned int nr_irqs);
        int (*activate)(struct irq_domain *d, struct irq_data *irqd, bool reserve);
        void (*deactivate)(struct irq_domain *d, struct irq_data *irq_data);
        int (*translate)(struct irq_domain *d, struct irq_fwspec *fwspec,
                         unsigned long *out_hwirq, unsigned int *out_type);
#endif
#ifdef CONFIG_GENERIC_IRQ_DEBUGFS
        void (*debug_show)(struct seq_file *m, struct irq_domain *d,
                           struct irq_data *irqd, int ind);
#endif
};
  • (*match)
    • 호스와 인터럽트 컨트롤러 디바이스 노드와 매치 여부를 수행하는 함수 포인터. 매치되면 1을 반환한다
  • (*select)
    • 도메인 선택을 위한 함수 포인터
  • (*map)
    • 가상 irq와 하드웨어 irq 번호끼리의 매핑을 만들거나 업데이트 하는 함수 포인터.
  • (*unmap)
    • 매핑을 해제하는 함수 포인터.
  • (*xlate)
    • 하드웨어 irq와 리눅스 irq와의 변환을 수행하는 함수 포인터.
  • (*alloc)
    • irq domain의 tree 구조 지원시 irq 할당 함수 포인터
  • (*free)
    • irq domain의 tree 구조 지원시 irq 할당 해제 함수 포인터
  • (*activate)
    • irq domain의 tree 구조 지원시 irq activate 함수 포인터
  • (*deactivate)
    • irq domain의 tree 구조 지원시 irq deactivate 함수 포인터
  • (*translate)
    • CONFIG_IRQ_DOMAIN_HIERARCHY 구성된 도메인에서 (*xlate)를 대체하여 사용하는 함수 포인터

 

참고

 

Interrupts -1- (Interrupt Controller)

<kernel v5.4>

아키텍처별 인터럽트 컨트롤러 H/W 구성

  • 아키텍처마다 인터럽트 컨트롤러 구성이 다른데 간략히 아래 그림과 같이 다른 처리 방법을 갖는 것을 이해하자
    • x86 with PIC
      • 초기 CPU를 하나만 사용하는 X86 시스템에서는 8259 PIC(Programmable Interrupt Controller)를 하나 이상 사용하여 구성하였다.
    • x86 with APIC
      • x86에서도 SMP 구성을 하면서 APIC(Advanced Programmble Interrupt Controller)를 두 개의 칩에 나누어 하나는 cpu가 있는 코어 프로세서칩에 사용하고 I/O를 담당하는 south 칩셋에 APIC를 구성하였다.
    • ARM SoC
      • ARM은 무척 구성이 다양하다. SoC를 제작하는 회사마다 소유한 인터럽트 컨트롤러 로직을 SoC의 IP 블럭으로 구성하여 사용하는데 점차적으로 ARM사가 디자인한 GIC(Generic Interrupt Controller)를 사용하게 되는 경향이 있다.

 

Single & Hierarchical 구성

다음 그림과 같이 2 개 이상의 인터럽트 컨트롤러들을 연결하여 구성할 수도 있다.

 

ARM에 사용되는 인터럽트 컨트롤러들

arm64 시스템에서 인터럽트 컨트롤러로 GIC v1 ~ GIC v4가 주로 사용되고 있다. 그리고 arm32 시스템에선 각사에서 디자인한 다양한 인터럽트 컨트롤러들이 채택되어 사용되고 있음을 알 수 있다.

  • ARM社 design
    • gic
      • arm,pl390
      • gic-400
      • arm11mp-gic
      • arm1176jzf-devchip-gic
      • cortex-a15-gic
      • cortex-a9-gic
      • cortex-a7-gic
      • qcom,msm-8660-qgic
      • qcom,msm-qgic2
    • gic-v2m
      • arm,gic-v2m-frame
    • gic-v3
      • arm,gic-v3
      • gic-v3-its
        arm,gic-v3-its
    • nvic
      • arm,armv7m-nvic
    • vic
      • arm,pl190-vic
      • arm,pl192-vic
      • arm,versatile-vic
  • Broadcom社 design
    • bcm2835-ic
      • rpi는 ARM의 GIC를 사용하지 않고 broadcom 인터럽트 컨트롤러를 사용한다.
        • 커널 소스 참고: https://github.com/raspberrypi/linux
        • 2가지 구현
          • architecture specific 인터럽트 핸들러로 구현 (머신 디스크립터 정의)
            • arch/arm/mach-bcm2708/bcm2708.c
          • DTB 기반 irq-domain 인터럽트 핸들러로 구현
            • drivers/irqchip/irq-bcm2835.c
    • bcm2836-ic
      • rpi2 역시 broadcom 사의 인터럽트 컨트롤러를 사용하는데 4개의 armv7 코어를 사용하면서 2835에 비해 더 복잡해졌다.
        • 커널 소스 참고: https://github.com/raspberrypi/linux
        • 2가지 구현 (커널 v4.4 이상)
          • architecture specific 인터럽트 핸들러로 구현 (머신 디스크립터 정의)
            • arch/arm/mach-bcm2709/bcm2709.c
          • DTB 기반 per-cpu irq-domain 인터럽트 핸들러로 구현
            • drivers/irqchip/irq-bcm2836.c
  • 그 외 제조사 custom 디자인 IP 블럭
    • exynos-combiner
    • armada-mpic
    • atmel-aic
    • hip04
    • keystone
    • omap-intc
    • xtensa-pic
    • (수십 종류라 생략…)

 


GIC(Generic Interrupt Controller)

GIC 버전별 주요 특징

  • GIC v1
    • 8개까지 PE 지원
    • 1020개 까지 인터럽트 소스 처리 가능
    • Security extension 지원
    • ARM Cortex-A5, A9, R7 등에서 사용
  • GIC v2
    • v1 기능을 모두 포함
    • 가상화(virtualization) 기능 추가
    • ARM Cortex-A7, A15, A53, A57, … 등에서 사용
    • GIC v2m은 MSI(Message based Interrupt) 기능을 추가한 모델
  • GIC v3
    • v2 기능을 모두 포함
    • 클러스터당 8개 PE씩 최대 128개 PE 지원
    • 1020개 초과 인터럽트 소스 처리 가능
    • 시그널(v1 및 v2에서 사용하는 legacy) 방식 뿐만 아니라 MSI 방식 지원
      • MSI는 SPI와 LPI에서 사용할 수 있다.
    • non-secure와 secure 그룹에 따라 인터럽트 처리를 분리하는 진화된 security 기능 추가
    • SPI, PPI & SGI 이외에 LPI(Locality specific Peripheral Interrupt) 지원
    • affinity routing 기능 지원
    • ARM Cortex-A53, A57, A72, … 등에서 사용
  • GICv4
    • v3 기능을 모두 포함
    • 가상 인터럽트의 직접 주입(injection) 기능
    • ARM Cortex-A53, A57, A72, … 등에서 사용

 

GIC 블럭 다이어그램

다음 그림은 GIC v1(390), v2(400), v3(500)에 대한 간단한 내부 블록 다이어그램이다.

 


GIC v2

security extension 지원

GIC v1부터 security extension이 있는 GIC는 인터럽트마다 secure 및 non-secure 지정을 할 수 있다. (칩 구현에 따라 security extension 지원 여부가 결정된다)

  • secure 인터럽트
    • irq 및 fiq를 secure 펌웨어에 전달할 수 있다.
    • irq보다 더 높은 우선 순위인 fiq는 cpu에서 기존 irq를 처리하는 도중에도 preemption되어 fiq를 처리할 수 있다.
  • non-secure 인터럽트
    • irq만 non-secure 커널에 전달할 수 있다.

 

IRQ vs FIQ

ARM 아키텍처는 IRQ와 FIQ 두 가지 인터럽트 소스를 위해 물리적인 각각의 시그널 라인을 사용한다. 인터럽트가 발생되면 ARM 아키텍처는 비동기(Async) Exception에 해당하는 각각의 벡터로 점프된다. FIQ는 IRQ에 비해 더 빠른 처리가 필요할 때 사용되지만 매우 많은 제약을 가지고 있다. 이러한 특징을 조금 더 알아본다.

  • IRQ 보다 더 높은 우선 순위를 FIQ에 부여하기 때문에 cpu가 IRQ 처리 중에도 preemption되어 FIQ에 따른 ISR을 우선 처리할 수 있다.
  • 32비트 ARM 아키텍처
    • FIQ용 벡터 엔트리가 가장 마지막에 위치해서 jump 코드가 아닌 필요한 코드를 곧바로 사용할 수 있어, 수 사이클이라도 줄일 수 있다.
    • IRQ와 다르게 2 개 이상의 워드를 처리하는 긴 명령 사이클 중간에도 인터럽트된다.
    • IRQ 전환 시 저장(Store)하지 않고 즉시 사용 가능한 뱅크된 레지스터는 r13과 r14 두 개를 사용한다. 그러나 FIQ 전환시에는 이보다 더 많은 r8~r14까지 총 7개를 사용할 수 있고 이 중 link register로 돌아가야 할 주소를 담아 사용하는 r14를 제외하면 6개를 사용할 수 있다.
      • 보통 DRAM access를 최소화(캐시된 DRAM access)하고 6개의 레지스터만을 사용하여 FIQ에 대한 ISR을 수행하므로 대단히 빠른 처리를 할 수 있다.
        • 캐시되지 않은 DRAM access를 ISR 내부에서 자주하는 경우 캐시되지 않은 한 번의 DRAM access당 수십~수백 사이클이 소요되므로 FIQ를 사용하는 의미가 거의 없어진다.
      • Exception 레벨 전환에 따른 Store/Restore해야 할 레지스터의 수가 더 적어 빠르게 처리할 수 있다. (context복원)
        • 레벨 전환에 Store/Restore할 레지스터가 더 적어 빠르다 하더라도 보통 FIQ에서는 IRQ에서 ISR 구현하는 것처럼 레지스터들을 백업하고 복구하는 루틴을 사용하지 않는다. 이는 매우 현명하지 않은 사용예일 뿐이다.
  • 64비트 ARM 아키텍처
    • 32비트 ARM과 다르게 뱅크 레지스터를 사용하지 않으므로 사용할 레지스터들은 Store/Release 루틴을 사용하여야 한다.
      • SRAM 등의 처리빠른 전용 메모리 장치를 사용하지 않는 경우 리눅스 커널에선 더욱 사용할 필요가 없다
  • FIQ 루틴은 IRQ보다 수십 나노 세컨드 또는 수십 사이클을 더 빠르게 처리하는 장점을 활용하기 위해 보통 수 개 이하의 입력 소스만 FIQ로 처리하도록 어셈블리 언어를 직접 사용한다.
    • IRQ 같이 여러 인터럽트 소스를 FIQ로 처리하려면 irq domain 등 분기 처리루틴이 추가되면서 많은 소요 시간이 추가되므로 FIQ를 사용하는 장점이 없어진다.
  • 특별한 사용자 변경 없이는 ARM 리눅스 커널은 IRQ를 처리하고, 시큐어 펌웨어에서 FIQ를 처리한다.
    • 리눅스 커널에서는 여러 인터럽트 소스를 사용하므로 대부분 FIQ를 사용하지 않는다.
    • latency 및 ISR의 처리 시간 단축 문제로 IRQ에서 처리하기 힘든 특정 ISR에서만 FIQ를 사용하도록 해야 한다.
  • 빠른 access 성능을 갖춘 전용 SRAM 등이 있는 하드웨어 환경인 경우 FIQ를 사용하면 레지스터들의 백업과 복구를 DRAM이 아닌 이러한 SRAM 등을 사용하여 처리하면 위의 처리 성능을 대폭 줄일 수 있다.
  • 참고: FIQ Handlers in the ARM Linux Kernel | Bootlin

 

인터럽트 전송 타입

디바이스에서 발생한 인터럽트를 아래 두 가지 형태로 신호 또는 메시지로 GIC에 전달한다. GIC는 관련 cpu에 irq 또는 fiq 형태로 시그널을 전달한다.

  • Legacy Interrupt
    • 시그널 기반 전송 인터럽트는 디바이스가 인터럽트를 위한 별도의 인터럽트 시그널 라인을 통해 직접 GIC에 시그널(1과 0의 표현)로 전달한다.
  • MSI(Message based Interrupt)
    • 메시지 기반 전송 인터럽트는 디바이스가  인터럽트를 위한 별도의 회로를 사용하지 않고 데이터 통신을 수행하는 interconnect 버스(arm 및 arm64에서는 AXI 버스)를 통해 메시지 형태로 GIC에 전달한다.
    • 장점
      • Legacy 인터럽트에 비해 별도의 라인을 사용하지 않아 인터럽트에 사용하는 많은 라인들을 줄일 수 있다.
      • Legacy  인터럽트는 1~4개의 인터럽트를 사용하지만 MSI 방식에서는 디바이스마다 더 많은 인터럽트를 정의하여 사용할 수 있다.
    • 단점
      • interconnect에 직접 연결되는 디바이스만 가능한다. 대표적으로 PCIe 컨트롤러가 있다.
        • PCIe 버스에 연결된 PCIe 디바이스의 경우 PCIe 버스를 경유하고 AXI 버스를 통해 GIC에 인터럽트가 전달된다.
      • interconnect 버스를 통해야 하므로 추가적인 지연(latency)이 발생한다.
        • ITS를 사용하는 경우 DRAM 테이블을 사용하므로 더 큰 지연이 발생하지만, 높은 우선 순위 및 빈도 높은 인터럽트등은 캐시되어 사용되므로 지연을 최대한 줄일 수 있다.

 

다음 그림은 Signal 기반과 Message 기반의 인터럽트 전송 방법을 비교하여 보여준다.

 

다음 그림은 Signal 기반과 Message 기반이 실제 PCIe 디바이스에 구현된 사례를 보여준다.

  • 현재 PCIe 규격은 legacy 인터럽트와 MSI 둘 다 지원한다.

 

GIC 인터럽트 상태

SGI, PPI, SPI 들은 각각의 인터럽트에 대해 아래와 같이 4개의 상태(state)로 구분할 수 있다. 단 LPI는 inactive와 pending 상태로만 구분된다.

  • Inactive
    • 인터럽트가 발생하지 않은 상태
  • Pending
    • 하드웨어 또는 소프트웨어에서 인터럽트가 발생하였으나 타깃 프로세스에게 전달되지 않음
    • level sensitive 트리거 모드에서는 인터럽트가 발생하는 동안 pending 상태가 지속된다.
  • Active
    • 인터럽트가 발생하여 프로세스에게 전달되었고 프로세스가 ack하여 인터럽트를 처리 중이며 완료되지 않은 상태
  • Active & Pending
    • 인터럽트가 발생하여 프로세스에게 전달되었고, 동일한 인터럽트가 발생하여 보류중인 상태

 

GIC 인터럽트 타입

인터럽트 타입은 다음과 같다. (INTID(인터럽트 ID) 1020~1022번은 특수 목적으로 예약되었다. 예: 1023=no pending interrupt)

    • SGIs(Software Generated Interrupts)
      • 각 core에 전용으로 사용되며, 외부 인터럽트가 아니라 소프트웨어에서 발생시킬 수 있는 내부 IRQ 들로 0 ~ 15 까지의 id를 사용한다.
      • INTID0~7번은 non-secure, INTID8~15번은 secure로 사용하도록 arm사가 적극 권장한다.
    • PPIs(Private Peripherals Interrupts)
      • 각 core에 전용으로 사용될 수 있는 IRQ 들로 INTID16 ~ 31 까지 사용한다.
      • GIC에서 사용하는 클럭과 연동된다.
    • SPIs(Shared Peripherals Interrupts)
      • core에 공용으로 사용될 수 있는 IRQ 들로 INTID32 ~ 1019까지 사용한다.
      • GIC에서 사용하는 클럭과 연동된다.
    • LPI(Locality-specific Peripheral Interrupt)
      • GICv3 이상에서 새롭게 지원하는 타입의 인터럽트로 legacy 시그널 형태는 지원하지 않고 메시지 방식인 MSI 형태만 지원하며 INTID8192 이상을 사용한다.
      • non-secure group 1 인터럽트로만 사용되며 edge trigger 방식으로 동작한다.
      • 지정된 PE에 연동된 redistributtor로 전달되지만, 옵션 장치인 ITS(Interrupt Translation Service)를 사용하면, 특정 PE의 redistributor로 변환하여 라우팅 서비스를 사용할 수 있다.

 

ARM 권장 PPI의 INTIDs

다음은 ARM사에서 권장하는 PPI의 INTID들이다. 그럼에도 불구하고 일부 arm64 SoC 제작사에서는 아래와 다른 번호를 가진 시스템도 있다.

  • 30 : EL1 physical timer
  • 29 : EL3 physical timer
  • 28: Non-Secure EL2 virtual timer (ARMv8.1)
  • 27: EL1 Virtual timer
  • 26: Non-Secure EL2 physical timer
  • 25: Virtual CPU Interface Maintenence interrupt
  • 24: Cross Trigger Interface interrupt
  • 23: Performance Monitor Counter Overflow interrupt
  • 22: Debug Communcations Channel interrupt
  • 20: Secure EL2 Physical Timer (ARMv8.4)
  • 19: Secure EL2 Virtual Timer (ARMv8.4)

 

인터럽트 트리거

인터럽트 트리거 모드는 다음과 같이 두가지 타입이 있고, high 또는 low 신호 방향 중 하나를 가진다.

  • Level Sensitive
  • Edge Trigger

 

다음 그림은 high activate 시그널로 동작하는 두 가지 인터럽트 트리거 모드에 대한 인터럽트 상태 변화를 보여준다.

 

우선 순위 (Priority)

인터럽트별로 0~255까지 우선 순위를 줄 수 있다.

  • 0=가장 높은 우선 순위
  • 255=가장 낮은 우선 순위

 

우선 순위 Filter

  • 설정된 우선 순위 filter 값보다 높은 우선 순위의 인터럽트를 전달하고, 그 외는 block 한다.
    • 설정된 우선 순위 값보다 작은 숫자만 인터럽트를 전달한다.
    • 예) priority filter = 0xf0인 경우
      • 우선 순위 값이 0x00 ~ 0xef 범위인 인터럽트만 허용하고, 나머지는 허용하지 않는다.

 

Prioritization

Preemption Interrupt

  • Binary Point
    • 3개의 비트를 사용한 0~7의 값으로 각 하드웨어 인터럽트에 설정된 priority 값을 두 그룹으로 분리한다.
    • 분리한 두 개의 그룹
      • Group Priority
        • irq preemption: fast interrupt 처리가 가능하도록 현재 처리하고 있는 인터럽트가 있다하더라도 더 높은 우선 순위의 인터럽트 발생 시  먼저 처리하도록 한다.
      • Sub Priority
        • 현재 처리하고 있는 인터럽트의 우선 순위보다 더 높은 우선 순위의 인터럽트 발생 시 먼저 처리하지 않는다.
    • 리눅스 커널은 GIC v3 드라이버에서 Binary Point 값으로 0을 기록하여 리셋시켜 사용한다. (리셋 후 값은 칩 구현에 따라 다르다)

 

다음 그림은 인터럽트 그루핑을 보여준다.

 

Priority Leveling

GIC는 칩 구현에 따라 security extension을 사용하는 경우 최소 32~256 레벨을 사용할 수 있다. (GIC v3 이상에서  two security states에서는 32~256단계를 사용하고, single security states에서는 16~256단계를 사용한다.)

  • GICD_IPRIORITYRn 레지스터는 인터럽트 n번의 우선순위를 기록하는데 사용한다.
    • GICD_IPRIORITYRn에 설정된 우선 순위는 GIC가 사용하는 단계에 맞춰 mask되어 사용된다.
    • 예) 칩이 32단계로 구현된 경우 0xff를 기록하더라도 mask 값 0xf8과 and하여 뒤의 3 비트는 무시되어 0으로 기록된다.
  • GIC v3를 사용하는 경우 칩이 사용중인 레벨은 ICC_CTLR_EL1.pribits 값을 읽어 알아올 수 있다. (Read Only)
    • 수식 = 2^(N+1) 단계(레벨)
    • 3=16 단계
    • 4=32 단계
    • 5=64 단계
    • 6=128 단계
    • 7=256 단계
  • 리눅스 커널은 모든 irq에 대해 한 가지 우선 순위를 사용하여 preemption이 발생하지 않는다. 단 최근 추가된 Pesudo-NMI 기능을 지원하는 경우 nmi를 사용하는 인터럽트는 더 높은 우선 순위로 설정한다.

 

Secure/Non-Secure에서 priority 값 변환

GIC v1~v2에서 security extension을 사용하는 경우 group 1 인터럽트는 non-secure로 사용되고, group 0 인터럽트는 secure로 사용된다.(참고로 GIC v3부터는 group 1 인터럽트도 non-secure와 secure로 분리할 수 있다) 그리고 group 1 인터럽트가 group 0 인터럽트를 선점하지 않도록 ARM 제작사는 다음 내용을 강력히 권장하고 있다.

  • group 1 인터럽트는 0x80 ~ 0xff 범위를 사용한다.
  • group 0 인터럽트는 0x00 ~ 0x7f 범위를 사용한다.
  • group 0 인터럽트는 group 1의 모든 인터럽트들보다 항상 우선 순위를 더 높게 강제한다.
    • 이는 priority 비트들 중 최상위 bit7에 따라 group 0와 group 1이 나뉘는 것을 의미한다.
      • bit7=0 -> group 0
      • bit7=1 -> group 1

 

secure states에 따라 다음과 같은 규칙을 갖는다.

  • secure states
    • group 0에 해당하는 0x00~0x7f 우선 순위와 group 1에 해당하는 0x80~0xff 우선 순위 모두 설정할 수 있고 그 값을 그대로 읽을 수 있다.
  • non-secure states
    • group 1에 해당하는 우선 순위만 기록하고 읽을 수 있다. (group 0에 해당하는 우선 순위는 접근할 수 없다.)
    • non-secure states에서는 secure states에서 사용하는 우선 순위 값과 다르게 표현된다. secure states에서 사용하는 값을 좌측으로 1 시프트한 값을 사용한다.
    • 반대로 non-secure states에서 기록한 값은 secure states 또는 distributor 입장에서 우측으로 1 시프트하고 bit7을 1로 설정한 값을 사용한다.

 

다음 그림과 같이 non-secure에서 사용하는 priority 값과 secure states(distributor와 동일)에서 priority 값은 변환되는 관계를 보여준다.

  • non-secure로 동작하는 리눅스 커널에서 특정 인터럽트의 우선 순위 값을 0x02로 설정하는 경우, GIC의 distributor는 이를 0x81 우선 순위로 인식하여 사용하는 것을 알 수 있다.

 

Virtualization 지원

다음 그림은 하이퍼바이저가 수신한 인터럽트를 Guest OS에 가상 인터럽트로 전달하는 과정을 보여준다.

 

GIC v2 주요 레지스터들

  • GIC는 CPU Interface 레지스터들과 Distributor 레지스트들을 통해 제어한다.
  • CPU Interface 레지스터
    • core로 전달된 group 1 irq들 전체를 한꺼번에 통제한다.
    • core로 전달될 irq들에 대해 설정한 priority mask 값을 사용하여 통과시킨다.
      • priority 레벨링 (16 ~ 256 단계)
  • Distributor 레지스터
    • secure 상태에 따라 group 0/1의 방향을 선택하게 한다. (irq/fiq)
      • non-secure extension 사용시 group은 항상 fiq로 forward된다.
      • secure extension 사용시 group-0은 fiq, group-1은 irq로 forward 된다.
    • IRQ 별로 forward를 설정(Set-enable) 및 클리어(Set-Clear) 요청할 수 있다.
    • IRQ 별로 priority를 설정할 수 있다.
    • IRQ 별로 개별 cpu interface로의 전달여부를 비트마스크로 설정할 수 있다. (1=forward, 0=drop)
    • PPI & SPI에 해당하는 하드웨어 IRQ 별로 인터럽트 트리거 타입을 설정할 수 있다.
      • 0=level sensitive (전압의 레벨이 지속되는 동안)
      • 1=edge trigger (high나 low로 바뀌는 순간만)
        • SGI는 edge 트리거를 사용한다.

 

GIC v2의 AArch64 시스템용 레지스터들은 다음과 같은 그룹으로 나눌 수 있다. (AArch32는 생략)

  • 메모리 맵드 레지스터들
    • GICC, CPU Interface Registers
    • GICD, Distributor Registers
    • GICH, Virtual CPU Interface Control Registers
      • 생략
    • GICV, Virtual CPU Interface Registers
      • 생략

 

1) GICC, CPU Interface Registers

  • GICC_CTLR (CPU Interface Control Register)
    • secure mode 별로 레지스터가 bank 되어 사용된다.
    • Enable
      • group 1 인터럽트의 forward 여부 (0=disable, 1=enable)
    • EnableGrp1
      • group 1 인터럽트의 forward 여부 (0=disable, 1=enable)
    • FIQBypDisGrp1 & IRQBypDisGrp1
      • cpu 인터페이스 비활성화시 PE에 인터럽트 바이패스 Disable 여부 (0=bypass, 1=bypass disable)
    • EOImodeNS
      • EOI 모드 운영 방법 선택
        • 0=GICC_EOIR & GICC_AEOIR을 사용하여 priority drop 기능과 비활성화 기능 지원
        • 1=GICC_EOIR & GICC_AEOIR을 사용하여 priority drop 기능만 지원, 인터럽트 비활성화 기능은 별도로 GICC_DIR 사용해야 한다.
  • GICC_PMR (Interrupt Priority Mask Register)
    • core로 전달될 irq들에 대해 설정한 priority 마스크 미만만 통과시킨다.
        • 리눅스 커널의 GIC v1~v4 드라이버는 디폴트 값으로 0xf0을 사용한다.
    • 0 값을 기록하는 경우 모든 인터럽트가 전달되지 않는다.
  • GICC_BPR (Binary Point Register)
    • priority 값을 group/sub와 같이 두 그룹으로 나누어 그 중 group에 해당하는 priority를 가진 인터럽트에 대해 preemption interrupt로 분류한다.
      • 리눅스 커널의 경우 GIC v3 부터 이 필드에 0 값을 기록하여 리셋시킨다. 설정되는 값은 구현에 따라 다르다.
  • GICC_IAR  (Interrupt Acknowledge Register)
    • 인터럽트 수신 시 이 레지스터를 읽어 인터럽트 id를 읽어오는 것으로 인터럽트 처리 루틴이 ack 처리되었음을 gic에 알린다.
  • GICC_EOIR  (End of Interrupt Register)
    • ISR(Interrupt Service Routine)에서 인터럽트 처리 완료 시 해당 인터럽트 id를 기록하여 eoi 처리하였음을 gic에 알린다.
  • GICC_RPR (Running Priority Register)
    • 읽기 전용으로 현재 동작하고 있는 인터럽트의 priority 값을 알아온다. idle 상태인 경우는 0xff
    • non-secure에서 읽은 경우 0x80을 mask 하여사용한다.
  • GICC_HPPIR (Highest Priority Pending Interrupt Register)
    • 읽기 전용으로 현재 하드웨어 인터럽트 (PPI&SPI)들 중 pending되고 있는 가장 높은 priority irq 번호와 cpu를 읽어온다.
    • 소프트 인터럽트(SGI)의 경우 cpu 값만 읽어올 수 있다.
  • GICC_IIDR (CPU Interface Identification Register)
    • 읽기 전용으로 GIC 제품 ID, 아키텍처 버전, 리비전, 구현회사 등의 정보를 읽어올 수 있다.
  • GICC_ABPR (Aliased Binary Point Register)
  • GICC_APRn (Active Priorities Register)
  • GICC_AEOIR (Aliased End of Interrupt Register)
  • GICC_AIAR (Aliased Interrupt Acknowledge Register)
  • GICC_AHPPIR (Aliased Highest Priority Pending Interrupt Register)
  • GICC_DIR (Deactivate Interrupt Register)
  • GICC_NSAPRn (Non-Secure Active Priorities Register)

 

2) GICD, Distributor Registers

  • GICD_CTRL (Distributor Control Register)
    • Pending 인터럽트에 대해 CPU interface로 올려보낼지 여부를 통제한다.
    • secure extension을 사용할 때 non-secure 모드에서는 group1에 대해서만 통제할 수 있다.
      • 1=forward enable
    • security extension 사용 시 bank 된다.
  • GICD_TYPER (Interrupt Controller Type Register)
    • 읽기 전용으로 Security Extension을 사용 시 최대 지원 cpu 수와 인터럽트 수 등을 알아내기 위해 사용한다.
      • Lockable SPI
        • 최대 지원 lockable SPI 수
      • SecurityExtn (bit:10)
        • 1=security extension 사용
        • 0=security extension 사용하지 않음
      • CPU Number
        • 최대 지원 CPU 수
      • ITLinesNumber
        • 최대 지원 인터럽트 수
  • GICD_IIDR (Distributor Implementer Identification Register)
    • 읽기 전용으로 GIC implementor 정보를 알아온다.
  • GICD_IGROUPRn (Interrupt Group Registers)
    • secure extension을 사용하는 경우 인터럽트별로 secure group 0와 non-secure group 1을 지정한다.
      • 0=group 0, 1=group 1
    • secure extension을 사용하는 경우 리셋시 0으로(RAS) 읽히며, 모든 인터럽트가 재설정되기 전엔 모두 group 0 상태가된다.
      • SMP 시스템에서 secure extension을 지원하고, non-secure 프로세서들에 대해서는 뱅크된 GICD_IGROUPR0은 group 1 상태로 리셋한다.
    • IRQ #0~31을 위해 첫 레지스트가 cpu별로 bank 되어 사용된다.
  • GICD_ISENABLERn (Interrupt Set-Enable Registers)
    • IRQ 별로 통과(Set-Enable) 여부를 설정할 수 있다.
      • 1=set 요청
    • IRQ #0~31을 위해 첫 레지스트가 cpu별로 bank 되어 사용된다.
  • GICD_ICENABLERn (Interrupt Clear-Enable Registers)
    • IRQ 별로 통제(Clear-Enable) 여부를 설정할 수 있다.
      • 1=clear 요청
    • IRQ #0~31을 위해 첫 레지스트가 cpu별로 bank 되어 사용된다.
  • GICD_ISPENDRn (Interrupt Set PENDing Registers)
    • IRQ 별로 pending 상태를 설정할 수 있다.
      • 1=set 요청
    • IRQ #0~31을 위해 첫 레지스트가 cpu별로 bank 되어 사용된다.
  • GICD_ICPENDRn (Interrupt Clear PENDing Registers)
    • IRQ 별로 pending 상태 해제를 요청할 수 있다.
      • 1=clear 요청
    • IRQ #0~31을 위해 첫 레지스트가 cpu별로 bank 되어 사용된다.
  • GICD_IPRIORITYRn (Interrupt PRIORITY Registers)
    • IRQ 별로 priority를 설정할 수 있다.
      • 0~255 priority 설정
    • IRQ #0~31을 위해 첫 8개의 레지스트가 cpu별로 bank 되어 사용된다.
  • GICD_ITARGETRn (Interrupt processor TARGET Registers)
    • IRQ 별로 개별 cpu interface로의 전달여부를 비트로 마스크 설정할 수 있다.
    • bit0=cpu#0 제어, bit1=cpu#1 제어…
      • 0=disable forward, 1=enable forward
    • IRQ #0~31을 위해 첫 8개의 레지스트가 cpu별로 bank 되어 사용된다.
  • GICD_ICFGRn (Interrupt ConFiGuration Registers)
    • IRQ 별로 인터럽트 트리거 방향을 설정할 수 있다.
      • 0=상향 시 트리거, 1=하향 시 트리거
    • IRQ #160~31을 위해 두 번째 레지스트가 cpu별로 bank 되어 사용된다.
  • GICD_SGIR (Software Generated Interrupt Register)
    • TLF (Target List Filter)
      • 0=white list 제어 방식, CPU Target List에 설정된 cpu로만 forward
      • 1=black list 제어 방식, CPU Target List에 설정된 cpu만 drop
      • 2=위의 ACL 방식 제어를 사용하지 않는다.
      • 3=reserved
    • CPU Target List
      • 0~7개의 cpu bit
    • NSATT (Non-Secure
      • 0=SGI#에 대해 group-0으로 설정된 경우 CPU Target List로 forward
      • 1=SGI#에 대해 group-1로 설정된 경우 CPU Target List로 forward

 

다음 그림은 GICv2 주요 레지스터들에 대해 GICv1 명칭과 비교하여 보여준다.

 


GIC v3

Security States

GIC v2까지 적용되었던 Security Extension 용어를 사용하지 않고, GIC v3 부터는 다음과 같이 두 가지 security states를 가지고 운영한다.

  • Single Security States
    • GIC에서 Secure와 Non-Secure를 나누어 사용하지 않는다.
    • EL0~3 Exception 레벨에 Secure와 Non-Secure 구분하지 않고 인터럽트를 전달한다.
  • Two Security States
    • GIC에서 Secure와 Non-Secure로 나누어 사용된다.
    • EL0~2 Exception 레벨에 Secure와 Non-Secure로 나누어 인터럽트를 전달한다. EL3의 경우는 Secure 상태만 사용한다.
    • 특정 레지스터는 Secure와 Non-Secure에 따라 뱅크되어 운영된다. (같은 이름을 사용하지만 각각 운영된다)

 

인터럽트 라이프 사이클

다음 그림과 같이 각 인터럽트의 발생과 종료에 대한 라이프 사이클을 보여준다.

 

ACK(Acknowledge) 처리 방법

ack 처리는 다음 읽기 전용 레지스터를 읽는 것만으로 완료된다.

  • ICC_IAR0_EL1
  • ICC_IAR1_EL1
  • GICC_IAR
  • GICC_AIAR

 

EOI(End Of Interrupt) 처리 방법

eoi 처리는 다음 쓰기 전용 레지스터를 기록하는 것만으로 완료된다.

  • ICC_EOIR0_EL1
  • ICC_EOIR1_EL1
  • GICC_EOIR
  • GICC_AEOIR

 

deactivation 처리는 다음 쓰기 전용 레지스터를 기록하는 것만으로 완료된다.

  • ICC_DIR_EL1
  • GICC_DIR

 

GIC v3 이상부터 eoi 처리 방법이 다음과 같이 두 개로 나뉜다.

  • priority drop & deactivation 통합 처리
    • GICD_CTLR.EOImode=0 설정 사용
    • eoi 명령 사용 시 priority drop과 deactivation이 자동으로 처리된다.
    • GIC v1 & v2의 경우 eoi 처리 시 priority drop과 deactivation을 둘 다 처리하였다.
  • priority drop & deactivation 분리 처리
    • GICD_CTLR.EOImode=1 설정 사용
    • eoi 명령 사용 시 priority drop만 처리한다.
      • 이 때 running priority에는 idle priority(0xff)가 설정되어 다른 우선 순위를 가진 인터럽트가 preempt되는 것을 허용한다.
      • 단 deactivation 명령 처리 전까지 현재 완료되지 않은 인터럽트 번호는 진입을 허용하지 않는다.
    • 이 모드는 virtualization을 지원하기 위해 채용되었다.
      • 리눅스 커널이 EL2에서 부팅한 경우에만 Host OS 역할로 동작할 때 이렇게 분리된 모드를 사용한다.
      • 리눅스 커널은 v4.3-rc1부터 EOImode=1을 지원한다.

 

인터럽트 수신 Exception 레벨

arm64 시스템에서 커널과 secure firmware를 동작시켜 인터럽트를 수신하는 경우 커널에서는 non-secure group 1에 대해 irq를 수신받고, secure firmware에서는 secure group 0에 대해 irq 보다 더 높은 우선 순위인 fiq를 수신받아 처리하였다. 최근 곧 출시할 ARMv8.4 아키텍처와 GIC v3 등의 최신 아키텍처로 무장한 시스템을 사용하여 linaro 측에서는 secure 처리에 대해 하나의 secure firmware로만 관리하지 않고 secure application과 secure OS를 각 Exception 레벨에서 분리하여 운영할 계획을 가지고 있다. 추가로 Hypervisor도 Secure와 Non-Secure를 분리하여 처리할 계획이 있다.

 

다음 그림은 각 Exception 레벨에서 운영할 Application과 OS등을 보여준다.

  • 각 Exception 레벨에서 인터럽트를 각각 할당하여 처리하여야한다.
  • 상위 EL2나 EL3 Exception 레벨에서는 하위 Exception 레벨을 대신 emulation 하기도 한다. (해당 OS가 직접받아 처리하는 것이 가장 빠르다)
  • ARMv8.4 아키텍처부터 Secure EL2가 동작 가능하다.

 

인터럽트별 group 및 secure 상태 분류

각 Exception 레벨의 Secure 및 Non-Secure 에 인터럽트를 전달하기 위한 경로를 3개로 나누어 처리하는 것을 보여준다.

  • 기존 GIC v2 까지는 single security states 처럼 처리하였다.
    • 인터럽트별로 group을 지정한다.
  • GIC v3부터는 single security states도 지원하지만, two security states를 사용하는 경우 인터럽트별로 group을 지정하고 이어서 group modifier 레지스터를 적용하여 다음과 같이 3가지 상태로 변환하여 처리할 수 있다.
    • G1NS(non-secure group 1)
    • G1S(secure group 1)
    • G0(secure group 0) 또는 G0S

 

IRQ 및 FIQ 분리

GIC v3 이전에는 인터럽트별로 설정된 group 0은 secure 상태로 FIQ로 전달되고, group 1은 non-secure 상태로 IRQ로 전달되었다. 따라서 non-secure 상태로 동작하는 리눅스 커널은 IRQ를 수신하여 처리하고, Secure Firmware는 FIQ를 수신하여 처리하는 것으로 간단히 분리하였다. 그러나 GIC v3 부터는 group modifier 레지스터를 통해 group + secure 상태로 변환되어 조금 더 복잡하게 처리한다.

  • 설정에 의해 각 secure/non-secure Exceptin 레벨로 IRQ 및 FIQ를 보낼 수 있게 하였다.

 

다음 그림은 리눅스 커널이 secure 펌웨어 등과 같이 동작할 때 single 및 two security state에 대해 동작하는 일반적인 사례를 보여준다.

 

다음 그림은 휴대폰으로 전화가 온 경우 secure에서 받은 fiq 인터럽트를 리눅스 커널까지 라우팅하는 두 가지 사례를 보여준다.

  • 1)번 그림의 경우 (1) cpu가 L1 secure state에 있을 때 non-secure group 1으로 지정된 인터럽트가 발생하였다. 이 인터럽트는 non-secure용이기 대문에 Rich OS에 전달해야 하는데 이 인터럽트는 fiq로 변환되어 일단 trust OS 또는 Secure Monitor로 보내게 된다. 왜냐면 SCR_EL3.FIQ=1로 설정되어 있으므로 fiq 인터럽트는 EL3 Secure Monitor로 향하게 된다. Secure Monitor에서는 특수 용도의 인터럽트 번호인 1021번으로 진입하여 fiq 벡터로 수신되는데, 이는 “non-secure로 전환하여 인터럽트를 보내라는 의미“이다. (2) 따라서 non-secure에서 동작하는 Rich OS로 인터럽트를 보내기 위해 non-secure EL1으로 context switching을 하면 (3) 자동으로 non-secure 인터럽트가 non-secure EL1에서 발생하여 Rich OS의 irq 벡터에서 수신할 수 있게 된다.
  • 2)번 그림의 경우는 1)번 그림과 유사하지만 (1) secure EL1에서 동작하는 Trusted OS로 fiq가 전달된다. 왜냐면 SCR_EL3.FIQ가 0으로 설정되었기 때문이다. 그런후 (2) smc 명령을 사용하여 EL3로 context switching을 수행한다. 그 이후 흐름은 1)번 그림과 같다.

 

Pseudo-NMI 구현

arm 및 arm64 시스템에는 NMI 기능이 지원되지 않는다. 그러나 최근 arm64 시스템에서 인터럽트 컨트롤러로 GIC v3 이상을 사용하는 경우 ICC_PMR(Prioirty  Mask Register) 기능으로 irq preemption 기법을 적용하여, x86 시스템의 NMI와 유사한 동작을 수행하도록 구현하였다.

  • local_irq_disable() 루틴의 동작
    • 기존 방법은 “msr daifset, #2” 명령으로 PSTATE.I를 설정하는 것으로 local irq를 disable하였다.
    • 새로운 방법은 PMR을 사용하여 IRQOFF를 위해 0x60 미만의 우선 순위만을 허용하게 설정하여 디폴트 우선 순위 값 0xa0을 사용하는 irq를 차단하지만, NMI용 우선 순위 값 0x20을 사용하는 irq는 허용한다.
  • local_irq_enable() 루틴의 동작
    • 기존 방법은 “msr daifclr, #2” 명령으로 PSTATE.I를 클리어하는 것으로 local irq를 enable하였다.
    • 새로운 방법은 PMR을 사용하여 IRQON을 위해 0xe0 미만의 우선 순위만을 허용하게 설정하여 디폴트 우선 순위 값 0xa0을 사용하는 irq 및 NMI용 우선 순위 값 0x20을 사용하는 irq 둘 다 허용한다.
  • PMR 관련 priority mask 상수 값
    • GIC_PRIO_IRQON (0xe0)
    • GIC_PRIO_IRQOFF (0x60) <- 위의 값 중 bit7 클리어
  • irq 라인별 우선 순위 상수 값
    • GICD_INT_DEF_PRI (0xa0)
    • GICD_INT_NMI_PRI (0x20) <- 위의 값 중 bit7 클리어
  • 사용 방법
    • CONFIG_ARM64_PSEUDO_NMI=y로 설정해야 한다.
    • 커널 파라미터 “irqchip_gicv3_pseudo_nmi=1” 설정
    • APIs
      • request_nmi() & free_nmi()
      • request_percpu_nmi() & free_percpu_nmi()
  • 제약 조건

 

다음은 irq를 disable 방법에 대해 일반적인 방법과 priority mask를 사용하는 방법을 비교하여 보여준다.

 

저전력 지원

절전 기능을 사용하는 경우 priority mask에 의한 인터럽트 마스킹이 아니라 일반 마스킹을 사용한 절전 방법을 보여준다.

  • core를 정지하는 wfi 명령을 사용한 후 수신된 인터럽트로 인해 깨어나서 해당 인터럽트를 처리하는 과정을 보여준다.

 

Affinity 라우팅 지원

SMP로 동작하는 ARM 아키텍처에는 core마다 각 레벨의 affinity 정보가 기록되어 있다. (각 레벨의 affinity 값은 최대 8비트를 사용한다)

  • AArch32에서는 3 레벨로 운영이된다. (MPIDR에 기록되어 있다.)
  • AArch64에서는 3 또는 4 레벨로 운영이된다. (MPIDR_EL1에 기록되어 있다.)

GIC v3의 Affinity 라우팅은 다음과 같이 운영된다.

  • Affnity 라우팅 사용 여부는 다음 레지스터를 사용한다.
    • GICD_CTLR.ARE_NS
    • GICD_CTLR.ARE_S
  • 칩에 설정된 Affinity 라우팅 레벨은 다음 레지스터에서 확인할 수 있다.
    • ICC_CTLR_EL3.A3V
    • ICC_CTLR_EL1.A3V
    • GICD_TYPER.A3V
  • AArch32에서는 3 레벨로 운영이된다.
  • AArch64에서는 3 레벨 또는 4 레벨로 운영된다.
    • 0.b.c.d (3 레벨 운영)
    • a.b.c.d (4 레벨 운영)

 

Affinity 라우팅 for SPI

각 SPI에 대한 Affinity 라우팅 설정은GICD_IROUTERn을 사용하여 기록한다.

  • 리눅스 커널의 GIC v3에서 모든 SPI 인터럽트들은 디폴트로 boot cpu에 라우팅되도록 boot cpu의 AFFx 값들을 읽어 이 레지스터에 기록하여 사용한다.
  • 예) 어떤 SPI 인터럽트를 1번 cpu의 2번 core로 라우팅하려면 aff3=0, aff2=0, aff1=1, aff0=2로 설정한다.

 

Affinity 라우팅 for SGI

각 SGI에 대한 인터럽트를 만들어 발생할 때 Affinity 라우팅은 다음과 같이 동작한다.

  • 관련 레지스터는 다음과 같다.
    • ICC_SGI0R_EL1
    • ICC_SGI1R_EL1
    • ICC_ASGI1R_EL1. 설정은 GICD_IROUTERn을 사용하여 기록한다.
  • SGI에서는 1개의 Aff3~Aff1까지를 지정하고 Aff0의 경우 16비트로 구성된 TargetList를 사용하여 최대 16개 까지 cpu들에 복수 라우팅이 가능하다.
  • 예) 어떤 SGI 인터럽트를 1번 cpu의 0~3번 core에 동시에 라우팅하려면 aff3=0, aff2=0, aff1=1, TargetList=0x000f로 설정한다.

 

Affinity 라우팅 Legacy 지원 옵션

GIC v3가 legacy (GIC v2로 작성된 드라이버 소프트웨어)를 지원하기 위해 GICD_CTRL 레지스터의 Affinity Routing Enable (ARE) 비트를 사용하여 결정한다.

  • 0: affinity 라우팅 비활성화 (legacy operation).
  • 1: affinity 라우팅 활성화

 

다음 그림은 two security states를 사용하면서 각 states에서 legacy 지원 여부를 각각 결정하는 모습을 보여준다.

 

Redistributor

Redistributor는 다음과 같이 프로그래밍 인터페이스를 제공한다.

  • SGI 및 PPI 활성화 또는 비활성화
  • SGI 및 PPI의 우선 순위 설정
  • 각 PPI를 레벨 감지 또는 에지 트리거로 설정
  • 각 SGI 및 PPI를 인터럽트 그룹에 할당
  • SGI 및 PPI의 보류(Pending) 상태 제어
  • SGI 및 PPI의 활성(Active) 상태 제어
  • 연결된 PE에 대한 전원 관리 지원
  • LPI가 지원되는 경우 관련 인터럽트 속성 및 보류 상태를 지원하는 메모리의 데이터 구조에 대한 기본 주소 제어
  • GICv4가 지원되는 경우 관련 가상 인터럽트 속성 및 보류 상태를 지원하는 메모리의 데이터 구조에 대한 기본 주소 제어

 

 

GIC v3 레지스터들

GIC v3에는 기존 GIC v2에는 없었던 3 가지 시스템 레지스터 그룹(ICC, ICV, ICH)들과 2 개의 메모리 맵드 레지스터 그룹(GICR, GITS)들이 추가되었다. GIC v3의 AArch64 시스템용 레지스터들은 다음과 같은 그룹으로 나눌 수 있다. (AArch32는 생략)

  • 시스템 레지스터들
    • ICC, Physical GIC CPU interface Systerm Registers (GICC를 대체)
    • ICV, Virtual GIC CPU interface Systerm Registers (GICV를 대체)
    • ICH, Virtual Interface Control System Registers (GICH를 대체)
  • 메모리 맵드 레지스터들
    • GICC, CPU Interface Registers
    • GICD, Distributor Registers
    • GICH, Virtual CPU Interface Control Registers
    • GICR, Redistributor Registers
    • GICV, Virtual CPU Interface Registers
    • GITS, ITS Registers

 

시스템 레지스터들과 메모리 맵드 레지스터간의 관계

GIC 아키텍처는 동일한 레지스터를 메모리 맵드 레지스터와 동등한 시스템 레지스터간에 공유 할 수 있도록 허용하지만 필수는 아니다. 다음과 같은 조건으로 하나를 선택하여 사용한다.

  • a) Legacy 미지원
    • 리눅스 커널의 GIC v3 드라이버가 사용한다. 이 경우 GIC v2와 호환하지 않는다.
    • ICC_SRE_ELx.SRE==1
    • 시스템 레지스터를 사용하여 메모리 맵드 레지스터보다 빠르다.
  • b) Legacy 지원
    • GIC v2와 호환 코드를 사용하기 위해 메모리 맵드 레지스터를 사용한다.
    • ICC_SRE_ELx.SRE==0
    • 메모리 맵드 레지스터에 액세스 한 경우 시스템 레지스터가 수정 될 수 있음을 의미한다

 

다음 그림은 레지스터 인터페이스의 Legacy의 호환 여부에 따른 비교를 보여준다.

 

1-1) ICC, Physical GIC CPU interface System Registers

  • ICC_CTLR_EL1 (Interrupt Controller Control Register EL1)
  • ICC_CTLR_EL3 (Interrupt Controller Control Register EL3)
    • CBPR (Common Binary Point Register)
      • 0=preemption 그룹으로 group 0만 사용
      • 1=preemption 그룹으로 group 0과 group 1 모두 사용
    • EOImode (End Of Interrupt Mode)
      • 0=ICC_EOIR_EL1 & ICC_AEOIR_EL1을 사용하여 priority drop 기능과 비활성화 기능 지원
      • 1=ICC_EOIR_EL1 & ICC_AEOIR_EL1을 사용하여 priority drop 기능만 지원, 인터럽트 비활성화 기능은 별도로 ICC_DIR_EL1 사용
    • PMHE (Priority Mask Hint Enable)
      • ICC_PMR_EL1을 힌트로 사용하는 것의 유무
      • 0=disable, 1=enable
    • PRIbists (Priority bits)
      • 몇 개의 priority 비트를 지원하는지를 알아온다. (Read Only)
        • 2개의 security state를 지원하는 시스템의 경우 최소 32단계(5 priority bits) 이상이어야 한다.
        • 1개의 security state를 지원하는 시스템의 경우 최소 16단계(4 priority bits) 이상이어야 한다.
    • IDbits (Identifier bits)
      • 인터럽트 id로 몇 비트를 사용하는지 알아온다. (Read Only)
        • 000=16bits, 001=24bits
    • SEIS (SEI Support)
      • CPU 인터페이스가 local SEI들의 generation을 지원하는지 여부 (Read Only)
        • 0=not support, 1=support
    • A3V (Affinity 3 Valid)
      • CPU 인터페이스가 SGI generation시 affinity 3의 사용을 지원하는지 여부(Read Only)
        • 0=zero values, 1=non-zero values
    • RSS (Range Select Support)
      • SGI 사용 시 Targeted Affinity 레벨 0 값으로 허용하는 범위
        • 0=0~15까지 허용한다. (0~15 cpu)
        • 1=0~255까지 허용한다. (0~255 cpu)
    • ExtRange
      • 확장 SPI 지원 여부
        • 0=INTID 1024 to 8191까지 사용하지 않는다.
        • 1=INTID 1024 to 8191까지 사용 가능하다.

 

  • ICC_PMR_EL1 (Interrupt Controller Interrupt Priority Mask Register EL1)
    • Priority Mask
      • priority mask 값으로 이 값보다 작은 값(수치가 작을 수록 가장 높은 우선 순위이다)의 priority를 가진 인터럽트를 PE(Processing Element)에 전달하고, 그 외의 인터럽트는 block 한다.
      • 참고로 BIT(8 – IIC_CTRL.pribits) 값을 이 필드에 저장하고 다시 읽었을 때 0인 값이 읽히면 group 0를 사용하지 못하는 상태를 알 수 있다.
      • Pesudo-NMI 구현 시 이 값으로 GIC_PRIO_IRQON(0xe0)과 GIC_PRIO_IRQOFF(0x60)을 기록하여 사용한다.
      • 0 값을 기록하는 경우 모든 인터럽트가 전달되지 않는다.
  • ICC_BPR0_EL1 (Interrupt Controller Interrupt Binary Point Register 0 EL1)
  • ICC_BPR1_EL1 (Interrupt Controller Interrupt Binary Point Register 1 EL1)
    • Binary Point
      • priority 값을 group priority(g) 필드와 subpriority(s) 필드로  나누는 기준 값을 설정한다.  group priority 필드는 인터럽트 preemption을 의미한다.
        • 0=ggggggg.s
        • 1=gggggg.ss
        • 2=ggggg.sss
        • 3=gggg.ssss
        • 4=ggg.sssss
        • 5=gg.ssssss
        • 6=g.sssssss
        • 7=ssssssss (no preemption)
      • 이 필드에 0 값을 기록하여 리셋시킬 수 있다. 리셋된 후의 값은 구현에 따라 다르다.
    • security 사용 여부에 따라 다음과 같이 처리한다.
      • Security Extension을 사용하지 않는 경우 다음과 같이 처리한다.
        • group 0 인터럽트 또는 GICC_CTLR.CBPR==1인 경우 GICC_BPR을 사용한다.
        • group 1 인터럽트 또는 GICC_CTLR.CBPR==0인 경우 GICC_ABPR을 사용한다.
      • Security Extension을 사용하는 경우 secure/non-secure별 뱅크된 GICC_BPR을 사용한다.
  • ICC_IAR0_EL1 (Interrupt Controller Interrupt Acknowledge Register 0 EL1)
  • ICC_IAR1_EL1 (Interrupt Controller Interrupt Acknowledge Register 1 EL1)
    • 인터럽트 수신 시 이 레지스터를 읽어 인터럽트 id를 읽어오는 것으로 인터럽트 처리 루틴이 ack 처리되었음을 gic에 알린다. (읽기 전용)
  • ICC_EOIR0_EL1 (Interrupt Controller Interrupt End Of Interrupt Register 0 EL1)
  • ICC_EOIR1_EL1 (Interrupt Controller Interrupt End Of Interrupt Register 1 EL1)
    • ISR(Interrupt Service Routine)에서 인터럽트 처리 완료 시 해당 인터럽트 id를 기록하여 eoi 처리하였음을 gic에 알린다. (쓰기 전용)
  • ICC_RPR_EL1 (Interrupt Controller Interrupt Running Priority Register EL1)
    • 읽기 전용으로 현재 동작하고 있는 인터럽트의 priority 값을 알아온다.
    • idle 상태인 경우는 0xff
  • ICC_HPPIR0_EL1 (Interrupt Controller Interrupt Highest Priority Pending Interrupt Register 0 EL1)
  • ICC_HPPIR1_EL1 (Interrupt Controller Interrupt Highest Priority Pending Interrupt Register 1 EL1)
    • 현재 하드웨어 인터럽트들 중 pending되고 있는 가장 높은 priority irq 번호를 읽어온다. (읽기 전용)
  • ICC_SRE_EL1 (Interrupt Controller Interrupt System Register Enable Register EL1)
  • ICC_SRE_EL2 (Interrupt Controller Interrupt System Register Enable Register EL2)
  • ICC_SRE_EL3 (Interrupt Controller Interrupt System Register Enable Register EL3)
    • SRE (System Register Enable)
      • 0=반드시 메모리 맵드 인터페이스가 사용되야 한다.
      • 1=현재 security state의 시스템 레지스터 인터페이스를 enable 한다.
        • 리눅스 커널의 GIC v3 드라이버는 시스템 레지스터를 사용한다.
    • DFB (Disable FIQ Bypass)
      • 0=FIQ bypass enable
      • 1=FIQ bypass disable
    • DIB (Disable IRQ Bypass)
      • 0=IRQ bypass enable
      • 1=IRQ bypass disable
  • ICC_DIR_EL1 (Interrupt Controller Interrupt Deactivate Interrupt Register EL1)
    • INTID에 해당하는 인터럽트를 비활성화시킨다. (쓰기 전용)
  • ICC_IGRPEN0_EL1 (Interrupt Controller Interrupt Group 0 Enable Register EL1)
  • ICC_IGRPEN1_EL1 (Interrupt Controller Interrupt Group 1 Enable Register EL1)
  • ICC_IGRPEN1_EL3 (Interrupt Controller Interrupt Group 1 Enable Register EL3)
    • Group 0(1) 인터럽트의 활성화를 결정한다.
      • 0=disable
      • 1=enable
  • ICC_AP0Rn_EL1 (Interrupt Controller Interrupt Active Priorities Group 0 Registers EL1)
  • ICC_AP1Rn_EL1 (Interrupt Controller Interrupt Active Priorities Group 1 Registers EL1)
    • group 0(1)의 active priorities 정보를 제공한다. (칩 구현에 따라 다르다.)

 

  • ICC_SGI0R_EL1 (Interrupt Contorller Software Generated Interrupt Group 0 Register EL1)
  • ICC_SGI1R_EL1 (Interrupt Contorller Software Generated Interrupt Group 1 Register EL1)
  • ICC_ASGI1R_EL1 (Interrupt Contorller Alias Software Generated Interrupt Group 1 Register EL1)
    • SGI를 발생시킨다. (쓰기 전용)
    • 리눅스 커널에서는 IPI(Inter Process Interrupt)라고 불린다.
    • TargetList
      • SGI를 발생시킬 aff0 레벨의 cpu들(최대 16개)
    • INTID
      • 발생시킬 SGI 번호
    • Aff1~3
      • SGI 인터럽트가 전달될 cpu affinity를 지정한다.

 

1-2) ICV, Virtual GIC CPU interface Systerm Registers

  • ICV_AP0Rn_EL1 (Interrupt Controller Virtual Active Priorities Group 0 Registers EL1)
  • ICV_AP1Rn_EL1 (Interrupt Controller Virtual Active Priorities Group 1 Registers EL1)
  • ICV_BPR0_EL1 (Interrupt Controller Virtual Binary Point Register 0 EL1)
  • ICV_BPR1_EL1 (Interrupt Controller Virtual Binary Point Register 1 EL1)
  • ICV_CTLR_EL1 (Interrupt Controller Virtual Control Register EL1)
  • ICV_DIR_EL1 (Interrupt Controller Deactivate Virtual Interrupt Register EL1)
  • ICV_EOIR0_EL1 (Interrupt Controller Virtual End Of Interrupt Register 0 EL1)
  • ICV_EOIR1_EL1 (Interrupt Controller Virtual End Of Interrupt Register 1 EL1)
  • ICV_HPPIR0_EL1 (Interrupt Controller Virtual Highest Priority Pending Interrupt Register 0 EL1)
  • ICV_HPPIR1_EL1 (Interrupt Controller Virtual Highest Priority Pending Interrupt Register 1 EL1)
  • ICV_IAR0_EL1 (Interrupt Controller Virtual Interrupt Acknowledge Register 0 EL1)
  • ICV_IAR1_EL1 (Interrupt Controller Virtual Interrupt Acknowledge Register 1 EL1)
  • ICV_IGRPEN0_EL1 (Interrupt Controller Virtual Interrupt Group 0 Enable register EL1)
  • ICV_IGRPEN1_EL1 (Interrupt Controller Virtual Interrupt Group 1 Enable register EL1)
  • ICV_PMR_EL1 (Interrupt Controller Virtual Interrupt Priority Mask Register EL1)
  • ICV_RPR_EL1 (Interrupt Controller Virtual Running Priority Register EL1)

 

1-3) ICH, Virtualization Control System Registers

  • ICH_AP0Rn_EL2 (Interrupt Controller Hyp Active Priorities Group 0 Registers EL2)
  • ICH_AP1Rn_EL2 (Interrupt Controller Hyp Active Priorities Group 1 Registers EL2)
  • ICH_HCR_EL2 (Interrupt Controller Hyp Control Register EL2)
  • ICH_VTR_EL2 (Interrupt Controller VGIC Type Register EL2)
  • ICH_MISR_EL2 (Interrupt Controller Maintenance Interrupt State Register EL2)
  • ICH_EISR_EL2 (Interrupt Controller End of Interrupt Status Register EL2)
  • ICH_ELRSR_EL2 (Interrupt Controller Empty List Register Status Register EL2)
  • ICH_VMCR_EL2 (Interrupt Controller Virtual Machine Control Register EL2)
  • ICH_LRn_EL2 (Interrupt Controller List Registers EL2)

 

2-1) GICC, CPU interface Registers

  • GICC_CTRL (CPU Interface Control Register)
    • GIC v2와 다르게 3가지 모드에서 사용방법이 다르고, 더 많은 제어 비트를 가진다.
      • 1) GICD_CTRL.DS=0 & Non-Secure
        • 리눅스 커널에서 GIC v3  드라이버가 이 모드를 사용하여 설정한다.
      • 2) GICD_CTRL.DS=0 & Secure
        • 시큐어 OS가 사용하는 모드이다.
      • 3) GICD_CTRL.DS=1
    • EnableGrp0~1
      • Group 0와 Group 1에 대한 인터럽트 시그널의 enable 설정이다. (0=disable, 1=enable)
    • FIQEn
      • group 0 인터럽트의 FIQ 시그널 처리 여부
        • 0=disable(IRQ로 처리), 1=enable(FIQ로 처리)
    • CBPR
      • 인터럽트 preemption 지원 방법
        • 0=GICC_BPR을 사용하여 group 0 인터럽트들의 preemption을 지원하고, group 1 인터럽트는 GICC_ABPR 레지스터를 사용하여 지원
        • 1=GICC_BPR을 사용하여 group 0 및 group 1 인터럽트들의 preemption을 지원한다.
    • FIQBypDisGrp0~1 & IRQBypDisGrp0~1
      • cpu 인터페이스 비활성화시 PE에 인터럽트 바이패스 Disable 여부 (0=bypass, 1=bypass disable)
    • EOImode (EOImodeS & EOImodeNS)
      • 0=GICC_EOIR & GICC_AEOIR을 사용하여 priority drop 기능과 비활성화 기능 지원
      • 1=GICC_EOIR & GICC_AEOIR을 사용하여 priority drop 기능만 지원, 인터럽트 비활성화 기능은 별도로 GICC_DIR 사용

 

  • GICC_PMR (Interrupt Priority Mask Register)
    • core로 전달될 irq들에 대해 설정한 priority 마스크 값보다 작은 priority 값(값이 작을 수록 우선 순위가 높다)을 cpu로 전달한다.
      • 리눅스 커널의 GIC v1~v4 드라이버는 0xf0을 설정하여 사용한다.
    • 0 값을 기록하는 경우 모든 인터럽트가 전달되지 않는다.
  • GICC_BPR (Binary Point Register)
    • priority 값을 group/sub와 같이 두 그룹으로 나누어 그 중 group에 해당하는 priority를 가진 인터럽트에 대해 preemption interrupt로 분류한다.
      • 0=ggggggg.s
      • 1=gggggg.ss
      • 2=ggggg.sss
      • 3=gggg.ssss
      • 4=ggg.sssss
      • 5=gg.ssssss
      • 6=g.sssssss
      • 7=ssssssss (no preemption)
    • 리눅스 커널의 경우 GIC v3 부터 이 필드에 0 값을 기록하여 리셋시킨 후 사용한다. 리셋 후의 값은 칩 구현에 따라 다르다.
    • two security state를 사용하는 경우 secure/non-secure별 뱅크된 GICC_BPR을 사용한다.
    • single security state를 사용하는 경우 group 0만 인터럽트 preemption을 지원한다.
  • GICC_IAR  (Interrupt Acknowledge Register)
    • 인터럽트 수신 시 이 레지스터를 읽어 인터럽트 id를 읽어오는 것으로 인터럽트 처리 루틴이 ack 처리되었음을 gic에 알린다.
  • GICC_EOIR  (End of Interrupt Register)
    • ISR(Interrupt Service Routine)에서 인터럽트 처리 완료 시 해당 인터럽트 id를 기록하여 eoi 처리하였음을 gic에 알린다.
  • GICC_RPR (Running Priority Register)
    • 읽기 전용으로 현재 동작하고 있는 인터럽트의 priority 값을 알아온다. idle 상태인 경우는 0xff
    • non-secure에서 읽은 경우 0x80을 mask 하여사용한다.
  • GICC_HPPIR (Highest Priority Pending Interrupt Register)
    • 읽기 전용으로 현재 하드웨어 인터럽트들 중 pending되고 있는 가장 높은 priority irq 번호를 읽어온다.
  • GICC_IIDR (CPU Interface Identification Register)
    • 읽기 전용으로 GIC 제품 ID, 아키텍처 버전, 리비전, 구현회사 등의 정보를 읽어올 수 있다.
  • GICC_ABPR (Aliased Binary Point Register)
  • GICC_APRn (Active Priorities Register)
  • GICC_NSAPRn (Non-Secure Active Priorities Register)
    • active priorities 정보를 제공한다. (칩 구현에 따라 다르다)
  • GICC_AEOIR (Aliased End of Interrupt Register)
  • GICC_AIAR (Aliased Interrupt Acknowledge Register)
  • GICC_AHPPIR (Aliased Highest Priority Pending Interrupt Register)
  • GICC_DIR (Deactivate Interrupt Register)
    • INTID에 해당하는 인터럽트를 비활성화시킨다. (쓰기 전용)

 

2-2) GICD, Distributor Registers

  • GICD_CTRL (Distributor Control Register)
    • EnableGrp0~1
      • Group 0(1) 인터럽트의 활성화 여부 (EnableGrp1NS=non-secure에서, EnableGrp1S=secure에서)
        • 0=disable, 1=enable
      • Pending 인터럽트에 대해 CPU interface로 올려보낼지 여부를 통제한다.
        • secure extension을 사용할 때 non-secure 모드에서는 group1에 대해서만 통제할 수 있다.
        • security extension 사용 시 bank 된다.
    • ARE (Affinity Routing Enable)
      • affinitiny routing의 활성화 여부 (ARE_NS=non-secure에서, ARE_S=secure에서)
        • 0=disable, 1=enable
    • DS (Disable Security)
      • non-secure 에서 group 0 인터럽트들에 대한 레지스터들에 access를 허용 여부
        • 0=access 금지, 1=access 허용
    • E1NWF (Enable 1 of N Wakeup Functionality)
      • N 개 중 하나의 인터럽트를 선택하여 PE를 깨어나게 하는 기능
        • 0=disable, 1=enabel
    • RWP (Register Write Pending)
      • 이 레지스터의 기록이 진행중인지 여부. 진행 중에는 기록하지 못한다. (Read Only)
        • 0=Write 가능
        • 1=Write 진행중

 

  • GICD_TYPER (Interrupt Controller Type Register)
    • 읽기 전용으로 Security Extension 사용 시 최대 지원 cpu 수와 인터럽트 수 등을 알아내기 위해 사용한다.
    • ESPI_range
      • GICD_TYPER.ESPI==1로 설정된 경우 최대 확장 SPI INTID 수로 다음 식과 같다.
        • = (32 * (ESPI_range + 1) + 4095)
    • RSS (Range Select Support)
      • affinity level 0에서 IRI 지원 SGI 대상 범위 선택
        • 0=0~15
        • 1=0~255
    • No1N (No support 1 Of N)
      • 1 of N SPI 인트럽트 비지원 여부
        • 0=supported, 1=not supported
    • A3V
      • Affinity 3 valid 여부
        • 0=not support (all zero values), 1=support
    • IDBits
      • 지원하는 인터럽트 수에 대한 비트 표현-1
      • 수식 = 2^(N+1)
        • 예) 0b01001 -> 1024 인터럽트
    • DVIS (Direct Virtual LPI Injection Support)
      • Direct Virtual LPI 인젝션의 지원 여부
        • 0=not support, 1=support
    • LPIS (LPI Support)
      • LPI 지원 여부
        • 0=not support, 1=support
    • MBIS (Message Based Interrupts Support)
      • 메시지 기반 인터럽트의 지원 여부
        • 0=not support, 1=support
    • num_LPIs
      • 지원 가능한 LPI 수 (GICD_TYPER.IDbits를 초과할 수 없다)
        • =2^(num_LPIs+1) .
          • LPI용 INITID 범위: 8192 ~ (8192 + 2^(num_LPIs+1) – 1)
        • 0인 경우 GICD_TYPER.IDbits 로 산출된 수와 동일
        • ◦ This field cannot indicate a maximum LPI INTID greater than that indicated byWhen the supported INTID width is less than 14 bits, this field is RES0 and no LPIs are supported.
    • SecurityExtn
      • Two Security 지원 여부
        • 0=not support (single security states), 1=support (two security states)
    • ESPI (Extended SPI range)
      • Extended SPI range 지원 여부
        • 0=미지원 1=지원
    • CPU Number
      • Affinity Routing 사용 시 최대 지원 CPU 수에 대한 비트 표현-1(0=ARE 미지원)
        • 수식 = 2^(N+1)
        • 예) 0b001 -> 4개 cpu
    • ITLinesNumber
      • 지원 SPI 인터럽트 수(최대 수=1020)
      • 수식 = 32 * (N+1)
        • 예) 0b00011 -> 32 * (3 + 1) = 128
        • 예) 0b11111 -> 32 * (31 + 1) = 1024이나 최대 수인 1020개 제한
  • GICD_IIDR (Distributor Implementer Identification Register)
    • 읽기 전용으로 GIC implementor 정보를 알아온다.

 

  • GICD_IGROUPRn (Interrupt Group Registers)
    • secure extension을 사용하는 경우 인터럽트별로 secure group 0와 non-secure group 1을 지정한다.
      • 0=secure group 0, 1=non-secure group 1
    • secure extension을 사용하는 경우 리셋시 0으로(RAS) 읽히며, 모든 인터럽트가 재설정되기 전엔 모두 secure group 0 상태가된다.
      • SMP 시스템에서 secure extension을 지원하고, non-secure 프로세서들에 대해서는 뱅크된 GICD_IGROUPR0은 non-secure group 1 상태로 리셋한다.
    • IRQ #0~31을 위해 첫 레지스트가 cpu별로 bank 되어 사용된다.
    • 최종 secure 상태를 결정하기 위해 GICD_IGRPMODRn 과 같이 사용된다.
    • two security states를 사용할 때에는 반드시 secure에서 설정을 해야 유효하다. non-secure에서 동작하는 리눅스 커널에서의 설정은 의미가 없다.
    • 리눅스 커널의 GIC v3 드라이버에서는 single security state를 위해 모든 SPI 인터럽트들을 G1NS(non-secure group 1)으로 설정한다.
  • GICD_IGRPMODRn (Interrupt Group Modifier Registers)
    • two security 모드로 동작 시 GICD_IGROUPRn와 같이 사용하여 최종 그룹과 secure 상태를 결정한다.
      • 0=secure group 0 -> G0S(secure group 0), non-secure group 1 -> G1NS(non-secure group 1)
      • 1=secure group 0 -> G1S(secure group 1), non-secure group 1 -> G1NS(non-secure group 1, reserved)
    • two security states를 사용할 때에는 반드시 secure에서 설정을 해야 유효하다. non-secure에서 동작하는 리눅스 커널에서의 설정은 의미가 없다.
  • GICD_ISENABLERn (Interrupt Set-Enable Registers)
    • IRQ 별로 통과(Set-Enable) 여부를 설정할 수 있다.
      • 1=set 요청
    • IRQ #0~31을 위해 첫 레지스트가 cpu별로 bank 되어 사용된다.
  • GICD_ICENABLERn (Interrupt Clear-Enable Registers)
    • IRQ 별로 통제(Clear-Enable) 여부를 설정할 수 있다.
      • 1=clear 요청
    • IRQ #0~31을 위해 첫 레지스트가 cpu별로 bank 되어 사용된다.
  • GICD_ISPENDRn (Interrupt Set PENDing Registers)
    • IRQ 별로 pending 상태를 설정할 수 있다.
      • 1=set 요청
    • IRQ #0~31을 위해 첫 레지스트가 cpu별로 bank 되어 사용된다.
  • GICD_ICPENDRn (Interrupt Clear PENDing Registers)
    • IRQ 별로 pending 상태 해제를 요청할 수 있다.
      • 1=clear 요청
    • IRQ #0~31을 위해 첫 레지스트가 cpu별로 bank 되어 사용된다.
  • GICD_IPRIORITYRn (Interrupt PRIORITY Registers)
    • IRQ 별로 priority를 설정할 수 있다.
      • 0~255 priority 설정
    • IRQ #0~31을 위해 첫 8개의 레지스트가 cpu별로 bank 되어 사용된다.
    • 리눅스 커널의 GIC v3 드라이버는 디폴트 값으로 0xa0 값을 사용한다.  단 최근 커널에서 pesudo-nmi를 지원하는 경우 nmi 모드를 위해서는 0x20 값을 사용한다.
      • non-secure에서 설정한 값이므로 우선순위 값은 다음과 같이 변환되어 사용된다.
        • (0xa0 >> 1 | 0x80) = 0xd0
        • (0x20 >> 1 | 0x80) = 0x90
  • GICD_ITARGETRn (Interrupt processor TARGET Registers)
    • IRQ 별로 개별 cpu interface로의 전달여부를 비트로 마스크 설정할 수 있다.
    • bit0=cpu#0 제어, bit1=cpu#1 제어…
      • 0=disable forward, 1=enable forward
    • IRQ #0~31을 위해 첫 8개의 레지스트가 cpu별로 bank 되어 사용된다.
  • GICD_ICFGRn (Interrupt ConFiGuration Registers)
    • IRQ 별로 인터럽트 트리거 방향을 설정할 수 있다.
      • 0=상향 시 트리거, 1=하향 시 트리거
    • IRQ #160~31을 위해 두 번째 레지스트가 cpu별로 bank 되어 사용된다.
  • GICD_ISACTIVERn (Interrupt Set-Active Registers)
    • IRQ 별로 활성화 요청한다.
      • 1=활성화 요청
  • GICD_ICACTIVERn (Interrupt Clear-Active Registers)
    • IRQ 별로 비활성화 요청한다.
      • 1=비활성화 요청
  • GICD_NSACRn (Non-secure Access Control Registers)
    • non-secure 소프트웨어만 설정할 수 있다.
    • 특정 PE의 non-secure 그룹 0 인터럽트에 대한 제어 활성화 여부
      • 00=not permit
      • 01=set-pending 허용, secure SGI 생성 허용, clear-pending 허용 가능(구현에 따라)
      • 10=01에 추가하여 clear-pending 허용, set-active 및 clear-active 허용
      • 11=10에 추가하여 target cpu 지정 및 affinity 라우팅 정보 사용 가능

 

  • GICD_SGIR (Software Generated Interrupt Register)
    • TLF (Target List Filter)
      • 0=white list 제어 방식, CPU Target List에 설정된 cpu로만 forward
      • 1=black list 제어 방식, CPU Target List에 설정된 cpu만 drop
      • 2=위의 ACL 방식 제어를 사용하지 않는다.
      • 3=reserved
    • CPU Target List
      • 0~7개의 cpu bit
    • NSATT (Non-Secure
      • 0=SGI#에 대해 group-0으로 설정된 경우 CPU Target List로 forward
      • 1=SGI#에 대해 group-1로 설정된 경우 CPU Target List로 forward
  • GICD_CPENDSGIRn (SGI Clear-Pending Registers)
    • Pending SGI 인터럽트 상태 클리어 (1=clear 요청)
  • GICD_SPENDSGIRn (SGI Set-Pending Registers)
    • Pending SGI 인터럽트 상태 설정 (1=set 요청)
  • GICD_IROUTERn (Interrupt Routing Registers)
    • affinity 라우팅(ARE)이 활성화된 경우 SPI에 대한 라우팅 정보를 제공한다.
    • Aff0~3
      • affinity 레벨별 cpu 마스크 정보
        • 리눅스 커널의 GIC v3 드라이버는 boot cpu의 aff3.aff2.aff1.aff0 정보를 기록하여 boot cpu로 라우팅하도록 디폴트로 설정하여 운영한다.
    • IRM (Interrupt Routing Mode)
      • 0=인터럽트가 aff3,aff2.aff1.aff0으로 라우팅 (정보를 사용하여 Affinity Routing)
        • 리눅스 커널의 GIC v3 드라이버가 이 모드를 디폴트 설정하여 운영한다.
      • 1=인터럽트가 협력하는 노드의 모든 PE로 라우팅 (정보를 사용하지 않고 노드내 모든 PR로 Affinity Routing)

 

2-3) GICH, Virtual CPU Interface Control Registers

  • GICH_APR (Active Priorities Register)
  • GICH_EISRn (End of Interrupt Status Registers)
  • GICH_ELRSRn (Empty List Register Status Registers)
  • GICH_HCR (Hypervisor Control Register)
  • GICH_LRn (List Registers)
  • GICH_MISR (Maintenance Interrupt Status Register)
  • GICH_VMCR (Virtual Machine Control Register)
  • GICH_VTR (VGIC Type Register)

 

2-4) GICR, Redistributor Registers

  • GICR_CLRLPIR (Clear LPI Pending Register)
  • GICR_CTLR (Redistributor Control Register)
  • GICR_ICACTIVER0 (Interrupt Clear-Active Register 0)
  • GICR_ICENABLER0 (Interrupt Clear-Enable Register 0)
  • GICR_ICFGR0 (Interrupt Configuration Register 0)
  • GICR_ICFGR1 (Interrupt Configuration Register 1)
  • GICR_ICPENDR0 (Interrupt Clear-Pending Register 0)
  • GICR_IGROUPR0 (Interrupt Group Register 0)
  • GICR_IGRPMODR0 (Interrupt Group Modifier Register 0)
  • GICR_IIDR (Redistributor Implementer Identification Register)
  • GICR_INVALLR (Redistributor Invalidate All Register)
  • GICR_INVLPIR (Redistributor Invalidate LPI Register)
  • GICR_IPRIORITYRn (Interrupt Priority Registers)
  • GICR_ISACTIVER0 (Interrupt Set-Active Register 0)
  • GICR_ISENABLER0 (Interrupt Set-Enable Register 0)
  • GICR_ISPENDR0 (Interrupt Set-Pending Register 0)
  • GICR_NSACR (Non-secure Access Control Register)
  • GICR_PENDBASER (Redistributor LPI Pending Table Base Address Register)
  • GICR_PROPBASER (Redistributor Properties Base Address Register)
  • GICR_SETLPIR (Set LPI Pending Register)
  • GICR_STATUSR (Error Reporting Status Register)
  • GICR_SYNCR (Redistributor Synchronize Register)
  • GICR_TYPER (Redistributor Type Register)
  • GICR_VPENDBASER (Virtual Redistributor LPI Pending Table Base Address Register)
  • GICR_VPROPBASER (Virtual Redistributor Properties Base Address Register)
  • GICR_WAKER (Redistributor Wake Register)

 

2-5) GICV, Virtual CPU Interface Registers

  • GICV_ABPR (VM Aliased Binary Point Register)
  • GICV_AEOIR (VM Aliased End of Interrupt Register)
  • GICV_AHPPIR (VM Aliased Highest Priority Pending Interrupt Register)
  • GICV_AIAR (VM Aliased Interrupt Acknowledge Register)
  • GICV_APRn (VM Active Priorities Registers)
  • GICV_BPR (VM Binary Point Register)
  • GICV_CTLR (Virtual Machine Control Register)
  • GICV_EOIR (VM End of Interrupt Register)
  • GICV_HPPIR (VM Highest Priority Pending Interrupt Register)
  • GICV_IAR (VM Interrupt Acknowledge Register)
  • GICV_PMR (VM Priority Mask Register)
  • GICV_RPR (VM Running Priority Register)
  • GICV_IIDR (VM CPU Interface Identification Register)
  • GICV_DIR (VM Deactivate Interrupt Register)

 

2-6) GITS, ITS Registers

  • GITS_BASERn (ITS Translation Table Descriptors)
  • GITS_CBASER (ITS Command Queue Descriptor)
  • GITS_CREADR (ITS Read Register)
  • GITS_CTLR (ITS Control Register)
  • GITS_CWRITER (ITS Write Register)
  • GITS_IIDR (ITS Identification Register)
  • GITS_TRANSLATER (ITS Translation Register)
  • GITS_TYPER (ITS Type Register)

 


BCM2708(RPI) 인터럽트 컨트롤러

BCM2708 인터럽트 컨트롤러

arm irq에 해당하는 박스에 색상이 있는 항목들은 실제 ARM 커널 드라이버에서 처리된다.

 

인터럽트 소스 구분

RPI에서 처리하는 인터럽트 소스는 다음과 같다.

  • Pending IRQ1:
    • GPU peripherals 인터럽트
    • irqnr = #0~31
      • 7, 9, 10, 18, 19번은 ARM과 share
  • Pending IRQ2:
    • GPU peripherals 인터럽트
    • irqnr = #32~63
      • 53~57, 62번은 ARM과 share
  • Pending Base IRQ0:
    • ARM peripherals 인터럽트
    • irqnr = #64~95
      • 64~71번은 timer, doorbell #0~1, mailbox, …
      • 72-73번은 pending #1-#2 레지스터 소스
      • 74~85번은 VideoCore와 share

 

 

관련 레지스터

  • 0x7E00_0000으로 시작하는 주소는 GPU(VC)에 연결된 I/O peripherals 기본 물리 주소이다. 따라서 ARM 리눅스에서 사용하는 물리주소와 가상주소로 변환하여 사용한다.
    • rpi (ARM 기본 주소):
      • GPU 물리 주소: 0x7e00_0000 (DTB에 구성된 주소로 ARM 관점에서 BUS 주소로 본다.)
      • ARM 물리 주소: 0x2000_0000
      • ARM 가상 주소: 0xf200_0000
    • rpi2 (ARM 기본 주소):
      • GPU 물리 주소: 0x7e00_0000 (DTB에 구성된 주소로 ARM 관점에서 BUS 주소로 본다.)
      • ARM 물리 주소: 0x3f00_0000
      • ARM 가상 주소: 0xf300_0000

 


BCM2709(RPI2) 인터럽트 컨트롤러

BCM2709 인터럽트 컨트롤러

arm irq에 해당하는 박스에 색상이 있는 항목들은 실제 ARM 커널 드라이버에서 처리된다.

인터럽트 소스 구분

RPI2에서 처리하는 인터럽트 소스는 다음과 같다. Machine Specific 함수에서 초기화한 경우와 Device Tree로 초기화할 때의 구성이 다르다.

  • HARD IRQs
    • GPU Pending IRQ1:
      • GPU peripherals 인터럽트
      • Machine Specific irqnr = #0~31
        • 7, 9, 10, 18, 19번은 ARM과 share
      • Device Tree virq=30~61, hwirq=32~63
    • GPU Pending IRQ2:
      • GPU peripherals 인터럽트
      • Machine Specific irqnr = #32~63
        • 53~57, 62번은 ARM과 share
      • Device Tree virq=62~93, hwirq=64~95
    • ARM Pending Base IRQ0:
      • ARM peripherals 인터럽트
      • irqnr = #64~95
        • 64~71번은 timer, doorbell #0~1, mailbox, …
        • 72-73번은 pending #1-#2 레지스터 소스
        • 74~85번은 VideoCore와 share
      • Device Tree virq=22~29, hwirq=0~7
    • LOCAL:
      • 인터럽트 소스로 해당 비트가 설정되는 경우 각각의 레지스터를 통해 해당 IRQ를 얻어낸다.
      • irqnr = #96~127
        • 100~103번은 mailbox0~3 interrupt controller 레지스터 소스
        • 104 번은 pending #0 레지스터 소스
        • 105번은 PMU 레지스터 소스
      • Device Tree virq=16~21, hwirq=0~9
  • Soft IRQs:
    • IPI (mailbox #0)
      • ipinr = #0~31
        • 8~31번은 리눅스에서 사용하지 않는다.
    • mailbox #1~3, doorbell, timer, …

 

BCM2709 인터럽트 컨트롤러 레지스터 (Machine Specific)

관련 레지스터

BCM2708의 10개의 (IRQ basic pending ~ ) 기본 레지스터들과 동일하고 BCM2709는 ARM 전용으로 다음과 같이 추가되었다.

이 레지스터들은 GPU(VC)에서 사용하지 않고 ARM 전용으로 사용된다.

  • rpi2 (ARM LOCAL 기본 주소):
    • ARM 물리 주소: 0x4000_0000
    • ARM 가상 주소: 0xf400_0000

 

RPI2 인터럽트 확인 (Machine-Specific)

rpi2를 machine specific 코드 기반으로 초기화된 인터럽트 정보이다.

  • 보여주는 정보 순서
    • irq 번호
    • cpu별 인터럽트 통계
    • irq_chip.name
    • irq_domain.hwirq
      • irq_domain이 설정되지 않아 출력되지 않음
    • 트리거 레벨
      • CONFIG_GENERIC_IRQ_SHOW_LEVEL이 설정되지 않아 출력되지 않음
    • irq name
      • 이름이 설정되지 않아 아무것도 출력되지 않음
    • action list
      • 1개 이상은 컴마로 분리됨
$ cat /proc/interrupts
           CPU0       CPU1       CPU2       CPU3
 16:          0          0          0          0   ARMCTRL  bcm2708_fb dma
 24:      12845          0          0          0   ARMCTRL  DMA IRQ
 25:       2980          0          0          0   ARMCTRL  DMA IRQ
 32:  128848277          0          0          0   ARMCTRL  dwc_otg, dwc_otg_pcd, dwc_otg_hcd:usb1
 52:          0          0          0          0   ARMCTRL  BCM2708 GPIO catchall handler
 65:         11          0          0          0   ARMCTRL  bcm2708_vcio
 66:          2          0          0          0   ARMCTRL  VCHIQ doorbell
 75:          1          0          0          0   ARMCTRL
 83:          2          0          0          0   ARMCTRL  uart-pl011
 84:     497931          0          0          0   ARMCTRL  mmc0
 99:    4675934    2099819     568663      90331   ARMCTRL  arch_timer
FIQ:              usb_fiq
IPI0:          0          0          0          0  CPU wakeup interrupts
IPI1:          0          0          0          0  Timer broadcast interrupts
IPI2:     137529      40597      36229      25588  Rescheduling interrupts
IPI3:         14         17         11         15  Function call interrupts
IPI4:          1          5          1          3  Single function call interrupts
IPI5:          0          0          0          0  CPU stop interrupts
IPI6:          0          0          0          0  IRQ work interrupts
IPI7:          0          0          0          0  completion interrupts
Err:

 

RPI2 인터럽트 확인 (Device Tree)

Device Tree로 구성한 인터럽트 정보이다..

  • 보여주는 정보 순서
    • irq 번호
    • cpu별 인터럽트 통계
    • irq_chip.name
    • irq_domain.hwirq
    • 트리거 레벨
    • irq name
      • 이름이 설정되지 않아 아무것도 출력되지 않음
    • action list
      • 1개 이상은 컴마로 분리됨
$ cat /proc/interrupts
           CPU0       CPU1       CPU2       CPU3
 16:          0          0          0          0  bcm2836-timer   0 Edge      arch_timer
 17:   37228140   22280702  154598435   50544784  bcm2836-timer   1 Edge      arch_timer
 23:      24375          0          0          0  ARMCTRL-level   1 Edge      3f00b880.mailbox
 24:        216          0          0          0  ARMCTRL-level   2 Edge      VCHIQ doorbell
 39:          1          0          0          0  ARMCTRL-level  41 Edge
 46:          0          0          0          0  ARMCTRL-level  48 Edge      bcm2708_fb dma
 48:     545428          0          0          0  ARMCTRL-level  50 Edge      DMA IRQ
 50:          0          0          0          0  ARMCTRL-level  52 Edge      DMA IRQ
 62:  925102072          0          0          0  ARMCTRL-level  64 Edge      dwc_otg, dwc_otg_pcd, dwc_otg_hcd:usb1
 79:          0          0          0          0  ARMCTRL-level  81 Edge      3f200000.gpio:bank0
 80:          0          0          0          0  ARMCTRL-level  82 Edge      3f200000.gpio:bank1
 86:     540806          0          0          0  ARMCTRL-level  88 Edge      mmc0
 87:       5053          0          0          0  ARMCTRL-level  89 Edge      uart-pl011
 92:    9308589          0          0          0  ARMCTRL-level  94 Edge      mmc1
FIQ:              usb_fiq
IPI0:          0          0          0          0  CPU wakeup interrupts
IPI1:          0          0          0          0  Timer broadcast interrupts
IPI2:    1160150    6582642    1541946    1893722  Rescheduling interrupts
IPI3:          3          5          8          8  Function call interrupts
IPI4:        114         91         79         97  Single function call interrupts
IPI5:          0          0          0          0  CPU stop interrupts
IPI6:          0          0          0          0  IRQ work interrupts
IPI7:          0          0          0          0  completion interrupts
Err:          0

 

참고