On 22/08/2021 12:45, Moustafa Nofal wrote:
> 
> Hi,
> I build Jailhouse on RPi4 using 5.3 Kernel and it is working nice. I
> need to toggle a GPIO pin. I tried baremetal code but I figured out,
> that I must map the peripheral using specifically this function:
> p->mem_fd = open("/dev/mem", O_RDWR|O_SYNC);
> So, I need the following headers to be included:
> /*For munmap, MAP_FAILED, MAP_SHARED, PROT_READ, PROT_WRITE*/> #include 
> <sys/mman.h>
> /* For open(), creat() */
> #include <unistd.h>
> /* For O_RDWR */
> #include <fcntl.h>

Do I understand correctly, that you want those header in your inmate?

> What could be a clean way, to add such headers into jailhouse, I have my
> own header-which describes addresses of GPIO registers- added to
> /inmates/lib/include, but is there any possible way to add these headers?

That's not the right approach to solve your issue. Having those standard
library functions means that you need tons of logic in your inmate,
including a fully-fledged operating systems.

What you actually want to do:
0. Pass the GPIO device to the inmate in your cell's config
1. Figure out the memory address of your GPIO controller + pin. For
   reference, consider looking at datasheets or device trees.
2. Map that address to your inmate using map_range()
   (instead of opening /dev/mem, there is no semantic at all for devices
    in our tiny libinmate)
3. directly write to the address

Other than that, have a look at demos/arm/gic-demo.c or
demos/x86/apic-demo.c. There we have the cmdline argument that allows
for specifying a led-pin, which is nothing else but a GPIO.


@Jan, BTW, I think I just found a bug in demos/arm/gic-demo.c: Since I
introduced arch_mmu_enable(), I forgot to map physical addresses for
map_range() for the led_reg. Will provide a patch soon…

  Ralf

> 
> Thanks in advance
> Moustafa Noufale
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Jailhouse" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected]
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jailhouse-dev/cd1adc59-e867-4ce1-a6ea-371ae1754cdan%40googlegroups.com
> <https://groups.google.com/d/msgid/jailhouse-dev/cd1adc59-e867-4ce1-a6ea-371ae1754cdan%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/434c3e0d-3f9d-cef4-faa8-e94248176db8%40oth-regensburg.de.

Reply via email to