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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0/] [or1ksim/] [peripheral/] [atadevice_cmdi.c] - Blame information for rev 919

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 919 rherveille
 
298 876 rherveille
       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 919 rherveille
    /*           " www.opencores.org  "                               */
328
    *buf++ = (' ' << 8) | 'w';
329
    *buf++ = ('w' << 8) | 'w';
330
    *buf++ = ('.' << 8) | 'o';
331
    *buf++ = ('p' << 8) | 'e';
332
    *buf++ = ('n' << 8) | 'c';
333
    *buf++ = ('o' << 8) | 'r';
334
    *buf++ = ('e' << 8) | 's';
335
    *buf++ = ('.' << 8) | 'o';
336
    *buf++ = ('r' << 8) | 'g';
337
    *buf++ = (' ' << 8) | ' ';
338 876 rherveille
 
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
    */
354 919 rherveille
    /*           " ata device model  (C)Richard Herveille "           */
355
    *buf++ = (' ' << 8) | 'a';
356
    *buf++ = ('t' << 8) | 'a';
357
    *buf++ = (' ' << 8) | 'd';
358
    *buf++ = ('e' << 8) | 'v';
359
    *buf++ = ('i' << 8) | 'c';
360
    *buf++ = ('e' << 8) | ' ';
361
    *buf++ = ('m' << 8) | 'o';
362
    *buf++ = ('d' << 8) | 'e';
363
    *buf++ = ('l' << 8) | ' ';
364
    *buf++ = (' ' << 8) | '(';
365
    *buf++ = ('C' << 8) | ')';
366 876 rherveille
    *buf++ = ('R' << 8) | 'i';
367
    *buf++ = ('c' << 8) | 'h';
368
    *buf++ = ('a' << 8) | 'r';
369
    *buf++ = ('d' << 8) | ' ';
370
    *buf++ = ('H' << 8) | 'e';
371
    *buf++ = ('r' << 8) | 'v';
372
    *buf++ = ('e' << 8) | 'i';
373
    *buf++ = ('l' << 8) | 'l';
374
    *buf++ = ('e' << 8) | ' ';
375
 
376
    /*
377
       word 47:
378
           15-8: 0x80
379
            7-0: 0x00 reserved
380
                 0x01-0xff maximum number of sectors to be transfered
381
                           per interrupt on a READ/WRITE MULTIPLE command
382
    */
383
    *buf++ = 0x8001;
384
 
385
    /*
386
       word 48: reserved
387
    */
388
    buf++;
389
 
390
    /*
391
       word 49: Capabilities
392
           15-14: reserved for IDENTIFY PACKET DEVICE
393
           13   : 1=standby timers are supported
394
                  0=standby timers are handled by the device FIXME
395
           12   : reserved for IDENTIFY PACKET DEVICE
396
           11   : 1=IORDY supported
397
                  0=IORDY may be supported
398
           10   : 1=IORDY may be disabled
399
            9   : set to one
400
            8   : set to one
401
            7-0 : retired
402
    */
403
    *buf++ = 0x0f00;
404
 
405
    /*
406
       word 50: Capabilities
407
           15  : always cleared to zero
408
           14  : always set to one
409
           13-1: reserved
410
 
411
    */
412
    *buf++ = 0x4000;
413
 
414
    /*
415
       word 52-51: obsolete
416
    */
417
    buf += 2;
418
 
419
    /*
420
       word 53:
421
           15-3: Reserved
422
           2   : 1=value in word 88 is valid
423
                 0=value in word 88 is not valid
424
           1   : 1=value in word 64-70 is valid
425
                 0=value in word 64-70 is not valid
426
 
427
                 0=value in word 54-58 is not valid
428
    */
429
    *buf++ = 0x0007;
430
 
431
 
432
    /*
433
       word 54: number of current logical cylinders (0-65535)
434
    */
435
    if ( (tmp = device->size / BYTES_PER_SECTOR) > 16514064 )
436
        tmp = 16514064;
437
 
438
    tmp /= (device->settings.heads_per_cylinder +1) * (device->settings.sectors_per_track);
