Access I2C bus from guest/DomU on ARM board

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Access I2C bus from guest/DomU on ARM board

Saumya Rajesh

Hi Xen community


I have built and brought up Xen 4.8 on Renesas RCar H3. For a specific requirement, I need to use the I2C bus of the board from Domain U. Is there a way to use the I2C bus from the guest?
I have looked into para-virtualization and passthrough [1][2] but there isn't enough support or resources related to I2C bus sharing on ARM. Any possible idea would be appreciated.

Regards
Saumya




_______________________________________________
Xen-users mailing list
[hidden email]
https://lists.xenproject.org/mailman/listinfo/xen-users
Reply | Threaded
Open this post in threaded view
|

Re: [Xen-devel] Access I2C bus from guest/DomU on ARM board

Lars Kurth-4
Added [hidden email]

On 16 Jan 2018, at 13:39, Saumya Rajesh <[hidden email]> wrote:

Hi Xen community


I have built and brought up Xen 4.8 on Renesas RCar H3. For a specific requirement, I need to use the I2C bus of the board from Domain U. Is there a way to use the I2C bus from the guest?
I have looked into para-virtualization and passthrough [1][2] but there isn't enough support or resources related to I2C bus sharing on ARM. Any possible idea would be appreciated.

Regards
Saumya



_______________________________________________
Xen-devel mailing list
[hidden email]
https://lists.xenproject.org/mailman/listinfo/xen-devel


_______________________________________________
Xen-users mailing list
[hidden email]
https://lists.xenproject.org/mailman/listinfo/xen-users
Reply | Threaded
Open this post in threaded view
|

Re: [Xen-devel] Access I2C bus from guest/DomU on ARM board

Andrii Anisov
In reply to this post by Saumya Rajesh
Dear Rajesh,


You can try to get an I2C bus controller in DomU in PIO mode following
[1], keeping in mind [2].

If you want it DMA capable you need Renesas IPMMU support in XEN [3],
[4] to be incorporated.


[1] - https://xenbits.xen.org/docs/unstable/misc/arm/passthrough.txt

[2] -
https://lists.xenproject.org/archives/html/xen-users/2017-10/msg00031.html

[3] -
https://lists.xenproject.org/archives/html/xen-devel/2017-07/msg02545.html

[4] -
https://lists.xenproject.org/archives/html/xen-devel/2017-07/msg02679.html


--

*Andrii Anisov*



_______________________________________________
Xen-users mailing list
[hidden email]
https://lists.xenproject.org/mailman/listinfo/xen-users
Reply | Threaded
Open this post in threaded view
|

Re: [Xen-devel] Access I2C bus from guest/DomU on ARM board

Saumya Rajesh
On Tue, Jan 16, 2018 at 9:22 PM, Andrii Anisov <[hidden email]> wrote:
Dear Rajesh,


You can try to get an I2C bus controller in DomU in PIO mode following [1], keeping in mind [2].

If you want it DMA capable you need Renesas IPMMU support in XEN [3], [4] to be incorporated.


[1] - https://xenbits.xen.org/docs/unstable/misc/arm/passthrough.txt

[2] - https://lists.xenproject.org/archives/html/xen-users/2017-10/msg00031.html

[3] - https://lists.xenproject.org/archives/html/xen-devel/2017-07/msg02545.html

[4] - https://lists.xenproject.org/archives/html/xen-devel/2017-07/msg02679.html


--

*Andrii Anisov*



Thank you Andrii for replying. I will try the device passthrough way of using I2C bus from guest and post the updates. 

Just out of curiosity, is it possible to split the Driver for the Renesas RCar I2C unit [1] into frontend and backend to use the i2c bus from guest? Or to do something similar to PCI passthrough? Please forgive me if I sound illogical. I'm just curious.

Regards
Saumya


_______________________________________________
Xen-users mailing list
[hidden email]
https://lists.xenproject.org/mailman/listinfo/xen-users
Reply | Threaded
Open this post in threaded view
|

Re: [Xen-devel] Access I2C bus from guest/DomU on ARM board

Saumya Rajesh
On Wed, Jan 17, 2018 at 9:06 PM, Andrii Anisov <[hidden email]> wrote:
Rajesh,

