How to obtain virtual addresses by operating hardware in linux

Source: Internet
Author: User
How to obtain the virtual address for operating hardware in linux-Linux general technology-Linux programming and kernel information. The following is a detailed description. After one or two days of exploration, I basically had a preliminary understanding of linux control hardware, the difference between hardware control in linux and hardware control in a non-operating system is that the hardware address is different. in linux, va (Virtual Address) is used ), in the absence of an operating system, you can directly use the hardware's pa (physical address). Of course, we need to further explore and verify whether a module is removed during kernel compilation, you can directly use pa in linux. Obviously, my efforts over the past two days are based on the inability to directly use pa.

The physical addresses and their virtual addresses of most hardware are defined in the linux-2.6.8.1/include/asm-arm/arch-s3c2410/map. h. In the user manual of the optical disk, um_s3c2410x_rev11_012003.pdf is also called datasheet. the physical address of the hardware is also described. Different from va, pa has the same base address and Their offset.

Taking gpio F as an example, the base address (ba) of gpio is 0x56000000, and GPFCON pa is 0x56000050, that is, the visible offset is 0x50, let's take a look at GPFCON va, vaba: 0xf0e0 0000, va: 0xf0e0 0050, And the offset is 0x50. Now, everything becomes clearer. As long as we know the vaba and its offset, we can calculate the va and operate it. So there are two problems: 1: How to Get vaba: In the linux-2.6.8.1/include/asm-arm/arch-s3c2410/map. h has a definition. Here we also need to map. h address definition is described below

In computers, the idea of hierarchical hierarchy is everywhere, which is also a basic idea and Idea on computers. Here, it is no exception. In the words of Lao Zhao, it is divided into three levels and three levels of offset. The ba of the CPC Central Committee is 0xf0000000, which is offset to the province, 0xf0e0 0000 (using GPIO as an example) and shifted to the grass-roots layer again, 0xf0e0 0050 (using GPFCON as an example ). Haha. Now, you can use 0xf0e0 0050 in linux to operate the GPFCON register.

The implementation process in the source code is extracted as follows: (of course, we can calculate va in advance for specific implementation. The process is as above)

# Define S3C2410_ADDR (x) (0xF0000000 + (x) // map. h
// Party Central Committee of all hardware in linux: 0xF0000000
# Define S3C2410_VA_GPIO S3C2410 (0X00E00000) // map. h

// The GPIO offset 0x00E00000. After this offset is added

# Define S3C2410_GPIOREG (x) + S3C2410_VA_GPIO)
# Define S3C2410_GPFCON S3C2410_GPIOREG (0x50) // regs-gpio.h

// The offset of the GPFCON register is 0x50. After this offset is added, the specific register can be used to operate the hardware.

# Define S3C2410_GPFDAT S3C2410_GPIOREG (0x54) // regs-gpio.h
# Define S3C2410_GPFUP S3C2410_GPIOREG (0x58) // regs-gpio.h

2: The second problem is getting the offset. In fact, this problem has been solved in 1. You just need to check the specific hardware header file.

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.