Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openbios / forth / util / pci.fs
1 \ tag: PCI helper functions
2
3 \ Copyright (C) 2003-2004 Stefan Reinauer
4 \ Copyright (C) 2003 Samuel Rydh
5
6 \ See the file "COPYING" for further information about
7 \ the copyright and warranty status of this work.
8
9
10 \ simple set of words for pci access, these are not 
11 \ compliant to the PCI bus binding of OpenFirmware.
12
13 \ only forth
14 \ vocabulary pci 
15 \ also pci definitions
16
17 hex
18
19 : busdevfn ( bus dev fn -- busdevfn )
20   7 and swap 
21   1f and 3 << or       ( dev fn -- devfn )
22   swap 8 << or            ( bus devfn -- busdevfn )
23   ;
24
25 : config-command ( busdevfn reg -- reg addr )
26   dup -rot
27   3 invert and 
28   swap 8 << or 
29   80000000 or
30   ;
31
32 : pci-c@ ( busdevfn reg -- x )
33   config-command
34   cf8 iol!
35   3 and cfc + 
36   ioc@
37   ;
38
39 : pci-w@ ( busdevfn reg -- x )
40   config-command
41   cf8 iol!
42   2 and cfc + iow@
43   ;
44
45 : pci-l@ ( busdevfn reg -- x )
46   config-command
47   cf8 iol! 
48   drop
49   cfc iol@
50   ;
51
52 : pci-c! ( busdevfn reg val -- )
53   -rot config-command 
54   cf8 iol! 
55   3 and cfc + ioc!
56   ;
57   
58 : pci-w! ( busdevfn reg val -- )
59   -rot config-command 
60   cf8 iol! 
61   2 and cfc + iow!
62   ;
63   
64 : pci-l! ( busdevfn reg val -- )
65   -rot config-command 
66   cf8 iol! 
67   drop
68   cfc iol!
69   ;
70  
71 : dump-pci-device ( bus dev fn -- )
72   2 pick (.) type 3a emit over 
73   (.) type 2e emit dup (.) type 20 emit 5b emit  \ 0:18.0 [
74   busdevfn >r
75   r@ 0 pci-w@ u. 2f emit r@ 2 pci-w@ u. 5d emit          \ 1022/1100]
76   r>
77   \ now we iterate
78   10 0 do
79     cr i todigit emit 30 emit 3a emit 20 emit
80     10 0 do
81       dup i j 4 << or  pci-c@ 
82       dup 4 >> todigit emit f and todigit emit
83       20 emit
84     loop
85   loop
86   drop
87   cr cr
88   ;
89   
90 \ : test-pci
91 \   0  2 0 dump-pci-device
92 \   ;