diff mbox

[v4,07/16] libxl/arm: Construct ACPI GTDT table

Message ID 1471343113-10652-8-git-send-email-zhaoshenglong@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Shannon Zhao Aug. 16, 2016, 10:25 a.m. UTC
From: Shannon Zhao <shannon.zhao@linaro.org>

Construct GTDT table with the interrupt information of timers.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 tools/libxl/libxl_arm_acpi.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

Comments

Wei Liu Aug. 24, 2016, 12:56 p.m. UTC | #1
On Tue, Aug 16, 2016 at 06:25:04PM +0800, Shannon Zhao wrote:
> From: Shannon Zhao <shannon.zhao@linaro.org>
> 
> Construct GTDT table with the interrupt information of timers.
> 
> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
> ---
>  tools/libxl/libxl_arm_acpi.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
> index 8cd1d9b..28fb6fe 100644
> --- a/tools/libxl/libxl_arm_acpi.c
> +++ b/tools/libxl/libxl_arm_acpi.c
> @@ -24,10 +24,18 @@ typedef uint8_t u8;
>  typedef uint16_t u16;
>  typedef uint32_t u32;
>  typedef uint64_t u64;
> +typedef int64_t s64;
>  
>  #include <acpi/acconfig.h>
>  #include <acpi/actbl.h>
>  
> +#include <asm-generic/bitsperlong.h>

Hmm... This is likely to be Linux-centric. But I'm not sure if FreeBSD
or other BSDes have plan for Xen on ARM support.

CC Roger here.

> +#define ACPI_MACHINE_WIDTH __BITS_PER_LONG
> +#define COMPILER_DEPENDENT_INT64 int64_t
> +#define COMPILER_DEPENDENT_UINT64 uint64_t
> +
> +#include <acpi/actypes.h>
> +
>  _hidden
>  extern const unsigned char dsdt_anycpu_arm[];
>  _hidden
> @@ -175,6 +183,26 @@ static void make_acpi_xsdt(libxl__gc *gc, struct xc_dom_image *dom,
>                         acpitables[XSDT].size);
>  }
>  
> +static void make_acpi_gtdt(libxl__gc *gc, struct xc_dom_image *dom,
> +                           struct acpitable acpitables[])
> +{
> +    uint64_t offset = acpitables[GTDT].addr - GUEST_ACPI_BASE;
> +    struct acpi_table_gtdt *gtdt = (void *)dom->acpi_modules[0].data + offset;
> +
> +    gtdt->non_secure_el1_interrupt = GUEST_TIMER_PHYS_NS_PPI;
> +    gtdt->non_secure_el1_flags =
> +                             (ACPI_LEVEL_SENSITIVE << ACPI_GTDT_INTERRUPT_MODE)
> +                             |(ACPI_ACTIVE_LOW << ACPI_GTDT_INTERRUPT_POLARITY);
> +    gtdt->virtual_timer_interrupt = GUEST_TIMER_VIRT_PPI;
> +    gtdt->virtual_timer_flags =
> +                             (ACPI_LEVEL_SENSITIVE << ACPI_GTDT_INTERRUPT_MODE)
> +                             |(ACPI_ACTIVE_LOW << ACPI_GTDT_INTERRUPT_POLARITY);
> +
> +    make_acpi_header(&gtdt->header, "GTDT", acpitables[GTDT].size, 2);
> +    calculate_checksum(gtdt, offsetof(struct acpi_table_header, checksum),
> +                       acpitables[GTDT].size);
> +}
> +
>  int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
>                          libxl__domain_build_state *state,
>                          struct xc_dom_image *dom)
> @@ -205,6 +233,7 @@ int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
>  
>      make_acpi_rsdp(gc, dom, acpitables);
>      make_acpi_xsdt(gc, dom, acpitables);
> +    make_acpi_gtdt(gc, dom, acpitables);
>  
>  out:
>      return rc;
> -- 
> 2.0.4
> 
>
Roger Pau Monné Aug. 24, 2016, 2:13 p.m. UTC | #2
On Wed, Aug 24, 2016 at 01:56:04PM +0100, Wei Liu wrote:
> On Tue, Aug 16, 2016 at 06:25:04PM +0800, Shannon Zhao wrote:
> > From: Shannon Zhao <shannon.zhao@linaro.org>
> > 
> > Construct GTDT table with the interrupt information of timers.
> > 
> > Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
> > ---
> >  tools/libxl/libxl_arm_acpi.c | 29 +++++++++++++++++++++++++++++
> >  1 file changed, 29 insertions(+)
> > 
> > diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
> > index 8cd1d9b..28fb6fe 100644
> > --- a/tools/libxl/libxl_arm_acpi.c
> > +++ b/tools/libxl/libxl_arm_acpi.c
> > @@ -24,10 +24,18 @@ typedef uint8_t u8;
> >  typedef uint16_t u16;
> >  typedef uint32_t u32;
> >  typedef uint64_t u64;
> > +typedef int64_t s64;
> >  
> >  #include <acpi/acconfig.h>
> >  #include <acpi/actbl.h>
> >  
> > +#include <asm-generic/bitsperlong.h>
> 
> Hmm... This is likely to be Linux-centric. But I'm not sure if FreeBSD
> or other BSDes have plan for Xen on ARM support.

