The power module now operates on top of resource-driver.
New attribute:
- id: DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE
- type: SYSCOMMON_RESMAN_DATA_TYPE_UINT64_UINT64_UINT64_UINT64
- setter: O
- getter: X
It trigger power transition to set current power state.
Requires 4 parameter:
1. FROM state
Transition take place only from the 'FROM' state. If you
don't mind whatever the 'FROM' state is, use
DEVICED_POWER_STATE_ALL for the 'FROM' state.
2. TO state
Next state to transition
3. triggering reason
4. user_data
New attribute:
- id: DEVICED_POWER_ATTR_UINT64_CURRENT_STATE
- type: SYSCOMMON_RESMAN_DATA_TYPE_UINT64
- setter: X
- getter: O
It gets the current power state.
New attribute:
- id: DEVICED_POWER_ATTR_INT_WAKEUP_REASON
- type: SYSCOMMON_RESMAN_DATA_TYPE_INT
- setter: X
- getter: O
It gets wakeup reason of the latest system wakeup.
All enums and macros regarding power state have moved to libsyscommon,
syscommon-plugin-deviced-power-interface.h, so that those value can be
used by both the deviced core and plugin.
To match type of user_data from resource-manager, fix the existing
'void *' to 'const void *'.
Change-Id: I58af2a74ce2313a07b676e1a884b4201751a882c
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
static void action_transition(void);
static uint64_t get_next_state(void);
-static void pre_action_normal(void *data);
-static void pre_action_poweroff(void *data);
-static void (*const pre_action_state[DEVICED_POWER_STATE_MAX_INDEX]) (void *) = {
+static void pre_action_normal(const void *data);
+static void pre_action_poweroff(const void *data);
+static void (*const pre_action_state[DEVICED_POWER_STATE_MAX_INDEX]) (const void *) = {
[DEVICED_POWER_STATE_NORMAL_INDEX] = pre_action_normal,
[DEVICED_POWER_STATE_POWEROFF_INDEX] = pre_action_poweroff,
[DEVICED_POWER_STATE_REBOOT_INDEX] = pre_action_poweroff,
[DEVICED_POWER_STATE_EXIT_INDEX] = pre_action_poweroff,
};
-static void post_action_sleep(void *data);
-static void post_action_poweroff(void *data);
-static void (*const post_action_state[DEVICED_POWER_STATE_MAX_INDEX]) (void *) = {
+static void post_action_sleep(const void *data);
+static void post_action_poweroff(const void *data);
+static void (*const post_action_state[DEVICED_POWER_STATE_MAX_INDEX]) (const void *) = {
[DEVICED_POWER_STATE_SLEEP_INDEX] = post_action_sleep,
[DEVICED_POWER_STATE_POWEROFF_INDEX] = post_action_poweroff,
[DEVICED_POWER_STATE_REBOOT_INDEX] = post_action_poweroff,
return ++id;
}
-static void pre_action_normal(void *udata)
+static void pre_action_normal(const void *udata)
{
if (transition_context.ti.curr == DEVICED_POWER_STATE_SLEEP)
power_resume(transition_context.ti.reason);
}
-static void post_action_sleep(void *udata)
+static void post_action_sleep(const void *udata)
{
power_suspend(transition_context.ti.reason);
}
-static void pre_action_poweroff(void *data)
+static void pre_action_poweroff(const void *data)
{
// do not transition anymore after poweroff
syscommon_notifier_unsubscribe_notify(DEVICE_NOTIFIER_REQUEST_TRANSITION_STATE, transition_request_callback);
poweroff_prepare(current);
}
-static void post_action_poweroff(void *data)
+static void post_action_poweroff(const void *data)
{
poweroff_main((void *)(intptr_t) current);
}
#include <glib.h>
#include <libsyscommon/ini-parser.h>
+#include <system/syscommon-plugin-deviced-power-interface.h>
#include "shared/log-macro.h"
#include "shared/device-notifier.h"
-enum {
- DEVICED_POWER_STATE_MIN_INDEX,
- DEVICED_POWER_STATE_START_INDEX = DEVICED_POWER_STATE_MIN_INDEX,
- DEVICED_POWER_STATE_NORMAL_INDEX,
- DEVICED_POWER_STATE_SLEEP_INDEX,
- DEVICED_POWER_STATE_POWEROFF_INDEX,
- DEVICED_POWER_STATE_REBOOT_INDEX,
- DEVICED_POWER_STATE_EXIT_INDEX,
- DEVICED_POWER_STATE_MAX_INDEX,
-
- DEVICED_POWER_TRANSIENT_STATE_MIN_INDEX,
- DEVICED_POWER_TRANSIENT_STATE_RESUMING_EARLY_INDEX = DEVICED_POWER_TRANSIENT_STATE_MIN_INDEX,
- DEVICED_POWER_TRANSIENT_STATE_RESUMING_INDEX,
- DEVICED_POWER_TRANSIENT_STATE_RESUMING_LATE_INDEX,
- DEVICED_POWER_TRANSIENT_STATE_SUSPENDING_EARLY_INDEX,
- DEVICED_POWER_TRANSIENT_STATE_SUSPENDING_INDEX,
- DEVICED_POWER_TRANSIENT_STATE_SUSPENDING_LATE_INDEX,
- DEVICED_POWER_TRANSIENT_STATE_MAX_INDEX,
-};
-
-#define DEVICED_POWER_STATE_UNDEFINED (0)
-
-#define DEVICED_POWER_STATE_START (1ULL << DEVICED_POWER_STATE_START_INDEX)
-#define DEVICED_POWER_STATE_NORMAL (1ULL << DEVICED_POWER_STATE_NORMAL_INDEX)
-#define DEVICED_POWER_STATE_SLEEP (1ULL << DEVICED_POWER_STATE_SLEEP_INDEX)
-#define DEVICED_POWER_STATE_POWEROFF (1ULL << DEVICED_POWER_STATE_POWEROFF_INDEX)
-#define DEVICED_POWER_STATE_REBOOT (1ULL << DEVICED_POWER_STATE_REBOOT_INDEX)
-#define DEVICED_POWER_STATE_EXIT (1ULL << DEVICED_POWER_STATE_EXIT_INDEX)
-#define DEVICED_POWER_STATE_ALL ((1ULL << DEVICED_POWER_STATE_MAX_INDEX) - (1ULL << DEVICED_POWER_STATE_MIN_INDEX))
-
-#define DEVICED_POWER_TRANSIENT_STATE_SUSPENDING_EARLY (1ULL << DEVICED_POWER_TRANSIENT_STATE_SUSPENDING_EARLY_INDEX)
-#define DEVICED_POWER_TRANSIENT_STATE_SUSPENDING (1ULL << DEVICED_POWER_TRANSIENT_STATE_SUSPENDING_INDEX)
-#define DEVICED_POWER_TRANSIENT_STATE_SUSPENDING_LATE (1ULL << DEVICED_POWER_TRANSIENT_STATE_SUSPENDING_LATE_INDEX)
-#define DEVICED_POWER_TRANSIENT_STATE_RESUMING_EARLY (1ULL << DEVICED_POWER_TRANSIENT_STATE_RESUMING_EARLY_INDEX)
-#define DEVICED_POWER_TRANSIENT_STATE_RESUMING (1ULL << DEVICED_POWER_TRANSIENT_STATE_RESUMING_INDEX)
-#define DEVICED_POWER_TRANSIENT_STATE_RESUMING_LATE (1ULL << DEVICED_POWER_TRANSIENT_STATE_RESUMING_LATE_INDEX)
-
-#define DEVICED_POWER_STATE_INDEX(state) (__builtin_ctzll(state))
-
struct trans_info {
uint64_t curr;
uint64_t next;
int reason;
- void *data;
+ const void *data;
};
void power_state_manager_init(void *data);
return !!(state & (DEVICED_POWER_STATE_POWEROFF | DEVICED_POWER_STATE_REBOOT | DEVICED_POWER_STATE_EXIT));
}
-static inline void power_request_change_state_strict(uint64_t curr, uint64_t next, int reason, void *udata)
+static inline void power_request_change_state_strict(uint64_t curr, uint64_t next, int reason, const void *udata)
{
struct trans_info ti = { curr, next, reason, udata };
GList l = { &ti, NULL, NULL };
--- /dev/null
+/*
+ * deviced
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <stdio.h>
+#include <stdint.h>
+
+#include <libsyscommon/resource-manager.h>
+#include <libsyscommon/resource-type.h>
+#include <system/syscommon-plugin-deviced-power.h>
+#include <system/syscommon-plugin-deviced-power-interface.h>
+#include <system/syscommon-plugin-deviced-common-interface.h>
+
+#include "power.h"
+#include "power-suspend.h"
+
+static bool attr_always_supported(int resource_id, const struct syscommon_resman_resource_attribute *attr)
+{
+ return true;
+}
+
+static int set_current_state(int resource_id, const struct syscommon_resman_resource_attribute *attr,
+ const void *data1, const void *data2, const void *data3, const void *data4,
+ int count1, int count2, int count3, int count4)
+{
+ uint64_t curr;
+ uint64_t next;
+ int reason;
+ const void *user_data;
+
+ if (!data1 || !data2 || !data3)
+ return -EINVAL;
+
+ curr = *(uint64_t *) data1;
+ next = *(uint64_t *) data2;
+ reason = *(int *) data3;
+ user_data = data4;
+
+ power_request_change_state_strict(curr, next, reason, user_data);
+
+ return 0;
+}
+
+static int get_current_state(int resource_id,
+ const struct syscommon_resman_resource_attribute *attr, void *data)
+{
+ if (!data)
+ return -EINVAL;
+
+ *(int *) data = power_get_state();
+
+ return 0;
+}
+
+static int get_wakeup_reason(int resource_id,
+ const struct syscommon_resman_resource_attribute *attr, void *data)
+{
+ if (!data)
+ return -EINVAL;
+
+ *(int *) data = power_get_wakeup_reason();
+
+ return 0;
+}
+
+static const struct syscommon_resman_resource_attribute power_attrs[] = {
+ {
+ .name = "DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE",
+ .id = DEVICED_POWER_ATTR_SET_UINT64_4_CURRENT_STATE,
+ .type = SYSCOMMON_RESMAN_DATA_TYPE_UINT64_UINT64_UINT64_UINT64,
+ .flag = SYSCOMMON_RESMAN_RESOURCE_FLAG_PUBLIC,
+ .ops = {
+ .set_4_tuple = set_current_state,
+ .is_supported = attr_always_supported,
+ },
+ }, {
+ .name = "DEVICED_POWER_ATTR_UINT64_CURRENT_STATE",
+ .id = DEVICED_POWER_ATTR_UINT64_CURRENT_STATE,
+ .type = SYSCOMMON_RESMAN_DATA_TYPE_UINT64,
+ .flag = SYSCOMMON_RESMAN_RESOURCE_FLAG_PUBLIC,
+ .ops = {
+ .get = get_current_state,
+ .is_supported = attr_always_supported,
+ },
+ }, {
+ .name = "DEVICED_POWER_ATTR_INT_WAKEUP_REASON",
+ .id = DEVICED_POWER_ATTR_INT_WAKEUP_REASON,
+ .type = SYSCOMMON_RESMAN_DATA_TYPE_INT,
+ .flag = SYSCOMMON_RESMAN_RESOURCE_FLAG_PUBLIC,
+ .ops = {
+ .get = get_wakeup_reason,
+ .is_supported = attr_always_supported,
+ },
+ }
+};
+
+static const struct syscommon_resman_resource_driver deviced_power_driver = {
+ .name = "power",
+ .type = DEVICED_RESOURCE_TYPE_POWER,
+ .flag = SYSCOMMON_RESMAN_RESOURCE_DRIVER_FLAG_COUNT_ONLY_ONE,
+ .attrs = power_attrs,
+ .num_attrs = ARRAY_SIZE(power_attrs),
+};
+SYSCOMMON_RESMAN_RESOURCE_DRIVER_REGISTER(&deviced_power_driver);