From patchwork Tue Nov 17 09:57:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 56772 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp1831137lbb; Tue, 17 Nov 2015 01:58:09 -0800 (PST) X-Received: by 10.66.156.1 with SMTP id wa1mr62806093pab.84.1447754289169; Tue, 17 Nov 2015 01:58:09 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id eo16si56569775pab.209.2015.11.17.01.58.08; Tue, 17 Nov 2015 01:58:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-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 devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753450AbbKQJ6I (ORCPT + 6 others); Tue, 17 Nov 2015 04:58:08 -0500 Received: from mail-wm0-f45.google.com ([74.125.82.45]:35519 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752921AbbKQJ6D (ORCPT ); Tue, 17 Nov 2015 04:58:03 -0500 Received: by wmdw130 with SMTP id w130so147181078wmd.0 for ; Tue, 17 Nov 2015 01:58:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zah983k02cD1KKmi5hRzcOKSnB339n+eyTYGgL1EytE=; b=jwFxOCttE+rqENSSEJ8BDeuSoAqy+QQjdUx6+qkOJs0IyJOL1zhpffBeATZyq7UWCR gWxu+Dvk559rHiN47a46729G0lhcJI0iFLRDyym/p2gXmbEvXQsFh7m75ixPxw//8n+G OtseFPZyvoI+LCqScPER+tnyQVw50lxhk180fC7rA1iwjvUB7AgZG66fN2H7L9q3yZ4/ oKSvlqAMtk4UfO0iG+TdN2fte4vnrILh5fygl8Ed9KC+FPYotIjy1X+1ohkkthDSTeJh ru9fMB8RoN+SPQbaMV+YTY7SJu8CAZyPceL8HFpdKWIivKFaeeK0hkV5/xf+2q80JN5K zF0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zah983k02cD1KKmi5hRzcOKSnB339n+eyTYGgL1EytE=; b=g93jJnewRZjKNRs5ObsckPcvypcAtZItZDW4PprKAB+mORz8+fIiTWO9UbMjrCmSG2 8BG9V9hrYeW7mR0aWz0UEsSj+7S5HWzMiTG6icKGUy/8hFLv0c35rrU22KkBTiyLcUI+ w+YFtbTEEuhCjVDlnSBYVPa5hZ6vaWsp5f6BRSXt1rxjcGUOyeZFSUn5qkDsUWMqSt2l QOesKPSwdIp8yOYvF0nMVOiNPYVmsV16zipvOJousqDgIPjAKqmDGw2W1bQeWwPO0Szg d4AUHBE7hBvvUnkv1WBry5Px5ttwqRU+arMeOyKNNQ3ZKgiR8tRq7TXuKxe6aFyj7fMT KX0w== X-Gm-Message-State: ALoCoQkO1B3gbEhCc02bWNHL3B/+0zeLz8tjd5b/okQxXjvAWRbs6yyQJvV+zMTqFJkBMgf91F6C X-Received: by 10.28.11.71 with SMTP id 68mr1628860wml.77.1447754282652; Tue, 17 Nov 2015 01:58:02 -0800 (PST) Received: from localhost ([78.129.251.54]) by smtp.gmail.com with ESMTPSA id s2sm23071967wmd.13.2015.11.17.01.57.59 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 17 Nov 2015 01:58:01 -0800 (PST) From: shannon.zhao@linaro.org To: ian.campbell@citrix.com, stefano.stabellini@citrix.com, catalin.marinas@arm.com, will.deacon@arm.com, julien.grall@citrix.com, ard.biesheuvel@linaro.org, mark.rutland@arm.com, linux-arm-kernel@lists.infradead.org Cc: xen-devel@lists.xen.org, christoffer.dall@linaro.org, devicetree@vger.kernel.org, linux-efi@vger.kernel.org, peter.huangpeng@huawei.com, shannon.zhao@linaro.org, zhaoshenglong@huawei.com, hangaohuai@huawei.com Subject: [PATCH 05/13] Xen: ARM: Add support for mapping platform device mmio Date: Tue, 17 Nov 2015 17:57:03 +0800 Message-Id: <1447754231-7772-6-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1447754231-7772-1-git-send-email-shannon.zhao@linaro.org> References: <1447754231-7772-1-git-send-email-shannon.zhao@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Shannon Zhao Add a bus_notifier for platform bus device in order to map the device mmio regions when DOM0 booting with ACPI. Signed-off-by: Shannon Zhao --- drivers/xen/Makefile | 1 + drivers/xen/platform.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 drivers/xen/platform.c -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe devicetree" 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/xen/Makefile b/drivers/xen/Makefile index e293bc5..2f867e7 100644 --- a/drivers/xen/Makefile +++ b/drivers/xen/Makefile @@ -11,6 +11,7 @@ CFLAGS_features.o := $(nostackp) CFLAGS_efi.o += -fshort-wchar +dom0-$(CONFIG_ARM64) += platform.o dom0-$(CONFIG_PCI) += pci.o dom0-$(CONFIG_USB_SUPPORT) += dbgp.o dom0-$(CONFIG_XEN_ACPI) += acpi.o $(xen-pad-y) diff --git a/drivers/xen/platform.c b/drivers/xen/platform.c new file mode 100644 index 0000000..0f95e7f --- /dev/null +++ b/drivers/xen/platform.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2015, Linaro Limited. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307 USA. + * + * Author: Shannon Zhao + */ + +#include +#include +#include +#include +#include +#include + +static int xen_map_platform_device_mmio(struct platform_device *pdev) +{ + int i, rc = 0; + + for (i = 0; i < pdev->num_resources; i++) + { + struct resource *r = &pdev->resource[i]; + + if (resource_type(r) == IORESOURCE_MEM) + { + int j; + int nr = DIV_ROUND_UP(resource_size(r), PAGE_SIZE); + xen_pfn_t *gpfns = kmalloc(sizeof(xen_pfn_t) * nr, + GFP_KERNEL); + xen_ulong_t *idxs = kmalloc(sizeof(xen_ulong_t) * nr, + GFP_KERNEL); + int *errs = kmalloc(sizeof(int) * nr, GFP_KERNEL); + struct xen_add_to_physmap_range xatp; + + for (j = 0; j < nr; j++) { + gpfns[j] = (r->start >> PAGE_SHIFT) + j; + idxs[j] = (r->start >> PAGE_SHIFT) + j; + errs[j] = 0; + } + + xatp.domid = DOMID_SELF; + xatp.size = nr; + xatp.space = XENMAPSPACE_dev_mmio; + + set_xen_guest_handle(xatp.gpfns, gpfns); + set_xen_guest_handle(xatp.idxs, idxs); + set_xen_guest_handle(xatp.errs, errs); + + rc = HYPERVISOR_memory_op(XENMEM_add_to_physmap_range, + &xatp); + kfree(gpfns); + kfree(idxs); + kfree(errs); + if (rc != 0) + return rc; + } + } + + return rc; +} + +static int xen_platform_notifier(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct platform_device *pdev = to_platform_device(data); + int r = 0; + + if (!acpi_disabled && (action == BUS_NOTIFY_ADD_DEVICE)) + r = xen_map_platform_device_mmio(pdev); + + if (r) + { + dev_err(&pdev->dev, "Failed to add_to_physmap device (%s) mmio!\n", + pdev->name); + return NOTIFY_OK; + } + + return NOTIFY_DONE; +} + +static struct notifier_block platform_device_nb = { + .notifier_call = xen_platform_notifier, +}; + +static int __init register_xen_platform_notifier(void) +{ + if (!xen_initial_domain()) + return 0; + + return bus_register_notifier(&platform_bus_type, &platform_device_nb); +} + +arch_initcall(register_xen_platform_notifier);