读取具有中断属性的设备树节点

Ami*_*mar 3 powerpc linux-device-driver linux-kernel device-tree

我有两个不同的设备树源的片段.

UART1: serial@ef600400 {
              device_type = "serial";
              compatible = "ns16550";
              reg = <0xef600400 8>;
              virtual-reg = <0xef600400>;
              clock-frequency = <0x00a8c000>;
              current-speed = <0>;
              interrupt-parent = <&UIC0>;
              interrupts = <1 4>;
                    };


serial0: serial@4500 {
                    cell-index = <0>;
                    device_type = "serial";
                    compatible = "ns16550";
                    reg = <0x4500 0x100>;
                    clock-frequency = <0>;
                    interrupts = <42 2>;
                    interrupt-parent = <&mpic>;
            };
Run Code Online (Sandbox Code Playgroud)

我想知道什么是中断= <1 4>; 中断= <42 2>; 代表?

我们从哪里得到<1 4>,<42 2>的值?

Jer*_*err 8

您需要更多上下文来确定这些interrupts属性所代表的内容.采取类似于你的第一个例子的东西,让我们来看看arch/powerpc/boot/dts/bamboo.dts,其中包含以下内容:

        UART1: serial@ef600400 {
            device_type = "serial";
            compatible = "ns16550";
            reg = <0xef600400 0x00000008>;
            virtual-reg = <0xef600400>;
            clock-frequency = <0>;
            current-speed = <0>;
            interrupt-parent = <&UIC0>;
            interrupts = <0x1 0x4>;
        };
Run Code Online (Sandbox Code Playgroud)

interrupts属性描述了从此设备到中断控制器的连接.假设控制器有多个输入(即中断线),我们需要找出该设备将与哪个线路进行交互.

不同的控制器可能具有不同的解复用其IRQ的方法,因此属性类型的变化.在这种情况下,让我们看一下中断控制器.我们看到该serial@ef600400节点具有以下属性:

            interrupt-parent = <&UIC0>;
Run Code Online (Sandbox Code Playgroud)

&UIC0语法告诉我们,有一个能通过UiC0标签在设备树的其他地方.那是我们的中断控制器.如果我们找到该标签,我们会看到:

UIC0: interrupt-controller0 {
    compatible = "ibm,uic-440ep","ibm,uic";
    interrupt-controller;
    cell-index = <0>;
    dcr-reg = <0x0c0 0x009>;
    #address-cells = <0>;
    #size-cells = <0>;
    #interrupt-cells = <2>;
};
Run Code Online (Sandbox Code Playgroud)

首先,我们看到它#interrupt-cells是2 - 这意味着每个中断描述符占用两个单元.由于串行设备的interrupt属性有两个单元(0x1和0x4),这告诉我们正在描述一个中断线.

compatible属性告诉我们这是一个IBM UIC中断控制器.如果我们看看这个控制器的驱动程序,我们会看到:

static struct irq_domain_ops uic_host_ops = {
    .map    = uic_host_map,
    .xlate  = irq_domain_xlate_twocell,
};
Run Code Online (Sandbox Code Playgroud)

xlate函数用于将中断源的interrupts属性映射到硬件IRQ编号(可能还有其IRQ类型).该irq_domain_xlate_twocell功能非常简单:

int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
            const u32 *intspec, unsigned int intsize,
            irq_hw_number_t *out_hwirq, unsigned int *out_type)
{
    if (WARN_ON(intsize < 2))
        return -EINVAL;
    *out_hwirq = intspec[0];
    *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

所以(和Peter L在他的评论中提到的),在这种情况下,两个单元<0x1 0x4>代表中断线1,以及一个高电平(0x4 == IRQ_TYPE_LEVEL_HIGH)中断类型.

你的第二个例子有点复杂:它使用一个mpic中断控制器,它有自己的xlate功能.看一看mpic_host_xlatearch/powerpc/sysdev/mpic.c为内部细节.