Search
lxdream.org :: lxdream/test/ide.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/ide.c
changeset 247:b356d391d02a
prev243:df1671d533bf
next251:3c5953d944e0
author nkeynes
date Tue Dec 19 09:56:09 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Remove debug_dump call and dump at end of wait_irq
file annotate diff log raw
nkeynes@185
     1
#include <assert.h>
nkeynes@185
     2
#include <stdlib.h>
nkeynes@185
     3
#include "ide.h"
nkeynes@185
     4
#include "lib.h"
nkeynes@185
     5
nkeynes@185
     6
#define IDE_BASE 0xA05F7000
nkeynes@185
     7
nkeynes@185
     8
#define IDE_ALTSTATUS IDE_BASE+0x018
nkeynes@185
     9
#define IDE_UNKNOWN   IDE_BASE+0x01C
nkeynes@185
    10
#define IDE_DATA      IDE_BASE+0x080 /* 16 bits */
nkeynes@185
    11
#define IDE_FEATURE   IDE_BASE+0x084
nkeynes@185
    12
#define IDE_COUNT     IDE_BASE+0x088
nkeynes@185
    13
#define IDE_LBA0      IDE_BASE+0x08C
nkeynes@185
    14
#define IDE_LBA1      IDE_BASE+0x090
nkeynes@185
    15
#define IDE_LBA2      IDE_BASE+0x094
nkeynes@185
    16
#define IDE_DEVICE    IDE_BASE+0x098
nkeynes@185
    17
#define IDE_COMMAND   IDE_BASE+0x09C
nkeynes@185
    18
#define IDE_ACTIVATE  IDE_BASE+0x4E4
nkeynes@185
    19
nkeynes@185
    20
#define IDE_DEVCONTROL IDE_ALTSTATUS
nkeynes@185
    21
#define IDE_ERROR      IDE_FEATURE
nkeynes@185
    22
#define IDE_STATUS     IDE_COMMAND
nkeynes@185
    23
nkeynes@185
    24
#define IDE_DMA_ADDR   IDE_BASE+0x404
nkeynes@185
    25
#define IDE_DMA_SIZE   IDE_BASE+0x408
nkeynes@185
    26
#define IDE_DMA_DIR    IDE_BASE+0x40C
nkeynes@185
    27
#define IDE_DMA_CTL1   IDE_BASE+0x414
nkeynes@185
    28
#define IDE_DMA_CTL2   IDE_BASE+0x418
nkeynes@185
    29
#define IDE_DMA_MAGIC  IDE_BASE+0x4B8
nkeynes@185
    30
#define IDE_DMA_STATUS IDE_BASE+0x4F8
nkeynes@185
    31
nkeynes@185
    32
#define DMA_BASE 0xFFA00000
nkeynes@185
    33
#define DMA_SAR1    DMA_BASE+0x010
nkeynes@185
    34
#define DMA_DAR1    DMA_BASE+0x014
nkeynes@185
    35
#define DMA_TCR1    DMA_BASE+0x018
nkeynes@185
    36
#define DMA_CHCR1   DMA_BASE+0x01C
nkeynes@185
    37
#define DMA_SAR2    DMA_BASE+0x020
nkeynes@185
    38
#define DMA_DAR2    DMA_BASE+0x024
nkeynes@185
    39
#define DMA_TCR2    DMA_BASE+0x028
nkeynes@185
    40
#define DMA_CHCR2   DMA_BASE+0x02C
nkeynes@185
    41
#define DMA_SAR3    DMA_BASE+0x030
nkeynes@185
    42
#define DMA_DAR3    DMA_BASE+0x034
nkeynes@185
    43
#define DMA_TCR3    DMA_BASE+0x038
nkeynes@185
    44
#define DMA_CHCR3   DMA_BASE+0x03C
nkeynes@185
    45
#define DMA_DMAOR   DMA_BASE+0x040
nkeynes@185
    46
#define QUEUECR0    0xFF000038
nkeynes@185
    47
#define QUEUECR1    0xFF00003C
nkeynes@185
    48
nkeynes@185
    49
