Annotation of qemu/roms/SLOF/slof/fs/usb/usb-enumerate.fs, revision 1.1.1.2

1.1       root        1: \ *****************************************************************************
                      2: \ * Copyright (c) 2004, 2008 IBM Corporation
                      3: \ * All rights reserved.
                      4: \ * This program and the accompanying materials
                      5: \ * are made available under the terms of the BSD License
                      6: \ * which accompanies this distribution, and is available at
                      7: \ * http://www.opensource.org/licenses/bsd-license.php
                      8: \ *
                      9: \ * Contributors:
                     10: \ *     IBM Corporation - initial implementation
                     11: \ ****************************************************************************/
                     12: 
                     13: 
                     14: \ create the device tree for hub
                     15: 
                     16: : (hub-create) ( -- )
                     17:    mps port-number new-device-address port-number 
                     18:    ( mps port-number usb-address port-number )
                     19:    new-device set-space                ( mps port-number usb-address )
                     20:    encode-int s" USB-ADDRESS" property ( mps port-number )
                     21:    s" Address Set"  usb-debug-print
                     22:    encode-int s" reg" property         ( mps )
                     23:    s" Port Number Set"   usb-debug-print 
                     24:    encode-int s" MPS-DCP" property
                     25:    s" MPS Set"   usb-debug-print
                     26:    s" usb-hub.fs" INCLUDED
                     27:    finish-device
                     28: ;
                     29: 
                     30: 
                     31: \ encode properties for scsi or atapi device
                     32: 
                     33: : (atapi-scsi-property-set) ( -- )
                     34:    dd-buffer @ e + c@     ( Manuf )
                     35:    dd-buffer @ f + c@     ( Manuf Prod )
                     36:    dd-buffer @ 10 + c@    ( Manuf Prod Serial-Num )
                     37:    cd-buffer @ 16 + w@-le ( Manuf Prod Serial-Num ep-mps )
                     38:    cd-buffer @ 14 + c@    ( Manuf Prod Serial-Num ep-mps ep-addr )
                     39:    cd-buffer @ 1d + w@-le ( Manuf Prod Serial-Num ep-mps ep-addr ep-mps )
                     40:    cd-buffer @ 1b + c@    ( Manuf Prod Serial-Num ep-mps ep-addr ep-mps ep-addr )
                     41:    mps port-number new-device-address port-number
                     42:                         ( Manuf Prod Serial-Num ep-mps ep-addr ep-mps ep-addr 
                     43:                           mps port-num usb-addr port-num )
                     44:    new-device set-space
                     45:                         ( Manuf Prod Serial-Num ep-mps ep-addr ep-mps ep-addr
                     46:                            mps port-num usb-addr )
                     47:    encode-int s" USB-ADDRESS" property
                     48:                         ( Manuf Prod Serial-Num ep-mps ep-addr ep-mps ep-addr
                     49:                            mps port-num )
                     50:    encode-int s" reg" property
                     51:                         ( Manuf Prod Serial-Num ep-mps ep-addr ep-mps ep-addr 
                     52:                            mps )
                     53:    encode-int s" MPS-DCP" property
                     54:                         ( Manuf Prod Serial-Num ep-mps ep-addr ep-mps ep-addr )
                     55:    2 0  DO
                     56:       dup 80 and IF
                     57:          7f and encode-int
                     58:          s" BULK-IN-EP-ADDR" property
                     59:          encode-int s" MPS-BULKIN" property
                     60:       ELSE
                     61:          encode-int s" BULK-OUT-EP-ADDR" property
                     62:          encode-int s" MPS-BULKOUT" property
                     63:       THEN
                     64:    LOOP                                  ( Manuf Prod Serial-Num )
                     65:    encode-int s" iSerialNumber" property ( Manuf Prod )
                     66:    encode-int s" iProduct" property      ( Manuf )
                     67:    encode-int s" iManufacturer" property
                     68: ;
                     69: 
                     70: 
                     71: \ To classify device as hub/atapi/scsi/HID device
                     72: 
                     73: : (device-classify) 
                     74:    ( -- Interface-protocol Interface-subclass Interface-class TRUE|FALSE )
                     75:    cd-buffer @ BULK-CONFIG-DESCRIPTOR-LEN erase
                     76:    cd-buffer @ BULK-CONFIG-DESCRIPTOR-LEN mps new-device-address 
                     77:                                   ( buffer descp-len mps usb-address )
                     78:    control-std-get-configuration-descriptor
                     79:    IF
                     80:       cd-buffer @ 1+ c@           ( Descriptor-type )
                     81:       2 =   IF
                     82:          cd-buffer @ 10 + c@      ( protocol )
                     83:          cd-buffer @ f + c@       ( protocol subclass )
                     84:          cd-buffer @ e + c@       ( protocol subclass class )
                     85:          TRUE
                     86:       ELSE
                     87:          s" Not a valid configuration descriptor!!" usb-debug-print
                     88:          FALSE
                     89:       THEN
                     90:    ELSE
                     91:       s" Unable to read configuration descriptor!!" usb-debug-print
                     92:       FALSE
                     93:    THEN
                     94: ;
                     95: 
                     96: 
                     97: \ create device tree for Atapi SFF-8020 device
                     98: 
                     99: : (atapi-8020-create) ( -- )
                    100:    (atapi-scsi-property-set)
                    101:    s" usb-storage.fs" INCLUDED
                    102:    finish-device
                    103: ;
                    104: 
                    105: \ create device tree for Atapi SFF-8070 device
                    106: 
                    107: : (atapi-8070-create) ( -- )
                    108:    (atapi-scsi-property-set)
                    109:    s" usb-storage.fs" INCLUDED
                    110:    \ s" storage" device-name
                    111:    finish-device
                    112: ;
                    113: 
                    114: 
                    115: \ create device tree for SCSI device
                    116: 
                    117: : (scsi-create) ( -- )
                    118:    s" SCSI-CREATE " usb-debug-print
                    119: 
                    120: \ ***********************************************************************
                    121: \ a problem was encountered on Media-Tray (REV-0):
                    122: \ The CDROM is connected to USB via an ATA/USB-Bridge (U38: CYPRESS CY7C68300)
                    123: \ The C-Revision of this chip has an malfunction which results in a
                    124: \ hanging IORD Signal at the ATA-Interface and so prevents from reading.
                    125: \ The B-Revision doesn't have this problem (populated on Media-Tray REV-5)
                    126: \ Two additional Mass-Storage-Resets are necessary to reset the ATA-Interface.
                    127: \ (see CYPRESS Application Notes to CY7C68300)
                    128: \ (see USB-Spec: 'Bulk-Only-Transport')
                    129: \ ***********************************************************************
                    130: \ a mounted ISO image (via USB) doesn't accept this bulk-reset-command!
                    131: \ ***********************************************************************
                    132: 
                    133:    dd-buffer @ 8 + w@-le 4b4 =         \ VendorID = CYPRESS ?
                    134:    IF
                    135:       dd-buffer @ a + w@-le 6830 =     \ Device = CY7C68300 ?
                    136:       IF
                    137:        \ here a Cypress ATA/USB Bridge is detected
                    138:        d# 20 ms
                    139:        mps new-device-address 0 0 0   ( MPS fun-addr dir data-buff data-len )
                    140:        control-bulk-reset             ( TRUE|FALSE )
                    141:        d# 100 ms
                    142:        mps new-device-address 0 0 0   ( TRUE|FALSE MPS fun-addr dir data-buff data-len )
                    143:        control-bulk-reset             ( TRUE|FALSE TRUE|FALSE )
                    144:        and invert
                    145:        IF
                    146:           ."   ** BULK-RESET failed **" cr
                    147:        THEN
                    148:        d# 20 ms
                    149:       THEN
                    150:    THEN
                    151: 
