Subversion Repositories shark

Rev

Rev 2 | Rev 80 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
11
 *   Luca Abeni          <luca@gandalf.sssup.it>
12
 *   (see the web pages for full authors list)
13
 *
14
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
15
 *
16
 * http://www.sssup.it
17
 * http://retis.sssup.it
18
 * http://shark.sssup.it
19
 */
20
 
21
 
22
/***************************************
23
 
24
  CVS :        $Id: ide.h,v 1.1.1.1 2002-03-29 14:12:49 pj Exp $
25
 
26
  Revision:    $Revision: 1.1.1.1 $
27
 
28
  Last update: $Date: 2002-03-29 14:12:49 $
29
 
30
  Header file for all the modules of the IDE block device interface
31
  sub-system.
32
 
33
***************************************/
34
 
35
/*
36
 * Copyright (C) 1999,2000 Massimiliano Giorgi
37
 *
38
 * This program is free software; you can redistribute it and/or modify
39
 * it under the terms of the GNU General Public License as published by
40
 * the Free Software Foundation; either version 2 of the License, or
41
 * (at your option) any later version.
42
 *
43
 * This program is distributed in the hope that it will be useful,
44
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
45
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46
 * GNU General Public License for more details.
47
 *
48
 * You should have received a copy of the GNU General Public License
49
 * along with this program; if not, write to the Free Software
50
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
51
 *
52
 */
53
 
54
#ifndef __IDE_H__
55
#define __IDE_H__
56
 
57
#include "glue.h"
58
#include "bdev.h"
59
#include "bqueue.h"
60
 
61
/*+ max number of ide interface (must be <= 8) +*/
62
#define MAXIDEINTERFACES 4
63
 
64
/*---*/
65
 
66
/*
67
 * CONSTANTS
68
 */
69
 
70
/*+ max number of "minor number" required +*/
71
#define MAXIDEMINOR (MAXIDEINTERFACES<<5)
72
 
73
/*+ max number of "logical partition" per hard disk +*/
74
#define MAXIDELODSK 16
75
 
76
/*+ number of physical region descriptors used by DMA bus master operations +*/
77
#define MAXPRDENTRIES 4
78
 
79
/*+ for a master hard disk +*/
80
#define IDE_MASTER 0x00
81
/*+ for a slave hard disk +*/
82
#define IDE_SLAVE  0x01
83
 
84
/*+ sector size in bytes +*/
85
#define IDE_SECTOR_SIZE 512
86
 
87
/*+ Log Level for errors +*/
88
#define IDEERRLOG   KERN_ERR
89
/*+ Log Level for log +*/
90
#define IDELOG      KERN_NOTICE
91
/*+ Log Level for debug purpose +*/
92
#define IDEDEBUGLOG KERN_DEBUG
93
 
94
/*
95
 * for result
96
 */
97
 
98
/*+
99
  This values are returned by the low level routine to indicate
100
  an error.
101
  +latex+ \\
102
 
103
  No error +*/
104
#define IDE_OK                0
105
/*+ there are too much request pending +*/
106
#define IDE_ERR_TOOMUCHREQ   -1
107
/*+ the interface is busy or can not do a command+*/
108
#define IDE_ERR_BUSY         -2
109
/*+ the following codes are from the IDE error register +*/
110
#define IDE_ERR_BADBLOCK     -3
111
#define IDE_ERR_CRCECC       -4
112
#define IDE_ERR_IDNOTFOUND   -5
113
#define IDE_ERR_ABORTCMD     -6
114
#define IDE_ERR_TRACK00      -7
115
#define IDE_ERR_DAMNOTFOUND  -8
116
/*+ generic error (when there are not other IDE_ERR_?? available) +*/
117
#define IDE_ERR_UNKNOWN      -9
118
/*+ there was an interrupt, we aspect data but there is not data +*/
119
#define IDE_ERR_NODATA      -10
120
/*+ there was an interrupt, we do not aspect data but there is data +*/
121
#define IDE_ERR_DATA        -11
122
/*+ interface not ready for a command +*/
123
#define IDE_ERR_NOTREADY    -12 
124
/*+ a timeout waiting for a reply +*/
125
#define IDE_ERR_TIMEOUT     -13
126
/*+ the interface must be busy but it is not +*/
127
#define IDE_ERR_NOTBUSY     -14
128
/*+ device fault +*/
129
#define IDE_ERR_FAULT       -15
130
/*+ we aspect to send data but there is no data request +*/
131
#define IDE_ERR_NODATAREQ   -16
132
/*+ the DRDY signal is not preset +*/
133
#define IDE_ERR_NOTDRDY     -17
134
/*+ DMA cycle error +*/
135
#define IDE_ERR_DMA         -18
136
 
