IO ports and IO memory mappings

Source: Internet
Author: User
Tags volatile
A. Almost every peripheral is done by reading and writing registers on the device. Peripheral registers are also known as "I/O ports, usually includes: control registers, State registers and data registers three categories, and a peripheral register is usually continuously address. There are two ways for the CPU to address the physical addresses of peripheral IO ports: One is I/O mapping (i/o-mapped) and the other is the memory-mapped method (memory-mapped). The exact one depends on the CPU architecture.

Some architectures of CPUs (e.g., PowerPC, m68k, etc.) typically implement only one physical address space (RAM). In this case, the physical address of the peripheral I/O port is mapped to the CPU's single physical address space and becomes part of the memory. At this point, the CPU can access the peripheral I/O port as if it were accessing a memory unit without having to set up specialized peripheral I/O directives. This is called the "Memory Mapping Method" (memory-mapped).

Other architecture CPUs (typically X86) implement a separate address space for peripherals, known as "I/O address space" or "I/OS port space." This is a different address space from the physical address space of the CPU RAM, and I/O ports of all peripherals are addressed in this space. The CPU accesses the address unit (also the I/O port) in this space by setting up specialized I/O directives, such as X86 in and out directives. This is called the "I/O mapping Method" (i/o-mapped). Compared to the RAM physical address space, I/O address space is usually relatively small, such as the x86 CPU I/O space is only 64KB (0-0XFFFF). This is one of the main drawbacks of the I/O mapping method.

Linux will be referred to as "I/O zone" (I/O region) based on I/O mapping or memory-mapped I/O ports. Before we discuss the administration of I/O zones, let's first analyze how Linux implements the abstract concept of "I/O resources".

B.

The difference between IO port and IO mem is rarely noticed during the driver writing process. While it is highly deprecated to use some code that does not conform to the specification to achieve the ultimate goal.

Together with the diagram below, we describe the relationship between IO port and IO memory and memory thoroughly. Main memory 16M Byte SDRAM, peripheral is a video capture card, with 16M bytes of SDRAM as buffer.

1. CPU is the case of i386 architecture

In the processing of the i386 series, memory and external IO are separate addresses and are individually addressable. MEM's memory space is 32 bits can be addressed to the 4g,io space is 16 bits can be addressed to 64K.

In the Linux kernel, the IO port on the access peripherals must be addressed through IO port. and access IO mem is more verbose, external mem can not be as main memory access, although the size of the same, but the external mem is not registered in the system. Access to the external IO mem must be mapped to the kernel's mem space through remap.

To achieve interface identity, the kernel provides a mapping function for IO port to io mem. After mapping IO port can be regarded as IO mem, according to IO mem access mode.

2. CPU is the case of arm or PPC architecture

In this kind of embedded processor, IO port is addressed by memory mapping, that is, IO Bus is mem bus. If the system's addressing capability is 32 bits, IO port+mem (including IO Mem) can reach 4G.

When accessing this type of IO port, we can also use the IO port dedicated addressing mode. As for the IO port addressing, the kernel is exactly how it is done, which is done when the kernel is ported. In this architecture of the processor, still maintain the IO port support, is completely i386 architecture legacy issues, there is little discussion. The way to access IO Mem is consistent with i386.

Note : The Linux kernel provides me with full support for IO port and IO mem, while specifically looking at the drivers in the driver directory, rarely follows this specification to organize IO port and IO mem resources. The key problem of the two access is address location, in C language, the use of volatile can be achieved. A lot of code access to the register in IO port, the use of the volatile keyword, although the function can be achieved, we still do not recommend the use. Just like the simplest delay is a while, but it is resolutely avoided in a multitasking system.

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.