<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SEMA4 on Linux userspace in i.MX Processors</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1700808#M210445</link>
    <description>&lt;P&gt;That’s nice! Yeah, I messed around with the driver but ended up realizing didn’t need to deal with it. &lt;LI-EMOJI id="lia_winking-face" title=":winking_face:"&gt;&lt;/LI-EMOJI&gt; Cheers.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Aug 2023 07:08:38 GMT</pubDate>
    <dc:creator>BitBakery</dc:creator>
    <dc:date>2023-08-08T07:08:38Z</dc:date>
    <item>
      <title>SEMA4 on Linux userspace</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1494195#M192883</link>
      <description>&lt;P&gt;Hi, I'd like to know if there's any examples or resources that explain how to deal with SEMA4 on Linux userspace. I want to access to the SEMA4 registers dynamically in the application. I'm using iMX8M Mini with imx-5.10.72 kernel. I tried accessing SEMA4 registers using a mmap'ed pointer, but only could read, writing to register simply froze it without errors. I'd appreciate it for any tips.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#It seems iMX6SX has its SEMA4 Linux driver. Would it be okay to reuse it for the Mini?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jul 2022 23:45:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1494195#M192883</guid>
      <dc:creator>BitBakery</dc:creator>
      <dc:date>2022-07-22T23:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: SEMA4 on Linux userspace</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1494285#M192894</link>
      <description>&lt;P&gt;you can check AIPS3 memory check to find the SEMA4, they should access by user space if they are R/W, if the register is readable only, maybe you couldn't write this, and you can refer to the imx6sx as example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jul 2022 05:26:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1494285#M192894</guid>
      <dc:creator>joanxie</dc:creator>
      <dc:date>2022-07-23T05:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: SEMA4 on Linux userspace</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1494334#M192910</link>
      <description>&lt;P&gt;Thanks for your reply. The reference manual says the SEMA4 gates are R/W registers, I don't know why I can't write on them from Linux.. By the way, SEMA4 node is missing under the AIPS3 in the imx8mm device tree. Is there a specific reason for that? Would it be okay to add it manually, based on the imx6sx devicetree?&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jul 2022 21:07:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1494334#M192910</guid>
      <dc:creator>BitBakery</dc:creator>
      <dc:date>2022-07-23T21:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: SEMA4 on Linux userspace</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1495242#M193013</link>
      <description>&lt;P&gt;Reply to myself. I should have accessed to SEMA4 registers using a byte pointer..! It turns out that I missed it on the reference manual. Everything works fine now. Also, I could integrate the SEMA4 driver to iMX8MM&amp;nbsp;successfully.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 05:21:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1495242#M193013</guid>
      <dc:creator>BitBakery</dc:creator>
      <dc:date>2022-07-26T05:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: SEMA4 on Linux userspace</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1495679#M193054</link>
      <description>&lt;P&gt;you integrate the SEMA4 according to the imx6 successfully, right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 14:56:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1495679#M193054</guid>
      <dc:creator>joanxie</dc:creator>
      <dc:date>2022-07-26T14:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: SEMA4 on Linux userspace</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1495684#M193056</link>
      <description>&lt;P&gt;Yes, that's correct. I added the SEMA4 node to imx8mm device tree with its corresponding register address, then added the driver(source, Kconfig &amp;amp; Makefile). v5.10.72 kernel probed it alright according to dmesg. Thanks.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 15:11:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1495684#M193056</guid>
      <dc:creator>BitBakery</dc:creator>
      <dc:date>2022-07-26T15:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: SEMA4 on Linux userspace</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1495696#M193057</link>
      <description>&lt;P&gt;thanks for sharing, imx8mm doesn't have much information about this like imx6, but I think they should be similar, good to know that it works&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 15:30:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1495696#M193057</guid>
      <dc:creator>joanxie</dc:creator>
      <dc:date>2022-07-26T15:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: SEMA4 on Linux userspace</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1495708#M193058</link>
      <description>&lt;P&gt;Sure thing! As far as I see the reference manuals of the imx6 and 8, SEMA4 looked identical(structure, offsets, etc)&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 15:45:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1495708#M193058</guid>
      <dc:creator>BitBakery</dc:creator>
      <dc:date>2022-07-26T15:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: SEMA4 on Linux userspace</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1694189#M209802</link>
      <description>&lt;P&gt;I'd like to revive this thread to ask how the SEMA4 driver can actually be used from Linux user space. Based on the hints provided by&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/196136"&gt;@BitBakery&lt;/a&gt;&amp;nbsp;I was able to build a Yocto mickledore image for the IMX8MN-EVK board where the SEMA4 driver is enabled in the kernel.&lt;/P&gt;&lt;P&gt;Are there any examples how to use the SEMA4 driver from Linux userspace?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 12:21:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1694189#M209802</guid>
      <dc:creator>stmatscaps</dc:creator>
      <dc:date>2023-07-27T12:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: SEMA4 on Linux userspace</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1700531#M210421</link>
      <description>&lt;P&gt;Hi, as far as you use SEMA4 on Linux userspace, you don't even need to enable the kernel driver. You can just access to SEMA4 registers directly via mmap'ing.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;How to access SEMA4 registers&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1. Find out the SEMA4 register addresses (base, gates, INE, NTF, etc). They should be on the reference manual. For example, SEMA4 base address for the iMX8MP is&amp;nbsp;0x30AC0000.&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. MMAP the base address so that you can access it from the userspace. You can access related registers by adding proper offsets to the base address. One thing to be aware of is that each register needs to be accessed by a specific type of pointer. (u8, u16, 32, etc). It's written in the reference manual.&amp;nbsp;&lt;/P&gt;&lt;P&gt;* You can't lock/unlock CP1 gates from CP0, vice versa. iMX8 looks where register access coming from and protect any improper write access.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ok, here's a rough sample code how to access the register. Hope this helps to give you an idea.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;unistd.h&amp;gt;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;fcntl.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;assert.h&amp;gt;