439
    if (tmp > 65535)
440
        *buf++ = 65535;
441
    else
442
        *buf++ = tmp;
443
 
444
    /*
445
       word 55: number of current logical heads, (0-15)
446
    */
447
    *buf++ = device->settings.heads_per_cylinder +1;
448
 
449
    /*
450
       word 56: number of current logical sectors per track (1-255)
451
    */
452
    *buf++ = device->settings.sectors_per_track;
453
 
454
    /*
455
       word 58-57: current capacity in sectors
456
    */
457
    tmp = *(buf-3) * *(buf-2) * *(buf-1);
458
    *buf++ = tmp >> 16;
459
    *buf++ = tmp & 0xffff;
460
 
461
    /*
462
       word 59:
463
           15-9: reserved
464
           8   : 1=multiple sector setting is valid
465
           7-0 : current setting for number of sectors to be transfered
466
                 per interrupt on a READ/WRITE MULTIPLE command
467
    */
468
    *buf++ = 0x0001; // not really a FIXME
469
 
470
    /*
471
       word 60-61: Total number of user addressable sectors (LBA only)
472
    */
473 919 rherveille
    *buf++ = (device->size / BYTES_PER_SECTOR);
474 876 rherveille
    *buf++ = (device->size / BYTES_PER_SECTOR) >> 16;
475
 
476
    /*
477
       word 62: obsolete
478
    */
479
    buf++;
480
 
481
    /* FIXME
482
       word 63: DMA settings
483
           15-11: Reserved
484
           10   : 1=Multiword DMA Mode 2 is selected
485
                  0=Multiword DMA Mode 2 is not selected
486
            9   : 1=Multiword DMA Mode 1 is selected
487
                  0=Multiword DMA Mode 1 is not selected
488
            8   : 1=Multiword DMA Mode 0 is selected
489
                  0=Multiword DMA Mode 0 is not selected
490
            7-3 : Reserved
491
            2   : Multiword DMA Mode 2 and below are supported
492
            1   : Multiword DMA Mode 1 and below are supported
493
 
494
    */
495
    #if   (MWDMA == -1)
496
      *buf++ = 0x0000;
497
    #elif (MWDMA == 2)
498
      *buf++ = 0x0007;
499
    #elif (MWDMA == 1)
500
      *buf++ = 0x0003;
501
    #else
502
      *buf++ = 0x0001;
503
    #endif
504
 
505
    /*
506
       word 64:
507
           15-8: reserved
508
            7-0: Advanced PIO modes supported
509
 
510
            7-2: reserved
511
            1  : PIO mode4 supported
512
 
513
    */
514
    *buf++ = 0x0003;
515
 
516
    /*
517
       word 65: Minimum Multiword DMA transfer cycle time per word (nsec)
518
    */
519
    *buf++ = MIN_MWDMA_CYCLE_TIME;
520
 
521
    /*
522
       word 66: Manufacturer's recommended Multiword DMA transfer cycle time per word (nsec)
523
    */
524
    *buf++ = RECOMMENDED_MWDMA_CYCLE_TIME;
525
 
526
 
527
    /*
528
       word 67: Minimum PIO transfer cycle time per word (nsec), without IORDY flow control
529
    */
530
    *buf++ = MIN_PIO_CYCLE_TIME_NO_IORDY;
531
 
532
    /*
533
       word 68: Minimum PIO transfer cycle time per word (nsec), with IORDY flow control
534
    */
535
    *buf++ = MIN_PIO_CYCLE_TIME_IORDY;
536
 
537
    /*
538
       word 69-70: reserved for future command overlap and queueing
539
            71-74: reserved for IDENTIFY PACKET DEVICE command
540
    */
541
    buf += 6;
542
 
543
    /*
544
       word 75: Queue depth
545
           15-5: reserved
546
            4-0: queue depth -1
547
    */
548
    *buf++ = SUPPORT_READ_WRITE_DMA_QUEUED ? QUEUE_DEPTH : 0x0000;
549
 
550
    /*
551
       word 76-79: reserved
552
    */
