Subversion Repositories HelenOS

Rev

Rev 2927 | Rev 4337 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2927 Rev 3674
1
/*
1
/*
2
 * Copyright (c) 2006 Jakub Jermar
2
 * Copyright (c) 2006 Jakub Jermar
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup sparc64
29
/** @addtogroup sparc64
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <arch/drivers/scr.h>
35
#include <arch/drivers/scr.h>
36
#include <genarch/ofw/ofw_tree.h>
36
#include <genarch/ofw/ofw_tree.h>
37
#include <genarch/fb/fb.h>
37
#include <genarch/fb/fb.h>
38
#include <genarch/fb/visuals.h>
38
#include <genarch/fb/visuals.h>
39
#include <arch/types.h>
39
#include <arch/types.h>
40
#include <func.h>
40
#include <func.h>
41
#include <align.h>
41
#include <align.h>
42
#include <print.h>
42
#include <print.h>
43
 
43
 
44
#define FFB_REG_24BPP   7
44
#define FFB_REG_24BPP   7
45
 
45
 
46
scr_type_t scr_type = SCR_UNKNOWN;
46
scr_type_t scr_type = SCR_UNKNOWN;
47
 
47
 
48
/** Initialize screen.
48
/** Initialize screen.
49
 *
49
 *
50
 * Traverse OpenFirmware device tree in order to find necessary
50
 * Traverse OpenFirmware device tree in order to find necessary
51
 * info about the screen device.
51
 * info about the screen device.
52
 *
52
 *
53
 * @param node Screen device node.
53
 * @param node Screen device node.
54
 */
54
 */
55
void scr_init(ofw_tree_node_t *node)
55
void scr_init(ofw_tree_node_t *node)
56
{
56
{
57
    ofw_tree_property_t *prop;
57
    ofw_tree_property_t *prop;
-
 
58
    ofw_pci_reg_t *pci_reg;
-
 
59
    ofw_pci_reg_t pci_abs_reg;
-
 
60
    ofw_upa_reg_t *upa_reg;
-
 
61
    ofw_sbus_reg_t *sbus_reg;
58
    const char *name;
62
    const char *name;
59
   
63
   
60
    name = ofw_tree_node_name(node);
64
    name = ofw_tree_node_name(node);
61
   
65
   
62
    if (strcmp(name, "SUNW,m64B") == 0)
66
    if (strcmp(name, "SUNW,m64B") == 0)
63
        scr_type = SCR_ATYFB;
67
        scr_type = SCR_ATYFB;
-
 
68
    else if (strcmp(name, "SUNW,XVR-100") == 0)
-
 
69
        scr_type = SCR_XVR;
64
    else if (strcmp(name, "SUNW,ffb") == 0)
70
    else if (strcmp(name, "SUNW,ffb") == 0)
65
        scr_type = SCR_FFB;
71
        scr_type = SCR_FFB;
66
    else if (strcmp(name, "cgsix") == 0)
72
    else if (strcmp(name, "cgsix") == 0)
67
        scr_type = SCR_CGSIX;
73
        scr_type = SCR_CGSIX;
68
   
74
   
69
    if (scr_type == SCR_UNKNOWN) {
75
    if (scr_type == SCR_UNKNOWN) {
70
        printf("Unknown keyboard device.\n");
76
        printf("Unknown screen device.\n");
71
        return;
77
        return;
72
    }
78
    }
73
   
79
   
74
    uintptr_t fb_addr;
80
    uintptr_t fb_addr;
75
    uint32_t fb_width = 0;
81
    uint32_t fb_width = 0;
76
    uint32_t fb_height = 0;
82
    uint32_t fb_height = 0;
77
    uint32_t fb_depth = 0;
83
    uint32_t fb_depth = 0;
78
    uint32_t fb_linebytes = 0;
84
    uint32_t fb_linebytes = 0;
79
    uint32_t fb_scanline = 0;
85
    uint32_t fb_scanline = 0;
80
    unsigned int visual;
86
    unsigned int visual;
81
 
87
 
82
    prop = ofw_tree_getprop(node, "width");
88
    prop = ofw_tree_getprop(node, "width");
83
    if (prop && prop->value)
89
    if (prop && prop->value)
84
        fb_width = *((uint32_t *) prop->value);
90
        fb_width = *((uint32_t *) prop->value);
85
 
91
 
86
    prop = ofw_tree_getprop(node, "height");
92
    prop = ofw_tree_getprop(node, "height");
87
    if (prop && prop->value)
93
    if (prop && prop->value)
88
        fb_height = *((uint32_t *) prop->value);
94
        fb_height = *((uint32_t *) prop->value);
89
 
95
 
90
    prop = ofw_tree_getprop(node, "depth");
96
    prop = ofw_tree_getprop(node, "depth");
91
    if (prop && prop->value)
97
    if (prop && prop->value)
92
        fb_depth = *((uint32_t *) prop->value);
98
        fb_depth = *((uint32_t *) prop->value);
93
 
99
 
94
    prop = ofw_tree_getprop(node, "linebytes");
100
    prop = ofw_tree_getprop(node, "linebytes");
95
    if (prop && prop->value)
101
    if (prop && prop->value)
96
        fb_linebytes = *((uint32_t *) prop->value);
102
        fb_linebytes = *((uint32_t *) prop->value);
97
 
103
 
98
    prop = ofw_tree_getprop(node, "reg");
104
    prop = ofw_tree_getprop(node, "reg");
99
    if (!prop)
105
    if (!prop)
100
        panic("Can't find \"reg\" property.\n");
106
        panic("Can't find \"reg\" property.\n");
101
 
107
 
102
    switch (scr_type) {
108
    switch (scr_type) {
103
    case SCR_ATYFB:
109
    case SCR_ATYFB:
104
        if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
110
        if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
105
            printf("Too few screen registers.\n");
111
            printf("Too few screen registers.\n");
106
            return;
112
            return;
107
        }
113
        }
108
   
114
   
109
        ofw_pci_reg_t *fb_reg = &((ofw_pci_reg_t *) prop->value)[1];
115
        pci_reg = &((ofw_pci_reg_t *) prop->value)[1];
110
        ofw_pci_reg_t abs_reg;
-
 
111
       
116
       
112
        if (!ofw_pci_reg_absolutize(node, fb_reg, &abs_reg)) {
117
        if (!ofw_pci_reg_absolutize(node, pci_reg, &pci_abs_reg)) {
113
            printf("Failed to absolutize fb register.\n");
118
            printf("Failed to absolutize fb register.\n");
114
            return;
119
            return;
115
        }
120
        }
116
   
121
   
117
        if (!ofw_pci_apply_ranges(node->parent, &abs_reg , &fb_addr)) {
122
        if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
-
 
123
            &fb_addr)) {
118
            printf("Failed to determine screen address.\n");
124
            printf("Failed to determine screen address.\n");
119
            return;
125
            return;
120
        }
126
        }
