From 1654efc31339972d0e6bd41a499fcffc0a45822e Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Wed, 15 Mar 2017 01:51:54 -0400 Subject: Unify storage threads into one * Editing a bunch of drivers' thread routines in order to implement a new feature is tedious. * No matter the number of storage drivers, they share one thread. No extra threads needed for CONFIG_STORAGE_MULTI. * Each has an event callback called by the storage thread. * A default callback is provided to fake sleeping in order to trigger idle callbacks. It could also do other default processing. Changes to it will be part of driver code without editing each one. * Drivers may sleep and wake as they please as long as they give a low pulse on their storage bit to ask to go into sleep mode. Idle callback is called on its behalf and driver immediately put into sleep mode. * Drivers may indicate they are to continue receiving events in USB mode, otherwise they receve nothing until disconnect (they do receive SYS_USB_DISCONNECTED no matter what). * Rework a few things to keep the callback implementation sane and maintainable. ata.c was dreadful with all those bools; make it a state machine and easier to follow. Remove last_user_activity; it has no purpose that isn't served by keeping the disk active through last_disk_activity instead. * Even-out stack sizes partly because of a lack of a decent place to define them by driver or SoC or whatever; it doesn't seem too critical to do that anyway. Many are simply too large while at least one isn't really adequate. They may be individually overridden if necessary (figure out where). The thread uses the greatest size demanded. Newer file code is much more frugal with stack space. I barely see use crack 50% after idle callbacks (usually mid-40s). Card insert/eject doesn't demand much. * No forcing of idle callbacks. If it isn't necessary for one or more non-disk storage types, it really isn't any more necessary for disk storage. Besides, it makes the whole thing easier to implement. Change-Id: Id30c284d82a8af66e47f2cfe104c52cbd8aa7215 --- firmware/target/arm/s5l8700/ata-nand-s5l8700.c | 1 - .../target/arm/s5l8700/ipodnano2g/nand-nano2g.c | 76 ++++++++++++---------- 2 files changed, 41 insertions(+), 36 deletions(-) (limited to 'firmware/target/arm/s5l8700') diff --git a/firmware/target/arm/s5l8700/ata-nand-s5l8700.c b/firmware/target/arm/s5l8700/ata-nand-s5l8700.c index 227f6b703b..7f68b82a0d 100644 --- a/firmware/target/arm/s5l8700/ata-nand-s5l8700.c +++ b/firmware/target/arm/s5l8700/ata-nand-s5l8700.c @@ -52,7 +52,6 @@ void nand_spindown(int seconds) void nand_sleep(void) { - nand_power_down(); } void nand_sleepnow(void) diff --git a/firmware/target/arm/s5l8700/ipodnano2g/nand-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/nand-nano2g.c index 1698dc2b9b..4b74405c1c 100644 --- a/firmware/target/arm/s5l8700/ipodnano2g/nand-nano2g.c +++ b/firmware/target/arm/s5l8700/ipodnano2g/nand-nano2g.c @@ -31,8 +31,7 @@ #include #include #include "led.h" -#include "ata_idle_notify.h" - +#include "storage.h" #define NAND_CMD_READ 0x00 #define NAND_CMD_PROGCNFRM 0x10 @@ -91,7 +90,6 @@ static int nand_powered = 0; static int nand_interleaved = 0; static int nand_cached = 0; static long nand_last_activity_value = -1; -static long nand_stack[DEFAULT_STACK_SIZE]; static struct mutex nand_mtx; static struct semaphore nand_complete; @@ -359,20 +357,22 @@ void nand_power_up(void) void nand_power_down(void) { - if (!nand_powered) return; mutex_lock(&nand_mtx); - pmu_ldo_power_off(4); - PCON2 = 0x11111111; - PDAT2 = 0; - PCON3 = 0x11111111; - PDAT3 = 0; - PCON4 = 0x11111111; - PDAT4 = 0; - PCON5 = (PCON5 & ~0xF) | 1; - PUNK5 = 1; - PWRCONEXT |= 0x40; - PWRCON |= 0x100000; - nand_powered = 0; + if (nand_powered) + { + pmu_ldo_power_off(4); + PCON2 = 0x11111111; + PDAT2 = 0; + PCON3 = 0x11111111; + PDAT3 = 0; + PCON4 = 0x11111111; + PDAT4 = 0; + PCON5 = (PCON5 & ~0xF) | 1; + PUNK5 = 1; + PWRCONEXT |= 0x40; + PWRCON |= 0x100000; + nand_powered = 0; + } mutex_unlock(&nand_mtx); } @@ -714,20 +714,6 @@ const struct nand_device_info_type* nand_get_device_type(uint32_t bank) return &nand_deviceinfotable[nand_type[bank]]; } -static void nand_thread(void) -{ - while (1) - { - if (TIME_AFTER(current_tick, nand_last_activity_value + HZ / 5) - && nand_powered) - { - call_storage_idle_notifys(false); - nand_power_down(); - } - sleep(HZ / 10); - } -} - int nand_device_init(void) { mutex_init(&nand_mtx); @@ -776,10 +762,30 @@ int nand_device_init(void) nand_cached = ((nand_deviceinfotable[nand_type[0]].id >> 23) & 1); nand_last_activity_value = current_tick; - create_thread(nand_thread, nand_stack, - sizeof(nand_stack), 0, "nand" - IF_PRIO(, PRIORITY_USER_INTERFACE) - IF_COP(, CPU)); - return 0; } + +int nand_event(long id, intptr_t data) +{ + int rc = 0; + + if (LIKELY(id == Q_STORAGE_TICK)) + { + if (!nand_powered || + TIME_BEFORE(current_tick, nand_last_activity_value + HZ / 5)) + { + STG_EVENT_ASSERT_ACTIVE(STORAGE_NAND); + } + } + else if (id == Q_STORAGE_SLEEPNOW) + { + nand_power_down(); + } + else + { + rc = storage_event_default_handler(id, data, nand_last_activity_value, + STORAGE_NAND); + } + + return rc; +} -- cgit v1.2.3