137
/*+ for the IDE_ERR_??? constants +*/
138
extern char *ide_error_msg[];
139
 
140
/*
141
 * DATA STRUCTURES
142
 */
143
 
144
/*+
145
  Information on IDE devices capabilities
146
  +*/
147
struct ide_diskinfo {
148
  __uint32_t use_lba:1;     /*+ use LBA address translation +*/
149
  __uint32_t use_dma:1;     /*+ use old dma operation +*/
150
  __uint32_t use_bm_dma:1;  /*+ use new bus master dma operation +*/
151
  __int8_t  max_pio_mode;   /*+ max pio mode supported (-1 no support) +*/
152
  __int8_t  max_dma_mode;   /*+ max multi word dma support (-1 no support) +*/
153
  __int8_t  max_udma_mode;  /*+ max ultra dma mode support (-1 no support) +*/
154
};
155
 
156
/*+
157
  Information on IDE interfaces
158
  +*/
159
struct ideinfo {
160
 
161
#ifdef _PARANOIA
162
  __uint32_t magic;        /*+ magic number +*/
163
#endif
164
 
165
  __uint16_t io_port;      /*+ I/O address +*/
166
  __uint16_t io_port2;     /*+ auxiliary I/O address +*/
167
  __uint8_t  irq;          /*+ irq number +*/
168
  __uint8_t  dma;          /*+ dma channel +*/
169
  __uint16_t io_bmdma;     /*+ I/O address for a bus master DMA cycle */
170
 
171
  /* this must be 4-bytes aligned */
172
  __uint32_t prd[MAXPRDENTRIES*2];
173
                           /*+ physical region descriptors (used by DMA) */
174
 
175
  struct phdskinfo    *pdisk[2]; /*+ physical disk pointer for master/slave +*/
176
  struct ide_diskinfo info[2];   /*+ more disk information for master/slave +*/
177
 
178
  bqueue_t   queue[2];
179
  int        actreq;       /*+ actual request that we are serving +*/
180
  int        actdrv;       /*+ drive id of the actual request +*/
181
 
182
  int        errors;       /*+ incremented for every error */
183
 
184
  /* for the glue routines (see ideglue.c) */
185
  __pid_t    server;       /*+ interface server pid +*/
186
 
187
} __attribute__ ((aligned (4)));
188
 
189
/*+
190
  Information on minor devices
191
  +*/
192
struct ideminorinfo {
193
 
194
#ifdef _PARANOIA
195
  __uint32_t  magic;     /*+ magic number +*/  
196
#endif
197
 
198
  __blkcnt_t  start;     /*+ first block of this logical disk (partition) +*/
199
  __blkcnt_t  size;      /*+ size of the logical disk (in sectors) +*/
200
 
201
  __uint16_t  used:1;    /*+ is this entry used? +*/
202
  __uint16_t  blocked:1; /*+ is this entry blocked? (is someone using it?) +*/
203
};
204
 
205
/*
206
 * DATA
207
 */
208
 
209
/* these are here because are used both ide.c and idelow.c */
210
 
211
extern struct ideinfo ide[MAXIDEINTERFACES];
212
 
213
extern int ide_showinfo_flag;
214
 
215
extern void *ide_parm_initserver;
216
 
217
/*
218
 * FUNCTIONS
219
 */
220
 
221
/* register an hardware interface on first free slot */
222
int ide_register(__uint16_t io_port, __uint16_t io_port2,
223
                 __uint8_t irq,
224
                 __uint8_t dma, __uint16_t io_bmdma);
225
/* release resource used by the ideif interface */
226
void ide_unregister(int ideif);
227
 
228
/* scan an interface to found device */
229
int ide_scan(int ideif);
230
 
231
/* scan an hard disk to found a partitions scheme */
232
int ide_scandisk(int hwif, int drv);
233
 
234
 
235
struct ata_diskid;
236
struct atapi_diskid;
237
 
238
int do_ide_softreset(int ideif);
239
int ide_read(int ideif, int id, __blkcnt_t lsector, __uint8_t *buffer);
240
int ide_write(int ideif, int id, __blkcnt_t lsector, __uint8_t *buffer);
241
int ide_seek(int ideif, int id, __blkcnt_t lsector);
242
int ide_pidentify(int ideif, int id, struct atapi_diskid *buffer);
243
int ide_identify(int ideif, int id, struct ata_diskid *buffer);
244
int ide_enablelookahead(int ideif, int id);
245
int ide_disablelookahead(int ideif, int id);
246
int ide_settransfertmode(int ideif, int id, int mode);
247
 
