Difference between revisions of "How to find Linux kernel driver associated to a device"

[quality revision] [quality revision]
m
 
 

Template:ArticleMainWriter Template:ArticleApprovedVersion

1 Introduction[edit]

This article shows the user how to find the Linux® kernel driver associated to a kernel device.

This can, for example, be useful when debugging devices that the user does not know, or monitoring for correct system behavior.

2 Find kernel driver for a device[edit]

2.1 Major and minor numbers for a Linux kernel device[edit]

The device files in the Linux kernel are associated to a MAJOR and a MINOR number, giving each file a unitary identity. This abstraction of device handling is a basic features of the Linux kernel.

A list of MAJOR numbers, and rules for MINOR numbers are given in Documentation/admin-guide/devices.txt of the Linux kernel source[1], or in kernel.org[2].

2.2 List of available devices[edit]

A list of the available devices for the Linux kernel can be read from the procfs file /proc/devices:

Board $> cat /proc/devices

This lists all of the available devices, according to their classification as a character or a block device.
The number preceding the device name corresponds to the MAJOR number of the device (for example, "4" is the MAJOR number for the "tty" device):

Character devices:
  1 mem
  2 pty
  3 ttyp
  4 /dev/vc/0
  4 tty
  5 /dev/tty
  5 /dev/console
  5 /dev/ptmx
  5 ttyRPMSG
  7 vcs
 10 misc
 13 input
 21 sg
 29 fb
 81 video4linux
 89 i2c
 90 mtd
116 alsa
128 ptm
136 pts
153 spi
166 ttyACM
180 usb
189 usb_device
199 galcore
226 drm
245 cec
246 media
247 ttySTM
248 bsg
249 watchdog
250 iio
251 ptp
252 pps
253 rtc
254 gpiochip

Block devices:
  1 ramdisk
  7 loop
  8 sd
 11 sr
 31 mtdblock
 65 sd
 66 sd
 67 sd
 68 sd
 69 sd
 70 sd
 71 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd
179 mmc
254 virtblk
259 blkext

For further information about the major and minor numbers for a Linux kernel driver, refer to the Linux tutorial web page[3].

Note: 'Misc devices have a specific setup; you can find the list of misc devices with the corresponding MINOR number in the /proc/misc file.

2.3 Device entries in /dev[edit]

Each device has a corresponding entry in the /dev directory of the Linux kernel pseudo filesystem.

Board $> ls -lR /dev

Be careful, /dev contains some sub-directories containing device entries, that is, input. That the reason why -R should be used.

This command lists all of the device entries, including the device type and the associated MAJOR and MINOR numbers

For example:

crw-rw---- 1 root video 81, 0 Dec 18 16:26 video0
This device video0 is of type character (c), with MAJOR number of 81 and MINOR number of 0.

2.4 System device entries in /sys/dev[edit]

All devices, classified by type (char or block), and identified by their MAJOR/MINOR number can be found in the dev subdirectory of the sysfs file system entry (/sys).

A platform device is then linked to each MAJOR/MINOR number.

For example:

Board $> ls -l /sys/dev/char/81\:0
lrwxrwxrwx 1 root root 0 Dec 18 17:00 81:0 -> ../../devices/platform/soc/4c006000.dcmi/video4linux/video0

The device video0 is linked to the platform device 4c006000.dcmi/video4linux/video0.

2.5 Driver associated to a platform device[edit]

If the device is linked to a platform device, you can find the corresponding driver definition in the device tree with the compatible parameter.

For example: Look for device 4c006000.dcmi/video4linux/video0 in stm32mp15c.dtsi (the device tree file for the STM32MP15 in arch/arm/boot/dts Linux kernel source path) /stm32mp157c.dtsi .

...
dcmi: dcmi@4c006000 {
 compatible = "st,stm32-dcmi";
 reg = <0x4c006000 0x400>;
 interrupts = <GIC_SPI 78 IRQ_TYPE_NONE>;
 resets = <&rcc CAMITF_R>;
 clocks = <&rcc DCMI>;
 clock-names = "mclk";
 dmas = <&dmamux1 75 0x400 0x05>;
 dma-names = "tx";
 status = "disabled";
};
...

The driver associated to the video0 device is st,stm32-dcmi.

