~jderose/ubuntu/raring/qemu/vde-again

« back to all changes in this revision

Viewing changes to hw/cirrus_vga.c

  • Committer: Bazaar Package Importer
  • Author(s): Aurelien Jarno, Aurelien Jarno
  • Date: 2009-03-22 10:13:17 UTC
  • mfrom: (1.2.1 upstream) (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090322101317-iigjtnu5qil35dtb
Tags: 0.10.1-1
[ Aurelien Jarno ]
* New upstream stable release:
  - patches/80_stable-branch.patch: remove.
* debian/control: 
  - Remove depends on proll.
  - Move depends on device-tree-compiler to build-depends.
  - Bump Standards-Version to 3.8.1 (no changes).
* patches/82_qemu-img_decimal.patch: new patch from upstream to make
  qemu-img accept sizes with decimal values (closes: bug#501400).

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "pci.h"
32
32
#include "console.h"
33
33
#include "vga_int.h"
 
34
#include "kvm.h"
34
35
 
35
36
/*
36
37
 * TODO:
172
173
#define CIRRUS_MMIO_LINEDRAW_MODE     0x39      // byte
173
174
#define CIRRUS_MMIO_BLTSTATUS         0x40      // byte
174
175
 
175
 
// PCI 0x00: vendor, 0x02: device
176
 
#define PCI_VENDOR_CIRRUS             0x1013
 
176
// PCI 0x02: device
177
177
#define PCI_DEVICE_CLGD5462           0x00d0
178
178
#define PCI_DEVICE_CLGD5465           0x00d6
179
179
 
220
220
#define CIRRUS_HOOK_NOT_HANDLED 0
221
221
#define CIRRUS_HOOK_HANDLED 1
222
222
 
 
223
#define ABS(a) ((signed)(a) > 0 ? a : -a)
 
224
 
 
225
#define BLTUNSAFE(s) \
 
226
    ( \
 
227
        ( /* check dst is within bounds */ \
 
228
            (s)->cirrus_blt_height * ABS((s)->cirrus_blt_dstpitch) \
 
229
                + ((s)->cirrus_blt_dstaddr & (s)->cirrus_addr_mask) > \
 
230
                    (s)->vram_size \
 
231
        ) || \
 
232
        ( /* check src is within bounds */ \
 
233
            (s)->cirrus_blt_height * ABS((s)->cirrus_blt_srcpitch) \
 
234
                + ((s)->cirrus_blt_srcaddr & (s)->cirrus_addr_mask) > \
 
235
                    (s)->vram_size \
 
236
        ) \
 
237
    )
 
238
 
223
239
struct CirrusVGAState;
224
240
typedef void (*cirrus_bitblt_rop_t) (struct CirrusVGAState *s,
225
241
                                     uint8_t * dst, const uint8_t * src,
270
286
    int last_hw_cursor_y_end;
271
287
    int real_vram_size; /* XXX: suppress that */
272
288
    CPUWriteMemoryFunc **cirrus_linear_write;
 
289
    int device_id;
 
290
    int bustype;
273
291
} CirrusVGAState;
274
292
 
