OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [framebuf/] [synth/] [current/] [src/] [synthfb.c] - Blame information for rev 791

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      synthfb.c
4
//
5
//      Provide one or more framebuffer devices for the synthetic target.
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 2008 Free Software Foundation, Inc.                        
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//###DESCRIPTIONBEGIN####
41
//
42
// Author(s):     bartv
43
// Date:          2005-10-28
44
//
45
//###DESCRIPTIONEND####
46
//========================================================================
47
 
48
#include <pkgconf/devs_framebuf_synth.h>
49
#include <pkgconf/io_framebuf.h>
50
#include <cyg/io/framebuf.h>
51
#include <errno.h>
52
#include <string.h>
53
#include <cyg/infra/cyg_type.h>
54
#include <cyg/infra/cyg_ass.h>
55
#include <cyg/infra/diag.h>
56
#include <cyg/hal/hal_io.h>
57
#include "protocol.h"
58
 
59
// Set the DEBUG_LEVEL to 0 for no debugging, 2 for maximum debugging.
60
#define DEBUG_LEVEL 0
61
#define DEBUG(_level_, _str_, ...)              \
62
    CYG_MACRO_START                             \
63
    if (_level_ <= DEBUG_LEVEL) {               \
64
        diag_printf( _str_, ## __VA_ARGS__);    \
65
    }                                           \
66
    CYG_MACRO_END
67
 
68
// Achieving high performance graphics operations in the synthetic
69
// target is difficult. Theoretically it might be possible to access
70
// the Linux framebuffer directly using MIT-SHM or DGA. However there
71
// is no practical way to handle the relevant parts of the X prococol,
72
// e.g. expose events. We also don't want to go via the
73
// general-purpose xchgmsg() functionality and a Tcl script, those
74
// are not appropriate for high performance.
75
//
76
// Instead if the I/O auxiliary is running a framebuffer device is
77
// instantiated, and the framebuf.tcl script will start a program
78
// framebuf. That program will create a shared memory region which
79
// then gets mapped into the synthetic target's address space. The
80
// shared memory region holds a synth_fb_data structure followed by
81
// the framebuffer data. If there are multiple framebuffer devices
82
// then there will be multiple invocations of the framebuf program.
83
//
84
// The framebuf program needs to respond to requests from several
85
// different sources. The X server may send events like expose.
86
// The synthetic target application can send synchronization requests,
87
// palette updates, and so on. The X events will come via a socket,
88
// and the requests from framebuf.tcl can come via a pipe. select()
89
// will serve for this. Several mechanisms can be used for the
90
// communication between the synthetic target application and framebuf
91
// including shared memory semaphores and reliable signals. To fit in
92
// neatly with the select() a named fifo is used.
93
//
94
// So assuming a framebuf program is running fb_op() writes a single
95
// byte to the fifo, then waits for framebuf to complete the
96
// operation. That wait also uses a named fifo. This keeps everything
97
// synchronous, and avoids some portability problems between
98
// Linux on various architectures.
99
static void
100
fb_op(cyg_fb* fb, int command)
101
{
102
    synth_fb_data*  fb_data = (synth_fb_data*) fb->fb_driver2;
103
    DEBUG(2, "target synthfb: fb_op %d\n", command);
104
    if (fb_data->connected) {
105
        cyg_uint8   data[1];
106
        int         rc;
107
 
108
        data[0] = (cyg_uint8)command;
109
        do {
110
            rc = cyg_hal_sys_write(fb_data->fifo_to_framebuf, (const void*) data, 1);
111
        } while (-CYG_HAL_SYS_EINTR == rc);
112
        do {
113
            rc = cyg_hal_sys_read(fb_data->fifo_from_framebuf, (void*) data, 1);
114
        } while (-CYG_HAL_SYS_EINTR == rc);
115
        if (rc < 0) {
116
            diag_printf("Internal error: unexpected result %d when receiving response from the framebuf program.\n", rc);
117
            diag_printf("              : disabling framebuffer device fb%d.\n", fb->fb_driver0);
118
            fb_data->connected = 0;
119
        }
120
    }
121
    DEBUG(2, "target synthfb: fb_op %d done\n", command);
122
}
123
 
124
// Create a framebuffer device. This gets called from a C++
125
// static constructor, to ensure that all the framebuffer
126
// windows are created early on during initialization before
127
// the host-side ecosynth support performs any cleanups.
128
void
129
_cyg_synth_fb_instantiate(struct cyg_fb* fb)
130
{
131
    synth_fb_data*  local_fb_data = (synth_fb_data*) fb->fb_driver2;
132
    synth_fb_data*  shared_fb_data;
133
    char            device_data[512];
134
    char            fb_name[4];
135
    char*           fb_format   = 0;
136
    char*           ptr;
137
    char*           filename;
138
    int             fd;
139
    int             len;
140
    int             reply;
141
    cyg_uint8*      fb_base;
142
    DEBUG(1, "target synth_fb_instantiate\n");
143
 
144
    if (!synth_auxiliary_running) {
145
        diag_printf("cyg_synth_fb_instantiate(): no I/O auxiliary, sticking with in-memory framebuffer\n");
146
        return;
147
    }
148
 
149
    diag_sprintf(fb_name, "fb%d", fb->fb_driver0);
150
    switch(fb->fb_format) {
151
        // Only bother with the formats used by gensynth_fb.tcl
152
      case CYG_FB_FORMAT_1BPP_PAL888:
153
        {
154
            static const cyg_uint8  fb_1bpp_palette[2 * 3]  = {
155
                0x00, 0x00, 0x00,   // colour 0 == black
156
                0xFF, 0xFF, 0xFF    // colour 1 == white
157
            };
158
            fb_format = "1BPP_PAL888";
159
            memcpy(local_fb_data->palette, fb_1bpp_palette, sizeof(fb_1bpp_palette));
160
            break;
161
        }
162
      case CYG_FB_FORMAT_2BPP_PAL888:
163
        {
164
            static const cyg_uint8  fb_2bpp_palette[4 * 3]  = {
165
                0x00, 0x00, 0x00,   // colour 0 == black
166
                0x54, 0x54, 0x54,   // dark grey
167
                0xA8, 0xA8, 0xA8,   // light grey
168
                0xFF, 0xFF, 0xFF    // colour 3 == white
169
            } ;
170
            fb_format = "2BPP_PAL888";
171
            memcpy(local_fb_data->palette, fb_2bpp_palette, sizeof(fb_2bpp_palette));
172
            break;
173
        }
174
      case CYG_FB_FORMAT_4BPP_PAL888:
175
        fb_format = "4BPP_PAL888";
176
        memcpy(local_fb_data->palette, cyg_fb_palette_ega, 16 * 3);
177
        break;
178
      case CYG_FB_FORMAT_8BPP_PAL888:
179
        fb_format = "8BPP_PAL888";
180
        memcpy(local_fb_data->palette, cyg_fb_palette_vga, 256 * 3);
181
        break;
182
      case CYG_FB_FORMAT_8BPP_TRUE_332:
183
        fb_format = "8BPP_TRUE_332";
184
        break;
185
      case CYG_FB_FORMAT_16BPP_TRUE_565:
186
        fb_format = "16BPP_TRUE_565";
187
        break;
188
      case CYG_FB_FORMAT_16BPP_TRUE_555:
189
        fb_format = "16BPP_TRUE_555";
190
        break;
191
      case CYG_FB_FORMAT_32BPP_TRUE_0888:
192
        fb_format = "32BPP_TRUE_0888";
193
        break;
194
    }
195
 
196
    diag_sprintf(device_data, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%s",
197
                 SYNTH_FB_PROTOCOL_VERSION,
198
                 fb->fb_driver0,  /* id 0-3   */
199
                 fb->fb_depth,
200
                 fb->fb_flags0 & CYG_FB_FLAGS0_LE,
201
                 fb->fb_width, fb->fb_height,
202
#ifdef CYGHWR_IO_FRAMEBUF_FUNCTIONALITY_VIEWPORT
203
                 fb->fb_viewport_width, fb->fb_viewport_height,
204
#else
205
                 fb->fb_width, fb->fb_height,
206
#endif
207
                 fb->fb_stride,
208
                 fb->fb_driver1,    /* number of pages */
209
                 fb_format);
210
 
211
    local_fb_data->devid = synth_auxiliary_instantiate("devs/framebuf/synth", SYNTH_MAKESTRING(CYGPKG_DEVS_FRAMEBUF_SYNTH),
212
                                                       "framebuf", fb_name, device_data);
213
    if (local_fb_data->devid < 0) {
214
        // The I/O auxiliary should have reported a suitable error.
215
        // Just stick with an in-memory device.
216
        diag_printf("cyg_synth_fb_instantiate(): failed to instantiate device, sticking with in-memory framebuffer\n");
217
        return;
218
    } else {
219
        DEBUG(1, "target synth_auxiliary_instantiate(), host-side framebuf utility running\n");
220
        // At this point the framebuf.tcl script has run, the window has
221
        // been created, the framebuf program has been started, it will
222
        // have created the shared memory region and the two fifos, 
223
        // passed the names back up to framebuf.tcl, and everything should
224
        // be running. This xchgmsg() retrieves the file names from
225
        // framebuf.tcl.
226
        synth_auxiliary_xchgmsg(local_fb_data->devid, SYNTH_FB_INIT, 0, 0, 0, 0, &reply, (unsigned char*)device_data, &len, 512);
227
        // First filename is the shared memory region.
228
        filename    = device_data;
229
        for (ptr = device_data; *ptr != ';'; ptr++)
230
            ;
231
        *ptr++  = '\0';
232
        DEBUG(1, "target :  Opening shared memory region %s\n", filename);
233
        fd = cyg_hal_sys_open(filename, CYG_HAL_SYS_O_RDWR, 0);
234
        if (fd < 0) {
235
            synth_auxiliary_xchgmsg(local_fb_data->devid, SYNTH_FB_ABORT, 0, 0, 0, 0, 0, 0, 0, 0);
236
            return;
237
        }
238
        shared_fb_data = (synth_fb_data*)cyg_hal_sys_mmap(0,
239
                                                          sizeof(synth_fb_data) + (fb->fb_height * fb->fb_stride * fb->fb_driver1),
240
                                                          CYG_HAL_SYS_PROT_READ | CYG_HAL_SYS_PROT_WRITE,
241
                                                          CYG_HAL_SYS_MAP_SHARED,
242
                                                          fd,
243
 
244
            );
245
        if (shared_fb_data <= 0) {
246
            synth_auxiliary_xchgmsg(local_fb_data->devid, SYNTH_FB_ABORT, 0, 0, 0, 0, 0, 0, 0, 0);
247
            cyg_hal_sys_close(fd);
248
            return;
249
        }
250
        DEBUG(1, "target:  mmap()'d shared memory region -> %p\n", shared_fb_data);
251
        shared_fb_data->devid       = local_fb_data->devid;
252
 
253
        // Next filename is the fifo to the framebuf program.
254
        filename = ptr;
255
        for (ptr = device_data; *ptr != ';'; ptr++)
256
            ;
257
        *ptr++ = '\0';
258
        DEBUG(1, "target:  Opening fifo to framebuf %s\n", filename);
259
        shared_fb_data->fifo_to_framebuf = cyg_hal_sys_open(filename, CYG_HAL_SYS_O_WRONLY, 0);
260
        if (shared_fb_data->fifo_to_framebuf < 0) {
261
            synth_auxiliary_xchgmsg(shared_fb_data->devid, SYNTH_FB_ABORT, 0, 0, 0, 0, 0, 0, 0, 0);
262
            cyg_hal_sys_close(fd);
263
            return;
264
        }
265
        // And finally the fifo from the framebuf program.
266
        filename = ptr;
267
        for (ptr = device_data; *ptr != ';'; ptr++)
268
            ;
269
        *ptr = '\0';
270
        DEBUG(1, "target:  Opening fifo from framebuf %s\n", filename);
271
        shared_fb_data->fifo_from_framebuf = cyg_hal_sys_open(filename, CYG_HAL_SYS_O_RDONLY, 0);
272
        if (shared_fb_data->fifo_from_framebuf < 0) {
273
            synth_auxiliary_xchgmsg(shared_fb_data->devid, SYNTH_FB_ABORT, 0, 0, 0, 0, 0, 0, 0, 0);
274
            cyg_hal_sys_close(fd);
275
            cyg_hal_sys_close(shared_fb_data->fifo_to_framebuf);
276
            return;
277
        }
278
 
279
        // We have a shared memory region and the two files. Copy
280
        // all existing fb_data contents (e.g. the palettes) and
281
        // the framebuffer contents to the shared memory region.
282
        // The MUST_BE_ON flag is not set for synthetic target
283
        // framebuffers so there may already be contents.
284
        fb_base  = (cyg_uint8*)fb->fb_base;
285
        fb_base -= (fb->fb_height * fb->fb_stride * shared_fb_data->page_drawable);
286
        memcpy(&(shared_fb_data->palette[0]), &(local_fb_data->palette[0]), 3 * 256);
287
        memcpy(&(shared_fb_data->framebuf[0]), fb_base, fb->fb_height * fb->fb_stride * fb->fb_driver1);
288
        shared_fb_data->connected   = 1;
289
        fb->fb_driver2              = (CYG_ADDRWORD)shared_fb_data;
290
 
291
        fb_base     = (cyg_uint8*)&(shared_fb_data->framebuf[0]);
292
        fb_base    += (fb->fb_height * fb->fb_stride * shared_fb_data->page_drawable);
293
        fb->fb_base = fb_base;
294
        *(cyg_uint8**)fb->fb_driver3    = fb_base;
295
 
296
        DEBUG(1, "target:  Fully instantiated, fb_data %p, blank_on %d, display_on %d\n",
297
              shared_fb_data, shared_fb_data->blank_on, shared_fb_data->display_on);
298
        DEBUG(1, "target:    devid %d, t2h %d, h2t %d\n",
299
                    shared_fb_data->devid, shared_fb_data->fifo_to_framebuf, shared_fb_data->fifo_from_framebuf);
300
        // Finally tell the framebuf program everything is ready.
301
        fb_op(fb, SYNTH_FB_OK);
302
        DEBUG(1, "target: Sent SYNTH_FB_OK\n");
303
    }
304
}
305
 
306
 
307
// Switch on a framebuffer device. This may get called multiple
308
// times, e.g. when switching between different screen modes.
309
// It just involves sending a message to the auxiliary.
310
static int
311
cyg_synth_fb_on(struct cyg_fb* fb)
312
{
313
    synth_fb_data*  fb_data = (synth_fb_data*) fb->fb_driver2;
314
    if (fb_data->connected) {
315
        synth_auxiliary_xchgmsg(fb_data->devid, SYNTH_FB_ON, 0, 0, 0, 0, 0, 0, 0, 0);
316
    }
317
 
318
    return 0;
319
}
320
 
321
static int
322
cyg_synth_fb_off(struct cyg_fb* fb)
323
{
324
    synth_fb_data*  fb_data = (synth_fb_data*) fb->fb_driver2;
325
    if (fb_data->connected) {
326
        synth_auxiliary_xchgmsg(fb_data->devid, SYNTH_FB_OFF, 0, 0, 0, 0, 0, 0, 0, 0);
327
    }
328
    return 0;
329
}
330
 
331
static int
332
cyg_synth_fb_ioctl(struct cyg_fb* fb, cyg_ucount16 key, void* data, size_t* len)
333
{
334
    synth_fb_data*  fb_data = (synth_fb_data*) fb->fb_driver2;
335
    int             result  = ENOSYS;
336
 
337
    switch(key) {
338
      case CYG_FB_IOCTL_VIEWPORT_GET_POSITION:
339
        DEBUG(1, "cyg_synth_fb_ioctl: viewport_get_position\n");
340
        if (fb->fb_flags0 & CYG_FB_FLAGS0_VIEWPORT) {
341
            cyg_fb_ioctl_viewport*  viewport = (cyg_fb_ioctl_viewport*)data;
342
            CYG_ASSERT(*len == sizeof(cyg_fb_ioctl_viewport), "data argument should be a cyg_fb_ioctl_viewport structure");
343
            viewport->fbvp_x    = fb_data->viewport_x;
344
            viewport->fbvp_y    = fb_data->viewport_y;
345
            result  = 0;
346
            DEBUG(1, "                  : current viewport x %d, y %d\n", fb_data->viewport_x, fb_data->viewport_y);
347
        } else {
348
            DEBUG(1, "                  : framebuffer does not support a viewport\n");
349
        }
350
        break;
351
      case CYG_FB_IOCTL_VIEWPORT_SET_POSITION:
352
        DEBUG(1, "cyg_synth_fb_ioctl: viewport_set_position\n");
353
        if (fb->fb_flags0 & CYG_FB_FLAGS0_VIEWPORT) {
354
            cyg_fb_ioctl_viewport*  viewport = (cyg_fb_ioctl_viewport*)data;
355
            CYG_ASSERT(*len == sizeof(cyg_fb_ioctl_viewport), "data argument should be a cyg_fb_ioctl_viewport structure");
356
            CYG_ASSERT(((viewport->fbvp_x + fb->fb_viewport_width) <= fb->fb_width) &&
357
                       ((viewport->fbvp_y + fb->fb_viewport_height) <= fb->fb_height),
358
                       "viewport should be within framebuffer dimensions");
359
            DEBUG(1, "                  : setting viewport from x %d, y %d to x %d, y %d\n",
360
                  fb_data->viewport_x, fb_data->viewport_y, (int) viewport->fbvp_x, (int) viewport->fbvp_y);
361
            if ((fb_data->viewport_x != (int)viewport->fbvp_x) || (fb_data->viewport_y != (int)viewport->fbvp_y)) {
362
                fb_data->viewport_x = (int)viewport->fbvp_x;
363
                fb_data->viewport_y = (int)viewport->fbvp_y;
364
                fb_op(fb, SYNTH_FB_VIEWPORT);
365
            }
366
            result = 0;
367
        } else {
368
            DEBUG(1, "                  : framebuffer does not support a viewport\n");
369
        }
370
        break;
371
      case CYG_FB_IOCTL_PAGE_FLIPPING_GET_PAGES:
372
        DEBUG(1, "cyg_synth_fb_ioctl: page_flipping_get_pages\n");
373
        if (fb->fb_flags0 & CYG_FB_FLAGS0_PAGE_FLIPPING) {
374
            cyg_fb_ioctl_page_flip* page_flip = (cyg_fb_ioctl_page_flip*)data;
375
            CYG_ASSERT(*len == sizeof(cyg_fb_ioctl_page_flip), "data argument should be a cyg_fb_ioctl_page_flip structure");
376
            page_flip->fbpf_number_pages    = fb->fb_driver1;
377
            page_flip->fbpf_visible_page    = fb_data->page_visible;
378
            page_flip->fbpf_drawable_page   = fb_data->page_drawable;
379
            result = 0;
380
            DEBUG(1, "                  : number_pages %d, visible page %d, drawable page %d\n",
381
                  fb->fb_driver1, fb_data->page_visible, fb_data->page_drawable);
382
        } else {
383
            DEBUG(1, "                  : framebuffer does not support page flipping\n");
384
        }
385
        break;
386
      case CYG_FB_IOCTL_PAGE_FLIPPING_SET_PAGES:
387
        DEBUG(1, "cyg_synth_fb_ioctl: page_flipping_set_pages\n");
388
        if (fb->fb_flags0 & CYG_FB_FLAGS0_PAGE_FLIPPING) {
389
            cyg_fb_ioctl_page_flip* page_flip = (cyg_fb_ioctl_page_flip*)data;
390
            cyg_uint8*  fb_base;
391
 
392
            CYG_ASSERT(*len == sizeof(cyg_fb_ioctl_page_flip), "data argument should be a cyg_fb_ioctl_page_flip structure");
393
            CYG_ASSERT((page_flip->fbpf_visible_page  < fb->driver1) &&
394
                       (page_flip->fbpf_drawable_page < fb->driver1),
395
                       "framebuffer does not have that many pages");
396
            DEBUG(1, "                  : drawable page was %d, now %d, visible page was %d, now %d\n",
397
                  fb_data->page_drawable, (int)page_flip->fbpf_drawable_page,
398
                  fb_data->page_visible, (int)page_flip->fbpf_visible_page);
399
            fb_base  = (cyg_uint8*)fb->fb_base;
400
            fb_base -= (fb->fb_height * fb->fb_stride * fb_data->page_drawable);
401
            fb_data->page_drawable          = page_flip->fbpf_drawable_page;
402
            fb_base += (fb->fb_height * fb->fb_stride * fb_data->page_drawable);
403
            fb->fb_base = fb_base;
404
            *(cyg_uint8**)fb->fb_driver3 = fb_base;
405
            if (fb_data->page_visible != (int)page_flip->fbpf_visible_page) {
406
                fb_data->page_visible = (int)page_flip->fbpf_visible_page;
407
                fb_op(fb, SYNTH_FB_PAGE_FLIP);
408
            }
409
            result = 0;
410
        } else {
411
            DEBUG(1, "                  : framebuffer does not support page flipping\n");
412
        }
413
        break;
414
      case CYG_FB_IOCTL_BLANK_GET:
415
        {
416
            cyg_fb_ioctl_blank* blank = (cyg_fb_ioctl_blank*)data;
417
            DEBUG(1, "cyg_synth_fb_ioctl: blank_get, current on state %d\n", fb_data->blank_on);
418
            CYG_ASSERT(*len == sizeof(cyg_fb_ioctl_blank), "data argument should be a cyg_fb_ioctl_blank structure");
419
            blank->fbbl_on  = fb_data->blank_on;
420
            result = 0;
421
        }
422
        break;
423
      case CYG_FB_IOCTL_BLANK_SET:
424
        {
425
            cyg_fb_ioctl_blank* blank = (cyg_fb_ioctl_blank*)data;
426
            CYG_ASSERT(*len == sizeof(cyg_fb_ioctl_blank), "data argument should be a cyg_fb_ioctl_blank structure");
427
            DEBUG(1, "cyg_synth_fb_ioctl: blank_set, on was %d, now %d\n", fb_data->blank_on, blank->fbbl_on);
428
            if (blank->fbbl_on != fb_data->blank_on) {
429
                fb_data->blank_on = blank->fbbl_on;
430
                fb_op(fb, SYNTH_FB_BLANK);
431
            }
432
            result = 0;
433
        }
434
        break;
435
      default:
436
        result  = ENOSYS;
437
        break;
438
    }
439
    return result;
440
}
441
 
442
void
443
cyg_synth_fb_synch(struct cyg_fb* fb, cyg_ucount16 when)
444
{
445
    // FIXME: update synch_x0/y0/x1/y1 once the generic framebuffer
446
    // code actually maintains a bounding box.
447
    fb_op(fb, SYNTH_FB_SYNC);
448
}
449
 
450
#ifdef CYGHWR_DEVS_FRAMEBUF_SYNTH_FUNCTIONALITY_PALETTED
451
// The palette is held in the synth_fb_data structure.
452
static void
453
cyg_synth_fb_read_palette(struct cyg_fb* fb, cyg_ucount32 first, cyg_ucount32 count, void* dest)
454
{
455
    synth_fb_data*  fb_data = (synth_fb_data*) fb->fb_driver2;
456
    CYG_ASSERT(fb->fb_flags0 & CYG_FB_FLAGS0_PALETTE, "reading palette of non-paletted display");
457
    CYG_ASSERT((first + count) <= (0x01 << fb->fb_depth), "palette size exceeded");
458
 
459
    memcpy(dest, &(fb_data->palette[3 * first]), 3 * count);
460
}
461
 
462
static void
463
cyg_synth_fb_write_palette(struct cyg_fb* fb, cyg_ucount32 first, cyg_ucount32 count, const void* source, cyg_ucount16 when)
464
{
465
    synth_fb_data*  fb_data = (synth_fb_data*) fb->fb_driver2;
466
    CYG_ASSERT(fb->fb_flags0 & CYG_FB_FLAGS0_PALETTE, "reading palette of non-paletted display");
467
    CYG_ASSERT((first + count) <= (0x01 << fb->fb_depth), "palette size exceeded");
468
 
469
    DEBUG(1, "write_palette: fb %p, first %d, count %d, source %p\n", fb, first, count, source);
470
    memcpy(&(fb_data->palette[3 * first]), source, 3 * count);
471
    fb_op(fb, SYNTH_FB_WRITE_PALETTE);
472
    CYG_UNUSED_PARAM(cyg_ucount16, when);
473
}
474
#endif
475
 
476
#define LINEAR1(_fn_, _suffix_)  cyg_fb_linear_ ## _fn_ ## _ ## _suffix_
477
#define LINEAR( _fn_, _suffix_)  LINEAR1(_fn_, _suffix_)
478
 
479
#ifdef CYGPKG_DEVS_FRAMEBUF_SYNTH_FB0
480
# ifdef CYGNUM_DEVS_FRAMEBUF_SYNTH_FB0_PAGE_FLIPPING
481
#  define FB0_PAGES CYGNUM_DEVS_FRAMEBUF_SYNTH_FB0_PAGE_FLIPPING
482
# else
483
#  define FB0_PAGES 1
484
#endif
485
 
486
// A default area of memory for the framebuffer, if the auxiliary is not
487
// running.
488
static cyg_uint8            cyg_synth_fb0_default_base[CYG_FB_fb0_HEIGHT * CYG_FB_fb0_STRIDE * FB0_PAGES];
489
 
490
// Pointer to framebuffer memory. This defaults to a statically
491
// allocated memory but will switch to a shared memory region if
492
// the auxiliary is running. It may also change if page flipping
493
// is enabled.
494
cyg_uint8*  cyg_synth_fb0_base  = cyg_synth_fb0_default_base;
495
 
496
// Driver-specific data needed for interacting with the auxiliary.
497
static synth_fb_data    cyg_synth_fb0_data;
498
 
499
CYG_FB_FRAMEBUFFER(CYG_FB_fb0_STRUCT,
500
                   CYG_FB_fb0_DEPTH,
501
                   CYG_FB_fb0_FORMAT,
502
                   CYG_FB_fb0_WIDTH,
503
                   CYG_FB_fb0_HEIGHT,
504
                   CYG_FB_fb0_VIEWPORT_WIDTH,
505
                   CYG_FB_fb0_VIEWPORT_HEIGHT,
506
                   cyg_synth_fb0_default_base,
507
                   CYG_FB_fb0_STRIDE,
508
                   CYG_FB_fb0_FLAGS0,
509
                   CYG_FB_fb0_FLAGS1,
510
                   CYG_FB_fb0_FLAGS2,
511
                   CYG_FB_fb0_FLAGS3,
512
                   (CYG_ADDRWORD) 0,  // id, 0 - 3
513
                   (CYG_ADDRWORD) FB0_PAGES,
514
                   (CYG_ADDRWORD) &cyg_synth_fb0_data,
515
                   (CYG_ADDRWORD) &cyg_synth_fb0_base,
516
                   &cyg_synth_fb_on,
517
                   &cyg_synth_fb_off,
518
                   &cyg_synth_fb_ioctl,
519
                   &cyg_synth_fb_synch,
520
                   &CYG_FB_fb0_READ_PALETTE_FN,
521
                   &CYG_FB_fb0_WRITE_PALETTE_FN,
522
                   &CYG_FB_fb0_MAKE_COLOUR_FN,
523
                   &CYG_FB_fb0_BREAK_COLOUR_FN,
524
                   LINEAR(write_pixel, CYG_FB_fb0_SUFFIX),
525
                   LINEAR(read_pixel, CYG_FB_fb0_SUFFIX),
526
                   LINEAR(write_hline, CYG_FB_fb0_SUFFIX),
527
                   LINEAR(write_vline, CYG_FB_fb0_SUFFIX),
528
                   LINEAR(fill_block, CYG_FB_fb0_SUFFIX),
529
                   LINEAR(write_block, CYG_FB_fb0_SUFFIX),
530
                   LINEAR(read_block, CYG_FB_fb0_SUFFIX),
531
                   LINEAR(move_block, CYG_FB_fb0_SUFFIX),
532
                   0, 0, 0, 0       // Spare0 -> spare3
533
    );
534
 
535
#endif
536
 
537
#ifdef CYGPKG_DEVS_FRAMEBUF_SYNTH_FB1
538
 
539
# ifdef CYGNUM_DEVS_FRAMEBUF_SYNTH_FB1_PAGE_FLIPPING
540
#  define FB1_PAGES CYGNUM_DEVS_FRAMEBUF_SYNTH_FB1_PAGE_FLIPPING
541
# else
542
#  define FB1_PAGES 1
543
#endif
544
static cyg_uint8 cyg_synth_fb1_default_base[CYG_FB_fb1_HEIGHT * CYG_FB_fb1_STRIDE * FB1_PAGES];
545
cyg_uint8*  cyg_synth_fb1_base  = cyg_synth_fb1_default_base;
546
static synth_fb_data    cyg_synth_fb1_data;
547
 
548
CYG_FB_FRAMEBUFFER(CYG_FB_fb1_STRUCT,
549
                   CYG_FB_fb1_DEPTH,
550
                   CYG_FB_fb1_FORMAT,
551
                   CYG_FB_fb1_WIDTH,
552
                   CYG_FB_fb1_HEIGHT,
553
                   CYG_FB_fb1_VIEWPORT_WIDTH,
554
                   CYG_FB_fb1_VIEWPORT_HEIGHT,
555
                   cyg_synth_fb1_default_base,
556
                   CYG_FB_fb1_STRIDE,
557
                   CYG_FB_fb1_FLAGS0,
558
                   CYG_FB_fb1_FLAGS1,
559
                   CYG_FB_fb1_FLAGS2,
560
                   CYG_FB_fb1_FLAGS3,
561
                   (CYG_ADDRWORD) 1,  // id, 0 - 3
562
                   (CYG_ADDRWORD) FB1_PAGES,
563
                   (CYG_ADDRWORD) &cyg_synth_fb1_data,
564
                   (CYG_ADDRWORD) &cyg_synth_fb1_base,
565
                   &cyg_synth_fb_on,
566
                   &cyg_synth_fb_off,
567
                   &cyg_synth_fb_ioctl,
568
                   &cyg_synth_fb_synch,
569
                   &CYG_FB_fb1_READ_PALETTE_FN,
570
                   &CYG_FB_fb1_WRITE_PALETTE_FN,
571
                   &CYG_FB_fb1_MAKE_COLOUR_FN,
572
                   &CYG_FB_fb1_BREAK_COLOUR_FN,
573
                   LINEAR(write_pixel, CYG_FB_fb1_SUFFIX),
574
                   LINEAR(read_pixel, CYG_FB_fb1_SUFFIX),
575
                   LINEAR(write_hline, CYG_FB_fb1_SUFFIX),
576
                   LINEAR(write_vline, CYG_FB_fb1_SUFFIX),
577
                   LINEAR(fill_block, CYG_FB_fb1_SUFFIX),
578
                   LINEAR(write_block, CYG_FB_fb1_SUFFIX),
579
                   LINEAR(read_block, CYG_FB_fb1_SUFFIX),
580
                   LINEAR(move_block, CYG_FB_fb1_SUFFIX),
581
                   0, 0, 0, 0       // Spare0 -> spare3
582
    );
583
 
584
#endif
585
 
586
#ifdef CYGPKG_DEVS_FRAMEBUF_SYNTH_FB2
587
 
588
# ifdef CYGNUM_DEVS_FRAMEBUF_SYNTH_FB2_PAGE_FLIPPING
589
#  define FB2_PAGES CYGNUM_DEVS_FRAMEBUF_SYNTH_FB2_PAGE_FLIPPING
590
# else
591
#  define FB2_PAGES 1
592
#endif
593
static cyg_uint8 cyg_synth_fb2_default_base[CYG_FB_fb2_HEIGHT * CYG_FB_fb2_STRIDE * FB2_PAGES];
594
cyg_uint8*  cyg_synth_fb2_base  = cyg_synth_fb2_default_base;
595
static synth_fb_data    cyg_synth_fb2_data;
596
 
597
CYG_FB_FRAMEBUFFER(CYG_FB_fb2_STRUCT,
598
                   CYG_FB_fb2_DEPTH,
599
                   CYG_FB_fb2_FORMAT,
600
                   CYG_FB_fb2_WIDTH,
601
                   CYG_FB_fb2_HEIGHT,
602
                   CYG_FB_fb2_VIEWPORT_WIDTH,
603
                   CYG_FB_fb2_VIEWPORT_HEIGHT,
604
                   cyg_synth_fb2_default_base,
605
                   CYG_FB_fb2_STRIDE,
606
                   CYG_FB_fb2_FLAGS0,
607
                   CYG_FB_fb2_FLAGS1,
608
                   CYG_FB_fb2_FLAGS2,
609
                   CYG_FB_fb2_FLAGS3,
610
                   (CYG_ADDRWORD) 2,  // id, 0 - 3
611
                   (CYG_ADDRWORD) FB2_PAGES,
612
                   (CYG_ADDRWORD) &cyg_synth_fb2_data,
613
                   (CYG_ADDRWORD) &cyg_synth_fb2_base,
614
                   &cyg_synth_fb_on,
615
                   &cyg_synth_fb_off,
616
                   &cyg_synth_fb_ioctl,
617
                   &cyg_synth_fb_synch,
618
                   &CYG_FB_fb2_READ_PALETTE_FN,
619
                   &CYG_FB_fb2_WRITE_PALETTE_FN,
620
                   &CYG_FB_fb2_MAKE_COLOUR_FN,
621
                   &CYG_FB_fb2_BREAK_COLOUR_FN,
622
                   LINEAR(write_pixel, CYG_FB_fb2_SUFFIX),
623
                   LINEAR(read_pixel, CYG_FB_fb2_SUFFIX),
624
                   LINEAR(write_hline, CYG_FB_fb2_SUFFIX),
625
                   LINEAR(write_vline, CYG_FB_fb2_SUFFIX),
626
                   LINEAR(fill_block, CYG_FB_fb2_SUFFIX),
627
                   LINEAR(write_block, CYG_FB_fb2_SUFFIX),
628
                   LINEAR(read_block, CYG_FB_fb2_SUFFIX),
629
                   LINEAR(move_block, CYG_FB_fb2_SUFFIX),
630
                   0, 0, 0, 0       // Spare0 -> spare3
631
    );
632
 
633
#endif
634
 
635
#ifdef CYGPKG_DEVS_FRAMEBUF_SYNTH_FB3
636
 
637
# ifdef CYGNUM_DEVS_FRAMEBUF_SYNTH_FB3_PAGE_FLIPPING
638
#  define FB3_PAGES CYGNUM_DEVS_FRAMEBUF_SYNTH_FB3_PAGE_FLIPPING
639
# else
640
#  define FB3_PAGES 1
641
#endif
642
static cyg_uint8 cyg_synth_fb3_default_base[CYG_FB_fb3_HEIGHT * CYG_FB_fb3_STRIDE * FB3_PAGES];
643
cyg_uint8*  cyg_synth_fb3_base  = cyg_synth_fb3_default_base;
644
static synth_fb_data    cyg_synth_fb3_data;
645
 
646
CYG_FB_FRAMEBUFFER(CYG_FB_fb3_STRUCT,
647
                   CYG_FB_fb3_DEPTH,
648
                   CYG_FB_fb3_FORMAT,
649
                   CYG_FB_fb3_WIDTH,
650
                   CYG_FB_fb3_HEIGHT,
651
                   CYG_FB_fb3_VIEWPORT_WIDTH,
652
                   CYG_FB_fb3_VIEWPORT_HEIGHT,
653
                   cyg_synth_fb3_default_base,
654
                   CYG_FB_fb3_STRIDE,
655
                   CYG_FB_fb3_FLAGS0,
656
                   CYG_FB_fb3_FLAGS1,
657
                   CYG_FB_fb3_FLAGS2,
658
                   CYG_FB_fb3_FLAGS3,
659
                   (CYG_ADDRWORD) 3,  // id, 0 - 3
660
                   (CYG_ADDRWORD) FB3_PAGES,
661
                   (CYG_ADDRWORD) &cyg_synth_fb3_data,
662
                   (CYG_ADDRWORD) &cyg_synth_fb3_base,
663
                   &cyg_synth_fb_on,
664
                   &cyg_synth_fb_off,
665
                   &cyg_synth_fb_ioctl,
666
                   &cyg_synth_fb_synch,
667
                   &CYG_FB_fb3_READ_PALETTE_FN,
668
                   &CYG_FB_fb3_WRITE_PALETTE_FN,
669
                   &CYG_FB_fb3_MAKE_COLOUR_FN,
670
                   &CYG_FB_fb3_BREAK_COLOUR_FN,
671
                   LINEAR(write_pixel, CYG_FB_fb3_SUFFIX),
672
                   LINEAR(read_pixel, CYG_FB_fb3_SUFFIX),
673
                   LINEAR(write_hline, CYG_FB_fb3_SUFFIX),
674
                   LINEAR(write_vline, CYG_FB_fb3_SUFFIX),
675
                   LINEAR(fill_block, CYG_FB_fb3_SUFFIX),
676
                   LINEAR(write_block, CYG_FB_fb3_SUFFIX),
677
                   LINEAR(read_block, CYG_FB_fb3_SUFFIX),
678
                   LINEAR(move_block, CYG_FB_fb3_SUFFIX),
679
                   0, 0, 0, 0       // Spare0 -> spare3
680
    );
681
 
682
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.