Skip to content

Commit 65082bf

Browse files
Lv Zhengrafaeljw
authored andcommitted
ACPICA: CLib: Add short multiply/shift support
ACPICA commit 01b8f5a2350b9cc329cd8402ac8faec36fc501f5 In order to build ACPICA EFI tools with EDK-II on Windows, 64-bit multiply/shift supports are also required to be implemented. Otherwise, MSVC complains: acpidump.lib(utstrtoul64.obj) : error LNK2001: unresolved external symbol __allmul acpidump.lib(uthex.obj) : error LNK2001: unresolved external symbol __aullshr Note: 1. This patch also splits _EDK2_EFI from _GNU_EFI as they might have different math64 supports. 2. Support of gcc math64 is not included in this patch. 3. Support of EDK2 arch independent math64 is done via linking to base_lib. This patch fixes this issue. Reported by Shao Ming, fixed by Lv Zheng. For Linux kernel, this patch is a functional no-op. Link: open-acpica/acpica@01b8f5a2 Tested-by: "Shao, Ming" <smbest163@163.com> Signed-off-by: Lv Zheng <lv.zheng@intel.com> Signed-off-by: Bob Moore <robert.moore@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent d5f23fe commit 65082bf

10 files changed

Lines changed: 237 additions & 18 deletions

File tree

‎drivers/acpi/acpica/acutils.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,13 @@ acpi_status
538538
acpi_ut_short_divide(u64 in_dividend,
539539
u32 divisor, u64 *out_quotient, u32 *out_remainder);
540540

541+
acpi_status
542+
acpi_ut_short_multiply(u64 in_multiplicand, u32 multiplier, u64 *outproduct);
543+
544+
acpi_status acpi_ut_short_shift_left(u64 operand, u32 count, u64 *out_result);
545+
546+
acpi_status acpi_ut_short_shift_right(u64 operand, u32 count, u64 *out_result);
547+
541548
/*
542549
* utmisc
543550
*/

