summaryrefslogtreecommitdiff
path: root/new.c
blob: cee2f2030f001e5adc7765a417e175d69e703bbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * Copyright 2017 Red Hat Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Authors: Jérôme Glisse <jglisse@redhat.com>
 */
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <strings.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>

#include "compote.h"
#include "compote-uapi.h"

int main(int argc, char *argv[])
{
    compote_context_t *ctx;
    compote_mo_t *mo;
    void *dst;
    int ret;

    ret = compote_context_new(&ctx);
    if (ret) {
        return ret;
    }

    ret = compote_mo_new(ctx, &mo, 32 << 20);
    if (ret) {
        goto out;
    }

    dst = malloc_below40(4 << 20);
    if (dst == NULL) {
        ret = -ENOMEM;
        goto out;
    }
    printf("dst addr %p\n", dst);

    {
        uint32_t *ptr = mo->ptr;
        uint32_t *sem = &ptr[128 >> 2];

        sem[0] = 0xcafedead;

        ptr[0] = nvk_sq_cmd(1, 0x10, 4);
        ptr[1] = ((unsigned long)sem) >> 32;
        ptr[2] = ((unsigned long)sem) & 0xffffffff;
        ptr[3] = 0xdeadcafe;
        ptr[4] = 0x00000002;
        ret = compote_context_execute(ctx, ptr, 5);
        if (ret) {
            goto out;
        }

        for (unsigned c = 0; (c < 10) && (ptr[128 >> 2] != 0xdeadcafe); c++) {
            printf("[%4d] = 0x%08x 0x%08x 0x%08x\n", 128 >> 2, sem[0], sem[1], sem[2]);
            sleep(1);
        }
        printf("[%4d] = 0x%08x 0x%08x 0x%08x\n", 128 >> 2, sem[0], sem[1], sem[2]);
    }

    ret = test_compute(ctx, mo->ptr, dst, 1024);
    if (ret)
        goto out;

    printf("La compote c'est bon !\n");

out:
    compote_mo_del(ctx, &mo);
    compote_context_del(&ctx);
    return ret;
}