Reduce mutex scope for NPU device IOCTL calls

Instead of locking the device mutex for all IOCTL calls to the NPU
device, the mutex will now only be locked for the calls that have
resources that must be protected from concurrent access. IOCTL calls
that only copy static data do not need to lock the mutex.

The same device mutex is used for all concurrent access protection in
the driver, including the mailbox handling, so removing unnecessary
locking decreases the need to wait for the mutex.

Change-Id: Ic606fe0e1db4aa2e3d4e579ada74418491546468
Signed-off-by: Mikael Olsson <mikael.olsson@arm.com>
diff --git a/kernel/ethosu_device.c b/kernel/ethosu_device.c
index b63d068..6866857 100644
--- a/kernel/ethosu_device.c
+++ b/kernel/ethosu_device.c
@@ -244,10 +244,6 @@
 	void __user *udata = (void __user *)arg;
 	int ret;
 
-	ret = device_lock_interruptible(dev);
-	if (ret)
-		return ret;
-
 	dev_info(dev, "Device ioctl. file=0x%pK, cmd=0x%x, arg=0x%lx",
 		 file, cmd, arg);
 
@@ -271,8 +267,16 @@
 		break;
 	}
 	case ETHOSU_IOCTL_PING: {
+		ret = device_lock_interruptible(dev);
+		if (ret)
+			return ret;
+
 		dev_info(dev, "Device ioctl: Send ping");
+
 		ret = ethosu_mailbox_ping(&edev->mailbox);
+
+		device_unlock(dev);
+
 		break;
 	}
 	case ETHOSU_IOCTL_BUFFER_CREATE: {
@@ -283,11 +287,18 @@
 			break;
 		}
 
+		ret = device_lock_interruptible(dev);
+		if (ret)
+			return ret;
+
 		dev_info(dev,
 			 "Device ioctl: Buffer create. capacity=%u",
 			 uapi.capacity);
 
 		ret = ethosu_buffer_create(dev, uapi.capacity);
+
+		device_unlock(dev);
+
 		break;
 	}
 	case ETHOSU_IOCTL_NETWORK_CREATE: {
@@ -298,11 +309,18 @@
 			break;
 		}
 
+		ret = device_lock_interruptible(dev);
+		if (ret)
+			return ret;
+
 		dev_info(dev,
 			 "Device ioctl: Network create. type=%u, fd/index=%u",
 			 uapi.type, uapi.fd);
 
 		ret = ethosu_network_create(dev, &edev->mailbox, &uapi);
+
+		device_unlock(dev);
+
 		break;
 	}
 	default: {
@@ -313,8 +331,6 @@
 	}
 	}
 
-	device_unlock(dev);
-
 	return ret;
 }