]> xenbits.xensource.com Git - people/vhanquez/xen-unstable.git/commitdiff
amd iommu: improve parse_event_log_entry()
authorJan Beulich <jbeulich@suse.com>
Wed, 23 May 2012 15:20:18 +0000 (17:20 +0200)
committerJan Beulich <jbeulich@suse.com>
Wed, 23 May 2012 15:20:18 +0000 (17:20 +0200)
- message table should be static (no need to set it up each time the
  function gets executed)
- don't bail on out-of-range event code values
- use message table also to print the kind of otherwise unhandled
  event codes

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Wei Wang <wei.wang2@amd.com>
xen/drivers/passthrough/amd/iommu_init.c

index 67e86f64fbd6a125330db7d613f878a3d72e1def..6a5e9edab5545b3856b23a6abab28c0f62e0fd6b 100644 (file)
@@ -568,14 +568,18 @@ static void parse_event_log_entry(struct amd_iommu *iommu, u32 entry[])
     u32 code;
     u64 *addr;
     int count = 0;
-    char * event_str[] = {"ILLEGAL_DEV_TABLE_ENTRY",
-                          "IO_PAGE_FAULT",
-                          "DEV_TABLE_HW_ERROR",
-                          "PAGE_TABLE_HW_ERROR",
-                          "ILLEGAL_COMMAND_ERROR",
-                          "COMMAND_HW_ERROR",
-                          "IOTLB_INV_TIMEOUT",
-                          "INVALID_DEV_REQUEST"};
+    static const char *const event_str[] = {
+#define EVENT_STR(name) [IOMMU_EVENT_##name - 1] = #name
+        EVENT_STR(ILLEGAL_DEV_TABLE_ENTRY),
+        EVENT_STR(IO_PAGE_FAULT),
+        EVENT_STR(DEV_TABLE_HW_ERROR),
+        EVENT_STR(PAGE_TABLE_HW_ERROR),
+        EVENT_STR(ILLEGAL_COMMAND_ERROR),
+        EVENT_STR(COMMAND_HW_ERROR),
+        EVENT_STR(IOTLB_INV_TIMEOUT),
+        EVENT_STR(INVALID_DEV_REQUEST)
+#undef EVENT_STR
+    };
 
     code = get_field_from_reg_u32(entry[1], IOMMU_EVENT_CODE_MASK,
                                             IOMMU_EVENT_CODE_SHIFT);
@@ -599,13 +603,6 @@ static void parse_event_log_entry(struct amd_iommu *iommu, u32 entry[])
                                       IOMMU_EVENT_CODE_SHIFT);
     }
 
-    if ( (code > IOMMU_EVENT_INVALID_DEV_REQUEST) ||
-        (code < IOMMU_EVENT_ILLEGAL_DEV_TABLE_ENTRY) )
-    {
-        AMD_IOMMU_DEBUG("Invalid event log entry!\n");
-        return;
-    }
-
     if ( code == IOMMU_EVENT_IO_PAGE_FAULT )
     {
         device_id = iommu_get_devid_from_event(entry[0]);
@@ -633,8 +630,10 @@ static void parse_event_log_entry(struct amd_iommu *iommu, u32 entry[])
     }
     else
     {
-        AMD_IOMMU_DEBUG("event 0x%08x 0x%08x 0x%08x 0x%08x\n", entry[0],
-                        entry[1], entry[2], entry[3]);
+        AMD_IOMMU_DEBUG("%s %08x %08x %08x %08x\n",
+                        code <= ARRAY_SIZE(event_str) ? event_str[code - 1]
+                                                      : "event",
+                        entry[0], entry[1], entry[2], entry[3]);
     }
 
     memset(entry, 0, IOMMU_EVENT_LOG_ENTRY_SIZE);