#define IDE_CMD_RESET 0x08
nkeynes@185
    50
#define IDE_CMD_PACKET 0xA0
nkeynes@185
    51
#define IDE_CMD_IDENTIFY_PACKET_DEVICE 0xA1
nkeynes@185
    52
#define IDE_CMD_IDENTIFY_DEVICE 0xEC
nkeynes@185
    53
nkeynes@185
    54
#define MMC_CMD_GET_CONFIGURATION 0x46
nkeynes@185
    55
#define GD_CMD_IDENTIFY 0x11 /* guessing */
nkeynes@185
    56
nkeynes@185
    57
nkeynes@185
    58
#define IDE_DMA_MAGIC_VALUE 0x8843407F
nkeynes@185
    59
nkeynes@185
    60
nkeynes@185
    61
#define MAX_WAIT     10000000
nkeynes@185
    62
#define MAX_IRQ_WAIT 1000000000
nkeynes@185
    63
nkeynes@185
    64
/**
nkeynes@185
    65
 * Dump all ide registers to stdout.
nkeynes@185
    66
 */
nkeynes@185
    67
void ide_dump_registers() {
nkeynes@185
    68
    int i,j;
nkeynes@185
    69
    printf( "IDE registers:\n");
nkeynes@185
    70
    printf( "Stats: %02X ", byte_read(IDE_ALTSTATUS) );
nkeynes@185
    71
    printf( "Error: %02X ", byte_read(IDE_ERROR) );
nkeynes@185
    72
    printf( "Count: %02X ", byte_read(IDE_COUNT) );
nkeynes@185
    73
    printf( "Dvice: %02X ", byte_read(IDE_DEVICE) );
nkeynes@185
    74
    if( long_read(ASIC_STATUS1)&1 ) {
nkeynes@185
    75
	printf( "INTRQ! " );
nkeynes@185
    76
    }
nkeynes@185
    77
    if( (long_read(ASIC_STATUS0)>>14)&1 ) {
nkeynes@185
    78
	printf( "DMARQ! " );
nkeynes@185
    79
    }
nkeynes@185
    80
    printf( "\nLBA 0: %02X ", byte_read(IDE_LBA0) );
nkeynes@185
    81
    printf( "LBA 1: %02X ", byte_read(IDE_LBA1) );
nkeynes@185
    82
    printf( "LBA 2: %02X ", byte_read(IDE_LBA2) );
nkeynes@185
    83
    printf( "0x01C: %02X\n", byte_read(IDE_UNKNOWN) );
nkeynes@185
    84
    printf( "DAddr: %08X ", long_read(IDE_DMA_ADDR) );
nkeynes@185
    85
    printf( "DSize: %08X ", long_read(IDE_DMA_SIZE) );
nkeynes@185
    86
    printf( "DDir : %08X ", long_read(IDE_DMA_DIR) );
nkeynes@185
    87
    printf( "DCtl1: %08X ", long_read(IDE_DMA_CTL1) );
nkeynes@185
    88
    printf( "DCtl2: %08X\n", long_read(IDE_DMA_CTL2) );
nkeynes@185
    89
    printf( "DStat: %08X\n", long_read(IDE_DMA_STATUS) );
nkeynes@185
    90
    printf( "ASIC: " );
nkeynes@185
    91
    for( i=0; i<12; i+=4 ) {
nkeynes@185
    92
	unsigned int val = long_read(ASIC_STATUS0+i);
nkeynes@185
    93
	for( j=0; j<32; j++ ) {
nkeynes@185
    94
	    if( val & (1<<j) ) {
nkeynes@185
    95
		printf( "%d ", j );
nkeynes@185
    96
	    }
nkeynes@185
    97
	}
nkeynes@185
    98
	printf( "| " );
nkeynes@185
    99
    }
nkeynes@185
   100
    printf( "\n" );
nkeynes@185
   101
}
nkeynes@185
   102
nkeynes@185
   103
/**
nkeynes@185
   104
 * Wait for the IDE INTRQ line to go active (bit 0 of the second word)
nkeynes@185
   105
 * @return 0 on success, non-zero on timeout
nkeynes@185
   106
 */
