diff mbox series

[RFC] vl.c: add is_system_on_chip flag to force board default cpu

Message ID 20170918215719.16415-1-f4bug@amsat.org
State New
Headers show
Series [RFC] vl.c: add is_system_on_chip flag to force board default cpu | expand

Commit Message

Philippe Mathieu-Daudé Sept. 18, 2017, 9:57 p.m. UTC
add a property to restrict the CPU for SoCs once on machine creation and avoid
duplicate code in each board.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
Based-on: 1505318697-77161-6-git-send-email-imammedo@redhat.com

 include/hw/boards.h |  3 +++
 vl.c                | 11 +++++++++++
 2 files changed, 14 insertions(+)

Comments

Eduardo Habkost Sept. 18, 2017, 10:55 p.m. UTC | #1
On Mon, Sep 18, 2017 at 06:57:19PM -0300, Philippe Mathieu-Daudé wrote:
> add a property to restrict the CPU for SoCs once on machine creation and avoid
> duplicate code in each board.
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

The valid_cpu_types approach implemented by Alistair is more
generic:
  Subject: [Qemu-devel] [RFC v1 0/2]  Add a valid_cpu_types property
  Message-ID: <cover.1504656490.git.alistair.francis@xilinx.com>

With it, boards that don't support other CPUs just need to set
valid_cpu_types = { default_cpu_type }.

