All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bin Meng <bmeng.cn@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v4 31/35] acpi: Add support for DSDT generation
Date: Mon, 13 Jul 2020 11:17:15 +0800	[thread overview]
Message-ID: <CAEUhbmWgA5X3EKzV-M4yfZA0_E1UhyyZwixF8MfmfKV4BJ06=w@mail.gmail.com> (raw)
In-Reply-To: <20200707191212.2542638-18-sjg@chromium.org>

On Wed, Jul 8, 2020 at 3:13 AM Simon Glass <sjg@chromium.org> wrote:
>
> Some devices need to inject extra code into the Differentiated System
> Descriptor Table (DSDT). Add a method to handle this.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
> ---
>
> Changes in v4:
> - Explain why 'fill' is used for one method and 'inject' for another
>
> Changes in v3:
> - Fix 'THe' typo
> - Rename build_type() to sort_acpi_item_type()
>
> Changes in v1:
> - Generalise the ACPI function recursion with acpi_recurse_method()
>
>  arch/sandbox/dts/test.dts |  2 ++
>  drivers/core/acpi.c       | 25 +++++++++++++++++++++-
>  include/dm/acpi.h         | 30 ++++++++++++++++++++++++++
>  test/dm/acpi.c            | 44 +++++++++++++++++++++++++++++++++++++++
>  4 files changed, 100 insertions(+), 1 deletion(-)
>
> diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
> index 6687efe2ae..fc6a6b1774 100644
> --- a/arch/sandbox/dts/test.dts
> +++ b/arch/sandbox/dts/test.dts
> @@ -257,6 +257,7 @@
>         acpi_test1: acpi-test {
>                 compatible = "denx,u-boot-acpi-test";
>                 acpi-ssdt-test-data = "ab";
> +               acpi-dsdt-test-data = "hi";
>                 child {
>                         compatible = "denx,u-boot-acpi-test";
>                 };
> @@ -265,6 +266,7 @@
>         acpi_test2: acpi-test2 {
>                 compatible = "denx,u-boot-acpi-test";
>                 acpi-ssdt-test-data = "cd";
> +               acpi-dsdt-test-data = "jk";
>         };
>
>         clocks {
> diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c
> index a9b7fc1d9a..7b32694ad4 100644
> --- a/drivers/core/acpi.c
> +++ b/drivers/core/acpi.c
> @@ -22,12 +22,14 @@
>  enum gen_type_t {
>         TYPE_NONE,
>         TYPE_SSDT,
> +       TYPE_DSDT,
>  };
>
>  /* Type of method to call */
>  enum method_t {
>         METHOD_WRITE_TABLES,
>         METHOD_FILL_SSDT,
> +       METHOD_INJECT_DSDT,
>  };
>
>  /* Prototype for all methods */
> @@ -144,7 +146,9 @@ static int sort_acpi_item_type(struct acpi_ctx *ctx, void *start,
>         void *end = ctx->current;
>
>         ptr = start;
> -       order = ofnode_read_chosen_prop("u-boot,acpi-ssdt-order", &size);
> +       order = ofnode_read_chosen_prop(type == TYPE_DSDT ?
> +                                       "u-boot,acpi-dsdt-order" :
> +                                       "u-boot,acpi-ssdt-order", &size);
>         if (!order) {
>                 log_warning("Failed to find ordering, leaving as is\n");
>                 return 0;
> @@ -198,6 +202,8 @@ acpi_method acpi_get_method(struct udevice *dev, enum method_t method)
>                         return aops->write_tables;
>                 case METHOD_FILL_SSDT:
>                         return aops->fill_ssdt;
> +               case METHOD_INJECT_DSDT:
> +                       return aops->inject_dsdt;
>                 }
>         }
>
> @@ -256,6 +262,23 @@ int acpi_fill_ssdt(struct acpi_ctx *ctx)
>         return ret;
>  }
>
> +int acpi_inject_dsdt(struct acpi_ctx *ctx)
> +{
> +       void *start = ctx->current;
> +       int ret;
> +
> +       log_debug("Writing DSDT tables\n");
> +       item_count = 0;
> +       ret = acpi_recurse_method(ctx, dm_root(), METHOD_INJECT_DSDT,
> +                                 TYPE_DSDT);
> +       log_debug("Writing DSDT finished, err=%d\n", ret);
> +       ret = sort_acpi_item_type(ctx, start, TYPE_DSDT);
> +       if (ret)
> +               return log_msg_ret("build", ret);
> +
> +       return ret;
> +}
> +
>  int acpi_write_dev_tables(struct acpi_ctx *ctx)
>  {
>         int ret;
> diff --git a/include/dm/acpi.h b/include/dm/acpi.h
> index e956e49680..72fa71d0a2 100644
> --- a/include/dm/acpi.h
> +++ b/include/dm/acpi.h
> @@ -82,11 +82,31 @@ struct acpi_ops {
>          * whatever ACPI code is needed by this device. It will end up in the
>          * SSDT table.
>          *
> +        * Note that this is called 'fill' because the entire contents of the
> +        * SSDT is build by calling this method on all devices.
> +        *
>          * @dev: Device to write
>          * @ctx: ACPI context to use
>          * @return 0 if OK, -ve on error
>          */
>         int (*fill_ssdt)(const struct udevice *dev, struct acpi_ctx *ctx);
> +
> +       /**
> +        * inject_dsdt() - Generate DSDT code for a device
> +        *
> +        * This is called to create the DSDT code. The method should write out
> +        * whatever ACPI code is needed by this device. It will end up in the
> +        * DSDT table.
> +        *
> +        * Note that this is called 'inject' because the output of calling this
> +        * method on all devices is injected into the DSDT, the bulk of which
> +        * is writte in .asl files for the board.

is wirtten

> +        *
> +        * @dev: Device to write
> +        * @ctx: ACPI context to use
> +        * @return 0 if OK, -ve on error
> +        */
> +       int (*inject_dsdt)(const struct udevice *dev, struct acpi_ctx *ctx);
>  };
>
>  #define device_get_acpi_ops(dev)       ((dev)->driver->acpi_ops)
> @@ -141,6 +161,16 @@ int acpi_write_dev_tables(struct acpi_ctx *ctx);
>   */
>  int acpi_fill_ssdt(struct acpi_ctx *ctx);
>
> +/**
> + * acpi_inject_dsdt() - Generate ACPI tables for DSDT
> + *
> + * This is called to create the DSDT code for all devices.
> + *
> + * @ctx: ACPI context to use
> + * @return 0 if OK, -ve on error
> + */
> +int acpi_inject_dsdt(struct acpi_ctx *ctx);
> +
>  #endif /* __ACPI__ */
>
>  #endif
> diff --git a/test/dm/acpi.c b/test/dm/acpi.c
> index 4e1d401e0d..1abde65c8c 100644
> --- a/test/dm/acpi.c
> +++ b/test/dm/acpi.c
> @@ -81,10 +81,24 @@ static int testacpi_fill_ssdt(const struct udevice *dev, struct acpi_ctx *ctx)
>         return 0;
>  }
>
> +static int testacpi_inject_dsdt(const struct udevice *dev, struct acpi_ctx *ctx)
> +{
> +       const char *data;
> +
> +       data = dev_read_string(dev, "acpi-dsdt-test-data");
> +       if (data) {
> +               while (*data)
> +                       acpigen_emit_byte(ctx, *data++);
> +       }
> +
> +       return 0;
> +}
> +
>  struct acpi_ops testacpi_ops = {
>         .get_name       = testacpi_get_name,
>         .write_tables   = testacpi_write_tables,
>         .fill_ssdt      = testacpi_fill_ssdt,
> +       .inject_dsdt    = testacpi_inject_dsdt,
>  };
>
>  static const struct udevice_id testacpi_ids[] = {
> @@ -441,3 +455,33 @@ static int dm_test_acpi_fill_ssdt(struct unit_test_state *uts)
>         return 0;
>  }
>  DM_TEST(dm_test_acpi_fill_ssdt, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
> +
> +/* Test acpi_inject_dsdt() */
> +static int dm_test_acpi_inject_dsdt(struct unit_test_state *uts)
> +{
> +       struct acpi_ctx ctx;
> +       u8 *buf;
> +
> +       buf = malloc(BUF_SIZE);
> +       ut_assertnonnull(buf);
> +
> +       ctx.current = buf;
> +       buf[4] = 'z';   /* sentinel */
> +       ut_assertok(acpi_inject_dsdt(&ctx));
> +
> +       /*
> +        * These values come from acpi-test's acpi-dsdt-test-data property.
> +        * There is no u-boot,acpi-dsdt-order so device-tree order is used.
> +        */
> +       ut_asserteq('h', buf[0]);
> +       ut_asserteq('i', buf[1]);
> +
> +       /* These values come from acpi-test's acpi-dsdt-test-data property */
> +       ut_asserteq('j', buf[2]);
> +       ut_asserteq('k', buf[3]);
> +
> +       ut_asserteq('z', buf[4]);
> +
> +       return 0;
> +}
> +DM_TEST(dm_test_acpi_inject_dsdt, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
> --

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

  reply	other threads:[~2020-07-13  3:17 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-07 19:11 [PATCH v4 00/35] dm: Add programmatic generation of ACPI tables (part B) Simon Glass
2020-07-07 19:11 ` [PATCH v4 01/35] dm: core: Add an ACPI name for the root node Simon Glass
2020-07-07 19:11 ` [PATCH v4 02/35] acpi: Add a function to get a device path and scope Simon Glass
2020-07-07 19:11 ` [PATCH v4 03/35] acpi: Add a way to check device status Simon Glass
2020-07-07 19:11 ` [PATCH v4 04/35] irq: Add a method to convert an interrupt to ACPI Simon Glass
2020-07-07 19:11 ` [PATCH v4 05/35] acpi: Support generation of ACPI code Simon Glass
2020-07-13  2:38   ` Bin Meng
2020-07-07 19:11 ` [PATCH v4 06/35] acpi: Support generation of interrupt descriptor Simon Glass
2020-07-13  2:41   ` Bin Meng
2020-07-07 19:11 ` [PATCH v4 07/35] gpio: Add a method to convert a GPIO to ACPI Simon Glass
2020-07-13  2:44   ` Bin Meng
2020-07-07 19:11 ` [PATCH v4 08/35] acpi: Support string output Simon Glass
2020-07-07 19:11 ` [PATCH v4 09/35] acpi: Support generation of GPIO descriptor Simon Glass
2020-07-13  2:47   ` Bin Meng
2020-07-13  4:22     ` Bin Meng
2020-07-07 19:11 ` [PATCH v4 10/35] acpi: Support generation of a GPIO/irq for a device Simon Glass
2020-07-07 19:11 ` [PATCH v4 11/35] acpi: Support generation of I2C descriptor Simon Glass
2020-07-07 19:11 ` [PATCH v4 12/35] acpi: Support generation of SPI descriptor Simon Glass
2020-07-13  4:22   ` Bin Meng
2020-07-13  5:48     ` Bin Meng
2020-08-29 21:20       ` Simon Glass
2020-07-07 19:11 ` [PATCH v4 13/35] acpigen: Support writing a length Simon Glass
2020-07-13  2:53   ` Bin Meng
2020-07-07 19:11 ` [PATCH v4 14/35] acpigen: Support writing a package Simon Glass
2020-07-07 19:11 ` [PATCH v4 15/35] acpi: Support writing an integer Simon Glass
2020-07-07 19:11 ` [PATCH v4 16/35] acpi: Support writing a string Simon Glass
2020-07-07 19:11 ` [PATCH v4 17/35] acpi: Support writing a name Simon Glass
2020-07-07 19:11 ` [PATCH v4 18/35] acpi: Support writing a UUID Simon Glass
2020-07-07 19:11 ` [PATCH v4 19/35] acpi: Support writing Device Properties objects via _DSD Simon Glass
2020-07-13  2:58   ` Bin Meng
2020-07-07 19:11 ` [PATCH v4 20/35] acpi: Support writing a GPIO Simon Glass
2020-07-07 19:11 ` [PATCH v4 21/35] acpi: Support copying properties from device tree to ACPI Simon Glass
2020-07-07 19:11 ` [PATCH v4 22/35] acpi: Add support for various misc ACPI opcodes Simon Glass
2020-07-07 19:12 ` [PATCH v4 23/35] acpi: Add support for writing a Power Resource Simon Glass
2020-07-07 19:12 ` [PATCH v4 24/35] acpi: Add support for writing a GPIO power sequence Simon Glass
2020-07-13  3:09   ` Bin Meng
2020-07-07 19:12 ` [PATCH v4 25/35] acpi: Add support for a generic " Simon Glass
2020-07-13  3:10   ` Bin Meng
2020-07-07 19:12 ` [PATCH v4 26/35] acpi: Add support for SSDT generation Simon Glass
2020-07-07 19:12 ` [PATCH v4 27/35] x86: acpi: Move MADT down a bit Simon Glass
2020-07-07 19:12 ` [PATCH v4 28/35] acpi: Record the items added to SSDT Simon Glass
2020-07-07 19:12 ` [PATCH v4 29/35] acpi: Support ordering SSDT data by device Simon Glass
2020-07-13  3:15   ` Bin Meng
2020-07-13  5:15   ` Bin Meng
2020-07-07 19:12 ` [PATCH v4 30/35] x86: Allow devices to write an SSDT Simon Glass
2020-07-07 19:12 ` [PATCH v4 31/35] acpi: Add support for DSDT generation Simon Glass
2020-07-13  3:17   ` Bin Meng [this message]
2020-07-13  4:22     ` Bin Meng
2020-07-07 19:12 ` [PATCH v4 32/35] x86: Allow devices to write to DSDT Simon Glass
2020-07-07 19:12 ` [PATCH v4 33/35] pci: Avoid a crash in device_is_on_pci_bus() Simon Glass
2020-07-07 19:12 ` [PATCH v4 34/35] dm: acpi: Enhance acpi_get_name() Simon Glass
2020-07-13  3:18   ` Bin Meng
2020-07-07 19:12 ` [PATCH v4 35/35] acpi: Add an acpi command to list/dump generated ACPI items Simon Glass
2020-07-13  4:25 ` [PATCH v4 00/35] dm: Add programmatic generation of ACPI tables (part B) Bin Meng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEUhbmWgA5X3EKzV-M4yfZA0_E1UhyyZwixF8MfmfKV4BJ06=w@mail.gmail.com' \
    --to=bmeng.cn@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.