nkeynes@185
   107
int ide_wait_irq() {
nkeynes@185
   108
    unsigned int status;
nkeynes@185
   109
    int i;
nkeynes@185
   110
    for( i=0; i<MAX_WAIT; i++ ) {
nkeynes@185
   111
	status = long_read( ASIC_STATUS1 );
nkeynes@185
   112
	if( (status&1) != 0 )
nkeynes@185
   113
	    return 0;
nkeynes@185
   114
    }
nkeynes@185
   115
    return 1;
nkeynes@185
   116
}
nkeynes@185
   117
nkeynes@185
   118
/**
nkeynes@185
   119
 * Wait for the IDE BSY flag to be de-asserted.
nkeynes@185
   120
 * @return 0 on success, non-zero on timeout
nkeynes@185
   121
 */
nkeynes@185
   122
int ide_wait_ready() {
nkeynes@185
   123
    unsigned char status;
nkeynes@185
   124
    int i;
nkeynes@185
   125
    for( i=0; i<MAX_WAIT; i++ ) {
nkeynes@185
   126
        status = byte_read(IDE_ALTSTATUS);
nkeynes@185
   127
	if( (status & 0x80) != 0x80 )
nkeynes@185
   128
	    return 0;
nkeynes@185
   129
    }
nkeynes@185
   130
    printf( "Timeout waiting for IDE to become ready\n" );
nkeynes@185
   131
    ide_dump_registers();
nkeynes@185
   132
    return 1;
nkeynes@185
   133
}
nkeynes@185
   134
nkeynes@185
   135
int ide_wait_dma() {
nkeynes@185
   136
    unsigned int status;
nkeynes@185
   137
    int i;
nkeynes@185
   138
    for( i=0; i<MAX_WAIT; i++ ) {
nkeynes@185
   139
	status = long_read(IDE_DMA_CTL2);
nkeynes@185
   140
	if( (status & 1) == 0 )
nkeynes@185
   141
	    return 0;
nkeynes@185
   142
    }
nkeynes@185
   143
    printf( "[IDE] Timeout waiting for DMA to become ready\n" );
nkeynes@185
   144
    return 1;
nkeynes@185
   145
}
nkeynes@185
   146
nkeynes@185
   147
/**
nkeynes@185
   148
 * Write the command packet out to the interface.
nkeynes@185
   149
 * @param cmd 12 byte ATAPI command packet
nkeynes@185
   150
 * @param dma 1 = dma mode, 0 = pio mode
nkeynes@185
   151
 */
nkeynes@185
   152
int ide_write_command_packet( char *cmd, int dma ) 
nkeynes@185
   153
{
nkeynes@185
   154
    int i, status;
nkeynes@185
   155
    unsigned short *spkt = (unsigned short *)cmd;
nkeynes@185
   156
    unsigned short length = 8;
nkeynes@185
   157
    if( ide_wait_ready() )
nkeynes@185
   158
	return 1;
nkeynes@185
   159
    byte_write( IDE_FEATURE, dma );
nkeynes@185
   160
    byte_write( IDE_COUNT, 0 );
nkeynes@185
   161
    byte_write( IDE_LBA0, 0 );
nkeynes@185
   162
    byte_write( IDE_LBA1, (length&0xFF) );
nkeynes@185
   163
    byte_write( IDE_LBA2, (length>>8)&0xFF );
nkeynes@185
   164
    byte_write( IDE_DEVICE, 0 );
nkeynes@185
   165
    byte_write( IDE_COMMAND, IDE_CMD_PACKET );
nkeynes@185
   166
    status = byte_read(IDE_ALTSTATUS); /* delay 1 PIO cycle as per spec */
nkeynes@185
   167
    printf( "After writing PACKET command byte:\n" );
nkeynes@185
   168
    ide_dump_registers();
nkeynes@185
   169
    /* Wait until device is ready to accept command */
nkeynes@185
   170
    if( ide_wait_ready() )
nkeynes@185
   171
	return 1;
nkeynes@185
   172
    printf( "Device ready to receive packet:\n" );
nkeynes@185
   173
    ide_dump_registers();
nkeynes@185
   174
nkeynes@185
   175
    /* Write the command */
nkeynes@185
   176
    for( i=0; i<6; i++ ) {
nkeynes@185
   177
        word_write( IDE_DATA, spkt[i] );
nkeynes@185
   178
    }
nkeynes@185
   179
    printf( "After writing command packet:\n" );
nkeynes@185
   180
    ide_dump_registers();
nkeynes@185
   181
}
nkeynes@185
   182