On 17.01.18 16:03, Saumya Rajesh wrote:
Just out of curiosity, is it possible to split the Driver for the Renesas RCar I2C unit [1] into frontend and backend to use the i2c bus from guest? Or to do something similar to PCI passthrough? Please forgive me if I sound illogical. I'm just curious.
I guess you could implement PV I2C using FE/BE scheme. With enormous efforts and unpredictable results.
But I'm sure it is not what you really need.

--

*Andrii Anisov*



Hi Andrii

Actually I am planning to set up Android as guest in Xen. In order to enable sound in the Android guest, I need to passthrough the audio codec device which communicates through the I2C bus. For BE/FE scheme, I think sharing the internal DMA and clock would pose problems. So I'm going to go ahead with the device passthrough way. 

Any thoughts or inputs you can possibly give regarding this use case will be very helpful and valuable.

Regards
Saumya


_______________________________________________
Xen-users mailing list
[hidden email]
https://lists.xenproject.org/mailman/listinfo/xen-users
Reply | Threaded
Open this post in threaded view
|

Re: [Xen-devel] Access I2C bus from guest/DomU on ARM board

Saumya Rajesh
On Thu, Jan 18, 2018 at 1:20 PM, Saumya Rajesh <[hidden email]> wrote:

> On Wed, Jan 17, 2018 at 9:06 PM, Andrii Anisov <[hidden email]>
> wrote:
>>
>> Rajesh,
>>
>> On 17.01.18 16:03, Saumya Rajesh wrote:
>>>
>>> Just out of curiosity, is it possible to split the Driver for the Renesas
>>> RCar I2C unit [1] into frontend and backend to use the i2c bus from guest?
>>> Or to do something similar to PCI passthrough? Please forgive me if I sound
>>> illogical. I'm just curious.
>>
>> I guess you could implement PV I2C using FE/BE scheme. With enormous
>> efforts and unpredictable results.
>> But I'm sure it is not what you really need.
>>
>> --
>>
>> *Andrii Anisov*
>>
>>
>
> Hi Andrii
>
> Actually I am planning to set up Android as guest in Xen. In order to enable
> sound in the Android guest, I need to passthrough the audio codec device
> which communicates through the I2C bus. For BE/FE scheme, I think sharing
> the internal DMA and clock would pose problems. So I'm going to go ahead
> with the device passthrough way.
>
> Any thoughts or inputs you can possibly give regarding this use case will be
> very helpful and valuable.
>
> Regards
> Saumya
>

Hi

I am trying to passthrough I2C bus to guest domain in Xen. I am
referring [1][2][3] to implement this on Renesas R-Car H3. Following
is the list of all I2C buses available when not passed through :

root@salvator-x-xen-dom0:~# i2cdetect -l
i2c-2 i2c        e6510000.i2c                    I2C adapter
i2c-4 i2c        e66d8000.i2c                    I2C adapter
i2c-7 i2c        e60b0000.i2c                    I2C adapter
i2c-8 i2c        DesignWare HDMI                  I2C adapter
i2c-9 i2c        DesignWare HDMI                  I2C adapter

I added " xen,passthrough = "1"; " and built the Dom0 device tree to
enable I2C bus passthrough :

r8a7795.dtsi:

i2c2: i2c@e6510000 {
#address-cells = <1>;
#size-cells = <0>;
compatible = "renesas,i2c-r8a7795";
reg = <0 0xe6510000 0 0x40>;
interrupts = <GIC_SPI 286 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&cpg CPG_MOD 929>;
power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
dmas = <&dmac1 0x95>, <&dmac1 0x94>;
dma-names = "tx", "rx";
i2c-scl-internal-delay-ns = <6>;
status = "disabled";
xen,passthrough = "1";
};

After booting using the modified dtb, i2c-2 disappears, meaning it was
not taken by Dom0 :

root@salvator-x-xen-dom0:~# i2cdetect -l
i2c-4 i2c        e66d8000.i2c                    I2C adapter
i2c-7 i2c        e60b0000.i2c                    I2C adapter
i2c-8 i2c        DesignWare HDMI                  I2C adapter
i2c-9 i2c        DesignWare HDMI                  I2C adapter

I built a partial device tree guest_dtb_test.dtb using the following content :

guest_dtb_test.dts:
/dts-v1/;

