The Linux device tree in my eyes (four interrupts)

Source: Internet
Author: User

Four interrupts

Interrupts typically include interrupt-generation equipment and interrupt-handling equipment. Interrupt Controller is responsible for processing interrupts, each of which has a corresponding interrupt number and trigger conditions. The interrupt generation device may have multiple interrupt sources, and sometimes multiple interrupt sources correspond to an interrupt in the interrupt controller, which interrupts the interrupt source of the device, which is called the interrupt controller. The general situation interrupts the number of devices more than the interrupt controller, multiple interrupt generation device interrupts are handled by an interrupt controller, this many-to-one relationship is also very similar to a tree structure, so in the device tree, the interrupt is also described as a tree, called the interrupt tree. The following statement in order to clearly say that the interrupt tree, in front of the parent node and the child node we all add the word "break", is to prevent and the device tree parent node, child node confusion (although most of the time the parent-child relationship of the device tree is the parent-child relationship of the interrupt tree, but because there are special cases, so we )。

Interrupt generation devices use the interrupts attribute to describe the interrupt source (interrupt specifier) because different hardware describes the amount of data required for the interrupt source, so the type of the interrupts attribute is also <prop-encoded-array >. To make it clear that an interrupt is represented by several u32, and the #interrupt-cells attribute is introduced, the type of the-cells property is U32, and if an interrupt source requires 2 u32 representations (one representing the interrupt number and the other for the interrupt type), then # The Interrupt-cells is set to 2. In some cases, the parent node of the device tree is not the parent of the interrupt (mostly the interrupt controller is not the parent node), and the Interrupt-parent property is introduced for this purpose, and the type of the property is <phandle&gt, which is used to refer to the Interrupt parent node (as we said earlier, The label of the parent node is generally used, and this place says there is a reason to break the parent node instead of the interrupt controller. If the parent node of the device tree is the interrupt parent, you do not have to set the Interrupt-parent property. Both the interrupts property and the Interrupt-parent property are interrupts that produce the properties of the device node, but the #interrupt-cells property is not, #interrupt the-cells property is the interrupt Controller node and the interrupt The properties of the Nexus node, both of which are likely to break the parent node.

The Interrupt Controller node uses the Interrupt-controller property to indicate that it is an interrupt controller, that the type of this property is empty, without setting a value, as long as the node is present that the node is an interrupt controller. In addition to this attribute, the interrupt Controller node also has the #interrupt-cells attribute, which is used to indicate that the interrupt controller is managed directly under interrupt domain (we will talk about interrupt sub-nodes in the interrupts controller interrupt The Nexus node has a separate interrupt domain) that represents an interrupt source (interrupt specifier) with several u32. The interrupt Controller node includes Interrupt-controller and #interrupt-cells two properties on interrupts. The #address-cells property of the interrupt controller is related to the interrupt mapping, but the attribute is not designed for interrupts, and the interrupt mapping only uses this property.

The front says that an interrupt in the interrupt controller may correspond to interrupts that result in multiple interrupt sources in the device, what is the description of the corresponding relationship? We also said that the #interrupt-celll property is not only the attribute of the interrupt Controller node, but also the interrupt Nexus node, which is the interrupt Nexus node that describes the interrupt mapping relationship, which is through Interrupt-map, The Interrupt-map-mask property describes the interrupt mapping relationship. The Interrupt-map property is of type <prop-encoded-array>, and each element represents an interrupt mapping relationship (note is an "interrupt mapping relationship", not an "interrupt" mapping relationship), formerly backwards including: Interrupt sub-device address, Interrupts the child device interrupt source (interrupt specifier), interrupts the parent device, interrupts the parent device address, interrupts the parent device interrupt source (interrupt specifier) five part. The interrupt sub-device address is made up of several u32 that are determined by the #address-cells property of the bus where the interrupt sub-device is located, not the parent device, and why this place interrupts the device address without interrupting the phandle of the device, for a reason, Because the interrupt device uses the Interrupt-parrent attribute to point to the Interrupt parent node, the interrupt sub-device is deterministic and does not need to be described. Also because the interrupt sub-device address can be done and operations, through the Interrupt-map-mask property can be implemented to achieve a many-to-one mapping. The interrupt sub-device interrupt source (interrupt specifier) consists of several u32 that are determined by #interrupt-cell under the Interrupt Nexus node. The interrupt parent device is a <phandle> property that points to the interrupt parent device, typically an interrupt controller, but according to the logic of the interrupt tree, it may also be a higher-level interrupt Nexus node. The interrupt parent device address consists of several u32 that are determined by the #address-cells property under the Interrupt Parent device node (note that the #address-cells attribute is not interrupted on the bus where the parent device is located). Breaking the parent device interrupt source (interrupt specifier) consists of several u32 that are determined by the #interrupt-cells attribute that interrupts the parent device.

