Documentation/translations/zh_CN/devicetree/usage-model.rst
Source file repositories/reference/linux-study-clean/Documentation/translations/zh_CN/devicetree/usage-model.rst
File Facts
- System
- Linux kernel
- Corpus path
Documentation/translations/zh_CN/devicetree/usage-model.rst- Extension
.rst- Size
- 17476 bytes
- Lines
- 331
- Domain
- Support Tooling And Documentation
- Bucket
- Documentation
- Inferred role
- Support Tooling And Documentation: documentation
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
function harmony_init_machine
Annotated Snippet
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/devicetree/usage-model.rst
:翻译:
司延腾 Yanteng Si <siyanteng@loongson.cn>
:校译:
===================
Linux 和 Devicetree
===================
Linux对设备树数据的使用模型
:作者: Grant Likely <grant.likely@secretlab.ca>
这篇文章描述了Linux如何使用设备树。关于设备树数据格式的概述可以在
devicetree.org\ [1]_ 的设备树使用页面上找到。
.. [1] https://www.devicetree.org/specifications/
"Open Firmware Device Tree",或简称为Devicetree(DT),是一种用于描述硬
件的数据结构和语言。更确切地说,它是一种操作系统可读的硬件描述,这样操作系统就不
需要对机器的细节进行硬编码。
从结构上看,DT是一棵树,或者说是带有命名节点的无环图,节点可以有任意数量的命名
属性来封装任意的数据。还存在一种机制,可以在自然的树状结构之外创建从一个节点到
另一个节点的任意链接。
从概念上讲,一套通用的使用惯例,称为 "bindings"(后文译为绑定),被定义为数据
应该如何出现在树中,以描述典型的硬件特性,包括数据总线、中断线、GPIO连接和外围
设备。
尽可能使用现有的绑定来描述硬件,以最大限度地利用现有的支持代码,但由于属性和节
点名称是简单的文本字符串,通过定义新的节点和属性来扩展现有的绑定或创建新的绑定
很容易。然而,要警惕的是,在创建一个新的绑定之前,最好先对已经存在的东西做一些
功课。目前有两种不同的、不兼容的i2c总线的绑定,这是因为在创建新的绑定时没有事先
调查i2c设备在现有系统中是如何被枚举的。
1. 历史
-------
DT最初是由Open Firmware创建的,作为将数据从Open Firmware传递给客户程序
(如传递给操作系统)的通信方法的一部分。操作系统使用设备树在运行时探测硬件的拓
扑结构,从而在没有硬编码信息的情况下支持大多数可用的硬件(假设所有设备的驱动程
序都可用)。
由于Open Firmware通常在PowerPC和SPARC平台上使用,长期以来,对这些架构的
Linux支持一直使用设备树。
2005年,当PowerPC Linux开始大规模清理并合并32位和64位支持时,决定在所有
Powerpc平台上要求DT支持,无论它们是否使用Open Firmware。为了做到这一点,
我们创建了一个叫做扁平化设备树(FDT)的DT表示法,它可以作为一个二进制的blob
传递给内核,而不需要真正的Open Firmware实现。U-Boot、kexec和其他引导程序
被修改,以支持传递设备树二进制(dtb)和在引导时修改dtb。DT也被添加到PowerPC
引导包装器(arch/powerpc/boot/\*)中,这样dtb就可以被包裹在内核镜像中,以
支持引导现有的非DT察觉的固件。
一段时间后,FDT基础架构被普及到了所有的架构中。在写这篇文章的时候,6个主线架
构(arm、microblaze、mips、powerpc、sparc和x86)和1个非主线架构(ios)
有某种程度的DT支持。
1. 数据模型
-----------
如果你还没有读过设备树用法\ [1]_页,那么现在就去读吧。没关系,我等着....
2.1 高层次视角
Annotation
- Detected declarations: `function harmony_init_machine`.
- Atlas domain: Support Tooling And Documentation / Documentation.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.