multiple devices, single driver

Joel Nider JOELN at il.ibm.com
Thu Oct 25 09:38:08 CEST 2018


Hi Alex,

> On 23.10.18 14:50, Joel Nider wrote:
> > I have been looking at several drivers in Genode, and they all seem to 

> > have static data - specifically a Heap object and Root object.  I am 
> > wondering with this kind of setup, is it possible to manage more than 
one 
> > device with a single driver?
> 
> of course. As described in the Genode book [0] in chapter 3.2.3, the
> root object provides the implementation just of the interface. Whenever
> a client connects to a service (like a driver for nic, ahci, nvme, usb
> etc.) a session is established via this interface. The driver may
> associate (typically does so depending on your specified policy) one
> specific device it drives to this session - as done e.g. for drivers
> handling multiple devices, e.g. ahci, nvme, usb.

I will give you my situation as a specific example. I am writing a driver 
for a PCIe attached NIC (x86 platform). Let us say that I have 2 physical 
NICs in my machine with the same device ID and vendor ID. I have specified 
in my config file that I have a driver called "nic_drv", without 
specifying the PCIe address (copied from the example in 
repos/os/run/ping.run).

When the driver starts, I can enumerate the PCIe devices through the 
Platform::Connection object that is instantiated from the 'env' object. I 
see all PCIe devices of class 'NET' (even other NICs that I don't want my 
driver to handle). So far so good. I can filter through the devices by 
requesting the capability (with Platform::Device_client) and I can read 
the device ID and vendor ID and pick the devices I want to handle.

Now I have a list of several devices that I want my driver handle. If I 
understand you correctly, I should have only one Root object (and one Heap 
object). That implies I should also only call parent().announce() once. 
But then how do I instantiate my Nic::Session_component once per device? 
What is happening so far, is that some time after I call 
parent().announce(), my Nic::Session_component derived class gets 
instantiated, and the constructor is called. But I have no way of knowing 
which device it is meant to handle, since there is no mechanism for 
passing the device capability to Nic::Session_component. In addition, I 
only see this constructor being called once. I expected to see one 
constructor per PCIe device. This causes further problems such as not 
being able to map the mmio region since the size and base address are not 
known until I query the PCIe BAR, and there is no 'new' operator 
available, which means to me I'm doing something fundamentally wrong.

So what is the correct way to build the driver such that I get an object 
per device (and the object knows the device)?

Thanks,
Joel 





More information about the users mailing list