linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Garry <john.garry@huawei.com>
To: "zhichang.yuan" <yuanzhichang@hisilicon.com>,
	<catalin.marinas@arm.com>, <will.deacon@arm.com>,
	<robh+dt@kernel.org>, <frowand.list@gmail.com>,
	<bhelgaas@google.com>, <rafael@kernel.org>,
	<mark.rutland@arm.com>, <brian.starkey@arm.com>, <olof@lixom.net>,
	<arnd@arndb.de>, <linux-arm-kernel@lists.infradead.org>
Cc: <lorenzo.pieralisi@arm.com>, <benh@kernel.crashing.org>,
	<linux-kernel@vger.kernel.org>, <linuxarm@huawei.com>,
	<devicetree@vger.kernel.org>, <linux-pci@vger.kernel.org>,
	<linux-serial@vger.kernel.org>, <minyard@acm.org>,
	<liviu.dudau@arm.com>, <zourongrong@gmail.com>,
	<gabriele.paoloni@huawei.com>, <zhichang.yuan02@gmail.com>,
	<kantyzc@163.com>, <xuwei5@hisilicon.com>,
	<linux-acpi@vger.kernel.org>
Subject: Re: [PATCH V5 5/5] LPC: Add the ACPI LPC support
Date: Sat, 4 Feb 2017 13:20:46 +0000	[thread overview]
Message-ID: <781b05af-1bf2-2be5-f614-5aeff0bc3df3@huawei.com> (raw)
In-Reply-To: <1485241525-201782-6-git-send-email-yuanzhichang@hisilicon.com>

+ linux-acpi

Adding linux-acpi list, which should have been originally included.

The patchset threads have had much discussion, here is a pointer: 
http://www.spinics.net/lists/devicetree/msg160611.html

John

