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: 56773 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp1831186lbb; Tue, 17 Nov 2015 01:58:15 -0800 (PST) X-Received: by 10.66.228.137 with SMTP id si9mr60919933pac.63.1447754295870; Tue, 17 Nov 2015 01:58:15 -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.15; Tue, 17 Nov 2015 01:58:15 -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 S1753533AbbKQJ6O (ORCPT + 6 others); Tue, 17 Nov 2015 04:58:14 -0500 Received: from mail-wm0-f44.google.com ([74.125.82.44]:36358 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753028AbbKQJ6M (ORCPT ); Tue, 17 Nov 2015 04:58:12 -0500 Received: by wmww144 with SMTP id w144so146101076wmw.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=dHdwjvbAGn++PiTYYYaUZtghYunAM52crwKqHR+gadhCVecoxUhceQnatNCydSRS5X qhY/hsGwsqN4XAAnKcasMao+zq2QIhYqvZlqGRyDQKEmMCzuN7SHwGBxMmFAQh4Itnzw 89fgWXQoaVZygij0Gx1h4bUW+dnQ2/OCcSveE41glnDUwadbOAzPrdJkFVrFbZE8vUzv zaLeTYPMpxAP0xGX30rq9plFsM2sdmIub7uyk/1aMuiZomLM6ISosjgqGAKNcPdCLLD2 +9ZaRx/u3j9Z1wzk7Fgr9Ir2dcbk7zWYmHo8Zt2NKhO82XBauKub9gHZGZtFcHuM5JX4 MbbQ== X-Gm-Message-State: ALoCoQntxsOEh4ngUaifTbpL87DRx/Qe9Cl2ePnUIDVKJTeREp3CwRAFR3z7Js9cYTGDW5zRIqB8 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 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 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> 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 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 -- 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 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);