121
       
127
       
122
        switch (fb_depth) {
128
        switch (fb_depth) {
123
        case 8:
129
        case 8:
124
            fb_scanline = fb_linebytes * (fb_depth >> 3);
130
            fb_scanline = fb_linebytes * (fb_depth >> 3);
125
            visual = VISUAL_INDIRECT_8;
131
            visual = VISUAL_INDIRECT_8;
126
            break;
132
            break;
127
        case 16:
133
        case 16:
128
            fb_scanline = fb_linebytes * (fb_depth >> 3);
134
            fb_scanline = fb_linebytes * (fb_depth >> 3);
129
            visual = VISUAL_RGB_5_6_5;
135
            visual = VISUAL_RGB_5_6_5;
130
            break;
136
            break;
131
        case 24:
137
        case 24:
132
            fb_scanline = fb_linebytes * 4;
138
            fb_scanline = fb_linebytes * 4;
133
            visual = VISUAL_RGB_8_8_8_0;
139
            visual = VISUAL_RGB_8_8_8_0;
134
            break;
140
            break;
135
        case 32:
141
        case 32:
136
            fb_scanline = fb_linebytes * (fb_depth >> 3);
142
            fb_scanline = fb_linebytes * (fb_depth >> 3);
137
            visual = VISUAL_RGB_0_8_8_8;
143
            visual = VISUAL_RGB_0_8_8_8;
138
            break;
144
            break;
139
        default:
145
        default:
140
            printf("Unsupported bits per pixel.\n");
146
            printf("Unsupported bits per pixel.\n");
141
            return;
147
            return;
142
        }
148
        }
143
       
149
       
144
        break;
150
        break;
-
 
151
    case SCR_XVR:
-
 
152
        if (prop->size / sizeof(ofw_pci_reg_t) < 2) {
-
 
153
            printf("Too few screen registers.\n");
-
 
154
            return;
-
 
155
        }
-
 
156
   
-
 
157
        pci_reg = &((ofw_pci_reg_t *) prop->value)[1];