1.1.1.2 ! root      152:    0 ch-buffer c!                \ preset a clean response
1.1       root      153:    mps new-device-address 0 ch-buffer 1 control-std-get-maxlun ( TRUE|FALSE )
                    154:    IF
                    155: \      s" GET-MAX-LUN IS WORKING :" usb-debug-print
1.1.1.2 ! root      156: \      ch-buffer  1 dump cr      \ dump the responsed message
1.1       root      157:    ELSE
                    158:       s" ERROR in GET-MAX-LUN " usb-debug-print
1.1.1.2 ! root      159:       0 ch-buffer c!             \ clear invalid numbers
1.1       root      160:       cd-buffer @ 5 + c@ to temp1
                    161:       temp1 new-device-address control-std-set-configuration drop
                    162:    THEN
                    163:    \ FIXME: an IBM external HDD reported a number of 127 LUNs which could
                    164:    \        not be set up. We need to understand how to set up the device
                    165:    \        to report the correct number of LUNs.
                    166:    \        The USB Massbulk Standard 1.0 defines a maximum of 15 mult. LUNs.
                    167:    \ Workaround: Devices that might report a higher number are treated
                    168:    \             as having exactly one LUN. Without this workaround the
                    169:    \             USB scan hangs during the setup of non-available LUNs.
                    170:    \
                    171:    \ Concerns: "FUJITSU MHV2040AT" (VendorID: 0x984 / DeviceID: 0x70)
                    172:    \
                    173:    \ MR: This Device reports an invalid MaxLUN number within the first
                    174:    \ three seconds after power-on or USB-Reset. The following loop repeats
                    175:    \ the MaxLUN request up to 8 times until a valid ( <15 ) value is responded.
                    176:    \ This can last up to four seconds as there is a delay of 500ms in every loop
                    177: 
                    178:    0                       ( counter )
                    179:    begin
                    180:       dup 8 <              ( counter flag )           \ max 8 * 500 ms
                    181:       ch-buffer c@ f >     ( counter flag flag )      \ is MuxLUN above limit ?
                    182:       AND                  ( counter flag )
                    183:       while
                    184:          d# 500 ms                     \ this device is not yet ready
