Linux device-driven DTS description of resources

Source: Internet
Author: User

When Linux uses Platform_driver_register () to register platform_driver, it needs to know the device's interrupt number, memory address and other resources in Platform_driver's probe ().

The description information of these resources is stored in the resource data structure, the same resources are stored in a tree-shaped tree data structure, through the parent node, the sibling node, the child node is connected. such as interrupt resources, IO port resources, IO memory resources, DMA resources have different resource tree.

Linux uses struct resource to describe a resouce

struct resource {    resource_size_t start;      //资源范围的开始    resource_size_t end;        //资源范围的结束    constchar *name;   //资源拥有者名    unsignedlong flags; //资源属性标识    struct resource *parent, *sibling, *child;  //资源树的父节点, 兄弟节点, 字节点指针};

The resource_size_t is determined by the system for uint32_t or uint64_t.

In the platform mechanism, use Platform_get_resource () to obtain the specified resource type.

//比如获取想获取中断号,irq = platform_get_irq(pdev, 0);int platform_get_irq(struct platform_device *dev, unsigned int num) {    *r = platform_get_resource(dev, IORESOURCE_IRQ, num);    return r ? r->start : -ENXIO;}EXPORT_SYMBOL_GPL(platform_get_irq);                 *res_mem0);

Can get an IO memory resource node pointer, including the beginning of the address, the end address, and so on, the length of the IO memory can be obtained by resource_size (), but this resource is just a description, want to really use this IO memory, but also through the first application, re-mapping process. For example, you can use Devm_request_mem_region () to request the use of this IO memory, and then use Ioremap () to map it out for user space.

Devm_request_mem_region (&pdev->dev, Res_mem->start, Resource_size (RES_MEM),
Res_mem->name))

Addr_start = Ioremap (Res_mem->start, Resource_size (Res_mem));

The return value of Ioremap () is the virtual address of the resource.

The resources for IO memory are given in the device tree source file (end of. DTS), the. dts file is used to describe the target board hardware information, and after Uboot is started, it is obtained using a specific API provided by Uboot, such as Fdt_ Getprop (), Fdt_path_offset (), these APIs are included in the Uboot header file

  gpio: gpio-controller@1070000000800 {            #gpio-cells=<2>;            ="cavium,octeon-3860-gpio";            =<0x107000x000008000x00x100>;            gpio-controller;

According to its description, it is known that the GPIO controller's IO Memory start address is: 0x107900000800, and the length is 0x100.

That is, from 0x107900000800 to 0X1079000008FF.

Use CAT/PROC/IOMEM in the target board to see:

1070000000800-10700000008FF:/[email protected]/[email protected]

A description of the i²c:

TWSI0: [Email protected]1180000001000{#address-cells = <1>;#size-cells = <0>; Compatible= "Cavium,octeon-3860-twsi"; Reg= <0x11800 0x00001000 0x0 0x200>; Interrupts= <0  $>; Clock-rate = <100000>;

IO Memory start address is: 0x118000001000, length is 0x200.

From 0x118000001000 to 0x1180000011ff.

Use CAT/PROC/IOMEM in the target board to see:

1180000001000-11800000011FF:/[email protected]/[email protected]

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linux device-driven DTS description of resources

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.