Search
lxdream.org :: lxdream :: r158:a0a82246b44e
lxdream 0.9.1
released Jun 29
Download Now
changeset158:a0a82246b44e
parent157:fbe03268ad8a
child159:406161fea392
authornkeynes
dateThu Jun 15 10:32:42 2006 +0000 (13 years ago)
Fix IDE DMA to actually work for real.
Implement the mystery packet 0x71 by cribbing a block of data from the dc.
src/asic.c
src/asic.h
src/gdrom/gdrom.c
src/gdrom/ide.c
src/gdrom/packet.h
1.1 --- a/src/asic.c Thu Jun 15 10:27:10 2006 +0000
1.2 +++ b/src/asic.c Thu Jun 15 10:32:42 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: asic.c,v 1.15 2006-05-24 11:50:19 nkeynes Exp $
1.6 + * $Id: asic.c,v 1.16 2006-06-15 10:32:38 nkeynes Exp $
1.7 *
1.8 * Support for the miscellaneous ASIC functions (Primarily event multiplexing,
1.9 * and DMA).
1.10 @@ -167,20 +167,19 @@
1.11
1.12 void asic_ide_dma_transfer( )
1.13 {
1.14 - if( MMIO_READ( EXTDMA, IDEDMACTL2 ) == 1 &&
1.15 - MMIO_READ( EXTDMA, IDEDMACTL1 ) == 0 ) {
1.16 - uint32_t addr = MMIO_READ( EXTDMA, IDEDMASH4 );
1.17 - uint32_t length = MMIO_READ( EXTDMA, IDEDMASIZ );
1.18 - int dir = MMIO_READ( EXTDMA, IDEDMADIR );
1.19 -
1.20 - uint32_t xfer = ide_read_data_dma( addr, length );
1.21 - if( xfer != 0 ) {
1.22 - MMIO_WRITE( EXTDMA, IDEDMASH4, addr + xfer );
1.23 - MMIO_WRITE( EXTDMA, IDEDMASIZ, length - xfer );
1.24 - if( xfer == length ) {
1.25 - MMIO_WRITE( EXTDMA, IDEDMACTL2, 0 );
1.26 - asic_event( EVENT_IDE_DMA );
1.27 - }
1.28 + if( MMIO_READ( EXTDMA, IDEDMACTL2 ) == 1 ) {
1.29 + if( MMIO_READ( EXTDMA, IDEDMACTL1 ) == 1 ) {
1.30 + MMIO_WRITE( EXTDMA, IDEDMATXSIZ, 0 );
1.31 +
1.32 + uint32_t addr = MMIO_READ( EXTDMA, IDEDMASH4 );
1.33 + uint32_t length = MMIO_READ( EXTDMA, IDEDMASIZ );
1.34 + int dir = MMIO_READ( EXTDMA, IDEDMADIR );
1.35 +
1.36 + uint32_t xfer = ide_read_data_dma( addr, length );
1.37 + MMIO_WRITE( EXTDMA, IDEDMATXSIZ, xfer );
1.38 + MMIO_WRITE( EXTDMA, IDEDMACTL2, 0 );
1.39 + } else { /* 0 */
1.40 + MMIO_WRITE( EXTDMA, IDEDMACTL2, 0 );
1.41 }
1.42 }
1.43
1.44 @@ -221,6 +220,9 @@
1.45 asic_event( EVENT_PVR_DMA );
1.46 }
1.47 break;
1.48 + case PVRDMADEST: case PVRDMACNT: case MAPLE_DMA:
1.49 + MMIO_WRITE( ASIC, reg, val );
1.50 + break;
1.51 default:
1.52 MMIO_WRITE( ASIC, reg, val );
1.53 WARN( "Write to ASIC (%03X <= %08X) [%s: %s]",
1.54 @@ -249,6 +251,7 @@
1.55 case IRQC0:
1.56 case IRQC1:
1.57 case IRQC2:
1.58 + case MAPLE_STATE:
1.59 val = MMIO_READ(ASIC, reg);
1.60 // WARN( "Read from ASIC (%03X => %08X) [%s: %s]",
1.61 // reg, val, MMIO_REGID(ASIC,reg), MMIO_REGDESC(ASIC,reg) );
1.62 @@ -266,7 +269,7 @@
1.63
1.64 MMIO_REGION_WRITE_FN( EXTDMA, reg, val )
1.65 {
1.66 - WARN( "EXTDMA write %08X <= %08X", reg, val );
1.67 + // WARN( "EXTDMA write %08X <= %08X", reg, val );
1.68
1.69 switch( reg ) {
1.70 case IDEALTSTATUS: /* Device control */
1.71 @@ -319,20 +322,22 @@
1.72 {
1.73 uint32_t val;
1.74 switch( reg ) {
1.75 - case IDEALTSTATUS: return idereg.status;
1.76 - case IDEDATA: return ide_read_data_pio( );
1.77 - case IDEFEAT: return idereg.error;
1.78 - case IDECOUNT:return idereg.count;
1.79 - case IDELBA0: return idereg.disc;
1.80 - case IDELBA1: return idereg.lba1;
1.81 - case IDELBA2: return idereg.lba2;
1.82 - case IDEDEV: return idereg.device;
1.83 - case IDECMD:
1.84 - return ide_read_status();
1.85 - default:
1.86 - val = MMIO_READ( EXTDMA, reg );
1.87 - //DEBUG( "EXTDMA read %08X => %08X", reg, val );
1.88 - return val;
1.89 + case IDEALTSTATUS:
1.90 + val = idereg.status;
1.91 + return val;
1.92 + case IDEDATA: return ide_read_data_pio( );
1.93 + case IDEFEAT: return idereg.error;
1.94 + case IDECOUNT:return idereg.count;
1.95 + case IDELBA0: return idereg.disc;
1.96 + case IDELBA1: return idereg.lba1;
1.97 + case IDELBA2: return idereg.lba2;
1.98 + case IDEDEV: return idereg.device;
1.99 + case IDECMD:
1.100 + val = ide_read_status();
1.101 + return val;
1.102 + default:
1.103 + val = MMIO_READ( EXTDMA, reg );
1.104 + return val;
1.105 }
1.106 }
1.107
2.1 --- a/src/asic.h Thu Jun 15 10:27:10 2006 +0000
2.2 +++ b/src/asic.h Thu Jun 15 10:32:42 2006 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: asic.h,v 1.9 2006-05-24 11:50:19 nkeynes Exp $
2.6 + * $Id: asic.h,v 1.10 2006-06-15 10:32:38 nkeynes Exp $
2.7 *
2.8 * Support for the miscellaneous ASIC functions (Primarily event multiplexing,
2.9 * and DMA). Includes MMIO definitions for the 5f6000 and 5f7000 regions,
2.10 @@ -113,8 +113,9 @@
2.11 LONG_PORT( 0x4A0, EXTDMAUNK6, PORT_MRW, 0, "Ext DMA <unknown6>" )
2.12 LONG_PORT( 0x4A4, EXTDMAUNK7, PORT_MRW, 0, "Ext DMA <unknown7>" )
2.13 LONG_PORT( 0x4B4, EXTDMAUNK8, PORT_MRW, 0, "Ext DMA <unknown8>" )
2.14 - LONG_PORT( 0x4B8, EXTDMAUNK9, PORT_MRW, 0, "Ext DMA <unknown9>" )
2.15 + LONG_PORT( 0x4B8, IDEDMACFG, PORT_MRW, 0, "IDE DMA Config" )
2.16 LONG_PORT( 0x4E4, IDEACTIVATE, PORT_MRW, 0, "IDE activate" )
2.17 + LONG_PORT( 0x4F8, IDEDMATXSIZ, PORT_MRW, 0, "IDE DMA transfered size" )
2.18 LONG_PORT( 0x800, SPUDMA0EXT, PORT_MRW, 0, "SPU DMA0 External address" )
2.19 LONG_PORT( 0x804, SPUDMA0SH4, PORT_MRW, 0, "SPU DMA0 SH4-based address" )
2.20 LONG_PORT( 0x808, SPUDMA0SIZ, PORT_MRW, 0, "SPU DMA0 Size" )
2.21 @@ -166,7 +167,7 @@
2.22 LONG_PORT( 0xC10, PVRDMA2MOD, PORT_MRW, 0, "PVR DMA Mode" )
2.23 LONG_PORT( 0xC14, PVRDMA2CTL1, PORT_MRW, 0, "PVR DMA Control 1" )
2.24 LONG_PORT( 0xC18, PVRDMA2CTL2, PORT_MRW, 0, "PVR DMA Control 2" )
2.25 - LONG_PORT( 0xC80, PVRDMA2UN1, PORT_MRW, 0, "PVR DMA <unknown1>" )
2.26 + LONG_PORT( 0xC80, PVRDMA2CFG, PORT_MRW, 0, "PVR DMA Config" )
2.27
2.28 MMIO_REGION_END
2.29
3.1 --- a/src/gdrom/gdrom.c Thu Jun 15 10:27:10 2006 +0000
3.2 +++ b/src/gdrom/gdrom.c Thu Jun 15 10:32:42 2006 +0000
3.3 @@ -1,5 +1,5 @@
3.4 /**
3.5 - * $Id: gdrom.c,v 1.6 2006-05-24 11:49:38 nkeynes Exp $
3.6 + * $Id: gdrom.c,v 1.7 2006-06-15 10:32:42 nkeynes Exp $
3.7 *
3.8 * GD-Rom access functions.
3.9 *
3.10 @@ -81,9 +81,10 @@
3.11
3.12 switch( mode ) {
3.13 case GDROM_GD:
3.14 - if( track->mode != GDROM_GD )
3.15 - return PKT_ERR_BADREADMODE;
3.16 - break;
3.17 + // Temporarily comment this out - it's wrong, but...
3.18 + // if( track->mode != GDROM_GD )
3.19 + // return PKT_ERR_BADREADMODE;
3.20 + // break;
3.21 case GDROM_MODE1:
3.22 switch( track->mode ) {
3.23 case GDROM_MODE1:
4.1 --- a/src/gdrom/ide.c Thu Jun 15 10:27:10 2006 +0000
4.2 +++ b/src/gdrom/ide.c Thu Jun 15 10:32:42 2006 +0000
4.3 @@ -1,5 +1,5 @@
4.4 /**
4.5 - * $Id: ide.c,v 1.14 2006-05-23 13:11:45 nkeynes Exp $
4.6 + * $Id: ide.c,v 1.15 2006-06-15 10:32:42 nkeynes Exp $
4.7 *
4.8 * IDE interface implementation
4.9 *
4.10 @@ -58,6 +58,57 @@
4.11 0x20, 0x20, 0x52, 0x65, 0x76, 0x20, 0x36, 0x2e,
4.12 0x34, 0x32, 0x39, 0x39, 0x30, 0x33, 0x31, 0x36 };
4.13
4.14 +unsigned char gdrom_71[] = { 0x3E, 0x0F, 0x90, 0xBE, 0x1D, 0xD9, 0x89, 0x04, 0x28, 0x3A, 0x8E, 0x26, 0x5C, 0x95, 0x10, 0x5A,
4.15 + 0x0A, 0x99, 0xEE, 0xFB, 0x69, 0xCE, 0xD9, 0x63, 0x00, 0xF5, 0x0A, 0xBC, 0x2C, 0x0D, 0xF8, 0xE2,
4.16 + 0x05, 0x02, 0x00, 0x7C, 0x03, 0x00, 0x3D, 0x08, 0xD8, 0x8D, 0x08, 0x7A, 0x6D, 0x00, 0x35, 0x06,
4.17 + 0xBA, 0x66, 0x10, 0x00, 0x91, 0x08, 0x10, 0x29, 0xD0, 0x45, 0xDA, 0x00, 0x2D, 0x05, 0x69, 0x09,
4.18 + 0x00, 0x5E, 0x0F, 0x70, 0x86, 0x12, 0x6C, 0x77, 0x5A, 0xFB, 0xCD, 0x56, 0xFB, 0xF7, 0xB7, 0x00,
4.19 + 0x5D, 0x07, 0x19, 0x99, 0xF2, 0xAF, 0x00, 0x63, 0x03, 0x00, 0xF0, 0x10, 0xBE, 0xD7, 0xA0, 0x63,
4.20 + 0xFA, 0x84, 0xA7, 0x74, 0x94, 0xEF, 0xAD, 0xC2, 0xAC, 0x00, 0x78, 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 0x2F, 0xF0, 0x00, 0x00 };
4.64 +
4.65
4.66 static void ide_init( void )
4.67 {
4.68 @@ -76,7 +127,7 @@
4.69 idereg.lba1 = 0x14;
4.70 idereg.lba2 = 0xeb;
4.71 idereg.feature = 0; /* Indeterminate really */
4.72 - idereg.status = 0x00;
4.73 + idereg.status = 0x50;
4.74 idereg.device = 0x00;
4.75 idereg.disc = gdrom_is_mounted() ? (IDE_DISC_CDROM|IDE_DISC_READY) : IDE_DISC_NONE;
4.76 idereg.state = IDE_STATE_IDLE;
4.77 @@ -89,7 +140,7 @@
4.78 {
4.79 fwrite( &idereg, sizeof(idereg), 1, f );
4.80 fwrite( &data_buffer_len, sizeof(data_buffer_len), 1, f );
4.81 - fwrite( data_buffer, data_buffer_len, 1, f );
4.82 + fwrite( data_buffer, MAX_SECTOR_SIZE, data_buffer_len, f );
4.83 }
4.84
4.85 static int ide_load_state( FILE *f )
4.86 @@ -100,16 +151,30 @@
4.87 if( length > data_buffer_len ) {
4.88 if( data_buffer != NULL )
4.89 free( data_buffer );
4.90 - data_buffer = malloc( length );
4.91 + data_buffer = malloc( MAX_SECTOR_SIZE * length );
4.92 assert( data_buffer != NULL );
4.93 data_buffer_len = length;
4.94 }
4.95 - fread( data_buffer, length, 1, f );
4.96 + fread( data_buffer, MAX_SECTOR_SIZE, length, f );
4.97 return 0;
4.98 }
4.99
4.100 /************************ State transitions *************************/
4.101
4.102 +void ide_set_packet_result( uint16_t result )
4.103 +{
4.104 + idereg.gdrom_sense[0] = 0xf0;
4.105 + idereg.gdrom_sense[2] = result & 0xFF;
4.106 + idereg.gdrom_sense[8] = (result >> 8) & 0xFF;
4.107 + idereg.error = (result & 0x0F) << 4;
4.108 + if( result != 0 ) {
4.109 + idereg.status = 0x51;
4.110 + ide_raise_interrupt();
4.111 + } else {
4.112 + idereg.status = idereg.status & ~(IDE_STATUS_BSY|IDE_STATUS_CHK);
4.113 + }
4.114 +}
4.115 +
4.116 /**
4.117 * Begin command packet write to the device. This is always 12 bytes of PIO data
4.118 */
4.119 @@ -129,27 +194,29 @@
4.120 */
4.121 static void ide_start_read( int length, int blocksize, gboolean dma )
4.122 {
4.123 - idereg.status = IDE_STATUS_DRDY | IDE_STATUS_DRQ;
4.124 idereg.count = IDE_COUNT_IO;
4.125 idereg.data_length = length;
4.126 idereg.data_offset = 0;
4.127 if( dma ) {
4.128 idereg.state = IDE_STATE_DMA_READ;
4.129 - idereg.status |= IDE_STATUS_DMRD;
4.130 + idereg.status = 0xD0;
4.131 } else {
4.132 idereg.state = IDE_STATE_PIO_READ;
4.133 + idereg.status = IDE_STATUS_DRDY | IDE_STATUS_DRQ;
4.134 idereg.lba1 = length & 0xFF;
4.135 idereg.lba2 = (length >> 8) & 0xFF;
4.136 // idereg.lba1 = blocksize & 0xFF;
4.137 // idereg.lba2 = blocksize >> 8;
4.138 idereg.block_length = blocksize;
4.139 idereg.block_left = blocksize;
4.140 + ide_raise_interrupt( );
4.141 }
4.142 }
4.143
4.144 static void ide_start_packet_read( int length, int blocksize )
4.145 {
4.146 - ide_start_read( length, blocksize, idereg.feature & IDE_FEAT_DMA ? TRUE : FALSE );
4.147 + ide_set_packet_result( PKT_ERR_OK );
4.148 + ide_start_read( length, blocksize, (idereg.feature & IDE_FEAT_DMA) ? TRUE : FALSE );
4.149 }
4.150
4.151 static void ide_raise_interrupt( void )
4.152 @@ -225,15 +292,15 @@
4.153 if( idereg.data_offset >= idereg.data_length ) {
4.154 idereg.data_offset = -1;
4.155 idereg.state = IDE_STATE_IDLE;
4.156 - idereg.status &= ~IDE_STATUS_DRQ;
4.157 + idereg.status = 0x50;
4.158 ide_raise_interrupt();
4.159 + asic_event( EVENT_IDE_DMA );
4.160 }
4.161 return xferlen;
4.162 }
4.163 return 0;
4.164 }
4.165
4.166 -
4.167 void ide_write_data_pio( uint16_t val ) {
4.168 if( idereg.state == IDE_STATE_CMD_WRITE ) {
4.169 WRITE_BUFFER(val);
4.170 @@ -308,19 +375,6 @@
4.171 idereg.status = (idereg.status | IDE_STATUS_DRDY | IDE_STATUS_SERV) & (~IDE_STATUS_CHK);
4.172 }
4.173
4.174 -void ide_set_packet_result( uint16_t result )
4.175 -{
4.176 - idereg.gdrom_sense[0] = 0xf0;
4.177 - idereg.gdrom_sense[2] = result & 0xFF;
4.178 - idereg.gdrom_sense[8] = (result >> 8) & 0xFF;
4.179 - idereg.error = (result & 0x0F) << 4;
4.180 - if( result != 0 ) {
4.181 - idereg.status = 0x51;
4.182 - } else {
4.183 - idereg.status = idereg.status & ~(IDE_STATUS_BSY|IDE_STATUS_CHK);
4.184 - }
4.185 -}
4.186 -
4.187 /**
4.188 * Execute a packet command. This particular method is responsible for parsing
4.189 * the command buffers (12 bytes), and generating the appropriate responses,
4.190 @@ -333,31 +387,31 @@
4.191 int mode;
4.192 int blocksize = idereg.lba1 + (idereg.lba2<<8);
4.193
4.194 - ide_raise_interrupt( );
4.195 /* Okay we have the packet in the command buffer */
4.196 WARN( "ATAPI: Received Packet command: %02X", cmd[0] );
4.197 fwrite_dump( (unsigned char *)cmd, 12, stderr );
4.198 + // fprint_stack_trace( stderr );
4.199 switch( cmd[0] ) {
4.200 case PKT_CMD_TEST_READY:
4.201 if( !gdrom_is_mounted() ) {
4.202 ide_set_packet_result( PKT_ERR_NODISC );
4.203 - return;
4.204 + } else {
4.205 + ide_set_packet_result( 0 );
4.206 + ide_raise_interrupt();
4.207 + idereg.status = 0x50;
4.208 }
4.209 - ide_set_packet_result( 0 );
4.210 - idereg.status = 0x50;
4.211 - return;
4.212 break;
4.213 case PKT_CMD_IDENTIFY:
4.214 lba = cmd[2];
4.215 if( lba >= sizeof(gdrom_ident) ) {
4.216 ide_set_error(PKT_ERR_BADFIELD);
4.217 - return;
4.218 + } else {
4.219 + length = cmd[4];
4.220 + if( lba+length > sizeof(gdrom_ident) )
4.221 + length = sizeof(gdrom_ident) - lba;
4.222 + memcpy( data_buffer, gdrom_ident + lba, length );
4.223 + ide_start_packet_read( length, blocksize );
4.224 }
4.225 - length = cmd[4];
4.226 - if( lba+length > sizeof(gdrom_ident) )
4.227 - length = sizeof(gdrom_ident) - lba;
4.228 - memcpy( data_buffer, gdrom_ident + lba, length );
4.229 - ide_start_packet_read( length, blocksize );
4.230 break;
4.231 case PKT_CMD_SENSE:
4.232 length = cmd[4];
4.233 @@ -374,31 +428,24 @@
4.234 status = gdrom_get_toc( data_buffer );
4.235 if( status != PKT_ERR_OK ) {
4.236 ide_set_packet_result( status );
4.237 - return;
4.238 + } else {
4.239 + ide_start_packet_read( length, blocksize );
4.240 }
4.241 - ide_start_packet_read( length, blocksize );
4.242 break;
4.243 - case PKT_CMD_DISC_INFO:
4.244 + case PKT_CMD_SESSION_INFO:
4.245 length = cmd[4];
4.246 if( length > 6 )
4.247 length = 6;
4.248 status = gdrom_get_info( data_buffer, cmd[2] );
4.249 if( status != PKT_ERR_OK ) {
4.250 ide_set_packet_result( status );
4.251 - return;
4.252 + } else {
4.253 + ide_start_packet_read( length, blocksize );
4.254 }
4.255 - ide_start_packet_read( length, blocksize );
4.256 break;
4.257 case PKT_CMD_READ_SECTOR:
4.258 lba = cmd[2] << 16 | cmd[3] << 8 | cmd[4];
4.259 length = cmd[8] << 16 | cmd[9] << 8 | cmd[10]; /* blocks */
4.260 - if( length > data_buffer_len ) {
4.261 - do {
4.262 - data_buffer_len = data_buffer_len << 1;
4.263 - } while( data_buffer_len < length );
4.264 - data_buffer = realloc( data_buffer, data_buffer_len );
4.265 - }
4.266 -
4.267 switch( cmd[1] ) {
4.268 case 0x20: mode = GDROM_MODE1; break;
4.269 case 0x24: mode = GDROM_GD; break;
4.270 @@ -409,6 +456,14 @@
4.271 ide_set_packet_result( PKT_ERR_BADFIELD );
4.272 return;
4.273 }
4.274 +
4.275 + if( length > data_buffer_len ) {
4.276 + do {
4.277 + data_buffer_len = data_buffer_len << 1;
4.278 + } while( data_buffer_len < length );
4.279 + data_buffer = realloc( data_buffer, MAX_SECTOR_SIZE * data_buffer_len );
4.280 + }
4.281 +
4.282 datalen = data_buffer_len;
4.283 status = gdrom_read_sectors( lba, length, mode, data_buffer, &datalen );
4.284 if( status != 0 ) {
4.285 @@ -416,16 +471,25 @@
4.286 idereg.gdrom_sense[5] = (lba >> 16) & 0xFF;
4.287 idereg.gdrom_sense[6] = (lba >> 8) & 0xFF;
4.288 idereg.gdrom_sense[7] = lba & 0xFF;
4.289 - return;
4.290 + } else {
4.291 + ide_start_packet_read( datalen, blocksize );
4.292 }
4.293 - ide_start_packet_read( datalen, blocksize );
4.294 break;
4.295 case PKT_CMD_SPIN_UP:
4.296 /* do nothing? */
4.297 + ide_set_packet_result( PKT_ERR_OK );
4.298 + ide_raise_interrupt();
4.299 + break;
4.300 + case PKT_CMD_71:
4.301 + /* This is a weird one. As far as I can tell it returns random garbage
4.302 + * (and not even the same length each time, never mind the same data).
4.303 + * For sake of something to do, it returns the results from a test dump
4.304 + */
4.305 + memcpy( data_buffer, gdrom_71, sizeof(gdrom_71) );
4.306 + ide_start_packet_read( sizeof(gdrom_71), blocksize );
4.307 break;
4.308 default:
4.309 ide_set_packet_result( PKT_ERR_BADCMD ); /* Invalid command */
4.310 return;
4.311 }
4.312 - ide_set_packet_result( PKT_ERR_OK );
4.313 }
5.1 --- a/src/gdrom/packet.h Thu Jun 15 10:27:10 2006 +0000
5.2 +++ b/src/gdrom/packet.h Thu Jun 15 10:32:42 2006 +0000
5.3 @@ -1,5 +1,5 @@
5.4 /**
5.5 - * $Id: packet.h,v 1.3 2006-05-20 06:24:49 nkeynes Exp $
5.6 + * $Id: packet.h,v 1.4 2006-06-15 10:32:42 nkeynes Exp $
5.7 *
5.8 * This file defines the command codes and any other flags used by the
5.9 * GD-Rom ATAPI packet commands.
5.10 @@ -39,7 +39,7 @@
5.11 * 53
5.12 * 54
5.13 * 55
5.14 - * 70
5.15 + * 70
5.16 * 71
5.17 * 72
5.18 * 73
5.19 @@ -50,9 +50,10 @@
5.20 #define PKT_CMD_IDENTIFY 0x11
5.21 #define PKT_CMD_SENSE 0x13
5.22 #define PKT_CMD_READ_TOC 0x14
5.23 -#define PKT_CMD_DISC_INFO 0x15
5.24 +#define PKT_CMD_SESSION_INFO 0x15
5.25 #define PKT_CMD_READ_SECTOR 0x30
5.26 #define PKT_CMD_SPIN_UP 0x70 /* ??? */
5.27 +#define PKT_CMD_71 0x71 /* ??? seems to return garbage */
5.28
5.29 #define PKT_ERR_OK 0x0000
5.30 #define PKT_ERR_NODISC 0x3A02
.