On 24/01/2017 07:05, zhichang.yuan wrote:
> The patch update the _CRS of LPC children with the system logical I/O resource
> after the translation from LPC-local I/O. Then the ACPI platform device
> enumeration for LPC can apply the right I/O resource to request the system I/O
> space.
>
> Signed-off-by: zhichang.yuan <yuanzhichang@hisilicon.com>
> ---
>  drivers/bus/hisi_lpc.c |  26 ++++++
>  include/linux/extio.h  |   4 +
>  lib/extio.c            | 228 +++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 258 insertions(+)
>
> diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c
> index a96e384..8d52666 100644
> --- a/drivers/bus/hisi_lpc.c
> +++ b/drivers/bus/hisi_lpc.c
> @@ -583,6 +583,32 @@ static int hisilpc_bus_platform_notify(struct notifier_block *nb,
>  	/* register the linux virtual IO range node to list. */
>  	register_extio(io_node);
>
> +	/*
> +	 * For ACPI children, translate the bus-local I/O range to logical
> +	 * I/O range and set it as the current resource before the children
> +	 * are enumerated.
> +	 */
> +	if (has_acpi_companion(dev)) {
> +		struct acpi_device *root, *child;
> +
> +		root = to_acpi_device_node(dev->fwnode);
> +		/* For hisilpc, only care about the sons of host. */
> +		list_for_each_entry(child, &root->children, node) {
> +			ret = acpi_set_extio_resource(child, root);
> +			if (ret) {
> +				dev_err(dev, "set resource failed..\n");
> +				break;
> +			}
> +		}
> +
> +		if (ret) {
> +			list_del(&io_node->list);
> +			kfree(io_node);
> +			dev_err(dev, "notify handling failed..\n");
> +			return NOTIFY_DONE;
> +		}
> +	}
> +
>  	return NOTIFY_OK;
>  }
>
> diff --git a/include/linux/extio.h b/include/linux/extio.h
> index 2ca7eab..c07607e 100644
> --- a/include/linux/extio.h
> +++ b/include/linux/extio.h
> @@ -20,6 +20,7 @@
>
>  #ifdef __KERNEL__
>
> +#include <linux/acpi.h>
>  #include <linux/fwnode.h>
>
>  struct extio_ops {
> @@ -81,5 +82,8 @@ static inline struct extio_node *extio_find_node(struct fwnode_handle *node)
>  #endif
>  extern void register_extio(struct extio_node *node);
>
> +extern int acpi_set_extio_resource(struct acpi_device *adev,
> +		struct acpi_device *host);
> +
>  #endif /* __KERNEL__ */
>  #endif /* __LINUX_EXTIO_H */
> diff --git a/lib/extio.c b/lib/extio.c
> index 46228de..47f5913 100644
> --- a/lib/extio.c
> +++ b/lib/extio.c
> @@ -75,6 +75,234 @@ unsigned long extio_translate(struct fwnode_handle *node,
>  	return port_id;
>  }
>
> +static inline bool acpi_extio_supported_resource(struct acpi_resource *res)
> +{
> +	switch (res->type) {
> +	case ACPI_RESOURCE_TYPE_ADDRESS16:
> +	case ACPI_RESOURCE_TYPE_ADDRESS32:
> +	case ACPI_RESOURCE_TYPE_ADDRESS64:
> +		return true;
> +	}
> +	return false;
> +}
> +
> +static acpi_status acpi_count_extiores(struct acpi_resource *res,
> +					   void *data)
> +{
> +	int *res_cnt = data;
> +
> +	if (acpi_extio_supported_resource(res) &&
> +		!acpi_dev_filter_resource_type(res, IORESOURCE_IO))
> +		(*res_cnt)++;
> +
> +	return AE_OK;
> +}
> +
> +static acpi_status acpi_read_one_extiores(struct acpi_resource *res,
> +		void *data)
> +{
> +	struct acpi_resource **resource = data;
> +
> +	if (acpi_extio_supported_resource(res) &&
> +		!acpi_dev_filter_resource_type(res, IORESOURCE_IO)) {
> +		memcpy((*resource), res, sizeof(struct acpi_resource));
> +		(*resource)->length = sizeof(struct acpi_resource);
> +		(*resource)->type = res->type;
> +		(*resource)++;
> +	}
> +
> +	return AE_OK;
> +}
> +
> +static acpi_status
> +acpi_build_extiores_template(struct acpi_device *adev,
> +			struct acpi_buffer *buffer)
> +{
> +	acpi_handle handle = adev->handle;
> +	struct acpi_resource *resource;
> +	acpi_status status;
> +	int res_cnt = 0;
> +
> +	status = acpi_walk_resources(handle, METHOD_NAME__PRS,
> +				     acpi_count_extiores, &res_cnt);
> +	if (ACPI_FAILURE(status) || !res_cnt) {
> +		dev_err(&adev->dev, "can't evaluate _CRS: %d\n", status);
> +		return -EINVAL;
> +	}
> +
> +	buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
> +	buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL);
> +	if (!buffer->pointer)
> +		return -ENOMEM;
> +
> +	resource = (struct acpi_resource *)buffer->pointer;
> +	status = acpi_walk_resources(handle, METHOD_NAME__PRS,
> +				     acpi_read_one_extiores, &resource);
> +	if (ACPI_FAILURE(status)) {
> +		kfree(buffer->pointer);
> +		dev_err(&adev->dev, "can't evaluate _PRS: %d\n", status);
> +		return -EINVAL;
> +	}
> +
> +	resource->type = ACPI_RESOURCE_TYPE_END_TAG;
> +	resource->length = sizeof(struct acpi_resource);
> +
> +	return 0;
> +}
> +
> +static int acpi_translate_extiores(struct acpi_device *adev,
> +		struct acpi_device *host, struct acpi_buffer *buffer)
> +{
> +	int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1;
> +	struct acpi_resource *resource = buffer->pointer;
> +	struct acpi_resource_address64 addr;
> +	unsigned long sys_port;
> +	struct device *dev = &adev->dev;
> +
> +	/* only one I/O resource now */
> +	if (res_cnt != 1) {
> +		dev_err(dev, "encode %d resources whose type is(%d)!\n",
> +			res_cnt, resource->type);
> +		return -EINVAL;
> +	}
> +
> +	if (ACPI_FAILURE(acpi_resource_to_address64(resource, &addr))) {
> +		dev_err(dev, "convert acpi resource(%d) as addr64 FAIL!\n",
> +			resource->type);
> +		return -EFAULT;
> +	}
> +
> +	/* For indirect-IO, addr length must be fixed. (>0, 0, 0) */
> +	if (!addr.address.address_length || addr.min_address_fixed ||
> +		addr.max_address_fixed) {
> +		dev_warn(dev, "variable I/O resource is invalid!\n");
> +		return -EINVAL;
> +	}
> +
> +	sys_port = extio_translate(&host->fwnode, addr.address.minimum);
> +	if (sys_port == -1) {
> +		dev_err(dev, "translate bus-addr(0x%llx) fail!\n",
> +			addr.address.minimum);
> +		return -EFAULT;
> +	}
> +
> +	switch (resource->type) {
> +	case ACPI_RESOURCE_TYPE_ADDRESS16:
> +	{
> +		struct acpi_resource_address16 *out_res;
> +
> +		out_res = &resource->data.address16;
> +		out_res->address.minimum = sys_port;
> +		out_res->address.maximum = sys_port +
> +			addr.address.address_length - 1;
> +
> +		dev_info(dev, "_SRS 16IO: [0x%x - 0x%x]\n",
> +			out_res->address.minimum,
> +			out_res->address.maximum);
> +
> +		break;
> +	}
> +
> +	case ACPI_RESOURCE_TYPE_ADDRESS32:
> +	{
> +		struct acpi_resource_address32 *out_res;
> +
> +		out_res = &resource->data.address32;
> +		out_res->address.minimum = sys_port;
> +		out_res->address.maximum = sys_port +
> +			addr.address.address_length - 1;
> +
> +		dev_info(dev, "_SRS 32IO: [0x%x - 0x%x]\n",
> +			out_res->address.minimum,
> +			out_res->address.maximum);
> +
> +		break;
> +	}
> +
> +	case ACPI_RESOURCE_TYPE_ADDRESS64:
> +	{
> +		struct acpi_resource_address64 *out_res;
> +
> +		out_res = &resource->data.address64;
> +		out_res->address.minimum = sys_port;
> +		out_res->address.maximum = sys_port +
> +			addr.address.address_length - 1;
> +
> +		dev_info(dev, "_SRS 64IO: [0x%llx - 0x%llx]\n",
> +			out_res->address.minimum,
> +			out_res->address.maximum);
> +
> +		break;
> +	}
> +
> +	default:
> +		return -EINVAL;
> +
> +	}
> +
> +	return 0;
> +}
> +
> +/*
> + * update/set the current I/O resource of the designated device node.
> + * after this calling, the enumeration can be started as the I/O resource
> + * had been translated to logicial I/O from bus-local I/O.
> + *
> + * @adev: the device node to be updated the I/O resource;
> + * @host: the device node where 'adev' is attached, which can be not
> + *	the parent of 'adev';
> + *
> + * return 0 when successful, negative is for failure.
> + */
> +int acpi_set_extio_resource(struct acpi_device *adev,
> +		struct acpi_device *host)
> +{
> +	struct device *dev = &adev->dev;
> +	struct acpi_buffer buffer;
> +	acpi_status status;
> +	int ret;
> +
> +	if (!host)
> +		return -EINVAL;
> +
> +	/* check the device state */
> +	if (!adev->status.present) {
> +		dev_info(dev, "ACPI: device is not present!\n");
> +		return 0;
> +	}
> +	/* whether the child had been enumerated? */
> +	if (acpi_device_enumerated(adev)) {
> +		dev_info(dev, "ACPI: had been enumerated!\n");
> +		return 0;
> +	}
> +
> +	/* read the _PRS and convert as acpi_buffer */
> +	status = acpi_build_extiores_template(adev, &buffer);
> +	if (ACPI_FAILURE(status)) {
> +		dev_warn(dev, "Failure evaluating %s\n",
> +				METHOD_NAME__PRS);
> +		return -ENODEV;
> +	}
> +
> +	/* translate the I/O resources */
> +	ret = acpi_translate_extiores(adev, host, &buffer);
> +	if (ret) {
> +		kfree(buffer.pointer);
> +		dev_err(dev, "Translate I/O range FAIL!\n");
> +		return ret;
> +	}
> +
> +	/* set current resource... */
> +	status = acpi_set_current_resources(adev->handle, &buffer);
> +	kfree(buffer.pointer);
> +	if (ACPI_FAILURE(status)) {
> +		dev_err(dev, "Error evaluating _SRS (0x%x)\n", status);
> +		ret = -EIO;
> +	}
> +
> +	return ret;
> +}
> +
>  #ifdef PCI_IOBASE
>
>  #define BUILD_EXTIO(bw, type)						\
>

      reply	other threads:[~2017-02-04 13:27 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-24  7:05 [PATCH V6 0/5] LPC: legacy ISA I/O support zhichang.yuan
2017-01-24  7:05 ` [PATCH V6 1/5] LIB: Indirect ISA/LPC port IO introduced zhichang.yuan
2017-01-30 17:12   ` Alexander Graf
2017-01-31 13:32     ` John Garry
2017-01-31 19:37       ` Alexander Graf
2017-02-01 12:29         ` Gabriele Paoloni
2017-02-13 14:17         ` zhichang.yuan
2017-02-14 13:17           ` Alexander Graf
2017-02-13 14:05     ` zhichang.yuan
2017-02-14 13:15       ` Alexander Graf
2017-01-31  0:09   ` Bjorn Helgaas
2017-01-31 13:34     ` John Garry
2017-01-24  7:05 ` [PATCH V6 2/5] PCI: Adapt pci_register_io_range() for indirect-IO and PCI I/O translation zhichang.yuan
2017-01-31  0:10   ` Bjorn Helgaas
2017-01-31 13:39     ` John Garry
2017-01-31  0:15   ` Bjorn Helgaas
2017-02-04 12:59     ` John Garry
2017-02-02 17:36   ` John Garry
2017-02-02 23:00     ` Rafael J. Wysocki
2017-01-24  7:05 ` [PATCH V6 3/5] OF: Add missing I/O range exception for indirect-IO devices zhichang.yuan
2017-01-27 22:03   ` Rob Herring
2017-01-30  8:57     ` John Garry
2017-01-30 10:08       ` Arnd Bergmann
2017-01-24  7:05 ` [PATCH V6 4/5] LPC: Support the device-tree LPC host on Hip06/Hip07 zhichang.yuan
2017-01-27 22:12   ` Rob Herring
2017-01-30 20:08   ` Alexander Graf
2017-01-31 10:07     ` John Garry
2017-01-31 11:03       ` Alexander Graf
2017-01-31 11:49         ` John Garry
2017-01-31 11:51         ` Gabriele Paoloni
2017-02-13 14:39     ` zhichang.yuan
2017-02-14 13:29       ` Alexander Graf
2017-02-15 11:35         ` zhichang.yuan
2017-02-15 11:53           ` Alexander Graf
2017-02-16  8:59             ` zhichang.yuan
2017-01-24  7:05 ` [PATCH V5 5/5] LPC: Add the ACPI LPC support zhichang.yuan
2017-02-04 13:20   ` John Garry [this message]

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=781b05af-1bf2-2be5-f614-5aeff0bc3df3@huawei.com \
    --to=john.garry@huawei.com \
    --cc=arnd@arndb.de \
    --cc=benh@kernel.crashing.org \
    --cc=bhelgaas@google.com \
    --cc=brian.starkey@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=gabriele.paoloni@huawei.com \
    --cc=kantyzc@163.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=liviu.dudau@arm.com \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=minyard@acm.org \
    --cc=olof@lixom.net \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=will.deacon@arm.com \
    --cc=xuwei5@hisilicon.com \
    --cc=yuanzhichang@hisilicon.com \
    --cc=zhichang.yuan02@gmail.com \
    --cc=zourongrong@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).