]>
Commit | Line | Data |
---|---|---|
ffd39257 BS |
1 | /* |
2 | * QEMU SM501 Device | |
3 | * | |
4 | * Copyright (c) 2008 Shin-ichiro KAWASAKI | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
23 | */ | |
24 | ||
47df5154 | 25 | #include "qemu/osdep.h" |
e2ee8476 | 26 | #include "qemu/cutils.h" |
da34e65c | 27 | #include "qapi/error.h" |
4771d756 PB |
28 | #include "qemu-common.h" |
29 | #include "cpu.h" | |
83c9f4ca | 30 | #include "hw/hw.h" |
0d09e41a | 31 | #include "hw/char/serial.h" |
28ecbaee | 32 | #include "ui/console.h" |
bd2be150 | 33 | #include "hw/devices.h" |
83c9f4ca | 34 | #include "hw/sysbus.h" |
efae2784 | 35 | #include "hw/pci/pci.h" |
1de7afc9 | 36 | #include "qemu/range.h" |
28ecbaee | 37 | #include "ui/pixel_ops.h" |
2c17449b | 38 | #include "exec/address-spaces.h" |
ffd39257 BS |
39 | |
40 | /* | |
604be200 | 41 | * Status: 2010/05/07 |
ffd39257 | 42 | * - Minimum implementation for Linux console : mmio regs and CRT layer. |
64f1603b | 43 | * - 2D graphics acceleration partially supported : only fill rectangle. |
ffd39257 BS |
44 | * |
45 | * TODO: | |
46 | * - Panel support | |
ffd39257 BS |
47 | * - Touch panel support |
48 | * - USB support | |
49 | * - UART support | |
604be200 | 50 | * - More 2D graphics engine support |
ffd39257 BS |
51 | * - Performance tuning |
52 | */ | |
53 | ||
64f1603b BZ |
54 | /*#define DEBUG_SM501*/ |
55 | /*#define DEBUG_BITBLT*/ | |
ffd39257 BS |
56 | |
57 | #ifdef DEBUG_SM501 | |
001faf32 | 58 | #define SM501_DPRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__) |
ffd39257 | 59 | #else |
64f1603b | 60 | #define SM501_DPRINTF(fmt, ...) do {} while (0) |
ffd39257 BS |
61 | #endif |
62 | ||
ffd39257 | 63 | #define MMIO_BASE_OFFSET 0x3e00000 |
ca8a1104 | 64 | #define MMIO_SIZE 0x200000 |
ffd39257 BS |
65 | |
66 | /* SM501 register definitions taken from "linux/include/linux/sm501-regs.h" */ | |
67 | ||
68 | /* System Configuration area */ | |
69 | /* System config base */ | |
64f1603b | 70 | #define SM501_SYS_CONFIG (0x000000) |
ffd39257 BS |
71 | |
72 | /* config 1 */ | |
64f1603b | 73 | #define SM501_SYSTEM_CONTROL (0x000000) |
ffd39257 | 74 | |
64f1603b BZ |
75 | #define SM501_SYSCTRL_PANEL_TRISTATE (1 << 0) |
76 | #define SM501_SYSCTRL_MEM_TRISTATE (1 << 1) | |
77 | #define SM501_SYSCTRL_CRT_TRISTATE (1 << 2) | |
ffd39257 | 78 | |
64f1603b BZ |
79 | #define SM501_SYSCTRL_PCI_SLAVE_BURST_MASK (3 << 4) |
80 | #define SM501_SYSCTRL_PCI_SLAVE_BURST_1 (0 << 4) | |
81 | #define SM501_SYSCTRL_PCI_SLAVE_BURST_2 (1 << 4) | |
82 | #define SM501_SYSCTRL_PCI_SLAVE_BURST_4 (2 << 4) | |
83 | #define SM501_SYSCTRL_PCI_SLAVE_BURST_8 (3 << 4) | |
ffd39257 | 84 | |
64f1603b BZ |
85 | #define SM501_SYSCTRL_PCI_CLOCK_RUN_EN (1 << 6) |
86 | #define SM501_SYSCTRL_PCI_RETRY_DISABLE (1 << 7) | |
87 | #define SM501_SYSCTRL_PCI_SUBSYS_LOCK (1 << 11) | |
88 | #define SM501_SYSCTRL_PCI_BURST_READ_EN (1 << 15) | |
ffd39257 BS |
89 | |
90 | /* miscellaneous control */ | |
91 | ||
64f1603b | 92 | #define SM501_MISC_CONTROL (0x000004) |
ffd39257 | 93 | |
64f1603b BZ |
94 | #define SM501_MISC_BUS_SH (0x0) |
95 | #define SM501_MISC_BUS_PCI (0x1) | |
96 | #define SM501_MISC_BUS_XSCALE (0x2) | |
97 | #define SM501_MISC_BUS_NEC (0x6) | |
98 | #define SM501_MISC_BUS_MASK (0x7) | |
ffd39257 | 99 | |
64f1603b BZ |
100 | #define SM501_MISC_VR_62MB (1 << 3) |
101 | #define SM501_MISC_CDR_RESET (1 << 7) | |
102 | #define SM501_MISC_USB_LB (1 << 8) | |
103 | #define SM501_MISC_USB_SLAVE (1 << 9) | |
104 | #define SM501_MISC_BL_1 (1 << 10) | |
105 | #define SM501_MISC_MC (1 << 11) | |
106 | #define SM501_MISC_DAC_POWER (1 << 12) | |
107 | #define SM501_MISC_IRQ_INVERT (1 << 16) | |
108 | #define SM501_MISC_SH (1 << 17) | |
ffd39257 | 109 | |
64f1603b BZ |
110 | #define SM501_MISC_HOLD_EMPTY (0 << 18) |
111 | #define SM501_MISC_HOLD_8 (1 << 18) | |
112 | #define SM501_MISC_HOLD_16 (2 << 18) | |
113 | #define SM501_MISC_HOLD_24 (3 << 18) | |
114 | #define SM501_MISC_HOLD_32 (4 << 18) | |
115 | #define SM501_MISC_HOLD_MASK (7 << 18) | |
ffd39257 | 116 | |
64f1603b BZ |
117 | #define SM501_MISC_FREQ_12 (1 << 24) |
118 | #define SM501_MISC_PNL_24BIT (1 << 25) | |
119 | #define SM501_MISC_8051_LE (1 << 26) | |
ffd39257 BS |
120 | |
121 | ||
122 | ||
64f1603b BZ |
123 | #define SM501_GPIO31_0_CONTROL (0x000008) |
124 | #define SM501_GPIO63_32_CONTROL (0x00000C) | |
125 | #define SM501_DRAM_CONTROL (0x000010) | |
ffd39257 BS |
126 | |
127 | /* command list */ | |
64f1603b | 128 | #define SM501_ARBTRTN_CONTROL (0x000014) |
ffd39257 BS |
129 | |
130 | /* command list */ | |
64f1603b | 131 | #define SM501_COMMAND_LIST_STATUS (0x000024) |
ffd39257 BS |
132 | |
133 | /* interrupt debug */ | |
64f1603b BZ |
134 | #define SM501_RAW_IRQ_STATUS (0x000028) |
135 | #define SM501_RAW_IRQ_CLEAR (0x000028) | |
136 | #define SM501_IRQ_STATUS (0x00002C) | |
137 | #define SM501_IRQ_MASK (0x000030) | |
138 | #define SM501_DEBUG_CONTROL (0x000034) | |
ffd39257 BS |
139 | |
140 | /* power management */ | |
64f1603b BZ |
141 | #define SM501_POWERMODE_P2X_SRC (1 << 29) |
142 | #define SM501_POWERMODE_V2X_SRC (1 << 20) | |
143 | #define SM501_POWERMODE_M_SRC (1 << 12) | |
144 | #define SM501_POWERMODE_M1_SRC (1 << 4) | |
145 | ||
146 | #define SM501_CURRENT_GATE (0x000038) | |
147 | #define SM501_CURRENT_CLOCK (0x00003C) | |
148 | #define SM501_POWER_MODE_0_GATE (0x000040) | |
149 | #define SM501_POWER_MODE_0_CLOCK (0x000044) | |
150 | #define SM501_POWER_MODE_1_GATE (0x000048) | |
151 | #define SM501_POWER_MODE_1_CLOCK (0x00004C) | |
152 | #define SM501_SLEEP_MODE_GATE (0x000050) | |
153 | #define SM501_POWER_MODE_CONTROL (0x000054) | |
ffd39257 BS |
154 | |
155 | /* power gates for units within the 501 */ | |
64f1603b BZ |
156 | #define SM501_GATE_HOST (0) |
157 | #define SM501_GATE_MEMORY (1) | |
158 | #define SM501_GATE_DISPLAY (2) | |
159 | #define SM501_GATE_2D_ENGINE (3) | |
160 | #define SM501_GATE_CSC (4) | |
161 | #define SM501_GATE_ZVPORT (5) | |
162 | #define SM501_GATE_GPIO (6) | |
163 | #define SM501_GATE_UART0 (7) | |
164 | #define SM501_GATE_UART1 (8) | |
165 | #define SM501_GATE_SSP (10) | |
166 | #define SM501_GATE_USB_HOST (11) | |
167 | #define SM501_GATE_USB_GADGET (12) | |
168 | #define SM501_GATE_UCONTROLLER (17) | |
169 | #define SM501_GATE_AC97 (18) | |
ffd39257 BS |
170 | |
171 | /* panel clock */ | |
64f1603b | 172 | #define SM501_CLOCK_P2XCLK (24) |
ffd39257 | 173 | /* crt clock */ |
64f1603b | 174 | #define SM501_CLOCK_V2XCLK (16) |
ffd39257 | 175 | /* main clock */ |
64f1603b | 176 | #define SM501_CLOCK_MCLK (8) |
ffd39257 | 177 | /* SDRAM controller clock */ |
64f1603b | 178 | #define SM501_CLOCK_M1XCLK (0) |
ffd39257 BS |
179 | |
180 | /* config 2 */ | |
64f1603b BZ |
181 | #define SM501_PCI_MASTER_BASE (0x000058) |
182 | #define SM501_ENDIAN_CONTROL (0x00005C) | |
183 | #define SM501_DEVICEID (0x000060) | |
ffd39257 BS |
184 | /* 0x050100A0 */ |
185 | ||
64f1603b BZ |
186 | #define SM501_DEVICEID_SM501 (0x05010000) |
187 | #define SM501_DEVICEID_IDMASK (0xffff0000) | |
188 | #define SM501_DEVICEID_REVMASK (0x000000ff) | |
ffd39257 | 189 | |
64f1603b BZ |
190 | #define SM501_PLLCLOCK_COUNT (0x000064) |
191 | #define SM501_MISC_TIMING (0x000068) | |
192 | #define SM501_CURRENT_SDRAM_CLOCK (0x00006C) | |
ffd39257 | 193 | |
64f1603b | 194 | #define SM501_PROGRAMMABLE_PLL_CONTROL (0x000074) |
ffd39257 BS |
195 | |
196 | /* GPIO base */ | |
64f1603b BZ |
197 | #define SM501_GPIO (0x010000) |
198 | #define SM501_GPIO_DATA_LOW (0x00) | |
199 | #define SM501_GPIO_DATA_HIGH (0x04) | |
200 | #define SM501_GPIO_DDR_LOW (0x08) | |
201 | #define SM501_GPIO_DDR_HIGH (0x0C) | |
202 | #define SM501_GPIO_IRQ_SETUP (0x10) | |
203 | #define SM501_GPIO_IRQ_STATUS (0x14) | |
204 | #define SM501_GPIO_IRQ_RESET (0x14) | |
ffd39257 BS |
205 | |
206 | /* I2C controller base */ | |
64f1603b BZ |
207 | #define SM501_I2C (0x010040) |
208 | #define SM501_I2C_BYTE_COUNT (0x00) | |
209 | #define SM501_I2C_CONTROL (0x01) | |
210 | #define SM501_I2C_STATUS (0x02) | |
211 | #define SM501_I2C_RESET (0x02) | |
212 | #define SM501_I2C_SLAVE_ADDRESS (0x03) | |
213 | #define SM501_I2C_DATA (0x04) | |
ffd39257 BS |
214 | |
215 | /* SSP base */ | |
64f1603b | 216 | #define SM501_SSP (0x020000) |
ffd39257 BS |
217 | |
218 | /* Uart 0 base */ | |
64f1603b | 219 | #define SM501_UART0 (0x030000) |
ffd39257 BS |
220 | |
221 | /* Uart 1 base */ | |
64f1603b | 222 | #define SM501_UART1 (0x030020) |
ffd39257 BS |
223 | |
224 | /* USB host port base */ | |
64f1603b | 225 | #define SM501_USB_HOST (0x040000) |
ffd39257 BS |
226 | |
227 | /* USB slave/gadget base */ | |
64f1603b | 228 | #define SM501_USB_GADGET (0x060000) |
ffd39257 BS |
229 | |
230 | /* USB slave/gadget data port base */ | |
64f1603b | 231 | #define SM501_USB_GADGET_DATA (0x070000) |
ffd39257 BS |
232 | |
233 | /* Display controller/video engine base */ | |
64f1603b | 234 | #define SM501_DC (0x080000) |
ffd39257 BS |
235 | |
236 | /* common defines for the SM501 address registers */ | |
64f1603b BZ |
237 | #define SM501_ADDR_FLIP (1 << 31) |
238 | #define SM501_ADDR_EXT (1 << 27) | |
239 | #define SM501_ADDR_CS1 (1 << 26) | |
240 | #define SM501_ADDR_MASK (0x3f << 26) | |
ffd39257 | 241 | |
64f1603b BZ |
242 | #define SM501_FIFO_MASK (0x3 << 16) |
243 | #define SM501_FIFO_1 (0x0 << 16) | |
244 | #define SM501_FIFO_3 (0x1 << 16) | |
245 | #define SM501_FIFO_7 (0x2 << 16) | |
246 | #define SM501_FIFO_11 (0x3 << 16) | |
ffd39257 BS |
247 | |
248 | /* common registers for panel and the crt */ | |
64f1603b BZ |
249 | #define SM501_OFF_DC_H_TOT (0x000) |
250 | #define SM501_OFF_DC_V_TOT (0x008) | |
251 | #define SM501_OFF_DC_H_SYNC (0x004) | |
252 | #define SM501_OFF_DC_V_SYNC (0x00C) | |
253 | ||
254 | #define SM501_DC_PANEL_CONTROL (0x000) | |
255 | ||
256 | #define SM501_DC_PANEL_CONTROL_FPEN (1 << 27) | |
257 | #define SM501_DC_PANEL_CONTROL_BIAS (1 << 26) | |
258 | #define SM501_DC_PANEL_CONTROL_DATA (1 << 25) | |
259 | #define SM501_DC_PANEL_CONTROL_VDD (1 << 24) | |
260 | #define SM501_DC_PANEL_CONTROL_DP (1 << 23) | |
261 | ||
262 | #define SM501_DC_PANEL_CONTROL_TFT_888 (0 << 21) | |
263 | #define SM501_DC_PANEL_CONTROL_TFT_333 (1 << 21) | |
264 | #define SM501_DC_PANEL_CONTROL_TFT_444 (2 << 21) | |
265 | ||
266 | #define SM501_DC_PANEL_CONTROL_DE (1 << 20) | |
267 | ||
268 | #define SM501_DC_PANEL_CONTROL_LCD_TFT (0 << 18) | |
269 | #define SM501_DC_PANEL_CONTROL_LCD_STN8 (1 << 18) | |
270 | #define SM501_DC_PANEL_CONTROL_LCD_STN12 (2 << 18) | |
271 | ||
272 | #define SM501_DC_PANEL_CONTROL_CP (1 << 14) | |
273 | #define SM501_DC_PANEL_CONTROL_VSP (1 << 13) | |
274 | #define SM501_DC_PANEL_CONTROL_HSP (1 << 12) | |
275 | #define SM501_DC_PANEL_CONTROL_CK (1 << 9) | |
276 | #define SM501_DC_PANEL_CONTROL_TE (1 << 8) | |
277 | #define SM501_DC_PANEL_CONTROL_VPD (1 << 7) | |
278 | #define SM501_DC_PANEL_CONTROL_VP (1 << 6) | |
279 | #define SM501_DC_PANEL_CONTROL_HPD (1 << 5) | |
280 | #define SM501_DC_PANEL_CONTROL_HP (1 << 4) | |
281 | #define SM501_DC_PANEL_CONTROL_GAMMA (1 << 3) | |
282 | #define SM501_DC_PANEL_CONTROL_EN (1 << 2) | |
283 | ||
284 | #define SM501_DC_PANEL_CONTROL_8BPP (0 << 0) | |
285 | #define SM501_DC_PANEL_CONTROL_16BPP (1 << 0) | |
286 | #define SM501_DC_PANEL_CONTROL_32BPP (2 << 0) | |
287 | ||
288 | ||
289 | #define SM501_DC_PANEL_PANNING_CONTROL (0x004) | |
290 | #define SM501_DC_PANEL_COLOR_KEY (0x008) | |
291 | #define SM501_DC_PANEL_FB_ADDR (0x00C) | |
292 | #define SM501_DC_PANEL_FB_OFFSET (0x010) | |
293 | #define SM501_DC_PANEL_FB_WIDTH (0x014) | |
294 | #define SM501_DC_PANEL_FB_HEIGHT (0x018) | |
295 | #define SM501_DC_PANEL_TL_LOC (0x01C) | |
296 | #define SM501_DC_PANEL_BR_LOC (0x020) | |
297 | #define SM501_DC_PANEL_H_TOT (0x024) | |
298 | #define SM501_DC_PANEL_H_SYNC (0x028) | |
299 | #define SM501_DC_PANEL_V_TOT (0x02C) | |
300 | #define SM501_DC_PANEL_V_SYNC (0x030) | |
301 | #define SM501_DC_PANEL_CUR_LINE (0x034) | |
302 | ||
303 | #define SM501_DC_VIDEO_CONTROL (0x040) | |
304 | #define SM501_DC_VIDEO_FB0_ADDR (0x044) | |
305 | #define SM501_DC_VIDEO_FB_WIDTH (0x048) | |
306 | #define SM501_DC_VIDEO_FB0_LAST_ADDR (0x04C) | |
307 | #define SM501_DC_VIDEO_TL_LOC (0x050) | |
308 | #define SM501_DC_VIDEO_BR_LOC (0x054) | |
309 | #define SM501_DC_VIDEO_SCALE (0x058) | |
310 | #define SM501_DC_VIDEO_INIT_SCALE (0x05C) | |
311 | #define SM501_DC_VIDEO_YUV_CONSTANTS (0x060) | |
312 | #define SM501_DC_VIDEO_FB1_ADDR (0x064) | |
313 | #define SM501_DC_VIDEO_FB1_LAST_ADDR (0x068) | |
314 | ||
315 | #define SM501_DC_VIDEO_ALPHA_CONTROL (0x080) | |
316 | #define SM501_DC_VIDEO_ALPHA_FB_ADDR (0x084) | |
317 | #define SM501_DC_VIDEO_ALPHA_FB_OFFSET (0x088) | |
318 | #define SM501_DC_VIDEO_ALPHA_FB_LAST_ADDR (0x08C) | |
319 | #define SM501_DC_VIDEO_ALPHA_TL_LOC (0x090) | |
320 | #define SM501_DC_VIDEO_ALPHA_BR_LOC (0x094) | |
321 | #define SM501_DC_VIDEO_ALPHA_SCALE (0x098) | |
322 | #define SM501_DC_VIDEO_ALPHA_INIT_SCALE (0x09C) | |
323 | #define SM501_DC_VIDEO_ALPHA_CHROMA_KEY (0x0A0) | |
324 | #define SM501_DC_VIDEO_ALPHA_COLOR_LOOKUP (0x0A4) | |
325 | ||
326 | #define SM501_DC_PANEL_HWC_BASE (0x0F0) | |
327 | #define SM501_DC_PANEL_HWC_ADDR (0x0F0) | |
328 | #define SM501_DC_PANEL_HWC_LOC (0x0F4) | |
329 | #define SM501_DC_PANEL_HWC_COLOR_1_2 (0x0F8) | |
330 | #define SM501_DC_PANEL_HWC_COLOR_3 (0x0FC) | |
331 | ||
332 | #define SM501_HWC_EN (1 << 31) | |
333 | ||
334 | #define SM501_OFF_HWC_ADDR (0x00) | |
335 | #define SM501_OFF_HWC_LOC (0x04) | |
336 | #define SM501_OFF_HWC_COLOR_1_2 (0x08) | |
337 | #define SM501_OFF_HWC_COLOR_3 (0x0C) | |
338 | ||
339 | #define SM501_DC_ALPHA_CONTROL (0x100) | |
340 | #define SM501_DC_ALPHA_FB_ADDR (0x104) | |
341 | #define SM501_DC_ALPHA_FB_OFFSET (0x108) | |
342 | #define SM501_DC_ALPHA_TL_LOC (0x10C) | |
343 | #define SM501_DC_ALPHA_BR_LOC (0x110) | |
344 | #define SM501_DC_ALPHA_CHROMA_KEY (0x114) | |
345 | #define SM501_DC_ALPHA_COLOR_LOOKUP (0x118) | |
346 | ||
347 | #define SM501_DC_CRT_CONTROL (0x200) | |
348 | ||
349 | #define SM501_DC_CRT_CONTROL_TVP (1 << 15) | |
350 | #define SM501_DC_CRT_CONTROL_CP (1 << 14) | |
351 | #define SM501_DC_CRT_CONTROL_VSP (1 << 13) | |
352 | #define SM501_DC_CRT_CONTROL_HSP (1 << 12) | |
353 | #define SM501_DC_CRT_CONTROL_VS (1 << 11) | |
354 | #define SM501_DC_CRT_CONTROL_BLANK (1 << 10) | |
355 | #define SM501_DC_CRT_CONTROL_SEL (1 << 9) | |
356 | #define SM501_DC_CRT_CONTROL_TE (1 << 8) | |
ffd39257 | 357 | #define SM501_DC_CRT_CONTROL_PIXEL_MASK (0xF << 4) |
64f1603b BZ |
358 | #define SM501_DC_CRT_CONTROL_GAMMA (1 << 3) |
359 | #define SM501_DC_CRT_CONTROL_ENABLE (1 << 2) | |
ffd39257 | 360 | |
64f1603b BZ |
361 | #define SM501_DC_CRT_CONTROL_8BPP (0 << 0) |
362 | #define SM501_DC_CRT_CONTROL_16BPP (1 << 0) | |
363 | #define SM501_DC_CRT_CONTROL_32BPP (2 << 0) | |
ffd39257 | 364 | |
64f1603b BZ |
365 | #define SM501_DC_CRT_FB_ADDR (0x204) |
366 | #define SM501_DC_CRT_FB_OFFSET (0x208) | |
367 | #define SM501_DC_CRT_H_TOT (0x20C) | |
368 | #define SM501_DC_CRT_H_SYNC (0x210) | |
369 | #define SM501_DC_CRT_V_TOT (0x214) | |
370 | #define SM501_DC_CRT_V_SYNC (0x218) | |
371 | #define SM501_DC_CRT_SIGNATURE_ANALYZER (0x21C) | |
372 | #define SM501_DC_CRT_CUR_LINE (0x220) | |
373 | #define SM501_DC_CRT_MONITOR_DETECT (0x224) | |
ffd39257 | 374 | |
64f1603b BZ |
375 | #define SM501_DC_CRT_HWC_BASE (0x230) |
376 | #define SM501_DC_CRT_HWC_ADDR (0x230) | |
377 | #define SM501_DC_CRT_HWC_LOC (0x234) | |
378 | #define SM501_DC_CRT_HWC_COLOR_1_2 (0x238) | |
379 | #define SM501_DC_CRT_HWC_COLOR_3 (0x23C) | |
ffd39257 | 380 | |
64f1603b | 381 | #define SM501_DC_PANEL_PALETTE (0x400) |
ffd39257 | 382 | |
64f1603b | 383 | #define SM501_DC_VIDEO_PALETTE (0x800) |
ffd39257 | 384 | |
64f1603b | 385 | #define SM501_DC_CRT_PALETTE (0xC00) |
ffd39257 BS |
386 | |
387 | /* Zoom Video port base */ | |
64f1603b | 388 | #define SM501_ZVPORT (0x090000) |
ffd39257 BS |
389 | |
390 | /* AC97/I2S base */ | |
64f1603b | 391 | #define SM501_AC97 (0x0A0000) |
ffd39257 BS |
392 | |
393 | /* 8051 micro controller base */ | |
64f1603b | 394 | #define SM501_UCONTROLLER (0x0B0000) |
ffd39257 BS |
395 | |
396 | /* 8051 micro controller SRAM base */ | |
64f1603b | 397 | #define SM501_UCONTROLLER_SRAM (0x0C0000) |
ffd39257 BS |
398 | |
399 | /* DMA base */ | |
64f1603b | 400 | #define SM501_DMA (0x0D0000) |
ffd39257 BS |
401 | |
402 | /* 2d engine base */ | |
64f1603b BZ |
403 | #define SM501_2D_ENGINE (0x100000) |
404 | #define SM501_2D_SOURCE (0x00) | |
405 | #define SM501_2D_DESTINATION (0x04) | |
406 | #define SM501_2D_DIMENSION (0x08) | |
407 | #define SM501_2D_CONTROL (0x0C) | |
408 | #define SM501_2D_PITCH (0x10) | |
409 | #define SM501_2D_FOREGROUND (0x14) | |
410 | #define SM501_2D_BACKGROUND (0x18) | |
411 | #define SM501_2D_STRETCH (0x1C) | |
412 | #define SM501_2D_COLOR_COMPARE (0x20) | |
413 | #define SM501_2D_COLOR_COMPARE_MASK (0x24) | |
414 | #define SM501_2D_MASK (0x28) | |
415 | #define SM501_2D_CLIP_TL (0x2C) | |
416 | #define SM501_2D_CLIP_BR (0x30) | |
417 | #define SM501_2D_MONO_PATTERN_LOW (0x34) | |
418 | #define SM501_2D_MONO_PATTERN_HIGH (0x38) | |
419 | #define SM501_2D_WINDOW_WIDTH (0x3C) | |
420 | #define SM501_2D_SOURCE_BASE (0x40) | |
421 | #define SM501_2D_DESTINATION_BASE (0x44) | |
422 | #define SM501_2D_ALPHA (0x48) | |
423 | #define SM501_2D_WRAP (0x4C) | |
424 | #define SM501_2D_STATUS (0x50) | |
425 | ||
426 | #define SM501_CSC_Y_SOURCE_BASE (0xC8) | |
427 | #define SM501_CSC_CONSTANTS (0xCC) | |
428 | #define SM501_CSC_Y_SOURCE_X (0xD0) | |
429 | #define SM501_CSC_Y_SOURCE_Y (0xD4) | |
430 | #define SM501_CSC_U_SOURCE_BASE (0xD8) | |
431 | #define SM501_CSC_V_SOURCE_BASE (0xDC) | |
432 | #define SM501_CSC_SOURCE_DIMENSION (0xE0) | |
433 | #define SM501_CSC_SOURCE_PITCH (0xE4) | |
434 | #define SM501_CSC_DESTINATION (0xE8) | |
435 | #define SM501_CSC_DESTINATION_DIMENSION (0xEC) | |
436 | #define SM501_CSC_DESTINATION_PITCH (0xF0) | |
437 | #define SM501_CSC_SCALE_FACTOR (0xF4) | |
438 | #define SM501_CSC_DESTINATION_BASE (0xF8) | |
439 | #define SM501_CSC_CONTROL (0xFC) | |
ffd39257 BS |
440 | |
441 | /* 2d engine data port base */ | |
64f1603b | 442 | #define SM501_2D_ENGINE_DATA (0x110000) |
ffd39257 BS |
443 | |
444 | /* end of register definitions */ | |
445 | ||
0a4e7cd2 SK |
446 | #define SM501_HWC_WIDTH (64) |
447 | #define SM501_HWC_HEIGHT (64) | |
ffd39257 BS |
448 | |
449 | /* SM501 local memory size taken from "linux/drivers/mfd/sm501.c" */ | |
450 | static const uint32_t sm501_mem_local_size[] = { | |
e2ee8476 BZ |
451 | [0] = 4 * M_BYTE, |
452 | [1] = 8 * M_BYTE, | |
453 | [2] = 16 * M_BYTE, | |
454 | [3] = 32 * M_BYTE, | |
455 | [4] = 64 * M_BYTE, | |
456 | [5] = 2 * M_BYTE, | |
ffd39257 BS |
457 | }; |
458 | #define get_local_mem_size(s) sm501_mem_local_size[(s)->local_mem_size_index] | |
459 | ||
460 | typedef struct SM501State { | |
461 | /* graphic console status */ | |
c78f7137 | 462 | QemuConsole *con; |
ffd39257 BS |
463 | |
464 | /* status & internal resources */ | |
ffd39257 | 465 | uint32_t local_mem_size_index; |
64f1603b | 466 | uint8_t *local_mem; |
25793bfa | 467 | MemoryRegion local_mem_region; |
ca8a1104 BZ |
468 | MemoryRegion mmio_region; |
469 | MemoryRegion system_config_region; | |
470 | MemoryRegion disp_ctrl_region; | |
471 | MemoryRegion twoD_engine_region; | |
ffd39257 BS |
472 | uint32_t last_width; |
473 | uint32_t last_height; | |
474 | ||
475 | /* mmio registers */ | |
476 | uint32_t system_control; | |
477 | uint32_t misc_control; | |
478 | uint32_t gpio_31_0_control; | |
479 | uint32_t gpio_63_32_control; | |
480 | uint32_t dram_control; | |
70e46ca8 | 481 | uint32_t arbitration_control; |
ffd39257 BS |
482 | uint32_t irq_mask; |
483 | uint32_t misc_timing; | |
484 | uint32_t power_mode_control; | |
485 | ||
486 | uint32_t uart0_ier; | |
487 | uint32_t uart0_lcr; | |
488 | uint32_t uart0_mcr; | |
489 | uint32_t uart0_scr; | |
490 | ||
491 | uint8_t dc_palette[0x400 * 3]; | |
492 | ||
493 | uint32_t dc_panel_control; | |
494 | uint32_t dc_panel_panning_control; | |
495 | uint32_t dc_panel_fb_addr; | |
496 | uint32_t dc_panel_fb_offset; | |
497 | uint32_t dc_panel_fb_width; | |
498 | uint32_t dc_panel_fb_height; | |
499 | uint32_t dc_panel_tl_location; | |
500 | uint32_t dc_panel_br_location; | |
501 | uint32_t dc_panel_h_total; | |
502 | uint32_t dc_panel_h_sync; | |
503 | uint32_t dc_panel_v_total; | |
504 | uint32_t dc_panel_v_sync; | |
505 | ||
506 | uint32_t dc_panel_hwc_addr; | |
507 | uint32_t dc_panel_hwc_location; | |
508 | uint32_t dc_panel_hwc_color_1_2; | |
509 | uint32_t dc_panel_hwc_color_3; | |
510 | ||
511 | uint32_t dc_crt_control; | |
512 | uint32_t dc_crt_fb_addr; | |
513 | uint32_t dc_crt_fb_offset; | |
514 | uint32_t dc_crt_h_total; | |
515 | uint32_t dc_crt_h_sync; | |
516 | uint32_t dc_crt_v_total; | |
517 | uint32_t dc_crt_v_sync; | |
518 | ||
519 | uint32_t dc_crt_hwc_addr; | |
520 | uint32_t dc_crt_hwc_location; | |
521 | uint32_t dc_crt_hwc_color_1_2; | |
522 | uint32_t dc_crt_hwc_color_3; | |
523 | ||
07d8a50c | 524 | uint32_t twoD_source; |
604be200 SK |
525 | uint32_t twoD_destination; |
526 | uint32_t twoD_dimension; | |
527 | uint32_t twoD_control; | |
528 | uint32_t twoD_pitch; | |
529 | uint32_t twoD_foreground; | |
530 | uint32_t twoD_stretch; | |
531 | uint32_t twoD_color_compare_mask; | |
532 | uint32_t twoD_mask; | |
533 | uint32_t twoD_window_width; | |
534 | uint32_t twoD_source_base; | |
535 | uint32_t twoD_destination_base; | |
536 | ||
ffd39257 BS |
537 | } SM501State; |
538 | ||
539 | static uint32_t get_local_mem_size_index(uint32_t size) | |
540 | { | |
541 | uint32_t norm_size = 0; | |
542 | int i, index = 0; | |
543 | ||
b1503cda | 544 | for (i = 0; i < ARRAY_SIZE(sm501_mem_local_size); i++) { |
64f1603b BZ |
545 | uint32_t new_size = sm501_mem_local_size[i]; |
546 | if (new_size >= size) { | |
547 | if (norm_size == 0 || norm_size > new_size) { | |
548 | norm_size = new_size; | |
549 | index = i; | |
550 | } | |
551 | } | |
ffd39257 BS |
552 | } |
553 | ||
554 | return index; | |
555 | } | |
556 | ||
0a4e7cd2 SK |
557 | /** |
558 | * Check the availability of hardware cursor. | |
559 | * @param crt 0 for PANEL, 1 for CRT. | |
560 | */ | |
561 | static inline int is_hwc_enabled(SM501State *state, int crt) | |
562 | { | |
563 | uint32_t addr = crt ? state->dc_crt_hwc_addr : state->dc_panel_hwc_addr; | |
e2ee8476 | 564 | return addr & SM501_HWC_EN; |
0a4e7cd2 SK |
565 | } |
566 | ||
567 | /** | |
568 | * Get the address which holds cursor pattern data. | |
569 | * @param crt 0 for PANEL, 1 for CRT. | |
570 | */ | |
571 | static inline uint32_t get_hwc_address(SM501State *state, int crt) | |
572 | { | |
573 | uint32_t addr = crt ? state->dc_crt_hwc_addr : state->dc_panel_hwc_addr; | |
574 | return (addr & 0x03FFFFF0)/* >> 4*/; | |
575 | } | |
576 | ||
577 | /** | |
578 | * Get the cursor position in y coordinate. | |
579 | * @param crt 0 for PANEL, 1 for CRT. | |
580 | */ | |
581 | static inline uint32_t get_hwc_y(SM501State *state, int crt) | |
582 | { | |
583 | uint32_t location = crt ? state->dc_crt_hwc_location | |
584 | : state->dc_panel_hwc_location; | |
585 | return (location & 0x07FF0000) >> 16; | |
586 | } | |
587 | ||
588 | /** | |
589 | * Get the cursor position in x coordinate. | |
590 | * @param crt 0 for PANEL, 1 for CRT. | |
591 | */ | |
592 | static inline uint32_t get_hwc_x(SM501State *state, int crt) | |
593 | { | |
594 | uint32_t location = crt ? state->dc_crt_hwc_location | |
595 | : state->dc_panel_hwc_location; | |
596 | return location & 0x000007FF; | |
597 | } | |
598 | ||
599 | /** | |
600 | * Get the cursor position in x coordinate. | |
601 | * @param crt 0 for PANEL, 1 for CRT. | |
602 | * @param index 0, 1, 2 or 3 which specifies color of corsor dot. | |
603 | */ | |
604 | static inline uint16_t get_hwc_color(SM501State *state, int crt, int index) | |
605 | { | |
c2780865 | 606 | uint32_t color_reg = 0; |
0a4e7cd2 SK |
607 | uint16_t color_565 = 0; |
608 | ||
609 | if (index == 0) { | |
610 | return 0; | |
611 | } | |
612 | ||
613 | switch (index) { | |
614 | case 1: | |
615 | case 2: | |
616 | color_reg = crt ? state->dc_crt_hwc_color_1_2 | |
617 | : state->dc_panel_hwc_color_1_2; | |
618 | break; | |
619 | case 3: | |
620 | color_reg = crt ? state->dc_crt_hwc_color_3 | |
621 | : state->dc_panel_hwc_color_3; | |
622 | break; | |
623 | default: | |
624 | printf("invalid hw cursor color.\n"); | |
43dc2a64 | 625 | abort(); |
0a4e7cd2 SK |
626 | } |
627 | ||
628 | switch (index) { | |
629 | case 1: | |
630 | case 3: | |
631 | color_565 = (uint16_t)(color_reg & 0xFFFF); | |
632 | break; | |
633 | case 2: | |
634 | color_565 = (uint16_t)((color_reg >> 16) & 0xFFFF); | |
635 | break; | |
636 | } | |
637 | return color_565; | |
638 | } | |
639 | ||
640 | static int within_hwc_y_range(SM501State *state, int y, int crt) | |
641 | { | |
642 | int hwc_y = get_hwc_y(state, crt); | |
643 | return (hwc_y <= y && y < hwc_y + SM501_HWC_HEIGHT); | |
644 | } | |
645 | ||
64f1603b | 646 | static void sm501_2d_operation(SM501State *s) |
604be200 SK |
647 | { |
648 | /* obtain operation parameters */ | |
649 | int operation = (s->twoD_control >> 16) & 0x1f; | |
07d8a50c AJ |
650 | int rtl = s->twoD_control & 0x8000000; |
651 | int src_x = (s->twoD_source >> 16) & 0x01FFF; | |
652 | int src_y = s->twoD_source & 0xFFFF; | |
604be200 SK |
653 | int dst_x = (s->twoD_destination >> 16) & 0x01FFF; |
654 | int dst_y = s->twoD_destination & 0xFFFF; | |
655 | int operation_width = (s->twoD_dimension >> 16) & 0x1FFF; | |
656 | int operation_height = s->twoD_dimension & 0xFFFF; | |
657 | uint32_t color = s->twoD_foreground; | |
658 | int format_flags = (s->twoD_stretch >> 20) & 0x3; | |
659 | int addressing = (s->twoD_stretch >> 16) & 0xF; | |
660 | ||
661 | /* get frame buffer info */ | |
64f1603b BZ |
662 | uint8_t *src = s->local_mem + (s->twoD_source_base & 0x03FFFFFF); |
663 | uint8_t *dst = s->local_mem + (s->twoD_destination_base & 0x03FFFFFF); | |
07d8a50c | 664 | int src_width = (s->dc_crt_h_total & 0x00000FFF) + 1; |
604be200 SK |
665 | int dst_width = (s->dc_crt_h_total & 0x00000FFF) + 1; |
666 | ||
667 | if (addressing != 0x0) { | |
668 | printf("%s: only XY addressing is supported.\n", __func__); | |
669 | abort(); | |
670 | } | |
671 | ||
672 | if ((s->twoD_source_base & 0x08000000) || | |
673 | (s->twoD_destination_base & 0x08000000)) { | |
674 | printf("%s: only local memory is supported.\n", __func__); | |
675 | abort(); | |
676 | } | |
677 | ||
678 | switch (operation) { | |
07d8a50c | 679 | case 0x00: /* copy area */ |
64f1603b BZ |
680 | #define COPY_AREA(_bpp, _pixel_type, rtl) { \ |
681 | int y, x, index_d, index_s; \ | |
682 | for (y = 0; y < operation_height; y++) { \ | |
683 | for (x = 0; x < operation_width; x++) { \ | |
684 | if (rtl) { \ | |
685 | index_s = ((src_y - y) * src_width + src_x - x) * _bpp; \ | |
686 | index_d = ((dst_y - y) * dst_width + dst_x - x) * _bpp; \ | |
687 | } else { \ | |
688 | index_s = ((src_y + y) * src_width + src_x + x) * _bpp; \ | |
689 | index_d = ((dst_y + y) * dst_width + dst_x + x) * _bpp; \ | |
690 | } \ | |
691 | *(_pixel_type *)&dst[index_d] = *(_pixel_type *)&src[index_s];\ | |
692 | } \ | |
693 | } \ | |
07d8a50c AJ |
694 | } |
695 | switch (format_flags) { | |
696 | case 0: | |
697 | COPY_AREA(1, uint8_t, rtl); | |
698 | break; | |
699 | case 1: | |
700 | COPY_AREA(2, uint16_t, rtl); | |
701 | break; | |
702 | case 2: | |
703 | COPY_AREA(4, uint32_t, rtl); | |
704 | break; | |
705 | } | |
706 | break; | |
604be200 | 707 | |
07d8a50c | 708 | case 0x01: /* fill rectangle */ |
604be200 SK |
709 | #define FILL_RECT(_bpp, _pixel_type) { \ |
710 | int y, x; \ | |
711 | for (y = 0; y < operation_height; y++) { \ | |
712 | for (x = 0; x < operation_width; x++) { \ | |
713 | int index = ((dst_y + y) * dst_width + dst_x + x) * _bpp; \ | |
64f1603b | 714 | *(_pixel_type *)&dst[index] = (_pixel_type)color; \ |
604be200 SK |
715 | } \ |
716 | } \ | |
717 | } | |
718 | ||
719 | switch (format_flags) { | |
720 | case 0: | |
721 | FILL_RECT(1, uint8_t); | |
722 | break; | |
723 | case 1: | |
724 | FILL_RECT(2, uint16_t); | |
725 | break; | |
726 | case 2: | |
727 | FILL_RECT(4, uint32_t); | |
728 | break; | |
729 | } | |
730 | break; | |
731 | ||
732 | default: | |
733 | printf("non-implemented SM501 2D operation. %d\n", operation); | |
734 | abort(); | |
735 | break; | |
736 | } | |
737 | } | |
738 | ||
a8170e5e | 739 | static uint64_t sm501_system_config_read(void *opaque, hwaddr addr, |
25793bfa | 740 | unsigned size) |
ffd39257 | 741 | { |
64f1603b | 742 | SM501State *s = (SM501State *)opaque; |
ffd39257 | 743 | uint32_t ret = 0; |
8da3ff18 | 744 | SM501_DPRINTF("sm501 system config regs : read addr=%x\n", (int)addr); |
ffd39257 | 745 | |
64f1603b | 746 | switch (addr) { |
ffd39257 | 747 | case SM501_SYSTEM_CONTROL: |
64f1603b BZ |
748 | ret = s->system_control; |
749 | break; | |
ffd39257 | 750 | case SM501_MISC_CONTROL: |
64f1603b BZ |
751 | ret = s->misc_control; |
752 | break; | |
ffd39257 | 753 | case SM501_GPIO31_0_CONTROL: |
64f1603b BZ |
754 | ret = s->gpio_31_0_control; |
755 | break; | |
ffd39257 | 756 | case SM501_GPIO63_32_CONTROL: |
64f1603b BZ |
757 | ret = s->gpio_63_32_control; |
758 | break; | |
ffd39257 | 759 | case SM501_DEVICEID: |
64f1603b BZ |
760 | ret = 0x050100A0; |
761 | break; | |
ffd39257 | 762 | case SM501_DRAM_CONTROL: |
64f1603b BZ |
763 | ret = (s->dram_control & 0x07F107C0) | s->local_mem_size_index << 13; |
764 | break; | |
70e46ca8 BZ |
765 | case SM501_ARBTRTN_CONTROL: |
766 | ret = s->arbitration_control; | |
767 | break; | |
ffd39257 | 768 | case SM501_IRQ_MASK: |
64f1603b BZ |
769 | ret = s->irq_mask; |
770 | break; | |
ffd39257 | 771 | case SM501_MISC_TIMING: |
64f1603b BZ |
772 | /* TODO : simulate gate control */ |
773 | ret = s->misc_timing; | |
774 | break; | |
ffd39257 | 775 | case SM501_CURRENT_GATE: |
64f1603b BZ |
776 | /* TODO : simulate gate control */ |
777 | ret = 0x00021807; | |
778 | break; | |
ffd39257 | 779 | case SM501_CURRENT_CLOCK: |
64f1603b BZ |
780 | ret = 0x2A1A0A09; |
781 | break; | |
ffd39257 | 782 | case SM501_POWER_MODE_CONTROL: |
64f1603b BZ |
783 | ret = s->power_mode_control; |
784 | break; | |
ffd39257 BS |
785 | |
786 | default: | |
64f1603b BZ |
787 | printf("sm501 system config : not implemented register read." |
788 | " addr=%x\n", (int)addr); | |
43dc2a64 | 789 | abort(); |
ffd39257 BS |
790 | } |
791 | ||
792 | return ret; | |
793 | } | |
794 | ||
a8170e5e | 795 | static void sm501_system_config_write(void *opaque, hwaddr addr, |
25793bfa | 796 | uint64_t value, unsigned size) |
ffd39257 | 797 | { |
64f1603b | 798 | SM501State *s = (SM501State *)opaque; |
8da3ff18 | 799 | SM501_DPRINTF("sm501 system config regs : write addr=%x, val=%x\n", |
64f1603b | 800 | (uint32_t)addr, (uint32_t)value); |
ffd39257 | 801 | |
64f1603b | 802 | switch (addr) { |
ffd39257 | 803 | case SM501_SYSTEM_CONTROL: |
64f1603b BZ |
804 | s->system_control = value & 0xE300B8F7; |
805 | break; | |
ffd39257 | 806 | case SM501_MISC_CONTROL: |
64f1603b BZ |
807 | s->misc_control = value & 0xFF7FFF20; |
808 | break; | |
ffd39257 | 809 | case SM501_GPIO31_0_CONTROL: |
64f1603b BZ |
810 | s->gpio_31_0_control = value; |
811 | break; | |
ffd39257 | 812 | case SM501_GPIO63_32_CONTROL: |
64f1603b BZ |
813 | s->gpio_63_32_control = value; |
814 | break; | |
ffd39257 | 815 | case SM501_DRAM_CONTROL: |
64f1603b BZ |
816 | s->local_mem_size_index = (value >> 13) & 0x7; |
817 | /* TODO : check validity of size change */ | |
818 | s->dram_control |= value & 0x7FFFFFC3; | |
819 | break; | |
70e46ca8 BZ |
820 | case SM501_ARBTRTN_CONTROL: |
821 | s->arbitration_control = value & 0x37777777; | |
822 | break; | |
ffd39257 | 823 | case SM501_IRQ_MASK: |
64f1603b BZ |
824 | s->irq_mask = value; |
825 | break; | |
ffd39257 | 826 | case SM501_MISC_TIMING: |
64f1603b BZ |
827 | s->misc_timing = value & 0xF31F1FFF; |
828 | break; | |
ffd39257 BS |
829 | case SM501_POWER_MODE_0_GATE: |
830 | case SM501_POWER_MODE_1_GATE: | |
831 | case SM501_POWER_MODE_0_CLOCK: | |
832 | case SM501_POWER_MODE_1_CLOCK: | |
64f1603b BZ |
833 | /* TODO : simulate gate & clock control */ |
834 | break; | |
ffd39257 | 835 | case SM501_POWER_MODE_CONTROL: |
64f1603b BZ |
836 | s->power_mode_control = value & 0x00000003; |
837 | break; | |
ffd39257 BS |
838 | |
839 | default: | |
64f1603b BZ |
840 | printf("sm501 system config : not implemented register write." |
841 | " addr=%x, val=%x\n", (int)addr, (uint32_t)value); | |
43dc2a64 | 842 | abort(); |
ffd39257 BS |
843 | } |
844 | } | |
845 | ||
25793bfa AK |
846 | static const MemoryRegionOps sm501_system_config_ops = { |
847 | .read = sm501_system_config_read, | |
848 | .write = sm501_system_config_write, | |
849 | .valid = { | |
850 | .min_access_size = 4, | |
851 | .max_access_size = 4, | |
852 | }, | |
853 | .endianness = DEVICE_NATIVE_ENDIAN, | |
ffd39257 BS |
854 | }; |
855 | ||
a8170e5e | 856 | static uint32_t sm501_palette_read(void *opaque, hwaddr addr) |
486579de | 857 | { |
64f1603b | 858 | SM501State *s = (SM501State *)opaque; |
486579de AZ |
859 | SM501_DPRINTF("sm501 palette read addr=%x\n", (int)addr); |
860 | ||
861 | /* TODO : consider BYTE/WORD access */ | |
862 | /* TODO : consider endian */ | |
863 | ||
45416789 | 864 | assert(range_covers_byte(0, 0x400 * 3, addr)); |
64f1603b | 865 | return *(uint32_t *)&s->dc_palette[addr]; |
486579de AZ |
866 | } |
867 | ||
64f1603b BZ |
868 | static void sm501_palette_write(void *opaque, hwaddr addr, |
869 | uint32_t value) | |
486579de | 870 | { |
64f1603b | 871 | SM501State *s = (SM501State *)opaque; |
486579de | 872 | SM501_DPRINTF("sm501 palette write addr=%x, val=%x\n", |
64f1603b | 873 | (int)addr, value); |
486579de AZ |
874 | |
875 | /* TODO : consider BYTE/WORD access */ | |
876 | /* TODO : consider endian */ | |
877 | ||
45416789 | 878 | assert(range_covers_byte(0, 0x400 * 3, addr)); |
64f1603b | 879 | *(uint32_t *)&s->dc_palette[addr] = value; |
486579de AZ |
880 | } |
881 | ||
a8170e5e | 882 | static uint64_t sm501_disp_ctrl_read(void *opaque, hwaddr addr, |
25793bfa | 883 | unsigned size) |
ffd39257 | 884 | { |
64f1603b | 885 | SM501State *s = (SM501State *)opaque; |
ffd39257 | 886 | uint32_t ret = 0; |
8da3ff18 | 887 | SM501_DPRINTF("sm501 disp ctrl regs : read addr=%x\n", (int)addr); |
ffd39257 | 888 | |
64f1603b | 889 | switch (addr) { |
ffd39257 BS |
890 | |
891 | case SM501_DC_PANEL_CONTROL: | |
64f1603b BZ |
892 | ret = s->dc_panel_control; |
893 | break; | |
ffd39257 | 894 | case SM501_DC_PANEL_PANNING_CONTROL: |
64f1603b BZ |
895 | ret = s->dc_panel_panning_control; |
896 | break; | |
ffd39257 | 897 | case SM501_DC_PANEL_FB_ADDR: |
64f1603b BZ |
898 | ret = s->dc_panel_fb_addr; |
899 | break; | |
ffd39257 | 900 | case SM501_DC_PANEL_FB_OFFSET: |
64f1603b BZ |
901 | ret = s->dc_panel_fb_offset; |
902 | break; | |
ffd39257 | 903 | case SM501_DC_PANEL_FB_WIDTH: |
64f1603b BZ |
904 | ret = s->dc_panel_fb_width; |
905 | break; | |
ffd39257 | 906 | case SM501_DC_PANEL_FB_HEIGHT: |
64f1603b BZ |
907 | ret = s->dc_panel_fb_height; |
908 | break; | |
ffd39257 | 909 | case SM501_DC_PANEL_TL_LOC: |
64f1603b BZ |
910 | ret = s->dc_panel_tl_location; |
911 | break; | |
ffd39257 | 912 | case SM501_DC_PANEL_BR_LOC: |
64f1603b BZ |
913 | ret = s->dc_panel_br_location; |
914 | break; | |
ffd39257 BS |
915 | |
916 | case SM501_DC_PANEL_H_TOT: | |
64f1603b BZ |
917 | ret = s->dc_panel_h_total; |
918 | break; | |
ffd39257 | 919 | case SM501_DC_PANEL_H_SYNC: |
64f1603b BZ |
920 | ret = s->dc_panel_h_sync; |
921 | break; | |
ffd39257 | 922 | case SM501_DC_PANEL_V_TOT: |
64f1603b BZ |
923 | ret = s->dc_panel_v_total; |
924 | break; | |
ffd39257 | 925 | case SM501_DC_PANEL_V_SYNC: |
64f1603b BZ |
926 | ret = s->dc_panel_v_sync; |
927 | break; | |
ffd39257 BS |
928 | |
929 | case SM501_DC_CRT_CONTROL: | |
64f1603b BZ |
930 | ret = s->dc_crt_control; |
931 | break; | |
ffd39257 | 932 | case SM501_DC_CRT_FB_ADDR: |
64f1603b BZ |
933 | ret = s->dc_crt_fb_addr; |
934 | break; | |
ffd39257 | 935 | case SM501_DC_CRT_FB_OFFSET: |
64f1603b BZ |
936 | ret = s->dc_crt_fb_offset; |
937 | break; | |
ffd39257 | 938 | case SM501_DC_CRT_H_TOT: |
64f1603b BZ |
939 | ret = s->dc_crt_h_total; |
940 | break; | |
ffd39257 | 941 | case SM501_DC_CRT_H_SYNC: |
64f1603b BZ |
942 | ret = s->dc_crt_h_sync; |
943 | break; | |
ffd39257 | 944 | case SM501_DC_CRT_V_TOT: |
64f1603b BZ |
945 | ret = s->dc_crt_v_total; |
946 | break; | |
ffd39257 | 947 | case SM501_DC_CRT_V_SYNC: |
64f1603b BZ |
948 | ret = s->dc_crt_v_sync; |
949 | break; | |
ffd39257 BS |
950 | |
951 | case SM501_DC_CRT_HWC_ADDR: | |
64f1603b BZ |
952 | ret = s->dc_crt_hwc_addr; |
953 | break; | |
ffd39257 | 954 | case SM501_DC_CRT_HWC_LOC: |
64f1603b BZ |
955 | ret = s->dc_crt_hwc_location; |
956 | break; | |
ffd39257 | 957 | case SM501_DC_CRT_HWC_COLOR_1_2: |
64f1603b BZ |
958 | ret = s->dc_crt_hwc_color_1_2; |
959 | break; | |
ffd39257 | 960 | case SM501_DC_CRT_HWC_COLOR_3: |
64f1603b BZ |
961 | ret = s->dc_crt_hwc_color_3; |
962 | break; | |
ffd39257 | 963 | |
64f1603b | 964 | case SM501_DC_PANEL_PALETTE ... SM501_DC_PANEL_PALETTE + 0x400 * 3 - 4: |
486579de AZ |
965 | ret = sm501_palette_read(opaque, addr - SM501_DC_PANEL_PALETTE); |
966 | break; | |
967 | ||
ffd39257 | 968 | default: |
64f1603b BZ |
969 | printf("sm501 disp ctrl : not implemented register read." |
970 | " addr=%x\n", (int)addr); | |
43dc2a64 | 971 | abort(); |
ffd39257 BS |
972 | } |
973 | ||
974 | return ret; | |
975 | } | |
976 | ||
a8170e5e | 977 | static void sm501_disp_ctrl_write(void *opaque, hwaddr addr, |
25793bfa | 978 | uint64_t value, unsigned size) |
ffd39257 | 979 | { |
64f1603b | 980 | SM501State *s = (SM501State *)opaque; |
8da3ff18 | 981 | SM501_DPRINTF("sm501 disp ctrl regs : write addr=%x, val=%x\n", |
64f1603b | 982 | (unsigned)addr, (unsigned)value); |
ffd39257 | 983 | |
64f1603b | 984 | switch (addr) { |
ffd39257 | 985 | case SM501_DC_PANEL_CONTROL: |
64f1603b BZ |
986 | s->dc_panel_control = value & 0x0FFF73FF; |
987 | break; | |
ffd39257 | 988 | case SM501_DC_PANEL_PANNING_CONTROL: |
64f1603b BZ |
989 | s->dc_panel_panning_control = value & 0xFF3FFF3F; |
990 | break; | |
ffd39257 | 991 | case SM501_DC_PANEL_FB_ADDR: |
64f1603b BZ |
992 | s->dc_panel_fb_addr = value & 0x8FFFFFF0; |
993 | break; | |
ffd39257 | 994 | case SM501_DC_PANEL_FB_OFFSET: |
64f1603b BZ |
995 | s->dc_panel_fb_offset = value & 0x3FF03FF0; |
996 | break; | |
ffd39257 | 997 | case SM501_DC_PANEL_FB_WIDTH: |
64f1603b BZ |
998 | s->dc_panel_fb_width = value & 0x0FFF0FFF; |
999 | break; | |
ffd39257 | 1000 | case SM501_DC_PANEL_FB_HEIGHT: |
64f1603b BZ |
1001 | s->dc_panel_fb_height = value & 0x0FFF0FFF; |
1002 | break; | |
ffd39257 | 1003 | case SM501_DC_PANEL_TL_LOC: |
64f1603b BZ |
1004 | s->dc_panel_tl_location = value & 0x07FF07FF; |
1005 | break; | |
ffd39257 | 1006 | case SM501_DC_PANEL_BR_LOC: |
64f1603b BZ |
1007 | s->dc_panel_br_location = value & 0x07FF07FF; |
1008 | break; | |
ffd39257 BS |
1009 | |
1010 | case SM501_DC_PANEL_H_TOT: | |
64f1603b BZ |
1011 | s->dc_panel_h_total = value & 0x0FFF0FFF; |
1012 | break; | |
ffd39257 | 1013 | case SM501_DC_PANEL_H_SYNC: |
64f1603b BZ |
1014 | s->dc_panel_h_sync = value & 0x00FF0FFF; |
1015 | break; | |
ffd39257 | 1016 | case SM501_DC_PANEL_V_TOT: |
64f1603b BZ |
1017 | s->dc_panel_v_total = value & 0x0FFF0FFF; |
1018 | break; | |
ffd39257 | 1019 | case SM501_DC_PANEL_V_SYNC: |
64f1603b BZ |
1020 | s->dc_panel_v_sync = value & 0x003F0FFF; |
1021 | break; | |
ffd39257 BS |
1022 | |
1023 | case SM501_DC_PANEL_HWC_ADDR: | |
64f1603b BZ |
1024 | s->dc_panel_hwc_addr = value & 0x8FFFFFF0; |
1025 | break; | |
ffd39257 | 1026 | case SM501_DC_PANEL_HWC_LOC: |
64f1603b BZ |
1027 | s->dc_panel_hwc_location = value & 0x0FFF0FFF; |
1028 | break; | |
ffd39257 | 1029 | case SM501_DC_PANEL_HWC_COLOR_1_2: |
64f1603b BZ |
1030 | s->dc_panel_hwc_color_1_2 = value; |
1031 | break; | |
ffd39257 | 1032 | case SM501_DC_PANEL_HWC_COLOR_3: |
64f1603b BZ |
1033 | s->dc_panel_hwc_color_3 = value & 0x0000FFFF; |
1034 | break; | |
ffd39257 BS |
1035 | |
1036 | case SM501_DC_CRT_CONTROL: | |
64f1603b BZ |
1037 | s->dc_crt_control = value & 0x0003FFFF; |
1038 | break; | |
ffd39257 | 1039 | case SM501_DC_CRT_FB_ADDR: |
64f1603b BZ |
1040 | s->dc_crt_fb_addr = value & 0x8FFFFFF0; |
1041 | break; | |
ffd39257 | 1042 | case SM501_DC_CRT_FB_OFFSET: |
64f1603b BZ |
1043 | s->dc_crt_fb_offset = value & 0x3FF03FF0; |
1044 | break; | |
ffd39257 | 1045 | case SM501_DC_CRT_H_TOT: |
64f1603b BZ |
1046 | s->dc_crt_h_total = value & 0x0FFF0FFF; |
1047 | break; | |
ffd39257 | 1048 | case SM501_DC_CRT_H_SYNC: |
64f1603b BZ |
1049 | s->dc_crt_h_sync = value & 0x00FF0FFF; |
1050 | break; | |
ffd39257 | 1051 | case SM501_DC_CRT_V_TOT: |
64f1603b BZ |
1052 | s->dc_crt_v_total = value & 0x0FFF0FFF; |
1053 | break; | |
ffd39257 | 1054 | case SM501_DC_CRT_V_SYNC: |
64f1603b BZ |
1055 | s->dc_crt_v_sync = value & 0x003F0FFF; |
1056 | break; | |
ffd39257 BS |
1057 | |
1058 | case SM501_DC_CRT_HWC_ADDR: | |
64f1603b BZ |
1059 | s->dc_crt_hwc_addr = value & 0x8FFFFFF0; |
1060 | break; | |
ffd39257 | 1061 | case SM501_DC_CRT_HWC_LOC: |
64f1603b BZ |
1062 | s->dc_crt_hwc_location = value & 0x0FFF0FFF; |
1063 | break; | |
ffd39257 | 1064 | case SM501_DC_CRT_HWC_COLOR_1_2: |
64f1603b BZ |
1065 | s->dc_crt_hwc_color_1_2 = value; |
1066 | break; | |
ffd39257 | 1067 | case SM501_DC_CRT_HWC_COLOR_3: |
64f1603b BZ |
1068 | s->dc_crt_hwc_color_3 = value & 0x0000FFFF; |
1069 | break; | |
ffd39257 | 1070 | |
64f1603b | 1071 | case SM501_DC_PANEL_PALETTE ... SM501_DC_PANEL_PALETTE + 0x400 * 3 - 4: |
486579de AZ |
1072 | sm501_palette_write(opaque, addr - SM501_DC_PANEL_PALETTE, value); |
1073 | break; | |
1074 | ||
ffd39257 | 1075 | default: |
64f1603b BZ |
1076 | printf("sm501 disp ctrl : not implemented register write." |
1077 | " addr=%x, val=%x\n", (int)addr, (unsigned)value); | |
43dc2a64 | 1078 | abort(); |
ffd39257 BS |
1079 | } |
1080 | } | |
1081 | ||
25793bfa AK |
1082 | static const MemoryRegionOps sm501_disp_ctrl_ops = { |
1083 | .read = sm501_disp_ctrl_read, | |
1084 | .write = sm501_disp_ctrl_write, | |
1085 | .valid = { | |
1086 | .min_access_size = 4, | |
1087 | .max_access_size = 4, | |
1088 | }, | |
1089 | .endianness = DEVICE_NATIVE_ENDIAN, | |
ffd39257 BS |
1090 | }; |
1091 | ||
a8170e5e | 1092 | static uint64_t sm501_2d_engine_read(void *opaque, hwaddr addr, |
25793bfa | 1093 | unsigned size) |
604be200 | 1094 | { |
64f1603b | 1095 | SM501State *s = (SM501State *)opaque; |
604be200 SK |
1096 | uint32_t ret = 0; |
1097 | SM501_DPRINTF("sm501 2d engine regs : read addr=%x\n", (int)addr); | |
1098 | ||
64f1603b | 1099 | switch (addr) { |
604be200 SK |
1100 | case SM501_2D_SOURCE_BASE: |
1101 | ret = s->twoD_source_base; | |
1102 | break; | |
1103 | default: | |
1104 | printf("sm501 disp ctrl : not implemented register read." | |
1105 | " addr=%x\n", (int)addr); | |
1106 | abort(); | |
1107 | } | |
1108 | ||
1109 | return ret; | |
1110 | } | |
1111 | ||
a8170e5e | 1112 | static void sm501_2d_engine_write(void *opaque, hwaddr addr, |
25793bfa | 1113 | uint64_t value, unsigned size) |
604be200 | 1114 | { |
64f1603b | 1115 | SM501State *s = (SM501State *)opaque; |
604be200 | 1116 | SM501_DPRINTF("sm501 2d engine regs : write addr=%x, val=%x\n", |
25793bfa | 1117 | (unsigned)addr, (unsigned)value); |
604be200 | 1118 | |
64f1603b | 1119 | switch (addr) { |
07d8a50c AJ |
1120 | case SM501_2D_SOURCE: |
1121 | s->twoD_source = value; | |
1122 | break; | |
604be200 SK |
1123 | case SM501_2D_DESTINATION: |
1124 | s->twoD_destination = value; | |
1125 | break; | |
1126 | case SM501_2D_DIMENSION: | |
1127 | s->twoD_dimension = value; | |
1128 | break; | |
1129 | case SM501_2D_CONTROL: | |
1130 | s->twoD_control = value; | |
1131 | ||
1132 | /* do 2d operation if start flag is set. */ | |
1133 | if (value & 0x80000000) { | |
1134 | sm501_2d_operation(s); | |
1135 | s->twoD_control &= ~0x80000000; /* start flag down */ | |
1136 | } | |
1137 | ||
1138 | break; | |
1139 | case SM501_2D_PITCH: | |
1140 | s->twoD_pitch = value; | |
1141 | break; | |
1142 | case SM501_2D_FOREGROUND: | |
1143 | s->twoD_foreground = value; | |
1144 | break; | |
1145 | case SM501_2D_STRETCH: | |
1146 | s->twoD_stretch = value; | |
1147 | break; | |
1148 | case SM501_2D_COLOR_COMPARE_MASK: | |
1149 | s->twoD_color_compare_mask = value; | |
1150 | break; | |
1151 | case SM501_2D_MASK: | |
1152 | s->twoD_mask = value; | |
1153 | break; | |
1154 | case SM501_2D_WINDOW_WIDTH: | |
1155 | s->twoD_window_width = value; | |
1156 | break; | |
1157 | case SM501_2D_SOURCE_BASE: | |
1158 | s->twoD_source_base = value; | |
1159 | break; | |
1160 | case SM501_2D_DESTINATION_BASE: | |
1161 | s->twoD_destination_base = value; | |
1162 | break; | |
1163 | default: | |
1164 | printf("sm501 2d engine : not implemented register write." | |
25793bfa | 1165 | " addr=%x, val=%x\n", (int)addr, (unsigned)value); |
604be200 SK |
1166 | abort(); |
1167 | } | |
1168 | } | |
1169 | ||
25793bfa AK |
1170 | static const MemoryRegionOps sm501_2d_engine_ops = { |
1171 | .read = sm501_2d_engine_read, | |
1172 | .write = sm501_2d_engine_write, | |
1173 | .valid = { | |
1174 | .min_access_size = 4, | |
1175 | .max_access_size = 4, | |
1176 | }, | |
1177 | .endianness = DEVICE_NATIVE_ENDIAN, | |
604be200 SK |
1178 | }; |
1179 | ||
ffd39257 BS |
1180 | /* draw line functions for all console modes */ |
1181 | ||
ffd39257 | 1182 | typedef void draw_line_func(uint8_t *d, const uint8_t *s, |
64f1603b | 1183 | int width, const uint32_t *pal); |
ffd39257 | 1184 | |
64f1603b | 1185 | typedef void draw_hwc_line_func(SM501State *s, int crt, uint8_t *palette, |
0a4e7cd2 SK |
1186 | int c_y, uint8_t *d, int width); |
1187 | ||
ffd39257 | 1188 | #define DEPTH 8 |
47b43a1f | 1189 | #include "sm501_template.h" |
ffd39257 BS |
1190 | |
1191 | #define DEPTH 15 | |
47b43a1f | 1192 | #include "sm501_template.h" |
ffd39257 BS |
1193 | |
1194 | #define BGR_FORMAT | |
1195 | #define DEPTH 15 | |
47b43a1f | 1196 | #include "sm501_template.h" |
ffd39257 BS |
1197 | |
1198 | #define DEPTH 16 | |
47b43a1f | 1199 | #include "sm501_template.h" |
ffd39257 BS |
1200 | |
1201 | #define BGR_FORMAT | |
1202 | #define DEPTH 16 | |
47b43a1f | 1203 | #include "sm501_template.h" |
ffd39257 BS |
1204 | |
1205 | #define DEPTH 32 | |
47b43a1f | 1206 | #include "sm501_template.h" |
ffd39257 BS |
1207 | |
1208 | #define BGR_FORMAT | |
1209 | #define DEPTH 32 | |
47b43a1f | 1210 | #include "sm501_template.h" |
ffd39257 | 1211 | |
64f1603b | 1212 | static draw_line_func *draw_line8_funcs[] = { |
ffd39257 BS |
1213 | draw_line8_8, |
1214 | draw_line8_15, | |
1215 | draw_line8_16, | |
1216 | draw_line8_32, | |
1217 | draw_line8_32bgr, | |
1218 | draw_line8_15bgr, | |
1219 | draw_line8_16bgr, | |
1220 | }; | |
1221 | ||
64f1603b | 1222 | static draw_line_func *draw_line16_funcs[] = { |
ffd39257 BS |
1223 | draw_line16_8, |
1224 | draw_line16_15, | |
1225 | draw_line16_16, | |
1226 | draw_line16_32, | |
1227 | draw_line16_32bgr, | |
1228 | draw_line16_15bgr, | |
1229 | draw_line16_16bgr, | |
1230 | }; | |
1231 | ||
64f1603b | 1232 | static draw_line_func *draw_line32_funcs[] = { |
ffd39257 BS |
1233 | draw_line32_8, |
1234 | draw_line32_15, | |
1235 | draw_line32_16, | |
1236 | draw_line32_32, | |
1237 | draw_line32_32bgr, | |
1238 | draw_line32_15bgr, | |
1239 | draw_line32_16bgr, | |
1240 | }; | |
1241 | ||
64f1603b | 1242 | static draw_hwc_line_func *draw_hwc_line_funcs[] = { |
0a4e7cd2 SK |
1243 | draw_hwc_line_8, |
1244 | draw_hwc_line_15, | |
1245 | draw_hwc_line_16, | |
1246 | draw_hwc_line_32, | |
1247 | draw_hwc_line_32bgr, | |
1248 | draw_hwc_line_15bgr, | |
1249 | draw_hwc_line_16bgr, | |
1250 | }; | |
1251 | ||
c78f7137 | 1252 | static inline int get_depth_index(DisplaySurface *surface) |
ffd39257 | 1253 | { |
c78f7137 | 1254 | switch (surface_bits_per_pixel(surface)) { |
ffd39257 BS |
1255 | default: |
1256 | case 8: | |
64f1603b | 1257 | return 0; |
ffd39257 | 1258 | case 15: |
8927bcfd | 1259 | return 1; |
ffd39257 | 1260 | case 16: |
8927bcfd | 1261 | return 2; |
ffd39257 | 1262 | case 32: |
c78f7137 GH |
1263 | if (is_surface_bgr(surface)) { |
1264 | return 4; | |
1265 | } else { | |
1266 | return 3; | |
1267 | } | |
ffd39257 BS |
1268 | } |
1269 | } | |
1270 | ||
64f1603b | 1271 | static void sm501_draw_crt(SM501State *s) |
ffd39257 | 1272 | { |
c78f7137 | 1273 | DisplaySurface *surface = qemu_console_surface(s->con); |
ffd39257 BS |
1274 | int y; |
1275 | int width = (s->dc_crt_h_total & 0x00000FFF) + 1; | |
1276 | int height = (s->dc_crt_v_total & 0x00000FFF) + 1; | |
1277 | ||
64f1603b | 1278 | uint8_t *src = s->local_mem; |
ffd39257 | 1279 | int src_bpp = 0; |
c78f7137 | 1280 | int dst_bpp = surface_bytes_per_pixel(surface); |
64f1603b BZ |
1281 | uint32_t *palette = (uint32_t *)&s->dc_palette[SM501_DC_CRT_PALETTE - |
1282 | SM501_DC_PANEL_PALETTE]; | |
0a4e7cd2 | 1283 | uint8_t hwc_palette[3 * 3]; |
c78f7137 | 1284 | int ds_depth_index = get_depth_index(surface); |
64f1603b BZ |
1285 | draw_line_func *draw_line = NULL; |
1286 | draw_hwc_line_func *draw_hwc_line = NULL; | |
ffd39257 BS |
1287 | int full_update = 0; |
1288 | int y_start = -1; | |
543c4c94 AJ |
1289 | ram_addr_t page_min = ~0l; |
1290 | ram_addr_t page_max = 0l; | |
25793bfa | 1291 | ram_addr_t offset = 0; |
ffd39257 BS |
1292 | |
1293 | /* choose draw_line function */ | |
1294 | switch (s->dc_crt_control & 3) { | |
1295 | case SM501_DC_CRT_CONTROL_8BPP: | |
64f1603b BZ |
1296 | src_bpp = 1; |
1297 | draw_line = draw_line8_funcs[ds_depth_index]; | |
1298 | break; | |
ffd39257 | 1299 | case SM501_DC_CRT_CONTROL_16BPP: |
64f1603b BZ |
1300 | src_bpp = 2; |
1301 | draw_line = draw_line16_funcs[ds_depth_index]; | |
1302 | break; | |
ffd39257 | 1303 | case SM501_DC_CRT_CONTROL_32BPP: |
64f1603b BZ |
1304 | src_bpp = 4; |
1305 | draw_line = draw_line32_funcs[ds_depth_index]; | |
1306 | break; | |
ffd39257 | 1307 | default: |
64f1603b BZ |
1308 | printf("sm501 draw crt : invalid DC_CRT_CONTROL=%x.\n", |
1309 | s->dc_crt_control); | |
43dc2a64 | 1310 | abort(); |
64f1603b | 1311 | break; |
ffd39257 BS |
1312 | } |
1313 | ||
0a4e7cd2 SK |
1314 | /* set up to draw hardware cursor */ |
1315 | if (is_hwc_enabled(s, 1)) { | |
1316 | int i; | |
1317 | ||
1318 | /* get cursor palette */ | |
1319 | for (i = 0; i < 3; i++) { | |
1320 | uint16_t rgb565 = get_hwc_color(s, 1, i + 1); | |
1321 | hwc_palette[i * 3 + 0] = (rgb565 & 0xf800) >> 8; /* red */ | |
1322 | hwc_palette[i * 3 + 1] = (rgb565 & 0x07e0) >> 3; /* green */ | |
1323 | hwc_palette[i * 3 + 2] = (rgb565 & 0x001f) << 3; /* blue */ | |
1324 | } | |
1325 | ||
1326 | /* choose cursor draw line function */ | |
1327 | draw_hwc_line = draw_hwc_line_funcs[ds_depth_index]; | |
1328 | } | |
1329 | ||
ffd39257 BS |
1330 | /* adjust console size */ |
1331 | if (s->last_width != width || s->last_height != height) { | |
c78f7137 GH |
1332 | qemu_console_resize(s->con, width, height); |
1333 | surface = qemu_console_surface(s->con); | |
64f1603b BZ |
1334 | s->last_width = width; |
1335 | s->last_height = height; | |
1336 | full_update = 1; | |
ffd39257 BS |
1337 | } |
1338 | ||
1339 | /* draw each line according to conditions */ | |
5299c0f2 | 1340 | memory_region_sync_dirty_bitmap(&s->local_mem_region); |
ffd39257 | 1341 | for (y = 0; y < height; y++) { |
64f1603b BZ |
1342 | int update_hwc = draw_hwc_line ? within_hwc_y_range(s, y, 1) : 0; |
1343 | int update = full_update || update_hwc; | |
cd7a45c9 BS |
1344 | ram_addr_t page0 = offset; |
1345 | ram_addr_t page1 = offset + width * src_bpp - 1; | |
ffd39257 | 1346 | |
64f1603b | 1347 | /* check dirty flags for each line */ |
d1f3dd34 BS |
1348 | update = memory_region_get_dirty(&s->local_mem_region, page0, |
1349 | page1 - page0, DIRTY_MEMORY_VGA); | |
ffd39257 | 1350 | |
64f1603b BZ |
1351 | /* draw line and change status */ |
1352 | if (update) { | |
c78f7137 GH |
1353 | uint8_t *d = surface_data(surface); |
1354 | d += y * width * dst_bpp; | |
0a4e7cd2 SK |
1355 | |
1356 | /* draw graphics layer */ | |
1357 | draw_line(d, src, width, palette); | |
1358 | ||
64f1603b | 1359 | /* draw hardware cursor */ |
0a4e7cd2 SK |
1360 | if (update_hwc) { |
1361 | draw_hwc_line(s, 1, hwc_palette, y - get_hwc_y(s, 1), d, width); | |
1362 | } | |
1363 | ||
64f1603b BZ |
1364 | if (y_start < 0) { |
1365 | y_start = y; | |
1366 | } | |
1367 | if (page0 < page_min) { | |
1368 | page_min = page0; | |
1369 | } | |
1370 | if (page1 > page_max) { | |
1371 | page_max = page1; | |
1372 | } | |
1373 | } else { | |
1374 | if (y_start >= 0) { | |
1375 | /* flush to display */ | |
c78f7137 | 1376 | dpy_gfx_update(s->con, 0, y_start, width, y - y_start); |
64f1603b BZ |
1377 | y_start = -1; |
1378 | } | |
1379 | } | |
ffd39257 | 1380 | |
64f1603b BZ |
1381 | src += width * src_bpp; |
1382 | offset += width * src_bpp; | |
ffd39257 BS |
1383 | } |
1384 | ||
1385 | /* complete flush to display */ | |
64f1603b | 1386 | if (y_start >= 0) { |
c78f7137 | 1387 | dpy_gfx_update(s->con, 0, y_start, width, y - y_start); |
64f1603b | 1388 | } |
ffd39257 BS |
1389 | |
1390 | /* clear dirty flags */ | |
543c4c94 | 1391 | if (page_min != ~0l) { |
64f1603b | 1392 | memory_region_reset_dirty(&s->local_mem_region, |
25793bfa AK |
1393 | page_min, page_max + TARGET_PAGE_SIZE, |
1394 | DIRTY_MEMORY_VGA); | |
543c4c94 | 1395 | } |
ffd39257 BS |
1396 | } |
1397 | ||
1398 | static void sm501_update_display(void *opaque) | |
1399 | { | |
64f1603b | 1400 | SM501State *s = (SM501State *)opaque; |
ffd39257 | 1401 | |
64f1603b BZ |
1402 | if (s->dc_crt_control & SM501_DC_CRT_CONTROL_ENABLE) { |
1403 | sm501_draw_crt(s); | |
1404 | } | |
ffd39257 BS |
1405 | } |
1406 | ||
380cd056 GH |
1407 | static const GraphicHwOps sm501_ops = { |
1408 | .gfx_update = sm501_update_display, | |
1409 | }; | |
1410 | ||
ca8a1104 | 1411 | static void sm501_reset(SM501State *s) |
ffd39257 | 1412 | { |
e2ee8476 BZ |
1413 | s->system_control = 0x00100000; /* 2D engine FIFO empty */ |
1414 | /* Bits 17 (SH), 7 (CDR), 6:5 (Test), 2:0 (Bus) are all supposed | |
1415 | * to be determined at reset by GPIO lines which set config bits. | |
1416 | * We hardwire them: | |
1417 | * SH = 0 : Hitachi Ready Polarity == Active Low | |
1418 | * CDR = 0 : do not reset clock divider | |
1419 | * TEST = 0 : Normal mode (not testing the silicon) | |
1420 | * BUS = 0 : Hitachi SH3/SH4 | |
1421 | */ | |
1422 | s->misc_control = SM501_MISC_DAC_POWER; | |
ca8a1104 BZ |
1423 | s->gpio_31_0_control = 0; |
1424 | s->gpio_63_32_control = 0; | |
1425 | s->dram_control = 0; | |
70e46ca8 | 1426 | s->arbitration_control = 0x05146732; |
ca8a1104 BZ |
1427 | s->irq_mask = 0; |
1428 | s->misc_timing = 0; | |
1429 | s->power_mode_control = 0; | |
e2ee8476 | 1430 | s->dc_panel_control = 0x00010000; /* FIFO level 3 */ |
ffd39257 | 1431 | s->dc_crt_control = 0x00010000; |
ca8a1104 BZ |
1432 | s->twoD_control = 0; |
1433 | } | |
ffd39257 | 1434 | |
c795fa84 | 1435 | static void sm501_init(SM501State *s, DeviceState *dev, |
ca8a1104 BZ |
1436 | uint32_t local_mem_bytes) |
1437 | { | |
ca8a1104 BZ |
1438 | s->local_mem_size_index = get_local_mem_size_index(local_mem_bytes); |
1439 | SM501_DPRINTF("sm501 local mem size=%x. index=%d\n", get_local_mem_size(s), | |
1440 | s->local_mem_size_index); | |
1441 | ||
1442 | /* local memory */ | |
1443 | memory_region_init_ram(&s->local_mem_region, OBJECT(dev), "sm501.local", | |
1444 | get_local_mem_size(s), &error_fatal); | |
c5705a77 | 1445 | vmstate_register_ram_global(&s->local_mem_region); |
74259ae5 | 1446 | memory_region_set_log(&s->local_mem_region, true, DIRTY_MEMORY_VGA); |
25793bfa | 1447 | s->local_mem = memory_region_get_ram_ptr(&s->local_mem_region); |
ca8a1104 BZ |
1448 | |
1449 | /* mmio */ | |
1450 | memory_region_init(&s->mmio_region, OBJECT(dev), "sm501.mmio", MMIO_SIZE); | |
1451 | memory_region_init_io(&s->system_config_region, OBJECT(dev), | |
1452 | &sm501_system_config_ops, s, | |
1453 | "sm501-system-config", 0x6c); | |
1454 | memory_region_add_subregion(&s->mmio_region, SM501_SYS_CONFIG, | |
1455 | &s->system_config_region); | |
1456 | memory_region_init_io(&s->disp_ctrl_region, OBJECT(dev), | |
1457 | &sm501_disp_ctrl_ops, s, | |
25793bfa | 1458 | "sm501-disp-ctrl", 0x1000); |
ca8a1104 BZ |
1459 | memory_region_add_subregion(&s->mmio_region, SM501_DC, |
1460 | &s->disp_ctrl_region); | |
1461 | memory_region_init_io(&s->twoD_engine_region, OBJECT(dev), | |
1462 | &sm501_2d_engine_ops, s, | |
25793bfa | 1463 | "sm501-2d-engine", 0x54); |
ca8a1104 BZ |
1464 | memory_region_add_subregion(&s->mmio_region, SM501_2D_ENGINE, |
1465 | &s->twoD_engine_region); | |
1466 | ||
1467 | /* create qemu graphic console */ | |
1468 | s->con = graphic_console_init(DEVICE(dev), 0, &sm501_ops, s); | |
1469 | } | |
1470 | ||
1471 | #define TYPE_SYSBUS_SM501 "sysbus-sm501" | |
1472 | #define SYSBUS_SM501(obj) \ | |
1473 | OBJECT_CHECK(SM501SysBusState, (obj), TYPE_SYSBUS_SM501) | |
1474 | ||
1475 | typedef struct { | |
1476 | /*< private >*/ | |
1477 | SysBusDevice parent_obj; | |
1478 | /*< public >*/ | |
1479 | SM501State state; | |
1480 | uint32_t vram_size; | |
1481 | uint32_t base; | |
1482 | void *chr_state; | |
1483 | } SM501SysBusState; | |
1484 | ||
1485 | static void sm501_realize_sysbus(DeviceState *dev, Error **errp) | |
1486 | { | |
1487 | SM501SysBusState *s = SYSBUS_SM501(dev); | |
1488 | SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | |
1489 | DeviceState *usb_dev; | |
1490 | ||
c795fa84 | 1491 | sm501_init(&s->state, dev, s->vram_size); |
ca8a1104 BZ |
1492 | if (get_local_mem_size(&s->state) != s->vram_size) { |
1493 | error_setg(errp, "Invalid VRAM size, nearest valid size is %" PRIu32, | |
1494 | get_local_mem_size(&s->state)); | |
1495 | return; | |
1496 | } | |
1497 | sysbus_init_mmio(sbd, &s->state.local_mem_region); | |
1498 | sysbus_init_mmio(sbd, &s->state.mmio_region); | |
ffd39257 | 1499 | |
ac611340 | 1500 | /* bridge to usb host emulation module */ |
ca8a1104 BZ |
1501 | usb_dev = qdev_create(NULL, "sysbus-ohci"); |
1502 | qdev_prop_set_uint32(usb_dev, "num-ports", 2); | |
1503 | qdev_prop_set_uint64(usb_dev, "dma-offset", s->base); | |
1504 | qdev_init_nofail(usb_dev); | |
1505 | memory_region_add_subregion(&s->state.mmio_region, SM501_USB_HOST, | |
1506 | sysbus_mmio_get_region(SYS_BUS_DEVICE(usb_dev), 0)); | |
1507 | sysbus_pass_irq(sbd, SYS_BUS_DEVICE(usb_dev)); | |
ac611340 | 1508 | |
ffd39257 | 1509 | /* bridge to serial emulation module */ |
ca8a1104 BZ |
1510 | if (s->chr_state) { |
1511 | serial_mm_init(&s->state.mmio_region, SM501_UART0, 2, | |
2d48377a | 1512 | NULL, /* TODO : chain irq to IRL */ |
ca8a1104 | 1513 | 115200, s->chr_state, DEVICE_NATIVE_ENDIAN); |
2d48377a | 1514 | } |
ca8a1104 | 1515 | } |
ffd39257 | 1516 | |
ca8a1104 BZ |
1517 | static Property sm501_sysbus_properties[] = { |
1518 | DEFINE_PROP_UINT32("vram-size", SM501SysBusState, vram_size, 0), | |
1519 | DEFINE_PROP_UINT32("base", SM501SysBusState, base, 0), | |
1520 | DEFINE_PROP_PTR("chr-state", SM501SysBusState, chr_state), | |
1521 | DEFINE_PROP_END_OF_LIST(), | |
1522 | }; | |
1523 | ||
1524 | static void sm501_reset_sysbus(DeviceState *dev) | |
1525 | { | |
1526 | SM501SysBusState *s = SYSBUS_SM501(dev); | |
1527 | sm501_reset(&s->state); | |
ffd39257 | 1528 | } |
ca8a1104 BZ |
1529 | |
1530 | static void sm501_sysbus_class_init(ObjectClass *klass, void *data) | |
1531 | { | |
1532 | DeviceClass *dc = DEVICE_CLASS(klass); | |
1533 | ||
1534 | dc->realize = sm501_realize_sysbus; | |
1535 | set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); | |
1536 | dc->desc = "SM501 Multimedia Companion"; | |
1537 | dc->props = sm501_sysbus_properties; | |
1538 | dc->reset = sm501_reset_sysbus; | |
1539 | /* Note: pointer property "chr-state" may remain null, thus | |
1540 | * no need for dc->cannot_instantiate_with_device_add_yet = true; | |
1541 | */ | |
1542 | } | |
1543 | ||
1544 | static const TypeInfo sm501_sysbus_info = { | |
1545 | .name = TYPE_SYSBUS_SM501, | |
1546 | .parent = TYPE_SYS_BUS_DEVICE, | |
1547 | .instance_size = sizeof(SM501SysBusState), | |
1548 | .class_init = sm501_sysbus_class_init, | |
1549 | }; | |
1550 | ||
efae2784 BZ |
1551 | #define TYPE_PCI_SM501 "sm501" |
1552 | #define PCI_SM501(obj) OBJECT_CHECK(SM501PCIState, (obj), TYPE_PCI_SM501) | |
1553 | ||
1554 | typedef struct { | |
1555 | /*< private >*/ | |
1556 | PCIDevice parent_obj; | |
1557 | /*< public >*/ | |
1558 | SM501State state; | |
1559 | uint32_t vram_size; | |
1560 | } SM501PCIState; | |
1561 | ||
1562 | static void sm501_realize_pci(PCIDevice *dev, Error **errp) | |
1563 | { | |
1564 | SM501PCIState *s = PCI_SM501(dev); | |
1565 | ||
1566 | sm501_init(&s->state, DEVICE(dev), s->vram_size); | |
1567 | if (get_local_mem_size(&s->state) != s->vram_size) { | |
1568 | error_setg(errp, "Invalid VRAM size, nearest valid size is %" PRIu32, | |
1569 | get_local_mem_size(&s->state)); | |
1570 | return; | |
1571 | } | |
1572 | pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, | |
1573 | &s->state.local_mem_region); | |
1574 | pci_register_bar(dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY, | |
1575 | &s->state.mmio_region); | |
1576 | } | |
1577 | ||
1578 | static Property sm501_pci_properties[] = { | |
1579 | DEFINE_PROP_UINT32("vram-size", SM501PCIState, vram_size, 64 * M_BYTE), | |
1580 | DEFINE_PROP_END_OF_LIST(), | |
1581 | }; | |
1582 | ||
1583 | static void sm501_reset_pci(DeviceState *dev) | |
1584 | { | |
1585 | SM501PCIState *s = PCI_SM501(dev); | |
1586 | sm501_reset(&s->state); | |
1587 | /* Bits 2:0 of misc_control register is 001 for PCI */ | |
1588 | s->state.misc_control |= 1; | |
1589 | } | |
1590 | ||
1591 | static void sm501_pci_class_init(ObjectClass *klass, void *data) | |
1592 | { | |
1593 | DeviceClass *dc = DEVICE_CLASS(klass); | |
1594 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); | |
1595 | ||
1596 | k->realize = sm501_realize_pci; | |
1597 | k->vendor_id = PCI_VENDOR_ID_SILICON_MOTION; | |
1598 | k->device_id = PCI_DEVICE_ID_SM501; | |
1599 | k->class_id = PCI_CLASS_DISPLAY_OTHER; | |
1600 | set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); | |
1601 | dc->desc = "SM501 Display Controller"; | |
1602 | dc->props = sm501_pci_properties; | |
1603 | dc->reset = sm501_reset_pci; | |
1604 | dc->hotpluggable = false; | |
1605 | } | |
1606 | ||
1607 | static const TypeInfo sm501_pci_info = { | |
1608 | .name = TYPE_PCI_SM501, | |
1609 | .parent = TYPE_PCI_DEVICE, | |
1610 | .instance_size = sizeof(SM501PCIState), | |
1611 | .class_init = sm501_pci_class_init, | |
1612 | }; | |
1613 | ||
ca8a1104 BZ |
1614 | static void sm501_register_types(void) |
1615 | { | |
1616 | type_register_static(&sm501_sysbus_info); | |
efae2784 | 1617 | type_register_static(&sm501_pci_info); |
ca8a1104 BZ |
1618 | } |
1619 | ||
1620 | type_init(sm501_register_types) |