nkeynes@185
   183
int ide_read_pio( char *buf, int buflen ) {
nkeynes@185
   184
    int i;
nkeynes@185
   185
    unsigned short *bufptr = (unsigned short *)buf;
nkeynes@185
   186
    unsigned int length = 0, avail;
nkeynes@185
   187
    int status;
nkeynes@185
   188
    
nkeynes@185
   189
    while(1) {
nkeynes@185
   190
	if( ide_wait_ready() )
nkeynes@185
   191
	    return -1;
nkeynes@185
   192
	status = byte_read( IDE_STATUS );
nkeynes@185
   193
	if( (status & 0xE9) == 0x48 ) {
nkeynes@185
   194
	    /* Bytes available */
nkeynes@185
   195
	    avail = (byte_read( IDE_LBA1 )) | (byte_read(IDE_LBA2)<<8);
nkeynes@185
   196
	    for( i=0; i<avail; i+=2 ) {
nkeynes@185
   197
		if( buflen > 0 ) {
nkeynes@185
   198
		    *bufptr++ = word_read(IDE_DATA);
nkeynes@185
   199
		    buflen-=2;
nkeynes@185
   200
		}
nkeynes@185
   201
	    }
nkeynes@185
   202
	    length += avail;
nkeynes@185
   203
	    if( avail == 0 ) {
nkeynes@185
   204
		/* Should never happen */
nkeynes@185
   205
		printf( "[IDE] Unexpected read length 0\n" );
nkeynes@185
   206
		return -1;
nkeynes@185
   207
	    }
nkeynes@185
   208
	} else {
nkeynes@185
   209
	    if( status&0x01 ) {
nkeynes@185
   210
		printf( "[IDE] ERROR! (%02X)\n", status );
nkeynes@243
   211
		return -1;
nkeynes@185
   212
	    } else if( (status&0x08) == 0 ) {
nkeynes@185
   213
		/* No more data */
nkeynes@185
   214
		return length;
nkeynes@185
   215
	    } else {
nkeynes@185
   216
		printf( "[IDE] Unexpected status result: %02X\n", status );
nkeynes@185
   217
		return -1;
nkeynes@185
   218
	    }
nkeynes@185
   219
	}
nkeynes@185
   220
    }
nkeynes@185
   221
}
nkeynes@185
   222
nkeynes@185
   223
int ide_read_dma( char *buf, int buflen ) 
nkeynes@185
   224
{
nkeynes@185
   225
    int status;
nkeynes@185
   226
    
nkeynes@185
   227
    long_write( IDE_DMA_CTL1, 1 );
nkeynes@185
   228
    long_write( IDE_DMA_CTL2, 1 );
nkeynes@185
   229
    
nkeynes@185
   230
    printf( "Started DMA\n" );
nkeynes@185
   231
    ide_dump_registers();
nkeynes@185
   232
    
nkeynes@185
   233
    ide_wait_irq();
nkeynes@185
   234
    printf( "After IRQ\n" );
nkeynes@185
   235
    ide_dump_registers();
nkeynes@185
   236
    long_write( IDE_DMA_CTL1, 0 );
nkeynes@185
   237
    status = ide_wait_dma();
nkeynes@185
   238
    printf( "After DMA finished\n");
nkeynes@185
   239
    ide_dump_registers();
nkeynes@185
   240
    if( status != 0 ) {
nkeynes@185
   241
	return -1;
nkeynes@185
   242
    }
nkeynes@185
   243
    status = long_read(ASIC_STATUS0);
nkeynes@185
   244
    if( (status & (1<<14)) == 0 ) {
nkeynes@185
   245
	printf( "DMARQ cleared already\n");
nkeynes@185
   246
    } else {
nkeynes@185
   247
	/*
nkeynes@185
   248
	status &= ~(1<<14);
nkeynes@185
   249
	long_write(ASIC_STATUS0, status);
nkeynes@185
   250
	status = long_read(ASIC_STATUS0);
nkeynes@185
   251
	*/
nkeynes@185
   252
	byte_read(IDE_STATUS );
nkeynes@185
   253
	if( (status & (1<<14)) == 0 ) {
nkeynes@185
   254
	    printf( "DMARQ cleared successfully\n" );
nkeynes@185
   255
	} else {
nkeynes@185
   256
	    printf( "DMARQ not cleared: %08X\n", long_read(ASIC_STATUS0) );
nkeynes@185
   257
	}
nkeynes@185
   258
    }
nkeynes@185
   259
    status = ide_wait_ready();
nkeynes@185
   260
    printf( "After IDE ready\n");
nkeynes@185
   261
    ide_dump_registers();
nkeynes@185
   262
    if( status != 0 ) {
nkeynes@185
   263
	return -1;
nkeynes@185
   264
    }
nkeynes@185
   265
    return long_read( IDE_DMA_STATUS );
nkeynes@185
   266
}
nkeynes@185
   267
