summaryrefslogtreecommitdiff
path: root/firmware/drivers/ata.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/ata.c')
-rw-r--r--firmware/drivers/ata.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c
index 6a1db22919..87dacc3ed0 100644
--- a/firmware/drivers/ata.c
+++ b/firmware/drivers/ata.c
@@ -71,6 +71,74 @@
71static struct thread_entry *ata_thread_p = NULL; 71static struct thread_entry *ata_thread_p = NULL;
72#endif 72#endif
73 73
74#if defined(MAX_PHYS_SECTOR_SIZE) && MEM == 64
75/* Hack - what's the deal with 5g? */
76struct ata_lock
77{
78 struct thread_entry *thread;
79 int count;
80 volatile unsigned char locked;
81 IF_COP( struct corelock cl; )
82};
83
84static void ata_lock_init(struct ata_lock *l)
85{
86 corelock_init(&l->cl);
87 l->locked = 0;
88 l->count = 0;
89 l->thread = NULL;
90}
91
92static void ata_lock_lock(struct ata_lock *l)
93{
94 struct thread_entry * const current = thread_get_current();
95
96 if (current == l->thread)
97 {
98 l->count++;
99 return;
100 }
101
102 corelock_lock(&l->cl);
103
104 IF_PRIO( current->skip_count = -1; )
105
106 while (l->locked != 0)
107 {
108 corelock_unlock(&l->cl);
109 switch_thread();
110 corelock_lock(&l->cl);
111 }
112
113 l->locked = 1;
114 l->thread = current;
115 corelock_unlock(&l->cl);
116}
117
118static void ata_lock_unlock(struct ata_lock *l)
119{
120 if (l->count > 0)
121 {
122 l->count--;
123 return;
124 }
125
126 corelock_lock(&l->cl);
127
128 IF_PRIO( l->thread->skip_count = 0; )
129
130 l->thread = NULL;
131 l->locked = 0;
132
133 corelock_unlock(&l->cl);
134}
135
136#define mutex ata_lock
137#define mutex_init ata_lock_init
138#define mutex_lock ata_lock_lock
139#define mutex_unlock ata_lock_unlock
140#endif /* MAX_PHYS_SECTOR_SIZE */
141
74static struct mutex ata_mtx SHAREDBSS_ATTR; 142static struct mutex ata_mtx SHAREDBSS_ATTR;
75int ata_device; /* device 0 (master) or 1 (slave) */ 143int ata_device; /* device 0 (master) or 1 (slave) */
76 144