101e04c3fSmrg/************************************************************************** 201e04c3fSmrg * 301e04c3fSmrg * Copyright 2007-2008 VMware, Inc. 401e04c3fSmrg * Copyright 2015 Advanced Micro Devices, Inc. 501e04c3fSmrg * All Rights Reserved. 601e04c3fSmrg * 701e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 801e04c3fSmrg * copy of this software and associated documentation files (the 901e04c3fSmrg * "Software"), to deal in the Software without restriction, including 1001e04c3fSmrg * without limitation the rights to use, copy, modify, merge, publish, 1101e04c3fSmrg * distribute, sub license, and/or sell copies of the Software, and to 1201e04c3fSmrg * permit persons to whom the Software is furnished to do so, subject to 1301e04c3fSmrg * the following conditions: 1401e04c3fSmrg * 1501e04c3fSmrg * The above copyright notice and this permission notice (including the 1601e04c3fSmrg * next paragraph) shall be included in all copies or substantial portions 1701e04c3fSmrg * of the Software. 1801e04c3fSmrg * 1901e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 2001e04c3fSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 2101e04c3fSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 2201e04c3fSmrg * IN NO EVENT SHALL AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR 2301e04c3fSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 2401e04c3fSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 2501e04c3fSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2601e04c3fSmrg * 2701e04c3fSmrg **************************************************************************/ 2801e04c3fSmrg 2901e04c3fSmrg#ifndef PB_CACHE_H 3001e04c3fSmrg#define PB_CACHE_H 3101e04c3fSmrg 3201e04c3fSmrg#include "pb_buffer.h" 337ec681f3Smrg#include "util/simple_mtx.h" 3401e04c3fSmrg#include "util/list.h" 3501e04c3fSmrg#include "os/os_thread.h" 3601e04c3fSmrg 3701e04c3fSmrg/** 3801e04c3fSmrg * Statically inserted into the driver-specific buffer structure. 3901e04c3fSmrg */ 4001e04c3fSmrgstruct pb_cache_entry 4101e04c3fSmrg{ 4201e04c3fSmrg struct list_head head; 4301e04c3fSmrg struct pb_buffer *buffer; /**< Pointer to the structure this is part of. */ 4401e04c3fSmrg struct pb_cache *mgr; 4501e04c3fSmrg int64_t start, end; /**< Caching time interval */ 4601e04c3fSmrg unsigned bucket_index; 4701e04c3fSmrg}; 4801e04c3fSmrg 4901e04c3fSmrgstruct pb_cache 5001e04c3fSmrg{ 5101e04c3fSmrg /* The cache is divided into buckets for minimizing cache misses. 5201e04c3fSmrg * The driver controls which buffer goes into which bucket. 5301e04c3fSmrg */ 5401e04c3fSmrg struct list_head *buckets; 5501e04c3fSmrg 567ec681f3Smrg simple_mtx_t mutex; 577ec681f3Smrg void *winsys; 5801e04c3fSmrg uint64_t cache_size; 5901e04c3fSmrg uint64_t max_cache_size; 6001e04c3fSmrg unsigned num_heaps; 6101e04c3fSmrg unsigned usecs; 6201e04c3fSmrg unsigned num_buffers; 6301e04c3fSmrg unsigned bypass_usage; 6401e04c3fSmrg float size_factor; 6501e04c3fSmrg 667ec681f3Smrg void (*destroy_buffer)(void *winsys, struct pb_buffer *buf); 677ec681f3Smrg bool (*can_reclaim)(void *winsys, struct pb_buffer *buf); 6801e04c3fSmrg}; 6901e04c3fSmrg 7001e04c3fSmrgvoid pb_cache_add_buffer(struct pb_cache_entry *entry); 7101e04c3fSmrgstruct pb_buffer *pb_cache_reclaim_buffer(struct pb_cache *mgr, pb_size size, 7201e04c3fSmrg unsigned alignment, unsigned usage, 7301e04c3fSmrg unsigned bucket_index); 7401e04c3fSmrgvoid pb_cache_release_all_buffers(struct pb_cache *mgr); 7501e04c3fSmrgvoid pb_cache_init_entry(struct pb_cache *mgr, struct pb_cache_entry *entry, 7601e04c3fSmrg struct pb_buffer *buf, unsigned bucket_index); 7701e04c3fSmrgvoid pb_cache_init(struct pb_cache *mgr, uint num_heaps, 7801e04c3fSmrg uint usecs, float size_factor, 7901e04c3fSmrg unsigned bypass_usage, uint64_t maximum_cache_size, 807ec681f3Smrg void *winsys, 817ec681f3Smrg void (*destroy_buffer)(void *winsys, struct pb_buffer *buf), 827ec681f3Smrg bool (*can_reclaim)(void *winsys, struct pb_buffer *buf)); 8301e04c3fSmrgvoid pb_cache_deinit(struct pb_cache *mgr); 8401e04c3fSmrg 8501e04c3fSmrg#endif 86