OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc2/] [or1ksim/] [peripheral/] [atadevice_cmdi.c] - Blame information for rev 876

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 876 rherveille
/*
2
    atadevice_cmdi.c -- ATA Device simulation
3
    Command interpreter for the simulated harddisk.
4
    Copyright (C) 2002 Richard Herveille, rherveille@opencores.org
5
 
6
    This file is part of OpenRISC 1000 Architectural Simulator
7
 
8
    This program is free software; you can redistribute it and/or modify
9
    it under the terms of the GNU General Public License as published by
10
    the Free Software Foundation; either version 2 of the License, or
11
    (at your option) any later version
12
 
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17
 
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
*/
22
 
23
/*
24
 For fun, count the number of FIXMEs :-(
25
*/
26
 
27
#include "messages.h"
28
#include "atadevice.h"
29
#include "atadevice_cmdi.h"
30
#include "atacmd.h"
31
 
32
int ata_device_execute_cmd(ata_device *device)
33
{
34
  /*display debug information                                         */
35
  ata_device_debug(2, "ata_device_execute_command called with command = 0x%02X\n", device->regs.command);
36
 
37
  /* execute the commands */
38
  switch (device->regs.command) {
39
 
40
      case DEVICE_RESET :
41
         ata_device_reset_cmd(device);
42
         return 0;
43
 
44
      case EXECUTE_DEVICE_DIAGNOSTICS :
45
        ata_execute_device_diagnostics_cmd(device);
46
        return 0;
47
 
48
      case IDENTIFY_DEVICE :
49
        ata_identify_device_cmd(device);
50
        return 0;
51
 
52
      case INITIALIZE_DEVICE_PARAMETERS :
53
        ata_initialize_device_parameters_cmd(device);
54
        return 0;
55
 
56
      case READ_SECTORS :
57
        ata_read_sectors_cmd(device);
58
 
59
      default :
60
        return -1;
61
  }
62
}
63
 
64
 
65
 
66
/*
67
  A T A _ S E T _ D E V I C E _ S I G N A T U R E
68
 
69
  called whenever a command needs to signal the device type (packet, non-packet)
70
*/
71
void ata_set_device_signature(ata_device *device, int signature)
72
{
73
    if (signature)
74
    {
75
      /* place PACKET Command feature set signature in register block   */
76
      device->regs.sector_count  = 0x01;
77
      device->regs.sector_number = 0x01;
78
      device->regs.cylinder_low  = 0x14;
79
      device->regs.cylinder_high = 0xEB;
80
    }
81
    else
82
    {
83
      /* place NON_PACKET Command feature set signature in register block */
84
      device->regs.sector_count  = 0x01;
85
      device->regs.sector_number = 0x01;
86
      device->regs.cylinder_low  = 0x00;
87
      device->regs.cylinder_high = 0x00;
88
      device->regs.device_head   = 0x00;
89
    }
90
}
91
 
92
 
93
/*
94
  A T A _ D E V I C E _ R E S E T
95
*/
96
void ata_device_reset_cmd(ata_device *device)
97
{
98
  /* print debug information                                          */
99
  ata_device_debug(2, "executing command 'device reset'\n");
100
 
101
  if (!device->packet)
102
      MSG_WARNING("executing DEVICE_RESET on non-packet device.");
103
 
104
  ata_execute_device_diagnostics_cmd(device);
105
}
106
 
107
 
108
/*
109
  A T A _ E X E C U T E _ D E V I C E _ D I A G N O S T I C S
110
*/
111
void ata_execute_device_diagnostics_cmd(ata_device *device)
112
{
113
  /* print debug information                                          */
114
  ata_device_debug(2, "executing command 'execute_device_diagnostics'\n");
115
 
116
  /* clear SRST bit, if set                                           */
117
  device->regs.device_control &= ~ATA_DCR_RST;
118
 
119
  /* content of features register is undefined                        */
120
 
121
  /*
122
      set device error register
123
      Device0: 0x01 = Device0 passed & Device1 passed/not present
124
      Device1: 0x01 = Device1 passed
125
  */
126
  device->regs.error = 0x01;
127
  /* something about DASP- and error_register_bit7                    */
128
  /* if device1 is not present or if device1 is present and passed    */
129
  /* diagnostics, than bit7 should be cleared.                        */
130
  /* This means we always clear bit7                                  */
131
 
132
 
133
  /* check if device implements packet protocol                       */
134
  if (device->packet)
135
  {
136
    /* place PACKET command feature set signature in register block   */
137
    ata_set_device_signature(device, PACKET_SIGNATURE);
138
 
139
    device->regs.status &= 0xf8;
140
 
141
    if (device->regs.command == DEVICE_RESET)
142
      device->regs.device_head = device->regs.device_head & ATA_DHR_LBA;
143
    else
144
      device->regs.device_head = 0x00;
145
  }
146
  else
147
  {
148
    /* place NON_PACKET Command feature set signature in register block */
149
    ata_set_device_signature(device, !PACKET_SIGNATURE);
150
 
151
    device->regs.status &= 0x82;
152
  }
153
 
154
 
155
  /* we passed diagnostics, so set the PDIAG-line                     */
156
  device->sigs.pdiago = 1;
157
}
158
 
