1 /* SPDX-License-Identifier: MIT */ 2 /* 3 * Copyright © 2024 Intel Corporation 4 */ 5 6 #ifndef _XE_GUC_BUF_H_ 7 #define _XE_GUC_BUF_H_ 8 9 #include <linux/cleanup.h> 10 #include <linux/err.h> 11 12 #include "xe_guc_buf_types.h" 13 14 int xe_guc_buf_cache_init(struct xe_guc_buf_cache *cache); 15 int xe_guc_buf_cache_init_with_size(struct xe_guc_buf_cache *cache, u32 size); 16 u32 xe_guc_buf_cache_dwords(struct xe_guc_buf_cache *cache); 17 struct xe_guc_buf xe_guc_buf_reserve(struct xe_guc_buf_cache *cache, u32 dwords); 18 struct xe_guc_buf xe_guc_buf_from_data(struct xe_guc_buf_cache *cache, 19 const void *data, size_t size); 20 void xe_guc_buf_release(const struct xe_guc_buf buf); 21 22 /** 23 * xe_guc_buf_is_valid() - Check if a buffer reference is valid. 24 * @buf: the &xe_guc_buf reference to check 25 * 26 * Return: true if @ref represents a valid sub-allication. 27 */ 28 static inline bool xe_guc_buf_is_valid(const struct xe_guc_buf buf) 29 { 30 return !IS_ERR_OR_NULL(buf.sa); 31 } 32 33 void *xe_guc_buf_cpu_ptr(const struct xe_guc_buf buf); 34 void *xe_guc_buf_sync_read(const struct xe_guc_buf buf); 35 u64 xe_guc_buf_flush(const struct xe_guc_buf buf); 36 u64 xe_guc_buf_gpu_addr(const struct xe_guc_buf buf); 37 u64 xe_guc_cache_gpu_addr_from_ptr(struct xe_guc_buf_cache *cache, const void *ptr, u32 size); 38 39 DEFINE_CLASS(xe_guc_buf, struct xe_guc_buf, 40 xe_guc_buf_release(_T), 41 xe_guc_buf_reserve(cache, num), 42 struct xe_guc_buf_cache *cache, u32 num); 43 44 DEFINE_CLASS(xe_guc_buf_from_data, struct xe_guc_buf, 45 xe_guc_buf_release(_T), 46 xe_guc_buf_from_data(cache, data, size), 47 struct xe_guc_buf_cache *cache, const void *data, size_t size); 48 49 #endif 50