Subversion Repositories shark

Rev

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