Revision 052e87b0

b/exec.c
801 801
    MemoryRegionSection *existing = phys_page_find(d, base >> TARGET_PAGE_BITS);
802 802
    MemoryRegionSection subsection = {
803 803
        .offset_within_address_space = base,
804
        .size = TARGET_PAGE_SIZE,
804
        .size = int128_make64(TARGET_PAGE_SIZE),
805 805
    };
806 806
    hwaddr start, end;
807 807

  
......
816 816
        subpage = container_of(existing->mr, subpage_t, iomem);
817 817
    }
818 818
    start = section->offset_within_address_space & ~TARGET_PAGE_MASK;
819
    end = start + section->size - 1;
819
    end = start + int128_get64(section->size) - 1;
820 820
    subpage_register(subpage, start, end, phys_section_add(section));
821 821
}
822 822

  
823 823

  
824
static void register_multipage(AddressSpaceDispatch *d, MemoryRegionSection *section)
824
static void register_multipage(AddressSpaceDispatch *d,
825
                               MemoryRegionSection *section)
825 826
{
826 827
    hwaddr start_addr = section->offset_within_address_space;
827 828
    uint16_t section_index = phys_section_add(section);
828
    uint64_t num_pages = section->size >> TARGET_PAGE_BITS;
829
    uint64_t num_pages = int128_get64(int128_rshift(section->size,
830
                                                    TARGET_PAGE_BITS));
829 831

  
830 832
    assert(num_pages);
831 833
    phys_page_set(d, start_addr >> TARGET_PAGE_BITS, num_pages, section_index);
......
835 837
{
836 838
    AddressSpaceDispatch *d = container_of(listener, AddressSpaceDispatch, listener);
837 839
    MemoryRegionSection now = *section, remain = *section;
840
    Int128 page_size = int128_make64(TARGET_PAGE_SIZE);
838 841

  
839 842
    if (now.offset_within_address_space & ~TARGET_PAGE_MASK) {
840 843
        uint64_t left = TARGET_PAGE_ALIGN(now.offset_within_address_space)
841 844
                       - now.offset_within_address_space;
842 845

  
843
        now.size = MIN(left, now.size);
846
        now.size = int128_min(int128_make64(left), now.size);
844 847
        register_subpage(d, &now);
845 848
    } else {
846
        now.size = 0;
849
        now.size = int128_zero();
847 850
    }
848
    while (remain.size != now.size) {
849
        remain.size -= now.size;
850
        remain.offset_within_address_space += now.size;
851
        remain.offset_within_region += now.size;
851
    while (int128_ne(remain.size, now.size)) {
852
        remain.size = int128_sub(remain.size, now.size);
853
        remain.offset_within_address_space += int128_get64(now.size);
854
        remain.offset_within_region += int128_get64(now.size);
852 855
        now = remain;
853
        if (remain.size < TARGET_PAGE_SIZE) {
856
        if (int128_lt(remain.size, page_size)) {
854 857
            register_subpage(d, &now);
855 858
        } else if (remain.offset_within_region & ~TARGET_PAGE_MASK) {
856
            now.size = TARGET_PAGE_SIZE;
859
            now.size = page_size;
857 860
            register_subpage(d, &now);
858 861
        } else {
859
            now.size &= -TARGET_PAGE_SIZE;
862
            now.size = int128_and(now.size, int128_neg(page_size));
860 863
            register_multipage(d, &now);
861 864
        }
862 865
    }
......
1666 1669
        .mr = mr,
1667 1670
        .offset_within_address_space = 0,
1668 1671
        .offset_within_region = 0,
1669
        .size = UINT64_MAX,
1672
        .size = int128_2_64(),
1670 1673
    };
1671 1674

  
1672 1675
    return phys_section_add(&section);
......
1735 1738
    mrio->mr = section->mr;
1736 1739
    mrio->offset = section->offset_within_region;
1737 1740
    iorange_init(&mrio->iorange, &memory_region_iorange_ops,
1738
                 section->offset_within_address_space, section->size);
1741
                 section->offset_within_address_space,
1742
                 int128_get64(section->size));
1739 1743
    ioport_register(&mrio->iorange);
1740 1744
}
1741 1745

  
1742 1746
static void io_region_del(MemoryListener *listener,
1743 1747
                          MemoryRegionSection *section)
1744 1748
{
1745
    isa_unassign_ioport(section->offset_within_address_space, section->size);
1749
    isa_unassign_ioport(section->offset_within_address_space,
1750
                        int128_get64(section->size));
1746 1751
}
1747 1752

  
1748 1753
static MemoryListener core_memory_listener = {
b/hw/core/loader.c
726 726
        addr  = rom->addr;
727 727
        addr += rom->romsize;
728 728
        section = memory_region_find(get_system_memory(), rom->addr, 1);
729
        rom->isrom = section.size && memory_region_is_rom(section.mr);
729
        rom->isrom = int128_nz(section.size) && memory_region_is_rom(section.mr);
730 730
    }
731 731
    qemu_register_reset(rom_reset, NULL);
732 732
    roms_loaded = 1;
b/hw/display/exynos4210_fimd.c
1133 1133
    DPRINT_TRACE("Window %u framebuffer changed: address=0x%08x, len=0x%x\n",
1134 1134
            win, fb_start_addr, w->fb_len);
1135 1135

  
1136
    if (w->mem_section.size != w->fb_len ||
1136
    if (int128_get64(w->mem_section.size) != w->fb_len ||
1137 1137
            !memory_region_is_ram(w->mem_section.mr)) {
1138 1138
        DPRINT_ERROR("Failed to find window %u framebuffer region\n", win);
1139 1139
        goto error_return;
......
1155 1155

  
1156 1156
error_return:
1157 1157
    w->mem_section.mr = NULL;
1158
    w->mem_section.size = 0;
1158
    w->mem_section.size = int128_zero();
1159 1159
    w->host_fb_addr = NULL;
1160 1160
    w->fb_len = 0;
1161 1161
}
b/hw/display/framebuffer.c
54 54
    src_len = src_width * rows;
55 55

  
56 56
    mem_section = memory_region_find(address_space, base, src_len);
57
    if (mem_section.size != src_len || !memory_region_is_ram(mem_section.mr)) {
57
    if (int128_get64(mem_section.size) != src_len ||
58
            !memory_region_is_ram(mem_section.mr)) {
58 59
        return;
59 60
    }
60 61
    mem = mem_section.mr;
b/hw/misc/vfio.c
1953 1953
    }
1954 1954

  
1955 1955
    iova = TARGET_PAGE_ALIGN(section->offset_within_address_space);
1956
    end = (section->offset_within_address_space + section->size) &
1956
    end = (section->offset_within_address_space + int128_get64(section->size)) &
1957 1957
          TARGET_PAGE_MASK;
1958 1958

  
1959 1959
    if (iova >= end) {
......
1997 1997
    }
1998 1998

  
1999 1999
    iova = TARGET_PAGE_ALIGN(section->offset_within_address_space);
2000
    end = (section->offset_within_address_space + section->size) &
2000
    end = (section->offset_within_address_space + int128_get64(section->size)) &
2001 2001
          TARGET_PAGE_MASK;
2002 2002

  
2003 2003
    if (iova >= end) {
b/hw/virtio/dataplane/hostmem.c
90 90
    hostmem->new_regions[num] = (HostMemRegion){
91 91
        .host_addr = ram_ptr + section->offset_within_region,
92 92
        .guest_addr = section->offset_within_address_space,
93
        .size = section->size,
93
        .size = int128_get64(section->size),
94 94
        .readonly = section->readonly,
95 95
    };
96 96
    hostmem->num_new_regions++;
b/hw/virtio/vhost.c
81 81
        return 0;
82 82
    }
83 83
    start_addr = section->offset_within_address_space;
84
    end_addr = range_get_last(start_addr, section->size);
84
    end_addr = range_get_last(start_addr, int128_get64(section->size));
85 85
    start_addr = MAX(first, start_addr);
86 86
    end_addr = MIN(last, end_addr);
87 87

  
......
379 379
    struct vhost_dev *dev = container_of(listener, struct vhost_dev,
380 380
                                         memory_listener);
381 381
    hwaddr start_addr = section->offset_within_address_space;
382
    ram_addr_t size = section->size;
382
    ram_addr_t size = int128_get64(section->size);
383 383
    bool log_dirty = memory_region_is_logging(section->mr);
384 384
    int s = offsetof(struct vhost_memory, regions) +
385 385
        (dev->mem->nregions + 1) * sizeof dev->mem->regions[0];
b/hw/virtio/virtio-balloon.c
197 197

  
198 198
            /* FIXME: remove get_system_memory(), but how? */
199 199
            section = memory_region_find(get_system_memory(), pa, 1);
200
            if (!section.size || !memory_region_is_ram(section.mr))
200
            if (!int128_nz(section.size) || !memory_region_is_ram(section.mr))
201 201
                continue;
202 202

  
203 203
            /* Using memory_region_get_ram_ptr is bending the rules a bit, but
b/hw/xen/xen_pt.c
547 547
    struct CheckBarArgs args = {
548 548
        .s = s,
549 549
        .addr = sec->offset_within_address_space,
550
        .size = sec->size,
550
        .size = int128_get64(sec->size),
551 551
        .rc = false,
552 552
    };
553 553

  
......
576 576
    if (d->io_regions[bar].type & PCI_BASE_ADDRESS_SPACE_IO) {
577 577
        uint32_t guest_port = sec->offset_within_address_space;
578 578
        uint32_t machine_port = s->bases[bar].access.pio_base;
579
        uint32_t size = sec->size;
579
        uint32_t size = int128_get64(sec->size);
580 580
        rc = xc_domain_ioport_mapping(xen_xc, xen_domid,
581 581
                                      guest_port, machine_port, size,
582 582
                                      op);
......
588 588
        pcibus_t guest_addr = sec->offset_within_address_space;
589 589
        pcibus_t machine_addr = s->bases[bar].access.maddr
590 590
            + sec->offset_within_region;
591
        pcibus_t size = sec->size;
591
        pcibus_t size = int128_get64(sec->size);
592 592
        rc = xc_domain_memory_mapping(xen_xc, xen_domid,
593 593
                                      XEN_PFN(guest_addr + XC_PAGE_SIZE - 1),
594 594
                                      XEN_PFN(machine_addr + XC_PAGE_SIZE - 1),
b/include/exec/memory.h
26 26
#include "exec/ioport.h"
27 27
#include "qemu/int128.h"
28 28

  
29
#define MAX_PHYS_ADDR_SPACE_BITS 62
30
#define MAX_PHYS_ADDR            (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1)
31

  
29 32
typedef struct MemoryRegionOps MemoryRegionOps;
30 33
typedef struct MemoryRegionPortio MemoryRegionPortio;
31 34
typedef struct MemoryRegionMmio MemoryRegionMmio;
......
185 188
    MemoryRegion *mr;
186 189
    AddressSpace *address_space;
187 190
    hwaddr offset_within_region;
188
    uint64_t size;
191
    Int128 size;
189 192
    hwaddr offset_within_address_space;
190 193
    bool readonly;
191 194
};
b/include/qemu/int128.h
34 34
    return (Int128) { 0, 1 };
35 35
}
36 36

  
37
static inline Int128 int128_and(Int128 a, Int128 b)
38
{
39
    return (Int128) { a.lo & b.lo, a.hi & b.hi };
40
}
41

  
42
static inline Int128 int128_rshift(Int128 a, int n)
43
{
44
    int64_t h;
45
    if (!n) {
46
        return a;
47
    }
48
    h = a.hi >> (n & 63);
49
    if (n >= 64) {
50
        return (Int128) { h, h >> 63 };
51
    } else {
52
        return (Int128) { (a.lo >> n) | (a.hi << (64 - n)), h };
53
    }
54
}
55

  
37 56
static inline Int128 int128_add(Int128 a, Int128 b)
38 57
{
39 58
    Int128 r = { a.lo + b.lo, a.hi + b.hi };
b/kvm-all.c
329 329
    int r;
330 330

  
331 331
    r = kvm_dirty_pages_log_change(section->offset_within_address_space,
332
                                   section->size, true);
332
                                   int128_get64(section->size), true);
333 333
    if (r < 0) {
334 334
        abort();
335 335
    }
......
341 341
    int r;
342 342

  
343 343
    r = kvm_dirty_pages_log_change(section->offset_within_address_space,
344
                                   section->size, false);
344
                                   int128_get64(section->size), false);
345 345
    if (r < 0) {
346 346
        abort();
347 347
    }
......
379 379
    unsigned int i, j;
380 380
    unsigned long page_number, c;
381 381
    hwaddr addr, addr1;
382
    unsigned int len = ((section->size / getpagesize()) + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
382
    unsigned int pages = int128_get64(section->size) / getpagesize();
383
    unsigned int len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
383 384
    unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
384 385

  
385 386
    /*
......
422 423
    KVMSlot *mem;
423 424
    int ret = 0;
424 425
    hwaddr start_addr = section->offset_within_address_space;
425
    hwaddr end_addr = start_addr + section->size;
426
    hwaddr end_addr = start_addr + int128_get64(section->size);
426 427

  
427 428
    d.dirty_bitmap = NULL;
428 429
    while (start_addr < end_addr) {
......
634 635
    bool writeable = !mr->readonly && !mr->rom_device;
635 636
    bool readonly_flag = mr->readonly || memory_region_is_romd(mr);
636 637
    hwaddr start_addr = section->offset_within_address_space;
637
    ram_addr_t size = section->size;
638
    ram_addr_t size = int128_get64(section->size);
638 639
    void *ram = NULL;
639 640
    unsigned delta;
640 641

  
......
832 833
    int r;
833 834

  
834 835
    r = kvm_set_ioeventfd_mmio(fd, section->offset_within_address_space,
835
                               data, true, section->size, match_data);
836
                               data, true, int128_get64(section->size),
837
                               match_data);
836 838
    if (r < 0) {
837 839
        abort();
838 840
    }
......
847 849
    int r;
848 850

  
849 851
    r = kvm_set_ioeventfd_mmio(fd, section->offset_within_address_space,
850
                               data, false, section->size, match_data);
852
                               data, false, int128_get64(section->size),
853
                               match_data);
851 854
    if (r < 0) {
852 855
        abort();
853 856
    }
......
862 865
    int r;
863 866

  
864 867
    r = kvm_set_ioeventfd_pio(fd, section->offset_within_address_space,
865
                              data, true, section->size, match_data);
868
                              data, true, int128_get64(section->size),
869
                              match_data);
866 870
    if (r < 0) {
867 871
        abort();
868 872
    }
......
878 882
    int r;
879 883

  
880 884
    r = kvm_set_ioeventfd_pio(fd, section->offset_within_address_space,
881
                              data, false, section->size, match_data);
885
                              data, false, int128_get64(section->size),
886
                              match_data);
882 887
    if (r < 0) {
883 888
        abort();
884 889
    }
b/memory.c
152 152
        .mr = (fr)->mr,                                                 \
153 153
        .address_space = (as),                                          \
154 154
        .offset_within_region = (fr)->offset_in_region,                 \
155
        .size = int128_get64((fr)->addr.size),                          \
155
        .size = (fr)->addr.size,                                        \
156 156
        .offset_within_address_space = int128_get64((fr)->addr.start),  \
157 157
        .readonly = (fr)->readonly,                                     \
158 158
              }))
......
634 634
            section = (MemoryRegionSection) {
635 635
                .address_space = as,
636 636
                .offset_within_address_space = int128_get64(fd->addr.start),
637
                .size = int128_get64(fd->addr.size),
637
                .size = fd->addr.size,
638 638
            };
639 639
            MEMORY_LISTENER_CALL(eventfd_del, Forward, &section,
640 640
                                 fd->match_data, fd->data, fd->e);
......
647 647
            section = (MemoryRegionSection) {
648 648
                .address_space = as,
649 649
                .offset_within_address_space = int128_get64(fd->addr.start),
650
                .size = int128_get64(fd->addr.size),
650
                .size = fd->addr.size,
651 651
            };
652 652
            MEMORY_LISTENER_CALL(eventfd_add, Reverse, &section,
653 653
                                 fd->match_data, fd->data, fd->e);
......
1215 1215
            section = (MemoryRegionSection) {
1216 1216
                .address_space = as,
1217 1217
                .offset_within_address_space = int128_get64(fr->addr.start),
1218
                .size = int128_get64(fr->addr.size),
1218
                .size = fr->addr.size,
1219 1219
            };
1220 1220

  
1221 1221
            MEMORY_LISTENER_CALL(coalesced_mmio_del, Reverse, &section,
......
1506 1506
MemoryRegionSection memory_region_find(MemoryRegion *mr,
1507 1507
                                       hwaddr addr, uint64_t size)
1508 1508
{
1509
    MemoryRegionSection ret = { .mr = NULL, .size = 0 };
1509
    MemoryRegionSection ret = { .mr = NULL };
1510 1510
    MemoryRegion *root;
1511 1511
    AddressSpace *as;
1512 1512
    AddrRange range;
......
1536 1536
    ret.offset_within_region = fr->offset_in_region;
1537 1537
    ret.offset_within_region += int128_get64(int128_sub(range.start,
1538 1538
                                                        fr->addr.start));
1539
    ret.size = int128_get64(range.size);
1539
    ret.size = range.size;
1540 1540
    ret.offset_within_address_space = int128_get64(range.start);
1541 1541
    ret.readonly = fr->readonly;
1542 1542
    return ret;
......
1584 1584
            .mr = fr->mr,
1585 1585
            .address_space = as,
1586 1586
            .offset_within_region = fr->offset_in_region,
1587
            .size = int128_get64(fr->addr.size),
1587
            .size = fr->addr.size,
1588 1588
            .offset_within_address_space = int128_get64(fr->addr.start),
1589 1589
            .readonly = fr->readonly,
1590 1590
        };
......
1712 1712
                   "-" TARGET_FMT_plx "\n",
1713 1713
                   base + mr->addr,
1714 1714
                   base + mr->addr
1715
                   + (hwaddr)int128_get64(mr->size) - 1,
1715
                   + (hwaddr)int128_get64(int128_sub(mr->size, int128_make64(1))),
1716 1716
                   mr->priority,
1717 1717
                   mr->romd_mode ? 'R' : '-',
1718 1718
                   !mr->readonly && !(mr->rom_device && mr->romd_mode) ? 'W'
......
1727 1727
                   TARGET_FMT_plx "-" TARGET_FMT_plx " (prio %d, %c%c): %s\n",
1728 1728
                   base + mr->addr,
1729 1729
                   base + mr->addr
1730
                   + (hwaddr)int128_get64(mr->size) - 1,
1730
                   + (hwaddr)int128_get64(int128_sub(mr->size, int128_make64(1))),
1731 1731
                   mr->priority,
1732 1732
                   mr->romd_mode ? 'R' : '-',
1733 1733
                   !mr->readonly && !(mr->rom_device && mr->romd_mode) ? 'W'
b/target-sparc/mmu_helper.c
845 845
        }
846 846
    }
847 847
    section = memory_region_find(get_system_memory(), phys_addr, 1);
848
    if (!section.size) {
848
    if (!int128_nz(section.size)) {
849 849
        return -1;
850 850
    }
851 851
    return phys_addr;
b/xen-all.c
418 418
{
419 419
    XenIOState *state = container_of(listener, XenIOState, memory_listener);
420 420
    hwaddr start_addr = section->offset_within_address_space;
421
    ram_addr_t size = section->size;
421
    ram_addr_t size = int128_get64(section->size);
422 422
    bool log_dirty = memory_region_is_logging(section->mr);
423 423
    hvmmem_type_t mem_type;
424 424

  
......
522 522
    XenIOState *state = container_of(listener, XenIOState, memory_listener);
523 523

  
524 524
    xen_sync_dirty_bitmap(state, section->offset_within_address_space,
525
                          section->size);
525
                          int128_get64(section->size));
526 526
}
527 527

  
528 528
static void xen_log_stop(MemoryListener *listener, MemoryRegionSection *section)
......
539 539
    XenIOState *state = container_of(listener, XenIOState, memory_listener);
540 540

  
541 541
    xen_sync_dirty_bitmap(state, section->offset_within_address_space,
542
                          section->size);
542
                          int128_get64(section->size));
543 543
}
544 544

  
545 545
static void xen_log_global_start(MemoryListener *listener)

Also available in: Unified diff