Пример #1
0
static gint pc_dimm_addr_sort(gconstpointer a, gconstpointer b)
{
    PCDIMMDevice *x = PC_DIMM(a);
    PCDIMMDevice *y = PC_DIMM(b);
    Int128 diff = int128_sub(int128_make64(x->addr), int128_make64(y->addr));

    if (int128_lt(diff, int128_zero())) {
        return -1;
    } else if (int128_gt(diff, int128_zero())) {
        return 1;
    }
    return 0;
}
Пример #2
0
int main(int argc, char** argv)
{
    int128 m;
    int128 a;
    int128 b;
    int128 f1,f2,tmp,fix;
    int128 x;
    int128 one;

    int res=0;

    unsigned long long progr;
    unsigned long long count=0;

    if (argc!=4)
    {
       printf("Program to find the fixpoint for given parameters m,a and b\nusage: ./fixpoint m a b\n");exit(-1);
    }

    int128_from_string(&m,argv[1]);
    int128_from_string(&a,argv[2]);
    int128_from_string(&b,argv[3]);
    int128_from_int(&x,0,0,0,0);
    int128_from_int(&one,0,0,0,1);

    int128_from_int(&tmp,0,0,0,50);
    int128_div(a,tmp,&tmp);
    progr=int128_getlower(tmp);
    if (progr==0) progr=1;
    count=0;

    int128_sub(a,one,&tmp);

    printf("m= %s, a= %s, b= %s\n",int128_toString(m,10,39),int128_toString(a,10,39),int128_toString(b,10,39));

    for(;int128_unsigned_compare(x,a)!=1;int128_add(x,one,&x))
    {
        //f1 = ((x*m) -b ) / (a-1)
        int128_mult(x,m,&f1);
        int128_sub(f1,b,&f1);
        int128_div(f1,tmp,&f1);

        //f2 = ((f1*a)-b) % m
        int128_mult(f1,a,&f2);
        int128_add(f2,b,&f2);
        int128_mod(f2,m,&f2);

        count++;
        if (count==progr) {count=0;printf(".");fflush(stdout);}

        if (int128_unsigned_compare(f1,f2)==0) 
        {
            //printf("\nx=%s: f1=%s, f2=%s\n",int128_toString(x,10,39),int128_toString(f1,10,39),int128_toString(f2,10,39));
            int128_copy(f1,&fix);
            res++;
        }
    }

    if (res==1) printf("\nfound Fixpoint: %s\n",int128_toString(fix,10,39));
    else if (res>1) printf("\nERROR: Found multiple Fixpoints (-> bad parameters)\n");
    else printf("\nno Fixpoint found\n");

    return 0;
}
Пример #3
0
static void vfio_prereg_listener_region_add(MemoryListener *listener,
                                            MemoryRegionSection *section)
{
    VFIOContainer *container = container_of(listener, VFIOContainer,
                                            prereg_listener);
    const hwaddr gpa = section->offset_within_address_space;
    hwaddr end;
    int ret;
    hwaddr page_mask = qemu_real_host_page_mask;
    struct vfio_iommu_spapr_register_memory reg = {
        .argsz = sizeof(reg),
        .flags = 0,
    };

    if (vfio_prereg_listener_skipped_section(section)) {
        trace_vfio_prereg_listener_region_add_skip(
                section->offset_within_address_space,
                section->offset_within_address_space +
                int128_get64(int128_sub(section->size, int128_one())));
        return;
    }

    if (unlikely((section->offset_within_address_space & ~page_mask) ||
                 (section->offset_within_region & ~page_mask) ||
                 (int128_get64(section->size) & ~page_mask))) {
        error_report("%s received unaligned region", __func__);
        return;
    }

    end = section->offset_within_address_space + int128_get64(section->size);
    if (gpa >= end) {
        return;
    }

    memory_region_ref(section->mr);

    reg.vaddr = (uintptr_t) vfio_prereg_gpa_to_vaddr(section, gpa);
    reg.size = end - gpa;

    ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_REGISTER_MEMORY, &reg);
    trace_vfio_prereg_register(reg.vaddr, reg.size, ret ? -errno : 0);
    if (ret) {
        /*
         * On the initfn path, store the first error in the container so we
         * can gracefully fail.  Runtime, there's not much we can do other
         * than throw a hardware error.
         */
        if (!container->initialized) {
            if (!container->error) {
                container->error = ret;
            }
        } else {
            hw_error("vfio: Memory registering failed, unable to continue");
        }
    }
}

