€•/BŒsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ4/translations/zh_CN/driver-api/driver-model/overview”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/zh_TW/driver-api/driver-model/overview”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/it_IT/driver-api/driver-model/overview”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/ja_JP/driver-api/driver-model/overview”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/ko_KR/driver-api/driver-model/overview”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/sp_SP/driver-api/driver-model/overview”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒThe Linux Kernel Device Model”h]”hŒThe Linux Kernel Device Model”…””}”(hh¨hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hh£hžhhŸŒN/var/lib/git/docbuild/linux/Documentation/driver-api/driver-model/overview.rst”h KubhŒ paragraph”“”)”}”(hŒ+Patrick Mochel ”h]”(hŒPatrick Mochel <”…””}”(hh¹hžhhŸNh NubhŒ reference”“”)”}”(hŒmochel@digitalimplant.org”h]”hŒmochel@digitalimplant.org”…””}”(hhÃhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”Œ mailto:mochel@digitalimplant.org”uh1hÁhh¹ubhŒ>”…””}”(hh¹hžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khh£hžhubh¸)”}”(hŒ.Drafted 26 August 2002 Updated 31 January 2006”h]”hŒ.Drafted 26 August 2002 Updated 31 January 2006”…””}”(hhÝhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khh£hžhubh¢)”}”(hhh]”(h§)”}”(hŒOverview”h]”hŒOverview”…””}”(hhîhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hhëhžhhŸh¶h K ubh¸)”}”(hXThe Linux Kernel Driver Model is a unification of all the disparate driver models that were previously used in the kernel. It is intended to augment the bus-specific drivers for bridges and devices by consolidating a set of data and operations into globally accessible data structures.”h]”hXThe Linux Kernel Driver Model is a unification of all the disparate driver models that were previously used in the kernel. It is intended to augment the bus-specific drivers for bridges and devices by consolidating a set of data and operations into globally accessible data structures.”…””}”(hhühžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khhëhžhubh¸)”}”(hŒ¸Traditional driver models implemented some sort of tree-like structure (sometimes just a list) for the devices they control. There wasn't any uniformity across the different bus types.”h]”hŒºTraditional driver models implemented some sort of tree-like structure (sometimes just a list) for the devices they control. There wasn’t any uniformity across the different bus types.”…””}”(hj hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khhëhžhubh¸)”}”(hXIThe current driver model provides a common, uniform data model for describing a bus and the devices that can appear under the bus. The unified bus model includes a set of common attributes which all busses carry, and a set of common callbacks, such as device discovery during bus probing, bus shutdown, bus power management, etc.”h]”hXIThe current driver model provides a common, uniform data model for describing a bus and the devices that can appear under the bus. The unified bus model includes a set of common attributes which all busses carry, and a set of common callbacks, such as device discovery during bus probing, bus shutdown, bus power management, etc.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khhëhžhubh¸)”}”(hXØThe common device and bridge interface reflects the goals of the modern computer: namely the ability to do seamless device "plug and play", power management, and hot plug. In particular, the model dictated by Intel and Microsoft (namely ACPI) ensures that almost every device on almost any bus on an x86-compatible system can work within this paradigm. Of course, not every bus is able to support all such operations, although most buses support most of those operations.”h]”hXÜThe common device and bridge interface reflects the goals of the modern computer: namely the ability to do seamless device “plug and playâ€, power management, and hot plug. In particular, the model dictated by Intel and Microsoft (namely ACPI) ensures that almost every device on almost any bus on an x86-compatible system can work within this paradigm. Of course, not every bus is able to support all such operations, although most buses support most of those operations.”…””}”(hj&hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khhëhžhubeh}”(h]”Œoverview”ah ]”h"]”Œoverview”ah$]”h&]”uh1h¡hh£hžhhŸh¶h K ubh¢)”}”(hhh]”(h§)”}”(hŒDownstream Access”h]”hŒDownstream Access”…””}”(hj?hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hj<hžhhŸh¶h K'ubh¸)”}”(hŒÂCommon data fields have been moved out of individual bus layers into a common data structure. These fields must still be accessed by the bus layers, and sometimes by the device-specific drivers.”h]”hŒÂCommon data fields have been moved out of individual bus layers into a common data structure. These fields must still be accessed by the bus layers, and sometimes by the device-specific drivers.”…””}”(hjMhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K)hj<hžhubh¸)”}”(hŒpOther bus layers are encouraged to do what has been done for the PCI layer. struct pci_dev now looks like this::”h]”hŒoOther bus layers are encouraged to do what has been done for the PCI layer. struct pci_dev now looks like this:”…””}”(hj[hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K-hj<hžhubhŒ literal_block”“”)”}”(hŒdstruct pci_dev { ... struct device dev; /* Generic device interface */ ... };”h]”hŒdstruct pci_dev { ... struct device dev; /* Generic device interface */ ... };”…””}”hjksbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1jihŸh¶h K0hj<hžhubh¸)”}”(hŒŒNote first that the struct device dev within the struct pci_dev is statically allocated. This means only one allocation on device discovery.”h]”hŒŒNote first that the struct device dev within the struct pci_dev is statically allocated. This means only one allocation on device discovery.”…””}”(hj{hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K7hj<hžhubh¸)”}”(hXNote also that that struct device dev is not necessarily defined at the front of the pci_dev structure. This is to make people think about what they're doing when switching between the bus driver and the global driver, and to discourage meaningless and incorrect casts between the two.”h]”hX Note also that that struct device dev is not necessarily defined at the front of the pci_dev structure. This is to make people think about what they’re doing when switching between the bus driver and the global driver, and to discourage meaningless and incorrect casts between the two.”…””}”(hj‰hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K:hj<hžhubh¸)”}”(hXeThe PCI bus layer freely accesses the fields of struct device. It knows about the structure of struct pci_dev, and it should know the structure of struct device. Individual PCI device drivers that have been converted to the current driver model generally do not and should not touch the fields of struct device, unless there is a compelling reason to do so.”h]”hXeThe PCI bus layer freely accesses the fields of struct device. It knows about the structure of struct pci_dev, and it should know the structure of struct device. Individual PCI device drivers that have been converted to the current driver model generally do not and should not touch the fields of struct device, unless there is a compelling reason to do so.”…””}”(hj—hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K?hj<hžhubh¸)”}”(hXHThe above abstraction prevents unnecessary pain during transitional phases. If it were not done this way, then when a field was renamed or removed, every downstream driver would break. On the other hand, if only the bus layer (and not the device layer) accesses the struct device, it is only the bus layer that needs to change.”h]”hXHThe above abstraction prevents unnecessary pain during transitional phases. If it were not done this way, then when a field was renamed or removed, every downstream driver would break. On the other hand, if only the bus layer (and not the device layer) accesses the struct device, it is only the bus layer that needs to change.”…””}”(hj¥hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KEhj<hžhubeh}”(h]”Œdownstream-access”ah ]”h"]”Œdownstream access”ah$]”h&]”uh1h¡hh£hžhhŸh¶h K'ubh¢)”}”(hhh]”(h§)”}”(hŒUser Interface”h]”hŒUser Interface”…””}”(hj¾hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hj»hžhhŸh¶h KMubh¸)”}”(hŒýBy virtue of having a complete hierarchical view of all the devices in the system, exporting a complete hierarchical view to userspace becomes relatively easy. This has been accomplished by implementing a special purpose virtual file system named sysfs.”h]”hŒýBy virtue of having a complete hierarchical view of all the devices in the system, exporting a complete hierarchical view to userspace becomes relatively easy. This has been accomplished by implementing a special purpose virtual file system named sysfs.”…””}”(hjÌhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KOhj»hžhubh¸)”}”(hŒ›Almost all mainstream Linux distros mount this filesystem automatically; you can see some variation of the following in the output of the "mount" command::”h]”hŒžAlmost all mainstream Linux distros mount this filesystem automatically; you can see some variation of the following in the output of the “mount†command:”…””}”(hjÚhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KThj»hžhubjj)”}”(hŒB$ mount ... none on /sys type sysfs (rw,noexec,nosuid,nodev) ... $”h]”hŒB$ mount ... none on /sys type sysfs (rw,noexec,nosuid,nodev) ... $”…””}”hjèsbah}”(h]”h ]”h"]”h$]”h&]”jyjzuh1jihŸh¶h KWhj»hžhubh¸)”}”(hŒrThe auto-mounting of sysfs is typically accomplished by an entry similar to the following in the /etc/fstab file::”h]”hŒqThe auto-mounting of sysfs is typically accomplished by an entry similar to the following in the /etc/fstab file:”…””}”(hjöhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K]hj»hžhubjj)”}”(hŒ9none /sys sysfs defaults 0 0”h]”hŒ9none /sys sysfs defaults 0 0”…””}”hjsbah}”(h]”h ]”h"]”h$]”h&]”jyjzuh1jihŸh¶h K`hj»hžhubh¸)”}”(hŒJor something similar in the /lib/init/fstab file on Debian-based systems::”h]”hŒIor something similar in the /lib/init/fstab file on Debian-based systems:”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kbhj»hžhubjj)”}”(hŒ;none /sys sysfs nodev,noexec,nosuid 0 0”h]”hŒ;none /sys sysfs nodev,noexec,nosuid 0 0”…””}”hj sbah}”(h]”h ]”h"]”h$]”h&]”jyjzuh1jihŸh¶h Kdhj»hžhubh¸)”}”(hŒKIf sysfs is not automatically mounted, you can always do it manually with::”h]”hŒJIf sysfs is not automatically mounted, you can always do it manually with:”…””}”(hj.hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kfhj»hžhubjj)”}”(hŒ# mount -t sysfs sysfs /sys”h]”hŒ# mount -t sysfs sysfs /sys”…””}”hj<sbah}”(h]”h ]”h"]”h$]”h&]”jyjzuh1jihŸh¶h Khhj»hžhubh¸)”}”(hŒ¾Whenever a device is inserted into the tree, a directory is created for it. This directory may be populated at each layer of discovery - the global layer, the bus layer, or the device layer.”h]”hŒ¾Whenever a device is inserted into the tree, a directory is created for it. This directory may be populated at each layer of discovery - the global layer, the bus layer, or the device layer.”…””}”(hjJhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kjhj»hžhubh¸)”}”(hŒáThe global layer currently creates two files - 'name' and 'power'. The former only reports the name of the device. The latter reports the current power state of the device. It will also be used to set the current power state.”h]”hŒéThe global layer currently creates two files - ‘name’ and ‘power’. The former only reports the name of the device. The latter reports the current power state of the device. It will also be used to set the current power state.”…””}”(hjXhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Knhj»hžhubh¸)”}”(hŒ°The bus layer may also create files for the devices it finds while probing the bus. For example, the PCI layer currently creates 'irq' and 'resource' files for each PCI device.”h]”hŒ¸The bus layer may also create files for the devices it finds while probing the bus. For example, the PCI layer currently creates ‘irq’ and ‘resource’ files for each PCI device.”…””}”(hjfhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kshj»hžhubh¸)”}”(hŒuA device-specific driver may also export files in its directory to expose device-specific data or tunable interfaces.”h]”hŒuA device-specific driver may also export files in its directory to expose device-specific data or tunable interfaces.”…””}”(hjthžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kwhj»hžhubh¸)”}”(hŒœMore information about the sysfs directory layout can be found in the other documents in this directory and in the file Documentation/filesystems/sysfs.rst.”h]”hŒœMore information about the sysfs directory layout can be found in the other documents in this directory and in the file Documentation/filesystems/sysfs.rst.”…””}”(hj‚hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kzhj»hžhubeh}”(h]”Œuser-interface”ah ]”h"]”Œuser interface”ah$]”h&]”uh1h¡hh£hžhhŸh¶h KMubeh}”(h]”Œthe-linux-kernel-device-model”ah ]”h"]”Œthe linux kernel device model”ah$]”h&]”uh1h¡hhhžhhŸh¶h Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”h¶uh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(h¦NŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jÃŒerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”h¶Œ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(jjšj9j6j¸jµj•j’uŒ nametypes”}”(j‰j9‰j¸‰j•‰uh}”(jšh£j6hëjµj<j’j»uŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nhžhub.