nkeynes@185
   268
int ide_do_packet_command_pio( char *cmd, char *buf, int length ) 
nkeynes@185
   269
{
nkeynes@185
   270
    ide_write_command_packet( cmd, 0 );
nkeynes@185
   271
    length = ide_read_pio( buf, length );
nkeynes@185
   272
    return length;
nkeynes@185
   273
}
nkeynes@185
   274
nkeynes@185
   275
int ide_do_packet_command_dma( char *cmd, char *buf, int length )
nkeynes@185
   276
{
nkeynes@185
   277
    long_write( QUEUECR0, 0x10 );
nkeynes@185
   278
    long_write( QUEUECR1, 0x10 );
nkeynes@185
   279
    long_write( IDE_DMA_MAGIC, IDE_DMA_MAGIC_VALUE );
nkeynes@185
   280
    long_write( IDE_DMA_ADDR, (unsigned int)buf );
nkeynes@185
   281
    long_write( IDE_DMA_SIZE, length );
nkeynes@185
   282
    long_write( IDE_DMA_DIR, 1 );
nkeynes@185
   283
    ide_write_command_packet( cmd, 1 );
nkeynes@185
   284
    length = ide_read_dma( buf, length );
nkeynes@185
   285
    return length;
nkeynes@185
   286
}
nkeynes@185
   287
nkeynes@243
   288
void ide_activate() {
nkeynes@243
   289
  register unsigned long p, x;
nkeynes@243
   290
nkeynes@243
   291
  /* Reactivate GD-ROM drive */
nkeynes@243
   292
nkeynes@243
   293
  *((volatile unsigned long *)0xa05f74e4) = 0x1fffff;
nkeynes@243
   294
  for(p=0; p<0x200000/4; p++)
nkeynes@243
   295
    x = ((volatile unsigned long *)0xa0000000)[p];
nkeynes@243
   296
}
nkeynes@243
   297
nkeynes@243
   298
nkeynes@185
   299
