asahi: Fix ASTC enums
[platform/upstream/mesa.git] / src / asahi / lib / agx_device.h
1 /*
2  * Copyright (C) 2021 Alyssa Rosenzweig <alyssa@rosenzweig.io>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23
24 #ifndef __AGX_DEVICE_H
25 #define __AGX_DEVICE_H
26
27 #include "util/sparse_array.h"
28 #include "io.h"
29 #include "agx_formats.h"
30
31 #if __APPLE__
32 #include <mach/mach.h>
33 #include <IOKit/IOKitLib.h>
34 #endif
35
36 enum agx_dbg {
37    AGX_DBG_TRACE = BITFIELD_BIT(0),
38    AGX_DBG_DEQP  = BITFIELD_BIT(1),
39    AGX_DBG_NO16  = BITFIELD_BIT(2),
40 };
41
42 struct agx_device {
43    void *memctx;
44    uint32_t debug;
45
46    /* XXX What to bind to? I don't understand the IOGPU UABI */
47    struct agx_command_queue queue;
48    struct agx_bo cmdbuf, memmap;
49    uint64_t next_global_id, last_global_id;
50
51    /* Device handle */
52 #if __APPLE__
53    io_connect_t fd;
54 #else
55    int fd;
56 #endif
57
58    pthread_mutex_t bo_map_lock;
59    struct util_sparse_array bo_map;
60
61    /* Fixed shaders */
62    struct {
63       struct agx_bo *bo;
64       uint32_t clear;
65       uint32_t store;
66    } internal;
67
68    struct {
69       struct agx_bo *bo;
70       uint32_t format[AGX_NUM_FORMATS];
71    } reload;
72 };
73
74 bool
75 agx_open_device(void *memctx, struct agx_device *dev);
76
77 void
78 agx_close_device(struct agx_device *dev);
79
80 static inline struct agx_bo *
81 agx_lookup_bo(struct agx_device *dev, uint32_t handle)
82 {
83    return util_sparse_array_get(&dev->bo_map, handle);
84 }
85
86 struct agx_bo
87 agx_shmem_alloc(struct agx_device *dev, size_t size, bool cmdbuf);
88
89 void
90 agx_shmem_free(struct agx_device *dev, unsigned handle);
91
92 uint64_t
93 agx_get_global_id(struct agx_device *dev);
94
95 struct agx_command_queue
96 agx_create_command_queue(struct agx_device *dev);
97
98 void
99 agx_submit_cmdbuf(struct agx_device *dev, unsigned cmdbuf, unsigned mappings, uint64_t scalar);
100
101 void
102 agx_wait_queue(struct agx_command_queue queue);
103
104 #endif