> ---
> Based-on: 1505318697-77161-6-git-send-email-imammedo@redhat.com
> 
>  include/hw/boards.h |  3 +++
>  vl.c                | 11 +++++++++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/include/hw/boards.h b/include/hw/boards.h
> index 6b67adaef6..20dc0a0ab9 100644
> --- a/include/hw/boards.h
> +++ b/include/hw/boards.h
> @@ -129,6 +129,8 @@ typedef struct {
>   *    specifies default CPU_TYPE, which will be used for parsing target
>   *    specific features and for creating CPUs if CPU name wasn't provided
>   *    explicitly at CLI
> + * @is_system_on_chip:
> + *    If true, board does not support other CPUs than default_cpu_type.
>   * @minimum_page_bits:
>   *    If non-zero, the board promises never to create a CPU with a page size
>   *    smaller than this, so QEMU can use a more efficient larger page
> @@ -182,6 +184,7 @@ struct MachineClass {
>      const char *hw_version;
>      ram_addr_t default_ram_size;
>      const char *default_cpu_type;
> +    bool is_system_on_chip;
>      bool option_rom_has_mr;
>      bool rom_file_has_mr;
>      int minimum_page_bits;
> diff --git a/vl.c b/vl.c
> index fb6a700e55..6e59ffa856 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -4717,10 +4717,21 @@ int main(int argc, char **argv, char **envp)
>      current_machine->cpu_model = cpu_model;
>  
>  
> +    if (machine_class->is_system_on_chip && !machine_class->default_cpu_type) {
> +        error_report("System-on-Chip must have a default CPU type");
> +        exit(1);
> +    }
>      /* parse features once if machine provides default cpu_type */
>      if (machine_class->default_cpu_type) {
>          current_machine->cpu_type = machine_class->default_cpu_type;
>          if (cpu_model) {
> +            if (machine_class->is_system_on_chip) {
> +                if (strcmp(cpu_model, machine_class->default_cpu_type) != 0) {
> +                    error_report("This board can only be used with CPU %s",
> +                                 machine_class->default_cpu_type);
> +                    exit(1);
> +                }
> +            }
>              current_machine->cpu_type =
>                  cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model);
>          }
> -- 
> 2.14.1
>
Peter Maydell Sept. 19, 2017, 9:03 a.m. UTC | #2
On 18 September 2017 at 22:57, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> add a property to restrict the CPU for SoCs once on machine creation and avoid
> duplicate code in each board.
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> Based-on: 1505318697-77161-6-git-send-email-imammedo@redhat.com
>
>  include/hw/boards.h |  3 +++
>  vl.c                | 11 +++++++++++
>  2 files changed, 14 insertions(+)
>
> diff --git a/include/hw/boards.h b/include/hw/boards.h
> index 6b67adaef6..20dc0a0ab9 100644
> --- a/include/hw/boards.h
> +++ b/include/hw/boards.h
> @@ -129,6 +129,8 @@ typedef struct {
>   *    specifies default CPU_TYPE, which will be used for parsing target
>   *    specific features and for creating CPUs if CPU name wasn't provided
>   *    explicitly at CLI
> + * @is_system_on_chip:
> + *    If true, board does not support other CPUs than default_cpu_type.

Being an SoC isn't the only reason a board might only support one
CPU type (perhaps it just never existed with other than a single
CPU soldered into it), so maybe a different name?

thanks
-- PMM
Philippe Mathieu-Daudé Sept. 19, 2017, 9:51 a.m. UTC | #3
On 09/18/2017 07:55 PM, Eduardo Habkost wrote:
> On Mon, Sep 18, 2017 at 06:57:19PM -0300, Philippe Mathieu-Daudé wrote:
>> add a property to restrict the CPU for SoCs once on machine creation and avoid
>> duplicate code in each board.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> 
> The valid_cpu_types approach implemented by Alistair is more
> generic:
>    Subject: [Qemu-devel] [RFC v1 0/2]  Add a valid_cpu_types property
>    Message-ID: <cover.1504656490.git.alistair.francis@xilinx.com>
> 
> With it, boards that don't support other CPUs just need to set
> valid_cpu_types = { default_cpu_type }.

Oh thank for pointing this out, I missed his series.

Many people waiting for Igor series to land ;)

Regards,

Phil.
Eduardo Habkost Sept. 19, 2017, 10:42 a.m. UTC | #4
On Tue, Sep 19, 2017 at 06:51:23AM -0300, Philippe Mathieu-Daudé wrote:
> On 09/18/2017 07:55 PM, Eduardo Habkost wrote:
> > On Mon, Sep 18, 2017 at 06:57:19PM -0300, Philippe Mathieu-Daudé wrote:
> > > add a property to restrict the CPU for SoCs once on machine creation and avoid
> > > duplicate code in each board.
> > > 
> > > Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> > 
> > The valid_cpu_types approach implemented by Alistair is more
> > generic:
> >    Subject: [Qemu-devel] [RFC v1 0/2]  Add a valid_cpu_types property
> >    Message-ID: <cover.1504656490.git.alistair.francis@xilinx.com>
> > 
> > With it, boards that don't support other CPUs just need to set
> > valid_cpu_types = { default_cpu_type }.
> 
> Oh thank for pointing this out, I missed his series.
> 
> Many people waiting for Igor series to land ;)

I plan to queue it today, and get a pull request out today or
tomorrow.
Alistair Francis Sept. 19, 2017, 6:16 p.m. UTC | #5
On Tue, Sep 19, 2017 at 2:03 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 18 September 2017 at 22:57, Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>> add a property to restrict the CPU for SoCs once on machine creation and avoid
>> duplicate code in each board.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>> Based-on: 1505318697-77161-6-git-send-email-imammedo@redhat.com
>>
>>  include/hw/boards.h |  3 +++
>>  vl.c                | 11 +++++++++++
>>  2 files changed, 14 insertions(+)
>>
>> diff --git a/include/hw/boards.h b/include/hw/boards.h
>> index 6b67adaef6..20dc0a0ab9 100644
>> --- a/include/hw/boards.h
>> +++ b/include/hw/boards.h
>> @@ -129,6 +129,8 @@ typedef struct {
>>   *    specifies default CPU_TYPE, which will be used for parsing target
>>   *    specific features and for creating CPUs if CPU name wasn't provided
>>   *    explicitly at CLI
>> + * @is_system_on_chip:
>> + *    If true, board does not support other CPUs than default_cpu_type.
>
> Being an SoC isn't the only reason a board might only support one
> CPU type (perhaps it just never existed with other than a single
> CPU soldered into it), so maybe a different name?

I don't think this makes a lot of sense. There are some SoCs that are
basically the same besides the CPU. I think a list of possible CPUs
makes more sense for machines. That way the list can be used for every
machine and not just machines with a single CPU. If your SoC only
supports one CPU then you only describe one, but if you want others
you can list others.

Thanks,
Alistair

>
> thanks
> -- PMM
>
diff mbox series

Patch

diff --git a/include/hw/boards.h b/include/hw/boards.h
index 6b67adaef6..20dc0a0ab9 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -129,6 +129,8 @@  typedef struct {
  *    specifies default CPU_TYPE, which will be used for parsing target
  *    specific features and for creating CPUs if CPU name wasn't provided
  *    explicitly at CLI
+ * @is_system_on_chip:
+ *    If true, board does not support other CPUs than default_cpu_type.
  * @minimum_page_bits:
  *    If non-zero, the board promises never to create a CPU with a page size
  *    smaller than this, so QEMU can use a more efficient larger page
@@ -182,6 +184,7 @@  struct MachineClass {
     const char *hw_version;
     ram_addr_t default_ram_size;
     const char *default_cpu_type;
+    bool is_system_on_chip;
     bool option_rom_has_mr;
     bool rom_file_has_mr;
     int minimum_page_bits;
diff --git a/vl.c b/vl.c
index fb6a700e55..6e59ffa856 100644
--- a/vl.c
+++ b/vl.c
@@ -4717,10 +4717,21 @@  int main(int argc, char **argv, char **envp)
     current_machine->cpu_model = cpu_model;
 
 
+    if (machine_class->is_system_on_chip && !machine_class->default_cpu_type) {
+        error_report("System-on-Chip must have a default CPU type");
+        exit(1);
+    }
     /* parse features once if machine provides default cpu_type */
     if (machine_class->default_cpu_type) {
         current_machine->cpu_type = machine_class->default_cpu_type;
         if (cpu_model) {
+            if (machine_class->is_system_on_chip) {
+                if (strcmp(cpu_model, machine_class->default_cpu_type) != 0) {
+                    error_report("This board can only be used with CPU %s",
+                                 machine_class->default_cpu_type);
+                    exit(1);
+                }
+            }
             current_machine->cpu_type =
                 cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model);
         }