248
TASK ide_server(int ideif);
249
 
250
#define is_ide_free(ideif) (ide[(ideif)].io_port==0)
251
#define mark_ide_free(ideif) (ide[(ideif)].io_port=0)
252
 
253
static inline int nextideif(void)
254
{
255
  int ideif;
256
  for (ideif=0;ideif<MAXIDEINTERFACES;ideif++)
257
    if (is_ide_free(ideif)) break;
258
  return ideif;
259
}
260
 
261
/*
262
 * LOW LEVEL data structures
263
 */
264
 
265
/* ATA-4 */
266
/* obs: obsolete res: reserved ven: vendor specific */
267
 
268
/*+ IDENTIFY command response (from ATA 4 specifications) +*/
269
struct ata_diskid {
270
  __uint16_t  config;
271
  __uint16_t  def_cyls;
272
  __uint16_t  res2;
273
  __uint16_t  def_heads;
274
  __uint16_t  res4;
275
  __uint16_t  res5;
276
  __uint16_t  def_sects;
277
  __uint16_t  ven7;
278
  __uint16_t  ven8;
279
  __uint16_t  ven9;
280
  __uint8_t   serial[20];
281
  __uint16_t  ven20;
282
  __uint16_t  ven21;
283
  __uint16_t  obs22;
284
  __uint8_t   firmware[8];
285
  __uint8_t   model[40];
286
  __uint16_t  maxmulsect;
287
  __uint16_t  res48;
288
  __uint16_t  capabilities;
289
  __uint16_t  capabilities2;
290
  __uint8_t   ven51;
291
  __uint8_t   PIO_mode;
292
  __uint16_t  ven52;
293
  __uint16_t  fields_valid;
294
  __uint16_t  act_cyls;      // 54
295
  __uint16_t  act_heads;
296
  __uint16_t  act_sects;
297
  __uint16_t  cur_capacity0;
298
  __uint16_t  cur_capacity1; // 58
299
  __uint8_t   multsect;      
300
  __uint8_t   multsect_valid;
301
  __uint32_t  lba_capacity;
302
  __uint16_t  obs62;
303
  __uint16_t  DMA_mword;
304
  __uint8_t   eide_PIO_modes;
305
  __uint8_t   res64 ;
306
  __uint16_t  eide_dma_min;
307
  __uint16_t  eide_dma_time;
308
  __uint16_t  eide_pio;    
309
  __uint16_t  eide_pio_iordy;
310
  __uint16_t  res69;
311
  __uint16_t  res70;          // 70
312
  __uint16_t  res71;
313
  __uint16_t  res72;
314
  __uint16_t  res73;
315
  __uint16_t  res74;
316
  __uint16_t  queue_depth;
317
  __uint16_t  res76;
318
  __uint16_t  res77;
319
  __uint16_t  res78;
320
  __uint16_t  res79;  
321
  __uint16_t  major_version;
322
  __uint16_t  minor_version;
323
  __uint16_t  command_sets;
324
  __uint16_t  command_sets2;
325
  __uint16_t  command_sets_ext;
326
  __uint16_t  command_sets_ena;
327
  __uint16_t  command_sets_ena2;
328
  __uint16_t  command_sets_def;
329
  __uint16_t  UDMA_cap;
330
  __uint16_t  erase_time;
331
  __uint16_t  erase_time2;
332
  __uint16_t  current_power;
333
  __uint16_t  reservedA[126-92+1];
334
  __uint16_t  status_notification;
335
  __uint16_t  security;
336
  __uint16_t  vendor[159-129+1];
337
  __uint16_t  reservedB[255-160+1];
338
} __attribute__((packed));
339
 
340
#define is_ATAdevice(p)    ((p)->config&0x8000)
341
#define is_removable(p)    ((p)->config&0x0080)
342
#define is_notremovable(p) ((p)->config&0x0040)
343
 
344
// 54 -> 58
345
#define is_actcurvalid(p)  ((p)->fields_valid&0x0001)
346
// 64 -> 70
347
#define is_eidevalid(p)    ((p)->fields_valid&0x0002)
348
// 88
349
#define is_udmavalid(p)  ((p)->fields_valid&0x0004)
350
 
351
#define is_ATA(p)          ((p)->major_version&0x02)
352
#define is_ATA2(p)         ((p)->major_version&0x04)
353
#define is_ATA3(p)         ((p)->major_version&0x08)
354
#define is_ATA4(p)         ((p)->major_version&0x10)
355
 
