Remove <swab.h> and swabXX() functions
GCC generates correct code for __builtin_bswapXX() on all architectures,
including ArmV4. It seems that whatever bug caused this to not work back
in commit 879ea7fce8 ("endian: Replace explicit byte swapping with
compiler builtin") has been fixed now. We can eliminate the swabXX()
functions and simplify the code.
All instances that had been calling these functions directly should have
been using real endianness conversions anyway.
Change-Id: I19713fd009aa5c0e01c4a42e0cf012364d6bed60
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/90438
Reviewed-by: Maximilian Brune <maximilian.brune@9elements.com>
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Frans Hendriks <fhendriks@eltan.com>
This commit is contained in:
parent
d556bc65c2
commit
8f34fdfab3
9 changed files with 17 additions and 76 deletions
|
|
@ -34,10 +34,6 @@
|
|||
#include <libpayload-config.h>
|
||||
#include <string.h>
|
||||
|
||||
#define swab16(x) __builtin_bswap16(x)
|
||||
#define swab32(x) __builtin_bswap32(x)
|
||||
#define swab64(x) __builtin_bswap64(x)
|
||||
|
||||
#if CONFIG(LP_BIG_ENDIAN)
|
||||
#define __BIG_ENDIAN
|
||||
#elif CONFIG(LP_LITTLE_ENDIAN)
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
/*
|
||||
* This header should not be included directly. Including source must define
|
||||
* prerequisites like uintXX_t types, the byteswap functions swabXX(),
|
||||
* __BIG_ENDIAN or __LITTLE_ENDIAN and I/O accessors readXX()/writeXX().
|
||||
* prerequisites like uintXX_t types, __BIG_ENDIAN or __LITTLE_ENDIAN and
|
||||
* I/O accessors readXX()/writeXX().
|
||||
*/
|
||||
|
||||
/* Endian functions from glibc 2.9 / BSD "endian.h" */
|
||||
|
|
@ -15,13 +15,13 @@
|
|||
#define htobe16(in) (in)
|
||||
#define htobe32(in) (in)
|
||||
#define htobe64(in) (in)
|
||||
#define htole16(in) ((uint16_t)swab16(in))
|
||||
#define htole32(in) ((uint32_t)swab32(in))
|
||||
#define htole64(in) ((uint64_t)swab64(in))
|
||||
#define htole16(in) ((uint16_t)__builtin_bswap16(in))
|
||||
#define htole32(in) ((uint32_t)__builtin_bswap32(in))
|
||||
#define htole64(in) ((uint64_t)__builtin_bswap64(in))
|
||||
#elif defined(__LITTLE_ENDIAN)
|
||||
#define htobe16(in) ((uint16_t)swab16(in))
|
||||
#define htobe32(in) ((uint32_t)swab32(in))
|
||||
#define htobe64(in) ((uint64_t)swab64(in))
|
||||
#define htobe16(in) ((uint16_t)__builtin_bswap16(in))
|
||||
#define htobe32(in) ((uint32_t)__builtin_bswap32(in))
|
||||
#define htobe64(in) ((uint64_t)__builtin_bswap64(in))
|
||||
#define htole16(in) (in)
|
||||
#define htole32(in) (in)
|
||||
#define htole64(in) (in)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include <console/console.h>
|
||||
#include <device/mmio.h>
|
||||
#include <ec/acpi/ec.h>
|
||||
#include <swab.h>
|
||||
#include <endian.h>
|
||||
#include <timer.h>
|
||||
#include <types.h>
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ void ec_set_kbled_timeout(uint16_t timeout)
|
|||
printk(BIOS_DEBUG, "EC: set keyboard backlight timeout to %us\n", timeout);
|
||||
|
||||
write8p(ECRAM + FDAT, timeout ? 0xff : 0x00);
|
||||
write16p(ECRAM + FBUF, swab16(timeout));
|
||||
write16p(ECRAM + FBUF, htobe16(timeout));
|
||||
ec_fcmd(FCMD_SET_KBLED_TIMEOUT);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
#include <arch/byteorder.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <swab.h>
|
||||
|
||||
/* This include depends on previous ones, do not reorder. */
|
||||
#include <commonlib/bsd/_endian.h>
|
||||
|
|
|
|||
|
|
@ -1,55 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
|
||||
/*
|
||||
* linux/byteorder/swab.h
|
||||
* Byte-swapping, independently from CPU endianness
|
||||
* swabXX[ps]?(foo)
|
||||
*
|
||||
* Francois-Rene Rideau <fare@tunes.org> 19971205
|
||||
* separated swab functions from cpu_to_XX,
|
||||
* to clean up support for bizarre-endian architectures.
|
||||
*
|
||||
* See asm-i386/byteorder.h and such for examples of how to provide
|
||||
* architecture-dependent optimized versions
|
||||
*
|
||||
*/
|
||||
|
||||
/* casts are necessary for constants, because we never know how for sure
|
||||
* how U/UL/ULL map to __u16, __u32, __u64. At least not in a portable way.
|
||||
*/
|
||||
|
||||
#ifndef _SWAB_H
|
||||
#define _SWAB_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if ENV_ARMV4
|
||||
#define swab16(x) \
|
||||
((unsigned short)( \
|
||||
(((unsigned short)(x) & (unsigned short)0x00ffU) << 8) | \
|
||||
(((unsigned short)(x) & (unsigned short)0xff00U) >> 8)))
|
||||
|
||||
#define swab32(x) \
|
||||
((unsigned int)( \
|
||||
(((unsigned int)(x) & 0x000000ffUL) << 24) | \
|
||||
(((unsigned int)(x) & 0x0000ff00UL) << 8) | \
|
||||
(((unsigned int)(x) & 0x00ff0000UL) >> 8) | \
|
||||
(((unsigned int)(x) & 0xff000000UL) >> 24)))
|
||||
|
||||
#define swab64(x) \
|
||||
((uint64_t)( \
|
||||
(((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \
|
||||
(((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
|
||||
(((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
|
||||
(((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
|
||||
(((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
|
||||
(((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
|
||||
(((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
|
||||
(((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56)))
|
||||
#else /* ENV_ARMV4 */
|
||||
#define swab16(x) ((uint16_t)__builtin_bswap16(x))
|
||||
#define swab32(x) ((uint32_t)__builtin_bswap32(x))
|
||||
#define swab64(x) ((uint64_t)__builtin_bswap64(x))
|
||||
#endif /* !ENV_ARMV4 */
|
||||
|
||||
#endif /* _SWAB_H */
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
#include <delay.h>
|
||||
#include <device/pci_ops.h>
|
||||
#include <device/smbus_host.h>
|
||||
#include <endian.h>
|
||||
#include <soc/intel/common/block/smbus/smbuslib.h>
|
||||
#include <string.h>
|
||||
#include <types.h>
|
||||
|
|
@ -163,7 +164,7 @@ bool eeprom_read_buffer(void *blob, size_t read_offset, size_t size)
|
|||
u8 tmp[2] = {0};
|
||||
|
||||
ret = do_smbus_process_call(SMBUS_IO_BASE, I2C_ADDR_EEPROM, 0,
|
||||
swab16(read_offset + i), (uint16_t *)&tmp[0]);
|
||||
htobe16(read_offset + i), (uint16_t *)&tmp[0]);
|
||||
if (ret < 0)
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@
|
|||
#include <bl_uapp/bl_syscall_public.h>
|
||||
#include <commonlib/bsd/helpers.h>
|
||||
#include <console/console.h>
|
||||
#include <endian.h>
|
||||
#include "psp_verstage.h"
|
||||
#include <soc/psp_verstage_addr.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <swab.h>
|
||||
#include <symbols.h>
|
||||
#include <vb2_api.h>
|
||||
|
||||
|
|
@ -161,7 +161,7 @@ vb2_error_t vb2ex_hwcrypto_modexp(const struct vb2_public_key *key,
|
|||
return VB2_ERROR_WORKBUF_SMALL;
|
||||
|
||||
for (i = 0; i < key->arrsize; i++)
|
||||
sig_swapped[i] = swab32(inout_32[key->arrsize - i - 1]);
|
||||
sig_swapped[i] = be32toh(inout_32[key->arrsize - i - 1]);
|
||||
|
||||
mod_exp_param.pExponent = (char *)&exp;
|
||||
mod_exp_param.ExpSize = sizeof(exp);
|
||||
|
|
@ -179,7 +179,7 @@ vb2_error_t vb2ex_hwcrypto_modexp(const struct vb2_public_key *key,
|
|||
|
||||
/* vboot expects results in *inout with BE, so copy & convert. */
|
||||
for (i = 0; i < key->arrsize; i++)
|
||||
inout_32[i] = swab32(output_buffer[key->arrsize - i - 1]);
|
||||
inout_32[i] = htobe32(output_buffer[key->arrsize - i - 1]);
|
||||
|
||||
return VB2_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include <mboot.h>
|
||||
#include <assert.h>
|
||||
#include <build.h>
|
||||
#include <endian.h>
|
||||
#include <vb2_api.h>
|
||||
#include <board_mboot.h>
|
||||
|
||||
|
|
@ -87,7 +88,7 @@ tpm_result_t tpm2_get_capability_pcrs(TPML_PCR_SELECTION *Pcrs)
|
|||
printk(BIOS_DEBUG, "Pcrs->count = %d\n", Pcrs->count);
|
||||
for (index = 0; index < Pcrs->count; index++) {
|
||||
Pcrs->pcrSelections[index].hash =
|
||||
swab16(TpmCap.data.assignedPCR.pcrSelections[index].hash);
|
||||
be16toh(TpmCap.data.assignedPCR.pcrSelections[index].hash);
|
||||
printk(BIOS_DEBUG, "Pcrs->pcrSelections[%d].hash = %#x\n", index,
|
||||
Pcrs->pcrSelections[index].hash);
|
||||
Pcrs->pcrSelections[index].sizeofSelect =
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
#include <boot/coreboot_tables.h>
|
||||
#include <security/tpm/tss/tcg-2.0/tss_structures.h>
|
||||
#include <security/tpm/tss.h>
|
||||
#include <swab.h>
|
||||
|
||||
/* TPM2 interface */
|
||||
#define EFI_TPM2_ACPI_TABLE_START_METHOD_TIS 6
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue