_ Iomem Linux

Source: Internet
Author: User
Http://lwn.net/Articles/102232/A new I/O memory access mechanic [posted September 15,200 4 by Corbet]

 

Most reasonably current cards for the PCI bus (and others) provide one or more I/O memory regions to the bus. by accessing those regions, the processor can communicate with the peripheral and make things happen. A look /Proc/iomemWill show the I/O memory regions which have been registered on a given system.

To work with an I/O memory region, a driver is supposed to map that region with a callIoremap (). The return value fromIoremap ()Is a Magic cookie which can be passed to a set of accessor functions (with names likeReadb ()OrWritel ()) To actually move data to or from the I/O memory. on Some ubuntures (notably x86), I/O memory is truly mapped into the kernel's memory space, so those accessor functions turn into a straightforward pointer dereference. other ubuntures require more complicated operations.

There have been some longstanding problems with this scheme. drivers written for the X86 architecture have often been known to simply dereference I/O memory addresses directly, rather than using the accessor functions. that approach works on the x86, but breaks on other ubuntures. other drivers, knowing that I/O memory addresses are not real pointers, store them in integer variables; that works until they encounter a system with a physical address space which doesn' t fit into 32 bits. and, in any case,Readb ()And friends perform no type checking, and thus fail to catch errors which cocould be found at compile time.

The 2.6.9 kernel will contain a series of changes designed to improve how the kernel works with I/O memory. The first of these is a new_ IomemAnnotation used to mark pointers to I/O memory. These annotations work much like_ UserMarkers, users t that they reference a different address space. As_ User,_ IomemMarker serves a documentation role in the kernel code; it is ignored by the compiler. when checking the CodeSparse, However, developers will see a whole new set of warnings caused by code which mixes normal pointers_ IomemPointers, or which dereferences those pointers.

The next step is the addition of a new set of accessor funsor which explicitly require a pointer argument. These functions are:

 

    unsigned int ioread8(void __iomem *addr);    unsigned int ioread16(void __iomem *addr);    unsigned int ioread32(void __iomem *addr);    void iowrite8(u8 value, void __iomem *addr);    void iowrite16(u16 value, void __iomem *addr);    void iowrite32(u32 value, void __iomem *addr);

By default, these functions are simply wrappers aroundReadb ()And friends. The explicit pointer type for the argument will generate warnings, however, if a driver passes in an integer type.

There are "string" versions of these operations:

 

    extern void ioread8_rep(void __iomem *port, void *buf,                             unsigned long count);

All of the other variants are defined as well, of course.

There is actually one other twist to these functions. some drivers have to be able to use either I/O memory or I/O Ports, depending on the architecture and the device. some such drivers have gone to considerable lengths to try to avoid duplicating code in those two cases. with the new accessors, a driver which finds it needs to work with x86-style ports can call:

 

    void __iomem *ioport_map(unsigned long port, unsigned int count);

The return value will be a cookie which allows the mapped ports to be treated as if they were I/O memory; functions likeIoread8 ()Will automatically do the right thing. For PCI devices, there is a new function:

 

    void __iomem *pci_iomap(struct pci_dev *dev, int base,                             unsigned long maxlen);

For this function,BaseCan be either a port number or an I/O memory address, and the right thing will be done.

As of 2.6.9-RC2, there are no in-tree users of the new interface. that can be expected to change soon as patches get merged and the kernel janitors get to work. for more information on the new I/O memory interface and the motivation behind it, see this explanation from Linus.

(Log in to post comments)

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.