Quick Reference

This chapter introduced the following symbols related to hardware management.

#include <linux/kernel.h> , void barrier(void)

This “software” memory barrier requests the compiler to consider all memory volatile across this instruction.

#include <asm/system.h> , void rmb(void); , void wmb(void); , void mb(void);

Hardware memory barriers. They request the CPU (and the compiler) to checkpoint all memory reads, writes, or both, across this instruction.

#include <asm/io.h> , unsigned inb(unsigned port); , void outb(unsigned char byte, unsigned port); , unsigned inw(unsigned port); , void outw(unsigned short word, unsigned port); , unsigned inl(unsigned port); , void outl(unsigned doubleword, unsigned port);

These functions are used to read and write I/O ports. They can also be called by user-space programs, provided they have the right privileges to access ports.

unsigned inb_p(unsigned port); , ...

The statement SLOW_DOWN_IO is sometimes needed to deal with slow ISA boards on the x86 platform. If a small delay is needed after an I/O operation, you can use the six pausing counterparts of the functions introduced in the previous entry; these pausing functions have names ending in _p.

void insb(unsigned port, void *addr, unsigned long count); , void outsb(unsigned port, void *addr, unsigned long count); , void insw(unsigned port, void *addr, unsigned long count); , void outsw(unsigned port, void *addr, unsigned long count); , void insl(unsigned port, void *addr, unsigned long count); , void outsl(unsigned port, void *addr, unsigned long count);

The “string functions” are optimized to transfer data from an input port to a region of memory, or the other way around. Such transfers are performed by reading or writing the same port count times.

#include <linux/ioport.h> , int check_region(unsigned long start, unsigned long len); , void request_region(unsigned long start, unsigned long len, char *name); , void release_region(unsigned long start, unsigned long len);

Resource allocators for I/O ports. The check function returns 0 for success and less than 0 in case of error.

int check_mem_region(unsigned long start, unsigned long len); , void request_mem_region(unsigned long start, unsigned long len, char *name); , void release_mem_region(unsigned long start, unsigned long len);

These functions handle resource allocation for memory regions.

#include <asm/io.h> , void *ioremap(unsigned long phys_addr, unsigned long size); , void *ioremap_nocache(unsigned long phys_addr, unsigned long size); , void iounmap(void *virt_addr);

ioremap remaps a physical address range into the processor’s virtual address space, making it available to the kernel. iounmap frees the mapping when it is no longer needed.

#include <linux/io.h> , unsigned readb(address); , unsigned readw(address); , unsigned readl(address); , void writeb(unsigned value, address); , void writew(unsigned value, address); , void writel(unsigned value, address); , memset_io(address, value, count); , memcpy_fromio(dest, source, nbytes); , memcpy_toio(dest, source, nbytes);

These functions are used to access I/O memory regions, either low ISA memory or high PCI buffers.

Get Linux Device Drivers, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.