diff mbox series

[RFC,11/15] exec/cpu: Make address_space_init/reloading_memory_map target agnostic

Message ID 20210517115525.1088693-12-f4bug@amsat.org (mailing list archive)
State New, archived
Headers show
Series softmmu: Make various objects target agnostic | expand

Commit Message

Philippe Mathieu-Daudé May 17, 2021, 11:55 a.m. UTC
cpu_address_space_init() and cpu_reloading_memory_map() don't
have to be target specific. Remove this limitation to be able
to build softmmu/cpus.c once for all targets.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 include/exec/cpu-common.h | 23 +++++++++++++++++++++++
 include/exec/exec-all.h   | 25 -------------------------
 2 files changed, 23 insertions(+), 25 deletions(-)

Comments

Richard Henderson May 26, 2021, 7:01 p.m. UTC | #1
On 5/17/21 4:55 AM, Philippe Mathieu-Daudé wrote:
> cpu_address_space_init() and cpu_reloading_memory_map() don't
> have to be target specific. Remove this limitation to be able
> to build softmmu/cpus.c once for all targets.
> 
> Signed-off-by: Philippe Mathieu-Daudé<f4bug@amsat.org>
> ---
>   include/exec/cpu-common.h | 23 +++++++++++++++++++++++
>   include/exec/exec-all.h   | 25 -------------------------
>   2 files changed, 23 insertions(+), 25 deletions(-)

It's not clear to me why the declarations moved file, instead of just droppig 
the surrounding ifdef.

If there's a good reason, fine, but the reason belongs in the commit message.

r~
Philippe Mathieu-Daudé May 26, 2021, 9:32 p.m. UTC | #2
On 5/26/21 9:01 PM, Richard Henderson wrote:
> On 5/17/21 4:55 AM, Philippe Mathieu-Daudé wrote:
>> cpu_address_space_init() and cpu_reloading_memory_map() don't
>> have to be target specific. Remove this limitation to be able
>> to build softmmu/cpus.c once for all targets.
>>
>> Signed-off-by: Philippe Mathieu-Daudé<f4bug@amsat.org>
>> ---
>>   include/exec/cpu-common.h | 23 +++++++++++++++++++++++
>>   include/exec/exec-all.h   | 25 -------------------------
>>   2 files changed, 23 insertions(+), 25 deletions(-)
> 
> It's not clear to me why the declarations moved file, instead of just
> droppig the surrounding ifdef.

hwaddr is target-specific, cpu_address_space_init don't uses it.

softmmu/cpus.c is target-agnostic but uses cpu_address_space_init().

Similarly with cpu_reloading_memory_map() in softmmu/physmem.c.

> If there's a good reason, fine, but the reason belongs in the commit
> message.

OK, I'll mention hwaddr.
Richard Henderson May 26, 2021, 9:43 p.m. UTC | #3
On 5/26/21 2:32 PM, Philippe Mathieu-Daudé wrote:
> On 5/26/21 9:01 PM, Richard Henderson wrote:
>> On 5/17/21 4:55 AM, Philippe Mathieu-Daudé wrote:
>>> cpu_address_space_init() and cpu_reloading_memory_map() don't
>>> have to be target specific. Remove this limitation to be able
>>> to build softmmu/cpus.c once for all targets.
>>>
>>> Signed-off-by: Philippe Mathieu-Daudé<f4bug@amsat.org>
>>> ---
>>>    include/exec/cpu-common.h | 23 +++++++++++++++++++++++
>>>    include/exec/exec-all.h   | 25 -------------------------
>>>    2 files changed, 23 insertions(+), 25 deletions(-)
>>
>> It's not clear to me why the declarations moved file, instead of just
>> droppig the surrounding ifdef.
> 
> hwaddr is target-specific, cpu_address_space_init don't uses it.

hwaddr is not target specific.