159
 
160
 
161
/*
162
  A T A _ I D E N T I F Y _ D E V I C E
163
*/
164
void ata_identify_device_cmd(ata_device *device)
165
{
166
  unsigned char  *chksum_buf, chksum;
167
  unsigned short *buf;
168
  int            n;
169
  unsigned int   tmp;
170
 
171
  /* print debug information                                          */
172
  ata_device_debug(2, "ata_device executing command 'identify device'\n");
173
 
174
  /* reset databuffer-counter                                         */
175
  device->settings.dbuf_cnt = 0;
176
 
177
  buf = device->settings.dbuf;
178
  chksum_buf = (char *)buf;
179
 
180
  /*
181
    if number_of_available_sectors (==device->size / BYTES_PER_SECTOR) < 16,514,064 then
182
       support CHS translation where:
183
    LBA = ( ((cylinder_number*heads_per_cylinder) +head_number) *sectors_per_track ) +sector_number -1;
184
 
185
    Cylinders : 1-255   (or max.cylinders)
186
    Heads     : 0-15    (or max.heads    )
187
    Sectors   : 0-65535 (or max.sectors  )
188
  */
189
 
190
  /*
191
   1) Word 1 shall contain the number of user-addressable logical cylinders in the default CHS
192
      translation. If the content of words (61:60) is less than 16,514,064 then the content of word 1
193
      shall be greater than or equal to one and less than or equal to 65,535. If the content of words
194
      (61:60) is greater than or equal to 16,514,064 then the content of
195
      word 1 shall be equal to 16,383.
196
   2) Word 3 shall contain the number of user-addressable logical heads in the default CHS
197
      translation. The content of word 3 shall be greater than or equal to one and less than or equal to
198
      16. For compatibility with some BIOSs, the content of word 3 may be equal to 15 if the content of
199
      word 1 is greater than 8192.
200
   3) Word 6 shall contain the number of user-addressable logical sectors in the default CHS
201
      translation. The content of word 6 shall be greater than or equal to one and less than or equal to
202
      63.
203
   4) [(The content of word 1) * (the content of word 3) * (the content of word 6)] shall be less than or
204
      equal to 16,514,064
205
   5) Word 54 shall contain the number of user-addressable logical cylinders in the current CHS
206
      translation. The content of word 54 shall be greater than or equal to one and less than or
207
      equal to 65,535. After power-on of after a hardware reset the content of word 54 shall be equal to
208
      the content of word 1.
209
   6) Word 55 shall contain the number of user-addressable logical heads in the current CHS
210
      translation. The content of word 55 shall be greater than or equal to one and less than or equal
211
      to 16. After power-on or after a hardware reset the content of word 55 shall equal the content of
212
      word 3.
213
   7) Word 56 shall contain the user-addressable logical sectors in the current CHS
214
      translation. The content of word 56 should be equal to 63 for compatibility with all BIOSs.
215
      However, the content of word 56 may be greater than or equal to one and less than or equal to
216
      255. At power-on or after a hardware reset the content of word 56 shall equal the content of
217
      word 6.
218
   8) Words (58:57) shall contain the user-addressable capacity in sectors for the current CHS
219
      translation. The content of words (58:57) shall equal [(the content of word 54) * (the content of
220
      word 55) * (the content of word 56)] The content of words (58:57) shall be less than or equal to
221
      16,514,064. The content of words (58:57) shall be less than or equal to the content of words
222
      (61:60).
223
   9) The content of words 54, 55, 56, and (58:57) may be affected by the host issuing an INITIALIZE
224
      DEVICE PARAMETERS command.
225
   10)If the content of words (61:60) is greater than 16,514,064 and if the device does not support CHS
226
      addressing, then the content of words 1, 3, 6, 54, 55, 56, and (58:57) shall equal zero. If the
227
      content of word 1, word 3, or word 6 equals zero, then the content of words 1, 3, 6, 54, 55, 56,
228
      and (58:57) shall equal zero.
229
   11)Words (61:60) shall contain the total number of user-addressable sectors. The content of words
230
      (61:60) shall be greater than or equal to one and less than or equal to 268,435,456.
231
   12)The content of words 1, 54, (58:57), and (61:60) may be affected by the host issuing a SET MAX
232
      ADDRESS command.
233
  */
234
 
235
 
236
  /* check if this is a NON-PACKET device                             */
237
  if (device->packet)
238
  {
239
    /*
240
      This is a PACKET device.
241
      Respond by placing PACKET Command feature set signature in block registers.
242
      Abort command.
243
    */
244
    ata_device_debug(1, "'identify_device' command: This is a PACKET device\n");
245
 
246
    ata_set_device_signature(device, PACKET_SIGNATURE);
247
    device->regs.status = ATA_SR_ERR;
248
    device->regs.error = ATA_ERR_ABT;
249
  }
250
  else
251
  {
252
    /* start filling buffer                                           */
253
 
254
    /*
255
       word 0: General configuration
256
               15  : 0 = ATA device
257
               14-8: retired
258
               7   : 1 = removable media device (not set)
259
               6   : 1 = not-removable controller and/or device (set)
260
               5-0 : retired and/or always set to zero
261
    */
262
    *buf++ = 0x0040;
263
 
264
    /*
265
       word 1: Number of logical cylinders
266
 
267
       >=1, <= 65535
268
    */
269
    if ( (tmp = device->size / BYTES_PER_SECTOR) >= 16514064 )
270
        *buf++ = 16383;
271
    else
272
      if ( (tmp /= (HEADS +1) * SECTORS) > 65535 )
273
          *buf++ = 65535;
274
      else
275
          *buf++ = tmp;
276
 
277
    /*
278
       word 2: Specific configuration
279
 
280
       0x37c8: Device requires SET_FEATURES subcommand to spinup after power-on
281
               and IDENTIFY_DEVICE response is incomplete
282
       0x738c: Device requires SET_FEATURES subcommand to spinup after power-on
283
               and IDENTIFY_DEVICE response is complete
284
       0x8c73: Device does not require SET_FEATURES subcommand to spinup after power-on
285
               and IDENTIFY_DEVICE response is incomplete
286
       0xc837: Device does not require SET_FEATURES subcommand to spinup after power-on
287
               and IDENTIFY_DEVICE response is complete
288
 
289
       pick-one
290
    */
291
    *buf++ = 0xc837;
292
 
293
    /*
294
       word 3: Number of logical heads
295
 
296
       >= 1, <= 16
297
 
298
       set to 15 if word1 > 8192 (BIOS compatibility)
299
    */
300
    *buf++ = HEADS;
301
 
302
    /*
303
       word 5-4: retired
304
    */
305
    buf += 2;
306
 
307
    /*
308
       word 6: Number of logical sectors per logical track
309
 
310
       >= 1, <= 63
311
    */
312
    *buf++ = SECTORS;
313
 
314
    /*
315
       word 8-7: Reserved by the CompactFLASH association
316
    */
317
    buf += 2;
318
 
319
    /*
320
       word 9: retired
321
    */
322
    buf++;
323
 
324
    /*
325
       word 19-10: Serial number (ASCII)
326
    */
327
    /*           " or1ksim ata_device "                               */
328
    *buf++ = (' ' << 8) | 'o';
329
    *buf++ = ('r' << 8) | '1';
330
    *buf++ = ('k' << 8) | 's';
331
    *buf++ = ('i' << 8) | 'm';
332
    *buf++ = (' ' << 8) | 'a';
333
    *buf++ = ('t' << 8) | 'a';
334
    *buf++ = ('_' << 8) | 'd';
335
    *buf++ = ('e' << 8) | 'v';
336
    *buf++ = ('i' << 8) | 'c';
337
    *buf++ = ('e' << 8) | ' ';
338
 
339
    /*
340
       word 22   : obsolete
341
       word 21-20: retired
342
    */
343
    buf += 3;
344
 
345
    /*
346
       word 26-23: Firmware revision
347
    */
348
    strncpy(buf, FIRMWARE, 8);
349
    buf += 4;
350
 
351
    /*
352
       word 46-27: Model number
353
       note the shuffled character order again.
354
       Damn Big/Little endian thingie
355
    */
356
    /*           "(C)2002 Richard Herveille  opencores.org"           */
357
    *buf++ = ('(' << 8) | 'C';
358
    *buf++ = (')' << 8) | '2';
359
    *buf++ = ('0' << 8) | '0';
360
    *buf++ = ('2' << 8) | ' ';
361
    *buf++ = ('R' << 8) | 'i';
362
    *buf++ = ('c' << 8) | 'h';
363
    *buf++ = ('a' << 8) | 'r';
364
    *buf++ = ('d' << 8) | ' ';
365
    *buf++ = ('H' << 8) | 'e';
366
    *buf++ = ('r' << 8) | 'v';
367
    *buf++ = ('e' << 8) | 'i';
368
    *buf++ = ('l' << 8) | 'l';
369
    *buf++ = ('e' << 8) | ' ';
370
    *buf++ = ('o' << 8) | 'p';
371
    *buf++ = ('e' << 8) | 'n';
372
    *buf++ = ('c' << 8) | 'o';
373
    *buf++ = ('r' << 8) | 'e';
374
    *buf++ = ('s' << 8) | '.';
375
    *buf++ = ('o' << 8) | 'r';
376
    *buf++ = ('g' << 8) | ' ';
377
 
378
    /*
379
       word 47:
380
           15-8: 0x80
381
            7-0: 0x00 reserved
382
                 0x01-0xff maximum number of sectors to be transfered
383
                           per interrupt on a READ/WRITE MULTIPLE command
384
    */
385
    *buf++ = 0x8001;
386
 
387
    /*
388
       word 48: reserved
389
    */
390
    buf++;
391
 
392
    /*
393
       word 49: Capabilities
394
           15-14: reserved for IDENTIFY PACKET DEVICE
395
           13   : 1=standby timers are supported
396
                  0=standby timers are handled by the device FIXME
397
           12   : reserved for IDENTIFY PACKET DEVICE
398
           11   : 1=IORDY supported
399
                  0=IORDY may be supported
400
           10   : 1=IORDY may be disabled
401
            9   : set to one
402
            8   : set to one
403
            7-0 : retired
404
    */
405
    *buf++ = 0x0f00;
406
 
407
    /*
408
       word 50: Capabilities
409
           15  : always cleared to zero
410
           14  : always set to one
411
           13-1: reserved
412
 
413
    */
414
    *buf++ = 0x4000;
415
 
416
    /*
417
       word 52-51: obsolete
418
    */
419
    buf += 2;
420
 
421
    /*
422
       word 53:
423
           15-3: Reserved
424
           2   : 1=value in word 88 is valid
425
                 0=value in word 88 is not valid
426
           1   : 1=value in word 64-70 is valid
427
                 0=value in word 64-70 is not valid
428
 
429
                 0=value in word 54-58 is not valid
430
    */
431
    *buf++ = 0x0007;
432
 
433
 
434
    /*
435
       word 54: number of current logical cylinders (0-65535)
436
    */
437
    if ( (tmp = device->size / BYTES_PER_SECTOR) > 16514064 )
438
        tmp = 16514064;
439
 
440
    tmp /= (device->settings.heads_per_cylinder +1) * (device->settings.sectors_per_track);
441
    if (tmp > 65535)
442
        *buf++ = 65535;
443
    else
444
        *buf++ = tmp;
445
 
446
    /*
447
       word 55: number of current logical heads, (0-15)
448
    */
449
    *buf++ = device->settings.heads_per_cylinder +1;
450
 
451
    /*
452
       word 56: number of current logical sectors per track (1-255)
453
    */
454
    *buf++ = device->settings.sectors_per_track;
455
 
456
    /*
457
       word 58-57: current capacity in sectors
458
    */
459
    tmp = *(buf-3) * *(buf-2) * *(buf-1);
460
    *buf++ = tmp >> 16;
461
    *buf++ = tmp & 0xffff;
462
 
463
    /*
464
       word 59:
465
           15-9: reserved
466
           8   : 1=multiple sector setting is valid
467
           7-0 : current setting for number of sectors to be transfered
468
                 per interrupt on a READ/WRITE MULTIPLE command
469
    */
470
    *buf++ = 0x0001; // not really a FIXME
471
 
472
    /*
473
       word 60-61: Total number of user addressable sectors (LBA only)
474
    */
475
    *buf++ = (device->size / BYTES_PER_SECTOR) >> 16;
476
    *buf++ = (device->size / BYTES_PER_SECTOR);
477
 
478
    /*
479
       word 62: obsolete
480
    */
481
    buf++;
482
 
483
    /* FIXME
484
       word 63: DMA settings
485
           15-11: Reserved
486
           10   : 1=Multiword DMA Mode 2 is selected
487
                  0=Multiword DMA Mode 2 is not selected
488
            9   : 1=Multiword DMA Mode 1 is selected
489
                  0=Multiword DMA Mode 1 is not selected
490
            8   : 1=Multiword DMA Mode 0 is selected
491
                  0=Multiword DMA Mode 0 is not selected
492
            7-3 : Reserved
493
            2   : Multiword DMA Mode 2 and below are supported
494
            1   : Multiword DMA Mode 1 and below are supported
495
 
496
    */
497
    #if   (MWDMA == -1)
498
      *buf++ = 0x0000;
499
    #elif (MWDMA == 2)
500
      *buf++ = 0x0007;
501
    #elif (MWDMA == 1)
502
      *buf++ = 0x0003;
503
    #else
504
      *buf++ = 0x0001;
505
    #endif
506
 
507
    /*
508
       word 64:
509
           15-8: reserved
510
            7-0: Advanced PIO modes supported
511
 
512
            7-2: reserved
513
            1  : PIO mode4 supported
514
 
515
    */
516
    *buf++ = 0x0003;
517
 
518
    /*
519
       word 65: Minimum Multiword DMA transfer cycle time per word (nsec)
520
    */
521
    *buf++ = MIN_MWDMA_CYCLE_TIME;
522
 
523
    /*
524
       word 66: Manufacturer's recommended Multiword DMA transfer cycle time per word (nsec)
525
    */
526
    *buf++ = RECOMMENDED_MWDMA_CYCLE_TIME;
527
 
528
 
529
    /*
530
       word 67: Minimum PIO transfer cycle time per word (nsec), without IORDY flow control
531
    */
532
    *buf++ = MIN_PIO_CYCLE_TIME_NO_IORDY;
533
 
534
    /*
535
       word 68: Minimum PIO transfer cycle time per word (nsec), with IORDY flow control
536
    */
537
    *buf++ = MIN_PIO_CYCLE_TIME_IORDY;
538
 
539
    /*
540
       word 69-70: reserved for future command overlap and queueing
541
            71-74: reserved for IDENTIFY PACKET DEVICE command
542
    */
543
    buf += 6;
544
 
545
    /*
546
       word 75: Queue depth
547
           15-5: reserved
548
            4-0: queue depth -1
549
    */
550
    *buf++ = SUPPORT_READ_WRITE_DMA_QUEUED ? QUEUE_DEPTH : 0x0000;
551
 
552
    /*
553
       word 76-79: reserved
554
    */
555
    buf += 4;
556
 
557
    /*
558
       word 80: MAJOR ATA version
559
                We simply report that we do not report a version
560
 
561
                You can also set bits 5-2 to indicate compliancy to
562
                ATA revisions 5-2 (1 & 0 are obsolete)
563
    */
564
    *buf++ = 0x0000;
565
 
566
    /*
567
       word 81: MINOR ATA version
568
                We report ATA/ATAPI-5 T13 1321D revision 3 (0x13)
569
    */
570
    *buf++ = 0x0013;
571
 
572
    /*
573
       word 82: Command set supported
574
    */
575
    *buf++ = 0                           << 15 | \ /* obsolete        */
576
             SUPPORT_NOP_CMD             << 14 | \
577
             SUPPORT_READ_BUFFER_CMD     << 13 | \
578
             SUPPORT_WRITE_BUFFER_CMD    << 12 | \
579
 
580
             SUPPORT_HOST_PROTECTED_AREA << 10 | \
581
             SUPPORT_DEVICE_RESET_CMD    << 9  | \
582
             SUPPORT_SERVICE_INTERRUPT   << 8  | \
583
             SUPPORT_RELEASE_INTERRUPT   << 7  | \
584
             SUPPORT_LOOKAHEAD           << 6  | \
585
             SUPPORT_WRITE_CACHE         << 5  | \
586
 
587
             SUPPORT_POWER_MANAGEMENT    << 3  | \
588
             SUPPORT_REMOVABLE_MEDIA     << 2  | \
589
             SUPPORT_SECURITY_MODE       << 1  | \
590
             SUPPORT_SMART               << 0
591
    ;
592
 
593
    /*
594
       word 83: Command set supported
595
    */
596
    *buf++ = 0                           << 15 | \ /* cleared to zero */
597
             1                           << 14 | \ /* set to one      */
598
 
599
             SUPPORT_SET_MAX             << 8  | \
600
 
601
                                                   /* project 1407DT  */
602
             SET_FEATURES_REQUIRED_AFTER_POWER_UP << 6  | \
603
             SUPPORT_POWER_UP_IN_STANDBY_MODE     << 5  | \
604
             SUPPORT_REMOVABLE_MEDIA_NOTIFICATION << 4  | \
605
             SUPPORT_APM                 << 3  | \
606
             SUPPORT_CFA                 << 2  | \
607
             SUPPORT_READ_WRITE_DMA_QUEUED        << 1  | \
608
             SUPPORT_DOWNLOAD_MICROCODE  << 0
609
    ;
610
 
611
    /*
612
       word 84: Command set/feature supported
613
    */
614
    *buf++ = 0                           << 15 | \ /* cleared to zero */
615
             1                           << 14     /* set to one      */
616
    ;                                              /* 0-13 reserved   */
617
 
618
    /*
619
       word 85: Command set enabled FIXME
620
    */
621
    *buf++ = 0                           << 15 | \ /* obsolete        */
622
             SUPPORT_NOP_CMD             << 14 | \
623
             SUPPORT_READ_BUFFER_CMD     << 13 | \
624
             SUPPORT_WRITE_BUFFER_CMD    << 12 | \
625
 
626
             SUPPORT_HOST_PROTECTED_AREA << 10 | \
627
             SUPPORT_DEVICE_RESET_CMD    << 9  | \
628
             SUPPORT_SERVICE_INTERRUPT   << 8  | \
629
             SUPPORT_RELEASE_INTERRUPT   << 7  | \
630
             SUPPORT_LOOKAHEAD           << 6  | \
631
             SUPPORT_WRITE_CACHE         << 5  | \
632
 
633
             SUPPORT_POWER_MANAGEMENT    << 3  | \
634
             SUPPORT_REMOVABLE_MEDIA     << 2  | \
635
             SUPPORT_SECURITY_MODE       << 1  | \
636
             SUPPORT_SMART               << 0
637
    ;
638
 
639
    /*
640
       word 86: Command set enables
641
    */
642
    *buf++ = 0                           << 9  | \ /* 15-9 reserved   */
643
             SUPPORT_SET_MAX             << 8  | \
644
 
645
                                                   /* project 1407DT  */
646
             SET_FEATURES_REQUIRED_AFTER_POWER_UP << 6  | \
647
             SUPPORT_POWER_UP_IN_STANDBY_MODE     << 5  | \
648
             SUPPORT_REMOVABLE_MEDIA_NOTIFICATION << 4  | \
649
             SUPPORT_APM                 << 3  | \
650
             SUPPORT_CFA                 << 2  | \
651
             SUPPORT_READ_WRITE_DMA_QUEUED        << 1  | \
652
             SUPPORT_DOWNLOAD_MICROCODE  << 0
653
    ;
654
 
655
    /*
656
       word 87: Command set/feature supported
657
    */
658
    *buf++ = 0                           << 15 | \ /* cleared to zero */
659
             1                           << 14     /* set to one      */
660
    ;                                              /* 0-13 reserved   */
661
 
662
    /*
663
       word 88: UltraDMA section
664
           15-13: reserved
665
           12   : 1=UltraDMA Mode 4 is selected
666
                  0=UltraDMA Mode 4 is not selected
667
           10   : 1=UltraDMA Mode 3 is selected
668
                  0=UltraDMA Mode 3 is not selected
669
           10   : 1=UltraDMA Mode 2 is selected
670
                  0=UltraDMA Mode 2 is not selected
671
            9   : 1=UltraDMA Mode 1 is selected
672
                  0=UltraDMA Mode 1 is not selected
673
            8   : 1=UltraDMA Mode 0 is selected
674
                  0=UltraDMA Mode 0 is not selected
675
            7-5 : Reserved
676
            4   : UltraDMA Mode 4 and below are supported
677
            3   : UltraDMA Mode 3 and below are supported
678
            2   : UltraDMA Mode 2 and below are supported
679
            1   : UltraDMA Mode 1 and below are supported
680
 
681
 
682
            Because the OCIDEC cores currently do not support
683
            UltraDMA we set all bits to zero
684
    */
685
    *buf++ = 0;
686
 
687
    /*
688
       word 89: Security sector erase unit completion time
689
 
690
       For now we report a 'value not specified'.
691
    */
692
    *buf++ = 0x0000; // not really a FIXME
693
 
694
    /*
695
       word 90: Enhanced security erase completion time
696
 
697
       For now we report a 'value not specified'.
698
    */
699
    *buf++ = 0x0000; // not really a FIXME
700
 
701
    /*
702
       word 91: Current advanced power management value
703
 
704
       For now set it to zero.
705
    */
706
    *buf++ = 0x0000; // FIXME
707
 
708
    /*
709
       word 92: Master Password Revision Code.
710
               We simply report that we do not support this.
711
    */
712
    *buf++ = 0x0000;
713
 
714
    /*
715
       word 93: Hardware reset result
716
    */
717
    if (device->settings.dev)
718
    {
719
      /* this is device1, clear device0 bits                                         */
720
      *buf++ = 0              << 15 | \
721
               1              << 14 | \
722
 
723
                                        /* 12-8 Device 1 hardware reset result       */
724
 
725
               device->sigs.pdiago << 11 | \ /* 1: Device1 did assert PDIAG               */
726
                                        /* 0: Device1 did not assert PDIAG           */
727
               3              <<  9 | \ /* Device1 determined device number by       */
728
                                        /* 00: reserved                              */
729
                                        /* 01: a jumper was used                     */
730
                                        /* 10: the CSEL signal was used              */
731
                                        /* 11: some other or unknown method was used */
732
               1              << 8      /* set to one                                */
733
      ;
734
    }
735
    else
736
    { /* FIXME bit 6 */
737
      /* this is device0, clear device1 bits                                         */
738
      *buf++ = 0              << 7 | \  /* reserved                                  */
739
 
740
                                        /* 0: Device0 does not respond for device1   */
741
               device->sigs.daspi  << 5 | \  /* 1: Device0 did detected DASP assertion    */
742
                                        /* 0: Device0 did not detect DASP assertion  */
743
               device->sigs.pdiagi << 4 | \  /* Device0 did detect PDIAG assertion        */
744
                                        /* Device0 did not detect PDIAG assertion    */
745
               1              << 3 | \  /* Device0 did pass diagnostics              */
746
               3              << 1 | \  /* Device0 determined device number by       */
747
                                        /* 00: reserved                              */
748
                                        /* 01: a jumper was used                     */
749
                                        /* 10: the CSEL signal was used              */
750
                                        /* 11: some other or unknown method was used */
751
               1              << 0      /* set to one                                */
752
      ;
753
    }
754
 
755
    /*
756
       word 94-126: Reserved
757
    */
758
    buf += 33;
759
 
760
    /*
761
       word 127: Removable Media Status Notification feature set support
762
           15-2: reserved
763
            1-0: 00 Removable media Status Notification not supported
764
                 01 Removable media Status Notification supported
765
                 10 reserved
766
                 11 reserved
767
    */
768
    *buf++ = SUPPORT_REMOVABLE_MEDIA_NOTIFICATION;
769
 
770
    /*
771
       word 128: Security status
772
           15-9: reserved
773
           8   : Security level, 0=high, 1=maximum
774
           7-6 : reserved
775
           5   : 1=enhanced security erase supported
776
           4   : 1=security count expired
777
           3   : 1=security frozen
778
           2   : 1=security locked
779
           1   : 1=security enabled
780
 
781
 
782
           for now we do not support security, set is to zero
783
    */
784
    *buf++ = 0;
785
 
786
    /*
787
       word 129-159: Vendor specific
788
    */
789
    buf += 31;
790
 
791
    /*
792
       word 160: CFA power mode 1
793
           15  : Word 160 supported
794
           14  : reserved
795
           13  : CFA power mode 1 is required for one or more commands
796
           12  : CFA power mode 1 disabled
797
           11-0: Maximum current in mA
798
    */
799
    *buf++ = 0;
800
 
801
    /*
802
       word 161-175: Reserved for the CompactFLASH Association
803
    */
804
    buf += 15;
805
 
806
    /*
807
       word 176-254: reserved
808
    */
809
    buf += 79;
810
 
811
    /*
812
       word 255: Integrity word
813
           15-8: Checksum
814
           7-0 : Signature
815
    */
816
    // set signature to indicate valid checksum
817
    *buf = 0x00a5;
818
 
819
    // calculate checksum
820
    chksum = 0;
821
    for (n=0; n < 511; n++)
822
      chksum += *chksum_buf++;
823
 
824
    *buf = ( (0-chksum) << 8) | 0x00a5;
825
 
826
    /* set status register bits                                       */
827
    device->regs.status = ATA_SR_DRDY;
828
  }
829
}
830
 
