1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2011 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
10 \ * IBM Corporation - initial implementation
11 \ ****************************************************************************/
13 \ Generic config space access function - xt is execution token of rtas-config-xx
14 : config-xt ( config-addr xt -- data )
16 my-puid TO puid \ Set my-puid
17 swap dup ffff00 AND 0= IF \ Has bus-device-function been specified?
18 my-space OR \ No: use my-space instead
20 swap execute \ Execute the rtas-config-xx function
21 r> TO puid \ Restore previous puid
24 \ define the config reads
25 : config-b@ ( config-addr -- data ) ['] rtas-config-b@ config-xt ;
26 : config-w@ ( config-addr -- data ) ['] rtas-config-w@ config-xt ;
27 : config-l@ ( config-addr -- data ) ['] rtas-config-l@ config-xt ;
29 \ define the config writes
30 : config-b! ( data config-addr -- ) ['] rtas-config-b! config-xt ;
31 : config-w! ( data config-addr -- ) ['] rtas-config-w! config-xt ;
32 : config-l! ( data config-addr -- ) ['] rtas-config-l! config-xt ;
34 \ for Debug purposes: dumps the whole config space
35 : config-dump puid >r my-puid TO puid my-space pci-dump r> TO puid ;
37 \ needed to find the right path in the device tree
38 : decode-unit ( addr len -- phys.lo ... phys.hi )
39 2 hex-decode-unit \ decode string
40 B lshift swap \ shift the devicenumber to the right spot
41 8 lshift or \ add the functionnumber
42 my-bus 10 lshift or \ add the busnumber
43 0 0 rot \ make phys.lo = 0 = phys.mid
46 \ needed to have the right unit address in the device tree listing
47 \ phys.lo=phys.mid=0 , phys.hi=config-address
48 : encode-unit ( phys.lo ... phys.hi -- unit-str unit-len )
49 nip nip \ forget the both zeros
50 dup 8 rshift 7 and swap \ calc Functionnumber
51 B rshift 1F and \ calc Devicenumber
52 over IF \ IF Function!=0
53 2 hex-encode-unit \ | create string with DevNum,FnNum
55 nip 1 hex-encode-unit \ | create string with only DevNum
59 : map-in ( phys.lo phys.mid phys.hi size -- virt )
60 \ ." map-in called: " .s cr
61 \ Ignore the size, phys.lo and phys.mid, get BAR from config space
62 drop nip nip ( phys.hi )
63 \ Sanity check whether config address is in expected range:
64 dup FF AND dup 10 28 WITHIN NOT swap 30 <> AND IF
65 cr ." phys.hi = " . cr
66 ABORT" map-in with illegal config space address"
68 00FFFFFF AND \ Need only bus-dev-fn+register bits
69 dup config-l@ ( phys.hi' bar.lo )
70 dup 7 AND 4 = IF \ Is it a 64-bit BAR?
71 swap 4 + config-l@ lxjoin \ Add upper part of 64-bit BAR
75 F NOT AND \ Clear indicator bits
76 \ TODO: Use translate-address here!
79 : map-out ( virt size -- )
80 \ ." map-out called: " .s cr
84 : dma-sync ( virt devaddr size -- )
85 \ XXX should we add at least a memory barrier here?
86 \ ." dma-sync called: " .s cr