r~
Philippe Mathieu-Daudé Feb. 3, 2022, 12:37 p.m. UTC | #4
On 26/5/21 21:01, Richard Henderson wrote:
> On 5/17/21 4:55 AM, Philippe Mathieu-Daudé wrote:
>> cpu_address_space_init() and cpu_reloading_memory_map() don't
>> have to be target specific. Remove this limitation to be able
>> to build softmmu/cpus.c once for all targets.
>>
>> Signed-off-by: Philippe Mathieu-Daudé<f4bug@amsat.org>
>> ---
>>   include/exec/cpu-common.h | 23 +++++++++++++++++++++++
>>   include/exec/exec-all.h   | 25 -------------------------
>>   2 files changed, 23 insertions(+), 25 deletions(-)
> 
> It's not clear to me why the declarations moved file, instead of just 
> droppig the surrounding ifdef.
> 
> If there's a good reason, fine, but the reason belongs in the commit 
> message.

What about:

'''
cpu_address_space_init() and cpu_reloading_memory_map() are
target-agnostic, but are declared in "exec/exec-all.h" which
contains target-specific declarations. Any target-agnostic
source including "exec/exec-all.h" becomes target-specific
and we have to compile it N times for the N targets built.
In order to avoid that, move the declarations to "exec/cpu-common.h"
which only contains target-agnostic declarations.
'''
diff mbox series

Patch

diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index ccabed4003a..a4fb6813206 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -68,6 +68,28 @@  void qemu_ram_unset_migratable(RAMBlock *rb);
 size_t qemu_ram_pagesize(RAMBlock *block);
 size_t qemu_ram_pagesize_largest(void);
 
+/**
+ * cpu_address_space_init:
+ * @cpu: CPU to add this address space to
+ * @asidx: integer index of this address space
+ * @prefix: prefix to be used as name of address space
+ * @mr: the root memory region of address space
+ *
+ * Add the specified address space to the CPU's cpu_ases list.
+ * The address space added with @asidx 0 is the one used for the
+ * convenience pointer cpu->as.
+ * The target-specific code which registers ASes is responsible
+ * for defining what semantics address space 0, 1, 2, etc have.
+ *
+ * Before the first call to this function, the caller must set
+ * cpu->num_ases to the total number of address spaces it needs
+ * to support.
+ *
+ * Note that with KVM only one address space is supported.
+ */
+void cpu_address_space_init(CPUState *cpu, int asidx,
+                            const char *prefix, MemoryRegion *mr);
+
 void cpu_physical_memory_rw(hwaddr addr, void *buf,
                             hwaddr len, bool is_write);
 static inline void cpu_physical_memory_read(hwaddr addr,
@@ -80,6 +102,7 @@  static inline void cpu_physical_memory_write(hwaddr addr,
 {
     cpu_physical_memory_rw(addr, (void *)buf, len, true);
 }
+void cpu_reloading_memory_map(void);
 void *cpu_physical_memory_map(hwaddr addr,
                               hwaddr *plen,
                               bool is_write);
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 6b036cae8f6..781ee62f395 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -84,31 +84,6 @@  static inline bool cpu_loop_exit_requested(CPUState *cpu)
     return (int32_t)qatomic_read(&cpu_neg(cpu)->icount_decr.u32) < 0;
 }
 
-#if !defined(CONFIG_USER_ONLY)
-void cpu_reloading_memory_map(void);
-/**
- * cpu_address_space_init:
- * @cpu: CPU to add this address space to
- * @asidx: integer index of this address space
- * @prefix: prefix to be used as name of address space
- * @mr: the root memory region of address space
- *
- * Add the specified address space to the CPU's cpu_ases list.
- * The address space added with @asidx 0 is the one used for the
- * convenience pointer cpu->as.
- * The target-specific code which registers ASes is responsible
- * for defining what semantics address space 0, 1, 2, etc have.
- *
- * Before the first call to this function, the caller must set
- * cpu->num_ases to the total number of address spaces it needs
- * to support.
- *
- * Note that with KVM only one address space is supported.
- */
-void cpu_address_space_init(CPUState *cpu, int asidx,
-                            const char *prefix, MemoryRegion *mr);
-#endif
-
 #if !defined(CONFIG_USER_ONLY) && defined(CONFIG_TCG)
 /* cputlb.c */
 /**