1.1.1.2 ! root      185:          0 ch-buffer c!                \ preset a clean response
1.1       root      186:          mps new-device-address 0 ch-buffer 1 control-std-get-maxlun ( TRUE|FALSE )
                    187:          not
                    188:          IF
                    189:             s"  ** ERROR in GET-MAX-LUN ** " usb-debug-print
                    190:             drop 10                    \ replace counter to force loop end
                    191:          THEN
                    192:          1+                ( counter+1 )
                    193:       repeat
                    194:    drop
                    195: 
                    196:    \ here is still the workaround to handle invalid MaxLUNs as '0'
                    197:    \
                    198:    ch-buffer c@ dup 0= swap f > or IF   
                    199:       s" + LUN: " ch-buffer c@  usb-debug-print-val
                    200:       (atapi-scsi-property-set)
                    201:       s" usb-storage.fs" INCLUDED
                    202:       finish-device
                    203: 
                    204:    ELSE
                    205:       s" - LUN: " ch-buffer c@ usb-debug-print-val
                    206:       (atapi-scsi-property-set)
                    207:       s" usb-storage-wrapper.fs" INCLUDED
                    208:       finish-device
                    209: 
                    210:    THEN
                    211: ;
                    212: 
                    213: 
                    214: \ Classify USB storage device by sub-class code
                    215: 
                    216: : (classify-storage)  ( interface-protocol interface-subclass -- )
                    217:    s" USB: Mass Storage Device Found!" usb-debug-print
                    218:    swap 50 <> IF
                    219:       s" USB storage: Protocol is not 50." usb-debug-print
                    220:       drop EXIT
                    221:    THEN
                    222:    ( interface-subclass )
                    223:    CASE
                    224:       02 OF  (atapi-8020-create) s" ATAPI Interface " usb-debug-print ENDOF
                    225:       05 OF  (atapi-8070-create) s" ATAPI Interface " usb-debug-print ENDOF
                    226:       06 OF  (scsi-create) s" SCSI Interface " usb-debug-print ENDOF
                    227:       dup OF  s" USB storage: Unsupported sub-class code." usb-debug-print ENDOF
                    228:    ENDCASE
                    229: ;
                    230: 
                    231: 
                    232: \ create keyboard device tree
                    233: 
                    234: : (keyboard-create) ( -- )
                    235:    cd-buffer @ 1f + c@                 ( ep-mps )
                    236:    cd-buffer @ 1d + c@                 ( ep-mps ep-addr )  
                    237:    mps port-number new-device-address port-number
                    238:                                         ( ep-mps ep-addr mps port-num usb-addr port-num )
                    239:    new-device set-space                 ( ep-mps ep-addr mps port-num usb-addr )
                    240:    encode-int s" USB-ADDRESS" property  ( ep-mps ep-addr mps port-num )
                    241:    encode-int s" reg" property          ( ep-mps ep-addr mps )
                    242:    encode-int s" MPS-DCP" property      ( ep-mps ep-addr )
                    243:    7f and encode-int s" INT-IN-EP-ADDR" property
                    244:    encode-int s" MPS-INTIN" property
                    245:    new-device-address   \ device-speed
                    246:    s" usb-keyboard.fs" INCLUDED
                    247:    finish-device
                    248: ;
                    249: 
                    250: : (mouse-create) ( -- )
                    251:    mps port-number new-device-address port-number
                    252:                                         ( mps port-num usb-addr port-num )
                    253:    new-device set-space                 ( mps port-num usb-addr )
                    254:    encode-int s" USB-ADDRESS" property  ( mps port-num )
                    255:    encode-int s" reg" property          ( mps )
                    256:    encode-int s" MPS-DCP" property
                    257:    s" usb-mouse.fs" INCLUDED
                    258:    finish-device
                    259: ;
                    260: 
                    261: 
                    262: \ Classify by interface class code
                    263: 
                    264: : (classify-by-interface) ( -- )
                    265:    (device-classify)  IF
                    266:       ( Interface-protocol Interface-subclass Interface-class )
                    267:       CASE
                    268:          08 OF
                    269:             ( Interface-protocol Interface-subclass )
                    270:             (classify-storage)
                    271:          ENDOF
                    272:          03 OF