275
293
typedef struct PCICirrusVGAState {
639
657
 
640
658
    for (y = 0; y < lines; y++) {
641
659
        off_cur = off_begin;
642
 
        off_cur_end = off_cur + bytesperline;
 
660
        off_cur_end = (off_cur + bytesperline) & s->cirrus_addr_mask;
643
661
        off_cur &= TARGET_PAGE_MASK;
644
662
        while (off_cur < off_cur_end) {
645
663
            cpu_physical_memory_set_dirty(s->vram_offset + off_cur);
654
672
{
655
673
    uint8_t *dst;
656
674
 
657
 
    dst = s->vram_ptr + s->cirrus_blt_dstaddr;
 
675
    dst = s->vram_ptr + (s->cirrus_blt_dstaddr & s->cirrus_addr_mask);
 
676
 
 
677
    if (BLTUNSAFE(s))
 
678
        return 0;
 
679
 
658
680
    (*s->cirrus_rop) (s, dst, src,
659
681
                      s->cirrus_blt_dstpitch, 0,
660
682
                      s->cirrus_blt_width, s->cirrus_blt_height);
670
692
{
671
693
    cirrus_fill_t rop_func;
672
694
 
 
695
    if (BLTUNSAFE(s))
 
696
        return 0;
673
697
    rop_func = cirrus_fill[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1];
674
 
    rop_func(s, s->vram_ptr + s->cirrus_blt_dstaddr,
 
698
    rop_func(s, s->vram_ptr + (s->cirrus_blt_dstaddr & s->cirrus_addr_mask),
675
699
             s->cirrus_blt_dstpitch,
676
700
             s->cirrus_blt_width, s->cirrus_blt_height);
677
701
    cirrus_invalidate_region(s, s->cirrus_blt_dstaddr,
690
714
static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState * s)
691
715
{
692
716
    return cirrus_bitblt_common_patterncopy(s,
693
 
                                            s->vram_ptr +
694
 
                                            (s->cirrus_blt_srcaddr & ~7));
 
717
                                            s->vram_ptr + ((s->cirrus_blt_srcaddr & ~7) &
 
718
                                            s->cirrus_addr_mask));
695
719
}
696
720
 
697
721
static void cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)
706
730
    s->get_resolution((VGAState *)s, &width, &height);
707
731
 
708
732
    /* extra x, y */
709
 
    sx = (src % (width * depth)) / depth;
710
 
    sy = (src / (width * depth));
711
 
    dx = (dst % (width *depth)) / depth;
712
 
    dy = (dst / (width * depth));
 
733
    sx = (src % ABS(s->cirrus_blt_srcpitch)) / depth;
 
734
    sy = (src / ABS(s->cirrus_blt_srcpitch));
 
735
    dx = (dst % ABS(s->cirrus_blt_dstpitch)) / depth;
 
736
    dy = (dst / ABS(s->cirrus_blt_dstpitch));
713
737
 
714
738
    /* normalize width */
715
739
    w /= depth;
741
765
    if (notify)
742
766
        vga_hw_update();
743
767
 
744
 
    (*s->cirrus_rop) (s, s->vram_ptr + s->cirrus_blt_dstaddr,
745
 
                      s->vram_ptr + s->cirrus_blt_srcaddr,
 
768
    (*s->cirrus_rop) (s, s->vram_ptr +
 
769
                      (s->cirrus_blt_dstaddr & s->cirrus_addr_mask),
 
770
                      s->vram_ptr +
 
771
                      (s->cirrus_blt_srcaddr & s->cirrus_addr_mask),
746
772
                      s->cirrus_blt_dstpitch, s->cirrus_blt_srcpitch,
747
773
                      s->cirrus_blt_width, s->cirrus_blt_height);
748
774
 
749
775
    if (notify)
750
 
        s->ds->dpy_copy(s->ds,
751
 
                        sx, sy, dx, dy,
752
 
                        s->cirrus_blt_width / depth,
753
 
                        s->cirrus_blt_height);
 
776
        qemu_console_copy(s->ds,
 
777
                          sx, sy, dx, dy,
 
778
                          s->cirrus_blt_width / depth,
 
779
                          s->cirrus_blt_height);
754
780
 
755
781
    /* we don't have to notify the display that this portion has
756
 
       changed since dpy_copy implies this */
 
782
       changed since qemu_console_copy implies this */
757
783
 
758
 
    if (!notify)
759
 
        cirrus_invalidate_region(s, s->cirrus_blt_dstaddr,
760
 
                                 s->cirrus_blt_dstpitch, s->cirrus_blt_width,
761
 
                                 s->cirrus_blt_height);
 
784
    cirrus_invalidate_region(s, s->cirrus_blt_dstaddr,
 
785
                                s->cirrus_blt_dstpitch, s->cirrus_blt_width,
 
786
                                s->cirrus_blt_height);
762
787
}
763
788
 
764
789
static int cirrus_bitblt_videotovideo_copy(CirrusVGAState * s)
765
790
{
766
 
    if (s->ds->dpy_copy) {
767
 
        cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->start_addr,
768
 
                       s->cirrus_blt_srcaddr - s->start_addr,
769
 
                       s->cirrus_blt_width, s->cirrus_blt_height);
770
 
    } else {
771
 
        (*s->cirrus_rop) (s, s->vram_ptr + s->cirrus_blt_dstaddr,
772
 
                          s->vram_ptr + s->cirrus_blt_srcaddr,
773
 
                          s->cirrus_blt_dstpitch, s->cirrus_blt_srcpitch,
774
 
                          s->cirrus_blt_width, s->cirrus_blt_height);
 
791
    if (BLTUNSAFE(s))
 
792
        return 0;
775
793
 
776
 
        cirrus_invalidate_region(s, s->cirrus_blt_dstaddr,
777
 
                                 s->cirrus_blt_dstpitch, s->cirrus_blt_width,
778
 
                                 s->cirrus_blt_height);
779
 
    }
 
794
    cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->start_addr,
 
795
            s->cirrus_blt_srcaddr - s->start_addr,
 
796
            s->cirrus_blt_width, s->cirrus_blt_height);
780
797
 
781
798
    return 1;
782
799
}
801
818
        } else {
802
819
            /* at least one scan line */
803
820
            do {
804
 
                (*s->cirrus_rop)(s, s->vram_ptr + s->cirrus_blt_dstaddr,
805
 
                                 s->cirrus_bltbuf, 0, 0, s->cirrus_blt_width, 1);
 
821
                (*s->cirrus_rop)(s, s->vram_ptr +
 
822
                                 (s->cirrus_blt_dstaddr & s->cirrus_addr_mask),
 
823
                                  s->cirrus_bltbuf, 0, 0, s->cirrus_blt_width, 1);
806
824
                cirrus_invalidate_region(s, s->cirrus_blt_dstaddr, 0,
807
825
                                         s->cirrus_blt_width, 1);
808
826
                s->cirrus_blt_dstaddr += s->cirrus_blt_dstpitch;
830
848
 
831
849
static void cirrus_bitblt_reset(CirrusVGAState * s)
832
850
{
 
851
    int need_update;
 
852
 
833
853
    s->gr[0x31] &=
834
854
        ~(CIRRUS_BLT_START | CIRRUS_BLT_BUSY | CIRRUS_BLT_FIFOUSED);
 
855
    need_update = s->cirrus_srcptr != &s->cirrus_bltbuf[0]
 
856
        || s->cirrus_srcptr_end != &s->cirrus_bltbuf[0];
835
857
    s->cirrus_srcptr = &s->cirrus_bltbuf[0];
836
858
    s->cirrus_srcptr_end = &s->cirrus_bltbuf[0];
837
859
    s->cirrus_srccounter = 0;
 
860
    if (!need_update)
 
861
        return;
838
862
    cirrus_update_memory_access(s);
839
863
}
840
864
 
1200
1224
    }
1201
1225
 
1202
1226
    if (limit > 0) {
 
1227
        /* Thinking about changing bank base? First, drop the dirty bitmap information
 
1228
         * on the current location, otherwise we lose this pointer forever */
 
1229
        if (s->lfb_vram_mapped) {
 
1230
            target_phys_addr_t base_addr = isa_mem_base + 0xa0000 + bank_index * 0x8000;
 
1231
            cpu_physical_sync_dirty_bitmap(base_addr, base_addr + 0x8000);
 
1232
        }
1203
1233
        s->cirrus_bank_base[bank_index] = offset;
1204
1234
        s->cirrus_bank_limit[bank_index] = limit;
1205
1235
    } else {
1328
1358
        s->hw_cursor_y = (reg_value << 3) | (reg_index >> 5);
1329
1359
        break;
1330
1360
    case 0x07:                  // Extended Sequencer Mode
 
1361
    cirrus_update_memory_access(s);
1331
1362
    case 0x08:                  // EEPROM Control
1332
1363
    case 0x09:                  // Scratch Register 0
1333
1364
    case 0x0a:                  // Scratch Register 1
1500
1531
        s->gr[reg_index] = reg_value;
1501
1532
        cirrus_update_bank_ptr(s, 0);
1502
1533
        cirrus_update_bank_ptr(s, 1);
 
1534
        cirrus_update_memory_access(s);
1503
1535
        break;
1504
1536
    case 0x0B:
1505
1537
        s->gr[reg_index] = reg_value;
1597
1629
    case 0x17:                  // Standard VGA
1598
1630
    case 0x18:                  // Standard VGA
1599
1631
        return CIRRUS_HOOK_NOT_HANDLED;
 
1632
    case 0x24:                  // Attribute Controller Toggle Readback (R)
 
1633
        *reg_value = (s->ar_flip_flop << 7);
 
1634
        break;
1600
1635
    case 0x19:                  // Interlace End
1601
1636
    case 0x1a:                  // Miscellaneous Control
1602
1637
    case 0x1b:                  // Extended Display Control
1603
1638
    case 0x1c:                  // Sync Adjust and Genlock
1604
1639
    case 0x1d:                  // Overlay Extended Control
1605
1640
    case 0x22:                  // Graphics Data Latches Readback (R)
1606
 
    case 0x24:                  // Attribute Controller Toggle Readback (R)
1607
1641
    case 0x25:                  // Part Status
1608
1642
    case 0x27:                  // Part ID (R)
1609
1643
        *reg_value = s->cr[reg_index];
1920
1954
    unsigned val = mem_value;
1921
1955
    uint8_t *dst;
1922
1956
 
1923
 
    dst = s->vram_ptr + offset;
 
1957
    dst = s->vram_ptr + (offset &= s->cirrus_addr_mask);
1924
1958
    for (x = 0; x < 8; x++) {
1925
1959
        if (val & 0x80) {
1926
1960
            *dst = s->cirrus_shadow_gr1;
1943
1977
    unsigned val = mem_value;
1944
1978
    uint8_t *dst;
1945
1979
 
1946
 
    dst = s->vram_ptr + offset;
 
1980
    dst = s->vram_ptr + (offset &= s->cirrus_addr_mask);
1947
1981
    for (x = 0; x < 8; x++) {
1948
1982
        if (val & 0x80) {
1949
1983
            *dst = s->cirrus_shadow_gr1;
2291
2325
    color1 = s->rgb_to_pixel(c6_to_8(palette[0xf * 3]),
2292
2326
                             c6_to_8(palette[0xf * 3 + 1]),
2293
2327
                             c6_to_8(palette[0xf * 3 + 2]));
2294
 
    bpp = ((s->ds->depth + 7) >> 3);
 
2328
    bpp = ((ds_get_bits_per_pixel(s->ds) + 7) >> 3);
2295
2329
    d1 += x1 * bpp;
2296
 
    switch(s->ds->depth) {
 
2330
    switch(ds_get_bits_per_pixel(s->ds)) {
2297
2331
    default:
2298
2332
        break;
2299
2333
    case 8:
2588
2622
    cirrus_linear_bitblt_writel,
2589
2623
};
2590
2624
 
 
2625
static void map_linear_vram(CirrusVGAState *s)
 
2626
{
 
2627
    vga_dirty_log_stop((VGAState *)s);
 
2628
 
 
2629
    if (!s->map_addr && s->lfb_addr && s->lfb_end) {
 
2630
        s->map_addr = s->lfb_addr;
 
2631
        s->map_end = s->lfb_end;
 
2632
        cpu_register_physical_memory(s->map_addr, s->map_end - s->map_addr, s->vram_offset);
 
2633
    }
 
2634
 
 
2635
    if (!s->map_addr)
 
2636
        return;
 
2637
 
 
2638
    s->lfb_vram_mapped = 0;
 
2639
 
 
2640
    cpu_register_physical_memory(isa_mem_base + 0xa0000, 0x8000,
 
2641
                                (s->vram_offset + s->cirrus_bank_base[0]) | IO_MEM_UNASSIGNED);
 
2642
    cpu_register_physical_memory(isa_mem_base + 0xa8000, 0x8000,
 
2643
                                (s->vram_offset + s->cirrus_bank_base[1]) | IO_MEM_UNASSIGNED);
 
2644
    if (!(s->cirrus_srcptr != s->cirrus_srcptr_end)
 
2645
        && !((s->sr[0x07] & 0x01) == 0)
 
2646
        && !((s->gr[0x0B] & 0x14) == 0x14)
 
2647
        && !(s->gr[0x0B] & 0x02)) {
 
2648
 
 
2649
        vga_dirty_log_stop((VGAState *)s);
 
2650
        cpu_register_physical_memory(isa_mem_base + 0xa0000, 0x8000,
 
2651
                                    (s->vram_offset + s->cirrus_bank_base[0]) | IO_MEM_RAM);
 
2652
        cpu_register_physical_memory(isa_mem_base + 0xa8000, 0x8000,
 
2653
                                    (s->vram_offset + s->cirrus_bank_base[1]) | IO_MEM_RAM);
 
2654
 
 
2655
        s->lfb_vram_mapped = 1;
 
2656
    }
 
2657
    else {
 
2658
        cpu_register_physical_memory(isa_mem_base + 0xa0000, 0x20000,
 
2659
                                     s->vga_io_memory);
 
2660
    }
 
2661
 
 
2662
    vga_dirty_log_start((VGAState *)s);
 
2663
}
 
2664
 
 
2665
static void unmap_linear_vram(CirrusVGAState *s)
 
2666
{
 
2667
    vga_dirty_log_stop((VGAState *)s);
 
2668
 
 
2669
    if (s->map_addr && s->lfb_addr && s->lfb_end)
 
2670
        s->map_addr = s->map_end = 0;
 
2671
 
 
2672
    cpu_register_physical_memory(isa_mem_base + 0xa0000, 0x20000,
 
2673
                                 s->vga_io_memory);
 
2674
 
 
2675
    vga_dirty_log_start((VGAState *)s);
 
2676
}
 
2677
 
2591
2678
/* Compute the memory access functions */
2592
2679
static void cirrus_update_memory_access(CirrusVGAState *s)
2593
2680
{
2606
2693
 
2607
2694
        mode = s->gr[0x05] & 0x7;
2608
2695
        if (mode < 4 || mode > 5 || ((s->gr[0x0B] & 0x4) == 0)) {
 
2696
            map_linear_vram(s);
2609
2697
            s->cirrus_linear_write[0] = cirrus_linear_mem_writeb;
2610
2698
            s->cirrus_linear_write[1] = cirrus_linear_mem_writew;
2611
2699
            s->cirrus_linear_write[2] = cirrus_linear_mem_writel;
2612
2700
        } else {
2613
2701
        generic_io:
 
2702
            unmap_linear_vram(s);
2614
2703
            s->cirrus_linear_write[0] = cirrus_linear_writeb;
2615
2704
            s->cirrus_linear_write[1] = cirrus_linear_writew;
2616
2705
            s->cirrus_linear_write[2] = cirrus_linear_writel;
2713
2802
        case 0x3ba:
2714
2803
        case 0x3da:
2715
2804
            /* just toggle to fool polling */
2716
 
            s->st01 ^= ST01_V_RETRACE | ST01_DISP_ENABLE;
2717
 
            val = s->st01;
 
2805
            val = s->st01 = s->retrace((VGAState *) s);
2718
2806
            s->ar_flip_flop = 0;
2719
2807
            break;
2720
2808
        default:
2777
2865
        break;
2778
2866
    case 0x3c2:
2779
2867
        s->msr = val & ~0x10;
 
2868
        s->update_retrace_info((VGAState *) s);
2780
2869
        break;
2781
2870
    case 0x3c4:
2782
2871
        s->sr_index = val;
2788
2877
        printf("vga: write SR%x = 0x%02x\n", s->sr_index, val);
2789
2878
#endif
2790
2879
        s->sr[s->sr_index] = val & sr_mask[s->sr_index];
 
2880
        if (s->sr_index == 1) s->update_retrace_info((VGAState *) s);
2791
2881
        break;
2792
2882
    case 0x3c6:
2793
2883
        cirrus_write_hidden_dac(s, val);
2855
2945
            s->cr[s->cr_index] = val;
2856
2946
            break;
2857
2947
        }
 
2948
 
 
2949
        switch(s->cr_index) {
 
2950
        case 0x00:
 
2951
        case 0x04:
 
2952
        case 0x05:
 
2953
        case 0x06:
 
2954
        case 0x07:
 
2955
        case 0x11:
 
2956
        case 0x17:
 
2957
            s->update_retrace_info((VGAState *) s);
 
2958
            break;
 
2959
        }
2858
2960
        break;
2859
2961
    case 0x3ba:
2860
2962
    case 0x3da:
3059
3161
    qemu_get_be32s(f, &s->hw_cursor_x);
3060
3162
    qemu_get_be32s(f, &s->hw_cursor_y);
3061
3163
 
 
3164
    cirrus_update_memory_access(s);
3062
3165
    /* force refresh */
3063
3166
    s->graphic_mode = -1;
3064
3167
    cirrus_update_bank_ptr(s, 0);
3072
3175
 *
3073
3176
 ***************************************/
3074
3177
 
 
3178
static void cirrus_reset(void *opaque)
 
3179
{
 
3180
    CirrusVGAState *s = opaque;
 
3181
 
 
3182
    vga_reset(s);
 
3183
    unmap_linear_vram(s);
 
3184
    s->sr[0x06] = 0x0f;
 
3185
    if (s->device_id == CIRRUS_ID_CLGD5446) {
 
3186
        /* 4MB 64 bit memory config, always PCI */
 
3187
        s->sr[0x1F] = 0x2d;             // MemClock
 
3188
        s->gr[0x18] = 0x0f;             // fastest memory configuration
 
3189
        s->sr[0x0f] = 0x98;
 
3190
        s->sr[0x17] = 0x20;
 
3191
        s->sr[0x15] = 0x04; /* memory size, 3=2MB, 4=4MB */
 
3192
    } else {
 
3193
        s->sr[0x1F] = 0x22;             // MemClock
 
3194
        s->sr[0x0F] = CIRRUS_MEMSIZE_2M;
 
3195
        s->sr[0x17] = s->bustype;
 
3196
        s->sr[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */
 
3197
    }
 
3198
    s->cr[0x27] = s->device_id;
 
3199
 
 
3200
    /* Win2K seems to assume that the pattern buffer is at 0xff
 
3201
       initially ! */
 
3202
    memset(s->vram_ptr, 0xff, s->real_vram_size);
 
3203
 
 
3204
    s->cirrus_hidden_dac_lockindex = 5;
 
3205
    s->cirrus_hidden_dac_data = 0;
 
3206
}
 
3207
 
3075
3208
static void cirrus_init_common(CirrusVGAState * s, int device_id, int is_pci)
3076
3209
{
3077
 
    int vga_io_memory, i;
 
3210
    int i;
3078
3211
    static int inited;
3079
3212
 
3080
3213
    if (!inited) {
3097
3230
        rop_to_index[CIRRUS_ROP_NOTSRC] = 13;
3098
3231
        rop_to_index[CIRRUS_ROP_NOTSRC_OR_DST] = 14;
3099
3232
        rop_to_index[CIRRUS_ROP_NOTSRC_AND_NOTDST] = 15;
 
3233
        s->device_id = device_id;
 
3234
        if (is_pci)
 
3235
            s->bustype = CIRRUS_BUSTYPE_PCI;
 
3236
        else
 
3237
            s->bustype = CIRRUS_BUSTYPE_ISA;
3100
3238
    }
3101
3239
 
3102
3240
    register_ioport_write(0x3c0, 16, 1, vga_ioport_write, s);
3113
3251
    register_ioport_read(0x3ba, 1, 1, vga_ioport_read, s);
3114
3252
    register_ioport_read(0x3da, 1, 1, vga_ioport_read, s);
3115
3253
 
3116
 
    vga_io_memory = cpu_register_io_memory(0, cirrus_vga_mem_read,
 
3254
    s->vga_io_memory = cpu_register_io_memory(0, cirrus_vga_mem_read,
3117
3255
                                           cirrus_vga_mem_write, s);
3118
3256
    cpu_register_physical_memory(isa_mem_base + 0x000a0000, 0x20000,
3119
 
                                 vga_io_memory);
3120
 
 
3121
 
    s->sr[0x06] = 0x0f;
3122
 
    if (device_id == CIRRUS_ID_CLGD5446) {
3123
 
        /* 4MB 64 bit memory config, always PCI */
3124
 
        s->sr[0x1F] = 0x2d;             // MemClock
3125
 
        s->gr[0x18] = 0x0f;             // fastest memory configuration
3126
 
#if 1
3127
 
        s->sr[0x0f] = 0x98;
3128
 
        s->sr[0x17] = 0x20;
3129
 
        s->sr[0x15] = 0x04; /* memory size, 3=2MB, 4=4MB */
3130
 
        s->real_vram_size = 4096 * 1024;
3131
 
#else
3132
 
        s->sr[0x0f] = 0x18;
3133
 
        s->sr[0x17] = 0x20;
3134
 
        s->sr[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */
3135
 
        s->real_vram_size = 2048 * 1024;
3136
 
#endif
3137
 
    } else {
3138
 
        s->sr[0x1F] = 0x22;             // MemClock
3139
 
        s->sr[0x0F] = CIRRUS_MEMSIZE_2M;
3140
 
        if (is_pci)
3141
 
            s->sr[0x17] = CIRRUS_BUSTYPE_PCI;
3142
 
        else
3143
 
            s->sr[0x17] = CIRRUS_BUSTYPE_ISA;
3144
 
        s->real_vram_size = 2048 * 1024;
3145
 
        s->sr[0x15] = 0x03; /* memory size, 3=2MB, 4=4MB */
3146
 
    }
3147
 
    s->cr[0x27] = device_id;
3148
 
 
3149
 
    /* Win2K seems to assume that the pattern buffer is at 0xff
3150
 
       initially ! */
3151
 
    memset(s->vram_ptr, 0xff, s->real_vram_size);
3152
 
 
3153
 
    s->cirrus_hidden_dac_lockindex = 5;
3154
 
    s->cirrus_hidden_dac_data = 0;
 
3257
                                 s->vga_io_memory);
 
3258
    qemu_register_coalesced_mmio(isa_mem_base + 0x000a0000, 0x20000);
3155
3259
 
3156
3260
    /* I/O handler for LFB */
3157
3261
    s->cirrus_linear_io_addr =
3158
 
        cpu_register_io_memory(0, cirrus_linear_read, cirrus_linear_write,
3159
 
                               s);
 
3262
        cpu_register_io_memory(0, cirrus_linear_read, cirrus_linear_write, s);
3160
3263
    s->cirrus_linear_write = cpu_get_io_memory_write(s->cirrus_linear_io_addr);
3161
3264
 
3162
3265
    /* I/O handler for LFB */
3163
3266
    s->cirrus_linear_bitblt_io_addr =
3164
 
        cpu_register_io_memory(0, cirrus_linear_bitblt_read, cirrus_linear_bitblt_write,
3165
 
                               s);
 
3267
        cpu_register_io_memory(0, cirrus_linear_bitblt_read,
 
3268
                               cirrus_linear_bitblt_write, s);
3166
3269
 
3167
3270
    /* I/O handler for memory-mapped I/O */
3168
3271
    s->cirrus_mmio_io_addr =
3169
 
        cpu_register_io_memory(0, cirrus_mmio_read, cirrus_mmio_write, s);
 
3272
        cpu_register_io_memory(0, cirrus_mmio_read, cirrus_mmio_write, s);
 
3273
 
 
3274
    s->real_vram_size =
 
3275
        (s->device_id == CIRRUS_ID_CLGD5446) ? 4096 * 1024 : 2048 * 1024;
3170
3276
 
3171
3277
    /* XXX: s->vram_size must be a power of two */
3172
3278
    s->cirrus_addr_mask = s->real_vram_size - 1;
3178
3284
    s->cursor_invalidate = cirrus_cursor_invalidate;
3179
3285
    s->cursor_draw_line = cirrus_cursor_draw_line;
3180
3286
 
 
3287
    qemu_register_reset(cirrus_reset, s);
 
3288
    cirrus_reset(s);
3181
3289
    register_savevm("cirrus_vga", 0, 2, cirrus_vga_save, cirrus_vga_load, s);
3182
3290
}
3183
3291
 
3187
3295
 *
3188
3296
 ***************************************/
3189
3297
 
3190
 
void isa_cirrus_vga_init(DisplayState *ds, uint8_t *vga_ram_base,
3191
 
                         unsigned long vga_ram_offset, int vga_ram_size)
 
3298
void isa_cirrus_vga_init(uint8_t *vga_ram_base,
 
3299
                         ram_addr_t vga_ram_offset, int vga_ram_size)
3192
3300
{
3193
3301
    CirrusVGAState *s;
3194
3302
 
3195
3303
    s = qemu_mallocz(sizeof(CirrusVGAState));
3196
3304
 
3197
3305
    vga_common_init((VGAState *)s,
3198
 
                    ds, vga_ram_base, vga_ram_offset, vga_ram_size);
 
3306
                    vga_ram_base, vga_ram_offset, vga_ram_size);
3199
3307
    cirrus_init_common(s, CIRRUS_ID_CLGD5430, 0);
 
3308
    s->ds = graphic_console_init(s->update, s->invalidate,
 
3309
                                 s->screen_dump, s->text_update, s);
3200
3310
    /* XXX ISA-LFB support */
3201
3311
}
3202
3312
 
3211
3321
{
3212
3322
    CirrusVGAState *s = &((PCICirrusVGAState *)d)->cirrus_vga;
3213
3323
 
 
3324
    vga_dirty_log_stop((VGAState *)s);
 
3325
 
3214
3326
    /* XXX: add byte swapping apertures */
3215
3327
    cpu_register_physical_memory(addr, s->vram_size,
3216
3328
                                 s->cirrus_linear_io_addr);
3217
3329
    cpu_register_physical_memory(addr + 0x1000000, 0x400000,
3218
3330
                                 s->cirrus_linear_bitblt_io_addr);
 
3331
 
 
3332
    s->map_addr = s->map_end = 0;
 
3333
    s->lfb_addr = addr & TARGET_PAGE_MASK;
 
3334
    s->lfb_end = ((addr + VGA_RAM_SIZE) + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
 
3335
    /* account for overflow */
 
3336
    if (s->lfb_end < addr + VGA_RAM_SIZE)
 
3337
        s->lfb_end = addr + VGA_RAM_SIZE;
 
3338
 
 
3339
    vga_dirty_log_start((VGAState *)s);
3219
3340
}
3220
3341
 
3221
3342
static void cirrus_pci_mmio_map(PCIDevice *d, int region_num,
3227
3348
                                 s->cirrus_mmio_io_addr);
3228
3349
}
3229
3350
 
3230
 
void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
3231
 
                         unsigned long vga_ram_offset, int vga_ram_size)
 
3351
static void pci_cirrus_write_config(PCIDevice *d,
 
3352
                                    uint32_t address, uint32_t val, int len)
 
3353
{
 
3354
    PCICirrusVGAState *pvs = container_of(d, PCICirrusVGAState, dev);
 
3355
    CirrusVGAState *s = &pvs->cirrus_vga;
 
3356
 
 
3357
    vga_dirty_log_stop((VGAState *)s);
 
3358
 
 
3359
    pci_default_write_config(d, address, val, len);
 
3360
    if (s->map_addr && pvs->dev.io_regions[0].addr == -1)
 
3361
        s->map_addr = 0;
 
3362
    cirrus_update_memory_access(s);
 
3363
 
 
3364
    vga_dirty_log_start((VGAState *)s);
 
3365
}
 
3366
 
 
3367
void pci_cirrus_vga_init(PCIBus *bus, uint8_t *vga_ram_base,
 
3368
                         ram_addr_t vga_ram_offset, int vga_ram_size)
3232
3369
{
3233
3370
    PCICirrusVGAState *d;
3234
3371
    uint8_t *pci_conf;
3240
3377
    /* setup PCI configuration registers */
3241
3378
    d = (PCICirrusVGAState *)pci_register_device(bus, "Cirrus VGA",
3242
3379
                                                 sizeof(PCICirrusVGAState),
3243
 
                                                 -1, NULL, NULL);
 
3380
                                                 -1, NULL, pci_cirrus_write_config);
3244
3381
    pci_conf = d->dev.config;
3245
 
    pci_conf[0x00] = (uint8_t) (PCI_VENDOR_CIRRUS & 0xff);
3246
 
    pci_conf[0x01] = (uint8_t) (PCI_VENDOR_CIRRUS >> 8);
3247
 
    pci_conf[0x02] = (uint8_t) (device_id & 0xff);
3248
 
    pci_conf[0x03] = (uint8_t) (device_id >> 8);
 
3382
    pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_CIRRUS);
 
3383
    pci_config_set_device_id(pci_conf, device_id);
3249
3384
    pci_conf[0x04] = PCI_COMMAND_IOACCESS | PCI_COMMAND_MEMACCESS;
3250
 
    pci_conf[0x0a] = PCI_CLASS_SUB_VGA;
3251
 
    pci_conf[0x0b] = PCI_CLASS_BASE_DISPLAY;
 
3385
    pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
3252
3386
    pci_conf[0x0e] = PCI_CLASS_HEADERTYPE_00h;
3253
3387
 
3254
3388
    /* setup VGA */
3255
3389
    s = &d->cirrus_vga;
3256
3390
    vga_common_init((VGAState *)s,
3257
 
                    ds, vga_ram_base, vga_ram_offset, vga_ram_size);
 
3391
                    vga_ram_base, vga_ram_offset, vga_ram_size);
3258
3392
    cirrus_init_common(s, device_id, 1);
3259
3393
 
3260
 
    graphic_console_init(s->ds, s->update, s->invalidate, s->screen_dump, s);
 
3394
    s->ds = graphic_console_init(s->update, s->invalidate,
 
3395
                                 s->screen_dump, s->text_update, s);
3261
3396
 
3262
3397
    s->pci_dev = (PCIDevice *)d;
3263
3398