‎drivers/acpi/acpica/uthex.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ static const char acpi_gbl_hex_to_ascii[] = {
6969

7070
char acpi_ut_hex_to_ascii_char(u64 integer, u32 position)
7171
{
72+
u64 index;
7273

73-
return (acpi_gbl_hex_to_ascii[(integer >> position) & 0xF]);
74+
acpi_ut_short_shift_right(integer, position, &index);
75+
return (acpi_gbl_hex_to_ascii[index & 0xF]);
7476
}
7577

7678
/*******************************************************************************

‎drivers/acpi/acpica/utmath.c‎

Lines changed: 213 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,6 @@
4747
#define _COMPONENT ACPI_UTILITIES
4848
ACPI_MODULE_NAME("utmath")
4949

50-
/*
51-
* Optional support for 64-bit double-precision integer divide. This code
52-
* is configurable and is implemented in order to support 32-bit kernel
53-
* environments where a 64-bit double-precision math library is not available.
54-
*
55-
* Support for a more normal 64-bit divide/modulo (with check for a divide-
56-
* by-zero) appears after this optional section of code.
57-
*/
58-
#ifndef ACPI_USE_NATIVE_DIVIDE
5950
/* Structures used only for 64-bit divide */
6051
typedef struct uint64_struct {
6152
u32 lo;
@@ -69,6 +60,217 @@ typedef union uint64_overlay {
6960

7061
} uint64_overlay;
7162

63+
/*
64+
* Optional support for 64-bit double-precision integer multiply and shift.
65+
* This code is configurable and is implemented in order to support 32-bit
66+
* kernel environments where a 64-bit double-precision math library is not
67+
* available.
68+
*/
69+
#ifndef ACPI_USE_NATIVE_MATH64
70+
71+
/*******************************************************************************
72+
*
73+
* FUNCTION: acpi_ut_short_multiply
74+
*
75+
* PARAMETERS: multiplicand - 64-bit multiplicand
76+
* multiplier - 32-bit multiplier
77+
* out_product - Pointer to where the product is returned
78+
*
79+
* DESCRIPTION: Perform a short multiply.
80+
*
81+
******************************************************************************/
82+
83+
acpi_status
84+
acpi_ut_short_multiply(u64 multiplicand, u32 multiplier, u64 *out_product)
85+
{
86+
union uint64_overlay multiplicand_ovl;
87+
union uint64_overlay product;
88+
u32 carry32;
89+
90+
ACPI_FUNCTION_TRACE(ut_short_multiply);
91+
92+
multiplicand_ovl.full = multiplicand;
93+
94+
/*
95+
* The Product is 64 bits, the carry is always 32 bits,
96+
* and is generated by the second multiply.
97+
*/
98+
ACPI_MUL_64_BY_32(0, multiplicand_ovl.part.hi, multiplier,
99+
product.part.hi, carry32);
100+
101+
ACPI_MUL_64_BY_32(0, multiplicand_ovl.part.lo, multiplier,
102+
product.part.lo, carry32);
103+
104+
product.part.hi += carry32;
105+
106+
/* Return only what was requested */
107+
108+
if (out_product) {
109+
*out_product = product.full;
110+
}
111+
112+
return_ACPI_STATUS(AE_OK);
113+
}
114+
115+
/*******************************************************************************
116+
*
117+
* FUNCTION: acpi_ut_short_shift_left
118+
*
119+
* PARAMETERS: operand - 64-bit shift operand
120+
* count - 32-bit shift count
121+
* out_result - Pointer to where the result is returned
122+
*
123+
* DESCRIPTION: Perform a short left shift.
124+
*
125+
******************************************************************************/
126+
127+
acpi_status acpi_ut_short_shift_left(u64 operand, u32 count, u64 *out_result)
128+
{
129+
union uint64_overlay operand_ovl;
130+
131+
ACPI_FUNCTION_TRACE(ut_short_shift_left);
132+
133+
operand_ovl.full = operand;
134+
135+
if ((count & 63) >= 32) {
136+
operand_ovl.part.hi = operand_ovl.part.lo;
137+
operand_ovl.part.lo ^= operand_ovl.part.lo;
138+
count = (count & 63) - 32;
139+
}
140+
ACPI_SHIFT_LEFT_64_BY_32(operand_ovl.part.hi,
141+
operand_ovl.part.lo, count);
142+
143+
/* Return only what was requested */
144+
145+
if (out_result) {
146+
*out_result = operand_ovl.full;
147+
}
148+
149+
return_ACPI_STATUS(AE_OK);
150+
}
151+
152+
/*******************************************************************************
153+
*
154+
* FUNCTION: acpi_ut_short_shift_right
155+
*
156+
* PARAMETERS: operand - 64-bit shift operand
157+
* count - 32-bit shift count
158+
* out_result - Pointer to where the result is returned
159+
*
160+
* DESCRIPTION: Perform a short right shift.
161+
*
162+
******************************************************************************/
163+
164+
acpi_status acpi_ut_short_shift_right(u64 operand, u32 count, u64 *out_result)
165+
{
166+
union uint64_overlay operand_ovl;
167+
168+
ACPI_FUNCTION_TRACE(ut_short_shift_right);
169+
170+
operand_ovl.full = operand;
171+
172+
if ((count & 63) >= 32) {
173+
operand_ovl.part.lo = operand_ovl.part.hi;
174+
operand_ovl.part.hi ^= operand_ovl.part.hi;
175+
count = (count & 63) - 32;
176+
}
177+
ACPI_SHIFT_RIGHT_64_BY_32(operand_ovl.part.hi,
178+
operand_ovl.part.lo, count);
179+
180+
/* Return only what was requested */
181+
182+
if (out_result) {
183+
*out_result = operand_ovl.full;
184+
}
185+
186+
return_ACPI_STATUS(AE_OK);
187+
}
188+
#else
189+
190+
/*******************************************************************************
191+
*
192+
* FUNCTION: acpi_ut_short_multiply
193+
*
194+
* PARAMETERS: See function headers above
195+
*
196+
* DESCRIPTION: Native version of the ut_short_multiply function.
197+
*
198+
******************************************************************************/
199+
200+
acpi_status
201+
acpi_ut_short_multiply(u64 multiplicand, u32 multiplier, u64 *out_product)
202+
{
203+
204+
ACPI_FUNCTION_TRACE(ut_short_multiply);
205+
206+
/* Return only what was requested */
207+
208+
if (out_product) {
209+
*out_product = multiplicand * multiplier;
210+
}
211+
212+
return_ACPI_STATUS(AE_OK);
213+
}
214+
215+
/*******************************************************************************
216+
*
217+
* FUNCTION: acpi_ut_short_shift_left
218+
*
219+
* PARAMETERS: See function headers above
220+
*
221+
* DESCRIPTION: Native version of the ut_short_shift_left function.
222+
*
223+
******************************************************************************/
224+
225+
acpi_status acpi_ut_short_shift_left(u64 operand, u32 count, u64 *out_result)
226+
{
227+
228+
ACPI_FUNCTION_TRACE(ut_short_shift_left);
229+
230+
/* Return only what was requested */
231+
232+
if (out_result) {
233+
*out_result = operand << count;
234+
}
235+
236+
return_ACPI_STATUS(AE_OK);
237+
}
238+
239+
/*******************************************************************************
240+
*
241+
* FUNCTION: acpi_ut_short_shift_right
242+
*
243+
* PARAMETERS: See function headers above
244+
*
245+
* DESCRIPTION: Native version of the ut_short_shift_right function.
246+
*
247+
******************************************************************************/
248+
249+
acpi_status acpi_ut_short_shift_right(u64 operand, u32 count, u64 *out_result)
250+
{
251+
252+
ACPI_FUNCTION_TRACE(ut_short_shift_right);
253+
254+
/* Return only what was requested */
255+
256+
if (out_result) {
257+
*out_result = operand >> count;
258+
}
259+
260+
return_ACPI_STATUS(AE_OK);
261+
}
262+
#endif
263+
264+
/*
265+
* Optional support for 64-bit double-precision integer divide. This code
266+
* is configurable and is implemented in order to support 32-bit kernel
267+
* environments where a 64-bit double-precision math library is not available.
268+
*
269+
* Support for a more normal 64-bit divide/modulo (with check for a divide-
270+
* by-zero) appears after this optional section of code.
271+
*/
272+
#ifndef ACPI_USE_NATIVE_DIVIDE
273+
72274
/*******************************************************************************
73275
*
74276
* FUNCTION: acpi_ut_short_divide
@@ -258,6 +460,7 @@ acpi_ut_divide(u64 in_dividend,
258460
}
259461

260462
#else
463+
261464
/*******************************************************************************
262465
*
263466
* FUNCTION: acpi_ut_short_divide, acpi_ut_divide
@@ -272,6 +475,7 @@ acpi_ut_divide(u64 in_dividend,
272475
* perform the divide.
273476
*
274477
******************************************************************************/
478+
275479
acpi_status
276480
acpi_ut_short_divide(u64 in_dividend,
277481
u32 divisor, u64 *out_quotient, u32 *out_remainder)

‎drivers/acpi/acpica/utprint.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const char *acpi_ut_scan_number(const char *string, u64 *number_ptr)
176176
u64 number = 0;
177177

178178
while (isdigit((int)*string)) {
179-
number *= 10;
179+
acpi_ut_short_multiply(number, 10, &number);
180180
number += *(string++) - '0';
181181
}
182182

‎drivers/acpi/acpica/utstrtoul64.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ static u64 acpi_ut_strtoul_base10(char *string, u32 flags)
276276

277277
/* Convert and insert (add) the decimal digit */
278278

279-
next_value =
280-
(return_value * 10) + (ascii_digit - ACPI_ASCII_ZERO);
279+
acpi_ut_short_multiply(return_value, 10, &next_value);
280+
next_value += (ascii_digit - ACPI_ASCII_ZERO);
281281

282282
/* Check for overflow (32 or 64 bit) - return current converted value */
283283

@@ -335,9 +335,8 @@ static u64 acpi_ut_strtoul_base16(char *string, u32 flags)
335335

336336
/* Convert and insert the hex digit */
337337

338-
return_value =
339-
(return_value << 4) |
340-
acpi_ut_ascii_char_to_hex(ascii_digit);
338+
acpi_ut_short_shift_left(return_value, 4, &return_value);
339+
return_value |= acpi_ut_ascii_char_to_hex(ascii_digit);
341340

342341
string++;
343342
valid_digits++;

‎include/acpi/actypes.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ typedef u64 acpi_physical_address;
166166
#define ACPI_SIZE_MAX ACPI_UINT64_MAX
167167

168168
#define ACPI_USE_NATIVE_DIVIDE /* Has native 64-bit integer support */
169+
#define ACPI_USE_NATIVE_MATH64 /* Has native 64-bit integer support */
169170

170171
/*
171172
* In the case of the Itanium Processor Family (IPF), the hardware does not

‎include/acpi/platform/acgcc.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,8 @@ typedef __builtin_va_list va_list;
8484

8585
#define COMPILER_VA_MACRO 1
8686

87+
/* GCC supports native multiply/shift on 32-bit platforms */
88+
89+
#define ACPI_USE_NATIVE_MATH64
90+
8791
#endif /* __ACGCC_H__ */

‎include/acpi/platform/aclinux.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
/* Host-dependent types and defines for in-kernel ACPICA */
129129

130130
#define ACPI_MACHINE_WIDTH BITS_PER_LONG
131+
#define ACPI_USE_NATIVE_MATH64
131132
#define ACPI_EXPORT_SYMBOL(symbol) EXPORT_SYMBOL(symbol);
132133
#define strtoul simple_strtoul
133134

@@ -216,6 +217,7 @@
216217
#define COMPILER_DEPENDENT_INT64 long long
217218
#define COMPILER_DEPENDENT_UINT64 unsigned long long
218219
#define ACPI_USE_NATIVE_DIVIDE
220+
#define ACPI_USE_NATIVE_MATH64
219221
#endif
220222

221223
#ifndef __cdecl

‎tools/power/acpi/tools/acpidump/apfiles.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static int ap_is_existing_file(char *pathname);
6161

6262
static int ap_is_existing_file(char *pathname)
6363
{
64-
#ifndef _GNU_EFI
64+
#if !defined(_GNU_EFI) && !defined(_EDK2_EFI)
6565
struct stat stat_info;
6666

6767
if (!stat(pathname, &stat_info)) {

‎tools/power/acpi/tools/acpidump/apmain.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static int ap_do_options(int argc, char **argv)
300300
*
301301
******************************************************************************/
302302

303-
#ifndef _GNU_EFI
303+
#if !defined(_GNU_EFI) && !defined(_EDK2_EFI)
304304
int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
305305
#else
306306
int ACPI_SYSTEM_XFACE acpi_main(int argc, char *argv[])

0 commit comments

Comments
 (0)