356
#define is_LBAcapable(p)   ( \
357
                            ((p)->capabilities&0x0200) \
358
                            || is_ATA3(p) \
359
                            || is_ATA4(p) \
360
                           )
361
 
362
/*+ PIDENTIFY command response (for ATAPI device from ATA 4 specs) +*/
363
struct atapi_diskid {
364
  __uint16_t  config;
365
  __uint16_t  res1;
366
  __uint16_t  res2;
367
  __uint16_t  res3;
368
  __uint16_t  res4;
369
  __uint16_t  res5;
370
  __uint16_t  res6;
371
  __uint16_t  ven7;
372
  __uint16_t  ven8;
373
  __uint16_t  ven9;
374
  __uint8_t   serial[20];
375
  __uint16_t  res20;
376
  __uint16_t  res21;
377
  __uint16_t  res22;
378
  __uint8_t   firmware[8];
379
  __uint8_t   model[40];
380
  __uint16_t  res47;
381
  __uint16_t  res48;
382
  __uint16_t  capabilities;
383
  __uint16_t  res50;
384
  __uint8_t   ven51;
385
  __uint8_t   tPIO;
386
  __uint16_t  res52;
387
  __uint16_t  fields_valid;
388
  __uint16_t  res54;   //54
389
  __uint16_t  res55;
390
  __uint16_t  res56;
391
  __uint16_t  res57;
392
  __uint16_t  res58;  // 58
393
  __uint16_t  res59;
394
  __uint16_t  res60;
395
  __uint16_t  res61;
396
  __uint16_t  res62;
397
  __uint16_t  dma_mword;
398
  __uint16_t  eide_pio_modes; //64
399
  __uint16_t  eide_dma_min;
400
  __uint16_t  eide_dma_time;
401
  __uint16_t  eide_pio;    
402
  __uint16_t  eide_pio_iordy;
403
  __uint16_t  res69;
404
  __uint16_t  res70;          // 70
405
  __uint16_t  time_packet;
406
  __uint16_t  time_service;
407
  __uint16_t  res73;
408
  __uint16_t  res74;
409
  __uint16_t  queue_depth;
410
  __uint16_t  res76;
411
  __uint16_t  res77;
412
  __uint16_t  res78;
413
  __uint16_t  res79;  
414
  __uint16_t  major_version;
415
  __uint16_t  minor_version;
416
  __uint16_t  command_sets;
417
  __uint16_t  command_sets2;
418
  __uint16_t  command_sets_ext;
419
  __uint16_t  command_sets_ena;
420
  __uint16_t  command_sets_ena2;
421
  __uint16_t  command_sets_def;
422
  __uint16_t  udma;
423
  __uint16_t  reservedA[126-89+1];
424
  __uint16_t  status_notification;
425
  __uint16_t  security;
426
  __uint16_t  vendor[159-129+1];
427
  __uint16_t  reservedB[255-160+1];
428
} __attribute__((packed));
429
 
430
#define is_ATAPIdevice(p)  (((p)->config&0xc000)==0x8000)
431
//#define is_removable(p)    ((p)->config&0x0080)
432
#define is_packet12capable(p) (((p)->conig&0x0003)==0x0000)
433
#define is_packet16capable(p) (((p)->conig&0x0003)==0x0001)
434
 
435
#define is_directdev(p)        ((((p)->config&0x1f00)>>8)==0x00)
436
#define is_sequentialdev(p)    ((((p)->config&0x1f00)>>8)==0x01)
437
#define is_printerdev(p)       ((((p)->config&0x1f00)>>8)==0x02)
438
#define is_processordev(p)     ((((p)->config&0x1f00)>>8)==0x03)
439
#define is_writeoncedev(p)     ((((p)->config&0x1f00)>>8)==0x04)
440
#define is_cdromdev(p)         ((((p)->config&0x1f00)>>8)==0x05)
441
#define is_scannerdev(p)       ((((p)->config&0x1f00)>>8)==0x06)
442
#define is_opticalmemorydev(p) ((((p)->config&0x1f00)>>8)==0x07)
443
#define is_mediachengerdev(p)  ((((p)->config&0x1f00)>>8)==0x08)
444
#define is_communicatordev(p)  ((((p)->config&0x1f00)>>8)==0x09)
445
#define is_arraydev(p)         ((((p)->config&0x1f00)>>8)==0x0c)
446
 
447
#endif
448
 
449
 
450
 
451
 
452
 
453