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 u32 xe_guc_buf_cache_dwords(struct xe_guc_buf_cache *cache); 16 struct xe_guc_buf xe_guc_buf_reserve(struct xe_guc_buf_cache *cache, u32 dwords); 17 struct xe_guc_buf xe_guc_buf_from_data(struct xe_guc_buf_cache *cache, 18 const void *data, size_t size); 19 void xe_guc_buf_release(const struct xe_guc_buf buf); 20 21 /** 22 * xe_guc_buf_is_valid() - Check if a buffer reference is valid. 23 * @buf: the &xe_guc_buf reference to check 24 * 25 * Return: true if @ref represents a valid sub-allication. 26 */ 27 static inline bool xe_guc_buf_is_valid(const struct xe_guc_buf buf) 28 { 29 return !IS_ERR_OR_NULL(buf.sa); 30 } 31 32 void *xe_guc_buf_cpu_ptr(const struct xe_guc_buf buf); 33 u64 xe_guc_buf_flush(const struct xe_guc_buf buf); 34 u64 xe_guc_buf_gpu_addr(const struct xe_guc_buf buf); 35 u64 xe_guc_cache_gpu_addr_from_ptr(struct xe_guc_buf_cache *cache, const void *ptr, u32 size); 36 37 DEFINE_CLASS(xe_guc_buf, struct xe_guc_buf, 38 xe_guc_buf_release(_T), 39 xe_guc_buf_reserve(cache, num), 40 struct xe_guc_buf_cache *cache, u32 num); 41 42 DEFINE_CLASS(xe_guc_buf_from_data, struct xe_guc_buf, 43 xe_guc_buf_release(_T), 44 xe_guc_buf_from_data(cache, data, size), 45 struct xe_guc_buf_cache *cache, const void *data, size_t size); 46 47 #endif 48