perf python: Do not force closing original perf descriptor in evlist.get_pollfd()
[linux/fpc-iii.git] / drivers / usb / gadget / u_os_desc.h
blob8acd21779ac8d08e82463a44ca7fdc3c173c5b0c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * u_os_desc.h
5 * Utility definitions for "OS Descriptors" support
7 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
8 * http://www.samsung.com
10 * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
13 #ifndef __U_OS_DESC_H__
14 #define __U_OS_DESC_H__
16 #include <asm/unaligned.h>
17 #include <linux/nls.h>
19 #define USB_EXT_PROP_DW_SIZE 0
20 #define USB_EXT_PROP_DW_PROPERTY_DATA_TYPE 4
21 #define USB_EXT_PROP_W_PROPERTY_NAME_LENGTH 8
22 #define USB_EXT_PROP_B_PROPERTY_NAME 10
23 #define USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH 10
24 #define USB_EXT_PROP_B_PROPERTY_DATA 14
26 #define USB_EXT_PROP_RESERVED 0
27 #define USB_EXT_PROP_UNICODE 1
28 #define USB_EXT_PROP_UNICODE_ENV 2
29 #define USB_EXT_PROP_BINARY 3
30 #define USB_EXT_PROP_LE32 4
31 #define USB_EXT_PROP_BE32 5
32 #define USB_EXT_PROP_UNICODE_LINK 6
33 #define USB_EXT_PROP_UNICODE_MULTI 7
35 static inline u8 *__usb_ext_prop_ptr(u8 *buf, size_t offset)
37 return buf + offset;
40 static inline u8 *usb_ext_prop_size_ptr(u8 *buf)
42 return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_SIZE);
45 static inline u8 *usb_ext_prop_type_ptr(u8 *buf)
47 return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_PROPERTY_DATA_TYPE);
50 static inline u8 *usb_ext_prop_name_len_ptr(u8 *buf)
52 return __usb_ext_prop_ptr(buf, USB_EXT_PROP_W_PROPERTY_NAME_LENGTH);
55 static inline u8 *usb_ext_prop_name_ptr(u8 *buf)
57 return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_NAME);
60 static inline u8 *usb_ext_prop_data_len_ptr(u8 *buf, size_t off)
62 return __usb_ext_prop_ptr(buf,
63 USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + off);
66 static inline u8 *usb_ext_prop_data_ptr(u8 *buf, size_t off)
68 return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_DATA + off);
71 static inline void usb_ext_prop_put_size(u8 *buf, int dw_size)
73 put_unaligned_le32(dw_size, usb_ext_prop_size_ptr(buf));
76 static inline void usb_ext_prop_put_type(u8 *buf, int type)
78 put_unaligned_le32(type, usb_ext_prop_type_ptr(buf));
81 static inline int usb_ext_prop_put_name(u8 *buf, const char *name, int pnl)
83 int result;
85 put_unaligned_le16(pnl, usb_ext_prop_name_len_ptr(buf));
86 result = utf8s_to_utf16s(name, strlen(name), UTF16_LITTLE_ENDIAN,
87 (wchar_t *) usb_ext_prop_name_ptr(buf), pnl - 2);
88 if (result < 0)
89 return result;
91 put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_NAME + pnl - 2]);
93 return pnl;
96 static inline void usb_ext_prop_put_binary(u8 *buf, int pnl, const u8 *data,
97 int data_len)
99 put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl));
100 memcpy(usb_ext_prop_data_ptr(buf, pnl), data, data_len);
103 static inline int usb_ext_prop_put_unicode(u8 *buf, int pnl, const char *string,
104 int data_len)
106 int result;
107 put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl));
108 result = utf8s_to_utf16s(string, data_len >> 1, UTF16_LITTLE_ENDIAN,
109 (wchar_t *) usb_ext_prop_data_ptr(buf, pnl),
110 data_len - 2);
111 if (result < 0)
112 return result;
114 put_unaligned_le16(0,
115 &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl + data_len - 2]);
117 return data_len;
120 #endif /* __U_OS_DESC_H__ */