IOMMUS: Refine IOMMU PAGE FAULT logs print

For debugging robustly, we provided more info to indicate
PAGE FAULT from which ISP.

- Move iommu from device to platform.
- Print all sysmmu ISP used.
- Check dmesg for sysmmu errors for avoiding misleading issues.

Bug: 215050600
Test: Logs and CTS, GCA
Signed-off-by: Nick Chung <nickchung@google.com>
Change-Id: Ic8bd4e08aad54d3cad0ed4c8a0ad1ac47c0106fe
diff --git a/lwis_device.h b/lwis_device.h
index 76764e7..e0c51ea 100644
--- a/lwis_device.h
+++ b/lwis_device.h
@@ -206,8 +206,6 @@
 	DECLARE_HASHTABLE(event_states, EVENT_HASH_BITS);
 	/* Virtual function table for sub classes */
 	struct lwis_device_subclass_operations vops;
-	/* Does the device have IOMMU. TODO: Move to platform */
-	bool has_iommu;
 	/* Mutex used to synchronize register access between clients */
 	struct mutex reg_rw_lock;
 	/* Heartbeat timer structure */
diff --git a/lwis_dt.c b/lwis_dt.c
index 0f31961..f90b101 100644
--- a/lwis_dt.c
+++ b/lwis_dt.c
@@ -959,8 +959,6 @@
 {
 	struct device *dev;
 	struct device_node *dev_node;
-	struct property *iommus;
-	int iommus_len = 0;
 	const char *name_str;
 	int ret = 0;
 
@@ -1067,9 +1065,6 @@
 
 	parse_bitwidths(lwis_dev);
 
-	iommus = of_find_property(dev_node, "iommus", &iommus_len);
-	lwis_dev->has_iommu = iommus && iommus_len;
-
 	lwis_dev->bts_scenario_name = NULL;
 	of_property_read_string(dev_node, "bts-scenario", &lwis_dev->bts_scenario_name);
 
diff --git a/platform/anchorage/lwis_platform_anchorage.c b/platform/anchorage/lwis_platform_anchorage.c
index 0f6f26d..2eb8d9b 100644
--- a/platform/anchorage/lwis_platform_anchorage.c
+++ b/platform/anchorage/lwis_platform_anchorage.c
@@ -58,12 +58,24 @@
 
 static int lwis_iommu_fault_handler(struct iommu_fault *fault, void *param)
 {
+	int ret;
+	struct of_phandle_iterator it;
 	struct lwis_device *lwis_dev = (struct lwis_device *)param;
 	struct lwis_mem_page_fault_event_payload event_payload;
 
 	pr_err("############ LWIS IOMMU PAGE FAULT ############\n");
 	pr_err("\n");
-	pr_err("Device: %s IOMMU Page Fault at Address: 0x%px Flag: 0x%08x\n", lwis_dev->name,
+	of_for_each_phandle (&it, ret, lwis_dev->plat_dev->dev.of_node, "iommus", 0, 0) {
+		u64 iommus_reg;
+		const char *port_name = NULL;
+		struct device_node *iommus_info = of_node_get(it.node);
+		of_property_read_u64(iommus_info, "reg", &iommus_reg);
+		of_property_read_string(iommus_info, "port-name", &port_name);
+		pr_info("Device [%s] registered IOMMUS :[%s] %#010llx.sysmmu\n", lwis_dev->name,
+			port_name, iommus_reg);
+		pr_err("\n");
+	}
+	pr_err("IOMMU Page Fault at Address: 0x%px Flag: 0x%08x. Check dmesg for sysmmu errors\n",
 	       (void *)fault->event.addr, fault->event.flags);
 	pr_err("\n");
 	lwis_debug_print_transaction_info(lwis_dev);
@@ -89,6 +101,7 @@
 int lwis_platform_device_enable(struct lwis_device *lwis_dev)
 {
 	int ret;
+	int iommus_len = 0;
 	struct lwis_platform *platform;
 
 	const int core_clock_qos = 67000;
@@ -110,7 +123,8 @@
 		return ret;
 	}
 
-	if (lwis_dev->has_iommu) {
+	if (of_find_property(lwis_dev->plat_dev->dev.of_node, "iommus", &iommus_len) &&
+	    iommus_len) {
 		/* Activate IOMMU for the platform device */
 		ret = iommu_register_device_fault_handler(&lwis_dev->plat_dev->dev,
 							  lwis_iommu_fault_handler, lwis_dev);
@@ -162,6 +176,7 @@
 
 int lwis_platform_device_disable(struct lwis_device *lwis_dev)
 {
+	int iommus_len = 0;
 	struct lwis_platform *platform;
 
 	if (!lwis_dev) {
@@ -182,7 +197,8 @@
 
 	lwis_platform_remove_qos(lwis_dev);
 
-	if (lwis_dev->has_iommu) {
+	if (of_find_property(lwis_dev->plat_dev->dev.of_node, "iommus", &iommus_len) &&
+	    iommus_len) {
 		/* Deactivate IOMMU */
 		iommu_unregister_device_fault_handler(&lwis_dev->plat_dev->dev);
 	}
diff --git a/platform/busan/lwis_platform_busan.c b/platform/busan/lwis_platform_busan.c
index daf888e..b9fe7c0 100644
--- a/platform/busan/lwis_platform_busan.c
+++ b/platform/busan/lwis_platform_busan.c
@@ -55,12 +55,24 @@
 
 static int lwis_iommu_fault_handler(struct iommu_fault *fault, void *param)
 {
+	int ret;
+	struct of_phandle_iterator it;
 	struct lwis_device *lwis_dev = (struct lwis_device *)param;
 	struct lwis_mem_page_fault_event_payload event_payload;
 
 	pr_err("############ LWIS IOMMU PAGE FAULT ############\n");
 	pr_err("\n");
-	pr_err("Device: %s IOMMU Page Fault at Address: 0x%px Flag: 0x%08x\n", lwis_dev->name,
+	of_for_each_phandle (&it, ret, lwis_dev->plat_dev->dev.of_node, "iommus", 0, 0) {
+		u64 iommus_reg;
+		const char *port_name = NULL;
+		struct device_node *iommus_info = of_node_get(it.node);
+		of_property_read_u64(iommus_info, "reg", &iommus_reg);
+		of_property_read_string(iommus_info, "port-name", &port_name);
+		pr_info("Device [%s] registered IOMMUS :[%s] %#010llx.sysmmu\n", lwis_dev->name,
+			port_name, iommus_reg);
+		pr_err("\n");
+	}
+	pr_err("IOMMU Page Fault at Address: 0x%px Flag: 0x%08x. Check dmesg for sysmmu errors\n",
 	       (void *)fault->event.addr, fault->event.flags);
 	pr_err("\n");
 	lwis_debug_print_transaction_info(lwis_dev);
@@ -86,6 +98,7 @@
 int lwis_platform_device_enable(struct lwis_device *lwis_dev)
 {
 	int ret;
+	int iommus_len = 0;
 	struct lwis_platform *platform;
 
 	const int core_clock_qos = 67000;
@@ -107,7 +120,8 @@
 		return ret;
 	}
 
-	if (lwis_dev->has_iommu) {
+	if (of_find_property(lwis_dev->plat_dev->dev.of_node, "iommus", &iommus_len) &&
+	    iommus_len) {
 		/* Activate IOMMU for the platform device */
 		ret = iommu_register_device_fault_handler(&lwis_dev->plat_dev->dev,
 							  lwis_iommu_fault_handler, lwis_dev);
@@ -159,6 +173,7 @@
 
 int lwis_platform_device_disable(struct lwis_device *lwis_dev)
 {
+	int iommus_len = 0;
 	struct lwis_platform *platform;
 
 	if (!lwis_dev) {
@@ -179,7 +194,8 @@
 
 	lwis_platform_remove_qos(lwis_dev);
 
-	if (lwis_dev->has_iommu) {
+	if (of_find_property(lwis_dev->plat_dev->dev.of_node, "iommus", &iommus_len) &&
+	    iommus_len) {
 		/* Deactivate IOMMU */
 		iommu_unregister_device_fault_handler(&lwis_dev->plat_dev->dev);
 	}