If the driver belongs to your Linux kernel tree, you can search for the driver by declaring st,stm32-dcmi as a compatible device.

  • In the previous example, when looking for the driver compatible with st,stm32-dcmi, you find drivers/media/platform/stm32/stm32-dcmi.c driver
PC $> cd <your_kernel_source_path>
PC $> grep -rs "st,stm32-dcmi" *
...
drivers/media/platform/stm32/stm32-dcmi.c:	{ .compatible = "st,stm32-dcmi"},
...

If the driver is not part of your Linux kernel source tree, it is present as a kernel object library file and you can check on the board:

Board $> cd /lib/modules/<kernel_version>
Board $> grep <compatible_name> modules.alias

This gives you the name of the module driver.

For example, for the gcnano driver used for the GPU:

Board $> grep "st,gcnano" modules.alias
 alias of:N*T*Cst,gcnano galcore


This means that the module name is galcore.ko.

3 References[edit]


<noinclude>

{{ArticleMainWriter | Jean-PhilippeR}}
{{ ArticleApprovedVersion | Jean-PhilippeR | Jean-ChristopheT, AlexandreT | No previous approved version  | PhilipS - 24Oct'18 - 9236 | 25Oct'18 }}

[[Category:How to trace and debug]]</noinclude>

== Introduction ==
This article shows the user how to find the Linux<sup>&reg;</sup> kernel driver associated to a kernel device.

This can, for example, be useful when debugging devices that the user does not know, or monitoring for correct system behavior.

== Find kernel driver for a device ==
=== Major and minor numbers for a Linux kernel device ===
The device files in the Linux kernel are associated to a MAJOR and a MINOR number, giving each file a unitary identity. This abstraction of device handling is a basic features of the Linux kernel.

A list of MAJOR numbers, and rules for MINOR numbers are given in ''Documentation/admin-guide/devices.txt'' of the Linux kernel source<ref>{{CodeSource | Linux kernel | Documentation/admin-guide/devices.txt}}</ref>, or in kernel.org<ref>https://www.kernel.org/doc/Documentation/admin-guide/devices.txt</ref>.

=== List of available devices ===
A list of the available devices for the Linux kernel can be read from the procfs file ''/proc/devices'':
 {{Board$}} cat /proc/devices
This lists all of the available devices, according to their classification as a character or a block device.<br>

The number preceding the device name corresponds to the MAJOR number of the device (for example, "4" is the MAJOR number for the "tty" device):
 Character devices:
   1 mem
   2 pty
   3 ttyp
   4 /dev/vc/0
   4 tty
   5 /dev/tty
   5 /dev/console
   5 /dev/ptmx
   5 ttyRPMSG
   7 vcs
  10 misc
  13 input
  21 sg
  29 fb
  81 video4linux
  89 i2c
  90 mtd
 116 alsa
 128 ptm
 136 pts
 153 spi
 166 ttyACM
 180 usb
 189 usb_device
 199 galcore
 226 drm
 245 cec
 246 media
 247 ttySTM
 248 bsg
 249 watchdog
 250 iio
 251 ptp
 252 pps
 253 rtc
 254 gpiochip

 Block devices:
   1 ramdisk
   7 loop
   8 sd
  11 sr
  31 mtdblock
  65 sd
  66 sd
  67 sd
  68 sd
  69 sd
  70 sd
  71 sd
 128 sd
 129 sd
 130 sd
 131 sd
 132 sd
 133 sd
 134 sd
 135 sd
 179 mmc
 254 virtblk
 259 blkext
{{UpdateNeededForNewRelease|Below InteralInfo banner to be removed}}
{{InternalInfo|<br/>

With Beta1 DV and earlier, UART are linked to TTYS*<br/>

 Character devices:
   1 mem
   2 pty
   3 ttyp
   4 /dev/vc/0
   4 tty
   5 /dev/tty
   5 /dev/console
   5 /dev/ptmx
   5 ttyRPMSG
   7 vcs
  10 misc
  13 input
  21 sg
  29 fb
  81 video4linux
  89 i2c
  90 mtd
 116 alsa
 128 ptm
 136 pts
 153 spi
 166 ttyACM
 180 usb
 189 usb_device
 199 galcore
 226 drm
 245 cec
 246 media
 247 ttyS
 248 bsg
 249 watchdog
 250 iio
 251 ptp
 252 pps
 253 rtc
 254 gpiochip

 Block devices:
   1 ramdisk
   7 loop
   8 sd
  11 sr
  31 mtdblock
  65 sd
  66 sd
  67 sd
  68 sd
  69 sd
  70 sd
  71 sd
 128 sd
 129 sd
 130 sd
 131 sd
 132 sd
 133 sd
 134 sd
 135 sd
 179 mmc
 254 virtblk
 259 blkext
}}
For further information about the major and minor numbers for a Linux kernel driver, refer to the Linux tutorial web page<ref>http://www.linux-tutorial.info/modules.php?name=MContent&pageid=94</ref>.

