€•CŒ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ŒPortuguese (Brazilian)”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ4/translations/pt_BR/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”…””}”(hjh²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.”…””}”(hjh²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.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´Khhÿh²hubhÌ)”}”(hXHThe 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 buses carry, and a set of common callbacks, such as device discovery during bus probing, bus shutdown, bus power management, etc.”h]”hXHThe 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 buses carry, and a set of common callbacks, such as device discovery during bus probing, bus shutdown, bus power management, etc.”…””}”(hj,h²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”…””}”(hjSh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hºhjPh²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.”…””}”(hjah²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K)hjPh²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:”…””}”(hjoh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K-hjPh²hubhŒ literal_block”“”)”}”(hŒdstruct pci_dev { ... struct device dev; /* Generic device interface */ ... };”h]”hŒdstruct pci_dev { ... struct device dev; /* Generic device interface */ ... };”…””}”hjsbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1j}h³hÊh´K0hjPh²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.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K7hjPh²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.”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´K:hjPh²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?hjPh²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´KEhjPh²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²hubj~)”}”(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&]”jjŽuh1j}h³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²hubj~)”}”(hŒ9none /sys sysfs defaults 0 0”h]”hŒ9none /sys sysfs defaults 0 0”…””}”hjsbah}”(h]”h ]”h"]”h$]”h&]”jjŽuh1j}h³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:”…””}”(hj&h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KbhjÏh²hubj~)”}”(hŒ;none /sys sysfs nodev,noexec,nosuid 0 0”h]”hŒ;none /sys sysfs nodev,noexec,nosuid 0 0”…””}”hj4sbah}”(h]”h ]”h"]”h$]”h&]”jjŽuh1j}h³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:”…””}”(hjBh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hËh³hÊh´KfhjÏh²hubj~)”}”(hŒ# mount -t sysfs sysfs /sys”h]”hŒ# mount -t sysfs sysfs /sys”…””}”hjPsbah}”(h]”h ]”h"]”h$]”h&]”jjŽuh1j}h³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.”…””}”(hj^h²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.”…””}”(hjlh²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.”…””}”(hjzh²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.”…””}”(hjˆh²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”}”(j±j®jMjJjÌjÉj©j¦uŒ nametypes”}”(j±‰jM‰j̉j©‰uh}”(j®h·jJhÿjÉjPj¦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.