diff mbox

[v2,05/47] acpi: add acpi_if() term

Message ID 1421938231-25698-6-git-send-email-imammedo@redhat.com
State New
Headers show

Commit Message

Igor Mammedov Jan. 22, 2015, 2:49 p.m. UTC
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/acpi/acpi-build-utils.c         | 8 ++++++++
 include/hw/acpi/acpi-build-utils.h | 1 +
 2 files changed, 9 insertions(+)

Comments

Marcel Apfelbaum Feb. 5, 2015, 3:01 p.m. UTC | #1
On 01/22/2015 04:49 PM, Igor Mammedov wrote:
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
>   hw/acpi/acpi-build-utils.c         | 8 ++++++++
>   include/hw/acpi/acpi-build-utils.h | 1 +
>   2 files changed, 9 insertions(+)
>
> diff --git a/hw/acpi/acpi-build-utils.c b/hw/acpi/acpi-build-utils.c
> index d0b0159..40a1769 100644
> --- a/hw/acpi/acpi-build-utils.c
> +++ b/hw/acpi/acpi-build-utils.c
> @@ -314,6 +314,14 @@ static AcpiAml aml_allocate_internal(uint8_t op, AcpiBlockFlags flags)
>       return var;
>   }
>
> +/* ACPI 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
> +AcpiAml acpi_if(AcpiAml predicate)
> +{
> +    AcpiAml var = aml_allocate_internal(0xA0 /* IfOp */, PACKAGE);
> +    aml_append(&var, predicate);
> +    return var;
> +}
There are other ACPI constructs exactly like the above, except
the operation number (0xA0).
Maybe we can have a generic internal function and the API
will call it.

For example IfWhile has the same structure except the op number,
and maybe many other Type 1 Opcodes.

Thanks,
Marcel

> +
>   /* ACPI 5.0: 20.2.5.2 Named Objects Encoding: DefMethod */
>   AcpiAml acpi_method(const char *name, int arg_count)
>   {
> diff --git a/include/hw/acpi/acpi-build-utils.h b/include/hw/acpi/acpi-build-utils.h
> index 19ebc2d..177f9ed 100644
> --- a/include/hw/acpi/acpi-build-utils.h
> +++ b/include/hw/acpi/acpi-build-utils.h
> @@ -22,6 +22,7 @@ typedef struct AcpiAml {
>   void aml_append(AcpiAml *parent_ctx, AcpiAml child);
>
>   /* Block ASL object primitives */
> +AcpiAml acpi_if(AcpiAml predicate);
>   AcpiAml acpi_method(const char *name, int arg_count);
>   AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...);
>   AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...);
>
Igor Mammedov Feb. 5, 2015, 5:54 p.m. UTC | #2
On Thu, 05 Feb 2015 17:01:33 +0200
Marcel Apfelbaum <marcel@redhat.com> wrote:

> On 01/22/2015 04:49 PM, Igor Mammedov wrote:
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> >   hw/acpi/acpi-build-utils.c         | 8 ++++++++
> >   include/hw/acpi/acpi-build-utils.h | 1 +
> >   2 files changed, 9 insertions(+)
> >
> > diff --git a/hw/acpi/acpi-build-utils.c b/hw/acpi/acpi-build-utils.c
> > index d0b0159..40a1769 100644
> > --- a/hw/acpi/acpi-build-utils.c
> > +++ b/hw/acpi/acpi-build-utils.c
> > @@ -314,6 +314,14 @@ static AcpiAml aml_allocate_internal(uint8_t op, AcpiBlockFlags flags)
> >       return var;
> >   }
> >
> > +/* ACPI 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
> > +AcpiAml acpi_if(AcpiAml predicate)
> > +{
> > +    AcpiAml var = aml_allocate_internal(0xA0 /* IfOp */, PACKAGE);
> > +    aml_append(&var, predicate);
> > +    return var;
> > +}
> There are other ACPI constructs exactly like the above, except
> the operation number (0xA0).
> Maybe we can have a generic internal function and the API
> will call it.
> 
> For example IfWhile has the same structure except the op number,
> and maybe many other Type 1 Opcodes.
since wrappers are trivial and very simple I'd prefer to keep 2 similar
functions than 2 wrappers and more generic one, which would force
me to jump around code when reading it.
It also helps to compare functions with ABNF for term in spec.


> 
> Thanks,
> Marcel
> 
> > +
> >   /* ACPI 5.0: 20.2.5.2 Named Objects Encoding: DefMethod */
> >   AcpiAml acpi_method(const char *name, int arg_count)
> >   {
> > diff --git a/include/hw/acpi/acpi-build-utils.h b/include/hw/acpi/acpi-build-utils.h
> > index 19ebc2d..177f9ed 100644
> > --- a/include/hw/acpi/acpi-build-utils.h
> > +++ b/include/hw/acpi/acpi-build-utils.h
> > @@ -22,6 +22,7 @@ typedef struct AcpiAml {
> >   void aml_append(AcpiAml *parent_ctx, AcpiAml child);
> >
> >   /* Block ASL object primitives */
> > +AcpiAml acpi_if(AcpiAml predicate);
> >   AcpiAml acpi_method(const char *name, int arg_count);
> >   AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...);
> >   AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...);
> >
>
diff mbox

Patch

diff --git a/hw/acpi/acpi-build-utils.c b/hw/acpi/acpi-build-utils.c
index d0b0159..40a1769 100644
--- a/hw/acpi/acpi-build-utils.c
+++ b/hw/acpi/acpi-build-utils.c
@@ -314,6 +314,14 @@  static AcpiAml aml_allocate_internal(uint8_t op, AcpiBlockFlags flags)
     return var;
 }
 
+/* ACPI 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefIfElse */
+AcpiAml acpi_if(AcpiAml predicate)
+{
+    AcpiAml var = aml_allocate_internal(0xA0 /* IfOp */, PACKAGE);
+    aml_append(&var, predicate);
+    return var;
+}
+
 /* ACPI 5.0: 20.2.5.2 Named Objects Encoding: DefMethod */
 AcpiAml acpi_method(const char *name, int arg_count)
 {
diff --git a/include/hw/acpi/acpi-build-utils.h b/include/hw/acpi/acpi-build-utils.h
index 19ebc2d..177f9ed 100644
--- a/include/hw/acpi/acpi-build-utils.h
+++ b/include/hw/acpi/acpi-build-utils.h
@@ -22,6 +22,7 @@  typedef struct AcpiAml {
 void aml_append(AcpiAml *parent_ctx, AcpiAml child);
 
 /* Block ASL object primitives */
+AcpiAml acpi_if(AcpiAml predicate);
 AcpiAml acpi_method(const char *name, int arg_count);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...);
 AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...);