'''Note''': 'Misc devices have a specific setup; you can find the list of misc devices with the corresponding MINOR number in the ''/proc/misc'' file.

=== Device entries in /dev ===
Each device has a corresponding entry in the /dev directory of the Linux kernel [[Pseudo filesystem|pseudo filesystem]].
 {{Board$}} ls -lR /dev
{{highlight|Be careful, /dev contains some sub-directories containing device entries, that is, ''input''. That the reason why ''-R'' should be used.}}

This command lists all of the device entries, including the device type and the associated MAJOR and MINOR numbers<br>


For example:
 {{Highlight|c}}rw-rw---- 1 root video {{Highlight|81}}, {{Highlight|0}} Dec 18 16:26 video0
:This device ''video0'' is of type character (c), with MAJOR number of 81 and MINOR number of 0.

=== System device entries in /sys/dev ===
All devices, classified by type (char or block), and identified by their MAJOR/MINOR number can be found in the ''dev'' subdirectory of the sysfs file system entry (''/sys'').

A platform device is then linked to each MAJOR/MINOR number.

For example:
 {{Board$}} ls -l /sys/dev/char/{{highlight|81\:0}}
 lrwxrwxrwx 1 root root 0 Dec 18 17:00 {{highlight|81:0}} -> ../../devices/platform/soc/{{Highlight|4c006000.dcmi/video4linux/video0}}
:The device ''video0'' is linked to the platform device ''4c006000.dcmi/video4linux/video0''.

=== Driver associated to a platform device ===
If the device is linked to a platform device, you can find the corresponding driver definition in the device tree with the compatible parameter.
{{UpdateNeededForNewRelease|Below InteralInfo banner to be removed}}
{{InternalInfo|When the DT for DCMI is upstreamed, it is convenient to link to stm32mp15c.dtsi instead of the "(device tree file for STM32MP15 in arch/arm/boot/dts Linux kernel source path)"}}For example:
Look for device {{highlight|4c006000.dcmi/video4linux/video0}} in stm32mp15c.dtsi (the device tree file for the STM32MP15 in ''{{CodeSource | Linux kernel | arch/arm/boot/dts'' Linux kernel source path)/stm32mp157c.dtsi}}....
 dcmi: dcmi@4c006000 {
  compatible {{=}} "{{Highlight|st,stm32-dcmi}}";
  reg = <0x4c006000 0x400>;
  interrupts = <GIC_SPI 78 IRQ_TYPE_NONE>;
  resets = <&rcc CAMITF_R>;
  clocks = <&rcc DCMI>;
  clock-names = "mclk";
  dmas = <&dmamux1 75 0x400 0x05>;
  dma-names = "tx";
  status = "disabled";
 };
 ...

:The driver associated to the video0 device is ''{{highlight|st,stm32-dcmi}}''.

If the driver belongs to your Linux kernel tree, you can search for the driver by declaring st,stm32-dcmi as a compatible device.
* In the previous example, when looking for the driver compatible with ''st,stm32-dcmi'', you find ''drivers/media/platform/stm32/stm32-dcmi.c'' driver
 {{PC$}} cd {{orange|''<your_kernel_source_path>''}}
 {{PC$}} grep -rs "st,stm32-dcmi" *
 ...
 {{Highlight|drivers/media/platform/stm32/stm32-dcmi.c}}:	{ .compatible = "st,stm32-dcmi"},
 ...

If the driver is not part of your Linux kernel source tree, it is present as a kernel object library file and you can check on the board:
 {{Board$}} cd /lib/modules/{{orange|<''kernel_version''>}}
 {{Board$}} grep {{orange|<''compatible_name''>}} modules.alias

This gives you the name of the module driver.

