/*1* © Copyright 2019 Alyssa Rosenzweig2* © Copyright 2019 Collabora, Ltd.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* 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 THE21* SOFTWARE.22*23*/2425#ifndef __PAN_BO_H__26#define __PAN_BO_H__2728#include "util/list.h"29#include "panfrost-job.h"30#include <time.h>3132/* Flags for allocated memory */3334/* This memory region is executable */35#define PAN_BO_EXECUTE (1 << 0)3637/* This memory region should be lazily allocated and grow-on-page-fault. Must38* be used in conjunction with INVISIBLE */39#define PAN_BO_GROWABLE (1 << 1)4041/* This memory region should not be mapped to the CPU */42#define PAN_BO_INVISIBLE (1 << 2)4344/* This region may not be used immediately and will not mmap on allocate45* (semantically distinct from INVISIBLE, which cannot never be mmaped) */46#define PAN_BO_DELAY_MMAP (1 << 3)4748/* BO is shared across processes (imported or exported) and therefore cannot be49* cached locally */50#define PAN_BO_SHARED (1 << 4)5152/* GPU access flags */5354/* BO is either shared (can be accessed by more than one GPU batch) or private55* (reserved by a specific GPU job). */56#define PAN_BO_ACCESS_PRIVATE (0 << 0)57#define PAN_BO_ACCESS_SHARED (1 << 0)5859/* BO is being read/written by the GPU */60#define PAN_BO_ACCESS_READ (1 << 1)61#define PAN_BO_ACCESS_WRITE (1 << 2)62#define PAN_BO_ACCESS_RW (PAN_BO_ACCESS_READ | PAN_BO_ACCESS_WRITE)6364/* BO is accessed by the vertex/tiler job. */65#define PAN_BO_ACCESS_VERTEX_TILER (1 << 3)6667/* BO is accessed by the fragment job. */68#define PAN_BO_ACCESS_FRAGMENT (1 << 4)6970struct panfrost_device;7172struct panfrost_ptr {73/* CPU address */74void *cpu;7576/* GPU address */77mali_ptr gpu;78};7980struct panfrost_bo {81/* Must be first for casting */82struct list_head bucket_link;8384/* Used to link the BO to the BO cache LRU list. */85struct list_head lru_link;8687/* Store the time this BO was use last, so the BO cache logic can evict88* stale BOs.89*/90time_t last_used;9192/* Atomic reference count */93int32_t refcnt;9495struct panfrost_device *dev;9697/* Mapping for the entire object (all levels) */98struct panfrost_ptr ptr;99100/* Size of all entire trees */101size_t size;102103int gem_handle;104105uint32_t flags;106107/* Combination of PAN_BO_ACCESS_{READ,WRITE} flags encoding pending108* GPU accesses to this BO. Useful to avoid calling the WAIT_BO ioctl109* when the BO is idle.110*/111uint32_t gpu_access;112113/* Human readable description of the BO for debugging. */114const char *label;115};116117bool118panfrost_bo_wait(struct panfrost_bo *bo, int64_t timeout_ns, bool wait_readers);119void120panfrost_bo_reference(struct panfrost_bo *bo);121void122panfrost_bo_unreference(struct panfrost_bo *bo);123struct panfrost_bo *124panfrost_bo_create(struct panfrost_device *dev, size_t size,125uint32_t flags, const char *label);126void127panfrost_bo_mmap(struct panfrost_bo *bo);128struct panfrost_bo *129panfrost_bo_import(struct panfrost_device *dev, int fd);130int131panfrost_bo_export(struct panfrost_bo *bo);132void133panfrost_bo_cache_evict_all(struct panfrost_device *dev);134135#endif /* __PAN_BO_H__ */136137138