1.1.1.2 ! root      273:             ( Interface-protocol Interface-subclass )
        !           274:             s" USB: HID Found!" usb-debug-print
        !           275:             01 = IF
        !           276:                case
        !           277:                   01 of
        !           278:                      s" USB keyboard!" usb-debug-print
        !           279:                      (keyboard-create)
        !           280:                   endof
        !           281:                   02 of
        !           282:                      s" USB mouse!" usb-debug-print
        !           283:                      (mouse-create)
        !           284:                   endof
        !           285:                   dup of
        !           286:                      s" USB: unsupported HID!" usb-debug-print
        !           287:                   endof
        !           288:                endcase
        !           289:             ELSE
        !           290:                s" USB: unsupported HID protocol " rot usb-debug-print-val
        !           291:             THEN
        !           292:          ENDOF
1.1       root      293:          dup OF
                    294:             ( Interface-protocol Interface-subclass )
                    295:             s" USB: unsupported interface type." usb-debug-print
                    296:             2drop
                    297:          ENDOF
                    298:       ENDCASE
                    299:    THEN
                    300: ;
                    301: 
                    302: 
                    303: \ create usb device tree depending upon classification of the device
                    304: \ after encoding apt properties
                    305: 
                    306: : create-usb-device-tree ( -- )
                    307:    dd-buffer @ DEVICE-DESCRIPTOR-DEVCLASS-OFFSET + c@    ( Device-class )
                    308:    CASE
                    309:       HUB-DEVICE-CLASS OF s" USB: HUB found"   usb-debug-print
                    310:          (hub-create)
                    311:       ENDOF
                    312:       NO-CLASS  OF
                    313:          \ In this case, the INTERFACE descriptor
                    314:          \ tells you whats what -- Refer USB spec.
                    315:          (classify-by-interface)
                    316:       ENDOF
                    317:       DUP OF
                    318:          s" USB: Unknown device found." usb-debug-print
                    319:       ENDOF
                    320:    ENDCASE
                    321: ;

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.