553
    buf += 4;
554
 
555
    /*
556
       word 80: MAJOR ATA version
557
                We simply report that we do not report a version
558
 
559
                You can also set bits 5-2 to indicate compliancy to
560
                ATA revisions 5-2 (1 & 0 are obsolete)
561
    */
562
    *buf++ = 0x0000;
563
 
564
    /*
565
       word 81: MINOR ATA version
566
                We report ATA/ATAPI-5 T13 1321D revision 3 (0x13)
567
    */
568
    *buf++ = 0x0013;
569
 
570
    /*
571
       word 82: Command set supported
572
    */
573
    *buf++ = 0                           << 15 | \ /* obsolete        */
574
             SUPPORT_NOP_CMD             << 14 | \
575
             SUPPORT_READ_BUFFER_CMD     << 13 | \
576
             SUPPORT_WRITE_BUFFER_CMD    << 12 | \
577
 
578
             SUPPORT_HOST_PROTECTED_AREA << 10 | \
579
             SUPPORT_DEVICE_RESET_CMD    << 9  | \
580
             SUPPORT_SERVICE_INTERRUPT   << 8  | \
581
             SUPPORT_RELEASE_INTERRUPT   << 7  | \
582
             SUPPORT_LOOKAHEAD           << 6  | \
583
             SUPPORT_WRITE_CACHE         << 5  | \
584
 
585
             SUPPORT_POWER_MANAGEMENT    << 3  | \
586
             SUPPORT_REMOVABLE_MEDIA     << 2  | \
587
             SUPPORT_SECURITY_MODE       << 1  | \
588
             SUPPORT_SMART               << 0
589
    ;
590
 
591
    /*
592
       word 83: Command set supported
593
    */
594
    *buf++ = 0                           << 15 | \ /* cleared to zero */
595
             1                           << 14 | \ /* set to one      */
596
 
597
             SUPPORT_SET_MAX             << 8  | \
598
 
599
                                                   /* project 1407DT  */
600
             SET_FEATURES_REQUIRED_AFTER_POWER_UP << 6  | \
601
             SUPPORT_POWER_UP_IN_STANDBY_MODE     << 5  | \
602
             SUPPORT_REMOVABLE_MEDIA_NOTIFICATION << 4  | \
603
             SUPPORT_APM                 << 3  | \
604
             SUPPORT_CFA                 << 2  | \
605
             SUPPORT_READ_WRITE_DMA_QUEUED        << 1  | \
606
             SUPPORT_DOWNLOAD_MICROCODE  << 0
607
    ;
608
 
609
    /*
610
       word 84: Command set/feature supported
611
    */
612
    *buf++ = 0                           << 15 | \ /* cleared to zero */
613
             1                           << 14     /* set to one      */
614
    ;                                              /* 0-13 reserved   */
615
 
616
    /*
617
       word 85: Command set enabled FIXME
618
    */
619
    *buf++ = 0                           << 15 | \ /* obsolete        */
620
             SUPPORT_NOP_CMD             << 14 | \
621
             SUPPORT_READ_BUFFER_CMD     << 13 | \
622
             SUPPORT_WRITE_BUFFER_CMD    << 12 | \
623
 
624
             SUPPORT_HOST_PROTECTED_AREA << 10 | \
625
             SUPPORT_DEVICE_RESET_CMD    << 9  | \
626
             SUPPORT_SERVICE_INTERRUPT   << 8  | \
627
             SUPPORT_RELEASE_INTERRUPT   << 7  | \
628
             SUPPORT_LOOKAHEAD           << 6  | \
629
             SUPPORT_WRITE_CACHE         << 5  | \
630
 
631
             SUPPORT_POWER_MANAGEMENT    << 3  | \
632
             SUPPORT_REMOVABLE_MEDIA     << 2  | \
633
             SUPPORT_SECURITY_MODE       << 1  | \
634
             SUPPORT_SMART               << 0
635
    ;
636
 
637
    /*
638
       word 86: Command set enables
639
    */
640
    *buf++ = 0                           << 9  | \ /* 15-9 reserved   */
