4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * Copyright (C) 2005-2006 Texas Instruments, Inc.
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 #include <linux/types.h>
19 #include <dspbridge/host_os.h>
21 #include <dspbridge/gs.h>
23 #include <dspbridge/gh.h>
30 struct gh_t_hash_tab {
33 struct element **buckets;
34 u16(*hash) (void *, u16);
35 bool(*match) (void *, void *);
36 void (*delete) (void *);
39 static void noop(void *p);
41 static void myfree(void *ptr, s32 size);
44 * ======== gh_create ========
47 struct gh_t_hash_tab *gh_create(u16 max_bucket, u16 val_size,
48 u16(*hash) (void *, u16), bool(*match) (void *,
50 void (*delete) (void *))
52 struct gh_t_hash_tab *hash_tab;
55 (struct gh_t_hash_tab *)gs_alloc(sizeof(struct gh_t_hash_tab));
58 hash_tab->max_bucket = max_bucket;
59 hash_tab->val_size = val_size;
60 hash_tab->hash = hash;
61 hash_tab->match = match;
62 hash_tab->delete = delete == NULL ? noop : delete;
64 hash_tab->buckets = (struct element **)
65 gs_alloc(sizeof(struct element *) * max_bucket);
66 if (hash_tab->buckets == NULL) {
71 for (i = 0; i < max_bucket; i++)
72 hash_tab->buckets[i] = NULL;
78 * ======== gh_delete ========
80 void gh_delete(struct gh_t_hash_tab *hash_tab)
82 struct element *elem, *next;
85 if (hash_tab != NULL) {
86 if (hash_tab->buckets != NULL) {
87 for (i = 0; i < hash_tab->max_bucket; i++) {
88 for (elem = hash_tab->buckets[i]; elem != NULL;
91 (*hash_tab->delete) (elem->data);
93 sizeof(struct element) - 1 +
98 myfree(hash_tab->buckets, sizeof(struct element *)
99 * hash_tab->max_bucket);
102 myfree(hash_tab, sizeof(struct gh_t_hash_tab));
107 * ======== gh_exit ========
118 * ======== gh_find ========
121 void *gh_find(struct gh_t_hash_tab *hash_tab, void *key)
123 struct element *elem;
125 elem = hash_tab->buckets[(*hash_tab->hash) (key, hash_tab->max_bucket)];
127 for (; elem; elem = elem->next) {
128 if ((*hash_tab->match) (key, elem->data))
136 * ======== gh_init ========
146 * ======== gh_insert ========
149 void *gh_insert(struct gh_t_hash_tab *hash_tab, void *key, void *value)
151 struct element *elem;
155 elem = (struct element *)gs_alloc(sizeof(struct element) - 1 +
159 dst = (char *)elem->data;
161 for (i = 0; i < hash_tab->val_size; i++)
164 i = (*hash_tab->hash) (key, hash_tab->max_bucket);
165 elem->next = hash_tab->buckets[i];
166 hash_tab->buckets[i] = elem;
175 * ======== noop ========
178 static void noop(void *p)
180 p = p; /* stifle compiler warning */
184 * ======== myfree ========
186 static void myfree(void *ptr, s32 size)
191 #ifdef CONFIG_TIDSPBRIDGE_BACKTRACE
193 * gh_iterate() - This function goes through all the elements in the hash table
194 * looking for the dsp symbols.
195 * @hash_tab: Hash table
196 * @callback: pointer to callback function
197 * @user_data: User data, contains the find_symbol_context pointer
200 void gh_iterate(struct gh_t_hash_tab *hash_tab,
201 void (*callback)(void *, void *), void *user_data)
203 struct element *elem;
206 if (hash_tab && hash_tab->buckets)
207 for (i = 0; i < hash_tab->max_bucket; i++) {
208 elem = hash_tab->buckets[i];
210 callback(&elem->data, user_data);