|
|
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: \ Hypertransport. ! 14: ! 15: \ See the PCI OF binding document. ! 16: ! 17: new-device ! 18: ! 19: s" ht" 2dup device-name device-type ! 20: s" u3-ht" compatible ! 21: s" U3" encode-string s" model" property ! 22: ! 23: 3 encode-int s" #address-cells" property ! 24: 2 encode-int s" #size-cells" property ! 25: ! 26: s" /mpic" find-node encode-int s" interrupt-parent" property ! 27: ! 28: 4000 encode-int 0 encode-int+ 0 encode-int+ ! 29: 1 encode-int+ s" /mpic" find-node encode-int+ ! 30: 10 encode-int+ 0 encode-int+ ! 31: s" interrupt-map" property ! 32: ! 33: f800 encode-int 0 encode-int+ 0 encode-int+ ! 34: 7 encode-int+ s" interrupt-map-mask" property ! 35: ! 36: : decode-unit 2 hex-decode-unit 3 lshift or ! 37: 8 lshift 0 0 rot ; ! 38: : encode-unit nip nip ff00 and 8 rshift dup 7 and swap 3 rshift ! 39: over IF 2 ELSE nip 1 THEN hex-encode-unit ; ! 40: ! 41: f2000000 CONSTANT my-puid ! 42: \ Configuration space accesses. ! 43: : >config dup ffff > IF 1000000 + THEN f2000000 + ; ! 44: ! 45: \ : config-l! >config cr ." config-l! " 2dup . space . rl!-le ; ! 46: \ : config-l@ >config cr ." config-l@ " dup . rl@-le space dup . ; ! 47: \ : config-w! >config cr ." config-w! " 2dup . space . rw!-le ; ! 48: \ : config-w@ >config cr ." config-w@ " dup . rw@-le space dup . ; ! 49: \ : config-b! >config cr ." config-b! " 2dup . space . rb! ; ! 50: \ : config-b@ >config cr ." config-b@ " dup . rb@ space dup . ; ! 51: ! 52: : config-l! >config rl!-le ; ! 53: : config-l@ >config rl@-le ; ! 54: : config-w! >config rw!-le ; ! 55: : config-w@ >config rw@-le ; ! 56: : config-b! >config rb! ; ! 57: : config-b@ >config rb@ ; ! 58: ! 59: : config-dump ( addr size -- ) ['] config-l@ 4 (dump) ; ! 60: ! 61: ! 62: \ 16MB of configuration space, seperate for type 0 and type 1. ! 63: 00000000 encode-int f2000000 encode-int+ ! 64: 00000000 encode-int+ 02000000 encode-int+ s" reg" property ! 65: ! 66: \ 4MB of I/O space. ! 67: 01000000 encode-int 00000000 encode-int+ 00000000 encode-int+ ! 68: 00000000 encode-int+ f4000000 encode-int+ ! 69: 00000000 encode-int+ 00400000 encode-int+ ! 70: ! 71: \ 1 GB of memory space @ 80000000 ! 72: 02000000 encode-int+ 00000000 encode-int+ 80000000 encode-int+ ! 73: 00000000 encode-int+ 80000000 encode-int+ ! 74: 00000000 encode-int+ 40000000 encode-int+ s" ranges" property ! 75: ! 76: \ Host bridge, so full bus range. ! 77: 0 encode-int ff encode-int+ s" bus-range" property ! 78: ! 79: : enable-ht-apic-space 3c0300fe f8070200 rl! ; ! 80: enable-ht-apic-space ! 81: ! 82: \ spare out 0xc0000000-0xefffffff for pcie ! 83: f8070200 rl@ fffffff0 and f8070200 rl! ! 84: \ enable io memory for pcie @ c0000000-efffffff ! 85: 70000003 f80903f0 rl!-le ! 86: ! 87: ! 88: \ Workaround for "takeover" boot on JS20: the top 8131 is programmed to be ! 89: \ device #1f, while it should be #01. ! 90: u3? IF f800 config-l@ 74501022 = IF 41 f8c2 config-w! THEN THEN ! 91: ! 92: \ Assign BUIDs. ! 93: ! 94: : find-ht-primary ! 95: 34 BEGIN config-b@ dup 0= ABORT" No HT capability block found!" ! 96: dup config-l@ e00000ff and 8 = IF 2 + EXIT THEN 1 + AGAIN ; ! 97: ! 98: : assign-buid ( this -- next ) ! 99: find-ht-primary dup >r config-w@ 5 rshift 1f and over r> config-b! + ; ! 100: ! 101: : assign-buids ( -- ) ! 102: 1 BEGIN 0 config-l@ ffffffff <> WHILE assign-buid REPEAT drop ; ! 103: ! 104: assign-buids ! 105: ! 106: : ldtstop f8000840 rl@ 40000 or f8000840 rl! ; ! 107: : delay 100000 0 DO LOOP ; ! 108: : wait-for-done BEGIN f8070110 rl@ 30 and UNTIL ! 109: BEGIN 8b4 config-l@ 30 and UNTIL ; ! 110: : ldtstop1 f8000840 rl@ dup 20000 or f8000840 rl! delay ! 111: f8000840 rl! wait-for-done ; ! 112: : warm 400000 f8070300 rl! 0 f8070300 rl! ; ! 113: ! 114: : dumpht cr f8070110 rl@ 8 0.r space 8b4 config-l@ 8 0.r ! 115: space f8070122 rb@ 2 0.r space 8bd config-b@ 2 0.r ; ! 116: ! 117: : clearht f8070110 dup rl@ swap rl! ! 118: f8070120 dup rl@ swap rl! ! 119: 08b4 dup config-l@ swap config-l! ! 120: 08bc dup config-l@ swap config-l! ; ! 121: ! 122: : setwidth dup f8070110 rb! 8b7 config-b! ; ! 123: : set8 00 setwidth ; ! 124: : set16 11 setwidth ; ! 125: ! 126: : setfreq dup f8070122 rb! 8bd config-b! ; ! 127: : set200 0 setfreq ; ! 128: : set300 1 setfreq ; ! 129: : set400 2 setfreq ; ! 130: : set500 3 setfreq ; ! 131: : set600 4 setfreq ; ! 132: : set800 5 setfreq ; ! 133: : set1000 6 setfreq ; ! 134: : set1200 7 setfreq ; ! 135: : set1400 8 setfreq ; ! 136: : set1600 9 setfreq ; ! 137: ! 138: : ht>freq 2 + dup 6 > IF 2* 6 - THEN d# 100 * ; ! 139: \ XXX: looks only at the U3/U4 side for max. link speed and width. ! 140: clearht f8070111 rb@ setwidth ! 141: f8070120 rw@ 2log dup .( Switching top HT bus to ) ht>freq 0 d# .r .( MHz...) cr ! 142: setfreq u3? IF ldtstop THEN u4? IF ldtstop1 THEN ! 143: ! 144: : open true ; ! 145: : close ; ! 146: ! 147: \ : probe-pci-host-bridge ( bus-max bus-min mmio-max mmio-base mem-max mem-base io-max io-base my-puid -- ) ! 148: s" /mpic" find-node my-puid pci-irq-init drop ! 149: 1f 0 c0000000 b8000000 b8000000 80000000 100000000 10000 ! 150: my-puid probe-pci-host-bridge ! 151: ! 152: : msi ! 153: f80040f0 010854 config-l! 0 010858 config-l! ! 154: ffff 01085c config-w! 81 010852 config-b! ! 155: ; ! 156: ! 157: \ This works. Needs cleaning up though; and we need to communicate the ! 158: \ MSI address range to the client program. (We keep the default range ! 159: \ at fee00000 for now). ! 160: : msi-on 7 1 DO 10000 i 800 * a0 + config-l! LOOP ; ! 161: msi-on ! 162: ! 163: \ PCIe debug / fixup ! 164: : find-pcie-cap ( devfn -- offset | 0 ) ! 165: >r 34 BEGIN r@ + config-b@ dup ff <> over and WHILE ! 166: dup r@ + config-b@ 10 = IF ! 167: r> drop EXIT ! 168: THEN 1+ ! 169: REPEAT r> 2drop 0 ! 170: ; ! 171: ! 172: : (set-ps) ( ps addr -- ) ! 173: 8 + >r 5 lshift r@ config-w@ ff1f and or r> config-w! ; ! 174: : set-ps ( ps -- ) ! 175: log2 7 - ! 176: 10000 0 DO i 8 lshift dup find-pcie-cap ?dup IF ! 177: + 2dup (set-ps) THEN drop LOOP drop ; ! 178: ! 179: : (set-rr) ( rr addr -- ) ! 180: 8 + >r c lshift r@ config-w@ 8fff and or r> config-w! ; ! 181: : set-rr ( rr -- ) ! 182: log2 7 - ! 183: 10000 0 DO i 8 lshift dup find-pcie-cap ?dup IF ! 184: + 2dup (set-rr) THEN drop LOOP drop ; ! 185: ! 186: 100 set-ps 200 set-rr ! 187: 100 set-ps 200 set-rr ! 188: ! 189: finish-device
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.