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: 7635411 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B421DBF90C for ; Tue, 17 Nov 2015 10:38:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CE91B204E0 for ; Tue, 17 Nov 2015 10:38:49 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CE55420458 for ; Tue, 17 Nov 2015 10:38:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zydcu-0000V1-Ps; Tue, 17 Nov 2015 10:36:40 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zyd1s-00068b-GF for linux-arm-kernel@lists.infradead.org; Tue, 17 Nov 2015 09:59:17 +0000 Received: by wmww144 with SMTP id w144so17741423wmw.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=MO1LDH8zZ3+H53AsFQ0Htmn7WSPVgaKkDQZDGssqfGvdWXcvkBXGrvcadbUaoY+pI+ 054wzZ6nJam+t7Jo5TOXwBALT2Ur80MNKqgXf8hcECY5fmHkVqY0PyIakgiVM9EvwcQs RBpANnLeFhDjAwM8xBEC5Yzqb9hjTNh2ugUnC2Ub5+u/KSoTcl4qCm9n6sGN/8pWL4Ub 8Gi0KVB5zp6VzliWyatVvRGV9UnWDv+X4ny/b7jX/0IXtKg+Ubo4GSRbMRLN/HMMZWHA 8IGXjmQ5TM3JBTIPnpiZT3OiC31Yf+BTQ505mnB4VRTXEMWBt6AAXMY5tYZ7jfb+tf/q zScA== X-Gm-Message-State: ALoCoQkg2wsNr0i6zP8QmYuIf3K5JHISLApT5r8XJonuDVbNbUf2YRd04Ukj5SVna1vG+tDRhVe+ 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151117_015825_604502_C2C32B5C X-CRM114-Status: GOOD ( 20.04 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, hangaohuai@huawei.com, linux-efi@vger.kernel.org, peter.huangpeng@huawei.com, xen-devel@lists.xen.org, shannon.zhao@linaro.org, zhaoshenglong@huawei.com, christoffer.dall@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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);