int ide_init()
nkeynes@185
   300
{
nkeynes@243
   301
    ide_activate();
nkeynes@243
   302
nkeynes@185
   303
    if( ide_wait_ready() )
nkeynes@185
   304
	return -1;
nkeynes@185
   305
nkeynes@185
   306
    /** Set Default PIO mode */
nkeynes@185
   307
    byte_write( IDE_FEATURE, 0x03 );
nkeynes@185
   308
    byte_write( IDE_COUNT, 0x0B );
nkeynes@185
   309
    byte_write( IDE_COMMAND, 0xEF );
nkeynes@185
   310
nkeynes@185
   311
    if( ide_wait_ready() )
nkeynes@185
   312
	return -1;
nkeynes@185
   313
    
nkeynes@185
   314
    /** Set Multi-word DMA mode 2 */
nkeynes@185
   315
    long_write( 0xA05F7490, 0x222 );
nkeynes@185
   316
    long_write( 0xA05F7494, 0x222 );
nkeynes@185
   317
    byte_write( IDE_FEATURE, 0x03 );
nkeynes@185
   318
    byte_write( IDE_COUNT, 0x22 );
nkeynes@185
   319
    byte_write( IDE_COMMAND, 0xEF );
nkeynes@185
   320
    if( ide_wait_ready() )
nkeynes@185
   321
	return -1;
nkeynes@185
   322
nkeynes@185
   323
    word_write( 0xA05F7480, 0x400 );
nkeynes@185
   324
    long_write( 0xA05F7488, 0x200 );
nkeynes@185
   325
    long_write( 0xA05F748C, 0x200 );
nkeynes@185
   326
    long_write( 0xA05F74A0, 0x2001 );
nkeynes@185
   327
    long_write( 0xA05F74A4, 0x2001 );
nkeynes@185
   328
    long_write( 0xA05F74B4, 0x0001 );
nkeynes@185
   329
}
nkeynes@185
   330
nkeynes@185
   331
int ide_sense_error( char *buf ) 
nkeynes@185
   332
{
nkeynes@185
   333
    char cmd[12] = { 0x13,0,0,0, 10,0,0,0, 0,0,0,0 };
nkeynes@185
   334
    return ide_do_packet_command_pio( cmd, buf, 10 );
nkeynes@185
   335
}
nkeynes@185
   336
nkeynes@185
   337
void ide_print_sense_error()
nkeynes@185
   338
{
nkeynes@185
   339
    char buf[10];
nkeynes@185
   340
    if( ide_sense_error(buf) != 10 ) {
nkeynes@185
   341
	printf( "ERROR - Sense error failed!\n" );
nkeynes@185
   342
	return;
nkeynes@185
   343
    }
nkeynes@185
   344
    int major = buf[2] & 0xFF;
nkeynes@185
   345
    int minor = buf[8] & 0xFF;
nkeynes@185
   346
    printf( "[IDE] Error code %02X,%02X\n", major, minor );
nkeynes@185
   347
}
nkeynes@185
   348
nkeynes@185
   349
int ide_test_ready()
nkeynes@185
   350
{
nkeynes@185
   351
    char cmd[12] = { 0,0,0,0, 0,0,0,0, 0,0,0,0 };
nkeynes@185
   352
    int length = ide_do_packet_command_pio( cmd, NULL, 0 );
nkeynes@185
   353
    return length;
nkeynes@185
   354
}
nkeynes@185
   355
nkeynes@185
   356
int ide_read_toc( char *buf, int length ) 
nkeynes@185
   357
{
nkeynes@185
   358
    char cmd[12] = { 0x14,0,0,0, 0x98,0,0,0, 0,0,0,0 };
nkeynes@185
   359
    return ide_do_packet_command_pio( cmd, buf, length );
nkeynes@185
   360
}
nkeynes@185
   361
nkeynes@185
   362
int ide_get_session( int session, struct gdrom_session *session_data )
nkeynes@185
   363
{
nkeynes@185
   364
    char cmd[12] = {0x15, 0, session, 0, 6,0,0,0, 0,0,0,0 };
nkeynes@185
   365
    char buf[6];
nkeynes@185
   366
    int length = ide_do_packet_command_pio( cmd, buf, sizeof(buf) );
nkeynes@185
   367
    if( length < 0 )
nkeynes@185
   368
	return length;
nkeynes@185
   369
    if( length != 6 )
nkeynes@185
   370
	return -1;
nkeynes@185
   371
    assert(length == 6);
nkeynes@185
   372
    session_data->track = ((int)buf[2])&0xFF;
nkeynes@185
   373
    session_data->lba = (((int)buf[3])&0xFF) << 16 | 
nkeynes@185
   374
	(((int)buf[4])&0xFF) << 8 | 
nkeynes@185
   375
	(((int)buf[5])&0xFF);
nkeynes@185
   376
    return 0;
nkeynes@185
   377
}
nkeynes@185
   378
nkeynes@185
   379
