From patchwork Tue Nov 17 09:57:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 7635351 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F14549F392 for ; Tue, 17 Nov 2015 10:32:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 05D8D204E0 for ; Tue, 17 Nov 2015 10:32:19 +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 0F9C02043C for ; Tue, 17 Nov 2015 10:32:18 +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 1ZydWe-0002bL-Ji; Tue, 17 Nov 2015 10:30:12 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zyd22-0006f3-U0 for linux-arm-kernel@bombadil.infradead.org; Tue, 17 Nov 2015 09:58:35 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by merlin.infradead.org with esmtps (Exim 4.85 #2 (Red Hat Linux)) id 1Zyd21-0006xv-G6 for linux-arm-kernel@lists.infradead.org; Tue, 17 Nov 2015 09:58:34 +0000 Received: by wmvv187 with SMTP id v187so218380909wmv.1 for ; Tue, 17 Nov 2015 01:58:11 -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=ESXv8ahLmpFR3v3XkoWSyQvDS/r5fVIL3hY1xgKPbBg=; b=TftQxw5SsbF2vHqQMGLUnMT4meFv0F9uFQIpdruIBPTmUJ5dS84fNn8VD4e7jY0ZhZ Fk9MI/xMW38tIx9U7NT6NTqRrGuenEMgGw0gPVtnKC2EtS0/ZjxVw5htCxDYEGzZOlr6 hKty5QZWiiewvLZbVTRKxA7XeFzhmw8lJ3z8SJ0a68sQxCkMjGqlSXeQ8KLkjYLAnMYp bM0HSsjr1YyFR7QXRLbejTi2RX/PX85QIYMdEHRlLnIk8cR8K2rQQ425G2CkYQXfFWDw XEwcYA4y/L5e+iFM7e9GAOaNZvtTfrgUrBdPzlUQiYWVQaqUcQ8KCpq60kgf/3nJSVsx gyig== 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=ESXv8ahLmpFR3v3XkoWSyQvDS/r5fVIL3hY1xgKPbBg=; b=nAq3/ENeDIOU9uTDRnCygrRoVO34N/Ad1FwVxc+aycmjYCdQX4eoAzMaJ0bvZSp5U5 eIEjucy8WQxyxaAvWiwF+vZGDaBlQQVkfGShsWi/DS3SmSoCnQtG1dVAggy/bUw9h8x0 pSmjz5vZRTrQHel/ogXN+XftpyIJwfQz0PeEXQpxAgvsaKoO6/TT1CDmURNIR4GjfJ7a /NuoNfY1CNk9WYK3Ji6KeKxrLcsSA6x3hQTSJEeGXrKBc49LXO+3FO3aNgtx4CJNznio 10FUMZkG01kJAATXQh6oqs682Z2K4ZsrEd5EGouvUgK+PPulOHDJYUq5TZ0FRP8/5/jX j5Bg== X-Gm-Message-State: ALoCoQmvM3Ur26B+FOMwG/4J7pIFdusXVe32LtZhrHdgPVkUDYxYAvNJlxqS5oH9Xefw+Jtye7Lb X-Received: by 10.28.61.4 with SMTP id k4mr1623862wma.34.1447754291466; Tue, 17 Nov 2015 01:58:11 -0800 (PST) Received: from localhost ([78.129.251.54]) by smtp.gmail.com with ESMTPSA id c194sm23060850wmd.13.2015.11.17.01.58.08 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 17 Nov 2015 01:58:10 -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 06/13] Xen: ARM: Add support for mapping amba device mmio Date: Tue, 17 Nov 2015 17:57:04 +0800 Message-Id: <1447754231-7772-7-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_045833_768908_E445700B X-CRM114-Status: GOOD ( 22.01 ) 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 AMBA 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/amba.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 drivers/xen/amba.c diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile index 2f867e7..139bd0b 100644 --- a/drivers/xen/Makefile +++ b/drivers/xen/Makefile @@ -12,6 +12,7 @@ CFLAGS_features.o := $(nostackp) CFLAGS_efi.o += -fshort-wchar dom0-$(CONFIG_ARM64) += platform.o +dom0-$(CONFIG_ARM_AMBA) += amba.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/amba.c b/drivers/xen/amba.c new file mode 100644 index 0000000..e491c8e --- /dev/null +++ b/drivers/xen/amba.c @@ -0,0 +1,99 @@ +/* + * 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_amba_device_mmio(struct amba_device *adev) +{ + int rc = 0; + struct resource *r = &adev->res; + + 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_amba_notifier(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct amba_device *adev = to_amba_device(data); + int r = 0; + + if (!acpi_disabled && (action == BUS_NOTIFY_ADD_DEVICE)) + r = xen_map_amba_device_mmio(adev); + + if (r) + { + dev_err(&adev->dev, "Failed to add_to_physmap device (%s) mmio!\n", + adev->dev.init_name); + return NOTIFY_OK; + } + + return NOTIFY_DONE; +} + +static struct notifier_block amba_device_nb = { + .notifier_call = xen_amba_notifier, +}; + +static int __init register_xen_amba_notifier(void) +{ + if (!xen_initial_domain()) + return 0; + + return bus_register_notifier(&amba_bustype, &amba_device_nb); +} + +arch_initcall(register_xen_amba_notifier);