Linux Device Drivers Flashcards

1
Q

What are device drivers?

A

Device drivers are computer programs that control how different hardware devices interact with the operating system. They act as a bridge between the hardware and the software, allowing the two to communicate with each other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Can you explain what a kernel module is in context with Linux Device Drivers?

A

A kernel module is a piece of code that can be loaded and unloaded into the kernel upon demand. It allows the kernel to be modular, meaning that features can be added and removed as needed, without having to recompile the entire kernel.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why do we need to use device drivers ?

A

Device drivers are necessary because they provide a layer of abstraction between the hardware and the software. This allows the software to interact with the hardware in a more uniform and consistent manner, regardless of the specific hardware that is being used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does it mean for a device driver to be modular ?

A

A modular device driver is one that is designed to be compiled separately from the kernel and loaded as a module at runtime. This allows for the driver to be updated without having to recompile and reboot the entire kernel.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does the operating system interact with the device driver?

A

The operating system interacts with the device driver through a set of APIs. The device driver is responsible for providing the implementation for these APIs, which the operating system then uses to communicate with the hardware.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Can you explain how a device driver communicates with an I/O controller?

A

A device driver communicates with an I/O controller by sending it commands and data. The I/O controller then interprets these commands and data and performs the appropriate actions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Do all devices require a device driver? If not, then which ones don’t require a device driver?

A

No, not all devices require a device driver. Devices that don’t require a device driver are typically simple devices that don’t need any special software to interface with them. For example, a USB flash drive is a simple device that doesn’t require a device driver.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are some examples of device drivers used by Linux Systems?

A

Some examples of device drivers used by Linux systems include:

– storage drivers, which allow the system to access and use storage devices such as hard drives and SSDs;
– network drivers, which enable the system to connect to and communicate over a network;
– printer drivers, which allow the system to print to a connected printer;
– and camera drivers, which allow the system to access and use a connected camera.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Are there any differences between user space and kernel space while dealing with device drivers?

A

Yes, there are some key differences between user space and kernel space when it comes to device drivers. In user space, drivers are not allowed to directly access hardware devices. Instead, they must go through a system call interface to request access to devices. In kernel space, however, drivers have direct access to hardware devices. This means that they can bypass the system call interface and directly access devices. This can lead to more efficient code, but it also comes with some risks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the various types of device drivers?

A

There are three main types of device drivers:

  1. Kernel modules
  2. User-space drivers
  3. Hybrid drivers

Kernel modules are drivers that are integrated into the kernel itself. They have direct access to hardware and other parts of the system, and are very efficient. However, they can also be more difficult to develop and maintain.

User-space drivers are drivers that run in user-space, outside of the kernel. They are usually easier to develop and maintain, but they are less efficient since they have to go through the kernel to access hardware.

Hybrid drivers are a mix of the two, with some code running in kernel-space and some in user-space. This can provide the best of both worlds, but can also be more complex to develop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between character device drivers and block device drivers?

A

Character device drivers allow for communication with a device one character at a time. Block device drivers allow for communication with a device in blocks of data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which type of device drivers can communicate directly with hardware?

A

There are two types of device drivers that can communicate directly with hardware: kernel-level drivers and user-level drivers. Kernel-level drivers are typically written in C and have direct access to hardware registers and other low-level features. User-level drivers are written in a higher-level language such as C++ and typically communicate with kernel-level drivers to access hardware.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which type of device drivers cannot communicate with the hardware directly?

A

There are two types of device drivers: those that can communicate with the hardware directly, and those that cannot. The type of device driver that cannot communicate with the hardware directly is called a software driver.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Can you give me some examples of where you would use character device drivers instead of block device drivers?

A

Character device drivers are used for devices that generate or receive a continuous stream of data, such as audio or video devices. Block device drivers are used for devices that store data in discrete blocks, such as hard drives or flash drives.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are three main components of a device driver

A

The three main components of a device driver are the device driver core, the bus driver, and the device driver client. The device driver core is responsible for managing the device driver and providing a interface for the bus driver and the device driver client. The bus driver is responsible for communication between the device driver and the hardware. The device driver client is responsible for communication between the device driver and the software.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the significance of the “open()” method when using device drivers?

A

The open() method is used to gain access to a device driver. This is the first step that must be taken in order to use a device driver. The open() method returns a file descriptor that is then used to refer to the device driver in all subsequent operations.

17
Q

Why should developers avoid using memory allocation routines like malloc or free when working with device drivers?

A

One of the main reasons for this is that device drivers operate in a very specific memory environment, which is often different from the memory environment in which application code runs. This can lead to memory allocation errors that are difficult to track down and debug. Additionally, memory allocation routines can be very slow, which can impact the performance of the device driver.

18
Q

What are the different ways of synchronizing access between process contexts?

A

The different ways of synchronizing access between process contexts are by using semaphores, locks, and atomic variables.

19
Q

Is it possible to have multiple processes accessing the same device at the same time? If yes, then how is this achieved?

A

Yes, it is possible to have multiple processes accessing the same device at the same time. This is typically achieved by using a device driver that supports concurrent access. Concurrent access can be implemented in a number of ways, but the most common approach is to use a shared memory area that is accessed by all processes that need to access the device.

20
Q

Can you explain the difference between interrupt driven I/O and polling based I/O?

A

Interrupt driven I/O is where the CPU is interrupted whenever an I/O event occurs. This allows the CPU to quickly respond to events as they happen, but can also lead to higher CPU usage as the CPU is constantly being interrupted. Polling based I/O is where the CPU periodically checks for I/O events, and only handles them when it finds them. This can lead to lower CPU usage, but can also mean that I/O events are not handled as quickly as they could be.