I would certainly love to see that happen, but I don't see myself working on 
that in the near future. In any case, this is a Linux-specific header, and 
should be included in libxl_osdeps.h. I would recommend that you use 
something like:

#ifndef BITS_PER_LONG
#ifdef _LP64
#define BITS_PER_LONG 64
#else
#define BITS_PER_LONG 32
#endif
#endif

So that it works on other systems also (or maybe you don't even need to 
include bitsperlong.h at all).

Roger.
Shannon Zhao Aug. 25, 2016, 7:58 a.m. UTC | #3
On 2016/8/24 22:13, Roger Pau Monné wrote:
> On Wed, Aug 24, 2016 at 01:56:04PM +0100, Wei Liu wrote:
>> On Tue, Aug 16, 2016 at 06:25:04PM +0800, Shannon Zhao wrote:
>>> From: Shannon Zhao <shannon.zhao@linaro.org>
>>>
>>> Construct GTDT table with the interrupt information of timers.
>>>
>>> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
>>> ---
>>>  tools/libxl/libxl_arm_acpi.c | 29 +++++++++++++++++++++++++++++
>>>  1 file changed, 29 insertions(+)
>>>
>>> diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
>>> index 8cd1d9b..28fb6fe 100644
>>> --- a/tools/libxl/libxl_arm_acpi.c
>>> +++ b/tools/libxl/libxl_arm_acpi.c
>>> @@ -24,10 +24,18 @@ typedef uint8_t u8;
>>>  typedef uint16_t u16;
>>>  typedef uint32_t u32;
>>>  typedef uint64_t u64;
>>> +typedef int64_t s64;
>>>  
>>>  #include <acpi/acconfig.h>
>>>  #include <acpi/actbl.h>
>>>  
>>> +#include <asm-generic/bitsperlong.h>
>>
>> Hmm... This is likely to be Linux-centric. But I'm not sure if FreeBSD
>> or other BSDes have plan for Xen on ARM support.
> 
> I would certainly love to see that happen, but I don't see myself working on 
> that in the near future. In any case, this is a Linux-specific header, and 
> should be included in libxl_osdeps.h. I would recommend that you use 
> something like:
> 
> #ifndef BITS_PER_LONG
> #ifdef _LP64
> #define BITS_PER_LONG 64
> #else
> #define BITS_PER_LONG 32
> #endif
> #endif
> 
> So that it works on other systems also (or maybe you don't even need to 
> include bitsperlong.h at all).
> 
OK, will fix this.

Thanks,
Julien Grall Aug. 29, 2016, 6:16 p.m. UTC | #4
Hi Shannon,

