All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
To: u-boot@lists.denx.de
Subject: Antwort: [PATCH v2 32/39] irq: Add a method to convert an interrupt to ACPI
Date: Wed, 18 Mar 2020 17:17:54 +0100	[thread overview]
Message-ID: <OF80768302.89C292FA-ONC125852F.00596AB0-C125852F.00597707@br-automation.com> (raw)
In-Reply-To: <20200308214442.v2.32.I29adaf758a9ea81f51ffbecf89b53983968a0d2a@changeid>

Hi Simon,

"Simon Glass" <sjg@chromium.org> schrieb am 09.03.2020 04:44:56:

> Von: "Simon Glass" <sjg@chromium.org>
> An: "U-Boot Mailing List" <u-boot@lists.denx.de>, 
> Kopie: "Bin Meng" <bmeng.cn@gmail.com>, "Wolfgang Wallner" 
> <wolfgang.wallner@br-automation.com>, "Andy Shevchenko" 
> <andriy.shevchenko@linux.intel.com>, "Simon Glass" <sjg@chromium.org>
> Datum: 09.03.2020 04:46
> Betreff: [PATCH v2 32/39] irq: Add a method to convert an interrupt to 
ACPI
> 
> When generating ACPI tables we need to convert IRQs in U-Boot to the 
ACPI
> structures required by ACPI. This is a SoC-specific conversion and 
cannot
> be handled by generic code, so add a new IRQ method to do the 
conversion.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
> Changes in v2: None
> 
>  drivers/misc/irq-uclass.c | 18 +++++++-
>  include/acpi_device.h     | 27 +++++++++++
>  include/irq.h             | 41 +++++++++++++++++
>  lib/acpi/acpi_device.c    | 94 +++++++++++++++++++++++++++++++++++++++
>  4 files changed, 178 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/misc/irq-uclass.c b/drivers/misc/irq-uclass.c
> index 61aa10e465..b4a8b7b429 100644
> --- a/drivers/misc/irq-uclass.c
> +++ b/drivers/misc/irq-uclass.c
> @@ -153,8 +153,6 @@ int irq_request(struct udevice *dev, struct irq 
*irq)
>     const struct irq_ops *ops;
> 
>     log_debug("(dev=%p, irq=%p)\n", dev, irq);
> -   if (!irq)
> -      return 0;

Why is this code dropped?

