Annotation of qemu/roms/SLOF/board-js2x/slof/pci-bridge_1022_7460.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: \ AMD 8111 I/O hub.
                     14: 
                     15: \ See the documentation at http://www.amd.com ; the datasheet for this chip is
                     16: \ document #24674.
                     17: 
1.1.1.2 ! root       18: \ Config space access functions - we're touching multiple device numbers and
        !            19: \ device functions below, so we've got to add our own my-space base here:
        !            20: : config-b@  dup 1000 < IF my-space + THEN config-b@ ;
        !            21: : config-w@  dup 1000 < IF my-space + THEN config-w@ ;
        !            22: : config-l@  dup 1000 < IF my-space + THEN config-l@ ;
        !            23: : config-b!  dup 1000 < IF my-space + THEN config-b! ;
        !            24: : config-w!  dup 1000 < IF my-space + THEN config-w! ;
        !            25: : config-l!  dup 1000 < IF my-space + THEN config-l! ;
        !            26: 
1.1       root       27: \ First, some master config.  Not all of this logically belongs to just
                     28: \ one function, and certainly not to the LPC bridge; also, we'll
                     29: \ initialize all functions in "downstream" order, and this code has to be
                     30: \ run first.  So do it now.
                     31: 
                     32: 00 842 config-b! \ Disable 8237 & 8254 & 8259's.  We're not a PC.
                     33: u3?  IF
                     34:    80 847 config-b! \ Disable EHCI, as it is terminally broken.
                     35: THEN
                     36: 03 848 config-b! \ Enable LPC, IDE; disable I2C, SMM, AC'97 functions.
                     37: 01 849 config-b! \ Enable USB, disable 100Mb enet.
                     38: 01 84b config-b! \ Enable IO-APIC.
                     39: 
                     40: fec00000 s" ioapic.fs" included
                     41: 00 init-ioapic
                     42: 
                     43: \ Program PNPIRQ[0,1,2] as IRQ #D,E,F; switch those GPIOs to low-active.
                     44:   0b 848 config-b! \ enable devB:3
                     45: 7000 b58 config-l! \ map PMxx at pci i/o 7000
                     46:   d1 b41 config-b! \ enable access to PMxx space
                     47: 
                     48: \ on JS20 the planar id is encoded in GPIO 29, 30 and 31
                     49: \ >=5 is GA2 else it is GA1
                     50: : (planar-id) ( -- planar-id)
                     51:    [ 70dd io-c@ 5 rshift 1 and ]  LITERAL
                     52:    [ 70de io-c@ 5 rshift 2 and ]  LITERAL
                     53:    [ 70df io-c@ 5 rshift 4 and ]  LITERAL
                     54:    + + 7 xor
                     55: ;
                     56: 
                     57: u3?  IF  [']  (planar-id) to planar-id  THEN
                     58: 
                     59: 8 70d3 io-c!  8 70d4 io-c!  8 70d5 io-c! \ set the pins to low-active
                     60:  bimini? IF 5 70c4 io-c! THEN \ on bimini set gpio4 as output and high to power up USB
                     61:  fec b44 config-w! \ set PNPIRQ pnpirq2 -> f , pnpirq1 -> e pnpirq0 -> c
                     62:   51 b41 config-b! \ disable access to PMxx space
                     63:   03 848 config-b! \ disable devB:3
                     64: 
                     65: \ The function of the PCI controller BARs change depending on the mode the
                     66: \ controller is in.
                     67: \ And the default is legacy mode.  Gross.
                     68: 05 909 config-b! \ Enable native PCI mode.
                     69: 03 940 config-b! \ Enable both ports.
                     70: 
                     71: \ Enable HPET on 8111, at address fe000000.
                     72: fe000001 8a0 config-l!
                     73: 
                     74: : >hpet  fe000000 + ;
                     75: : hpet@  >hpet rl@-le ;
                     76: : hpet!  >hpet rl!-le ;
                     77: 
                     78: INCLUDE freq.fs
                     79: 
                     80: \ Disable HPET.
                     81: 0 8a0 config-l!
                     82: 
                     83: \ 8111 has only 16 bits of PCI I/O space.  Get the address in range.
                     84: 8000 next-pci-io !
                     85: 
                     86: \ before disabling EHCI it needs to be reset
                     87: 
                     88: \ first we are setting up the BAR0, so that we can talk to the
                     89: \ memory mapped controller; not using the PCI scan because we just
                     90: \ want a temporary setup
                     91: 
                     92: : really-disable-broken-amd8111-ehci  ( -- )
                     93:    \ this word only works on U4 systems (JS21/Bimini)
                     94:    \ yeah, hardcoded!
                     95:    f2000000 to puid
                     96:    
                     97:    \ the PCI scan would assign pci-next-mmio to that device
                     98:    \ let's just take that address
                     99:    pci-next-mmio @ 100000 #aligned 
                    100:    \ pci-bus-number 10 lshift 210 or could be something like 70210
                    101:    \ 7: pci-bus-number
                    102:    \ 2: device function
                    103:    \ 10: offset 10 (bar 0)
                    104:    pci-bus-number 10 lshift 210 or rtas-config-l!
                    105: 
                    106:    \ enable memory space
                    107:    pci-bus-number 10 lshift 204 or dup rtas-config-l@ 2 or swap rtas-config-l!
                    108: 
                    109:    pci-next-mmio @ 100000 #aligned ( base )
                    110: 
                    111:    \ Sequence prescribed for resetting the EHCI contoller
                    112: 
                    113:    \ If Run/Stop bit (ECAP30 bit 0) is 1
                    114:    \   Set Run/Stop bit to 0
                    115:    \   wait 2ms
                    116: 
                    117:    dup 30 + rl@ 1 and 1 =  IF
                    118:       dup 30 + rl@ 1 or
                    119:       over 30 + rl!
                    120:       2 ms
                    121:    THEN
                    122: 
                    123:    \ While HCHalted bit (ECAP34 bit 12) is 0  (still running, wait forever)
                    124:    \   wait 2ms
                    125: 
                    126:    BEGIN  dup 34 + rl@ 1000 and 0= 2 ms UNTIL
                    127: 
                    128:    \ Set HCReset bit (ECAP30 bit 1)
                    129: 
                    130:    dup 30 + 2 swap rl!
                    131: 
                    132:    \ While HCReset bit is 1 (wait forever for reset to complete)
                    133:    \   wait 2ms
                    134: 
                    135:    BEGIN  dup 30 + rl@ 2 and 0= 2 ms UNTIL  drop
                    136: 
                    137:    \ now it is really disabled
                    138: 
                    139:    \ disable memory space access again
                    140:    2100000 pci-bus-number 10 lshift 204 or rtas-config-l!
                    141: 
                    142:    80 847 config-b! \ Disable EHCI, as it is terminally broken.
                    143: ;
                    144: 
                    145: my-space pci-class-name type cr
                    146: 
                    147: \ copied from pci-properties.fs and pci-scan.fs
                    148: \ changed to disable the EHCI completely just before the scan
                    149: \ and after mem/IO transactions have been enabled
                    150: 
                    151: \ Setup the Base and Limits in the Bridge
                    152: \ and scan the bus(es) beyond that Bridge
                    153: : pci-bridge-probe-amd8111 ( addr -- )
                    154:    dup pci-bridge-set-bases                        \ SetUp all Base Registers
                    155:    pci-bus-number 1+ TO pci-bus-number             \ increase number of busses found
                    156:    pci-device-vec-len 1+ TO pci-device-vec-len     \ increase the device-slot vector depth
                    157:    dup                                             \ stack config-addr for pci-bus!
                    158:    FF swap                                         \ Subordinate Bus Number ( for now to max to open all subbusses )
                    159:    pci-bus-number swap                             \ Secondary   Bus Number ( the new busnumber )
                    160:    dup pci-addr2bus swap                           \ Primary     Bus Number ( the current bus )
                    161:    pci-bus!                                        \ and set them into the bridge
                    162:    pci-enable                                      \ enable mem/IO transactions
                    163: 
                    164:    \ at this point we can talk to the broken EHCI controller
                    165:    really-disable-broken-amd8111-ehci
                    166: 
                    167:    dup pci-bus-scnd@ func-pci-probe-bus            \ and probe the secondary bus
                    168:    dup pci-bus-number swap pci-bus-subo!           \ set SubOrdinate Bus Number to current number of busses
                    169:    pci-device-vec-len 1- TO pci-device-vec-len     \ decrease the device-slot vector depth
                    170:    dup pci-bridge-set-limits                       \ SetUp all Limit Registers
                    171:    drop                                            \ forget the config-addr
                    172: ;
                    173: 
                    174: \ used to set up all unknown Bridges.
                    175: \ If a Bridge has no special handling for setup
                    176: \ the device file (pci-bridge_VENDOR_DEVICE.fs) can call
                    177: \ this word to setup busses and scan beyond.
                    178: : pci-bridge-generic-setup-amd8111 ( addr -- )
                    179:    pci-device-slots >r             \ save the slot array on return stack
                    180:    dup pci-common-props            \ set the common properties before scanning the bus
                    181:    s" pci" device-type             \ the type is allways "pci"
                    182:    dup pci-bridge-probe-amd8111    \ find all device connected to it
                    183:    dup assign-all-bridge-bars      \ set up all memory access BARs
                    184:    dup pci-set-irq-line            \ set the interrupt pin
                    185:    dup pci-set-capabilities        \ set up the capabilities
                    186:    pci-bridge-props                \ and generate all properties
                    187:    r> TO pci-device-slots          \ and reset the slot array
                    188: ;
                    189: 
                    190: : amd8111-bridge-setup
                    191:     my-space
                    192:     u3? takeover? or  IF
                    193:        \ if it is js20 or we are coming from takeover
                    194:        \ we just do the normal setup
                    195:        pci-bridge-generic-setup
                    196:     ELSE
                    197:        pci-bridge-generic-setup-amd8111
                    198:     THEN
                    199:     s" pci" device-name
                    200: ;
                    201: 
                    202: amd8111-bridge-setup

unix.superglobalmegacorp.com

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