#include &amp;lt;sys/types.h&amp;gt;
#include &amp;lt;sys/stat.h&amp;gt;
#include &amp;lt;sys/ioctl.h&amp;gt;
#include &amp;lt;sys/mman.h&amp;gt;

#define PAGESIZE        (4096)
#define SEMA4_BASE      (0x30AC0000u)
#define SEMA4_UNLOCK    (0x0)
#define SEMA4_CP0_LOCK  (0x1)
#define SEMA4_CP1_LOCK  (0x2)

int main(void)
{
    void* pSEMA4 = NULL;
    volatile __u8 *mmPtr = NULL; 

    int fd = open("/dev/mem", O_RDWR);
    pSEMA4 = mmap(NULL, PAGESIZE, PROT_READ|PROT_WRITE,
			MAP_SHARED, fd, SEMA4_BASE);
	close(fd);
	assert(pSEMA4 != MAP_FAILED);

    // Locking SEMA4 Gate0 (CP0)
    // CP0 refers the application core, in my case it's A53. 
    mmPtr = (__u8 *)(pSEMA4 + 0x0); // Gate0 offset is 0x0
    *mmPtr = SEMA4_CP0_LOCK;
    if (*mmPtr == SEMA4_CP0_LOCK) {
        printf("SEMA4 lock success\n");
    } else {
        printf("SEMA4 lock failed : Currently locked by the other core\n");
    }

    // Unlocking
    *mmPtr = SEMA4_UNLOCK;
    if (*mmPtr == SEMA4_UNLOCK) {
        printf("SEMA4 unlock success\n");
    } else {
        printf("SEMA4 unlock failed : Currently locked by the other core\n");
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 23:16:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1700531#M210421</guid>
      <dc:creator>BitBakery</dc:creator>
      <dc:date>2023-08-07T23:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: SEMA4 on Linux userspace</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1700797#M210444</link>
      <description>&lt;P&gt;Thanks for the example,&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/196136"&gt;@BitBakery&lt;/a&gt;. This is similar to what I implemented in the meantime.&lt;/P&gt;&lt;P&gt;From the existing thread I had the impression that you had implemented a solution based on the driver, and I was interested how that would work. But after re-reading your messages I see now that I misunderstood that, and your example confirms my existing implementation.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 07:00:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1700797#M210444</guid>
      <dc:creator>stmatscaps</dc:creator>
      <dc:date>2023-08-08T07:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: SEMA4 on Linux userspace</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1700808#M210445</link>
      <description>&lt;P&gt;That’s nice! Yeah, I messed around with the driver but ended up realizing didn’t need to deal with it. &lt;LI-EMOJI id="lia_winking-face" title=":winking_face:"&gt;&lt;/LI-EMOJI&gt; Cheers.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 07:08:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/SEMA4-on-Linux-userspace/m-p/1700808#M210445</guid>
      <dc:creator>BitBakery</dc:creator>
      <dc:date>2023-08-08T07:08:38Z</dc:date>
    </item>
  </channel>
</rss>

