mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-02-14 04:40:28 +01:00
anv: Use os_get_page_size for mmap offset alignment to work with page size other than 4K
Instead of hardcoding 4096-byte page size in bo mapping/unmapping logic, use os_get_page_size() to determine the correct alignment for munmap() offset adjustments and address assertions. Signed-off-by: Zhou Qiankang <wszqkzqk@qq.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37389>
This commit is contained in:
parent
eaeff6ba0e
commit
b0528bcab1
3 changed files with 12 additions and 5 deletions
|
|
@ -1811,8 +1811,9 @@ anv_device_map_bo(struct anv_device *device,
|
|||
if (real != bo) {
|
||||
offset += (bo->offset - real->offset);
|
||||
|
||||
const uint64_t page_size = device->physical->page_size;
|
||||
/* KMD rounds munmap() to whole pages, so here doing some adjustments */
|
||||
const uint64_t munmap_offset = ROUND_DOWN_TO(offset, 4096);
|
||||
const uint64_t munmap_offset = ROUND_DOWN_TO(offset, page_size);
|
||||
if (munmap_offset != offset) {
|
||||
offset_adjustment = offset - munmap_offset;
|
||||
size += offset_adjustment;
|
||||
|
|
@ -1822,7 +1823,7 @@ anv_device_map_bo(struct anv_device *device,
|
|||
placed_addr -= offset_adjustment;
|
||||
}
|
||||
|
||||
assert((offset & (4096 - 1)) == 0);
|
||||
assert((offset & (page_size - 1)) == 0);
|
||||
}
|
||||
|
||||
void *map = device->kmd_backend->gem_mmap(device, bo, offset, size, placed_addr);
|
||||
|
|
@ -1850,14 +1851,15 @@ anv_device_unmap_bo(struct anv_device *device,
|
|||
|
||||
struct anv_bo *real = anv_bo_get_real(bo);
|
||||
if (real != bo) {
|
||||
const uint64_t page_size = device->physical->page_size;
|
||||
uint64_t slab_offset = bo->offset - real->offset;
|
||||
|
||||
if (ROUND_DOWN_TO(slab_offset, 4096) != slab_offset) {
|
||||
slab_offset -= ROUND_DOWN_TO(slab_offset, 4096);
|
||||
if (ROUND_DOWN_TO(slab_offset, page_size) != slab_offset) {
|
||||
slab_offset -= ROUND_DOWN_TO(slab_offset, page_size);
|
||||
map -= slab_offset;
|
||||
map_size += slab_offset;
|
||||
}
|
||||
assert(((uintptr_t)map & (4096 - 1)) == 0);
|
||||
assert(((uintptr_t)map & (page_size - 1)) == 0);
|
||||
}
|
||||
|
||||
if (replace) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "util/disk_cache.h"
|
||||
#include "util/mesa-sha1.h"
|
||||
#include "util/os_misc.h"
|
||||
|
||||
#include <xf86drm.h>
|
||||
#include <fcntl.h>
|
||||
|
|
@ -2761,6 +2762,8 @@ anv_physical_device_try_create(struct vk_instance *vk_instance,
|
|||
if (result != VK_SUCCESS)
|
||||
goto fail_compiler;
|
||||
|
||||
os_get_page_size(&device->page_size);
|
||||
|
||||
anv_physical_device_init_va_ranges(device);
|
||||
|
||||
anv_physical_device_init_disk_cache(device);
|
||||
|
|
|
|||
|
|
@ -1393,6 +1393,8 @@ struct anv_physical_device {
|
|||
VkQueueGlobalPriorityKHR max_context_priority;
|
||||
uint64_t gtt_size;
|
||||
|
||||
uint64_t page_size;
|
||||
|
||||
/** True if we can read the GPU timestamp register
|
||||
*
|
||||
* When running in a virtual context, the timestamp register is unreadable
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue