How does the OS know which device driver to call?

I was always opening and write/readfrom device files / files and read on operating systems, but I never understood how the device driver is inevitably called.

For example, when we execute write- stdout, which is equal fd=1.
When I do write, I understand that the OS calls the device driver for this specific device file, which is already open, but I do not understand how we get into the device driver itself.


  • What is required in order for the device file (i.e. stdout) to be even created in the first place? Installation? Loading a kernel module?

  • (Followup to [1]) So, if I have a peripheral device, such as a single LED, that is connected to my computer using the correct device drivers for the LED already installed, and the device file created in /dev/singleled, what happens when I call openin /dev/singleled?

(In particular)

  • How does the OS know which device driver calls this device file when I call writeto it?
  • Do we store information in a file descriptor when we make opendevices in this file?

I really want to understand how this installation is created.
Thanks to everyone in advance.

+4
source share
2 answers

, ls -l , mknod, .

.

, .

, sysfs, .. /sys/class/LED/xxx, , / .

, , /dev, /sys, . /, , .

+2

( ) ​​ , , . , , .

, , ( , , ) . , , , . compatible , .

, , :

  ps7_axi_interconnect_0: axi@0 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "xlnx,ps7-axi-interconnect-1.00.a", "simple-bus";
ranges ;
gic: interrupt-controller@f8f01000 {
  #interrupt-cells = < 3 >;
  compatible = "arm,cortex-a9-gic";
  interrupt-controller ;
  reg = < 0xf8f01000 0x1000  >,< 0xf8f00100 0x100  >;
} ;
pl310: pl310-controller@f8f02000 {
  arm,data-latency = < 3 2 2 >;
  arm,tag-latency = < 2 2 2 >;
  cache-level = < 2 >;
  cache-unified ;
  compatible = "arm,pl310-cache";
  interrupts = < 0 34 4 >;
  reg = < 0xf8f02000 0x1000 >;
} ;

  [ ... more items ... ]

xillybus_0: xillybus@50000000 {
  compatible = "xlnx,xillybus-1.00.a";
  reg = < 0x50000000 0x1000 >;
  interrupts = < 0 59 1 >;
  interrupt-parent = <&gic>;
  xlnx,max-burst-len = <0x10>;
  xlnx,native-data-width = <0x20>;
  xlnx,slv-awidth = <0x20>;
  xlnx,slv-dwidth = <0x20>;
  xlnx,use-wstrb = <0x1>;
} ;

};

compatible. , node, - :

static struct of_device_id xillybus_of_match[] __devinitdata = {
  { .compatible = "xlnx,xillybus-1.00.a", },
  {}
};

MODULE_DEVICE_TABLE(of, xillybus_of_match);
/********something else*******/
static struct platform_driver xillybus_platform_driver = {
  .probe = xilly_drv_probe,
  .remove = xilly_drv_remove,
  .driver = {
    .name = "xillybus",
    .owner = THIS_MODULE,
    .of_match_table = xillybus_of_match,
  },
};

, , . , .

git , , compatible , . C, . , C, , open close ..

0

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


All Articles