Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of the hardware device driver of Linux system

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what is the role of the hardware device driver of the Linux system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

What is a driver?

The most popular explanation is "drive hardware devices to act".

Effect?

The device driver deals directly with the underlying hardware, reads and writes device registers according to the specific working mode of the hardware device, completes device polling, interrupt processing, DMA communication, and maps physical memory to virtual memory. Finally, the communication device can send and receive data, display devices can display text and pictures, and storage devices can record file number data.

The hardware of computer system is mainly composed of cpu, memory and peripherals. However, with the development of IC manufacturing technology, the integration of chips is getting higher and higher, and memory and peripheral adapters are often integrated inside the cpu. ARM processor integrates UART, I2C controller, USB controller, SDRAM controller, etc.

The driver is aimed at memory and peripherals (including cpu internal integrated memory and peripherals), not for cpu cores. Linux divides memory and peripherals into three basic categories: character devices, block devices, and network devices.

Devices that must be accessed in serial order, such as touch screens, tape drives, mice, and so on. The device can be accessed in any order and operated in blocks, such as hard disk, floppy drive and so on. The character device is not buffered by the system, while the block device is buffered by the system. However, there is no obvious boundary between the character device and the block device, for example, the flash device meets the characteristics of the block device, but we can still access it as a character device.

In the Linux system, the network device is designed for the receiving and sending of data packets, which does not correspond to the nodes of the file system. The communication between the kernel and the network device is completely different from that between the kernel and the character device and the block device.

As shown in the figure above, except for network devices, character devices and block devices are mapped to files and directories of the Linux file system, and can be accessed through the file system's system call interfaces open (), write (), read (), close () and other functions. Block devices are more complex than character devices, on which a disk / Flash file system is first established, such as FAT, Ext3, YAFFS, JFFS, FAT, Ext3, YAFFS, JFFS standardize the organization of files and directories on the storage media

Applications can be programmed using Linux's system call interface, or by using c library functions, which are more recommended for portability. The C library function itself is also implemented through the system call interface.

In the design of embedded system, LED is generally directly controlled by GPIO of cpu. GPIO is generally controlled by two sets of registers, namely, a set of control registers and a set of data registers. The control register can set the working mode of the GPIO port to input or output. When the pin is set to output, writing 1 and 0 to the corresponding bits of the data register will generate high and low levels on the pin, respectively; when the pin is set as input, the corresponding level signal on the pin can be obtained by reading the corresponding bit of the data register.

The hardware basis of driver design

The classification of processors, as shown in the following figure:

Memory can be divided into read-only memory (ROM), flash memory (Flash), random access memory (RAM), optical media memory and magnetic media memory.

The interface between Nor Flash and cpu is a typical SRAM-like interface, and there is no need to add additional control circuit. The characteristic of Nor Flash is that it can be executed on chip, and the program can be run directly in Nor. The interface between Nand Fash and cpu must be converted by the corresponding control circuit. Of course, the signal of Nand Flash interface can be generated through the address line or GPIO. Nand Flash is accessed in block mode and does not support on-chip execution.

The programming principle of Flash is that you can only write 1 as 0, but not finish 0. So the corresponding block must be erased before Flash programming, and the process of erasing is to write all the bits as 1, and all the bytes in the block become 1xFF.

The classification of memory, as shown in the following figure:

Schematic analysis: get all kinds of hardware resources used by memory and peripherals by reading the schematics of the circuit board, including chip selection, interrupt and DMA resources used by memory and peripheral control chips. The memory and I / O base address of the chip are obtained by analyzing the chip, and the interrupt number and DMA channel used by the chip are obtained by analyzing the interrupt and DMA signals, which are similar to the following table:

Timing analysis: for driver engineers or hardware engineers, timing analysis means that the access between chips meets the requirements of the effective sequence, sampling establishment time and holding time of the sequence diagram signals in the chip manual, and accurately locate the timing problems when the circuit board is not working properly.

Kernel and kernel programming

In terms of device drivers, Linux2.6 has made great changes compared with Linux2.4, which is mainly reflected in the addition of many new features in kernel API (such as memory pool), sysfs file system, kernel module from .o to .ko, driver module compilation, module usage counting, definition of module loading and unloading functions, etc.

The Linux kernel consists of five subsystems: process scheduling, memory management, virtual file system, network interface and inter-process communication, as shown in the following figure:

In device driver programming, when the requested resource is not satisfied, the driver will generally schedule other threads to execute and put the corresponding process of the driver to sleep until the requested resource is released. It will be awakened and ready for the anniversary.

In device driver programming, if you need several concurrent tasks, you can start the kernel thread. The function to start the kernel thread is: int kernel_thread (int (* fn) (void *), void * arg, unsigned long flags).

Linux memory management completes the conversion of virtual memory to physical memory for each process. Generally speaking, each process in Linux has the memory space of 4GB, 0-3GB belongs to user space, 3-4GB belongs to kernel space, and kernel space has different ways to deal with conventional memory, I-4GB device memory and high-end memory.

The virtual file system hides the details of all kinds of hardware and provides a unified interface for all devices. Moreover, it is independent of each specific file system and is an abstraction of various file systems. It uses super block to store file system related information, index node inode to store physical information of files, and directory entry dentry to store logical information of files.

Linux system can only transfer control from user space to kernel space through system calls and hardware interrupts.

This is the end of the content of "what is the function of the hardware device driver of the Linux system". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report