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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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