On 16/08/2016 06:25, Shannon Zhao wrote:
> From: Shannon Zhao <shannon.zhao@linaro.org>
>
> Construct GTDT table with the interrupt information of timers.
>
> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
> ---
>  tools/libxl/libxl_arm_acpi.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
>
> diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
> index 8cd1d9b..28fb6fe 100644
> --- a/tools/libxl/libxl_arm_acpi.c
> +++ b/tools/libxl/libxl_arm_acpi.c
> @@ -24,10 +24,18 @@ typedef uint8_t u8;
>  typedef uint16_t u16;
>  typedef uint32_t u32;
>  typedef uint64_t u64;
> +typedef int64_t s64;
>
>  #include <acpi/acconfig.h>
>  #include <acpi/actbl.h>
>
> +#include <asm-generic/bitsperlong.h>
> +#define ACPI_MACHINE_WIDTH __BITS_PER_LONG
> +#define COMPILER_DEPENDENT_INT64 int64_t
> +#define COMPILER_DEPENDENT_UINT64 uint64_t
> +
> +#include <acpi/actypes.h>
> +
>  _hidden
>  extern const unsigned char dsdt_anycpu_arm[];
>  _hidden
> @@ -175,6 +183,26 @@ static void make_acpi_xsdt(libxl__gc *gc, struct xc_dom_image *dom,
>                         acpitables[XSDT].size);
>  }
>
> +static void make_acpi_gtdt(libxl__gc *gc, struct xc_dom_image *dom,
> +                           struct acpitable acpitables[])
> +{
> +    uint64_t offset = acpitables[GTDT].addr - GUEST_ACPI_BASE;
> +    struct acpi_table_gtdt *gtdt = (void *)dom->acpi_modules[0].data + offset;
> +
> +    gtdt->non_secure_el1_interrupt = GUEST_TIMER_PHYS_NS_PPI;
> +    gtdt->non_secure_el1_flags =
> +                             (ACPI_LEVEL_SENSITIVE << ACPI_GTDT_INTERRUPT_MODE)
> +                             |(ACPI_ACTIVE_LOW << ACPI_GTDT_INTERRUPT_POLARITY);
> +    gtdt->virtual_timer_interrupt = GUEST_TIMER_VIRT_PPI;
> +    gtdt->virtual_timer_flags =
> +                             (ACPI_LEVEL_SENSITIVE << ACPI_GTDT_INTERRUPT_MODE)
> +                             |(ACPI_ACTIVE_LOW << ACPI_GTDT_INTERRUPT_POLARITY);
> +

I don't see any setting for the field counter_block_address. From the 
ACPI spec, the field should be 0xFFFFFFFFFFFFFFFF when the counter 
control block is not available.

> +    make_acpi_header(&gtdt->header, "GTDT", acpitables[GTDT].size, 2);
> +    calculate_checksum(gtdt, offsetof(struct acpi_table_header, checksum),
> +                       acpitables[GTDT].size);
> +}
> +
>  int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
>                          libxl__domain_build_state *state,
>                          struct xc_dom_image *dom)
> @@ -205,6 +233,7 @@ int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
>
>      make_acpi_rsdp(gc, dom, acpitables);
>      make_acpi_xsdt(gc, dom, acpitables);
> +    make_acpi_gtdt(gc, dom, acpitables);
>
>  out:
>      return rc;
>

