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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_70/] [or1ksim/] [peripheral/] [atadevice_cmdi.c] - Blame information for rev 1765

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

powered by: WebSVN 2.1.0

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