summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/s3c2440
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2017-03-15 01:51:54 -0400
committerMichael Sevakis <jethead71@rockbox.org>2017-10-26 14:35:41 -0400
commit1654efc31339972d0e6bd41a499fcffc0a45822e (patch)
tree5fb7f59ab918a3694608bb1138c2c52fb47698c3 /firmware/target/arm/s3c2440
parent7807934a271e9eb7b045cdcd89ba70fb59a91d69 (diff)
downloadrockbox-1654efc31339972d0e6bd41a499fcffc0a45822e.tar.gz
rockbox-1654efc31339972d0e6bd41a499fcffc0a45822e.tar.bz2
rockbox-1654efc31339972d0e6bd41a499fcffc0a45822e.zip
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
Diffstat (limited to 'firmware/target/arm/s3c2440')
-rw-r--r--firmware/target/arm/s3c2440/gigabeat-fx/ata-target.h4
-rw-r--r--firmware/target/arm/s3c2440/sd-s3c2440.c100
2 files changed, 35 insertions, 69 deletions
diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/ata-target.h b/firmware/target/arm/s3c2440/gigabeat-fx/ata-target.h
index 7ca7d77c4f..5403b2418a 100644
--- a/firmware/target/arm/s3c2440/gigabeat-fx/ata-target.h
+++ b/firmware/target/arm/s3c2440/gigabeat-fx/ata-target.h
@@ -21,10 +21,6 @@
#ifndef ATA_TARGET_H
#define ATA_TARGET_H
-#ifdef BOOTLOADER
-#define ATA_DRIVER_CLOSE
-#endif
-
/* Plain C read & write loops */
#define PREFER_C_READING
#define PREFER_C_WRITING
diff --git a/firmware/target/arm/s3c2440/sd-s3c2440.c b/firmware/target/arm/s3c2440/sd-s3c2440.c
index e8de3ac78d..2ff68aa4ee 100644
--- a/firmware/target/arm/s3c2440/sd-s3c2440.c
+++ b/firmware/target/arm/s3c2440/sd-s3c2440.c
@@ -21,11 +21,9 @@
//#define SD_DEBUG
-#include "sd.h"
#include "system.h"
#include <string.h>
#include "gcc_extensions.h"
-#include "thread.h"
#include "panic.h"
#ifdef SD_DEBUG
@@ -33,8 +31,8 @@
#endif
#ifdef HAVE_HOTSWAP
#include "sdmmc.h"
-#include "disk.h"
#endif
+#include "storage.h"
#include "dma-target.h"
#include "system-target.h"
#include "led-mini2440.h"
@@ -90,6 +88,12 @@ struct sd_card_status
/* for compatibility */
static long last_disk_activity = -1;
+#ifdef CONFIG_STORAGE_MULTI
+static int sd_first_drive = 0;
+#else
+#define sd_first_drive 0
+#endif
+
static bool initialized = false;
static bool sd_enabled = false;
static long next_yield = 0;
@@ -109,11 +113,7 @@ static struct sd_card_status sd_status[NUM_CARDS] =
#endif
#endif
-/* Shoot for around 75% usage */
-static long sd_stack [(DEFAULT_STACK_SIZE*2 + 0x1c0)/sizeof(long)];
-static const char sd_thread_name[] = "sd";
static struct mutex sd_mtx SHAREDBSS_ATTR;
-static struct event_queue sd_queue;
static struct semaphore transfer_completion_signal;
static volatile unsigned int transfer_error[NUM_DRIVES];
/* align on cache line size */
@@ -511,17 +511,13 @@ static inline bool card_detect_target(void)
static int sd1_oneshot_callback(struct timeout *tmo)
{
- (void)tmo;
-
/* This is called only if the state was stable for 300ms - check state
* and post appropriate event. */
- if (card_detect_target())
- {
- queue_broadcast(SYS_HOTSWAP_INSERTED, 0);
- }
- else
- queue_broadcast(SYS_HOTSWAP_EXTRACTED, 0);
+ queue_broadcast(card_detect_target() ? SYS_HOTSWAP_INSERTED :
+ SYS_HOTSWAP_EXTRACTED,
+ sd_first_drive + CARD_NUM_SLOT);
return 0;
+ (void)tmo;
}
void EINT8_23(void)
@@ -571,46 +567,6 @@ bool sd_removable(IF_MD_NONVOID(int card_no))
#endif /* HAVE_HOTSWAP */
/*****************************************************************************/
-static void sd_thread(void) NORETURN_ATTR;
-static void sd_thread(void)
-{
- struct queue_event ev;
-
- /* TODO */
- while (1)
- {
- queue_wait_w_tmo(&sd_queue, &ev, HZ);
- switch ( ev.id )
- {
-#ifdef HAVE_HOTSWAP
- case SYS_HOTSWAP_INSERTED:
- case SYS_HOTSWAP_EXTRACTED:;
- int success = 1;
-
- disk_unmount(0); /* release "by force" */
-
- mutex_lock(&sd_mtx); /* lock-out card activity */
-
- /* Force card init for new card, re-init for re-inserted one or
- * clear if the last attempt to init failed with an error. */
- card_info[0].initialized = 0;
-
- /* Access is now safe */
- mutex_unlock(&sd_mtx);
-
- if (ev.id == SYS_HOTSWAP_INSERTED)
- success = disk_mount(0); /* 0 if fail */
-
- /* notify the system about the changed filesystems
- */
- if (success)
- queue_broadcast(SYS_FS_CHANGED, 0);
- break;
-#endif /* HAVE_HOTSWAP */
- }
- }
-}
-
static int sd_wait_for_state(const int card_no, unsigned int state)
{
unsigned long response = 0;
@@ -907,9 +863,6 @@ int sd_init(void)
semaphore_init(&transfer_completion_signal, 1, 0);
/* init mutex */
mutex_init(&sd_mtx);
- queue_init(&sd_queue, true);
- create_thread(sd_thread, sd_stack, sizeof(sd_stack), 0,
- sd_thread_name IF_PRIO(, PRIORITY_USER_INTERFACE) IF_COP(, CPU));
uncached_buffer = UNCACHED_ADDR(&aligned_buffer[0]);
@@ -950,18 +903,11 @@ tCardInfo *card_get_info_target(int card_no)
int sd_num_drives(int first_drive)
{
dbgprintf ("sd_num_drv");
-#if 0
/* Store which logical drive number(s) we have been assigned */
sd_first_drive = first_drive;
-#endif
-
return NUM_CARDS;
}
-void sd_sleepnow(void)
-{
-}
-
bool sd_disk_is_active(void)
{
return false;
@@ -980,3 +926,27 @@ int sd_spinup_time(void)
#endif /* CONFIG_STORAGE_MULTI */
/*****************************************************************************/
+int sd_event(long id, intptr_t data)
+{
+ int rc = 0;
+
+ switch (id)
+ {
+#ifdef HAVE_HOTSWAP
+ case SYS_HOTSWAP_INSERTED:
+ case SYS_HOTSWAP_EXTRACTED:
+ mutex_lock(&sd_mtx);
+ /* Force card init for new card, re-init for re-inserted one or
+ * clear if the last attempt to init failed with an error. */
+ card_info[data].initialized = 0;
+ mutex_unlock(&sd_mtx);
+ break;
+#endif /* HAVE_HOTSWAP */
+ default:
+ rc = storage_event_default_handler(id, data, last_disk_activity,
+ STORAGE_SD);
+ break;
+ }
+
+ return rc;
+}