home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / DASD / CDROM / ATAPI / ATAPIORB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-14  |  8.1 KB  |  269 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 =     ATAPIORB.C
  15.  *
  16.  * DESCRIPTIVE NAME =     ATAPI IORB Interface to State Machine
  17.  *
  18.  *
  19.  *
  20.  * VERSION = 1.0
  21.  *
  22.  * DATE
  23.  *
  24.  * DESCRIPTION :
  25.  *
  26.  * Purpose:
  27.  *
  28.  *
  29.  *
  30.  *
  31.  *
  32. */
  33.  
  34. #define INCL_NOBASEAPI
  35. #define INCL_NOPMAPI
  36. #include "os2.h"
  37. #include "dos.h"
  38. #include "dskinit.h"
  39.  
  40. #include "iorb.h"
  41. #include "addcalls.h"
  42. #include "dhcalls.h"
  43.  
  44. #define INCL_INITRP_ONLY
  45. #include "reqpkt.h"
  46.  
  47. #include "scsi.h"
  48. #include "cdbscsi.h"
  49.  
  50. #include "atapicon.h"
  51. #include "atapireg.h"
  52. #include "atapityp.h"
  53. #include "atapiext.h"
  54. #include "atapipro.h"
  55.  
  56.  
  57. VOID FAR _loadds ATAPIADDEntry( PIORBH pNewIORB )
  58. {
  59.    PIORBH    pNewsTailIORB;  /* The tail of the iorb chain for pNewIORB *//*@V102677*/
  60.    NPACB     npACB;
  61.    NPUCB     npUCB;
  62.  
  63.    /*┌─────────────────────────────────┐
  64.      │ Queue IORBs which don't address │
  65.      │ a specific unit to ACB 0 Unit 0 │
  66.      └─────────────────────────────────┘ */
  67.  
  68.    if (pNewIORB->CommandCode == IOCC_CONFIGURATION)
  69.       pNewIORB->UnitHandle = (USHORT) (npUCB = ACBPtrs[0].npACB->npUCB);
  70.  
  71.    else
  72.       npUCB = (NPUCB) pNewIORB->UnitHandle;
  73.  
  74.    npACB = npUCB->npACB;
  75.  
  76.    if ( Valid_CDB_Length_Check(pNewIORB, npACB) )
  77.    {
  78.       pNewIORB->Status    = IORB_DONE | IORB_ERROR;
  79.       pNewIORB->ErrorCode = IOERR_CMD_NOT_SUPPORTED;
  80.  
  81.       if ( pNewIORB->RequestControl & IORB_ASYNC_POST )
  82.       {
  83.          (*pNewIORB->NotifyAddress)(pNewIORB);
  84.       }
  85.       return;
  86.    }
  87.  
  88.    DISABLE
  89.  
  90.    /*┌──────────────────────────────┐
  91.      │ Put new IORB on end of Queue │
  92.      └──────────────────────────────┘*/
  93.    if (!npACB->pHeadIORB)
  94.       npACB->pHeadIORB = pNewIORB;
  95.    else
  96.       npACB->pFootIORB->pNxtIORB = pNewIORB;
  97.  
  98.  
  99.    /*┌───────────────────────────┐*/                               /*@V102677*/
  100.    /*│Find end of chained request│*/                               /*@V102677*/
  101.    /*└───────────────────────────┘*/                               /*@V102677*/
  102.    for ( pNewsTailIORB = pNewIORB;                                 /*@V102677*/
  103.          pNewsTailIORB->RequestControl & IORB_CHAIN;               /*@V102677*/
  104.          pNewsTailIORB = pNewsTailIORB->pNxtIORB                   /*@V102677*/
  105.        )                                                           /*@V102677*/
  106.      ;                                                             /*@V102677*/
  107.                                                                    /*@V102677*/
  108.    /*┌─────────────────────────────────────────┐*/                 /*@V102677*/
  109.    /*│ Point the foot of the IORB Queue to the │*/                 /*@V102677*/
  110.    /*│ tail of the new IORB chain.             │*/                 /*@V102677*/
  111.    /*└─────────────────────────────────────────┘*/                 /*@V102677*/
  112.    npACB->pFootIORB = pNewsTailIORB;                               /*@V102677*/
  113.                                                                    /*@V102677*/
  114.    /*┌────────────────────────────────────┐*/                      /*@V102677*/
  115.    /*│Make sure pNxtIORB for the for the  │*/                      /*@V102677*/
  116.    /*│Last IORB on our Q is clear.        │*/                      /*@V102677*/
  117.    /*└────────────────────────────────────┘*/                      /*@V102677*/
  118.    npACB->pFootIORB->pNxtIORB = 0;                                 /*@V102677*/
  119.  
  120.    if ( !(npACB->OSMFlags & ACBOF_SM_ACTIVE))
  121.    {
  122.       npACB->OSMFlags |= ACBOF_SM_ACTIVE;
  123.  
  124.       NextIORB(npACB);
  125.  
  126.       npACB->OSMState = ACBOS_START_IORB;
  127.       npACB->IORBStatus = 0;
  128.       npACB->IORBError = 0;
  129.       npACB->cResetRequests = 0;
  130.       npACB->npCmdIO = &npACB->ExternalCmd;
  131.  
  132.       if (  ( npACB->ResourceFlags & ACBRF_SHARED ) &&
  133.            !( npACB->ResourceFlags & ACBRF_CURR_OWNER ) &&
  134.            !( pNewIORB->CommandCode == IOCC_CONFIGURATION ) &&
  135.            !( pNewIORB->CommandCode == IOCC_UNIT_CONTROL ) )
  136.       {
  137.  
  138.          npACB->OSMState = ACBOS_SUSPEND_COMPLETE;
  139.  
  140.          ENABLE
  141.  
  142.          SuspendOtherAdd( npACB );
  143.       }
  144.       else
  145.       {
  146.          ENABLE
  147.          StartOSM( npACB );
  148.       }
  149.    }
  150.    ENABLE
  151. }
  152.  
  153. USHORT NEAR Valid_CDB_Length_Check( PIORBH pIORB, NPACB npACB )
  154. {
  155.    USHORT                 rc = FALSE;
  156.    PIORB_ADAPTER_PASSTHRU pAP_IORB;
  157.  
  158.    pAP_IORB = (PIORB_ADAPTER_PASSTHRU) pIORB;
  159.  
  160.    if (( pIORB->CommandCode     == IOCC_ADAPTER_PASSTHRU ) &&
  161.        ( pIORB->CommandModifier == IOCM_EXECUTE_CDB ))
  162.    {
  163.       if ( pAP_IORB->ControllerCmdLen == npACB->npUCB->CmdPacketLength )
  164.       {
  165.          rc = TRUE;
  166.       }
  167.    }
  168.    else
  169.       rc = TRUE;
  170.  
  171.    return(!rc);
  172. }
  173.  
  174.  
  175. /***************************************************************************
  176. *
  177. * FUNCTION NAME = x2BCD
  178. *
  179. * DESCRIPTION   = Convert binary byte to BCD byte ( 2 digits )
  180. *
  181. *                 PSEUDOCODE:
  182. *                     return ( (n / 10 << 4) | (n % 10) );
  183. *
  184. * INPUT         = binary byte
  185. *
  186. * OUTPUT        =
  187. *
  188. * RETURN-NORMAL = al = BCD
  189. *
  190. * RETURN-ERROR  = none
  191. *
  192. **************************************************************************/
  193.  
  194. UCHAR NEAR x2BCD ( UCHAR Data )
  195. {
  196.    _asm {
  197.            mov     al, Data
  198.            xor     ah, ah
  199.            mov     cl, 10
  200.            div     cl
  201.            xchg    ah, al
  202.            shl     ah, 4
  203.            or      al, ah
  204.            mov     Data, al
  205.         }
  206.  
  207.    return( Data );
  208. }
  209.  
  210. VOID NEAR Convert_17B_to_ATAPI( ULONG pPhysData )
  211. {
  212.    struct translatetable
  213.    {
  214.       ULONG OldValue;
  215.       ULONG NewValue;
  216.    };
  217.  
  218.    PBYTE  pData;
  219.    USHORT ModeFlag;
  220.    ULONG  Capabilities_17B = *pData+4;
  221.    PBYTE  pCaps            =  pData+4;
  222.    UCHAR  i, tsize;
  223.  
  224.    static struct translatetable table[] =
  225.    {
  226.       { CP_AUDIO_PLAY ,                 CP_AUDIO_PLAY },
  227.       { REV_17B_CP_MODE2_FORM1,         CP_MODE2_FORM1 },
  228.       { REV_17B_CP_MODE2_FORM2,         CP_MODE2_FORM2 },
  229.       { REV_17B_CP_READ_CDDA,           CP_CDDA },
  230.       { REV_17B_CP_PHOTO_CD,            CP_MULTISESSION },
  231.       { REV_17B_CP_EJECT,               CP_EJECT },
  232.       { REV_17B_CP_LOCK,                CP_LOCK },
  233.       { REV_17B_CP_UPC,                 CP_UPC },
  234.       { REV_17B_CP_ISRC,                CP_ISRC },
  235.       { REV_17B_CP_INDEPENDENT_VOL_LEV, CP_INDEPENDENT_VOLUME_LEVELS },
  236.       { REV_17B_CP_SEPARATE_CH_MUTE,    CP_SEPARATE_CHANNEL_MUTE },
  237.       { REV_17B_CP_TRAY_LOADER,         CP_TRAY_LOADER },
  238.       { REV_17B_CP_POPUP_LOADER,        CP_POPUP_LOADER },
  239.       { REV_17B_CP_RESERVED_LOADER,     CP_RESERVED_LOADER },
  240.       { REV_17B_CP_PREVENT_JUMPER,      CP_PREVENT_JUMPER },
  241.       { REV_17B_CP_LOCK_STATE,          CP_LOCK_STATE },
  242.       { REV_17B_CP_CDDA_ACCURATE,       CP_CDDA_ACCURATE },
  243.       { REV_17B_CP_C2_POINTERS,         CP_C2_POINTERS }
  244.    };
  245.  
  246.    tsize = sizeof(table) / sizeof(struct translatetable);
  247.  
  248.    if ( DevHelp_PhysToVirt( (ULONG)   pPhysData,
  249.                              (USHORT)  1,
  250.                              (PVOID)   &pData,
  251.                              (PUSHORT) &ModeFlag  ) )
  252.    {
  253.       _asm { int 3 }
  254.    }
  255.  
  256.    Capabilities_17B = *pData+4;
  257.    pCaps            =  pData+4;
  258.  
  259.    *pCaps = 0;
  260.  
  261.    for (i=0; i < tsize; i++ )
  262.    {
  263.       if ( Capabilities_17B & table[i].OldValue )
  264.       {
  265.          *pCaps |= table[i].NewValue;
  266.       }
  267.    }
  268. }
  269.