17ec681f3Smrg/*
27ec681f3Smrg * Copyright (C) 2021 Alyssa Rosenzweig <alyssa@rosenzweig.io>
37ec681f3Smrg *
47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg * to deal in the Software without restriction, including without limitation
77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the
97ec681f3Smrg * Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg *
117ec681f3Smrg * The above copyright notice and this permission notice (including the next
127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
137ec681f3Smrg * Software.
147ec681f3Smrg *
157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
207ec681f3Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
217ec681f3Smrg * SOFTWARE.
227ec681f3Smrg */
237ec681f3Smrg
247ec681f3Smrg#ifndef __AGX_DEVICE_H
257ec681f3Smrg#define __AGX_DEVICE_H
267ec681f3Smrg
277ec681f3Smrg#include "util/sparse_array.h"
287ec681f3Smrg#include "io.h"
297ec681f3Smrg#include "agx_formats.h"
307ec681f3Smrg
317ec681f3Smrg#if __APPLE__
327ec681f3Smrg#include <mach/mach.h>
337ec681f3Smrg#include <IOKit/IOKitLib.h>
347ec681f3Smrg#endif
357ec681f3Smrg
367ec681f3Smrgenum agx_dbg {
377ec681f3Smrg   AGX_DBG_TRACE = BITFIELD_BIT(0),
387ec681f3Smrg   AGX_DBG_DEQP  = BITFIELD_BIT(1),
397ec681f3Smrg   AGX_DBG_NO16  = BITFIELD_BIT(2),
407ec681f3Smrg};
417ec681f3Smrg
427ec681f3Smrgstruct agx_device {
437ec681f3Smrg   void *memctx;
447ec681f3Smrg   uint32_t debug;
457ec681f3Smrg
467ec681f3Smrg   /* XXX What to bind to? I don't understand the IOGPU UABI */
477ec681f3Smrg   struct agx_command_queue queue;
487ec681f3Smrg   struct agx_bo cmdbuf, memmap;
497ec681f3Smrg   uint64_t next_global_id, last_global_id;
507ec681f3Smrg
517ec681f3Smrg   /* Device handle */
527ec681f3Smrg#if __APPLE__
537ec681f3Smrg   io_connect_t fd;
547ec681f3Smrg#else
557ec681f3Smrg   int fd;
567ec681f3Smrg#endif
577ec681f3Smrg
587ec681f3Smrg   pthread_mutex_t bo_map_lock;
597ec681f3Smrg   struct util_sparse_array bo_map;
607ec681f3Smrg
617ec681f3Smrg   /* Fixed shaders */
627ec681f3Smrg   struct {
637ec681f3Smrg      struct agx_bo *bo;
647ec681f3Smrg      uint32_t clear;
657ec681f3Smrg      uint32_t store;
667ec681f3Smrg   } internal;
677ec681f3Smrg
687ec681f3Smrg   struct {
697ec681f3Smrg      struct agx_bo *bo;
707ec681f3Smrg      uint32_t format[AGX_NUM_FORMATS];
717ec681f3Smrg   } reload;
727ec681f3Smrg};
737ec681f3Smrg
747ec681f3Smrgbool
757ec681f3Smrgagx_open_device(void *memctx, struct agx_device *dev);
767ec681f3Smrg
777ec681f3Smrgvoid
787ec681f3Smrgagx_close_device(struct agx_device *dev);
797ec681f3Smrg
807ec681f3Smrgstatic inline struct agx_bo *
817ec681f3Smrgagx_lookup_bo(struct agx_device *dev, uint32_t handle)
827ec681f3Smrg{
837ec681f3Smrg   return util_sparse_array_get(&dev->bo_map, handle);
847ec681f3Smrg}
857ec681f3Smrg
867ec681f3Smrgstruct agx_bo
877ec681f3Smrgagx_shmem_alloc(struct agx_device *dev, size_t size, bool cmdbuf);
887ec681f3Smrg
897ec681f3Smrgvoid
907ec681f3Smrgagx_shmem_free(struct agx_device *dev, unsigned handle);
917ec681f3Smrg
927ec681f3Smrguint64_t
937ec681f3Smrgagx_get_global_id(struct agx_device *dev);
947ec681f3Smrg
957ec681f3Smrgstruct agx_command_queue
967ec681f3Smrgagx_create_command_queue(struct agx_device *dev);
977ec681f3Smrg
987ec681f3Smrgvoid
997ec681f3Smrgagx_submit_cmdbuf(struct agx_device *dev, unsigned cmdbuf, unsigned mappings, uint64_t scalar);
1007ec681f3Smrg
1017ec681f3Smrgvoid
1027ec681f3Smrgagx_wait_queue(struct agx_command_queue queue);
1037ec681f3Smrg
1047ec681f3Smrg#endif
105