firmware: arm_scmi: Move handle get/set helpers
authorCristian Marussi <cristian.marussi@arm.com>
Thu, 22 Dec 2022 18:50:46 +0000 (18:50 +0000)
committerSudeep Holla <sudeep.holla@arm.com>
Thu, 19 Jan 2023 09:49:34 +0000 (09:49 +0000)
Move handle get/set helpers definitions into driver.c and invoke them
through the bus notifier helper.

Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Link: https://lore.kernel.org/r/20221222185049.737625-7-cristian.marussi@arm.com
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
drivers/firmware/arm_scmi/bus.c
drivers/firmware/arm_scmi/common.h
drivers/firmware/arm_scmi/driver.c

index e63cc1194d43c284843b78033eb7ad89b70af611..61113def5a9ae558b906bed820a6081bf139a506 100644 (file)
@@ -344,27 +344,10 @@ put_dev:
 void scmi_device_destroy(struct scmi_device *scmi_dev)
 {
        kfree_const(scmi_dev->name);
-       scmi_handle_put(scmi_dev->handle);
        ida_free(&scmi_bus_id, scmi_dev->id);
        device_unregister(&scmi_dev->dev);
 }
 
-void scmi_device_link_add(struct device *consumer, struct device *supplier)
-{
-       struct device_link *link;
-
-       link = device_link_add(consumer, supplier, DL_FLAG_AUTOREMOVE_CONSUMER);
-
-       WARN_ON(!link);
-}
-
-void scmi_set_handle(struct scmi_device *scmi_dev)
-{
-       scmi_dev->handle = scmi_handle_get(&scmi_dev->dev);
-       if (scmi_dev->handle)
-               scmi_device_link_add(&scmi_dev->dev, scmi_dev->handle->dev);
-}
-
 static int __scmi_devices_unregister(struct device *dev, void *data)
 {
        struct scmi_device *scmi_dev = to_scmi_dev(dev);
index 0f411679df7ecfdf9fe5424b6d7c190f13a0c2ef..07d34954c060de51857c73f5c6eb13e516708988 100644 (file)
@@ -96,10 +96,6 @@ static inline void unpack_scmi_header(u32 msg_hdr, struct scmi_msg_hdr *hdr)
 
 struct scmi_revision_info *
 scmi_revision_area_get(const struct scmi_protocol_handle *ph);
-int scmi_handle_put(const struct scmi_handle *handle);
-void scmi_device_link_add(struct device *consumer, struct device *supplier);
-struct scmi_handle *scmi_handle_get(struct device *dev);
-void scmi_set_handle(struct scmi_device *scmi_dev);
 void scmi_setup_protocol_implemented(const struct scmi_protocol_handle *ph,
                                     u8 *prot_imp);
 
index 73f640e9448f7f4fb46319bb83ce4f9a30ddfc4a..8591b2c740c65e992e30ee81c419057a85d949f6 100644 (file)
@@ -1890,13 +1890,6 @@ static bool scmi_is_transport_atomic(const struct scmi_handle *handle,
        return ret;
 }
 
-static inline
-struct scmi_handle *scmi_handle_get_from_info_unlocked(struct scmi_info *info)
-{
-       info->users++;
-       return &info->handle;
-}
-
 /**
  * scmi_handle_get() - Get the SCMI handle for a device
  *
@@ -1908,7 +1901,7 @@ struct scmi_handle *scmi_handle_get_from_info_unlocked(struct scmi_info *info)
  *
  * Return: pointer to handle if successful, NULL on error
  */
-struct scmi_handle *scmi_handle_get(struct device *dev)
+static struct scmi_handle *scmi_handle_get(struct device *dev)
 {
        struct list_head *p;
        struct scmi_info *info;
@@ -1918,7 +1911,8 @@ struct scmi_handle *scmi_handle_get(struct device *dev)
        list_for_each(p, &scmi_list) {
                info = list_entry(p, struct scmi_info, node);
                if (dev->parent == info->dev) {
-                       handle = scmi_handle_get_from_info_unlocked(info);
+                       info->users++;
+                       handle = &info->handle;
                        break;
                }
        }
@@ -1939,7 +1933,7 @@ struct scmi_handle *scmi_handle_get(struct device *dev)
  * Return: 0 is successfully released
  *     if null was passed, it returns -EINVAL;
  */
-int scmi_handle_put(const struct scmi_handle *handle)
+static int scmi_handle_put(const struct scmi_handle *handle)
 {
        struct scmi_info *info;
 
@@ -1955,6 +1949,23 @@ int scmi_handle_put(const struct scmi_handle *handle)
        return 0;
 }
 
+static void scmi_device_link_add(struct device *consumer,
+                                struct device *supplier)
+{
+       struct device_link *link;
+
+       link = device_link_add(consumer, supplier, DL_FLAG_AUTOREMOVE_CONSUMER);
+
+       WARN_ON(!link);
+}
+
+static void scmi_set_handle(struct scmi_device *scmi_dev)
+{
+       scmi_dev->handle = scmi_handle_get(&scmi_dev->dev);
+       if (scmi_dev->handle)
+               scmi_device_link_add(&scmi_dev->dev, scmi_dev->handle->dev);
+}
+
 static int __scmi_xfer_info_init(struct scmi_info *sinfo,
                                 struct scmi_xfers_info *info)
 {
@@ -2234,8 +2245,12 @@ static int scmi_bus_notifier(struct notifier_block *nb,
 
        switch (action) {
        case BUS_NOTIFY_BIND_DRIVER:
+               /* setup handle now as the transport is ready */
+               scmi_set_handle(sdev);
                break;
        case BUS_NOTIFY_UNBOUND_DRIVER:
+               scmi_handle_put(sdev->handle);
+               sdev->handle = NULL;
                break;
        default:
                return NOTIFY_DONE;