home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Headers / bsd / dev / fd_extern.h < prev    next >
Text File  |  1992-07-29  |  15KB  |  528 lines

  1. /*    @(#)fd_extern.h     2.0    01/25/90    (c) 1990 NeXT    
  2.  *
  3.  * fd_vars.h -- Externally used data structures and constants for Floppy 
  4.  *        Disk driver
  5.  *
  6.  * KERNEL VERSION
  7.  *
  8.  * HISTORY
  9.  * 20-Mar-91    Doug Mitchell
  10.  *    Made #importing  pmap.h and vm_map.h dependent on #ifdef KERNEL.
  11.  * 25-Jan-90    Doug Mitchell at NeXT
  12.  *    Created.
  13.  *
  14.  */
  15.  
  16. #ifndef    _FDEXTERN_
  17. #define _FDEXTERN_
  18.  
  19. #import <sys/types.h>
  20. #import <sys/ioctl.h>
  21. #ifdef    KERNEL
  22. #import <machdep/machine/pmap.h>
  23. #import <vm/vm_map.h>
  24. #endif    KERNEL
  25.  
  26. #define FD_CMDSIZE    0x10        /* max size of command passed to 
  27.                      * controller */
  28. #define FD_STATSIZE    0x10        /* max size of status array returned
  29.                      * from controller */
  30.                      
  31. typedef    int fd_return_t;        /* see FDR_xxx, below */
  32.  
  33. struct fd_drive_stat {
  34.     u_char        media_id:2,    /* media type currently inserted. See
  35.                      * FD_MID_xxx, below. */
  36.              motor_on:1,    /* state of motor at I/O complete 
  37.                      * 1 = on; 0 = off */
  38.             write_prot:1,    /* write protect 1 = Write Protected */
  39.             drive_present:1,
  40.             rsvd1:3;    /* reserved */
  41. };
  42.  
  43. /*
  44.  * I/O request struct. Used in DKIOCREQ ioctl to specify one command sequence
  45.  * to be executed.
  46.  */
  47. struct fd_ioreq {
  48.     /* 
  49.      * inputs to driver:
  50.      */
  51.     u_char        density;    /* see FD_DENS_xxx, below */
  52.     int        timeout;    /* I/O timeout in milliseconds. Used
  53.                      * in FDCMD_CMD_XFR commands only. */
  54.     int        command;    /* see FDCMD_xxx, below */
  55.     u_char        cmd_blk[FD_CMDSIZE];
  56.                     /* actual command bytes */
  57.     u_int        num_cmd_bytes;    /* expected # of bytes in cmd_blk[] to
  58.                      * transfer */
  59.     caddr_t        addrs;        /* source/dest of data */
  60.     u_int        byte_count;    /* max # of data bytes to move */
  61.     u_char        stat_blk[FD_STATSIZE];
  62.                     /* status returned from controller */
  63.     u_int        num_stat_bytes;    /* number of status bytes to transfer
  64.                      * to stat_blk[] */
  65.     int         flags;        /* see FD_IOF_xxx, below */
  66.     
  67.     /*
  68.      * outputs from driver:
  69.      */
  70.     fd_return_t    status;        /* FDR_SUCCESS, etc. */
  71.     u_int        cmd_bytes_xfr;    /* # of command bytes actually moved */
  72.     u_int        bytes_xfr;    /* # of data bytes actually moved */
  73.     u_int        stat_bytes_xfr;    /* # if status bytes moved to 
  74.                      * stat_blk[] */
  75.     struct fd_drive_stat drive_stat; /* media ID, etc. */
  76.  
  77.     /*
  78.      * used internally by driver
  79.      */
  80. #ifdef    KERNEL
  81.     pmap_t        pmap;        /* DMA is mapped by this */
  82.     vm_map_t    map;        /* map of reque(3's task */
  83. #else    KERNEL
  84.     void        *pmap;
  85.     void        *map;
  86. #endif    KERNEL
  87.     u_char        unit;        /* drive # (relative to controller) */
  88. };
  89.  
  90. typedef struct fd_ioreq *fd_ioreq_t;
  91.  
  92. /*
  93.  * fd_ioreq.command values 
  94.  */
  95. #define FDCMD_BAD        0x00    /* not used */
  96. #define FDCMD_CMD_XFR        0x01    /* transfer command in fd_ioreq.cmd_blk
  97.                      */
  98. #define FDCMD_EJECT        0x02    /* eject disk */
  99. #define FDCMD_MOTOR_ON        0x03    /* motor on */
  100. #define FDCMD_MOTOR_OFF        0x04    /* motor off */
  101. #define FDCMD_GET_STATUS    0x05    /* Get status (media ID, motor state,
  102.                      * write protect) */
  103.  
  104. /*
  105.  * fd_ioreq.density values. Some routines rely on these being in
  106.  * cardinal order...
  107.  */
  108. #define FD_DENS_NONE    0        /* unformatted */
  109. #define FD_DENS_1    1        /* 1 MByte/disk unformatted */
  110. #define FD_DENS_2    2        /* 2 MByte/disk unformatted */
  111. #define FD_DENS_4    3        /* 4 MByte/disk unformatted */
  112.  
  113. /*
  114.  * fd_ioreq.flags values
  115.  */
  116. #define FD_IOF_DMA_DIR        0x00000002
  117. #define FD_IOF_DMA_RD        0x00000002    /* DMA direction = device to
  118.                          * host */
  119. #define FD_IOF_DMA_WR        0x00000000    /* DMA direction = host to
  120.                          * device */
  121.                          
  122. /*
  123.  * fdr_return_t values
  124.  */
  125. #define FDR_SUCCESS        0    /* OK */
  126. #define FDR_TIMEOUT        1    /* fd_ioreq.timeout exceeded */
  127. #define FDR_MEMALLOC        2    /* couldn't allocate memory */
  128. #define FDR_MEMFAIL        3    /* memory transfer error */
  129. #define FDR_REJECT        4    /* bad field in fd_ioreq */
  130. #define FDR_BADDRV        5    /* drive not present */
  131. #define FDR_DATACRC        6    /* media error - data CRC */
  132. #define FDR_HDRCRC        7    /* media error - header CRC */
  133. #define FDR_MEDIA        8    /* misc. media error */
  134. #define FDR_SEEK         9    /* seek error */
  135. #define FDR_BADPHASE        10    /* controller changed phase 
  136.                      * unexpectedly */
  137. #define FDR_DRIVE_FAIL        11    /* Basic Drive Failure */
  138. #define FDR_NOHDR        12    /* Header Not Found */
  139. #define FDR_WRTPROT        13    /* Disk Write Protected */
  140. #define FDR_NO_ADDRS_MK        14    /* Missing Address Mark */
  141. #define FDR_CNTRL_MK        15    /* Missing Control Mark */
  142. #define FDR_NO_DATA_MK        16    /* Missing Data Mark */
  143. #define FDR_CNTRL_REJECT    17    /* controller rejected command */
  144. #define FDR_CNTRLR        18    /* Controller Handshake Error */
  145. #define FDR_DMAOURUN        19    /* DMA Over/underrun */
  146. #define FDR_VOLUNAVAIL        20    /* Requested Volume not available */
  147.  
  148. /*
  149.  * fd_drive_stat.media_id values
  150.  */
  151. #define FD_MID_NONE        0    /* no disk inserted */
  152. #define FD_MID_1MB        3    /* 1 MByte unformatted */
  153. #define FD_MID_2MB        2    (4 MByte unformatted */
  154. #define FD_MID_4MB        1    /* 4 MBytes unformatted */
  155.  
  156.  
  157. /*
  158.  * ioctl's specific to floppy disk
  159.  */
  160. #define    FDIOCREQ    _IOWR('f', 0, struct fd_ioreq)    /* cmd request */
  161. #define FDIOCGFORM    _IOR ('f', 1, struct fd_format_info)
  162.                             /* get format */
  163. #define FDIOCSDENS    _IOW ('f', 2, int)        /* set density */
  164. #define FDIOCSSIZE    _IOW ('f', 3, int)        /* set sector size */
  165. #define FDIOCSGAPL    _IOW ('f', 4, int)        /* set Gap 3 length */
  166. #define FDIOCRRW    _IOWR('f', 5, struct fd_rawio)    /* raw read/write */
  167. #define FDIOCSIRETRY    _IOW ('f', 6, int)        /* set inner retry loop
  168.                              * count */
  169. #define FDIOCGIRETRY    _IOR ('f', 7, int)        /* get inner retry loop
  170.                              * count */
  171. #define FDIOCSORETRY    _IOW ('f', 8, int)        /* set outer retry loop
  172.                              * count */
  173. #define FDIOCGORETRY    _IOR ('f', 9, int)        /* get outer retry loop
  174.                              * count */
  175. /*
  176.  *     software registers passed to controller during command sequences 
  177.  */
  178.  
  179. struct fd_rw_cmd {
  180.     /*
  181.      * 9 command bytes passed at start of read/write data
  182.      */
  183.     u_char     mt:1,            /* multitrack */
  184.         mfm:1,            /* MFM encoding */
  185.         sk:1,            /* skip sectors with deleted AM */
  186.         opcode:5;
  187.     u_char    rsvd1:5,        /* reserved */
  188.         hds:1,            /* head select */
  189.         drive_sel:2;        /* drive select */
  190.     u_char    cylinder;
  191.     u_char    head;
  192.     u_char    sector;
  193.     u_char    sector_size;        /* 'n' in the Intel spec. */
  194.     u_char    eot;            /* sector # at end of track */
  195.     u_char    gap_length;        /* gap length */
  196.     u_char    dtl;            /* special sector size */
  197. };
  198.  
  199. #define SIZEOF_RW_CMD    9        /* compiler yields 9 as sizeof this
  200.                      * struct */
  201.                      
  202. struct fd_rw_stat {
  203.     /* 
  204.      * 7 status bytes passed at completion of read/write data 
  205.      */
  206.  
  207.     u_char    stat0;
  208.     u_char    stat1;
  209.     u_char     stat2;
  210.     u_char    cylinder;
  211.     u_char    head;
  212.     u_char    sector;
  213.     u_char    sector_size;        /* 'n' in the Intel spec. */
  214. };
  215.  
  216. #define SIZEOF_RW_STAT    7
  217.  
  218. struct fd_int_stat {
  219.     /* 
  220.      * result of Sense Interrupt Status command
  221.      */
  222.     u_char     stat0;    
  223.     u_char    pcn;            /* present cylinder & */
  224. };
  225.  
  226. struct fd_seek_cmd {
  227.     /* 
  228.      * Seek command. Uses Sense Interrupt Status to get results.
  229.      */
  230.     u_char    relative:1,        /* 1 = relative */
  231.         dir:1,            /* 1 == towards spindle */
  232.         opcode:6;        /* will be FCCMD_SEEK */
  233.     u_char    rsvd1:5,        /* reserved */
  234.         hds:1,            /* head select */
  235.         drive_sel:2;        /* drive select */
  236.     u_char    cyl;            /* cylinder # or offset */
  237. };
  238.  
  239. #define SEEK_DIR_IN        1        /* seek towards spindle */
  240. #(5ne SEEK_DIR_OUT        0        /* seek away from spindle */
  241.  
  242. #define SIZEOF_SEEK_CMD        3
  243.  
  244. struct fd_recal_cmd {
  245.     /* 
  246.      * Recalibrate command. Uses Sense Interrupt Status to get results.
  247.      */
  248.     u_char    opcode;            /* will be FCCMD_RECAL */
  249.     u_char    rsvd1:6,        /* reserved */
  250.         drive_sel:2;        /* drive select */
  251. };
  252.     
  253. struct fd_configure_cmd {
  254.     /*
  255.      * configure command. No result bytes are returned.
  256.      */
  257.     u_char     opcode;            /* will be FCCMD_CONFIGURE */
  258.     u_char    rsvd1;            /* must be 0 */
  259.     u_char     conf_2;            /* EIS, EFIFO, etc. */
  260.     u_char    pretrk;            /* write precomp track # */
  261. };
  262.  
  263. /*
  264.  * configure command fields 
  265.  */
  266. #define CF2_EIS            0x40    /* enable implied seek */
  267. #define CF2_EFIFO        0x20    /* enable FIFO. True Low. */
  268. #define CF2_DPOLL        0x10    /* disable polling */
  269. #define CF2_FIFO_DEFAULT    0x08    /* OUR default FIFO threshold */
  270. #define CF_PRETRACK        0x00    /* OUR default precom track */
  271. #define I82077_FIFO_SIZE    0x10    /* size of FIFO */
  272.  
  273. struct fd_specify_cmd {
  274.     /*
  275.      * Specify command. No result bytes are returned.
  276.      */
  277.     u_char     opcode;            /* will be FCCMD_SPECIFY */
  278.     u_char    srt:4,            /* step rate */
  279.          hut:4;            /* head unload time */
  280.     u_char    hlt:7,            /* head load time */
  281.         nd:1;            /* Non-DMA mode */
  282. };
  283.  
  284. #define SIZEOF_SPECIFY_CMD    3
  285.  
  286. struct fd_readid_cmd {
  287.     /* 
  288.      * Read ID command. Returns status in an fd_rw_stat.
  289.      */
  290.     u_char     rsvd1:1,
  291.         mfm:1,
  292.         opcode:6;        /* Will be FCCMD_READID */
  293.     u_char    rsvd2:5,        /* reserved */
  294.         hds:1,            /* head select */
  295.         drive_sel:2;        /* drive select */
  296. };
  297.  
  298. struct fd_perpendicular_cmd {
  299.     u_char    opcode;            /* will be FCCMD_PERPENDICULAR */
  300.     u_char    rsvd1:6,        /* must be 0 */
  301.         wgate:1,
  302.         gap:1;
  303. };
  304.  
  305. struct fd_format_cmd {
  306.     /*
  307.      * Format track command. Returns status in an fd_rw_stat
  308.      * (with undefined address fields).
  309.      */
  310.     u_char    rsvd1:1,
  311.         mfm:1,
  312.         opcode:6;        /* will be FCCMD_FORMAT */
  313.     u_char    rsvd2:5,        /* reserved */
  314.         hds:1,            /* head select */
  315.         drive_sel:2;        /* drive select */
  316.     u_char    n;            /* sector size (2**n * 128 = sect_size)
  317.                      */
  318.     u_char    sects_per_trk;
  319.     u_char    gap_length;
  320.     u_char    filler_data;        /* data field written with this byte */
  321. };
  322.  
  323. /*
  324.  *    software register values
  325.  */
  326.  
  327. /*
  328.  * cmd (command byte). Not all of these opcodes are used with the fd_rw_cmd 
  329.  * struct...
  330.  */
  331. #define FCCMD_OPCODE_MASK    0x1F
  332. #define    FCCMD_MULTITRACK    0x80
  333. #define FCCMD_MFM        0x40        /* MFM flag */
  334. #define FCCMD_SK        0x20        /* skip flag */
  335. #defi(6CCMD_READ        0x06
  336. #define FCCMD_READ_DELETE    0x0C
  337. #define FCCMD_WRITE        0x05
  338. #define FCCMD_WRITE_DELETE    0x09
  339. #define FCCMD_READ_TRACK    0x02
  340. #define FCCMD_VERIFY        0x16
  341. #define FCCMD_VERSION        0x10
  342. #define FCCMD_FORMAT        0x0D
  343. #define FCCMD_RECAL        0x07
  344. #define FCCMD_INTSTAT        0x08        /* sense interrupt status */
  345. #define FCCMD_SPECIFY        0x03
  346. #define FCCMD_DRIVE_STATUS    0x04
  347. #define FCCMD_SEEK        0x0F
  348. #define FCCMD_CONFIGURE        0x13
  349. #define FCCMD_DUMPREG        0x0E
  350. #define FCCMD_READID        0x0A        /* Read ID */
  351. #define FCCMD_PERPENDICULAR    0x12        /* perpendicular recording mode
  352.                          */
  353. /* 
  354.  * rws_stat0 (status register 0)
  355.  */
  356. #define SR0_INTCODE        0xC0    /* interrupt code - see INTCODE_xxx */
  357. #define INTCODE_COMPLETE    0x00    /* normal I/O complete */
  358. #define INTCODE_ABNORMAL    0x40    /* abnormal termination */
  359. #define INTCODE_INVALID        0x80    /* Invalid command */
  360. #define INTCODE_POLL_TERM    0xC0    /* abnormal termination caused by 
  361.                      * polling */
  362. #define SR0_SEEKEND        0x20    /* Seek End */
  363. #define SR0_EQ_CHECK        0x10    /* Equipment check (recal failed,
  364.                      *    seek beyond track 0, etc.) */
  365. #define SR0_HEAD        0x04    /* current head address */
  366. #define SR0_DRVSEL        0x03
  367. #define SR0_DRVSEL1        0x02    /* Drive Select 1 */
  368. #define SR0_DRVSEL0        0x01    /* Drive Select 0 */
  369.  
  370. /*
  371.  * rws_stat1 (status register 1)
  372.  */
  373. #define SR1_EOCYL        0x80    /* end of cylinder */
  374. #define SR1_CRCERR        0x20    /* data or ID CRC error */
  375. #define SR1_OURUN        0x10    /* DMA over/underrun */
  376. #define SR1_NOHDR        0x04    /* Header Not Found */
  377. #define SR1_NOT_WRT        0x02    /* Not writable */
  378. #define SR1_MISS_AM        0x01    /* Missing Address mark */
  379.  
  380. /*
  381.  * rws_stat2 (status register 2)
  382.  */
  383. #define SR2_CNTRL_MK        0x40    /* control mark */
  384. #define SR2_DATACRC        0x20    /* Data CRC error */
  385. #define SR2_WRONG_CYL        0x10    /* wrong cylinder */
  386. #define SR2_BAD_CYL        0x02    /* Bad cylinder */
  387. #define SR2_MISS_AM        0x01    /* missing data mark */
  388.  
  389. /*
  390.  * rws_stat3 (status register 3)
  391.  */
  392. #define SR3_WP            0x40    /* write protected */
  393. #define SR3_TRACK0        0x10    /* Track 0 */
  394. #define SR3_HEAD        0x04    /* Head # */
  395. #define SR3_DRVSEL1        0x02    /* same as status register 0?? */
  396. #define SR3_DEVSEL0        0x01    
  397.  
  398. /*
  399.  * disk info - maps media_id to tracks_per_cyl and num_cylinders.
  400.  */
  401. struct fd_disk_info {
  402.     u_int     media_id;            /* FD_MID_1MB, etc. */
  403.     u_char    tracks_per_cyl;            /* # of heads */
  404.     u_int    num_cylinders;    
  405.     u_int    max_density;            /* maximum legal density.
  406.                          *(7_DENS_1, etc.) */
  407. };
  408.  
  409. /*
  410.  * sector size info - maps sector size to 82077 sector size code and
  411.  * gap3 length.  Note that the controller must be programmed for different
  412.  * gap3 size when formatting as opposed to reading or writing.  Since gap3
  413.  * sizes may be dependent on the actual disk hardware, the fmt gap is
  414.  * maintained here to avoid requiring the formatter to determine
  415.  * the disk device type.
  416.  */
  417. struct fd_sectsize_info {
  418.     u_int         sect_size;        /* in bytes */
  419.     u_char        n;            /* 82077 sectsize code */
  420.     u_int        sects_per_trk;        /* physical sectors per trk */
  421.     u_char        rw_gap_length;        /* Gap 3 for rw cmds */ 
  422.     u_char        fmt_gap_length;        /* Gap 3 for fmt cmds */ 
  423. };
  424.  
  425. /*
  426.  * density info - maps density to capacity. Note that a disk may be formatted
  427.  * with a lower density than its max possible density.
  428.  */
  429. struct fd_density_info {
  430.     u_int         density;        /* FD_DENS_1, etc. */
  431.     u_int         capacity;        /* in bytes */
  432.     boolean_t    mfm;            /* TRUE = MFM encoding */
  433. };
  434.  
  435. /*
  436.  * disk format info. Used with ioctl(FDIOCGFORM).
  437.  */
  438. struct fd_format_info {
  439.     /*
  440.      * the disk_info struct is always valid as long as a disk is
  441.      * inserted.
  442.      */
  443.     struct fd_disk_info    disk_info;
  444.     
  445.     int            flags;        /* See FFI_xxx, below */
  446.  
  447.     /*
  448.      * the remainder is only valid if (flags & FFI_FORMATTED) is true.
  449.      */
  450.     struct fd_density_info    density_info;
  451.     struct fd_sectsize_info    sectsize_info;
  452.     u_int            total_sects;    /* total # of sectors on 
  453.                          * disk */
  454. };
  455.  
  456. /*
  457.  * fd_format_info.flags fields
  458.  */
  459. #define FFI_FORMATTED        0x00000001    /* known disk format */
  460. #define FFI_LABELVALID        0x00000002    /* Valid NeXT file system label
  461.                          * present */
  462. #define FFI_WRITEPROTECT    0x00000004    /* disk is write protected */
  463.                          
  464. struct format_data {
  465.     /* 
  466.      * one of these per sector. A Format command involves DMA'ing one of 
  467.      * these for each sector on a track. The format command is executed
  468.      * with a FDIOCREQ ioctl.
  469.      */
  470.     u_char cylinder;
  471.     u_char head;
  472.     u_char sector;
  473.     u_char n;            /* as in sector_size = 2**n * 128 */
  474. };
  475.  
  476. /*
  477.  * result of FCCMD_DUMPREG command
  478.  */
  479. struct fd_82077_regs {
  480.     u_char    pcn[4];        /* cylinder # for drives 0..3 */
  481.     u_char    srt:4,
  482.         hut:4;
  483.     u_char    hlt:7,
  484.         nd:1;
  485.     u_char    sc_eot;
  486.     u_char    rsvd1;
  487.     u_char    rsvd2:1,
  488.         eis:1,
  489.         efifo:1,
  490.         poll:1,
  491.         fifothr:4;
  492.     u_char    pretrk;
  493. };
  494.  
  495. /*
  496.  * Used for FDIOCRRW - raw disk I/O 
  497.  * -- no bad block mapping
  498.  * -- no label required
  499.  *(8no front porch 
  500.  * -- block size = physical sector size
  501.  */
  502. struct fd_rawio {
  503.     /*
  504.      * Passed to driver
  505.      */
  506.     u_int         sector;
  507.     u_int        sector_count;
  508.     caddr_t        dma_addrs;
  509.     boolean_t    read;        /* TRUE = read; FALSE = write */
  510.     /*
  511.      * Returned from driver
  512.      */
  513.     fd_return_t    status;        /* FDR_xxx (see above) */
  514.     u_int         sects_xfr;    /* sectors actually moved */
  515. };
  516.  
  517. /*
  518.  * misc. hardware constants
  519.  */
  520. #define NUM_FD_HEADS     2        /* number of tracks/cylinder */
  521. #define NUM_FD_CYL    80        /* cylinders/disk (is this actually a 
  522.                      * constant for all densities?) */
  523. #define FD_PARK_TRACK    79        /* track to which to seek before
  524.                      * eject */
  525. #define NUM_UNITS    4        /* max # of drives per controller */ 
  526.  
  527. #endif    _FDEXTERN_
  528.