qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] hw/intc/apic: QOM cleanup
@ 2023-09-15 16:20 Philippe Mathieu-Daudé
  2023-09-15 16:20 ` [PATCH 1/2] target/i386: Only realize existing APIC device Philippe Mathieu-Daudé
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-09-15 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Bernhard Beschow, Michael S. Tsirkin,
	Philippe Mathieu-Daudé

Minor cleanup extracted from a bigger series
touching x86_cpu_realizefn().

Philippe Mathieu-Daudé (2):
  target/i386: Only realize existing APIC device
  hw/intc/apic: Pass CPU using QOM link property

 hw/intc/apic_common.c    |  2 ++
 target/i386/cpu-sysemu.c | 20 +++++++++-----------
 target/i386/cpu.c        |  8 +++++---
 3 files changed, 16 insertions(+), 14 deletions(-)

-- 
2.41.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] target/i386: Only realize existing APIC device
  2023-09-15 16:20 [PATCH 0/2] hw/intc/apic: QOM cleanup Philippe Mathieu-Daudé
@ 2023-09-15 16:20 ` Philippe Mathieu-Daudé
  2023-09-15 16:20 ` [PATCH 2/2] hw/intc/apic: Pass CPU using QOM link property Philippe Mathieu-Daudé
  2023-10-03  6:45 ` [PATCH 0/2] hw/intc/apic: QOM cleanup Philippe Mathieu-Daudé
  2 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-09-15 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Bernhard Beschow, Michael S. Tsirkin,
	Philippe Mathieu-Daudé

APIC state is created under a certain condition,
use the same condition to realize it.
Having a NULL APIC state is a bug: use assert().

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/i386/cpu-sysemu.c | 9 +++------
 target/i386/cpu.c        | 8 +++++---
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/target/i386/cpu-sysemu.c b/target/i386/cpu-sysemu.c
index 2375e48178..6a164d3769 100644
--- a/target/i386/cpu-sysemu.c
+++ b/target/i386/cpu-sysemu.c
@@ -272,9 +272,7 @@ void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
     APICCommonState *apic;
     APICCommonClass *apic_class = apic_get_class(errp);
 
-    if (!apic_class) {
-        return;
-    }
+    assert(apic_class);
 
     cpu->apic_state = DEVICE(object_new_with_class(OBJECT_CLASS(apic_class)));
     object_property_add_child(OBJECT(cpu), "lapic",
@@ -293,9 +291,8 @@ void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
     APICCommonState *apic;
     static bool apic_mmio_map_once;
 
-    if (cpu->apic_state == NULL) {
-        return;
-    }
+    assert(cpu->apic_state);
+
     qdev_realize(DEVICE(cpu->apic_state), NULL, errp);
 
     /* Map APIC MMIO area */
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index b2a20365e1..a23d4795e0 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -7448,9 +7448,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
     }
 
 #ifndef CONFIG_USER_ONLY
