1/*
2Copyright (c) 2012, Broadcom Europe Ltd
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27#ifndef KHRN_CLIENT_CACHE_H
28#define KHRN_CLIENT_CACHE_H
29
30//#define WORKAROUND_HW2551 // define to pad header structure to 32 bytes
31
32#include "interface/khronos/common/khrn_client_pointermap.h"
33#include "interface/khronos/common/khrn_client.h"
34
35typedef struct CACHE_LINK_S {
36 struct CACHE_LINK_S *prev;
37 struct CACHE_LINK_S *next;
38} CACHE_LINK_T;
39
40typedef struct {
41 CACHE_LINK_T link;
42
43 int len;
44 int key;
45
46#ifdef WORKAROUND_HW2551
47 uint8_t pad[16];
48#endif
49
50 //on the server side
51 //we store a KHRN_INTERLOCK_T in the
52 //same space as this struct
53 uint8_t pad_for_interlock[24];
54
55 uint8_t data[1];
56} CACHE_ENTRY_T;
57
58typedef struct {
59 uint8_t *tree;
60 uint8_t *data;
61
62 int client_depth;
63 int server_depth;
64
65 CACHE_LINK_T start;
66 CACHE_LINK_T end;
67
68 KHRN_POINTER_MAP_T map;
69} KHRN_CACHE_T;
70
71#define CACHE_LOG2_BLOCK_SIZE 6
72#define CACHE_MAX_DEPTH 16
73
74#define CACHE_SIG_ATTRIB_0 0
75#define CACHE_SIG_ATTRIB_1 1
76#define CACHE_SIG_ATTRIB_2 2
77#define CACHE_SIG_ATTRIB_3 3
78#define CACHE_SIG_ATTRIB_4 4
79#define CACHE_SIG_ATTRIB_5 5
80#define CACHE_SIG_ATTRIB_6 6
81#define CACHE_SIG_ATTRIB_7 7
82
83#define CACHE_SIG_INDEX 8
84
85extern int khrn_cache_init(KHRN_CACHE_T *cache);
86extern void khrn_cache_term(KHRN_CACHE_T *cache);
87
88extern int khrn_cache_lookup(CLIENT_THREAD_STATE_T *thread, KHRN_CACHE_T *cache, const void *data, int len, int sig);
89extern int khrn_cache_get_entries(KHRN_CACHE_T *cache);
90
91#endif
92
93