Remember that the interrupt source of the interrupt device and the interrupt controller may be a many-to-one relationship, and if each sub-interrupt is represented by a line in Interrupt-map, then the Interrupt-map property will be very large. In order to allow multiple sub-interrupts to share the mapping relationship, the Interrupt-map-mask attribute is introduced, and the type of the property is <prop-enacoded-array> a bit mask with interrupt sub-device address and interrupt source, given a sub-interrupt source , then first and interrupt-map-mask to do with the operation, the results of the operation again through the Interrupt-map property to find the corresponding interrupt parent device interrupt source. That's why we said the front line of the Interrupt-map property is a "break mapping relationship", not the reason for the "one break" mapping relationship.

Let's go over it again, the bottom of the entire interrupt tree is the interrupt generation device (also possibly from the interrupt Nexus node), and the interrupt generation device describes the interrupts he can generate with the interrupts attribute. Because his interrupt parent device may be different from the parent device of the device tree, use the interrupt-parent attribute to point to his interrupt parent device. His interruption to the parent device may be an interrupt controller (if interrupts are generated for the device and interrupts for the interrupt controller are one by one corresponding, or the bottom is the interrupt Nexus node), or the Interrupt Nexus node (if the bottom is interrupt-generating devices and need to be mapped). The interrupt Nexus node and all of his direct child nodes constitute a interrupt domain, in which case the interrupt source is represented by the #interrupt-cells attribute, as determined in the interrupt domain. How to find interrupts by interrupting a sub-device interrupt source The parent device interrupt source is determined by the Interrupt-map and Interrupt-map-mask properties. The parent node of the interrupt Nexus may also be a interrupt Nexus parent node or an interrupt controller, and when the last interrupt controller is found, and the interrupt controller no longer interrupts the parent device, the entire interrupt tree is traversed. The interrupt controller uses the Interrupt-controller property to indicate that it is an interrupt controller, and uses the #interrupt-cells attribute to indicate that interrupt domain he is directly managing uses several u32 to represent an interrupt source. Depending on the nature of the interrupt tree, there may be multiple interrupt trees in a device tree.