static void vfio_prereg_listener_region_del(MemoryListener *listener,
                                            MemoryRegionSection *section)
{
    VFIOContainer *container = container_of(listener, VFIOContainer,
                                            prereg_listener);
    const hwaddr gpa = section->offset_within_address_space;
    hwaddr end;
    int ret;
    hwaddr page_mask = qemu_real_host_page_mask;
    struct vfio_iommu_spapr_register_memory reg = {
        .argsz = sizeof(reg),
        .flags = 0,
    };

    if (vfio_prereg_listener_skipped_section(section)) {
        trace_vfio_prereg_listener_region_del_skip(
                section->offset_within_address_space,
                section->offset_within_address_space +
                int128_get64(int128_sub(section->size, int128_one())));
        return;
    }

    if (unlikely((section->offset_within_address_space & ~page_mask) ||
                 (section->offset_within_region & ~page_mask) ||
                 (int128_get64(section->size) & ~page_mask))) {
        error_report("%s received unaligned region", __func__);
        return;
    }

    end = section->offset_within_address_space + int128_get64(section->size);
    if (gpa >= end) {
        return;
    }

    reg.vaddr = (uintptr_t) vfio_prereg_gpa_to_vaddr(section, gpa);
    reg.size = end - gpa;

    ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY, &reg);
    trace_vfio_prereg_unregister(reg.vaddr, reg.size, ret ? -errno : 0);
}

const MemoryListener vfio_prereg_listener = {
    .region_add = vfio_prereg_listener_region_add,
    .region_del = vfio_prereg_listener_region_del,
};

int vfio_spapr_create_window(VFIOContainer *container,
                             MemoryRegionSection *section,
                             hwaddr *pgsize)
{
    int ret;
    unsigned pagesize = memory_region_iommu_get_min_page_size(section->mr);
    unsigned entries, pages;
    struct vfio_iommu_spapr_tce_create create = { .argsz = sizeof(create) };

    /*
     * FIXME: For VFIO iommu types which have KVM acceleration to
     * avoid bouncing all map/unmaps through qemu this way, this
     * would be the right place to wire that up (tell the KVM
     * device emulation the VFIO iommu handles to use).
     */
    create.window_size = int128_get64(section->size);
    create.page_shift = ctz64(pagesize);
    /*
     * SPAPR host supports multilevel TCE tables, there is some
     * heuristic to decide how many levels we want for our table:
     * 0..64 = 1; 65..4096 = 2; 4097..262144 = 3; 262145.. = 4
     */
    entries = create.window_size >> create.page_shift;
    pages = MAX((entries * sizeof(uint64_t)) / getpagesize(), 1);
    pages = MAX(pow2ceil(pages) - 1, 1); /* Round up */
    create.levels = ctz64(pages) / 6 + 1;

    ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_CREATE, &create);
    if (ret) {
        error_report("Failed to create a window, ret = %d (%m)", ret);
        return -errno;
    }

    if (create.start_addr != section->offset_within_address_space) {
        vfio_spapr_remove_window(container, create.start_addr);

        error_report("Host doesn't support DMA window at %"HWADDR_PRIx", must be %"PRIx64,
                     section->offset_within_address_space,
                     (uint64_t)create.start_addr);
        return -EINVAL;
    }
    trace_vfio_spapr_create_window(create.page_shift,
                                   create.window_size,
                                   create.start_addr);
    *pgsize = pagesize;

    return 0;
}

