Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / board-qemu / slof / pci-device_1234_1111.fs
1 \ *****************************************************************************
2 \ * Copyright (c) 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 my-space pci-device-generic-setup
14
15 \ Defaults, overriden from qemu
16 d# 800 VALUE disp-width
17 d# 600 VALUE disp-height
18 d#   8 VALUE disp-depth
19
20 \ Determine base address
21 10 config-l@ translate-my-address f not AND VALUE fb-base
22
23 \ Fixed up later
24 -1 VALUE io-base
25
26 \ We support only one instance
27 false VALUE is-installed?
28
29 : vga-io-xlate ( port -- addr )
30   io-base -1 = IF
31     dup translate-my-address fff not and to io-base
32   THEN
33   io-base +
34 ;
35
36 : vga-w! ( value port -- )
37   vga-io-xlate rw!-le
38 ;
39
40 : vga-w@ ( port -- value )
41   vga-io-xlate rw@-le
42 ;
43
44 : vga-b! ( value port -- )
45   vga-io-xlate rb!
46 ;
47
48 : vga-b@ ( port -- value )
49   vga-io-xlate rb@
50 ;
51
52 : vbe!  ( value index -- )
53   1ce vga-w! 1d0 vga-w!
54 ;
55
56 : vbe@  ( index -- value )
57   1ce vga-w! 1d0 vga-w@
58 ;
59
60 : color! ( r g b number -- ) 
61    3c8 vga-b!
62    rot 3c9 vga-b!
63    swap 3c9 vga-b!
64    3c9 vga-b!
65 ;
66
67 : color@ ( number -- r g b ) 
68    3c8 vga-b!
69    3c9 vga-b@
70    3c9 vga-b@
71    3c9 vga-b@
72 ;
73
74 : set-colors ( adr number #numbers -- )
75    over 3c8 vga-b!
76    swap DO
77      rb@ 3c9 vga-b!
78      rb@ 3c9 vga-b!
79      rb@ 3c9 vga-b!
80    LOOP
81    3drop
82 ;
83
84 : get-colors ( adr number #numbers -- )
85    3drop
86 ;
87
88 include graphics.fs
89
90 \ qemu fake VBE IO registers
91 0 CONSTANT VBE_DISPI_INDEX_ID
92 1 CONSTANT VBE_DISPI_INDEX_XRES
93 2 CONSTANT VBE_DISPI_INDEX_YRES
94 3 CONSTANT VBE_DISPI_INDEX_BPP
95 4 CONSTANT VBE_DISPI_INDEX_ENABLE
96 5 CONSTANT VBE_DISPI_INDEX_BANK
97 6 CONSTANT VBE_DISPI_INDEX_VIRT_WIDTH
98 7 CONSTANT VBE_DISPI_INDEX_VIRT_HEIGHT
99 8 CONSTANT VBE_DISPI_INDEX_X_OFFSET
100 9 CONSTANT VBE_DISPI_INDEX_Y_OFFSET
101 a CONSTANT VBE_DISPI_INDEX_NB
102
103 \ ENABLE register
104 00 CONSTANT VBE_DISPI_DISABLED
105 01 CONSTANT VBE_DISPI_ENABLED
106 02 CONSTANT VBE_DISPI_GETCAPS
107 20 CONSTANT VBE_DISPI_8BIT_DAC
108 40 CONSTANT VBE_DISPI_LFB_ENABLED
109 80 CONSTANT VBE_DISPI_NOCLEARMEM
110
111 : init-mode
112   0 3c0 vga-b!
113   VBE_DISPI_DISABLED VBE_DISPI_INDEX_ENABLE vbe!
114   0 VBE_DISPI_INDEX_X_OFFSET vbe!
115   0 VBE_DISPI_INDEX_Y_OFFSET vbe!
116   disp-width VBE_DISPI_INDEX_XRES vbe!
117   disp-height VBE_DISPI_INDEX_YRES vbe!
118   disp-depth VBE_DISPI_INDEX_BPP vbe!
119   VBE_DISPI_ENABLED VBE_DISPI_8BIT_DAC or VBE_DISPI_INDEX_ENABLE vbe!
120   0 3c0 vga-b!
121   20 3c0 vga-b!
122 ;
123
124 : clear-screen
125   fb-base disp-width disp-height disp-depth 7 + 8 / * * 0 rfill
126 ;
127
128 : read-settings
129   s" qemu,graphic-width" get-chosen IF
130      decode-int to disp-width 2drop
131   THEN
132   s" qemu,graphic-height" get-chosen IF
133      decode-int to disp-height 2drop
134   THEN
135   s" qemu,graphic-depth" get-chosen IF
136      decode-int nip nip     
137        dup 8 =
138        over f = or
139        over 10 = or
140        over 20 = or IF
141          to disp-depth
142        ELSE
143          ." Unsupported bit depth, using 8bpp " drop cr
144        THEN
145   THEN
146 ;
147
148 : add-legacy-reg
149   \ add legacy I/O Ports / Memory regions to assigned-addresses
150   \ see PCI Bus Binding Revision 2.1 Section 7.
151   s" reg" get-node get-property IF
152     \ "reg" does not exist, create new
153     encode-start
154   ELSE
155     \ "reg" does exist, copy it 
156     encode-bytes
157   THEN
158   \ I/O Range 0x1ce-0x1d2
159   my-space a1000000 or encode-int+ \ non-relocatable, aliased I/O space
160   1ce encode-64+ 4 encode-64+ \ addr size
161   \ I/O Range 0x3B0-0x3BB
162   my-space a1000000 or encode-int+ \ non-relocatable, aliased I/O space
163   3b0 encode-64+ c encode-64+ \ addr size
164   \ I/O Range 0x3C0-0x3DF
165   my-space a1000000 or encode-int+ \ non-relocatable, aliased I/O space
166   3c0 encode-64+ 20 encode-64+ \ addr size
167   \ Memory Range 0xA0000-0xBFFFF
168   my-space a2000000 or encode-int+ \ non-relocatable, <1MB Memory space
169   a0000 encode-64+ 20000 encode-64+ \ addr size
170   s" reg" property \ store "reg" property
171 ;
172
173 : setup-properties
174    \ Shouldn't this be done from open ?
175    disp-width encode-int s" width" property
176    disp-height encode-int s" height" property
177    disp-width disp-depth 7 + 8 / * encode-int s" linebytes" property
178    disp-depth encode-int s" depth" property
179    s" ISO8859-1" encode-string s" character-set" property \ i hope this is ok...
180    \ add "device_type" property
181    s" display" device-type
182    s" qemu,std-vga" encode-string s" compatible" property
183    \ XXX We don't create an "address" property because Linux doesn't know what
184    \ to do with it for >32-bit
185 ;
186
187 \ words for installation/removal, needed by is-install/is-remove, see display.fs
188 : display-remove ( -- ) 
189 ;
190
191 : hcall-invert-screen ( -- )
192     frame-buffer-adr frame-buffer-adr 3
193     screen-height screen-width * screen-depth * /x /
194     1 hv-logical-memop
195     drop
196 ;
197
198 : hcall-blink-screen ( -- )
199     \ 32 msec delay for visually noticing the blink
200     hcall-invert-screen 20 ms hcall-invert-screen
201 ;
202
203 : display-install ( -- )
204     is-installed? NOT IF
205         ." Installing QEMU fb" cr
206         fb-base to frame-buffer-adr
207         clear-screen
208         default-font 
209         set-font
210         disp-width disp-height
211         disp-width char-width / disp-height char-height /
212         disp-depth 7 + 8 /                      ( width height #lines #cols depth )
213         fb-install
214         ['] hcall-invert-screen to invert-screen
215         ['] hcall-blink-screen to blink-screen
216          true to is-installed?
217     THEN
218 ;
219
220 : set-alias
221     s" screen" find-alias 0= IF
222       \ no previous screen alias defined, define it...
223       s" screen" get-node node>path set-alias
224     ELSE
225        drop
226     THEN 
227 ;
228
229
230 ." qemu vga" cr
231
232 pci-master-enable
233 pci-mem-enable
234 pci-io-enable
235 add-legacy-reg
236 read-settings
237 init-mode
238 init-default-palette
239 setup-properties
240 ' display-install is-install
241 ' display-remove is-remove
242 set-alias