root/drivers/block/paride/paride.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. pi_swab16
  2. pi_swab32

   1 #ifndef __DRIVERS_PARIDE_H__
   2 #define __DRIVERS_PARIDE_H__
   3 
   4 /* 
   5         paride.h        (c) 1997-8  Grant R. Guenther <grant@torque.net>
   6                                     Under the terms of the GPL.
   7 
   8    This file defines the interface between the high-level parallel
   9    IDE device drivers (pd, pf, pcd, pt) and the adapter chips.
  10 
  11 */
  12 
  13 /* Changes:
  14 
  15         1.01    GRG 1998.05.05  init_proto, release_proto
  16 */
  17 
  18 #define PARIDE_H_VERSION        "1.01"
  19 
  20 /* Some adapters need to know what kind of device they are in
  21 
  22    Values for devtype:
  23 */
  24 
  25 #define PI_PD   0       /* IDE disk */
  26 #define PI_PCD  1       /* ATAPI CDrom */
  27 #define PI_PF   2       /* ATAPI disk */
  28 #define PI_PT   3       /* ATAPI tape */
  29 #define PI_PG   4       /* ATAPI generic */
  30 
  31 /* The paride module contains no state, instead the drivers allocate
  32    a pi_adapter data structure and pass it to paride in every operation.
  33 
  34 */
  35 
  36 struct pi_adapter  {
  37 
  38         struct pi_protocol *proto;   /* adapter protocol */
  39         int     port;                /* base address of parallel port */
  40         int     mode;                /* transfer mode in use */
  41         int     delay;               /* adapter delay setting */
  42         int     devtype;             /* device type: PI_PD etc. */
  43         char    *device;             /* name of driver */
  44         int     unit;                /* unit number for chained adapters */
  45         int     saved_r0;            /* saved port state */
  46         int     saved_r2;            /* saved port state */
  47         int     reserved;            /* number of ports reserved */
  48         unsigned long   private;     /* for protocol module */
  49 
  50         wait_queue_head_t parq;     /* semaphore for parport sharing */
  51         void    *pardev;             /* pointer to pardevice */
  52         char    *parname;            /* parport name */
  53         int     claimed;             /* parport has already been claimed */
  54         void (*claim_cont)(void);    /* continuation for parport wait */
  55 };
  56 
  57 typedef struct pi_adapter PIA;
  58 
  59 /* functions exported by paride to the high level drivers */
  60 
  61 extern int pi_init(PIA *pi, 
  62         int autoprobe,          /* 1 to autoprobe */
  63         int port,               /* base port address */
  64         int mode,               /* -1 for autoprobe */
  65         int unit,               /* unit number, if supported */
  66         int protocol,           /* protocol to use */
  67         int delay,              /* -1 to use adapter specific default */
  68         char * scratch,         /* address of 512 byte buffer */
  69         int devtype,            /* device type: PI_PD, PI_PCD, etc ... */
  70         int verbose,            /* log verbose data while probing */
  71         char *device            /* name of the driver */
  72         );                      /* returns 0 on failure, 1 on success */
  73 
  74 extern void pi_release(PIA *pi);
  75 
  76 /* registers are addressed as (cont,regr)
  77 
  78         cont: 0 for command register file, 1 for control register(s)
  79         regr: 0-7 for register number.
  80 
  81 */
  82 
  83 extern void pi_write_regr(PIA *pi, int cont, int regr, int val);
  84 
  85 extern int pi_read_regr(PIA *pi, int cont, int regr);
  86 
  87 extern void pi_write_block(PIA *pi, char * buf, int count);
  88 
  89 extern void pi_read_block(PIA *pi, char * buf, int count);
  90 
  91 extern void pi_connect(PIA *pi);
  92 
  93 extern void pi_disconnect(PIA *pi);
  94 
  95 extern void pi_do_claimed(PIA *pi, void (*cont)(void));
  96 extern int pi_schedule_claimed(PIA *pi, void (*cont)(void));
  97 
  98 /* macros and functions exported to the protocol modules */
  99 
 100 #define delay_p                 (pi->delay?udelay(pi->delay):(void)0)
 101 #define out_p(offs,byte)        outb(byte,pi->port+offs); delay_p;
 102 #define in_p(offs)              (delay_p,inb(pi->port+offs))
 103 
 104 #define w0(byte)                {out_p(0,byte);}
 105 #define r0()                    (in_p(0) & 0xff)
 106 #define w1(byte)                {out_p(1,byte);}
 107 #define r1()                    (in_p(1) & 0xff)
 108 #define w2(byte)                {out_p(2,byte);}
 109 #define r2()                    (in_p(2) & 0xff)
 110 #define w3(byte)                {out_p(3,byte);}
 111 #define w4(byte)                {out_p(4,byte);}
 112 #define r4()                    (in_p(4) & 0xff)
 113 #define w4w(data)               {outw(data,pi->port+4); delay_p;}
 114 #define w4l(data)               {outl(data,pi->port+4); delay_p;}
 115 #define r4w()                   (delay_p,inw(pi->port+4)&0xffff)
 116 #define r4l()                   (delay_p,inl(pi->port+4)&0xffffffff)
 117 
 118 static inline u16 pi_swab16( char *b, int k)
 119 
 120 {       union { u16 u; char t[2]; } r;
 121 
 122         r.t[0]=b[2*k+1]; r.t[1]=b[2*k];
 123         return r.u;
 124 }
 125 
 126 static inline u32 pi_swab32( char *b, int k)
 127 
 128 {       union { u32 u; char f[4]; } r;
 129 
 130         r.f[0]=b[4*k+1]; r.f[1]=b[4*k];
 131         r.f[2]=b[4*k+3]; r.f[3]=b[4*k+2];
 132         return r.u;
 133 }
 134 
 135 struct pi_protocol {
 136 
 137         char    name[8];        /* name for this protocol */
 138         int     index;          /* index into protocol table */
 139 
 140         int     max_mode;       /* max mode number */
 141         int     epp_first;      /* modes >= this use 8 ports */
 142         
 143         int     default_delay;  /* delay parameter if not specified */
 144         int     max_units;      /* max chained units probed for */
 145 
 146         void (*write_regr)(PIA *,int,int,int);
 147         int  (*read_regr)(PIA *,int,int);
 148         void (*write_block)(PIA *,char *,int);
 149         void (*read_block)(PIA *,char *,int);
 150 
 151         void (*connect)(PIA *);
 152         void (*disconnect)(PIA *);
 153         
 154         int  (*test_port)(PIA *);
 155         int  (*probe_unit)(PIA *);
 156         int  (*test_proto)(PIA *,char *,int);
 157         void (*log_adapter)(PIA *,char *,int);
 158         
 159         int (*init_proto)(PIA *);
 160         void (*release_proto)(PIA *);
 161         struct module *owner;
 162 };
 163 
 164 typedef struct pi_protocol PIP;
 165 
 166 extern int paride_register( PIP * );
 167 extern void paride_unregister ( PIP * );
 168 void *pi_register_driver(char *);
 169 void pi_unregister_driver(void *);
 170 
 171 #endif /* __DRIVERS_PARIDE_H__ */
 172 /* end of paride.h */

/* [<][>][^][v][top][bottom][index][help] */