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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [mw/] [src/] [nanox/] [clientfb.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * Microwindows direct client-side framebuffer mapping routines
3
 *
4
 * Copyright (c) 2001 by Greg Haerr <greg@censoft.com>
5
 */
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <unistd.h>
9
#include <fcntl.h>
10
#include <sys/ioctl.h>
11
#include <sys/mman.h>
12
#include <asm/page.h>           /* For definition of PAGE_SIZE */
13
#include <linux/fb.h>
14
#include "nano-X.h"
15
 
16
/* globals: assumes use of non-shared libnano-X.a for now*/
17
static int              frame_fd;       /* client side framebuffer fd*/
18
static unsigned char *  frame_map;      /* client side framebuffer mmap'd addr*/
19
static int              frame_len;      /* client side framebuffer length*/
20
static unsigned char *  physpixels;     /* start address of pixels*/
21
static GR_SCREEN_INFO   sinfo;
22
 
23
/* map framebuffer address into client memory*/
24
unsigned char *
25
GrOpenClientFramebuffer(void)
26
{
27
        int     frame_offset;
28
        char *  fbdev;
29
        struct fb_fix_screeninfo finfo;
30
 
31
        /* if already open, return fb address*/
32
        if (physpixels)
33
                return physpixels;
34
 
35
        /*
36
         * For now, we'll just check whether or not Microwindows
37
         * is running its framebuffer driver to determine whether
38
         * to allow direct client-side framebuffer mapping.  In
39
         * the future, we could allow direct mapping for Microwindows
40
         * running on top of X, and finding the address of the
41
         * window within the Microwindows X window.
42
         */
43
        GrGetScreenInfo(&sinfo);
44
        if (!sinfo.fbdriver)
45
                return NULL;
46
 
47
        /*
48
         * Try to open the framebuffer directly.
49
         */
50
        if (!(fbdev = getenv("FRAMEBUFFER")))
51
                fbdev = "/dev/fb0";
52
        frame_fd = open(fbdev, O_RDWR);
53
        if (frame_fd < 0) {
54
                printf("Can't open framebuffer device\n");
55
                return NULL;
56
        }
57
 
58
        /* Get the type of video hardware */
59
        if (ioctl(frame_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) {
60
                printf("Couldn't get fb hardware info\n");
61
                goto err;
62
        }
63
 
64
        // FIXME remove when mwin returns fb or X
65
        switch (finfo.visual) {
66
                case FB_VISUAL_TRUECOLOR:
67
                case FB_VISUAL_PSEUDOCOLOR:
68
                case FB_VISUAL_STATIC_PSEUDOCOLOR:
69
                case FB_VISUAL_DIRECTCOLOR:
70
                        break;
71
                default:
72
                        printf("Unsupported fb color map\n");
73
                        goto err;
74
        }
75
 
76
        /* Memory map the device, compensating for buggy PPC mmap() */
77
        frame_offset = (((long)finfo.smem_start) -
78
                (((long)finfo.smem_start)&~(PAGE_SIZE-1)));
79
        frame_len = finfo.smem_len + frame_offset;
80
        frame_map = (unsigned char *)mmap(NULL, frame_len, PROT_READ|PROT_WRITE,
81
                MAP_SHARED, frame_fd, 0);
82 716 simons
 
83 673 markom
        if (frame_map == (unsigned char *)-1) {
84
                printf("Unable to memory map the video hardware\n");
85
                frame_map = NULL;
86
                goto err;
87
        }
88
        physpixels = frame_map + frame_offset;
89
        return physpixels;
90
 
91
err:
92
        close(frame_fd);
93
        return NULL;
94
}
95
 
96
void
97
GrCloseClientFramebuffer(void)
98
{
99
        if (frame_fd >= 0) {
100
                if (frame_map) {
101
                        munmap(frame_map, frame_len);
102
                        frame_map = NULL;
103
                        physpixels = NULL;
104
                }
105
                close(frame_fd);
106
                frame_fd = -1;
107
 
108
                /* reset sinfo struct*/
109
                sinfo.cols = 0;
110
        }
111
}
112
 
113
/*
114
 * Return client-side mapped framebuffer info for
115
 * passed window.  If not running framebuffer, the
116
 * physpixel and winpixel members will be NULL, and
117
 * everything else correct.
118
 */
119
void
120
GrGetWindowFBInfo(GR_WINDOW_ID wid, GR_WINDOW_FB_INFO *fbinfo)
121
{
122
        int                     physoffset;
123
        GR_WINDOW_INFO          info;
124
        static int              last_portrait = -1;
125
 
126
        /* re-get screen info on auto-portrait switch*/
127
        if (sinfo.cols == 0 || last_portrait != sinfo.portrait)
128
                GrGetScreenInfo(&sinfo);
129
        last_portrait = sinfo.portrait;
130
 
131
        /* must get window position anew each time*/
132
        GrGetWindowInfo(wid, &info);
133
 
134
        fbinfo->bpp = sinfo.bpp;
135
        fbinfo->bytespp = (sinfo.bpp+7)/8;
136
        fbinfo->pixtype = sinfo.pixtype;
137
        fbinfo->x = info.x;
138
        fbinfo->y = info.y;
139
        fbinfo->portrait_mode = sinfo.portrait;
140
 
141
        switch (fbinfo->portrait_mode) {
142
        case MWPORTRAIT_RIGHT:
143
        case MWPORTRAIT_LEFT:
144
                /*
145
                 * We reverse coords since Microwindows reports
146
                 * back the virtual xres/yres, and we want
147
                 * the physical xres/yres.
148
                 */
149
                // FIXME return xres and xvirtres in SCREENINFO?
150
                fbinfo->xres = sinfo.rows;      /* reverse coords*/
151
                fbinfo->yres = sinfo.cols;
152
                break;
153
        default:
154
                fbinfo->xres = sinfo.cols;
155
                fbinfo->yres = sinfo.rows;
156
                break;
157
        }
158
        fbinfo->xvirtres = sinfo.cols;
159
        fbinfo->yvirtres = sinfo.rows;
160
        fbinfo->pitch = fbinfo->xres * fbinfo->bytespp;
161
 
162
        /* fill in memory mapped addresses*/
163
        fbinfo->physpixels = physpixels;
164
 
165
        /* winpixels only valid for non-portrait modes*/
166
        physoffset = info.y*fbinfo->pitch + info.x*fbinfo->bytespp;
167
        fbinfo->winpixels = physpixels? (physpixels + physoffset): NULL;
168
}

powered by: WebSVN 2.1.0

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