int ide_spinup( )
nkeynes@185
   380
{
nkeynes@185
   381
    char cmd[12] = {0x70,0x1F,0,0, 0,0,0,0, 0,0,0,0};
nkeynes@185
   382
    int length = ide_do_packet_command_pio( cmd, NULL, 0 );
nkeynes@185
   383
    return length;
nkeynes@185
   384
}
nkeynes@185
   385
nkeynes@185
   386
int ide_unknown71( char *buf, int length )
nkeynes@185
   387
{
nkeynes@185
   388
    char cmd[12] = {0x71,0,0,0, 0,0,0,0, 0,0,0,0};
nkeynes@185
   389
    return ide_do_packet_command_pio( cmd, buf, length );
nkeynes@185
   390
}
nkeynes@185
   391
nkeynes@185
   392
int ide_read_sector_pio( uint32_t sector, uint32_t count, int mode,
nkeynes@185
   393
			 char *buf, int length )
nkeynes@185
   394
{
nkeynes@185
   395
    char cmd[12] = { 0x30,0,0,0, 0,0,0,0, 0,0,0,0 };
nkeynes@185
   396
nkeynes@185
   397
    cmd[1] = mode;
nkeynes@185
   398
    cmd[2] = (sector>>16)&0xFF;
nkeynes@185
   399
    cmd[3] = (sector>>8)&0xFF;
nkeynes@185
   400
    cmd[4] = sector&0xFF;
nkeynes@185
   401
    cmd[8] = (count>>16)&0xFF;
nkeynes@185
   402
    cmd[9] = (count>>8)&0xFF;
nkeynes@185
   403
    cmd[10] = count&0xFF;
nkeynes@185
   404
    return ide_do_packet_command_pio( cmd, buf, length );
nkeynes@185
   405
}
nkeynes@185
   406
nkeynes@185
   407
nkeynes@185
   408
int ide_read_sector_dma( uint32_t sector, uint32_t count, int mode,
nkeynes@185
   409
			 char *buf, int length )
nkeynes@185
   410
{
nkeynes@185
   411
    char cmd[12] = { 0x30,0,0,0, 0,0,0,0, 0,0,0,0 };
nkeynes@185
   412
nkeynes@185
   413
    cmd[1] = mode;
nkeynes@185
   414
    cmd[2] = (sector>>16)&0xFF;
nkeynes@185
   415
    cmd[3] = (sector>>8)&0xFF;
nkeynes@185
   416
    cmd[4] = sector&0xFF;
nkeynes@185
   417
    cmd[8] = (count>>16)&0xFF;
nkeynes@185
   418
    cmd[9] = (count>>8)&0xFF;
nkeynes@185
   419
    cmd[10] = count&0xFF;
nkeynes@185
   420
    return ide_do_packet_command_dma( cmd, buf, length );
nkeynes@185
   421
}
nkeynes@185
   422
nkeynes@185
   423
int ide_read_something( )
nkeynes@185
   424
{
nkeynes@185
   425
    char cmd[12] = { 0x12,0,0,0, 0x0a,0,0,0, 0,0,0,0 };
nkeynes@185
   426
    char result[10];
nkeynes@185
   427
    ide_do_packet_command_pio( cmd, result, 10 );
nkeynes@185
   428
    return 0;
nkeynes@243
   429
}
nkeynes@243
   430
nkeynes@243
   431
int ide_read_status( char *buf, int length )
nkeynes@243
   432
{
nkeynes@243
   433
    char cmd[12] = { 0x40,0,0,0, 0xFF,0,0,0, 0,0,0,0 };
nkeynes@243
   434
nkeynes@243
   435
    return ide_do_packet_command_pio( cmd, buf, length );
nkeynes@243
   436
}
nkeynes@243
   437
		     
nkeynes@243
   438
int ide_play_cd( char *buf, int length )
nkeynes@243
   439
{
nkeynes@243
   440
    char cmd[12] = { 0x21, 0x04,0,0, 0,0,0,0, 0,0,0,0 };
nkeynes@243
   441
    return ide_do_packet_command_pio( cmd, buf, length );
nkeynes@243
   442
}
.