]> git.proxmox.com Git - mirror_qemu.git/blame - thunk.h
usb: Call wakeup when data becomes available for all devices with int eps
[mirror_qemu.git] / thunk.h
CommitLineData
3ef693a0
FB
1/*
2 * Generic thunking code to convert data between host and target CPU
5fafdf24 3 *
3ef693a0
FB
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
8167ee88 17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
3ef693a0 18 */
31e31b8a
FB
19#ifndef THUNK_H
20#define THUNK_H
21
22#include <inttypes.h>
35b66fc4 23#include "cpu.h"
34313956 24
31e31b8a
FB
25/* types enums definitions */
26
27typedef enum argtype {
28 TYPE_NULL,
29 TYPE_CHAR,
30 TYPE_SHORT,
31 TYPE_INT,
32 TYPE_LONG,
33 TYPE_ULONG,
34 TYPE_PTRVOID, /* pointer on unknown data */
35 TYPE_LONGLONG,
36 TYPE_ULONGLONG,
37 TYPE_PTR,
38 TYPE_ARRAY,
39 TYPE_STRUCT,
6083abd9 40 TYPE_OLDDEVT,
31e31b8a
FB
41} argtype;
42
43#define MK_PTR(type) TYPE_PTR, type
44#define MK_ARRAY(type, size) TYPE_ARRAY, size, type
45#define MK_STRUCT(id) TYPE_STRUCT, id
46
47#define THUNK_TARGET 0
48#define THUNK_HOST 1
49
50typedef struct {
51 /* standard struct handling */
52 const argtype *field_types;
53 int nb_fields;
54 int *field_offsets[2];
55 /* special handling */
56 void (*convert[2])(void *dst, const void *src);
57 int size[2];
58 int align[2];
59 const char *name;
60} StructEntry;
61
62/* Translation table for bitmasks... */
63typedef struct bitmask_transtbl {
64 unsigned int x86_mask;
65 unsigned int x86_bits;
66 unsigned int alpha_mask;
67 unsigned int alpha_bits;
68} bitmask_transtbl;
69
70void thunk_register_struct(int id, const char *name, const argtype *types);
8e853dc7
BS
71void thunk_register_struct_direct(int id, const char *name,
72 const StructEntry *se1);
5fafdf24 73const argtype *thunk_convert(void *dst, const void *src,
31e31b8a 74 const argtype *type_ptr, int to_host);
0ad041d4 75#ifndef NO_THUNK_TYPE_SIZE
31e31b8a 76
24374901
FB
77extern StructEntry struct_entries[];
78
26553115
JM
79int thunk_type_size_array(const argtype *type_ptr, int is_host);
80int thunk_type_align_array(const argtype *type_ptr, int is_host);
81
24374901
FB
82static inline int thunk_type_size(const argtype *type_ptr, int is_host)
83{
84 int type, size;
85 const StructEntry *se;
86
87 type = *type_ptr;
88 switch(type) {
89 case TYPE_CHAR:
90 return 1;
91 case TYPE_SHORT:
92 return 2;
93 case TYPE_INT:
94 return 4;
95 case TYPE_LONGLONG:
96 case TYPE_ULONGLONG:
97 return 8;
98 case TYPE_LONG:
99 case TYPE_ULONG:
100 case TYPE_PTRVOID:
101 case TYPE_PTR:
102 if (is_host) {
9c6ecf3e 103 return sizeof(void *);
24374901 104 } else {
992f48a0 105 return TARGET_ABI_BITS / 8;
24374901
FB
106 }
107 break;
6083abd9
AG
108 case TYPE_OLDDEVT:
109 if (is_host) {
110#if defined(HOST_X86_64)
111 return 8;
112#elif defined(HOST_ALPHA) || defined(HOST_IA64) || defined(HOST_MIPS) || \
113 defined(HOST_PARISC) || defined(HOST_SPARC64)
114 return 4;
115#elif defined(HOST_PPC)
65074706 116 return sizeof(void *);
6083abd9
AG
117#else
118 return 2;
119#endif
120 } else {
121#if defined(TARGET_X86_64)
122 return 8;
123#elif defined(TARGET_ALPHA) || defined(TARGET_IA64) || defined(TARGET_MIPS) || \
124 defined(TARGET_PARISC) || defined(TARGET_SPARC64)
125 return 4;
126#elif defined(TARGET_PPC)
127 return TARGET_ABI_BITS / 8;
128#else
129 return 2;
130#endif
131 }
132 break;
24374901
FB
133 case TYPE_ARRAY:
134 size = type_ptr[1];
26553115 135 return size * thunk_type_size_array(type_ptr + 2, is_host);
24374901
FB
136 case TYPE_STRUCT:
137 se = struct_entries + type_ptr[1];
138 return se->size[is_host];
139 default:
140 return -1;
141 }
142}
143
144static inline int thunk_type_align(const argtype *type_ptr, int is_host)
145{
146 int type;
147 const StructEntry *se;
148
149 type = *type_ptr;
150 switch(type) {
151 case TYPE_CHAR:
152 return 1;
153 case TYPE_SHORT:
154 return 2;
155 case TYPE_INT:
156 return 4;
157 case TYPE_LONGLONG:
158 case TYPE_ULONGLONG:
159 return 8;
160 case TYPE_LONG:
161 case TYPE_ULONG:
162 case TYPE_PTRVOID:
163 case TYPE_PTR:
164 if (is_host) {
9c6ecf3e 165 return sizeof(void *);
24374901 166 } else {
992f48a0 167 return TARGET_ABI_BITS / 8;
24374901
FB
168 }
169 break;
6083abd9
AG
170 case TYPE_OLDDEVT:
171 return thunk_type_size(type_ptr, is_host);
24374901 172 case TYPE_ARRAY:
26553115 173 return thunk_type_align_array(type_ptr + 2, is_host);
24374901
FB
174 case TYPE_STRUCT:
175 se = struct_entries + type_ptr[1];
176 return se->align[is_host];
177 default:
178 return -1;
179 }
180}
181
0ad041d4
FB
182#endif /* NO_THUNK_TYPE_SIZE */
183
5fafdf24 184unsigned int target_to_host_bitmask(unsigned int x86_mask,
b39bc503 185 const bitmask_transtbl * trans_tbl);
5fafdf24 186unsigned int host_to_target_bitmask(unsigned int alpha_mask,
b39bc503 187 const bitmask_transtbl * trans_tbl);
31e31b8a
FB
188
189#endif