From patchwork Fri Oct 27 16:11:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriele Paoloni X-Patchwork-Id: 117367 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp948162qgn; Fri, 27 Oct 2017 09:15:02 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QpkpxZozSbPMA64dukfIp1oyMKQZBqHOXjSXrc6c4QgQYqiQv+ETW61P5bc6gDFI+hnd6i X-Received: by 10.98.217.214 with SMTP id b83mr927182pfl.144.1509120902667; Fri, 27 Oct 2017 09:15:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509120902; cv=none; d=google.com; s=arc-20160816; b=aV+uTAgi7Fd/iiUymvsH/xFI2+6oa1CVPoBqHZRfQXuxx4zH9rZgjjcXbmNDCEusxa puCrAl5A8InYfg3XRO2BEPp2GMTy0Tz6D8/lYv0AgNMwsKNpBfvsIcDeQhh2rBO3S22f hf7mVDllxU6VKioEXfWR8fxncpJMNyb1XDWTmBgbH5EPeP9sJIKVYxKIYVFc68CIVaf3 KkXMfiyGh8hfkkCxLe8fyZJEzBWWAeC+sRsPggODR9p8yCCQ9qj67COsoo/vjyAU5Pzh vk0uMgaOA50F37mFQQZCYJhGxgrGC0BabVQoEvsRPOZJ26o2FAA9UtV7BVkRvkVtBgRU VbPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=trnVyEdt5XD+oIVRJVzb1isdpCKiioMkY74Zq+8wwYU=; b=vBRnsA9OIuyAPOV5xMPOK5VjxBLD9mk2+ERTaMXcJhVlD+G03BEmY5Sueg+OIhvyCm vIP/JpW5zE0pP8h2SYj8WmCaGtDQzjeScyuZiRYtmqiw5/a9iSjYRRmwJg1y8NgyenkE y8L6NFheLeiUfStYWno5kSGv7UlqXOxXLcJM5HwDn5ibOzRUalv78f4rRwlpq7kGo3eD RJnCWWRSkaebYwOUBIzcD9wV6Avm5UCIL4oUjJ5YvdFK1WTkmrY7aAfgmUcD41YFp0FB BFJDA+5V2a50GlLf3bMvQql9vpj8o6uFLq3YKoaDSh20B0i9l+bJq1BwNoA7zDei/p1h qPZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 14si4581727ple.239.2017.10.27.09.15.00; Fri, 27 Oct 2017 09:15:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752522AbdJ0QO5 (ORCPT + 7 others); Fri, 27 Oct 2017 12:14:57 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:9453 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752574AbdJ0QOu (ORCPT ); Fri, 27 Oct 2017 12:14:50 -0400 Received: from 172.30.72.58 (EHLO DGGEMS414-HUB.china.huawei.com) ([172.30.72.58]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DJX16568; Sat, 28 Oct 2017 00:14:39 +0800 (CST) Received: from G00308965-DELL1.china.huawei.com (10.202.226.113) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.361.1; Sat, 28 Oct 2017 00:12:58 +0800 From: Gabriele Paoloni To: , , , , , , , , CC: , , , , , , , , , , , Subject: [PATCH v10 7/9] ACPI: Translate the I/O range of non-MMIO devices before scanning Date: Fri, 27 Oct 2017 17:11:25 +0100 Message-ID: <1509120687-7352-8-git-send-email-gabriele.paoloni@huawei.com> X-Mailer: git-send-email 2.7.1.windows.1 In-Reply-To: <1509120687-7352-1-git-send-email-gabriele.paoloni@huawei.com> References: <1509120687-7352-1-git-send-email-gabriele.paoloni@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.226.113] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.59F35B70.0050, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 49727a8b2ee5a09c5d69a8b24490fdd6 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: gabriele paoloni On some platforms(such as Hip06/Hip07), the legacy ISA/LPC devices access I/O with some special host-local I/O ports known on x86. As their I/O space are not memory mapped like PCI/PCIE MMIO host bridges, this patch is meant to support a new class of I/O host controllers where the local IO ports of the children devices are translated into the Indirect I/O address space. Through the handler attach callback, all the I/O translations are done before starting the enumeration on children devices and the translated addresses are replaced in the children resources. Signed-off-by: zhichang.yuan Signed-off-by: Gabriele Paoloni --- drivers/acpi/arm64/Makefile | 1 + drivers/acpi/arm64/acpi_indirectio.c | 156 +++++++++++++++++++++++++++++++++++ drivers/acpi/arm64/acpi_indirectio.h | 24 ++++++ drivers/acpi/internal.h | 5 ++ drivers/acpi/scan.c | 1 + 5 files changed, 187 insertions(+) create mode 100644 drivers/acpi/arm64/acpi_indirectio.c create mode 100644 drivers/acpi/arm64/acpi_indirectio.h -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/acpi/arm64/Makefile b/drivers/acpi/arm64/Makefile index 1017def..6a33ac6 100644 --- a/drivers/acpi/arm64/Makefile +++ b/drivers/acpi/arm64/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_ACPI_IORT) += iort.o obj-$(CONFIG_ACPI_GTDT) += gtdt.o +obj-$(CONFIG_INDIRECT_PIO) += acpi_indirectio.o diff --git a/drivers/acpi/arm64/acpi_indirectio.c b/drivers/acpi/arm64/acpi_indirectio.c new file mode 100644 index 0000000..013db6f --- /dev/null +++ b/drivers/acpi/arm64/acpi_indirectio.c @@ -0,0 +1,156 @@ +/* + * ACPI support for indirect-IO bus. + * + * Copyright (C) 2017 Hisilicon Limited, All Rights Reserved. + * Author: Gabriele Paoloni + * Author: Zhichang Yuan + * + * 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 +#include +#include + +#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); +} diff --git a/drivers/acpi/arm64/acpi_indirectio.h b/drivers/acpi/arm64/acpi_indirectio.h new file mode 100644 index 0000000..8102ea0 --- /dev/null +++ b/drivers/acpi/arm64/acpi_indirectio.h @@ -0,0 +1,24 @@ +/* + * ACPI support for indirect-IO bus. + * + * Copyright (C) 2017 Hisilicon Limited, All Rights Reserved. + * Author: Gabriele Paoloni + * Author: Zhichang Yuan + * + * 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 diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index 9531d32..36da45c 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -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 diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 3389729..14d6126 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -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);