home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / f / ftp-102.zip / ftape-1.02 / driver / ftape-regs.h < prev    next >
Text File  |  1992-10-12  |  13KB  |  384 lines

  1. /* Floppy disk controller and tape definitions.
  2.    Copyright (C) 1992 David L. Brown, Jr.
  3.  
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; see the file COPYING.  If not, write to
  16. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /*
  19.  * ftape-regs.h,v 1.3 1992/10/13 01:44:38 dbrown Exp
  20.  *
  21.  * ftape-regs.h,v
  22.  * Revision 1.3  1992/10/13  01:44:38  dbrown
  23.  * Added FSF copyright.
  24.  *
  25.  * Revision 1.2  1992/10/03  23:56:28  dbrown
  26.  * Moved enough of the old driver into the new to get drive status, and
  27.  * seek the tape and the tape head.
  28.  *
  29.  * Revision 1.1  1992/09/07  16:44:43  dbrown
  30.  * Copied from old tape driver.
  31.  *
  32.  */
  33.  
  34. /* I/O ports for the floppy disk controller.  The FDC is approximately
  35.    an Intel 82077. */
  36.  
  37. #define FDC_CONTROL_REGISTER    0x3f2
  38. #define FDC_STATUS_REGISTER    0x3f4
  39. #define FDC_DATA_REGISTER    0x3f5
  40. #define FDC_VFO_REGISTER    0x3f7
  41.  
  42. /* The control register contains the following bits: */
  43.  
  44. #define FDC_UNIT_MASK        0x01 /* 0 - unit select.  The unit
  45.                     to by used must be selected
  46.                     here.  This enables the
  47.                     drive select line. */
  48. #define FDC_RESET        0x04 /* 2 - Reset bit.  When 0 the
  49.                     !reset line is asserted on the
  50.                     FDC. */
  51. #define FDC_DMA_REQUEST        0x08 /* 3 - DMA request.  Unknown? */
  52. #define FDC_MOTOR_0        0x10 /* 4,5 - Motor select for drives
  53.                     0 and 1.  A 1 bit enables the
  54.                     motor. */
  55.  
  56. /* The status register (Main Status Register) gives the main status of
  57.    the FDC. */
  58.  
  59. #define FDC_STATUS_REQUEST_FOR_MASTER \
  60.             0x80    /* The FDC is ready to send or receive
  61.                    data through the data register.
  62.                    The data register should not be
  63.                    accessed unless this is set. */
  64. #define FDC_STATUS_DATA_OUT \
  65.             0x40    /* If set along with request for
  66.                    master, the FDC has data available
  67.                    that should be read from the data
  68.                    register. */
  69. #define FDC_STATUS_BUSY 0x10    /* The FDC is reading or writing and
  70.                    will not accept any commands. */
  71. #define FDC_STATUS_SEEK_MASK \
  72.             0x0f    /* The FDC is seeking disks.  Do not
  73.                    issue read or write requests. */
  74.  
  75. /* Commands themselves are pushed onto a stack through the data
  76.    register.  Each command has a specified number of fixed arguments
  77.    and returns a specified number of result values on return.  The
  78.    parameters are indicated here with a W for write.  The result codes
  79.    are indicated with an R for read. */
  80.  
  81. /* Specify timing parameters.
  82.    - SRT (Step rate time) is the interval between step pulses.
  83.    Encoded as 16 minus the number of ms.  (15 = 1ms, 14 = 2ms).
  84.    - HUT (Head unload time) is the time between the completion of a
  85.    read or write and the head unload.  Encoded in increments of 16ms
  86.    (1 = 16ms, 2 = 32ms).
  87.    - HLT (Head load time) is the time between the Head load signal
  88.    going high and the start of a read or write operation.  Encoded in
  89.    increments of 2 ms (1 = 2ms, 2 = 4ms, 127 = 254ms).
  90.    - ND (Non-dma) selects non-dma mode.
  91.         7  6  5  4  3  2  1  0
  92.    W - ........Specify.........
  93.    W - ....SRT.... ....HUT.....
  94.    W - .........HLT......... ND */
  95.  
  96. #define FDC_SPECIFY        0x03
  97.  
  98. /* Sense drive status.  Return drive status ST3.
  99.    US is the 2 bit unit number.
  100.         7  6  5  4  3  2  1  0
  101.    W - ...Sense drive status...
  102.    W -  X  X  X  X  X  0 ..US..
  103.    ----------------------------
  104.    R - ..........ST3........... */
  105.  
  106. #define FDC_SENSE_DRIVE_STATUS    0x04
  107.  
  108. /* Recalibrate.  Issue up to 77 step pulses toward track 0 testing the
  109.    track 0 detect each time.  Once the seek completes the FDC will
  110.    interrupt.  If track 0 was found, the interrupt code in ST0 will be
  111.    normal, and the seek end bit will be set.  If it was not found, the
  112.    interrupt code will be abnormal and the equipment check bit will be
  113.    set as well (see FDC_SENSE_INTERRUPT_STATUS).
  114.    - US is the unit number.
  115.         7  6  5  4  3  2  1  0
  116.    W - ......Recalibrate.......
  117.    W -  X  X  X  X  X  0 ..US.. */
  118.  
  119. #define FDC_RECALIBRATE        0x07
  120.  
  121. /* Sense interrupt status.  Returns status register 0 (ST0) and the
  122.    present cylinder number (PCN).
  123.         7  6  5  4  3  2  1  0
  124.    W - ..........SIS...........
  125.    ----------------------------
  126.    R - ..........ST0...........
  127.    R - ..........PCN........... */
  128.  
  129. #define FDC_SENSE_INTERRUPT_STATUS    0x08
  130.  
  131. /* Seek.  Issue step pusles to move the drive to the new track.  When
  132.    completed, PCN will be set the the new cylinder number, and ST0
  133.    will have the seek end bit set.
  134.         7  6  5  4  3  2  1  0
  135.    W - ..........Seek..........
  136.    W -  X  X  X  X  X  HD .US..
  137.    W - ..........NCN........... */
  138.  
  139. #define FDC_SEEK        0x0f
  140.  
  141. /* Read Data.  Read data from the media.  The controller loads the
  142.    head if necessary then begins looking for the appropriate cylinder,
  143.    head, and sector.  If two index holes pass by, the read terminates.
  144.    The gap length should be set to 218 (why?).  The SK bit is set here
  145.    causing deleted data sectors to be skipped.
  146.         7  6  5  4  3  2  1  0
  147.    W - .......READ_DATA........ [0]
  148.    W - ............... HD .US.. [1]
  149.    W - ........Cylinder........ [2]
  150.    W - ..........Head.......... [3]
  151.    W - .........Sector......... [4]
  152.    W - .......Sector_Size...... [5]
  153.    W - ......End_of_Track...... [6]
  154.    W - .......Gap_Length....... [7]
  155.    W - ..........DTL........... [8]
  156.    ----------------------------
  157.    R - ..........ST0........... [0]
  158.    R - ..........ST1........... [1]
  159.    R - ..........ST2........... [2]
  160.    R - ........Cylinder........ [3]
  161.    R - ..........Head.......... [4]
  162.    R - .........Sector......... [5]
  163.    R - .......Sector_Size...... [6] */
  164.  
  165. #define FDC_READ_DATA        (0x46 | 0x20)
  166.  
  167. /* Read a track, same arguments as read_data.  The entire track is
  168.    read starting after the next index pulse.  The data will be read
  169.    even if errors occurred. */
  170.  
  171. #define FDC_READ_TRACK        0x42
  172.  
  173. /* Write data, same arguments as read_data. */
  174.  
  175. #define FDC_WRITE_DATA        0x45
  176.  
  177. /* Read ID.  Reads the ID of the next available sector.  ST0 is set to
  178.    abnormal termination if two index pulses go by without reading
  179.    anything.
  180.         7  6  5  4  3  2  1  0
  181.    W - ........READ_ID.........
  182.    W - ............... HD .US..
  183.    ----------------------------
  184.    R - ..........ST0........... [0]
  185.    R - ..........ST1........... [1]
  186.    R - ..........ST2........... [2]
  187.    R - ........Cylinder........ [3]
  188.    R - ..........Head.......... [4]
  189.    R - .........Sector......... [5]
  190.    R - .......Sector_Size...... [6] */
  191.  
  192. #define FDC_READ_ID        0x4a
  193.  
  194. /* Status information. */
  195.  
  196. /* Status register 0 is the interrupt status register.  When an
  197.    interrupt occurs, the SENSE_INTERRUPT_STATUS command should be
  198.    issued to determine why. */
  199.  
  200. /* The reason for the interrupt is storred in the top two bits.
  201.    Normal means that a command has completed.  Abnormal means that the
  202.    command did not complete (such as a recalibrate with no track 0).
  203.    Invalid means the command was never issued.  Ready changed
  204.    indicates that the drive ready bit on one of the drives has changed
  205.    (such as inserting or removing a disk). */
  206.  
  207. #define ST0_CODE_MASK    0xc0
  208. #define ST0_NORMAL    0x00
  209. #define ST0_ABNORMAL    0x40
  210. #define ST0_INVALID    0x80
  211. #define ST0_READY_CHANGED 0xc0
  212.  
  213. #define ST0_SEEK_END    0x20    /* A seek command has completed. */
  214. #define ST0_EQUIPMENT_CHECK 0x10 /* Recalibrate failed. */
  215. #define ST0_NOT_READY    0x08    /* Read or write attempted while drive
  216.                    not ready. */
  217. #define ST0_HEAD_ADDRESS 0x04    /* State of the head at the interrupt. */
  218. #define ST0_UNIT_MASK    0x03    /* Unit selected at time of interupt. */
  219.  
  220. /* Status register 1.  Reports result from reading or writing. */
  221.  
  222. #define ST1_END_OF_CYLINDER    0x80 /* Read past last sector of the
  223.                     track. */
  224. #define ST1_DATA_ERROR        0x20 /* A CRC error occurred on either
  225.                     the ID field or the data
  226.                     field. */
  227. #define ST1_OVERRUN        0x10 /* A data over or under run
  228.                     occurred.  Probably means the
  229.                     DMA controller is not properly
  230.                     configured. */
  231. #define ST1_NO_DATA        0x04 /* The command could not find the
  232.                     proper data to read/write. */
  233. #define ST1_NOT_WRITABLE    0x02 /* Write Protect became asserted
  234.                     during write. */
  235. #define ST1_MISSING_ADDRESS_MARK 0x01 /* Address mark was missing. */
  236.  
  237. /* Status register 2.  This reports result from a read or write. */
  238.  
  239. #define ST2_CONTROL_MARK    0x40 /* A read found a deleted sector,
  240.                     or a read deleted sector found
  241.                     a non/deleted sector. */
  242. #define ST2_DATA_ERROR        0x20 /* A CRC error occurred in the
  243.                     data field. */
  244. #define ST2_WRONG_CYLINDER    0x10 /* The FDC thinks we're on a
  245.                     different track than what was
  246.                     read. */
  247. #define ST2_BAD_CYLINDER    0x02 /* The FDC encountered a cylinder
  248.                     marked bad. */
  249. #define ST2_MISSING_DATA_MARK    0x01 /* The data address mark was not
  250.                     found. */
  251.  
  252. /* Status register 3.  This reports the current status and state of
  253.    the drive.  This is returned with report drive status. */
  254.  
  255. #define ST3_FAULT    0x80    /* From the fault signal on the drive.
  256.                    This might not be connected. */
  257. #define ST3_WRITE_PROTECT 0x40    /* From the write protect line on the
  258.                    drive. */
  259. #define ST3_READY    0x20    /* Drive ready indicator.  This might
  260.                    be connected to disk change. */
  261. #define ST3_TRACK_0    0x10    /* Track 0 indicator from line. */
  262. #define ST3_2_SIDE    0x08    /* 2 side line.  Probably not
  263.                    connected. */
  264. #define ST3_HEAD_ADDRESS 0x04    /* Which side is selected. */
  265. #define ST3_UNIT_MASK    0x03    /* Unit selected. */
  266.  
  267. /* Unit number for the tape drive. */
  268.  
  269. #define FDTAPE_UNIT 1
  270. #undef FDTAPE_USE_MOTOR
  271.  
  272. /* QIC commands.  These commands are sent as pulses over the step
  273.    line. */
  274.  
  275. #define QIC_RESET            1
  276. #define QIC_REPORT_NEXT_BIT        2
  277. #define QIC_PAUSE            3
  278. #define QIC_MICRO_STEP_PAUSE        4
  279. #define QIC_ALTERNATE_TIMEOUT        5
  280. #define QIC_REPORT_DRIVE_STATUS        6
  281. #define QIC_REPORT_ERROR_CODE        7
  282. #define QIC_REPORT_DRIVE_CONFIGURATION    8
  283. #define QIC_REPORT_ROM_VERSION        9
  284. #define QIC_LOGICAL_FORWARD        10
  285. #define QIC_PHYSICAL_REVERSE        11
  286. #define QIC_PHYSICAL_FORWARD        12
  287. #define QIC_SEEK_HEAD_TO_TRACK        13
  288. #define QIC_SEEK_LOAD_POINT        14
  289. #define QIC_ENTER_FORMAT_MODE        15
  290. #define QIC_WRITE_REFERENCE_BURST    16
  291. #define QIC_ENTER_VERIFY_MODE        17
  292. #define QIC_STOP_TAPE            18
  293. #define QIC_MICRO_STEP_HEAD_UP        21
  294. #define QIC_MICRO_STEP_HEAD_DOWN    22
  295. #define QIC_SKIP_REVERSE        25
  296. #define QIC_SKIP_FORWARD        26
  297. #define QIC_SELECT_RATE            27
  298. #define QIC_ENTER_PRIMARY_MODE        28
  299. #define QIC_REPORT_VENDOR_ID        32
  300.  
  301. /* In order to allow the tape drives to coexist with floppy drives at
  302.    the same unit, manufacturers have added their own commands that
  303.    enable and disable the tape drives.  The Mountain Tape drive
  304.    requires two commands to enable.  However, this drive doesn't care
  305.    about motor on so it is conceivable that ordinary floppy use could
  306.    enable the drive causing unusual havoc. */
  307.  
  308. #define QIC_COLORADO_ENABLE1        46
  309. #define QIC_COLORADO_ENABLE2        2
  310. #define QIC_COLORADO_DISABLE        47
  311. #define QIC_MOUNTAIN_ENABLE1        23
  312. #define QIC_MOUNTAIN_ENABLE2        20
  313. #define QIC_MOUNTAIN_DISABLE        24
  314.  
  315. /* Drive types detected by startup. */
  316.  
  317. enum _drive_types {
  318.   DRIVE_IS_UNKNOWN,
  319.   DRIVE_IS_COLORADO,
  320.   DRIVE_IS_MOUNTAIN,
  321. };
  322.  
  323. /* I don't know why this is in each driver. */
  324.  
  325. #ifndef HZ
  326. # define HZ 100
  327. #endif
  328. /* We can't actually sleep for a millisecond.  This is as close as we
  329.    get. */
  330. #define MILLISECOND 2
  331.  
  332. /* Timeouts for various operations. */
  333.  
  334. #define RECALIBRATE_RESULT_RETRIES 3
  335. #define RECALIBRATE_TIMEOUT    (5 * HZ)
  336. #define SEEK_RESULT_RETRIES  3
  337. #define SEEK_TIMEOUT (5 * HZ)
  338. #define READ_TIMEOUT (10 * HZ)
  339. #define WRITE_TIMEOUT (10 * HZ)
  340.  
  341. #define fdt_spl spl4
  342.  
  343. /* Number of times to retry reading the controller status before a
  344.    timeout is given. */
  345.  
  346. #define FDC_STATUS_RETRIES 0x2800
  347.  
  348. /* Parameters to specify for different modes.  Recalibrate causes the
  349.    head to step slower to keep the drive from interpreting the seek as
  350.    a command, and to keep from damaging any floppy drives. */
  351.  
  352. #define specify_normal()   specify (13, 15, 1, 0)
  353. #define specify_recalibrate()    specify (13, 10, 1, 0)
  354.  
  355. /* Reasons to be waken. */
  356.  
  357. #define WAKEN_BY_TIMEOUT  1
  358. #define WAKEN_BY_INTERRUPT 2
  359.  
  360. /* DMA registers and values.  Refer to documentation on Intel 8237 for
  361.    details. */
  362.  
  363. #define DMA_COMMAND    0x08    /* Command register */
  364. #define DMA_MASK    0x0f    /* Set the mask register.  A 0 bit
  365.                    means this DMA channel is masked. */
  366. #define DMA_MODE    0x0b    /* Mode of dma operation.  See below
  367.                    for meaningful values here. */
  368. #define DMA_CLEAR_FLIP_FLOP  0x0c /* Must write before writing the
  369.                      address. */
  370. #define DMA_ADDRESS    0x04    /* Write 2 bytes, low byte first for
  371.                    the first 16 bits of the address. */
  372. #define DMA_COUNT    0x05    /* Write 2 bytes, low byte first for
  373.                    the 16 bits of the count.  1
  374.                    greater than this value will be
  375.                    copied. */
  376. #define DMA_PAGE    0x81    /* bits 16-23 of the address.  This
  377.                    allows for a 16Meg address range. */
  378. #define DMA_MASK_BIT    0x0a    /* Enable a single channel by setting
  379.                    the bit here.  The other channels
  380.                    are not affected. */
  381.  
  382. #define DMA_MODE_READ    0x46
  383. #define DMA_MODE_WRITE    0x4a
  384.