About ioremap, request_mem_region

Source: Internet
Author: User

ArticleContent from: http://blog.csdn.net/fudan_abc/archive/2007/10/04/1811451.aspx

In the i386 series processor represented by Intel, memory and external Io are independently addressing, so there is an address space called memory space, another address space is called I/O space. that is to say, from the processor's point of view, i386 provides some separate commands to access the I/O space. in other words, different commands must be used to access the I/O space and access the normal memory. in some embedded processors, such as PowerPC, their family only uses one space, that is, the memory space. In this case, the physical address of the peripheral I/O port is mapped to the memory address space. This is the legendary memory-mapped, memory ing. in our family, the physical address of the peripheral I/O port is mapped to the I/O address space. This is the legendary I/O-mapped, i/O ing.

To use the I/O memory, you must first apply for it and then map it. To use the I/O port, you must first apply for it, or call it a request, the request for the I/O port means to let the kernel know that you want to access this port, so that the kernel will not allow others to access this port after it knows it. after all, this world is rare. the function for applying for the I/O port is request_region, which is from include/Linux/ioport. h,

/* Convenience shorthand with allocation */

# Define request_region (START, N, name) _ request_region (& ioport_resource, (start), (n), (name ))

# Define request_mem_region (START, N, name) _ request_region (& iomem_resource, (start), (n), (name ))

# Define rename_region (Region, newname) do {(region)-> name = (newname);} while (0)

Extern struct resource * _ request_region (struct resource *,

Resource_size_t start,

Resource_size_t N, const char * Name );

The request_mem_region we see here applies for I/O memory. after application, you also need to use the ioremap or ioremap_nocache function for ing. for request_region, the three parameters start, N and name indicate that you want to use an I/O port resource whose size starts from start is N. Name is your name.

These two functions will almost appear in the kernel driver, such as the probe function in the ohci-at91.c:

View plaincopy to clipboardprint?

    1. HCD-> rsrc_start = pdev-> resource [0]. Start;
    2. HCD-> rsrc_len = pdev-> resource [0]. End-pdev-> resource [0]. Start + 1;
    3. If (! Request_mem_region (HCD-> rsrc_start, HCD-> rsrc_len, hcd_name) {
    4. pr_debug ("request_mem_region failed \ n");
    5. retval =-ebusy;
    6. goto err1;
    7. }
    8. HCD-> regs = ioremap (HCD-> rsrc_start, HCD-> rsrc_len);
    9. If (! HCd-> regs) {
    10. pr_debug ("ioremap failed \ n");
    11. retval =-EIO;
    12. goto err2;
    13. }

HCd-> rsrc_start = pdev-> resource [0]. start; HCD-> rsrc_len = pdev-> resource [0]. end-pdev-> resource [0]. start + 1; if (! Request_mem_region (HCD-> rsrc_start, HCD-> rsrc_len, hcd_name) {pr_debug ("request_mem_region failed \ n"); retval =-ebusy; goto err1 ;} HCd-> regs = ioremap (HCD-> rsrc_start, HCD-> rsrc_len); If (! HCd-> regs) {pr_debug ("ioremap failed \ n"); retval =-EIO; goto err2 ;}

The advantage is that the Register Access Method looks good, as long as an offset address is added.

But sometimes I don't like it. Because these two statements are used to access registers. It is equivalent to obtaining the register virtual address. But we have already mapped the virtual address during initialization, so I like to directly operate the virtual address of the register.

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.