From: ljsebald <ljs...@us...> - 2023-11-20 01:01:41
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 92a76c016c9d0c89e5f8613189ca6ba7bff1616e (commit) via b575f6f941b3b7b0be12e14b4b32673506954888 (commit) from f8644374d6beaf41365e30d185cb455f340c7014 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 92a76c016c9d0c89e5f8613189ca6ba7bff1616e Merge: f864437 b575f6f Author: Lawrence Sebald <ljs...@us...> Date: Sun Nov 19 19:59:02 2023 -0500 Merge pull request #375 from DC-SWAT/g1_ata_select Fixed ATA device selection and mutex. commit b575f6f941b3b7b0be12e14b4b32673506954888 Author: DC-SWAT <sw...@21...> Date: Sun Nov 19 17:18:17 2023 +0700 Fixed ATA device selection and mutex. ----------------------------------------------------------------------- Summary of changes: kernel/arch/dreamcast/hardware/cdrom.c | 69 +++++++--------------------------- kernel/arch/dreamcast/hardware/g1ata.c | 5 +++ 2 files changed, 18 insertions(+), 56 deletions(-) diff --git a/kernel/arch/dreamcast/hardware/cdrom.c b/kernel/arch/dreamcast/hardware/cdrom.c index c0ad6a9..870c5fe 100644 --- a/kernel/arch/dreamcast/hardware/cdrom.c +++ b/kernel/arch/dreamcast/hardware/cdrom.c @@ -125,7 +125,7 @@ static int gdc_check_pio_transfer(int f, int *size) { #endif /* The G1 ATA access mutex */ -mutex_t _g1_ata_mutex = RECURSIVE_MUTEX_INITIALIZER; +mutex_t _g1_ata_mutex = MUTEX_INITIALIZER; /* Shortcut to cdrom_reinit_ex. Typically this is the only thing changed. */ int cdrom_set_sector_size(int size) { @@ -146,9 +146,6 @@ int cdrom_exec_cmd(int cmd, void *param) { assert(cmd > 0 && cmd < CMD_MAX); mutex_lock(&_g1_ata_mutex); - /* Make sure to select the GD-ROM drive. */ - g1_ata_select_device(G1_ATA_MASTER); - /* Submit the command */ for(n = 0; n < 10; ++n) { f = gdc_req_cmd(cmd, param); @@ -197,8 +194,8 @@ int cdrom_exec_cmd(int cmd, void *param) { /* Return the status of the drive as two integers (see constants) */ int cdrom_get_status(int *status, int *disc_type) { - int rv = ERR_OK; - uint32 params[2]; + int rv = ERR_OK; + uint32_t params[2]; /* We might be called in an interrupt to check for ISO cache flushing, so make sure we're not interrupting something @@ -212,9 +209,6 @@ int cdrom_get_status(int *status, int *disc_type) { mutex_lock(&_g1_ata_mutex); } - /* Make sure to select the GD-ROM drive. */ - g1_ata_select_device(G1_ATA_MASTER); - rv = gdc_get_drv_stat(params); mutex_unlock(&_g1_ata_mutex); @@ -244,10 +238,9 @@ int cdrom_change_dataype(int sector_part, int cdxa, int sector_size) { /* Wrapper for the change datatype syscall */ int cdrom_change_datatype(int sector_part, int cdxa, int sector_size) { int rv = ERR_OK; - uint32 params[4]; + uint32_t params[4]; mutex_lock(&_g1_ata_mutex); - g1_ata_select_device(G1_ATA_MASTER); /* Check if we are using default params */ if(sector_size == 2352) { @@ -292,26 +285,16 @@ int cdrom_reinit_ex(int sector_part, int cdxa, int sector_size) { int r = -1; int timeout; - mutex_lock(&_g1_ata_mutex); - /* Try a few times; it might be busy. If it's still busy after this loop then it's probably really dead. */ timeout = 10 * 1000 / 20; /* 10 second timeout */ - /* Make sure to select the GD-ROM drive. */ - g1_ata_select_device(G1_ATA_MASTER); - while(timeout > 0) { r = cdrom_exec_cmd(CMD_INIT, NULL); if(r == 0) break; - if(r == ERR_NO_DISC) { - mutex_unlock(&_g1_ata_mutex); - return r; - } - else if(r == ERR_SYS) { - mutex_unlock(&_g1_ata_mutex); + if(r == ERR_NO_DISC || r == ERR_SYS) { return r; } @@ -321,6 +304,7 @@ int cdrom_reinit_ex(int sector_part, int cdxa, int sector_size) { } if(timeout <= 0) { + mutex_lock(&_g1_ata_mutex); /* Send an abort since we're giving up waiting for the init */ gdc_abort_cmd(CMD_INIT); mutex_unlock(&_g1_ata_mutex); @@ -328,7 +312,6 @@ int cdrom_reinit_ex(int sector_part, int cdxa, int sector_size) { } r = cdrom_change_datatype(sector_part, cdxa, sector_size); - mutex_unlock(&_g1_ata_mutex); return r; } @@ -337,17 +320,14 @@ int cdrom_reinit_ex(int sector_part, int cdxa, int sector_size) { int cdrom_read_toc(CDROM_TOC *toc_buffer, int session) { struct { int session; - void *buffer; + void *buffer; } params; int rv; params.session = session; params.buffer = toc_buffer; - mutex_lock(&_g1_ata_mutex); - rv = cdrom_exec_cmd(CMD_GETTOC2, ¶ms); - mutex_unlock(&_g1_ata_mutex); return rv; } @@ -356,17 +336,15 @@ int cdrom_read_toc(CDROM_TOC *toc_buffer, int session) { int cdrom_read_sectors_ex(void *buffer, int sector, int cnt, int mode) { struct { int sec, num; - void *buffer; - int dunno; + void *buffer; + int is_test; } params; int rv = ERR_OK; params.sec = sector; /* Starting sector */ params.num = cnt; /* Number of sectors */ params.buffer = buffer; /* Output buffer */ - params.dunno = 0; /* ? */ - - mutex_lock(&_g1_ata_mutex); + params.is_test = 0; /* Enable test mode */ /* The DMA mode blocks the thread it is called in by the way we execute gd syscalls. It does however allow for other threads to run. */ @@ -378,7 +356,6 @@ int cdrom_read_sectors_ex(void *buffer, int sector, int cnt, int mode) { else if(mode == CDROM_READ_PIO) rv = cdrom_exec_cmd(CMD_PIOREAD, ¶ms); - mutex_unlock(&_g1_ata_mutex); return rv; } @@ -397,16 +374,14 @@ int cdrom_get_subcode(void *buffer, int buflen, int which) { struct { int which; int buflen; - void *buffer; + void *buffer; } params; int rv; params.which = which; params.buflen = buflen; params.buffer = buffer; - mutex_lock(&_g1_ata_mutex); rv = cdrom_exec_cmd(CMD_GETSCD, ¶ms); - mutex_unlock(&_g1_ata_mutex); return rv; } @@ -451,48 +426,32 @@ int cdrom_cdda_play(uint32 start, uint32 end, uint32 repeat, int mode) { params.end = end; params.repeat = repeat; - mutex_lock(&_g1_ata_mutex); - if(mode == CDDA_TRACKS) rv = cdrom_exec_cmd(CMD_PLAY, ¶ms); else if(mode == CDDA_SECTORS) rv = cdrom_exec_cmd(CMD_PLAY2, ¶ms); - mutex_unlock(&_g1_ata_mutex); - return rv; } /* Pause CDDA audio playback */ int cdrom_cdda_pause(void) { int rv; - - mutex_lock(&_g1_ata_mutex); rv = cdrom_exec_cmd(CMD_PAUSE, NULL); - mutex_unlock(&_g1_ata_mutex); - return rv; } /* Resume CDDA audio playback */ int cdrom_cdda_resume(void) { int rv; - - mutex_lock(&_g1_ata_mutex); rv = cdrom_exec_cmd(CMD_RELEASE, NULL); - mutex_unlock(&_g1_ata_mutex); - return rv; } /* Spin down the CD */ int cdrom_spin_down(void) { int rv; - - mutex_lock(&_g1_ata_mutex); rv = cdrom_exec_cmd(CMD_STOP, NULL); - mutex_unlock(&_g1_ata_mutex); - return rv; } @@ -502,6 +461,8 @@ int cdrom_init(void) { volatile uint32 *react = (uint32 *)0xa05f74e4, *bios = (uint32 *)0xa0000000; + mutex_lock(&_g1_ata_mutex); + /* Reactivate drive: send the BIOS size and then read each word across the bus so the controller can verify it. If first bytes are 0xe6ff instead of usual 0xe3ff, then @@ -520,10 +481,6 @@ int cdrom_init(void) { } } - mutex_lock(&_g1_ata_mutex); - /* Make sure to select the GD-ROM drive. */ - g1_ata_select_device(G1_ATA_MASTER); - /* Reset system functions */ gdc_init_system(); mutex_unlock(&_g1_ata_mutex); diff --git a/kernel/arch/dreamcast/hardware/g1ata.c b/kernel/arch/dreamcast/hardware/g1ata.c index f2d1567..a4d227d 100644 --- a/kernel/arch/dreamcast/hardware/g1ata.c +++ b/kernel/arch/dreamcast/hardware/g1ata.c @@ -206,6 +206,8 @@ inline int g1_ata_mutex_lock(void) { } inline int g1_ata_mutex_unlock(void) { + /* Make sure to select the GD-ROM drive back. */ + g1_ata_select_device(G1_ATA_MASTER); return mutex_unlock(&_g1_ata_mutex); } @@ -222,6 +224,9 @@ static void g1_dma_irq_hnd(uint32 code) { } dma_in_progress = 0; + + /* Make sure to select the GD-ROM drive back. */ + g1_ata_select_device(G1_ATA_MASTER); mutex_unlock_as_thread(&_g1_ata_mutex, dma_thd); } } hooks/post-receive -- A pseudo Operating System for the Dreamcast. |