@@ -1,2 +1,3 @@
obj-$(CONFIG_ACPI_IORT) += iort.o
obj-$(CONFIG_ACPI_GTDT) += gtdt.o
+obj-$(CONFIG_INDIRECT_PIO) += acpi_indirectio.o
new file mode 100644
@@ -0,0 +1,156 @@
+/*
+ * ACPI support for indirect-IO bus.
+ *
+ * Copyright (C) 2017 Hisilicon Limited, All Rights Reserved.
+ * Author: Gabriele Paoloni <gabriele.paoloni@huawei.com>
+ * Author: Zhichang Yuan <yuanzhichang@hisilicon.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/acpi.h>
+#include <linux/platform_device.h>
+#include <linux/logic_pio.h>
+
+#include "acpi_indirectio.h"
+
+ACPI_MODULE_NAME("indirect IO");
+
+#define INDIRECT_IO_INFO(desc) ((unsigned long)&desc)
+
+static int acpi_translate_logiciores(struct acpi_device *adev,
+ struct acpi_device *host, struct resource *resource)
+{
+ unsigned long sys_port;
+ struct device *dev = &adev->dev;
+ resource_size_t length = resource->end - resource->start;
+
+ sys_port = logic_pio_trans_hwaddr(&host->fwnode, resource->start,
+ length);
+
+ if (sys_port == -1) {
+ dev_err(dev, "translate bus-addr(0x%llx) fail!\n",
+ resource->start);
+ return -EFAULT;
+ }
+
+ resource->start = sys_port;
+ resource->end = sys_port + length;
+
+ 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.
+ *
+ * @child: the device node to be updated the I/O resource;
+ * @hostdev: the device node where 'adev' is attached, which can be not
+ * the parent of 'adev';
+ * @res: double pointer to be set to the address of the updated resources
+ * @num_res: address of the variable to contain the number of updated resources
+ *
+ * return 0 when successful, negative is for failure.
+ */
+int acpi_set_logicio_resource(struct device *child,
+ struct device *hostdev, const struct resource **res,
+ int *num_res)
+{
+ struct acpi_device *adev;
+ struct acpi_device *host;
+ struct resource_entry *rentry;
+ LIST_HEAD(resource_list);
+ struct resource *resources = NULL;
+ int count;
+ int i;
+ int ret = -EIO;
+
+ if (!child || !hostdev)
+ return -EINVAL;
+
+ host = to_acpi_device(hostdev);
+ adev = to_acpi_device(child);
+
+ /* check the device state */
+ if (!adev->status.present) {
+ dev_info(child, "ACPI: device is not present!\n");
+ return 0;
+ }
+ /* whether the child had been enumerated? */
+ if (acpi_device_enumerated(adev)) {
+ dev_info(child, "ACPI: had been enumerated!\n");
+ return 0;
+ }
+
+ count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
+ if (count <= 0) {
+ dev_err(&adev->dev, "failed to get ACPI resources\n");
+ return count ? count : -EIO;
+ }
+
+ resources = kcalloc(count, sizeof(struct resource), GFP_KERNEL);
+ if (!resources) {
+ dev_err(&adev->dev, "No memory for resources\n");
+ acpi_dev_free_resource_list(&resource_list);
+ return -ENOMEM;
+ }
+ count = 0;
+ list_for_each_entry(rentry, &resource_list, node)
+ resources[count++] = *rentry->res;
+
+ acpi_dev_free_resource_list(&resource_list);
+
+ /* translate the I/O resources */
+ for (i = 0; i < count; i++) {
+ if (resources[i].flags & IORESOURCE_IO) {
+ ret = acpi_translate_logiciores(adev, host,
+ &resources[i]);
+ if (ret) {
+ kfree(resources);
+ dev_err(child, "Translate I/O range FAIL!\n");
+ return ret;
+ }
+ }
+ }
+ *res = resources;
+ *num_res = count;
+
+ return ret;
+}
+
+/* All the host devices which apply indirect-IO can be listed here. */
+static const struct acpi_device_id acpi_indirect_host_id[] = {
+ {""},
+};
+
+static int acpi_indirectio_attach(struct acpi_device *adev,
+ const struct acpi_device_id *id)
+{
+ struct indirectio_device_desc *hostdata;
+ int ret;
+
+ hostdata = (struct indirectio_device_desc *)id->driver_data;
+ if (!hostdata || !hostdata->pre_setup)
+ return -EINVAL;
+
+ ret = hostdata->pre_setup(adev, hostdata->pdata);
+
+ if (ret < 0)
+ return ret;
+
+ return 1;
+}
+
+
+static struct acpi_scan_handler acpi_indirect_handler = {
+ .ids = acpi_indirect_host_id,
+ .attach = acpi_indirectio_attach,
+};
+
+void __init acpi_indirectio_scan_init(void)
+{
+ acpi_scan_add_handler(&acpi_indirect_handler);
+}
new file mode 100644
@@ -0,0 +1,24 @@
+/*
+ * ACPI support for indirect-IO bus.
+ *
+ * Copyright (C) 2017 Hisilicon Limited, All Rights Reserved.
+ * Author: Gabriele Paoloni <gabriele.paoloni@huawei.com>
+ * Author: Zhichang Yuan <yuanzhichang@hisilicon.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ACPI_INDIRECTIO_H
+#define _ACPI_INDIRECTIO_H
+
+struct indirectio_device_desc {
+ void *pdata; /* device relevant info data */
+ int (*pre_setup)(struct acpi_device *adev, void *pdata);
+};
+
+int acpi_set_logicio_resource(struct device *child,
+ struct device *hostdev, const struct resource **res,
+ int *num_res);
+#endif
@@ -31,6 +31,11 @@ void acpi_processor_init(void);
void acpi_platform_init(void);
void acpi_pnp_init(void);
void acpi_int340x_thermal_init(void);
+#ifdef CONFIG_INDIRECT_PIO
+void acpi_indirectio_scan_init(void);
+#else
+static inline void acpi_indirectio_scan_init(void) {}
+#endif
#ifdef CONFIG_ARM_AMBA
void acpi_amba_init(void);
#else
@@ -2041,6 +2041,7 @@ int __init acpi_scan_init(void)
acpi_int340x_thermal_init();
acpi_amba_init();
acpi_watchdog_init();
+ acpi_indirectio_scan_init();
acpi_scan_add_handler(&generic_device_handler);