firmware: arm_scmi: Convert events registration to protocol handles
authorCristian Marussi <cristian.marussi@arm.com>
Tue, 16 Mar 2021 12:48:32 +0000 (12:48 +0000)
committerSudeep Holla <sudeep.holla@arm.com>
Mon, 29 Mar 2021 09:00:35 +0000 (10:00 +0100)
Convert all refactored events registration routines to use protocol
handles.

In order to maintain bisectability and to allow protocols and drivers
to be later ported to the new protocol handle interface one by one,
introduce here also some transient code that will be removed later
in order to ease such transition.

Link: https://lore.kernel.org/r/20210316124903.35011-8-cristian.marussi@arm.com
Tested-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
drivers/firmware/arm_scmi/base.c
drivers/firmware/arm_scmi/driver.c
drivers/firmware/arm_scmi/notify.c
drivers/firmware/arm_scmi/notify.h
drivers/firmware/arm_scmi/perf.c
drivers/firmware/arm_scmi/power.c
drivers/firmware/arm_scmi/reset.c
drivers/firmware/arm_scmi/sensors.c
drivers/firmware/arm_scmi/system.c

index 34c8a29ede0c3efc3aead44ea36522e5e3298d3d..6a5cdef197d008aa9310c9c6229d7773e416f184 100644 (file)
@@ -262,7 +262,7 @@ static int scmi_base_error_notify(const struct scmi_handle *handle, bool enable)
        return ret;
 }
 
