summaryrefslogtreecommitdiffstats
path: root/qemu/roms/openbios/forth/util/pci.fs
blob: 57ded62650c0731b44f588d6ca65e291934b365d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
\ tag: PCI helper functions
\ 
\ Copyright (C) 2003-2004 Stefan Reinauer
\ Copyright (C) 2003 Samuel Rydh
\ 
\ See the file "COPYING" for further information about
\ the copyright and warranty status of this work.
\ 

\ simple set of words for pci access, these are not 
\ compliant to the PCI bus binding of OpenFirmware.

\ only forth
\ vocabulary pci 
\ also pci definitions

hex

: busdevfn ( bus dev fn -- busdevfn )
  7 and swap 
  1f and 3 << or       ( dev fn -- devfn )
  swap 8 << or            ( bus devfn -- busdevfn )
  ;

: config-command ( busdevfn reg -- reg addr )
  dup -rot
  3 invert and 
  swap 8 << or 
  80000000 or
  ;

: pci-c@ ( busdevfn reg -- x )
  config-command
  cf8 iol!
  3 and cfc + 
  ioc@
  ;

: pci-w@ ( busdevfn reg -- x )
  config-command
  cf8 iol!
  2 and cfc + iow@
  ;

: pci-l@ ( busdevfn reg -- x )
  config-command
  cf8 iol! 
  drop
  cfc iol@
  ;

: pci-c! ( busdevfn reg val -- )
  -rot config-command 
  cf8 iol! 
  3 and cfc + ioc!
  ;
  
: pci-w! ( busdevfn reg val -- )
  -rot config-command 
  cf8 iol! 
  2 and cfc + iow!
  ;
  
: pci-l! ( busdevfn reg val -- )
  -rot config-command 
  cf8 iol! 
  drop
  cfc iol!
  ;
 
: dump-pci-device ( bus dev fn -- )
  2 pick (.) type 3a emit over 
  (.) type 2e emit dup (.) type 20 emit 5b emit  \ 0:18.0 [
  busdevfn >r
  r@ 0 pci-w@ u. 2f emit r@ 2 pci-w@ u. 5d emit 	 \ 1022/1100]
  r>
  \ now we iterate
  10 0 do
    cr i todigit emit 30 emit 3a emit 20 emit
    10 0 do
      dup i j 4 << or  pci-c@ 
      dup 4 >> todigit emit f and todigit emit
      20 emit
    loop
  loop
  drop
  cr cr
  ;
  
\ : test-pci
\   0  2 0 dump-pci-device
\   ;