| 1 |
/* |
| 2 |
* Copyright (C) 2019 Collabora, Ltd. |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "util/macros.h" |
| 7 |
|
| 8 |
#include "kmod/pan_kmod.h" |
| 9 |
#include "pan_props.h" |
| 10 |
|
| 11 |
#include <genxml/gen_macros.h> |
| 12 |
|
| 13 |
unsigned |
| 14 |
pan_query_l2_slices(const struct pan_kmod_dev_props *props) |
| 15 |
{ |
| 16 |
/* L2_SLICES is MEM_FEATURES[11:8] minus(1) */ |
| 17 |
return ((props->mem_features >> 8) & 0xF) + 1; |
| 18 |
} |
| 19 |
|
| 20 |
struct pan_tiler_features |
| 21 |
pan_query_tiler_features(const struct pan_kmod_dev_props *props) |
| 22 |
{ |
| 23 |
/* Default value (2^9 bytes and 8 levels) to match old behaviour */ |
| 24 |
uint32_t raw = props->tiler_features; |
| 25 |
|
| 26 |
/* Bin size is log2 in the first byte, max levels in the second byte */ |
| 27 |
return (struct pan_tiler_features){ |
| 28 |
.bin_size = (1 << (raw & BITFIELD_MASK(5))), |
| 29 |
.max_levels = (raw >> 8) & BITFIELD_MASK(4), |
| 30 |
}; |
| 31 |
} |
| 32 |
|
| 33 |
unsigned |
| 34 |
pan_query_core_count(const struct pan_kmod_dev_props *props, |
| 35 |
unsigned *core_id_range) |
| 36 |
{ |
| 37 |
/* On older kernels, worst-case to 16 cores */ |
| 38 |
|
| 39 |
unsigned mask = props->shader_present; |
| 40 |
|
| 41 |
/* Some cores might be absent. In some cases, we care |
| 42 |
* about the range of core IDs (that is, the greatest core ID + 1). If |
| 43 |
* the core mask is contiguous, this equals the core count. |
| 44 |
*/ |
| 45 |
*core_id_range = util_last_bit(mask); |
| 46 |
|
| 47 |
/* The actual core count skips overs the gaps */ |
| 48 |
return util_bitcount(mask); |
| 49 |
} |
| 50 |
|
| 51 |
unsigned |
| 52 |
pan_query_thread_tls_alloc(const struct pan_kmod_dev_props *props) |
| 53 |
{ |
| 54 |
return props->max_tls_instance_per_core ?: props->max_threads_per_core; |
| 55 |
} |
| 56 |
|
| 57 |
unsigned |
| 58 |
pan_compute_max_thread_count(const struct pan_kmod_dev_props *props, |
| 59 |
unsigned work_reg_count) |
| 60 |
{ |
| 61 |
unsigned aligned_reg_count; |
| 62 |
|
| 63 |
/* 4, 8 or 16 registers per shader on Midgard |
| 64 |
* 32 or 64 registers per shader on Bifrost |
| 65 |
*/ |
| 66 |
if (pan_arch(props->gpu_id) <= 5) { |
| 67 |
aligned_reg_count = util_next_power_of_two(MAX2(work_reg_count, 4)); |
| 68 |
assert(aligned_reg_count <= 16); |
| 69 |
} else { |
| 70 |
aligned_reg_count = work_reg_count <= 32 ? 32 : 64; |
| 71 |
} |
| 72 |
|
| 73 |
return MIN3(props->max_threads_per_wg, props->max_threads_per_core, |
| 74 |
props->num_registers_per_core / aligned_reg_count); |
| 75 |
} |
| 76 |
|
| 77 |
uint32_t |
| 78 |
pan_query_compressed_formats(const struct pan_kmod_dev_props *props) |
| 79 |
{ |
| 80 |
return props->texture_features[0]; |
| 81 |
} |
| 82 |
|
| 83 |
/* Check for AFBC hardware support. AFBC is introduced in v5. Implementations |
| 84 |
* may omit it, signaled as a nonzero value in the AFBC_FEATURES property. */ |
| 85 |
|
| 86 |
bool |
| 87 |
pan_query_afbc(const struct pan_kmod_dev_props *props) |
| 88 |
{ |
| 89 |
unsigned reg = props->afbc_features; |
| 90 |
|
| 91 |
return (pan_arch(props->gpu_id) >= 5) && (reg == 0); |
| 92 |
} |
| 93 |
|
| 94 |
/* Check for AFRC hardware support. AFRC is introduced in v10. Implementations |
| 95 |
* may omit it, signaled in bit 25 of TEXTURE_FEATURES_0 property. */ |
| 96 |
|
| 97 |
bool |
| 98 |
pan_query_afrc(const struct pan_kmod_dev_props *props) |
| 99 |
{ |
| 100 |
return (pan_arch(props->gpu_id) >= 10) && |
| 101 |
(props->texture_features[0] & (1 << 25)); |
| 102 |
} |
| 103 |
|
| 104 |
/* |
| 105 |
* To pipeline multiple tiles, a given tile may use at most half of the tile |
| 106 |
* buffer. This function returns the optimal size (assuming pipelining). |
| 107 |
* |
| 108 |
* For Mali-G510 and Mali-G310, we will need extra logic to query the tilebuffer |
| 109 |
* size for the particular variant. The CORE_FEATURES register might help. |
| 110 |
*/ |
| 111 |
unsigned |
| 112 |
pan_query_tib_size(const struct pan_model *model) |
| 113 |
{ |
| 114 |
/* Preconditions ensure the returned value is a multiple of 1 KiB, the |
| 115 |
* granularity of the colour buffer allocation field. |
| 116 |
*/ |
| 117 |
assert(model->tilebuffer.color_size >= 2048); |
| 118 |
assert(util_is_power_of_two_nonzero(model->tilebuffer.color_size)); |
| 119 |
|
| 120 |
return model->tilebuffer.color_size; |
| 121 |
} |
| 122 |
|
| 123 |
unsigned |
| 124 |
pan_query_z_tib_size(const struct pan_model *model) |
| 125 |
{ |
| 126 |
/* Preconditions ensure the returned value is a multiple of 1 KiB, the |
| 127 |
* granularity of the colour buffer allocation field. |
| 128 |
*/ |
| 129 |
assert(model->tilebuffer.z_size >= 1024); |
| 130 |
assert(util_is_power_of_two_nonzero(model->tilebuffer.z_size)); |
| 131 |
|
| 132 |
return model->tilebuffer.z_size; |
| 133 |
} |
| 134 |
|
| 135 |
uint64_t |
| 136 |
pan_clamp_to_usable_va_range(const struct pan_kmod_dev *dev, uint64_t va) |
| 137 |
{ |
| 138 |
struct pan_kmod_va_range user_va_range = |
| 139 |
pan_kmod_dev_query_user_va_range(dev); |
| 140 |
|
| 141 |
if (va < user_va_range.start) |
| 142 |
return user_va_range.start; |
| 143 |
else if (va > user_va_range.start + user_va_range.size) |
| 144 |
return user_va_range.start + user_va_range.size; |
| 145 |
|
| 146 |
return va; |
| 147 |
} |
| 148 |
|
| 149 |
uint64_t |
| 150 |
pan_choose_gpu_va_alignment(const struct pan_kmod_vm *vm, uint64_t size) |
| 151 |
{ |
| 152 |
assert(vm->pgsize_bitmap != 0); |
| 153 |
|
| 154 |
uint64_t align = 0; |
| 155 |
u_foreach_bit64(pgsize_bit, vm->pgsize_bitmap) { |
| 156 |
uint64_t pgsize = (uint64_t)1 << pgsize_bit; |
| 157 |
if (align > 0 && pgsize > size) |
| 158 |
break; |
| 159 |
align = pgsize; |
| 160 |
} |
| 161 |
return align; |
| 162 |
} |