From patchwork Fri Apr 1 15:49:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 8726151 Return-Path: X-Original-To: patchwork-xen-devel@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 C47F39FC82 for ; Fri, 1 Apr 2016 15:52:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B78B420109 for ; Fri, 1 Apr 2016 15:52:57 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9B9A0203DA for ; Fri, 1 Apr 2016 15:52:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1am1LG-0004Wr-7H; Fri, 01 Apr 2016 15:50:34 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1am1LF-0004WU-LL for xen-devel@lists.xen.org; Fri, 01 Apr 2016 15:50:33 +0000 Received: from [193.109.254.147] by server-1.bemta-14.messagelabs.com id 84/5D-30565-8C89EF65; Fri, 01 Apr 2016 15:50:32 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrBIsWRWlGSWpSXmKPExsVyMfSOge6JGf/ CDFY+FLdY8nExiwOjx9Hdv5kCGKNYM/OS8isSWDP6WnawFCxTrXh3t4epgXGxfBcjF4eQwERG ia8t51lBHBaBecwST9rWsIM4EgL9rBIXv/cxdTFyAjkxElsabrBD2FUSm3c2gsWFBNQklh1ey Awx6gmjxPvbvSwgCTYBHYkXk3aydTFycIgIeEjs+VgLUsMssIxJYt6mSYwgNcICgRIXeycwg9 gsAqoSJ/fPZAOxeQXcJbZ++Au1TE7i/PGfYDWcQHMm/3vFArHYXeLhrFnsExgFFjAyrGJUL04 tKkst0rXQSyrKTM8oyU3MzNE1NDTRy00tLk5MT81JTCrWS87P3cQIDC0GINjBuHGS8yFGSQ4m JVFew2n/woT4kvJTKjMSizPii0pzUosPMWpwcAj0rll9gVGKJS8/L1VJgrdoOlCdYFFqempFW mYOMPhhSiU4eJREeGtB0rzFBYm5xZnpEKlTjJYcW35fW8vEcWzuDSC5beq9tUxCYPOkxHlDQR oEQBoySvPgxsEi9BKjrJQwLyPQsUI8BalFuZklqPKvGMU5GJWEIa7iycwrgdv6CuggJqCDOqT BDipJREhJNTCeXLny8M6XZSXH5h1eF3ypaPcxGbldMX/ixI73drlLt75Wq/8z95j8q+Rykw8Z +U9uTJl7aZ2zfpRqO2NwpUPRtNpsRkXrp61KswNe3N8rt+5Kp9K3Jcmvj8/0uzRppkvL4bLVL T+74pcVJTg76/F7rtxpzfo7+6WVmuqTNO+rnK8cTS5e3SSixFKckWioxVxUnAgAGSAK1csCAA A= X-Env-Sender: shannon.zhao@linaro.org X-Msg-Ref: server-4.tower-27.messagelabs.com!1459525830!34161695!1 X-Originating-IP: [209.85.220.48] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.28; banners=-,-,- X-VirusChecked: Checked Received: (qmail 57156 invoked from network); 1 Apr 2016 15:50:32 -0000 Received: from mail-pa0-f48.google.com (HELO mail-pa0-f48.google.com) (209.85.220.48) by server-4.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 1 Apr 2016 15:50:32 -0000 Received: by mail-pa0-f48.google.com with SMTP id td3so93475478pab.2 for ; Fri, 01 Apr 2016 08:50:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sYI/jb6hkHrlv5Q7TtJCmY3B8Yyi2HIkHn5CkvRTyuE=; b=UpEk6E1H0qA5HuDBnVH2di307/awj6Dpg4bef9jD1maO1SratkYOhaH6rmqsvW+UDP RRxTRa/8qwOZHjq+URjSHVmzbuFd9341VPBsZHGr/Dmsts+0mWOWGX2LPPv1e+1n7mKj gIFMAtp4aWSzpqV5H3IzHeDeY/pFfYNGtNLiQ= 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=sYI/jb6hkHrlv5Q7TtJCmY3B8Yyi2HIkHn5CkvRTyuE=; b=DMKGBFP4BPudzmE/ZalCmlCl2Dr41+A4kPKk+ZIdrVzh+C3d6hphtzmG1gT9kkg3q8 zxDlVQUcVGOSj9r1vnZYp0nXfmoQ2iPXGjchApVvzRqWqY6PVJFwQper7IIGGkw/uvv9 beSg9ycLg0bhM1rDVFyMt2A29D5IMny6jQvIoPAcH5Cp7Uw7vEo/QwFq1BwBRKPcMo30 uzbH2kRriyjmL7p7h5qLECtLw0zLBwW6ZwfnAZmPJ5CtOfY70YlGPJtaoA/MFY7DEDg0 wsIBSi+ovm7/UNYOEzy87233W6A/a5MTHK8BLccNow8JKg2WQn923lEr/WXiNhr40Nco JuWQ== X-Gm-Message-State: AD7BkJL7OoOFKspa/UTuggIji7AH1rVTHWaS23XYlbMlgqN4psbyLrm35DwNP1UhTEMAcja7 X-Received: by 10.66.183.230 with SMTP id ep6mr32462844pac.89.1459525830146; Fri, 01 Apr 2016 08:50:30 -0700 (PDT) Received: from localhost.localdomain ([167.160.116.218]) by smtp.gmail.com with ESMTPSA id yj1sm22536791pac.16.2016.04.01.08.50.22 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 01 Apr 2016 08:50:28 -0700 (PDT) From: Shannon Zhao To: linux-arm-kernel@lists.infradead.org, stefano.stabellini@citrix.com Date: Fri, 1 Apr 2016 23:49:04 +0800 Message-Id: <1459525755-36968-7-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1459525755-36968-1-git-send-email-shannon.zhao@linaro.org> References: <1459525755-36968-1-git-send-email-shannon.zhao@linaro.org> Cc: devicetree@vger.kernel.org, linux-efi@vger.kernel.org, catalin.marinas@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, peter.huangpeng@huawei.com, julien.grall@arm.com, david.vrabel@citrix.com, zhaoshenglong@huawei.com, xen-devel@lists.xen.org, shannon.zhao@linaro.org Subject: [Xen-devel] [PATCH v10 06/17] Xen: ARM: Add support for mapping platform device mmio X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, 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 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 Acked-by: Stefano Stabellini --- drivers/xen/Makefile | 1 + drivers/xen/arm-device.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 drivers/xen/arm-device.c diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile index 9b7a35c..415f286 100644 --- a/drivers/xen/Makefile +++ b/drivers/xen/Makefile @@ -9,6 +9,7 @@ CFLAGS_features.o := $(nostackp) CFLAGS_efi.o += -fshort-wchar +dom0-$(CONFIG_ARM64) += arm-device.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/arm-device.c b/drivers/xen/arm-device.c new file mode 100644 index 0000000..76e26e5 --- /dev/null +++ b/drivers/xen/arm-device.c @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2015, Linaro Limited, Shannon Zhao + * + * 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, see . + */ + +#include +#include +#include +#include +#include +#include +#include + +static int xen_unmap_device_mmio(struct resource *resource, unsigned int count) +{ + unsigned int i, j, nr; + int rc = 0; + struct resource *r; + struct xen_remove_from_physmap xrp; + + for (i = 0; i < count; i++) { + r = &resource[i]; + nr = DIV_ROUND_UP(resource_size(r), XEN_PAGE_SIZE); + if ((resource_type(r) != IORESOURCE_MEM) || (nr == 0)) + continue; + + for (j = 0; j < nr; j++) { + xrp.domid = DOMID_SELF; + xrp.gpfn = XEN_PFN_DOWN(r->start) + j; + rc = HYPERVISOR_memory_op(XENMEM_remove_from_physmap, + &xrp); + if (rc) + return rc; + } + } + + return rc; +} + +static int xen_map_device_mmio(struct resource *resource, unsigned int count) +{ + unsigned int i, j, nr; + int rc = 0; + struct resource *r; + xen_pfn_t *gpfns; + xen_ulong_t *idxs; + int *errs; + struct xen_add_to_physmap_range xatp; + + for (i = 0; i < count; i++) { + r = &resource[i]; + nr = DIV_ROUND_UP(resource_size(r), XEN_PAGE_SIZE); + if ((resource_type(r) != IORESOURCE_MEM) || (nr == 0)) + continue; + + gpfns = kzalloc(sizeof(xen_pfn_t) * nr, GFP_KERNEL); + idxs = kzalloc(sizeof(xen_ulong_t) * nr, GFP_KERNEL); + errs = kzalloc(sizeof(int) * nr, GFP_KERNEL); + if (!gpfns || !idxs || !errs) { + kfree(gpfns); + kfree(idxs); + kfree(errs); + return -ENOMEM; + } + + for (j = 0; j < nr; j++) { + gpfns[j] = XEN_PFN_DOWN(r->start) + j; + idxs[j] = XEN_PFN_DOWN(r->start) + j; + } + + 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) + 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 (pdev->num_resources == 0 || pdev->resource == NULL) + return NOTIFY_OK; + + switch (action) { + case BUS_NOTIFY_ADD_DEVICE: + r = xen_map_device_mmio(pdev->resource, pdev->num_resources); + break; + case BUS_NOTIFY_DEL_DEVICE: + r = xen_unmap_device_mmio(pdev->resource, pdev->num_resources); + break; + default: + return NOTIFY_DONE; + } + if (r) + dev_err(&pdev->dev, "Platform: Failed to %s device %s MMIO!\n", + action == BUS_NOTIFY_ADD_DEVICE ? "map" : + (action == BUS_NOTIFY_DEL_DEVICE ? "unmap" : "?"), + pdev->name); + + return NOTIFY_OK; +} + +static struct notifier_block platform_device_nb = { + .notifier_call = xen_platform_notifier, +}; + +static int __init register_xen_platform_notifier(void) +{ + if (!xen_initial_domain() || acpi_disabled) + return 0; + + return bus_register_notifier(&platform_bus_type, &platform_device_nb); +} + +arch_initcall(register_xen_platform_notifier);