Discussion:
Inheriting from Mmio class
Johannes Schlatow
2016-12-07 17:26:37 UTC
Permalink
Hi,

I really like Genode's Register API as it makes accessing memory mapped hardware registers quite clean and simple.

However, I recently encountered the need to access a rather complex I2C slave device. The I2C controller itself is accessible via MMIO. Yet, the slave device itself has a notion of registers. Basically, you first send the register address to the I2C slave and, in a second transaction, you can read/write the register's value.

Being used to the clean appearance of MMIO in Genode, I was wondering whether the access to I2C slave registers could be wrapped in a similar way. My intuition is that it might simply suffice to inherit from the Mmio class and modify the write<>() and read<>() functions but haven't checked the code in detail. Any suggestions/ideas?

Cheers
Johannes
Martin Stein
2016-12-08 14:37:05 UTC
Permalink
Hi Johannes,

We actually had an internal discussion about such an approach. As far as
I remember, it was in the context of the Zynq drivers. I absolutely like
the idea of using the Mmio framework with different back-ends. I think
you would have to exchange merely the two raw-access methods of the
framework:

! template <typename _ACCESS_T>
! void Mmio::_write(off_t const, _ACCESS_T const)'
!
! template <typename _ACCESS_T>
! _ACCESS_T Mmio::_read(off_t const) const

The read<>() and write<>() methods you mention should not contain any
code that depends on the way of accessing registers but only the bit and
offset logic that could be reused.

I'm curious about the outcome of your idea and help willingly if you
have further questions.

Cheers,
Martin
Post by Johannes Schlatow
Hi,
I really like Genode's Register API as it makes accessing memory mapped hardware registers quite clean and simple.
However, I recently encountered the need to access a rather complex I2C slave device. The I2C controller itself is accessible via MMIO. Yet, the slave device itself has a notion of registers. Basically, you first send the register address to the I2C slave and, in a second transaction, you can read/write the register's value.
Being used to the clean appearance of MMIO in Genode, I was wondering whether the access to I2C slave registers could be wrapped in a similar way. My intuition is that it might simply suffice to inherit from the Mmio class and modify the write<>() and read<>() functions but haven't checked the code in detail. Any suggestions/ideas?
Cheers
Johannes
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
genode-main mailing list
https://lists.sourceforge.net/lists/listinfo/genode-main
Martin Stein
2016-12-09 08:42:04 UTC
Permalink
Hey Johannes,

I could not get it out of my mind. What do you think of the following
solution scheme:

~~~util/io_space.h~~~

template <typename IO>
class Io_space
{
..
public:

Io_space(IO &io) ..

template .. struct Register ..;
template .. struct Register_array ..;

template .. read(..) { .. _io._read(..); .. }
template .. write(..) { .. _io._write(..); .. }
..
};

~~~util/mmio.h~~~

class Mmio : public Io_space<Mmio>
{
friend class Io_space<Mmio>;

private:

template .. _read(..) { .. }
template .. _write(..) { .. }

public:

Mmio_b(addr_t base) : Io_space<Mmio_accessor>(*this) ..
};

~~~i2c_io.h~~~

class I2c_io : public Io_space<I2c_io> { .. };

~~~~~~

This would keep the back-end hidden and enable diversification.

