diff mbox

[Xen-devel,RFC,for-4.5,4/5] xen/arm: Remove processor specific setup in vcpu_initialise

Message ID 1392149085-14366-5-git-send-email-julien.grall@linaro.org
State RFC
Headers show

Commit Message

Julien Grall Feb. 11, 2014, 8:04 p.m. UTC
This patch introduces the possibility to have specific processor callbacks
that can be called in various place.

Currently VCPU initialization code contains processor specific setup (for
Cortex A7 and Cortex A15) for the ACTRL registers. It's possible to have
processor with a different layout for this register.

Move this setup in a specific callback for ARM v7 processor.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
---
 xen/arch/arm/Makefile          |    1 +
 xen/arch/arm/arm32/Makefile    |    2 +-
 xen/arch/arm/arm32/proc-v7-c.c |   32 ++++++++++++++++++++++++++
 xen/arch/arm/arm32/proc-v7.S   |    3 +++
 xen/arch/arm/domain.c          |    8 ++-----
 xen/arch/arm/processor.c       |   49 ++++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/setup.c           |    3 +++
 xen/include/asm-arm/procinfo.h |   17 ++++++++++++--
 8 files changed, 106 insertions(+), 9 deletions(-)
 create mode 100644 xen/arch/arm/arm32/proc-v7-c.c
 create mode 100644 xen/arch/arm/processor.c

Comments

