Using Resources
A module can’t accomplish its task without using system resources, such as memory, I/O ports, and interrupt lines, as well as DMA channels if you use the mainboard’s DMA controller.
As a programmer, you are already accustomed to managing memory
allocation, and writing kernel code is no different in this regard.
Your program obtains a memory area using kmalloc and
releases it using kfree. These functions behave like malloc
and free, except that kmalloc takes an additional argument, the
priority. Most of the time, a priority of GFP_KERNEL will
do. The GFP acronym stands for ``Get Free Page.''
Requesting I/O ports and interrupt lines, on the other hand, looks strange at first, because normally a programmer accesses them with explicit instructions in the code, without telling the operating system about it. ``Allocating'' ports and interrupts is different from memory allocation in that memory is allocated from a pool, and every address behaves the same; I/O ports have individual roles, and a driver needs to work with specific ports, not just some ports.
Ports
The job of a typical driver is, for the most part, writing and reading ports. This is true both at initialization time and during normal work. A device driver must be guaranteed exclusive access to its ports in order to prevent interference from other drivers—if a module probing for its hardware should happen to write to ports owned by another device, weird things would undoubtedly happen.
The developers ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access