Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / slof / fs / pci-config-bridge.fs
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
8 \ *
9 \ * Contributors:
10 \ *     IBM Corporation - initial implementation
11 \ ****************************************************************************/
12
13 \ Generic config space access function - xt is execution token of rtas-config-xx
14 : config-xt  ( config-addr xt -- data )
15    puid >r                            \ Safe puid
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
19    THEN
20    swap execute                       \ Execute the rtas-config-xx function
21    r> TO puid                         \ Restore previous puid
22 ;
23
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 ;
28
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 ;
33
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 ;
36
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
44 ;
45
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
54         ELSE                            \ ELSE
55                 nip 1 hex-encode-unit   \ | create string with only DevNum
56         THEN                            \ FI
57 ;
58
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"
67    THEN
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
72    ELSE
73       nip
74    THEN
75    F NOT AND                            \ Clear indicator bits
76    \ TODO: Use translate-address here!
77 ;
78
79 : map-out ( virt size -- )
80    \ ." map-out called: " .s cr
81    2drop 
82 ;
83
84 : dma-alloc ( ... size -- virt )
85    \ ." dma-alloc called: " .s cr
86    alloc-mem
87 ;
88
89 : dma-free ( virt size -- )
90    \ ." dma-free called: " .s cr
91    free-mem
92 ;
93
94 : dma-map-in ( ... virt size cacheable? -- devaddr )
95    \ ." dma-map-in called: " .s cr
96    2drop
97 ;
98
99 : dma-map-out ( virt devaddr size -- )
100    \ ." dma-map-out called: " .s cr
101    2drop drop
102 ;
103
104 : dma-sync ( virt devaddr size -- )
105    \ XXX should we add at least a memory barrier here?
106    \ ." dma-sync called: " .s cr
107    2drop drop
108 ;
109
110 : open true ;
111 : close ;