refactor(mediatek): add new LPM API for further extension
Add new LPM API `mt_lp_rm_find_constraint` and `mt_lp_rm_run_constraint`
for further extension.
Change-Id: I8298811e03227285a7d086166edf9e87471f74b4
diff --git a/plat/mediatek/common/lpm/mt_lp_rm.c b/plat/mediatek/common/lpm/mt_lp_rm.c
index 9f64cbd..9f07968 100644
--- a/plat/mediatek/common/lpm/mt_lp_rm.c
+++ b/plat/mediatek/common/lpm/mt_lp_rm.c
@@ -36,12 +36,11 @@
return MT_RM_STATUS_OK;
}
-int mt_lp_rm_reset_constraint(int idx, unsigned int cpuid, int stateid)
+int mt_lp_rm_reset_constraint(unsigned int idx, unsigned int cpuid, int stateid)
{
struct mt_resource_constraint const *rc = NULL;
- if ((plat_mt_rm.plat_rm == NULL) || (idx < 0) ||
- (idx >= plat_mt_rm.count)) {
+ if ((plat_mt_rm.plat_rm == NULL) || (idx >= plat_mt_rm.count)) {
return MT_RM_STATUS_BAD;
}
@@ -77,14 +76,33 @@
return res;
}
-int mt_lp_rm_find_and_run_constraint(int idx, unsigned int cpuid,
- int stateid, void *priv)
+int mt_lp_rm_do_constraint(unsigned int constraint_id, unsigned int cpuid, int stateid)
{
- int i, res = MT_RM_STATUS_BAD;
+ int res = MT_RM_STATUS_BAD;
+ struct mt_resource_constraint const *rc;
+ struct mt_resource_manager *rm = plat_mt_rm.plat_rm;
+
+ if ((rm == NULL) || (constraint_id >= plat_mt_rm.count)) {
+ return res;
+ }
+
+ rc = rm->consts[constraint_id];
+ if ((rc != NULL) && (rc->run != NULL)) {
+ res = rc->run(cpuid, stateid);
+ }
+
+ return res;
+}
+
+int mt_lp_rm_find_constraint(unsigned int idx, unsigned int cpuid,
+ int stateid, void *priv)
+{
+ unsigned int i;
+ int res = MT_RM_STATUS_BAD;
struct mt_resource_constraint *const *rc;
struct mt_resource_manager *rm = plat_mt_rm.plat_rm;
- if ((rm == NULL) || (idx < 0) || (idx >= plat_mt_rm.count)) {
+ if ((rm == NULL) || (idx >= plat_mt_rm.count)) {
return res;
}
@@ -92,24 +110,35 @@
if (rm->update != NULL) {
res = rm->update(rm->consts, plat_mt_rm.count, stateid, priv);
if (res != 0) {
- return res;
+ return MT_RM_STATUS_BAD;
}
}
+ res = MT_RM_STATUS_BAD;
for (i = idx, rc = (rm->consts + idx); *rc != NULL; i++, rc++) {
if (((*rc)->is_valid != NULL) &&
((*rc)->is_valid(cpuid, stateid))) {
- if (((*rc)->run != NULL) &&
- ((*rc)->run(cpuid, stateid) == 0)) {
- res = i;
- break;
- }
+ res = i;
+ break;
}
}
return res;
}
+int mt_lp_rm_find_and_run_constraint(unsigned int idx, unsigned int cpuid,
+ int stateid, void *priv)
+{
+ int res = MT_RM_STATUS_BAD;
+
+ res = mt_lp_rm_find_constraint(idx, cpuid, stateid, priv);
+ if (res != MT_RM_STATUS_BAD) {
+ mt_lp_rm_do_constraint(res, cpuid, stateid);
+ }
+
+ return res;
+}
+
int mt_lp_rm_do_update(int stateid, int type, void const *p)
{
int res = MT_RM_STATUS_BAD;
diff --git a/plat/mediatek/include/lpm/mt_lp_rm.h b/plat/mediatek/include/lpm/mt_lp_rm.h
index ce7e520..bf99489 100644
--- a/plat/mediatek/include/lpm/mt_lp_rm.h
+++ b/plat/mediatek/include/lpm/mt_lp_rm.h
@@ -55,10 +55,12 @@
};
extern int mt_lp_rm_register(struct mt_resource_manager *rm);
-extern int mt_lp_rm_find_and_run_constraint(int idx, unsigned int cpuid,
+extern int mt_lp_rm_do_constraint(unsigned int constraint_id, unsigned int cpuid, int stateid);
+extern int mt_lp_rm_find_constraint(unsigned int idx, unsigned int cpuid,
+ int stateid, void *priv);
+extern int mt_lp_rm_find_and_run_constraint(unsigned int idx, unsigned int cpuid,
int stateid, void *priv);
-extern int mt_lp_rm_reset_constraint(int constraint_id, unsigned int cpuid,
- int stateid);
+extern int mt_lp_rm_reset_constraint(unsigned int idx, unsigned int cpuid, int stateid);
extern int mt_lp_rm_do_update(int stateid, int type, void const *p);
extern int mt_lp_rm_get_status(unsigned int type, void *priv);