ui: implement timers with waitsets
[petitboot] / ui / common / ps3.c
index 5c83289ec254c4716fa706995b41a55b45f6f1d2..c62a10d20dffc4f5f8eee107ac42ffa04c549d0a 100644 (file)
@@ -49,6 +49,11 @@ static const struct os_area_db_id id_flags =
        .owner = OS_AREA_DB_OWNER_PETITBOOT, /* 3 */
        .key = 3,
 };
+static const struct os_area_db_id id_timeout =
+{
+       .owner = OS_AREA_DB_OWNER_PETITBOOT, /* 3 */
+       .key = 4,
+};
 
 struct ps3_flash_ctx {
        FILE *dev;
@@ -59,6 +64,8 @@ struct ps3_flash_ctx {
 
 static void ps3_flash_close(struct ps3_flash_ctx *fc)
 {
+       assert(fc->dev);
+
        fclose(fc->dev);
        fc->dev = NULL;
 }
@@ -80,7 +87,7 @@ static int ps3_flash_open(struct ps3_flash_ctx *fc, const char *mode)
        result = os_area_fixed_read(&fc->header, &fc->params, fc->dev);
 
        if (result) {
-               pb_log("%s: os_area_fixed_read failed: %s\n", __func__);
+               pb_log("%s: os_area_fixed_read failed\n", __func__);
                goto fail;
        }
 
@@ -104,15 +111,15 @@ int ps3_flash_get_values(struct ps3_flash_values *values)
        struct ps3_flash_ctx fc;
        uint64_t tmp;
 
-       memset(values, 0, sizeof(*values));
-
        result = ps3_flash_open(&fc, "r");
 
        if (result)
-               return -1;
+               goto fail;
 
        result = os_area_db_read(&fc.db, &fc.header, fc.dev);
 
+       ps3_flash_close(&fc);
+
        if (result) {
                pb_log("%s: os_area_db_read failed: %s\n", __func__,
                        strerror(errno));
@@ -124,21 +131,24 @@ int ps3_flash_get_values(struct ps3_flash_values *values)
        if (!result)
                values->default_item = (uint32_t)tmp;
 
-       sum += result = os_area_db_get(&fc.db, &id_video_mode, &tmp);
+       result = os_area_db_get(&fc.db, &id_timeout, &tmp);
 
        if (!result)
-               values->video_mode = (uint16_t)tmp;
+               values->timeout = (uint8_t)tmp;
 
+       sum += result = os_area_db_get(&fc.db, &id_video_mode, &tmp);
 
-       pb_log("%s: default_item: %u\n", __func__, values->default_item);
-       pb_log("%s: video_mode:   %u\n", __func__, values->video_mode);
-
-       ps3_flash_close(&fc);
-       return !!sum;
+       if (!result)
+               values->video_mode = (uint16_t)tmp;
 
+       pb_log("%s: default_item: %x\n", __func__,
+               (unsigned int)values->default_item);
+       pb_log("%s: timeout: %u\n", __func__,
+               (unsigned int)values->timeout);
+       pb_log("%s: video_mode:   %u\n", __func__,
+               (unsigned int)values->video_mode);
 fail:
-       ps3_flash_close(&fc);
-       return -1;
+       return (result || sum) ? -1 : 0;
 }
 
 /**
@@ -177,6 +187,8 @@ int ps3_flash_set_values(const struct ps3_flash_values *values)
                }
        }
 
+       /* timeout is currently read-only, set with ps3-bl-option */
+
        result = os_area_db_set_32(&fc.db, &id_default_item,
                values->default_item);
        result += os_area_db_set_16(&fc.db, &id_video_mode,