From patchwork Mon Jun 23 14:54:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alvise Rigo X-Patchwork-Id: 362968 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A23F91400A7 for ; Tue, 24 Jun 2014 00:56:34 +1000 (EST) Received: from localhost ([::1]:53992 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz5fc-00039y-Lh for incoming@patchwork.ozlabs.org; Mon, 23 Jun 2014 10:56:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52038) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz5dW-0008E3-GF for qemu-devel@nongnu.org; Mon, 23 Jun 2014 10:54:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wz5dQ-00046i-P0 for qemu-devel@nongnu.org; Mon, 23 Jun 2014 10:54:22 -0400 Received: from mail-we0-f171.google.com ([74.125.82.171]:40036) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz5dQ-00046Y-GZ for qemu-devel@nongnu.org; Mon, 23 Jun 2014 10:54:16 -0400 Received: by mail-we0-f171.google.com with SMTP id q58so7221820wes.30 for ; Mon, 23 Jun 2014 07:54:15 -0700 (PDT) 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=cV2cxmDp5180fsvgzcxWuwyDXWoScWBP1NH3OzIKjrQ=; b=N2jMWpTZRcGhDVNDu47mE+BofO1oJv9FYZc614B1ewRPC/wMpThoM/+I5wNU891ICr 84KdQJX39Gj2l+QJ5NvNg6JFap2rE6Li9kIQ8j77N46MO/yTpL9Qz3y5WNfaftJxkalJ x6JG/ESG3OFZPHGAR3nkLzh7+M0fhe01yMpiMQyodfIVfnhRX4rRVfQ0u5Pnzs+RCFV2 TdM5J0Now5UvjN9FJYbUhAYofJ7zIDntzF2VW/zuFnjDhNoTW8sK2RD6Lhs91J+cNNgV v3PUhHg2L6zNCCubyk1pxl4vLIBBmCITgxKpA0Tyg0KQXASLWj50IR10S/G+VcNfNguB 5XCQ== X-Gm-Message-State: ALoCoQmOiduDebPV/9lbR+M79EjK08+DiHPdP+UTALS4+86xMYeeOAKl0QnMXlVbM8SQU3qMkx75 X-Received: by 10.194.92.148 with SMTP id cm20mr28818775wjb.57.1403535254097; Mon, 23 Jun 2014 07:54:14 -0700 (PDT) Received: from localhost.localdomain (AGrenoble-651-1-433-141.w90-52.abo.wanadoo.fr. [90.52.177.141]) by mx.google.com with ESMTPSA id di7sm17576989wjb.34.2014.06.23.07.54.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Jun 2014 07:54:13 -0700 (PDT) From: Alvise Rigo To: qemu-devel@nongnu.org, a.motakis@virtualopensystems.com, eric.auger@st.com Date: Mon, 23 Jun 2014 16:54:02 +0200 Message-Id: <1403535245-30041-2-git-send-email-a.rigo@virtualopensystems.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1403535245-30041-1-git-send-email-a.rigo@virtualopensystems.com> References: <1403535245-30041-1-git-send-email-a.rigo@virtualopensystems.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.171 Cc: Peter Maydell , tech@virtualopensystems.com, Alvise Rigo , Eric Auger Subject: [Qemu-devel] [RFC PATCH v3 1/4] Add AMBA devices support to VFIO X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The impossibility to add more then one compatibility property to the device tree node was not permitting to bind AMBA devices. Now we can add an arbitrary number of compatibility property values divided by the character ";". If the compatibility string contains the substring "arm,primecell", a clock property will be added to the device tree node in order to allow the AMBA bus code to probe the device. [Eric Auger] put str_ptr in the declaration part and rename pcompat into compat Signed-off-by: Alvise Rigo Signed-off-by: Eric Auger --- hw/arm/virt.c | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 8de6d1a..bc561b5 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -369,6 +369,7 @@ static int vfio_init_func(QemuOpts *opts, void *opaque) int irq_start = vbi->avail_vfio_irq; hwaddr vfio_base = vbi->avail_vfio_base; char *nodename; + char *str_ptr; char *corrected_compat, *compat, *name; int num_irqs, num_regions; MemoryRegion *mr; @@ -377,6 +378,8 @@ static int vfio_init_func(QemuOpts *opts, void *opaque) uint64_t *reg_attr; uint64_t size; Error *errp = NULL; + bool is_amba = false; + int compat_str_len; if (!driver) { qerror_report(QERR_MISSING_PARAMETER, "driver"); @@ -442,17 +445,30 @@ static int vfio_init_func(QemuOpts *opts, void *opaque) /* * process compatibility property string passed by end-user - * replaces / by , - * currently a single property compatibility value is supported! + * replaces / by , and ; by NUL character */ corrected_compat = g_strdup(compat); - char *slash = strchr(corrected_compat, '/'); - if (slash != NULL) { - *slash = ','; - } else { - error_report("Wrong compat string %s, should contain a /\n", - compat); - exit(1); + /* + * the total length of the string has to include also the last + * NUL char. + */ + compat_str_len = strlen(corrected_compat) + 1; + + str_ptr = corrected_compat; + while ((str_ptr = strchr(str_ptr, '/')) != NULL) { + *str_ptr = ','; + } + + /* check if is an AMBA device */ + str_ptr = corrected_compat; + if (strstr(str_ptr, "arm,primecell") != NULL) { + is_amba = true; + } + + /* substitute ";" with the NUL char */ + str_ptr = corrected_compat; + while ((str_ptr = strchr(str_ptr, ';')) != NULL) { + *str_ptr = '\0'; } sysbus_mmio_map(s, 0, vfio_base); @@ -462,7 +478,7 @@ static int vfio_init_func(QemuOpts *opts, void *opaque) qemu_fdt_add_subnode(vbi->fdt, nodename); qemu_fdt_setprop(vbi->fdt, nodename, "compatible", - corrected_compat, strlen(corrected_compat)); + corrected_compat, compat_str_len); ret = qemu_fdt_setprop_sized_cells_from_array(vbi->fdt, nodename, "reg", num_regions*2, reg_attr); @@ -471,6 +487,15 @@ static int vfio_init_func(QemuOpts *opts, void *opaque) } irq_attr = g_new(uint32_t, num_irqs*3); + + if (is_amba) { + qemu_fdt_setprop_cells(vbi->fdt, nodename, "clocks", + vbi->clock_phandle); + char clock_names[] = "apb_pclk"; + qemu_fdt_setprop(vbi->fdt, nodename, "clock-names", clock_names, + sizeof(clock_names)); + } + for (i = 0; i < num_irqs; i++) { sysbus_connect_irq(s, i, vbi->pic[irq_start+i]);