Ian Campbell Feb. 19, 2014, 12:18 p.m. UTC | #1
On Tue, 2014-02-11 at 20:04 +0000, Julien Grall wrote:
> diff --git a/xen/arch/arm/arm32/proc-v7-c.c b/xen/arch/arm/arm32/proc-v7-c.c
> new file mode 100644
> index 0000000..a3b94a2
> --- /dev/null
> +++ b/xen/arch/arm/arm32/proc-v7-c.c
> @@ -0,0 +1,32 @@
> +/*
> + * xen/arch/arm/arm32/proc-v7-c.c
> + *
> + * arm v7 specific initializations (C part)

I think strictly speaking this is actually cortex a{7,15} specific.

Calling this file "proc-v7-ca15.c" or something (core-cortex.c?) would
be nicer than the ugly -c suffix...

> + *
> + * Julien Grall <julien.grall@linaro.org>
> + * Copyright (c) 2014 Linaro Limited.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +#include <asm/procinfo.h>
> +#include <asm/processor.h>
> +
> +static void armv7_vcpu_initialize(struct vcpu *v)
> +{
> +    if ( v->domain->max_vcpus > 1 )
> +        v->arch.actlr |= ACTLR_V7_SMP;
> +    else
> +        v->arch.actlr &= ~ACTLR_V7_SMP;
> +}
> +
> +const struct processor armv7_processor = {

__rodata? (or whatever it is called)

> +    .vcpu_initialize = armv7_vcpu_initialize,
> +};
Julien Grall Feb. 20, 2014, 4:45 p.m. UTC | #2
Hi Ian,

On 02/19/2014 12:18 PM, Ian Campbell wrote:
> On Tue, 2014-02-11 at 20:04 +0000, Julien Grall wrote:
>> diff --git a/xen/arch/arm/arm32/proc-v7-c.c b/xen/arch/arm/arm32/proc-v7-c.c
>> new file mode 100644
>> index 0000000..a3b94a2
>> --- /dev/null
>> +++ b/xen/arch/arm/arm32/proc-v7-c.c
>> @@ -0,0 +1,32 @@
>> +/*
>> + * xen/arch/arm/arm32/proc-v7-c.c
>> + *
>> + * arm v7 specific initializations (C part)
> 
> I think strictly speaking this is actually cortex a{7,15} specific.
> Calling this file "proc-v7-ca15.c" or something (core-cortex.c?) would
> be nicer than the ugly -c suffix...

Right, but it's possible to have some specific quirk written in C for
other ARMv7 CPU.

I think we need to have a file where we can store v7 code (as
proc-v7.S). Creating a file per specific processor for only one function
seems odd. I'm open to any other generic name for this file.

Cheers,
Julien Grall Feb. 20, 2014, 7:43 p.m. UTC | #3
On 02/19/2014 12:18 PM, Ian Campbell wrote:

>> + *
>> + * Julien Grall <julien.grall@linaro.org>
>> + * Copyright (c) 2014 Linaro Limited.
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> + * GNU General Public License for more details.
>> + */
>> +#include <asm/procinfo.h>
>> +#include <asm/processor.h>
>> +
>> +static void armv7_vcpu_initialize(struct vcpu *v)
>> +{
>> +    if ( v->domain->max_vcpus > 1 )
>> +        v->arch.actlr |= ACTLR_V7_SMP;
>> +    else
>> +        v->arch.actlr &= ~ACTLR_V7_SMP;
>> +}
>> +
>> +const struct processor armv7_processor = {
> 
> __rodata? (or whatever it is called)

I forgot to answer to this part. The compiler will put it by default in
rodata. Did you want to say __initconst? If so, we can't because I use a
pointer to this structure in arch/arm/processor.c

If we want to save space, we can copy it in another variable in
processor_setup.
Ian Campbell Feb. 24, 2014, 9:58 a.m. UTC | #4
On Thu, 2014-02-20 at 19:43 +0000, Julien Grall wrote:
> On 02/19/2014 12:18 PM, Ian Campbell wrote:
> 
> >> + *
> >> + * Julien Grall <julien.grall@linaro.org>
> >> + * Copyright (c) 2014 Linaro Limited.
> >> + *
> >> + * This program is free software; you can redistribute it and/or modify
> >> + * it under the terms of the GNU General Public License as published by
> >> + * the Free Software Foundation; either version 2 of the License, or
> >> + * (at your option) any later version.
> >> + *
> >> + * This program is distributed in the hope that it will be useful,
> >> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> >> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> >> + * GNU General Public License for more details.
> >> + */
> >> +#include <asm/procinfo.h>
> >> +#include <asm/processor.h>
> >> +
> >> +static void armv7_vcpu_initialize(struct vcpu *v)
> >> +{
> >> +    if ( v->domain->max_vcpus > 1 )
> >> +        v->arch.actlr |= ACTLR_V7_SMP;
> >> +    else
> >> +        v->arch.actlr &= ~ACTLR_V7_SMP;
> >> +}
> >> +
> >> +const struct processor armv7_processor = {
> > 
> > __rodata? (or whatever it is called)
> 
> I forgot to answer to this part. The compiler will put it by default in
> rodata. Did you want to say __initconst? If so, we can't because I use a
> pointer to this structure in arch/arm/processor.c

I meant __initconst yes. Leaving it in rodata is fine.

__init indeed doesn't make sense now you make me think of it.

> If we want to save space, we can copy it in another variable in
> processor_setup.

No need IMHO (at least not yet, maybe if we end up with dozens of
these...).

 Thanks.

Ian.
diff mbox

Patch

diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile
index d70f6d5..63e0460 100644
--- a/xen/arch/arm/Makefile
+++ b/xen/arch/arm/Makefile
@@ -32,6 +32,7 @@  obj-y += vuart.o
 obj-y += hvm.o
 obj-y += device.o
 obj-y += decode.o
+obj-y += processor.o
 
 #obj-bin-y += ....o
 
diff --git a/xen/arch/arm/arm32/Makefile b/xen/arch/arm/arm32/Makefile
index 65ecff4..0e7c3b4 100644
--- a/xen/arch/arm/arm32/Makefile
+++ b/xen/arch/arm/arm32/Makefile
@@ -1,7 +1,7 @@ 
 subdir-y += lib
 
 obj-y += entry.o
-obj-y += proc-v7.o
+obj-y += proc-v7.o proc-v7-c.o
 
 obj-y += traps.o
 obj-y += domain.o
diff --git a/xen/arch/arm/arm32/proc-v7-c.c b/xen/arch/arm/arm32/proc-v7-c.c
new file mode 100644
index 0000000..a3b94a2
--- /dev/null
+++ b/xen/arch/arm/arm32/proc-v7-c.c
@@ -0,0 +1,32 @@ 
+/*
+ * xen/arch/arm/arm32/proc-v7-c.c
+ *
+ * arm v7 specific initializations (C part)
+ *
+ * Julien Grall <julien.grall@linaro.org>
+ * Copyright (c) 2014 Linaro Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include <asm/procinfo.h>
+#include <asm/processor.h>
+
+static void armv7_vcpu_initialize(struct vcpu *v)
+{
+    if ( v->domain->max_vcpus > 1 )
+        v->arch.actlr |= ACTLR_V7_SMP;
+    else
+        v->arch.actlr &= ~ACTLR_V7_SMP;
+}
+
+const struct processor armv7_processor = {
+    .vcpu_initialize = armv7_vcpu_initialize,
+};
diff --git a/xen/arch/arm/arm32/proc-v7.S b/xen/arch/arm/arm32/proc-v7.S
index 2c8cb9c..d7d2318 100644
--- a/xen/arch/arm/arm32/proc-v7.S
+++ b/xen/arch/arm/arm32/proc-v7.S
@@ -33,6 +33,7 @@  __v7_ca15mp_proc_info:
         .long 0x410FC0F0             /* Cortex-A15 */
         .long 0xFF0FFFF0             /* Mask */
         .long v7_init
+        .long armv7_processor
         .size __v7_ca15mp_proc_info, . - __v7_ca15mp_proc_info
 
         .section ".init.proc.info", #alloc, #execinstr
@@ -41,6 +42,7 @@  __v7_ca7mp_proc_info:
         .long 0x410FC070             /* Cortex-A7 */
         .long 0xFF0FFFF0             /* Mask */
         .long v7_init
+        .long armv7_processor
         .size __v7_ca7mp_proc_info, . - __v7_ca7mp_proc_info
 
         .section ".init.proc.info", #alloc, #execinstr
@@ -49,6 +51,7 @@  __v7_brahma15mp_proc_info:
         .long 0x420F00F2             /* Broadcom Brahma-B15 */
         .long 0xFF0FFFFF             /* Mask */
         .long v7_init
+        .long armv7_processor
         .size __v7_brahma15mp_proc_info, . - __v7_brahma15mp_proc_info
 
 /*
diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index c279a27..df23147 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -29,7 +29,7 @@ 
 #include <asm/irq.h>
 #include <asm/cpufeature.h>
 #include <asm/vfp.h>
-#include <asm/processor-ca15.h>
+#include <asm/procinfo.h>
 
 #include <asm/gic.h>
 #include <asm/platform.h>
@@ -487,11 +487,7 @@  int vcpu_initialise(struct vcpu *v)
 
     v->arch.actlr = READ_SYSREG32(ACTLR_EL1);
 
-    /* XXX: Handle other than CA15 cpus */
-    if ( v->domain->max_vcpus > 1 )
-        v->arch.actlr |= ACTLR_CA15_SMP;
-    else
-        v->arch.actlr &= ~ACTLR_CA15_SMP;
+    processor_vcpu_initialize(v);
 
     if ( (rc = vcpu_vgic_init(v)) != 0 )
         return rc;
diff --git a/xen/arch/arm/processor.c b/xen/arch/arm/processor.c
new file mode 100644
index 0000000..b06fcc5
--- /dev/null
+++ b/xen/arch/arm/processor.c
@@ -0,0 +1,49 @@ 
+/*
+ * xen/arch/arm/processor.c
+ *
+ * Helpers to execute processor specific code.
+ *
+ * Julien Grall <julien.grall@linaro.org>
+ * Copyright (C) 2014 Linaro Limited.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include <asm/procinfo.h>
+
+static const struct processor *processor = NULL;
+
+void __init processor_setup(void)
+{
+    const struct proc_info_list *procinfo;
+
+    procinfo = lookup_processor_type();
+    if ( !procinfo )
+        return;
+
+    processor = procinfo->processor;
+}
+
+void processor_vcpu_initialize(struct vcpu *v)
+{
+    if ( !processor || !processor->vcpu_initialize )
+        return;
+
+    processor->vcpu_initialize(v);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 1f6d713..5529cb1 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -42,6 +42,7 @@ 
 #include <asm/gic.h>
 #include <asm/cpufeature.h>
 #include <asm/platform.h>
+#include <asm/procinfo.h>
 
 struct cpuinfo_arm __read_mostly boot_cpu_data;
 
@@ -148,6 +149,8 @@  static void __init processor_id(void)
     {
         printk("32-bit Execution: Unsupported\n");
     }
+
+    processor_setup();
 }
 
 static void dt_unreserved_regions(paddr_t s, paddr_t e,
diff --git a/xen/include/asm-arm/procinfo.h b/xen/include/asm-arm/procinfo.h
index 9d3feb7..9cb7a86 100644
--- a/xen/include/asm-arm/procinfo.h
+++ b/xen/include/asm-arm/procinfo.h
@@ -21,10 +21,23 @@ 
 #ifndef __ASM_ARM_PROCINFO_H
 #define __ASM_ARM_PROCINFO_H
 
+#include <xen/sched.h>
+
+struct processor {
+    /* Initialize specific processor register for the new VPCU*/
+    void (*vcpu_initialize)(struct vcpu *v);
+};
+
 struct proc_info_list {
-	unsigned int		cpu_val;
-	unsigned int		cpu_mask;
+    unsigned int        cpu_val;
+    unsigned int        cpu_mask;
     void                (*cpu_init)(void);
+    struct processor    *processor;
 };
 
+const __init struct proc_info_list *lookup_processor_type(void);
+
+void __init processor_setup(void);
+void processor_vcpu_initialize(struct vcpu *v);
+
 #endif