staging: unisys: remove ERRDEV macros
[deliverable/linux.git] / drivers / staging / unisys / uislib / uisutils.c
1 /* uisutils.c
2 *
3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
4 * All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14 * NON INFRINGEMENT. See the GNU General Public License for more
15 * details.
16 */
17
18 #include <linux/string.h>
19 #include <linux/slab.h>
20 #include <linux/types.h>
21 #include <linux/uuid.h>
22 #include <linux/spinlock.h>
23 #include <linux/list.h>
24 #include "uniklog.h"
25 #include "uisutils.h"
26 #include "version.h"
27 #include "vbushelper.h"
28 #include <linux/skbuff.h>
29 #ifdef CONFIG_HIGHMEM
30 #include <linux/highmem.h>
31 #endif
32
33 /* this is shorter than using __FILE__ (full path name) in
34 * debug/info/error messages
35 */
36 #define CURRENT_FILE_PC UISLIB_PC_uisutils_c
37 #define __MYFILE__ "uisutils.c"
38
39 /* exports */
40 atomic_t uisutils_registered_services = ATOMIC_INIT(0);
41 /* num registrations via
42 * uisctrl_register_req_handler() or
43 * uisctrl_register_req_handler_ex() */
44
45 /*****************************************************/
46 /* Utility functions */
47 /*****************************************************/
48
49 int
50 uisutil_add_proc_line_ex(int *total, char **buffer, int *buffer_remaining,
51 char *format, ...)
52 {
53 va_list args;
54 int len;
55
56 va_start(args, format);
57 len = vsnprintf(*buffer, *buffer_remaining, format, args);
58 va_end(args);
59 if (len >= *buffer_remaining) {
60 *buffer += *buffer_remaining;
61 *total += *buffer_remaining;
62 *buffer_remaining = 0;
63 return -1;
64 }
65 *buffer_remaining -= len;
66 *buffer += len;
67 *total += len;
68 return len;
69 }
70 EXPORT_SYMBOL_GPL(uisutil_add_proc_line_ex);
71
72 int
73 uisctrl_register_req_handler(int type, void *fptr,
74 struct ultra_vbus_deviceinfo *chipset_driver_info)
75 {
76 switch (type) {
77 case 2:
78 if (fptr) {
79 if (!virt_control_chan_func)
80 atomic_inc(&uisutils_registered_services);
81 virt_control_chan_func = fptr;
82 } else {
83 if (virt_control_chan_func)
84 atomic_dec(&uisutils_registered_services);
85 virt_control_chan_func = NULL;
86 }
87 break;
88
89 default:
90 return 0;
91 }
92 if (chipset_driver_info)
93 bus_device_info_init(chipset_driver_info, "chipset", "uislib",
94 VERSION, NULL);
95
96 return 1;
97 }
98 EXPORT_SYMBOL_GPL(uisctrl_register_req_handler);
99
100 /*
101 * unsigned int uisutil_copy_fragsinfo_from_skb(unsigned char *calling_ctx,
102 * void *skb_in,
103 * unsigned int firstfraglen,
104 * unsigned int frags_max,
105 * struct phys_info frags[])
106 *
107 * calling_ctx - input - a string that is displayed to show
108 * who called * this func
109 * void *skb_in - skb whose frag info we're copying type is hidden so we
110 * don't need to include skbbuff in uisutils.h which is
111 * included in non-networking code.
112 * unsigned int firstfraglen - input - length of first fragment in skb
113 * unsigned int frags_max - input - max len of frags array
114 * struct phys_info frags[] - output - frags array filled in on output
115 * return value indicates number of
116 * entries filled in frags
117 */
118
119 static LIST_HEAD(req_handler_info_list); /* list of struct req_handler_info */
120 static DEFINE_SPINLOCK(req_handler_info_list_lock);
121
122 struct req_handler_info *
123 req_handler_find(uuid_le switch_uuid)
124 {
125 struct list_head *lelt, *tmp;
126 struct req_handler_info *entry = NULL;
127
128 spin_lock(&req_handler_info_list_lock);
129 list_for_each_safe(lelt, tmp, &req_handler_info_list) {
130 entry = list_entry(lelt, struct req_handler_info, list_link);
131 if (uuid_le_cmp(entry->switch_uuid, switch_uuid) == 0) {
132 spin_unlock(&req_handler_info_list_lock);
133 return entry;
134 }
135 }
136 spin_unlock(&req_handler_info_list_lock);
137 return NULL;
138 }
This page took 0.053239 seconds and 5 git commands to generate.