/ {
    /* #*cells are here to keep DTC happy */
    #address-cells = <2>;
    #size-cells = <2>;

    aliases {
        i2c0 = &i2c0;
    };
passthrough {
compatible = "simple-bus";
ranges;
#address-cells = <2>;
#size-cells = <2>;
i2c0: i2c@10000000 {
compatible = "renesas,i2c-r8a7795";
reg = <0 0x10000000 0 0x40>;
interrupts = <0 286 4>;
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
};
};
};

I also added the following lines to DomU configuration file :

device_tree = "/root/guest_test_dtb.dtb"
dtdev = [ "/soc/i2c@e6510000" ]
irqs = [ 318 ]
iomem = [ "0xe6510,1" ]

But when I start DomU, the booting fails. Log of starting DomU :

root@salvator-x-xen-dom0:~# xl create -c Domu.cfg
Parsing config from Domu.cfg
[ 2160.083551] rcar_gen3_thermal e61a8000.thermal: Can't register thermal zone
(XEN) avc:  denied  { use } for domid=0 irq=318
scontext=system_u:system_r:domU_t tcontext=system_u:object_r:irq_t
tclass=resource
libxl: error: libxl_create.c:1284:domcreate_launch_dm: failed give
dom2 access to irq 318: Permission denied
libxl: error: libxl.c:1575:libxl__destroy_domid: non-existant domain 2
libxl: error: libxl.c:1534:domain_destroy_callback: unable to destroy
guest with domid 2

libxl: error: libxl.c:1463:domain_destroy_cb: destruction of domain 2 failed

Seeing the log, I guess the irq could not be given to DomU. It is
actually 286 + 32, as it was mentioned in [1].

Is there a workaround to this issue? Any solution or suggestion
related to this will be much appreciated.

Regards
Saumya

[1] https://xenbits.xen.org/docs/unstable/misc/arm/passthrough.txt
[2] https://events.static.linuxfound.org/sites/events/files/slides/talk_5.pdf
[3] https://lists.xenproject.org/archives/html/xen-users/2017-10/msg00031.html

_______________________________________________
Xen-users mailing list
[hidden email]
https://lists.xenproject.org/mailman/listinfo/xen-users
Reply | Threaded
Open this post in threaded view
|

Re: [Xen-devel] Access I2C bus from guest/DomU on ARM board

Saumya Rajesh
In reply to this post by Saumya Rajesh
On Wed, Jan 31, 2018 at 8:36 PM, Andrii Anisov <[hidden email]> wrote:

> Hello Saumya,
>
>
> On 18.01.18 09:50, Saumya Rajesh wrote:
>>
>> Actually I am planning to set up Android as guest in Xen.
>
> I see.
>
>> In order to enable sound in the Android guest, I need to passthrough the
>> audio codec device which communicates through the I2C bus. For BE/FE scheme,
>> I think sharing the internal DMA and clock would pose problems. So I'm going
>> to go ahead with the device passthrough way.
>
> Passing through I2C bus to guest domain would not be enough to get sound in
> Android. You would face more dependencies, and they may appear not solvable.
>
>> Any thoughts or inputs you can possibly give regarding this use case will
>> be very helpful and valuable.
>
> We are using PV Audio solution for such a task:
>
> https://lists.xenproject.org/archives/html/xen-devel/2017-03/msg02428.html
> https://lkml.org/lkml/2017/8/7/115
>
> --
>
> *Andrii Anisov*
>
>

Hi Andrii

I guess you are right. I am already facing issues in doing I2C bus
passthrough. If you find time, please look into [1][2].

I was able to successfully build and execute the PV Audio solution on
R-Car H3, with xen-front[3] as frontend and snd_be[4] as backend. The
only issue I encountered was that Dom0 could not use the sound card as
long as the backend application ran. It is the only working solution
that I have found till now.

I think I am back to square one but I can't help but ask if you are
familiar with any work which is going on in Xen which makes it
possible for the guest domain(Linux based) to interact with all kinds
of I2C devices such as audio SoCs or sensors?

Regards
Saumya

[1] https://lists.xenproject.org/archives/html/xen-devel/2018-01/msg02711.html
[2] https://lists.xenproject.org/archives/html/xen-devel/2018-01/msg02618.html
[3] https://lists.xen.org/archives/html/xen-devel/2017-08/msg00626.html
[4] https://github.com/xen-troops/snd_be

_______________________________________________
Xen-users mailing list
[hidden email]
https://lists.xenproject.org/mailman/listinfo/xen-users