-static int scmi_base_set_notify_enabled(const struct scmi_handle *handle,
+static int scmi_base_set_notify_enabled(const void *handle,
                                        u8 evt_id, u32 src_id, bool enable)
 {
        int ret;
@@ -274,7 +274,7 @@ static int scmi_base_set_notify_enabled(const struct scmi_handle *handle,
        return ret;
 }
 
-static void *scmi_base_fill_custom_report(const struct scmi_handle *handle,
+static void *scmi_base_fill_custom_report(const void *handle,
                                          u8 evt_id, ktime_t timestamp,
                                          const void *payld, size_t payld_sz,
                                          void *report, u32 *src_id)
index 2357b93732ae482fc6f689ae5e1ea36d2e1a4b95..568b3f963e1542a7a5562a36e161339b2f7cc6b2 100644 (file)
@@ -641,6 +641,7 @@ scmi_alloc_init_protocol_instance(struct scmi_info *info,
         */
        if (pi->proto->events) {
                ret = scmi_register_protocol_events(handle, pi->proto->id,
+                                                   &pi->ph,
                                                    pi->proto->events);
                if (ret)
                        dev_warn(handle->dev,
index cbb2b004eb607f9c4109cc8f583b94820216c86c..023c93deb14bdb3708596bcbc143506a034885ac 100644 (file)
 #define REVT_NOTIFY_SET_STATUS(revt, eid, sid, state)          \
 ({                                                             \
        typeof(revt) r = revt;                                  \
-       r->proto->ops->set_notify_enabled(r->proto->ni->handle, \
+       r->proto->ops->set_notify_enabled(r->proto->ph,         \
                                        (eid), (sid), (state)); \
 })
 
 #define REVT_FILL_REPORT(revt, ...)                            \
 ({                                                             \
        typeof(revt) r = revt;                                  \
-       r->proto->ops->fill_custom_report(r->proto->ni->handle, \
+       r->proto->ops->fill_custom_report(r->proto->ph,         \
                                          __VA_ARGS__);         \
 })
 
@@ -279,6 +279,7 @@ struct scmi_registered_event;
  *                    events' descriptors, whose fixed-size is determined at
  *                    compile time.
  * @registered_mtx: A mutex to protect @registered_events_handlers
+ * @ph: SCMI protocol handle reference
  * @registered_events_handlers: An hashtable containing all events' handlers
  *                             descriptors registered for this protocol
  *
@@ -303,6 +304,7 @@ struct scmi_registered_events_desc {
        struct scmi_registered_event    **registered_events;
        /* mutex to protect registered_events_handlers */
        struct mutex                    registered_mtx;
+       const struct scmi_protocol_handle       *ph;
        DECLARE_HASHTABLE(registered_events_handlers, SCMI_REGISTERED_HASH_SZ);
 };
 
@@ -735,6 +737,7 @@ scmi_allocate_registered_events_desc(struct scmi_notify_instance *ni,
  * @handle: The handle identifying the platform instance against which the
  *         protocol's events are registered
  * @proto_id: Protocol ID
+ * @ph: SCMI protocol handle.
  * @ee: A structure describing the events supported by this protocol.
  *
  * Used by SCMI Protocols initialization code to register with the notification
@@ -745,6 +748,7 @@ scmi_allocate_registered_events_desc(struct scmi_notify_instance *ni,
  * Return: 0 on Success
  */
 int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,
+                                 const struct scmi_protocol_handle *ph,
                                  const struct scmi_protocol_events *ee)
 {
        int i;
@@ -754,7 +758,7 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,
        struct scmi_notify_instance *ni;
        const struct scmi_event *evt;
 
-       if (!ee || !ee->ops || !ee->evts ||
+       if (!ee || !ee->ops || !ee->evts || !ph ||
            (!ee->num_sources && !ee->ops->get_num_sources))
                return -EINVAL;
 
@@ -768,7 +772,7 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,
        if (ee->num_sources) {
                num_sources = ee->num_sources;
        } else {
-               int nsrc = ee->ops->get_num_sources(handle);
+               int nsrc = ee->ops->get_num_sources(ph);
 
                if (nsrc <= 0)
                        return -EINVAL;
@@ -786,6 +790,7 @@ int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,
        if (IS_ERR(pd))
                return PTR_ERR(pd);
 
+       pd->ph = ph;
        for (i = 0; i < ee->num_events; i++, evt++) {
                struct scmi_registered_event *r_evt;
 
index 03500ca9cf560677bcd72c46f3a29ce40c7a529e..97c0e3dd973b43ff40deb2c691c234a501d8e53c 100644 (file)
@@ -50,10 +50,10 @@ struct scmi_protocol_handle;
  *         process context.
  */
 struct scmi_event_ops {
-       int (*get_num_sources)(const struct scmi_handle *handle);
-       int (*set_notify_enabled)(const struct scmi_handle *handle,
+       int (*get_num_sources)(const void *handle);
+       int (*set_notify_enabled)(const void *handle,
                                  u8 evt_id, u32 src_id, bool enabled);
-       void *(*fill_custom_report)(const struct scmi_handle *handle,
+       void *(*fill_custom_report)(const void *handle,
                                    u8 evt_id, ktime_t timestamp,
                                    const void *payld, size_t payld_sz,
                                    void *report, u32 *src_id);
@@ -82,6 +82,7 @@ void scmi_notification_exit(struct scmi_handle *handle);
 
 struct scmi_protocol_handle;
 int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,
+                                 const struct scmi_protocol_handle *ph,
                                  const struct scmi_protocol_events *ee);
 void scmi_deregister_protocol_events(const struct scmi_handle *handle,
                                     u8 proto_id);
index 80af823af8ec0e43029073ba145e34074b13deb4..6e37a6ebfcd85821a005fe6e9628c77c3836561f 100644 (file)
@@ -772,7 +772,7 @@ static const struct scmi_perf_ops perf_ops = {
        .power_scale_mw_get = scmi_power_scale_mw_get,
 };
 
-static int scmi_perf_set_notify_enabled(const struct scmi_handle *handle,
+static int scmi_perf_set_notify_enabled(const void *handle,
                                        u8 evt_id, u32 src_id, bool enable)
 {
        int ret, cmd_id;
@@ -789,7 +789,7 @@ static int scmi_perf_set_notify_enabled(const struct scmi_handle *handle,
        return ret;
 }
 
-static void *scmi_perf_fill_custom_report(const struct scmi_handle *handle,
+static void *scmi_perf_fill_custom_report(const void *handle,
                                          u8 evt_id, ktime_t timestamp,
                                          const void *payld, size_t payld_sz,
                                          void *report, u32 *src_id)
@@ -837,9 +837,10 @@ static void *scmi_perf_fill_custom_report(const struct scmi_handle *handle,
        return rep;
 }
 
-static int scmi_perf_get_num_sources(const struct scmi_handle *handle)
+static int scmi_perf_get_num_sources(const void *handle)
 {
-       struct scmi_perf_info *pi = handle->perf_priv;
+       struct scmi_perf_info *pi =
+               ((const struct scmi_handle *)(handle))->perf_priv;
 
        if (!pi)
                return -EINVAL;
index 1cfd10dc18a5a866230c089782de9f41eedf61f6..5f43c45ebc13181b008dd419264de658a2a8511e 100644 (file)
@@ -213,7 +213,7 @@ static int scmi_power_request_notify(const struct scmi_handle *handle,
        return ret;
 }
 
-static int scmi_power_set_notify_enabled(const struct scmi_handle *handle,
+static int scmi_power_set_notify_enabled(const void *handle,
                                         u8 evt_id, u32 src_id, bool enable)
 {
        int ret;
@@ -226,7 +226,7 @@ static int scmi_power_set_notify_enabled(const struct scmi_handle *handle,
        return ret;
 }
 
-static void *scmi_power_fill_custom_report(const struct scmi_handle *handle,
+static void *scmi_power_fill_custom_report(const void *handle,
                                           u8 evt_id, ktime_t timestamp,
                                           const void *payld, size_t payld_sz,
                                           void *report, u32 *src_id)
@@ -246,9 +246,10 @@ static void *scmi_power_fill_custom_report(const struct scmi_handle *handle,
        return r;
 }
 
-static int scmi_power_get_num_sources(const struct scmi_handle *handle)
+static int scmi_power_get_num_sources(const void *handle)
 {
-       struct scmi_power_info *pinfo = handle->power_priv;
+       struct scmi_power_info *pinfo =
+               ((const struct scmi_handle *)(handle))->power_priv;
 
        if (!pinfo)
                return -EINVAL;
index 06fecf044153dce2078de52a78f0c3f66943b3d2..572dc1fdcede5d4a50c88856f4f801865d1be73a 100644 (file)
@@ -224,7 +224,7 @@ static int scmi_reset_notify(const struct scmi_handle *handle, u32 domain_id,
        return ret;
 }
 
-static int scmi_reset_set_notify_enabled(const struct scmi_handle *handle,
+static int scmi_reset_set_notify_enabled(const void *handle,
                                         u8 evt_id, u32 src_id, bool enable)
 {
        int ret;
@@ -237,7 +237,7 @@ static int scmi_reset_set_notify_enabled(const struct scmi_handle *handle,
        return ret;
 }
 
-static void *scmi_reset_fill_custom_report(const struct scmi_handle *handle,
+static void *scmi_reset_fill_custom_report(const void *handle,
                                           u8 evt_id, ktime_t timestamp,
                                           const void *payld, size_t payld_sz,
                                           void *report, u32 *src_id)
@@ -257,9 +257,10 @@ static void *scmi_reset_fill_custom_report(const struct scmi_handle *handle,
        return r;
 }
 
-static int scmi_reset_get_num_sources(const struct scmi_handle *handle)
+static int scmi_reset_get_num_sources(const void *handle)
 {
-       struct scmi_reset_info *pinfo = handle->reset_priv;
+       struct scmi_reset_info *pinfo =
+               ((const struct scmi_handle *)(handle))->reset_priv;
 
        if (!pinfo)
                return -EINVAL;
index 03b7a274ee80fb9f262f0ee6d624fea851b9a8d6..e40e49869a5d8cde2efe8085517af53e8abf151a 100644 (file)
@@ -835,7 +835,7 @@ static const struct scmi_sensor_ops sensor_ops = {
        .config_set = scmi_sensor_config_set,
 };
 
-static int scmi_sensor_set_notify_enabled(const struct scmi_handle *handle,
+static int scmi_sensor_set_notify_enabled(const void *handle,
                                          u8 evt_id, u32 src_id, bool enable)
 {
        int ret;
@@ -860,7 +860,7 @@ static int scmi_sensor_set_notify_enabled(const struct scmi_handle *handle,
        return ret;
 }
 
-static void *scmi_sensor_fill_custom_report(const struct scmi_handle *handle,
+static void *scmi_sensor_fill_custom_report(const void *handle,
                                            u8 evt_id, ktime_t timestamp,
                                            const void *payld, size_t payld_sz,
                                            void *report, u32 *src_id)
@@ -890,7 +890,8 @@ static void *scmi_sensor_fill_custom_report(const struct scmi_handle *handle,
                struct scmi_sensor_info *s;
                const struct scmi_sensor_update_notify_payld *p = payld;
                struct scmi_sensor_update_report *r = report;
-               struct sensors_info *sinfo = handle->sensor_priv;
+               struct sensors_info *sinfo =
+                       ((const struct scmi_handle *)(handle))->sensor_priv;
 
                /* payld_sz is variable for this event */
                r->sensor_id = le32_to_cpu(p->sensor_id);
@@ -920,9 +921,10 @@ static void *scmi_sensor_fill_custom_report(const struct scmi_handle *handle,
        return rep;
 }
 
-static int scmi_sensor_get_num_sources(const struct scmi_handle *handle)
+static int scmi_sensor_get_num_sources(const void *handle)
 {
-       struct sensors_info *si = handle->sensor_priv;
+       struct sensors_info *si =
+               ((const struct scmi_handle *)(handle))->sensor_priv;
 
        return si->num_sensors;
 }
index e1ee6327f76106779d46f7e6faedf63c38ea56d2..9d016dff4be525984e20e0cda72fa7737b9194fc 100644 (file)
@@ -53,7 +53,7 @@ static int scmi_system_request_notify(const struct scmi_handle *handle,
        return ret;
 }
 
-static int scmi_system_set_notify_enabled(const struct scmi_handle *handle,
+static int scmi_system_set_notify_enabled(const void *handle,
                                          u8 evt_id, u32 src_id, bool enable)
 {
        int ret;
@@ -65,7 +65,7 @@ static int scmi_system_set_notify_enabled(const struct scmi_handle *handle,
        return ret;
 }
 
-static void *scmi_system_fill_custom_report(const struct scmi_handle *handle,
+static void *scmi_system_fill_custom_report(const void *handle,
                                            u8 evt_id, ktime_t timestamp,
                                            const void *payld, size_t payld_sz,
                                            void *report, u32 *src_id)