当前位置:网站首页>[21 days learning challenge - kernel notes] (2), based in the device tree
[21 days learning challenge - kernel notes] (2), based in the device tree
2022-08-04 20:57:00 【light chases rain】
活动地址:CSDN21天学习挑战赛
学习的最大理由是想摆脱平庸,早一天就多一份人生的精彩;迟一天就多一天平庸的困扰.各位小伙伴,如果您:
想系统/深入学习某技术知识点…
一个人摸索学习很难坚持,想组团高效学习…
想写博客但无从下手,急需写作干货注入能量…
热爱写作,愿意让自己成为更好的人…
(This page was previously located at http://devicetree.org/Device_Tree_Usage)
This page describes how to write device tree for new machines.It aims to provide overview of the concept of device tree and how they are used to describe the machine.
有关设备树数据格式的完整技术描述,请参阅 ePAPR v1.1规范.ePAPR Specification includes more detail than this page covers the basic theme of the,Please refer to this page does not cover more advanced usage. ePAPR Currently updating to Devicetree The new name for the canonical document.
内容
1 基本数据格式
2 基本概念
2.1 Sample machine
2.2 初始结构
2.3 中央处理器
2.4 节点名称
2.5 设备
2.6 了解 compatible 属性
3 How addressing works
3.1 CPU 寻址
3.2 内存映射设备
3.3 非内存映射设备
3.4 范围(地址转换)
4 中断如何工作
5 设备特定数据
6 特殊节点
6.1 别名节点
6.2 选择的节点
7 高级主题
7.1 Advanced sample machine
7.2 PCI host bridge
7.2.1 PCI 总线编号
7.2.2 PCI 地址转换
7.2.3 PCI DMA 地址转换
7.3 Advanced interrupt mapping
8 笔记
基本数据格式
The device tree is a simple tree structure nodes and attributes.属性是键值对,Nodes may also contain properties and child nodes.例如,以下是.dtsA simple tree in the format:
/dts-v1/;
/ {
node1 {
a-string-property = "A string";
a-string-list-property = "first string", "second string";
// hex is implied in byte arrays. no '0x' prefix is required
a-byte-data-property = [01 23 34 56];
child-node1 {
first-child-property;
second-child-property = <1>;
a-string-property = "Hello, world";
};
child-node2 {
};
};
node2 {
an-empty-property;
a-cell-property = <1 2 3 4>; /* each number (cell) is a uint32 */
child-node1 {
};
};
};
The tree is clearly useless,Because it does not describe any thing,But it really shows the structure of the nodes and attributes.有:
a single root node:“ /”
several child nodes:“ node1”和“ node2”
node1 several children:“ child-node1”和“ child-node2”
A pile of spreading properties in the tree.
Properties are simple key-value pairs,The value can be null or contain any byte stream.Although data types not encoded into a data structure,But there are some basic data representation may be expressed in the device tree in the source file.
文本字符串(以空结尾)用双引号表示:
string-property = “a string”;
‘Cells’ are delimited by angle brackets 32 位无符号整数:
cell-property = <0xbeef 123 0xabcd1234>;
Binary data in square brackets separated:
binary-property = [0x01 0x23 0x45 0x67];
Different representation of the data can use commas together:
mixed-property = “a string”, [0x01 0x23 0x45 0x67], <0x12345678>;
Commas are used to create a string list:
string-list = “red fish”, “blue fish”;
基本概念
To understand how to use the device tree is,We'll start with a simple machine,And establish a device tree to describe it.
Sample machine
考虑以下由“Acme”Made and named“Coyote’s Revenge”imaginary machine(大致基于 ARM Versatile):
1 个 32 位 ARM CPU
Processor local bus is connected to the memory mapping serial port、spi 总线控制器、i2c 控制器、中断控制器和外部总线桥
基于 0 的 256MB SDRAM
2 个基于 0x101F1000 和 0x101F2000 的串行端口
基于 0x101F3000 的 GPIO 控制器
基于 0x10170000 的 SPI 控制器,Has the following equipment
带有 SS 引脚的 MMC 插槽连接到 GPIO #1
Has the following equipment external total line bridge adapter
SMC SMC91111 Ethernet device connected to the based on 0x10100000 the external bus
i2c 控制器基于 0x10160000 and the following devices
Maxim DS1338 实时时钟.Response slave address 1101000 (0x58)
基于 0x30000000 的 64MB NOR 闪存
初始结构
The first step is for laying machine skeleton structure.This is the minimum needed for effective device tree structure.在这个阶段,You want to uniquely identify the machine.
/dts-v1/;
/ {
compatible = "acme,coyotes-revenge";
};
compatibleSpecifies the name of the system.It contains the format “, 的字符串.Specify the exact and contain equipment manufacturer name is very important to avoid namespace conflicts.Because the operating system will use thecompatible值来决定如何在机器上运行,Put the correct data in this property is very important.
从理论上讲,Compatibility is the only operating system identification machine all the necessary data.If all the machine details are hard coded,The operating system can be in the topcompatibleSpecifically looking for properties“acme,coyotes-revenge”.
中央处理器
The next step is to describe each CPU.添加一个名为“cpus”的容器节点,每个 CPU has a child node.在这种情况下,系统是 ARM 的双核 Cortex A9 系统.
/dts-v1/;
/ {
compatible = "acme,coyotes-revenge";
cpus {
[email protected]0 {
compatible = "arm,cortex-a9";
};
[email protected]1 {
compatible = "arm,cortex-a9";
};
};
};
每个 cpu 节点中的 compatible 属性是一个字符串,它以 The form specifies the exact cpu 模型,,like the top one compatible 属性一样.
稍后会为cpu节点添加更多属性,But we first need to talk about the basic concept of more.
节点名称
Is worth to spend bit of time to talk about naming convention.Each node must have a format for[@] 的名称.
是一个简单的 ascii 字符串,最长可达 31 个字符.一般来说,Node is according to the names of the device type that it represents.IE.3com Ethernet adapter node will use the nameethernet,而不是3com509.
If the node describes the address of the equipment,then includes the unit address.通常,Unit address is used to access the device's main,juxtaposed at the nodereg属性中.We will be introduced later in this document reg 属性.
Brother nodes must be the only name,But as long as the addresses are different(即,[email protected] & [email protected]),Multiple nodes using the same generic names are normal.
Complete detailed information about the node named,请参阅 ePAPR 规范的第 2.2.1 节.
设备
系统中的每个设备都由一个设备树节点表示.The next step is to use each device node fill the tree.目前,New nodes will remain blank,直到我们可以讨论如何处理地址范围和 irq.
/dts-v1/;
/ {
compatible = "acme,coyotes-revenge";
cpus {
[email protected]0 {
compatible = "arm,cortex-a9";
};
[email protected]1 {
compatible = "arm,cortex-a9";
};
};
[email protected]101F0000 {
compatible = "arm,pl011";
};
[email protected]101F2000 {
compatible = "arm,pl011";
};
[email protected]101F3000 {
compatible = "arm,pl061";
};
interrupt-[email protected]10140000 {
compatible = "arm,pl190";
};
[email protected]10115000 {
compatible = "arm,pl022";
};
external-bus {
[email protected]0,0 {
compatible = "smc,smc91c111";
};
[email protected]1,0 {
compatible = "acme,a1234-i2c-bus";
[email protected]58 {
compatible = "maxim,ds1338";
};
};
[email protected]2,0 {
compatible = "samsung,k8f1315ebm", "cfi-flash";
};
};
};
在这棵树中,For each device in the system adds a node,层次结构反映了设备如何连接到系统.IE.extern Of the devices on the bus is the child nodes of the external bus node,而 i2c 设备是 i2c 总线控制器节点的子节点.一般来说,Hierarchy represents from CPU Perspective view of the system.
The tree is invalid at this time.It lacks information about equipment connection between.This data will be added later.
Some matters need to pay attention to in the tree:
Each device node has acompatible属性.
flash 节点在 compatible 属性中有 2 个字符串.Please continue to read the next part of the in order to understand the reason.
如前所述,Node name reflects the type of equipment,rather than a specific model.请参阅 ePAPR 规范的第 2.2.2 节,Understand should as far as possible use of defined general node name list.
了解compatible属性
Every node tree said equipment must have thecompatible属性. compatibleWhich operating system is used to determine whether the device drivers are bound to the key.
compatible是一个字符串列表.In the form in the list of the first string specified node said the exact equipment",".The following string represents the device compatible with other devices.
例如,飞思卡尔 MPC8349 片上系统 (SoC) 有一个串行设备,可实现 National Semiconductor ns16550 寄存器接口.因此,MPC8349 串行设备的 compatible 属性应为:compatible = “fsl,mpc8349-uart”, “ns16550”. 在这种情况下,fsl,mpc8349-uartSpecify the exact device,并ns16550declare it with National Semiconductor 16550 UART register-level compatibility.
注意:ns16550A purely historical reasons no manufacturer prefixes.All new compatible values should prefix manufacturers.
This approach allows for the existing device driver is bound to the newer devices,At the same time still uniquely identify the exact hardware.
警告:Do not use wildcard compatible with the values of the,例如“fsl,mpc83xx-uart”或类似的值.Chip suppliers will always change,Break your wildcard assumptions,Once it's changed it's too late.相反,Choosing a specific silicon and silicon and it is compatible with all subsequent.
How addressing works
可寻址设备使用以下属性将地址信息编码到设备树中:
reg
#address-cells
#size-cells
Each addressable device has areg元组列表,格式为reg = <address1 length1 [address2 length2] [address3 length3] … >.每个元组代表设备使用的地址范围.Each address values are one or more 32 位整数的列表,称为单元格.同样,The length value can be a list of cell,也可以是空的.
由于地址和长度字段都是可变大小的变量,因此父节点中的#address-cells和#size-cellsProperty is used to illustrate how many of each field cell.或者换句话说,正确解释 reg 属性需要父节点的 #address-cells 和 #size-cells 值.要了解这一切是如何工作的,让我们将寻址属性添加到示例设备树中,从 CPU 开始.
CPU 寻址
When talking about addressing,CPU Nodes represent the simplest case.每个 CPU 都分配有一个唯一的 ID,and no with CPU id associated size.
cpus {
#address-cells = <1>;
#size-cells = <0>;
[email protected]0 {
compatible = "arm,cortex-a9";
reg = <0>;
};
[email protected]1 {
compatible = "arm,cortex-a9";
reg = <1>;
};
};
在cpus节点中,#address-cells设置为 1,#size-cells设置为 0.这意味着子reg值是单个 uint32,Said there was no size field address.在这种情况下,两个 cpu address is assigned 0 和 1. #size-cells对于 cpu Node is 0,因为每个 cpu Only one address is assigned.
You'll also notice thatregValues with the values in the node name matching.按照惯例,如果节点具有reg属性,The node name must contain the unit address,即regThe first address of attribute value.
内存映射设备
与在 cpu Nodes with different values found in a single address,The memory mapping equipment were given a series of address,它将响应. #size-cellsused to describe each subregThe size of the tuple length field.在下面的示例中,每个地址值是 1 个单元(32 位),So does each length value 1 个单元,这在 32 Typical on bit systems.64 Bit machines can be#address-cells 和#size-cells 使用值2 to get in the device tree64 位寻址.
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
...
[email protected]101f0000 {
compatible = "arm,pl011";
reg = <0x101f0000 0x1000 >;
};
[email protected]101f2000 {
compatible = "arm,pl011";
reg = <0x101f2000 0x1000 >;
};
gp[email protected]101f3000 {
compatible = "arm,pl061";
reg = <0x101f3000 0x1000
0x101f4000 0x0010>;
};
interrupt-[email protected]10140000 {
compatible = "arm,pl190";
reg = <0x10140000 0x1000 >;
};
[email protected]10115000 {
compatible = "arm,pl022";
reg = <0x10115000 0x1000 >;
};
...
};
Each device is assigned a base address,And the size of the area assigned to it.本例中的 GPIO The device address is assigned two address range;0x101f3000…0x101f3fff 和 0x101f4000…0x101f400f.
Some devices on the bus with different addressing schemes.例如,With discrete pieces of line selection devices can be connected to external bus.由于每个父节点都为其子节点定义了寻址域,So can choose address mapping to best describe the system.The code below shows the equipment connected to the external bus address assignment,Code number for the chip to the address.
external-bus {
#address-cells = <2>;
#size-cells = <1>;
[email protected]0,0 {
compatible = "smc,smc91c111";
reg = <0 0 0x1000>;
};
[email protected]1,0 {
compatible = "acme,a1234-i2c-bus";
reg = <1 0 0x1000>;
[email protected]58 {
compatible = "maxim,ds1338";
};
};
[email protected]2,0 {
compatible = "samsung,k8f1315ebm", "cfi-flash";
reg = <2 0 0x4000000>;
};
};
使用external-bus2 A cell as address values;One for the chip select number,One for the piece of selected base offset.The length of the field for a single cell,Because only address offset part of the need to have a range of.因此,在此示例中,每个reg条目包含 3 个单元格;Chip select number、偏移量和长度.
由于地址域包含在节点及其子节点中,So the parent node is free to define any meaningful addressing scheme for the bus.Outside the direct parent and child node usually don't have to care about local addressing domain,And must address mapping from one domain to another domain.
非内存映射设备
Other equipment not memory mapping on the processor bus.They can have address ranges,但 CPU They cannot be accessed directly.相反,Parent device driver will represent CPU 执行间接访问.
以 i2c 设备为例,Each device is assigned has an address,But not associated with length or range.这看起来与 CPU Address assignments are very similar.
[email protected]1,0 {
compatible = "acme,a1234-i2c-bus";
#address-cells = <1>;
#size-cells = <0>;
reg = <1 0 0x1000>;
[email protected]58 {
compatible = "maxim,ds1338";
reg = <58>;
};
};
范围(地址转换)
我们已经讨论了如何为设备分配地址,But now these addresses only the device node is local.It hasn't describe how from the address mapping to CPU 可以使用的地址.
The root node is always described CPU Views on the address space.The child nodes of the root is already in use CPU 的地址域,因此不需要任何显式映射.例如,[email protected] The device assigns the address directly 0x101f0000.
Is not the root of direct child nodes of node does not use CPU 的地址域.为了获得内存映射地址,设备树必须指定如何将地址从一个域转换到另一个域.该rangesThe property is used for this purpose.
This is to add the scope attribute of the sample device tree.
/dts-v1/;
/ {
compatible = "acme,coyotes-revenge";
#address-cells = <1>;
#size-cells = <1>;
...
external-bus {
#address-cells = <2>;
#size-cells = <1>;
ranges = <0 0 0x10100000 0x10000 // Chipselect 1, Ethernet
1 0 0x10160000 0x10000 // Chipselect 2, i2c controller
2 0 0x30000000 0x1000000>; // Chipselect 3, NOR Flash
[email protected]0,0 {
compatible = "smc,smc91c111";
reg = <0 0 0x1000>;
};
[email protected]1,0 {
compatible = "acme,a1234-i2c-bus";
#address-cells = <1>;
#size-cells = <0>;
reg = <1 0 0x1000>;
[email protected]58 {
compatible = "maxim,ds1338";
reg = <58>;
};
};
[email protected]2,0 {
compatible = "samsung,k8f1315ebm", "cfi-flash";
reg = <2 0 0x4000000>;
};
};
};
rangesis a list of address translations.Scope of each entry in the table are a tuple,It contains subaddresses、The parent address space in the area the size of the child and.The size of each field is determined by sub#address-cells值、父#address-cells值和子#size-cells值确定.对于我们示例中the external bus,The subaddress is 2 个单元,The parent address is 1 个单元,大小也是 1 个单元.Three ranges are being translated:
片选 0 的偏移量 0 Map to address range 0x10100000…0x1010ffff
片选 1 的偏移量 0 Map to address range 0x10160000…0x1016ffff
片选 2 的偏移量 0 Map to address range 0x30000000…0x30ffffff
或者,如果父地址空间和子地址空间相同,The node can add an emptyranges属性.The existence of empty range attributes means that the address in the address space is son 1:1 映射到父地址空间.
您可能会问,When address translation can be used 1:1 When mapping is written,Why use address translation.certain buses(如 PCI)具有完全不同的地址空间,The detailed information need to operating system.其他的有 DMA 引擎,Need to know the bus real address.Sometimes you need to equipment together,Because they all share the same software programmable physical address mapping.是否应该使用 1:1 Mapping depends largely on the information required to operating system and hardware design.
您还应该注意到 [email protected],0 节点中没有ranges属性.这样做的原因是,与外部总线不同,i2c Of the devices on the bus is not memory mapped to CPU on the address field.相反,CPU 通过 [email protected],0 设备间接访问 [email protected] 设备.缺少rangesAttribute means equipment cannot be anything other than the parent equipment direct access to the.
中断如何工作
与遵循树的自然结构的地址范围转换不同,Interrupt signal can be derived from and end on any device in the machine.With natural expression in the device tree equipment addressing different,Interrupt signal to be expressed as independent of the links between the nodes of the tree.Four properties are used to describe interrupt connection:
interrupt-controller- The nodes statement for empty attributes of the device receives the interrupt signal
#interrupt-cells- 这是中断控制器节点的属性.It illustrates how many of the interruption of the interrupt controller specifiers units(类似于#address-cellsand #size-cells).
interrupt-parent- 设备节点的属性,Contains Pointers to the interrupt controller it connectionphandle .没有interrupt-parent Properties of nodes can also be inherited from its parent this property.
interrupts- It contains a list of interrupt specifiers device node properties,One for the equipment on each interrupt output signal.
Interrupt specifier is one or more data unit(由#interrupt-cells 指定),It specifies which interrupt input device is connected to the.Most devices only an interrupt output,如下例所示,But a device can have multiple interrupt output.Interrupt specifier depends entirely on the meaning of the interrupt controller device binding.Each interrupt controller can decide it need how many unit to uniquely define an interrupt input.
The following code will interrupt connection is added to our Coyote’s Revenge 示例机器:
/dts-v1/;
/ {
compatible = "acme,coyotes-revenge";
#address-cells = <1>;
#size-cells = <1>;
interrupt-parent = <&intc>;
cpus {
#address-cells = <1>;
#size-cells = <0>;
[email protected]0 {
compatible = "arm,cortex-a9";
reg = <0>;
};
[email protected]1 {
compatible = "arm,cortex-a9";
reg = <1>;
};
};
[email protected]101f0000 {
compatible = "arm,pl011";
reg = <0x101f0000 0x1000 >;
interrupts = < 1 0 >;
};
[email protected]101f2000 {
compatible = "arm,pl011";
reg = <0x101f2000 0x1000 >;
interrupts = < 2 0 >;
};
[email protected]101f3000 {
compatible = "arm,pl061";
reg = <0x101f3000 0x1000
0x101f4000 0x0010>;
interrupts = < 3 0 >;
};
intc: interrupt-[email protected]10140000 {
compatible = "arm,pl190";
reg = <0x10140000 0x1000 >;
interrupt-controller;
#interrupt-cells = <2>;
};
[email protected]10115000 {
compatible = "arm,pl022";
reg = <0x10115000 0x1000 >;
interrupts = < 4 0 >;
};
external-bus {
#address-cells = <2>;
#size-cells = <1>;
ranges = <0 0 0x10100000 0x10000 // Chipselect 1, Ethernet
1 0 0x10160000 0x10000 // Chipselect 2, i2c controller
2 0 0x30000000 0x1000000>; // Chipselect 3, NOR Flash
[email protected]0,0 {
compatible = "smc,smc91c111";
reg = <0 0 0x1000>;
interrupts = < 5 2 >;
};
[email protected]1,0 {
compatible = "acme,a1234-i2c-bus";
#address-cells = <1>;
#size-cells = <0>;
reg = <1 0 0x1000>;
interrupts = < 6 2 >;
[email protected]58 {
compatible = "maxim,ds1338";
reg = <58>;
interrupts = < 7 3 >;
};
};
[email protected]2,0 {
compatible = "samsung,k8f1315ebm", "cfi-flash";
reg = <2 0 0x4000000>;
};
};
};
需要注意的一些事项:
The machine has an interrupt controller,[email protected]
标签“intc:”Have been added to the interrupt controller node,And this tag is used to put phandle assigned to the root node interrupt-parent 属性.这个 interrupt-parent The value becomes the default value of the system,Because all child nodes will inherit it,unless it is explicitly overridden.
Each device using an interrupt attribute to specify different interrupt input line.
#interrupt-cells 为 2,Therefore each interrupt descriptor has 2 个单元.This example uses common patterns,Use the first unit to encode interrupt line number,Using the second unit to encode sign,For example, high effective and low level effective,or edge and level sensitive.For any given interrupt controller,Please refer to the controller of the binding documents in order to understand how specifier code.
设备特定数据
Except for generic properties,Can also be arbitrary properties and child nodes are added to the node.Just follow some rules,Operating systems need any data can add.
首先,New device-specific attribute name prefix should use manufacturers,So they don't conflict with the existing standard attribute name.
其次,Must be recorded in the binding properties and child nodes meaning,So that the device driver author knows how to interpret data.The meaning of compatible binding document the specific value、properties it should have、It may have child nodes, and it represents the equipment.每个唯一compatibleValue should have their own binding(Compatible with another value or statement of compatibility).此 wiki Recorded the binding of the new equipment.The description of the relevant document format and review process,See home page.
第三,在 [email protected] Mailing list released new binding for review.Review new binding will find many common mistakes,These errors will cause problems in the future.
特殊节点
aliases节点
Specific nodes usually by the full path to the reference,例如/external-bus/[email protected],0,But when the user really want to know is“which device is eth0?”时,This can get cumbersome.该aliasesNodes can be used to assign short aliases complete device path.例如:
aliases {
ethernet0 = ð0;
serial0 = &serial0;
};
Welcome to the operating system at the time of equipment allocation identifier using alias.
You'll notice here USES a new grammar.A full node of the syntax to label reference path allocation for string property.This is the same as the one used before phandle Values into the cell in the form of different. property = &label;phandle = < &label >;
chosen节点
该chosenNode does not represent the real equipment,But used to transfer data between the firmware and the operating system of the local,例如启动参数.Data from the selected node does not represent the hardware.通常,The selected node is in .dts The source file is empty,and populate it at boot.
in our example system,The firmware may add the following to the selected node:
chosen {
bootargs = "root=/dev/nfs rw nfsroot=192.168.1.1 console=ttyS0,115200";
};
高级主题
Advanced sample machine
Now we have defined the basic knowledge of,Let's add some hardware to the sample machine to discuss some of the more complicated cases.
Senior added a sample machine PCI host bridge,The control register memory mapped to 0x10180000,并且 BAR is programmed as a slave address 0x80000000 以上开始.
Since we already know about device tree,We can start with add the following node to describe PCI host bridge.
[email protected]10180000 {
compatible = "arm,versatile-pci-hostbridge", "pci";
reg = <0x10180000 0x1000>;
interrupts = <8 0>;
};
PCI host bridge
This section describes hosts/PCI 桥节点.
请注意,This section assumes that PCI 的一些基本知识.这不是关于 PCI 的教程,If you need further information,请阅读[1].您还可以参考 ePAPR v1.1 或PCI Bus Binding to Open Firmware.Can be found in the freescale MPC5200 的完整工作示例.
PCI 总线编号
每个 PCI The serial number of bus segment has only,bus number by using thisbus-range属性在 pci public in the node,This property contains two cell.The first unit assigned to the given node number of the bus,The second unit given any affiliate PCI The maximum bus number of the bus.
The example machine has one pci 总线,So both cells are 0.
[email protected]0x10180000 {
compatible = "arm,versatile-pci-hostbridge", "pci";
reg = <0x10180000 0x1000>;
interrupts = <8 0>;
bus-range = <0 0>;
};
如您所见,子地址(PCI 地址)使用 3 个单元格,而 PCI Ranges are encoded as 2 个单元格.第一个问题可能是,为什么我们需要三个 32 specified in bit units PCI 地址.These three cells are labeled phys.hi、phys.mid 和 phys.low [2].
phys.hi cell: npt000ss bbbbbbbb dddddfff rrrrrrrr
phys.mid cell: hhhhhhhh hhhhhhhh hhhhhhhh hhhhhhhh
phys.low cell: llllllll llllllll llllllll llllllll
PCI 地址为 64 位宽,编码为 phys.mid 和 phys.low.然而,The really interesting stuff is there phys.high 中,This is a bit field:
n: Relocatable region flags(在这里不起作用)
p: Prefetchable(可缓存)区域标志
t: Alias address flag(在这里不起作用)
ss: 空间代码
00:配置空间
01:I/O 空间
10:32位内存空间
11:64位内存空间
bbbbbbbb: PCI 总线编号.PCI Can be hierarchical.So we may have defined child bus PCI/PCI 桥.
ddddd:设备编号,通常与 IDSEL Signal connection related.
fff:功能编号.for multifunction PCI 设备.
rrrrrrrr: 注册号码; Used to configure the cycle.
就 PCI address translation,The important fields arep和ss.phys.hi 中 p 和 ss The values of the decision is on a visit to the PCI 地址空间.因此,Check out our range properties,We have three areas:
一个 32 Bit prefetchable memory region,从 PCI 地址 0x80000000 开始,大小为 512 MB,will be mapped to the host CPU 上的地址 0x80000000.
一个 32 An prefetching area of memory,从 PCI 地址 0xa0000000 开始,大小为 256 MB,will be mapped to the host CPU 上的地址 0xa0000000.
一个 I/O 区域,从 PCI 地址 0x00000000 开始,大小为 16 MB,will be mapped to the host CPU 上的地址 0xb0000000.
In order to make the work more into,phys.hi The existence of a domain means that the operating system needs to know nodes represent PCI 桥,So that it can ignore unrelated fields to translate.操作系统将在 PCI Bus nodes in the search string“pci”To determine whether it is need extra field shielding.
PCI DMA 地址转换
The above range is defined CPU 如何看待 PCI 内存,并帮助 CPU Set the correct memory window and writing correct parameters in various PCI 设备寄存器.This is sometimes called outbound memory.
A special case involving address translation PCI The core of the host hardware how system memory.当 PCI The host controller ACTS as a main controller and the core of independent access system memory,就会发生这种情况.Since this is usually associated with CPU 的视图不同(As a result of the memory line wiring way),So may need to initialize its programming to PCI in the host controller.This is seen as one DMA,因为 PCI Bus independently execute direct memory access,Hence the mapping is nameddma-ranges.This type of memory mapping are sometimes referred to as the inbound memory,它不是 PCI Part of the device tree specification.
在某些情况下,ROM (BIOS) Or similar equipment will set these registers at startup,但在其他情况下,PCI The controller is completely uninitialized,Need to set the conversion from the tree of equipment.然后,PCI The host driver usually resolve dma-ranges Properties and set some registers in the host controller accordingly.
扩展上面的例子:
[email protected]0x10180000 {
compatible = "arm,versatile-pci-hostbridge", "pci";
reg = <0x10180000 0x1000>;
interrupts = <8 0>;
bus-range = <0 0>;
#address-cells = <3>
#size-cells = <2>;
ranges = <0x42000000 0 0x80000000 0x80000000 0 0x20000000
0x02000000 0 0xa0000000 0xa0000000 0 0x10000000
0x01000000 0 0x00000000 0xb0000000 0 0x01000000
dma-ranges = <0x02000000 0 0x00000000 0x80000000 0 0x20000000>;
};
这个dma-rangesentry indicates,从 PCI The host controller's point of view,PCI 地址0x00000000的512 MBwill appear in the address0x80000000in the main core memory.如您所见,我们只是将ssThe address type is set to 0x02,Indicates that this is some 32 位内存.
Advanced interrupt mapping
Now we come to the most interesting part of the,PCI 中断映射.PCI 设备可以使用#INTA、#INTB、#INTC 和#INTD line trigger interrupt.before the break name#Well, said it is a low level and effective,This is a common convention,PCI Interrupt line is always low level effective.Single-function devices must be used#INTA 进行中断.If the multifunction devices using a single interrupt pin,则必须使用#INTA,If you use two interrupt pin,则必须使用#INTA 和#INTB 等.由于这些规则,#INTA Usually used for ratio#INTB、#INTC More features and #INTD.为了在支持#INTA 到#INTD 的四个IRQ Distribute the load on the line,每个PCI Slot or equipment is usually connected to the interrupt controller in rotating way different input,以避免所有#INTA The client connect to the same incoming interrupt line.Transfer interrupted.因此,Device tree needs a will each PCI Interrupt signal is mapped to the interrupt controller input method.、#interrupt-cells和interrupt-map属性interrupt-map-maskUsed to describe interrupt mapping.
实际上,Interrupt mapping, as described here, is not limited to PCI 总线,Any node can specify complex interrupt map,但 PCI The situation is by far the most common.
[email protected]0x10180000 {
compatible = "arm,versatile-pci-hostbridge", "pci";
reg = <0x10180000 0x1000>;
interrupts = <8 0>;
bus-range = <0 0>;
#address-cells = <3>
#size-cells = <2>;
ranges = <0x42000000 0 0x80000000 0x80000000 0 0x20000000
0x02000000 0 0xa0000000 0xa0000000 0 0x10000000
0x01000000 0 0x00000000 0xb0000000 0 0x01000000>;
#interrupt-cells = <1>;
interrupt-map-mask = <0xf800 0 0 7>;
interrupt-map = <0xc000 0 0 1 &intc 9 3 // 1st slot
0xc000 0 0 2 &intc 10 3
0xc000 0 0 3 &intc 11 3
0xc000 0 0 4 &intc 12 3
0xc800 0 0 1 &intc 10 3 // 2nd slot
0xc800 0 0 2 &intc 11 3
0xc800 0 0 3 &intc 12 3
0xc800 0 0 4 &intc 9 3>;
};
首先,您会注意到 PCI Interrupt number using only one unit,与使用 2 A unit system interrupt controller is different;One for the interrupt number,one for the logo.PCI Only need one unit for interrupt,因为 PCI Interrupts are specified as always sensitive to low level.
in our example board,我们有 2 个 PCI 插槽,分别有 4 条中断线,因此我们必须将 8 A break in the mapping to the interrupt controller.This is the use of interrupt mapping attributes to complete.[3]Describe the interrupt the exact process map.
because of the interrupt number(#INTA 等)Not enough to distinguish a single one PCI 总线上的多个 PCI 设备,We also have to point out which PCI The device triggered the interrupt line.幸运的是,每个 PCI Equipment is the only one we can use equipment serial number.To distinguish between several PCI 设备的中断,We need a by PCI 设备号和 PCI A tuple of interrupt numbers.更一般地说,We constructed a unit interrupt specifiers,It has four units:
由phys.hi 、 phys.mid、phys.low 和
一个#interrupt-cell(#INTA、#INTB、#INTC、#INTD).
因为我们只需要 PCI The device number portion of the address,interrupt-map-mask 属性就派上用场了.interrupt-map-mask 也是一个 4 元组,Like unit interrupt specifiers.掩码中的 1 Which part of said unit should be considered the interrupt specifiers.在我们的示例中,We can see only need phys.hi part of the device number,并且我们需要 3 Distinguish between four break line(计数 PCI interrupt line from 1 开始,而不是从 0 开始!).
Now we can construct the interrupt mapping attribute.The property is a table,Each entry in the table by a child(PCI 总线)Unit break specifier、A parent handle(Responsible for the interruption service interrupt controller)And a parent unit interrupts, specifiers.So we can read in the first linePCI中断#INTA被映射到IRQ 9,We interrupt controller is sensitive to the low level of. [4].
The only missing part PCI Interrupt bus unit specifiers in odd Numbers.Unit is an important part of interrupt descriptor from phys.hi The device number of the bit field.Equipment number is specific to the board,It depends on each PCI On how the host controller to activate each device IDSEL 引脚.在此示例中,PCI 插槽 1 Equipment is assigned id 24 (0x18),PCI 插槽 2 Equipment is assigned id 25 (0x19).每个插槽的 phys.hi Value is through the equipment number moving up 11 bit-domain ddddd part to be determined,如下所示:
插槽 1 的 phys.hi 为 0xC000,并且
插槽 2 的 phys.hi 为 0xC800.
将它们放在一起,Interrupt map property display:
#INTA 的 slot 1 是 IRQ9,Sensitive to the interrupt controller low level
#INTB 的 slot 1 是 IRQ10,Sensitive to the interrupt controller low level
#slot 1的INTC是IRQ11,Sensitive to the interrupt controller low level
#INTD of slot 1 is IRQ12, level lowsensitive on the primary interrupt controller
和
#INTA of slot 2 is IRQ10, level lowsensitive on the primary interrupt controller
#INTB 的 slot 2 是 IRQ11,Sensitive to the interrupt controller low level
#INTC 的 slot 2 是 IRQ12,Sensitive to the interrupt controller low level
#INTD of slot 2 is IRQ9, level low sensitive on the primary interrupt controller
该interrupts = <8 0>;Properties describe the host/PCI Bridge may trigger the interrupt controller itself.Don't use these interrupts with PCI Equipment may trigger interrupt confused(使用 INTA、INTB、…).
One last thing to note.就像interrupt-parent 属性一样,节点上interrupt-map The existence of the property will change all the child nodes and node sun's default interrupt controller.在这个 PCI 示例中,这意味着 PCI The default host bridge interrupt controller.如果通过 PCI Bus connection device directly connected to another interrupt controller,So it also need to specify its own interrupt father properties.
边栏推荐
- About the state transfer problem of SAP e-commerce cloud Spartacus UI SSR
- QT(41)-多线程-QTThread-同步QSemaphore-互斥QMutex
- c语言小项目(三子棋游戏实现)
- MySQL字段类型
- 暴雨中的人
- 简单理解 JS 事件循环
- 深度解析:为什么跨链桥又双叒出事了?
- 零知识证明——zkSNARK证明体系
- Comic | Two weeks after the boss laid me off, he hired me back and doubled my salary!
- 2022-8-4 第七组 ptz 锁与线程池和工具类
猜你喜欢
QT(41)-多线程-QTThread-同步QSemaphore-互斥QMutex
[2022 Hangzhou Electric Power Multi-School 5 1012 Questions Buy Figurines] Application of STL
暴雨中的人
How to understand the crawler's Scrapy framework in the simplest and most popular way?
IPV6地址
【数据挖掘】搜狐公司数据挖掘工程师笔试题
动态数组底层是如何实现的
使用百度EasyDL实现森林火灾预警识别
CAS :80750-24-9(脱硫生物素 NHS 酯)
ADB 安装 + 打驱动全教程
随机推荐
二叉搜索树解决硬木问题
visual studio 2015 warning MSB3246
matlab 画图
idea2021版本添加上一步和下一步操作到工具栏
PowerCLi 批量配置NTP
明明加了唯一索引,为什么还是产生了重复数据?
【学术相关】清华教授发文劝退读博:我见过太多博士生精神崩溃、心态失衡、身体垮掉、一事无成!...
构建Buildroot根文件系统(I.MX6ULL)
Cryptography Series: PEM and PKCS7, PKCS8, PKCS12
1、File对象学习
顺序队列
【TypeScript】深入学习TypeScript枚举
[TypeScript] In-depth study of TypeScript enumeration
[Teach you to use the serial port idle interrupt of the STM32HAL library]
Nuxt.js的优缺点和注意事项
C语言之实现扫雷小游戏
【编程思想】
After encountering MapStruct, the conversion between PO, DTO and VO objects is no longer handwritten
3. Byte stream and character stream of IO stream
新式茶饮,卷完水果还能卷什么?