Difference between device file and device driver

I am currently reading the Linux Module Programming Guide, and I came across two terms that confused the device file bits and the device driver. When studying these terms, I came across the following:

A device driver is a piece of software that controls or controls a particular type of device.

A device file is an interface for a device driver that appears in the file system as if it were a regular file. On Unix-like operating systems, they are usually located in the / dev directory and are also called device nodes.

What I would like to know -

1) Are device files an interface between user space programs and a device driver? 2) Does the program provide access to the driver in the kernel through a special file of the corresponding device?

for example, when using the spidev char dev file, does my user space program allow me to interact with spi.c and omap2_mcspi.c, etc. using simple read, write, and ioctl calls?

+6
source share
3 answers

One of the main abstractions in Unix is ​​the file ( source ):

Programs, services, texts, images, etc. - all files. Input and output devices, as a rule, all devices are considered files in accordance with the system.

This allows users to process various objects using a single set of operations, even when implementing these operations can be completely different.

As you ask your question, device files are a user who is facing the side of abstraction. This is what the user sees; file that they can write, read, open, close, etc. Device drivers are an implementation of these operations.

Thus, the user will make a call to a file operation, such as recording, and then the kernel will use the device driver to perform the operation.

+6
source

spidev.c is a special type of driver that is registered for universal client (chip) devices SPI, and its main purpose is to export a low-level SPI API to user space.

A device file, such as /dev/spidevX.Y, is a software abstraction of an SPI device that provides a low-level Linux SPI API for user space using system calls (in the world of Linux drivers known as “file operations”):

That is read(), write(), ioctl()...

Between spi.c a whole level of SPI is defined on Linux

The device driver representing the actual HW SPI controller is the place where callbacks (interceptors) are implemented and registered in the kernel as part of the spi_controller structure. Here is the callback for sending the SPI message:

 master->transfer_one_message = atmel_spi_transfer_one_message; 
0
source

everything on Linux is a file. A device driver is software used by the operating system to communicate with a device. The device driver uses device files.

-1
source

Source: https://habr.com/ru/post/974152/


All Articles