diff mbox

[RFC,v2,2/3] hw/vfio: amba device support

Message ID 1419265427-24238-3-git-send-email-b.reynal@virtualopensystems.com
State New
Headers show

Commit Message

Baptiste Reynal Dec. 22, 2014, 4:23 p.m. UTC
Add VFIO_DEVICE_TYPE_AMBA.
Differentiate amba and platform devices according to compatible string.

Signed-off-by: Baptiste Reynal <b.reynal@virtualopensystems.com>
---
 hw/vfio/platform.c            | 15 ++++++++++++---
 include/hw/vfio/vfio-common.h |  1 +
 2 files changed, 13 insertions(+), 3 deletions(-)

Comments

Eric Auger Jan. 15, 2015, 3:08 p.m. UTC | #1
Baptiste,
On 12/22/2014 05:23 PM, Baptiste Reynal wrote:
> Add VFIO_DEVICE_TYPE_AMBA.
> Differentiate amba and platform devices according to compatible string.
> 
> Signed-off-by: Baptiste Reynal <b.reynal@virtualopensystems.com>
> ---
>  hw/vfio/platform.c            | 15 ++++++++++++---
>  include/hw/vfio/vfio-common.h |  1 +
>  2 files changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
> index 39eef08..0a96178 100644
> --- a/hw/vfio/platform.c
> +++ b/hw/vfio/platform.c
> @@ -563,8 +563,13 @@ static int vfio_base_device_init(VFIODevice *vbasedev)
>      }
>  
>      /* Check that the host device exists */
> -    snprintf(path, sizeof(path), "/sys/bus/platform/devices/%s/",
> -             vbasedev->name);
> +    if (vbasedev->type == VFIO_DEVICE_TYPE_AMBA) {
> +        snprintf(path, sizeof(path), "/sys/bus/amba/devices/%s/",
> +                vbasedev->name);
> +    } else {
> +        snprintf(path, sizeof(path), "/sys/bus/platform/devices/%s/",
> +                vbasedev->name);
> +    }
>  
>      if (stat(path, &st) < 0) {
>          error_report("vfio: error: no such host device: %s", path);
> @@ -661,7 +666,11 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp)
>      VFIODevice *vbasedev = &vdev->vbasedev;
>      int i, ret;
>  
> -    vbasedev->type = VFIO_DEVICE_TYPE_PLATFORM;
> +    if (strstr(vdev->compat, "arm,primecell")) {
> +        vbasedev->type = VFIO_DEVICE_TYPE_AMBA;
> +    } else {
> +        vbasedev->type = VFIO_DEVICE_TYPE_PLATFORM;
> +    }
>      vbasedev->ops = &vfio_platform_ops;
>  
>  #ifdef CONFIG_KVM
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index 58fd786..2f1b09c 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -49,6 +49,7 @@ extern int vfio_kvm_device_fd;
>  enum {
>      VFIO_DEVICE_TYPE_PCI = 0,
>      VFIO_DEVICE_TYPE_PLATFORM = 1,
> +    VFIO_DEVICE_TYPE_AMBA = 2,
>  };
>  
>  typedef struct VFIORegion {
> 
With last version I added a check of the flags in vfio_populate_device
following Alex advice. You will need to check AMBA too.

Best Regards

Eric
diff mbox

Patch

diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
index 39eef08..0a96178 100644
--- a/hw/vfio/platform.c
+++ b/hw/vfio/platform.c
@@ -563,8 +563,13 @@  static int vfio_base_device_init(VFIODevice *vbasedev)
     }
 
     /* Check that the host device exists */
-    snprintf(path, sizeof(path), "/sys/bus/platform/devices/%s/",
-             vbasedev->name);
+    if (vbasedev->type == VFIO_DEVICE_TYPE_AMBA) {
+        snprintf(path, sizeof(path), "/sys/bus/amba/devices/%s/",
+                vbasedev->name);
+    } else {
+        snprintf(path, sizeof(path), "/sys/bus/platform/devices/%s/",
+                vbasedev->name);
+    }
 
     if (stat(path, &st) < 0) {
         error_report("vfio: error: no such host device: %s", path);
@@ -661,7 +666,11 @@  static void vfio_platform_realize(DeviceState *dev, Error **errp)
     VFIODevice *vbasedev = &vdev->vbasedev;
     int i, ret;
 
-    vbasedev->type = VFIO_DEVICE_TYPE_PLATFORM;
+    if (strstr(vdev->compat, "arm,primecell")) {
+        vbasedev->type = VFIO_DEVICE_TYPE_AMBA;
+    } else {
+        vbasedev->type = VFIO_DEVICE_TYPE_PLATFORM;
+    }
     vbasedev->ops = &vfio_platform_ops;
 
 #ifdef CONFIG_KVM
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 58fd786..2f1b09c 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -49,6 +49,7 @@  extern int vfio_kvm_device_fd;
 enum {
     VFIO_DEVICE_TYPE_PCI = 0,
     VFIO_DEVICE_TYPE_PLATFORM = 1,
+    VFIO_DEVICE_TYPE_AMBA = 2,
 };
 
 typedef struct VFIORegion {