Regards,
Shannon Zhao Aug. 30, 2016, 1:36 a.m. UTC | #5
On 2016/8/30 2:16, Julien Grall wrote:
> On 16/08/2016 06:25, Shannon Zhao wrote:
>> From: Shannon Zhao <shannon.zhao@linaro.org>
>>
>> Construct GTDT table with the interrupt information of timers.
>>
>> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
>> ---
>>  tools/libxl/libxl_arm_acpi.c | 29 +++++++++++++++++++++++++++++
>>  1 file changed, 29 insertions(+)
>>
>> diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
>> index 8cd1d9b..28fb6fe 100644
>> --- a/tools/libxl/libxl_arm_acpi.c
>> +++ b/tools/libxl/libxl_arm_acpi.c
>> @@ -24,10 +24,18 @@ typedef uint8_t u8;
>>  typedef uint16_t u16;
>>  typedef uint32_t u32;
>>  typedef uint64_t u64;
>> +typedef int64_t s64;
>>
>>  #include <acpi/acconfig.h>
>>  #include <acpi/actbl.h>
>>
>> +#include <asm-generic/bitsperlong.h>
>> +#define ACPI_MACHINE_WIDTH __BITS_PER_LONG
>> +#define COMPILER_DEPENDENT_INT64 int64_t
>> +#define COMPILER_DEPENDENT_UINT64 uint64_t
>> +
>> +#include <acpi/actypes.h>
>> +
>>  _hidden
>>  extern const unsigned char dsdt_anycpu_arm[];
>>  _hidden
>> @@ -175,6 +183,26 @@ static void make_acpi_xsdt(libxl__gc *gc, struct
>> xc_dom_image *dom,
>>                         acpitables[XSDT].size);
>>  }
>>
>> +static void make_acpi_gtdt(libxl__gc *gc, struct xc_dom_image *dom,
>> +                           struct acpitable acpitables[])
>> +{
>> +    uint64_t offset = acpitables[GTDT].addr - GUEST_ACPI_BASE;
>> +    struct acpi_table_gtdt *gtdt = (void *)dom->acpi_modules[0].data
>> + offset;
>> +
>> +    gtdt->non_secure_el1_interrupt = GUEST_TIMER_PHYS_NS_PPI;
>> +    gtdt->non_secure_el1_flags =
>> +                             (ACPI_LEVEL_SENSITIVE <<
>> ACPI_GTDT_INTERRUPT_MODE)
>> +                             |(ACPI_ACTIVE_LOW <<
>> ACPI_GTDT_INTERRUPT_POLARITY);
>> +    gtdt->virtual_timer_interrupt = GUEST_TIMER_VIRT_PPI;
>> +    gtdt->virtual_timer_flags =
>> +                             (ACPI_LEVEL_SENSITIVE <<
>> ACPI_GTDT_INTERRUPT_MODE)
>> +                             |(ACPI_ACTIVE_LOW <<
>> ACPI_GTDT_INTERRUPT_POLARITY);
>> +
> 
> I don't see any setting for the field counter_block_address. From the
> ACPI spec, the field should be 0xFFFFFFFFFFFFFFFF when the counter
> control block is not available
Oops, will add. Thanks.
diff mbox

Patch

diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c
index 8cd1d9b..28fb6fe 100644
--- a/tools/libxl/libxl_arm_acpi.c
+++ b/tools/libxl/libxl_arm_acpi.c
@@ -24,10 +24,18 @@  typedef uint8_t u8;
 typedef uint16_t u16;
 typedef uint32_t u32;
 typedef uint64_t u64;
+typedef int64_t s64;
 
 #include <acpi/acconfig.h>
 #include <acpi/actbl.h>
 
+#include <asm-generic/bitsperlong.h>
+#define ACPI_MACHINE_WIDTH __BITS_PER_LONG
+#define COMPILER_DEPENDENT_INT64 int64_t
+#define COMPILER_DEPENDENT_UINT64 uint64_t
+
+#include <acpi/actypes.h>
+
 _hidden
 extern const unsigned char dsdt_anycpu_arm[];
 _hidden
@@ -175,6 +183,26 @@  static void make_acpi_xsdt(libxl__gc *gc, struct xc_dom_image *dom,
                        acpitables[XSDT].size);
 }
 
+static void make_acpi_gtdt(libxl__gc *gc, struct xc_dom_image *dom,
+                           struct acpitable acpitables[])
+{
+    uint64_t offset = acpitables[GTDT].addr - GUEST_ACPI_BASE;
+    struct acpi_table_gtdt *gtdt = (void *)dom->acpi_modules[0].data + offset;
+
+    gtdt->non_secure_el1_interrupt = GUEST_TIMER_PHYS_NS_PPI;
+    gtdt->non_secure_el1_flags =
+                             (ACPI_LEVEL_SENSITIVE << ACPI_GTDT_INTERRUPT_MODE)
+                             |(ACPI_ACTIVE_LOW << ACPI_GTDT_INTERRUPT_POLARITY);
+    gtdt->virtual_timer_interrupt = GUEST_TIMER_VIRT_PPI;
+    gtdt->virtual_timer_flags =
+                             (ACPI_LEVEL_SENSITIVE << ACPI_GTDT_INTERRUPT_MODE)
+                             |(ACPI_ACTIVE_LOW << ACPI_GTDT_INTERRUPT_POLARITY);
+
+    make_acpi_header(&gtdt->header, "GTDT", acpitables[GTDT].size, 2);
+    calculate_checksum(gtdt, offsetof(struct acpi_table_header, checksum),
+                       acpitables[GTDT].size);
+}
+
 int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
                         libxl__domain_build_state *state,
                         struct xc_dom_image *dom)
@@ -205,6 +233,7 @@  int libxl__prepare_acpi(libxl__gc *gc, libxl_domain_build_info *info,
 
     make_acpi_rsdp(gc, dom, acpitables);
     make_acpi_xsdt(gc, dom, acpitables);
+    make_acpi_gtdt(gc, dom, acpitables);
 
 out:
     return rc;