xref: /qemu/hw/display/ati.c (revision c026350a842a02c225e3ecbcda5c298e70e37a62)
1862b4a29SBALATON Zoltan /*
2862b4a29SBALATON Zoltan  * QEMU ATI SVGA emulation
3862b4a29SBALATON Zoltan  *
4862b4a29SBALATON Zoltan  * Copyright (c) 2019 BALATON Zoltan
5862b4a29SBALATON Zoltan  *
6862b4a29SBALATON Zoltan  * This work is licensed under the GNU GPL license version 2 or later.
7862b4a29SBALATON Zoltan  */
8862b4a29SBALATON Zoltan 
9862b4a29SBALATON Zoltan /*
10862b4a29SBALATON Zoltan  * WARNING:
11862b4a29SBALATON Zoltan  * This is very incomplete and only enough for Linux console and some
12862b4a29SBALATON Zoltan  * unaccelerated X output at the moment.
13862b4a29SBALATON Zoltan  * Currently it's little more than a frame buffer with minimal functions,
14862b4a29SBALATON Zoltan  * other more advanced features of the hardware are yet to be implemented.
15862b4a29SBALATON Zoltan  * We only aim for Rage 128 Pro (and some RV100) and 2D only at first,
16862b4a29SBALATON Zoltan  * No 3D at all yet (maybe after 2D works, but feel free to improve it)
17862b4a29SBALATON Zoltan  */
18862b4a29SBALATON Zoltan 
19bbfff196SMarkus Armbruster #include "qemu/osdep.h"
20862b4a29SBALATON Zoltan #include "ati_int.h"
21862b4a29SBALATON Zoltan #include "ati_regs.h"
22a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
23862b4a29SBALATON Zoltan #include "vga_regs.h"
24862b4a29SBALATON Zoltan #include "qemu/log.h"
250b8fa32fSMarkus Armbruster #include "qemu/module.h"
26862b4a29SBALATON Zoltan #include "qemu/error-report.h"
27862b4a29SBALATON Zoltan #include "qapi/error.h"
28862b4a29SBALATON Zoltan #include "ui/console.h"
29c82c7336SBALATON Zoltan #include "hw/display/i2c-ddc.h"
30862b4a29SBALATON Zoltan #include "trace.h"
31862b4a29SBALATON Zoltan 
32862b4a29SBALATON Zoltan #define ATI_DEBUG_HW_CURSOR 0
33862b4a29SBALATON Zoltan 
34862b4a29SBALATON Zoltan static const struct {
35862b4a29SBALATON Zoltan     const char *name;
36862b4a29SBALATON Zoltan     uint16_t dev_id;
37862b4a29SBALATON Zoltan } ati_model_aliases[] = {
38862b4a29SBALATON Zoltan     { "rage128p", PCI_DEVICE_ID_ATI_RAGE128_PF },
39862b4a29SBALATON Zoltan     { "rv100", PCI_DEVICE_ID_ATI_RADEON_QY },
40862b4a29SBALATON Zoltan };
41862b4a29SBALATON Zoltan 
42862b4a29SBALATON Zoltan enum { VGA_MODE, EXT_MODE };
43862b4a29SBALATON Zoltan 
44862b4a29SBALATON Zoltan static void ati_vga_switch_mode(ATIVGAState *s)
45862b4a29SBALATON Zoltan {
46862b4a29SBALATON Zoltan     DPRINTF("%d -> %d\n",
47862b4a29SBALATON Zoltan             s->mode, !!(s->regs.crtc_gen_cntl & CRTC2_EXT_DISP_EN));
48862b4a29SBALATON Zoltan     if (s->regs.crtc_gen_cntl & CRTC2_EXT_DISP_EN) {
49862b4a29SBALATON Zoltan         /* Extended mode enabled */
50862b4a29SBALATON Zoltan         s->mode = EXT_MODE;
51862b4a29SBALATON Zoltan         if (s->regs.crtc_gen_cntl & CRTC2_EN) {
52862b4a29SBALATON Zoltan             /* CRT controller enabled, use CRTC values */
53*c026350aSBALATON Zoltan             /* FIXME Should these be the same as VGA CRTC regs? */
54862b4a29SBALATON Zoltan             uint32_t offs = s->regs.crtc_offset & 0x07ffffff;
55862b4a29SBALATON Zoltan             int stride = (s->regs.crtc_pitch & 0x7ff) * 8;
56862b4a29SBALATON Zoltan             int bpp = 0;
57862b4a29SBALATON Zoltan             int h, v;
58862b4a29SBALATON Zoltan 
59862b4a29SBALATON Zoltan             if (s->regs.crtc_h_total_disp == 0) {
60862b4a29SBALATON Zoltan                 s->regs.crtc_h_total_disp = ((640 / 8) - 1) << 16;
61862b4a29SBALATON Zoltan             }
62862b4a29SBALATON Zoltan             if (s->regs.crtc_v_total_disp == 0) {
63862b4a29SBALATON Zoltan                 s->regs.crtc_v_total_disp = (480 - 1) << 16;
64862b4a29SBALATON Zoltan             }
65862b4a29SBALATON Zoltan             h = ((s->regs.crtc_h_total_disp >> 16) + 1) * 8;
66862b4a29SBALATON Zoltan             v = (s->regs.crtc_v_total_disp >> 16) + 1;
67862b4a29SBALATON Zoltan             switch (s->regs.crtc_gen_cntl & CRTC_PIX_WIDTH_MASK) {
68862b4a29SBALATON Zoltan             case CRTC_PIX_WIDTH_4BPP:
69862b4a29SBALATON Zoltan                 bpp = 4;
70862b4a29SBALATON Zoltan                 break;
71862b4a29SBALATON Zoltan             case CRTC_PIX_WIDTH_8BPP:
72862b4a29SBALATON Zoltan                 bpp = 8;
73862b4a29SBALATON Zoltan                 break;
74862b4a29SBALATON Zoltan             case CRTC_PIX_WIDTH_15BPP:
75862b4a29SBALATON Zoltan                 bpp = 15;
76862b4a29SBALATON Zoltan                 break;
77862b4a29SBALATON Zoltan             case CRTC_PIX_WIDTH_16BPP:
78862b4a29SBALATON Zoltan                 bpp = 16;
79862b4a29SBALATON Zoltan                 break;
80862b4a29SBALATON Zoltan             case CRTC_PIX_WIDTH_24BPP:
81862b4a29SBALATON Zoltan                 bpp = 24;
82862b4a29SBALATON Zoltan                 break;
83862b4a29SBALATON Zoltan             case CRTC_PIX_WIDTH_32BPP:
84862b4a29SBALATON Zoltan                 bpp = 32;
85862b4a29SBALATON Zoltan                 break;
86862b4a29SBALATON Zoltan             default:
87862b4a29SBALATON Zoltan                 qemu_log_mask(LOG_UNIMP, "Unsupported bpp value\n");
88862b4a29SBALATON Zoltan             }
89862b4a29SBALATON Zoltan             assert(bpp != 0);
90862b4a29SBALATON Zoltan             DPRINTF("Switching to %dx%d %d %d @ %x\n", h, v, stride, bpp, offs);
91862b4a29SBALATON Zoltan             vbe_ioport_write_index(&s->vga, 0, VBE_DISPI_INDEX_ENABLE);
92862b4a29SBALATON Zoltan             vbe_ioport_write_data(&s->vga, 0, VBE_DISPI_DISABLED);
93a3812741SBALATON Zoltan             s->vga.big_endian_fb = false;
94862b4a29SBALATON Zoltan             /* reset VBE regs then set up mode */
95862b4a29SBALATON Zoltan             s->vga.vbe_regs[VBE_DISPI_INDEX_XRES] = h;
96862b4a29SBALATON Zoltan             s->vga.vbe_regs[VBE_DISPI_INDEX_YRES] = v;
97862b4a29SBALATON Zoltan             s->vga.vbe_regs[VBE_DISPI_INDEX_BPP] = bpp;
98862b4a29SBALATON Zoltan             /* enable mode via ioport so it updates vga regs */
99862b4a29SBALATON Zoltan             vbe_ioport_write_index(&s->vga, 0, VBE_DISPI_INDEX_ENABLE);
100862b4a29SBALATON Zoltan             vbe_ioport_write_data(&s->vga, 0, VBE_DISPI_ENABLED |
101862b4a29SBALATON Zoltan                 VBE_DISPI_LFB_ENABLED | VBE_DISPI_NOCLEARMEM |
102862b4a29SBALATON Zoltan                 (s->regs.dac_cntl & DAC_8BIT_EN ? VBE_DISPI_8BIT_DAC : 0));
103862b4a29SBALATON Zoltan             /* now set offset and stride after enable as that resets these */
104862b4a29SBALATON Zoltan             if (stride) {
105*c026350aSBALATON Zoltan                 int bypp = DIV_ROUND_UP(bpp, BITS_PER_BYTE);
106*c026350aSBALATON Zoltan 
107862b4a29SBALATON Zoltan                 vbe_ioport_write_index(&s->vga, 0, VBE_DISPI_INDEX_VIRT_WIDTH);
108862b4a29SBALATON Zoltan                 vbe_ioport_write_data(&s->vga, 0, stride);
109*c026350aSBALATON Zoltan                 stride *= bypp;
110*c026350aSBALATON Zoltan                 if (offs % stride) {
111*c026350aSBALATON Zoltan                     DPRINTF("CRTC offset is not multiple of pitch\n");
112*c026350aSBALATON Zoltan                     vbe_ioport_write_index(&s->vga, 0,
113*c026350aSBALATON Zoltan                                            VBE_DISPI_INDEX_X_OFFSET);
114*c026350aSBALATON Zoltan                     vbe_ioport_write_data(&s->vga, 0, offs % stride / bypp);
115*c026350aSBALATON Zoltan                 }
116862b4a29SBALATON Zoltan                 vbe_ioport_write_index(&s->vga, 0, VBE_DISPI_INDEX_Y_OFFSET);
117862b4a29SBALATON Zoltan                 vbe_ioport_write_data(&s->vga, 0, offs / stride);
118*c026350aSBALATON Zoltan                 DPRINTF("VBE offset (%d,%d), vbe_start_addr=%x\n",
119*c026350aSBALATON Zoltan                         s->vga.vbe_regs[VBE_DISPI_INDEX_X_OFFSET],
120*c026350aSBALATON Zoltan                         s->vga.vbe_regs[VBE_DISPI_INDEX_Y_OFFSET],
121*c026350aSBALATON Zoltan                         s->vga.vbe_start_addr);
122862b4a29SBALATON Zoltan             }
123862b4a29SBALATON Zoltan         }
124862b4a29SBALATON Zoltan     } else {
125862b4a29SBALATON Zoltan         /* VGA mode enabled */
126862b4a29SBALATON Zoltan         s->mode = VGA_MODE;
127862b4a29SBALATON Zoltan         vbe_ioport_write_index(&s->vga, 0, VBE_DISPI_INDEX_ENABLE);
128862b4a29SBALATON Zoltan         vbe_ioport_write_data(&s->vga, 0, VBE_DISPI_DISABLED);
129862b4a29SBALATON Zoltan     }
130862b4a29SBALATON Zoltan }
131862b4a29SBALATON Zoltan 
132862b4a29SBALATON Zoltan /* Used by host side hardware cursor */
133862b4a29SBALATON Zoltan static void ati_cursor_define(ATIVGAState *s)
134862b4a29SBALATON Zoltan {
135862b4a29SBALATON Zoltan     uint8_t data[1024];
136862b4a29SBALATON Zoltan     uint8_t *src;
137862b4a29SBALATON Zoltan     int i, j, idx = 0;
138862b4a29SBALATON Zoltan 
139862b4a29SBALATON Zoltan     if ((s->regs.cur_offset & BIT(31)) || s->cursor_guest_mode) {
140862b4a29SBALATON Zoltan         return; /* Do not update cursor if locked or rendered by guest */
141862b4a29SBALATON Zoltan     }
142862b4a29SBALATON Zoltan     /* FIXME handle cur_hv_offs correctly */
143747d7ad2SBALATON Zoltan     src = s->vga.vram_ptr + s->regs.cur_offset -
144747d7ad2SBALATON Zoltan           (s->regs.cur_hv_offs >> 16) - (s->regs.cur_hv_offs & 0xffff) * 16;
145862b4a29SBALATON Zoltan     for (i = 0; i < 64; i++) {
146862b4a29SBALATON Zoltan         for (j = 0; j < 8; j++, idx++) {
147862b4a29SBALATON Zoltan             data[idx] = src[i * 16 + j];
148862b4a29SBALATON Zoltan             data[512 + idx] = src[i * 16 + j + 8];
149862b4a29SBALATON Zoltan         }
150862b4a29SBALATON Zoltan     }
151862b4a29SBALATON Zoltan     if (!s->cursor) {
152862b4a29SBALATON Zoltan         s->cursor = cursor_alloc(64, 64);
153862b4a29SBALATON Zoltan     }
154862b4a29SBALATON Zoltan     cursor_set_mono(s->cursor, s->regs.cur_color1, s->regs.cur_color0,
155862b4a29SBALATON Zoltan                     &data[512], 1, &data[0]);
156862b4a29SBALATON Zoltan     dpy_cursor_define(s->vga.con, s->cursor);
157862b4a29SBALATON Zoltan }
158862b4a29SBALATON Zoltan 
159862b4a29SBALATON Zoltan /* Alternatively support guest rendered hardware cursor */
160862b4a29SBALATON Zoltan static void ati_cursor_invalidate(VGACommonState *vga)
161862b4a29SBALATON Zoltan {
162862b4a29SBALATON Zoltan     ATIVGAState *s = container_of(vga, ATIVGAState, vga);
163862b4a29SBALATON Zoltan     int size = (s->regs.crtc_gen_cntl & CRTC2_CUR_EN) ? 64 : 0;
164862b4a29SBALATON Zoltan 
165862b4a29SBALATON Zoltan     if (s->regs.cur_offset & BIT(31)) {
166862b4a29SBALATON Zoltan         return; /* Do not update cursor if locked */
167862b4a29SBALATON Zoltan     }
168862b4a29SBALATON Zoltan     if (s->cursor_size != size ||
169862b4a29SBALATON Zoltan         vga->hw_cursor_x != s->regs.cur_hv_pos >> 16 ||
170862b4a29SBALATON Zoltan         vga->hw_cursor_y != (s->regs.cur_hv_pos & 0xffff) ||
171862b4a29SBALATON Zoltan         s->cursor_offset != s->regs.cur_offset - (s->regs.cur_hv_offs >> 16) -
172862b4a29SBALATON Zoltan         (s->regs.cur_hv_offs & 0xffff) * 16) {
173862b4a29SBALATON Zoltan         /* Remove old cursor then update and show new one if needed */
174862b4a29SBALATON Zoltan         vga_invalidate_scanlines(vga, vga->hw_cursor_y, vga->hw_cursor_y + 63);
175862b4a29SBALATON Zoltan         vga->hw_cursor_x = s->regs.cur_hv_pos >> 16;
176862b4a29SBALATON Zoltan         vga->hw_cursor_y = s->regs.cur_hv_pos & 0xffff;
177862b4a29SBALATON Zoltan         s->cursor_offset = s->regs.cur_offset - (s->regs.cur_hv_offs >> 16) -
178862b4a29SBALATON Zoltan                            (s->regs.cur_hv_offs & 0xffff) * 16;
179862b4a29SBALATON Zoltan         s->cursor_size = size;
180862b4a29SBALATON Zoltan         if (size) {
181862b4a29SBALATON Zoltan             vga_invalidate_scanlines(vga,
182862b4a29SBALATON Zoltan                                      vga->hw_cursor_y, vga->hw_cursor_y + 63);
183862b4a29SBALATON Zoltan         }
184862b4a29SBALATON Zoltan     }
185862b4a29SBALATON Zoltan }
186862b4a29SBALATON Zoltan 
187862b4a29SBALATON Zoltan static void ati_cursor_draw_line(VGACommonState *vga, uint8_t *d, int scr_y)
188862b4a29SBALATON Zoltan {
189862b4a29SBALATON Zoltan     ATIVGAState *s = container_of(vga, ATIVGAState, vga);
190862b4a29SBALATON Zoltan     uint8_t *src;
191862b4a29SBALATON Zoltan     uint32_t *dp = (uint32_t *)d;
192862b4a29SBALATON Zoltan     int i, j, h;
193862b4a29SBALATON Zoltan 
194862b4a29SBALATON Zoltan     if (!(s->regs.crtc_gen_cntl & CRTC2_CUR_EN) ||
195862b4a29SBALATON Zoltan         scr_y < vga->hw_cursor_y || scr_y >= vga->hw_cursor_y + 64 ||
196862b4a29SBALATON Zoltan         scr_y > s->regs.crtc_v_total_disp >> 16) {
197862b4a29SBALATON Zoltan         return;
198862b4a29SBALATON Zoltan     }
199862b4a29SBALATON Zoltan     /* FIXME handle cur_hv_offs correctly */
200747d7ad2SBALATON Zoltan     src = s->vga.vram_ptr + s->cursor_offset + (scr_y - vga->hw_cursor_y) * 16;
201862b4a29SBALATON Zoltan     dp = &dp[vga->hw_cursor_x];
202862b4a29SBALATON Zoltan     h = ((s->regs.crtc_h_total_disp >> 16) + 1) * 8;
203862b4a29SBALATON Zoltan     for (i = 0; i < 8; i++) {
204862b4a29SBALATON Zoltan         uint32_t color;
205862b4a29SBALATON Zoltan         uint8_t abits = src[i];
206862b4a29SBALATON Zoltan         uint8_t xbits = src[i + 8];
207862b4a29SBALATON Zoltan         for (j = 0; j < 8; j++, abits <<= 1, xbits <<= 1) {
208862b4a29SBALATON Zoltan             if (abits & BIT(7)) {
209862b4a29SBALATON Zoltan                 if (xbits & BIT(7)) {
210862b4a29SBALATON Zoltan                     color = dp[i * 8 + j] ^ 0xffffffff; /* complement */
211862b4a29SBALATON Zoltan                 } else {
212862b4a29SBALATON Zoltan                     continue; /* transparent, no change */
213862b4a29SBALATON Zoltan                 }
214862b4a29SBALATON Zoltan             } else {
215862b4a29SBALATON Zoltan                 color = (xbits & BIT(7) ? s->regs.cur_color1 :
21650bc6af5SBALATON Zoltan                                           s->regs.cur_color0) | 0xff000000;
217862b4a29SBALATON Zoltan             }
218862b4a29SBALATON Zoltan             if (vga->hw_cursor_x + i * 8 + j >= h) {
219862b4a29SBALATON Zoltan                 return; /* end of screen, don't span to next line */
220862b4a29SBALATON Zoltan             }
221862b4a29SBALATON Zoltan             dp[i * 8 + j] = color;
222862b4a29SBALATON Zoltan         }
223862b4a29SBALATON Zoltan     }
224862b4a29SBALATON Zoltan }
225862b4a29SBALATON Zoltan 
226c82c7336SBALATON Zoltan static uint64_t ati_i2c(bitbang_i2c_interface *i2c, uint64_t data, int base)
227c82c7336SBALATON Zoltan {
228c82c7336SBALATON Zoltan     bool c = (data & BIT(base + 17) ? !!(data & BIT(base + 1)) : 1);
229c82c7336SBALATON Zoltan     bool d = (data & BIT(base + 16) ? !!(data & BIT(base)) : 1);
230c82c7336SBALATON Zoltan 
231c82c7336SBALATON Zoltan     bitbang_i2c_set(i2c, BITBANG_I2C_SCL, c);
232c82c7336SBALATON Zoltan     d = bitbang_i2c_set(i2c, BITBANG_I2C_SDA, d);
233c82c7336SBALATON Zoltan 
234c82c7336SBALATON Zoltan     data &= ~0xf00ULL;
235c82c7336SBALATON Zoltan     if (c) {
236c82c7336SBALATON Zoltan         data |= BIT(base + 9);
237c82c7336SBALATON Zoltan     }
238c82c7336SBALATON Zoltan     if (d) {
239c82c7336SBALATON Zoltan         data |= BIT(base + 8);
240c82c7336SBALATON Zoltan     }
241c82c7336SBALATON Zoltan     return data;
242c82c7336SBALATON Zoltan }
243c82c7336SBALATON Zoltan 
244862b4a29SBALATON Zoltan static inline uint64_t ati_reg_read_offs(uint32_t reg, int offs,
245862b4a29SBALATON Zoltan                                          unsigned int size)
246862b4a29SBALATON Zoltan {
247862b4a29SBALATON Zoltan     if (offs == 0 && size == 4) {
248862b4a29SBALATON Zoltan         return reg;
249862b4a29SBALATON Zoltan     } else {
250862b4a29SBALATON Zoltan         return extract32(reg, offs * BITS_PER_BYTE, size * BITS_PER_BYTE);
251862b4a29SBALATON Zoltan     }
252862b4a29SBALATON Zoltan }
253862b4a29SBALATON Zoltan 
254862b4a29SBALATON Zoltan static uint64_t ati_mm_read(void *opaque, hwaddr addr, unsigned int size)
255862b4a29SBALATON Zoltan {
256862b4a29SBALATON Zoltan     ATIVGAState *s = opaque;
257862b4a29SBALATON Zoltan     uint64_t val = 0;
258862b4a29SBALATON Zoltan 
259862b4a29SBALATON Zoltan     switch (addr) {
260862b4a29SBALATON Zoltan     case MM_INDEX:
261862b4a29SBALATON Zoltan         val = s->regs.mm_index;
262862b4a29SBALATON Zoltan         break;
263862b4a29SBALATON Zoltan     case MM_DATA ... MM_DATA + 3:
264862b4a29SBALATON Zoltan         /* indexed access to regs or memory */
265862b4a29SBALATON Zoltan         if (s->regs.mm_index & BIT(31)) {
266339534d4SBALATON Zoltan             uint32_t idx = s->regs.mm_index & ~BIT(31);
267339534d4SBALATON Zoltan             if (idx <= s->vga.vram_size - size) {
268339534d4SBALATON Zoltan                 val = ldn_le_p(s->vga.vram_ptr + idx, size);
269862b4a29SBALATON Zoltan             }
270862b4a29SBALATON Zoltan         } else {
271862b4a29SBALATON Zoltan             val = ati_mm_read(s, s->regs.mm_index + addr - MM_DATA, size);
272862b4a29SBALATON Zoltan         }
273862b4a29SBALATON Zoltan         break;
274862b4a29SBALATON Zoltan     case BIOS_0_SCRATCH ... BUS_CNTL - 1:
275862b4a29SBALATON Zoltan     {
276862b4a29SBALATON Zoltan         int i = (addr - BIOS_0_SCRATCH) / 4;
277862b4a29SBALATON Zoltan         if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF && i > 3) {
278862b4a29SBALATON Zoltan             break;
279862b4a29SBALATON Zoltan         }
280862b4a29SBALATON Zoltan         val = ati_reg_read_offs(s->regs.bios_scratch[i],
281862b4a29SBALATON Zoltan                                 addr - (BIOS_0_SCRATCH + i * 4), size);
282862b4a29SBALATON Zoltan         break;
283862b4a29SBALATON Zoltan     }
284862b4a29SBALATON Zoltan     case CRTC_GEN_CNTL ... CRTC_GEN_CNTL + 3:
285862b4a29SBALATON Zoltan         val = ati_reg_read_offs(s->regs.crtc_gen_cntl,
286862b4a29SBALATON Zoltan                                 addr - CRTC_GEN_CNTL, size);
287862b4a29SBALATON Zoltan         break;
288862b4a29SBALATON Zoltan     case CRTC_EXT_CNTL ... CRTC_EXT_CNTL + 3:
289862b4a29SBALATON Zoltan         val = ati_reg_read_offs(s->regs.crtc_ext_cntl,
290862b4a29SBALATON Zoltan                                 addr - CRTC_EXT_CNTL, size);
291862b4a29SBALATON Zoltan         break;
292862b4a29SBALATON Zoltan     case DAC_CNTL:
293862b4a29SBALATON Zoltan         val = s->regs.dac_cntl;
294862b4a29SBALATON Zoltan         break;
295c82c7336SBALATON Zoltan     case GPIO_VGA_DDC:
296c82c7336SBALATON Zoltan         val = s->regs.gpio_vga_ddc;
297c82c7336SBALATON Zoltan         break;
298c82c7336SBALATON Zoltan     case GPIO_DVI_DDC:
299c82c7336SBALATON Zoltan         val = s->regs.gpio_dvi_ddc;
300c82c7336SBALATON Zoltan         break;
301c82c7336SBALATON Zoltan     case GPIO_MONID ... GPIO_MONID + 3:
302c82c7336SBALATON Zoltan         val = ati_reg_read_offs(s->regs.gpio_monid,
303c82c7336SBALATON Zoltan                                 addr - GPIO_MONID, size);
304c82c7336SBALATON Zoltan         break;
305862b4a29SBALATON Zoltan     case PALETTE_INDEX:
306862b4a29SBALATON Zoltan         /* FIXME unaligned access */
307862b4a29SBALATON Zoltan         val = vga_ioport_read(&s->vga, VGA_PEL_IR) << 16;
308862b4a29SBALATON Zoltan         val |= vga_ioport_read(&s->vga, VGA_PEL_IW) & 0xff;
309862b4a29SBALATON Zoltan         break;
310862b4a29SBALATON Zoltan     case PALETTE_DATA:
311862b4a29SBALATON Zoltan         val = vga_ioport_read(&s->vga, VGA_PEL_D);
312862b4a29SBALATON Zoltan         break;
313862b4a29SBALATON Zoltan     case CNFG_MEMSIZE:
314862b4a29SBALATON Zoltan         val = s->vga.vram_size;
315862b4a29SBALATON Zoltan         break;
3161d8d4d86SBALATON Zoltan     case CONFIG_APER_0_BASE:
3171d8d4d86SBALATON Zoltan     case CONFIG_APER_1_BASE:
3181d8d4d86SBALATON Zoltan         val = pci_default_read_config(&s->dev,
3191d8d4d86SBALATON Zoltan                                       PCI_BASE_ADDRESS_0, size) & 0xfffffff0;
3201d8d4d86SBALATON Zoltan         break;
3211d8d4d86SBALATON Zoltan     case CONFIG_APER_SIZE:
3221d8d4d86SBALATON Zoltan         val = s->vga.vram_size;
3231d8d4d86SBALATON Zoltan         break;
3241d8d4d86SBALATON Zoltan     case CONFIG_REG_1_BASE:
3251d8d4d86SBALATON Zoltan         val = pci_default_read_config(&s->dev,
3261d8d4d86SBALATON Zoltan                                       PCI_BASE_ADDRESS_2, size) & 0xfffffff0;
3271d8d4d86SBALATON Zoltan         break;
3281d8d4d86SBALATON Zoltan     case CONFIG_REG_APER_SIZE:
3291d8d4d86SBALATON Zoltan         val = memory_region_size(&s->mm);
3301d8d4d86SBALATON Zoltan         break;
331862b4a29SBALATON Zoltan     case MC_STATUS:
332862b4a29SBALATON Zoltan         val = 5;
333862b4a29SBALATON Zoltan         break;
334862b4a29SBALATON Zoltan     case RBBM_STATUS:
335862b4a29SBALATON Zoltan     case GUI_STAT:
336862b4a29SBALATON Zoltan         val = 64; /* free CMDFIFO entries */
337862b4a29SBALATON Zoltan         break;
338862b4a29SBALATON Zoltan     case CRTC_H_TOTAL_DISP:
339862b4a29SBALATON Zoltan         val = s->regs.crtc_h_total_disp;
340862b4a29SBALATON Zoltan         break;
341862b4a29SBALATON Zoltan     case CRTC_H_SYNC_STRT_WID:
342862b4a29SBALATON Zoltan         val = s->regs.crtc_h_sync_strt_wid;
343862b4a29SBALATON Zoltan         break;
344862b4a29SBALATON Zoltan     case CRTC_V_TOTAL_DISP:
345862b4a29SBALATON Zoltan         val = s->regs.crtc_v_total_disp;
346862b4a29SBALATON Zoltan         break;
347862b4a29SBALATON Zoltan     case CRTC_V_SYNC_STRT_WID:
348862b4a29SBALATON Zoltan         val = s->regs.crtc_v_sync_strt_wid;
349862b4a29SBALATON Zoltan         break;
350862b4a29SBALATON Zoltan     case CRTC_OFFSET:
351862b4a29SBALATON Zoltan         val = s->regs.crtc_offset;
352862b4a29SBALATON Zoltan         break;
353862b4a29SBALATON Zoltan     case CRTC_OFFSET_CNTL:
354862b4a29SBALATON Zoltan         val = s->regs.crtc_offset_cntl;
355862b4a29SBALATON Zoltan         break;
356862b4a29SBALATON Zoltan     case CRTC_PITCH:
357862b4a29SBALATON Zoltan         val = s->regs.crtc_pitch;
358862b4a29SBALATON Zoltan         break;
359862b4a29SBALATON Zoltan     case 0xf00 ... 0xfff:
360862b4a29SBALATON Zoltan         val = pci_default_read_config(&s->dev, addr - 0xf00, size);
361862b4a29SBALATON Zoltan         break;
362862b4a29SBALATON Zoltan     case CUR_OFFSET:
363862b4a29SBALATON Zoltan         val = s->regs.cur_offset;
364862b4a29SBALATON Zoltan         break;
365862b4a29SBALATON Zoltan     case CUR_HORZ_VERT_POSN:
366862b4a29SBALATON Zoltan         val = s->regs.cur_hv_pos;
367862b4a29SBALATON Zoltan         val |= s->regs.cur_offset & BIT(31);
368862b4a29SBALATON Zoltan         break;
369862b4a29SBALATON Zoltan     case CUR_HORZ_VERT_OFF:
370862b4a29SBALATON Zoltan         val = s->regs.cur_hv_offs;
371862b4a29SBALATON Zoltan         val |= s->regs.cur_offset & BIT(31);
372862b4a29SBALATON Zoltan         break;
373862b4a29SBALATON Zoltan     case CUR_CLR0:
374862b4a29SBALATON Zoltan         val = s->regs.cur_color0;
375862b4a29SBALATON Zoltan         break;
376862b4a29SBALATON Zoltan     case CUR_CLR1:
377862b4a29SBALATON Zoltan         val = s->regs.cur_color1;
378862b4a29SBALATON Zoltan         break;
379862b4a29SBALATON Zoltan     case DST_OFFSET:
380862b4a29SBALATON Zoltan         val = s->regs.dst_offset;
381862b4a29SBALATON Zoltan         break;
382862b4a29SBALATON Zoltan     case DST_PITCH:
383862b4a29SBALATON Zoltan         val = s->regs.dst_pitch;
384862b4a29SBALATON Zoltan         if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
385862b4a29SBALATON Zoltan             val &= s->regs.dst_tile << 16;
386862b4a29SBALATON Zoltan         }
387862b4a29SBALATON Zoltan         break;
388862b4a29SBALATON Zoltan     case DST_WIDTH:
389862b4a29SBALATON Zoltan         val = s->regs.dst_width;
390862b4a29SBALATON Zoltan         break;
391862b4a29SBALATON Zoltan     case DST_HEIGHT:
392862b4a29SBALATON Zoltan         val = s->regs.dst_height;
393862b4a29SBALATON Zoltan         break;
394862b4a29SBALATON Zoltan     case SRC_X:
395862b4a29SBALATON Zoltan         val = s->regs.src_x;
396862b4a29SBALATON Zoltan         break;
397862b4a29SBALATON Zoltan     case SRC_Y:
398862b4a29SBALATON Zoltan         val = s->regs.src_y;
399862b4a29SBALATON Zoltan         break;
400862b4a29SBALATON Zoltan     case DST_X:
401862b4a29SBALATON Zoltan         val = s->regs.dst_x;
402862b4a29SBALATON Zoltan         break;
403862b4a29SBALATON Zoltan     case DST_Y:
404862b4a29SBALATON Zoltan         val = s->regs.dst_y;
405862b4a29SBALATON Zoltan         break;
406862b4a29SBALATON Zoltan     case DP_GUI_MASTER_CNTL:
407862b4a29SBALATON Zoltan         val = s->regs.dp_gui_master_cntl;
408862b4a29SBALATON Zoltan         break;
409862b4a29SBALATON Zoltan     case SRC_OFFSET:
410862b4a29SBALATON Zoltan         val = s->regs.src_offset;
411862b4a29SBALATON Zoltan         break;
412862b4a29SBALATON Zoltan     case SRC_PITCH:
413862b4a29SBALATON Zoltan         val = s->regs.src_pitch;
414862b4a29SBALATON Zoltan         if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
415862b4a29SBALATON Zoltan             val &= s->regs.src_tile << 16;
416862b4a29SBALATON Zoltan         }
417862b4a29SBALATON Zoltan         break;
418862b4a29SBALATON Zoltan     case DP_BRUSH_BKGD_CLR:
419862b4a29SBALATON Zoltan         val = s->regs.dp_brush_bkgd_clr;
420862b4a29SBALATON Zoltan         break;
421862b4a29SBALATON Zoltan     case DP_BRUSH_FRGD_CLR:
422862b4a29SBALATON Zoltan         val = s->regs.dp_brush_frgd_clr;
423862b4a29SBALATON Zoltan         break;
424862b4a29SBALATON Zoltan     case DP_SRC_FRGD_CLR:
425862b4a29SBALATON Zoltan         val = s->regs.dp_src_frgd_clr;
426862b4a29SBALATON Zoltan         break;
427862b4a29SBALATON Zoltan     case DP_SRC_BKGD_CLR:
428862b4a29SBALATON Zoltan         val = s->regs.dp_src_bkgd_clr;
429862b4a29SBALATON Zoltan         break;
430862b4a29SBALATON Zoltan     case DP_CNTL:
431862b4a29SBALATON Zoltan         val = s->regs.dp_cntl;
432862b4a29SBALATON Zoltan         break;
433862b4a29SBALATON Zoltan     case DP_DATATYPE:
434862b4a29SBALATON Zoltan         val = s->regs.dp_datatype;
435862b4a29SBALATON Zoltan         break;
436862b4a29SBALATON Zoltan     case DP_MIX:
437862b4a29SBALATON Zoltan         val = s->regs.dp_mix;
438862b4a29SBALATON Zoltan         break;
439862b4a29SBALATON Zoltan     case DP_WRITE_MASK:
440862b4a29SBALATON Zoltan         val = s->regs.dp_write_mask;
441862b4a29SBALATON Zoltan         break;
442862b4a29SBALATON Zoltan     case DEFAULT_OFFSET:
443862b4a29SBALATON Zoltan         val = s->regs.default_offset;
444866ad5f5SBALATON Zoltan         if (s->dev_id != PCI_DEVICE_ID_ATI_RAGE128_PF) {
445866ad5f5SBALATON Zoltan             val >>= 10;
446866ad5f5SBALATON Zoltan             val |= s->regs.default_pitch << 16;
447866ad5f5SBALATON Zoltan             val |= s->regs.default_tile << 30;
448866ad5f5SBALATON Zoltan         }
449862b4a29SBALATON Zoltan         break;
450862b4a29SBALATON Zoltan     case DEFAULT_PITCH:
451862b4a29SBALATON Zoltan         val = s->regs.default_pitch;
452866ad5f5SBALATON Zoltan         val |= s->regs.default_tile << 16;
453862b4a29SBALATON Zoltan         break;
454862b4a29SBALATON Zoltan     case DEFAULT_SC_BOTTOM_RIGHT:
455862b4a29SBALATON Zoltan         val = s->regs.default_sc_bottom_right;
456862b4a29SBALATON Zoltan         break;
457862b4a29SBALATON Zoltan     default:
458862b4a29SBALATON Zoltan         break;
459862b4a29SBALATON Zoltan     }
460862b4a29SBALATON Zoltan     if (addr < CUR_OFFSET || addr > CUR_CLR1 || ATI_DEBUG_HW_CURSOR) {
461862b4a29SBALATON Zoltan         trace_ati_mm_read(size, addr, ati_reg_name(addr & ~3ULL), val);
462862b4a29SBALATON Zoltan     }
463862b4a29SBALATON Zoltan     return val;
464862b4a29SBALATON Zoltan }
465862b4a29SBALATON Zoltan 
466862b4a29SBALATON Zoltan static inline void ati_reg_write_offs(uint32_t *reg, int offs,
467862b4a29SBALATON Zoltan                                       uint64_t data, unsigned int size)
468862b4a29SBALATON Zoltan {
469862b4a29SBALATON Zoltan     if (offs == 0 && size == 4) {
470862b4a29SBALATON Zoltan         *reg = data;
471862b4a29SBALATON Zoltan     } else {
472862b4a29SBALATON Zoltan         *reg = deposit32(*reg, offs * BITS_PER_BYTE, size * BITS_PER_BYTE,
473862b4a29SBALATON Zoltan                          data);
474862b4a29SBALATON Zoltan     }
475862b4a29SBALATON Zoltan }
476862b4a29SBALATON Zoltan 
477862b4a29SBALATON Zoltan static void ati_mm_write(void *opaque, hwaddr addr,
478862b4a29SBALATON Zoltan                            uint64_t data, unsigned int size)
479862b4a29SBALATON Zoltan {
480862b4a29SBALATON Zoltan     ATIVGAState *s = opaque;
481862b4a29SBALATON Zoltan 
482862b4a29SBALATON Zoltan     if (addr < CUR_OFFSET || addr > CUR_CLR1 || ATI_DEBUG_HW_CURSOR) {
483862b4a29SBALATON Zoltan         trace_ati_mm_write(size, addr, ati_reg_name(addr & ~3ULL), data);
484862b4a29SBALATON Zoltan     }
485862b4a29SBALATON Zoltan     switch (addr) {
486862b4a29SBALATON Zoltan     case MM_INDEX:
487862b4a29SBALATON Zoltan         s->regs.mm_index = data;
488862b4a29SBALATON Zoltan         break;
489862b4a29SBALATON Zoltan     case MM_DATA ... MM_DATA + 3:
490862b4a29SBALATON Zoltan         /* indexed access to regs or memory */
491862b4a29SBALATON Zoltan         if (s->regs.mm_index & BIT(31)) {
492339534d4SBALATON Zoltan             uint32_t idx = s->regs.mm_index & ~BIT(31);
493339534d4SBALATON Zoltan             if (idx <= s->vga.vram_size - size) {
494339534d4SBALATON Zoltan                 stn_le_p(s->vga.vram_ptr + idx, size, data);
495862b4a29SBALATON Zoltan             }
496862b4a29SBALATON Zoltan         } else {
497862b4a29SBALATON Zoltan             ati_mm_write(s, s->regs.mm_index + addr - MM_DATA, data, size);
498862b4a29SBALATON Zoltan         }
499862b4a29SBALATON Zoltan         break;
500862b4a29SBALATON Zoltan     case BIOS_0_SCRATCH ... BUS_CNTL - 1:
501862b4a29SBALATON Zoltan     {
502862b4a29SBALATON Zoltan         int i = (addr - BIOS_0_SCRATCH) / 4;
503862b4a29SBALATON Zoltan         if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF && i > 3) {
504862b4a29SBALATON Zoltan             break;
505862b4a29SBALATON Zoltan         }
506862b4a29SBALATON Zoltan         ati_reg_write_offs(&s->regs.bios_scratch[i],
507862b4a29SBALATON Zoltan                            addr - (BIOS_0_SCRATCH + i * 4), data, size);
508862b4a29SBALATON Zoltan         break;
509862b4a29SBALATON Zoltan     }
510862b4a29SBALATON Zoltan     case CRTC_GEN_CNTL ... CRTC_GEN_CNTL + 3:
511862b4a29SBALATON Zoltan     {
512862b4a29SBALATON Zoltan         uint32_t val = s->regs.crtc_gen_cntl;
513862b4a29SBALATON Zoltan         ati_reg_write_offs(&s->regs.crtc_gen_cntl,
514862b4a29SBALATON Zoltan                            addr - CRTC_GEN_CNTL, data, size);
515862b4a29SBALATON Zoltan         if ((val & CRTC2_CUR_EN) != (s->regs.crtc_gen_cntl & CRTC2_CUR_EN)) {
516862b4a29SBALATON Zoltan             if (s->cursor_guest_mode) {
517862b4a29SBALATON Zoltan                 s->vga.force_shadow = !!(s->regs.crtc_gen_cntl & CRTC2_CUR_EN);
518862b4a29SBALATON Zoltan             } else {
519862b4a29SBALATON Zoltan                 if (s->regs.crtc_gen_cntl & CRTC2_CUR_EN) {
520862b4a29SBALATON Zoltan                     ati_cursor_define(s);
521862b4a29SBALATON Zoltan                 }
522862b4a29SBALATON Zoltan                 dpy_mouse_set(s->vga.con, s->regs.cur_hv_pos >> 16,
523862b4a29SBALATON Zoltan                               s->regs.cur_hv_pos & 0xffff,
524862b4a29SBALATON Zoltan                               (s->regs.crtc_gen_cntl & CRTC2_CUR_EN) != 0);
525862b4a29SBALATON Zoltan             }
526862b4a29SBALATON Zoltan         }
527862b4a29SBALATON Zoltan         if ((val & (CRTC2_EXT_DISP_EN | CRTC2_EN)) !=
528862b4a29SBALATON Zoltan             (s->regs.crtc_gen_cntl & (CRTC2_EXT_DISP_EN | CRTC2_EN))) {
529862b4a29SBALATON Zoltan             ati_vga_switch_mode(s);
530862b4a29SBALATON Zoltan         }
531862b4a29SBALATON Zoltan         break;
532862b4a29SBALATON Zoltan     }
533862b4a29SBALATON Zoltan     case CRTC_EXT_CNTL ... CRTC_EXT_CNTL + 3:
534862b4a29SBALATON Zoltan     {
535862b4a29SBALATON Zoltan         uint32_t val = s->regs.crtc_ext_cntl;
536862b4a29SBALATON Zoltan         ati_reg_write_offs(&s->regs.crtc_ext_cntl,
537862b4a29SBALATON Zoltan                            addr - CRTC_EXT_CNTL, data, size);
538862b4a29SBALATON Zoltan         if (s->regs.crtc_ext_cntl & CRT_CRTC_DISPLAY_DIS) {
539862b4a29SBALATON Zoltan             DPRINTF("Display disabled\n");
540862b4a29SBALATON Zoltan             s->vga.ar_index &= ~BIT(5);
541862b4a29SBALATON Zoltan         } else {
542862b4a29SBALATON Zoltan             DPRINTF("Display enabled\n");
543862b4a29SBALATON Zoltan             s->vga.ar_index |= BIT(5);
544862b4a29SBALATON Zoltan             ati_vga_switch_mode(s);
545862b4a29SBALATON Zoltan         }
546862b4a29SBALATON Zoltan         if ((val & CRT_CRTC_DISPLAY_DIS) !=
547862b4a29SBALATON Zoltan             (s->regs.crtc_ext_cntl & CRT_CRTC_DISPLAY_DIS)) {
548862b4a29SBALATON Zoltan             ati_vga_switch_mode(s);
549862b4a29SBALATON Zoltan         }
550862b4a29SBALATON Zoltan         break;
551862b4a29SBALATON Zoltan     }
552862b4a29SBALATON Zoltan     case DAC_CNTL:
553862b4a29SBALATON Zoltan         s->regs.dac_cntl = data & 0xffffe3ff;
554862b4a29SBALATON Zoltan         s->vga.dac_8bit = !!(data & DAC_8BIT_EN);
555862b4a29SBALATON Zoltan         break;
556c82c7336SBALATON Zoltan     case GPIO_VGA_DDC:
557c82c7336SBALATON Zoltan         if (s->dev_id != PCI_DEVICE_ID_ATI_RAGE128_PF) {
558c82c7336SBALATON Zoltan             /* FIXME: Maybe add a property to select VGA or DVI port? */
559c82c7336SBALATON Zoltan         }
560c82c7336SBALATON Zoltan         break;
561c82c7336SBALATON Zoltan     case GPIO_DVI_DDC:
562c82c7336SBALATON Zoltan         if (s->dev_id != PCI_DEVICE_ID_ATI_RAGE128_PF) {
56341742927SPeter Maydell             s->regs.gpio_dvi_ddc = ati_i2c(&s->bbi2c, data, 0);
564c82c7336SBALATON Zoltan         }
565c82c7336SBALATON Zoltan         break;
566c82c7336SBALATON Zoltan     case GPIO_MONID ... GPIO_MONID + 3:
567c82c7336SBALATON Zoltan         /* FIXME What does Radeon have here? */
568c82c7336SBALATON Zoltan         if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
569c82c7336SBALATON Zoltan             ati_reg_write_offs(&s->regs.gpio_monid,
570c82c7336SBALATON Zoltan                                addr - GPIO_MONID, data, size);
571c82c7336SBALATON Zoltan             /*
572c82c7336SBALATON Zoltan              * Rage128p accesses DDC used to get EDID via these bits.
573006388a8SBALATON Zoltan              * Because some drivers access this via multiple byte writes
574006388a8SBALATON Zoltan              * we have to be careful when we send bits to avoid spurious
575006388a8SBALATON Zoltan              * changes in bitbang_i2c state. So only do it when mask is set
576006388a8SBALATON Zoltan              * and either the enable bits are changed or output bits changed
577006388a8SBALATON Zoltan              * while enabled.
578c82c7336SBALATON Zoltan              */
579c82c7336SBALATON Zoltan             if ((s->regs.gpio_monid & BIT(25)) &&
580006388a8SBALATON Zoltan                 ((addr <= GPIO_MONID + 2 && addr + size > GPIO_MONID + 2) ||
581006388a8SBALATON Zoltan                  (addr == GPIO_MONID && (s->regs.gpio_monid & 0x60000)))) {
58241742927SPeter Maydell                 s->regs.gpio_monid = ati_i2c(&s->bbi2c, s->regs.gpio_monid, 1);
583c82c7336SBALATON Zoltan             }
584c82c7336SBALATON Zoltan         }
585c82c7336SBALATON Zoltan         break;
586862b4a29SBALATON Zoltan     case PALETTE_INDEX ... PALETTE_INDEX + 3:
587862b4a29SBALATON Zoltan         if (size == 4) {
588862b4a29SBALATON Zoltan             vga_ioport_write(&s->vga, VGA_PEL_IR, (data >> 16) & 0xff);
589862b4a29SBALATON Zoltan             vga_ioport_write(&s->vga, VGA_PEL_IW, data & 0xff);
590862b4a29SBALATON Zoltan         } else {
591862b4a29SBALATON Zoltan             if (addr == PALETTE_INDEX) {
592862b4a29SBALATON Zoltan                 vga_ioport_write(&s->vga, VGA_PEL_IW, data & 0xff);
593862b4a29SBALATON Zoltan             } else {
594862b4a29SBALATON Zoltan                 vga_ioport_write(&s->vga, VGA_PEL_IR, data & 0xff);
595862b4a29SBALATON Zoltan             }
596862b4a29SBALATON Zoltan         }
597862b4a29SBALATON Zoltan         break;
598862b4a29SBALATON Zoltan     case PALETTE_DATA ... PALETTE_DATA + 3:
599862b4a29SBALATON Zoltan         data <<= addr - PALETTE_DATA;
600862b4a29SBALATON Zoltan         data = bswap32(data) >> 8;
601862b4a29SBALATON Zoltan         vga_ioport_write(&s->vga, VGA_PEL_D, data & 0xff);
602862b4a29SBALATON Zoltan         data >>= 8;
603862b4a29SBALATON Zoltan         vga_ioport_write(&s->vga, VGA_PEL_D, data & 0xff);
604862b4a29SBALATON Zoltan         data >>= 8;
605862b4a29SBALATON Zoltan         vga_ioport_write(&s->vga, VGA_PEL_D, data & 0xff);
606862b4a29SBALATON Zoltan         break;
607862b4a29SBALATON Zoltan     case CRTC_H_TOTAL_DISP:
608862b4a29SBALATON Zoltan         s->regs.crtc_h_total_disp = data & 0x07ff07ff;
609862b4a29SBALATON Zoltan         break;
610862b4a29SBALATON Zoltan     case CRTC_H_SYNC_STRT_WID:
611862b4a29SBALATON Zoltan         s->regs.crtc_h_sync_strt_wid = data & 0x17bf1fff;
612862b4a29SBALATON Zoltan         break;
613862b4a29SBALATON Zoltan     case CRTC_V_TOTAL_DISP:
614862b4a29SBALATON Zoltan         s->regs.crtc_v_total_disp = data & 0x0fff0fff;
615862b4a29SBALATON Zoltan         break;
616862b4a29SBALATON Zoltan     case CRTC_V_SYNC_STRT_WID:
617862b4a29SBALATON Zoltan         s->regs.crtc_v_sync_strt_wid = data & 0x9f0fff;
618862b4a29SBALATON Zoltan         break;
619862b4a29SBALATON Zoltan     case CRTC_OFFSET:
620862b4a29SBALATON Zoltan         s->regs.crtc_offset = data & 0xc7ffffff;
621862b4a29SBALATON Zoltan         break;
622862b4a29SBALATON Zoltan     case CRTC_OFFSET_CNTL:
623862b4a29SBALATON Zoltan         s->regs.crtc_offset_cntl = data; /* FIXME */
624862b4a29SBALATON Zoltan         break;
625862b4a29SBALATON Zoltan     case CRTC_PITCH:
626862b4a29SBALATON Zoltan         s->regs.crtc_pitch = data & 0x07ff07ff;
627862b4a29SBALATON Zoltan         break;
628862b4a29SBALATON Zoltan     case 0xf00 ... 0xfff:
629862b4a29SBALATON Zoltan         /* read-only copy of PCI config space so ignore writes */
630862b4a29SBALATON Zoltan         break;
631862b4a29SBALATON Zoltan     case CUR_OFFSET:
632862b4a29SBALATON Zoltan         if (s->regs.cur_offset != (data & 0x87fffff0)) {
633862b4a29SBALATON Zoltan             s->regs.cur_offset = data & 0x87fffff0;
634862b4a29SBALATON Zoltan             ati_cursor_define(s);
635862b4a29SBALATON Zoltan         }
636862b4a29SBALATON Zoltan         break;
637862b4a29SBALATON Zoltan     case CUR_HORZ_VERT_POSN:
638862b4a29SBALATON Zoltan         s->regs.cur_hv_pos = data & 0x3fff0fff;
639862b4a29SBALATON Zoltan         if (data & BIT(31)) {
640862b4a29SBALATON Zoltan             s->regs.cur_offset |= data & BIT(31);
641862b4a29SBALATON Zoltan         } else if (s->regs.cur_offset & BIT(31)) {
642862b4a29SBALATON Zoltan             s->regs.cur_offset &= ~BIT(31);
643862b4a29SBALATON Zoltan             ati_cursor_define(s);
644862b4a29SBALATON Zoltan         }
645862b4a29SBALATON Zoltan         if (!s->cursor_guest_mode &&
646862b4a29SBALATON Zoltan             (s->regs.crtc_gen_cntl & CRTC2_CUR_EN) && !(data & BIT(31))) {
647862b4a29SBALATON Zoltan             dpy_mouse_set(s->vga.con, s->regs.cur_hv_pos >> 16,
648862b4a29SBALATON Zoltan                           s->regs.cur_hv_pos & 0xffff, 1);
649862b4a29SBALATON Zoltan         }
650862b4a29SBALATON Zoltan         break;
651862b4a29SBALATON Zoltan     case CUR_HORZ_VERT_OFF:
652862b4a29SBALATON Zoltan         s->regs.cur_hv_offs = data & 0x3f003f;
653862b4a29SBALATON Zoltan         if (data & BIT(31)) {
654862b4a29SBALATON Zoltan             s->regs.cur_offset |= data & BIT(31);
655862b4a29SBALATON Zoltan         } else if (s->regs.cur_offset & BIT(31)) {
656862b4a29SBALATON Zoltan             s->regs.cur_offset &= ~BIT(31);
657862b4a29SBALATON Zoltan             ati_cursor_define(s);
658862b4a29SBALATON Zoltan         }
659862b4a29SBALATON Zoltan         break;
660862b4a29SBALATON Zoltan     case CUR_CLR0:
661862b4a29SBALATON Zoltan         if (s->regs.cur_color0 != (data & 0xffffff)) {
662862b4a29SBALATON Zoltan             s->regs.cur_color0 = data & 0xffffff;
663862b4a29SBALATON Zoltan             ati_cursor_define(s);
664862b4a29SBALATON Zoltan         }
665862b4a29SBALATON Zoltan         break;
666862b4a29SBALATON Zoltan     case CUR_CLR1:
667862b4a29SBALATON Zoltan         /*
668862b4a29SBALATON Zoltan          * Update cursor unconditionally here because some clients set up
669862b4a29SBALATON Zoltan          * other registers before actually writing cursor data to memory at
670862b4a29SBALATON Zoltan          * offset so we would miss cursor change unless always updating here
671862b4a29SBALATON Zoltan          */
672862b4a29SBALATON Zoltan         s->regs.cur_color1 = data & 0xffffff;
673862b4a29SBALATON Zoltan         ati_cursor_define(s);
674862b4a29SBALATON Zoltan         break;
675862b4a29SBALATON Zoltan     case DST_OFFSET:
676862b4a29SBALATON Zoltan         if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
677862b4a29SBALATON Zoltan             s->regs.dst_offset = data & 0xfffffff0;
678862b4a29SBALATON Zoltan         } else {
679862b4a29SBALATON Zoltan             s->regs.dst_offset = data & 0xfffffc00;
680862b4a29SBALATON Zoltan         }
681862b4a29SBALATON Zoltan         break;
682862b4a29SBALATON Zoltan     case DST_PITCH:
683862b4a29SBALATON Zoltan         if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
684862b4a29SBALATON Zoltan             s->regs.dst_pitch = data & 0x3fff;
685862b4a29SBALATON Zoltan             s->regs.dst_tile = (data >> 16) & 1;
686862b4a29SBALATON Zoltan         } else {
687862b4a29SBALATON Zoltan             s->regs.dst_pitch = data & 0x3ff0;
688862b4a29SBALATON Zoltan         }
689862b4a29SBALATON Zoltan         break;
690862b4a29SBALATON Zoltan     case DST_TILE:
691862b4a29SBALATON Zoltan         if (s->dev_id == PCI_DEVICE_ID_ATI_RADEON_QY) {
692862b4a29SBALATON Zoltan             s->regs.dst_tile = data & 3;
693862b4a29SBALATON Zoltan         }
694862b4a29SBALATON Zoltan         break;
695862b4a29SBALATON Zoltan     case DST_WIDTH:
696862b4a29SBALATON Zoltan         s->regs.dst_width = data & 0x3fff;
697862b4a29SBALATON Zoltan         ati_2d_blt(s);
698862b4a29SBALATON Zoltan         break;
699862b4a29SBALATON Zoltan     case DST_HEIGHT:
700862b4a29SBALATON Zoltan         s->regs.dst_height = data & 0x3fff;
701862b4a29SBALATON Zoltan         break;
702862b4a29SBALATON Zoltan     case SRC_X:
703862b4a29SBALATON Zoltan         s->regs.src_x = data & 0x3fff;
704862b4a29SBALATON Zoltan         break;
705862b4a29SBALATON Zoltan     case SRC_Y:
706862b4a29SBALATON Zoltan         s->regs.src_y = data & 0x3fff;
707862b4a29SBALATON Zoltan         break;
708862b4a29SBALATON Zoltan     case DST_X:
709862b4a29SBALATON Zoltan         s->regs.dst_x = data & 0x3fff;
710862b4a29SBALATON Zoltan         break;
711862b4a29SBALATON Zoltan     case DST_Y:
712862b4a29SBALATON Zoltan         s->regs.dst_y = data & 0x3fff;
713862b4a29SBALATON Zoltan         break;
714862b4a29SBALATON Zoltan     case SRC_PITCH_OFFSET:
715862b4a29SBALATON Zoltan         if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
716146dd326SBALATON Zoltan             s->regs.src_offset = (data & 0x1fffff) << 5;
717866ad5f5SBALATON Zoltan             s->regs.src_pitch = (data & 0x7fe00000) >> 21;
718862b4a29SBALATON Zoltan             s->regs.src_tile = data >> 31;
719862b4a29SBALATON Zoltan         } else {
720866ad5f5SBALATON Zoltan             s->regs.src_offset = (data & 0x3fffff) << 10;
721862b4a29SBALATON Zoltan             s->regs.src_pitch = (data & 0x3fc00000) >> 16;
722862b4a29SBALATON Zoltan             s->regs.src_tile = (data >> 30) & 1;
723862b4a29SBALATON Zoltan         }
724862b4a29SBALATON Zoltan         break;
725862b4a29SBALATON Zoltan     case DST_PITCH_OFFSET:
726862b4a29SBALATON Zoltan         if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
727146dd326SBALATON Zoltan             s->regs.dst_offset = (data & 0x1fffff) << 5;
728866ad5f5SBALATON Zoltan             s->regs.dst_pitch = (data & 0x7fe00000) >> 21;
729862b4a29SBALATON Zoltan             s->regs.dst_tile = data >> 31;
730862b4a29SBALATON Zoltan         } else {
731866ad5f5SBALATON Zoltan             s->regs.dst_offset = (data & 0x3fffff) << 10;
732862b4a29SBALATON Zoltan             s->regs.dst_pitch = (data & 0x3fc00000) >> 16;
733862b4a29SBALATON Zoltan             s->regs.dst_tile = data >> 30;
734862b4a29SBALATON Zoltan         }
735862b4a29SBALATON Zoltan         break;
736862b4a29SBALATON Zoltan     case SRC_Y_X:
737862b4a29SBALATON Zoltan         s->regs.src_x = data & 0x3fff;
738862b4a29SBALATON Zoltan         s->regs.src_y = (data >> 16) & 0x3fff;
739862b4a29SBALATON Zoltan         break;
740862b4a29SBALATON Zoltan     case DST_Y_X:
741862b4a29SBALATON Zoltan         s->regs.dst_x = data & 0x3fff;
742862b4a29SBALATON Zoltan         s->regs.dst_y = (data >> 16) & 0x3fff;
743862b4a29SBALATON Zoltan         break;
744862b4a29SBALATON Zoltan     case DST_HEIGHT_WIDTH:
745862b4a29SBALATON Zoltan         s->regs.dst_width = data & 0x3fff;
746862b4a29SBALATON Zoltan         s->regs.dst_height = (data >> 16) & 0x3fff;
747862b4a29SBALATON Zoltan         ati_2d_blt(s);
748862b4a29SBALATON Zoltan         break;
749862b4a29SBALATON Zoltan     case DP_GUI_MASTER_CNTL:
750862b4a29SBALATON Zoltan         s->regs.dp_gui_master_cntl = data & 0xf800000f;
751862b4a29SBALATON Zoltan         s->regs.dp_datatype = (data & 0x0f00) >> 8 | (data & 0x30f0) << 4 |
752862b4a29SBALATON Zoltan                               (data & 0x4000) << 16;
753862b4a29SBALATON Zoltan         s->regs.dp_mix = (data & GMC_ROP3_MASK) | (data & 0x7000000) >> 16;
754862b4a29SBALATON Zoltan         break;
755862b4a29SBALATON Zoltan     case DST_WIDTH_X:
756862b4a29SBALATON Zoltan         s->regs.dst_x = data & 0x3fff;
757862b4a29SBALATON Zoltan         s->regs.dst_width = (data >> 16) & 0x3fff;
758862b4a29SBALATON Zoltan         ati_2d_blt(s);
759862b4a29SBALATON Zoltan         break;
760862b4a29SBALATON Zoltan     case SRC_X_Y:
761862b4a29SBALATON Zoltan         s->regs.src_y = data & 0x3fff;
762862b4a29SBALATON Zoltan         s->regs.src_x = (data >> 16) & 0x3fff;
763862b4a29SBALATON Zoltan         break;
764862b4a29SBALATON Zoltan     case DST_X_Y:
765862b4a29SBALATON Zoltan         s->regs.dst_y = data & 0x3fff;
766862b4a29SBALATON Zoltan         s->regs.dst_x = (data >> 16) & 0x3fff;
767862b4a29SBALATON Zoltan         break;
768862b4a29SBALATON Zoltan     case DST_WIDTH_HEIGHT:
769862b4a29SBALATON Zoltan         s->regs.dst_height = data & 0x3fff;
770862b4a29SBALATON Zoltan         s->regs.dst_width = (data >> 16) & 0x3fff;
771862b4a29SBALATON Zoltan         ati_2d_blt(s);
772862b4a29SBALATON Zoltan         break;
773862b4a29SBALATON Zoltan     case DST_HEIGHT_Y:
774862b4a29SBALATON Zoltan         s->regs.dst_y = data & 0x3fff;
775862b4a29SBALATON Zoltan         s->regs.dst_height = (data >> 16) & 0x3fff;
776862b4a29SBALATON Zoltan         break;
777862b4a29SBALATON Zoltan     case SRC_OFFSET:
778862b4a29SBALATON Zoltan         if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
779862b4a29SBALATON Zoltan             s->regs.src_offset = data & 0xfffffff0;
780862b4a29SBALATON Zoltan         } else {
781862b4a29SBALATON Zoltan             s->regs.src_offset = data & 0xfffffc00;
782862b4a29SBALATON Zoltan         }
783862b4a29SBALATON Zoltan         break;
784862b4a29SBALATON Zoltan     case SRC_PITCH:
785862b4a29SBALATON Zoltan         if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
786862b4a29SBALATON Zoltan             s->regs.src_pitch = data & 0x3fff;
787862b4a29SBALATON Zoltan             s->regs.src_tile = (data >> 16) & 1;
788862b4a29SBALATON Zoltan         } else {
789862b4a29SBALATON Zoltan             s->regs.src_pitch = data & 0x3ff0;
790862b4a29SBALATON Zoltan         }
791862b4a29SBALATON Zoltan         break;
792862b4a29SBALATON Zoltan     case DP_BRUSH_BKGD_CLR:
793862b4a29SBALATON Zoltan         s->regs.dp_brush_bkgd_clr = data;
794862b4a29SBALATON Zoltan         break;
795862b4a29SBALATON Zoltan     case DP_BRUSH_FRGD_CLR:
796862b4a29SBALATON Zoltan         s->regs.dp_brush_frgd_clr = data;
797862b4a29SBALATON Zoltan         break;
798862b4a29SBALATON Zoltan     case DP_CNTL:
799862b4a29SBALATON Zoltan         s->regs.dp_cntl = data;
800862b4a29SBALATON Zoltan         break;
801862b4a29SBALATON Zoltan     case DP_DATATYPE:
802862b4a29SBALATON Zoltan         s->regs.dp_datatype = data & 0xe0070f0f;
803862b4a29SBALATON Zoltan         break;
804862b4a29SBALATON Zoltan     case DP_MIX:
805862b4a29SBALATON Zoltan         s->regs.dp_mix = data & 0x00ff0700;
806862b4a29SBALATON Zoltan         break;
807862b4a29SBALATON Zoltan     case DP_WRITE_MASK:
808862b4a29SBALATON Zoltan         s->regs.dp_write_mask = data;
809862b4a29SBALATON Zoltan         break;
810862b4a29SBALATON Zoltan     case DEFAULT_OFFSET:
811866ad5f5SBALATON Zoltan         if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
812866ad5f5SBALATON Zoltan             s->regs.default_offset = data & 0xfffffff0;
813866ad5f5SBALATON Zoltan         } else {
814866ad5f5SBALATON Zoltan             /* Radeon has DEFAULT_PITCH_OFFSET here like DST_PITCH_OFFSET */
815866ad5f5SBALATON Zoltan             s->regs.default_offset = (data & 0x3fffff) << 10;
816866ad5f5SBALATON Zoltan             s->regs.default_pitch = (data & 0x3fc00000) >> 16;
817866ad5f5SBALATON Zoltan             s->regs.default_tile = data >> 30;
818866ad5f5SBALATON Zoltan         }
819862b4a29SBALATON Zoltan         break;
820862b4a29SBALATON Zoltan     case DEFAULT_PITCH:
821862b4a29SBALATON Zoltan         if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
822866ad5f5SBALATON Zoltan             s->regs.default_pitch = data & 0x3fff;
823866ad5f5SBALATON Zoltan             s->regs.default_tile = (data >> 16) & 1;
824862b4a29SBALATON Zoltan         }
825862b4a29SBALATON Zoltan         break;
826862b4a29SBALATON Zoltan     case DEFAULT_SC_BOTTOM_RIGHT:
827862b4a29SBALATON Zoltan         s->regs.default_sc_bottom_right = data & 0x3fff3fff;
828862b4a29SBALATON Zoltan         break;
829862b4a29SBALATON Zoltan     default:
830862b4a29SBALATON Zoltan         break;
831862b4a29SBALATON Zoltan     }
832862b4a29SBALATON Zoltan }
833862b4a29SBALATON Zoltan 
834862b4a29SBALATON Zoltan static const MemoryRegionOps ati_mm_ops = {
835862b4a29SBALATON Zoltan     .read = ati_mm_read,
836862b4a29SBALATON Zoltan     .write = ati_mm_write,
837862b4a29SBALATON Zoltan     .endianness = DEVICE_LITTLE_ENDIAN,
838862b4a29SBALATON Zoltan };
839862b4a29SBALATON Zoltan 
840862b4a29SBALATON Zoltan static void ati_vga_realize(PCIDevice *dev, Error **errp)
841862b4a29SBALATON Zoltan {
842862b4a29SBALATON Zoltan     ATIVGAState *s = ATI_VGA(dev);
843862b4a29SBALATON Zoltan     VGACommonState *vga = &s->vga;
844862b4a29SBALATON Zoltan 
845862b4a29SBALATON Zoltan     if (s->model) {
846862b4a29SBALATON Zoltan         int i;
847862b4a29SBALATON Zoltan         for (i = 0; i < ARRAY_SIZE(ati_model_aliases); i++) {
848862b4a29SBALATON Zoltan             if (!strcmp(s->model, ati_model_aliases[i].name)) {
849862b4a29SBALATON Zoltan                 s->dev_id = ati_model_aliases[i].dev_id;
850862b4a29SBALATON Zoltan                 break;
851862b4a29SBALATON Zoltan             }
852862b4a29SBALATON Zoltan         }
853862b4a29SBALATON Zoltan         if (i >= ARRAY_SIZE(ati_model_aliases)) {
854862b4a29SBALATON Zoltan             warn_report("Unknown ATI VGA model name, "
855862b4a29SBALATON Zoltan                         "using default rage128p");
856862b4a29SBALATON Zoltan         }
857862b4a29SBALATON Zoltan     }
858862b4a29SBALATON Zoltan     if (s->dev_id != PCI_DEVICE_ID_ATI_RAGE128_PF &&
859862b4a29SBALATON Zoltan         s->dev_id != PCI_DEVICE_ID_ATI_RADEON_QY) {
860862b4a29SBALATON Zoltan         error_setg(errp, "Unknown ATI VGA device id, "
861862b4a29SBALATON Zoltan                    "only 0x5046 and 0x5159 are supported");
862862b4a29SBALATON Zoltan         return;
863862b4a29SBALATON Zoltan     }
864862b4a29SBALATON Zoltan     pci_set_word(dev->config + PCI_DEVICE_ID, s->dev_id);
865862b4a29SBALATON Zoltan 
866862b4a29SBALATON Zoltan     if (s->dev_id == PCI_DEVICE_ID_ATI_RADEON_QY &&
867862b4a29SBALATON Zoltan         s->vga.vram_size_mb < 16) {
868862b4a29SBALATON Zoltan         warn_report("Too small video memory for device id");
869862b4a29SBALATON Zoltan         s->vga.vram_size_mb = 16;
870862b4a29SBALATON Zoltan     }
871862b4a29SBALATON Zoltan 
872862b4a29SBALATON Zoltan     /* init vga bits */
873862b4a29SBALATON Zoltan     vga_common_init(vga, OBJECT(s));
874862b4a29SBALATON Zoltan     vga_init(vga, OBJECT(s), pci_address_space(dev),
875862b4a29SBALATON Zoltan              pci_address_space_io(dev), true);
876862b4a29SBALATON Zoltan     vga->con = graphic_console_init(DEVICE(s), 0, s->vga.hw_ops, &s->vga);
877862b4a29SBALATON Zoltan     if (s->cursor_guest_mode) {
878862b4a29SBALATON Zoltan         vga->cursor_invalidate = ati_cursor_invalidate;
879862b4a29SBALATON Zoltan         vga->cursor_draw_line = ati_cursor_draw_line;
880862b4a29SBALATON Zoltan     }
881862b4a29SBALATON Zoltan 
882c82c7336SBALATON Zoltan     /* ddc, edid */
883c82c7336SBALATON Zoltan     I2CBus *i2cbus = i2c_init_bus(DEVICE(s), "ati-vga.ddc");
88441742927SPeter Maydell     bitbang_i2c_init(&s->bbi2c, i2cbus);
885c82c7336SBALATON Zoltan     I2CSlave *i2cddc = I2C_SLAVE(qdev_create(BUS(i2cbus), TYPE_I2CDDC));
886c82c7336SBALATON Zoltan     i2c_set_slave_address(i2cddc, 0x50);
887c82c7336SBALATON Zoltan 
888862b4a29SBALATON Zoltan     /* mmio register space */
889862b4a29SBALATON Zoltan     memory_region_init_io(&s->mm, OBJECT(s), &ati_mm_ops, s,
890862b4a29SBALATON Zoltan                           "ati.mmregs", 0x4000);
891862b4a29SBALATON Zoltan     /* io space is alias to beginning of mmregs */
892862b4a29SBALATON Zoltan     memory_region_init_alias(&s->io, OBJECT(s), "ati.io", &s->mm, 0, 0x100);
893862b4a29SBALATON Zoltan 
894862b4a29SBALATON Zoltan     pci_register_bar(dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &vga->vram);
895862b4a29SBALATON Zoltan     pci_register_bar(dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &s->io);
896862b4a29SBALATON Zoltan     pci_register_bar(dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mm);
897862b4a29SBALATON Zoltan }
898862b4a29SBALATON Zoltan 
899862b4a29SBALATON Zoltan static void ati_vga_reset(DeviceState *dev)
900862b4a29SBALATON Zoltan {
901862b4a29SBALATON Zoltan     ATIVGAState *s = ATI_VGA(dev);
902862b4a29SBALATON Zoltan 
903862b4a29SBALATON Zoltan     /* reset vga */
904862b4a29SBALATON Zoltan     vga_common_reset(&s->vga);
905862b4a29SBALATON Zoltan     s->mode = VGA_MODE;
906862b4a29SBALATON Zoltan }
907862b4a29SBALATON Zoltan 
908862b4a29SBALATON Zoltan static void ati_vga_exit(PCIDevice *dev)
909862b4a29SBALATON Zoltan {
910862b4a29SBALATON Zoltan     ATIVGAState *s = ATI_VGA(dev);
911862b4a29SBALATON Zoltan 
912862b4a29SBALATON Zoltan     graphic_console_close(s->vga.con);
913862b4a29SBALATON Zoltan }
914862b4a29SBALATON Zoltan 
915862b4a29SBALATON Zoltan static Property ati_vga_properties[] = {
916862b4a29SBALATON Zoltan     DEFINE_PROP_UINT32("vgamem_mb", ATIVGAState, vga.vram_size_mb, 16),
917862b4a29SBALATON Zoltan     DEFINE_PROP_STRING("model", ATIVGAState, model),
918862b4a29SBALATON Zoltan     DEFINE_PROP_UINT16("x-device-id", ATIVGAState, dev_id,
919862b4a29SBALATON Zoltan                        PCI_DEVICE_ID_ATI_RAGE128_PF),
920862b4a29SBALATON Zoltan     DEFINE_PROP_BOOL("guest_hwcursor", ATIVGAState, cursor_guest_mode, false),
921862b4a29SBALATON Zoltan     DEFINE_PROP_END_OF_LIST()
922862b4a29SBALATON Zoltan };
923862b4a29SBALATON Zoltan 
924862b4a29SBALATON Zoltan static void ati_vga_class_init(ObjectClass *klass, void *data)
925862b4a29SBALATON Zoltan {
926862b4a29SBALATON Zoltan     DeviceClass *dc = DEVICE_CLASS(klass);
927862b4a29SBALATON Zoltan     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
928862b4a29SBALATON Zoltan 
929862b4a29SBALATON Zoltan     dc->reset = ati_vga_reset;
930862b4a29SBALATON Zoltan     dc->props = ati_vga_properties;
931862b4a29SBALATON Zoltan     dc->hotpluggable = false;
932862b4a29SBALATON Zoltan     set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);
933862b4a29SBALATON Zoltan 
934862b4a29SBALATON Zoltan     k->class_id = PCI_CLASS_DISPLAY_VGA;
935862b4a29SBALATON Zoltan     k->vendor_id = PCI_VENDOR_ID_ATI;
936862b4a29SBALATON Zoltan     k->device_id = PCI_DEVICE_ID_ATI_RAGE128_PF;
937263807f4SGerd Hoffmann     k->romfile = "vgabios-ati.bin";
938862b4a29SBALATON Zoltan     k->realize = ati_vga_realize;
939862b4a29SBALATON Zoltan     k->exit = ati_vga_exit;
940862b4a29SBALATON Zoltan }
941862b4a29SBALATON Zoltan 
942862b4a29SBALATON Zoltan static const TypeInfo ati_vga_info = {
943862b4a29SBALATON Zoltan     .name = TYPE_ATI_VGA,
944862b4a29SBALATON Zoltan     .parent = TYPE_PCI_DEVICE,
945862b4a29SBALATON Zoltan     .instance_size = sizeof(ATIVGAState),
946862b4a29SBALATON Zoltan     .class_init = ati_vga_class_init,
947862b4a29SBALATON Zoltan     .interfaces = (InterfaceInfo[]) {
948862b4a29SBALATON Zoltan           { INTERFACE_CONVENTIONAL_PCI_DEVICE },
949862b4a29SBALATON Zoltan           { },
950862b4a29SBALATON Zoltan     },
951862b4a29SBALATON Zoltan };
952862b4a29SBALATON Zoltan 
953862b4a29SBALATON Zoltan static void ati_vga_register_types(void)
954862b4a29SBALATON Zoltan {
955862b4a29SBALATON Zoltan     type_register_static(&ati_vga_info);
956862b4a29SBALATON Zoltan }
957862b4a29SBALATON Zoltan 
958862b4a29SBALATON Zoltan type_init(ati_vga_register_types)
959