Cheers,
Martin
Post by Martin Stein
Hi Johannes,
We actually had an internal discussion about such an approach. As far as
I remember, it was in the context of the Zynq drivers. I absolutely like
the idea of using the Mmio framework with different back-ends. I think
you would have to exchange merely the two raw-access methods of the
! template <typename _ACCESS_T>
! void Mmio::_write(off_t const, _ACCESS_T const)'
!
! template <typename _ACCESS_T>
! _ACCESS_T Mmio::_read(off_t const) const
The read<>() and write<>() methods you mention should not contain any
code that depends on the way of accessing registers but only the bit and
offset logic that could be reused.
I'm curious about the outcome of your idea and help willingly if you
have further questions.
Cheers,
Martin
Post by Johannes Schlatow
Hi,
I really like Genode's Register API as it makes accessing memory mapped hardware registers quite clean and simple.
However, I recently encountered the need to access a rather complex I2C slave device. The I2C controller itself is accessible via MMIO. Yet, the slave device itself has a notion of registers. Basically, you first send the register address to the I2C slave and, in a second transaction, you can read/write the register's value.
Being used to the clean appearance of MMIO in Genode, I was wondering whether the access to I2C slave registers could be wrapped in a similar way. My intuition is that it might simply suffice to inherit from the Mmio class and modify the write<>() and read<>() functions but haven't checked the code in detail. Any suggestions/ideas?
Cheers
Johannes
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
genode-main mailing list
https://lists.sourceforge.net/lists/listinfo/genode-main
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
genode-main mailing list
https://lists.sourceforge.net/lists/listinfo/genode-main
Johannes Schlatow
2016-12-09 10:12:09 UTC
Permalink
Hey Martin,

looks great. I also had in mind that the generic part from Mmio should be separated as Mmio is already a specialisation of IO access.

So, how do we proceed. Do you want to do the refactoring yourself and I add the I2c implementation afterwards?

Cheers
Johannes

On Fri, 9 Dec 2016 09:42:04 +0100
Post by Martin Stein
Hey Johannes,
I could not get it out of my mind. What do you think of the following
~~~util/io_space.h~~~
template <typename IO>
class Io_space
{
..
Io_space(IO &io) ..
template .. struct Register ..;
template .. struct Register_array ..;
template .. read(..) { .. _io._read(..); .. }
template .. write(..) { .. _io._write(..); .. }
..
};
~~~util/mmio.h~~~
class Mmio : public Io_space<Mmio>
{
friend class Io_space<Mmio>;
template .. _read(..) { .. }
template .. _write(..) { .. }
Mmio_b(addr_t base) : Io_space<Mmio_accessor>(*this) ..
};
~~~i2c_io.h~~~
class I2c_io : public Io_space<I2c_io> { .. };
~~~~~~
This would keep the back-end hidden and enable diversification.
Cheers,
Martin
Post by Martin Stein
Hi Johannes,
We actually had an internal discussion about such an approach. As far as
I remember, it was in the context of the Zynq drivers. I absolutely like
the idea of using the Mmio framework with different back-ends. I think
you would have to exchange merely the two raw-access methods of the
! template <typename _ACCESS_T>
! void Mmio::_write(off_t const, _ACCESS_T const)'
!
! template <typename _ACCESS_T>
! _ACCESS_T Mmio::_read(off_t const) const
The read<>() and write<>() methods you mention should not contain any
code that depends on the way of accessing registers but only the bit and
offset logic that could be reused.
I'm curious about the outcome of your idea and help willingly if you
have further questions.
Cheers,
Martin
Post by Johannes Schlatow
Hi,
I really like Genode's Register API as it makes accessing memory mapped hardware registers quite clean and simple.
However, I recently encountered the need to access a rather complex I2C slave device. The I2C controller itself is accessible via MMIO. Yet, the slave device itself has a notion of registers. Basically, you first send the register address to the I2C slave and, in a second transaction, you can read/write the register's value.
Being used to the clean appearance of MMIO in Genode, I was wondering whether the access to I2C slave registers could be wrapped in a similar way. My intuition is that it might simply suffice to inherit from the Mmio class and modify the write<>() and read<>() functions but haven't checked the code in detail. Any suggestions/ideas?
Cheers
Johannes
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
genode-main mailing list
https://lists.sourceforge.net/lists/listinfo/genode-main
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
genode-main mailing list
https://lists.sourceforge.net/lists/listinfo/genode-main
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
genode-main mailing list
https://lists.sourceforge.net/lists/listinfo/genode-main
--
Johannes Schlatow, M.Sc.

IDA, Institute of Computer and Network Engineering
Technische Universität Braunschweig
Hans-Sommer-Str. 66
38106 Braunschweig - Germany

Phone +49 531 391 - 9668

www.ida.ing.tu-bs.de
***@ida.ing.tu-bs.de
Loading...