€•Ï1Œ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”Œ*/translations/zh_CN/i2c/dma-considerations”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/zh_TW/i2c/dma-considerations”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/it_IT/i2c/dma-considerations”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/ja_JP/i2c/dma-considerations”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/ko_KR/i2c/dma-considerations”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ*/translations/sp_SP/i2c/dma-considerations”Œ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ŒLinux I2C and DMA”h]”hŒLinux I2C and DMA”…””}”(hh¨hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hh£hžhhŸŒD/var/lib/git/docbuild/linux/Documentation/i2c/dma-considerations.rst”h KubhŒ paragraph”“”)”}”(hXoGiven that I2C is a low-speed bus, over which the majority of messages transferred are small, it is not considered a prime user of DMA access. At this time of writing, only 10% of I2C bus master drivers have DMA support implemented. And the vast majority of transactions are so small that setting up DMA for it will likely add more overhead than a plain PIO transfer.”h]”hXoGiven that I2C is a low-speed bus, over which the majority of messages transferred are small, it is not considered a prime user of DMA access. At this time of writing, only 10% of I2C bus master drivers have DMA support implemented. And the vast majority of transactions are so small that setting up DMA for it will likely add more overhead than a plain PIO transfer.”…””}”(hh¹hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khh£hžhubh¸)”}”(hXTherefore, it is *not* mandatory that the buffer of an I2C message is DMA safe. It does not seem reasonable to apply additional burdens when the feature is so rarely used. However, it is recommended to use a DMA-safe buffer if your message size is likely applicable for DMA. Most drivers have this threshold around 8 bytes (as of today, this is mostly an educated guess, however). For any message of 16 byte or larger, it is probably a really good idea. Please note that other subsystems you use might add requirements. E.g., if your I2C bus master driver is using USB as a bridge, then you need to have DMA safe buffers always, because USB requires it.”h]”(hŒTherefore, it is ”…””}”(hhÇhžhhŸNh NubhŒemphasis”“”)”}”(hŒ*not*”h]”hŒnot”…””}”(hhÑhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÏhhÇubhXw mandatory that the buffer of an I2C message is DMA safe. It does not seem reasonable to apply additional burdens when the feature is so rarely used. However, it is recommended to use a DMA-safe buffer if your message size is likely applicable for DMA. Most drivers have this threshold around 8 bytes (as of today, this is mostly an educated guess, however). For any message of 16 byte or larger, it is probably a really good idea. Please note that other subsystems you use might add requirements. E.g., if your I2C bus master driver is using USB as a bridge, then you need to have DMA safe buffers always, because USB requires it.”…””}”(hhÇhžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K hh£hžhubh¢)”}”(hhh]”(h§)”}”(hŒClients”h]”hŒClients”…””}”(hhìhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hhéhžhhŸh¶h Kubh¸)”}”(hXûFor clients, if you use a DMA safe buffer in i2c_msg, set the I2C_M_DMA_SAFE flag with it. Then, the I2C core and drivers know they can safely operate DMA on it. Note that using this flag is optional. I2C host drivers which are not updated to use this flag will work like before. And like before, they risk using an unsafe DMA buffer. To improve this situation, using I2C_M_DMA_SAFE in more and more clients and host drivers is the planned way forward. Note also that setting this flag makes only sense in kernel space. User space data is copied into kernel space anyhow. The I2C core makes sure the destination buffers in kernel space are always DMA capable. Also, when the core emulates SMBus transactions via I2C, the buffers for block transfers are DMA safe. Users of i2c_master_send() and i2c_master_recv() functions can now use DMA safe variants (i2c_master_send_dmasafe() and i2c_master_recv_dmasafe()) once they know their buffers are DMA safe. Users of i2c_transfer() must set the I2C_M_DMA_SAFE flag manually.”h]”hXûFor clients, if you use a DMA safe buffer in i2c_msg, set the I2C_M_DMA_SAFE flag with it. Then, the I2C core and drivers know they can safely operate DMA on it. Note that using this flag is optional. I2C host drivers which are not updated to use this flag will work like before. And like before, they risk using an unsafe DMA buffer. To improve this situation, using I2C_M_DMA_SAFE in more and more clients and host drivers is the planned way forward. Note also that setting this flag makes only sense in kernel space. User space data is copied into kernel space anyhow. The I2C core makes sure the destination buffers in kernel space are always DMA capable. Also, when the core emulates SMBus transactions via I2C, the buffers for block transfers are DMA safe. Users of i2c_master_send() and i2c_master_recv() functions can now use DMA safe variants (i2c_master_send_dmasafe() and i2c_master_recv_dmasafe()) once they know their buffers are DMA safe. Users of i2c_transfer() must set the I2C_M_DMA_SAFE flag manually.”…””}”(hhúhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khhéhžhubeh}”(h]”Œclients”ah ]”h"]”Œclients”ah$]”h&]”uh1h¡hh£hžhhŸh¶h Kubh¢)”}”(hhh]”(h§)”}”(hŒMasters”h]”hŒMasters”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjhžhhŸh¶h K(ubh¸)”}”(hŒ¸Bus master drivers wishing to implement safe DMA can use helper functions from the I2C core. One gives you a DMA-safe buffer for a given i2c_msg as long as a certain threshold is met::”h]”hŒ·Bus master drivers wishing to implement safe DMA can use helper functions from the I2C core. One gives you a DMA-safe buffer for a given i2c_msg as long as a certain threshold is met:”…””}”(hj!hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K*hjhžhubhŒ literal_block”“”)”}”(hŒ;dma_buf = i2c_get_dma_safe_msg_buf(msg, threshold_in_byte);”h]”hŒ;dma_buf = i2c_get_dma_safe_msg_buf(msg, threshold_in_byte);”…””}”hj1sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1j/hŸh¶h K.hjhžhubh¸)”}”(hX#If a buffer is returned, it is either msg->buf for the I2C_M_DMA_SAFE case or a bounce buffer. But you don't need to care about that detail, just use the returned buffer. If NULL is returned, the threshold was not met or a bounce buffer could not be allocated. Fall back to PIO in that case.”h]”hX%If a buffer is returned, it is either msg->buf for the I2C_M_DMA_SAFE case or a bounce buffer. But you don’t need to care about that detail, just use the returned buffer. If NULL is returned, the threshold was not met or a bounce buffer could not be allocated. Fall back to PIO in that case.”…””}”(hjAhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K0hjhžhubh¸)”}”(hŒ‹In any case, a buffer obtained from above needs to be released. Another helper function ensures a potentially used bounce buffer is freed::”h]”hŒŠIn any case, a buffer obtained from above needs to be released. Another helper function ensures a potentially used bounce buffer is freed:”…””}”(hjOhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K5hjhžhubj0)”}”(hŒ0i2c_put_dma_safe_msg_buf(dma_buf, msg, xferred);”h]”hŒ0i2c_put_dma_safe_msg_buf(dma_buf, msg, xferred);”…””}”hj]sbah}”(h]”h ]”h"]”h$]”h&]”j?j@uh1j/hŸh¶h K8hjhžhubh¸)”}”(hŒµThe last argument 'xferred' controls if the buffer is synced back to the message or not. No syncing is needed in cases setting up DMA had an error and there was no data transferred.”h]”hŒ¹The last argument ‘xferred’ controls if the buffer is synced back to the message or not. No syncing is needed in cases setting up DMA had an error and there was no data transferred.”…””}”(hjkhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K:hjhžhubh¸)”}”(hŒàThe bounce buffer handling from the core is generic and simple. It will always allocate a new bounce buffer. If you want a more sophisticated handling (e.g. reusing pre-allocated buffers), you are free to implement your own.”h]”hŒàThe bounce buffer handling from the core is generic and simple. It will always allocate a new bounce buffer. If you want a more sophisticated handling (e.g. reusing pre-allocated buffers), you are free to implement your own.”…””}”(hjyhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K>hjhžhubh¸)”}”(hŒ”Please also check the in-kernel documentation for details. The i2c-sh_mobile driver can be used as a reference example how to use the above helpers.”h]”hŒ”Please also check the in-kernel documentation for details. The i2c-sh_mobile driver can be used as a reference example how to use the above helpers.”…””}”(hj‡hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KBhjhžhubh¸)”}”(hŒÞFinal note: If you plan to use DMA with I2C (or with anything else, actually) make sure you have CONFIG_DMA_API_DEBUG enabled during development. It can help you find various issues which can be complex to debug otherwise.”h]”hŒÞFinal note: If you plan to use DMA with I2C (or with anything else, actually) make sure you have CONFIG_DMA_API_DEBUG enabled during development. It can help you find various issues which can be complex to debug otherwise.”…””}”(hj•hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KEhjhžhubeh}”(h]”Œmasters”ah ]”h"]”Œmasters”ah$]”h&]”uh1h¡hh£hžhhŸh¶h K(ubeh}”(h]”Œlinux-i2c-and-dma”ah ]”h"]”Œlinux i2c and dma”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­j j j¨j¥uŒ nametypes”}”(j°‰j ‰j¨‰uh}”(j­h£j héj¥juŒ 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.