-    x86_cpu_apic_realize(cpu, &local_err);
-    if (local_err != NULL) {
-        goto out;
+    if (cpu->env.features[FEAT_1_EDX] & CPUID_APIC || ms->smp.cpus > 1) {
+        x86_cpu_apic_realize(cpu, &local_err);
+        if (local_err != NULL) {
+            goto out;
+        }
     }
 #endif /* !CONFIG_USER_ONLY */
     cpu_reset(cs);
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] hw/intc/apic: Pass CPU using QOM link property
  2023-09-15 16:20 [PATCH 0/2] hw/intc/apic: QOM cleanup Philippe Mathieu-Daudé
  2023-09-15 16:20 ` [PATCH 1/2] target/i386: Only realize existing APIC device Philippe Mathieu-Daudé
@ 2023-09-15 16:20 ` Philippe Mathieu-Daudé
  2023-10-03  6:45 ` [PATCH 0/2] hw/intc/apic: QOM cleanup Philippe Mathieu-Daudé
  2 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-09-15 16:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Bernhard Beschow, Michael S. Tsirkin,
	Philippe Mathieu-Daudé

QOM objects shouldn't access each other internals fields
except using the QOM API.

Declare the 'cpu' and 'base-addr' properties, set them
using object_property_set_link() and qdev_prop_set_uint32()
respectively.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/intc/apic_common.c    |  2 ++
 target/i386/cpu-sysemu.c | 11 ++++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index 68ad30e2f5..e28f7402ab 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -394,6 +394,8 @@ static Property apic_properties_common[] = {
                     true),
     DEFINE_PROP_BOOL("legacy-instance-id", APICCommonState, legacy_instance_id,
                      false),
+    DEFINE_PROP_LINK("cpu", APICCommonState, cpu, TYPE_X86_CPU, X86CPU *),
+    DEFINE_PROP_UINT32("base-addr", APICCommonState, apicbase, 0),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/target/i386/cpu-sysemu.c b/target/i386/cpu-sysemu.c
index 6a164d3769..6edfb7e2af 100644
--- a/target/i386/cpu-sysemu.c
+++ b/target/i386/cpu-sysemu.c
@@ -269,7 +269,6 @@ APICCommonClass *apic_get_class(Error **errp)
 
 void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
 {
-    APICCommonState *apic;
     APICCommonClass *apic_class = apic_get_class(errp);
 
     assert(apic_class);
@@ -279,11 +278,13 @@ void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
                               OBJECT(cpu->apic_state));
     object_unref(OBJECT(cpu->apic_state));
 
+    if (!object_property_set_link(OBJECT(cpu->apic_state), "cpu",
+                                  OBJECT(cpu), errp)) {
+        return;
+    }
     qdev_prop_set_uint32(cpu->apic_state, "id", cpu->apic_id);
-    /* TODO: convert to link<> */
-    apic = APIC_COMMON(cpu->apic_state);
-    apic->cpu = cpu;
-    apic->apicbase = APIC_DEFAULT_ADDRESS | MSR_IA32_APICBASE_ENABLE;
+    qdev_prop_set_uint32(cpu->apic_state, "base-addr",
+                         APIC_DEFAULT_ADDRESS | MSR_IA32_APICBASE_ENABLE);
 }
 
 void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] hw/intc/apic: QOM cleanup
  2023-09-15 16:20 [PATCH 0/2] hw/intc/apic: QOM cleanup Philippe Mathieu-Daudé
  2023-09-15 16:20 ` [PATCH 1/2] target/i386: Only realize existing APIC device Philippe Mathieu-Daudé
  2023-09-15 16:20 ` [PATCH 2/2] hw/intc/apic: Pass CPU using QOM link property Philippe Mathieu-Daudé
@ 2023-10-03  6:45 ` Philippe Mathieu-Daudé
  2023-10-03  7:07   ` Philippe Mathieu-Daudé
  2 siblings, 1 reply; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-03  6:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Bernhard Beschow, Michael S. Tsirkin,
	Alex Bennée, Markus Armbruster

On 15/9/23 18:20, Philippe Mathieu-Daudé wrote:
> Minor cleanup extracted from a bigger series
> touching x86_cpu_realizefn().
> 
> Philippe Mathieu-Daudé (2):
>    target/i386: Only realize existing APIC device
>    hw/intc/apic: Pass CPU using QOM link property

Ping?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] hw/intc/apic: QOM cleanup
  2023-10-03  6:45 ` [PATCH 0/2] hw/intc/apic: QOM cleanup Philippe Mathieu-Daudé
@ 2023-10-03  7:07   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-03  7:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, Bernhard Beschow, Michael S. Tsirkin,
	Alex Bennée, Markus Armbruster

On 3/10/23 08:45, Philippe Mathieu-Daudé wrote:
> On 15/9/23 18:20, Philippe Mathieu-Daudé wrote:
>> Minor cleanup extracted from a bigger series
>> touching x86_cpu_realizefn().
>>
>> Philippe Mathieu-Daudé (2):
>>    target/i386: Only realize existing APIC device
>>    hw/intc/apic: Pass CPU using QOM link property
> 
> Ping?

Oops I didn't noticed I sent these patches by mistake
in another series, and Richard already reviewed them
(with comment to address):
https://lore.kernel.org/qemu-devel/a6d0175f-a343-4b1f-232f-280786e7dce3@linaro.org/


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-03  7:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-15 16:20 [PATCH 0/2] hw/intc/apic: QOM cleanup Philippe Mathieu-Daudé
2023-09-15 16:20 ` [PATCH 1/2] target/i386: Only realize existing APIC device Philippe Mathieu-Daudé
2023-09-15 16:20 ` [PATCH 2/2] hw/intc/apic: Pass CPU using QOM link property Philippe Mathieu-Daudé
2023-10-03  6:45 ` [PATCH 0/2] hw/intc/apic: QOM cleanup Philippe Mathieu-Daudé
2023-10-03  7:07   ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).