paride.h 5.0 KB

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