int vfio_spapr_remove_window(VFIOContainer *container,
                             hwaddr offset_within_address_space)
{
    struct vfio_iommu_spapr_tce_remove remove = {
        .argsz = sizeof(remove),
        .start_addr = offset_within_address_space,
    };
    int ret;

    ret = ioctl(container->fd, VFIO_IOMMU_SPAPR_TCE_REMOVE, &remove);
    if (ret) {
        error_report("Failed to remove window at %"PRIx64,
                     (uint64_t)remove.start_addr);
        return -errno;
    }

    trace_vfio_spapr_remove_window(offset_within_address_space);

    return 0;
}
Пример #4
0
int main(int argc, char ** argv)
{
  int128 test1,test2,test3,test4;
  unsigned long long tmp1,tmp2,tmp3,tmp4,tmp5,tmp6,tmp7,tmp8;
  int err,res;

  int128_from_int(&test1,0,0,1,0xfffffffe);
  int128_from_int(&test2,0,0,0,0xffffffff);
  int128_from_int(&test3,0x7fffffff,0xffffffff,0xffffffff,0xffffffff);

 // int128_from_string(&test1,"10");
 // int128_from_string(&test2,"-19");
 // int128_from_string(&test3,"0");

  //int128_neg(&test1);
  //int128_neg(&test2);

  printf("hex:\n");

  printf("  test1: %s, upper= %016llx, lower= %016llx\n",int128_toString(test1,16,32),int128_getupper(test1),int128_getlower(test1));
  printf("  test2: %s, upper= %016llx, lower= %016llx\n",int128_toString(test2,16,32),int128_getupper(test2),int128_getlower(test2));
  printf("  test3: %s, upper= %016llx, lower= %016llx\n",int128_toString(test3,16,32),int128_getupper(test3),int128_getlower(test3));

  printf("dezimal:\n");

  printf("  test1: %s\n",int128_toString(test1,10,39));
  printf("  test2: %s\n",int128_toString(test2,10,39));
  printf("  test3: %s\n",int128_toString(test3,10,39));

  printf("test:\n");

   res=int128_unsigned_compare(test1,test2);

   if (res==0) printf(" %s = %s\n",int128_toString(test1,10,39),int128_toString(test2,10,39));
   if (res==-1) printf(" %s < %s\n",int128_toString(test1,10,39),int128_toString(test2,10,39));
   if (res==1) printf(" %s > %s\n",int128_toString(test1,10,39),int128_toString(test2,10,39));

    err = int128_add(test1,test2,&test3);
    if (err) {
                printf("   ERROR: add :: %i\n",err);//exit(-1);
             }
    printf (" %s + %s = %s\n",int128_toString(test1,16,32),int128_toString(test2,16,32),int128_toString(test3,16,32));
    printf (" %s + %s = %s\n",int128_toString(test1,10,39),int128_toString(test2,10,39),int128_toString(test3,10,39));

    err = int128_sub(test1,test2,&test3);
    if (err) {
                printf("   ERROR: sub :: %i\n",err);//exit(-1);
             }
    printf (" %s - %s = %s\n",int128_toString(test1,16,32),int128_toString(test2,16,32),int128_toString(test3,16,32));
    printf (" %s - %s = %s\n",int128_toString(test1,10,39),int128_toString(test2,10,39),int128_toString(test3,10,39));

    err = int128_mult(test1,test2,&test3);
    if (err) {
                printf("   ERROR: mul :: %i\n",err);//exit(-1);
             }
    printf (" %s * %s = %s\n",int128_toString(test1,16,32),int128_toString(test2,16,32),int128_toString(test3,16,32));
    printf (" %s * %s = %s\n",int128_toString(test1,10,39),int128_toString(test2,10,39),int128_toString(test3,10,39));

    err = int128_div(test1,test2,&test3);
    if (err) {
                printf("   ERROR: div :: %i\n",err);//exit(-1);
             }
    printf (" %s / %s = %s\n",int128_toString(test1,16,32),int128_toString(test2,16,32),int128_toString(test3,16,32));
    printf (" %s / %s = %s\n",int128_toString(test1,10,39),int128_toString(test2,10,39),int128_toString(test3,10,39));

    err = int128_mod(test1,test2,&test3);
    if (err) {
                printf("   ERROR: mod :: %i\n",err);//exit(-1);
             }
    printf (" %s %% %s = %s\n",int128_toString(test1,16,32),int128_toString(test2,16,32),int128_toString(test3,16,32));
    printf (" %s %% %s = %s\n",int128_toString(test1,10,39),int128_toString(test2,10,39),int128_toString(test3,10,39));
}