All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudio Fontana <claudio.fontana@huawei.com>
To: Alvise Rigo <a.rigo@virtualopensystems.com>,
	qemu-devel@nongnu.org, peter.maydell@linaro.org
Cc: rob.herring@linaro.org, tech@virtualopensystems.com
Subject: Re: [Qemu-devel] [RFC v2 1/4] hw/arm/virt: Allow multiple agents to modify dt
Date: Mon, 24 Nov 2014 12:47:42 +0100	[thread overview]
Message-ID: <54731ADE.302@huawei.com> (raw)
In-Reply-To: <1416593261-13751-2-git-send-email-a.rigo@virtualopensystems.com>

On 21.11.2014 19:07, Alvise Rigo wrote:
> Keep a global list with all the functions that need to modify the device
> tree.  Using qemu_add_machine_init_done_notifier we register a notifier
> that executes all the functions on the list and loads the kernel.
> 
> Signed-off-by: Alvise Rigo <a.rigo@virtualopensystems.com>

Peter, could you weigh in about whether this is a good idea or not?


> ---
>  hw/arm/virt.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 54 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 314e55b..e8d527d 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -70,6 +70,16 @@ enum {
>      VIRT_RTC,
>  };
>  
> +typedef void (*modify_dtb_func)(void *fdt, DeviceState *dev);
> +typedef struct DTModifier {
> +    QLIST_ENTRY(DTModifier) entry;
> +    modify_dtb_func modify_dtb;
> +    DeviceState *dev;
> +} DTModifier;
> +
> +static QLIST_HEAD(, DTModifier) dtb_modifiers =
> +                    QLIST_HEAD_INITIALIZER(dtb_modifiers);
> +
>  typedef struct MemMapEntry {
>      hwaddr base;
>      hwaddr size;
> @@ -149,6 +159,23 @@ static VirtBoardInfo *find_machine_info(const char *cpu)
>      return NULL;
>  }
>  
> +static void add_dtb_modifier(modify_dtb_func func, DeviceState *dev)
> +{
> +    DTModifier *mod_entry = g_new(DTModifier, 1);
> +    mod_entry->modify_dtb = func;
> +    mod_entry->dev = dev;
> +    QLIST_INSERT_HEAD(&dtb_modifiers, mod_entry, entry);
> +}
> +
> +static void free_dtb_modifiers(void)
> +{
> +    while (!QLIST_EMPTY(&dtb_modifiers)) {
> +        DTModifier *modifier = QLIST_FIRST(&dtb_modifiers);
> +        QLIST_REMOVE(modifier, entry);
> +        g_free(modifier);
> +    }
> +}
> +
>  static void create_fdt(VirtBoardInfo *vbi)
>  {
>      void *fdt = create_device_tree(&vbi->fdt_size);
> @@ -527,6 +554,29 @@ static void *machvirt_dtb(const struct arm_boot_info *binfo, int *fdt_size)
>      return board->fdt;
>  }
>  
> +static void machvirt_finalize_dt(Notifier *notify, void *data)
> +{
> +    VirtBoardInfo *vbi;
> +    MachineState *machine;
> +
> +    machine = MACHINE(qdev_get_machine());
> +
> +    vbi = find_machine_info(machine->cpu_model);
> +    if (!vbi) {
> +        vbi = find_machine_info("cortex-a15");
> +    }
> +
> +    struct DTModifier *modifier, *next;
> +    QLIST_FOREACH_SAFE(modifier, &dtb_modifiers, entry, next) {
> +        modifier->modify_dtb(vbi->fdt, modifier->dev);
> +    }
> +
> +    free_dtb_modifiers();
> +
> +    /* Load the kernel only after that the device tree has been modified. */
> +    arm_load_kernel(ARM_CPU(first_cpu), &vbi->bootinfo);
> +}
> +
>  static void machvirt_init(MachineState *machine)
>  {
>      qemu_irq pic[NUM_IRQS];
> @@ -604,6 +654,10 @@ static void machvirt_init(MachineState *machine)
>       */
>      create_virtio_devices(vbi, pic);
>  
> +    Notifier *finalize_dtb_notifier = g_new(Notifier, 1);
> +    finalize_dtb_notifier->notify = machvirt_finalize_dt;
> +    qemu_add_machine_init_done_notifier(finalize_dtb_notifier);
> +
>      vbi->bootinfo.ram_size = machine->ram_size;
>      vbi->bootinfo.kernel_filename = machine->kernel_filename;
>      vbi->bootinfo.kernel_cmdline = machine->kernel_cmdline;
> @@ -612,7 +666,6 @@ static void machvirt_init(MachineState *machine)
>      vbi->bootinfo.board_id = -1;
>      vbi->bootinfo.loader_start = vbi->memmap[VIRT_MEM].base;
>      vbi->bootinfo.get_dtb = machvirt_dtb;
> -    arm_load_kernel(ARM_CPU(first_cpu), &vbi->bootinfo);
>  }
>  
>  static QEMUMachine machvirt_a15_machine = {
> 

  reply	other threads:[~2014-11-24 11:48 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-21 18:07 [Qemu-devel] [RFC v2 0/4] Add Generic PCI host device update Alvise Rigo
2014-11-21 18:07 ` [Qemu-devel] [RFC v2 1/4] hw/arm/virt: Allow multiple agents to modify dt Alvise Rigo
2014-11-24 11:47   ` Claudio Fontana [this message]
2015-01-05 15:36     ` Peter Maydell
2015-01-05 16:14       ` alvise rigo
2015-01-05 16:41         ` Peter Maydell
2015-01-05 17:35           ` alvise rigo
2015-01-05 18:07             ` Peter Maydell
2015-01-06  9:56               ` alvise rigo
2015-01-06  9:18         ` Eric Auger
2015-01-06  9:29           ` alvise rigo
2015-01-06  9:51           ` Peter Maydell
2015-01-06 10:05             ` Eric Auger
2014-11-21 18:07 ` [Qemu-devel] [RFC v2 2/4] hw/arm/virt: find_machine_info: handle NULL value Alvise Rigo
2015-01-05 15:36   ` Peter Maydell
2015-01-05 16:31     ` alvise rigo
2015-01-05 16:42       ` Peter Maydell
2014-11-21 18:07 ` [Qemu-devel] [RFC v2 3/4] hw/pci-host: Add a generic PCI host controller for virtual platforms Alvise Rigo
2014-11-24 10:34   ` Claudio Fontana
2014-11-24 14:57     ` alvise rigo
2014-11-25 10:20       ` Claudio Fontana
2015-01-05 17:13   ` Alexander Graf
2015-01-06  8:47     ` alvise rigo
2015-01-06 11:18       ` Alexander Graf
     [not found] ` <1416593261-13751-5-git-send-email-a.rigo@virtualopensystems.com>
2014-11-24 10:38   ` [Qemu-devel] [RFC v2 4/4] hw/arm/virt: Add generic-pci device support Claudio Fontana
2014-11-24 10:47     ` alvise rigo
2014-11-24 15:50 ` [Qemu-devel] [RFC v2 0/4] Add Generic PCI host device update Claudio Fontana
2014-11-25 10:28   ` alvise rigo
2015-01-12 16:26 ` Claudio Fontana

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=54731ADE.302@huawei.com \
    --to=claudio.fontana@huawei.com \
    --cc=a.rigo@virtualopensystems.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rob.herring@linaro.org \
    --cc=tech@virtualopensystems.com \
    /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.