This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] AM6442:在 Linux 内核驱动程序和 R5F 之间创建 IPC

Guru**** 2487425 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1441319/am6442-creating-ipc-between-linux-kernel-driver-and-r5f

您、好、Nick

我们以前使用 rpmsg_char_zerocopy 在应用层发送和接收数据。 现在、我们希望在内核层发送和接收数据、因为我们有自己的内核驱动程序。 我们不确定内核层是否有这样的接口允许在 A53和 R5F 之间直接传输和接收数据。

此致、
Mack
对于未来的读者、这是上讨论的继续  
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Mack、您好!

    内核级别绝对有一个接口用于在 Linux A53和 R5F 之间发送和接收数据。 事实上、您可以使用低级邮箱驱动程序来实现该内核驱动程序通信、而不是 RPMsg。 邮箱的延迟应比 RPMsg 低得多。

    在本线程中、我深入探讨了如何使用邮箱从 Linux 向 R5F 发送"平稳关机"消息。 希望这能让您了解如何在内核驱动程序中开始邮箱通信: https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1420796/sk-am62b-p1-how-to-enable-graceful-shutdown-of-remote-cores-with-multithreading-in-freertos-threads

    如果您需要更多指导、请在此处告诉我。 如果您想进行代码审核、可随时将您的代码交给 Kevin、以便他与我分享。

    此致、

    Nick

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Mack:

    在遵循 Nick 的建议后、您是否有任何进一步的支持需求?

    谢谢!

    Kevin

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    大家好、Kevin

    根据 Nick 的建议、我们目前正在准备进行测试。

    谢谢、

    Mack

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Nick J ü、

    1. 邮箱能否处理8K 的发送和接收数据量?
    2. Linux 内核中的邮箱驱动程序位于哪个文件中? 由于我们有另一个驱动程序需要直接访问该邮箱、所以我们要修改该邮箱驱动程序、这是否可行? 如果是、您能否提供有关如何处理此问题的一般概念?

    此致、

    Mack

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Mack、您好!

    邮箱本身只是与32位寄存器配对的中断。 所以、您将使用一个共享存储器区域来实际传递数据、然后使用邮箱来在存储器区域准备好被读取时快速发送一个通知。

    为了确保我理解:您想要多个不同的 Linux 驱动程序访问完全相同的邮箱队列? 为什么不为每个 Linux 驱动程序提供专用的邮箱队列?

    此致、

    Nick

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Nick。

    这可能是我的误解,因为我认为邮箱是一个独立的驱动程序。 根据您的说法、如果我想在我自己的 Linux 驱动程序中设置一个专用的邮箱队列来与 R5F 通信、我该怎么做? 是否有示例?

    此致、

    Mack

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Mack、您好!

    供参考:讨论分为2个主题

    我已将讨论拆分为两个线程:
    上一个主题是关于 IPC 基准测试和零复制示例
    本新主题介绍如何在 Linux 驱动程序和远程内核之间创建 IPC

    有关邮箱外设的更多详细信息

    有关更多信息、请参阅 AM64x 技术参考手册(TRM)的处理器间通信(IPC)>邮箱一节。

    邮箱外设中包含8个集群。 每个群集有16个队列。 每个队列最多可容纳4条消息。 每条消息为32位。

    当我们说我们为两个内核之间的 IPC 分配一个邮箱时、我们实际上是在分配一个特定的邮箱队列

    其中也有几个有关您的设计的重要详细信息:

    1)您需要为每个方向分配不同的邮箱队列。

    那么、假设您要在1个 Linux 驱动程序和4个 R5F 内核之间进行通信。 通常需要设置8个邮箱队列进行通信:
    - 4邮箱队列用于从 Linux 驱动程序向每个 R5F 内核发送消息
    -每个 R5F 内核有4个邮箱队列,用于向 Linux 驱动程序发送消息

    2)一次最多只能有4封未读邮箱邮件。 因此、如果 Linux 尝试发送第5个邮箱消息到其中一个 R5F 内核、但 R5F 内核尚未读取之前4个邮箱消息中的任何一个、则 Linux 将等待发送第5个邮箱消息。 我们不支持覆盖已在邮箱队列中的邮件。

    有关邮箱驱动程序的更多详细信息  

    邮箱驱动程序是一款低级内核驱动程序。 这意味着此驱动程序设计为供其他 Linux 驱动程序使用、而不是供用户空间使用。

    Linux remoteproc 和 rpmsg 驱动程序是使用邮箱驱动程序进行低级通信的2个驱动程序、因此我们可以将它们作为您想要如何编写自定义内核驱动程序的示例。

    我们来看看 AM64x SDK 10.0、 arch/arm64/boot/dts/ti/k3-am642-evm.dts、以了解如何 配置邮箱设置以及将邮箱信息传递给 Remoteproc 驱动程序的示例:

    // the mailboxes are configured here
    
    &mailbox0_cluster2 {
        status = "okay";
    
        mbox_main_r5fss0_core0: mbox-main-r5fss0-core0 {
            ti,mbox-rx = <0 0 2>;
            ti,mbox-tx = <1 0 2>;
        };
    
        mbox_main_r5fss0_core1: mbox-main-r5fss0-core1 {
            ti,mbox-rx = <2 0 2>;
            ti,mbox-tx = <3 0 2>;
        };
    };
    
    &mailbox0_cluster4 {
        status = "okay";
    
        mbox_main_r5fss1_core0: mbox-main-r5fss1-core0 {
            ti,mbox-rx = <0 0 2>;
            ti,mbox-tx = <1 0 2>;
        };
    
        mbox_main_r5fss1_core1: mbox-main-r5fss1-core1 {
            ti,mbox-rx = <2 0 2>;
            ti,mbox-tx = <3 0 2>;
        };
    };
    
    &mailbox0_cluster6 {
        status = "okay";
    
        mbox_m4_0: mbox-m4-0 {
            ti,mbox-rx = <0 0 2>;
            ti,mbox-tx = <1 0 2>;
        };
    };
    

    // we pass the associated mailbox to the Linux remoteproc driver here
    
    &main_r5fss0_core0 {
        mboxes = <&mailbox0_cluster2 &mbox_main_r5fss0_core0>;
        memory-region = <&main_r5fss0_core0_dma_memory_region>,
                <&main_r5fss0_core0_memory_region>;
    };
    
    &main_r5fss0_core1 {
        mboxes = <&mailbox0_cluster2 &mbox_main_r5fss0_core1>;
        memory-region = <&main_r5fss0_core1_dma_memory_region>,
                <&main_r5fss0_core1_memory_region>;
    };
    
    &main_r5fss1_core0 {
        mboxes = <&mailbox0_cluster4 &mbox_main_r5fss1_core0>;
        memory-region = <&main_r5fss1_core0_dma_memory_region>,
                <&main_r5fss1_core0_memory_region>;
    };
    
    &main_r5fss1_core1 {
        mboxes = <&mailbox0_cluster4 &mbox_main_r5fss1_core1>;
        memory-region = <&main_r5fss1_core1_dma_memory_region>,
                <&main_r5fss1_core1_memory_region>;
    };
    
    &mcu_m4fss {
        mboxes = <&mailbox0_cluster6 &mbox_m4_0>;
        memory-region = <&mcu_m4fss_dma_memory_region>,
                <&mcu_m4fss_memory_region>;
        status = "okay";
    };
    

    此致、

    Nick

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Nick

    1、在 ti-linux-kernel-6.6.32内核中、我找到了邮箱驱动程序、位于drivers/mailbox/omap-mailbox.c。 但是、我只能在其中看到邮箱数据的发送。 为什么没有收到邮箱数据?

    2、另一个问题:邮箱集群可以一次发送2K 的数据,还是需要分批发送?

    此致、

    Mack

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Mack、您好!

    您可以看到、邮箱的 devicetree 节点同时定义了一个"TX"邮箱和一个"Rx"邮箱。 因此我希望 Linux 邮箱驱动程序能够"发送"和"接收"。

    如果我们检查绑定文档、我们可以看到有 RX 和 TX 功能:

    ti-linux-kernel-6.6.32+git-ti/arch/arm64/boot/dts/ti$ grep -r --include=k3-am64* mailbox0_cluster4
    k3-am64-main.dtsi:      mailbox0_cluster4: mailbox@29040000 {
    k3-am642-evm.dts:&mailbox0_cluster4 {
    k3-am642-evm.dts:       mboxes = <&mailbox0_cluster4 &mbox_main_r5fss1_core0>;
    k3-am642-evm.dts:       mboxes = <&mailbox0_cluster4 &mbox_main_r5fss1_core1>;
    grep: k3-am642-evm.dtb: binary file matches
    k3-am64-phycore-som.dtsi:&mailbox0_cluster4 {
    k3-am64-phycore-som.dtsi:       mboxes = <&mailbox0_cluster4 &mbox_main_r5fss1_core0>;
    k3-am64-phycore-som.dtsi:       mboxes = <&mailbox0_cluster4 &mbox_main_r5fss1_core1>;
    k3-am642-sk.dts:&mailbox0_cluster4 {
    k3-am642-sk.dts:        mboxes = <&mailbox0_cluster4 &mbox_main_r5fss1_core0>;
    k3-am642-sk.dts:        mboxes = <&mailbox0_cluster4 &mbox_main_r5fss1_core1>;
    k3-am642-tqma64xxl.dtsi:&mailbox0_cluster4 {
    k3-am642-tqma64xxl.dtsi:        mboxes = <&mailbox0_cluster4 &mbox_main_r5fss1_core0>;
    k3-am642-tqma64xxl.dtsi:        mboxes = <&mailbox0_cluster4 &mbox_main_r5fss1_core1>;
    
    // let's get the compatibility string so we can find the driver
    ti-linux-kernel-6.6.32+git-ti/arch/arm64/boot/dts/ti$ vi k3-am64-main.dtsi
    
    // now look at the bindings documentation
    // this talks about devicetree usage
    ti-linux-kernel-6.6.32+git-ti/arch/arm64/boot/dts/ti$ cd ../../../../../Documentation/devicetree/bindings/
    ti-linux-kernel-6.6.32+git-ti/Documentation/devicetree/bindings$ grep -r 'ti,am64-mailbox'
    mailbox/ti,omap-mailbox.yaml:      - ti,am64-mailbox  # for K3 AM64x SoCs
    mailbox/ti,omap-mailbox.yaml:            - ti,am64-mailbox
    ti-linux-kernel-6.6.32+git-ti/Documentation/devicetree/bindings$ vi mailbox/ti,omap-mailbox.yaml
    

    如果您查看驱动程序、将看到为接收数据而设置的 ISR:

    ti-linux-kernel-6.6.32+git-ti/Documentation/devicetree/bindings$ cd ../../../drivers/
    ti-linux-kernel-6.6.32+git-ti/drivers$ grep -r 'ti,am64-mailbox'
    grep: mailbox/omap-mailbox.o: binary file matches
    mailbox/omap-mailbox.c:         .compatible     = "ti,am64-mailbox",
    ti-linux-kernel-6.6.32+git-ti/drivers$ vi mailbox/omap-mailbox.c

    我不确定驱动程序的确切使用方式、但我怀疑您没有调用特定函数到.receive_data。 相反、当收到邮箱且 ISR 代码运行时、你会得到一个中断。

    Remoteproc 驱动程序应提供有关发送和接收邮箱的更多详细信息。

    此致、

    Nick