diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2017-03-15 01:51:54 -0400 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2017-10-26 14:35:41 -0400 |
commit | 1654efc31339972d0e6bd41a499fcffc0a45822e (patch) | |
tree | 5fb7f59ab918a3694608bb1138c2c52fb47698c3 /firmware/target/arm/s3c2440/sd-s3c2440.c | |
parent | 7807934a271e9eb7b045cdcd89ba70fb59a91d69 (diff) | |
download | rockbox-1654efc31339972d0e6bd41a499fcffc0a45822e.tar.gz 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/sd-s3c2440.c')
-rw-r--r-- | firmware/target/arm/s3c2440/sd-s3c2440.c | 100 |
1 files changed, 35 insertions, 65 deletions
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 @@ | |||
21 | 21 | ||
22 | //#define SD_DEBUG | 22 | //#define SD_DEBUG |
23 | 23 | ||
24 | #include "sd.h" | ||
25 | #include "system.h" | 24 | #include "system.h" |
26 | #include <string.h> | 25 | #include <string.h> |
27 | #include "gcc_extensions.h" | 26 | #include "gcc_extensions.h" |
28 | #include "thread.h" | ||
29 | #include "panic.h" | 27 | #include "panic.h" |
30 | 28 | ||
31 | #ifdef SD_DEBUG | 29 | #ifdef SD_DEBUG |
@@ -33,8 +31,8 @@ | |||
33 | #endif | 31 | #endif |
34 | #ifdef HAVE_HOTSWAP | 32 | #ifdef HAVE_HOTSWAP |
35 | #include "sdmmc.h" | 33 | #include "sdmmc.h" |
36 | #include "disk.h" | ||
37 | #endif | 34 | #endif |
35 | #include "storage.h" | ||
38 | #include "dma-target.h" | 36 | #include "dma-target.h" |
39 | #include "system-target.h" | 37 | #include "system-target.h" |
40 | #include "led-mini2440.h" | 38 | #include "led-mini2440.h" |
@@ -90,6 +88,12 @@ struct sd_card_status | |||
90 | /* for compatibility */ | 88 | /* for compatibility */ |
91 | static long last_disk_activity = -1; | 89 | static long last_disk_activity = -1; |
92 | 90 | ||
91 | #ifdef CONFIG_STORAGE_MULTI | ||
92 | static int sd_first_drive = 0; | ||
93 | #else | ||
94 | #define sd_first_drive 0 | ||
95 | #endif | ||
96 | |||
93 | static bool initialized = false; | 97 | static bool initialized = false; |
94 | static bool sd_enabled = false; | 98 | static bool sd_enabled = false; |
95 | static long next_yield = 0; | 99 | static long next_yield = 0; |
@@ -109,11 +113,7 @@ static struct sd_card_status sd_status[NUM_CARDS] = | |||
109 | #endif | 113 | #endif |
110 | #endif | 114 | #endif |
111 | 115 | ||
112 | /* Shoot for around 75% usage */ | ||
113 | static long sd_stack [(DEFAULT_STACK_SIZE*2 + 0x1c0)/sizeof(long)]; | ||
114 | static const char sd_thread_name[] = "sd"; | ||
115 | static struct mutex sd_mtx SHAREDBSS_ATTR; | 116 | static struct mutex sd_mtx SHAREDBSS_ATTR; |
116 | static struct event_queue sd_queue; | ||
117 | static struct semaphore transfer_completion_signal; | 117 | static struct semaphore transfer_completion_signal; |
118 | static volatile unsigned int transfer_error[NUM_DRIVES]; | 118 | static volatile unsigned int transfer_error[NUM_DRIVES]; |
119 | /* align on cache line size */ | 119 | /* align on cache line size */ |
@@ -511,17 +511,13 @@ static inline bool card_detect_target(void) | |||
511 | 511 | ||
512 | static int sd1_oneshot_callback(struct timeout *tmo) | 512 | static int sd1_oneshot_callback(struct timeout *tmo) |
513 | { | 513 | { |
514 | (void)tmo; | ||
515 | |||
516 | /* This is called only if the state was stable for 300ms - check state | 514 | /* This is called only if the state was stable for 300ms - check state |
517 | * and post appropriate event. */ | 515 | * and post appropriate event. */ |
518 | if (card_detect_target()) | 516 | queue_broadcast(card_detect_target() ? SYS_HOTSWAP_INSERTED : |
519 | { | 517 | SYS_HOTSWAP_EXTRACTED, |
520 | queue_broadcast(SYS_HOTSWAP_INSERTED, 0); | 518 | sd_first_drive + CARD_NUM_SLOT); |
521 | } | ||
522 | else | ||
523 | queue_broadcast(SYS_HOTSWAP_EXTRACTED, 0); | ||
524 | return 0; | 519 | return 0; |
520 | (void)tmo; | ||
525 | } | 521 | } |
526 | 522 | ||
527 | void EINT8_23(void) | 523 | void EINT8_23(void) |
@@ -571,46 +567,6 @@ bool sd_removable(IF_MD_NONVOID(int card_no)) | |||
571 | #endif /* HAVE_HOTSWAP */ | 567 | #endif /* HAVE_HOTSWAP */ |
572 | /*****************************************************************************/ | 568 | /*****************************************************************************/ |
573 | 569 | ||
574 | static void sd_thread(void) NORETURN_ATTR; | ||
575 | static void sd_thread(void) | ||
576 | { | ||
577 | struct queue_event ev; | ||
578 | |||
579 | /* TODO */ | ||
580 | while (1) | ||
581 | { | ||
582 | queue_wait_w_tmo(&sd_queue, &ev, HZ); | ||
583 | switch ( ev.id ) | ||
584 | { | ||
585 | #ifdef HAVE_HOTSWAP | ||
586 | case SYS_HOTSWAP_INSERTED: | ||
587 | case SYS_HOTSWAP_EXTRACTED:; | ||
588 | int success = 1; | ||
589 | |||
590 | disk_unmount(0); /* release "by force" */ | ||
591 | |||
592 | mutex_lock(&sd_mtx); /* lock-out card activity */ | ||
593 | |||
594 | /* Force card init for new card, re-init for re-inserted one or | ||
595 | * clear if the last attempt to init failed with an error. */ | ||
596 | card_info[0].initialized = 0; | ||
597 | |||
598 | /* Access is now safe */ | ||
599 | mutex_unlock(&sd_mtx); | ||
600 | |||
601 | if (ev.id == SYS_HOTSWAP_INSERTED) | ||
602 | success = disk_mount(0); /* 0 if fail */ | ||
603 | |||
604 | /* notify the system about the changed filesystems | ||
605 | */ | ||
606 | if (success) | ||
607 | queue_broadcast(SYS_FS_CHANGED, 0); | ||
608 | break; | ||
609 | #endif /* HAVE_HOTSWAP */ | ||
610 | } | ||
611 | } | ||
612 | } | ||
613 | |||
614 | static int sd_wait_for_state(const int card_no, unsigned int state) | 570 | static int sd_wait_for_state(const int card_no, unsigned int state) |
615 | { | 571 | { |
616 | unsigned long response = 0; | 572 | unsigned long response = 0; |
@@ -907,9 +863,6 @@ int sd_init(void) | |||
907 | semaphore_init(&transfer_completion_signal, 1, 0); | 863 | semaphore_init(&transfer_completion_signal, 1, 0); |
908 | /* init mutex */ | 864 | /* init mutex */ |
909 | mutex_init(&sd_mtx); | 865 | mutex_init(&sd_mtx); |
910 | queue_init(&sd_queue, true); | ||
911 | create_thread(sd_thread, sd_stack, sizeof(sd_stack), 0, | ||
912 | sd_thread_name IF_PRIO(, PRIORITY_USER_INTERFACE) IF_COP(, CPU)); | ||
913 | 866 | ||
914 | uncached_buffer = UNCACHED_ADDR(&aligned_buffer[0]); | 867 | uncached_buffer = UNCACHED_ADDR(&aligned_buffer[0]); |
915 | 868 | ||
@@ -950,18 +903,11 @@ tCardInfo *card_get_info_target(int card_no) | |||
950 | int sd_num_drives(int first_drive) | 903 | int sd_num_drives(int first_drive) |
951 | { | 904 | { |
952 | dbgprintf ("sd_num_drv"); | 905 | dbgprintf ("sd_num_drv"); |
953 | #if 0 | ||
954 | /* Store which logical drive number(s) we have been assigned */ | 906 | /* Store which logical drive number(s) we have been assigned */ |
955 | sd_first_drive = first_drive; | 907 | sd_first_drive = first_drive; |
956 | #endif | ||
957 | |||
958 | return NUM_CARDS; | 908 | return NUM_CARDS; |
959 | } | 909 | } |
960 | 910 | ||
961 | void sd_sleepnow(void) | ||
962 | { | ||
963 | } | ||
964 | |||
965 | bool sd_disk_is_active(void) | 911 | bool sd_disk_is_active(void) |
966 | { | 912 | { |
967 | return false; | 913 | return false; |
@@ -980,3 +926,27 @@ int sd_spinup_time(void) | |||
980 | #endif /* CONFIG_STORAGE_MULTI */ | 926 | #endif /* CONFIG_STORAGE_MULTI */ |
981 | /*****************************************************************************/ | 927 | /*****************************************************************************/ |
982 | 928 | ||
929 | int sd_event(long id, intptr_t data) | ||
930 | { | ||
931 | int rc = 0; | ||
932 | |||
933 | switch (id) | ||
934 | { | ||
935 | #ifdef HAVE_HOTSWAP | ||
936 | case SYS_HOTSWAP_INSERTED: | ||
937 | case SYS_HOTSWAP_EXTRACTED: | ||
938 | mutex_lock(&sd_mtx); | ||
939 | /* Force card init for new card, re-init for re-inserted one or | ||
940 | * clear if the last attempt to init failed with an error. */ | ||
941 | card_info[data].initialized = 0; | ||
942 | mutex_unlock(&sd_mtx); | ||
943 | break; | ||
944 | #endif /* HAVE_HOTSWAP */ | ||
945 | default: | ||
946 | rc = storage_event_default_handler(id, data, last_disk_activity, | ||
947 | STORAGE_SD); | ||
948 | break; | ||
949 | } | ||
950 | |||
951 | return rc; | ||
952 | } | ||