From patchwork Sun May 11 17:13:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alvise Rigo X-Patchwork-Id: 347805 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D16B2140087 for ; Mon, 12 May 2014 03:16:51 +1000 (EST) Received: from localhost ([::1]:33750 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjXMn-0002vb-NR for incoming@patchwork.ozlabs.org; Sun, 11 May 2014 13:16:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjXK0-0007ZK-5R for qemu-devel@nongnu.org; Sun, 11 May 2014 13:14:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WjXJt-0005XT-Az for qemu-devel@nongnu.org; Sun, 11 May 2014 13:13:56 -0400 Received: from mail-we0-f169.google.com ([74.125.82.169]:54674) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjXJt-0005XP-2r for qemu-devel@nongnu.org; Sun, 11 May 2014 13:13:49 -0400 Received: by mail-we0-f169.google.com with SMTP id u56so5982491wes.14 for ; Sun, 11 May 2014 10:13:48 -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=K3kEyxI3WMzWu8dhyz5E+WvPMZGXob0pMlZRRke2goE=; b=h8aBXtw6CJMZXoRIj/rmmtXAwrjzBU3rvwNgVKjK29puHbU83S1aDgMMODcBIZn9XY fLtieY7bfuD3pcVf/Y3Sv8UW4a5TDWDW2/a5VAintP8gg/osjDhm+ZNOcbBJC06kSeyr xGewo132Lo2xVdusbS0RTSnpV0tQ3aYZF6civZZiWE5q8F7EpUVviEZ34KSkTQYDBLSl VW4f4TMtJMg/vkhqMaItAYDl58AaxEq5ZspoJnuxeB63AwO1be5CYoYDKjx5+3IPNFAW RwxDn8V29hilw5wkO75F8Wcq9a78V6hK5HAGs0i3MjrUVc1EgbCPeZ6RP6XPKNhvutdj yP/Q== X-Gm-Message-State: ALoCoQk/o84xRS59Bl08TaMA9qRqu+/Qt/aHUvMx+nOccKZKJIEFHUmXSkxmWAKBgV9GJEOdXue1 X-Received: by 10.180.221.8 with SMTP id qa8mr11914937wic.39.1399828428365; Sun, 11 May 2014 10:13:48 -0700 (PDT) Received: from localhost.localdomain (AGrenoble-651-1-595-48.w90-42.abo.wanadoo.fr. [90.42.235.48]) by mx.google.com with ESMTPSA id fq2sm11326154wib.2.2014.05.11.10.13.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 11 May 2014 10:13:47 -0700 (PDT) From: Alvise Rigo To: qemu-devel@nongnu.org, a.motakis@virtualopensystems.com, eric.auger@st.com, kim.phillips@linaro.org Date: Sun, 11 May 2014 19:13:34 +0200 Message-Id: <1399828415-13007-4-git-send-email-a.rigo@virtualopensystems.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1399828415-13007-1-git-send-email-a.rigo@virtualopensystems.com> References: <1399828415-13007-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.169 Cc: Alex Williamson , tech@virtualopensystems.com, Alvise Rigo Subject: [Qemu-devel] [RFC v2 3/4] MemoryRegion with EOI callbacks for VFIO Platform devices 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 user can specify the location of the memory region (register) used by the guest driver to clear the pending interrupt; if enabled, this mechanism will overlap to the default one (timer based). The region is provided as command line property "intclr-region" of the vfio-platform device. The property is a string "region_index;offset;size" where: region_index: is the index of the memory region where the register lives, offset: offset of the register in the region, size: size of the register. example: -device vfio-platform,...,intclr-region="0;0x2c;4" Signed-off-by: Alvise Rigo --- hw/vfio/platform.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 2 deletions(-) diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index c4a4286..ec6a29e 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -40,6 +40,7 @@ #include "vfio-common.h" +/*#define DEBUG_VFIO 1*/ #ifdef DEBUG_VFIO #define DPRINTF(fmt, ...) \ do { fprintf(stderr, "vfio: %s: " fmt, __func__, ## __VA_ARGS__); } \ @@ -56,6 +57,11 @@ #define TYPE_VFIO_PLATFORM "vfio-platform" +struct intclr_region { + hwaddr offset; + hwaddr size; +}; + typedef struct VFIORegion { off_t fd_offset; /* offset of region within device fd */ int fd; /* device fd, allows us to pass VFIORegion as opaque data */ @@ -65,6 +71,7 @@ typedef struct VFIORegion { size_t size; uint32_t flags; /* VFIO region flags (rd/wr/mmap) */ uint8_t nr; /* cache the region number for debug */ + struct intclr_region intclr_reg; } VFIORegion; @@ -99,6 +106,8 @@ typedef struct VFIODevice { QLIST_ENTRY(VFIODevice) next; struct VFIOGroup *group; QLIST_HEAD(, VFIOINTp) intp_list; + char *intclr_region_str; /* clear interrupt region string */ + bool has_intclr_region; } VFIODevice; @@ -120,6 +129,48 @@ void vfio_get_props(SysBusDevice *s, char **pname, *psize = vdev->regions[0].size; } +static int parse_clrint_string(const char *intclr_str, uint32_t *id_reg, + hwaddr *off_reg, uint64_t *size_reg) +{ + char *str_ptr = g_strdup(intclr_str); + char *idx, *off, *size; + + if (strlen(intclr_str) < 5) { + return -1; + } + + idx = str_ptr; + str_ptr = strchr(str_ptr, ';'); + if (!str_ptr || idx == str_ptr) { + return -1; + } + *str_ptr = '\0'; + + off = ++str_ptr; + str_ptr = strchr(str_ptr, ';'); + if (!str_ptr || off == str_ptr) { + return -1; + } + *str_ptr = '\0'; + + size = ++str_ptr; + if (!*size) { + return -1; + } + + *id_reg = strtol(idx, NULL, 10); + *off_reg = strtol(off, NULL, 0); + *size_reg = strtol(size, NULL, 10); + + if (errno == EINVAL || errno == ERANGE) { + return -1; + } + + DPRINTF("intclr region - id: %u offset: 0x%"HWADDR_PRIx" size: %"PRIx64"\n", + *id_reg, *off_reg, *size_reg); + return 0; +} + static void vfio_disable_irqindex(VFIODevice *vdev, int index) { struct vfio_irq_set irq_set = { @@ -397,6 +448,8 @@ static void vfio_region_write(void *opaque, hwaddr addr, uint64_t data, unsigned size) { VFIORegion *region = opaque; + VFIODevice *vdev = NULL; + union { uint8_t byte; uint16_t word; @@ -427,13 +480,22 @@ static void vfio_region_write(void *opaque, hwaddr addr, DPRINTF("(region %d, addr=0x%"HWADDR_PRIx", data= 0x%"PRIx64", %d)\n", region->nr, addr, data, size); - vfio_irq_eoi(container_of(region, VFIODevice, regions[region->nr])); + vdev = container_of(region, VFIODevice, regions[region->nr]); + struct intclr_region *intr = ®ion->intclr_reg; + /* If an interrupt clear region has been specified we clear the pending + * intterrupts only when the memory accesse is inside the region. + * */ + if ((addr >= intr->offset && addr + size <= intr->offset + intr->size) + || !vdev->has_intclr_region) { + vfio_irq_eoi(vdev); + } } static uint64_t vfio_region_read(void *opaque, hwaddr addr, unsigned size) { VFIORegion *region = opaque; + VFIODevice *vdev = NULL; union { uint8_t byte; uint16_t word; @@ -466,7 +528,10 @@ static uint64_t vfio_region_read(void *opaque, hwaddr addr, unsigned size) DPRINTF("(region %d, addr= 0x%"HWADDR_PRIx", data=%d) = 0x%"PRIx64"\n", region->nr, addr, size, data); - vfio_irq_eoi(container_of(region, VFIODevice, regions[region->nr])); + vdev = container_of(region, VFIODevice, regions[region->nr]); + if (!vdev->has_intclr_region) { + vfio_irq_eoi(vdev); + } return data; } @@ -669,6 +734,17 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp) } } + hwaddr intclr_off = 0; + uint64_t intclr_size = 0; + uint32_t id = 0; + if (vdev->intclr_region_str) { + ret = parse_clrint_string(vdev->intclr_region_str, &id, &intclr_off, + &intclr_size); + } else { + ret = -1; + } + vdev->has_intclr_region = (!ret) ? true : false; + ret = vfio_get_device(group, path, vdev); if (ret) { error_report("vfio: failed to get device %s", path); @@ -678,6 +754,16 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp) for (i = 0; i < vdev->num_regions; i++) { vfio_map_region(vdev, i); + + if (id == i && vdev->has_intclr_region) { + struct intclr_region *intclr_reg = NULL; + + intclr_reg = &(vdev->regions[i].intclr_reg); + + intclr_reg->offset = intclr_off; + intclr_reg->size = intclr_size; + } + sysbus_init_mmio(sbdev, &vdev->regions[i].mem); } } @@ -729,6 +815,7 @@ typedef struct VFIOPlatformDeviceClass { static Property vfio_platform_dev_properties[] = { DEFINE_PROP_STRING("vfio_device", VFIODevice, name), DEFINE_PROP_STRING("compat", VFIODevice, compat), +DEFINE_PROP_STRING("intclr-region", VFIODevice, intclr_region_str), DEFINE_PROP_UINT32("mmap-timeout-ms", VFIODevice, mmap_timeout, 1100), DEFINE_PROP_END_OF_LIST(), };