summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/ata.c28
-rw-r--r--firmware/drivers/ata.h10
2 files changed, 32 insertions, 6 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c
index ebe9602f01..0795eaf1f8 100644
--- a/firmware/drivers/ata.c
+++ b/firmware/drivers/ata.c
@@ -89,6 +89,9 @@ static char ata_stack[DEFAULT_STACK_SIZE];
89static char ata_thread_name[] = "ata"; 89static char ata_thread_name[] = "ata";
90static struct event_queue ata_queue; 90static struct event_queue ata_queue;
91static bool initialized = false; 91static bool initialized = false;
92static bool delayed_write = false;
93static unsigned char delayed_sector[SECTOR_SIZE];
94static int delayed_sector_num;
92 95
93#ifdef USE_POWEROFF 96#ifdef USE_POWEROFF
94static int ata_power_on(void); 97static int ata_power_on(void);
@@ -215,6 +218,10 @@ int ata_read_sectors(unsigned long start,
215 ret = -1; 218 ret = -1;
216 219
217 mutex_unlock(&ata_mtx); 220 mutex_unlock(&ata_mtx);
221
222 if ( delayed_write )
223 ata_flush();
224
218 return ret; 225 return ret;
219} 226}
220 227
@@ -279,9 +286,30 @@ int ata_write_sectors(unsigned long start,
279 i = wait_for_end_of_transfer(); 286 i = wait_for_end_of_transfer();
280 287
281 mutex_unlock(&ata_mtx); 288 mutex_unlock(&ata_mtx);
289
290 if ( delayed_write )
291 ata_flush();
292
282 return i; 293 return i;
283} 294}
284 295
296extern void ata_delayed_write(unsigned long sector, void* buf)
297{
298 memcpy(delayed_sector, buf, SECTOR_SIZE);
299 delayed_sector_num = sector;
300 delayed_write = true;
301}
302
303extern void ata_flush(void)
304{
305 if ( delayed_write ) {
306 delayed_write = false;
307 ata_write_sectors(delayed_sector_num, 1, delayed_sector);
308 }
309}
310
311
312
285static int check_registers(void) 313static int check_registers(void)
286{ 314{
287 if ( ATA_STATUS & STATUS_BSY ) 315 if ( ATA_STATUS & STATUS_BSY )
diff --git a/firmware/drivers/ata.h b/firmware/drivers/ata.h
index 4209fdcd1e..244ec63777 100644
--- a/firmware/drivers/ata.h
+++ b/firmware/drivers/ata.h
@@ -39,11 +39,9 @@ extern bool ata_disk_is_active(void);
39extern int ata_hard_reset(void); 39extern int ata_hard_reset(void);
40extern int ata_soft_reset(void); 40extern int ata_soft_reset(void);
41extern int ata_init(void); 41extern int ata_init(void);
42extern int ata_read_sectors(unsigned long start, 42extern int ata_read_sectors(unsigned long start, int count, void* buf);
43 int count, 43extern int ata_write_sectors(unsigned long start, int count, void* buf);
44 void* buf); 44extern void ata_delayed_write(unsigned long sector, void* buf);
45extern int ata_write_sectors(unsigned long start, 45extern void ata_flush(void);
46 int count,
47 void* buf);
48 46
49#endif 47#endif