From: Francois B <mrs...@us...> - 2005-05-23 14:10:55
|
Update of /cvsroot/openneo/openneo/firmware/drivers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24244 Modified Files: ata.c Log Message: Make sure the mutex is locked during the init phase Index: ata.c =================================================================== RCS file: /cvsroot/openneo/openneo/firmware/drivers/ata.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** ata.c 30 Apr 2005 19:20:17 -0000 1.15 --- ata.c 23 May 2005 14:10:43 -0000 1.16 *************** *** 796,896 **** } ! int ata_init(void) { ! int rc; ! bool coldstart = (PACR2 & 0x4000) != 0; ! // bool coldstart=true; ! mutex_init(&ata_mtx); ! ! /* Port A setup */ ! PAIOR |= 0x0200; /* output for ATA reset */ ! PADR |= 0x0200; /* release ATA reset */ ! PACR2 &= 0xFFFB; /* GPIO function for PA1 (IDE enable) */ ! ! sleeping = false; ! ata_enable(true); ! ! if ( !initialized ) { ! if (coldstart) ! { ! DEBUGF("ata_init: Cold start detected...\r\n"); ! /* Reset both master and slave, we don't yet know what's in */ ! /* this is safe because non-present devices don't report busy */ ! ata_device = 0; ! if (ata_hard_reset()) ! return -1; ! ata_device = SELECT_DEVICE1; ! if (ata_hard_reset()) ! return -2; ! } ! ! rc = master_slave_detect(); ! if (rc) ! return -10 + rc; ! ! rc = io_address_detect(); ! if (rc) ! return -20 + rc; ! ! /* symptom fix: else check_registers() below may fail */ ! if (!wait_for_bsy()) ! { ! return -29; ! } ! ! rc = check_registers(); ! if (rc) ! return -30 + rc; ! ! rc = freeze_lock(); ! if (rc) ! return -40 + rc; ! ! rc = identify(); ! if (rc) ! return -50 + rc; ! ! multisectors = identify_info[47] & 0xff; ! DEBUGF("ata: %d sectors per ata request\n",multisectors); ! ! rc=identify_info[80]&0xFF; ! if (identify_info[80]&0x40) { ! DEBUGF("ata: ATA/ATAPI-6 device detected...\n"); ! if (identify_info[83]&0x400) { ! if (identify_info[86]&0x400) { ! DEBUGF("ata: ATA/ATAPI-6 48-bit Addresses supported...\n"); ! DEBUGF("ata: Maximum 48-bit Address=0x%x%x%x%x\n", ! identify_info[100],identify_info[101], ! identify_info[102],identify_info[103]); ! } else { ! DEBUGF("ata: Conflicting reports about 48-bit Addressing!\n"); ! } ! } else { ! DEBUGF("ata: ATA/ATAPI-6 48-bit Addresses not supported...\n"); ! } ! } else if (identify_info[80]&0x20) { ! DEBUGF("ata: ATA/ATAPI-5 device detected...\n"); ! } else if (identify_info[80]&0x20) { ! DEBUGF("ata: ATA/ATAPI-4 device detected...\n"); ! } else if (identify_info[80]&0x20) { ! DEBUGF("ata: ATA/ATAPI-3 device detected...\n"); ! } ! ! rc = set_features(); ! if (rc) ! return -60 + rc; ! ! // queue_init(&ata_queue); ! last_disk_activity = current_tick; ! initialized = true; } ! rc = set_multiple_mode(multisectors); ! if (rc) ! return -70 + rc; ! if(ata_flags & ATA_FLAGS_PACKET_DEV) ! panicf( "ata PACKET not supported!" ); ! return 0; } --- 796,911 ---- } ! static int ata_initialize(void) { ! int rc; ! bool coldstart = (PACR2 & 0x4000) != 0; ! if (coldstart) ! { ! DEBUGF("ata_init: Cold start detected...\r\n"); ! /* Reset both master and slave, we don't yet know what's in */ ! /* this is safe because non-present devices don't report busy */ ! ata_device = 0; ! if (ata_hard_reset()) ! return -1; ! ata_device = SELECT_DEVICE1; ! if (ata_hard_reset()) ! return -2; } ! ! rc = master_slave_detect(); ! if (rc) ! return -10 + rc; ! ! rc = io_address_detect(); ! if (rc) ! return -20 + rc; ! ! /* symptom fix: else check_registers() below may fail */ ! if (!wait_for_bsy()) ! { ! return -29; ! } ! ! rc = check_registers(); ! if (rc) ! return -30 + rc; ! ! rc = freeze_lock(); ! if (rc) ! return -40 + rc; ! ! rc = identify(); ! if (rc) ! return -50 + rc; ! ! multisectors = identify_info[47] & 0xff; ! DEBUGF("ata: %d sectors per ata request\n",multisectors); ! ! rc=identify_info[80]&0xFF; ! if (identify_info[80]&0x40) { ! DEBUGF("ata: ATA/ATAPI-6 device detected...\n"); ! if (identify_info[83]&0x400) { ! if (identify_info[86]&0x400) { ! DEBUGF("ata: ATA/ATAPI-6 48-bit Addresses supported...\n"); ! DEBUGF("ata: Maximum 48-bit Address=0x%x%x%x%x\n", ! identify_info[100],identify_info[101], ! identify_info[102],identify_info[103]); ! } else { ! DEBUGF("ata: Conflicting reports about 48-bit Addressing!\n"); ! } ! } else { ! DEBUGF("ata: ATA/ATAPI-6 48-bit Addresses not supported...\n"); ! } ! } else if (identify_info[80]&0x20) { ! DEBUGF("ata: ATA/ATAPI-5 device detected...\n"); ! } else if (identify_info[80]&0x20) { ! DEBUGF("ata: ATA/ATAPI-4 device detected...\n"); ! } else if (identify_info[80]&0x20) { ! DEBUGF("ata: ATA/ATAPI-3 device detected...\n"); ! } ! ! rc = set_features(); ! if (rc) ! return -60 + rc; ! ! // queue_init(&ata_queue); ! ! last_disk_activity = current_tick; ! initialized = true; ! rc = set_multiple_mode(multisectors); ! if (rc) ! return -70 + rc; ! ! return 0; ! } ! int ata_init(void) ! { ! int rc; ! ! mutex_init(&ata_mtx); ! ! /*Because functions like wait_for_busy() yield() to ! other threads we need to lock the mutex just in case...*/ ! mutex_lock(&ata_mtx); ! ! /* Port A setup */ ! PAIOR |= 0x0200; /* output for ATA reset */ ! PADR |= 0x0200; /* release ATA reset */ ! PACR2 &= 0xFFFB; /* GPIO function for PA1 (IDE enable) */ ! ! sleeping = false; ! ata_enable(true); ! ! if ( !initialized ) ! rc = ata_initialize(); ! ! if(!rc && (ata_flags & ATA_FLAGS_PACKET_DEV)) ! panicf( "ata PACKET not supported!" ); ! ! mutex_unlock(&ata_mtx); ! ! return rc; } |