qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Strange behaviour in network device initialization.


From: Peter Maydell
Subject: Re: [Qemu-devel] Strange behaviour in network device initialization.
Date: Sat, 18 Mar 2017 22:22:55 +0000

On 18 March 2017 at 21:15, Marc Bommert <address@hidden> wrote:
> I ran into some behaviour I don't understand and which may be a qemu problem 
> but which may also be my fault, since I haven't investigated much on QOM so 
> far.
> I am currently writing a NIC sysbus device based on the structure of 
> hw/net/smc91c111.c
>
> qemu is invoked as:
>
>   $ qemu-system-arm -M mymachine -m 8 -kernel kernel.elf -nographic -net 
> nic,id=myid -netdev tap,ifname=tap0,id=myid,script=no,downscript=no -device 
> mydevice,netdev=myid
>
>
> The initialization structure is a little special here. A "legacy helper" 
> initialization function is called from the board module mymachine.c:
>
>    for(n = 0; n < nb_nics; n++) {
>         nd = &nd_table[n];
>
>         if (!nd->model || strcmp(nd->model, "mydevice") == 0) {
>             mydevice_init(nd, MYDEVICE_BASE, pic[17]);
>             break;
>         } else {
>         /* We don't know this NIC model */
>         }
>     }


> Now, the actual problem is that mydevice_init1() is called twice and
> the device state is also instantiated twice.

This is expected, because you're creating two devices.
Device 1 is the one that's created by calling
mydevice_init() here in the board code.
Device 2 is created because you say "-device mydevice"
on the command line.

smc91c111 is an "embedded" device which is memory mapped
into a particular address in the memory space and directly
wired up to an interrupt line. (QEMU calls these "sysbus
devices".) These can't be sensibly created from the command
line because there's no way to specify how to wire them
up and where they live in memory.

Conversely, the -device command line option is for
devices which go in pluggable buses, like PCI and
ISA devices. The -device option says "create one
of these and plug it into some available bus of
the right type"; it creates devices in addition to
any that the board creates itself.

The slightly odd thing is that -device mydevice
doesn't fail for you -- if you try that for smc91c111 it
will complain:
 "Device smc91c111 cannot be dynamically instantiated"
to let you know that the command line option is wrong.

PS: smc91c111 is not a very good model to copy,
because that device code is very old, and doesn't
necessarily follow current QEMU coding practices.
Looking at a device that's been added to QEMU
more recently may be a better idea.

thanks
-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]