From patchwork Wed Jul 8 00:11:47 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 29556 Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id D9D19B709F for ; Wed, 8 Jul 2009 10:21:14 +1000 (EST) Received: by ozlabs.org (Postfix) id 65352DE76A; Wed, 8 Jul 2009 10:19:53 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 63872DE3D7 for ; Wed, 8 Jul 2009 10:19:53 +1000 (EST) X-Original-To: cbe-oss-dev@ozlabs.org Delivered-To: cbe-oss-dev@ozlabs.org Received: from hera.kernel.org (hera.kernel.org [140.211.167.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EE5B0DDEDB; Wed, 8 Jul 2009 10:18:16 +1000 (EST) Received: from hera.kernel.org (IDENT:U2FsdGVkX1+bdMcENRMb41uQzldHmIsbleQ1Ohxz7lY@localhost [127.0.0.1]) by hera.kernel.org (8.14.2/8.14.2) with ESMTP id n680I91K026597 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 8 Jul 2009 00:18:09 GMT Received: (from geoff@localhost) by hera.kernel.org (8.14.2/8.13.1/Submit) id n680I8AW026596; Wed, 8 Jul 2009 00:18:08 GMT Message-Id: <20090708001135.811474099@am.sony.com> User-Agent: quilt/0.47-1 Date: Tue, 07 Jul 2009 17:11:47 -0700 From: Geoff Levand To: Jeremy Kerr In-Reply-To: <20090708001134.934244536@am.sony.com> References: <20090708001134.934244536@am.sony.com> Content-Disposition: inline; filename=ps3-timer.diff X-Virus-Scanned: ClamAV 0.93.3/9541/Tue Jul 7 17:31:53 2009 on hera.kernel.org X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on hera.kernel.org X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0 (hera.kernel.org [127.0.0.1]); Wed, 08 Jul 2009 00:18:11 +0000 (UTC) Cc: cbe-oss-dev@ozlabs.org Subject: [Cbe-oss-dev] [patch 13/31] petitboot: Add PS3 countdown timer X-BeenThere: cbe-oss-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Discussion about Open Source Software for the Cell Broadband Engine List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Add countdown timer support to the PS3 UI programs. Signed-off-by: Geoff Levand --- ui/common/ps3.c | 43 +++++++++++++++++++++++++++++++------------ ui/common/ps3.h | 6 ++++++ ui/ncurses/ps3-cui.c | 32 +++++++++++++++++++++++++++++--- 3 files changed, 66 insertions(+), 15 deletions(-) --- a/ui/common/ps3.c +++ b/ui/common/ps3.c @@ -49,6 +49,11 @@ static const struct os_area_db_id id_fla .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; } @@ -104,19 +111,25 @@ int ps3_flash_get_values(struct ps3_flas struct ps3_flash_ctx fc; uint64_t tmp; - memset(values, 0, sizeof(*values)); + /* Set default values. */ + + values->default_item = 0; + values->timeout = ps3_timeout_forever; + values->video_mode = 1; result = ps3_flash_open(&fc, "r"); if (result) - return -1; + goto done; 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)); - goto fail; + goto done; } sum = result = os_area_db_get(&fc.db, &id_default_item, &tmp); @@ -124,21 +137,25 @@ int ps3_flash_get_values(struct ps3_flas 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); + if (!result) + values->video_mode = (uint16_t)tmp; - ps3_flash_close(&fc); - return !!sum; +done: + 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 +194,8 @@ int ps3_flash_set_values(const struct ps } } + /* 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, --- a/ui/common/ps3.h +++ b/ui/common/ps3.h @@ -33,9 +33,14 @@ enum ps3_flash_flags { ps3_flag_telnet = 1, }; +enum ps3_timeouts { + ps3_timeout_forever = 255, +}; + /** * struct ps3_flash_values - Values from PS3 flash memory. * @default_item: The default menu item. + * @timeout: The timeout in seconds. * @video_mode: The default video_mode. * @flags: Logical OR of enum ps3_flash_flags. */ @@ -44,6 +49,7 @@ struct ps3_flash_values { uint32_t default_item; uint16_t video_mode; /* uint16_t flags; */ + uint8_t timeout; }; int ps3_flash_get_values(struct ps3_flash_values *values); --- a/ui/ncurses/ps3-cui.c +++ b/ui/ncurses/ps3-cui.c @@ -21,9 +21,7 @@ /* * TODO * removable media event - * resize after video mode change * ncurses mouse support - * timeout */ #if defined(HAVE_CONFIG_H) @@ -36,6 +34,7 @@ #include #include #include +#include #include "log/log.h" #include "talloc/talloc.h" @@ -283,6 +282,21 @@ static int ps3_hot_key(struct pmenu __at } /** + * ps3_timer_update - Timer callback. + */ + +static void ps3_timer_update(struct ui_timer *timer, unsigned int timeout) +{ + struct ps3_cui *ps3 = ps3_from_cui(cui_from_timer(timer)); + + //FIXME: make scr:timer. + // nc_scr_timer_update(&ps3.mm->scr, timeout); + + nc_scr_status_printf(&ps3->mm->scr, + "Welcome to Petitboot (timeout %u sec)", timeout); +} + +/** * ps3_mm_init - Setup the main menu instance. */ @@ -434,6 +448,10 @@ static void sig_handler(int signum) DBGS("%d\n", signum); switch (signum) { + case SIGALRM: + if (ps3.cui) + ui_timer_sigalrm(&ps3.cui->timer); + break; case SIGWINCH: if (ps3.cui) cui_resize(ps3.cui); @@ -491,8 +509,9 @@ int main(int argc, char *argv[]) pb_log("--- pb-cui ---\n"); sa.sa_handler = sig_handler; - result = sigaction(SIGINT, &sa, NULL); + result = sigaction(SIGALRM, &sa, NULL); result += sigaction(SIGHUP, &sa, NULL); + result += sigaction(SIGINT, &sa, NULL); result += sigaction(SIGTERM, &sa, NULL); result += sigaction(SIGWINCH, &sa, NULL); @@ -523,6 +542,13 @@ int main(int argc, char *argv[]) ps3.mm = ps3_mm_init(&ps3); ps3.svm = ps3_svm_init(&ps3); + if (ps3.values.timeout == ps3_timeout_forever) + ui_timer_disable(&ps3.cui->timer); + else { + ps3.cui->timer.update_display = ps3_timer_update; + ui_timer_init(&ps3.cui->timer, ps3.values.timeout); + } + cui_result = cui_run(ps3.cui, ps3.mm, ps3.values.default_item); pmenu_delete(ps3.mm);