641
             SUPPORT_SET_MAX             << 8  | \
642
 
643
                                                   /* project 1407DT  */
644
             SET_FEATURES_REQUIRED_AFTER_POWER_UP << 6  | \
645
             SUPPORT_POWER_UP_IN_STANDBY_MODE     << 5  | \
646
             SUPPORT_REMOVABLE_MEDIA_NOTIFICATION << 4  | \
647
             SUPPORT_APM                 << 3  | \
648
             SUPPORT_CFA                 << 2  | \
649
             SUPPORT_READ_WRITE_DMA_QUEUED        << 1  | \
650
             SUPPORT_DOWNLOAD_MICROCODE  << 0
651
    ;
652
 
653
    /*
654
       word 87: Command set/feature supported
655
    */
656
    *buf++ = 0                           << 15 | \ /* cleared to zero */
657
             1                           << 14     /* set to one      */
658
    ;                                              /* 0-13 reserved   */
659
 
660
    /*
661
       word 88: UltraDMA section
662
           15-13: reserved
663
           12   : 1=UltraDMA Mode 4 is selected
664
                  0=UltraDMA Mode 4 is not selected
665
           10   : 1=UltraDMA Mode 3 is selected
666
                  0=UltraDMA Mode 3 is not selected
667
           10   : 1=UltraDMA Mode 2 is selected
668
                  0=UltraDMA Mode 2 is not selected
669
            9   : 1=UltraDMA Mode 1 is selected
670
                  0=UltraDMA Mode 1 is not selected
671
            8   : 1=UltraDMA Mode 0 is selected
672
                  0=UltraDMA Mode 0 is not selected
673
            7-5 : Reserved
674
            4   : UltraDMA Mode 4 and below are supported
675
            3   : UltraDMA Mode 3 and below are supported
676
            2   : UltraDMA Mode 2 and below are supported
677
            1   : UltraDMA Mode 1 and below are supported
678
 
679
 
680
            Because the OCIDEC cores currently do not support
681
            UltraDMA we set all bits to zero
682
    */
683
    *buf++ = 0;
684
 
685
    /*
686
       word 89: Security sector erase unit completion time
687
 
688
       For now we report a 'value not specified'.
689
    */
690
    *buf++ = 0x0000; // not really a FIXME
691
 
692
    /*
693
       word 90: Enhanced security erase completion time
694
 
695
       For now we report a 'value not specified'.
696
    */
697
    *buf++ = 0x0000; // not really a FIXME
698
 
699
    /*
700
       word 91: Current advanced power management value
701
 
702
       For now set it to zero.
703
    */
704
    *buf++ = 0x0000; // FIXME
705
 
706
    /*
707
       word 92: Master Password Revision Code.
708
               We simply report that we do not support this.
709
    */
710
    *buf++ = 0x0000;
711
 
712
    /*
713
       word 93: Hardware reset result
714
    */
715
    if (device->settings.dev)
716
    {
717
      /* this is device1, clear device0 bits                                         */
718
      *buf++ = 0              << 15 | \
719
               1              << 14 | \
720
 
721
                                        /* 12-8 Device 1 hardware reset result       */
722
 
723
               device->sigs.pdiago << 11 | \ /* 1: Device1 did assert PDIAG               */
724
                                        /* 0: Device1 did not assert PDIAG           */
725
               3              <<  9 | \ /* Device1 determined device number by       */
726
                                        /* 00: reserved                              */
727
                                        /* 01: a jumper was used                     */
728
                                        /* 10: the CSEL signal was used              */
729
                                        /* 11: some other or unknown method was used */
730
               1              << 8      /* set to one                                */
731
      ;
732
    }
733
    else
