home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / DASD / CDROM / ATAPI / ATAPIDAT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-14  |  19.1 KB  |  382 lines

  1. /*DDK*************************************************************************/
  2. /*                                                                           */
  3. /* COPYRIGHT    Copyright (C) 1995 IBM Corporation                           */
  4. /*                                                                           */
  5. /*    The following IBM OS/2 WARP source code is provided to you solely for  */
  6. /*    the purpose of assisting you in your development of OS/2 WARP device   */
  7. /*    drivers. You may use this code in accordance with the IBM License      */
  8. /*    Agreement provided in the IBM Device Driver Source Kit for OS/2. This  */
  9. /*    Copyright statement may not be removed.                                */
  10. /*                                                                           */
  11. /*****************************************************************************/
  12. /**************************************************************************
  13.  *
  14.  * SOURCE FILE NAME = ATAPIDAT.C
  15.  *
  16.  * DESCRIPTION : Global Data for ATAPI driver
  17.  *
  18.  *
  19.  *
  20.  * VERSION = 1.0
  21.  *
  22.  * DATE
  23.  *
  24.  * DESCRIPTION :
  25.  *
  26.  * Purpose:
  27.  *
  28.  *
  29. */
  30. #define INCL_NOBASEAPI
  31. #define INCL_NOPMAPI
  32. #include "os2.h"
  33. #include "dos.h"
  34. #include "dskinit.h"
  35.  
  36. #include "iorb.h"
  37. #include "addcalls.h"
  38. #include "dhcalls.h"
  39.  
  40. #define INCL_INITRP_ONLY
  41. #include "reqpkt.h"
  42.  
  43. #include "scsi.h"
  44. #include "cdbscsi.h"
  45.  
  46. #include "atapicon.h"
  47. #include "atapireg.h"
  48. #include "atapityp.h"
  49. #include "atapiext.h"
  50. #include "atapipro.h"
  51.  
  52. ACBPTRS      ACBPtrs[MAX_ADAPTERS] = { { 0, &AdapterIRQ0 },
  53.                                        { 0, &AdapterIRQ1 },
  54.                                        { 0, &AdapterIRQ2 },
  55.                                        { 0, &AdapterIRQ3 } };
  56. USHORT       InitComplete          = 0;
  57. USHORT       startresume           = 0;
  58. USHORT       startsuspend          = 0;
  59. PFN          Device_Help           = 0L;
  60. USHORT       ADDHandle             = 0;
  61. USHORT       cAdapters             = 0;
  62. USHORT       cUnits                = 0;
  63. USHORT       InitActive            = 0;
  64. USHORT       InitIOComplete        = 0;
  65. USHORT       MachineID             = 0;
  66. USHORT       Calibrate             = 0;
  67. ULONG        WaitDRQCount          = 0;
  68. ULONG        WaitBSYCount          = 0;                              /*V@93531*/
  69. ULONG        CheckReadyCount       = 0;
  70. ULONG        IODelayCount          = 0;
  71. ULONG        ElapsedTimerHandle    = 0;
  72. UCHAR        AdapterName[17]       = "ATAPI CDROM"; /* Adapter Name ASCII string */
  73. LIN          plDataSeg             = 0;
  74. LIN          plSwapCode            = 0;
  75. USHORT       SwapCodeLen           = 0;
  76. USHORT       ADDLockCount          = 0;
  77. LIN          plADDLockHandle       = 0;
  78. #define      TASKTIME               -1L
  79. PULONG       pNestedIntCount       = 0;
  80. USHORT       cInt                  = 0;
  81. UCHAR        ADDLockHandle[12]     = { 0 };
  82.  
  83. UCHAR        SenseDataBuf[SENSE_DATA_BYTES] = { 0 };
  84. ULONG        ppSenseDataBuf          = 0;
  85. SCATGATENTRY SenseDataSGList         = { 0, SENSE_DATA_BYTES };
  86.  
  87. USHORT AddSenseDataMap[] = {
  88.    0,                                /* 00h No sense information              */
  89.    IOERR_RBA_ADDRESSING_ERROR,       /* 01h No index/sector signal            */
  90.    IOERR_RBA_ADDRESSING_ERROR,       /* 02h No seek complete                  */
  91.    IOERR_RBA_CRC_ERROR,              /* 03h Write fault                       */
  92.    IOERR_UNIT_NOT_READY,             /* 04h Drive not ready                   */
  93.    IOERR_ADAPTER_DEVICE_TIMEOUT,     /* 05h LUN not selected                  */
  94.    IOERR_RBA_ADDRESSING_ERROR,       /* 06h No track zero found                           */
  95.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 07h Multiple drives selected          */
  96.    IOERR_ADAPTER_DEVICE_TIMEOUT,     /* 08h Logical unit communication failure*/
  97.    IOERR_RBA_ADDRESSING_ERROR,       /* 09h Track following error             */
  98.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 0Ah Reserved                          */
  99.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 0Bh Reserved                          */
  100.    IOERR_RBA_CRC_ERROR,              /* 0Ch Write Error                       */
  101.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 0Dh Reserved                          */
  102.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 0Eh Reserved                          */
  103.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 0Fh Reserved                          */
  104.    IOERR_RBA_ADDRESSING_ERROR,       /* 10h ID CRC or ECC error               */
  105.    IOERR_RBA_CRC_ERROR,              /* 11h Unrecovered Read error            */
  106.    IOERR_RBA_ADDRESSING_ERROR,       /* 12h No address mark found             */
  107.    IOERR_RBA_ADDRESSING_ERROR,       /* 13h No addr mark in data field        */
  108.    IOERR_RBA_ADDRESSING_ERROR,       /* 14h No record found                   */
  109.    IOERR_RBA_ADDRESSING_ERROR,       /* 15h Seek positioning error            */
  110.    IOERR_RBA_ADDRESSING_ERROR,       /* 16h Data synchroniztion mark error    */
  111.    IOERR_RBA_CRC_ERROR,              /* 17h Recovered read w/ retries         */
  112.    IOERR_RBA_CRC_ERROR,              /* 18h Recovered read data w/correction  */
  113.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 19h Defect list error                 */
  114.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 1Ah Parameter overrun                 */
  115.    IOERR_ADAPTER_DEVICEBUSCHECK,     /* 1Bh Synchronous transfer err          */
  116.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 1Ch Primary defect list not found     */
  117.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 1Dh Compare error                     */
  118.    IOERR_RBA_ADDRESSING_ERROR,       /* 1Eh Recovered ID with ECC correction  */
  119.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 1Fh Reserved                          */
  120.    IOERR_CMD_SYNTAX,                 /* 20h Invalid command op code           */
  121.    IOERR_RBA_ADDRESSING_ERROR,       /* 21h Illegal logical blk addr          */
  122.    IOERR_CMD_SYNTAX,                 /* 22h Illegal func for dev type         */
  123.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 23h Reserved                          */
  124.    IOERR_CMD_SYNTAX,                 /* 24h Illegal field in CDW              */
  125.    IOERR_CMD_SYNTAX,                 /* 25h Invalid LUN                       */
  126.    IOERR_CMD_SYNTAX,                 /* 26h Invalid param list field          */
  127.    IOERR_MEDIA_WRITE_PROTECT,        /* 27h Write protected                   */
  128.    IOERR_MEDIA_CHANGED,              /* 28h Medium changed                    */
  129.    IOERR_DEVICE_RESET,               /* 29h Power on reset or bus device reset*/
  130.    IOERR_MEDIA_CHANGED,              /* 2Ah Mode select parameters changed    */
  131.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 2Bh Reserved                          */
  132.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 2Ch Reserved                          */
  133.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 2Dh Reserved                          */
  134.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 2Eh Reserved                          */
  135.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 2Fh Reserved                          */
  136.    IOERR_MEDIA_NOT_SUPPORTED,        /* 30h Incompatible cartridge            */
  137.    IOERR_MEDIA_NOT_FORMATTED,        /* 31h Medium format corrupted           */
  138.    IOERR_MEDIA_NOT_FORMATTED,        /* 32h No defect spare location available*/
  139.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 33h Reserved                          */
  140.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 34h Reserved                          */
  141.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 35h Reserved                          */
  142.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 36h Reserved                          */
  143.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 37h Reserved                          */
  144.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 38h Reserved                          */
  145.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 39h Reserved                          */
  146.    IOERR_MEDIA_NOT_PRESENT,          /* 3Ah Medium Not Present                */
  147.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 3Bh Reserved                          */
  148.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 3Ch Reserved                          */
  149.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 3Dh Reserved                          */
  150.    IOERR_UNIT_NOT_READY,             /* 3Eh LUN  not self-configured yet      */
  151.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 3Fh Reserved                          */
  152.    IOERR_DEVICE_DIAGFAIL,            /* 40h RAM failure                       */
  153.    IOERR_DEVICE_DIAGFAIL,            /* 41h Data path diagnostic failure      */
  154.    IOERR_DEVICE_DIAGFAIL,            /* 42h Power-on diag failure             */
  155.    IOERR_DEVICE_DEVICEBUSCHECK,      /* 43h Message reject error              */
  156.    IOERR_DEVICE,                     /* 44h Internal controller error         */
  157.    IOERR_UNIT_NOT_READY,             /* 45h Select/reselect failed            */
  158.    IOERR_DEVICE_BUSY,                /* 46h Unsuccessful soft reset           */
  159.    IOERR_DEVICE_DEVICEBUSCHECK,      /* 47h SCSI interface parity error       */
  160.    IOERR_DEVICE_DEVICEBUSCHECK,      /* 48h Initiator detected error          */
  161.    IOERR_DEVICE_DEVICEBUSCHECK,      /* 49h Inappropriate/illegal message     */
  162.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 50H - Reserved                      */
  163.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 51H - Reserved                      */
  164.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 52H - Reserved                      */
  165.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 53H - Media Load or eject failed    */
  166.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 54H - Reserved                      */
  167.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 55H - Reserved                      */
  168.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 56H - Reserved                      */
  169.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 57H - Unable to recover TOC         */
  170.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 58H - Reserved                      */
  171.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 59H - Reserved                      */
  172.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 5AH - Operator request/state change */
  173.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 5BH - LOG exception                 */
  174.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 5CH - Reserved                      */
  175.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 5DH - Reserved                      */
  176.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 5EH - Reserved                      */
  177.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 5FH - Reserved                      */
  178.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 60H - Reserved                      */
  179.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 61H - Reserved                      */
  180.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 62H - Reserved                      */
  181.    IOERR_ADAPTER_REFER_TO_STATUS,    /* 63H - End of User area encountered  */
  182.    IOERR_MEDIA_NOT_SUPPORTED         /* 64H - Illegal Mode for this track   */
  183.    };
  184.  
  185.    USHORT       MaxAddSenseDataEntry =
  186.                                   ( sizeof(AddSenseDataMap) / sizeof(USHORT) );
  187.  
  188. USHORT       ACBPoolAvail          = ACB_POOL_SIZE + TIMER_POOL_SIZE +
  189.                                      UNITINFO_POOL_SIZE;
  190.  
  191. UCHAR        ACBPool[ACB_POOL_SIZE + TIMER_POOL_SIZE +
  192.                      UNITINFO_POOL_SIZE] = { 0 };
  193.  
  194. NPBYTE       npACBPool             = ACBPool;
  195.  
  196. /* The throw away section begins with npACBPool.  (At the end of init, it has
  197.    been incremented by the amount of used memory for internal structures.  Any
  198.    unused portion, and all the init data is then thrown away.) */
  199.  
  200. UCHAR        ScratchBuf[SCRATCH_BUF_SIZE]  = { 0 };
  201. UCHAR        ScratchBuf1[SCRATCH_BUF_SIZE]  = { 0 };
  202.  
  203. USHORT       ComPort               = COM2ADDRESS;
  204. USHORT       cResets               = 0;
  205.  
  206. ATBL         AdapterTable[MAX_ADAPTERS] =
  207. {
  208.    /*┌──────────────────────────────────────────────────────────────────────┐
  209.      │ Port, IRQ, IRQHandler,       Flags,            Status, npACB, cUnits │
  210.      │                                       Unit Flags, Unit Status        │
  211.      │                                       Unit Flags, Unit Status        │
  212.      └──────────────────────────────────────────────────────────────────────┘*/
  213.      {0,     0, &AdapterIRQ0, ATBF_DISABLED | ATBF_SHARED_ADAPTER, 0, 0 ,0,
  214.                                                   {{0, UTS_NOT_PRESENT},
  215.                                                    {0, UTS_NOT_PRESENT}} },
  216.  
  217.      {0,     0, &AdapterIRQ1, ATBF_DISABLED | ATBF_SHARED_ADAPTER, 0, 0 ,0,
  218.                                                   {{0, UTS_NOT_PRESENT},
  219.                                                    {0, UTS_NOT_PRESENT}} },
  220.  
  221.      {0,     0, &AdapterIRQ2, ATBF_DISABLED | ATBF_SHARED_ADAPTER, 0, 0 ,0,
  222.                                                   {{0, UTS_NOT_PRESENT},
  223.                                                    {0, UTS_NOT_PRESENT}} },
  224.  
  225.      {0,     0, &AdapterIRQ3, ATBF_DISABLED | ATBF_SHARED_ADAPTER, 0, 0 ,0,
  226.                                                   {{0, UTS_NOT_PRESENT},
  227.                                                    {0, UTS_NOT_PRESENT}} }
  228. };
  229.  
  230.  
  231.  
  232.  
  233. /*
  234. ┌────────────────────────────────────┐
  235. │                                    │
  236. │    Initialization Data             │
  237. │                                    │
  238. │                                    │
  239. │ This is the address of the         │
  240. │ discardable data.  All data        │
  241. │ references after this point will   │
  242. │ be discarded after init.           │
  243. └────────────────────────────────────┘ */
  244. UCHAR        BeginInitData         = 0;
  245.  
  246. BOOL         Verbose               = FALSE;
  247. BOOL         Installed             = FALSE;
  248.  
  249. UCHAR       TimersCalibrated       = 0;
  250.  
  251.  
  252. #define      MSG_REPLACEMENT_STRING  1178
  253.  
  254.  
  255. MSGTABLE     InitMsg               = { MSG_REPLACEMENT_STRING,
  256.                                        1,
  257.                                        0                      };
  258.  
  259. UCHAR AdptMsg0[] = "OK";
  260. UCHAR AdptMsg1[] = "Adapter not located";
  261. UCHAR AdptMsg2[] = "Adapter skipped";
  262. UCHAR AdptMsg3[] = "Failed to set IRQ";
  263.  
  264. NPSZ AdptMsgs[] = { AdptMsg0,
  265.                     AdptMsg1,
  266.                     AdptMsg2,
  267.                     AdptMsg3 };
  268.  
  269. UCHAR UnitMsg0[] = "OK - Device Filtered";
  270. UCHAR UnitMsg1[] = "";
  271.  
  272. NPSZ UnitMsgs[] = { UnitMsg0,
  273.                     UnitMsg1 };
  274.  
  275. UCHAR ProtocolTypeMsg0[] = "     ATA";
  276. UCHAR ProtocolTypeMsg1[] = "     ATA";
  277. UCHAR ProtocolTypeMsg2[] = "   ATAPI";
  278. UCHAR ProtocolTypeMsg3[] = "Reserved";
  279.  
  280. NPSZ ProtocolTypeMsgs[] = { ProtocolTypeMsg0,
  281.                             ProtocolTypeMsg1,
  282.                             ProtocolTypeMsg2,
  283.                             ProtocolTypeMsg3 };
  284.  
  285. UCHAR DeviceTypeMsg0[] = "             Reserved";
  286. UCHAR DeviceTypeMsg1[] = " Direct-Access Device";
  287. UCHAR DeviceTypeMsg2[] = "               CD-ROM";
  288. UCHAR DeviceTypeMsg3[] = "Optical Memory Device";
  289. UCHAR DeviceTypeMsg4[] = "              Unknown";
  290.  
  291. NPSZ DeviceTypeMsgs[] = { DeviceTypeMsg1, DeviceTypeMsg0,
  292.                           DeviceTypeMsg0, DeviceTypeMsg0,
  293.                           DeviceTypeMsg0, DeviceTypeMsg2,
  294.                           DeviceTypeMsg0, DeviceTypeMsg3,
  295.                           DeviceTypeMsg0, DeviceTypeMsg0,
  296.                           DeviceTypeMsg0, DeviceTypeMsg0,
  297.                           DeviceTypeMsg0, DeviceTypeMsg0,
  298.                           DeviceTypeMsg0, DeviceTypeMsg0,
  299.                           DeviceTypeMsg0, DeviceTypeMsg0,
  300.                           DeviceTypeMsg0, DeviceTypeMsg0,
  301.                           DeviceTypeMsg0, DeviceTypeMsg0,
  302.                           DeviceTypeMsg0, DeviceTypeMsg0,
  303.                           DeviceTypeMsg0, DeviceTypeMsg0,
  304.                           DeviceTypeMsg0, DeviceTypeMsg0,
  305.                           DeviceTypeMsg0, DeviceTypeMsg0,
  306.                           DeviceTypeMsg0, DeviceTypeMsg4 };
  307.  
  308. UCHAR CMDDRQTypeMsg0[] = "Microprocessor DRQ";
  309. UCHAR CMDDRQTypeMsg1[] = "     Interrupt DRQ";
  310. UCHAR CMDDRQTypeMsg2[] = "   Accelerated DRQ";
  311. UCHAR CMDDRQTypeMsg3[] = "          Reserved";
  312.  
  313. NPSZ CMDDRQTypeMsgs[] = { CMDDRQTypeMsg0,
  314.                           CMDDRQTypeMsg1,
  315.                           CMDDRQTypeMsg2,
  316.                           CMDDRQTypeMsg3 };
  317.  
  318. UCHAR        ParmErrMsg[]          = " Warning: IBMIDECD.FLT - Invalid CONFIG.SYS parameters";
  319. UCHAR        UninstallMsg[]        = " Warning: IBMIDECD.FLT - Driver did not load";
  320. UCHAR        VersionMsg[]          =
  321.             "╔═══════════════════════════════════════════════════════════╗\r\n"
  322.             "║                                                           ║\r\n"
  323.             "║ IBM ATAPI (IDE) CDROM Filter for OS/2 2.x & 3.x (v011095) ║\r\n"
  324.             "║                                                           ║\r\n"
  325.             "╚═══════════════════════════════════════════════════════════╝\0";
  326. UCHAR        DevEqualsMsg[]        =
  327.                    "╔════════════════════════════════════════════════════╗\r\n"
  328.                    "║                                                    ║\r\n"
  329.                    "║ IBM ATAPI (IDE) CDROM Driver for OS/2 requires     ║\r\n"
  330.                    "║ the following statement in your config.sys file:   ║\r\n"
  331.                    "║                                                    ║\r\n"
  332.                    "║ BASEDEV=ibmidecd.flt                               ║\r\n"
  333.                    "║                                                    ║\r\n"
  334.                    "╚════════════════════════════════════════════════════╝\0";
  335.  
  336. ULONG        CalibrateTimerHandle   = 0;
  337. ULONG        CallWorkerSync         = 0;
  338. ULONG        CallWorker             = 0;
  339.  
  340. UCHAR                 StringBuffer[80] = { 0 };
  341. UCHAR                 INTStringBuffer[80] = { 0 };
  342. IORB_ADAPTER_PASSTHRU InitIORB = { 0 };
  343. SCATGATENTRY          IdentifySGList         = { 0, 512 };
  344.  
  345. UCHAR        SearchKeytxt[]        = "IDE_0";
  346. HDRIVER      hDriver               = 0L;
  347. PFN          RM_Help               = 0L;
  348. PFN          RM_Help0              = 0L;
  349. PFN          RM_Help3              = 0L;
  350. ULONG        RMFlags               = 0L;
  351.  
  352. UCHAR  DrvrNameTxt[]     = "IBMIDECD.FLT";
  353. USHORT DrvrNameSize      = sizeof(DrvrNameTxt);
  354. UCHAR  DrvrDescriptTxt[] = "IBM Filter Driver for IDE ATAPI CDROMs";
  355. UCHAR  VendorNameTxt[]   = "IBM OS/2";
  356.  
  357. DRIVERSTRUCT DriverStruct =
  358. {
  359.    DrvrNameTxt,                              /* DrvrName                */
  360.    DrvrDescriptTxt,                          /* DrvrDescript            */
  361.    VendorNameTxt,                            /* VendorName              */
  362.    CMVERSION_MAJOR,                          /* MajorVer                */
  363.    CMVERSION_MINOR,                          /* MinorVer                */
  364.    1995,1,10,                                /* Date                    */
  365.    0,                                        /* DrvrFlags               */
  366.    DRT_ADDDM,                                /* DrvrType                */
  367.    DRS_FILTER,                               /* DrvrSubType             */
  368.    NULL                                      /* DrvrCallback            */
  369. };
  370.  
  371. /*----------------------------------------------*/
  372. /* Device Description                           */
  373. /*----------------------------------------------*/
  374. UCHAR DevDescriptNameTxt[] = "ATAPI_0 IDE CDROM Drive";
  375.  
  376. DEVICESTRUCT DevStruct =
  377. {
  378.    DevDescriptNameTxt,   /* DevDescriptName; */
  379.    DS_FIXED_LOGICALNAME, /* DevFlags;        */
  380.    DS_TYPE_CDROM         /* DevFlags;        */
  381. };
  382.