831
 
832
/*
833
  A T A _ I N I T I A L I Z E _ D E V I C E _ P A R A M E T E R S
834
*/
835
void ata_initialize_device_parameters_cmd(ata_device *device)
836
{
837
  /* print debug information                                          */
838
  ata_device_debug(2, "executing command 'initialize device parameters'\n");
839
 
840
  device->settings.sectors_per_track = device->regs.sector_count;
841
  device->settings.heads_per_cylinder = device->regs.device_head & ATA_DHR_H;
842
 
843
  /* set status register bits                                         */
844
  device->regs.status = 0;
845
}
846
 
847
 
848
/*
849
  A T A _ R E A D _ S E C T O R S
850
*/
851
void ata_read_sectors_cmd(ata_device *device)
852
{
853
  int sector_count;
854
  unsigned long lba;
855
 
856
  /* print debug information                                          */
857
  ata_device_debug(2, "executing command 'read sectors'\n");
858
 
859
 
860
  /* check if this is a NON-PACKET device                             */
861
  if (device->packet)
862
  {
863
    /*
864
      This is a PACKET device.
865
      Respond by placing PACKET Command feature set signature in block registers.
866
      Abort command.
867
    */
868
    ata_device_debug(1, "'identify_device' command: This is a PACKET device\n");
869
 
870
    ata_set_device_signature(device, PACKET_SIGNATURE);
871
    device->regs.status = ATA_SR_ERR;
872
    device->regs.error = ATA_ERR_ABT;
873
  }
874
  else
875
  {
876
    /* get the sector count                                           */
877
    if (device->regs.sector_count == 0)
878
        sector_count = 256;
879
    else
880
        sector_count = device->regs.sector_count;
881
 
882
    /* check if we are using CHS or LBA translation, fill in the bits */
883
    if (device->regs.device_head & ATA_DHR_LBA)
884
    {   /* we are using LBA translation                               */
885
        lba = (device->regs.device_head & ATA_DHR_H) << 24 | \
886
              (device->regs.cylinder_high          ) << 16 | \
887
              (device->regs.cylinder_low           ) <<  8 |
888
               device->regs.sector_number
889
        ;
890
    }
891
    else
892
    {   /* we are using CHS translation, calculate lba address        */
893
        lba  = (device->regs.cylinder_high << 16) | device->regs.cylinder_low;
894
        lba *= device->settings.heads_per_cylinder;
895
        lba += device->regs.device_head & ATA_DHR_H;
896
        lba *= device->settings.sectors_per_track;
897
        lba += device->regs.sector_number;
898
        lba -= 1;
899
    }
900
 
901
    /* check if sector within bounds                                  */
902
    if (lba > (device->size / BYTES_PER_SECTOR) )
903
    {   /* invalid sector address                                     */
904
        /* set the status & error registers                           */
905
        device->regs.status = ATA_SR_DRDY | ATA_SR_ERR;
906
        device->regs.error = ATA_ERR_IDNF;
907
    }
908
    else
909
    {   /* go ahead, read the bytestream                              */
910
        lba *= BYTES_PER_SECTOR;
911
 
912
        /* set the file-positon pointer to the start of the sector    */
913
        fseek(device->stream, lba, SEEK_SET);
914
 
915
        /* get the bytes from the stream                              */
916
        fread(device->settings.dbuf, BYTES_PER_SECTOR, 1, device->stream);
917
 
918
        /* set status register bits                                   */
919
        device->regs.status = ATA_SR_DRDY;
920
    }
921
  }
922
}
923
 
924
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.