734
    { /* FIXME bit 6 */
735
      /* this is device0, clear device1 bits                                         */
736
      *buf++ = 0              << 7 | \  /* reserved                                  */
737
 
738
                                        /* 0: Device0 does not respond for device1   */
739
               device->sigs.daspi  << 5 | \  /* 1: Device0 did detected DASP assertion    */
740
                                        /* 0: Device0 did not detect DASP assertion  */
741
               device->sigs.pdiagi << 4 | \  /* Device0 did detect PDIAG assertion        */
742
                                        /* Device0 did not detect PDIAG assertion    */
743
               1              << 3 | \  /* Device0 did pass diagnostics              */
744
               3              << 1 | \  /* Device0 determined device number by       */
745
                                        /* 00: reserved                              */
746
                                        /* 01: a jumper was used                     */
747
                                        /* 10: the CSEL signal was used              */
748
                                        /* 11: some other or unknown method was used */
749
               1              << 0      /* set to one                                */
750
      ;
751
    }
752
 
753
    /*
754
       word 94-126: Reserved
755
    */
756
    buf += 33;
757
 
758
    /*
759
       word 127: Removable Media Status Notification feature set support
760
           15-2: reserved
761
            1-0: 00 Removable media Status Notification not supported
762
                 01 Removable media Status Notification supported
763
                 10 reserved
764
                 11 reserved
765
    */
766
    *buf++ = SUPPORT_REMOVABLE_MEDIA_NOTIFICATION;
767
 
768
    /*
769
       word 128: Security status
770
           15-9: reserved
771
           8   : Security level, 0=high, 1=maximum
772
           7-6 : reserved
773
           5   : 1=enhanced security erase supported
774
           4   : 1=security count expired
775
           3   : 1=security frozen
776
           2   : 1=security locked
777
           1   : 1=security enabled
778
 
779
 
780
           for now we do not support security, set is to zero
781
    */
782
    *buf++ = 0;
783
 
784
    /*
785
       word 129-159: Vendor specific
786
    */
787
    buf += 31;
788
 
789
    /*
790
       word 160: CFA power mode 1
791
           15  : Word 160 supported
792
           14  : reserved
793
           13  : CFA power mode 1 is required for one or more commands
794
           12  : CFA power mode 1 disabled
795
           11-0: Maximum current in mA
796
    */
797
    *buf++ = 0;
798
 
799
    /*
800
       word 161-175: Reserved for the CompactFLASH Association
801
    */
802
    buf += 15;
803
 
804
    /*
805
       word 176-254: reserved
806
    */
807
    buf += 79;
808
 
809
    /*
810
       word 255: Integrity word
811
           15-8: Checksum
812
           7-0 : Signature
813
    */
814
    // set signature to indicate valid checksum
815
    *buf = 0x00a5;
816
 
817
    // calculate checksum
818
    chksum = 0;
819
    for (n=0; n < 511; n++)
820
      chksum += *chksum_buf++;
821
 
822
    *buf = ( (0-chksum) << 8) | 0x00a5;
823
 
824
    /* set status register bits                                       */
825
    device->regs.status = ATA_SR_DRDY;
826
  }
827
}
828
 
829
 
830
/*
831
  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
832
*/
833
void ata_initialize_device_parameters_cmd(ata_device *device)
834
{
835
  /* print debug information                                          */
836
  ata_device_debug(2, "executing command 'initialize device parameters'\n");
837 919 rherveille
 
838 876 rherveille
  device->settings.sectors_per_track = device->regs.sector_count;
839
  device->settings.heads_per_cylinder = device->regs.device_head & ATA_DHR_H;
840 919 rherveille
 
841 876 rherveille
  /* set status register bits                                         */
842
  device->regs.status = 0;
843
}
844
 
845
 
846
/*
847
  A T A _ R E A D _ S E C T O R S
848
*/
849
void ata_read_sectors_cmd(ata_device *device)
850
{
851 919 rherveille
  size_t sector_count;
852 876 rherveille
  unsigned long lba;
853
 
854
  /* print debug information                                          */
855
  ata_device_debug(2, "executing command 'read sectors'\n");
856
 
857 919 rherveille
  /* reset the buffer-counter                                         */
858
  device->settings.dbuf_cnt = 0;
859 876 rherveille
 
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 919 rherveille
        fread(device->settings.dbuf, BYTES_PER_SECTOR, sector_count, device->stream);
917 876 rherveille
 
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.