-
 
158
       
-
 
159
        if (!ofw_pci_reg_absolutize(node, pci_reg, &pci_abs_reg)) {
-
 
160
            printf("Failed to absolutize fb register.\n");
-
 
161
            return;
-
 
162
        }
-
 
163
   
-
 
164
        if (!ofw_pci_apply_ranges(node->parent, &pci_abs_reg,
-
 
165
            &fb_addr)) {
-
 
166
            printf("Failed to determine screen address.\n");
-
 
167
            return;
-
 
168
        }
-
 
169
 
-
 
170
        switch (fb_depth) {
-
 
171
        case 8:
-
 
172
            fb_scanline = fb_linebytes * (fb_depth >> 3);
-
 
173
            visual = VISUAL_SB1500_PALETTE;
-
 
174
            break;
-
 
175
        case 16:
-
 
176
            fb_scanline = fb_linebytes * (fb_depth >> 3);
-
 
177
            visual = VISUAL_RGB_5_6_5;
-
 
178
            break;
-
 
179
        case 24:
-
 
180
            fb_scanline = fb_linebytes * 4;
-
 
181
            visual = VISUAL_RGB_8_8_8_0;
-
 
182
            break;
-
 
183
        case 32:
-
 
184
            fb_scanline = fb_linebytes * (fb_depth >> 3);
-
 
185
            visual = VISUAL_RGB_0_8_8_8;
-
 
186
            break;
-
 
187
        default:
-
 
188
            printf("Unsupported bits per pixel.\n");
-
 
189
            return;
-
 
190
        }
-
 
191
       
-
 
192
        break;
145
    case SCR_FFB:  
193
    case SCR_FFB:  
146
        fb_scanline = 8192;
194
        fb_scanline = 8192;
147
        visual = VISUAL_BGR_0_8_8_8;
195
        visual = VISUAL_BGR_0_8_8_8;
148
 
196
 
149
        ofw_upa_reg_t *reg = &((ofw_upa_reg_t *) prop->value)[FFB_REG_24BPP];
197
        upa_reg = &((ofw_upa_reg_t *) prop->value)[FFB_REG_24BPP];
150
        if (!ofw_upa_apply_ranges(node->parent, reg, &fb_addr)) {
198
        if (!ofw_upa_apply_ranges(node->parent, upa_reg, &fb_addr)) {
151
            printf("Failed to determine screen address.\n");
199
            printf("Failed to determine screen address.\n");
152
            return;
200
            return;
153
        }
201
        }
154
 
202
 
155
        break;
203
        break;
156
    case SCR_CGSIX:
204
    case SCR_CGSIX:
157
        switch (fb_depth) {
205
        switch (fb_depth) {
158
        case 8:
206
        case 8:
159
            fb_scanline = fb_linebytes;
207
            fb_scanline = fb_linebytes;
160
            visual = VISUAL_INDIRECT_8;
208
            visual = VISUAL_INDIRECT_8;
161
            break;
209
            break;
162
        default:
210
        default:
163
            printf("Not implemented.\n");
211
            printf("Not implemented.\n");
164
            return;
212
            return;
165
        }
213
        }
166
       
214
       
167
        ofw_sbus_reg_t *cg6_reg = &((ofw_sbus_reg_t *) prop->value)[0];
215
        sbus_reg = &((ofw_sbus_reg_t *) prop->value)[0];
168
        if (!ofw_sbus_apply_ranges(node->parent, cg6_reg, &fb_addr)) {
216
        if (!ofw_sbus_apply_ranges(node->parent, sbus_reg, &fb_addr)) {
169
            printf("Failed to determine screen address.\n");
217
            printf("Failed to determine screen address.\n");
170
            return;
218
            return;
171
        }
219
        }
172
   
220
   
173
        break;
221
        break;
174
    default:
222
    default:
175
        panic("Unexpected type.\n");
223
        panic("Unexpected type.\n");
176
    }
224
    }
177
 
225
 
-
 
226
    fb_properties_t props = {
-
 
227
        .addr = fb_addr,
-
 
228
        .offset = 0,
-
 
229
        .x = fb_width,
-
 
230
        .y = fb_height,
178
    fb_init(fb_addr, fb_width, fb_height, fb_scanline, visual);
231
        .scan = fb_scanline,
-
 
232
        .visual = visual,
-
 
233
    };
-
 
234
    fb_init(&props);
179
}
235
}
180
 
236
 
181
/** @}
237
/** @}
182
 */
238
 */
183
 
239