3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
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.
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
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>
27 #include "vbushelper.h"
28 #include <linux/skbuff.h>
30 #include <linux/highmem.h>
33 /* this is shorter than using __FILE__ (full path name) in
34 * debug/info/error messages
36 #define CURRENT_FILE_PC UISLIB_PC_uisutils_c
37 #define __MYFILE__ "uisutils.c"
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() */
45 /*****************************************************/
46 /* Utility functions */
47 /*****************************************************/
50 uisutil_add_proc_line_ex(int *total
, char **buffer
, int *buffer_remaining
,
56 va_start(args
, format
);
57 len
= vsnprintf(*buffer
, *buffer_remaining
, format
, args
);
59 if (len
>= *buffer_remaining
) {
60 *buffer
+= *buffer_remaining
;
61 *total
+= *buffer_remaining
;
62 *buffer_remaining
= 0;
65 *buffer_remaining
-= len
;
70 EXPORT_SYMBOL_GPL(uisutil_add_proc_line_ex
);
73 uisctrl_register_req_handler(int type
, void *fptr
,
74 struct ultra_vbus_deviceinfo
*chipset_driver_info
)
79 if (!virt_control_chan_func
)
80 atomic_inc(&uisutils_registered_services
);
81 virt_control_chan_func
= fptr
;
83 if (virt_control_chan_func
)
84 atomic_dec(&uisutils_registered_services
);
85 virt_control_chan_func
= NULL
;
92 if (chipset_driver_info
)
93 bus_device_info_init(chipset_driver_info
, "chipset", "uislib",
98 EXPORT_SYMBOL_GPL(uisctrl_register_req_handler
);
101 * unsigned int uisutil_copy_fragsinfo_from_skb(unsigned char *calling_ctx,
103 * unsigned int firstfraglen,
104 * unsigned int frags_max,
105 * struct phys_info frags[])
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
119 static LIST_HEAD(req_handler_info_list
); /* list of struct req_handler_info */
120 static DEFINE_SPINLOCK(req_handler_info_list_lock
);
122 struct req_handler_info
*
123 req_handler_find(uuid_le switch_uuid
)
125 struct list_head
*lelt
, *tmp
;
126 struct req_handler_info
*entry
= NULL
;
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
);
136 spin_unlock(&req_handler_info_list_lock
);