All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Marc Bommert <marc@brightwise.de>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] Strange behaviour in network device initialization.
Date: Sat, 18 Mar 2017 22:22:55 +0000	[thread overview]
Message-ID: <CAFEAcA-82Hx102VSxxsxD_20RSRCG6BWWtvtxpY4vhWnQTFo-g@mail.gmail.com> (raw)
In-Reply-To: <741795585.70221.1489871707491@communicator.strato.de>

On 18 March 2017 at 21:15, Marc Bommert <marc@brightwise.de> 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	other threads:[~2017-03-18 22:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-18 18:15 [Qemu-devel] Error checking and qemu_thread_create Anton Volkov
2017-03-18 21:15 ` [Qemu-devel] Strange behaviour in network device initialization Marc Bommert
2017-03-18 22:22   ` Peter Maydell [this message]
2017-03-19 13:41     ` Marc Bommert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFEAcA-82Hx102VSxxsxD_20RSRCG6BWWtvtxpY4vhWnQTFo-g@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=marc@brightwise.de \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.