Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openbios / drivers / pci.fs
1 [IFDEF] CONFIG_DRIVER_PCI
2
3 : pci-addr-encode ( addr.lo addr.mi addr.hi )
4   rot >r swap >r 
5   encode-int 
6   r> encode-int encode+ 
7   r> encode-int encode+
8   ;
9  
10 : pci-len-encode ( len.lo len.hi )
11   encode-int 
12   rot encode-int encode+ 
13   ;
14
15 \ Get region offset for BAR reg
16 : pci-bar-offset@ ( bar-reg -- off.lo off.hi -1 | 0 )
17   " reg" active-package get-package-property 0= if
18     begin
19       decode-phys    \ ( reg prop prop-len phys.lo phys.mid phys.hi )
20       ff and 5 pick = if
21         >r >r 3drop r> r>
22         -1 exit
23       else
24         2drop
25       then
26       \ Drop the size as we don't need it
27       decode-int drop decode-int drop
28       dup 0=
29     until
30     3drop
31     0 exit
32   else
33     0
34   then
35   ;
36
37 \ Get region size for BAR reg
38 : pci-bar-size@ ( bar-reg -- size )
39   " reg" active-package get-package-property 0= if
40     begin
41       decode-phys    \ ( reg prop prop-len phys.lo phys.mid phys.hi )
42       ff and 5 pick = if
43         2drop decode-int drop
44         decode-int
45         >r 3drop r>
46         exit
47       else
48         2drop decode-int drop
49         decode-int drop
50       then
51       dup 0=
52     until
53     3drop
54     0    \ default size of 0 if BAR not found
55   then
56   ;
57
58 \ Get base address for configured BAR reg
59 : pci-bar-base@ ( bar-reg -- addr.lo addr.hi -1 | 0 )
60   " assigned-addresses" active-package get-package-property 0= if
61     begin
62       decode-phys    \ ( reg prop prop-len phys.lo phys.mid phys.hi )
63       ff and 5 pick = if
64         >r >r 3drop r> r>
65         -1 exit
66       else
67         2drop
68       then
69       \ Drop the size as we don't need it
70       decode-int drop decode-int drop
71       dup 0=
72     until
73     3drop
74     0 exit
75   else
76     0
77   then
78   ;
79
80 \ Get PCI bus address and size for configured BAR reg
81 : pci-bar>pci-region  ( bar-reg -- addr.lo addr.hi size )
82   dup
83   >r pci-bar-offset@ if
84     swap r@ pci-bar-base@ if
85       swap d+
86     then
87     swap r@ pci-bar-size@
88   then
89   r> drop
90   ;
91
92 [THEN]