Rev 2071 | Rev 2510 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2071 | Rev 2089 | ||
---|---|---|---|
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 <typedefs.h> |
- | |
41 | #include <func.h> |
40 | #include <func.h> |
42 | #include <align.h> |
41 | #include <align.h> |
43 | #include <print.h> |
42 | #include <print.h> |
44 | 43 | ||
45 | #define FFB_REG_24BPP 7 |
44 | #define FFB_REG_24BPP 7 |
46 | 45 | ||
47 | scr_type_t scr_type = SCR_UNKNOWN; |
46 | scr_type_t scr_type = SCR_UNKNOWN; |
48 | 47 | ||
49 | /** Initialize screen. |
48 | /** Initialize screen. |
50 | * |
49 | * |
51 | * Traverse OpenFirmware device tree in order to find necessary |
50 | * Traverse OpenFirmware device tree in order to find necessary |
52 | * info about the screen device. |
51 | * info about the screen device. |
53 | * |
52 | * |
54 | * @param node Screen device node. |
53 | * @param node Screen device node. |
55 | */ |
54 | */ |
56 | void scr_init(ofw_tree_node_t *node) |
55 | void scr_init(ofw_tree_node_t *node) |
57 | { |
56 | { |
58 | ofw_tree_property_t *prop; |
57 | ofw_tree_property_t *prop; |
59 | const char *name; |
58 | const char *name; |
60 | 59 | ||
61 | name = ofw_tree_node_name(node); |
60 | name = ofw_tree_node_name(node); |
62 | 61 | ||
63 | if (strcmp(name, "SUNW,m64B") == 0) |
62 | if (strcmp(name, "SUNW,m64B") == 0) |
64 | scr_type = SCR_ATYFB; |
63 | scr_type = SCR_ATYFB; |
65 | else if (strcmp(name, "SUNW,ffb") == 0) |
64 | else if (strcmp(name, "SUNW,ffb") == 0) |
66 | scr_type = SCR_FFB; |
65 | scr_type = SCR_FFB; |
67 | 66 | ||
68 | if (scr_type == SCR_UNKNOWN) { |
67 | if (scr_type == SCR_UNKNOWN) { |
69 | printf("Unknown keyboard device.\n"); |
68 | printf("Unknown keyboard device.\n"); |
70 | return; |
69 | return; |
71 | } |
70 | } |
72 | 71 | ||
73 | uintptr_t fb_addr; |
72 | uintptr_t fb_addr; |
74 | uint32_t fb_width = 0; |
73 | uint32_t fb_width = 0; |
75 | uint32_t fb_height = 0; |
74 | uint32_t fb_height = 0; |
76 | uint32_t fb_depth = 0; |
75 | uint32_t fb_depth = 0; |
77 | uint32_t fb_linebytes = 0; |
76 | uint32_t fb_linebytes = 0; |
78 | uint32_t fb_scanline = 0; |
77 | uint32_t fb_scanline = 0; |
79 | unsigned int visual; |
78 | unsigned int visual; |
80 | 79 | ||
81 | prop = ofw_tree_getprop(node, "width"); |
80 | prop = ofw_tree_getprop(node, "width"); |
82 | if (prop && prop->value) |
81 | if (prop && prop->value) |
83 | fb_width = *((uint32_t *) prop->value); |
82 | fb_width = *((uint32_t *) prop->value); |
84 | 83 | ||
85 | prop = ofw_tree_getprop(node, "height"); |
84 | prop = ofw_tree_getprop(node, "height"); |
86 | if (prop && prop->value) |
85 | if (prop && prop->value) |
87 | fb_height = *((uint32_t *) prop->value); |
86 | fb_height = *((uint32_t *) prop->value); |
88 | 87 | ||
89 | prop = ofw_tree_getprop(node, "depth"); |
88 | prop = ofw_tree_getprop(node, "depth"); |
90 | if (prop && prop->value) |
89 | if (prop && prop->value) |
91 | fb_depth = *((uint32_t *) prop->value); |
90 | fb_depth = *((uint32_t *) prop->value); |
92 | 91 | ||
93 | prop = ofw_tree_getprop(node, "linebytes"); |
92 | prop = ofw_tree_getprop(node, "linebytes"); |
94 | if (prop && prop->value) |
93 | if (prop && prop->value) |
95 | fb_linebytes = *((uint32_t *) prop->value); |
94 | fb_linebytes = *((uint32_t *) prop->value); |
96 | 95 | ||
97 | prop = ofw_tree_getprop(node, "reg"); |
96 | prop = ofw_tree_getprop(node, "reg"); |
98 | if (!prop) |
97 | if (!prop) |
99 | panic("Can't find \"reg\" property.\n"); |
98 | panic("Can't find \"reg\" property.\n"); |
100 | 99 | ||
101 | switch (scr_type) { |
100 | switch (scr_type) { |
102 | case SCR_ATYFB: |
101 | case SCR_ATYFB: |
103 | if (prop->size / sizeof(ofw_pci_reg_t) < 2) { |
102 | if (prop->size / sizeof(ofw_pci_reg_t) < 2) { |
104 | printf("Too few screen registers.\n"); |
103 | printf("Too few screen registers.\n"); |
105 | return; |
104 | return; |
106 | } |
105 | } |
107 | 106 | ||
108 | ofw_pci_reg_t *fb_reg = &((ofw_pci_reg_t *) prop->value)[1]; |
107 | ofw_pci_reg_t *fb_reg = &((ofw_pci_reg_t *) prop->value)[1]; |
109 | ofw_pci_reg_t abs_reg; |
108 | ofw_pci_reg_t abs_reg; |
110 | 109 | ||
111 | if (!ofw_pci_reg_absolutize(node, fb_reg, &abs_reg)) { |
110 | if (!ofw_pci_reg_absolutize(node, fb_reg, &abs_reg)) { |
112 | printf("Failed to absolutize fb register.\n"); |
111 | printf("Failed to absolutize fb register.\n"); |
113 | return; |
112 | return; |
114 | } |
113 | } |
115 | 114 | ||
116 | if (!ofw_pci_apply_ranges(node->parent, &abs_reg , &fb_addr)) { |
115 | if (!ofw_pci_apply_ranges(node->parent, &abs_reg , &fb_addr)) { |
117 | printf("Failed to determine screen address.\n"); |
116 | printf("Failed to determine screen address.\n"); |
118 | return; |
117 | return; |
119 | } |
118 | } |
120 | 119 | ||
121 | switch (fb_depth) { |
120 | switch (fb_depth) { |
122 | case 8: |
121 | case 8: |
123 | fb_scanline = fb_linebytes * (fb_depth >> 3); |
122 | fb_scanline = fb_linebytes * (fb_depth >> 3); |
124 | visual = VISUAL_INDIRECT_8; |
123 | visual = VISUAL_INDIRECT_8; |
125 | break; |
124 | break; |
126 | case 16: |
125 | case 16: |
127 | fb_scanline = fb_linebytes * (fb_depth >> 3); |
126 | fb_scanline = fb_linebytes * (fb_depth >> 3); |
128 | visual = VISUAL_RGB_5_6_5; |
127 | visual = VISUAL_RGB_5_6_5; |
129 | break; |
128 | break; |
130 | case 24: |
129 | case 24: |
131 | fb_scanline = fb_linebytes * 4; |
130 | fb_scanline = fb_linebytes * 4; |
132 | visual = VISUAL_RGB_8_8_8_0; |
131 | visual = VISUAL_RGB_8_8_8_0; |
133 | break; |
132 | break; |
134 | case 32: |
133 | case 32: |
135 | fb_scanline = fb_linebytes * (fb_depth >> 3); |
134 | fb_scanline = fb_linebytes * (fb_depth >> 3); |
136 | visual = VISUAL_RGB_0_8_8_8; |
135 | visual = VISUAL_RGB_0_8_8_8; |
137 | break; |
136 | break; |
138 | default: |
137 | default: |
139 | printf("Unsupported bits per pixel.\n"); |
138 | printf("Unsupported bits per pixel.\n"); |
140 | return; |
139 | return; |
141 | } |
140 | } |
142 | 141 | ||
143 | break; |
142 | break; |
144 | case SCR_FFB: |
143 | case SCR_FFB: |
145 | fb_scanline = 8192; |
144 | fb_scanline = 8192; |
146 | visual = VISUAL_BGR_0_8_8_8; |
145 | visual = VISUAL_BGR_0_8_8_8; |
147 | 146 | ||
148 | ofw_upa_reg_t *reg = &((ofw_upa_reg_t *) prop->value)[FFB_REG_24BPP]; |
147 | ofw_upa_reg_t *reg = &((ofw_upa_reg_t *) prop->value)[FFB_REG_24BPP]; |
149 | if (!ofw_upa_apply_ranges(node->parent, reg, &fb_addr)) { |
148 | if (!ofw_upa_apply_ranges(node->parent, reg, &fb_addr)) { |
150 | printf("Failed to determine screen address.\n"); |
149 | printf("Failed to determine screen address.\n"); |
151 | return; |
150 | return; |
152 | } |
151 | } |
153 | 152 | ||
154 | break; |
153 | break; |
155 | default: |
154 | default: |
156 | panic("Unexpected type.\n"); |
155 | panic("Unexpected type.\n"); |
157 | } |
156 | } |
158 | 157 | ||
159 | fb_init(fb_addr, fb_width, fb_height, fb_scanline, visual); |
158 | fb_init(fb_addr, fb_width, fb_height, fb_scanline, visual); |
160 | } |
159 | } |
161 | 160 | ||
162 | /** @} |
161 | /** @} |
163 | */ |
162 | */ |
164 | 163 |