VirtualBox

Changeset 36383 in vbox


Ignore:
Timestamp:
Mar 24, 2011 6:03:17 AM (14 years ago)
Author:
vboxsync
Message:

AHCI+ATAController: Port r70670 + r70674 (Signal no current profile if no medium is loaded and add mandatory features to the GET CONFIGURATION reply)

Location:
trunk/src/VBox/Devices/Storage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/ATAController.cpp

    r36316 r36383  
    16321632}
    16331633
     1634static size_t atapiGetConfigurationFillFeatureListProfiles(AHCIATADevState *s, uint8_t *pbBuf, size_t cbBuf)
     1635{
     1636    if (cbBuf < 3*4)
     1637        return 0;
     1638
     1639    ataH2BE_U16(pbBuf, 0x0); /* feature 0: list of profiles supported */
     1640    pbBuf[2] = (0 << 2) | (1 << 1) | (1 || 0); /* version 0, persistent, current */
     1641    pbBuf[3] = 8; /* additional bytes for profiles */
     1642    /* The MMC-3 spec says that DVD-ROM read capability should be reported
     1643     * before CD-ROM read capability. */
     1644    ataH2BE_U16(pbBuf + 4, 0x10); /* profile: read-only DVD */
     1645    pbBuf[6] = (0 << 0); /* NOT current profile */
     1646    ataH2BE_U16(pbBuf + 8, 0x08); /* profile: read only CD */
     1647    pbBuf[10] = (1 << 0); /* current profile */
     1648
     1649    return 3*4; /* Header + 2 profiles entries */
     1650}
     1651
     1652static size_t atapiGetConfigurationFillFeatureCore(AHCIATADevState *s, uint8_t *pbBuf, size_t cbBuf)
     1653{
     1654    if (cbBuf < 12)
     1655        return 0;
     1656
     1657    ataH2BE_U16(pbBuf, 0x1); /* feature 0001h: Core Feature */
     1658    pbBuf[2] = (0x2 << 2) | RT_BIT(1) | RT_BIT(0); /* Version | Persistent | Current */
     1659    pbBuf[3] = 8; /* Additional length */
     1660    ataH2BE_U16(pbBuf + 4, 0x00000002); /* Physical interface ATAPI. */
     1661    pbBuf[8] = RT_BIT(0); /* DBE */
     1662    /* Rest is reserved. */
     1663
     1664    return 12;
     1665}
     1666
     1667static size_t atapiGetConfigurationFillFeatureMorphing(AHCIATADevState *s, uint8_t *pbBuf, size_t cbBuf)
     1668{
     1669    if (cbBuf < 8)
     1670        return 0;
     1671
     1672    ataH2BE_U16(pbBuf, 0x2); /* feature 0002h: Morphing Feature */
     1673    pbBuf[2] = (0x1 << 2) | RT_BIT(1) | RT_BIT(0); /* Version | Persistent | Current */
     1674    pbBuf[3] = 4; /* Additional length */
     1675    pbBuf[4] = RT_BIT(1) | 0x0; /* OCEvent | !ASYNC */
     1676    /* Rest is reserved. */
     1677
     1678    return 8;
     1679}
     1680
     1681static size_t atapiGetConfigurationFillFeatureRemovableMedium(AHCIATADevState *s, uint8_t *pbBuf, size_t cbBuf)
     1682{
     1683    if (cbBuf < 8)
     1684        return 0;
     1685
     1686    ataH2BE_U16(pbBuf, 0x3); /* feature 0003h: Removable Medium Feature */
     1687    pbBuf[2] = (0x2 << 2) | RT_BIT(1) | RT_BIT(0); /* Version | Persistent | Current */
     1688    pbBuf[3] = 4; /* Additional length */
     1689    /* Tray type loading | Load | Eject | !Pvnt Jmpr | !DBML | Lock */
     1690    pbBuf[4] = (0x2 << 5) | RT_BIT(4) | RT_BIT(3) | (0x0 << 2) | (0x0 << 1) | RT_BIT(0);
     1691    /* Rest is reserved. */
     1692
     1693    return 8;
     1694}
     1695
     1696static size_t atapiGetConfigurationFillFeatureRandomReadable(AHCIATADevState *s, uint8_t *pbBuf, size_t cbBuf)
     1697{
     1698    if (cbBuf < 12)
     1699        return 0;
     1700
     1701    ataH2BE_U16(pbBuf, 0x10); /* feature 0010h: Random Readable Feature */
     1702    pbBuf[2] = (0x0 << 2) | RT_BIT(1) | RT_BIT(0); /* Version | Persistent | Current */
     1703    pbBuf[3] = 8; /* Additional length */
     1704    ataH2BE_U32(pbBuf + 4, 2048); /* Logical block size. */
     1705    ataH2BE_U16(pbBuf + 8, 0x10); /* Blocking (0x10 for DVD, CD is not defined). */
     1706    pbBuf[10] = 0; /* PP not present */
     1707    /* Rest is reserved. */
     1708
     1709    return 12;
     1710}
     1711
     1712static size_t atapiGetConfigurationFillFeatureCDRead(AHCIATADevState *s, uint8_t *pbBuf, size_t cbBuf)
     1713{
     1714    if (cbBuf < 8)
     1715        return 0;
     1716
     1717    ataH2BE_U16(pbBuf, 0x1e); /* feature 001Eh: CD Read Feature */
     1718    pbBuf[2] = (0x2 << 2) | RT_BIT(1) | RT_BIT(0); /* Version | Persistent | Current */
     1719    pbBuf[3] = 0; /* Additional length */
     1720    pbBuf[4] = (0x0 << 7) | (0x0 << 1) | 0x0; /* !DAP | !C2-Flags | !CD-Text. */
     1721    /* Rest is reserved. */
     1722
     1723    return 8;
     1724}
     1725
     1726static size_t atapiGetConfigurationFillFeaturePowerManagement(AHCIATADevState *s, uint8_t *pbBuf, size_t cbBuf)
     1727{
     1728    if (cbBuf < 4)
     1729        return 0;
     1730
     1731    ataH2BE_U16(pbBuf, 0x100); /* feature 0100h: Power Management Feature */
     1732    pbBuf[2] = (0x0 << 2) | RT_BIT(1) | RT_BIT(0); /* Version | Persistent | Current */
     1733    pbBuf[3] = 0; /* Additional length */
     1734
     1735    return 4;
     1736}
     1737
     1738static size_t atapiGetConfigurationFillFeatureTimeout(AHCIATADevState *s, uint8_t *pbBuf, size_t cbBuf)
     1739{
     1740    if (cbBuf < 8)
     1741        return 0;
     1742
     1743    ataH2BE_U16(pbBuf, 0x105); /* feature 0105h: Timeout Feature */
     1744    pbBuf[2] = (0x0 << 2) | RT_BIT(1) | RT_BIT(0); /* Version | Persistent | Current */
     1745    pbBuf[3] = 4; /* Additional length */
     1746    pbBuf[4] = 0x0; /* !Group3 */
     1747
     1748    return 8;
     1749}
    16341750
    16351751static bool atapiGetConfigurationSS(AHCIATADevState *s)
    16361752{
    16371753    uint8_t *pbBuf = s->CTXALLSUFF(pbIOBuffer);
     1754    size_t cbBuf = s->cbIOBuffer;
     1755    size_t cbCopied = 0;
    16381756    uint16_t u16Sfn = ataBE2H_U16(&s->aATAPICmd[2]);
    16391757
    16401758    Assert(s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE);
    1641     Assert(s->cbElementaryTransfer <= 32);
     1759    Assert(s->cbElementaryTransfer <= 80);
    16421760    /* Accept valid request types only, and only starting feature 0. */
    16431761    if ((s->aATAPICmd[1] & 0x03) == 3 || u16Sfn != 0)
     
    16461764        return false;
    16471765    }
    1648     memset(pbBuf, '\0', 32);
    1649     ataH2BE_U32(pbBuf, 16);
     1766    memset(pbBuf, '\0', cbBuf);
    16501767    /** @todo implement switching between CD-ROM and DVD-ROM profile (the only
    1651      * way to differentiate them right now is based on the image size). Also
    1652      * implement signalling "no current profile" if no medium is loaded. */
    1653     ataH2BE_U16(pbBuf + 6, 0x08); /* current profile: read-only CD */
    1654 
    1655     ataH2BE_U16(pbBuf + 8, 0); /* feature 0: list of profiles supported */
    1656     pbBuf[10] = (0 << 2) | (1 << 1) | (1 || 0); /* version 0, persistent, current */
    1657     pbBuf[11] = 8; /* additional bytes for profiles */
    1658     /* The MMC-3 spec says that DVD-ROM read capability should be reported
    1659      * before CD-ROM read capability. */
    1660     ataH2BE_U16(pbBuf + 12, 0x10); /* profile: read-only DVD */
    1661     pbBuf[14] = (0 << 0); /* NOT current profile */
    1662     ataH2BE_U16(pbBuf + 16, 0x08); /* profile: read only CD */
    1663     pbBuf[18] = (1 << 0); /* current profile */
     1768     * way to differentiate them right now is based on the image size). */
     1769    if (s->cTotalSectors)
     1770        ataH2BE_U16(pbBuf + 6, 0x08); /* current profile: read-only CD */
     1771    else
     1772        ataH2BE_U16(pbBuf + 6, 0x00); /* current profile: none -> no media */
     1773    cbBuf    -= 8;
     1774    pbBuf    += 8;
     1775
     1776    cbCopied = atapiGetConfigurationFillFeatureListProfiles(s, pbBuf, cbBuf);
     1777    cbBuf -= cbCopied;
     1778    pbBuf += cbCopied;
     1779
     1780    cbCopied = atapiGetConfigurationFillFeatureCore(s, pbBuf, cbBuf);
     1781    cbBuf -= cbCopied;
     1782    pbBuf += cbCopied;
     1783
     1784    cbCopied = atapiGetConfigurationFillFeatureMorphing(s, pbBuf, cbBuf);
     1785    cbBuf -= cbCopied;
     1786    pbBuf += cbCopied;
     1787
     1788    cbCopied = atapiGetConfigurationFillFeatureRemovableMedium(s, pbBuf, cbBuf);
     1789    cbBuf -= cbCopied;
     1790    pbBuf += cbCopied;
     1791
     1792    cbCopied = atapiGetConfigurationFillFeatureRandomReadable(s, pbBuf, cbBuf);
     1793    cbBuf -= cbCopied;
     1794    pbBuf += cbCopied;
     1795
     1796    cbCopied = atapiGetConfigurationFillFeatureCDRead(s, pbBuf, cbBuf);
     1797    cbBuf -= cbCopied;
     1798    pbBuf += cbCopied;
     1799
     1800    cbCopied = atapiGetConfigurationFillFeaturePowerManagement(s, pbBuf, cbBuf);
     1801    cbBuf -= cbCopied;
     1802    pbBuf += cbCopied;
     1803
     1804    cbCopied = atapiGetConfigurationFillFeatureTimeout(s, pbBuf, cbBuf);
     1805    cbBuf -= cbCopied;
     1806    pbBuf += cbCopied;
     1807
     1808    /* Set data length now. */
     1809    ataH2BE_U32(s->CTX_SUFF(pbIOBuffer), s->cbIOBuffer - cbBuf);
     1810
    16641811    /* Other profiles we might want to add in the future: 0x40 (BD-ROM) and 0x50 (HDDVD-ROM) */
    16651812    s->iSourceSink = ATAFN_SS_NULL;
     
    23992546            /* No media change stuff here, it can confuse Linux guests. */
    24002547            cbMax = ataBE2H_U16(pbPacket + 7);
    2401             ataStartTransfer(s, RT_MIN(cbMax, 32), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_GET_CONFIGURATION, true);
     2548            ataStartTransfer(s, RT_MIN(cbMax, 80), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_GET_CONFIGURATION, true);
    24022549            break;
    24032550        case SCSI_INQUIRY:
  • trunk/src/VBox/Devices/Storage/DevAHCI.cpp

    r36316 r36383  
    30653065}
    30663066
     3067static size_t atapiGetConfigurationFillFeatureListProfiles(PAHCIPort pAhciPort, uint8_t *pbBuf, size_t cbBuf)
     3068{
     3069    if (cbBuf < 3*4)
     3070        return 0;
     3071
     3072    ataH2BE_U16(pbBuf, 0x0); /* feature 0: list of profiles supported */
     3073    pbBuf[2] = (0 << 2) | (1 << 1) | (1 || 0); /* version 0, persistent, current */
     3074    pbBuf[3] = 8; /* additional bytes for profiles */
     3075    /* The MMC-3 spec says that DVD-ROM read capability should be reported
     3076     * before CD-ROM read capability. */
     3077    ataH2BE_U16(pbBuf + 4, 0x10); /* profile: read-only DVD */
     3078    pbBuf[6] = (0 << 0); /* NOT current profile */
     3079    ataH2BE_U16(pbBuf + 8, 0x08); /* profile: read only CD */
     3080    pbBuf[10] = (1 << 0); /* current profile */
     3081
     3082    return 3*4; /* Header + 2 profiles entries */
     3083}
     3084
     3085static size_t atapiGetConfigurationFillFeatureCore(PAHCIPort pAhciPort, uint8_t *pbBuf, size_t cbBuf)
     3086{
     3087    if (cbBuf < 12)
     3088        return 0;
     3089
     3090    ataH2BE_U16(pbBuf, 0x1); /* feature 0001h: Core Feature */
     3091    pbBuf[2] = (0x2 << 2) | RT_BIT(1) | RT_BIT(0); /* Version | Persistent | Current */
     3092    pbBuf[3] = 8; /* Additional length */
     3093    ataH2BE_U16(pbBuf + 4, 0x00000002); /* Physical interface ATAPI. */
     3094    pbBuf[8] = RT_BIT(0); /* DBE */
     3095    /* Rest is reserved. */
     3096
     3097    return 12;
     3098}
     3099
     3100static size_t atapiGetConfigurationFillFeatureMorphing(PAHCIPort pAhciPort, uint8_t *pbBuf, size_t cbBuf)
     3101{
     3102    if (cbBuf < 8)
     3103        return 0;
     3104
     3105    ataH2BE_U16(pbBuf, 0x2); /* feature 0002h: Morphing Feature */
     3106    pbBuf[2] = (0x1 << 2) | RT_BIT(1) | RT_BIT(0); /* Version | Persistent | Current */
     3107    pbBuf[3] = 4; /* Additional length */
     3108    pbBuf[4] = RT_BIT(1) | 0x0; /* OCEvent | !ASYNC */
     3109    /* Rest is reserved. */
     3110
     3111    return 8;
     3112}
     3113
     3114static size_t atapiGetConfigurationFillFeatureRemovableMedium(PAHCIPort pAhciPort, uint8_t *pbBuf, size_t cbBuf)
     3115{
     3116    if (cbBuf < 8)
     3117        return 0;
     3118
     3119    ataH2BE_U16(pbBuf, 0x3); /* feature 0003h: Removable Medium Feature */
     3120    pbBuf[2] = (0x2 << 2) | RT_BIT(1) | RT_BIT(0); /* Version | Persistent | Current */
     3121    pbBuf[3] = 4; /* Additional length */
     3122    /* Tray type loading | Load | Eject | !Pvnt Jmpr | !DBML | Lock */
     3123    pbBuf[4] = (0x2 << 5) | RT_BIT(4) | RT_BIT(3) | (0x0 << 2) | (0x0 << 1) | RT_BIT(0);
     3124    /* Rest is reserved. */
     3125
     3126    return 8;
     3127}
     3128
     3129static size_t atapiGetConfigurationFillFeatureRandomReadable(PAHCIPort pAhciPort, uint8_t *pbBuf, size_t cbBuf)
     3130{
     3131    if (cbBuf < 12)
     3132        return 0;
     3133
     3134    ataH2BE_U16(pbBuf, 0x10); /* feature 0010h: Random Readable Feature */
     3135    pbBuf[2] = (0x0 << 2) | RT_BIT(1) | RT_BIT(0); /* Version | Persistent | Current */
     3136    pbBuf[3] = 8; /* Additional length */
     3137    ataH2BE_U32(pbBuf + 4, 2048); /* Logical block size. */
     3138    ataH2BE_U16(pbBuf + 8, 0x10); /* Blocking (0x10 for DVD, CD is not defined). */
     3139    pbBuf[10] = 0; /* PP not present */
     3140    /* Rest is reserved. */
     3141
     3142    return 12;
     3143}
     3144
     3145static size_t atapiGetConfigurationFillFeatureCDRead(PAHCIPort pAhciPort, uint8_t *pbBuf, size_t cbBuf)
     3146{
     3147    if (cbBuf < 8)
     3148        return 0;
     3149
     3150    ataH2BE_U16(pbBuf, 0x1e); /* feature 001Eh: CD Read Feature */
     3151    pbBuf[2] = (0x2 << 2) | RT_BIT(1) | RT_BIT(0); /* Version | Persistent | Current */
     3152    pbBuf[3] = 0; /* Additional length */
     3153    pbBuf[4] = (0x0 << 7) | (0x0 << 1) | 0x0; /* !DAP | !C2-Flags | !CD-Text. */
     3154    /* Rest is reserved. */
     3155
     3156    return 8;
     3157}
     3158
     3159static size_t atapiGetConfigurationFillFeaturePowerManagement(PAHCIPort pAhciPort, uint8_t *pbBuf, size_t cbBuf)
     3160{
     3161    if (cbBuf < 4)
     3162        return 0;
     3163
     3164    ataH2BE_U16(pbBuf, 0x100); /* feature 0100h: Power Management Feature */
     3165    pbBuf[2] = (0x0 << 2) | RT_BIT(1) | RT_BIT(0); /* Version | Persistent | Current */
     3166    pbBuf[3] = 0; /* Additional length */
     3167
     3168    return 4;
     3169}
     3170
     3171static size_t atapiGetConfigurationFillFeatureTimeout(PAHCIPort pAhciPort, uint8_t *pbBuf, size_t cbBuf)
     3172{
     3173    if (cbBuf < 8)
     3174        return 0;
     3175
     3176    ataH2BE_U16(pbBuf, 0x105); /* feature 0105h: Timeout Feature */
     3177    pbBuf[2] = (0x0 << 2) | RT_BIT(1) | RT_BIT(0); /* Version | Persistent | Current */
     3178    pbBuf[3] = 4; /* Additional length */
     3179    pbBuf[4] = 0x0; /* !Group3 */
     3180
     3181    return 8;
     3182}
    30673183
    30683184static int atapiGetConfigurationSS(PAHCIPORTTASKSTATE pAhciPortTaskState, PAHCIPort pAhciPort, int *pcbData)
    30693185{
    3070     uint8_t aBuf[32];
     3186    uint8_t aBuf[80];
     3187    uint8_t *pbBuf = &aBuf[0];
     3188    size_t cbBuf = sizeof(aBuf);
     3189    size_t cbCopied = 0;
    30713190
    30723191    /* Accept valid request types only, and only starting feature 0. */
     
    30763195        return VINF_SUCCESS;
    30773196    }
    3078     memset(aBuf, '\0', 32);
    3079     ataH2BE_U32(aBuf, 16);
    30803197    /** @todo implement switching between CD-ROM and DVD-ROM profile (the only
    3081      * way to differentiate them right now is based on the image size). Also
    3082      * implement signalling "no current profile" if no medium is loaded. */
    3083     ataH2BE_U16(aBuf + 6, 0x08); /* current profile: read-only CD */
    3084 
    3085     ataH2BE_U16(aBuf + 8, 0); /* feature 0: list of profiles supported */
    3086     aBuf[10] = (0 << 2) | (1 << 1) | (1 || 0); /* version 0, persistent, current */
    3087     aBuf[11] = 8; /* additional bytes for profiles */
    3088     /* The MMC-3 spec says that DVD-ROM read capability should be reported
    3089      * before CD-ROM read capability. */
    3090     ataH2BE_U16(aBuf + 12, 0x10); /* profile: read-only DVD */
    3091     aBuf[14] = (0 << 0); /* NOT current profile */
    3092     ataH2BE_U16(aBuf + 16, 0x08); /* profile: read only CD */
    3093     aBuf[18] = (1 << 0); /* current profile */
     3198     * way to differentiate them right now is based on the image size). */
     3199    if (pAhciPort->cTotalSectors)
     3200        ataH2BE_U16(pbBuf + 6, 0x08); /* current profile: read-only CD */
     3201    else
     3202        ataH2BE_U16(pbBuf + 6, 0x00); /* current profile: none -> no media */
     3203    cbBuf    -= 8;
     3204    pbBuf    += 8;
     3205
     3206    cbCopied = atapiGetConfigurationFillFeatureListProfiles(pAhciPort, pbBuf, cbBuf);
     3207    cbBuf -= cbCopied;
     3208    pbBuf += cbCopied;
     3209
     3210    cbCopied = atapiGetConfigurationFillFeatureCore(pAhciPort, pbBuf, cbBuf);
     3211    cbBuf -= cbCopied;
     3212    pbBuf += cbCopied;
     3213
     3214    cbCopied = atapiGetConfigurationFillFeatureMorphing(pAhciPort, pbBuf, cbBuf);
     3215    cbBuf -= cbCopied;
     3216    pbBuf += cbCopied;
     3217
     3218    cbCopied = atapiGetConfigurationFillFeatureRemovableMedium(pAhciPort, pbBuf, cbBuf);
     3219    cbBuf -= cbCopied;
     3220    pbBuf += cbCopied;
     3221
     3222    cbCopied = atapiGetConfigurationFillFeatureRandomReadable(pAhciPort, pbBuf, cbBuf);
     3223    cbBuf -= cbCopied;
     3224    pbBuf += cbCopied;
     3225
     3226    cbCopied = atapiGetConfigurationFillFeatureCDRead(pAhciPort, pbBuf, cbBuf);
     3227    cbBuf -= cbCopied;
     3228    pbBuf += cbCopied;
     3229
     3230    cbCopied = atapiGetConfigurationFillFeaturePowerManagement(pAhciPort, pbBuf, cbBuf);
     3231    cbBuf -= cbCopied;
     3232    pbBuf += cbCopied;
     3233
     3234    cbCopied = atapiGetConfigurationFillFeatureTimeout(pAhciPort, pbBuf, cbBuf);
     3235    cbBuf -= cbCopied;
     3236    pbBuf += cbCopied;
     3237
     3238    /* Set data length now. */
     3239    ataH2BE_U32(&aBuf[0], sizeof(aBuf) - cbBuf);
    30943240
    30953241    /* Copy the buffer in to the scatter gather list. */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette