Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / board-qemu / slof / pci-device_1013_00b8.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 : vga-crt@ ( index -- value )
53   3d4 vga-b!
54   3d5 vga-b@
55 ;
56
57 : vga-crt! ( value index -- )
58   3d4 vga-b!
59   3d5 vga-b!
60 ;
61
62 : vga-seq@ ( index -- value )
63   3c4 vga-b!
64   3c5 vga-b@
65 ;
66
67 : vga-seq! ( value index -- )
68   3c4 vga-b!
69   3c5 vga-b!
70 ;
71
72 : vga-att@ ( index -- value )
73   3c0 vga-b!
74   3c1 vga-b@
75 ;
76
77 : vga-att! ( value index -- )
78   3c0 vga-b!
79   3c0 vga-b!
80 ;
81
82 : vga-gfx@ ( index -- value )
83   3ce vga-b!
84   3cf vga-b@
85 ;
86
87 : vga-gfx! ( value index -- )
88   3ce vga-b!
89   3cf vga-b!
90 ;
91
92 : color! ( r g b number -- ) 
93    3c8 vga-b!
94    rot 2 >> 3c9 vga-b!
95    swap 2 >> 3c9 vga-b!
96    2 >> 3c9 vga-b!
97 ;
98
99 : color@ ( number -- r g b ) 
100    3c8 vga-b!
101    3c9 vga-b@ 2 <<
102    3c9 vga-b@ 2 <<
103    3c9 vga-b@ 2 <<
104 ;
105
106 : set-colors ( adr number #numbers -- )
107    over 3c8 vga-b!
108    swap DO
109      rb@ 2 >> 3c9 vga-b!
110      rb@ 2 >> 3c9 vga-b!
111      rb@ 2 >> 3c9 vga-b!
112    LOOP
113    3drop
114 ;
115
116 : get-colors ( adr number #numbers -- )
117    3drop
118 ;
119
120 include graphics.fs
121
122 : init-mode
123   3da vga-b@ drop \ reset flip flop
124   0f 3c2 vga-b!   \ color mode, ram enable, ...
125   12 06 vga-seq!  \ unlock extensions
126   05 06 vga-gfx!  \ graphic mode  
127   \ set bit depth. Note: we should set the hidden
128   \ dac register to differenciate 15 and 16bpp, but
129   \ it's annoying and in practice we don't care as
130   \ we are only displaying in black & white atm
131   disp-depth CASE \ set depth
132      8 OF 01 07 vga-seq! ENDOF
133      f OF 07 07 vga-seq! ENDOF
134     10 OF 07 07 vga-seq! ENDOF
135     20 OF 09 07 vga-seq! ENDOF
136   ENDCASE
137   ff 02 vga-seq!  \ enable plane write
138   0a 04 vga-seq!  \ memory mode
139   03 17 vga-crt!  \ disable display
140   \ calculate line offset & split
141   disp-width disp-depth 7 + 8 / * 3 >>
142   dup ff and 13 vga-crt!  \ bottom bits
143   4 >> 10 and 1b vga-crt! \ top bit
144   disp-width 3 >> 1 -                  01 vga-crt! \ H_DISP
145   disp-height 1 - ff and               12 vga-crt! \ V_DISP
146   disp-height 1 - 7 >> 2 and
147   disp-height 1 - 3 >> 40 and
148   or 10 or                             07 vga-crt! \ OFLOW
149   ff 18 vga-crt! \ LINE_COMPARE
150   40 09 vga-crt! \ MAX_SCAN
151   08 04 vga-crt! \ SYNC_START
152   0f 02 vga-crt! \ BLANK_START
153   00 0c vga-crt!
154   00 0d vga-crt!
155   40 05 vga-gfx! \ gfx mode
156   83 17 vga-crt! \ enable display
157   33 3c0 vga-b!  \ gfx in ar index
158   00 3c0 vga-b!
159   01 01 vga-seq! \ enable seq
160 ;
161
162 : clear-screen
163   fb-base disp-width disp-height disp-depth 7 + 8 / * * 0 rfill
164 ;
165
166 : read-settings
167   s" qemu,graphic-width" get-chosen IF
168      decode-int to disp-width 2drop
169   THEN
170   s" qemu,graphic-height" get-chosen IF
171      decode-int to disp-height 2drop
172   THEN
173   s" qemu,graphic-depth" get-chosen IF
174      decode-int nip nip     
175        dup 8 =
176        over f = or
177        over 10 = or
178        over 20 = or IF
179          to disp-depth
180        ELSE
181          ." Unsupported bit depth, using 8bpp " drop cr
182        THEN
183   THEN
184 ;
185
186 : add-legacy-reg
187   \ add legacy I/O Ports / Memory regions to assigned-addresses
188   \ see PCI Bus Binding Revision 2.1 Section 7.
189   s" reg" get-node get-property IF
190     \ "reg" does not exist, create new
191     encode-start
192   ELSE
193     \ "reg" does exist, copy it 
194     encode-bytes
195   THEN
196   \ I/O Range 0x1ce-0x1d2
197   my-space a1000000 or encode-int+ \ non-relocatable, aliased I/O space
198   1ce encode-64+ 4 encode-64+ \ addr size
199   \ I/O Range 0x3B0-0x3BB
200   my-space a1000000 or encode-int+ \ non-relocatable, aliased I/O space
201   3b0 encode-64+ c encode-64+ \ addr size
202   \ I/O Range 0x3C0-0x3DF
203   my-space a1000000 or encode-int+ \ non-relocatable, aliased I/O space
204   3c0 encode-64+ 20 encode-64+ \ addr size
205   \ Memory Range 0xA0000-0xBFFFF
206   my-space a2000000 or encode-int+ \ non-relocatable, <1MB Memory space
207   a0000 encode-64+ 20000 encode-64+ \ addr size
208   s" reg" property \ store "reg" property
209 ;
210
211 : setup-properties
212    \ Shouldn't this be done from open ?
213    disp-width encode-int s" width" property
214    disp-height encode-int s" height" property
215    disp-width disp-depth 7 + 8 / * encode-int s" linebytes" property
216    disp-depth encode-int s" depth" property
217    s" ISO8859-1" encode-string s" character-set" property \ i hope this is ok...
218    \ add "device_type" property
219    s" display" device-type
220    \ XXX We don't create an "address" property because Linux doesn't know what
221    \ to do with it for >32-bit
222 ;
223
224 \ words for installation/removal, needed by is-install/is-remove, see display.fs
225 : display-remove ( -- ) 
226 ;
227
228 : display-install ( -- )
229     is-installed? NOT IF
230         ." Installing QEMU fb" cr
231         fb-base to frame-buffer-adr
232         default-font 
233         set-font
234         disp-width disp-height
235         disp-width char-width / disp-height char-height /
236         disp-depth 7 + 8 /                      ( width height #lines #cols depth )
237         fb-install
238         true to is-installed?
239     THEN
240 ;
241
242 : set-alias
243     s" screen" find-alias 0= IF
244       \ no previous screen alias defined, define it...
245       s" screen" get-node node>path set-alias
246     ELSE
247        drop
248     THEN 
249 ;
250
251
252 ." cirrus vga" cr
253
254 pci-master-enable
255 pci-mem-enable
256 pci-io-enable
257 add-legacy-reg
258 read-settings
259 init-mode
260 clear-screen
261 init-default-palette
262 setup-properties
263 ' display-install is-install
264 ' display-remove is-remove
265 set-alias