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.
>
> > 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.
>
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.
> >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.
> 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.
> 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 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
>
> >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.
>
>
> >@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?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/560fff74-e071-4713-a1ec-e29b842f7564n%40googlegroups.com.