From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47096) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrN0x-0002YQ-0d for qemu-devel@nongnu.org; Mon, 02 Jun 2014 03:50:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrN0r-0001Tm-Br for qemu-devel@nongnu.org; Mon, 02 Jun 2014 03:50:38 -0400 Received: from mail-wg0-f41.google.com ([74.125.82.41]:59856) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrN0q-0001TR-OW for qemu-devel@nongnu.org; Mon, 02 Jun 2014 03:50:33 -0400 Received: by mail-wg0-f41.google.com with SMTP id z12so4595348wgg.0 for ; Mon, 02 Jun 2014 00:50:32 -0700 (PDT) From: Eric Auger Date: Mon, 2 Jun 2014 08:49:32 +0100 Message-Id: <1401695374-4287-9-git-send-email-eric.auger@linaro.org> In-Reply-To: <1401695374-4287-1-git-send-email-eric.auger@linaro.org> References: <1401695374-4287-1-git-send-email-eric.auger@linaro.org> Subject: [Qemu-devel] [RFC v3 08/10] Add AMBA devices support to VFIO List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: eric.auger@st.com, christoffer.dall@linaro.org, qemu-devel@nongnu.org, kim.phillips@freescale.com, a.rigo@virtualopensystems.com Cc: peter.maydell@linaro.org, eric.auger@linaro.org, patches@linaro.org, agraf@suse.de, stuart.yoder@freescale.com, alex.williamson@redhat.com, christophe.barnichon@st.com, a.motakis@virtualopensystems.com, kvmarm@lists.cs.columbia.edu From: Alvise Rigo 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]); -- 1.8.3.2