For example, for the gcnano driver used for the GPU:
 {{Board$}} grep "st,gcnano" modules.alias
  alias of:N*T*Cst,gcnano {{Highlight|galcore}}

This means that the module name is ''{{highlight|galcore.ko}}''.

== References ==<references />


{{ PublicationRequestId | 9236 | 24Oct'18 }}

[[Category:How to trace and debug]]
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
<noinclude>
 
{{ArticleMainWriter | Jean-PhilippeR}}
 
{{ ArticleApprovedVersion | Jean-PhilippeR | Jean-ChristopheT, AlexandreT | No previous approved version  | PhilipS - 24Oct'18 - 9236 | 25Oct'18 }}
 
 
[[Category:How to trace and debug]]
 
</noinclude>
 
 
 
== Introduction ==
 
== Introduction ==
 
This article shows the user how to find the Linux<sup>&reg;</sup> kernel driver associated to a kernel device.
 
This article shows the user how to find the Linux<sup>&reg;</sup> kernel driver associated to a kernel device.
Line 84: Line 77:
 
  254 virtblk
 
  254 virtblk
 
  259 blkext
 
  259 blkext
 
{{UpdateNeededForNewRelease|Below InteralInfo banner to be removed}}
 
{{InternalInfo|<br/>
 
With Beta1 DV and earlier, UART are linked to TTYS*<br/>
 
Character devices:
 
  1 mem
 
  2 pty
 
  3 ttyp
 
  4 /dev/vc/0
 
  4 tty
 
  5 /dev/tty
 
  5 /dev/console
 
  5 /dev/ptmx
 
  5 ttyRPMSG
 
  7 vcs
 
  10 misc
 
  13 input
 
  21 sg
 
  29 fb
 
  81 video4linux
 
  89 i2c
 
  90 mtd
 
116 alsa
 
128 ptm
 
136 pts
 
153 spi
 
166 ttyACM
 
180 usb
 
189 usb_device
 
199 galcore
 
226 drm
 
245 cec
 
246 media
 
247 ttyS
 
248 bsg
 
249 watchdog
 
250 iio
 
251 ptp
 
252 pps
 
253 rtc
 
254 gpiochip
 
 
Block devices:
 
  1 ramdisk
 
  7 loop
 
  8 sd
 
  11 sr
 
  31 mtdblock
 
  65 sd
 
  66 sd
 
  67 sd
 
  68 sd
 
  69 sd
 
  70 sd
 
  71 sd
 
128 sd
 
129 sd
 
130 sd
 
131 sd
 
132 sd
 
133 sd
 
134 sd
 
135 sd
 
179 mmc
 
254 virtblk
 
259 blkext
 
}}
 
   
 
For further information about the major and minor numbers for a Linux kernel driver, refer to the Linux tutorial web page<ref>http://www.linux-tutorial.info/modules.php?name=MContent&pageid=94</ref>.
 
For further information about the major and minor numbers for a Linux kernel driver, refer to the Linux tutorial web page<ref>http://www.linux-tutorial.info/modules.php?name=MContent&pageid=94</ref>.
Line 180: Line 106:
 
If the device is linked to a platform device, you can find the corresponding driver definition in the device tree with the compatible parameter.
 
If the device is linked to a platform device, you can find the corresponding driver definition in the device tree with the compatible parameter.
   
{{UpdateNeededForNewRelease|Below InteralInfo banner to be removed}}
 
{{InternalInfo|When the DT for DCMI is upstreamed, it is convenient to link to stm32mp15c.dtsi instead of the "(device tree file for STM32MP15 in arch/arm/boot/dts Linux kernel source path)"}}
 
 
For example:
 
For example:
Look for device {{highlight|4c006000.dcmi/video4linux/video0}} in stm32mp15c.dtsi (the device tree file for the STM32MP15 in ''arch/arm/boot/dts'' Linux kernel source path)
+
Look for device {{highlight|4c006000.dcmi/video4linux/video0}} in {{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp157c.dtsi}}.
 
  ...
 
  ...
 
  dcmi: dcmi@4c006000 {
 
  dcmi: dcmi@4c006000 {
Line 222: Line 146:
 
== References ==
 
== References ==
 
<references />
 
<references />
  +
  +
{{ PublicationRequestId | 9236 | 24Oct'18 }}
  +
  +
[[Category:How to trace and debug]]

Attachments

Discussions