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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [peripheral/] [atadevice_cmdi.c] - Blame information for rev 1488

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

powered by: WebSVN 2.1.0

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