staging: tidspbridge: set9 remove hungarian from structs
[linux-block.git] / drivers / staging / tidspbridge / gen / uuidutil.c
CommitLineData
7227b671
ORL
1/*
2 * uuidutil.c
3 *
4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5 *
6 * This file contains the implementation of UUID helper functions.
7 *
8 * Copyright (C) 2005-2006 Texas Instruments, Inc.
9 *
10 * This package is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 */
2094f12d 18#include <linux/types.h>
7227b671
ORL
19
20/* ----------------------------------- Host OS */
21#include <dspbridge/host_os.h>
22
23/* ----------------------------------- DSP/BIOS Bridge */
7227b671
ORL
24#include <dspbridge/dbdefs.h>
25
26/* ----------------------------------- Trace & Debug */
27#include <dspbridge/dbc.h>
28
29/* ----------------------------------- This */
30#include <dspbridge/uuidutil.h>
31
32/*
33 * ======== uuid_uuid_to_string ========
34 * Purpose:
35 * Converts a struct dsp_uuid to a string.
36 * Note: snprintf format specifier is:
37 * %[flags] [width] [.precision] [{h | l | I64 | L}]type
38 */
e6bf74f0 39void uuid_uuid_to_string(struct dsp_uuid *uuid_obj, char *sz_uuid,
9d7d0a52 40 s32 size)
7227b671
ORL
41{
42 s32 i; /* return result from snprintf. */
43
383b8345 44 DBC_REQUIRE(uuid_obj && sz_uuid);
7227b671 45
383b8345 46 i = snprintf(sz_uuid, size,
7227b671 47 "%.8X_%.4X_%.4X_%.2X%.2X_%.2X%.2X%.2X%.2X%.2X%.2X",
a534f17b
RS
48 uuid_obj->data1, uuid_obj->data2, uuid_obj->data3,
49 uuid_obj->data4, uuid_obj->data5,
50 uuid_obj->data6[0], uuid_obj->data6[1],
51 uuid_obj->data6[2], uuid_obj->data6[3],
52 uuid_obj->data6[4], uuid_obj->data6[5]);
7227b671
ORL
53
54 DBC_ENSURE(i != -1);
55}
56
5b2652b6 57static s32 uuid_hex_to_bin(char *buf, s32 len)
7227b671 58{
5b2652b6
AS
59 s32 i;
60 s32 result = 0;
0d9073ab 61 int value;
5b2652b6
AS
62
63 for (i = 0; i < len; i++) {
64 value = hex_to_bin(*buf++);
65 result *= 16;
66 if (value > 0)
67 result += value;
7227b671 68 }
5b2652b6
AS
69
70 return result;
7227b671
ORL
71}
72
73/*
74 * ======== uuid_uuid_from_string ========
75 * Purpose:
76 * Converts a string to a struct dsp_uuid.
77 */
e6bf74f0 78void uuid_uuid_from_string(char *sz_uuid, struct dsp_uuid *uuid_obj)
7227b671 79{
5b2652b6 80 s32 j;
7227b671 81
dab7f7fe 82 uuid_obj->data1 = uuid_hex_to_bin(sz_uuid, 8);
383b8345 83 sz_uuid += 8;
7227b671
ORL
84
85 /* Step over underscore */
383b8345 86 sz_uuid++;
7227b671 87
a534f17b 88 uuid_obj->data2 = (u16) uuid_hex_to_bin(sz_uuid, 4);
383b8345 89 sz_uuid += 4;
7227b671
ORL
90
91 /* Step over underscore */
383b8345 92 sz_uuid++;
7227b671 93
a534f17b 94 uuid_obj->data3 = (u16) uuid_hex_to_bin(sz_uuid, 4);
383b8345 95 sz_uuid += 4;
7227b671
ORL
96
97 /* Step over underscore */
383b8345 98 sz_uuid++;
7227b671 99
a534f17b 100 uuid_obj->data4 = (u8) uuid_hex_to_bin(sz_uuid, 2);
383b8345 101 sz_uuid += 2;
7227b671 102
a534f17b 103 uuid_obj->data5 = (u8) uuid_hex_to_bin(sz_uuid, 2);
383b8345 104 sz_uuid += 2;
7227b671
ORL
105
106 /* Step over underscore */
383b8345 107 sz_uuid++;
7227b671
ORL
108
109 for (j = 0; j < 6; j++) {
a534f17b 110 uuid_obj->data6[j] = (u8) uuid_hex_to_bin(sz_uuid, 2);
383b8345 111 sz_uuid += 2;
7227b671
ORL
112 }
113}