The above is the rule that interrupts how to describe in the device tree, sounds quite complicated, but as long as it is understood it is very simple, in order to help understand we give a practical example. In order to highlight the interrupt section, we made a simplification.
/ {
Model = "Marvell Armada 375 family SoC";
compatible = "marvell,armada375";
Soc {
#address-cells = <2>;
#size-cells = <1>;
Interrupt-parent = <&gic>;

Internal-regs {
compatible = "Simple-bus";
#address-cells = <1>;
#size-cells = <1>;

[Email protected] {
compatible = "Arm,cortex-a9-twd-timer";
Reg = <0xc600 0x20>;
Interrupts = <gic_ppi (irq_type_edge_rising | Gic_cpu_mask_simple (2)) >;
Clocks = <&coreclk 2>;
};

GIC: [email protected]0 {
compatible = "Arm,cortex-a9-gic";
#interrupt-cells = <3>;
#address-cells = <0>;
Interrupt-controller;
reg = <0xd000 0x1000>
<0xc100 0x100>;
};
}

Pcie-controller {
compatible = "Marvell,armada-370-pcie";
#address-cells = <3>;
#size-cells = <2>;

[Email protected],0 {
#address-cells = <3>;
#size-cells = <2>;
#interrupt-cells = <1>;
Interrupt-map-mask = <0 0 0 0>;
Interrupt-map = <0 0 0 0 &gic gic_spi irq_type_level_high>;
};
};
}

First we see [email protected] This device node defines the interrupts attribute, which means that the device can produce interrupts, but this property describes a few interrupts we can't see (if we have experience, we can guess just an interrupt, now we follow the rules to confirm )。 Because the node does not have a interrupt-parent attribute, it is assumed that the parent node of the device tree is internal-regs the parent node, and that there is no interrupt-parent attribute under the Internal-regs parent node. Then continue to find the device tree parent node, found the SOC, below the node has the Interrupt-parent property. This property refers to the label GIC, which searches the entire device tree, and the [email protected] label is GIC. The GIC node has the Interrupt-controller attribute, which indicates that he is an interrupt controller. The GIC node also has properties #interrupt-cells = <3&gt, which indicates that the interrupt source (interrupt specifier) is represented by 3 u32 in the interrupt domain of the controller, and we look at the [email The interrupts property under protected] is also really composed of 3 u32 (you can refer to the GIC specification, the first u32 represents the break type, the second is the interrupt number, and the third is the interrupt trigger condition). This example shows that if the interrupt generation device interrupts the source and interrupt Controller's interrupt source is one by one corresponding, then you can not need to interrupt Nexus node and related attributes to represent the interrupt mapping.

Look again [email protected],0 This node, there are #interrupt-cells properties, but there is no Interrupt-controller attribute, which indicates that he is a interrupt Nexus node. The #interrupt-cells property of the node is 1, indicating that the interrupt source under the interrupt Nexus node is represented by 1 u32. In the [email protected],0 node There is no child node, and there is no node interrupt-parent attribute pointing to the [email protected],0 node, so the interrupt is not visible from the device tree Interrupt generation devices under domain may be due to the fact that the device software can be dynamically identified by these interrupts, so no device tree description is required. Because the Interrupt-map-mask property consists of an interrupt-generating device's address and interrupt source (interrupt specifier), and the interrupt source is represented by 1 u32, it is assumed that the interrupt-generating device address consists of 3 u32. Note here is [email protected],0 node #address-cells attribute is 3, is said that the device address below the bus is represented by 3 u32, but does not mean the device address of the interrupt generation device is also a certain 3 U32 said, here can not be said to be a coincidence, But let's be clear that the address of the interrupt generation device consists of several u32, which is determined by the bus on which the device is located, and indeed 3 for the PCIe bus, but other buses may have other kinds of situations. Now let's analyze the Interrupt-map property, the first three digits are the interrupt device address, and the fourth number is the interrupt source of the interrupt device. Because Interrupt-map-mask is all 0, so no matter with what number do and the result of the operation is the 0,interrupt-map attribute of the first 4 numbers are also 0, which means in [email protected], 0 below all interrupts mapped to interrupts on the parent node are an interrupt. Next is the <phandle&gt that points to GIC, because the #address-cells property under the GIC node is 0, so there is no need to describe the address of the interrupt parent device behind, and the 3 digits behind will interrupt the parent device interrupt source. One sentence description is [email protected],0 all interrupts are mapped to the GIC,GIC_SPI type 29th interrupt, the trigger type is high-level trigger. This example shows that the bottom of the interrupt tree can be the interrupt Nexus node.

The above example interrupts the root of the tree is gic,gic below there are two children, one is the interrupt device [email protected], one is interrupt Nexus node [email protected],0. GIC directly governs the interrupt domain with 3 u32 to represent the interrupt source, [email protected] under this interrupt domain. [Email protected],0 defined a new interrupt domain, under the interrupt domain, the interrupt source with 1 U32 said, [email protected], 0 Use the Interrupt-map and Interrupt-map-mask attributes to map interrupts for all devices below to a single interrupt below the GIC.

The Linux device tree in my eyes (four interrupts)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.