diff options
| author | Yuval Adam <_@yuv.al> | 2017-08-30 08:25:59 +0000 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2017-08-30 08:25:59 +0000 |
| commit | 8e4bff4cab0ddac6060645b0715210484d02ff40 (patch) | |
| tree | 3a5c3024371a04692a3a6d9974d001cdff8ebf84 /drivers/staging/tidspbridge/gen | |
Diffstat (limited to 'drivers/staging/tidspbridge/gen')
| -rw-r--r-- | drivers/staging/tidspbridge/gen/gh.c | 177 | ||||
| -rw-r--r-- | drivers/staging/tidspbridge/gen/uuidutil.c | 85 |
2 files changed, 262 insertions, 0 deletions
diff --git a/drivers/staging/tidspbridge/gen/gh.c b/drivers/staging/tidspbridge/gen/gh.c new file mode 100644 index 00000000..25eaef78 --- /dev/null +++ b/drivers/staging/tidspbridge/gen/gh.c @@ -0,0 +1,177 @@ +/* + * gh.c + * + * DSP-BIOS Bridge driver support functions for TI OMAP processors. + * + * Copyright (C) 2005-2006 Texas Instruments, Inc. + * + * This package is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include <linux/types.h> + +#include <dspbridge/host_os.h> +#include <dspbridge/gh.h> + +struct element { + struct element *next; + u8 data[1]; +}; + +struct gh_t_hash_tab { + u16 max_bucket; + u16 val_size; + struct element **buckets; + u16(*hash) (void *, u16); + bool(*match) (void *, void *); + void (*delete) (void *); +}; + +static void noop(void *p); + +/* + * ======== gh_create ======== + */ + +struct gh_t_hash_tab *gh_create(u16 max_bucket, u16 val_size, + u16(*hash) (void *, u16), bool(*match) (void *, + void *), + void (*delete) (void *)) +{ + struct gh_t_hash_tab *hash_tab; + u16 i; + hash_tab = kzalloc(sizeof(struct gh_t_hash_tab), GFP_KERNEL); + if (hash_tab == NULL) + return NULL; + hash_tab->max_bucket = max_bucket; + hash_tab->val_size = val_size; + hash_tab->hash = hash; + hash_tab->match = match; + hash_tab->delete = delete == NULL ? noop : delete; + + hash_tab->buckets = + kzalloc(sizeof(struct element *) * max_bucket, GFP_KERNEL); + if (hash_tab->buckets == NULL) { + gh_delete(hash_tab); + return NULL; + } + + for (i = 0; i < max_bucket; i++) + hash_tab->buckets[i] = NULL; + + return hash_tab; +} + +/* + * ======== gh_delete ======== + */ +void gh_delete(struct gh_t_hash_tab *hash_tab) +{ + struct element *elem, *next; + u16 i; + + if (hash_tab != NULL) { + if (hash_tab->buckets != NULL) { + for (i = 0; i < hash_tab->max_bucket; i++) { + for (elem = hash_tab->buckets[i]; elem != NULL; + elem = next) { + next = elem->next; + (*hash_tab->delete) (elem->data); + kfree(elem); + } + } + + kfree(hash_tab->buckets); + } + + kfree(hash_tab); + } +} + +/* + * ======== gh_find ======== + */ + +void *gh_find(struct gh_t_hash_tab *hash_tab, void *key) +{ + struct element *elem; + + elem = hash_tab->buckets[(*hash_tab->hash) (key, hash_tab->max_bucket)]; + + for (; elem; elem = elem->next) { + if ((*hash_tab->match) (key, elem->data)) + return elem->data; + } + + return NULL; +} + +/* + * ======== gh_insert ======== + */ + +void *gh_insert(struct gh_t_hash_tab *hash_tab, void *key, void *value) +{ + struct element *elem; + u16 i; + char *src, *dst; + + elem = kzalloc(sizeof(struct element) - 1 + hash_tab->val_size, + GFP_KERNEL); + if (elem != NULL) { + + dst = (char *)elem->data; + src = (char *)value; + for (i = 0; i < hash_tab->val_size; i++) + *dst++ = *src++; + + i = (*hash_tab->hash) (key, hash_tab->max_bucket); + elem->next = hash_tab->buckets[i]; + hash_tab->buckets[i] = elem; + + return elem->data; + } + + return NULL; +} + +/* + * ======== noop ======== + */ +/* ARGSUSED */ +static void noop(void *p) +{ + p = p; /* stifle compiler warning */ +} + +#ifdef CONFIG_TIDSPBRIDGE_BACKTRACE +/** + * gh_iterate() - This function goes through all the elements in the hash table + * looking for the dsp symbols. + * @hash_tab: Hash table + * @callback: pointer to callback function + * @user_data: User data, contains the find_symbol_context pointer + * + */ +void gh_iterate(struct gh_t_hash_tab *hash_tab, + void (*callback)(void *, void *), void *user_data) +{ + struct element *elem; + u32 i; + + if (hash_tab && hash_tab->buckets) + for (i = 0; i < hash_tab->max_bucket; i++) { + elem = hash_tab->buckets[i]; + while (elem) { + callback(&elem->data, user_data); + elem = elem->next; + } + } +} +#endif diff --git a/drivers/staging/tidspbridge/gen/uuidutil.c b/drivers/staging/tidspbridge/gen/uuidutil.c new file mode 100644 index 00000000..b7d8313d --- /dev/null +++ b/drivers/staging/tidspbridge/gen/uuidutil.c @@ -0,0 +1,85 @@ +/* + * uuidutil.c + * + * DSP-BIOS Bridge driver support functions for TI OMAP processors. + * + * This file contains the implementation of UUID helper functions. + * + * Copyright (C) 2005-2006 Texas Instruments, Inc. + * + * This package is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ +#include <linux/types.h> + +/* ----------------------------------- Host OS */ +#include <dspbridge/host_os.h> + +/* ----------------------------------- DSP/BIOS Bridge */ +#include <dspbridge/dbdefs.h> + +/* ----------------------------------- This */ +#include <dspbridge/uuidutil.h> + +static s32 uuid_hex_to_bin(char *buf, s32 len) +{ + s32 i; + s32 result = 0; + int value; + + for (i = 0; i < len; i++) { + value = hex_to_bin(*buf++); + result *= 16; + if (value > 0) + result += value; + } + + return result; +} + +/* + * ======== uuid_uuid_from_string ======== + * Purpose: + * Converts a string to a struct dsp_uuid. + */ +void uuid_uuid_from_string(char *sz_uuid, struct dsp_uuid *uuid_obj) +{ + s32 j; + + uuid_obj->data1 = uuid_hex_to_bin(sz_uuid, 8); + sz_uuid += 8; + + /* Step over underscore */ + sz_uuid++; + + uuid_obj->data2 = (u16) uuid_hex_to_bin(sz_uuid, 4); + sz_uuid += 4; + + /* Step over underscore */ + sz_uuid++; + + uuid_obj->data3 = (u16) uuid_hex_to_bin(sz_uuid, 4); + sz_uuid += 4; + + /* Step over underscore */ + sz_uuid++; + + uuid_obj->data4 = (u8) uuid_hex_to_bin(sz_uuid, 2); + sz_uuid += 2; + + uuid_obj->data5 = (u8) uuid_hex_to_bin(sz_uuid, 2); + sz_uuid += 2; + + /* Step over underscore */ + sz_uuid++; + + for (j = 0; j < 6; j++) { + uuid_obj->data6[j] = (u8) uuid_hex_to_bin(sz_uuid, 2); + sz_uuid += 2; + } +} |
