Annotation of qemu/roms/SLOF/board-qemu/slof/pci-device_1234_1111.fs, revision 1.1.1.1

1.1       root        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 3 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: 
                     61: \ **************************************************************************
                     62: \ ** These come from vga-display.fs and should probably be moved to a common
                     63: \ ** location.
                     64: 
                     65: : draw-rectangle ( adr x y w h -- )
                     66:    is-installed? IF
                     67:       0 ?DO
                     68:          4dup ( adr x y w adr x y w )
                     69:          drop ( adr x y w adr x y )
                     70:          i + screen-width * + \ calculate offset into framebuffer ((y + i) * screen_width + x) 
                     71:          ( adr x y w adr offs ) 
                     72:          frame-buffer-adr + \ add to frame-buffer-adr ( adr x y w adr fb_adr ) 
                     73:          1 pick 3 pick i * + swap 3 pick ( adr x y w adr adr_offs fb_adr w )
                     74:          rmove \ copy line ( adr x y w adr )
                     75:          drop ( adr x y w )
                     76:       LOOP
                     77:       4drop
                     78:    ELSE
                     79:       4drop drop
                     80:    THEN
                     81: ;
                     82: 
                     83: : fill-rectangle ( number x y w h -- )
                     84:    is-installed? IF
                     85:       0 ?DO
                     86:          4dup ( number x y w number x y w )
                     87:          drop ( number x y w number x y )
                     88:          i + screen-width * + \ calculate offset into framebuffer ((y + i) * screen_width + x) 
                     89:          ( number x y w number offs ) 
                     90:          frame-buffer-adr + \ add to frame-buffer-adr ( number x y w number adr ) 
                     91:          2 pick 2 pick ( number x y w number adr w number )
                     92:          rfill \ draw line ( number x y w number )
                     93:          drop ( number x y w )
                     94:       LOOP
                     95:       4drop
                     96:    ELSE
                     97:       4drop drop
                     98:    THEN
                     99: ;
                    100: 
                    101: : read-rectangle ( adr x y w h -- )
                    102:    is-installed? IF
                    103:       0 ?DO
                    104:          4dup ( adr x y w adr x y w )
                    105:          drop ( adr x y w adr x y )
                    106:          i + screen-width * + \ calculate offset into framebuffer ((y + i) * screen_width + x) 
                    107:          ( adr x y w adr offs ) 
                    108:          frame-buffer-adr + \ add to frame-buffer-adr ( adr x y w adr fb_adr ) 
                    109:          1 pick 3 pick i * + 3 pick ( adr x y w adr fb_adr adr_offs w )
                    110:          rmove \ copy line ( adr x y w adr )
                    111:          drop ( adr x y w )
                    112:       LOOP
                    113:       4drop
                    114:    ELSE
                    115:       4drop drop
                    116:    THEN
                    117: ;
                    118: 
                    119: \ ** end of copy from vga-display.fs
                    120: \ **************************************************************************
                    121: 
                    122: : color! ( r g b number -- ) 
                    123:    3c8 vga-b!
                    124:    rot 3c9 vga-b!
                    125:    swap 3c9 vga-b!
                    126:    3c9 vga-b!
                    127: ;
                    128: 
                    129: : color@ ( number -- r g b ) 
                    130:    3c8 vga-b!
                    131:    3c9 vga-b@
                    132:    3c9 vga-b@
                    133:    3c9 vga-b@
                    134: ;
                    135: 
                    136: : set-colors ( adr number #numbers -- )
                    137:    over 3c8 vga-b!
                    138:    swap DO
                    139:      rb@ 3c9 vga-b!
                    140:      rb@ 3c9 vga-b!
                    141:      rb@ 3c9 vga-b!
                    142:    LOOP
                    143:    3drop
                    144: ;
                    145: 
                    146: : get-colors ( adr number #numbers -- )
                    147:    3drop
                    148: ;
                    149: 
                    150: : default-palette
                    151:   \ Grayscale ramp for now, be smarter later
                    152:   100 0 DO
                    153:     i i i i color!
                    154:   LOOP
                    155: ;
                    156: 
                    157: \ qemu fake VBE IO registers
                    158: 0 CONSTANT VBE_DISPI_INDEX_ID
                    159: 1 CONSTANT VBE_DISPI_INDEX_XRES
                    160: 2 CONSTANT VBE_DISPI_INDEX_YRES
                    161: 3 CONSTANT VBE_DISPI_INDEX_BPP
                    162: 4 CONSTANT VBE_DISPI_INDEX_ENABLE
                    163: 5 CONSTANT VBE_DISPI_INDEX_BANK
                    164: 6 CONSTANT VBE_DISPI_INDEX_VIRT_WIDTH
                    165: 7 CONSTANT VBE_DISPI_INDEX_VIRT_HEIGHT
                    166: 8 CONSTANT VBE_DISPI_INDEX_X_OFFSET
                    167: 9 CONSTANT VBE_DISPI_INDEX_Y_OFFSET
                    168: a CONSTANT VBE_DISPI_INDEX_NB
                    169: 
                    170: \ ENABLE register
                    171: 00 CONSTANT VBE_DISPI_DISABLED
                    172: 01 CONSTANT VBE_DISPI_ENABLED
                    173: 02 CONSTANT VBE_DISPI_GETCAPS
                    174: 20 CONSTANT VBE_DISPI_8BIT_DAC
                    175: 40 CONSTANT VBE_DISPI_LFB_ENABLED
                    176: 80 CONSTANT VBE_DISPI_NOCLEARMEM
                    177: 
                    178: : init-mode
                    179:   0 3c0 vga-b!
                    180:   VBE_DISPI_DISABLED VBE_DISPI_INDEX_ENABLE vbe!
                    181:   0 VBE_DISPI_INDEX_X_OFFSET vbe!
                    182:   0 VBE_DISPI_INDEX_Y_OFFSET vbe!
                    183:   disp-width VBE_DISPI_INDEX_XRES vbe!
                    184:   disp-height VBE_DISPI_INDEX_YRES vbe!
                    185:   disp-depth VBE_DISPI_INDEX_BPP vbe!
                    186:   VBE_DISPI_ENABLED VBE_DISPI_8BIT_DAC or VBE_DISPI_INDEX_ENABLE vbe!
                    187:   0 3c0 vga-b!
                    188:   20 3c0 vga-b!
                    189: ;
                    190: 
                    191: : clear-screen
                    192:   fb-base disp-width disp-height disp-depth 7 + 8 / * * 0 rfill
                    193: ;
                    194: 
                    195: : read-settings
                    196:   s" qemu,graphic-width" get-chosen IF
                    197:      decode-int to disp-width 2drop
                    198:   THEN
                    199:   s" qemu,graphic-height" get-chosen IF
                    200:      decode-int to disp-height 2drop
                    201:   THEN
                    202:   s" qemu,graphic-depth" get-chosen IF
                    203:      decode-int nip nip     
                    204:        dup 8 =
                    205:        over f = or
                    206:        over 10 = or
                    207:        over 20 = or IF
                    208:          to disp-depth
                    209:        ELSE
                    210:          ." Unsupported bit depth, using 8bpp " drop cr
                    211:        THEN
                    212:   THEN
                    213: ;
                    214: 
                    215: : add-legacy-reg
                    216:   \ add legacy I/O Ports / Memory regions to assigned-addresses
                    217:   \ see PCI Bus Binding Revision 2.1 Section 7.
                    218:   s" reg" get-node get-property IF
                    219:     \ "reg" does not exist, create new
                    220:     encode-start
                    221:   ELSE
                    222:     \ "reg" does exist, copy it 
                    223:     encode-bytes
                    224:   THEN
                    225:   \ I/O Range 0x1ce-0x1d2
                    226:   my-space a1000000 or encode-int+ \ non-relocatable, aliased I/O space
                    227:   1ce encode-64+ 4 encode-64+ \ addr size
                    228:   \ I/O Range 0x3B0-0x3BB
                    229:   my-space a1000000 or encode-int+ \ non-relocatable, aliased I/O space
                    230:   3b0 encode-64+ c encode-64+ \ addr size
                    231:   \ I/O Range 0x3C0-0x3DF
                    232:   my-space a1000000 or encode-int+ \ non-relocatable, aliased I/O space
                    233:   3c0 encode-64+ 20 encode-64+ \ addr size
                    234:   \ Memory Range 0xA0000-0xBFFFF
                    235:   my-space a2000000 or encode-int+ \ non-relocatable, <1MB Memory space
                    236:   a0000 encode-64+ 20000 encode-64+ \ addr size
                    237:   s" reg" property \ store "reg" property
                    238: ;
                    239: 
                    240: : setup-properties
                    241:    \ Shouldn't this be done from open ?
                    242:    disp-width encode-int s" width" property
                    243:    disp-height encode-int s" height" property
                    244:    disp-width disp-depth 7 + 8 / * encode-int s" linebytes" property
                    245:    disp-depth encode-int s" depth" property
                    246:    s" ISO8859-1" encode-string s" character-set" property \ i hope this is ok...
                    247:    \ add "device_type" property
                    248:    s" display" encode-string s" device_type" property
                    249:    s" qemu,std-vga" encode-string s" compatible" property
                    250:    \ XXX We don't create an "address" property because Linux doesn't know what
                    251:    \ to do with it for >32-bit
                    252: ;
                    253: 
                    254: \ words for installation/removal, needed by is-install/is-remove, see display.fs
                    255: : display-remove ( -- ) 
                    256: ;
                    257: 
                    258: : display-install ( -- )
                    259:     is-installed? NOT IF
                    260:         ." Installing QEMU fb" cr
                    261:         fb-base to frame-buffer-adr
                    262:         clear-screen
                    263:         default-font 
                    264:         set-font
                    265:         disp-width disp-height
                    266:         disp-width char-width / disp-height char-height /
                    267:         disp-depth 7 + 8 /                      ( width height #lines #cols depth )
                    268:         fb-install
                    269:         true to is-installed?
                    270:     THEN
                    271: ;
                    272: 
                    273: : dimensions ( -- width height )
                    274:   disp-width disp-height
                    275: ;
                    276: 
                    277: : set-alias
                    278:     s" screen" find-alias 0= IF
                    279:       \ no previous screen alias defined, define it...
                    280:       s" screen" get-node node>path set-alias
                    281:     ELSE
                    282:        drop
                    283:     THEN 
                    284: ;
                    285: 
                    286: 
                    287: ." qemu vga" cr
                    288: 
                    289: pci-master-enable
                    290: pci-mem-enable
                    291: pci-io-enable
                    292: add-legacy-reg
                    293: read-settings
                    294: init-mode
                    295: default-palette
                    296: setup-properties
                    297: ' display-install is-install
                    298: ' display-remove is-remove
                    299: set-alias

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.