fbpx How Linux Handles Hardware: Drivers, Kernel and udev | Certificação Linux

How Linux Handles Hardware

📅 03/06/2019 ⏱ 5 min ✍️ Uira Ribeiro
Linuxcommandshow-to
How Linux Handles Hardware
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

Learn about the function of the /proc/pci, /proc/dma, /proc/interrupts and /proc/ioports files

For everything to work correctly, it is necessary that devices are allocating computer resources.

These resources can be input/output ports, interrupt requests (IRQ) and direct memory access (DMA). Let's look at these concepts.

Input/Output Ports

Input and output ports are memory addresses reserved in the microprocessor for devices to perform input and output of information.

These memory addresses are used for simplified data exchange between the processor and devices.

Devices can use more than one input/output port or a range of addresses. For example, a standard sound card uses ports 0x220, 0x330 and 0x388.

Each device has a unique port address that cannot be shared with other devices.

The I/O addresses in use on the system can be viewed with the command:

# cat /proc/ioports
0000-001f : dma1
0020-003f : pic1
0040-005f : timer
0060-006f : keyboard
0070-007f : rtc
(...)

Interrupt Request (IRQ)

IRQs are calls that devices can make to request special attention from the processor.

Most computers only offer 16 hardware interrupts for the most diverse devices.

It may seem few for modern configurations with the most different devices. Fortunately IRQs can be shared.

System interrupts can be viewed in the Kernel with the command:

# cat /proc/interrupts CPU0

0:          604694      XT-PIC   timer

1:          35746        XT-PIC keyboard

2:          0                XT-PIC cascade

3:          13546        XT-PIC orinoco_cs

11:        15              XT-PIC ALi Audio Accelerator

14:        38759        XT-PIC ide0

Direct Memory Access (DMA)

DMA is used to allow data transfer between devices and memory without processor intervention.

This access is done through channels. Most computers have two DMA controllers. The first controls channels 0, 1, 2, 3 and the second channels 4, 5, 6, 7, totaling 8 channels.

DMA channels in use on the system can be viewed with the command:

# cat /proc/dma
4: cascade

It is important that you know these resources are limited and need to be managed so that conflicts between devices are avoided.

Some devices like serial and parallel ports already use the resources in the following standard:

TABLE - Device reference in Linux

Device Name on Linux Device Name on Windows I/O Port DMA IRQ
ttyS0 COM1 0x3F8 - 4
ttyS1 COM2 0x2F8 - 3
ttyS2 COM3 0x3E8 - 4
ttyS3 COM4 0x2E8 - 3
lp0 LPT1 0x378 - 7
lp1 LPT1 0x278 - 5
/dev/hda1 C: 0x1F0 - 14
/dev/fd0 A: 0x3F0 2 6

In the LPIC-1 exam you may need to resolve some possible resource conflicts on serial or parallel ports.

Hotplug x Coldplug

There are devices that can be connected or removed with the computer on and fully operational, which are categorized as hotplug.

For these, the Kernel will be able to detect their presence or absence and load the necessary drivers, scripts and programs for their correct operation.

In this category are: keyboard, mouse, webcam, external HD USB, external USB cd-rom, printers, speakers, microphones, monitors, cell phones, pen drives, etc.

Devices that must necessarily be connected and removed with the computer off are called coldplug.

Any attempt to change their state may cause freezing or even burning of the equipment. They are: CPU, RAM Memory, internal hard drives, internal cards (sound, video, etc).

Storage Devices

Linux supports several types of mass data storage. These devices can be categorized as optical, magnetic or memory.

Optical discs are CD-ROMs (700Mb), DVDs (4.7-8.5 Gb) and Blu-Rays (25-50Gb). They are not as fast as HDs, but have great durability if stored in appropriate places and do not allow data to be recorded multiple times. 

Magnetic disks have large data storage capacity, which can reach 8 Terabytes.

Some models are hybrid, as they have magnetic disks and large flash memories to store the most read data or even the operating system. They are sensitive to shocks and drops.

Still in the magnetic devices category, we have magnetic tapes, widely used for data backup. They allow data to be recorded sequentially at low cost.

Their use is decreasing due to the low price of disks, cloud computing and other more advanced backup copy strategies.

The "disks" in memory are actually flash memory banks called Solid State Drive (SSD) – solid state drive – encapsulated in a box the size of an HD and have no moving parts like optical and magnetic disks. Their data access time is incredibly fast compared to magnetic and optical disks, they are resistant to drops and shocks, consume less energy, among other benefits.

However, storage capacity does not exceed 1 Terabyte, and its cost is high compared to magnetic disks. They are widely used in Ultrabooks and high-performance servers.

PCI Devices

During the system boot process, the Kernel detects the connected PCI devices on the computer. The list of expansion cards found can be read through the special file /proc/pci.

# cat /proc/pci

PCI devices found:

Bus 0, device 0, function 0:

Host bridge: PCI device 10b9:1644 (Acer Laboratories Inc. [ALi]) (rev 1).

Prefetchable 32 bit memory at 0xf0000000 [0xf3ffffff].

Bus 0, device 1, function 0:

PCI bridge: Acer Laboratories Inc. [ALi] M5247 (rev 0).

Master Capable. No bursts. Min Gnt=8.

Bus 0, device 2, function 0:

USB Controller: Acer Laboratories Inc. [ALi] M5237 USB (rev 3).

IRQ 11.

Want to learn more about Linux special files in /proc? Check out our LPIC-1 course

Learn much more about Linux in our online course. You can enroll here with a 7-day free trial. If you already have an account, you can access it here.

Like it? Share :-)

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp