On 22/08/2021 19:40, Moustafa Nofal wrote:
> 
> 
> On Sunday, 22 August 2021 at 15:42:12 UTC+2 Ralf Ramsauer wrote:
> 
> 
> 
>     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?
>     I am not sure about it, but I needed to know the correct procedure.

Please do _not_ reply with html mails in future. It's almost impossible
to figure out where you exactly responded. And please always reply to all.

> 
>  
> 
>     > 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?

Sorry, I think I don't understand the question. Of course, if you have
custom modifications, you can place you headers there.

> 
>     >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.
> 
> 
> I have done this in the inmate file, read the datasheet and device tree
> and edited also the .dts file in jailhouse, I wonder, whether it is
> necessary.

The device tree is only required if you use Linux in your inmate. If you
want to use the bare-metal inmate library, then you only need to adjust
the configuration of your inmate.

> 
>     >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)
> 
>  
> 
>     Yes, that was my problem, I tried accessing the registers directly,
>     but it must be mapped first, there are two solutions for this,
>     either using assembly code or use such a function.
>     I did not know about map_range, or whether jailhouse uses it, but I
>     will check and get back to you.

map_range is a routine of libinmate, it /belongs/ to jailhouse. Use "git
grep map_range" to see how it is used.

>     On the other hand, I found mmio_write32() for writing registers, but
>     I could not find the source file. Also timer_start(), I do not know
>     where is the definition of this function.

After you mapped the physical memory, you can then access registers with
mmio_write()-accessors. To find the definition of those routines, just
use git grep:

lib/arm-common/include/inmate.h:static inline void mmio_write32

>     One more question, I think you must have mapped the timer and UART0
>     peripherals, in order to be able to trigger it. I saw the memory

In order to trigger what? What is "it"? :)

>     region structure  in *rpi4-inmate-demo.c *and could understand, how
>     could you make it and implemented something similar for the GPIO. 
>     But where the initialization of the timer and uart, I mean in which
>     file, or how is that made

On arm, libinmate uses the platform timer. Take a look at
inmates/lib/arm-common/timing.c.

> 
>     >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.
>     Yes, this part I understand, but my experience was with
>     ARM-Cortex-M, so I thought I could just write to the register
>     without mapping it. But thanks for the information and would really
>     appreciate, if you could tell in which direction shall I dig.

On ARM, we use virtual memory management for inmates. So you definitely
need a mapping prior to accessing MMIO registers.

HTH,
  Ralf

> 
> 
>     >@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
>     Best regards,
>     Moustafa Noufale
>     >
>     > 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>
> 
>     >
>     
> <https://groups.google.com/d/msgid/jailhouse-dev/cd1adc59-e867-4ce1-a6ea-371ae1754cdan%40googlegroups.com?utm_medium=email&utm_source=footer
>     
> <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]
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jailhouse-dev/560fff74-e071-4713-a1ec-e29b842f7564n%40googlegroups.com
> <https://groups.google.com/d/msgid/jailhouse-dev/560fff74-e071-4713-a1ec-e29b842f7564n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
Mit freundlichen Grüßen

Ralf Ramsauer
Labor für Digitalisierung
Fakultät für Informatik und Mathematik

Ostbayerische Technische Hochschule Regensburg
Galgenbergstrasse 32
93053 Regensburg

Tel.: +49 (0)941 943-9267
E-Mail: [email protected]
http://www.oth-regensburg.de

-- 
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/a30c722d-4fc3-fd3a-f2c2-5dd80b2d8887%40oth-regensburg.de.

Reply via email to