>     ops = irq_get_ops(dev);
> 
>     irq->dev = dev;
> @@ -176,6 +174,22 @@ int irq_first_device_type(enum irq_dev_t type, 
> struct udevice **devp)
>     return 0;
>  }
> 
> +#if CONFIG_IS_ENABLED(ACPIGEN)
> +int irq_get_acpi(const struct irq *irq, struct acpi_irq *acpi_irq)
> +{
> +   struct irq_ops *ops;
> +
> +   if (!irq_is_valid(irq))
> +      return -EINVAL;
> +
> +   ops = irq_get_ops(irq->dev);
> +   if (!ops->get_acpi)
> +      return -ENOSYS;
> +
> +   return ops->get_acpi(irq, acpi_irq);
> +}
> +#endif
> +
>  UCLASS_DRIVER(irq) = {
>     .id      = UCLASS_IRQ,
>     .name      = "irq",
> diff --git a/include/acpi_device.h b/include/acpi_device.h
> index acd26c0f54..50ba9b66aa 100644
> --- a/include/acpi_device.h
> +++ b/include/acpi_device.h
> @@ -545,6 +545,33 @@ int acpi_dp_write(struct acpi_ctx *ctx, struct 
> acpi_dp *table);
>  int acpi_device_write_gpio_desc(struct acpi_ctx *ctx,
>              const struct gpio_desc *desc);
> 
> +/**
> + * acpi_device_write_interrupt_irq() - Write an interrupt to ACPI
> + *
> + * This creates an interrupt descriptor for an interrupt, including
> information
> + * ACPI needs to use it.
> + *
> + * @req_irq: Interrupt to write
> + * @return 0 if OK, -ve on error
> + */
> +int acpi_device_write_interrupt_irq(struct acpi_ctx *ctx,
> +                const struct irq *req_irq);
> +
> +/**
> + * acpi_device_write_interrupt_or_gpio() - Write interrupt or GPIO to 
ACPI
> + *
> + * This reads the an interrupt from the device tree, if available. If 
not it

typo: "the an"

The description of what this function should do is rather vague.
At least I'm not sure how it is meant to work.

> + * reads the first GPIO with the name @prop.
> + *
> + * If an interrupt is found, that is written to ACPI. If not, but an 
GPIO is
> + * found, that is written.
> + *
> + * @return 0 if OK, -ve if neither an interrupt nor a GPIO could 
befound, or
> + * some other error occurred
> + */
> +int acpi_device_write_interrupt_or_gpio(struct acpi_ctx *ctx,
> +               struct udevice *dev, const char *prop);
> +
>  /**
>   * acpi_device_write_i2c_dev() - Write an I2C device to ACPI, including
>   * information ACPI needs to use it.
> diff --git a/include/irq.h b/include/irq.h
> index d4948e6dc4..8527e4dd79 100644
> --- a/include/irq.h
> +++ b/include/irq.h
> @@ -8,6 +8,7 @@
>  #ifndef __irq_H
>  #define __irq_H
> 
> +struct acpi_irq;
>  struct ofnode_phandle_args;
> 
>  /*
> @@ -26,10 +27,12 @@ enum irq_dev_t {
>   *
>   * @dev: IRQ device that handles this irq
>   * @id: ID to identify this irq with the device
> + * @flags: Flags associated with this interrupt (IRQ_TYPE_...)
>   */
>  struct irq {
>     struct udevice *dev;
>     ulong id;
> +   ulong flags;
>  };
> 
>  /**
> @@ -121,10 +124,36 @@ struct irq_ops {
>      * @return 0 if OK, or a negative error code.
>      */
>     int (*free)(struct irq *irq);
> +
> +#if CONFIG_IS_ENABLED(ACPIGEN)
> +   /**
> +    * get_acpi() - Get the ACPI info for an irq
> +    *
> +    * This converts a irq to an ACPI structure for adding to the ACPI
> +    * tables.
> +    *
> +    * @irq:   irq to convert
> +    * @acpi_irq:   Output ACPI interrupt information
> +    * @return ACPI pin number or -ve on error
> +    */
> +   int (*get_acpi)(const struct irq *irq, struct acpi_irq *acpi_irq);
> +#endif
>  };
> 
>  #define irq_get_ops(dev)   ((struct irq_ops *)(dev)->driver->ops)
> 
> +/**
> + * irq_is_valid() - Check if an IRQ is valid
> + *
> + * @irq:   IRQ description containing device and ID, e.g. previously
> + *      returned by irq_get_by_index()
> + * @return true if valid, false if not
> + */
> +static inline bool irq_is_valid(const struct irq *irq)
> +{
> +   return irq->dev != NULL;
> +}
> +
>  /**
>   * irq_route_pmc_gpio_gpe() - Get the GPIO for an event
>   *
> @@ -225,4 +254,16 @@ int irq_free(struct irq *irq);
>   */
>  int irq_first_device_type(enum irq_dev_t type, struct udevice **devp);
> 
> +/**
> + * irq_get_acpi() - Get the ACPI info for an irq
> + *
> + * This converts a irq to an ACPI structure for adding to the ACPI
> + * tables.
> + *
> + * @irq:   irq to convert
> + * @acpi_irq:   Output ACPI interrupt information
> + * @return ACPI pin number or -ve on error
> + */
> +int irq_get_acpi(const struct irq *irq, struct acpi_irq *acpi_irq);
> +
>  #endif
> diff --git a/lib/acpi/acpi_device.c b/lib/acpi/acpi_device.c
> index adc32f1216..aa5edfe807 100644
> --- a/lib/acpi/acpi_device.c
> +++ b/lib/acpi/acpi_device.c
> @@ -154,6 +154,58 @@ int acpi_device_status(const struct udevice *dev)
>     return ACPI_STATUS_DEVICE_ALL_ON;
>  }
> 
> +/* ACPI 6.1 section 6.4.3.6: Extended Interrupt Descriptor */
> +static int acpi_device_write_interrupt(struct acpi_ctx *ctx,
> +                   const struct acpi_irq *irq)
> +{
> +   void *desc_length;
> +   u8 flags;
> +
> +   if (!irq || !irq->pin)
> +      return -ENOENT;
> +
> +   /* This is supported by GpioInt() but not Interrupt() */
> +   if (irq->polarity == ACPI_IRQ_ACTIVE_BOTH)
> +      return -EINVAL;
> +
> +   /* Byte 0: Descriptor Type */
> +   acpigen_emit_byte(ctx, ACPI_DESCRIPTOR_INTERRUPT);
> +
> +   /* Byte 1-2: Length (filled in later) */
> +   desc_length = acpi_device_write_zero_len(ctx);
> +
> +   /*
> +    * Byte 3: Flags
> +    *  [7:5]: Reserved
> +    *    [4]: Wake     (0=NO_WAKE   1=WAKE)
> +    *    [3]: Sharing  (0=EXCLUSIVE 1=SHARED)
> +    *    [2]: Polarity (0=HIGH      1=LOW)
> +    *    [1]: Mode     (0=LEVEL     1=EDGE)
> +    *    [0]: Resource (0=PRODUCER  1=CONSUMER)
> +    */
> +   flags = 1 << 0; /* ResourceConsumer */
> +   if (irq->mode == ACPI_IRQ_EDGE_TRIGGERED)
> +      flags |= 1 << 1;
> +   if (irq->polarity == ACPI_IRQ_ACTIVE_LOW)
> +      flags |= 1 << 2;
> +   if (irq->shared == ACPI_IRQ_SHARED)
> +      flags |= 1 << 3;
> +   if (irq->wake == ACPI_IRQ_WAKE)
> +      flags |= 1 << 4;
> +   acpigen_emit_byte(ctx, flags);
> +
> +   /* Byte 4: Interrupt Table Entry Count */
> +   acpigen_emit_byte(ctx, 1);
> +
> +   /* Byte 5-8: Interrupt Number */
> +   acpigen_emit_dword(ctx, irq->pin);
> +
> +   /* Fill in Descriptor Length (account for len word) */
> +   acpi_device_fill_len(ctx, desc_length);
> +
> +   return 0;
> +}
> +
>  /* ACPI 6.1 section 6.4.3.8.1 - GPIO Interrupt or I/O */
>  int acpi_device_write_gpio(struct acpi_ctx *ctx, const struct 
> acpi_gpio *gpio)
>  {
> @@ -304,6 +356,48 @@ int acpi_device_write_gpio_desc(struct acpi_ctx 
*ctx,
>     return 0;
>  }
> 
> +int acpi_device_write_interrupt_irq(struct acpi_ctx *ctx,
> +                const struct irq *req_irq)
> +{
> +   struct acpi_irq irq;
> +   int ret;
> +
> +   ret = irq_get_acpi(req_irq, &irq);
> +   if (ret)
> +      return log_msg_ret("get", ret);
> +   ret = acpi_device_write_interrupt(ctx, &irq);
> +   if (ret)
> +      return log_msg_ret("write", ret);
> +
> +   return 0;
> +}
> +
> +int acpi_device_write_interrupt_or_gpio(struct acpi_ctx *ctx,
> +               struct udevice *dev, const char *prop)
> +{
> +   struct irq req_irq;
> +   int ret;
> +
> +   ret = irq_get_by_index(dev, 0, &req_irq);
> +   if (!ret) {
> +      ret = acpi_device_write_interrupt_irq(ctx, &req_irq);
> +      if (ret)
> +         return log_msg_ret("irq", ret);
> +   } else {
> +      struct gpio_desc req_gpio;
> +
> +      ret = gpio_request_by_name(dev, prop, 0, &req_gpio,
> +                  GPIOD_IS_IN);
> +      if (ret)
> +         return log_msg_ret("no gpio", ret);
> +      ret = acpi_device_write_gpio_desc(ctx, &req_gpio);
> +      if (ret)
> +         return log_msg_ret("gpio", ret);
> +   }

Both code paths set the index value hardcoded to 0.
Why is that? Would other indices not make sense?

> +
> +   return 0;
> +}
> +
>  /* ACPI 6.1 section 6.4.3.8.2.1 - I2cSerialBus() */
>  static void acpi_device_write_i2c(struct acpi_ctx *ctx,
>                const struct acpi_i2c *i2c)
> -- 
> 2.25.1.481.gfbce0eb801-goog
> 

regards, Wolfgang

  reply	other threads:[~2020-03-18 16:17 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-09  3:44 [PATCH v2 00/39] dm: Add programmatic generation of ACPI tables (part A) Simon Glass
2020-03-09  3:44 ` [PATCH v2 01/39] cpu: Support querying the address width Simon Glass
2020-03-09  3:44 ` [PATCH v2 02/39] spi: Add SPI mode enums Simon Glass
2020-03-09  7:41   ` Andy Shevchenko
2020-03-09  3:44 ` [PATCH v2 03/39] tpm: cr50: Release locality on exit Simon Glass
2020-03-09  3:44 ` [PATCH v2 04/39] tpm: cr50: Add a comment for cr50_priv Simon Glass
2020-03-09  3:44 ` [PATCH v2 05/39] tpm: cr50: Use the correct GPIO binding Simon Glass
2020-03-09  3:44 ` [PATCH v2 06/39] tpm: Don't cleanup unless an error happens Simon Glass
2020-03-09  3:44 ` [PATCH v2 07/39] dm: pci: Allow disabling auto-config for a device Simon Glass
2020-03-09  7:43   ` Andy Shevchenko
2020-03-09  3:44 ` [PATCH v2 08/39] x86: Correct wording of coreboot source code Simon Glass
2020-03-09  7:44   ` Andy Shevchenko
2020-03-10 23:22     ` Simon Glass
2020-03-09  3:44 ` [PATCH v2 09/39] x86: apl: Move p2sb ofdata reading to the correct method Simon Glass
2020-03-10 14:39   ` Andy Shevchenko
2020-03-11 12:17     ` Simon Glass
2020-03-11 13:06       ` Andy Shevchenko
2020-03-09  3:44 ` [PATCH v2 10/39] pci: Adjust dm_pci_read_bar32() to return errors correctly Simon Glass
2020-03-09  3:44 ` [PATCH v2 11/39] x86: apl: Add Global NVS table header Simon Glass
2020-03-09  3:44 ` [PATCH v2 12/39] dm: core: Add basic ACPI support Simon Glass
2020-03-10 14:46   ` Andy Shevchenko
2020-03-11 12:17     ` Simon Glass
2020-03-09  3:44 ` [PATCH v2 13/39] acpi: Add a binding for ACPI settings in the device tree Simon Glass
2020-03-10 14:50   ` Andy Shevchenko
2020-03-12  3:22     ` Simon Glass
2020-03-09  3:44 ` [PATCH v2 14/39] acpi: Add a simple sandbox test Simon Glass
2020-03-09  3:44 ` [PATCH v2 15/39] x86: Move acpi_table header to main include/ directory Simon Glass
2020-03-09  3:44 ` [PATCH v2 16/39] acpi: Add an __ACPI__ preprocessor symbol Simon Glass
2020-03-09  3:44 ` [PATCH v2 17/39] acpi: Add a central location for table version numbers Simon Glass
2020-03-09  3:44 ` [PATCH v2 18/39] acpi: Add support for DMAR Simon Glass
2020-03-09  3:44 ` [PATCH v2 19/39] acpi: Move acpi_fill_header() to generic code Simon Glass
2020-03-09  3:44 ` [PATCH v2 20/39] acpi: Add a method to write tables for a device Simon Glass
2020-03-09  3:44 ` [PATCH v2 21/39] acpi: Convert part of acpi_table to use acpi_ctx Simon Glass
2020-03-09  3:44 ` [PATCH v2 22/39] x86: Allow devices to write ACPI tables Simon Glass
2020-03-09  3:44 ` [PATCH v2 23/39] acpi: Drop code for missing XSDT from acpi_write_rsdp() Simon Glass
2020-03-09  3:44 ` [PATCH v2 24/39] acpi: Move acpi_add_table() to generic code Simon Glass
2020-03-09  3:44 ` [PATCH v2 25/39] acpi: Put table-setup code in its own function Simon Glass
2020-03-09  3:44 ` [PATCH v2 26/39] acpi: Move the xsdt pointer to acpi_ctx Simon Glass
2020-03-09  3:44 ` [PATCH v2 27/39] acpi: Add an acpi command Simon Glass
2020-03-09  3:44 ` [PATCH v2 28/39] acpi: Add some tables required by the generation code Simon Glass
2020-03-09  3:44 ` [PATCH v2 29/39] acpi: Add generation code for devices Simon Glass
2020-03-09  3:44 ` [PATCH v2 30/39] acpi: Add functions to generate ACPI code Simon Glass
2020-03-09  3:44 ` [PATCH v2 31/39] gpio: Add a method to convert a GPIO to ACPI Simon Glass
2020-03-09  3:44 ` [PATCH v2 32/39] irq: Add a method to convert an interrupt " Simon Glass
2020-03-18 16:17   ` Wolfgang Wallner [this message]
2020-03-18 16:20   ` Antwort: " Wolfgang Wallner
2020-03-19 16:18     ` Simon Glass
2020-03-09  3:44 ` [PATCH v2 33/39] acpi: Add support for SSDT generation Simon Glass
2020-03-18 16:48   ` Antwort: " Wolfgang Wallner
2020-03-19  7:39   ` Wolfgang Wallner
2020-03-09  3:44 ` [PATCH v2 34/39] x86: acpi: Move MADT up a bit Simon Glass
2020-03-09  3:44 ` [PATCH v2 35/39] acpi: Record the items added to SSDT Simon Glass
2020-03-09  3:45 ` [PATCH v2 36/39] acpi: Support ordering SSDT data by device Simon Glass
2020-03-09  3:45 ` [PATCH v2 37/39] x86: Allow devices to write an SSDT Simon Glass
2020-03-09  3:45 ` [PATCH v2 38/39] acpi: Add support for DSDT generation Simon Glass
2020-03-09  3:45 ` [PATCH v2 39/39] x86: Allow devices to write to DSDT Simon Glass
2020-03-09  7:38 ` Antwort: [PATCH v2 02/39] spi: Add SPI mode enums Wolfgang Wallner
2020-03-09  7:38 ` Antwort: [PATCH v2 08/39] x86: Correct wording of coreboot source code Wolfgang Wallner
2020-03-09  7:38 ` Antwort: [PATCH v2 10/39] pci: Adjust dm_pci_read_bar32() to return errors correctly Wolfgang Wallner
2020-03-09  7:38 ` Antwort: [PATCH v2 11/39] x86: apl: Add Global NVS table header Wolfgang Wallner
2020-03-09  9:07 ` Antwort: [PATCH v2 12/39] dm: core: Add basic ACPI support Wolfgang Wallner
2020-03-10  9:15 ` Antwort: [PATCH v2 13/39] acpi: Add a binding for ACPI settings in the device tree Wolfgang Wallner
2020-03-12  3:24   ` Simon Glass
2020-03-12 12:44   ` Antwort: " Wolfgang Wallner
2020-03-13  0:36     ` Simon Glass
2020-03-10  9:16 ` Antwort: [PATCH v2 15/39] x86: Move acpi_table header to main include/ directory Wolfgang Wallner
2020-03-10  9:17 ` Antwort: [PATCH v2 16/39] acpi: Add an __ACPI__ preprocessor symbol Wolfgang Wallner
2020-03-10  9:26 ` Antwort: [PATCH v2 17/39] acpi: Add a central location for table version numbers Wolfgang Wallner
2020-03-12  3:22   ` Simon Glass
2020-03-10 12:32 ` Antwort: [PATCH v2 18/39] acpi: Add support for DMAR Wolfgang Wallner
2020-03-10 12:33 ` Antwort: [PATCH v2 19/39] acpi: Move acpi_fill_header() to generic code Wolfgang Wallner
2020-03-10 12:53 ` Antwort: [PATCH v2 14/39] acpi: Add a simple sandbox test Wolfgang Wallner
2020-03-11  9:04 ` Antwort: [PATCH v2 19/39] acpi: Move acpi_fill_header() to generic code Wolfgang Wallner
2020-03-11 11:36 ` Antwort: [PATCH v2 20/39] acpi: Add a method to write tables for a device Wolfgang Wallner
2020-03-11 11:37 ` Antwort: [PATCH v2 22/39] x86: Allow devices to write ACPI tables Wolfgang Wallner
2020-03-11 12:58 ` Antwort: [PATCH v2 21/39] acpi: Convert part of acpi_table to use acpi_ctx Wolfgang Wallner
2020-03-12  3:23   ` Simon Glass
2020-03-12 13:03   ` Antwort: " Wolfgang Wallner
2020-03-11 13:43 ` Antwort: [PATCH v2 24/39] acpi: Move acpi_add_table() to generic code Wolfgang Wallner
2020-03-11 14:33 ` Antwort: [PATCH v2 25/39] acpi: Put table-setup code in its own function Wolfgang Wallner
2020-03-11 14:34 ` Antwort: [PATCH v2 23/39] acpi: Drop code for missing XSDT from acpi_write_rsdp() Wolfgang Wallner
2020-03-11 14:57 ` Antwort: [PATCH v2 26/39] acpi: Move the xsdt pointer to acpi_ctx Wolfgang Wallner
2020-03-12 14:30 ` Antwort: [PATCH v2 27/39] acpi: Add an acpi command Wolfgang Wallner
2020-03-13  9:55 ` Antwort: [PATCH v2 30/39] acpi: Add functions to generate ACPI code Wolfgang Wallner
2020-03-14 20:34   ` Simon Glass
2020-03-13 11:16 ` Antwort: [PATCH v2 31/39] gpio: Add a method to convert a GPIO to ACPI Wolfgang Wallner

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=OF80768302.89C292FA-ONC125852F.00596AB0-C125852F.00597707@br-automation.com \
    --to=wolfgang.wallner@br-automation.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.