Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * © Copyright 2019 Alyssa Rosenzweig |
| 3 | * © Copyright 2019 Collabora, Ltd. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the next |
| 13 | * paragraph) shall be included in all copies or substantial portions of the |
| 14 | * Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #ifndef __PAN_BO_H__ |
| 27 | #define __PAN_BO_H__ |
| 28 | |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 29 | #include "util/list.h" |
Alyssa Rosenzweig | ca8c625 | 2020-03-23 18:44:21 -0400 | [diff] [blame] | 30 | #include "pan_device.h" |
Peter Seiderer | d512028 | 2020-03-22 11:48:31 +0100 | [diff] [blame] | 31 | #include <time.h> |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 32 | |
| 33 | /* Flags for allocated memory */ |
| 34 | |
| 35 | /* This memory region is executable */ |
| 36 | #define PAN_BO_EXECUTE (1 << 0) |
| 37 | |
| 38 | /* This memory region should be lazily allocated and grow-on-page-fault. Must |
| 39 | * be used in conjunction with INVISIBLE */ |
| 40 | #define PAN_BO_GROWABLE (1 << 1) |
| 41 | |
| 42 | /* This memory region should not be mapped to the CPU */ |
| 43 | #define PAN_BO_INVISIBLE (1 << 2) |
| 44 | |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 45 | /* This region may not be used immediately and will not mmap on allocate |
| 46 | * (semantically distinct from INVISIBLE, which cannot never be mmaped) */ |
Alyssa Rosenzweig | 64608b4 | 2020-07-13 10:07:56 -0400 | [diff] [blame] | 47 | #define PAN_BO_DELAY_MMAP (1 << 3) |
Boris Brezillon | 9af4aea | 2019-09-14 11:46:44 +0200 | [diff] [blame] | 48 | |
Alyssa Rosenzweig | 62ec4e0 | 2020-05-26 13:10:41 -0400 | [diff] [blame] | 49 | /* BO is shared across processes (imported or exported) and therefore cannot be |
| 50 | * cached locally */ |
Alyssa Rosenzweig | 64608b4 | 2020-07-13 10:07:56 -0400 | [diff] [blame] | 51 | #define PAN_BO_SHARED (1 << 4) |
Boris Brezillon | 22190bc | 2019-09-14 17:11:03 +0200 | [diff] [blame] | 52 | |
Boris Brezillon | ada752a | 2019-09-15 09:21:13 +0200 | [diff] [blame] | 53 | /* GPU access flags */ |
| 54 | |
| 55 | /* BO is either shared (can be accessed by more than one GPU batch) or private |
| 56 | * (reserved by a specific GPU job). */ |
| 57 | #define PAN_BO_ACCESS_PRIVATE (0 << 0) |
| 58 | #define PAN_BO_ACCESS_SHARED (1 << 0) |
| 59 | |
| 60 | /* BO is being read/written by the GPU */ |
| 61 | #define PAN_BO_ACCESS_READ (1 << 1) |
| 62 | #define PAN_BO_ACCESS_WRITE (1 << 2) |
| 63 | #define PAN_BO_ACCESS_RW (PAN_BO_ACCESS_READ | PAN_BO_ACCESS_WRITE) |
| 64 | |
| 65 | /* BO is accessed by the vertex/tiler job. */ |
| 66 | #define PAN_BO_ACCESS_VERTEX_TILER (1 << 3) |
| 67 | |
| 68 | /* BO is accessed by the fragment job. */ |
| 69 | #define PAN_BO_ACCESS_FRAGMENT (1 << 4) |
| 70 | |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 71 | struct panfrost_bo { |
| 72 | /* Must be first for casting */ |
Boris Brezillon | ee82f9f | 2019-11-07 09:32:31 +0100 | [diff] [blame] | 73 | struct list_head bucket_link; |
| 74 | |
| 75 | /* Used to link the BO to the BO cache LRU list. */ |
| 76 | struct list_head lru_link; |
| 77 | |
| 78 | /* Store the time this BO was use last, so the BO cache logic can evict |
| 79 | * stale BOs. |
| 80 | */ |
| 81 | time_t last_used; |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 82 | |
Alyssa Rosenzweig | 3283c7f | 2020-03-23 19:17:49 -0400 | [diff] [blame] | 83 | /* Atomic reference count */ |
| 84 | int32_t refcnt; |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 85 | |
Alyssa Rosenzweig | ca8c625 | 2020-03-23 18:44:21 -0400 | [diff] [blame] | 86 | struct panfrost_device *dev; |
Boris Brezillon | e15ab93 | 2019-09-14 10:35:47 +0200 | [diff] [blame] | 87 | |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 88 | /* Mapping for the entire object (all levels) */ |
| 89 | uint8_t *cpu; |
| 90 | |
| 91 | /* GPU address for the object */ |
| 92 | mali_ptr gpu; |
| 93 | |
| 94 | /* Size of all entire trees */ |
| 95 | size_t size; |
| 96 | |
| 97 | int gem_handle; |
| 98 | |
| 99 | uint32_t flags; |
Boris Brezillon | 2225383 | 2019-08-31 18:51:20 +0200 | [diff] [blame] | 100 | |
| 101 | /* Combination of PAN_BO_ACCESS_{READ,WRITE} flags encoding pending |
| 102 | * GPU accesses to this BO. Useful to avoid calling the WAIT_BO ioctl |
| 103 | * when the BO is idle. |
| 104 | */ |
| 105 | uint32_t gpu_access; |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 106 | }; |
| 107 | |
Boris Brezillon | 2225383 | 2019-08-31 18:51:20 +0200 | [diff] [blame] | 108 | bool |
Icecream95 | 858cc13 | 2020-07-18 11:36:36 +1200 | [diff] [blame] | 109 | panfrost_bo_wait(struct panfrost_bo *bo, int64_t timeout_ns, bool wait_readers); |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 110 | void |
| 111 | panfrost_bo_reference(struct panfrost_bo *bo); |
| 112 | void |
Boris Brezillon | e15ab93 | 2019-09-14 10:35:47 +0200 | [diff] [blame] | 113 | panfrost_bo_unreference(struct panfrost_bo *bo); |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 114 | struct panfrost_bo * |
Alyssa Rosenzweig | ca8c625 | 2020-03-23 18:44:21 -0400 | [diff] [blame] | 115 | panfrost_bo_create(struct panfrost_device *dev, size_t size, |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 116 | uint32_t flags); |
| 117 | void |
Boris Brezillon | e15ab93 | 2019-09-14 10:35:47 +0200 | [diff] [blame] | 118 | panfrost_bo_mmap(struct panfrost_bo *bo); |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 119 | struct panfrost_bo * |
Alyssa Rosenzweig | ca8c625 | 2020-03-23 18:44:21 -0400 | [diff] [blame] | 120 | panfrost_bo_import(struct panfrost_device *dev, int fd); |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 121 | int |
Boris Brezillon | e15ab93 | 2019-09-14 10:35:47 +0200 | [diff] [blame] | 122 | panfrost_bo_export(struct panfrost_bo *bo); |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 123 | void |
Alyssa Rosenzweig | ca8c625 | 2020-03-23 18:44:21 -0400 | [diff] [blame] | 124 | panfrost_bo_cache_evict_all(struct panfrost_device *dev); |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 125 | |
| 126 | #endif /* __PAN_BO_H__ */ |