summaryrefslogtreecommitdiff
path: root/compote.h
blob: 6d0cc3b87c21eef2f9e2519f6370728c713027a0 (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
89
90
91
92
93
94
/*
 * 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>
 */
#ifndef COMPOTE_H
#define COMPOTE_H

#include <stdint.h>

typedef struct {
    uint64_t                    id;
} compote_channel_t;

typedef struct {
    int                         fd;
    compote_channel_t           channel;
} compote_context_t;

typedef struct {
    uint64_t                    foffset;
    uint64_t                    nbytes;
    void                        *ptr;
} compote_mo_t;

int compote_context_new(compote_context_t **ctxp);
void compote_context_del(compote_context_t **ctxp);
int compote_context_ioctl(compote_context_t *ctx, int command, void *arg);
int compote_context_execute(compote_context_t *ctx,
                            void *addr, unsigned ndw);

int compote_mo_new(compote_context_t *ctx, compote_mo_t **mop, uint64_t nbytes);
void compote_mo_del(compote_context_t *ctx, compote_mo_t **mop);

static inline uint64_t compote_mo_gpu_addr(compote_mo_t *mo)
{
    if (mo == NULL || mo->ptr == NULL) {
        return -1UL;
    }

    return (unsigned long)mo->ptr;
}

void *malloc_below40(unsigned nbytes);

static inline uint32_t nvk_sq_cmd(unsigned subc, unsigned method, unsigned len)
{
    return ((method >> 2) & 0x1fff) |
           ((len & 0xfff) << 16) |
           ((subc & 0x7) << 13) |
           (0x1 << 29);
}

static inline uint32_t nvk_ni_cmd(unsigned subc, unsigned method, unsigned len)
{
    return ((method >> 2) & 0x1fff) |
           ((len & 0xfff) << 16) |
           ((subc & 0x7) << 13) |
           (0x3 << 29);
}

static inline uint32_t nvk_addr_high(uint64_t offset)
{
    return (offset >> 32) & 0xffffffff;
}

static inline uint32_t nvk_addr_low(uint64_t offset)
{
    return offset & 0xffffffff;
}

static inline uint32_t nvk_size_high(uint64_t offset)
{
    return (offset >> 32) & 0xffffffff;
}

static inline uint32_t nvk_size_low(uint64_t offset)
{
    return offset & 0xffffffff;
}

int test_compute(compote_context_t *ctx, void *buffer, void *dstp, unsigned dimx);

#endif // COMPOTE_H