GK SDK 源码库: XMIPCLinuxV100R005C00SPC030 (kernel/tools/open_source excluded)
This commit is contained in:
@@ -0,0 +1,211 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
#ifndef _LINUX_APM_H
|
||||
#define _LINUX_APM_H
|
||||
|
||||
/*
|
||||
* Include file for the interface to an APM BIOS
|
||||
* Copyright 1994-2001 Stephen Rothwell (sfr@canb.auug.org.au)
|
||||
*/
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
typedef unsigned short apm_event_t;
|
||||
typedef unsigned short apm_eventinfo_t;
|
||||
|
||||
struct apm_bios_info {
|
||||
__u16 version;
|
||||
__u16 cseg;
|
||||
__u32 offset;
|
||||
__u16 cseg_16;
|
||||
__u16 dseg;
|
||||
__u16 flags;
|
||||
__u16 cseg_len;
|
||||
__u16 cseg_16_len;
|
||||
__u16 dseg_len;
|
||||
};
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
#define APM_CS (GDT_ENTRY_APMBIOS_BASE * 8)
|
||||
#define APM_CS_16 (APM_CS + 8)
|
||||
#define APM_DS (APM_CS_16 + 8)
|
||||
|
||||
/* Results of APM Installation Check */
|
||||
#define APM_16_BIT_SUPPORT 0x0001
|
||||
#define APM_32_BIT_SUPPORT 0x0002
|
||||
#define APM_IDLE_SLOWS_CLOCK 0x0004
|
||||
#define APM_BIOS_DISABLED 0x0008
|
||||
#define APM_BIOS_DISENGAGED 0x0010
|
||||
|
||||
/*
|
||||
* Data for APM that is persistent across module unload/load
|
||||
*/
|
||||
struct apm_info {
|
||||
struct apm_bios_info bios;
|
||||
unsigned short connection_version;
|
||||
int get_power_status_broken;
|
||||
int get_power_status_swabinminutes;
|
||||
int allow_ints;
|
||||
int forbid_idle;
|
||||
int realmode_power_off;
|
||||
int disabled;
|
||||
};
|
||||
|
||||
/*
|
||||
* The APM function codes
|
||||
*/
|
||||
#define APM_FUNC_INST_CHECK 0x5300
|
||||
#define APM_FUNC_REAL_CONN 0x5301
|
||||
#define APM_FUNC_16BIT_CONN 0x5302
|
||||
#define APM_FUNC_32BIT_CONN 0x5303
|
||||
#define APM_FUNC_DISCONN 0x5304
|
||||
#define APM_FUNC_IDLE 0x5305
|
||||
#define APM_FUNC_BUSY 0x5306
|
||||
#define APM_FUNC_SET_STATE 0x5307
|
||||
#define APM_FUNC_ENABLE_PM 0x5308
|
||||
#define APM_FUNC_RESTORE_BIOS 0x5309
|
||||
#define APM_FUNC_GET_STATUS 0x530a
|
||||
#define APM_FUNC_GET_EVENT 0x530b
|
||||
#define APM_FUNC_GET_STATE 0x530c
|
||||
#define APM_FUNC_ENABLE_DEV_PM 0x530d
|
||||
#define APM_FUNC_VERSION 0x530e
|
||||
#define APM_FUNC_ENGAGE_PM 0x530f
|
||||
#define APM_FUNC_GET_CAP 0x5310
|
||||
#define APM_FUNC_RESUME_TIMER 0x5311
|
||||
#define APM_FUNC_RESUME_ON_RING 0x5312
|
||||
#define APM_FUNC_TIMER 0x5313
|
||||
|
||||
/*
|
||||
* Function code for APM_FUNC_RESUME_TIMER
|
||||
*/
|
||||
#define APM_FUNC_DISABLE_TIMER 0
|
||||
#define APM_FUNC_GET_TIMER 1
|
||||
#define APM_FUNC_SET_TIMER 2
|
||||
|
||||
/*
|
||||
* Function code for APM_FUNC_RESUME_ON_RING
|
||||
*/
|
||||
#define APM_FUNC_DISABLE_RING 0
|
||||
#define APM_FUNC_ENABLE_RING 1
|
||||
#define APM_FUNC_GET_RING 2
|
||||
|
||||
/*
|
||||
* Function code for APM_FUNC_TIMER_STATUS
|
||||
*/
|
||||
#define APM_FUNC_TIMER_DISABLE 0
|
||||
#define APM_FUNC_TIMER_ENABLE 1
|
||||
#define APM_FUNC_TIMER_GET 2
|
||||
|
||||
/*
|
||||
* in arch/i386/kernel/setup.c
|
||||
*/
|
||||
extern struct apm_info apm_info;
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
/*
|
||||
* Power states
|
||||
*/
|
||||
#define APM_STATE_READY 0x0000
|
||||
#define APM_STATE_STANDBY 0x0001
|
||||
#define APM_STATE_SUSPEND 0x0002
|
||||
#define APM_STATE_OFF 0x0003
|
||||
#define APM_STATE_BUSY 0x0004
|
||||
#define APM_STATE_REJECT 0x0005
|
||||
#define APM_STATE_OEM_SYS 0x0020
|
||||
#define APM_STATE_OEM_DEV 0x0040
|
||||
|
||||
#define APM_STATE_DISABLE 0x0000
|
||||
#define APM_STATE_ENABLE 0x0001
|
||||
|
||||
#define APM_STATE_DISENGAGE 0x0000
|
||||
#define APM_STATE_ENGAGE 0x0001
|
||||
|
||||
/*
|
||||
* Events (results of Get PM Event)
|
||||
*/
|
||||
#define APM_SYS_STANDBY 0x0001
|
||||
#define APM_SYS_SUSPEND 0x0002
|
||||
#define APM_NORMAL_RESUME 0x0003
|
||||
#define APM_CRITICAL_RESUME 0x0004
|
||||
#define APM_LOW_BATTERY 0x0005
|
||||
#define APM_POWER_STATUS_CHANGE 0x0006
|
||||
#define APM_UPDATE_TIME 0x0007
|
||||
#define APM_CRITICAL_SUSPEND 0x0008
|
||||
#define APM_USER_STANDBY 0x0009
|
||||
#define APM_USER_SUSPEND 0x000a
|
||||
#define APM_STANDBY_RESUME 0x000b
|
||||
#define APM_CAPABILITY_CHANGE 0x000c
|
||||
|
||||
/*
|
||||
* Error codes
|
||||
*/
|
||||
#define APM_SUCCESS 0x00
|
||||
#define APM_DISABLED 0x01
|
||||
#define APM_CONNECTED 0x02
|
||||
#define APM_NOT_CONNECTED 0x03
|
||||
#define APM_16_CONNECTED 0x05
|
||||
#define APM_16_UNSUPPORTED 0x06
|
||||
#define APM_32_CONNECTED 0x07
|
||||
#define APM_32_UNSUPPORTED 0x08
|
||||
#define APM_BAD_DEVICE 0x09
|
||||
#define APM_BAD_PARAM 0x0a
|
||||
#define APM_NOT_ENGAGED 0x0b
|
||||
#define APM_BAD_FUNCTION 0x0c
|
||||
#define APM_RESUME_DISABLED 0x0d
|
||||
#define APM_NO_ERROR 0x53
|
||||
#define APM_BAD_STATE 0x60
|
||||
#define APM_NO_EVENTS 0x80
|
||||
#define APM_NOT_PRESENT 0x86
|
||||
|
||||
/*
|
||||
* APM Device IDs
|
||||
*/
|
||||
#define APM_DEVICE_BIOS 0x0000
|
||||
#define APM_DEVICE_ALL 0x0001
|
||||
#define APM_DEVICE_DISPLAY 0x0100
|
||||
#define APM_DEVICE_STORAGE 0x0200
|
||||
#define APM_DEVICE_PARALLEL 0x0300
|
||||
#define APM_DEVICE_SERIAL 0x0400
|
||||
#define APM_DEVICE_NETWORK 0x0500
|
||||
#define APM_DEVICE_PCMCIA 0x0600
|
||||
#define APM_DEVICE_BATTERY 0x8000
|
||||
#define APM_DEVICE_OEM 0xe000
|
||||
#define APM_DEVICE_OLD_ALL 0xffff
|
||||
#define APM_DEVICE_CLASS 0x00ff
|
||||
#define APM_DEVICE_MASK 0xff00
|
||||
|
||||
#ifdef __KERNEL__
|
||||
/*
|
||||
* This is the "All Devices" ID communicated to the BIOS
|
||||
*/
|
||||
#define APM_DEVICE_BALL ((apm_info.connection_version > 0x0100) ? \
|
||||
APM_DEVICE_ALL : APM_DEVICE_OLD_ALL)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Battery status
|
||||
*/
|
||||
#define APM_MAX_BATTERIES 2
|
||||
|
||||
/*
|
||||
* APM defined capability bit flags
|
||||
*/
|
||||
#define APM_CAP_GLOBAL_STANDBY 0x0001
|
||||
#define APM_CAP_GLOBAL_SUSPEND 0x0002
|
||||
#define APM_CAP_RESUME_STANDBY_TIMER 0x0004 /* Timer resume from standby */
|
||||
#define APM_CAP_RESUME_SUSPEND_TIMER 0x0008 /* Timer resume from suspend */
|
||||
#define APM_CAP_RESUME_STANDBY_RING 0x0010 /* Resume on Ring fr standby */
|
||||
#define APM_CAP_RESUME_SUSPEND_RING 0x0020 /* Resume on Ring fr suspend */
|
||||
#define APM_CAP_RESUME_STANDBY_PCMCIA 0x0040 /* Resume on PCMCIA Ring */
|
||||
#define APM_CAP_RESUME_SUSPEND_PCMCIA 0x0080 /* Resume on PCMCIA Ring */
|
||||
|
||||
/*
|
||||
* ioctl operations
|
||||
*/
|
||||
#include <linux/ioctl.h>
|
||||
|
||||
#define APM_IOC_STANDBY _IO('A', 1)
|
||||
#define APM_IOC_SUSPEND _IO('A', 2)
|
||||
|
||||
#endif /* LINUX_APM_H */
|
||||
@@ -0,0 +1,125 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Copyright (c) 2015, Linaro Limited
|
||||
*/
|
||||
#ifndef __LINUX_ARM_SMCCC_H
|
||||
#define __LINUX_ARM_SMCCC_H
|
||||
|
||||
/*
|
||||
* This file provides common defines for ARM SMC Calling Convention as
|
||||
* specified in
|
||||
* http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
|
||||
*/
|
||||
|
||||
#define ARM_SMCCC_STD_CALL 0
|
||||
#define ARM_SMCCC_FAST_CALL 1
|
||||
#define ARM_SMCCC_TYPE_SHIFT 31
|
||||
|
||||
#define ARM_SMCCC_SMC_32 0
|
||||
#define ARM_SMCCC_SMC_64 1
|
||||
#define ARM_SMCCC_CALL_CONV_SHIFT 30
|
||||
|
||||
#define ARM_SMCCC_OWNER_MASK 0x3F
|
||||
#define ARM_SMCCC_OWNER_SHIFT 24
|
||||
|
||||
#define ARM_SMCCC_FUNC_MASK 0xFFFF
|
||||
|
||||
#define ARM_SMCCC_IS_FAST_CALL(smc_val) \
|
||||
((smc_val) & (ARM_SMCCC_FAST_CALL << ARM_SMCCC_TYPE_SHIFT))
|
||||
#define ARM_SMCCC_IS_64(smc_val) \
|
||||
((smc_val) & (ARM_SMCCC_SMC_64 << ARM_SMCCC_CALL_CONV_SHIFT))
|
||||
#define ARM_SMCCC_FUNC_NUM(smc_val) ((smc_val) & ARM_SMCCC_FUNC_MASK)
|
||||
#define ARM_SMCCC_OWNER_NUM(smc_val) \
|
||||
(((smc_val) >> ARM_SMCCC_OWNER_SHIFT) & ARM_SMCCC_OWNER_MASK)
|
||||
|
||||
#define ARM_SMCCC_CALL_VAL(type, calling_convention, owner, func_num) \
|
||||
(((type) << ARM_SMCCC_TYPE_SHIFT) | \
|
||||
((calling_convention) << ARM_SMCCC_CALL_CONV_SHIFT) | \
|
||||
(((owner) & ARM_SMCCC_OWNER_MASK) << ARM_SMCCC_OWNER_SHIFT) | \
|
||||
((func_num) & ARM_SMCCC_FUNC_MASK))
|
||||
|
||||
#define ARM_SMCCC_OWNER_ARCH 0
|
||||
#define ARM_SMCCC_OWNER_CPU 1
|
||||
#define ARM_SMCCC_OWNER_SIP 2
|
||||
#define ARM_SMCCC_OWNER_OEM 3
|
||||
#define ARM_SMCCC_OWNER_STANDARD 4
|
||||
#define ARM_SMCCC_OWNER_TRUSTED_APP 48
|
||||
#define ARM_SMCCC_OWNER_TRUSTED_APP_END 49
|
||||
#define ARM_SMCCC_OWNER_TRUSTED_OS 50
|
||||
#define ARM_SMCCC_OWNER_TRUSTED_OS_END 63
|
||||
|
||||
#define ARM_SMCCC_QUIRK_NONE 0
|
||||
#define ARM_SMCCC_QUIRK_QCOM_A6 1 /* Save/restore register a6 */
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#include <linux/linkage.h>
|
||||
#include <linux/types.h>
|
||||
/**
|
||||
* struct arm_smccc_res - Result from SMC/HVC call
|
||||
* @a0-a3 result values from registers 0 to 3
|
||||
*/
|
||||
struct arm_smccc_res {
|
||||
unsigned long a0;
|
||||
unsigned long a1;
|
||||
unsigned long a2;
|
||||
unsigned long a3;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct arm_smccc_quirk - Contains quirk information
|
||||
* @id: quirk identification
|
||||
* @state: quirk specific information
|
||||
* @a6: Qualcomm quirk entry for returning post-smc call contents of a6
|
||||
*/
|
||||
struct arm_smccc_quirk {
|
||||
int id;
|
||||
union {
|
||||
unsigned long a6;
|
||||
} state;
|
||||
};
|
||||
|
||||
/**
|
||||
* __arm_smccc_smc() - make SMC calls
|
||||
* @a0-a7: arguments passed in registers 0 to 7
|
||||
* @res: result values from registers 0 to 3
|
||||
* @quirk: points to an arm_smccc_quirk, or NULL when no quirks are required.
|
||||
*
|
||||
* This function is used to make SMC calls following SMC Calling Convention.
|
||||
* The content of the supplied param are copied to registers 0 to 7 prior
|
||||
* to the SMC instruction. The return values are updated with the content
|
||||
* from register 0 to 3 on return from the SMC instruction. An optional
|
||||
* quirk structure provides vendor specific behavior.
|
||||
*/
|
||||
asmlinkage void __arm_smccc_smc(unsigned long a0, unsigned long a1,
|
||||
unsigned long a2, unsigned long a3, unsigned long a4,
|
||||
unsigned long a5, unsigned long a6, unsigned long a7,
|
||||
struct arm_smccc_res *res, struct arm_smccc_quirk *quirk);
|
||||
|
||||
/**
|
||||
* __arm_smccc_hvc() - make HVC calls
|
||||
* @a0-a7: arguments passed in registers 0 to 7
|
||||
* @res: result values from registers 0 to 3
|
||||
* @quirk: points to an arm_smccc_quirk, or NULL when no quirks are required.
|
||||
*
|
||||
* This function is used to make HVC calls following SMC Calling
|
||||
* Convention. The content of the supplied param are copied to registers 0
|
||||
* to 7 prior to the HVC instruction. The return values are updated with
|
||||
* the content from register 0 to 3 on return from the HVC instruction. An
|
||||
* optional quirk structure provides vendor specific behavior.
|
||||
*/
|
||||
asmlinkage void __arm_smccc_hvc(unsigned long a0, unsigned long a1,
|
||||
unsigned long a2, unsigned long a3, unsigned long a4,
|
||||
unsigned long a5, unsigned long a6, unsigned long a7,
|
||||
struct arm_smccc_res *res, struct arm_smccc_quirk *quirk);
|
||||
|
||||
#define arm_smccc_smc(...) __arm_smccc_smc(__VA_ARGS__, NULL)
|
||||
|
||||
#define arm_smccc_smc_quirk(...) __arm_smccc_smc(__VA_ARGS__)
|
||||
|
||||
#define arm_smccc_hvc(...) __arm_smccc_hvc(__VA_ARGS__, NULL)
|
||||
|
||||
#define arm_smccc_hvc_quirk(...) __arm_smccc_hvc(__VA_ARGS__)
|
||||
|
||||
#endif /*__ASSEMBLY__*/
|
||||
#endif /*__LINUX_ARM_SMCCC_H*/
|
||||
@@ -0,0 +1,65 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/* ASN.1 BER/DER/CER encoding definitions
|
||||
*
|
||||
* Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
|
||||
* Written by David Howells (dhowells@redhat.com)
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_ASN1_H
|
||||
#define _LINUX_ASN1_H
|
||||
|
||||
/* Class */
|
||||
enum asn1_class {
|
||||
ASN1_UNIV = 0, /* Universal */
|
||||
ASN1_APPL = 1, /* Application */
|
||||
ASN1_CONT = 2, /* Context */
|
||||
ASN1_PRIV = 3 /* Private */
|
||||
};
|
||||
#define ASN1_CLASS_BITS 0xc0
|
||||
|
||||
|
||||
enum asn1_method {
|
||||
ASN1_PRIM = 0, /* Primitive */
|
||||
ASN1_CONS = 1 /* Constructed */
|
||||
};
|
||||
#define ASN1_CONS_BIT 0x20
|
||||
|
||||
/* Tag */
|
||||
enum asn1_tag {
|
||||
ASN1_EOC = 0, /* End Of Contents or N/A */
|
||||
ASN1_BOOL = 1, /* Boolean */
|
||||
ASN1_INT = 2, /* Integer */
|
||||
ASN1_BTS = 3, /* Bit String */
|
||||
ASN1_OTS = 4, /* Octet String */
|
||||
ASN1_NULL = 5, /* Null */
|
||||
ASN1_OID = 6, /* Object Identifier */
|
||||
ASN1_ODE = 7, /* Object Description */
|
||||
ASN1_EXT = 8, /* External */
|
||||
ASN1_REAL = 9, /* Real float */
|
||||
ASN1_ENUM = 10, /* Enumerated */
|
||||
ASN1_EPDV = 11, /* Embedded PDV */
|
||||
ASN1_UTF8STR = 12, /* UTF8 String */
|
||||
ASN1_RELOID = 13, /* Relative OID */
|
||||
/* 14 - Reserved */
|
||||
/* 15 - Reserved */
|
||||
ASN1_SEQ = 16, /* Sequence and Sequence of */
|
||||
ASN1_SET = 17, /* Set and Set of */
|
||||
ASN1_NUMSTR = 18, /* Numerical String */
|
||||
ASN1_PRNSTR = 19, /* Printable String */
|
||||
ASN1_TEXSTR = 20, /* T61 String / Teletext String */
|
||||
ASN1_VIDSTR = 21, /* Videotex String */
|
||||
ASN1_IA5STR = 22, /* IA5 String */
|
||||
ASN1_UNITIM = 23, /* Universal Time */
|
||||
ASN1_GENTIM = 24, /* General Time */
|
||||
ASN1_GRASTR = 25, /* Graphic String */
|
||||
ASN1_VISSTR = 26, /* Visible String */
|
||||
ASN1_GENSTR = 27, /* General String */
|
||||
ASN1_UNISTR = 28, /* Universal String */
|
||||
ASN1_CHRSTR = 29, /* Character String */
|
||||
ASN1_BMPSTR = 30, /* BMP String */
|
||||
ASN1_LONG_TAG = 31 /* Long form tag */
|
||||
};
|
||||
|
||||
#define ASN1_INDEFINITE_LENGTH 0x80
|
||||
|
||||
#endif /* _LINUX_ASN1_H */
|
||||
@@ -0,0 +1,89 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/* ASN.1 BER/DER/CER parsing state machine internal definitions
|
||||
*
|
||||
* Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
|
||||
* Written by David Howells (dhowells@redhat.com)
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_ASN1_BER_BYTECODE_H
|
||||
#define _LINUX_ASN1_BER_BYTECODE_H
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#include <linux/types.h>
|
||||
#endif
|
||||
#include <linux/asn1.h>
|
||||
|
||||
typedef int (*asn1_action_t)(void *context,
|
||||
size_t hdrlen, /* In case of ANY type */
|
||||
unsigned char tag, /* In case of ANY type */
|
||||
const void *value, size_t vlen);
|
||||
|
||||
struct asn1_decoder {
|
||||
const unsigned char *machine;
|
||||
size_t machlen;
|
||||
const asn1_action_t *actions;
|
||||
};
|
||||
|
||||
enum asn1_opcode {
|
||||
/* The tag-matching ops come first and the odd-numbered slots
|
||||
* are for OR_SKIP ops.
|
||||
*/
|
||||
#define ASN1_OP_MATCH__SKIP 0x01
|
||||
#define ASN1_OP_MATCH__ACT 0x02
|
||||
#define ASN1_OP_MATCH__JUMP 0x04
|
||||
#define ASN1_OP_MATCH__ANY 0x08
|
||||
#define ASN1_OP_MATCH__COND 0x10
|
||||
|
||||
ASN1_OP_MATCH = 0x00,
|
||||
ASN1_OP_MATCH_OR_SKIP = 0x01,
|
||||
ASN1_OP_MATCH_ACT = 0x02,
|
||||
ASN1_OP_MATCH_ACT_OR_SKIP = 0x03,
|
||||
ASN1_OP_MATCH_JUMP = 0x04,
|
||||
ASN1_OP_MATCH_JUMP_OR_SKIP = 0x05,
|
||||
ASN1_OP_MATCH_ANY = 0x08,
|
||||
ASN1_OP_MATCH_ANY_OR_SKIP = 0x09,
|
||||
ASN1_OP_MATCH_ANY_ACT = 0x0a,
|
||||
ASN1_OP_MATCH_ANY_ACT_OR_SKIP = 0x0b,
|
||||
/* Everything before here matches unconditionally */
|
||||
|
||||
ASN1_OP_COND_MATCH_OR_SKIP = 0x11,
|
||||
ASN1_OP_COND_MATCH_ACT_OR_SKIP = 0x13,
|
||||
ASN1_OP_COND_MATCH_JUMP_OR_SKIP = 0x15,
|
||||
ASN1_OP_COND_MATCH_ANY = 0x18,
|
||||
ASN1_OP_COND_MATCH_ANY_OR_SKIP = 0x19,
|
||||
ASN1_OP_COND_MATCH_ANY_ACT = 0x1a,
|
||||
ASN1_OP_COND_MATCH_ANY_ACT_OR_SKIP = 0x1b,
|
||||
|
||||
/* Everything before here will want a tag from the data */
|
||||
#define ASN1_OP__MATCHES_TAG ASN1_OP_COND_MATCH_ANY_ACT_OR_SKIP
|
||||
|
||||
/* These are here to help fill up space */
|
||||
ASN1_OP_COND_FAIL = 0x1c,
|
||||
ASN1_OP_COMPLETE = 0x1d,
|
||||
ASN1_OP_ACT = 0x1e,
|
||||
ASN1_OP_MAYBE_ACT = 0x1f,
|
||||
|
||||
/* The following eight have bit 0 -> SET, 1 -> OF, 2 -> ACT */
|
||||
ASN1_OP_END_SEQ = 0x20,
|
||||
ASN1_OP_END_SET = 0x21,
|
||||
ASN1_OP_END_SEQ_OF = 0x22,
|
||||
ASN1_OP_END_SET_OF = 0x23,
|
||||
ASN1_OP_END_SEQ_ACT = 0x24,
|
||||
ASN1_OP_END_SET_ACT = 0x25,
|
||||
ASN1_OP_END_SEQ_OF_ACT = 0x26,
|
||||
ASN1_OP_END_SET_OF_ACT = 0x27,
|
||||
#define ASN1_OP_END__SET 0x01
|
||||
#define ASN1_OP_END__OF 0x02
|
||||
#define ASN1_OP_END__ACT 0x04
|
||||
|
||||
ASN1_OP_RETURN = 0x28,
|
||||
|
||||
ASN1_OP__NR
|
||||
};
|
||||
|
||||
#define _tag(CLASS, CP, TAG) ((ASN1_##CLASS << 6) | (ASN1_##CP << 5) | ASN1_##TAG)
|
||||
#define _tagn(CLASS, CP, TAG) ((ASN1_##CLASS << 6) | (ASN1_##CP << 5) | TAG)
|
||||
#define _jump_target(N) (N)
|
||||
#define _action(N) (N)
|
||||
|
||||
#endif /* _LINUX_ASN1_BER_BYTECODE_H */
|
||||
@@ -0,0 +1,20 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/* ASN.1 decoder
|
||||
*
|
||||
* Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
|
||||
* Written by David Howells (dhowells@redhat.com)
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_ASN1_DECODER_H
|
||||
#define _LINUX_ASN1_DECODER_H
|
||||
|
||||
#include <linux/asn1.h>
|
||||
|
||||
struct asn1_decoder;
|
||||
|
||||
extern int asn1_ber_decoder(const struct asn1_decoder *decoder,
|
||||
void *context,
|
||||
const unsigned char *data,
|
||||
size_t datalen);
|
||||
|
||||
#endif /* _LINUX_ASN1_DECODER_H */
|
||||
@@ -0,0 +1,67 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Generic binary BCH encoding/decoding library
|
||||
*
|
||||
* Copyright © 2011 Parrot S.A.
|
||||
*
|
||||
* Author: Ivan Djelic <ivan.djelic@parrot.com>
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* This library provides runtime configurable encoding/decoding of binary
|
||||
* Bose-Chaudhuri-Hocquenghem (BCH) codes.
|
||||
*/
|
||||
#ifndef _BCH_H
|
||||
#define _BCH_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
/**
|
||||
* struct bch_control - BCH control structure
|
||||
* @m: Galois field order
|
||||
* @n: maximum codeword size in bits (= 2^m-1)
|
||||
* @t: error correction capability in bits
|
||||
* @ecc_bits: ecc exact size in bits, i.e. generator polynomial degree (<=m*t)
|
||||
* @ecc_bytes: ecc max size (m*t bits) in bytes
|
||||
* @a_pow_tab: Galois field GF(2^m) exponentiation lookup table
|
||||
* @a_log_tab: Galois field GF(2^m) log lookup table
|
||||
* @mod8_tab: remainder generator polynomial lookup tables
|
||||
* @ecc_buf: ecc parity words buffer
|
||||
* @ecc_buf2: ecc parity words buffer
|
||||
* @xi_tab: GF(2^m) base for solving degree 2 polynomial roots
|
||||
* @syn: syndrome buffer
|
||||
* @cache: log-based polynomial representation buffer
|
||||
* @elp: error locator polynomial
|
||||
* @poly_2t: temporary polynomials of degree 2t
|
||||
*/
|
||||
struct bch_control {
|
||||
unsigned int m;
|
||||
unsigned int n;
|
||||
unsigned int t;
|
||||
unsigned int ecc_bits;
|
||||
unsigned int ecc_bytes;
|
||||
/* private: */
|
||||
uint16_t *a_pow_tab;
|
||||
uint16_t *a_log_tab;
|
||||
uint32_t *mod8_tab;
|
||||
uint32_t *ecc_buf;
|
||||
uint32_t *ecc_buf2;
|
||||
unsigned int *xi_tab;
|
||||
unsigned int *syn;
|
||||
int *cache;
|
||||
struct gf_poly *elp;
|
||||
struct gf_poly *poly_2t[4];
|
||||
};
|
||||
|
||||
struct bch_control *init_bch(int m, int t, unsigned int prim_poly);
|
||||
|
||||
void free_bch(struct bch_control *bch);
|
||||
|
||||
void encode_bch(struct bch_control *bch, const uint8_t *data,
|
||||
unsigned int len, uint8_t *ecc);
|
||||
|
||||
int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len,
|
||||
const uint8_t *recv_ecc, const uint8_t *calc_ecc,
|
||||
const unsigned int *syn, unsigned int *errloc);
|
||||
|
||||
#endif /* _BCH_H */
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Felix Fietkau <nbd@nbd.name>
|
||||
* Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_BITFIELD_H
|
||||
#define _LINUX_BITFIELD_H
|
||||
|
||||
#include <linux/bug.h>
|
||||
|
||||
/*
|
||||
* Bitfield access macros
|
||||
*
|
||||
* FIELD_{GET,PREP} macros take as first parameter shifted mask
|
||||
* from which they extract the base mask and shift amount.
|
||||
* Mask must be a compilation time constant.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* #define REG_FIELD_A GENMASK(6, 0)
|
||||
* #define REG_FIELD_B BIT(7)
|
||||
* #define REG_FIELD_C GENMASK(15, 8)
|
||||
* #define REG_FIELD_D GENMASK(31, 16)
|
||||
*
|
||||
* Get:
|
||||
* a = FIELD_GET(REG_FIELD_A, reg);
|
||||
* b = FIELD_GET(REG_FIELD_B, reg);
|
||||
*
|
||||
* Set:
|
||||
* reg = FIELD_PREP(REG_FIELD_A, 1) |
|
||||
* FIELD_PREP(REG_FIELD_B, 0) |
|
||||
* FIELD_PREP(REG_FIELD_C, c) |
|
||||
* FIELD_PREP(REG_FIELD_D, 0x40);
|
||||
*
|
||||
* Modify:
|
||||
* reg &= ~REG_FIELD_C;
|
||||
* reg |= FIELD_PREP(REG_FIELD_C, c);
|
||||
*/
|
||||
|
||||
#define __bf_shf(x) (__builtin_ffsll(x) - 1)
|
||||
|
||||
#define __BF_FIELD_CHECK(_mask, _reg, _val, _pfx) \
|
||||
({ \
|
||||
BUILD_BUG_ON_MSG(!__builtin_constant_p(_mask), \
|
||||
_pfx "mask is not constant"); \
|
||||
BUILD_BUG_ON_MSG(!(_mask), _pfx "mask is zero"); \
|
||||
BUILD_BUG_ON_MSG(__builtin_constant_p(_val) ? \
|
||||
~((_mask) >> __bf_shf(_mask)) & (_val) : 0, \
|
||||
_pfx "value too large for the field"); \
|
||||
BUILD_BUG_ON_MSG((_mask) > (typeof(_reg))~0ull, \
|
||||
_pfx "type of reg too small for mask"); \
|
||||
__BUILD_BUG_ON_NOT_POWER_OF_2((_mask) + \
|
||||
(1ULL << __bf_shf(_mask))); \
|
||||
})
|
||||
|
||||
/**
|
||||
* FIELD_FIT() - check if value fits in the field
|
||||
* @_mask: shifted mask defining the field's length and position
|
||||
* @_val: value to test against the field
|
||||
*
|
||||
* Return: true if @_val can fit inside @_mask, false if @_val is too big.
|
||||
*/
|
||||
#define FIELD_FIT(_mask, _val) \
|
||||
({ \
|
||||
__BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_FIT: "); \
|
||||
!((((typeof(_mask))_val) << __bf_shf(_mask)) & ~(_mask)); \
|
||||
})
|
||||
|
||||
/**
|
||||
* FIELD_PREP() - prepare a bitfield element
|
||||
* @_mask: shifted mask defining the field's length and position
|
||||
* @_val: value to put in the field
|
||||
*
|
||||
* FIELD_PREP() masks and shifts up the value. The result should
|
||||
* be combined with other fields of the bitfield using logical OR.
|
||||
*/
|
||||
#define FIELD_PREP(_mask, _val) \
|
||||
({ \
|
||||
__BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_PREP: "); \
|
||||
((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask); \
|
||||
})
|
||||
|
||||
/**
|
||||
* FIELD_GET() - extract a bitfield element
|
||||
* @_mask: shifted mask defining the field's length and position
|
||||
* @_reg: 32bit value of entire bitfield
|
||||
*
|
||||
* FIELD_GET() extracts the field specified by @_mask from the
|
||||
* bitfield passed in as @_reg by masking and shifting it down.
|
||||
*/
|
||||
#define FIELD_GET(_mask, _reg) \
|
||||
({ \
|
||||
__BF_FIELD_CHECK(_mask, _reg, 0U, "FIELD_GET: "); \
|
||||
(typeof(_mask))(((_reg) & (_mask)) >> __bf_shf(_mask)); \
|
||||
})
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,84 @@
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
#ifndef __LINUX_BITMAP_H
|
||||
#define __LINUX_BITMAP_H
|
||||
|
||||
#include <asm/types.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/bitops.h>
|
||||
|
||||
#define small_const_nbits(nbits) \
|
||||
(__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG)
|
||||
|
||||
static inline void bitmap_zero(unsigned long *dst, int nbits)
|
||||
{
|
||||
if (small_const_nbits(nbits)) {
|
||||
*dst = 0UL;
|
||||
} else {
|
||||
int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
|
||||
|
||||
memset(dst, 0, len);
|
||||
}
|
||||
}
|
||||
|
||||
static inline unsigned long
|
||||
find_next_bit(const unsigned long *addr, unsigned long size,
|
||||
unsigned long offset)
|
||||
{
|
||||
const unsigned long *p = addr + BIT_WORD(offset);
|
||||
unsigned long result = offset & ~(BITS_PER_LONG - 1);
|
||||
unsigned long tmp;
|
||||
|
||||
if (offset >= size)
|
||||
return size;
|
||||
size -= result;
|
||||
offset %= BITS_PER_LONG;
|
||||
if (offset) {
|
||||
tmp = *(p++);
|
||||
tmp &= (~0UL << offset);
|
||||
if (size < BITS_PER_LONG)
|
||||
goto found_first;
|
||||
if (tmp)
|
||||
goto found_middle;
|
||||
size -= BITS_PER_LONG;
|
||||
result += BITS_PER_LONG;
|
||||
}
|
||||
while (size & ~(BITS_PER_LONG - 1)) {
|
||||
tmp = *(p++);
|
||||
if ((tmp))
|
||||
goto found_middle;
|
||||
result += BITS_PER_LONG;
|
||||
size -= BITS_PER_LONG;
|
||||
}
|
||||
if (!size)
|
||||
return result;
|
||||
tmp = *p;
|
||||
|
||||
found_first:
|
||||
tmp &= (~0UL >> (BITS_PER_LONG - size));
|
||||
if (tmp == 0UL) /* Are any bits set? */
|
||||
return result + size; /* Nope. */
|
||||
found_middle:
|
||||
return result + __ffs(tmp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the first set bit in a memory region.
|
||||
*/
|
||||
static inline unsigned long find_first_bit(const unsigned long *addr, unsigned long size)
|
||||
{
|
||||
unsigned long idx;
|
||||
|
||||
for (idx = 0; idx * BITS_PER_LONG < size; idx++) {
|
||||
if (addr[idx])
|
||||
return min(idx * BITS_PER_LONG + __ffs(addr[idx]), size);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
#define for_each_set_bit(bit, addr, size) \
|
||||
for ((bit) = find_first_bit((addr), (size)); \
|
||||
(bit) < (size); \
|
||||
(bit) = find_next_bit((addr), (size), (bit) + 1))
|
||||
|
||||
#endif /* __LINUX_BITMAP_H */
|
||||
@@ -0,0 +1,207 @@
|
||||
#ifndef _LINUX_BITOPS_H
|
||||
#define _LINUX_BITOPS_H
|
||||
|
||||
#include <asm/types.h>
|
||||
#include <asm-generic/bitsperlong.h>
|
||||
#include <linux/compiler.h>
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#define BIT(nr) (1UL << (nr))
|
||||
#define BIT_ULL(nr) (1ULL << (nr))
|
||||
#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
|
||||
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
|
||||
#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
|
||||
#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
|
||||
#define BITS_PER_BYTE 8
|
||||
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Create a contiguous bitmask starting at bit position @l and ending at
|
||||
* position @h. For example
|
||||
* GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
|
||||
*/
|
||||
#ifdef CONFIG_SANDBOX
|
||||
#define GENMASK(h, l) \
|
||||
(((~0UL) << (l)) & (~0UL >> (CONFIG_SANDBOX_BITS_PER_LONG - 1 - (h))))
|
||||
#else
|
||||
#define GENMASK(h, l) \
|
||||
(((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
|
||||
#endif
|
||||
|
||||
#define GENMASK_ULL(h, l) \
|
||||
(((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
|
||||
|
||||
/*
|
||||
* ffs: find first bit set. This is defined the same way as
|
||||
* the libc and compiler builtin ffs routines, therefore
|
||||
* differs in spirit from the above ffz (man ffs).
|
||||
*/
|
||||
|
||||
static inline int generic_ffs(int x)
|
||||
{
|
||||
int r = 1;
|
||||
|
||||
if (!x)
|
||||
return 0;
|
||||
if (!(x & 0xffff)) {
|
||||
x >>= 16;
|
||||
r += 16;
|
||||
}
|
||||
if (!(x & 0xff)) {
|
||||
x >>= 8;
|
||||
r += 8;
|
||||
}
|
||||
if (!(x & 0xf)) {
|
||||
x >>= 4;
|
||||
r += 4;
|
||||
}
|
||||
if (!(x & 3)) {
|
||||
x >>= 2;
|
||||
r += 2;
|
||||
}
|
||||
if (!(x & 1)) {
|
||||
x >>= 1;
|
||||
r += 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* fls - find last (most-significant) bit set
|
||||
* @x: the word to search
|
||||
*
|
||||
* This is defined the same way as ffs.
|
||||
* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
|
||||
*/
|
||||
static inline int generic_fls(int x)
|
||||
{
|
||||
int r = 32;
|
||||
|
||||
if (!x)
|
||||
return 0;
|
||||
if (!(x & 0xffff0000u)) {
|
||||
x <<= 16;
|
||||
r -= 16;
|
||||
}
|
||||
if (!(x & 0xff000000u)) {
|
||||
x <<= 8;
|
||||
r -= 8;
|
||||
}
|
||||
if (!(x & 0xf0000000u)) {
|
||||
x <<= 4;
|
||||
r -= 4;
|
||||
}
|
||||
if (!(x & 0xc0000000u)) {
|
||||
x <<= 2;
|
||||
r -= 2;
|
||||
}
|
||||
if (!(x & 0x80000000u)) {
|
||||
x <<= 1;
|
||||
r -= 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* hweightN: returns the hamming weight (i.e. the number
|
||||
* of bits set) of a N-bit word
|
||||
*/
|
||||
|
||||
static inline unsigned int generic_hweight32(unsigned int w)
|
||||
{
|
||||
unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
|
||||
res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
|
||||
res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
|
||||
res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
|
||||
return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
|
||||
}
|
||||
|
||||
static inline unsigned int generic_hweight16(unsigned int w)
|
||||
{
|
||||
unsigned int res = (w & 0x5555) + ((w >> 1) & 0x5555);
|
||||
res = (res & 0x3333) + ((res >> 2) & 0x3333);
|
||||
res = (res & 0x0F0F) + ((res >> 4) & 0x0F0F);
|
||||
return (res & 0x00FF) + ((res >> 8) & 0x00FF);
|
||||
}
|
||||
|
||||
static inline unsigned int generic_hweight8(unsigned int w)
|
||||
{
|
||||
unsigned int res = (w & 0x55) + ((w >> 1) & 0x55);
|
||||
res = (res & 0x33) + ((res >> 2) & 0x33);
|
||||
return (res & 0x0F) + ((res >> 4) & 0x0F);
|
||||
}
|
||||
|
||||
#include <asm/bitops.h>
|
||||
|
||||
/* linux/include/asm-generic/bitops/non-atomic.h */
|
||||
|
||||
#ifndef PLATFORM__SET_BIT
|
||||
# define __set_bit generic_set_bit
|
||||
#endif
|
||||
|
||||
#ifndef PLATFORM__CLEAR_BIT
|
||||
# define __clear_bit generic_clear_bit
|
||||
#endif
|
||||
|
||||
#ifndef PLATFORM_FFS
|
||||
# define ffs generic_ffs
|
||||
#endif
|
||||
|
||||
#ifndef PLATFORM_FLS
|
||||
# define fls generic_fls
|
||||
#endif
|
||||
|
||||
static inline unsigned fls_long(unsigned long l)
|
||||
{
|
||||
if (sizeof(l) == 4)
|
||||
return fls(l);
|
||||
return fls64(l);
|
||||
}
|
||||
|
||||
/**
|
||||
* __ffs64 - find first set bit in a 64 bit word
|
||||
* @word: The 64 bit word
|
||||
*
|
||||
* On 64 bit arches this is a synomyn for __ffs
|
||||
* The result is not defined if no bits are set, so check that @word
|
||||
* is non-zero before calling this.
|
||||
*/
|
||||
static inline unsigned long __ffs64(u64 word)
|
||||
{
|
||||
#if BITS_PER_LONG == 32
|
||||
if (((u32)word) == 0UL)
|
||||
return __ffs((u32)(word >> 32)) + 32;
|
||||
#elif BITS_PER_LONG != 64
|
||||
#error BITS_PER_LONG not 32 or 64
|
||||
#endif
|
||||
return __ffs((unsigned long)word);
|
||||
}
|
||||
|
||||
/**
|
||||
* __set_bit - Set a bit in memory
|
||||
* @nr: the bit to set
|
||||
* @addr: the address to start counting from
|
||||
*
|
||||
* Unlike set_bit(), this function is non-atomic and may be reordered.
|
||||
* If it's called on the same region of memory simultaneously, the effect
|
||||
* may be that only one operation succeeds.
|
||||
*/
|
||||
static inline void generic_set_bit(int nr, volatile unsigned long *addr)
|
||||
{
|
||||
unsigned long mask = BIT_MASK(nr);
|
||||
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
||||
|
||||
*p |= mask;
|
||||
}
|
||||
|
||||
static inline void generic_clear_bit(int nr, volatile unsigned long *addr)
|
||||
{
|
||||
unsigned long mask = BIT_MASK(nr);
|
||||
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
|
||||
|
||||
*p &= ~mask;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,105 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef _LINUX_BITREV_H
|
||||
#define _LINUX_BITREV_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
#ifdef CONFIG_HAVE_ARCH_BITREVERSE
|
||||
#include <asm/bitrev.h>
|
||||
|
||||
#define __bitrev32 __arch_bitrev32
|
||||
#define __bitrev16 __arch_bitrev16
|
||||
#define __bitrev8 __arch_bitrev8
|
||||
|
||||
#else
|
||||
extern u8 const byte_rev_table[256];
|
||||
static inline u8 __bitrev8(u8 byte)
|
||||
{
|
||||
return byte_rev_table[byte];
|
||||
}
|
||||
|
||||
static inline u16 __bitrev16(u16 x)
|
||||
{
|
||||
return (__bitrev8(x & 0xff) << 8) | __bitrev8(x >> 8);
|
||||
}
|
||||
|
||||
static inline u32 __bitrev32(u32 x)
|
||||
{
|
||||
return (__bitrev16(x & 0xffff) << 16) | __bitrev16(x >> 16);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_HAVE_ARCH_BITREVERSE */
|
||||
|
||||
#define __bitrev8x4(x) (__bitrev32(swab32(x)))
|
||||
|
||||
#define __constant_bitrev32(x) \
|
||||
({ \
|
||||
u32 __x = x; \
|
||||
__x = (__x >> 16) | (__x << 16);\
|
||||
__x = ((__x & (u32)0xFF00FF00UL) >> 8) | ((__x & (u32)0x00FF00FFUL) << 8); \
|
||||
__x = ((__x & (u32)0xF0F0F0F0UL) >> 4) | ((__x & (u32)0x0F0F0F0FUL) << 4); \
|
||||
__x = ((__x & (u32)0xCCCCCCCCUL) >> 2) | ((__x & (u32)0x33333333UL) << 2); \
|
||||
__x = ((__x & (u32)0xAAAAAAAAUL) >> 1) | ((__x & (u32)0x55555555UL) << 1); \
|
||||
__x; \
|
||||
})
|
||||
|
||||
#define __constant_bitrev16(x) \
|
||||
({ \
|
||||
u16 __x = x; \
|
||||
__x = (__x >> 8) | (__x << 8); \
|
||||
__x = ((__x & (u16)0xF0F0U) >> 4) | ((__x & (u16)0x0F0FU) << 4); \
|
||||
__x = ((__x & (u16)0xCCCCU) >> 2) | ((__x & (u16)0x3333U) << 2); \
|
||||
__x = ((__x & (u16)0xAAAAU) >> 1) | ((__x & (u16)0x5555U) << 1); \
|
||||
__x; \
|
||||
})
|
||||
|
||||
#define __constant_bitrev8x4(x) \
|
||||
({ \
|
||||
u32 __x = x; \
|
||||
__x = ((__x & (u32)0xF0F0F0F0UL) >> 4) | ((__x & (u32)0x0F0F0F0FUL) << 4); \
|
||||
__x = ((__x & (u32)0xCCCCCCCCUL) >> 2) | ((__x & (u32)0x33333333UL) << 2); \
|
||||
__x = ((__x & (u32)0xAAAAAAAAUL) >> 1) | ((__x & (u32)0x55555555UL) << 1); \
|
||||
__x; \
|
||||
})
|
||||
|
||||
#define __constant_bitrev8(x) \
|
||||
({ \
|
||||
u8 __x = x; \
|
||||
__x = (__x >> 4) | (__x << 4); \
|
||||
__x = ((__x & (u8)0xCCU) >> 2) | ((__x & (u8)0x33U) << 2); \
|
||||
__x = ((__x & (u8)0xAAU) >> 1) | ((__x & (u8)0x55U) << 1); \
|
||||
__x; \
|
||||
})
|
||||
|
||||
#define bitrev32(x) \
|
||||
({ \
|
||||
u32 __x = x; \
|
||||
__builtin_constant_p(__x) ? \
|
||||
__constant_bitrev32(__x) : \
|
||||
__bitrev32(__x); \
|
||||
})
|
||||
|
||||
#define bitrev16(x) \
|
||||
({ \
|
||||
u16 __x = x; \
|
||||
__builtin_constant_p(__x) ? \
|
||||
__constant_bitrev16(__x) : \
|
||||
__bitrev16(__x); \
|
||||
})
|
||||
|
||||
#define bitrev8x4(x) \
|
||||
({ \
|
||||
u32 __x = x; \
|
||||
__builtin_constant_p(__x) ? \
|
||||
__constant_bitrev8x4(__x) : \
|
||||
__bitrev8x4(__x); \
|
||||
})
|
||||
|
||||
#define bitrev8(x) \
|
||||
({ \
|
||||
u8 __x = x; \
|
||||
__builtin_constant_p(__x) ? \
|
||||
__constant_bitrev8(__x) : \
|
||||
__bitrev8(__x) ; \
|
||||
})
|
||||
#endif /* _LINUX_BITREV_H */
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifndef _LINUX_BUG_H
|
||||
#define _LINUX_BUG_H
|
||||
|
||||
#include <vsprintf.h> /* for panic() */
|
||||
#include <linux/build_bug.h>
|
||||
#include <linux/compiler.h>
|
||||
#include <linux/printk.h>
|
||||
|
||||
#define BUG() do { \
|
||||
printk("BUG at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
|
||||
panic("BUG!"); \
|
||||
} while (0)
|
||||
|
||||
#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
|
||||
|
||||
#define WARN_ON(condition) ({ \
|
||||
int __ret_warn_on = !!(condition); \
|
||||
if (unlikely(__ret_warn_on)) \
|
||||
printk("WARNING at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
|
||||
unlikely(__ret_warn_on); \
|
||||
})
|
||||
|
||||
#define WARN(condition, format...) ({ \
|
||||
int __ret_warn_on = !!(condition); \
|
||||
if (unlikely(__ret_warn_on)) \
|
||||
printf(format); \
|
||||
unlikely(__ret_warn_on); \
|
||||
})
|
||||
|
||||
#define WARN_ON_ONCE(condition) ({ \
|
||||
static bool __warned; \
|
||||
int __ret_warn_once = !!(condition); \
|
||||
\
|
||||
if (unlikely(__ret_warn_once && !__warned)) { \
|
||||
__warned = true; \
|
||||
WARN_ON(1); \
|
||||
} \
|
||||
unlikely(__ret_warn_once); \
|
||||
})
|
||||
|
||||
#define WARN_ONCE(condition, format...) ({ \
|
||||
static bool __warned; \
|
||||
int __ret_warn_once = !!(condition); \
|
||||
\
|
||||
if (unlikely(__ret_warn_once && !__warned)) { \
|
||||
__warned = true; \
|
||||
WARN(1, format); \
|
||||
} \
|
||||
unlikely(__ret_warn_once); \
|
||||
})
|
||||
|
||||
#endif /* _LINUX_BUG_H */
|
||||
@@ -0,0 +1,84 @@
|
||||
#ifndef _LINUX_BUILD_BUG_H
|
||||
#define _LINUX_BUILD_BUG_H
|
||||
|
||||
#include <linux/compiler.h>
|
||||
|
||||
#ifdef __CHECKER__
|
||||
#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)
|
||||
#define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0)
|
||||
#define BUILD_BUG_ON_ZERO(e) (0)
|
||||
#define BUILD_BUG_ON_NULL(e) ((void *)0)
|
||||
#define BUILD_BUG_ON_INVALID(e) (0)
|
||||
#define BUILD_BUG_ON_MSG(cond, msg) (0)
|
||||
#define BUILD_BUG_ON(condition) (0)
|
||||
#define BUILD_BUG() (0)
|
||||
#else /* __CHECKER__ */
|
||||
|
||||
/* Force a compilation error if a constant expression is not a power of 2 */
|
||||
#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) \
|
||||
BUILD_BUG_ON(((n) & ((n) - 1)) != 0)
|
||||
#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
|
||||
BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
|
||||
|
||||
/*
|
||||
* Force a compilation error if condition is true, but also produce a
|
||||
* result (of value 0 and type size_t), so the expression can be used
|
||||
* e.g. in a structure initializer (or where-ever else comma expressions
|
||||
* aren't permitted).
|
||||
*/
|
||||
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); }))
|
||||
#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:(-!!(e)); }))
|
||||
|
||||
/*
|
||||
* BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the
|
||||
* expression but avoids the generation of any code, even if that expression
|
||||
* has side-effects.
|
||||
*/
|
||||
#define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e))))
|
||||
|
||||
/**
|
||||
* BUILD_BUG_ON_MSG - break compile if a condition is true & emit supplied
|
||||
* error message.
|
||||
* @condition: the condition which the compiler should know is false.
|
||||
*
|
||||
* See BUILD_BUG_ON for description.
|
||||
*/
|
||||
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
|
||||
|
||||
/**
|
||||
* BUILD_BUG_ON - break compile if a condition is true.
|
||||
* @condition: the condition which the compiler should know is false.
|
||||
*
|
||||
* If you have some code which relies on certain constants being equal, or
|
||||
* some other compile-time-evaluated condition, you should use BUILD_BUG_ON to
|
||||
* detect if someone changes it.
|
||||
*
|
||||
* The implementation uses gcc's reluctance to create a negative array, but gcc
|
||||
* (as of 4.4) only emits that error for obvious cases (e.g. not arguments to
|
||||
* inline functions). Luckily, in 4.3 they added the "error" function
|
||||
* attribute just for this type of case. Thus, we use a negative sized array
|
||||
* (should always create an error on gcc versions older than 4.4) and then call
|
||||
* an undefined function with the error attribute (should always create an
|
||||
* error on gcc 4.3 and later). If for some reason, neither creates a
|
||||
* compile-time error, we'll still have a link-time error, which is harder to
|
||||
* track down.
|
||||
*/
|
||||
#ifndef __OPTIMIZE__
|
||||
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
|
||||
#else
|
||||
#define BUILD_BUG_ON(condition) \
|
||||
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* BUILD_BUG - break compile if used.
|
||||
*
|
||||
* If you have some code that you expect the compiler to eliminate at
|
||||
* build time, you should use BUILD_BUG to detect if it is
|
||||
* unexpectedly used.
|
||||
*/
|
||||
#define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
|
||||
|
||||
#endif /* __CHECKER__ */
|
||||
|
||||
#endif /* _LINUX_BUILD_BUG_H */
|
||||
@@ -0,0 +1,110 @@
|
||||
#ifndef _LINUX_BYTEORDER_BIG_ENDIAN_H
|
||||
#define _LINUX_BYTEORDER_BIG_ENDIAN_H
|
||||
|
||||
#ifndef __BIG_ENDIAN
|
||||
#define __BIG_ENDIAN 4321
|
||||
#endif
|
||||
#ifndef __BIG_ENDIAN_BITFIELD
|
||||
#define __BIG_ENDIAN_BITFIELD
|
||||
#endif
|
||||
#define __BYTE_ORDER __BIG_ENDIAN
|
||||
|
||||
#include <linux/compiler.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/byteorder/swab.h>
|
||||
|
||||
#define __constant_htonl(x) ((__force __be32)(__u32)(x))
|
||||
#define __constant_ntohl(x) ((__force __u32)(__be32)(x))
|
||||
#define __constant_htons(x) ((__force __be16)(__u16)(x))
|
||||
#define __constant_ntohs(x) ((__force __u16)(__be16)(x))
|
||||
#define __constant_cpu_to_le64(x) ((__force __le64)___constant_swab64((x)))
|
||||
#define __constant_le64_to_cpu(x) ___constant_swab64((__force __u64)(__le64)(x))
|
||||
#define __constant_cpu_to_le32(x) ((__force __le32)___constant_swab32((x)))
|
||||
#define __constant_le32_to_cpu(x) ___constant_swab32((__force __u32)(__le32)(x))
|
||||
#define __constant_cpu_to_le16(x) ((__force __le16)___constant_swab16((x)))
|
||||
#define __constant_le16_to_cpu(x) ___constant_swab16((__force __u16)(__le16)(x))
|
||||
#define __constant_cpu_to_be64(x) ((__force __be64)(__u64)(x))
|
||||
#define __constant_be64_to_cpu(x) ((__force __u64)(__be64)(x))
|
||||
#define __constant_cpu_to_be32(x) ((__force __be32)(__u32)(x))
|
||||
#define __constant_be32_to_cpu(x) ((__force __u32)(__be32)(x))
|
||||
#define __constant_cpu_to_be16(x) ((__force __be16)(__u16)(x))
|
||||
#define __constant_be16_to_cpu(x) ((__force __u16)(__be16)(x))
|
||||
#define __cpu_to_le64(x) ((__force __le64)__swab64((x)))
|
||||
#define __le64_to_cpu(x) __swab64((__force __u64)(__le64)(x))
|
||||
#define __cpu_to_le32(x) ((__force __le32)__swab32((x)))
|
||||
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
|
||||
#define __cpu_to_le16(x) ((__force __le16)__swab16((x)))
|
||||
#define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
|
||||
#define __cpu_to_be64(x) ((__force __be64)(__u64)(x))
|
||||
#define __be64_to_cpu(x) ((__force __u64)(__be64)(x))
|
||||
#define __cpu_to_be32(x) ((__force __be32)(__u32)(x))
|
||||
#define __be32_to_cpu(x) ((__force __u32)(__be32)(x))
|
||||
#define __cpu_to_be16(x) ((__force __be16)(__u16)(x))
|
||||
#define __be16_to_cpu(x) ((__force __u16)(__be16)(x))
|
||||
|
||||
static inline __le64 __cpu_to_le64p(const __u64 *p)
|
||||
{
|
||||
return (__force __le64)__swab64p(p);
|
||||
}
|
||||
static inline __u64 __le64_to_cpup(const __le64 *p)
|
||||
{
|
||||
return __swab64p((__u64 *)p);
|
||||
}
|
||||
static inline __le32 __cpu_to_le32p(const __u32 *p)
|
||||
{
|
||||
return (__force __le32)__swab32p(p);
|
||||
}
|
||||
static inline __u32 __le32_to_cpup(const __le32 *p)
|
||||
{
|
||||
return __swab32p((__u32 *)p);
|
||||
}
|
||||
static inline __le16 __cpu_to_le16p(const __u16 *p)
|
||||
{
|
||||
return (__force __le16)__swab16p(p);
|
||||
}
|
||||
static inline __u16 __le16_to_cpup(const __le16 *p)
|
||||
{
|
||||
return __swab16p((__u16 *)p);
|
||||
}
|
||||
static inline __be64 __cpu_to_be64p(const __u64 *p)
|
||||
{
|
||||
return (__force __be64)*p;
|
||||
}
|
||||
static inline __u64 __be64_to_cpup(const __be64 *p)
|
||||
{
|
||||
return (__force __u64)*p;
|
||||
}
|
||||
static inline __be32 __cpu_to_be32p(const __u32 *p)
|
||||
{
|
||||
return (__force __be32)*p;
|
||||
}
|
||||
static inline __u32 __be32_to_cpup(const __be32 *p)
|
||||
{
|
||||
return (__force __u32)*p;
|
||||
}
|
||||
static inline __be16 __cpu_to_be16p(const __u16 *p)
|
||||
{
|
||||
return (__force __be16)*p;
|
||||
}
|
||||
static inline __u16 __be16_to_cpup(const __be16 *p)
|
||||
{
|
||||
return (__force __u16)*p;
|
||||
}
|
||||
#define __cpu_to_le64s(x) __swab64s((x))
|
||||
#define __le64_to_cpus(x) __swab64s((x))
|
||||
#define __cpu_to_le32s(x) __swab32s((x))
|
||||
#define __le32_to_cpus(x) __swab32s((x))
|
||||
#define __cpu_to_le16s(x) __swab16s((x))
|
||||
#define __le16_to_cpus(x) __swab16s((x))
|
||||
#define __cpu_to_be64s(x) do { (void)(x); } while (0)
|
||||
#define __be64_to_cpus(x) do { (void)(x); } while (0)
|
||||
#define __cpu_to_be32s(x) do { (void)(x); } while (0)
|
||||
#define __be32_to_cpus(x) do { (void)(x); } while (0)
|
||||
#define __cpu_to_be16s(x) do { (void)(x); } while (0)
|
||||
#define __be16_to_cpus(x) do { (void)(x); } while (0)
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#include <linux/byteorder/generic.h>
|
||||
#endif
|
||||
|
||||
#endif /* _LINUX_BYTEORDER_BIG_ENDIAN_H */
|
||||
@@ -0,0 +1,207 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef _LINUX_BYTEORDER_GENERIC_H
|
||||
#define _LINUX_BYTEORDER_GENERIC_H
|
||||
|
||||
/*
|
||||
* linux/byteorder/generic.h
|
||||
* Generic Byte-reordering support
|
||||
*
|
||||
* The "... p" macros, like le64_to_cpup, can be used with pointers
|
||||
* to unaligned data, but there will be a performance penalty on
|
||||
* some architectures. Use get_unaligned for unaligned data.
|
||||
*
|
||||
* Francois-Rene Rideau <fare@tunes.org> 19970707
|
||||
* gathered all the good ideas from all asm-foo/byteorder.h into one file,
|
||||
* cleaned them up.
|
||||
* I hope it is compliant with non-GCC compilers.
|
||||
* I decided to put __BYTEORDER_HAS_U64__ in byteorder.h,
|
||||
* because I wasn't sure it would be ok to put it in types.h
|
||||
* Upgraded it to 2.1.43
|
||||
* Francois-Rene Rideau <fare@tunes.org> 19971012
|
||||
* Upgraded it to 2.1.57
|
||||
* to please Linus T., replaced huge #ifdef's between little/big endian
|
||||
* by nestedly #include'd files.
|
||||
* Francois-Rene Rideau <fare@tunes.org> 19971205
|
||||
* Made it to 2.1.71; now a facelift:
|
||||
* Put files under include/linux/byteorder/
|
||||
* Split swab from generic support.
|
||||
*
|
||||
* TODO:
|
||||
* = Regular kernel maintainers could also replace all these manual
|
||||
* byteswap macros that remain, disseminated among drivers,
|
||||
* after some grep or the sources...
|
||||
* = Linus might want to rename all these macros and files to fit his taste,
|
||||
* to fit his personal naming scheme.
|
||||
* = it seems that a few drivers would also appreciate
|
||||
* nybble swapping support...
|
||||
* = every architecture could add their byteswap macro in asm/byteorder.h
|
||||
* see how some architectures already do (i386, alpha, ppc, etc)
|
||||
* = cpu_to_beXX and beXX_to_cpu might some day need to be well
|
||||
* distinguished throughout the kernel. This is not the case currently,
|
||||
* since little endian, big endian, and pdp endian machines needn't it.
|
||||
* But this might be the case for, say, a port of Linux to 20/21 bit
|
||||
* architectures (and F21 Linux addict around?).
|
||||
*/
|
||||
|
||||
/*
|
||||
* The following macros are to be defined by <asm/byteorder.h>:
|
||||
*
|
||||
* Conversion of long and short int between network and host format
|
||||
* ntohl(__u32 x)
|
||||
* ntohs(__u16 x)
|
||||
* htonl(__u32 x)
|
||||
* htons(__u16 x)
|
||||
* It seems that some programs (which? where? or perhaps a standard? POSIX?)
|
||||
* might like the above to be functions, not macros (why?).
|
||||
* if that's true, then detect them, and take measures.
|
||||
* Anyway, the measure is: define only ___ntohl as a macro instead,
|
||||
* and in a separate file, have
|
||||
* unsigned long inline ntohl(x){return ___ntohl(x);}
|
||||
*
|
||||
* The same for constant arguments
|
||||
* __constant_ntohl(__u32 x)
|
||||
* __constant_ntohs(__u16 x)
|
||||
* __constant_htonl(__u32 x)
|
||||
* __constant_htons(__u16 x)
|
||||
*
|
||||
* Conversion of XX-bit integers (16- 32- or 64-)
|
||||
* between native CPU format and little/big endian format
|
||||
* 64-bit stuff only defined for proper architectures
|
||||
* cpu_to_[bl]eXX(__uXX x)
|
||||
* [bl]eXX_to_cpu(__uXX x)
|
||||
*
|
||||
* The same, but takes a pointer to the value to convert
|
||||
* cpu_to_[bl]eXXp(__uXX x)
|
||||
* [bl]eXX_to_cpup(__uXX x)
|
||||
*
|
||||
* The same, but change in situ
|
||||
* cpu_to_[bl]eXXs(__uXX x)
|
||||
* [bl]eXX_to_cpus(__uXX x)
|
||||
*
|
||||
* See asm-foo/byteorder.h for examples of how to provide
|
||||
* architecture-optimized versions
|
||||
*
|
||||
*/
|
||||
|
||||
#define cpu_to_le64 __cpu_to_le64
|
||||
#define le64_to_cpu __le64_to_cpu
|
||||
#define cpu_to_le32 __cpu_to_le32
|
||||
#define le32_to_cpu __le32_to_cpu
|
||||
#define cpu_to_le16 __cpu_to_le16
|
||||
#define le16_to_cpu __le16_to_cpu
|
||||
#define cpu_to_be64 __cpu_to_be64
|
||||
#define be64_to_cpu __be64_to_cpu
|
||||
#define cpu_to_be32 __cpu_to_be32
|
||||
#define be32_to_cpu __be32_to_cpu
|
||||
#define cpu_to_be16 __cpu_to_be16
|
||||
#define be16_to_cpu __be16_to_cpu
|
||||
#define cpu_to_le64p __cpu_to_le64p
|
||||
#define le64_to_cpup __le64_to_cpup
|
||||
#define cpu_to_le32p __cpu_to_le32p
|
||||
#define le32_to_cpup __le32_to_cpup
|
||||
#define cpu_to_le16p __cpu_to_le16p
|
||||
#define le16_to_cpup __le16_to_cpup
|
||||
#define cpu_to_be64p __cpu_to_be64p
|
||||
#define be64_to_cpup __be64_to_cpup
|
||||
#define cpu_to_be32p __cpu_to_be32p
|
||||
#define be32_to_cpup __be32_to_cpup
|
||||
#define cpu_to_be16p __cpu_to_be16p
|
||||
#define be16_to_cpup __be16_to_cpup
|
||||
#define cpu_to_le64s __cpu_to_le64s
|
||||
#define le64_to_cpus __le64_to_cpus
|
||||
#define cpu_to_le32s __cpu_to_le32s
|
||||
#define le32_to_cpus __le32_to_cpus
|
||||
#define cpu_to_le16s __cpu_to_le16s
|
||||
#define le16_to_cpus __le16_to_cpus
|
||||
#define cpu_to_be64s __cpu_to_be64s
|
||||
#define be64_to_cpus __be64_to_cpus
|
||||
#define cpu_to_be32s __cpu_to_be32s
|
||||
#define be32_to_cpus __be32_to_cpus
|
||||
#define cpu_to_be16s __cpu_to_be16s
|
||||
#define be16_to_cpus __be16_to_cpus
|
||||
|
||||
/*
|
||||
* They have to be macros in order to do the constant folding
|
||||
* correctly - if the argument passed into a inline function
|
||||
* it is no longer constant according to gcc..
|
||||
*/
|
||||
|
||||
#undef ntohl
|
||||
#undef ntohs
|
||||
#undef htonl
|
||||
#undef htons
|
||||
|
||||
#define ___htonl(x) __cpu_to_be32(x)
|
||||
#define ___htons(x) __cpu_to_be16(x)
|
||||
#define ___ntohl(x) __be32_to_cpu(x)
|
||||
#define ___ntohs(x) __be16_to_cpu(x)
|
||||
|
||||
#define htonl(x) ___htonl(x)
|
||||
#define ntohl(x) ___ntohl(x)
|
||||
#define htons(x) ___htons(x)
|
||||
#define ntohs(x) ___ntohs(x)
|
||||
|
||||
static inline void le16_add_cpu(__le16 *var, u16 val)
|
||||
{
|
||||
*var = cpu_to_le16(le16_to_cpu(*var) + val);
|
||||
}
|
||||
|
||||
static inline void le32_add_cpu(__le32 *var, u32 val)
|
||||
{
|
||||
*var = cpu_to_le32(le32_to_cpu(*var) + val);
|
||||
}
|
||||
|
||||
static inline void le64_add_cpu(__le64 *var, u64 val)
|
||||
{
|
||||
*var = cpu_to_le64(le64_to_cpu(*var) + val);
|
||||
}
|
||||
|
||||
/* XXX: this stuff can be optimized */
|
||||
static inline void le32_to_cpu_array(u32 *buf, unsigned int words)
|
||||
{
|
||||
while (words--) {
|
||||
__le32_to_cpus(buf);
|
||||
buf++;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void cpu_to_le32_array(u32 *buf, unsigned int words)
|
||||
{
|
||||
while (words--) {
|
||||
__cpu_to_le32s(buf);
|
||||
buf++;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void be16_add_cpu(__be16 *var, u16 val)
|
||||
{
|
||||
*var = cpu_to_be16(be16_to_cpu(*var) + val);
|
||||
}
|
||||
|
||||
static inline void be32_add_cpu(__be32 *var, u32 val)
|
||||
{
|
||||
*var = cpu_to_be32(be32_to_cpu(*var) + val);
|
||||
}
|
||||
|
||||
static inline void be64_add_cpu(__be64 *var, u64 val)
|
||||
{
|
||||
*var = cpu_to_be64(be64_to_cpu(*var) + val);
|
||||
}
|
||||
|
||||
static inline void cpu_to_be32_array(__be32 *dst, const u32 *src, size_t len)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
dst[i] = cpu_to_be32(src[i]);
|
||||
}
|
||||
|
||||
static inline void be32_to_cpu_array(u32 *dst, const __be32 *src, size_t len)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
dst[i] = be32_to_cpu(src[i]);
|
||||
}
|
||||
|
||||
#endif /* _LINUX_BYTEORDER_GENERIC_H */
|
||||
@@ -0,0 +1,110 @@
|
||||
#ifndef _LINUX_BYTEORDER_LITTLE_ENDIAN_H
|
||||
#define _LINUX_BYTEORDER_LITTLE_ENDIAN_H
|
||||
|
||||
#ifndef __LITTLE_ENDIAN
|
||||
#define __LITTLE_ENDIAN 1234
|
||||
#endif
|
||||
#ifndef __LITTLE_ENDIAN_BITFIELD
|
||||
#define __LITTLE_ENDIAN_BITFIELD
|
||||
#endif
|
||||
#define __BYTE_ORDER __LITTLE_ENDIAN
|
||||
|
||||
#include <linux/compiler.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/byteorder/swab.h>
|
||||
|
||||
#define __constant_htonl(x) ((__force __be32)___constant_swab32((x)))
|
||||
#define __constant_ntohl(x) ___constant_swab32((__force __be32)(x))
|
||||
#define __constant_htons(x) ((__force __be16)___constant_swab16((x)))
|
||||
#define __constant_ntohs(x) ___constant_swab16((__force __be16)(x))
|
||||
#define __constant_cpu_to_le64(x) ((__force __le64)(__u64)(x))
|
||||
#define __constant_le64_to_cpu(x) ((__force __u64)(__le64)(x))
|
||||
#define __constant_cpu_to_le32(x) ((__force __le32)(__u32)(x))
|
||||
#define __constant_le32_to_cpu(x) ((__force __u32)(__le32)(x))
|
||||
#define __constant_cpu_to_le16(x) ((__force __le16)(__u16)(x))
|
||||
#define __constant_le16_to_cpu(x) ((__force __u16)(__le16)(x))
|
||||
#define __constant_cpu_to_be64(x) ((__force __be64)___constant_swab64((x)))
|
||||
#define __constant_be64_to_cpu(x) ___constant_swab64((__force __u64)(__be64)(x))
|
||||
#define __constant_cpu_to_be32(x) ((__force __be32)___constant_swab32((x)))
|
||||
#define __constant_be32_to_cpu(x) ___constant_swab32((__force __u32)(__be32)(x))
|
||||
#define __constant_cpu_to_be16(x) ((__force __be16)___constant_swab16((x)))
|
||||
#define __constant_be16_to_cpu(x) ___constant_swab16((__force __u16)(__be16)(x))
|
||||
#define __cpu_to_le64(x) ((__force __le64)(__u64)(x))
|
||||
#define __le64_to_cpu(x) ((__force __u64)(__le64)(x))
|
||||
#define __cpu_to_le32(x) ((__force __le32)(__u32)(x))
|
||||
#define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
|
||||
#define __cpu_to_le16(x) ((__force __le16)(__u16)(x))
|
||||
#define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
|
||||
#define __cpu_to_be64(x) ((__force __be64)__swab64((x)))
|
||||
#define __be64_to_cpu(x) __swab64((__force __u64)(__be64)(x))
|
||||
#define __cpu_to_be32(x) ((__force __be32)__swab32((x)))
|
||||
#define __be32_to_cpu(x) __swab32((__force __u32)(__be32)(x))
|
||||
#define __cpu_to_be16(x) ((__force __be16)__swab16((x)))
|
||||
#define __be16_to_cpu(x) __swab16((__force __u16)(__be16)(x))
|
||||
|
||||
static inline __le64 __cpu_to_le64p(const __u64 *p)
|
||||
{
|
||||
return (__force __le64)*p;
|
||||
}
|
||||
static inline __u64 __le64_to_cpup(const __le64 *p)
|
||||
{
|
||||
return (__force __u64)*p;
|
||||
}
|
||||
static inline __le32 __cpu_to_le32p(const __u32 *p)
|
||||
{
|
||||
return (__force __le32)*p;
|
||||
}
|
||||
static inline __u32 __le32_to_cpup(const __le32 *p)
|
||||
{
|
||||
return (__force __u32)*p;
|
||||
}
|
||||
static inline __le16 __cpu_to_le16p(const __u16 *p)
|
||||
{
|
||||
return (__force __le16)*p;
|
||||
}
|
||||
static inline __u16 __le16_to_cpup(const __le16 *p)
|
||||
{
|
||||
return (__force __u16)*p;
|
||||
}
|
||||
static inline __be64 __cpu_to_be64p(const __u64 *p)
|
||||
{
|
||||
return (__force __be64)__swab64p(p);
|
||||
}
|
||||
static inline __u64 __be64_to_cpup(const __be64 *p)
|
||||
{
|
||||
return __swab64p((__u64 *)p);
|
||||
}
|
||||
static inline __be32 __cpu_to_be32p(const __u32 *p)
|
||||
{
|
||||
return (__force __be32)__swab32p(p);
|
||||
}
|
||||
static inline __u32 __be32_to_cpup(const __be32 *p)
|
||||
{
|
||||
return __swab32p((__u32 *)p);
|
||||
}
|
||||
static inline __be16 __cpu_to_be16p(const __u16 *p)
|
||||
{
|
||||
return (__force __be16)__swab16p(p);
|
||||
}
|
||||
static inline __u16 __be16_to_cpup(const __be16 *p)
|
||||
{
|
||||
return __swab16p((__u16 *)p);
|
||||
}
|
||||
#define __cpu_to_le64s(x) do { (void)(x); } while (0)
|
||||
#define __le64_to_cpus(x) do { (void)(x); } while (0)
|
||||
#define __cpu_to_le32s(x) do { (void)(x); } while (0)
|
||||
#define __le32_to_cpus(x) do { (void)(x); } while (0)
|
||||
#define __cpu_to_le16s(x) do { (void)(x); } while (0)
|
||||
#define __le16_to_cpus(x) do { (void)(x); } while (0)
|
||||
#define __cpu_to_be64s(x) __swab64s((x))
|
||||
#define __be64_to_cpus(x) __swab64s((x))
|
||||
#define __cpu_to_be32s(x) __swab32s((x))
|
||||
#define __be32_to_cpus(x) __swab32s((x))
|
||||
#define __cpu_to_be16s(x) __swab16s((x))
|
||||
#define __be16_to_cpus(x) __swab16s((x))
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#include <linux/byteorder/generic.h>
|
||||
#endif
|
||||
|
||||
#endif /* _LINUX_BYTEORDER_LITTLE_ENDIAN_H */
|
||||
@@ -0,0 +1,156 @@
|
||||
#ifndef _LINUX_BYTEORDER_SWAB_H
|
||||
#define _LINUX_BYTEORDER_SWAB_H
|
||||
|
||||
/*
|
||||
* 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 suches 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.
|
||||
*/
|
||||
#define ___swab16(x) \
|
||||
((__u16)( \
|
||||
(((__u16)(x) & (__u16)0x00ffU) << 8) | \
|
||||
(((__u16)(x) & (__u16)0xff00U) >> 8) ))
|
||||
#define ___swab32(x) \
|
||||
((__u32)( \
|
||||
(((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
|
||||
(((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
|
||||
(((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
|
||||
(((__u32)(x) & (__u32)0xff000000UL) >> 24) ))
|
||||
#define ___swab64(x) \
|
||||
((__u64)( \
|
||||
(__u64)(((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) | \
|
||||
(__u64)(((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) | \
|
||||
(__u64)(((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) | \
|
||||
(__u64)(((__u64)(x) & (__u64)0x00000000ff000000ULL) << 8) | \
|
||||
(__u64)(((__u64)(x) & (__u64)0x000000ff00000000ULL) >> 8) | \
|
||||
(__u64)(((__u64)(x) & (__u64)0x0000ff0000000000ULL) >> 24) | \
|
||||
(__u64)(((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) | \
|
||||
(__u64)(((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56) ))
|
||||
|
||||
/*
|
||||
* provide defaults when no architecture-specific optimization is detected
|
||||
*/
|
||||
#ifndef __arch__swab16
|
||||
# define __arch__swab16(x) ___swab16(x)
|
||||
#endif
|
||||
#ifndef __arch__swab32
|
||||
# define __arch__swab32(x) ___swab32(x)
|
||||
#endif
|
||||
#ifndef __arch__swab64
|
||||
# define __arch__swab64(x) ___swab64(x)
|
||||
#endif
|
||||
|
||||
#ifndef __arch__swab16p
|
||||
# define __arch__swab16p(x) __swab16(*(x))
|
||||
#endif
|
||||
#ifndef __arch__swab32p
|
||||
# define __arch__swab32p(x) __swab32(*(x))
|
||||
#endif
|
||||
#ifndef __arch__swab64p
|
||||
# define __arch__swab64p(x) __swab64(*(x))
|
||||
#endif
|
||||
|
||||
#ifndef __arch__swab16s
|
||||
# define __arch__swab16s(x) do { *(x) = __swab16p((x)); } while (0)
|
||||
#endif
|
||||
#ifndef __arch__swab32s
|
||||
# define __arch__swab32s(x) do { *(x) = __swab32p((x)); } while (0)
|
||||
#endif
|
||||
#ifndef __arch__swab64s
|
||||
# define __arch__swab64s(x) do { *(x) = __swab64p((x)); } while (0)
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Allow constant folding
|
||||
*/
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 2) && defined(__OPTIMIZE__)
|
||||
# define __swab16(x) \
|
||||
(__builtin_constant_p((__u16)(x)) ? \
|
||||
___swab16((x)) : \
|
||||
__fswab16((x)))
|
||||
# define __swab32(x) \
|
||||
(__builtin_constant_p((__u32)(x)) ? \
|
||||
___swab32((x)) : \
|
||||
__fswab32((x)))
|
||||
# define __swab64(x) \
|
||||
(__builtin_constant_p((__u64)(x)) ? \
|
||||
___swab64((x)) : \
|
||||
__fswab64((x)))
|
||||
#else
|
||||
# define __swab16(x) __fswab16(x)
|
||||
# define __swab32(x) __fswab32(x)
|
||||
# define __swab64(x) __fswab64(x)
|
||||
#endif /* OPTIMIZE */
|
||||
|
||||
|
||||
static __inline__ __attribute__((const)) __u16 __fswab16(__u16 x)
|
||||
{
|
||||
return __arch__swab16(x);
|
||||
}
|
||||
static __inline__ __u16 __swab16p(const __u16 *x)
|
||||
{
|
||||
return __arch__swab16p(x);
|
||||
}
|
||||
static __inline__ void __swab16s(__u16 *addr)
|
||||
{
|
||||
__arch__swab16s(addr);
|
||||
}
|
||||
|
||||
static __inline__ __attribute__((const)) __u32 __fswab32(__u32 x)
|
||||
{
|
||||
return __arch__swab32(x);
|
||||
}
|
||||
static __inline__ __u32 __swab32p(const __u32 *x)
|
||||
{
|
||||
return __arch__swab32p(x);
|
||||
}
|
||||
static __inline__ void __swab32s(__u32 *addr)
|
||||
{
|
||||
__arch__swab32s(addr);
|
||||
}
|
||||
|
||||
static __inline__ __attribute__((const)) __u64 __fswab64(__u64 x)
|
||||
{
|
||||
# ifdef __SWAB_64_THRU_32__
|
||||
__u32 h = x >> 32;
|
||||
__u32 l = x & ((1ULL<<32)-1);
|
||||
return (((__u64)__swab32(l)) << 32) | ((__u64)(__swab32(h)));
|
||||
# else
|
||||
return __arch__swab64(x);
|
||||
# endif
|
||||
}
|
||||
static __inline__ __u64 __swab64p(const __u64 *x)
|
||||
{
|
||||
return __arch__swab64p(x);
|
||||
}
|
||||
static __inline__ void __swab64s(__u64 *addr)
|
||||
{
|
||||
__arch__swab64s(addr);
|
||||
}
|
||||
|
||||
#if defined(__KERNEL__)
|
||||
#define swab16 __swab16
|
||||
#define swab32 __swab32
|
||||
#define swab64 __swab64
|
||||
#define swab16p __swab16p
|
||||
#define swab32p __swab32p
|
||||
#define swab64p __swab64p
|
||||
#define swab16s __swab16s
|
||||
#define swab32s __swab32s
|
||||
#define swab64s __swab64s
|
||||
#endif
|
||||
|
||||
#endif /* _LINUX_BYTEORDER_SWAB_H */
|
||||
@@ -0,0 +1,190 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* Copyright (C) 2019 DENX Software Engineering
|
||||
* Lukasz Majewski, DENX Software Engineering, lukma@denx.de
|
||||
*
|
||||
* Copyright (c) 2010-2011 Jeremy Kerr <jeremy.kerr@canonical.com>
|
||||
* Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
|
||||
*/
|
||||
#ifndef __LINUX_CLK_PROVIDER_H
|
||||
#define __LINUX_CLK_PROVIDER_H
|
||||
#include <clk-uclass.h>
|
||||
|
||||
static inline void clk_dm(ulong id, struct clk *clk)
|
||||
{
|
||||
if (!IS_ERR(clk))
|
||||
clk->id = id;
|
||||
}
|
||||
|
||||
/*
|
||||
* flags used across common struct clk. these flags should only affect the
|
||||
* top-level framework. custom flags for dealing with hardware specifics
|
||||
* belong in struct clk_foo
|
||||
*
|
||||
* Please update clk_flags[] in drivers/clk/clk.c when making changes here!
|
||||
*/
|
||||
#define CLK_SET_RATE_GATE BIT(0) /* must be gated across rate change */
|
||||
#define CLK_SET_PARENT_GATE BIT(1) /* must be gated across re-parent */
|
||||
#define CLK_SET_RATE_PARENT BIT(2) /* propagate rate change up one level */
|
||||
#define CLK_IGNORE_UNUSED BIT(3) /* do not gate even if unused */
|
||||
/* unused */
|
||||
#define CLK_IS_BASIC BIT(5) /* Basic clk, can't do a to_clk_foo() */
|
||||
#define CLK_GET_RATE_NOCACHE BIT(6) /* do not use the cached clk rate */
|
||||
#define CLK_SET_RATE_NO_REPARENT BIT(7) /* don't re-parent on rate change */
|
||||
#define CLK_GET_ACCURACY_NOCACHE BIT(8) /* do not use the cached clk accuracy */
|
||||
#define CLK_RECALC_NEW_RATES BIT(9) /* recalc rates after notifications */
|
||||
#define CLK_SET_RATE_UNGATE BIT(10) /* clock needs to run to set rate */
|
||||
#define CLK_IS_CRITICAL BIT(11) /* do not gate, ever */
|
||||
/* parents need enable during gate/ungate, set rate and re-parent */
|
||||
#define CLK_OPS_PARENT_ENABLE BIT(12)
|
||||
/* duty cycle call may be forwarded to the parent clock */
|
||||
#define CLK_DUTY_CYCLE_PARENT BIT(13)
|
||||
|
||||
#define CLK_MUX_INDEX_ONE BIT(0)
|
||||
#define CLK_MUX_INDEX_BIT BIT(1)
|
||||
#define CLK_MUX_HIWORD_MASK BIT(2)
|
||||
#define CLK_MUX_READ_ONLY BIT(3) /* mux can't be changed */
|
||||
#define CLK_MUX_ROUND_CLOSEST BIT(4)
|
||||
|
||||
struct clk_mux {
|
||||
struct clk clk;
|
||||
void __iomem *reg;
|
||||
u32 *table;
|
||||
u32 mask;
|
||||
u8 shift;
|
||||
u8 flags;
|
||||
|
||||
/*
|
||||
* Fields from struct clk_init_data - this struct has been
|
||||
* omitted to avoid too deep level of CCF for bootloader
|
||||
*/
|
||||
const char * const *parent_names;
|
||||
u8 num_parents;
|
||||
#if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
|
||||
u32 io_mux_val;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#define to_clk_mux(_clk) container_of(_clk, struct clk_mux, clk)
|
||||
extern const struct clk_ops clk_mux_ops;
|
||||
u8 clk_mux_get_parent(struct clk *clk);
|
||||
|
||||
struct clk_gate {
|
||||
struct clk clk;
|
||||
void __iomem *reg;
|
||||
u8 bit_idx;
|
||||
u8 flags;
|
||||
#if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
|
||||
u32 io_gate_val;
|
||||
#endif
|
||||
};
|
||||
|
||||
#define to_clk_gate(_clk) container_of(_clk, struct clk_gate, clk)
|
||||
|
||||
#define CLK_GATE_SET_TO_DISABLE BIT(0)
|
||||
#define CLK_GATE_HIWORD_MASK BIT(1)
|
||||
|
||||
extern const struct clk_ops clk_gate_ops;
|
||||
struct clk *clk_register_gate(struct device *dev, const char *name,
|
||||
const char *parent_name, unsigned long flags,
|
||||
void __iomem *reg, u8 bit_idx,
|
||||
u8 clk_gate_flags, spinlock_t *lock);
|
||||
|
||||
struct clk_div_table {
|
||||
unsigned int val;
|
||||
unsigned int div;
|
||||
};
|
||||
|
||||
struct clk_divider {
|
||||
struct clk clk;
|
||||
void __iomem *reg;
|
||||
u8 shift;
|
||||
u8 width;
|
||||
u8 flags;
|
||||
const struct clk_div_table *table;
|
||||
#if CONFIG_IS_ENABLED(SANDBOX_CLK_CCF)
|
||||
u32 io_divider_val;
|
||||
#endif
|
||||
};
|
||||
|
||||
#define clk_div_mask(width) ((1 << (width)) - 1)
|
||||
#define to_clk_divider(_clk) container_of(_clk, struct clk_divider, clk)
|
||||
|
||||
#define CLK_DIVIDER_ONE_BASED BIT(0)
|
||||
#define CLK_DIVIDER_POWER_OF_TWO BIT(1)
|
||||
#define CLK_DIVIDER_ALLOW_ZERO BIT(2)
|
||||
#define CLK_DIVIDER_HIWORD_MASK BIT(3)
|
||||
#define CLK_DIVIDER_ROUND_CLOSEST BIT(4)
|
||||
#define CLK_DIVIDER_READ_ONLY BIT(5)
|
||||
#define CLK_DIVIDER_MAX_AT_ZERO BIT(6)
|
||||
extern const struct clk_ops clk_divider_ops;
|
||||
unsigned long divider_recalc_rate(struct clk *hw, unsigned long parent_rate,
|
||||
unsigned int val,
|
||||
const struct clk_div_table *table,
|
||||
unsigned long flags, unsigned long width);
|
||||
|
||||
struct clk_fixed_factor {
|
||||
struct clk clk;
|
||||
unsigned int mult;
|
||||
unsigned int div;
|
||||
};
|
||||
|
||||
#define to_clk_fixed_factor(_clk) container_of(_clk, struct clk_fixed_factor,\
|
||||
clk)
|
||||
|
||||
struct clk_fixed_rate {
|
||||
struct clk clk;
|
||||
unsigned long fixed_rate;
|
||||
};
|
||||
|
||||
#define to_clk_fixed_rate(dev) ((struct clk_fixed_rate *)dev_get_platdata(dev))
|
||||
|
||||
struct clk_composite {
|
||||
struct clk clk;
|
||||
struct clk_ops ops;
|
||||
|
||||
struct clk *mux;
|
||||
struct clk *rate;
|
||||
struct clk *gate;
|
||||
|
||||
const struct clk_ops *mux_ops;
|
||||
const struct clk_ops *rate_ops;
|
||||
const struct clk_ops *gate_ops;
|
||||
};
|
||||
|
||||
#define to_clk_composite(_clk) container_of(_clk, struct clk_composite, clk)
|
||||
|
||||
struct clk *clk_register_composite(struct device *dev, const char *name,
|
||||
const char * const *parent_names, int num_parents,
|
||||
struct clk *mux_clk, const struct clk_ops *mux_ops,
|
||||
struct clk *rate_clk, const struct clk_ops *rate_ops,
|
||||
struct clk *gate_clk, const struct clk_ops *gate_ops,
|
||||
unsigned long flags);
|
||||
|
||||
int clk_register(struct clk *clk, const char *drv_name, const char *name,
|
||||
const char *parent_name);
|
||||
|
||||
struct clk *clk_register_fixed_factor(struct device *dev, const char *name,
|
||||
const char *parent_name, unsigned long flags,
|
||||
unsigned int mult, unsigned int div);
|
||||
|
||||
struct clk *clk_register_divider(struct device *dev, const char *name,
|
||||
const char *parent_name, unsigned long flags,
|
||||
void __iomem *reg, u8 shift, u8 width,
|
||||
u8 clk_divider_flags);
|
||||
|
||||
struct clk *clk_register_mux(struct device *dev, const char *name,
|
||||
const char * const *parent_names, u8 num_parents,
|
||||
unsigned long flags,
|
||||
void __iomem *reg, u8 shift, u8 width,
|
||||
u8 clk_mux_flags);
|
||||
|
||||
const char *clk_hw_get_name(const struct clk *hw);
|
||||
ulong clk_generic_get_rate(struct clk *clk);
|
||||
|
||||
static inline struct clk *dev_get_clk_ptr(struct udevice *dev)
|
||||
{
|
||||
return (struct clk *)dev_get_uclass_priv(dev);
|
||||
}
|
||||
#endif /* __LINUX_CLK_PROVIDER_H */
|
||||
@@ -0,0 +1,79 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Copyright (C) 2018-2019 SiFive, Inc.
|
||||
* Wesley Terpstra
|
||||
* Paul Walmsley
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_CLK_ANALOGBITS_WRPLL_CLN28HPC_H
|
||||
#define __LINUX_CLK_ANALOGBITS_WRPLL_CLN28HPC_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
/* DIVQ_VALUES: number of valid DIVQ values */
|
||||
#define DIVQ_VALUES 6
|
||||
|
||||
/*
|
||||
* Bit definitions for struct wrpll_cfg.flags
|
||||
*
|
||||
* WRPLL_FLAGS_BYPASS_FLAG: if set, the PLL is either in bypass, or should be
|
||||
* programmed to enter bypass
|
||||
* WRPLL_FLAGS_RESET_FLAG: if set, the PLL is in reset
|
||||
* WRPLL_FLAGS_INT_FEEDBACK_FLAG: if set, the PLL is configured for internal
|
||||
* feedback mode
|
||||
* WRPLL_FLAGS_EXT_FEEDBACK_FLAG: if set, the PLL is configured for external
|
||||
* feedback mode (not yet supported by this driver)
|
||||
*/
|
||||
#define WRPLL_FLAGS_BYPASS_SHIFT 0
|
||||
#define WRPLL_FLAGS_BYPASS_MASK BIT(WRPLL_FLAGS_BYPASS_SHIFT)
|
||||
#define WRPLL_FLAGS_RESET_SHIFT 1
|
||||
#define WRPLL_FLAGS_RESET_MASK BIT(WRPLL_FLAGS_RESET_SHIFT)
|
||||
#define WRPLL_FLAGS_INT_FEEDBACK_SHIFT 2
|
||||
#define WRPLL_FLAGS_INT_FEEDBACK_MASK BIT(WRPLL_FLAGS_INT_FEEDBACK_SHIFT)
|
||||
#define WRPLL_FLAGS_EXT_FEEDBACK_SHIFT 3
|
||||
#define WRPLL_FLAGS_EXT_FEEDBACK_MASK BIT(WRPLL_FLAGS_EXT_FEEDBACK_SHIFT)
|
||||
|
||||
/**
|
||||
* struct wrpll_cfg - WRPLL configuration values
|
||||
* @divr: reference divider value (6 bits), as presented to the PLL signals
|
||||
* @divf: feedback divider value (9 bits), as presented to the PLL signals
|
||||
* @divq: output divider value (3 bits), as presented to the PLL signals
|
||||
* @flags: PLL configuration flags. See above for more information
|
||||
* @range: PLL loop filter range. See below for more information
|
||||
* @output_rate_cache: cached output rates, swept across DIVQ
|
||||
* @parent_rate: PLL refclk rate for which values are valid
|
||||
* @max_r: maximum possible R divider value, given @parent_rate
|
||||
* @init_r: initial R divider value to start the search from
|
||||
*
|
||||
* @divr, @divq, @divq, @range represent what the PLL expects to see
|
||||
* on its input signals. Thus @divr and @divf are the actual divisors
|
||||
* minus one. @divq is a power-of-two divider; for example, 1 =
|
||||
* divide-by-2 and 6 = divide-by-64. 0 is an invalid @divq value.
|
||||
*
|
||||
* When initially passing a struct wrpll_cfg record, the
|
||||
* record should be zero-initialized with the exception of the @flags
|
||||
* field. The only flag bits that need to be set are either
|
||||
* WRPLL_FLAGS_INT_FEEDBACK or WRPLL_FLAGS_EXT_FEEDBACK.
|
||||
*/
|
||||
struct wrpll_cfg {
|
||||
u8 divr;
|
||||
u8 divq;
|
||||
u8 range;
|
||||
u8 flags;
|
||||
u16 divf;
|
||||
/* private: */
|
||||
u32 output_rate_cache[DIVQ_VALUES];
|
||||
unsigned long parent_rate;
|
||||
u8 max_r;
|
||||
u8 init_r;
|
||||
};
|
||||
|
||||
int wrpll_configure_for_rate(struct wrpll_cfg *c, u32 target_rate,
|
||||
unsigned long parent_rate);
|
||||
|
||||
unsigned int wrpll_calc_max_lock_us(const struct wrpll_cfg *c);
|
||||
|
||||
unsigned long wrpll_calc_output_rate(const struct wrpll_cfg *c,
|
||||
unsigned long parent_rate);
|
||||
|
||||
#endif /* __LINUX_CLK_ANALOGBITS_WRPLL_CLN28HPC_H */
|
||||
@@ -0,0 +1,378 @@
|
||||
#ifndef _LINUX_COMPAT_H_
|
||||
#define _LINUX_COMPAT_H_
|
||||
|
||||
#include <malloc.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/kernel.h>
|
||||
|
||||
struct unused {};
|
||||
typedef struct unused unused_t;
|
||||
|
||||
struct p_current{
|
||||
int pid;
|
||||
};
|
||||
|
||||
extern struct p_current *current;
|
||||
|
||||
/* avoid conflict with <dm/device.h> */
|
||||
#ifdef dev_dbg
|
||||
#undef dev_dbg
|
||||
#endif
|
||||
#ifdef dev_vdbg
|
||||
#undef dev_vdbg
|
||||
#endif
|
||||
#ifdef dev_info
|
||||
#undef dev_info
|
||||
#endif
|
||||
#ifdef dev_err
|
||||
#undef dev_err
|
||||
#endif
|
||||
#ifdef dev_warn
|
||||
#undef dev_warn
|
||||
#endif
|
||||
|
||||
#define dev_dbg(dev, fmt, args...) \
|
||||
debug(fmt, ##args)
|
||||
#define dev_vdbg(dev, fmt, args...) \
|
||||
debug(fmt, ##args)
|
||||
#define dev_info(dev, fmt, args...) \
|
||||
printf(fmt, ##args)
|
||||
#define dev_err(dev, fmt, args...) \
|
||||
printf(fmt, ##args)
|
||||
#define dev_warn(dev, fmt, args...) \
|
||||
printf(fmt, ##args)
|
||||
|
||||
#define netdev_emerg(dev, fmt, args...) \
|
||||
printf(fmt, ##args)
|
||||
#define netdev_alert(dev, fmt, args...) \
|
||||
printf(fmt, ##args)
|
||||
#define netdev_crit(dev, fmt, args...) \
|
||||
printf(fmt, ##args)
|
||||
#define netdev_err(dev, fmt, args...) \
|
||||
printf(fmt, ##args)
|
||||
#define netdev_warn(dev, fmt, args...) \
|
||||
printf(fmt, ##args)
|
||||
#define netdev_notice(dev, fmt, args...) \
|
||||
printf(fmt, ##args)
|
||||
#define netdev_info(dev, fmt, args...) \
|
||||
printf(fmt, ##args)
|
||||
#define netdev_dbg(dev, fmt, args...) \
|
||||
debug(fmt, ##args)
|
||||
#define netdev_vdbg(dev, fmt, args...) \
|
||||
debug(fmt, ##args)
|
||||
|
||||
#define GFP_ATOMIC ((gfp_t) 0)
|
||||
#define GFP_KERNEL ((gfp_t) 0)
|
||||
#define GFP_NOFS ((gfp_t) 0)
|
||||
#define GFP_USER ((gfp_t) 0)
|
||||
#define __GFP_NOWARN ((gfp_t) 0)
|
||||
#define __GFP_ZERO ((__force gfp_t)0x8000u) /* Return zeroed page on success */
|
||||
|
||||
void *kmalloc(size_t size, int flags);
|
||||
|
||||
static inline void *kzalloc(size_t size, gfp_t flags)
|
||||
{
|
||||
return kmalloc(size, flags | __GFP_ZERO);
|
||||
}
|
||||
|
||||
static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
|
||||
{
|
||||
if (size != 0 && n > SIZE_MAX / size)
|
||||
return NULL;
|
||||
return kmalloc(n * size, flags | __GFP_ZERO);
|
||||
}
|
||||
|
||||
static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
|
||||
{
|
||||
return kmalloc_array(n, size, flags | __GFP_ZERO);
|
||||
}
|
||||
|
||||
#define vmalloc(size) kmalloc(size, 0)
|
||||
#define __vmalloc(size, flags, pgsz) kmalloc(size, flags)
|
||||
static inline void *vzalloc(unsigned long size)
|
||||
{
|
||||
return kzalloc(size, 0);
|
||||
}
|
||||
static inline void kfree(const void *block)
|
||||
{
|
||||
free((void *)block);
|
||||
}
|
||||
static inline void vfree(const void *addr)
|
||||
{
|
||||
free((void *)addr);
|
||||
}
|
||||
|
||||
struct kmem_cache { int sz; };
|
||||
|
||||
struct kmem_cache *get_mem(int element_sz);
|
||||
#define kmem_cache_create(a, sz, c, d, e) get_mem(sz)
|
||||
void *kmem_cache_alloc(struct kmem_cache *obj, int flag);
|
||||
static inline void kmem_cache_free(struct kmem_cache *cachep, void *obj)
|
||||
{
|
||||
free(obj);
|
||||
}
|
||||
static inline void kmem_cache_destroy(struct kmem_cache *cachep)
|
||||
{
|
||||
free(cachep);
|
||||
}
|
||||
|
||||
#define DECLARE_WAITQUEUE(...) do { } while (0)
|
||||
#define add_wait_queue(...) do { } while (0)
|
||||
#define remove_wait_queue(...) do { } while (0)
|
||||
|
||||
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
/* drivers/char/random.c */
|
||||
#define get_random_bytes(...)
|
||||
|
||||
/* include/linux/leds.h */
|
||||
struct led_trigger {};
|
||||
|
||||
#define DEFINE_LED_TRIGGER(x) static struct led_trigger *x;
|
||||
enum led_brightness {
|
||||
LED_OFF = 0,
|
||||
LED_HALF = 127,
|
||||
LED_FULL = 255,
|
||||
};
|
||||
|
||||
static inline void led_trigger_register_simple(const char *name,
|
||||
struct led_trigger **trigger) {}
|
||||
static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {}
|
||||
static inline void led_trigger_event(struct led_trigger *trigger,
|
||||
enum led_brightness event) {}
|
||||
|
||||
/* uapi/linux/limits.h */
|
||||
#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */
|
||||
|
||||
/**
|
||||
* The type used for indexing onto a disc or disc partition.
|
||||
*
|
||||
* Linux always considers sectors to be 512 bytes long independently
|
||||
* of the devices real block size.
|
||||
*
|
||||
* blkcnt_t is the type of the inode's block count.
|
||||
*/
|
||||
#ifdef CONFIG_LBDAF
|
||||
typedef u64 sector_t;
|
||||
typedef u64 blkcnt_t;
|
||||
#else
|
||||
typedef unsigned long sector_t;
|
||||
typedef unsigned long blkcnt_t;
|
||||
#endif
|
||||
|
||||
/* module */
|
||||
#define THIS_MODULE 0
|
||||
#define try_module_get(...) 1
|
||||
#define module_put(...) do { } while (0)
|
||||
#define module_init(...)
|
||||
#define module_exit(...)
|
||||
#define EXPORT_SYMBOL(...)
|
||||
#define EXPORT_SYMBOL_GPL(...)
|
||||
#define module_param(...)
|
||||
#define module_param_call(...)
|
||||
#define MODULE_PARM_DESC(...)
|
||||
#define MODULE_VERSION(...)
|
||||
#define MODULE_DESCRIPTION(...)
|
||||
#define MODULE_AUTHOR(...)
|
||||
#define MODULE_LICENSE(...)
|
||||
#define MODULE_ALIAS(...)
|
||||
#define __module_get(...)
|
||||
|
||||
/* character device */
|
||||
#define MKDEV(...) 0
|
||||
#define MAJOR(dev) 0
|
||||
#define MINOR(dev) 0
|
||||
|
||||
#define alloc_chrdev_region(...) 0
|
||||
#define unregister_chrdev_region(...)
|
||||
|
||||
#define class_create(...) __builtin_return_address(0)
|
||||
#define class_create_file(...) 0
|
||||
#define class_register(...) 0
|
||||
#define class_unregister(...)
|
||||
#define class_remove_file(...)
|
||||
#define class_destroy(...)
|
||||
#define misc_register(...) 0
|
||||
#define misc_deregister(...)
|
||||
|
||||
#define blocking_notifier_call_chain(...) 0
|
||||
|
||||
#define __initdata
|
||||
#define late_initcall(...)
|
||||
|
||||
#define dev_set_name(...) do { } while (0)
|
||||
#define device_register(...) 0
|
||||
#define device_unregister(...)
|
||||
#define volume_sysfs_init(...) 0
|
||||
#define volume_sysfs_close(...) do { } while (0)
|
||||
|
||||
#define init_waitqueue_head(...) do { } while (0)
|
||||
#define wait_event_interruptible(...) 0
|
||||
#define wake_up_interruptible(...) do { } while (0)
|
||||
#define dump_stack(...) do { } while (0)
|
||||
|
||||
#define task_pid_nr(x) 0
|
||||
#define set_freezable(...) do { } while (0)
|
||||
#define try_to_freeze(...) 0
|
||||
#define set_current_state(...) do { } while (0)
|
||||
#define kthread_should_stop(...) 0
|
||||
#define schedule() do { } while (0)
|
||||
|
||||
#define setup_timer(timer, func, data) do {} while (0)
|
||||
#define del_timer_sync(timer) do {} while (0)
|
||||
#define schedule_work(work) do {} while (0)
|
||||
#define INIT_WORK(work, fun) do {} while (0)
|
||||
|
||||
struct work_struct {};
|
||||
|
||||
unsigned long copy_from_user(void *dest, const void *src,
|
||||
unsigned long count);
|
||||
|
||||
typedef unused_t spinlock_t;
|
||||
typedef int wait_queue_head_t;
|
||||
|
||||
#define spin_lock_init(lock) do {} while (0)
|
||||
#define spin_lock(lock) do {} while (0)
|
||||
#define spin_unlock(lock) do {} while (0)
|
||||
#define spin_lock_irqsave(lock, flags) do { debug("%lu\n", flags); } while (0)
|
||||
#define spin_unlock_irqrestore(lock, flags) do { flags = 0; } while (0)
|
||||
|
||||
#define DEFINE_MUTEX(...)
|
||||
#define mutex_init(...)
|
||||
#define mutex_lock(...)
|
||||
#define mutex_unlock(...)
|
||||
|
||||
#define init_rwsem(...) do { } while (0)
|
||||
#define down_read(...) do { } while (0)
|
||||
#define down_write(...) do { } while (0)
|
||||
#define down_write_trylock(...) 1
|
||||
#define up_read(...) do { } while (0)
|
||||
#define up_write(...) do { } while (0)
|
||||
|
||||
#define cond_resched() do { } while (0)
|
||||
#define yield() do { } while (0)
|
||||
|
||||
#define __init
|
||||
#define __exit
|
||||
#define __devinit
|
||||
#define __devinitdata
|
||||
#define __devinitconst
|
||||
|
||||
#define kthread_create(...) __builtin_return_address(0)
|
||||
#define kthread_stop(...) do { } while (0)
|
||||
#define wake_up_process(...) do { } while (0)
|
||||
|
||||
struct rw_semaphore { int i; };
|
||||
#define down_write(...) do { } while (0)
|
||||
#define up_write(...) do { } while (0)
|
||||
#define down_read(...) do { } while (0)
|
||||
#define up_read(...) do { } while (0)
|
||||
struct device {
|
||||
struct device *parent;
|
||||
struct class *class;
|
||||
dev_t devt; /* dev_t, creates the sysfs "dev" */
|
||||
void (*release)(struct device *dev);
|
||||
/* This is used from drivers/usb/musb-new subsystem only */
|
||||
void *driver_data; /* data private to the driver */
|
||||
void *device_data; /* data private to the device */
|
||||
};
|
||||
struct mutex { int i; };
|
||||
struct kernel_param { int i; };
|
||||
|
||||
struct cdev {
|
||||
int owner;
|
||||
dev_t dev;
|
||||
};
|
||||
#define cdev_init(...) do { } while (0)
|
||||
#define cdev_add(...) 0
|
||||
#define cdev_del(...) do { } while (0)
|
||||
|
||||
#define prandom_u32(...) 0
|
||||
|
||||
typedef struct {
|
||||
uid_t val;
|
||||
} kuid_t;
|
||||
|
||||
typedef struct {
|
||||
gid_t val;
|
||||
} kgid_t;
|
||||
|
||||
/* from include/linux/types.h */
|
||||
|
||||
/**
|
||||
* struct callback_head - callback structure for use with RCU and task_work
|
||||
* @next: next update requests in a list
|
||||
* @func: actual update function to call after the grace period.
|
||||
*/
|
||||
struct callback_head {
|
||||
struct callback_head *next;
|
||||
void (*func)(struct callback_head *head);
|
||||
};
|
||||
#define rcu_head callback_head
|
||||
enum writeback_sync_modes {
|
||||
WB_SYNC_NONE, /* Don't wait on anything */
|
||||
WB_SYNC_ALL, /* Wait on every mapping */
|
||||
};
|
||||
|
||||
/* from include/linux/writeback.h */
|
||||
/*
|
||||
* A control structure which tells the writeback code what to do. These are
|
||||
* always on the stack, and hence need no locking. They are always initialised
|
||||
* in a manner such that unspecified fields are set to zero.
|
||||
*/
|
||||
struct writeback_control {
|
||||
long nr_to_write; /* Write this many pages, and decrement
|
||||
this for each page written */
|
||||
long pages_skipped; /* Pages which were not written */
|
||||
|
||||
/*
|
||||
* For a_ops->writepages(): if start or end are non-zero then this is
|
||||
* a hint that the filesystem need only write out the pages inside that
|
||||
* byterange. The byte at `end' is included in the writeout request.
|
||||
*/
|
||||
loff_t range_start;
|
||||
loff_t range_end;
|
||||
|
||||
enum writeback_sync_modes sync_mode;
|
||||
|
||||
unsigned for_kupdate:1; /* A kupdate writeback */
|
||||
unsigned for_background:1; /* A background writeback */
|
||||
unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */
|
||||
unsigned for_reclaim:1; /* Invoked from the page allocator */
|
||||
unsigned range_cyclic:1; /* range_start is cyclic */
|
||||
unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */
|
||||
};
|
||||
|
||||
void *kmemdup(const void *src, size_t len, gfp_t gfp);
|
||||
|
||||
typedef int irqreturn_t;
|
||||
|
||||
struct timer_list {};
|
||||
struct notifier_block {};
|
||||
|
||||
typedef unsigned long dmaaddr_t;
|
||||
|
||||
#define pm_runtime_get_sync(dev) do {} while (0)
|
||||
#define pm_runtime_put(dev) do {} while (0)
|
||||
#define pm_runtime_put_sync(dev) do {} while (0)
|
||||
#define pm_runtime_use_autosuspend(dev) do {} while (0)
|
||||
#define pm_runtime_set_autosuspend_delay(dev, delay) do {} while (0)
|
||||
#define pm_runtime_enable(dev) do {} while (0)
|
||||
|
||||
#define IRQ_NONE 0
|
||||
#define IRQ_HANDLED 1
|
||||
#define IRQ_WAKE_THREAD 2
|
||||
|
||||
#define dev_set_drvdata(dev, data) do {} while (0)
|
||||
|
||||
#define enable_irq(...)
|
||||
#define disable_irq(...)
|
||||
#define disable_irq_wake(irq) do {} while (0)
|
||||
#define enable_irq_wake(irq) -EINVAL
|
||||
#define free_irq(irq, data) do {} while (0)
|
||||
#define request_irq(nr, f, flags, nm, data) 0
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef __LINUX_COMPILER_H
|
||||
#error "Please don't include <linux/compiler-clang.h> directly, include <linux/compiler.h> instead."
|
||||
#endif
|
||||
|
||||
/* Some compiler specific definitions are overwritten here
|
||||
* for Clang compiler
|
||||
*/
|
||||
|
||||
#ifdef uninitialized_var
|
||||
#undef uninitialized_var
|
||||
#define uninitialized_var(x) x = *(&(x))
|
||||
#endif
|
||||
@@ -0,0 +1,285 @@
|
||||
#ifndef __LINUX_COMPILER_H
|
||||
#error "Please don't include <linux/compiler-gcc.h> directly, include <linux/compiler.h> instead."
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Common definitions for all gcc versions go here.
|
||||
*/
|
||||
#define GCC_VERSION (__GNUC__ * 10000 \
|
||||
+ __GNUC_MINOR__ * 100 \
|
||||
+ __GNUC_PATCHLEVEL__)
|
||||
|
||||
/* Optimization barrier */
|
||||
|
||||
/* The "volatile" is due to gcc bugs */
|
||||
#define barrier() \
|
||||
__asm__ __volatile__("": : :"memory")
|
||||
/*
|
||||
* This version is i.e. to prevent dead stores elimination on @ptr
|
||||
* where gcc and llvm may behave differently when otherwise using
|
||||
* normal barrier(): while gcc behavior gets along with a normal
|
||||
* barrier(), llvm needs an explicit input variable to be assumed
|
||||
* clobbered. The issue is as follows: while the inline asm might
|
||||
* access any memory it wants, the compiler could have fit all of
|
||||
* @ptr into memory registers instead, and since @ptr never escaped
|
||||
* from that, it proofed that the inline asm wasn't touching any of
|
||||
* it. This version works well with both compilers, i.e. we're telling
|
||||
* the compiler that the inline asm absolutely may see the contents
|
||||
* of @ptr. See also: https://llvm.org/bugs/show_bug.cgi?id=15495
|
||||
*/
|
||||
#define barrier_data(ptr) \
|
||||
__asm__ __volatile__("": :"r"(ptr) :"memory")
|
||||
|
||||
/*
|
||||
* This macro obfuscates arithmetic on a variable address so that gcc
|
||||
* shouldn't recognize the original var, and make assumptions about it.
|
||||
*
|
||||
* This is needed because the C standard makes it undefined to do
|
||||
* pointer arithmetic on "objects" outside their boundaries and the
|
||||
* gcc optimizers assume this is the case. In particular they
|
||||
* assume such arithmetic does not wrap.
|
||||
*
|
||||
* A miscompilation has been observed because of this on PPC.
|
||||
* To work around it we hide the relationship of the pointer and the object
|
||||
* using this macro.
|
||||
*
|
||||
* Versions of the ppc64 compiler before 4.1 had a bug where use of
|
||||
* RELOC_HIDE could trash r30. The bug can be worked around by changing
|
||||
* the inline assembly constraint from =g to =r, in this particular
|
||||
* case either is valid.
|
||||
*/
|
||||
#define RELOC_HIDE(ptr, off) \
|
||||
({ \
|
||||
unsigned long __ptr; \
|
||||
__asm__ ("" : "=r"(__ptr) : "0"(ptr)); \
|
||||
(typeof(ptr)) (__ptr + (off)); \
|
||||
})
|
||||
|
||||
/* Make the optimizer believe the variable can be manipulated arbitrarily. */
|
||||
#define OPTIMIZER_HIDE_VAR(var) \
|
||||
__asm__ ("" : "=r" (var) : "0" (var))
|
||||
|
||||
#ifdef __CHECKER__
|
||||
#define __must_be_array(a) 0
|
||||
#else
|
||||
/* &a[0] degrades to a pointer: a different type from an array */
|
||||
#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Force always-inline if the user requests it so via the .config,
|
||||
* or if gcc is too old:
|
||||
*/
|
||||
#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
|
||||
!defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
|
||||
#define inline inline __attribute__((always_inline)) notrace
|
||||
#define __inline__ __inline__ __attribute__((always_inline)) notrace
|
||||
#define __inline __inline __attribute__((always_inline)) notrace
|
||||
#else
|
||||
/* A lot of inline functions can cause havoc with function tracing */
|
||||
#define inline inline notrace
|
||||
#define __inline__ __inline__ notrace
|
||||
#define __inline __inline notrace
|
||||
#endif
|
||||
|
||||
#define __always_inline inline __attribute__((always_inline))
|
||||
#define noinline __attribute__((noinline))
|
||||
|
||||
#define __deprecated __attribute__((deprecated))
|
||||
#define __packed __attribute__((packed))
|
||||
#define __weak __attribute__((weak))
|
||||
#define __alias(symbol) __attribute__((alias(#symbol)))
|
||||
|
||||
/*
|
||||
* it doesn't make sense on ARM (currently the only user of __naked)
|
||||
* to trace naked functions because then mcount is called without
|
||||
* stack and frame pointer being set up and there is no chance to
|
||||
* restore the lr register to the value before mcount was called.
|
||||
*
|
||||
* The asm() bodies of naked functions often depend on standard calling
|
||||
* conventions, therefore they must be noinline and noclone.
|
||||
*
|
||||
* GCC 4.[56] currently fail to enforce this, so we must do so ourselves.
|
||||
* See GCC PR44290.
|
||||
*/
|
||||
#define __naked __attribute__((naked)) noinline __noclone notrace
|
||||
|
||||
#define __noreturn __attribute__((noreturn))
|
||||
|
||||
/*
|
||||
* From the GCC manual:
|
||||
*
|
||||
* Many functions have no effects except the return value and their
|
||||
* return value depends only on the parameters and/or global
|
||||
* variables. Such a function can be subject to common subexpression
|
||||
* elimination and loop optimization just as an arithmetic operator
|
||||
* would be.
|
||||
* [...]
|
||||
*/
|
||||
#define __pure __attribute__((pure))
|
||||
#define __aligned(x) __attribute__((aligned(x)))
|
||||
#define __printf(a, b) __attribute__((format(printf, a, b)))
|
||||
#define __scanf(a, b) __attribute__((format(scanf, a, b)))
|
||||
#define __attribute_const__ __attribute__((__const__))
|
||||
#define __maybe_unused __attribute__((unused))
|
||||
#define __always_unused __attribute__((unused))
|
||||
|
||||
/* gcc version specific checks */
|
||||
|
||||
#if GCC_VERSION < 30200
|
||||
# error Sorry, your compiler is too old - please upgrade it.
|
||||
#endif
|
||||
|
||||
#if GCC_VERSION < 30300
|
||||
# define __used __attribute__((__unused__))
|
||||
#else
|
||||
# define __used __attribute__((__used__))
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_GCOV_KERNEL
|
||||
# if GCC_VERSION < 30400
|
||||
# error "GCOV profiling support for gcc versions below 3.4 not included"
|
||||
# endif /* __GNUC_MINOR__ */
|
||||
#endif /* CONFIG_GCOV_KERNEL */
|
||||
|
||||
#if GCC_VERSION >= 30400
|
||||
#define __must_check __attribute__((warn_unused_result))
|
||||
#endif
|
||||
|
||||
#if GCC_VERSION >= 40000
|
||||
|
||||
/* GCC 4.1.[01] miscompiles __weak */
|
||||
#ifdef __KERNEL__
|
||||
# if GCC_VERSION >= 40100 && GCC_VERSION <= 40101
|
||||
# error Your version of gcc miscompiles the __weak directive
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define __used __attribute__((__used__))
|
||||
#define __compiler_offsetof(a, b) \
|
||||
__builtin_offsetof(a, b)
|
||||
|
||||
#if GCC_VERSION >= 40100 && GCC_VERSION < 40600
|
||||
# define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
|
||||
#endif
|
||||
|
||||
#if GCC_VERSION >= 40300
|
||||
/* Mark functions as cold. gcc will assume any path leading to a call
|
||||
* to them will be unlikely. This means a lot of manual unlikely()s
|
||||
* are unnecessary now for any paths leading to the usual suspects
|
||||
* like BUG(), printk(), panic() etc. [but let's keep them for now for
|
||||
* older compilers]
|
||||
*
|
||||
* Early snapshots of gcc 4.3 don't support this and we can't detect this
|
||||
* in the preprocessor, but we can live with this because they're unreleased.
|
||||
* Maketime probing would be overkill here.
|
||||
*
|
||||
* gcc also has a __attribute__((__hot__)) to move hot functions into
|
||||
* a special section, but I don't see any sense in this right now in
|
||||
* the kernel context
|
||||
*/
|
||||
#define __cold __attribute__((__cold__))
|
||||
|
||||
#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
|
||||
|
||||
#ifndef __CHECKER__
|
||||
# define __compiletime_warning(message) __attribute__((warning(message)))
|
||||
# define __compiletime_error(message) __attribute__((error(message)))
|
||||
#endif /* __CHECKER__ */
|
||||
#endif /* GCC_VERSION >= 40300 */
|
||||
|
||||
#if GCC_VERSION >= 40500
|
||||
/*
|
||||
* Mark a position in code as unreachable. This can be used to
|
||||
* suppress control flow warnings after asm blocks that transfer
|
||||
* control elsewhere.
|
||||
*
|
||||
* Early snapshots of gcc 4.5 don't support this and we can't detect
|
||||
* this in the preprocessor, but we can live with this because they're
|
||||
* unreleased. Really, we need to have autoconf for the kernel.
|
||||
*/
|
||||
#define unreachable() __builtin_unreachable()
|
||||
|
||||
/* Mark a function definition as prohibited from being cloned. */
|
||||
#define __noclone __attribute__((__noclone__))
|
||||
|
||||
#endif /* GCC_VERSION >= 40500 */
|
||||
|
||||
#if GCC_VERSION >= 40600
|
||||
/*
|
||||
* When used with Link Time Optimization, gcc can optimize away C functions or
|
||||
* variables which are referenced only from assembly code. __visible tells the
|
||||
* optimizer that something else uses this function or variable, thus preventing
|
||||
* this.
|
||||
*/
|
||||
#define __visible __attribute__((externally_visible))
|
||||
#endif
|
||||
|
||||
|
||||
#if GCC_VERSION >= 40900 && !defined(__CHECKER__)
|
||||
/*
|
||||
* __assume_aligned(n, k): Tell the optimizer that the returned
|
||||
* pointer can be assumed to be k modulo n. The second argument is
|
||||
* optional (default 0), so we use a variadic macro to make the
|
||||
* shorthand.
|
||||
*
|
||||
* Beware: Do not apply this to functions which may return
|
||||
* ERR_PTRs. Also, it is probably unwise to apply it to functions
|
||||
* returning extra information in the low bits (but in that case the
|
||||
* compiler should see some alignment anyway, when the return value is
|
||||
* massaged by 'flags = ptr & 3; ptr &= ~3;').
|
||||
*/
|
||||
#define __assume_aligned(a, ...) __attribute__((__assume_aligned__(a, ## __VA_ARGS__)))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* GCC 'asm goto' miscompiles certain code sequences:
|
||||
*
|
||||
* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
|
||||
*
|
||||
* Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
|
||||
*
|
||||
* (asm goto is automatically volatile - the naming reflects this.)
|
||||
*/
|
||||
#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
|
||||
|
||||
#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
|
||||
#if GCC_VERSION >= 40400
|
||||
#define __HAVE_BUILTIN_BSWAP32__
|
||||
#define __HAVE_BUILTIN_BSWAP64__
|
||||
#endif
|
||||
#if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600)
|
||||
#define __HAVE_BUILTIN_BSWAP16__
|
||||
#endif
|
||||
#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
|
||||
|
||||
#if GCC_VERSION >= 50000
|
||||
#define KASAN_ABI_VERSION 4
|
||||
#elif GCC_VERSION >= 40902
|
||||
#define KASAN_ABI_VERSION 3
|
||||
#endif
|
||||
|
||||
#if GCC_VERSION >= 40902
|
||||
/*
|
||||
* Tell the compiler that address safety instrumentation (KASAN)
|
||||
* should not be applied to that function.
|
||||
* Conflicts with inlining: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368
|
||||
*/
|
||||
#define __no_sanitize_address __attribute__((no_sanitize_address))
|
||||
#endif
|
||||
|
||||
#endif /* gcc version >= 40000 specific checks */
|
||||
|
||||
#if !defined(__noclone)
|
||||
#define __noclone /* not needed */
|
||||
#endif
|
||||
|
||||
#if !defined(__no_sanitize_address)
|
||||
#define __no_sanitize_address
|
||||
#endif
|
||||
|
||||
/*
|
||||
* A trick to suppress uninitialized variable warning without generating any
|
||||
* code
|
||||
*/
|
||||
#define uninitialized_var(x) x = x
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef __LINUX_COMPILER_H
|
||||
#error "Please don't include <linux/compiler-intel.h> directly, include <linux/compiler.h> instead."
|
||||
#endif
|
||||
|
||||
#ifdef __ECC
|
||||
|
||||
/* Some compiler specific definitions are overwritten here
|
||||
* for Intel ECC compiler
|
||||
*/
|
||||
|
||||
#include <asm/intrinsics.h>
|
||||
|
||||
/* Intel ECC compiler doesn't support gcc specific asm stmts.
|
||||
* It uses intrinsics to do the equivalent things.
|
||||
*/
|
||||
#undef barrier
|
||||
#undef barrier_data
|
||||
#undef RELOC_HIDE
|
||||
#undef OPTIMIZER_HIDE_VAR
|
||||
|
||||
#define barrier() __memory_barrier()
|
||||
#define barrier_data(ptr) barrier()
|
||||
|
||||
#define RELOC_HIDE(ptr, off) \
|
||||
({ unsigned long __ptr; \
|
||||
__ptr = (unsigned long) (ptr); \
|
||||
(typeof(ptr)) (__ptr + (off)); })
|
||||
|
||||
/* This should act as an optimization barrier on var.
|
||||
* Given that this compiler does not have inline assembly, a compiler barrier
|
||||
* is the best we can do.
|
||||
*/
|
||||
#define OPTIMIZER_HIDE_VAR(var) barrier()
|
||||
|
||||
/* Intel ECC compiler doesn't support __builtin_types_compatible_p() */
|
||||
#define __must_be_array(a) 0
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef __HAVE_BUILTIN_BSWAP16__
|
||||
/* icc has this, but it's called _bswap16 */
|
||||
#define __HAVE_BUILTIN_BSWAP16__
|
||||
#define __builtin_bswap16 _bswap16
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,559 @@
|
||||
#ifndef __LINUX_COMPILER_H
|
||||
#define __LINUX_COMPILER_H
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#ifdef __CHECKER__
|
||||
# define __user __attribute__((noderef, address_space(1)))
|
||||
# define __kernel __attribute__((address_space(0)))
|
||||
# define __safe __attribute__((safe))
|
||||
# define __force __attribute__((force))
|
||||
# define __nocast __attribute__((nocast))
|
||||
# define __iomem __attribute__((noderef, address_space(2)))
|
||||
# define __must_hold(x) __attribute__((context(x,1,1)))
|
||||
# define __acquires(x) __attribute__((context(x,0,1)))
|
||||
# define __releases(x) __attribute__((context(x,1,0)))
|
||||
# define __acquire(x) __context__(x,1)
|
||||
# define __release(x) __context__(x,-1)
|
||||
# define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
|
||||
# define __percpu __attribute__((noderef, address_space(3)))
|
||||
# define __pmem __attribute__((noderef, address_space(5)))
|
||||
#ifdef CONFIG_SPARSE_RCU_POINTER
|
||||
# define __rcu __attribute__((noderef, address_space(4)))
|
||||
#else
|
||||
# define __rcu
|
||||
#endif
|
||||
extern void __chk_user_ptr(const volatile void __user *);
|
||||
extern void __chk_io_ptr(const volatile void __iomem *);
|
||||
#else
|
||||
# define __user
|
||||
# define __kernel
|
||||
# define __safe
|
||||
# define __force
|
||||
# define __nocast
|
||||
# define __iomem
|
||||
# define __chk_user_ptr(x) (void)0
|
||||
# define __chk_io_ptr(x) (void)0
|
||||
# define __builtin_warning(x, y...) (1)
|
||||
# define __must_hold(x)
|
||||
# define __acquires(x)
|
||||
# define __releases(x)
|
||||
# define __acquire(x) (void)0
|
||||
# define __release(x) (void)0
|
||||
# define __cond_lock(x,c) (c)
|
||||
# define __percpu
|
||||
# define __rcu
|
||||
# define __pmem
|
||||
#endif
|
||||
|
||||
/* Indirect macros required for expanded argument pasting, eg. __LINE__. */
|
||||
#define ___PASTE(a,b) a##b
|
||||
#define __PASTE(a,b) ___PASTE(a,b)
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
#ifdef __GNUC__
|
||||
#include <linux/compiler-gcc.h>
|
||||
#endif
|
||||
|
||||
#if defined(CC_USING_HOTPATCH) && !defined(__CHECKER__)
|
||||
#define notrace __attribute__((hotpatch(0,0)))
|
||||
#else
|
||||
#define notrace __attribute__((no_instrument_function))
|
||||
#endif
|
||||
|
||||
/* Intel compiler defines __GNUC__. So we will overwrite implementations
|
||||
* coming from above header files here
|
||||
*/
|
||||
#ifdef __INTEL_COMPILER
|
||||
# include <linux/compiler-intel.h>
|
||||
#endif
|
||||
|
||||
/* Clang compiler defines __GNUC__. So we will overwrite implementations
|
||||
* coming from above header files here
|
||||
*/
|
||||
#ifdef __clang__
|
||||
#include <linux/compiler-clang.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Generic compiler-dependent macros required for kernel
|
||||
* build go below this comment. Actual compiler/compiler version
|
||||
* specific implementations come from the above header files
|
||||
*/
|
||||
|
||||
struct ftrace_branch_data {
|
||||
const char *func;
|
||||
const char *file;
|
||||
unsigned line;
|
||||
union {
|
||||
struct {
|
||||
unsigned long correct;
|
||||
unsigned long incorrect;
|
||||
};
|
||||
struct {
|
||||
unsigned long miss;
|
||||
unsigned long hit;
|
||||
};
|
||||
unsigned long miss_hit[2];
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
* Note: DISABLE_BRANCH_PROFILING can be used by special lowlevel code
|
||||
* to disable branch tracing on a per file basis.
|
||||
*/
|
||||
#if defined(CONFIG_TRACE_BRANCH_PROFILING) \
|
||||
&& !defined(DISABLE_BRANCH_PROFILING) && !defined(__CHECKER__)
|
||||
void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
|
||||
|
||||
#define likely_notrace(x) __builtin_expect(!!(x), 1)
|
||||
#define unlikely_notrace(x) __builtin_expect(!!(x), 0)
|
||||
|
||||
#define __branch_check__(x, expect) ({ \
|
||||
int ______r; \
|
||||
static struct ftrace_branch_data \
|
||||
__attribute__((__aligned__(4))) \
|
||||
__attribute__((section("_ftrace_annotated_branch"))) \
|
||||
______f = { \
|
||||
.func = __func__, \
|
||||
.file = __FILE__, \
|
||||
.line = __LINE__, \
|
||||
}; \
|
||||
______r = likely_notrace(x); \
|
||||
ftrace_likely_update(&______f, ______r, expect); \
|
||||
______r; \
|
||||
})
|
||||
|
||||
/*
|
||||
* Using __builtin_constant_p(x) to ignore cases where the return
|
||||
* value is always the same. This idea is taken from a similar patch
|
||||
* written by Daniel Walker.
|
||||
*/
|
||||
# ifndef likely
|
||||
# define likely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 1))
|
||||
# endif
|
||||
# ifndef unlikely
|
||||
# define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0))
|
||||
# endif
|
||||
|
||||
#ifdef CONFIG_PROFILE_ALL_BRANCHES
|
||||
/*
|
||||
* "Define 'is'", Bill Clinton
|
||||
* "Define 'if'", Steven Rostedt
|
||||
*/
|
||||
#define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
|
||||
#define __trace_if(cond) \
|
||||
if (__builtin_constant_p(!!(cond)) ? !!(cond) : \
|
||||
({ \
|
||||
int ______r; \
|
||||
static struct ftrace_branch_data \
|
||||
__attribute__((__aligned__(4))) \
|
||||
__attribute__((section("_ftrace_branch"))) \
|
||||
______f = { \
|
||||
.func = __func__, \
|
||||
.file = __FILE__, \
|
||||
.line = __LINE__, \
|
||||
}; \
|
||||
______r = !!(cond); \
|
||||
______f.miss_hit[______r]++; \
|
||||
______r; \
|
||||
}))
|
||||
#endif /* CONFIG_PROFILE_ALL_BRANCHES */
|
||||
|
||||
#else
|
||||
# define likely(x) __builtin_expect(!!(x), 1)
|
||||
# define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
#endif
|
||||
|
||||
/* Optimization barrier */
|
||||
#ifndef barrier
|
||||
# define barrier() __memory_barrier()
|
||||
#endif
|
||||
|
||||
#ifndef barrier_data
|
||||
# define barrier_data(ptr) barrier()
|
||||
#endif
|
||||
|
||||
/* Unreachable code */
|
||||
#ifndef unreachable
|
||||
# define unreachable() do { } while (1)
|
||||
#endif
|
||||
|
||||
#ifndef RELOC_HIDE
|
||||
# define RELOC_HIDE(ptr, off) \
|
||||
({ unsigned long __ptr; \
|
||||
__ptr = (unsigned long) (ptr); \
|
||||
(typeof(ptr)) (__ptr + (off)); })
|
||||
#endif
|
||||
|
||||
#ifndef OPTIMIZER_HIDE_VAR
|
||||
#define OPTIMIZER_HIDE_VAR(var) barrier()
|
||||
#endif
|
||||
|
||||
/* Not-quite-unique ID. */
|
||||
#ifndef __UNIQUE_ID
|
||||
# define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __LINE__)
|
||||
#endif
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
#define __READ_ONCE_SIZE \
|
||||
({ \
|
||||
switch (size) { \
|
||||
case 1: *(__u8 *)res = *(volatile __u8 *)p; break; \
|
||||
case 2: *(__u16 *)res = *(volatile __u16 *)p; break; \
|
||||
case 4: *(__u32 *)res = *(volatile __u32 *)p; break; \
|
||||
case 8: *(__u64 *)res = *(volatile __u64 *)p; break; \
|
||||
default: \
|
||||
barrier(); \
|
||||
__builtin_memcpy((void *)res, (const void *)p, size); \
|
||||
barrier(); \
|
||||
} \
|
||||
})
|
||||
|
||||
static __always_inline
|
||||
void __read_once_size(const volatile void *p, void *res, int size)
|
||||
{
|
||||
__READ_ONCE_SIZE;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_KASAN
|
||||
/*
|
||||
* This function is not 'inline' because __no_sanitize_address confilcts
|
||||
* with inlining. Attempt to inline it may cause a build failure.
|
||||
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368
|
||||
* '__maybe_unused' allows us to avoid defined-but-not-used warnings.
|
||||
*/
|
||||
static __no_sanitize_address __maybe_unused
|
||||
void __read_once_size_nocheck(const volatile void *p, void *res, int size)
|
||||
{
|
||||
__READ_ONCE_SIZE;
|
||||
}
|
||||
#else
|
||||
static __always_inline
|
||||
void __read_once_size_nocheck(const volatile void *p, void *res, int size)
|
||||
{
|
||||
__READ_ONCE_SIZE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static __always_inline void __write_once_size(volatile void *p, void *res, int size)
|
||||
{
|
||||
switch (size) {
|
||||
case 1: *(volatile __u8 *)p = *(__u8 *)res; break;
|
||||
case 2: *(volatile __u16 *)p = *(__u16 *)res; break;
|
||||
case 4: *(volatile __u32 *)p = *(__u32 *)res; break;
|
||||
case 8: *(volatile __u64 *)p = *(__u64 *)res; break;
|
||||
default:
|
||||
barrier();
|
||||
__builtin_memcpy((void *)p, (const void *)res, size);
|
||||
barrier();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Prevent the compiler from merging or refetching reads or writes. The
|
||||
* compiler is also forbidden from reordering successive instances of
|
||||
* READ_ONCE, WRITE_ONCE and ACCESS_ONCE (see below), but only when the
|
||||
* compiler is aware of some particular ordering. One way to make the
|
||||
* compiler aware of ordering is to put the two invocations of READ_ONCE,
|
||||
* WRITE_ONCE or ACCESS_ONCE() in different C statements.
|
||||
*
|
||||
* In contrast to ACCESS_ONCE these two macros will also work on aggregate
|
||||
* data types like structs or unions. If the size of the accessed data
|
||||
* type exceeds the word size of the machine (e.g., 32 bits or 64 bits)
|
||||
* READ_ONCE() and WRITE_ONCE() will fall back to memcpy and print a
|
||||
* compile-time warning.
|
||||
*
|
||||
* Their two major use cases are: (1) Mediating communication between
|
||||
* process-level code and irq/NMI handlers, all running on the same CPU,
|
||||
* and (2) Ensuring that the compiler does not fold, spindle, or otherwise
|
||||
* mutilate accesses that either do not require ordering or that interact
|
||||
* with an explicit memory barrier or atomic instruction that provides the
|
||||
* required ordering.
|
||||
*/
|
||||
|
||||
#define __READ_ONCE(x, check) \
|
||||
({ \
|
||||
union { typeof(x) __val; char __c[1]; } __u; \
|
||||
if (check) \
|
||||
__read_once_size(&(x), __u.__c, sizeof(x)); \
|
||||
else \
|
||||
__read_once_size_nocheck(&(x), __u.__c, sizeof(x)); \
|
||||
__u.__val; \
|
||||
})
|
||||
#define READ_ONCE(x) __READ_ONCE(x, 1)
|
||||
|
||||
/*
|
||||
* Use READ_ONCE_NOCHECK() instead of READ_ONCE() if you need
|
||||
* to hide memory access from KASAN.
|
||||
*/
|
||||
#define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0)
|
||||
|
||||
#define WRITE_ONCE(x, val) \
|
||||
({ \
|
||||
union { typeof(x) __val; char __c[1]; } __u = \
|
||||
{ .__val = (__force typeof(x)) (val) }; \
|
||||
__write_once_size(&(x), __u.__c, sizeof(x)); \
|
||||
__u.__val; \
|
||||
})
|
||||
|
||||
/**
|
||||
* smp_cond_acquire() - Spin wait for cond with ACQUIRE ordering
|
||||
* @cond: boolean expression to wait for
|
||||
*
|
||||
* Equivalent to using smp_load_acquire() on the condition variable but employs
|
||||
* the control dependency of the wait to reduce the barrier on many platforms.
|
||||
*
|
||||
* The control dependency provides a LOAD->STORE order, the additional RMB
|
||||
* provides LOAD->LOAD order, together they provide LOAD->{LOAD,STORE} order,
|
||||
* aka. ACQUIRE.
|
||||
*/
|
||||
#define smp_cond_acquire(cond) do { \
|
||||
while (!(cond)) \
|
||||
cpu_relax(); \
|
||||
smp_rmb(); /* ctrl + rmb := acquire */ \
|
||||
} while (0)
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
|
||||
#ifdef __KERNEL__
|
||||
/*
|
||||
* Allow us to mark functions as 'deprecated' and have gcc emit a nice
|
||||
* warning for each use, in hopes of speeding the functions removal.
|
||||
* Usage is:
|
||||
* int __deprecated foo(void)
|
||||
*/
|
||||
#ifndef __deprecated
|
||||
# define __deprecated /* unimplemented */
|
||||
#endif
|
||||
|
||||
#ifdef MODULE
|
||||
#define __deprecated_for_modules __deprecated
|
||||
#else
|
||||
#define __deprecated_for_modules
|
||||
#endif
|
||||
|
||||
#ifndef __must_check
|
||||
#define __must_check
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ENABLE_MUST_CHECK
|
||||
#undef __must_check
|
||||
#define __must_check
|
||||
#endif
|
||||
#ifndef CONFIG_ENABLE_WARN_DEPRECATED
|
||||
#undef __deprecated
|
||||
#undef __deprecated_for_modules
|
||||
#define __deprecated
|
||||
#define __deprecated_for_modules
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Allow us to avoid 'defined but not used' warnings on functions and data,
|
||||
* as well as force them to be emitted to the assembly file.
|
||||
*
|
||||
* As of gcc 3.4, static functions that are not marked with attribute((used))
|
||||
* may be elided from the assembly file. As of gcc 3.4, static data not so
|
||||
* marked will not be elided, but this may change in a future gcc version.
|
||||
*
|
||||
* NOTE: Because distributions shipped with a backported unit-at-a-time
|
||||
* compiler in gcc 3.3, we must define __used to be __attribute__((used))
|
||||
* for gcc >=3.3 instead of 3.4.
|
||||
*
|
||||
* In prior versions of gcc, such functions and data would be emitted, but
|
||||
* would be warned about except with attribute((unused)).
|
||||
*
|
||||
* Mark functions that are referenced only in inline assembly as __used so
|
||||
* the code is emitted even though it appears to be unreferenced.
|
||||
*/
|
||||
#ifndef __used
|
||||
# define __used /* unimplemented */
|
||||
#endif
|
||||
|
||||
#ifndef __maybe_unused
|
||||
# define __maybe_unused /* unimplemented */
|
||||
#endif
|
||||
|
||||
#ifndef __always_unused
|
||||
# define __always_unused /* unimplemented */
|
||||
#endif
|
||||
|
||||
#ifndef noinline
|
||||
#define noinline
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Rather then using noinline to prevent stack consumption, use
|
||||
* noinline_for_stack instead. For documentation reasons.
|
||||
*/
|
||||
#define noinline_for_stack noinline
|
||||
|
||||
#ifndef __always_inline
|
||||
#define __always_inline inline
|
||||
#endif
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
/*
|
||||
* From the GCC manual:
|
||||
*
|
||||
* Many functions do not examine any values except their arguments,
|
||||
* and have no effects except the return value. Basically this is
|
||||
* just slightly more strict class than the `pure' attribute above,
|
||||
* since function is not allowed to read global memory.
|
||||
*
|
||||
* Note that a function that has pointer arguments and examines the
|
||||
* data pointed to must _not_ be declared `const'. Likewise, a
|
||||
* function that calls a non-`const' function usually must not be
|
||||
* `const'. It does not make sense for a `const' function to return
|
||||
* `void'.
|
||||
*/
|
||||
#ifndef __attribute_const__
|
||||
# define __attribute_const__ /* unimplemented */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Tell gcc if a function is cold. The compiler will assume any path
|
||||
* directly leading to the call is unlikely.
|
||||
*/
|
||||
|
||||
#ifndef __cold
|
||||
#define __cold
|
||||
#endif
|
||||
|
||||
/* Simple shorthand for a section definition */
|
||||
#ifndef __section
|
||||
# define __section(S) __attribute__ ((__section__(#S)))
|
||||
#endif
|
||||
|
||||
#ifndef __visible
|
||||
#define __visible
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Assume alignment of return value.
|
||||
*/
|
||||
#ifndef __assume_aligned
|
||||
#define __assume_aligned(a, ...)
|
||||
#endif
|
||||
|
||||
|
||||
/* Are two types/vars the same type (ignoring qualifiers)? */
|
||||
#ifndef __same_type
|
||||
# define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
|
||||
#endif
|
||||
|
||||
/* Is this type a native word size -- useful for atomic operations */
|
||||
#ifndef __native_word
|
||||
# define __native_word(t) (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
|
||||
#endif
|
||||
|
||||
/* Compile time object size, -1 for unknown */
|
||||
#ifndef __compiletime_object_size
|
||||
# define __compiletime_object_size(obj) -1
|
||||
#endif
|
||||
#ifndef __compiletime_warning
|
||||
# define __compiletime_warning(message)
|
||||
#endif
|
||||
#ifndef __compiletime_error
|
||||
# define __compiletime_error(message)
|
||||
/*
|
||||
* Sparse complains of variable sized arrays due to the temporary variable in
|
||||
* __compiletime_assert. Unfortunately we can't just expand it out to make
|
||||
* sparse see a constant array size without breaking compiletime_assert on old
|
||||
* versions of GCC (e.g. 4.2.4), so hide the array from sparse altogether.
|
||||
*/
|
||||
# ifndef __CHECKER__
|
||||
# define __compiletime_error_fallback(condition) \
|
||||
do { ((void)sizeof(char[1 - 2 * condition])); } while (0)
|
||||
# endif
|
||||
#endif
|
||||
#ifndef __compiletime_error_fallback
|
||||
# define __compiletime_error_fallback(condition) do { } while (0)
|
||||
#endif
|
||||
|
||||
#ifdef __OPTIMIZE__
|
||||
# define __compiletime_assert(condition, msg, prefix, suffix) \
|
||||
do { \
|
||||
bool __cond = !(condition); \
|
||||
extern void prefix ## suffix(void) __compiletime_error(msg); \
|
||||
if (__cond) \
|
||||
prefix ## suffix(); \
|
||||
__compiletime_error_fallback(__cond); \
|
||||
} while (0)
|
||||
#else
|
||||
# define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0)
|
||||
#endif
|
||||
|
||||
#define _compiletime_assert(condition, msg, prefix, suffix) \
|
||||
__compiletime_assert(condition, msg, prefix, suffix)
|
||||
|
||||
/**
|
||||
* compiletime_assert - break build and emit msg if condition is false
|
||||
* @condition: a compile-time constant condition to check
|
||||
* @msg: a message to emit if condition is false
|
||||
*
|
||||
* In tradition of POSIX assert, this macro will break the build if the
|
||||
* supplied condition is *false*, emitting the supplied error message if the
|
||||
* compiler has support to do so.
|
||||
*/
|
||||
#define compiletime_assert(condition, msg) \
|
||||
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
|
||||
|
||||
#define compiletime_assert_atomic_type(t) \
|
||||
compiletime_assert(__native_word(t), \
|
||||
"Need native word sized stores/loads for atomicity.")
|
||||
|
||||
/*
|
||||
* Prevent the compiler from merging or refetching accesses. The compiler
|
||||
* is also forbidden from reordering successive instances of ACCESS_ONCE(),
|
||||
* but only when the compiler is aware of some particular ordering. One way
|
||||
* to make the compiler aware of ordering is to put the two invocations of
|
||||
* ACCESS_ONCE() in different C statements.
|
||||
*
|
||||
* ACCESS_ONCE will only work on scalar types. For union types, ACCESS_ONCE
|
||||
* on a union member will work as long as the size of the member matches the
|
||||
* size of the union and the size is smaller than word size.
|
||||
*
|
||||
* The major use cases of ACCESS_ONCE used to be (1) Mediating communication
|
||||
* between process-level code and irq/NMI handlers, all running on the same CPU,
|
||||
* and (2) Ensuring that the compiler does not fold, spindle, or otherwise
|
||||
* mutilate accesses that either do not require ordering or that interact
|
||||
* with an explicit memory barrier or atomic instruction that provides the
|
||||
* required ordering.
|
||||
*
|
||||
* If possible use READ_ONCE()/WRITE_ONCE() instead.
|
||||
*/
|
||||
#define __ACCESS_ONCE(x) ({ \
|
||||
__maybe_unused typeof(x) __var = (__force typeof(x)) 0; \
|
||||
(volatile typeof(x) *)&(x); })
|
||||
#define ACCESS_ONCE(x) (*__ACCESS_ONCE(x))
|
||||
|
||||
/**
|
||||
* lockless_dereference() - safely load a pointer for later dereference
|
||||
* @p: The pointer to load
|
||||
*
|
||||
* Similar to rcu_dereference(), but for situations where the pointed-to
|
||||
* object's lifetime is managed by something other than RCU. That
|
||||
* "something other" might be reference counting or simple immortality.
|
||||
*/
|
||||
#define lockless_dereference(p) \
|
||||
({ \
|
||||
typeof(p) _________p1 = READ_ONCE(p); \
|
||||
smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
|
||||
(_________p1); \
|
||||
})
|
||||
|
||||
/* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
|
||||
#ifdef CONFIG_KPROBES
|
||||
# define __kprobes __attribute__((__section__(".kprobes.text")))
|
||||
# define nokprobe_inline __always_inline
|
||||
#else
|
||||
# define __kprobes
|
||||
# define nokprobe_inline inline
|
||||
#endif
|
||||
#endif /* __LINUX_COMPILER_H */
|
||||
@@ -0,0 +1,173 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LINUX_COMPLETION_H
|
||||
#define __LINUX_COMPLETION_H
|
||||
|
||||
/*
|
||||
* (C) Copyright 2001 Linus Torvalds
|
||||
*
|
||||
* Atomic wait-for-completion handler data structures.
|
||||
* See kernel/sched/completion.c for details.
|
||||
*/
|
||||
#ifndef __UBOOT__
|
||||
#include <linux/wait.h>
|
||||
#endif /* __UBOOT__ */
|
||||
|
||||
/*
|
||||
* struct completion - structure used to maintain state for a "completion"
|
||||
*
|
||||
* This is the opaque structure used to maintain the state for a "completion".
|
||||
* Completions currently use a FIFO to queue threads that have to wait for
|
||||
* the "completion" event.
|
||||
*
|
||||
* See also: complete(), wait_for_completion() (and friends _timeout,
|
||||
* _interruptible, _interruptible_timeout, and _killable), init_completion(),
|
||||
* reinit_completion(), and macros DECLARE_COMPLETION(),
|
||||
* DECLARE_COMPLETION_ONSTACK().
|
||||
*/
|
||||
struct completion {
|
||||
unsigned int done;
|
||||
#ifndef __UBOOT__
|
||||
wait_queue_head_t wait;
|
||||
#endif /* __UBOOT__ */
|
||||
};
|
||||
|
||||
#define init_completion_map(x, m) __init_completion(x)
|
||||
#define init_completion(x) __init_completion(x)
|
||||
static inline void complete_acquire(struct completion *x) {}
|
||||
static inline void complete_release(struct completion *x) {}
|
||||
|
||||
#define COMPLETION_INITIALIZER(work) \
|
||||
{ 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
|
||||
|
||||
#define COMPLETION_INITIALIZER_ONSTACK_MAP(work, map) \
|
||||
(*({ init_completion_map(&(work), &(map)); &(work); }))
|
||||
|
||||
#define COMPLETION_INITIALIZER_ONSTACK(work) \
|
||||
(*({ init_completion(&work); &work; }))
|
||||
|
||||
/**
|
||||
* DECLARE_COMPLETION - declare and initialize a completion structure
|
||||
* @work: identifier for the completion structure
|
||||
*
|
||||
* This macro declares and initializes a completion structure. Generally used
|
||||
* for static declarations. You should use the _ONSTACK variant for automatic
|
||||
* variables.
|
||||
*/
|
||||
#define DECLARE_COMPLETION(work) \
|
||||
struct completion work = COMPLETION_INITIALIZER(work)
|
||||
|
||||
/*
|
||||
* Lockdep needs to run a non-constant initializer for on-stack
|
||||
* completions - so we use the _ONSTACK() variant for those that
|
||||
* are on the kernel stack:
|
||||
*/
|
||||
/**
|
||||
* DECLARE_COMPLETION_ONSTACK - declare and initialize a completion structure
|
||||
* @work: identifier for the completion structure
|
||||
*
|
||||
* This macro declares and initializes a completion structure on the kernel
|
||||
* stack.
|
||||
*/
|
||||
#ifdef CONFIG_LOCKDEP
|
||||
# define DECLARE_COMPLETION_ONSTACK(work) \
|
||||
struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
|
||||
# define DECLARE_COMPLETION_ONSTACK_MAP(work, map) \
|
||||
struct completion work = COMPLETION_INITIALIZER_ONSTACK_MAP(work, map)
|
||||
#else
|
||||
# define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
|
||||
# define DECLARE_COMPLETION_ONSTACK_MAP(work, map) DECLARE_COMPLETION(work)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* init_completion - Initialize a dynamically allocated completion
|
||||
* @x: pointer to completion structure that is to be initialized
|
||||
*
|
||||
* This inline function will initialize a dynamically created completion
|
||||
* structure.
|
||||
*/
|
||||
static inline void __init_completion(struct completion *x)
|
||||
{
|
||||
x->done = 0;
|
||||
#ifndef __UBOOT__
|
||||
init_waitqueue_head(&x->wait);
|
||||
#endif /* __UBOOT__ */
|
||||
}
|
||||
|
||||
/**
|
||||
* reinit_completion - reinitialize a completion structure
|
||||
* @x: pointer to completion structure that is to be reinitialized
|
||||
*
|
||||
* This inline function should be used to reinitialize a completion structure so it can
|
||||
* be reused. This is especially important after complete_all() is used.
|
||||
*/
|
||||
static inline void reinit_completion(struct completion *x)
|
||||
{
|
||||
x->done = 0;
|
||||
}
|
||||
|
||||
#ifndef __UBOOT__
|
||||
extern void wait_for_completion(struct completion *);
|
||||
extern void wait_for_completion_io(struct completion *);
|
||||
extern int wait_for_completion_interruptible(struct completion *x);
|
||||
extern int wait_for_completion_killable(struct completion *x);
|
||||
extern unsigned long wait_for_completion_timeout(struct completion *x,
|
||||
unsigned long timeout);
|
||||
extern unsigned long wait_for_completion_io_timeout(struct completion *x,
|
||||
unsigned long timeout);
|
||||
extern long wait_for_completion_interruptible_timeout(
|
||||
struct completion *x, unsigned long timeout);
|
||||
extern long wait_for_completion_killable_timeout(
|
||||
struct completion *x, unsigned long timeout);
|
||||
extern bool try_wait_for_completion(struct completion *x);
|
||||
extern bool completion_done(struct completion *x);
|
||||
|
||||
extern void complete(struct completion *);
|
||||
extern void complete_all(struct completion *);
|
||||
|
||||
#else /* __UBOOT __ */
|
||||
|
||||
#define wait_for_completion(x) do {} while (0)
|
||||
#define wait_for_completion_io(x) do {} while (0)
|
||||
|
||||
inline int wait_for_completion_interruptible(struct completion *x)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
inline int wait_for_completion_killable(struct completion *x)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
inline unsigned long wait_for_completion_timeout(struct completion *x,
|
||||
unsigned long timeout)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
inline unsigned long wait_for_completion_io_timeout(struct completion *x,
|
||||
unsigned long timeout)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
inline long wait_for_completion_interruptible_timeout(struct completion *x,
|
||||
unsigned long timeout)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
inline long wait_for_completion_killable_timeout(struct completion *x,
|
||||
unsigned long timeout)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
inline bool try_wait_for_completion(struct completion *x)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
inline bool completion_done(struct completion *x)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define complete(x) do {} while (0)
|
||||
#define complete_all(x) do {} while (0)
|
||||
#endif /* __UBOOT__ */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
||||
#ifndef _LINUX_CONST_H
|
||||
#define _LINUX_CONST_H
|
||||
|
||||
/* const.h: Macros for dealing with constants. */
|
||||
|
||||
/* Some constant macros are used in both assembler and
|
||||
* C code. Therefore we cannot annotate them always with
|
||||
* 'UL' and other type specifiers unilaterally. We
|
||||
* use the following macros to deal with this.
|
||||
*
|
||||
* Similarly, _AT() will cast an expression with a type in C, but
|
||||
* leave it unchanged in asm.
|
||||
*/
|
||||
|
||||
#ifdef __ASSEMBLY__
|
||||
#define _AC(X,Y) X
|
||||
#define _AT(T,X) X
|
||||
#else
|
||||
#define __AC(X,Y) (X##Y)
|
||||
#define _AC(X,Y) __AC(X,Y)
|
||||
#define _AT(T,X) ((T)(X))
|
||||
#endif
|
||||
|
||||
#define _UL(x) (_AC(x, UL))
|
||||
#define _ULL(x) (_AC(x, ULL))
|
||||
|
||||
#define _BITUL(x) (_UL(1) << (x))
|
||||
#define _BITULL(x) (_ULL(1) << (x))
|
||||
|
||||
#define UL(x) (_UL(x))
|
||||
#define ULL(x) (_ULL(x))
|
||||
|
||||
#endif /* _LINUX_CONST_H */
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* crc32.h
|
||||
* See linux/lib/crc32.c for license and changes
|
||||
*/
|
||||
#ifndef _LINUX_CRC32_H
|
||||
#define _LINUX_CRC32_H
|
||||
|
||||
#include <linux/types.h>
|
||||
/* #include <linux/bitrev.h> */
|
||||
|
||||
extern u32 crc32_le(u32 crc, unsigned char const *p, size_t len);
|
||||
/* extern u32 crc32_be(u32 crc, unsigned char const *p, size_t len); */
|
||||
|
||||
#define crc32(seed, data, length) crc32_le(seed, (unsigned char const *)data, length)
|
||||
|
||||
/*
|
||||
* Helpers for hash table generation of ethernet nics:
|
||||
*
|
||||
* Ethernet sends the least significant bit of a byte first, thus crc32_le
|
||||
* is used. The output of crc32_le is bit reversed [most significant bit
|
||||
* is in bit nr 0], thus it must be reversed before use. Except for
|
||||
* nics that bit swap the result internally...
|
||||
*/
|
||||
/* #define ether_crc(length, data) bitrev32(crc32_le(~0, data, length)) */
|
||||
/* #define ether_crc_le(length, data) crc32_le(~0, data, length) */
|
||||
|
||||
#endif /* _LINUX_CRC32_H */
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef _LINUX_CRC7_H
|
||||
#define _LINUX_CRC7_H
|
||||
#include <linux/types.h>
|
||||
|
||||
extern const u8 crc7_syndrome_table[256];
|
||||
|
||||
static inline u8 crc7_byte(u8 crc, u8 data)
|
||||
{
|
||||
return crc7_syndrome_table[(crc << 1) ^ data];
|
||||
}
|
||||
|
||||
extern u8 crc7(u8 crc, const u8 *buffer, size_t len);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,60 @@
|
||||
#ifndef _LINUX_CTYPE_H
|
||||
#define _LINUX_CTYPE_H
|
||||
|
||||
/*
|
||||
* NOTE! This ctype does not handle EOF like the standard C
|
||||
* library is required to.
|
||||
*/
|
||||
|
||||
#define _U 0x01 /* upper */
|
||||
#define _L 0x02 /* lower */
|
||||
#define _D 0x04 /* digit */
|
||||
#define _C 0x08 /* cntrl */
|
||||
#define _P 0x10 /* punct */
|
||||
#define _S 0x20 /* white space (space/lf/tab) */
|
||||
#define _X 0x40 /* hex digit */
|
||||
#define _SP 0x80 /* hard space (0x20) */
|
||||
|
||||
extern const unsigned char _ctype[];
|
||||
|
||||
#define __ismask(x) (_ctype[(int)(unsigned char)(x)])
|
||||
|
||||
#define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0)
|
||||
#define isalpha(c) ((__ismask(c)&(_U|_L)) != 0)
|
||||
#define iscntrl(c) ((__ismask(c)&(_C)) != 0)
|
||||
#define isdigit(c) ((__ismask(c)&(_D)) != 0)
|
||||
#define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)
|
||||
#define islower(c) ((__ismask(c)&(_L)) != 0)
|
||||
#define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
|
||||
#define ispunct(c) ((__ismask(c)&(_P)) != 0)
|
||||
#define isspace(c) ((__ismask(c)&(_S)) != 0)
|
||||
#define isupper(c) ((__ismask(c)&(_U)) != 0)
|
||||
#define isxdigit(c) ((__ismask(c)&(_D|_X)) != 0)
|
||||
|
||||
/*
|
||||
* Rather than doubling the size of the _ctype lookup table to hold a 'blank'
|
||||
* flag, just check for space or tab.
|
||||
*/
|
||||
#define isblank(c) (c == ' ' || c == '\t')
|
||||
|
||||
#define isascii(c) (((unsigned char)(c))<=0x7f)
|
||||
#define toascii(c) (((unsigned char)(c))&0x7f)
|
||||
|
||||
static inline unsigned char __tolower(unsigned char c)
|
||||
{
|
||||
if (isupper(c))
|
||||
c -= 'A'-'a';
|
||||
return c;
|
||||
}
|
||||
|
||||
static inline unsigned char __toupper(unsigned char c)
|
||||
{
|
||||
if (islower(c))
|
||||
c -= 'a'-'A';
|
||||
return c;
|
||||
}
|
||||
|
||||
#define tolower(c) __tolower(c)
|
||||
#define toupper(c) __toupper(c)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
|
||||
#ifndef _LINUX_DELAY_H
|
||||
#define _LINUX_DELAY_H
|
||||
|
||||
#include <linux/kernel.h>
|
||||
|
||||
void __udelay(unsigned long usec);
|
||||
void udelay(unsigned long usec);
|
||||
|
||||
static inline void mdelay(unsigned long msec)
|
||||
{
|
||||
udelay(1000 * msec);
|
||||
}
|
||||
|
||||
static inline void ndelay(unsigned long nsec)
|
||||
{
|
||||
udelay(DIV_ROUND_UP(nsec, 1000));
|
||||
}
|
||||
|
||||
#endif /* defined(_LINUX_DELAY_H) */
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef _LINUX_DMA_DIRECTION_H
|
||||
#define _LINUX_DMA_DIRECTION_H
|
||||
/*
|
||||
* These definitions mirror those in pci.h, so they can be used
|
||||
* interchangeably with their PCI_ counterparts.
|
||||
*/
|
||||
enum dma_data_direction {
|
||||
DMA_BIDIRECTIONAL = 0,
|
||||
DMA_TO_DEVICE = 1,
|
||||
DMA_FROM_DEVICE = 2,
|
||||
DMA_NONE = 3,
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,406 @@
|
||||
/*
|
||||
* Copyright © 2008 Keith Packard
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||
* documentation for any purpose is hereby granted without fee, provided that
|
||||
* the above copyright notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting documentation, and
|
||||
* that the name of the copyright holders not be used in advertising or
|
||||
* publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. The copyright holders make no representations
|
||||
* about the suitability of this software for any purpose. It is provided "as
|
||||
* is" without express or implied warranty.
|
||||
*
|
||||
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
||||
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _DRM_DP_HELPER_H_
|
||||
#define _DRM_DP_HELPER_H_
|
||||
|
||||
/*
|
||||
* Unless otherwise noted, all values are from the DP 1.1a spec. Note that
|
||||
* DP and DPCD versions are independent. Differences from 1.0 are not noted,
|
||||
* 1.0 devices basically don't exist in the wild.
|
||||
*
|
||||
* Abbreviations, in chronological order:
|
||||
*
|
||||
* eDP: Embedded DisplayPort version 1
|
||||
* DPI: DisplayPort Interoperability Guideline v1.1a
|
||||
* 1.2: DisplayPort 1.2
|
||||
* MST: Multistream Transport - part of DP 1.2a
|
||||
*
|
||||
* 1.2 formally includes both eDP and DPI definitions.
|
||||
*/
|
||||
|
||||
#define DP_AUX_I2C_WRITE 0x0
|
||||
#define DP_AUX_I2C_READ 0x1
|
||||
#define DP_AUX_I2C_STATUS 0x2
|
||||
#define DP_AUX_I2C_MOT 0x4
|
||||
#define DP_AUX_NATIVE_WRITE 0x8
|
||||
#define DP_AUX_NATIVE_READ 0x9
|
||||
|
||||
#define DP_AUX_NATIVE_REPLY_ACK (0x0 << 0)
|
||||
#define DP_AUX_NATIVE_REPLY_NACK (0x1 << 0)
|
||||
#define DP_AUX_NATIVE_REPLY_DEFER (0x2 << 0)
|
||||
#define DP_AUX_NATIVE_REPLY_MASK (0x3 << 0)
|
||||
|
||||
#define DP_AUX_I2C_REPLY_ACK (0x0 << 2)
|
||||
#define DP_AUX_I2C_REPLY_NACK (0x1 << 2)
|
||||
#define DP_AUX_I2C_REPLY_DEFER (0x2 << 2)
|
||||
#define DP_AUX_I2C_REPLY_MASK (0x3 << 2)
|
||||
|
||||
/* AUX CH addresses */
|
||||
/* DPCD */
|
||||
#define DP_DPCD_REV 0x000
|
||||
|
||||
#define DP_MAX_LINK_RATE 0x001
|
||||
|
||||
#define DP_MAX_LANE_COUNT 0x002
|
||||
# define DP_MAX_LANE_COUNT_MASK 0x1f
|
||||
# define DP_TPS3_SUPPORTED (1 << 6) /* 1.2 */
|
||||
# define DP_ENHANCED_FRAME_CAP (1 << 7)
|
||||
|
||||
#define DP_MAX_DOWNSPREAD 0x003
|
||||
# define DP_NO_AUX_HANDSHAKE_LINK_TRAINING (1 << 6)
|
||||
|
||||
#define DP_NORP 0x004
|
||||
|
||||
#define DP_DOWNSTREAMPORT_PRESENT 0x005
|
||||
# define DP_DWN_STRM_PORT_PRESENT (1 << 0)
|
||||
# define DP_DWN_STRM_PORT_TYPE_MASK 0x06
|
||||
# define DP_DWN_STRM_PORT_TYPE_DP (0 << 1)
|
||||
# define DP_DWN_STRM_PORT_TYPE_ANALOG (1 << 1)
|
||||
# define DP_DWN_STRM_PORT_TYPE_TMDS (2 << 1)
|
||||
# define DP_DWN_STRM_PORT_TYPE_OTHER (3 << 1)
|
||||
# define DP_FORMAT_CONVERSION (1 << 3)
|
||||
# define DP_DETAILED_CAP_INFO_AVAILABLE (1 << 4) /* DPI */
|
||||
|
||||
#define DP_MAIN_LINK_CHANNEL_CODING 0x006
|
||||
|
||||
#define DP_DOWN_STREAM_PORT_COUNT 0x007
|
||||
# define DP_PORT_COUNT_MASK 0x0f
|
||||
# define DP_MSA_TIMING_PAR_IGNORED (1 << 6) /* eDP */
|
||||
# define DP_OUI_SUPPORT (1 << 7)
|
||||
|
||||
#define DP_I2C_SPEED_CAP 0x00c /* DPI */
|
||||
# define DP_I2C_SPEED_1K 0x01
|
||||
# define DP_I2C_SPEED_5K 0x02
|
||||
# define DP_I2C_SPEED_10K 0x04
|
||||
# define DP_I2C_SPEED_100K 0x08
|
||||
# define DP_I2C_SPEED_400K 0x10
|
||||
# define DP_I2C_SPEED_1M 0x20
|
||||
|
||||
#define DP_EDP_CONFIGURATION_CAP 0x00d /* XXX 1.2? */
|
||||
#define DP_TRAINING_AUX_RD_INTERVAL 0x00e /* XXX 1.2? */
|
||||
|
||||
/* Multiple stream transport */
|
||||
#define DP_FAUX_CAP 0x020 /* 1.2 */
|
||||
# define DP_FAUX_CAP_1 (1 << 0)
|
||||
|
||||
#define DP_MSTM_CAP 0x021 /* 1.2 */
|
||||
# define DP_MST_CAP (1 << 0)
|
||||
|
||||
#define DP_GUID 0x030 /* 1.2 */
|
||||
|
||||
#define DP_PSR_SUPPORT 0x070 /* XXX 1.2? */
|
||||
# define DP_PSR_IS_SUPPORTED 1
|
||||
#define DP_PSR_CAPS 0x071 /* XXX 1.2? */
|
||||
# define DP_PSR_NO_TRAIN_ON_EXIT 1
|
||||
# define DP_PSR_SETUP_TIME_330 (0 << 1)
|
||||
# define DP_PSR_SETUP_TIME_275 (1 << 1)
|
||||
# define DP_PSR_SETUP_TIME_220 (2 << 1)
|
||||
# define DP_PSR_SETUP_TIME_165 (3 << 1)
|
||||
# define DP_PSR_SETUP_TIME_110 (4 << 1)
|
||||
# define DP_PSR_SETUP_TIME_55 (5 << 1)
|
||||
# define DP_PSR_SETUP_TIME_0 (6 << 1)
|
||||
# define DP_PSR_SETUP_TIME_MASK (7 << 1)
|
||||
# define DP_PSR_SETUP_TIME_SHIFT 1
|
||||
|
||||
/*
|
||||
* 0x80-0x8f describe downstream port capabilities, but there are two layouts
|
||||
* based on whether DP_DETAILED_CAP_INFO_AVAILABLE was set. If it was not,
|
||||
* each port's descriptor is one byte wide. If it was set, each port's is
|
||||
* four bytes wide, starting with the one byte from the base info. As of
|
||||
* DP interop v1.1a only VGA defines additional detail.
|
||||
*/
|
||||
|
||||
/* offset 0 */
|
||||
#define DP_DOWNSTREAM_PORT_0 0x80
|
||||
# define DP_DS_PORT_TYPE_MASK (7 << 0)
|
||||
# define DP_DS_PORT_TYPE_DP 0
|
||||
# define DP_DS_PORT_TYPE_VGA 1
|
||||
# define DP_DS_PORT_TYPE_DVI 2
|
||||
# define DP_DS_PORT_TYPE_HDMI 3
|
||||
# define DP_DS_PORT_TYPE_NON_EDID 4
|
||||
# define DP_DS_PORT_HPD (1 << 3)
|
||||
/* offset 1 for VGA is maximum megapixels per second / 8 */
|
||||
/* offset 2 */
|
||||
# define DP_DS_VGA_MAX_BPC_MASK (3 << 0)
|
||||
# define DP_DS_VGA_8BPC 0
|
||||
# define DP_DS_VGA_10BPC 1
|
||||
# define DP_DS_VGA_12BPC 2
|
||||
# define DP_DS_VGA_16BPC 3
|
||||
|
||||
/* link configuration */
|
||||
#define DP_LINK_BW_SET 0x100
|
||||
# define DP_LINK_BW_1_62 0x06
|
||||
# define DP_LINK_BW_2_7 0x0a
|
||||
# define DP_LINK_BW_5_4 0x14 /* 1.2 */
|
||||
|
||||
#define DP_LANE_COUNT_SET 0x101
|
||||
# define DP_LANE_COUNT_MASK 0x0f
|
||||
# define DP_LANE_COUNT_ENHANCED_FRAME_EN (1 << 7)
|
||||
|
||||
#define DP_TRAINING_PATTERN_SET 0x102
|
||||
# define DP_TRAINING_PATTERN_DISABLE 0
|
||||
# define DP_TRAINING_PATTERN_1 1
|
||||
# define DP_TRAINING_PATTERN_2 2
|
||||
# define DP_TRAINING_PATTERN_3 3 /* 1.2 */
|
||||
# define DP_TRAINING_PATTERN_MASK 0x3
|
||||
|
||||
# define DP_LINK_QUAL_PATTERN_DISABLE (0 << 2)
|
||||
# define DP_LINK_QUAL_PATTERN_D10_2 (1 << 2)
|
||||
# define DP_LINK_QUAL_PATTERN_ERROR_RATE (2 << 2)
|
||||
# define DP_LINK_QUAL_PATTERN_PRBS7 (3 << 2)
|
||||
# define DP_LINK_QUAL_PATTERN_MASK (3 << 2)
|
||||
|
||||
# define DP_RECOVERED_CLOCK_OUT_EN (1 << 4)
|
||||
# define DP_LINK_SCRAMBLING_DISABLE (1 << 5)
|
||||
|
||||
# define DP_SYMBOL_ERROR_COUNT_BOTH (0 << 6)
|
||||
# define DP_SYMBOL_ERROR_COUNT_DISPARITY (1 << 6)
|
||||
# define DP_SYMBOL_ERROR_COUNT_SYMBOL (2 << 6)
|
||||
# define DP_SYMBOL_ERROR_COUNT_MASK (3 << 6)
|
||||
|
||||
#define DP_TRAINING_LANE0_SET 0x103
|
||||
#define DP_TRAINING_LANE1_SET 0x104
|
||||
#define DP_TRAINING_LANE2_SET 0x105
|
||||
#define DP_TRAINING_LANE3_SET 0x106
|
||||
|
||||
# define DP_TRAIN_VOLTAGE_SWING_MASK 0x3
|
||||
# define DP_TRAIN_VOLTAGE_SWING_SHIFT 0
|
||||
# define DP_TRAIN_MAX_SWING_REACHED (1 << 2)
|
||||
# define DP_TRAIN_VOLTAGE_SWING_LEVEL_0 (0 << 0)
|
||||
# define DP_TRAIN_VOLTAGE_SWING_LEVEL_1 (1 << 0)
|
||||
# define DP_TRAIN_VOLTAGE_SWING_LEVEL_2 (2 << 0)
|
||||
# define DP_TRAIN_VOLTAGE_SWING_LEVEL_3 (3 << 0)
|
||||
|
||||
# define DP_TRAIN_PRE_EMPHASIS_MASK (3 << 3)
|
||||
# define DP_TRAIN_PRE_EMPH_LEVEL_0 (0 << 3)
|
||||
# define DP_TRAIN_PRE_EMPH_LEVEL_1 (1 << 3)
|
||||
# define DP_TRAIN_PRE_EMPH_LEVEL_2 (2 << 3)
|
||||
# define DP_TRAIN_PRE_EMPH_LEVEL_3 (3 << 3)
|
||||
|
||||
# define DP_TRAIN_PRE_EMPHASIS_SHIFT 3
|
||||
# define DP_TRAIN_MAX_PRE_EMPHASIS_REACHED (1 << 5)
|
||||
|
||||
#define DP_DOWNSPREAD_CTRL 0x107
|
||||
# define DP_SPREAD_AMP_0_5 (1 << 4)
|
||||
# define DP_MSA_TIMING_PAR_IGNORE_EN (1 << 7) /* eDP */
|
||||
|
||||
#define DP_MAIN_LINK_CHANNEL_CODING_SET 0x108
|
||||
# define DP_SET_ANSI_8B10B (1 << 0)
|
||||
|
||||
#define DP_I2C_SPEED_CONTROL_STATUS 0x109 /* DPI */
|
||||
/* bitmask as for DP_I2C_SPEED_CAP */
|
||||
|
||||
#define DP_EDP_CONFIGURATION_SET 0x10a /* XXX 1.2? */
|
||||
|
||||
#define DP_MSTM_CTRL 0x111 /* 1.2 */
|
||||
# define DP_MST_EN (1 << 0)
|
||||
# define DP_UP_REQ_EN (1 << 1)
|
||||
# define DP_UPSTREAM_IS_SRC (1 << 2)
|
||||
|
||||
#define DP_PSR_EN_CFG 0x170 /* XXX 1.2? */
|
||||
# define DP_PSR_ENABLE (1 << 0)
|
||||
# define DP_PSR_MAIN_LINK_ACTIVE (1 << 1)
|
||||
# define DP_PSR_CRC_VERIFICATION (1 << 2)
|
||||
# define DP_PSR_FRAME_CAPTURE (1 << 3)
|
||||
|
||||
#define DP_ADAPTER_CTRL 0x1a0
|
||||
# define DP_ADAPTER_CTRL_FORCE_LOAD_SENSE (1 << 0)
|
||||
|
||||
#define DP_BRANCH_DEVICE_CTRL 0x1a1
|
||||
# define DP_BRANCH_DEVICE_IRQ_HPD (1 << 0)
|
||||
|
||||
#define DP_PAYLOAD_ALLOCATE_SET 0x1c0
|
||||
#define DP_PAYLOAD_ALLOCATE_START_TIME_SLOT 0x1c1
|
||||
#define DP_PAYLOAD_ALLOCATE_TIME_SLOT_COUNT 0x1c2
|
||||
|
||||
#define DP_SINK_COUNT 0x200
|
||||
/* prior to 1.2 bit 7 was reserved mbz */
|
||||
# define DP_GET_SINK_COUNT(x) ((((x) & 0x80) >> 1) | ((x) & 0x3f))
|
||||
# define DP_SINK_CP_READY (1 << 6)
|
||||
|
||||
#define DP_DEVICE_SERVICE_IRQ_VECTOR 0x201
|
||||
# define DP_REMOTE_CONTROL_COMMAND_PENDING (1 << 0)
|
||||
# define DP_AUTOMATED_TEST_REQUEST (1 << 1)
|
||||
# define DP_CP_IRQ (1 << 2)
|
||||
# define DP_MCCS_IRQ (1 << 3)
|
||||
# define DP_DOWN_REP_MSG_RDY (1 << 4) /* 1.2 MST */
|
||||
# define DP_UP_REQ_MSG_RDY (1 << 5) /* 1.2 MST */
|
||||
# define DP_SINK_SPECIFIC_IRQ (1 << 6)
|
||||
|
||||
#define DP_LANE0_1_STATUS 0x202
|
||||
#define DP_LANE2_3_STATUS 0x203
|
||||
# define DP_LANE_CR_DONE (1 << 0)
|
||||
# define DP_LANE_CHANNEL_EQ_DONE (1 << 1)
|
||||
# define DP_LANE_SYMBOL_LOCKED (1 << 2)
|
||||
|
||||
#define DP_CHANNEL_EQ_BITS (DP_LANE_CR_DONE | \
|
||||
DP_LANE_CHANNEL_EQ_DONE | \
|
||||
DP_LANE_SYMBOL_LOCKED)
|
||||
|
||||
#define DP_LANE_ALIGN_STATUS_UPDATED 0x204
|
||||
|
||||
#define DP_INTERLANE_ALIGN_DONE (1 << 0)
|
||||
#define DP_DOWNSTREAM_PORT_STATUS_CHANGED (1 << 6)
|
||||
#define DP_LINK_STATUS_UPDATED (1 << 7)
|
||||
|
||||
#define DP_SINK_STATUS 0x205
|
||||
#define DP_SINK_STATUS_PORT0_IN_SYNC (1 << 0)
|
||||
|
||||
#define DP_RECEIVE_PORT_0_STATUS (1 << 0)
|
||||
#define DP_RECEIVE_PORT_1_STATUS (1 << 1)
|
||||
|
||||
#define DP_ADJUST_REQUEST_LANE0_1 0x206
|
||||
#define DP_ADJUST_REQUEST_LANE2_3 0x207
|
||||
# define DP_ADJUST_VOLTAGE_SWING_LANE0_MASK 0x03
|
||||
# define DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT 0
|
||||
# define DP_ADJUST_PRE_EMPHASIS_LANE0_MASK 0x0c
|
||||
# define DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT 2
|
||||
# define DP_ADJUST_VOLTAGE_SWING_LANE1_MASK 0x30
|
||||
# define DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT 4
|
||||
# define DP_ADJUST_PRE_EMPHASIS_LANE1_MASK 0xc0
|
||||
# define DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT 6
|
||||
|
||||
#define DP_TEST_REQUEST 0x218
|
||||
# define DP_TEST_LINK_TRAINING (1 << 0)
|
||||
# define DP_TEST_LINK_VIDEO_PATTERN (1 << 1)
|
||||
# define DP_TEST_LINK_EDID_READ (1 << 2)
|
||||
# define DP_TEST_LINK_PHY_TEST_PATTERN (1 << 3) /* DPCD >= 1.1 */
|
||||
# define DP_TEST_LINK_FAUX_PATTERN (1 << 4) /* DPCD >= 1.2 */
|
||||
|
||||
#define DP_TEST_LINK_RATE 0x219
|
||||
# define DP_LINK_RATE_162 (0x6)
|
||||
# define DP_LINK_RATE_27 (0xa)
|
||||
|
||||
#define DP_TEST_LANE_COUNT 0x220
|
||||
|
||||
#define DP_TEST_PATTERN 0x221
|
||||
|
||||
#define DP_TEST_CRC_R_CR 0x240
|
||||
#define DP_TEST_CRC_G_Y 0x242
|
||||
#define DP_TEST_CRC_B_CB 0x244
|
||||
|
||||
#define DP_TEST_SINK_MISC 0x246
|
||||
#define DP_TEST_CRC_SUPPORTED (1 << 5)
|
||||
|
||||
#define DP_TEST_RESPONSE 0x260
|
||||
# define DP_TEST_ACK (1 << 0)
|
||||
# define DP_TEST_NAK (1 << 1)
|
||||
# define DP_TEST_EDID_CHECKSUM_WRITE (1 << 2)
|
||||
|
||||
#define DP_TEST_EDID_CHECKSUM 0x261
|
||||
|
||||
#define DP_TEST_SINK 0x270
|
||||
#define DP_TEST_SINK_START (1 << 0)
|
||||
|
||||
#define DP_PAYLOAD_TABLE_UPDATE_STATUS 0x2c0 /* 1.2 MST */
|
||||
# define DP_PAYLOAD_TABLE_UPDATED (1 << 0)
|
||||
# define DP_PAYLOAD_ACT_HANDLED (1 << 1)
|
||||
|
||||
#define DP_VC_PAYLOAD_ID_SLOT_1 0x2c1 /* 1.2 MST */
|
||||
/* up to ID_SLOT_63 at 0x2ff */
|
||||
|
||||
#define DP_SOURCE_OUI 0x300
|
||||
#define DP_SINK_OUI 0x400
|
||||
#define DP_BRANCH_OUI 0x500
|
||||
|
||||
#define DP_SET_POWER 0x600
|
||||
# define DP_SET_POWER_D0 0x1
|
||||
# define DP_SET_POWER_D3 0x2
|
||||
# define DP_SET_POWER_MASK 0x3
|
||||
|
||||
#define DP_SIDEBAND_MSG_DOWN_REQ_BASE 0x1000 /* 1.2 MST */
|
||||
#define DP_SIDEBAND_MSG_UP_REP_BASE 0x1200 /* 1.2 MST */
|
||||
#define DP_SIDEBAND_MSG_DOWN_REP_BASE 0x1400 /* 1.2 MST */
|
||||
#define DP_SIDEBAND_MSG_UP_REQ_BASE 0x1600 /* 1.2 MST */
|
||||
|
||||
#define DP_SINK_COUNT_ESI 0x2002 /* 1.2 */
|
||||
/* 0-5 sink count */
|
||||
# define DP_SINK_COUNT_CP_READY (1 << 6)
|
||||
|
||||
#define DP_DEVICE_SERVICE_IRQ_VECTOR_ESI0 0x2003 /* 1.2 */
|
||||
|
||||
#define DP_DEVICE_SERVICE_IRQ_VECTOR_ESI1 0x2004 /* 1.2 */
|
||||
|
||||
#define DP_LINK_SERVICE_IRQ_VECTOR_ESI0 0x2005 /* 1.2 */
|
||||
|
||||
#define DP_PSR_ERROR_STATUS 0x2006 /* XXX 1.2? */
|
||||
# define DP_PSR_LINK_CRC_ERROR (1 << 0)
|
||||
# define DP_PSR_RFB_STORAGE_ERROR (1 << 1)
|
||||
|
||||
#define DP_PSR_ESI 0x2007 /* XXX 1.2? */
|
||||
# define DP_PSR_CAPS_CHANGE (1 << 0)
|
||||
|
||||
#define DP_PSR_STATUS 0x2008 /* XXX 1.2? */
|
||||
# define DP_PSR_SINK_INACTIVE 0
|
||||
# define DP_PSR_SINK_ACTIVE_SRC_SYNCED 1
|
||||
# define DP_PSR_SINK_ACTIVE_RFB 2
|
||||
# define DP_PSR_SINK_ACTIVE_SINK_SYNCED 3
|
||||
# define DP_PSR_SINK_ACTIVE_RESYNC 4
|
||||
# define DP_PSR_SINK_INTERNAL_ERROR 7
|
||||
# define DP_PSR_SINK_STATE_MASK 0x07
|
||||
|
||||
/* DP 1.2 Sideband message defines */
|
||||
/* peer device type - DP 1.2a Table 2-92 */
|
||||
#define DP_PEER_DEVICE_NONE 0x0
|
||||
#define DP_PEER_DEVICE_SOURCE_OR_SST 0x1
|
||||
#define DP_PEER_DEVICE_MST_BRANCHING 0x2
|
||||
#define DP_PEER_DEVICE_SST_SINK 0x3
|
||||
#define DP_PEER_DEVICE_DP_LEGACY_CONV 0x4
|
||||
|
||||
/* DP 1.2 MST sideband request names DP 1.2a Table 2-80 */
|
||||
#define DP_LINK_ADDRESS 0x01
|
||||
#define DP_CONNECTION_STATUS_NOTIFY 0x02
|
||||
#define DP_ENUM_PATH_RESOURCES 0x10
|
||||
#define DP_ALLOCATE_PAYLOAD 0x11
|
||||
#define DP_QUERY_PAYLOAD 0x12
|
||||
#define DP_RESOURCE_STATUS_NOTIFY 0x13
|
||||
#define DP_CLEAR_PAYLOAD_ID_TABLE 0x14
|
||||
#define DP_REMOTE_DPCD_READ 0x20
|
||||
#define DP_REMOTE_DPCD_WRITE 0x21
|
||||
#define DP_REMOTE_I2C_READ 0x22
|
||||
#define DP_REMOTE_I2C_WRITE 0x23
|
||||
#define DP_POWER_UP_PHY 0x24
|
||||
#define DP_POWER_DOWN_PHY 0x25
|
||||
#define DP_SINK_EVENT_NOTIFY 0x30
|
||||
#define DP_QUERY_STREAM_ENC_STATUS 0x38
|
||||
|
||||
/* DP 1.2 MST sideband nak reasons - table 2.84 */
|
||||
#define DP_NAK_WRITE_FAILURE 0x01
|
||||
#define DP_NAK_INVALID_READ 0x02
|
||||
#define DP_NAK_CRC_FAILURE 0x03
|
||||
#define DP_NAK_BAD_PARAM 0x04
|
||||
#define DP_NAK_DEFER 0x05
|
||||
#define DP_NAK_LINK_FAILURE 0x06
|
||||
#define DP_NAK_NO_RESOURCES 0x07
|
||||
#define DP_NAK_DPCD_FAIL 0x08
|
||||
#define DP_NAK_I2C_NAK 0x09
|
||||
#define DP_NAK_ALLOCATE_FAIL 0x0a
|
||||
|
||||
#define MODE_I2C_START 1
|
||||
#define MODE_I2C_WRITE 2
|
||||
#define MODE_I2C_READ 4
|
||||
#define MODE_I2C_STOP 8
|
||||
|
||||
/* Rest of file omitted as it is not used in U-Boot */
|
||||
|
||||
#endif /* _DRM_DP_HELPER_H_ */
|
||||
@@ -0,0 +1,185 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* linux/include/linux/edd.h
|
||||
* Copyright (C) 2002, 2003, 2004 Dell Inc.
|
||||
* by Matt Domsch <Matt_Domsch@dell.com>
|
||||
*
|
||||
* structures and definitions for the int 13h, ax={41,48}h
|
||||
* BIOS Enhanced Disk Drive Services
|
||||
* This is based on the T13 group document D1572 Revision 0 (August 14 2002)
|
||||
* available at http://www.t13.org/docs2002/d1572r0.pdf. It is
|
||||
* very similar to D1484 Revision 3 http://www.t13.org/docs2002/d1484r3.pdf
|
||||
*
|
||||
* In a nutshell, arch/{i386,x86_64}/boot/setup.S populates a scratch
|
||||
* table in the boot_params that contains a list of BIOS-enumerated
|
||||
* boot devices.
|
||||
* In arch/{i386,x86_64}/kernel/setup.c, this information is
|
||||
* transferred into the edd structure, and in drivers/firmware/edd.c, that
|
||||
* information is used to identify BIOS boot disk. The code in setup.S
|
||||
* is very sensitive to the size of these structures.
|
||||
*/
|
||||
#ifndef _LINUX_EDD_H
|
||||
#define _LINUX_EDD_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
#define EDDNR 0x1e9 /* addr of number of edd_info structs at EDDBUF
|
||||
in boot_params - treat this as 1 byte */
|
||||
#define EDDBUF 0xd00 /* addr of edd_info structs in boot_params */
|
||||
#define EDDMAXNR 6 /* number of edd_info structs starting at EDDBUF */
|
||||
#define EDDEXTSIZE 8 /* change these if you muck with the structures */
|
||||
#define EDDPARMSIZE 74
|
||||
#define CHECKEXTENSIONSPRESENT 0x41
|
||||
#define GETDEVICEPARAMETERS 0x48
|
||||
#define LEGACYGETDEVICEPARAMETERS 0x08
|
||||
#define EDDMAGIC1 0x55AA
|
||||
#define EDDMAGIC2 0xAA55
|
||||
|
||||
|
||||
#define READ_SECTORS 0x02 /* int13 AH=0x02 is READ_SECTORS command */
|
||||
#define EDD_MBR_SIG_OFFSET 0x1B8 /* offset of signature in the MBR */
|
||||
#define EDD_MBR_SIG_BUF 0x290 /* addr in boot params */
|
||||
#define EDD_MBR_SIG_MAX 16 /* max number of signatures to store */
|
||||
#define EDD_MBR_SIG_NR_BUF 0x1ea /* addr of number of MBR signtaures at EDD_MBR_SIG_BUF
|
||||
in boot_params - treat this as 1 byte */
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#define EDD_EXT_FIXED_DISK_ACCESS (1 << 0)
|
||||
#define EDD_EXT_DEVICE_LOCKING_AND_EJECTING (1 << 1)
|
||||
#define EDD_EXT_ENHANCED_DISK_DRIVE_SUPPORT (1 << 2)
|
||||
#define EDD_EXT_64BIT_EXTENSIONS (1 << 3)
|
||||
|
||||
#define EDD_INFO_DMA_BOUNDARY_ERROR_TRANSPARENT (1 << 0)
|
||||
#define EDD_INFO_GEOMETRY_VALID (1 << 1)
|
||||
#define EDD_INFO_REMOVABLE (1 << 2)
|
||||
#define EDD_INFO_WRITE_VERIFY (1 << 3)
|
||||
#define EDD_INFO_MEDIA_CHANGE_NOTIFICATION (1 << 4)
|
||||
#define EDD_INFO_LOCKABLE (1 << 5)
|
||||
#define EDD_INFO_NO_MEDIA_PRESENT (1 << 6)
|
||||
#define EDD_INFO_USE_INT13_FN50 (1 << 7)
|
||||
|
||||
struct edd_device_params {
|
||||
__u16 length;
|
||||
__u16 info_flags;
|
||||
__u32 num_default_cylinders;
|
||||
__u32 num_default_heads;
|
||||
__u32 sectors_per_track;
|
||||
__u64 number_of_sectors;
|
||||
__u16 bytes_per_sector;
|
||||
__u32 dpte_ptr; /* 0xFFFFFFFF for our purposes */
|
||||
__u16 key; /* = 0xBEDD */
|
||||
__u8 device_path_info_length; /* = 44 */
|
||||
__u8 reserved2;
|
||||
__u16 reserved3;
|
||||
__u8 host_bus_type[4];
|
||||
__u8 interface_type[8];
|
||||
union {
|
||||
struct {
|
||||
__u16 base_address;
|
||||
__u16 reserved1;
|
||||
__u32 reserved2;
|
||||
} __attribute__ ((packed)) isa;
|
||||
struct {
|
||||
__u8 bus;
|
||||
__u8 slot;
|
||||
__u8 function;
|
||||
__u8 channel;
|
||||
__u32 reserved;
|
||||
} __attribute__ ((packed)) pci;
|
||||
/* pcix is same as pci */
|
||||
struct {
|
||||
__u64 reserved;
|
||||
} __attribute__ ((packed)) ibnd;
|
||||
struct {
|
||||
__u64 reserved;
|
||||
} __attribute__ ((packed)) xprs;
|
||||
struct {
|
||||
__u64 reserved;
|
||||
} __attribute__ ((packed)) htpt;
|
||||
struct {
|
||||
__u64 reserved;
|
||||
} __attribute__ ((packed)) unknown;
|
||||
} interface_path;
|
||||
union {
|
||||
struct {
|
||||
__u8 device;
|
||||
__u8 reserved1;
|
||||
__u16 reserved2;
|
||||
__u32 reserved3;
|
||||
__u64 reserved4;
|
||||
} __attribute__ ((packed)) ata;
|
||||
struct {
|
||||
__u8 device;
|
||||
__u8 lun;
|
||||
__u8 reserved1;
|
||||
__u8 reserved2;
|
||||
__u32 reserved3;
|
||||
__u64 reserved4;
|
||||
} __attribute__ ((packed)) atapi;
|
||||
struct {
|
||||
__u16 id;
|
||||
__u64 lun;
|
||||
__u16 reserved1;
|
||||
__u32 reserved2;
|
||||
} __attribute__ ((packed)) scsi;
|
||||
struct {
|
||||
__u64 serial_number;
|
||||
__u64 reserved;
|
||||
} __attribute__ ((packed)) usb;
|
||||
struct {
|
||||
__u64 eui;
|
||||
__u64 reserved;
|
||||
} __attribute__ ((packed)) i1394;
|
||||
struct {
|
||||
__u64 wwid;
|
||||
__u64 lun;
|
||||
} __attribute__ ((packed)) fibre;
|
||||
struct {
|
||||
__u64 identity_tag;
|
||||
__u64 reserved;
|
||||
} __attribute__ ((packed)) i2o;
|
||||
struct {
|
||||
__u32 array_number;
|
||||
__u32 reserved1;
|
||||
__u64 reserved2;
|
||||
} __attribute__ ((packed)) raid;
|
||||
struct {
|
||||
__u8 device;
|
||||
__u8 reserved1;
|
||||
__u16 reserved2;
|
||||
__u32 reserved3;
|
||||
__u64 reserved4;
|
||||
} __attribute__ ((packed)) sata;
|
||||
struct {
|
||||
__u64 reserved1;
|
||||
__u64 reserved2;
|
||||
} __attribute__ ((packed)) unknown;
|
||||
} device_path;
|
||||
__u8 reserved4;
|
||||
__u8 checksum;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct edd_info {
|
||||
__u8 device;
|
||||
__u8 version;
|
||||
__u16 interface_support;
|
||||
__u16 legacy_max_cylinder;
|
||||
__u8 legacy_max_head;
|
||||
__u8 legacy_sectors_per_track;
|
||||
struct edd_device_params params;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct edd {
|
||||
unsigned int mbr_signature[EDD_MBR_SIG_MAX];
|
||||
struct edd_info edd_info[EDDMAXNR];
|
||||
unsigned char mbr_signature_nr;
|
||||
unsigned char edd_info_nr;
|
||||
};
|
||||
|
||||
#ifdef __KERNEL__
|
||||
extern struct edd edd;
|
||||
#endif /* __KERNEL__ */
|
||||
#endif /*!__ASSEMBLY__ */
|
||||
|
||||
#endif /* _LINUX_EDD_H */
|
||||
@@ -0,0 +1,59 @@
|
||||
#ifndef _LINUX_ERR_H
|
||||
#define _LINUX_ERR_H
|
||||
|
||||
#include <linux/compiler.h>
|
||||
#include <linux/compat.h>
|
||||
|
||||
#include <linux/errno.h>
|
||||
|
||||
|
||||
/*
|
||||
* Kernel pointers have redundant information, so we can use a
|
||||
* scheme where we can return either an error code or a dentry
|
||||
* pointer with the same return value.
|
||||
*
|
||||
* This should be a per-architecture thing, to allow different
|
||||
* error and pointer decisions.
|
||||
*/
|
||||
#define MAX_ERRNO 4095
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
|
||||
|
||||
static inline void *ERR_PTR(long error)
|
||||
{
|
||||
return (void *)(CONFIG_ERR_PTR_OFFSET + error);
|
||||
}
|
||||
|
||||
static inline long PTR_ERR(const void *ptr)
|
||||
{
|
||||
return ((long)ptr - CONFIG_ERR_PTR_OFFSET);
|
||||
}
|
||||
|
||||
static inline long IS_ERR(const void *ptr)
|
||||
{
|
||||
return IS_ERR_VALUE((unsigned long)PTR_ERR(ptr));
|
||||
}
|
||||
|
||||
static inline bool IS_ERR_OR_NULL(const void *ptr)
|
||||
{
|
||||
return !ptr || IS_ERR_VALUE((unsigned long)PTR_ERR(ptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* ERR_CAST - Explicitly cast an error-valued pointer to another pointer type
|
||||
* @ptr: The pointer to cast.
|
||||
*
|
||||
* Explicitly cast an error-valued pointer to another pointer type in such a
|
||||
* way as to make it clear that's what's going on.
|
||||
*/
|
||||
static inline void * __must_check ERR_CAST(__force const void *ptr)
|
||||
{
|
||||
/* cast away the const */
|
||||
return (void *) ptr;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _LINUX_ERR_H */
|
||||
@@ -0,0 +1,168 @@
|
||||
#ifndef _LINUX_ERRNO_H
|
||||
#define _LINUX_ERRNO_H
|
||||
|
||||
#define EPERM 1 /* Operation not permitted */
|
||||
#define ENOENT 2 /* No such file or directory */
|
||||
#define ESRCH 3 /* No such process */
|
||||
#define EINTR 4 /* Interrupted system call */
|
||||
#define EIO 5 /* I/O error */
|
||||
#define ENXIO 6 /* No such device or address */
|
||||
#define E2BIG 7 /* Argument list too long */
|
||||
#define ENOEXEC 8 /* Exec format error */
|
||||
#define EBADF 9 /* Bad file number */
|
||||
#define ECHILD 10 /* No child processes */
|
||||
#define EAGAIN 11 /* Try again */
|
||||
#define ENOMEM 12 /* Out of memory */
|
||||
#define EACCES 13 /* Permission denied */
|
||||
#define EFAULT 14 /* Bad address */
|
||||
#define ENOTBLK 15 /* Block device required */
|
||||
#define EBUSY 16 /* Device or resource busy */
|
||||
#define EEXIST 17 /* File exists */
|
||||
#define EXDEV 18 /* Cross-device link */
|
||||
#define ENODEV 19 /* No such device */
|
||||
#define ENOTDIR 20 /* Not a directory */
|
||||
#define EISDIR 21 /* Is a directory */
|
||||
#define EINVAL 22 /* Invalid argument */
|
||||
#define ENFILE 23 /* File table overflow */
|
||||
#define EMFILE 24 /* Too many open files */
|
||||
#define ENOTTY 25 /* Not a typewriter */
|
||||
#define ETXTBSY 26 /* Text file busy */
|
||||
#define EFBIG 27 /* File too large */
|
||||
#define ENOSPC 28 /* No space left on device */
|
||||
#define ESPIPE 29 /* Illegal seek */
|
||||
#define EROFS 30 /* Read-only file system */
|
||||
#define EMLINK 31 /* Too many links */
|
||||
#define EPIPE 32 /* Broken pipe */
|
||||
#define EDOM 33 /* Math argument out of domain of func */
|
||||
#define ERANGE 34 /* Math result not representable */
|
||||
|
||||
#define EDEADLK 35 /* Resource deadlock would occur */
|
||||
#define ENAMETOOLONG 36 /* File name too long */
|
||||
#define ENOLCK 37 /* No record locks available */
|
||||
|
||||
#define ENOSYS 38 /* Invalid system call number */
|
||||
|
||||
#define ENOTEMPTY 39 /* Directory not empty */
|
||||
#define ELOOP 40 /* Too many symbolic links encountered */
|
||||
#define EWOULDBLOCK EAGAIN /* Operation would block */
|
||||
#define ENOMSG 42 /* No message of desired type */
|
||||
#define EIDRM 43 /* Identifier removed */
|
||||
#define ECHRNG 44 /* Channel number out of range */
|
||||
#define EL2NSYNC 45 /* Level 2 not synchronized */
|
||||
#define EL3HLT 46 /* Level 3 halted */
|
||||
#define EL3RST 47 /* Level 3 reset */
|
||||
#define ELNRNG 48 /* Link number out of range */
|
||||
#define EUNATCH 49 /* Protocol driver not attached */
|
||||
#define ENOCSI 50 /* No CSI structure available */
|
||||
#define EL2HLT 51 /* Level 2 halted */
|
||||
#define EBADE 52 /* Invalid exchange */
|
||||
#define EBADR 53 /* Invalid request descriptor */
|
||||
#define EXFULL 54 /* Exchange full */
|
||||
#define ENOANO 55 /* No anode */
|
||||
#define EBADRQC 56 /* Invalid request code */
|
||||
#define EBADSLT 57 /* Invalid slot */
|
||||
|
||||
#define EDEADLOCK EDEADLK
|
||||
|
||||
#define EBFONT 59 /* Bad font file format */
|
||||
#define ENOSTR 60 /* Device not a stream */
|
||||
#define ENODATA 61 /* No data available */
|
||||
#define ETIME 62 /* Timer expired */
|
||||
#define ENOSR 63 /* Out of streams resources */
|
||||
#define ENONET 64 /* Machine is not on the network */
|
||||
#define ENOPKG 65 /* Package not installed */
|
||||
#define EREMOTE 66 /* Object is remote */
|
||||
#define ENOLINK 67 /* Link has been severed */
|
||||
#define EADV 68 /* Advertise error */
|
||||
#define ESRMNT 69 /* Srmount error */
|
||||
#define ECOMM 70 /* Communication error on send */
|
||||
#define EPROTO 71 /* Protocol error */
|
||||
#define EMULTIHOP 72 /* Multihop attempted */
|
||||
#define EDOTDOT 73 /* RFS specific error */
|
||||
#define EBADMSG 74 /* Not a data message */
|
||||
#define EOVERFLOW 75 /* Value too large for defined data type */
|
||||
#define ENOTUNIQ 76 /* Name not unique on network */
|
||||
#define EBADFD 77 /* File descriptor in bad state */
|
||||
#define EREMCHG 78 /* Remote address changed */
|
||||
#define ELIBACC 79 /* Can not access a needed shared library */
|
||||
#define ELIBBAD 80 /* Accessing a corrupted shared library */
|
||||
#define ELIBSCN 81 /* .lib section in a.out corrupted */
|
||||
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
|
||||
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
|
||||
#define EILSEQ 84 /* Illegal byte sequence */
|
||||
#define ERESTART 85 /* Interrupted system call should be restarted */
|
||||
#define ESTRPIPE 86 /* Streams pipe error */
|
||||
#define EUSERS 87 /* Too many users */
|
||||
#define ENOTSOCK 88 /* Socket operation on non-socket */
|
||||
#define EDESTADDRREQ 89 /* Destination address required */
|
||||
#define EMSGSIZE 90 /* Message too long */
|
||||
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
|
||||
#define ENOPROTOOPT 92 /* Protocol not available */
|
||||
#define EPROTONOSUPPORT 93 /* Protocol not supported */
|
||||
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
|
||||
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
|
||||
#define EPFNOSUPPORT 96 /* Protocol family not supported */
|
||||
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
|
||||
#define EADDRINUSE 98 /* Address already in use */
|
||||
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
|
||||
#define ENETDOWN 100 /* Network is down */
|
||||
#define ENETUNREACH 101 /* Network is unreachable */
|
||||
#define ENETRESET 102 /* Network dropped connection because of reset */
|
||||
#define ECONNABORTED 103 /* Software caused connection abort */
|
||||
#define ECONNRESET 104 /* Connection reset by peer */
|
||||
#define ENOBUFS 105 /* No buffer space available */
|
||||
#define EISCONN 106 /* Transport endpoint is already connected */
|
||||
#define ENOTCONN 107 /* Transport endpoint is not connected */
|
||||
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
|
||||
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
|
||||
#define ETIMEDOUT 110 /* Connection timed out */
|
||||
#define ECONNREFUSED 111 /* Connection refused */
|
||||
#define EHOSTDOWN 112 /* Host is down */
|
||||
#define EHOSTUNREACH 113 /* No route to host */
|
||||
#define EALREADY 114 /* Operation already in progress */
|
||||
#define EINPROGRESS 115 /* Operation now in progress */
|
||||
#define ESTALE 116 /* Stale file handle */
|
||||
#define EUCLEAN 117 /* Structure needs cleaning */
|
||||
#define ENOTNAM 118 /* Not a XENIX named type file */
|
||||
#define ENAVAIL 119 /* No XENIX semaphores available */
|
||||
#define EISNAM 120 /* Is a named type file */
|
||||
#define EREMOTEIO 121 /* Remote I/O error */
|
||||
#define EDQUOT 122 /* Quota exceeded */
|
||||
|
||||
#define ENOMEDIUM 123 /* No medium found */
|
||||
#define EMEDIUMTYPE 124 /* Wrong medium type */
|
||||
#define ECANCELED 125 /* Operation Canceled */
|
||||
#define ENOKEY 126 /* Required key not available */
|
||||
#define EKEYEXPIRED 127 /* Key has expired */
|
||||
#define EKEYREVOKED 128 /* Key has been revoked */
|
||||
#define EKEYREJECTED 129 /* Key was rejected by service */
|
||||
|
||||
/* for robust mutexes */
|
||||
#define EOWNERDEAD 130 /* Owner died */
|
||||
#define ENOTRECOVERABLE 131 /* State not recoverable */
|
||||
|
||||
#define ERFKILL 132 /* Operation not possible due to RF-kill */
|
||||
|
||||
#define EHWPOISON 133 /* Memory page has hardware error */
|
||||
|
||||
#define ERESTARTSYS 512
|
||||
#define ERESTARTNOINTR 513
|
||||
#define ERESTARTNOHAND 514 /* restart if no handler.. */
|
||||
#define ENOIOCTLCMD 515 /* No ioctl command */
|
||||
#define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */
|
||||
#define EPROBE_DEFER 517 /* Driver requests probe retry */
|
||||
#define EOPENSTALE 518 /* open found a stale dentry */
|
||||
|
||||
/* Defined for the NFSv3 protocol */
|
||||
#define EBADHANDLE 521 /* Illegal NFS file handle */
|
||||
#define ENOTSYNC 522 /* Update synchronization mismatch */
|
||||
#define EBADCOOKIE 523 /* Cookie is stale */
|
||||
#define ENOTSUPP 524 /* Operation is not supported */
|
||||
#define ETOOSMALL 525 /* Buffer or request is too small */
|
||||
#define ESERVERFAULT 526 /* An untranslatable error occurred */
|
||||
#define EBADTYPE 527 /* Type not supported by server */
|
||||
#define EJUKEBOX 528 /* Request initiated, but will not complete before timeout */
|
||||
#define EIOCBQUEUED 529 /* iocb queued, will get completion event */
|
||||
#define ERECALLCONFLICT 530 /* conflict with recalled state */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,725 @@
|
||||
/*
|
||||
* ethtool.h: Defines for Linux ethtool.
|
||||
*
|
||||
* Copyright (C) 1998 David S. Miller (davem@redhat.com)
|
||||
* Copyright 2001 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Portions Copyright 2001 Sun Microsystems (thockin@sun.com)
|
||||
* Portions Copyright 2002 Intel (eli.kupermann@intel.com,
|
||||
* christopher.leech@intel.com,
|
||||
* scott.feldman@intel.com)
|
||||
* Portions Copyright (C) Sun Microsystems 2008
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_ETHTOOL_H
|
||||
#define _LINUX_ETHTOOL_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
/* This should work for both 32 and 64 bit userland. */
|
||||
struct ethtool_cmd {
|
||||
__u32 cmd;
|
||||
__u32 supported; /* Features this interface supports */
|
||||
__u32 advertising; /* Features this interface advertises */
|
||||
__u16 speed; /* The forced speed, 10Mb, 100Mb, gigabit */
|
||||
__u8 duplex; /* Duplex, half or full */
|
||||
__u8 port; /* Which connector port */
|
||||
__u8 phy_address;
|
||||
__u8 transceiver; /* Which transceiver to use */
|
||||
__u8 autoneg; /* Enable or disable autonegotiation */
|
||||
__u8 mdio_support;
|
||||
__u32 maxtxpkt; /* Tx pkts before generating tx int */
|
||||
__u32 maxrxpkt; /* Rx pkts before generating rx int */
|
||||
__u16 speed_hi;
|
||||
__u8 eth_tp_mdix;
|
||||
__u8 reserved2;
|
||||
__u32 lp_advertising; /* Features the link partner advertises */
|
||||
__u32 reserved[2];
|
||||
};
|
||||
|
||||
static inline void ethtool_cmd_speed_set(struct ethtool_cmd *ep,
|
||||
__u32 speed)
|
||||
{
|
||||
|
||||
ep->speed = (__u16)speed;
|
||||
ep->speed_hi = (__u16)(speed >> 16);
|
||||
}
|
||||
|
||||
static inline __u32 ethtool_cmd_speed(struct ethtool_cmd *ep)
|
||||
{
|
||||
return (ep->speed_hi << 16) | ep->speed;
|
||||
}
|
||||
|
||||
#define ETHTOOL_FWVERS_LEN 32
|
||||
#define ETHTOOL_BUSINFO_LEN 32
|
||||
/* these strings are set to whatever the driver author decides... */
|
||||
struct ethtool_drvinfo {
|
||||
__u32 cmd;
|
||||
char driver[32]; /* driver short name, "tulip", "eepro100" */
|
||||
char version[32]; /* driver version string */
|
||||
char fw_version[ETHTOOL_FWVERS_LEN]; /* firmware version string */
|
||||
char bus_info[ETHTOOL_BUSINFO_LEN]; /* Bus info for this IF. */
|
||||
/* For PCI devices, use pci_name(pci_dev). */
|
||||
char reserved1[32];
|
||||
char reserved2[12];
|
||||
/*
|
||||
* Some struct members below are filled in
|
||||
* using ops->get_sset_count(). Obtaining
|
||||
* this info from ethtool_drvinfo is now
|
||||
* deprecated; Use ETHTOOL_GSSET_INFO
|
||||
* instead.
|
||||
*/
|
||||
__u32 n_priv_flags; /* number of flags valid in ETHTOOL_GPFLAGS */
|
||||
__u32 n_stats; /* number of u64's from ETHTOOL_GSTATS */
|
||||
__u32 testinfo_len;
|
||||
__u32 eedump_len; /* Size of data from ETHTOOL_GEEPROM (bytes) */
|
||||
__u32 regdump_len; /* Size of data from ETHTOOL_GREGS (bytes) */
|
||||
};
|
||||
|
||||
#define SOPASS_MAX 6
|
||||
/* wake-on-lan settings */
|
||||
struct ethtool_wolinfo {
|
||||
__u32 cmd;
|
||||
__u32 supported;
|
||||
__u32 wolopts;
|
||||
__u8 sopass[SOPASS_MAX]; /* SecureOn(tm) password */
|
||||
};
|
||||
|
||||
/* for passing single values */
|
||||
struct ethtool_value {
|
||||
__u32 cmd;
|
||||
__u32 data;
|
||||
};
|
||||
|
||||
/* for passing big chunks of data */
|
||||
struct ethtool_regs {
|
||||
__u32 cmd;
|
||||
__u32 version; /* driver-specific, indicates different chips/revs */
|
||||
__u32 len; /* bytes */
|
||||
__u8 data[0];
|
||||
};
|
||||
|
||||
/* for passing EEPROM chunks */
|
||||
struct ethtool_eeprom {
|
||||
__u32 cmd;
|
||||
__u32 magic;
|
||||
__u32 offset; /* in bytes */
|
||||
__u32 len; /* in bytes */
|
||||
__u8 data[0];
|
||||
};
|
||||
|
||||
/* for configuring coalescing parameters of chip */
|
||||
struct ethtool_coalesce {
|
||||
__u32 cmd; /* ETHTOOL_{G,S}COALESCE */
|
||||
|
||||
/* How many usecs to delay an RX interrupt after
|
||||
* a packet arrives. If 0, only rx_max_coalesced_frames
|
||||
* is used.
|
||||
*/
|
||||
__u32 rx_coalesce_usecs;
|
||||
|
||||
/* How many packets to delay an RX interrupt after
|
||||
* a packet arrives. If 0, only rx_coalesce_usecs is
|
||||
* used. It is illegal to set both usecs and max frames
|
||||
* to zero as this would cause RX interrupts to never be
|
||||
* generated.
|
||||
*/
|
||||
__u32 rx_max_coalesced_frames;
|
||||
|
||||
/* Same as above two parameters, except that these values
|
||||
* apply while an IRQ is being serviced by the host. Not
|
||||
* all cards support this feature and the values are ignored
|
||||
* in that case.
|
||||
*/
|
||||
__u32 rx_coalesce_usecs_irq;
|
||||
__u32 rx_max_coalesced_frames_irq;
|
||||
|
||||
/* How many usecs to delay a TX interrupt after
|
||||
* a packet is sent. If 0, only tx_max_coalesced_frames
|
||||
* is used.
|
||||
*/
|
||||
__u32 tx_coalesce_usecs;
|
||||
|
||||
/* How many packets to delay a TX interrupt after
|
||||
* a packet is sent. If 0, only tx_coalesce_usecs is
|
||||
* used. It is illegal to set both usecs and max frames
|
||||
* to zero as this would cause TX interrupts to never be
|
||||
* generated.
|
||||
*/
|
||||
__u32 tx_max_coalesced_frames;
|
||||
|
||||
/* Same as above two parameters, except that these values
|
||||
* apply while an IRQ is being serviced by the host. Not
|
||||
* all cards support this feature and the values are ignored
|
||||
* in that case.
|
||||
*/
|
||||
__u32 tx_coalesce_usecs_irq;
|
||||
__u32 tx_max_coalesced_frames_irq;
|
||||
|
||||
/* How many usecs to delay in-memory statistics
|
||||
* block updates. Some drivers do not have an in-memory
|
||||
* statistic block, and in such cases this value is ignored.
|
||||
* This value must not be zero.
|
||||
*/
|
||||
__u32 stats_block_coalesce_usecs;
|
||||
|
||||
/* Adaptive RX/TX coalescing is an algorithm implemented by
|
||||
* some drivers to improve latency under low packet rates and
|
||||
* improve throughput under high packet rates. Some drivers
|
||||
* only implement one of RX or TX adaptive coalescing. Anything
|
||||
* not implemented by the driver causes these values to be
|
||||
* silently ignored.
|
||||
*/
|
||||
__u32 use_adaptive_rx_coalesce;
|
||||
__u32 use_adaptive_tx_coalesce;
|
||||
|
||||
/* When the packet rate (measured in packets per second)
|
||||
* is below pkt_rate_low, the {rx,tx}_*_low parameters are
|
||||
* used.
|
||||
*/
|
||||
__u32 pkt_rate_low;
|
||||
__u32 rx_coalesce_usecs_low;
|
||||
__u32 rx_max_coalesced_frames_low;
|
||||
__u32 tx_coalesce_usecs_low;
|
||||
__u32 tx_max_coalesced_frames_low;
|
||||
|
||||
/* When the packet rate is below pkt_rate_high but above
|
||||
* pkt_rate_low (both measured in packets per second) the
|
||||
* normal {rx,tx}_* coalescing parameters are used.
|
||||
*/
|
||||
|
||||
/* When the packet rate is (measured in packets per second)
|
||||
* is above pkt_rate_high, the {rx,tx}_*_high parameters are
|
||||
* used.
|
||||
*/
|
||||
__u32 pkt_rate_high;
|
||||
__u32 rx_coalesce_usecs_high;
|
||||
__u32 rx_max_coalesced_frames_high;
|
||||
__u32 tx_coalesce_usecs_high;
|
||||
__u32 tx_max_coalesced_frames_high;
|
||||
|
||||
/* How often to do adaptive coalescing packet rate sampling,
|
||||
* measured in seconds. Must not be zero.
|
||||
*/
|
||||
__u32 rate_sample_interval;
|
||||
};
|
||||
|
||||
/* for configuring RX/TX ring parameters */
|
||||
struct ethtool_ringparam {
|
||||
__u32 cmd; /* ETHTOOL_{G,S}RINGPARAM */
|
||||
|
||||
/* Read only attributes. These indicate the maximum number
|
||||
* of pending RX/TX ring entries the driver will allow the
|
||||
* user to set.
|
||||
*/
|
||||
__u32 rx_max_pending;
|
||||
__u32 rx_mini_max_pending;
|
||||
__u32 rx_jumbo_max_pending;
|
||||
__u32 tx_max_pending;
|
||||
|
||||
/* Values changeable by the user. The valid values are
|
||||
* in the range 1 to the "*_max_pending" counterpart above.
|
||||
*/
|
||||
__u32 rx_pending;
|
||||
__u32 rx_mini_pending;
|
||||
__u32 rx_jumbo_pending;
|
||||
__u32 tx_pending;
|
||||
};
|
||||
|
||||
/* for configuring link flow control parameters */
|
||||
struct ethtool_pauseparam {
|
||||
__u32 cmd; /* ETHTOOL_{G,S}PAUSEPARAM */
|
||||
|
||||
/* If the link is being auto-negotiated (via ethtool_cmd.autoneg
|
||||
* being true) the user may set 'autonet' here non-zero to have the
|
||||
* pause parameters be auto-negotiated too. In such a case, the
|
||||
* {rx,tx}_pause values below determine what capabilities are
|
||||
* advertised.
|
||||
*
|
||||
* If 'autoneg' is zero or the link is not being auto-negotiated,
|
||||
* then {rx,tx}_pause force the driver to use/not-use pause
|
||||
* flow control.
|
||||
*/
|
||||
__u32 autoneg;
|
||||
__u32 rx_pause;
|
||||
__u32 tx_pause;
|
||||
};
|
||||
|
||||
#define ETH_GSTRING_LEN 32
|
||||
enum ethtool_stringset {
|
||||
ETH_SS_TEST = 0,
|
||||
ETH_SS_STATS,
|
||||
ETH_SS_PRIV_FLAGS,
|
||||
ETH_SS_NTUPLE_FILTERS,
|
||||
ETH_SS_FEATURES,
|
||||
};
|
||||
|
||||
/* for passing string sets for data tagging */
|
||||
struct ethtool_gstrings {
|
||||
__u32 cmd; /* ETHTOOL_GSTRINGS */
|
||||
__u32 string_set; /* string set id e.c. ETH_SS_TEST, etc*/
|
||||
__u32 len; /* number of strings in the string set */
|
||||
__u8 data[0];
|
||||
};
|
||||
|
||||
struct ethtool_sset_info {
|
||||
__u32 cmd; /* ETHTOOL_GSSET_INFO */
|
||||
__u32 reserved;
|
||||
__u64 sset_mask; /* input: each bit selects an sset to query */
|
||||
/* output: each bit a returned sset */
|
||||
__u32 data[0]; /* ETH_SS_xxx count, in order, based on bits
|
||||
in sset_mask. One bit implies one
|
||||
__u32, two bits implies two
|
||||
__u32's, etc. */
|
||||
};
|
||||
|
||||
enum ethtool_test_flags {
|
||||
ETH_TEST_FL_OFFLINE = (1 << 0), /* online / offline */
|
||||
ETH_TEST_FL_FAILED = (1 << 1), /* test passed / failed */
|
||||
};
|
||||
|
||||
/* for requesting NIC test and getting results*/
|
||||
struct ethtool_test {
|
||||
__u32 cmd; /* ETHTOOL_TEST */
|
||||
__u32 flags; /* ETH_TEST_FL_xxx */
|
||||
__u32 reserved;
|
||||
__u32 len; /* result length, in number of u64 elements */
|
||||
__u64 data[0];
|
||||
};
|
||||
|
||||
/* for dumping NIC-specific statistics */
|
||||
struct ethtool_stats {
|
||||
__u32 cmd; /* ETHTOOL_GSTATS */
|
||||
__u32 n_stats; /* number of u64's being returned */
|
||||
__u64 data[0];
|
||||
};
|
||||
|
||||
struct ethtool_perm_addr {
|
||||
__u32 cmd; /* ETHTOOL_GPERMADDR */
|
||||
__u32 size;
|
||||
__u8 data[0];
|
||||
};
|
||||
|
||||
/* boolean flags controlling per-interface behavior characteristics.
|
||||
* When reading, the flag indicates whether or not a certain behavior
|
||||
* is enabled/present. When writing, the flag indicates whether
|
||||
* or not the driver should turn on (set) or off (clear) a behavior.
|
||||
*
|
||||
* Some behaviors may read-only (unconditionally absent or present).
|
||||
* If such is the case, return EINVAL in the set-flags operation if the
|
||||
* flag differs from the read-only value.
|
||||
*/
|
||||
enum ethtool_flags {
|
||||
ETH_FLAG_TXVLAN = (1 << 7), /* TX VLAN offload enabled */
|
||||
ETH_FLAG_RXVLAN = (1 << 8), /* RX VLAN offload enabled */
|
||||
ETH_FLAG_LRO = (1 << 15), /* LRO is enabled */
|
||||
ETH_FLAG_NTUPLE = (1 << 27), /* N-tuple filters enabled */
|
||||
ETH_FLAG_RXHASH = (1 << 28),
|
||||
};
|
||||
|
||||
/* The following structures are for supporting RX network flow
|
||||
* classification and RX n-tuple configuration. Note, all multibyte
|
||||
* fields, e.g., ip4src, ip4dst, psrc, pdst, spi, etc. are expected to
|
||||
* be in network byte order.
|
||||
*/
|
||||
|
||||
/**
|
||||
* struct ethtool_tcpip4_spec - flow specification for TCP/IPv4 etc.
|
||||
* @ip4src: Source host
|
||||
* @ip4dst: Destination host
|
||||
* @psrc: Source port
|
||||
* @pdst: Destination port
|
||||
* @tos: Type-of-service
|
||||
*
|
||||
* This can be used to specify a TCP/IPv4, UDP/IPv4 or SCTP/IPv4 flow.
|
||||
*/
|
||||
struct ethtool_tcpip4_spec {
|
||||
__be32 ip4src;
|
||||
__be32 ip4dst;
|
||||
__be16 psrc;
|
||||
__be16 pdst;
|
||||
__u8 tos;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct ethtool_ah_espip4_spec - flow specification for IPsec/IPv4
|
||||
* @ip4src: Source host
|
||||
* @ip4dst: Destination host
|
||||
* @spi: Security parameters index
|
||||
* @tos: Type-of-service
|
||||
*
|
||||
* This can be used to specify an IPsec transport or tunnel over IPv4.
|
||||
*/
|
||||
struct ethtool_ah_espip4_spec {
|
||||
__be32 ip4src;
|
||||
__be32 ip4dst;
|
||||
__be32 spi;
|
||||
__u8 tos;
|
||||
};
|
||||
|
||||
#define ETH_RX_NFC_IP4 1
|
||||
|
||||
/**
|
||||
* struct ethtool_usrip4_spec - general flow specification for IPv4
|
||||
* @ip4src: Source host
|
||||
* @ip4dst: Destination host
|
||||
* @l4_4_bytes: First 4 bytes of transport (layer 4) header
|
||||
* @tos: Type-of-service
|
||||
* @ip_ver: Value must be %ETH_RX_NFC_IP4; mask must be 0
|
||||
* @proto: Transport protocol number; mask must be 0
|
||||
*/
|
||||
struct ethtool_usrip4_spec {
|
||||
__be32 ip4src;
|
||||
__be32 ip4dst;
|
||||
__be32 l4_4_bytes;
|
||||
__u8 tos;
|
||||
__u8 ip_ver;
|
||||
__u8 proto;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* struct ethtool_rxfh_indir - command to get or set RX flow hash indirection
|
||||
* @cmd: Specific command number - %ETHTOOL_GRXFHINDIR or %ETHTOOL_SRXFHINDIR
|
||||
* @size: On entry, the array size of the user buffer. On return from
|
||||
* %ETHTOOL_GRXFHINDIR, the array size of the hardware indirection table.
|
||||
* @ring_index: RX ring/queue index for each hash value
|
||||
*/
|
||||
struct ethtool_rxfh_indir {
|
||||
__u32 cmd;
|
||||
__u32 size;
|
||||
__u32 ring_index[0];
|
||||
};
|
||||
|
||||
#define ETHTOOL_FLASH_MAX_FILENAME 128
|
||||
enum ethtool_flash_op_type {
|
||||
ETHTOOL_FLASH_ALL_REGIONS = 0,
|
||||
};
|
||||
|
||||
/* for passing firmware flashing related parameters */
|
||||
struct ethtool_flash {
|
||||
__u32 cmd;
|
||||
__u32 region;
|
||||
char data[ETHTOOL_FLASH_MAX_FILENAME];
|
||||
};
|
||||
|
||||
/* for returning and changing feature sets */
|
||||
|
||||
/**
|
||||
* struct ethtool_get_features_block - block with state of 32 features
|
||||
* @available: mask of changeable features
|
||||
* @requested: mask of features requested to be enabled if possible
|
||||
* @active: mask of currently enabled features
|
||||
* @never_changed: mask of features not changeable for any device
|
||||
*/
|
||||
struct ethtool_get_features_block {
|
||||
__u32 available;
|
||||
__u32 requested;
|
||||
__u32 active;
|
||||
__u32 never_changed;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct ethtool_gfeatures - command to get state of device's features
|
||||
* @cmd: command number = %ETHTOOL_GFEATURES
|
||||
* @size: in: number of elements in the features[] array;
|
||||
* out: number of elements in features[] needed to hold all features
|
||||
* @features: state of features
|
||||
*/
|
||||
struct ethtool_gfeatures {
|
||||
__u32 cmd;
|
||||
__u32 size;
|
||||
struct ethtool_get_features_block features[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* struct ethtool_set_features_block - block with request for 32 features
|
||||
* @valid: mask of features to be changed
|
||||
* @requested: values of features to be changed
|
||||
*/
|
||||
struct ethtool_set_features_block {
|
||||
__u32 valid;
|
||||
__u32 requested;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct ethtool_sfeatures - command to request change in device's features
|
||||
* @cmd: command number = %ETHTOOL_SFEATURES
|
||||
* @size: array size of the features[] array
|
||||
* @features: feature change masks
|
||||
*/
|
||||
struct ethtool_sfeatures {
|
||||
__u32 cmd;
|
||||
__u32 size;
|
||||
struct ethtool_set_features_block features[0];
|
||||
};
|
||||
|
||||
/*
|
||||
* %ETHTOOL_SFEATURES changes features present in features[].valid to the
|
||||
* values of corresponding bits in features[].requested. Bits in .requested
|
||||
* not set in .valid or not changeable are ignored.
|
||||
*
|
||||
* Returns %EINVAL when .valid contains undefined or never-changable bits
|
||||
* or size is not equal to required number of features words (32-bit blocks).
|
||||
* Returns >= 0 if request was completed; bits set in the value mean:
|
||||
* %ETHTOOL_F_UNSUPPORTED - there were bits set in .valid that are not
|
||||
* changeable (not present in %ETHTOOL_GFEATURES' features[].available)
|
||||
* those bits were ignored.
|
||||
* %ETHTOOL_F_WISH - some or all changes requested were recorded but the
|
||||
* resulting state of bits masked by .valid is not equal to .requested.
|
||||
* Probably there are other device-specific constraints on some features
|
||||
* in the set. When %ETHTOOL_F_UNSUPPORTED is set, .valid is considered
|
||||
* here as though ignored bits were cleared.
|
||||
* %ETHTOOL_F_COMPAT - some or all changes requested were made by calling
|
||||
* compatibility functions. Requested offload state cannot be properly
|
||||
* managed by kernel.
|
||||
*
|
||||
* Meaning of bits in the masks are obtained by %ETHTOOL_GSSET_INFO (number of
|
||||
* bits in the arrays - always multiple of 32) and %ETHTOOL_GSTRINGS commands
|
||||
* for ETH_SS_FEATURES string set. First entry in the table corresponds to least
|
||||
* significant bit in features[0] fields. Empty strings mark undefined features.
|
||||
*/
|
||||
enum ethtool_sfeatures_retval_bits {
|
||||
ETHTOOL_F_UNSUPPORTED__BIT,
|
||||
ETHTOOL_F_WISH__BIT,
|
||||
ETHTOOL_F_COMPAT__BIT,
|
||||
};
|
||||
|
||||
#define ETHTOOL_F_UNSUPPORTED (1 << ETHTOOL_F_UNSUPPORTED__BIT)
|
||||
#define ETHTOOL_F_WISH (1 << ETHTOOL_F_WISH__BIT)
|
||||
#define ETHTOOL_F_COMPAT (1 << ETHTOOL_F_COMPAT__BIT)
|
||||
|
||||
/* CMDs currently supported */
|
||||
#define ETHTOOL_GSET 0x00000001 /* Get settings. */
|
||||
#define ETHTOOL_SSET 0x00000002 /* Set settings. */
|
||||
#define ETHTOOL_GDRVINFO 0x00000003 /* Get driver info. */
|
||||
#define ETHTOOL_GREGS 0x00000004 /* Get NIC registers. */
|
||||
#define ETHTOOL_GWOL 0x00000005 /* Get wake-on-lan options. */
|
||||
#define ETHTOOL_SWOL 0x00000006 /* Set wake-on-lan options. */
|
||||
#define ETHTOOL_GMSGLVL 0x00000007 /* Get driver message level */
|
||||
#define ETHTOOL_SMSGLVL 0x00000008 /* Set driver msg level. */
|
||||
#define ETHTOOL_NWAY_RST 0x00000009 /* Restart autonegotiation. */
|
||||
/* Get link status for host, i.e. whether the interface *and* the
|
||||
* physical port (if there is one) are up (ethtool_value). */
|
||||
#define ETHTOOL_GLINK 0x0000000a
|
||||
#define ETHTOOL_GEEPROM 0x0000000b /* Get EEPROM data */
|
||||
#define ETHTOOL_SEEPROM 0x0000000c /* Set EEPROM data. */
|
||||
#define ETHTOOL_GCOALESCE 0x0000000e /* Get coalesce config */
|
||||
#define ETHTOOL_SCOALESCE 0x0000000f /* Set coalesce config. */
|
||||
#define ETHTOOL_GRINGPARAM 0x00000010 /* Get ring parameters */
|
||||
#define ETHTOOL_SRINGPARAM 0x00000011 /* Set ring parameters. */
|
||||
#define ETHTOOL_GPAUSEPARAM 0x00000012 /* Get pause parameters */
|
||||
#define ETHTOOL_SPAUSEPARAM 0x00000013 /* Set pause parameters. */
|
||||
#define ETHTOOL_GRXCSUM 0x00000014 /* Get RX hw csum enable (ethtool_value) */
|
||||
#define ETHTOOL_SRXCSUM 0x00000015 /* Set RX hw csum enable (ethtool_value) */
|
||||
#define ETHTOOL_GTXCSUM 0x00000016 /* Get TX hw csum enable (ethtool_value) */
|
||||
#define ETHTOOL_STXCSUM 0x00000017 /* Set TX hw csum enable (ethtool_value) */
|
||||
#define ETHTOOL_GSG 0x00000018 /* Get scatter-gather enable
|
||||
* (ethtool_value) */
|
||||
#define ETHTOOL_SSG 0x00000019 /* Set scatter-gather enable
|
||||
* (ethtool_value). */
|
||||
#define ETHTOOL_TEST 0x0000001a /* execute NIC self-test. */
|
||||
#define ETHTOOL_GSTRINGS 0x0000001b /* get specified string set */
|
||||
#define ETHTOOL_PHYS_ID 0x0000001c /* identify the NIC */
|
||||
#define ETHTOOL_GSTATS 0x0000001d /* get NIC-specific statistics */
|
||||
#define ETHTOOL_GTSO 0x0000001e /* Get TSO enable (ethtool_value) */
|
||||
#define ETHTOOL_STSO 0x0000001f /* Set TSO enable (ethtool_value) */
|
||||
#define ETHTOOL_GPERMADDR 0x00000020 /* Get permanent hardware address */
|
||||
#define ETHTOOL_GUFO 0x00000021 /* Get UFO enable (ethtool_value) */
|
||||
#define ETHTOOL_SUFO 0x00000022 /* Set UFO enable (ethtool_value) */
|
||||
#define ETHTOOL_GGSO 0x00000023 /* Get GSO enable (ethtool_value) */
|
||||
#define ETHTOOL_SGSO 0x00000024 /* Set GSO enable (ethtool_value) */
|
||||
#define ETHTOOL_GFLAGS 0x00000025 /* Get flags bitmap(ethtool_value) */
|
||||
#define ETHTOOL_SFLAGS 0x00000026 /* Set flags bitmap(ethtool_value) */
|
||||
#define ETHTOOL_GPFLAGS 0x00000027 /* Get driver-private flags bitmap */
|
||||
#define ETHTOOL_SPFLAGS 0x00000028 /* Set driver-private flags bitmap */
|
||||
|
||||
#define ETHTOOL_GRXFH 0x00000029 /* Get RX flow hash configuration */
|
||||
#define ETHTOOL_SRXFH 0x0000002a /* Set RX flow hash configuration */
|
||||
#define ETHTOOL_GGRO 0x0000002b /* Get GRO enable (ethtool_value) */
|
||||
#define ETHTOOL_SGRO 0x0000002c /* Set GRO enable (ethtool_value) */
|
||||
#define ETHTOOL_GRXRINGS 0x0000002d /* Get RX rings available for LB */
|
||||
#define ETHTOOL_GRXCLSRLCNT 0x0000002e /* Get RX class rule count */
|
||||
#define ETHTOOL_GRXCLSRULE 0x0000002f /* Get RX classification rule */
|
||||
#define ETHTOOL_GRXCLSRLALL 0x00000030 /* Get all RX classification rule */
|
||||
#define ETHTOOL_SRXCLSRLDEL 0x00000031 /* Delete RX classification rule */
|
||||
#define ETHTOOL_SRXCLSRLINS 0x00000032 /* Insert RX classification rule */
|
||||
#define ETHTOOL_FLASHDEV 0x00000033 /* Flash firmware to device */
|
||||
#define ETHTOOL_RESET 0x00000034 /* Reset hardware */
|
||||
#define ETHTOOL_SRXNTUPLE 0x00000035 /* Add an n-tuple filter to device */
|
||||
#define ETHTOOL_GRXNTUPLE 0x00000036 /* Get n-tuple filters from device */
|
||||
#define ETHTOOL_GSSET_INFO 0x00000037 /* Get string set info */
|
||||
#define ETHTOOL_GRXFHINDIR 0x00000038 /* Get RX flow hash indir'n table */
|
||||
#define ETHTOOL_SRXFHINDIR 0x00000039 /* Set RX flow hash indir'n table */
|
||||
|
||||
#define ETHTOOL_GFEATURES 0x0000003a /* Get device offload settings */
|
||||
#define ETHTOOL_SFEATURES 0x0000003b /* Change device offload settings */
|
||||
|
||||
/* compatibility with older code */
|
||||
#define SPARC_ETH_GSET ETHTOOL_GSET
|
||||
#define SPARC_ETH_SSET ETHTOOL_SSET
|
||||
|
||||
/* Indicates what features are supported by the interface. */
|
||||
#define SUPPORTED_10baseT_Half (1 << 0)
|
||||
#define SUPPORTED_10baseT_Full (1 << 1)
|
||||
#define SUPPORTED_100baseT_Half (1 << 2)
|
||||
#define SUPPORTED_100baseT_Full (1 << 3)
|
||||
#define SUPPORTED_1000baseT_Half (1 << 4)
|
||||
#define SUPPORTED_1000baseT_Full (1 << 5)
|
||||
#define SUPPORTED_Autoneg (1 << 6)
|
||||
#define SUPPORTED_TP (1 << 7)
|
||||
#define SUPPORTED_AUI (1 << 8)
|
||||
#define SUPPORTED_MII (1 << 9)
|
||||
#define SUPPORTED_FIBRE (1 << 10)
|
||||
#define SUPPORTED_BNC (1 << 11)
|
||||
#define SUPPORTED_10000baseT_Full (1 << 12)
|
||||
#define SUPPORTED_Pause (1 << 13)
|
||||
#define SUPPORTED_Asym_Pause (1 << 14)
|
||||
#define SUPPORTED_2500baseX_Full (1 << 15)
|
||||
#define SUPPORTED_Backplane (1 << 16)
|
||||
#define SUPPORTED_1000baseKX_Full (1 << 17)
|
||||
#define SUPPORTED_10000baseKX4_Full (1 << 18)
|
||||
#define SUPPORTED_10000baseKR_Full (1 << 19)
|
||||
#define SUPPORTED_10000baseR_FEC (1 << 20)
|
||||
#define SUPPORTED_1000baseX_Half (1 << 21)
|
||||
#define SUPPORTED_1000baseX_Full (1 << 22)
|
||||
|
||||
/* Indicates what features are advertised by the interface. */
|
||||
#define ADVERTISED_10baseT_Half (1 << 0)
|
||||
#define ADVERTISED_10baseT_Full (1 << 1)
|
||||
#define ADVERTISED_100baseT_Half (1 << 2)
|
||||
#define ADVERTISED_100baseT_Full (1 << 3)
|
||||
#define ADVERTISED_1000baseT_Half (1 << 4)
|
||||
#define ADVERTISED_1000baseT_Full (1 << 5)
|
||||
#define ADVERTISED_Autoneg (1 << 6)
|
||||
#define ADVERTISED_TP (1 << 7)
|
||||
#define ADVERTISED_AUI (1 << 8)
|
||||
#define ADVERTISED_MII (1 << 9)
|
||||
#define ADVERTISED_FIBRE (1 << 10)
|
||||
#define ADVERTISED_BNC (1 << 11)
|
||||
#define ADVERTISED_10000baseT_Full (1 << 12)
|
||||
#define ADVERTISED_Pause (1 << 13)
|
||||
#define ADVERTISED_Asym_Pause (1 << 14)
|
||||
#define ADVERTISED_2500baseX_Full (1 << 15)
|
||||
#define ADVERTISED_Backplane (1 << 16)
|
||||
#define ADVERTISED_1000baseKX_Full (1 << 17)
|
||||
#define ADVERTISED_10000baseKX4_Full (1 << 18)
|
||||
#define ADVERTISED_10000baseKR_Full (1 << 19)
|
||||
#define ADVERTISED_10000baseR_FEC (1 << 20)
|
||||
#define ADVERTISED_1000baseX_Half (1 << 21)
|
||||
#define ADVERTISED_1000baseX_Full (1 << 22)
|
||||
|
||||
/* The following are all involved in forcing a particular link
|
||||
* mode for the device for setting things. When getting the
|
||||
* devices settings, these indicate the current mode and whether
|
||||
* it was foced up into this mode or autonegotiated.
|
||||
*/
|
||||
|
||||
/* The forced speed, 10Mb, 100Mb, gigabit, 2.5Gb, 10GbE. */
|
||||
#define SPEED_10 10
|
||||
#define SPEED_100 100
|
||||
#define SPEED_1000 1000
|
||||
#define SPEED_2500 2500
|
||||
#define SPEED_10000 10000
|
||||
|
||||
/* Duplex, half or full. */
|
||||
#define DUPLEX_HALF 0x00
|
||||
#define DUPLEX_FULL 0x01
|
||||
|
||||
/* Which connector port. */
|
||||
#define PORT_TP 0x00
|
||||
#define PORT_AUI 0x01
|
||||
#define PORT_MII 0x02
|
||||
#define PORT_FIBRE 0x03
|
||||
#define PORT_BNC 0x04
|
||||
#define PORT_DA 0x05
|
||||
#define PORT_NONE 0xef
|
||||
#define PORT_OTHER 0xff
|
||||
|
||||
/* Which transceiver to use. */
|
||||
#define XCVR_INTERNAL 0x00
|
||||
#define XCVR_EXTERNAL 0x01
|
||||
#define XCVR_DUMMY1 0x02
|
||||
#define XCVR_DUMMY2 0x03
|
||||
#define XCVR_DUMMY3 0x04
|
||||
|
||||
/* Enable or disable autonegotiation. If this is set to enable,
|
||||
* the forced link modes above are completely ignored.
|
||||
*/
|
||||
#define AUTONEG_DISABLE 0x00
|
||||
#define AUTONEG_ENABLE 0x01
|
||||
|
||||
/* Mode MDI or MDI-X */
|
||||
#define ETH_TP_MDI_INVALID 0x00
|
||||
#define ETH_TP_MDI 0x01
|
||||
#define ETH_TP_MDI_X 0x02
|
||||
|
||||
/* Wake-On-Lan options. */
|
||||
#define WAKE_PHY (1 << 0)
|
||||
#define WAKE_UCAST (1 << 1)
|
||||
#define WAKE_MCAST (1 << 2)
|
||||
#define WAKE_BCAST (1 << 3)
|
||||
#define WAKE_ARP (1 << 4)
|
||||
#define WAKE_MAGIC (1 << 5)
|
||||
#define WAKE_MAGICSECURE (1 << 6) /* only meaningful if WAKE_MAGIC */
|
||||
|
||||
/* L2-L4 network traffic flow types */
|
||||
#define TCP_V4_FLOW 0x01 /* hash or spec (tcp_ip4_spec) */
|
||||
#define UDP_V4_FLOW 0x02 /* hash or spec (udp_ip4_spec) */
|
||||
#define SCTP_V4_FLOW 0x03 /* hash or spec (sctp_ip4_spec) */
|
||||
#define AH_ESP_V4_FLOW 0x04 /* hash only */
|
||||
#define TCP_V6_FLOW 0x05 /* hash only */
|
||||
#define UDP_V6_FLOW 0x06 /* hash only */
|
||||
#define SCTP_V6_FLOW 0x07 /* hash only */
|
||||
#define AH_ESP_V6_FLOW 0x08 /* hash only */
|
||||
#define AH_V4_FLOW 0x09 /* hash or spec (ah_ip4_spec) */
|
||||
#define ESP_V4_FLOW 0x0a /* hash or spec (esp_ip4_spec) */
|
||||
#define AH_V6_FLOW 0x0b /* hash only */
|
||||
#define ESP_V6_FLOW 0x0c /* hash only */
|
||||
#define IP_USER_FLOW 0x0d /* spec only (usr_ip4_spec) */
|
||||
#define IPV4_FLOW 0x10 /* hash only */
|
||||
#define IPV6_FLOW 0x11 /* hash only */
|
||||
#define ETHER_FLOW 0x12 /* spec only (ether_spec) */
|
||||
|
||||
/* L3-L4 network traffic flow hash options */
|
||||
#define RXH_L2DA (1 << 1)
|
||||
#define RXH_VLAN (1 << 2)
|
||||
#define RXH_L3_PROTO (1 << 3)
|
||||
#define RXH_IP_SRC (1 << 4)
|
||||
#define RXH_IP_DST (1 << 5)
|
||||
#define RXH_L4_B_0_1 (1 << 6) /* src port in case of TCP/UDP/SCTP */
|
||||
#define RXH_L4_B_2_3 (1 << 7) /* dst port in case of TCP/UDP/SCTP */
|
||||
#define RXH_DISCARD (1 << 31)
|
||||
|
||||
#define RX_CLS_FLOW_DISC 0xffffffffffffffffULL
|
||||
|
||||
/* Reset flags */
|
||||
/* The reset() operation must clear the flags for the components which
|
||||
* were actually reset. On successful return, the flags indicate the
|
||||
* components which were not reset, either because they do not exist
|
||||
* in the hardware or because they cannot be reset independently. The
|
||||
* driver must never reset any components that were not requested.
|
||||
*/
|
||||
enum ethtool_reset_flags {
|
||||
/* These flags represent components dedicated to the interface
|
||||
* the command is addressed to. Shift any flag left by
|
||||
* ETH_RESET_SHARED_SHIFT to reset a shared component of the
|
||||
* same type.
|
||||
*/
|
||||
ETH_RESET_MGMT = 1 << 0, /* Management processor */
|
||||
ETH_RESET_IRQ = 1 << 1, /* Interrupt requester */
|
||||
ETH_RESET_DMA = 1 << 2, /* DMA engine */
|
||||
ETH_RESET_FILTER = 1 << 3, /* Filtering/flow direction */
|
||||
ETH_RESET_OFFLOAD = 1 << 4, /* Protocol offload */
|
||||
ETH_RESET_MAC = 1 << 5, /* Media access controller */
|
||||
ETH_RESET_PHY = 1 << 6, /* Transceiver/PHY */
|
||||
ETH_RESET_RAM = 1 << 7, /* RAM shared between
|
||||
* multiple components */
|
||||
|
||||
ETH_RESET_DEDICATED = 0x0000ffff, /* All components dedicated to
|
||||
* this interface */
|
||||
ETH_RESET_ALL = 0xffffffff, /* All components used by this
|
||||
* interface, even if shared */
|
||||
};
|
||||
#define ETH_RESET_SHARED_SHIFT 16
|
||||
|
||||
#endif /* _LINUX_ETHTOOL_H */
|
||||
@@ -0,0 +1,619 @@
|
||||
#ifndef _LINUX_FB_H
|
||||
#define _LINUX_FB_H
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/list.h>
|
||||
|
||||
/* Definitions of frame buffers */
|
||||
|
||||
#define FB_MAX 32 /* sufficient for now */
|
||||
|
||||
#define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
|
||||
|
||||
#define FB_VISUAL_MONO01 0 /* Monochr. 1=Black 0=White */
|
||||
#define FB_VISUAL_MONO10 1 /* Monochr. 1=White 0=Black */
|
||||
#define FB_VISUAL_TRUECOLOR 2 /* True color */
|
||||
#define FB_VISUAL_PSEUDOCOLOR 3 /* Pseudo color (like atari) */
|
||||
#define FB_VISUAL_DIRECTCOLOR 4 /* Direct color */
|
||||
#define FB_VISUAL_STATIC_PSEUDOCOLOR 5 /* Pseudo color readonly */
|
||||
|
||||
#define FB_ACCEL_NONE 0 /* no hardware accelerator */
|
||||
|
||||
struct fb_fix_screeninfo {
|
||||
char id[16]; /* identification string eg "TT Builtin" */
|
||||
unsigned long smem_start; /* Start of frame buffer mem */
|
||||
/* (physical address) */
|
||||
__u32 smem_len; /* Length of frame buffer mem */
|
||||
__u32 type; /* see FB_TYPE_* */
|
||||
__u32 type_aux; /* Interleave for interleaved Planes */
|
||||
__u32 visual; /* see FB_VISUAL_* */
|
||||
__u16 xpanstep; /* zero if no hardware panning */
|
||||
__u16 ypanstep; /* zero if no hardware panning */
|
||||
__u16 ywrapstep; /* zero if no hardware ywrap */
|
||||
__u32 line_length; /* length of a line in bytes */
|
||||
unsigned long mmio_start; /* Start of Memory Mapped I/O */
|
||||
/* (physical address) */
|
||||
__u32 mmio_len; /* Length of Memory Mapped I/O */
|
||||
__u32 accel; /* Indicate to driver which */
|
||||
/* specific chip/card we have */
|
||||
__u16 reserved[3]; /* Reserved for future compatibility */
|
||||
};
|
||||
|
||||
/*
|
||||
* Interpretation of offset for color fields: All offsets are from the right,
|
||||
* inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you
|
||||
* can use the offset as right argument to <<). A pixel afterwards is a bit
|
||||
* stream and is written to video memory as that unmodified.
|
||||
*
|
||||
* For pseudocolor: offset and length should be the same for all color
|
||||
* components. Offset specifies the position of the least significant bit
|
||||
* of the pallette index in a pixel value. Length indicates the number
|
||||
* of available palette entries (i.e. # of entries = 1 << length).
|
||||
*/
|
||||
struct fb_bitfield {
|
||||
__u32 offset; /* beginning of bitfield */
|
||||
__u32 length; /* length of bitfield */
|
||||
__u32 msb_right;
|
||||
|
||||
};
|
||||
|
||||
#define FB_NONSTD_HAM 1 /* Hold-And-Modify (HAM) */
|
||||
#define FB_NONSTD_REV_PIX_IN_B 2 /* order of pixels in each byte is reversed */
|
||||
|
||||
#define FB_ACTIVATE_NOW 0 /* set values immediately (or vbl)*/
|
||||
#define FB_ACTIVATE_NXTOPEN 1 /* activate on next open */
|
||||
#define FB_ACTIVATE_TEST 2 /* don't set, round up impossible */
|
||||
#define FB_ACTIVATE_MASK 15
|
||||
/* values */
|
||||
#define FB_ACTIVATE_VBL 16 /* activate values on next vbl */
|
||||
#define FB_CHANGE_CMAP_VBL 32 /* change colormap on vbl */
|
||||
#define FB_ACTIVATE_ALL 64 /* change all VCs on this fb */
|
||||
#define FB_ACTIVATE_FORCE 128 /* force apply even when no change*/
|
||||
#define FB_ACTIVATE_INV_MODE 256 /* invalidate videomode */
|
||||
|
||||
#define FB_SYNC_HOR_HIGH_ACT 1 /* horizontal sync high active */
|
||||
#define FB_SYNC_VERT_HIGH_ACT 2 /* vertical sync high active */
|
||||
#define FB_SYNC_EXT 4 /* external sync */
|
||||
#define FB_SYNC_COMP_HIGH_ACT 8 /* composite sync high active */
|
||||
#define FB_SYNC_BROADCAST 16 /* broadcast video timings */
|
||||
/* vtotal = 144d/288n/576i => PAL */
|
||||
/* vtotal = 121d/242n/484i => NTSC */
|
||||
#define FB_SYNC_ON_GREEN 32 /* sync on green */
|
||||
|
||||
#define FB_VMODE_NONINTERLACED 0 /* non interlaced */
|
||||
#define FB_VMODE_INTERLACED 1 /* interlaced */
|
||||
#define FB_VMODE_DOUBLE 2 /* double scan */
|
||||
#define FB_VMODE_ODD_FLD_FIRST 4 /* interlaced: top line first */
|
||||
#define FB_VMODE_MASK 255
|
||||
|
||||
#define FB_VMODE_YWRAP 256 /* ywrap instead of panning */
|
||||
#define FB_VMODE_SMOOTH_XPAN 512 /* smooth xpan possible (internally used) */
|
||||
#define FB_VMODE_CONUPDATE 512 /* don't update x/yoffset */
|
||||
|
||||
/*
|
||||
* Display rotation support
|
||||
*/
|
||||
#define FB_ROTATE_UR 0
|
||||
#define FB_ROTATE_CW 1
|
||||
#define FB_ROTATE_UD 2
|
||||
#define FB_ROTATE_CCW 3
|
||||
|
||||
#define PICOS2KHZ(a) (1000000000UL/(a))
|
||||
#define KHZ2PICOS(a) (1000000000UL/(a))
|
||||
|
||||
struct fb_var_screeninfo {
|
||||
__u32 xres; /* visible resolution */
|
||||
__u32 yres;
|
||||
__u32 xres_virtual; /* virtual resolution */
|
||||
__u32 yres_virtual;
|
||||
__u32 xoffset; /* offset from virtual to visible */
|
||||
__u32 yoffset; /* resolution */
|
||||
|
||||
__u32 bits_per_pixel; /* guess what */
|
||||
__u32 grayscale; /* != 0 Graylevels instead of colors */
|
||||
|
||||
struct fb_bitfield red; /* bitfield in fb mem if true color, */
|
||||
struct fb_bitfield green; /* else only length is significant */
|
||||
struct fb_bitfield blue;
|
||||
struct fb_bitfield transp; /* transparency */
|
||||
|
||||
__u32 nonstd; /* != 0 Non standard pixel format */
|
||||
|
||||
__u32 activate; /* see FB_ACTIVATE_* */
|
||||
|
||||
__u32 height; /* height of picture in mm */
|
||||
__u32 width; /* width of picture in mm */
|
||||
|
||||
__u32 accel_flags; /* (OBSOLETE) see fb_info.flags */
|
||||
|
||||
/* Timing: All values in pixclocks, except pixclock (of course) */
|
||||
__u32 pixclock; /* pixel clock in ps (pico seconds) */
|
||||
__u32 left_margin; /* time from sync to picture */
|
||||
__u32 right_margin; /* time from picture to sync */
|
||||
__u32 upper_margin; /* time from sync to picture */
|
||||
__u32 lower_margin;
|
||||
__u32 hsync_len; /* length of horizontal sync */
|
||||
__u32 vsync_len; /* length of vertical sync */
|
||||
__u32 sync; /* see FB_SYNC_* */
|
||||
__u32 vmode; /* see FB_VMODE_* */
|
||||
__u32 rotate; /* angle we rotate counter clockwise */
|
||||
__u32 reserved[5]; /* Reserved for future compatibility */
|
||||
};
|
||||
|
||||
struct fb_cmap {
|
||||
__u32 start; /* First entry */
|
||||
__u32 len; /* Number of entries */
|
||||
__u16 *red; /* Red values */
|
||||
__u16 *green;
|
||||
__u16 *blue;
|
||||
__u16 *transp; /* transparency, can be NULL */
|
||||
};
|
||||
|
||||
struct fb_con2fbmap {
|
||||
__u32 console;
|
||||
__u32 framebuffer;
|
||||
};
|
||||
|
||||
/* VESA Blanking Levels */
|
||||
#define VESA_NO_BLANKING 0
|
||||
#define VESA_VSYNC_SUSPEND 1
|
||||
#define VESA_HSYNC_SUSPEND 2
|
||||
#define VESA_POWERDOWN 3
|
||||
|
||||
|
||||
enum {
|
||||
/* screen: unblanked, hsync: on, vsync: on */
|
||||
FB_BLANK_UNBLANK = VESA_NO_BLANKING,
|
||||
|
||||
/* screen: blanked, hsync: on, vsync: on */
|
||||
FB_BLANK_NORMAL = VESA_NO_BLANKING + 1,
|
||||
|
||||
/* screen: blanked, hsync: on, vsync: off */
|
||||
FB_BLANK_VSYNC_SUSPEND = VESA_VSYNC_SUSPEND + 1,
|
||||
|
||||
/* screen: blanked, hsync: off, vsync: on */
|
||||
FB_BLANK_HSYNC_SUSPEND = VESA_HSYNC_SUSPEND + 1,
|
||||
|
||||
/* screen: blanked, hsync: off, vsync: off */
|
||||
FB_BLANK_POWERDOWN = VESA_POWERDOWN + 1
|
||||
};
|
||||
|
||||
#define FB_VBLANK_VBLANKING 0x001 /* currently in a vertical blank */
|
||||
#define FB_VBLANK_HBLANKING 0x002 /* currently in a horizontal blank */
|
||||
#define FB_VBLANK_HAVE_VBLANK 0x004 /* vertical blanks can be detected */
|
||||
#define FB_VBLANK_HAVE_HBLANK 0x008 /* horizontal blanks can be detected */
|
||||
#define FB_VBLANK_HAVE_COUNT 0x010 /* global retrace counter is available */
|
||||
#define FB_VBLANK_HAVE_VCOUNT 0x020 /* the vcount field is valid */
|
||||
#define FB_VBLANK_HAVE_HCOUNT 0x040 /* the hcount field is valid */
|
||||
#define FB_VBLANK_VSYNCING 0x080 /* currently in a vsync */
|
||||
#define FB_VBLANK_HAVE_VSYNC 0x100 /* verical syncs can be detected */
|
||||
|
||||
struct fb_vblank {
|
||||
__u32 flags; /* FB_VBLANK flags */
|
||||
__u32 count; /* counter of retraces since boot */
|
||||
__u32 vcount; /* current scanline position */
|
||||
__u32 hcount; /* current scandot position */
|
||||
__u32 reserved[4]; /* reserved for future compatibility */
|
||||
};
|
||||
|
||||
/* Internal HW accel */
|
||||
#define ROP_COPY 0
|
||||
#define ROP_XOR 1
|
||||
|
||||
struct fb_copyarea {
|
||||
__u32 dx;
|
||||
__u32 dy;
|
||||
__u32 width;
|
||||
__u32 height;
|
||||
__u32 sx;
|
||||
__u32 sy;
|
||||
};
|
||||
|
||||
struct fb_fillrect {
|
||||
__u32 dx; /* screen-relative */
|
||||
__u32 dy;
|
||||
__u32 width;
|
||||
__u32 height;
|
||||
__u32 color;
|
||||
__u32 rop;
|
||||
};
|
||||
|
||||
struct fb_image {
|
||||
__u32 dx; /* Where to place image */
|
||||
__u32 dy;
|
||||
__u32 width; /* Size of image */
|
||||
__u32 height;
|
||||
__u32 fg_color; /* Only used when a mono bitmap */
|
||||
__u32 bg_color;
|
||||
__u8 depth; /* Depth of the image */
|
||||
const char *data; /* Pointer to image data */
|
||||
struct fb_cmap cmap; /* color map info */
|
||||
};
|
||||
|
||||
/*
|
||||
* hardware cursor control
|
||||
*/
|
||||
|
||||
#define FB_CUR_SETIMAGE 0x01
|
||||
#define FB_CUR_SETPOS 0x02
|
||||
#define FB_CUR_SETHOT 0x04
|
||||
#define FB_CUR_SETCMAP 0x08
|
||||
#define FB_CUR_SETSHAPE 0x10
|
||||
#define FB_CUR_SETSIZE 0x20
|
||||
#define FB_CUR_SETALL 0xFF
|
||||
|
||||
struct fbcurpos {
|
||||
__u16 x, y;
|
||||
};
|
||||
|
||||
struct fb_cursor {
|
||||
__u16 set; /* what to set */
|
||||
__u16 enable; /* cursor on/off */
|
||||
__u16 rop; /* bitop operation */
|
||||
const char *mask; /* cursor mask bits */
|
||||
struct fbcurpos hot; /* cursor hot spot */
|
||||
struct fb_image image; /* Cursor image */
|
||||
};
|
||||
|
||||
#ifdef CONFIG_FB_BACKLIGHT
|
||||
/* Settings for the generic backlight code */
|
||||
#define FB_BACKLIGHT_LEVELS 128
|
||||
#define FB_BACKLIGHT_MAX 0xFF
|
||||
#endif
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
struct vm_area_struct;
|
||||
struct fb_info;
|
||||
struct device;
|
||||
struct file;
|
||||
|
||||
/* Definitions below are used in the parsed monitor specs */
|
||||
#define FB_DPMS_ACTIVE_OFF 1
|
||||
#define FB_DPMS_SUSPEND 2
|
||||
#define FB_DPMS_STANDBY 4
|
||||
|
||||
#define FB_DISP_DDI 1
|
||||
#define FB_DISP_ANA_700_300 2
|
||||
#define FB_DISP_ANA_714_286 4
|
||||
#define FB_DISP_ANA_1000_400 8
|
||||
#define FB_DISP_ANA_700_000 16
|
||||
|
||||
#define FB_DISP_MONO 32
|
||||
#define FB_DISP_RGB 64
|
||||
#define FB_DISP_MULTI 128
|
||||
#define FB_DISP_UNKNOWN 256
|
||||
|
||||
#define FB_SIGNAL_NONE 0
|
||||
#define FB_SIGNAL_BLANK_BLANK 1
|
||||
#define FB_SIGNAL_SEPARATE 2
|
||||
#define FB_SIGNAL_COMPOSITE 4
|
||||
#define FB_SIGNAL_SYNC_ON_GREEN 8
|
||||
#define FB_SIGNAL_SERRATION_ON 16
|
||||
|
||||
#define FB_MISC_PRIM_COLOR 1
|
||||
#define FB_MISC_1ST_DETAIL 2 /* First Detailed Timing is preferred */
|
||||
struct fb_chroma {
|
||||
__u32 redx; /* in fraction of 1024 */
|
||||
__u32 greenx;
|
||||
__u32 bluex;
|
||||
__u32 whitex;
|
||||
__u32 redy;
|
||||
__u32 greeny;
|
||||
__u32 bluey;
|
||||
__u32 whitey;
|
||||
};
|
||||
|
||||
struct fb_monspecs {
|
||||
struct fb_chroma chroma;
|
||||
struct fb_videomode *modedb; /* mode database */
|
||||
__u8 manufacturer[4]; /* Manufacturer */
|
||||
__u8 monitor[14]; /* Monitor String */
|
||||
__u8 serial_no[14]; /* Serial Number */
|
||||
__u8 ascii[14]; /* ? */
|
||||
__u32 modedb_len; /* mode database length */
|
||||
__u32 model; /* Monitor Model */
|
||||
__u32 serial; /* Serial Number - Integer */
|
||||
__u32 year; /* Year manufactured */
|
||||
__u32 week; /* Week Manufactured */
|
||||
__u32 hfmin; /* hfreq lower limit (Hz) */
|
||||
__u32 hfmax; /* hfreq upper limit (Hz) */
|
||||
__u32 dclkmin; /* pixelclock lower limit (Hz) */
|
||||
__u32 dclkmax; /* pixelclock upper limit (Hz) */
|
||||
__u16 input; /* display type - see FB_DISP_* */
|
||||
__u16 dpms; /* DPMS support - see FB_DPMS_ */
|
||||
__u16 signal; /* Signal Type - see FB_SIGNAL_* */
|
||||
__u16 vfmin; /* vfreq lower limit (Hz) */
|
||||
__u16 vfmax; /* vfreq upper limit (Hz) */
|
||||
__u16 gamma; /* Gamma - in fractions of 100 */
|
||||
__u16 gtf : 1; /* supports GTF */
|
||||
__u16 misc; /* Misc flags - see FB_MISC_* */
|
||||
__u8 version; /* EDID version... */
|
||||
__u8 revision; /* ...and revision */
|
||||
__u8 max_x; /* Maximum horizontal size (cm) */
|
||||
__u8 max_y; /* Maximum vertical size (cm) */
|
||||
};
|
||||
|
||||
struct fb_cmap_user {
|
||||
__u32 start; /* First entry */
|
||||
__u32 len; /* Number of entries */
|
||||
__u16 *red; /* Red values */
|
||||
__u16 *green;
|
||||
__u16 *blue;
|
||||
__u16 *transp; /* transparency, can be NULL */
|
||||
};
|
||||
|
||||
struct fb_image_user {
|
||||
__u32 dx; /* Where to place image */
|
||||
__u32 dy;
|
||||
__u32 width; /* Size of image */
|
||||
__u32 height;
|
||||
__u32 fg_color; /* Only used when a mono bitmap */
|
||||
__u32 bg_color;
|
||||
__u8 depth; /* Depth of the image */
|
||||
const char *data; /* Pointer to image data */
|
||||
struct fb_cmap_user cmap; /* color map info */
|
||||
};
|
||||
|
||||
struct fb_cursor_user {
|
||||
__u16 set; /* what to set */
|
||||
__u16 enable; /* cursor on/off */
|
||||
__u16 rop; /* bitop operation */
|
||||
const char *mask; /* cursor mask bits */
|
||||
struct fbcurpos hot; /* cursor hot spot */
|
||||
struct fb_image_user image; /* Cursor image */
|
||||
};
|
||||
|
||||
/*
|
||||
* Register/unregister for framebuffer events
|
||||
*/
|
||||
|
||||
/* The resolution of the passed in fb_info about to change */
|
||||
#define FB_EVENT_MODE_CHANGE 0x01
|
||||
/* The display on this fb_info is beeing suspended, no access to the
|
||||
* framebuffer is allowed any more after that call returns
|
||||
*/
|
||||
#define FB_EVENT_SUSPEND 0x02
|
||||
/* The display on this fb_info was resumed, you can restore the display
|
||||
* if you own it
|
||||
*/
|
||||
#define FB_EVENT_RESUME 0x03
|
||||
/* An entry from the modelist was removed */
|
||||
#define FB_EVENT_MODE_DELETE 0x04
|
||||
/* A driver registered itself */
|
||||
#define FB_EVENT_FB_REGISTERED 0x05
|
||||
/* A driver unregistered itself */
|
||||
#define FB_EVENT_FB_UNREGISTERED 0x06
|
||||
/* CONSOLE-SPECIFIC: get console to framebuffer mapping */
|
||||
#define FB_EVENT_GET_CONSOLE_MAP 0x07
|
||||
/* CONSOLE-SPECIFIC: set console to framebuffer mapping */
|
||||
#define FB_EVENT_SET_CONSOLE_MAP 0x08
|
||||
/* A hardware display blank change occurred */
|
||||
#define FB_EVENT_BLANK 0x09
|
||||
/* Private modelist is to be replaced */
|
||||
#define FB_EVENT_NEW_MODELIST 0x0A
|
||||
/* The resolution of the passed in fb_info about to change and
|
||||
all vc's should be changed */
|
||||
#define FB_EVENT_MODE_CHANGE_ALL 0x0B
|
||||
/* A software display blank change occurred */
|
||||
#define FB_EVENT_CONBLANK 0x0C
|
||||
/* Get drawing requirements */
|
||||
#define FB_EVENT_GET_REQ 0x0D
|
||||
/* Unbind from the console if possible */
|
||||
#define FB_EVENT_FB_UNBIND 0x0E
|
||||
|
||||
struct fb_event {
|
||||
struct fb_info *info;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct fb_blit_caps {
|
||||
u32 x;
|
||||
u32 y;
|
||||
u32 len;
|
||||
u32 flags;
|
||||
};
|
||||
|
||||
/*
|
||||
* Pixmap structure definition
|
||||
*
|
||||
* The purpose of this structure is to translate data
|
||||
* from the hardware independent format of fbdev to what
|
||||
* format the hardware needs.
|
||||
*/
|
||||
|
||||
#define FB_PIXMAP_DEFAULT 1 /* used internally by fbcon */
|
||||
#define FB_PIXMAP_SYSTEM 2 /* memory is in system RAM */
|
||||
#define FB_PIXMAP_IO 4 /* memory is iomapped */
|
||||
#define FB_PIXMAP_SYNC 256 /* set if GPU can DMA */
|
||||
|
||||
struct fb_pixmap {
|
||||
u8 *addr; /* pointer to memory */
|
||||
u32 size; /* size of buffer in bytes */
|
||||
u32 offset; /* current offset to buffer */
|
||||
u32 buf_align; /* byte alignment of each bitmap */
|
||||
u32 scan_align; /* alignment per scanline */
|
||||
u32 access_align; /* alignment per read/write (bits) */
|
||||
u32 flags; /* see FB_PIXMAP_* */
|
||||
u32 blit_x; /* supported bit block dimensions (1-32)*/
|
||||
u32 blit_y; /* Format: blit_x = 1 << (width - 1) */
|
||||
/* blit_y = 1 << (height - 1) */
|
||||
/* if 0, will be set to 0xffffffff (all)*/
|
||||
/* access methods */
|
||||
void (*writeio)(struct fb_info *info, void *dst, void *src, unsigned int size);
|
||||
void (*readio) (struct fb_info *info, void *dst, void *src, unsigned int size);
|
||||
};
|
||||
|
||||
#ifdef CONFIG_FB_DEFERRED_IO
|
||||
struct fb_deferred_io {
|
||||
/* delay between mkwrite and deferred handler */
|
||||
unsigned long delay;
|
||||
struct mutex lock; /* mutex that protects the page list */
|
||||
struct list_head pagelist; /* list of touched pages */
|
||||
/* callback */
|
||||
void (*deferred_io)(struct fb_info *info, struct list_head *pagelist);
|
||||
};
|
||||
#endif
|
||||
|
||||
/* FBINFO_* = fb_info.flags bit flags */
|
||||
#define FBINFO_MODULE 0x0001 /* Low-level driver is a module */
|
||||
#define FBINFO_HWACCEL_DISABLED 0x0002
|
||||
/* When FBINFO_HWACCEL_DISABLED is set:
|
||||
* Hardware acceleration is turned off. Software implementations
|
||||
* of required functions (copyarea(), fillrect(), and imageblit())
|
||||
* takes over; acceleration engine should be in a quiescent state */
|
||||
|
||||
/* hints */
|
||||
#define FBINFO_PARTIAL_PAN_OK 0x0040 /* otw use pan only for double-buffering */
|
||||
#define FBINFO_READS_FAST 0x0080 /* soft-copy faster than rendering */
|
||||
|
||||
/*
|
||||
* A driver may set this flag to indicate that it does want a set_par to be
|
||||
* called every time when fbcon_switch is executed. The advantage is that with
|
||||
* this flag set you can really be sure that set_par is always called before
|
||||
* any of the functions dependant on the correct hardware state or altering
|
||||
* that state, even if you are using some broken X releases. The disadvantage
|
||||
* is that it introduces unwanted delays to every console switch if set_par
|
||||
* is slow. It is a good idea to try this flag in the drivers initialization
|
||||
* code whenever there is a bug report related to switching between X and the
|
||||
* framebuffer console.
|
||||
*/
|
||||
#define FBINFO_MISC_ALWAYS_SETPAR 0x40000
|
||||
|
||||
/*
|
||||
* Host and GPU endianness differ.
|
||||
*/
|
||||
#define FBINFO_FOREIGN_ENDIAN 0x100000
|
||||
/*
|
||||
* Big endian math. This is the same flags as above, but with different
|
||||
* meaning, it is set by the fb subsystem depending FOREIGN_ENDIAN flag
|
||||
* and host endianness. Drivers should not use this flag.
|
||||
*/
|
||||
#define FBINFO_BE_MATH 0x100000
|
||||
|
||||
struct fb_info {
|
||||
int node;
|
||||
int flags;
|
||||
struct fb_var_screeninfo var; /* Current var */
|
||||
struct fb_fix_screeninfo fix; /* Current fix */
|
||||
struct fb_monspecs monspecs; /* Current Monitor specs */
|
||||
struct fb_pixmap pixmap; /* Image hardware mapper */
|
||||
struct fb_pixmap sprite; /* Cursor hardware mapper */
|
||||
struct fb_cmap cmap; /* Current cmap */
|
||||
struct list_head modelist; /* mode list */
|
||||
struct fb_videomode *mode; /* current mode */
|
||||
|
||||
char *screen_base; /* Virtual address */
|
||||
unsigned long screen_size; /* Amount of ioremapped VRAM or 0 */
|
||||
void *pseudo_palette; /* Fake palette of 16 colors */
|
||||
#define FBINFO_STATE_RUNNING 0
|
||||
#define FBINFO_STATE_SUSPENDED 1
|
||||
u32 state; /* Hardware state i.e suspend */
|
||||
void *fbcon_par; /* fbcon use-only private area */
|
||||
/* From here on everything is device dependent */
|
||||
void *par;
|
||||
};
|
||||
|
||||
#define FBINFO_DEFAULT 0
|
||||
|
||||
#define FBINFO_FLAG_MODULE FBINFO_MODULE
|
||||
#define FBINFO_FLAG_DEFAULT FBINFO_DEFAULT
|
||||
|
||||
/* This will go away */
|
||||
#if defined(__sparc__)
|
||||
|
||||
/* We map all of our framebuffers such that big-endian accesses
|
||||
* are what we want, so the following is sufficient.
|
||||
*/
|
||||
|
||||
/* This will go away */
|
||||
#define fb_readb sbus_readb
|
||||
#define fb_readw sbus_readw
|
||||
#define fb_readl sbus_readl
|
||||
#define fb_readq sbus_readq
|
||||
#define fb_writeb sbus_writeb
|
||||
#define fb_writew sbus_writew
|
||||
#define fb_writel sbus_writel
|
||||
#define fb_writeq sbus_writeq
|
||||
#define fb_memset sbus_memset_io
|
||||
|
||||
#elif defined(__i386__) || defined(__alpha__) || defined(__x86_64__) || defined(__hppa__) || defined(__sh__) || defined(__powerpc__) || defined(__bfin__)
|
||||
|
||||
#define fb_readb __raw_readb
|
||||
#define fb_readw __raw_readw
|
||||
#define fb_readl __raw_readl
|
||||
#define fb_readq __raw_readq
|
||||
#define fb_writeb __raw_writeb
|
||||
#define fb_writew __raw_writew
|
||||
#define fb_writel __raw_writel
|
||||
#define fb_writeq __raw_writeq
|
||||
#define fb_memset memset_io
|
||||
|
||||
#else
|
||||
|
||||
#define fb_readb(addr) (*(volatile u8 *) (addr))
|
||||
#define fb_readw(addr) (*(volatile u16 *) (addr))
|
||||
#define fb_readl(addr) (*(volatile u32 *) (addr))
|
||||
#define fb_readq(addr) (*(volatile u64 *) (addr))
|
||||
#define fb_writeb(b,addr) (*(volatile u8 *) (addr) = (b))
|
||||
#define fb_writew(b,addr) (*(volatile u16 *) (addr) = (b))
|
||||
#define fb_writel(b,addr) (*(volatile u32 *) (addr) = (b))
|
||||
#define fb_writeq(b,addr) (*(volatile u64 *) (addr) = (b))
|
||||
#define fb_memset memset
|
||||
|
||||
#endif
|
||||
|
||||
#define FB_LEFT_POS(p, bpp) (fb_be_math(p) ? (32 - (bpp)) : 0)
|
||||
#define FB_SHIFT_HIGH(p, val, bits) (fb_be_math(p) ? (val) >> (bits) : \
|
||||
(val) << (bits))
|
||||
#define FB_SHIFT_LOW(p, val, bits) (fb_be_math(p) ? (val) << (bits) : \
|
||||
(val) >> (bits))
|
||||
/* drivers/video/fbmon.c */
|
||||
#define FB_MAXTIMINGS 0
|
||||
#define FB_VSYNCTIMINGS 1
|
||||
#define FB_HSYNCTIMINGS 2
|
||||
#define FB_DCLKTIMINGS 3
|
||||
#define FB_IGNOREMON 0x100
|
||||
|
||||
#define FB_MODE_IS_UNKNOWN 0
|
||||
#define FB_MODE_IS_DETAILED 1
|
||||
#define FB_MODE_IS_STANDARD 2
|
||||
#define FB_MODE_IS_VESA 4
|
||||
#define FB_MODE_IS_CALCULATED 8
|
||||
#define FB_MODE_IS_FIRST 16
|
||||
#define FB_MODE_IS_FROM_VAR 32
|
||||
|
||||
|
||||
/* drivers/video/fbcmap.c */
|
||||
|
||||
extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp);
|
||||
extern void fb_dealloc_cmap(struct fb_cmap *cmap);
|
||||
extern int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to);
|
||||
extern int fb_cmap_to_user(const struct fb_cmap *from, struct fb_cmap_user *to);
|
||||
extern int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *fb_info);
|
||||
extern int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *fb_info);
|
||||
extern const struct fb_cmap *fb_default_cmap(int len);
|
||||
extern void fb_invert_cmaps(void);
|
||||
|
||||
struct fb_videomode {
|
||||
const char *name; /* optional */
|
||||
u32 refresh; /* optional */
|
||||
u32 xres;
|
||||
u32 yres;
|
||||
u32 pixclock;
|
||||
u32 left_margin;
|
||||
u32 right_margin;
|
||||
u32 upper_margin;
|
||||
u32 lower_margin;
|
||||
u32 hsync_len;
|
||||
u32 vsync_len;
|
||||
u32 sync;
|
||||
u32 vmode;
|
||||
u32 flag;
|
||||
};
|
||||
|
||||
int board_video_skip(void);
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
#endif /* _LINUX_FB_H */
|
||||
@@ -0,0 +1,178 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
|
||||
/*
|
||||
* INET An implementation of the TCP/IP protocol suite for the LINUX
|
||||
* operating system. INET is implemented using the BSD Socket
|
||||
* interface as the means of communication with the user level.
|
||||
*
|
||||
* Global definitions for the Ethernet IEEE 802.3 interface.
|
||||
*
|
||||
* Version: @(#)if_ether.h 1.0.1a 02/08/94
|
||||
*
|
||||
* Author: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
|
||||
* Donald Becker, <becker@super.org>
|
||||
* Alan Cox, <alan@lxorguk.ukuu.org.uk>
|
||||
* Steve Whitehouse, <gw7rrm@eeshack3.swan.ac.uk>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version
|
||||
* 2 of the License, or (at your option) any later version.
|
||||
*/
|
||||
|
||||
#ifndef _UAPI_LINUX_IF_ETHER_H
|
||||
#define _UAPI_LINUX_IF_ETHER_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
/*
|
||||
* IEEE 802.3 Ethernet magic constants. The frame sizes omit the preamble
|
||||
* and FCS/CRC (frame check sequence).
|
||||
*/
|
||||
|
||||
#define ETH_ALEN 6 /* Octets in one ethernet addr */
|
||||
#define ETH_TLEN 2 /* Octets in ethernet type field */
|
||||
#define ETH_HLEN 14 /* Total octets in header. */
|
||||
#define ETH_ZLEN 60 /* Min. octets in frame sans FCS */
|
||||
#define ETH_DATA_LEN 1500 /* Max. octets in payload */
|
||||
#define ETH_FRAME_LEN 1514 /* Max. octets in frame sans FCS */
|
||||
#define ETH_FCS_LEN 4 /* Octets in the FCS */
|
||||
|
||||
#define ETH_MIN_MTU 68 /* Min IPv4 MTU per RFC791 */
|
||||
#define ETH_MAX_MTU 0xFFFFU /* 65535, same as IP_MAX_MTU */
|
||||
|
||||
/*
|
||||
* These are the defined Ethernet Protocol ID's.
|
||||
*/
|
||||
|
||||
#define ETH_P_LOOP 0x0060 /* Ethernet Loopback packet */
|
||||
#define ETH_P_PUP 0x0200 /* Xerox PUP packet */
|
||||
#define ETH_P_PUPAT 0x0201 /* Xerox PUP Addr Trans packet */
|
||||
#define ETH_P_TSN 0x22F0 /* TSN (IEEE 1722) packet */
|
||||
#define ETH_P_ERSPAN2 0x22EB /* ERSPAN version 2 (type III) */
|
||||
#define ETH_P_IP 0x0800 /* Internet Protocol packet */
|
||||
#define ETH_P_X25 0x0805 /* CCITT X.25 */
|
||||
#define ETH_P_ARP 0x0806 /* Address Resolution packet */
|
||||
#define ETH_P_BPQ 0x08FF /* G8BPQ AX.25 Ethernet Packet */
|
||||
/* [ NOT AN OFFICIALLY REGISTERED ID ] */
|
||||
#define ETH_P_IEEEPUP 0x0a00 /* Xerox IEEE802.3 PUP packet */
|
||||
#define ETH_P_IEEEPUPAT 0x0a01 /* Xerox IEEE802.3 PUP Addr Trans packet */
|
||||
#define ETH_P_BATMAN 0x4305 /* B.A.T.M.A.N.-Advanced packet */
|
||||
/* [ NOT AN OFFICIALLY REGISTERED ID ] */
|
||||
#define ETH_P_DEC 0x6000 /* DEC Assigned proto */
|
||||
#define ETH_P_DNA_DL 0x6001 /* DEC DNA Dump/Load */
|
||||
#define ETH_P_DNA_RC 0x6002 /* DEC DNA Remote Console */
|
||||
#define ETH_P_DNA_RT 0x6003 /* DEC DNA Routing */
|
||||
#define ETH_P_LAT 0x6004 /* DEC LAT */
|
||||
#define ETH_P_DIAG 0x6005 /* DEC Diagnostics */
|
||||
#define ETH_P_CUST 0x6006 /* DEC Customer use */
|
||||
#define ETH_P_SCA 0x6007 /* DEC Systems Comms Arch */
|
||||
#define ETH_P_TEB 0x6558 /* Trans Ether Bridging */
|
||||
#define ETH_P_RARP 0x8035 /* Reverse Addr Res packet */
|
||||
#define ETH_P_ATALK 0x809B /* Appletalk DDP */
|
||||
#define ETH_P_AARP 0x80F3 /* Appletalk AARP */
|
||||
#define ETH_P_8021Q 0x8100 /* 802.1Q VLAN Extended Header */
|
||||
#define ETH_P_ERSPAN 0x88BE /* ERSPAN type II */
|
||||
#define ETH_P_IPX 0x8137 /* IPX over DIX */
|
||||
#define ETH_P_IPV6 0x86DD /* IPv6 over bluebook */
|
||||
#define ETH_P_PAUSE 0x8808 /* IEEE Pause frames. See 802.3 31B */
|
||||
#define ETH_P_SLOW 0x8809 /* Slow Protocol. See 802.3ad 43B */
|
||||
#define ETH_P_WCCP 0x883E /* Web-cache coordination */
|
||||
/* protocol defined in */
|
||||
/* draft-wilson-wrec-wccp-v2-00.txt */
|
||||
#define ETH_P_MPLS_UC 0x8847 /* MPLS Unicast traffic */
|
||||
#define ETH_P_MPLS_MC 0x8848 /* MPLS Multicast traffic */
|
||||
#define ETH_P_ATMMPOA 0x884c /* MultiProtocol Over ATM */
|
||||
#define ETH_P_PPP_DISC 0x8863 /* PPPoE discovery messages */
|
||||
#define ETH_P_PPP_SES 0x8864 /* PPPoE session messages */
|
||||
#define ETH_P_LINK_CTL 0x886c /* HPNA, wlan link local tunnel */
|
||||
#define ETH_P_ATMFATE 0x8884 /* Frame-based ATM Transport over Ethernet */
|
||||
#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
|
||||
#define ETH_P_AOE 0x88A2 /* ATA over Ethernet */
|
||||
#define ETH_P_8021AD 0x88A8 /* 802.1ad Service VLAN */
|
||||
#define ETH_P_802_EX1 0x88B5 /* 802.1 Local Experimental 1. */
|
||||
#define ETH_P_PREAUTH 0x88C7 /* 802.11 Preauthentication */
|
||||
#define ETH_P_TIPC 0x88CA /* TIPC */
|
||||
#define ETH_P_MACSEC 0x88E5 /* 802.1ae MACsec */
|
||||
#define ETH_P_8021AH 0x88E7 /* 802.1ah Backbone Service Tag */
|
||||
#define ETH_P_MVRP 0x88F5 /* 802.1Q MVRP */
|
||||
#define ETH_P_1588 0x88F7 /* IEEE 1588 Timesync */
|
||||
#define ETH_P_NCSI 0x88F8 /* NCSI protocol */
|
||||
#define ETH_P_PRP 0x88FB /* IEC 62439-3 PRP/HSRv0 */
|
||||
#define ETH_P_FCOE 0x8906 /* Fibre Channel over Ethernet */
|
||||
#define ETH_P_IBOE 0x8915 /* Infiniband over Ethernet */
|
||||
#define ETH_P_TDLS 0x890D /* TDLS */
|
||||
#define ETH_P_FIP 0x8914 /* FCoE Initialization Protocol */
|
||||
#define ETH_P_80221 0x8917 /* IEEE 802.21 Media Independent */
|
||||
/* Handover Protocol */
|
||||
#define ETH_P_HSR 0x892F /* IEC 62439-3 HSRv1 */
|
||||
#define ETH_P_NSH 0x894F /* Network Service Header */
|
||||
#define ETH_P_LOOPBACK 0x9000 /* Ethernet loopback packet, per IEEE 802.3 */
|
||||
#define ETH_P_QINQ1 0x9100 /* deprecated QinQ VLAN */
|
||||
/* [ NOT AN OFFICIALLY REGISTERED ID ] */
|
||||
#define ETH_P_QINQ2 0x9200 /* deprecated QinQ VLAN */
|
||||
/* [ NOT AN OFFICIALLY REGISTERED ID ] */
|
||||
#define ETH_P_QINQ3 0x9300 /* deprecated QinQ VLAN] */
|
||||
/* [ NOT AN OFFICIALLY REGISTERED ID ] */
|
||||
#define ETH_P_EDSA 0xDADA /* Ethertype DSA */
|
||||
/* [ NOT AN OFFICIALLY REGISTERED ID ] */
|
||||
#define ETH_P_IFE 0xED3E /* ForCES inter-FE LFB type */
|
||||
#define ETH_P_AF_IUCV 0xFBFB /* IBM af_iucv */
|
||||
/* [ NOT AN OFFICIALLY REGISTERED ID ] */
|
||||
|
||||
#define ETH_P_802_3_MIN 0x0600 /* If the value in the ethernet type is less */
|
||||
/* than this value then the frame is Ethernet */
|
||||
/* II. Else it is 802.3 */
|
||||
|
||||
/*
|
||||
* Non DIX types. Won't clash for 1500 types.
|
||||
*/
|
||||
|
||||
#define ETH_P_802_3 0x0001 /* Dummy type for 802.3 frames */
|
||||
#define ETH_P_AX25 0x0002 /* Dummy protocol id for AX.25 */
|
||||
#define ETH_P_ALL 0x0003 /* Every packet (be careful!!!) */
|
||||
#define ETH_P_802_2 0x0004 /* 802.2 frames */
|
||||
#define ETH_P_SNAP 0x0005 /* Internal only */
|
||||
#define ETH_P_DDCMP 0x0006 /* DEC DDCMP: Internal only */
|
||||
#define ETH_P_WAN_PPP 0x0007 /* Dummy type for WAN PPP frames*/
|
||||
#define ETH_P_PPP_MP 0x0008 /* Dummy type for PPP MP frames */
|
||||
#define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type */
|
||||
#define ETH_P_CAN 0x000C /* CAN: Controller Area Network */
|
||||
#define ETH_P_CANFD 0x000D /* CANFD: CAN flexible data rate*/
|
||||
#define ETH_P_PPPTALK 0x0010 /* Dummy type for Atalk over PPP*/
|
||||
#define ETH_P_TR_802_2 0x0011 /* 802.2 frames */
|
||||
#define ETH_P_MOBITEX 0x0015 /* Mobitex (kaz@cafe.net) */
|
||||
#define ETH_P_CONTROL 0x0016 /* Card specific control frames */
|
||||
#define ETH_P_IRDA 0x0017 /* Linux-IrDA */
|
||||
#define ETH_P_ECONET 0x0018 /* Acorn Econet */
|
||||
#define ETH_P_HDLC 0x0019 /* HDLC frames */
|
||||
#define ETH_P_ARCNET 0x001A /* 1A for ArcNet :-) */
|
||||
#define ETH_P_DSA 0x001B /* Distributed Switch Arch */
|
||||
#define ETH_P_TRAILER 0x001C /* Trailer switch tagging */
|
||||
#define ETH_P_PHONET 0x00F5 /* Nokia Phonet frames */
|
||||
#define ETH_P_IEEE802154 0x00F6 /* IEEE802.15.4 frame */
|
||||
#define ETH_P_CAIF 0x00F7 /* ST-Ericsson CAIF protocol */
|
||||
#define ETH_P_XDSA 0x00F8 /* Multiplexed DSA protocol */
|
||||
#define ETH_P_MAP 0x00F9 /* Qualcomm multiplexing and */
|
||||
/* aggregation protocol */
|
||||
|
||||
/* The following macros come from Linux kernel include/linux/if_vlan.h */
|
||||
|
||||
#define VLAN_HLEN 4 /* The additional bytes required by VLAN */
|
||||
/* (in addition to the Ethernet header) */
|
||||
#define VLAN_ETH_HLEN 18 /* Total octets in header. */
|
||||
#define VLAN_ETH_ZLEN 64 /* Min. octets in frame sans FCS */
|
||||
|
||||
/*
|
||||
* According to 802.3ac, the packet can be 4 bytes longer. --Klika Jan
|
||||
*/
|
||||
#define VLAN_ETH_DATA_LEN 1500 /* Max. octets in payload */
|
||||
#define VLAN_ETH_FRAME_LEN 1518 /* Max. octets in frame sans FCS */
|
||||
|
||||
#define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */
|
||||
#define VLAN_PRIO_SHIFT 13
|
||||
#define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator */
|
||||
#define VLAN_TAG_PRESENT VLAN_CFI_MASK
|
||||
#define VLAN_VID_MASK 0x0fff /* VLAN Identifier */
|
||||
#define VLAN_N_VID 4096
|
||||
|
||||
#endif /* _UAPI_LINUX_IF_ETHER_H */
|
||||
@@ -0,0 +1,593 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* QUICC Engine (QE) Internal Memory Map.
|
||||
* The Internal Memory Map for devices with QE on them. This
|
||||
* is the superset of all QE devices (8360, etc.).
|
||||
*
|
||||
* Copyright (c) 2006-2009, 2011 Freescale Semiconductor, Inc.
|
||||
* Author: Shlomi Gridih <gridish@freescale.com>
|
||||
*/
|
||||
|
||||
#ifndef __IMMAP_QE_H__
|
||||
#define __IMMAP_QE_H__
|
||||
|
||||
#ifdef CONFIG_MPC83xx
|
||||
#if defined(CONFIG_ARCH_MPC8360)
|
||||
#define QE_MURAM_SIZE 0xc000UL
|
||||
#define MAX_QE_RISC 2
|
||||
#define QE_NUM_OF_SNUM 28
|
||||
#elif defined(CONFIG_ARCH_MPC832X) || defined(CONFIG_ARCH_MPC8309)
|
||||
#define QE_MURAM_SIZE 0x4000UL
|
||||
#define MAX_QE_RISC 1
|
||||
#define QE_NUM_OF_SNUM 28
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ARCH_LS1021A
|
||||
#define QE_MURAM_SIZE 0x6000UL
|
||||
#define MAX_QE_RISC 1
|
||||
#define QE_NUM_OF_SNUM 28
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PPC
|
||||
#define QE_IMMR_OFFSET 0x00140000
|
||||
#else
|
||||
#define QE_IMMR_OFFSET 0x01400000
|
||||
#endif
|
||||
|
||||
/* QE I-RAM */
|
||||
typedef struct qe_iram {
|
||||
u32 iadd; /* I-RAM Address Register */
|
||||
u32 idata; /* I-RAM Data Register */
|
||||
u8 res0[0x4];
|
||||
u32 iready;
|
||||
u8 res1[0x70];
|
||||
} __attribute__ ((packed)) qe_iram_t;
|
||||
|
||||
/* QE Interrupt Controller */
|
||||
typedef struct qe_ic {
|
||||
u32 qicr;
|
||||
u32 qivec;
|
||||
u32 qripnr;
|
||||
u32 qipnr;
|
||||
u32 qipxcc;
|
||||
u32 qipycc;
|
||||
u32 qipwcc;
|
||||
u32 qipzcc;
|
||||
u32 qimr;
|
||||
u32 qrimr;
|
||||
u32 qicnr;
|
||||
u8 res0[0x4];
|
||||
u32 qiprta;
|
||||
u32 qiprtb;
|
||||
u8 res1[0x4];
|
||||
u32 qricr;
|
||||
u8 res2[0x20];
|
||||
u32 qhivec;
|
||||
u8 res3[0x1C];
|
||||
} __attribute__ ((packed)) qe_ic_t;
|
||||
|
||||
/* Communications Processor */
|
||||
typedef struct cp_qe {
|
||||
u32 cecr; /* QE command register */
|
||||
u32 ceccr; /* QE controller configuration register */
|
||||
u32 cecdr; /* QE command data register */
|
||||
u8 res0[0xA];
|
||||
u16 ceter; /* QE timer event register */
|
||||
u8 res1[0x2];
|
||||
u16 cetmr; /* QE timers mask register */
|
||||
u32 cetscr; /* QE time-stamp timer control register */
|
||||
u32 cetsr1; /* QE time-stamp register 1 */
|
||||
u32 cetsr2; /* QE time-stamp register 2 */
|
||||
u8 res2[0x8];
|
||||
u32 cevter; /* QE virtual tasks event register */
|
||||
u32 cevtmr; /* QE virtual tasks mask register */
|
||||
u16 cercr; /* QE RAM control register */
|
||||
u8 res3[0x2];
|
||||
u8 res4[0x24];
|
||||
u16 ceexe1; /* QE external request 1 event register */
|
||||
u8 res5[0x2];
|
||||
u16 ceexm1; /* QE external request 1 mask register */
|
||||
u8 res6[0x2];
|
||||
u16 ceexe2; /* QE external request 2 event register */
|
||||
u8 res7[0x2];
|
||||
u16 ceexm2; /* QE external request 2 mask register */
|
||||
u8 res8[0x2];
|
||||
u16 ceexe3; /* QE external request 3 event register */
|
||||
u8 res9[0x2];
|
||||
u16 ceexm3; /* QE external request 3 mask register */
|
||||
u8 res10[0x2];
|
||||
u16 ceexe4; /* QE external request 4 event register */
|
||||
u8 res11[0x2];
|
||||
u16 ceexm4; /* QE external request 4 mask register */
|
||||
u8 res12[0x2];
|
||||
u8 res13[0x280];
|
||||
} __attribute__ ((packed)) cp_qe_t;
|
||||
|
||||
/* QE Multiplexer */
|
||||
typedef struct qe_mux {
|
||||
u32 cmxgcr; /* CMX general clock route register */
|
||||
u32 cmxsi1cr_l; /* CMX SI1 clock route low register */
|
||||
u32 cmxsi1cr_h; /* CMX SI1 clock route high register */
|
||||
u32 cmxsi1syr; /* CMX SI1 SYNC route register */
|
||||
u32 cmxucr1; /* CMX UCC1, UCC3 clock route register */
|
||||
u32 cmxucr2; /* CMX UCC5, UCC7 clock route register */
|
||||
u32 cmxucr3; /* CMX UCC2, UCC4 clock route register */
|
||||
u32 cmxucr4; /* CMX UCC6, UCC8 clock route register */
|
||||
u32 cmxupcr; /* CMX UPC clock route register */
|
||||
u8 res0[0x1C];
|
||||
} __attribute__ ((packed)) qe_mux_t;
|
||||
|
||||
/* QE Timers */
|
||||
typedef struct qe_timers {
|
||||
u8 gtcfr1; /* Timer 1 2 global configuration register */
|
||||
u8 res0[0x3];
|
||||
u8 gtcfr2; /* Timer 3 4 global configuration register */
|
||||
u8 res1[0xB];
|
||||
u16 gtmdr1; /* Timer 1 mode register */
|
||||
u16 gtmdr2; /* Timer 2 mode register */
|
||||
u16 gtrfr1; /* Timer 1 reference register */
|
||||
u16 gtrfr2; /* Timer 2 reference register */
|
||||
u16 gtcpr1; /* Timer 1 capture register */
|
||||
u16 gtcpr2; /* Timer 2 capture register */
|
||||
u16 gtcnr1; /* Timer 1 counter */
|
||||
u16 gtcnr2; /* Timer 2 counter */
|
||||
u16 gtmdr3; /* Timer 3 mode register */
|
||||
u16 gtmdr4; /* Timer 4 mode register */
|
||||
u16 gtrfr3; /* Timer 3 reference register */
|
||||
u16 gtrfr4; /* Timer 4 reference register */
|
||||
u16 gtcpr3; /* Timer 3 capture register */
|
||||
u16 gtcpr4; /* Timer 4 capture register */
|
||||
u16 gtcnr3; /* Timer 3 counter */
|
||||
u16 gtcnr4; /* Timer 4 counter */
|
||||
u16 gtevr1; /* Timer 1 event register */
|
||||
u16 gtevr2; /* Timer 2 event register */
|
||||
u16 gtevr3; /* Timer 3 event register */
|
||||
u16 gtevr4; /* Timer 4 event register */
|
||||
u16 gtps; /* Timer 1 prescale register */
|
||||
u8 res2[0x46];
|
||||
} __attribute__ ((packed)) qe_timers_t;
|
||||
|
||||
/* BRG */
|
||||
typedef struct qe_brg {
|
||||
u32 brgc1; /* BRG1 configuration register */
|
||||
u32 brgc2; /* BRG2 configuration register */
|
||||
u32 brgc3; /* BRG3 configuration register */
|
||||
u32 brgc4; /* BRG4 configuration register */
|
||||
u32 brgc5; /* BRG5 configuration register */
|
||||
u32 brgc6; /* BRG6 configuration register */
|
||||
u32 brgc7; /* BRG7 configuration register */
|
||||
u32 brgc8; /* BRG8 configuration register */
|
||||
u32 brgc9; /* BRG9 configuration register */
|
||||
u32 brgc10; /* BRG10 configuration register */
|
||||
u32 brgc11; /* BRG11 configuration register */
|
||||
u32 brgc12; /* BRG12 configuration register */
|
||||
u32 brgc13; /* BRG13 configuration register */
|
||||
u32 brgc14; /* BRG14 configuration register */
|
||||
u32 brgc15; /* BRG15 configuration register */
|
||||
u32 brgc16; /* BRG16 configuration register */
|
||||
u8 res0[0x40];
|
||||
} __attribute__ ((packed)) qe_brg_t;
|
||||
|
||||
/* SPI */
|
||||
typedef struct spi {
|
||||
u8 res0[0x20];
|
||||
u32 spmode; /* SPI mode register */
|
||||
u8 res1[0x2];
|
||||
u8 spie; /* SPI event register */
|
||||
u8 res2[0x1];
|
||||
u8 res3[0x2];
|
||||
u8 spim; /* SPI mask register */
|
||||
u8 res4[0x1];
|
||||
u8 res5[0x1];
|
||||
u8 spcom; /* SPI command register */
|
||||
u8 res6[0x2];
|
||||
u32 spitd; /* SPI transmit data register (cpu mode) */
|
||||
u32 spird; /* SPI receive data register (cpu mode) */
|
||||
u8 res7[0x8];
|
||||
} __attribute__ ((packed)) spi_t;
|
||||
|
||||
/* SI */
|
||||
typedef struct si1 {
|
||||
u16 siamr1; /* SI1 TDMA mode register */
|
||||
u16 sibmr1; /* SI1 TDMB mode register */
|
||||
u16 sicmr1; /* SI1 TDMC mode register */
|
||||
u16 sidmr1; /* SI1 TDMD mode register */
|
||||
u8 siglmr1_h; /* SI1 global mode register high */
|
||||
u8 res0[0x1];
|
||||
u8 sicmdr1_h; /* SI1 command register high */
|
||||
u8 res2[0x1];
|
||||
u8 sistr1_h; /* SI1 status register high */
|
||||
u8 res3[0x1];
|
||||
u16 sirsr1_h; /* SI1 RAM shadow address register high */
|
||||
u8 sitarc1; /* SI1 RAM counter Tx TDMA */
|
||||
u8 sitbrc1; /* SI1 RAM counter Tx TDMB */
|
||||
u8 sitcrc1; /* SI1 RAM counter Tx TDMC */
|
||||
u8 sitdrc1; /* SI1 RAM counter Tx TDMD */
|
||||
u8 sirarc1; /* SI1 RAM counter Rx TDMA */
|
||||
u8 sirbrc1; /* SI1 RAM counter Rx TDMB */
|
||||
u8 sircrc1; /* SI1 RAM counter Rx TDMC */
|
||||
u8 sirdrc1; /* SI1 RAM counter Rx TDMD */
|
||||
u8 res4[0x8];
|
||||
u16 siemr1; /* SI1 TDME mode register 16 bits */
|
||||
u16 sifmr1; /* SI1 TDMF mode register 16 bits */
|
||||
u16 sigmr1; /* SI1 TDMG mode register 16 bits */
|
||||
u16 sihmr1; /* SI1 TDMH mode register 16 bits */
|
||||
u8 siglmg1_l; /* SI1 global mode register low 8 bits */
|
||||
u8 res5[0x1];
|
||||
u8 sicmdr1_l; /* SI1 command register low 8 bits */
|
||||
u8 res6[0x1];
|
||||
u8 sistr1_l; /* SI1 status register low 8 bits */
|
||||
u8 res7[0x1];
|
||||
u16 sirsr1_l; /* SI1 RAM shadow address register low 16 bits */
|
||||
u8 siterc1; /* SI1 RAM counter Tx TDME 8 bits */
|
||||
u8 sitfrc1; /* SI1 RAM counter Tx TDMF 8 bits */
|
||||
u8 sitgrc1; /* SI1 RAM counter Tx TDMG 8 bits */
|
||||
u8 sithrc1; /* SI1 RAM counter Tx TDMH 8 bits */
|
||||
u8 sirerc1; /* SI1 RAM counter Rx TDME 8 bits */
|
||||
u8 sirfrc1; /* SI1 RAM counter Rx TDMF 8 bits */
|
||||
u8 sirgrc1; /* SI1 RAM counter Rx TDMG 8 bits */
|
||||
u8 sirhrc1; /* SI1 RAM counter Rx TDMH 8 bits */
|
||||
u8 res8[0x8];
|
||||
u32 siml1; /* SI1 multiframe limit register */
|
||||
u8 siedm1; /* SI1 extended diagnostic mode register */
|
||||
u8 res9[0xBB];
|
||||
} __attribute__ ((packed)) si1_t;
|
||||
|
||||
/* SI Routing Tables */
|
||||
typedef struct sir {
|
||||
u8 tx[0x400];
|
||||
u8 rx[0x400];
|
||||
u8 res0[0x800];
|
||||
} __attribute__ ((packed)) sir_t;
|
||||
|
||||
/* USB Controller. */
|
||||
typedef struct usb_ctlr {
|
||||
u8 usb_usmod;
|
||||
u8 usb_usadr;
|
||||
u8 usb_uscom;
|
||||
u8 res1[1];
|
||||
u16 usb_usep1;
|
||||
u16 usb_usep2;
|
||||
u16 usb_usep3;
|
||||
u16 usb_usep4;
|
||||
u8 res2[4];
|
||||
u16 usb_usber;
|
||||
u8 res3[2];
|
||||
u16 usb_usbmr;
|
||||
u8 res4[1];
|
||||
u8 usb_usbs;
|
||||
u16 usb_ussft;
|
||||
u8 res5[2];
|
||||
u16 usb_usfrn;
|
||||
u8 res6[0x22];
|
||||
} __attribute__ ((packed)) usb_t;
|
||||
|
||||
/* MCC */
|
||||
typedef struct mcc {
|
||||
u32 mcce; /* MCC event register */
|
||||
u32 mccm; /* MCC mask register */
|
||||
u32 mccf; /* MCC configuration register */
|
||||
u32 merl; /* MCC emergency request level register */
|
||||
u8 res0[0xF0];
|
||||
} __attribute__ ((packed)) mcc_t;
|
||||
|
||||
/* QE UCC Slow */
|
||||
typedef struct ucc_slow {
|
||||
u32 gumr_l; /* UCCx general mode register (low) */
|
||||
u32 gumr_h; /* UCCx general mode register (high) */
|
||||
u16 upsmr; /* UCCx protocol-specific mode register */
|
||||
u8 res0[0x2];
|
||||
u16 utodr; /* UCCx transmit on demand register */
|
||||
u16 udsr; /* UCCx data synchronization register */
|
||||
u16 ucce; /* UCCx event register */
|
||||
u8 res1[0x2];
|
||||
u16 uccm; /* UCCx mask register */
|
||||
u8 res2[0x1];
|
||||
u8 uccs; /* UCCx status register */
|
||||
u8 res3[0x24];
|
||||
u16 utpt;
|
||||
u8 guemr; /* UCC general extended mode register */
|
||||
u8 res4[0x200 - 0x091];
|
||||
} __attribute__ ((packed)) ucc_slow_t;
|
||||
|
||||
typedef struct ucc_mii_mng {
|
||||
u32 miimcfg; /* MII management configuration reg */
|
||||
u32 miimcom; /* MII management command reg */
|
||||
u32 miimadd; /* MII management address reg */
|
||||
u32 miimcon; /* MII management control reg */
|
||||
u32 miimstat; /* MII management status reg */
|
||||
u32 miimind; /* MII management indication reg */
|
||||
u32 ifctl; /* interface control reg */
|
||||
u32 ifstat; /* interface statux reg */
|
||||
} __attribute__ ((packed))uec_mii_t;
|
||||
|
||||
typedef struct ucc_ethernet {
|
||||
u32 maccfg1; /* mac configuration reg. 1 */
|
||||
u32 maccfg2; /* mac configuration reg. 2 */
|
||||
u32 ipgifg; /* interframe gap reg. */
|
||||
u32 hafdup; /* half-duplex reg. */
|
||||
u8 res1[0x10];
|
||||
u32 miimcfg; /* MII management configuration reg */
|
||||
u32 miimcom; /* MII management command reg */
|
||||
u32 miimadd; /* MII management address reg */
|
||||
u32 miimcon; /* MII management control reg */
|
||||
u32 miimstat; /* MII management status reg */
|
||||
u32 miimind; /* MII management indication reg */
|
||||
u32 ifctl; /* interface control reg */
|
||||
u32 ifstat; /* interface statux reg */
|
||||
u32 macstnaddr1; /* mac station address part 1 reg */
|
||||
u32 macstnaddr2; /* mac station address part 2 reg */
|
||||
u8 res2[0x8];
|
||||
u32 uempr; /* UCC Ethernet Mac parameter reg */
|
||||
u32 utbipar; /* UCC tbi address reg */
|
||||
u16 uescr; /* UCC Ethernet statistics control reg */
|
||||
u8 res3[0x180 - 0x15A];
|
||||
u32 tx64; /* Total number of frames (including bad
|
||||
* frames) transmitted that were exactly
|
||||
* of the minimal length (64 for un tagged,
|
||||
* 68 for tagged, or with length exactly
|
||||
* equal to the parameter MINLength */
|
||||
u32 tx127; /* Total number of frames (including bad
|
||||
* frames) transmitted that were between
|
||||
* MINLength (Including FCS length==4)
|
||||
* and 127 octets */
|
||||
u32 tx255; /* Total number of frames (including bad
|
||||
* frames) transmitted that were between
|
||||
* 128 (Including FCS length==4) and 255
|
||||
* octets */
|
||||
u32 rx64; /* Total number of frames received including
|
||||
* bad frames that were exactly of the
|
||||
* mninimal length (64 bytes) */
|
||||
u32 rx127; /* Total number of frames (including bad
|
||||
* frames) received that were between
|
||||
* MINLength (Including FCS length==4)
|
||||
* and 127 octets */
|
||||
u32 rx255; /* Total number of frames (including
|
||||
* bad frames) received that were between
|
||||
* 128 (Including FCS length==4) and 255
|
||||
* octets */
|
||||
u32 txok; /* Total number of octets residing in frames
|
||||
* that where involved in succesfull
|
||||
* transmission */
|
||||
u16 txcf; /* Total number of PAUSE control frames
|
||||
* transmitted by this MAC */
|
||||
u8 res4[0x2];
|
||||
u32 tmca; /* Total number of frames that were transmitted
|
||||
* succesfully with the group address bit set
|
||||
* that are not broadcast frames */
|
||||
u32 tbca; /* Total number of frames transmitted
|
||||
* succesfully that had destination address
|
||||
* field equal to the broadcast address */
|
||||
u32 rxfok; /* Total number of frames received OK */
|
||||
u32 rxbok; /* Total number of octets received OK */
|
||||
u32 rbyt; /* Total number of octets received including
|
||||
* octets in bad frames. Must be implemented
|
||||
* in HW because it includes octets in frames
|
||||
* that never even reach the UCC */
|
||||
u32 rmca; /* Total number of frames that were received
|
||||
* succesfully with the group address bit set
|
||||
* that are not broadcast frames */
|
||||
u32 rbca; /* Total number of frames received succesfully
|
||||
* that had destination address equal to the
|
||||
* broadcast address */
|
||||
u32 scar; /* Statistics carry register */
|
||||
u32 scam; /* Statistics caryy mask register */
|
||||
u8 res5[0x200 - 0x1c4];
|
||||
} __attribute__ ((packed)) uec_t;
|
||||
|
||||
/* QE UCC Fast */
|
||||
typedef struct ucc_fast {
|
||||
u32 gumr; /* UCCx general mode register */
|
||||
u32 upsmr; /* UCCx protocol-specific mode register */
|
||||
u16 utodr; /* UCCx transmit on demand register */
|
||||
u8 res0[0x2];
|
||||
u16 udsr; /* UCCx data synchronization register */
|
||||
u8 res1[0x2];
|
||||
u32 ucce; /* UCCx event register */
|
||||
u32 uccm; /* UCCx mask register. */
|
||||
u8 uccs; /* UCCx status register */
|
||||
u8 res2[0x7];
|
||||
u32 urfb; /* UCC receive FIFO base */
|
||||
u16 urfs; /* UCC receive FIFO size */
|
||||
u8 res3[0x2];
|
||||
u16 urfet; /* UCC receive FIFO emergency threshold */
|
||||
u16 urfset; /* UCC receive FIFO special emergency
|
||||
* threshold */
|
||||
u32 utfb; /* UCC transmit FIFO base */
|
||||
u16 utfs; /* UCC transmit FIFO size */
|
||||
u8 res4[0x2];
|
||||
u16 utfet; /* UCC transmit FIFO emergency threshold */
|
||||
u8 res5[0x2];
|
||||
u16 utftt; /* UCC transmit FIFO transmit threshold */
|
||||
u8 res6[0x2];
|
||||
u16 utpt; /* UCC transmit polling timer */
|
||||
u8 res7[0x2];
|
||||
u32 urtry; /* UCC retry counter register */
|
||||
u8 res8[0x4C];
|
||||
u8 guemr; /* UCC general extended mode register */
|
||||
u8 res9[0x100 - 0x091];
|
||||
uec_t ucc_eth;
|
||||
} __attribute__ ((packed)) ucc_fast_t;
|
||||
|
||||
/* QE UCC */
|
||||
typedef struct ucc_common {
|
||||
u8 res1[0x90];
|
||||
u8 guemr;
|
||||
u8 res2[0x200 - 0x091];
|
||||
} __attribute__ ((packed)) ucc_common_t;
|
||||
|
||||
typedef struct ucc {
|
||||
union {
|
||||
ucc_slow_t slow;
|
||||
ucc_fast_t fast;
|
||||
ucc_common_t common;
|
||||
};
|
||||
} __attribute__ ((packed)) ucc_t;
|
||||
|
||||
/* MultiPHY UTOPIA POS Controllers (UPC) */
|
||||
typedef struct upc {
|
||||
u32 upgcr; /* UTOPIA/POS general configuration register */
|
||||
u32 uplpa; /* UTOPIA/POS last PHY address */
|
||||
u32 uphec; /* ATM HEC register */
|
||||
u32 upuc; /* UTOPIA/POS UCC configuration */
|
||||
u32 updc1; /* UTOPIA/POS device 1 configuration */
|
||||
u32 updc2; /* UTOPIA/POS device 2 configuration */
|
||||
u32 updc3; /* UTOPIA/POS device 3 configuration */
|
||||
u32 updc4; /* UTOPIA/POS device 4 configuration */
|
||||
u32 upstpa; /* UTOPIA/POS STPA threshold */
|
||||
u8 res0[0xC];
|
||||
u32 updrs1_h; /* UTOPIA/POS device 1 rate select */
|
||||
u32 updrs1_l; /* UTOPIA/POS device 1 rate select */
|
||||
u32 updrs2_h; /* UTOPIA/POS device 2 rate select */
|
||||
u32 updrs2_l; /* UTOPIA/POS device 2 rate select */
|
||||
u32 updrs3_h; /* UTOPIA/POS device 3 rate select */
|
||||
u32 updrs3_l; /* UTOPIA/POS device 3 rate select */
|
||||
u32 updrs4_h; /* UTOPIA/POS device 4 rate select */
|
||||
u32 updrs4_l; /* UTOPIA/POS device 4 rate select */
|
||||
u32 updrp1; /* UTOPIA/POS device 1 receive priority low */
|
||||
u32 updrp2; /* UTOPIA/POS device 2 receive priority low */
|
||||
u32 updrp3; /* UTOPIA/POS device 3 receive priority low */
|
||||
u32 updrp4; /* UTOPIA/POS device 4 receive priority low */
|
||||
u32 upde1; /* UTOPIA/POS device 1 event */
|
||||
u32 upde2; /* UTOPIA/POS device 2 event */
|
||||
u32 upde3; /* UTOPIA/POS device 3 event */
|
||||
u32 upde4; /* UTOPIA/POS device 4 event */
|
||||
u16 uprp1;
|
||||
u16 uprp2;
|
||||
u16 uprp3;
|
||||
u16 uprp4;
|
||||
u8 res1[0x8];
|
||||
u16 uptirr1_0; /* Device 1 transmit internal rate 0 */
|
||||
u16 uptirr1_1; /* Device 1 transmit internal rate 1 */
|
||||
u16 uptirr1_2; /* Device 1 transmit internal rate 2 */
|
||||
u16 uptirr1_3; /* Device 1 transmit internal rate 3 */
|
||||
u16 uptirr2_0; /* Device 2 transmit internal rate 0 */
|
||||
u16 uptirr2_1; /* Device 2 transmit internal rate 1 */
|
||||
u16 uptirr2_2; /* Device 2 transmit internal rate 2 */
|
||||
u16 uptirr2_3; /* Device 2 transmit internal rate 3 */
|
||||
u16 uptirr3_0; /* Device 3 transmit internal rate 0 */
|
||||
u16 uptirr3_1; /* Device 3 transmit internal rate 1 */
|
||||
u16 uptirr3_2; /* Device 3 transmit internal rate 2 */
|
||||
u16 uptirr3_3; /* Device 3 transmit internal rate 3 */
|
||||
u16 uptirr4_0; /* Device 4 transmit internal rate 0 */
|
||||
u16 uptirr4_1; /* Device 4 transmit internal rate 1 */
|
||||
u16 uptirr4_2; /* Device 4 transmit internal rate 2 */
|
||||
u16 uptirr4_3; /* Device 4 transmit internal rate 3 */
|
||||
u32 uper1; /* Device 1 port enable register */
|
||||
u32 uper2; /* Device 2 port enable register */
|
||||
u32 uper3; /* Device 3 port enable register */
|
||||
u32 uper4; /* Device 4 port enable register */
|
||||
u8 res2[0x150];
|
||||
} __attribute__ ((packed)) upc_t;
|
||||
|
||||
/* SDMA */
|
||||
typedef struct sdma {
|
||||
u32 sdsr; /* Serial DMA status register */
|
||||
u32 sdmr; /* Serial DMA mode register */
|
||||
u32 sdtr1; /* SDMA system bus threshold register */
|
||||
u32 sdtr2; /* SDMA secondary bus threshold register */
|
||||
u32 sdhy1; /* SDMA system bus hysteresis register */
|
||||
u32 sdhy2; /* SDMA secondary bus hysteresis register */
|
||||
u32 sdta1; /* SDMA system bus address register */
|
||||
u32 sdta2; /* SDMA secondary bus address register */
|
||||
u32 sdtm1; /* SDMA system bus MSNUM register */
|
||||
u32 sdtm2; /* SDMA secondary bus MSNUM register */
|
||||
u8 res0[0x10];
|
||||
u32 sdaqr; /* SDMA address bus qualify register */
|
||||
u32 sdaqmr; /* SDMA address bus qualify mask register */
|
||||
u8 res1[0x4];
|
||||
u32 sdwbcr; /* SDMA CAM entries base register */
|
||||
u8 res2[0x38];
|
||||
} __attribute__ ((packed)) sdma_t;
|
||||
|
||||
/* Debug Space */
|
||||
typedef struct dbg {
|
||||
u32 bpdcr; /* Breakpoint debug command register */
|
||||
u32 bpdsr; /* Breakpoint debug status register */
|
||||
u32 bpdmr; /* Breakpoint debug mask register */
|
||||
u32 bprmrr0; /* Breakpoint request mode risc register 0 */
|
||||
u32 bprmrr1; /* Breakpoint request mode risc register 1 */
|
||||
u8 res0[0x8];
|
||||
u32 bprmtr0; /* Breakpoint request mode trb register 0 */
|
||||
u32 bprmtr1; /* Breakpoint request mode trb register 1 */
|
||||
u8 res1[0x8];
|
||||
u32 bprmir; /* Breakpoint request mode immediate register */
|
||||
u32 bprmsr; /* Breakpoint request mode serial register */
|
||||
u32 bpemr; /* Breakpoint exit mode register */
|
||||
u8 res2[0x48];
|
||||
} __attribute__ ((packed)) dbg_t;
|
||||
|
||||
/*
|
||||
* RISC Special Registers (Trap and Breakpoint). These are described in
|
||||
* the QE Developer's Handbook.
|
||||
*/
|
||||
typedef struct rsp {
|
||||
u32 tibcr[16]; /* Trap/instruction breakpoint control regs */
|
||||
u8 res0[64];
|
||||
u32 ibcr0;
|
||||
u32 ibs0;
|
||||
u32 ibcnr0;
|
||||
u8 res1[4];
|
||||
u32 ibcr1;
|
||||
u32 ibs1;
|
||||
u32 ibcnr1;
|
||||
u32 npcr;
|
||||
u32 dbcr;
|
||||
u32 dbar;
|
||||
u32 dbamr;
|
||||
u32 dbsr;
|
||||
u32 dbcnr;
|
||||
u8 res2[12];
|
||||
u32 dbdr_h;
|
||||
u32 dbdr_l;
|
||||
u32 dbdmr_h;
|
||||
u32 dbdmr_l;
|
||||
u32 bsr;
|
||||
u32 bor;
|
||||
u32 bior;
|
||||
u8 res3[4];
|
||||
u32 iatr[4];
|
||||
u32 eccr; /* Exception control configuration register */
|
||||
u32 eicr;
|
||||
u8 res4[0x100-0xf8];
|
||||
} __attribute__ ((packed)) rsp_t;
|
||||
|
||||
typedef struct qe_immap {
|
||||
qe_iram_t iram; /* I-RAM */
|
||||
qe_ic_t ic; /* Interrupt Controller */
|
||||
cp_qe_t cp; /* Communications Processor */
|
||||
qe_mux_t qmx; /* QE Multiplexer */
|
||||
qe_timers_t qet; /* QE Timers */
|
||||
spi_t spi[0x2]; /* spi */
|
||||
mcc_t mcc; /* mcc */
|
||||
qe_brg_t brg; /* brg */
|
||||
usb_t usb; /* USB */
|
||||
si1_t si1; /* SI */
|
||||
u8 res11[0x800];
|
||||
sir_t sir; /* SI Routing Tables */
|
||||
ucc_t ucc1; /* ucc1 */
|
||||
ucc_t ucc3; /* ucc3 */
|
||||
ucc_t ucc5; /* ucc5 */
|
||||
ucc_t ucc7; /* ucc7 */
|
||||
u8 res12[0x600];
|
||||
upc_t upc1; /* MultiPHY UTOPIA POS Controller 1 */
|
||||
ucc_t ucc2; /* ucc2 */
|
||||
ucc_t ucc4; /* ucc4 */
|
||||
ucc_t ucc6; /* ucc6 */
|
||||
ucc_t ucc8; /* ucc8 */
|
||||
u8 res13[0x600];
|
||||
upc_t upc2; /* MultiPHY UTOPIA POS Controller 2 */
|
||||
sdma_t sdma; /* SDMA */
|
||||
dbg_t dbg; /* Debug Space */
|
||||
rsp_t rsp[0x2]; /* RISC Special Registers
|
||||
* (Trap and Breakpoint) */
|
||||
u8 res14[0x300];
|
||||
u8 res15[0x3A00];
|
||||
u8 res16[0x8000]; /* 0x108000 - 0x110000 */
|
||||
u8 muram[QE_MURAM_SIZE];
|
||||
} __attribute__ ((packed)) qe_map_t;
|
||||
|
||||
extern qe_map_t *qe_immr;
|
||||
|
||||
#endif /* __IMMAP_QE_H__ */
|
||||
@@ -0,0 +1,152 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Copyright (c) 1999-2002 Vojtech Pavlik
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_INPUT_H
|
||||
#define _LINUX_INPUT_H
|
||||
|
||||
/*
|
||||
* Keys and buttons
|
||||
*
|
||||
* Most of the keys/buttons are modeled after USB HUT 1.12
|
||||
* (see http://www.usb.org/developers/hidpage).
|
||||
* Abbreviations in the comments:
|
||||
* AC - Application Control
|
||||
* AL - Application Launch Button
|
||||
* SC - System Control
|
||||
*/
|
||||
|
||||
#define KEY_RESERVED 0
|
||||
#define KEY_ESC 1
|
||||
#define KEY_1 2
|
||||
#define KEY_2 3
|
||||
#define KEY_3 4
|
||||
#define KEY_4 5
|
||||
#define KEY_5 6
|
||||
#define KEY_6 7
|
||||
#define KEY_7 8
|
||||
#define KEY_8 9
|
||||
#define KEY_9 10
|
||||
#define KEY_0 11
|
||||
#define KEY_MINUS 12
|
||||
#define KEY_EQUAL 13
|
||||
#define KEY_BACKSPACE 14
|
||||
#define KEY_TAB 15
|
||||
#define KEY_Q 16
|
||||
#define KEY_W 17
|
||||
#define KEY_E 18
|
||||
#define KEY_R 19
|
||||
#define KEY_T 20
|
||||
#define KEY_Y 21
|
||||
#define KEY_U 22
|
||||
#define KEY_I 23
|
||||
#define KEY_O 24
|
||||
#define KEY_P 25
|
||||
#define KEY_LEFTBRACE 26
|
||||
#define KEY_RIGHTBRACE 27
|
||||
#define KEY_ENTER 28
|
||||
#define KEY_LEFTCTRL 29
|
||||
#define KEY_A 30
|
||||
#define KEY_S 31
|
||||
#define KEY_D 32
|
||||
#define KEY_F 33
|
||||
#define KEY_G 34
|
||||
#define KEY_H 35
|
||||
#define KEY_J 36
|
||||
#define KEY_K 37
|
||||
#define KEY_L 38
|
||||
#define KEY_SEMICOLON 39
|
||||
#define KEY_APOSTROPHE 40
|
||||
#define KEY_GRAVE 41
|
||||
#define KEY_LEFTSHIFT 42
|
||||
#define KEY_BACKSLASH 43
|
||||
#define KEY_Z 44
|
||||
#define KEY_X 45
|
||||
#define KEY_C 46
|
||||
#define KEY_V 47
|
||||
#define KEY_B 48
|
||||
#define KEY_N 49
|
||||
#define KEY_M 50
|
||||
#define KEY_COMMA 51
|
||||
#define KEY_DOT 52
|
||||
#define KEY_SLASH 53
|
||||
#define KEY_RIGHTSHIFT 54
|
||||
#define KEY_KPASTERISK 55
|
||||
#define KEY_LEFTALT 56
|
||||
#define KEY_SPACE 57
|
||||
#define KEY_CAPSLOCK 58
|
||||
#define KEY_F1 59
|
||||
#define KEY_F2 60
|
||||
#define KEY_F3 61
|
||||
#define KEY_F4 62
|
||||
#define KEY_F5 63
|
||||
#define KEY_F6 64
|
||||
#define KEY_F7 65
|
||||
#define KEY_F8 66
|
||||
#define KEY_F9 67
|
||||
#define KEY_F10 68
|
||||
#define KEY_NUMLOCK 69
|
||||
#define KEY_SCROLLLOCK 70
|
||||
#define KEY_KP7 71
|
||||
#define KEY_KP8 72
|
||||
#define KEY_KP9 73
|
||||
#define KEY_KPMINUS 74
|
||||
#define KEY_KP4 75
|
||||
#define KEY_KP5 76
|
||||
#define KEY_KP6 77
|
||||
#define KEY_KPPLUS 78
|
||||
#define KEY_KP1 79
|
||||
#define KEY_KP2 80
|
||||
#define KEY_KP3 81
|
||||
#define KEY_KP0 82
|
||||
#define KEY_KPDOT 83
|
||||
|
||||
#define KEY_ZENKAKUHANKAKU 85
|
||||
#define KEY_102ND 86
|
||||
#define KEY_F11 87
|
||||
#define KEY_F12 88
|
||||
#define KEY_RO 89
|
||||
#define KEY_KATAKANA 90
|
||||
#define KEY_HIRAGANA 91
|
||||
#define KEY_HENKAN 92
|
||||
#define KEY_KATAKANAHIRAGANA 93
|
||||
#define KEY_MUHENKAN 94
|
||||
#define KEY_KPJPCOMMA 95
|
||||
#define KEY_KPENTER 96
|
||||
#define KEY_RIGHTCTRL 97
|
||||
#define KEY_KPSLASH 98
|
||||
#define KEY_SYSRQ 99
|
||||
#define KEY_RIGHTALT 100
|
||||
#define KEY_LINEFEED 101
|
||||
#define KEY_HOME 102
|
||||
#define KEY_UP 103
|
||||
#define KEY_PAGEUP 104
|
||||
#define KEY_LEFT 105
|
||||
#define KEY_RIGHT 106
|
||||
#define KEY_END 107
|
||||
#define KEY_DOWN 108
|
||||
#define KEY_PAGEDOWN 109
|
||||
#define KEY_INSERT 110
|
||||
#define KEY_DELETE 111
|
||||
#define KEY_MACRO 112
|
||||
#define KEY_MUTE 113
|
||||
#define KEY_VOLUMEDOWN 114
|
||||
#define KEY_VOLUMEUP 115
|
||||
#define KEY_POWER 116 /* SC System Power Down */
|
||||
#define KEY_KPEQUAL 117
|
||||
#define KEY_KPPLUSMINUS 118
|
||||
#define KEY_PAUSE 119
|
||||
#define KEY_SCALE 120 /* AL Compiz Scale (Expose) */
|
||||
|
||||
#define KEY_KPCOMMA 121
|
||||
#define KEY_HANGEUL 122
|
||||
#define KEY_HANGUEL KEY_HANGEUL
|
||||
#define KEY_HANJA 123
|
||||
#define KEY_YEN 124
|
||||
#define KEY_LEFTMETA 125
|
||||
#define KEY_RIGHTMETA 126
|
||||
#define KEY_COMPOSE 127
|
||||
#define KEY_FN 0x1d0
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,72 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
|
||||
#ifndef _LINUX_IO_H
|
||||
#define _LINUX_IO_H
|
||||
|
||||
#include <linux/compiler.h>
|
||||
#include <linux/types.h>
|
||||
#include <asm/io.h>
|
||||
|
||||
#ifndef CONFIG_HAVE_ARCH_IOMAP
|
||||
static inline u8 ioread8(const volatile void __iomem *addr)
|
||||
{
|
||||
return readb(addr);
|
||||
}
|
||||
|
||||
static inline u16 ioread16(const volatile void __iomem *addr)
|
||||
{
|
||||
return readw(addr);
|
||||
}
|
||||
|
||||
static inline u32 ioread32(const volatile void __iomem *addr)
|
||||
{
|
||||
return readl(addr);
|
||||
}
|
||||
#endif /* !CONFIG_HAVE_ARCH_IOMAP */
|
||||
|
||||
#ifdef CONFIG_64BIT
|
||||
static inline u64 ioread64(const volatile void __iomem *addr)
|
||||
{
|
||||
return readq(addr);
|
||||
}
|
||||
#endif /* CONFIG_64BIT */
|
||||
|
||||
#ifndef CONFIG_HAVE_ARCH_IOMAP
|
||||
static inline void iowrite8(u8 value, volatile void __iomem *addr)
|
||||
{
|
||||
writeb(value, addr);
|
||||
}
|
||||
|
||||
static inline void iowrite16(u16 value, volatile void __iomem *addr)
|
||||
{
|
||||
writew(value, addr);
|
||||
}
|
||||
|
||||
static inline void iowrite32(u32 value, volatile void __iomem *addr)
|
||||
{
|
||||
writel(value, addr);
|
||||
}
|
||||
#endif /* !CONFIG_HAVE_ARCH_IOMAP */
|
||||
|
||||
#ifdef CONFIG_64BIT
|
||||
static inline void iowrite64(u64 value, volatile void __iomem *addr)
|
||||
{
|
||||
writeq(value, addr);
|
||||
}
|
||||
#endif /* CONFIG_64BIT */
|
||||
|
||||
#ifndef CONFIG_HAVE_ARCH_IOREMAP
|
||||
static inline void __iomem *ioremap(resource_size_t offset,
|
||||
resource_size_t size)
|
||||
{
|
||||
return (void __iomem *)(unsigned long)offset;
|
||||
}
|
||||
|
||||
static inline void iounmap(void __iomem *addr)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
#define devm_ioremap(dev, offset, size) ioremap(offset, size)
|
||||
|
||||
#endif /* _LINUX_IO_H */
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef _LINUX_IOCTL_H
|
||||
#define _LINUX_IOCTL_H
|
||||
|
||||
#include <asm/ioctl.h>
|
||||
|
||||
#endif /* _LINUX_IOCTL_H */
|
||||
@@ -0,0 +1,67 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Copyright (c) 2012-2014 The Linux Foundation. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_IOPOLL_H
|
||||
#define _LINUX_IOPOLL_H
|
||||
|
||||
#include <linux/errno.h>
|
||||
#include <linux/io.h>
|
||||
#include <time.h>
|
||||
|
||||
/**
|
||||
* readx_poll_timeout - Periodically poll an address until a condition is met or a timeout occurs
|
||||
* @op: accessor function (takes @addr as its only argument)
|
||||
* @addr: Address to poll
|
||||
* @val: Variable to read the value into
|
||||
* @cond: Break condition (usually involving @val)
|
||||
* @timeout_us: Timeout in us, 0 means never timeout
|
||||
*
|
||||
* Returns 0 on success and -ETIMEDOUT upon a timeout. In either
|
||||
* case, the last read value at @addr is stored in @val.
|
||||
*
|
||||
* When available, you'll probably want to use one of the specialized
|
||||
* macros defined below rather than this macro directly.
|
||||
*/
|
||||
#define readx_poll_timeout(op, addr, val, cond, timeout_us) \
|
||||
({ \
|
||||
unsigned long timeout = timer_get_us() + timeout_us; \
|
||||
for (;;) { \
|
||||
(val) = op(addr); \
|
||||
if (cond) \
|
||||
break; \
|
||||
if (timeout_us && time_after(timer_get_us(), timeout)) { \
|
||||
(val) = op(addr); \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
(cond) ? 0 : -ETIMEDOUT; \
|
||||
})
|
||||
|
||||
|
||||
#define readb_poll_timeout(addr, val, cond, timeout_us) \
|
||||
readx_poll_timeout(readb, addr, val, cond, timeout_us)
|
||||
|
||||
#define readw_poll_timeout(addr, val, cond, timeout_us) \
|
||||
readx_poll_timeout(readw, addr, val, cond, timeout_us)
|
||||
|
||||
#define readl_poll_timeout(addr, val, cond, timeout_us) \
|
||||
readx_poll_timeout(readl, addr, val, cond, timeout_us)
|
||||
|
||||
#define readq_poll_timeout(addr, val, cond, timeout_us) \
|
||||
readx_poll_timeout(readq, addr, val, cond, timeout_us)
|
||||
|
||||
#define readb_relaxed_poll_timeout(addr, val, cond, timeout_us) \
|
||||
readx_poll_timeout(readb_relaxed, addr, val, cond, timeout_us)
|
||||
|
||||
#define readw_relaxed_poll_timeout(addr, val, cond, timeout_us) \
|
||||
readx_poll_timeout(readw_relaxed, addr, val, cond, timeout_us)
|
||||
|
||||
#define readl_relaxed_poll_timeout(addr, val, cond, timeout_us) \
|
||||
readx_poll_timeout(readl_relaxed, addr, val, cond, timeout_us)
|
||||
|
||||
#define readq_relaxed_poll_timeout(addr, val, cond, timeout_us) \
|
||||
readx_poll_timeout(readq_relaxed, addr, val, cond, timeout_us)
|
||||
|
||||
#endif /* _LINUX_IOPOLL_H */
|
||||
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
* ioport.h Definitions of routines for detecting, reserving and
|
||||
* allocating system resources.
|
||||
*
|
||||
* Authors: Linus Torvalds
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_IOPORT_H
|
||||
#define _LINUX_IOPORT_H
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
#include <linux/compiler.h>
|
||||
#include <linux/types.h>
|
||||
/*
|
||||
* Resources are tree-like, allowing
|
||||
* nesting etc..
|
||||
*/
|
||||
struct resource {
|
||||
resource_size_t start;
|
||||
resource_size_t end;
|
||||
const char *name;
|
||||
unsigned long flags;
|
||||
struct resource *parent, *sibling, *child;
|
||||
};
|
||||
|
||||
struct resource_list {
|
||||
struct resource_list *next;
|
||||
struct resource *res;
|
||||
struct pci_dev *dev;
|
||||
};
|
||||
|
||||
/*
|
||||
* IO resources have these defined flags.
|
||||
*/
|
||||
#define IORESOURCE_BITS 0x000000ff /* Bus-specific bits */
|
||||
|
||||
#define IORESOURCE_TYPE_BITS 0x00000f00 /* Resource type */
|
||||
#define IORESOURCE_IO 0x00000100
|
||||
#define IORESOURCE_MEM 0x00000200
|
||||
#define IORESOURCE_IRQ 0x00000400
|
||||
#define IORESOURCE_DMA 0x00000800
|
||||
|
||||
#define IORESOURCE_PREFETCH 0x00001000 /* No side effects */
|
||||
#define IORESOURCE_READONLY 0x00002000
|
||||
#define IORESOURCE_CACHEABLE 0x00004000
|
||||
#define IORESOURCE_RANGELENGTH 0x00008000
|
||||
#define IORESOURCE_SHADOWABLE 0x00010000
|
||||
|
||||
#define IORESOURCE_SIZEALIGN 0x00020000 /* size indicates alignment */
|
||||
#define IORESOURCE_STARTALIGN 0x00040000 /* start field is alignment */
|
||||
|
||||
#define IORESOURCE_MEM_64 0x00100000
|
||||
|
||||
#define IORESOURCE_EXCLUSIVE 0x08000000 /* Userland may not map this resource */
|
||||
#define IORESOURCE_DISABLED 0x10000000
|
||||
#define IORESOURCE_UNSET 0x20000000
|
||||
#define IORESOURCE_AUTO 0x40000000
|
||||
#define IORESOURCE_BUSY 0x80000000 /* Driver has marked this resource busy */
|
||||
|
||||
/* PnP IRQ specific bits (IORESOURCE_BITS) */
|
||||
#define IORESOURCE_IRQ_HIGHEDGE (1<<0)
|
||||
#define IORESOURCE_IRQ_LOWEDGE (1<<1)
|
||||
#define IORESOURCE_IRQ_HIGHLEVEL (1<<2)
|
||||
#define IORESOURCE_IRQ_LOWLEVEL (1<<3)
|
||||
#define IORESOURCE_IRQ_SHAREABLE (1<<4)
|
||||
#define IORESOURCE_IRQ_OPTIONAL (1<<5)
|
||||
|
||||
/* PnP DMA specific bits (IORESOURCE_BITS) */
|
||||
#define IORESOURCE_DMA_TYPE_MASK (3<<0)
|
||||
#define IORESOURCE_DMA_8BIT (0<<0)
|
||||
#define IORESOURCE_DMA_8AND16BIT (1<<0)
|
||||
#define IORESOURCE_DMA_16BIT (2<<0)
|
||||
|
||||
#define IORESOURCE_DMA_MASTER (1<<2)
|
||||
#define IORESOURCE_DMA_BYTE (1<<3)
|
||||
#define IORESOURCE_DMA_WORD (1<<4)
|
||||
|
||||
#define IORESOURCE_DMA_SPEED_MASK (3<<6)
|
||||
#define IORESOURCE_DMA_COMPATIBLE (0<<6)
|
||||
#define IORESOURCE_DMA_TYPEA (1<<6)
|
||||
#define IORESOURCE_DMA_TYPEB (2<<6)
|
||||
#define IORESOURCE_DMA_TYPEF (3<<6)
|
||||
|
||||
/* PnP memory I/O specific bits (IORESOURCE_BITS) */
|
||||
#define IORESOURCE_MEM_WRITEABLE (1<<0) /* dup: IORESOURCE_READONLY */
|
||||
#define IORESOURCE_MEM_CACHEABLE (1<<1) /* dup: IORESOURCE_CACHEABLE */
|
||||
#define IORESOURCE_MEM_RANGELENGTH (1<<2) /* dup: IORESOURCE_RANGELENGTH */
|
||||
#define IORESOURCE_MEM_TYPE_MASK (3<<3)
|
||||
#define IORESOURCE_MEM_8BIT (0<<3)
|
||||
#define IORESOURCE_MEM_16BIT (1<<3)
|
||||
#define IORESOURCE_MEM_8AND16BIT (2<<3)
|
||||
#define IORESOURCE_MEM_32BIT (3<<3)
|
||||
#define IORESOURCE_MEM_SHADOWABLE (1<<5) /* dup: IORESOURCE_SHADOWABLE */
|
||||
#define IORESOURCE_MEM_EXPANSIONROM (1<<6)
|
||||
|
||||
/* PnP I/O specific bits (IORESOURCE_BITS) */
|
||||
#define IORESOURCE_IO_16BIT_ADDR (1<<0)
|
||||
#define IORESOURCE_IO_FIXED (1<<1)
|
||||
|
||||
/* PCI ROM control bits (IORESOURCE_BITS) */
|
||||
#define IORESOURCE_ROM_ENABLE (1<<0) /* ROM is enabled, same as PCI_ROM_ADDRESS_ENABLE */
|
||||
#define IORESOURCE_ROM_SHADOW (1<<1) /* ROM is copy at C000:0 */
|
||||
#define IORESOURCE_ROM_COPY (1<<2) /* ROM is alloc'd copy, resource field overlaid */
|
||||
#define IORESOURCE_ROM_BIOS_COPY (1<<3) /* ROM is BIOS copy, resource field overlaid */
|
||||
|
||||
/* PCI control bits. Shares IORESOURCE_BITS with above PCI ROM. */
|
||||
#define IORESOURCE_PCI_FIXED (1<<4) /* Do not move resource */
|
||||
|
||||
/* PC/ISA/whatever - the normal PC address spaces: IO and memory */
|
||||
extern struct resource ioport_resource;
|
||||
extern struct resource iomem_resource;
|
||||
|
||||
extern int request_resource(struct resource *root, struct resource *new);
|
||||
extern int release_resource(struct resource *new);
|
||||
extern void reserve_region_with_split(struct resource *root,
|
||||
resource_size_t start, resource_size_t end,
|
||||
const char *name);
|
||||
extern int insert_resource(struct resource *parent, struct resource *new);
|
||||
extern void insert_resource_expand_to_fit(struct resource *root, struct resource *new);
|
||||
extern int allocate_resource(struct resource *root, struct resource *new,
|
||||
resource_size_t size, resource_size_t min,
|
||||
resource_size_t max, resource_size_t align,
|
||||
void (*alignf)(void *, struct resource *,
|
||||
resource_size_t, resource_size_t),
|
||||
void *alignf_data);
|
||||
int adjust_resource(struct resource *res, resource_size_t start,
|
||||
resource_size_t size);
|
||||
resource_size_t resource_alignment(struct resource *res);
|
||||
static inline resource_size_t resource_size(const struct resource *res)
|
||||
{
|
||||
return res->end - res->start + 1;
|
||||
}
|
||||
static inline unsigned long resource_type(const struct resource *res)
|
||||
{
|
||||
return res->flags & IORESOURCE_TYPE_BITS;
|
||||
}
|
||||
|
||||
/* Convenience shorthand with allocation */
|
||||
#define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name), 0)
|
||||
#define __request_mem_region(start,n,name, excl) __request_region(&iomem_resource, (start), (n), (name), excl)
|
||||
#define request_mem_region(start,n,name) __request_region(&iomem_resource, (start), (n), (name), 0)
|
||||
#define request_mem_region_exclusive(start,n,name) \
|
||||
__request_region(&iomem_resource, (start), (n), (name), IORESOURCE_EXCLUSIVE)
|
||||
#define rename_region(region, newname) do { (region)->name = (newname); } while (0)
|
||||
|
||||
extern struct resource * __request_region(struct resource *,
|
||||
resource_size_t start,
|
||||
resource_size_t n,
|
||||
const char *name, int flags);
|
||||
|
||||
/* Compatibility cruft */
|
||||
#define release_region(start,n) __release_region(&ioport_resource, (start), (n))
|
||||
#define check_mem_region(start,n) __check_region(&iomem_resource, (start), (n))
|
||||
#define release_mem_region(start,n) __release_region(&iomem_resource, (start), (n))
|
||||
|
||||
extern int __check_region(struct resource *, resource_size_t, resource_size_t);
|
||||
extern void __release_region(struct resource *, resource_size_t,
|
||||
resource_size_t);
|
||||
|
||||
static inline int __deprecated check_region(resource_size_t s,
|
||||
resource_size_t n)
|
||||
{
|
||||
return __check_region(&ioport_resource, s, n);
|
||||
}
|
||||
|
||||
/* Wrappers for managed devices */
|
||||
struct device;
|
||||
#define devm_request_region(dev,start,n,name) \
|
||||
__devm_request_region(dev, &ioport_resource, (start), (n), (name))
|
||||
#define devm_request_mem_region(dev,start,n,name) \
|
||||
__devm_request_region(dev, &iomem_resource, (start), (n), (name))
|
||||
|
||||
extern struct resource * __devm_request_region(struct device *dev,
|
||||
struct resource *parent, resource_size_t start,
|
||||
resource_size_t n, const char *name);
|
||||
|
||||
#define devm_release_region(dev, start, n) \
|
||||
__devm_release_region(dev, &ioport_resource, (start), (n))
|
||||
#define devm_release_mem_region(dev, start, n) \
|
||||
__devm_release_region(dev, &iomem_resource, (start), (n))
|
||||
|
||||
extern void __devm_release_region(struct device *dev, struct resource *parent,
|
||||
resource_size_t start, resource_size_t n);
|
||||
extern int iomem_map_sanity_check(resource_size_t addr, unsigned long size);
|
||||
extern int iomem_is_exclusive(u64 addr);
|
||||
|
||||
extern int
|
||||
walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,
|
||||
void *arg, int (*func)(unsigned long, unsigned long, void *));
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* _LINUX_IOPORT_H */
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copied from Linux:
|
||||
* commit 37487a56523d402e25650da16c337acf4cecd13d
|
||||
* Author: Christoph Lameter <clameter@sgi.com>
|
||||
*/
|
||||
#ifndef __LINUX_KBUILD_H
|
||||
#define __LINUX_KBUILD_H
|
||||
|
||||
#define DEFINE(sym, val) \
|
||||
asm volatile("\n.ascii \"->" #sym " %0 " #val "\"" : : "i" (val))
|
||||
|
||||
#define BLANK() asm volatile("\n.ascii \"->\"" : : )
|
||||
|
||||
#define OFFSET(sym, str, mem) \
|
||||
DEFINE(sym, offsetof(struct str, mem))
|
||||
|
||||
#define COMMENT(x) \
|
||||
asm volatile("\n.ascii \"->#" x "\"")
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,109 @@
|
||||
#ifndef __LINUX_KCONFIG_H
|
||||
#define __LINUX_KCONFIG_H
|
||||
|
||||
#include <generated/autoconf.h>
|
||||
|
||||
/*
|
||||
* Helper macros to use CONFIG_ options in C/CPP expressions. Note that
|
||||
* these only work with boolean and tristate options.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Getting something that works in C and CPP for an arg that may or may
|
||||
* not be defined is tricky. Here, if we have "#define CONFIG_BOOGER 1"
|
||||
* we match on the placeholder define, insert the "0," for arg1 and generate
|
||||
* the triplet (0, 1, 0). Then the last step cherry picks the 2nd arg (a one).
|
||||
* When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
|
||||
* the last step cherry picks the 2nd arg, we get a zero.
|
||||
*/
|
||||
#define __ARG_PLACEHOLDER_1 0,
|
||||
#define config_enabled(cfg) _config_enabled(cfg)
|
||||
#define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value)
|
||||
#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0)
|
||||
#define ___config_enabled(__ignored, val, ...) val
|
||||
|
||||
/*
|
||||
* IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
|
||||
* 0 otherwise.
|
||||
*
|
||||
*/
|
||||
#define IS_ENABLED(option) \
|
||||
(config_enabled(option) || config_enabled(option##_MODULE))
|
||||
|
||||
/*
|
||||
* IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0
|
||||
* otherwise. For boolean options, this is equivalent to
|
||||
* IS_ENABLED(CONFIG_FOO).
|
||||
*/
|
||||
#define IS_BUILTIN(option) config_enabled(option)
|
||||
|
||||
/*
|
||||
* IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
|
||||
* otherwise.
|
||||
*/
|
||||
#define IS_MODULE(option) config_enabled(option##_MODULE)
|
||||
|
||||
/*
|
||||
* U-Boot add-on: Helper macros to reference to different macros
|
||||
* (CONFIG_ or CONFIG_SPL_ prefixed), depending on the build context.
|
||||
*/
|
||||
#ifdef CONFIG_SPL_BUILD
|
||||
#define _IS_SPL 1
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_TPL_BUILD
|
||||
#define _IS_TPL 1
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_TPL_BUILD)
|
||||
#define config_val(cfg) _config_val(_IS_TPL, cfg)
|
||||
#define _config_val(x, cfg) __config_val(x, cfg)
|
||||
#define __config_val(x, cfg) ___config_val(__ARG_PLACEHOLDER_##x, cfg)
|
||||
#define ___config_val(arg1_or_junk, cfg) \
|
||||
____config_val(arg1_or_junk CONFIG_TPL_##cfg, CONFIG_##cfg)
|
||||
#define ____config_val(__ignored, val, ...) val
|
||||
#else
|
||||
#define config_val(cfg) _config_val(_IS_SPL, cfg)
|
||||
#define _config_val(x, cfg) __config_val(x, cfg)
|
||||
#define __config_val(x, cfg) ___config_val(__ARG_PLACEHOLDER_##x, cfg)
|
||||
#define ___config_val(arg1_or_junk, cfg) \
|
||||
____config_val(arg1_or_junk CONFIG_SPL_##cfg, CONFIG_##cfg)
|
||||
#define ____config_val(__ignored, val, ...) val
|
||||
#endif
|
||||
|
||||
/*
|
||||
* CONFIG_VAL(FOO) evaluates to the value of
|
||||
* CONFIG_FOO if CONFIG_SPL_BUILD is undefined,
|
||||
* CONFIG_SPL_FOO if CONFIG_SPL_BUILD is defined.
|
||||
* CONFIG_TPL_FOO if CONFIG_TPL_BUILD is defined.
|
||||
*/
|
||||
#define CONFIG_VAL(option) config_val(option)
|
||||
|
||||
/*
|
||||
* CONFIG_IS_ENABLED(FOO) evaluates to
|
||||
* 1 if CONFIG_SPL_BUILD is undefined and CONFIG_FOO is set to 'y' or 'm',
|
||||
* 1 if CONFIG_SPL_BUILD is defined and CONFIG_SPL_FOO is set to 'y' or 'm',
|
||||
* 1 if CONFIG_TPL_BUILD is defined and CONFIG_TPL_FOO is set to 'y' or 'm',
|
||||
* 0 otherwise.
|
||||
*/
|
||||
#define CONFIG_IS_ENABLED(option) \
|
||||
(config_enabled(CONFIG_VAL(option)) || \
|
||||
config_enabled(CONFIG_VAL(option##_MODULE)))
|
||||
|
||||
/*
|
||||
* CONFIG_IS_BUILTIN(FOO) evaluates to
|
||||
* 1 if CONFIG_SPL_BUILD is undefined and CONFIG_FOO is set to 'y',
|
||||
* 1 if CONFIG_SPL_BUILD is defined and CONFIG_SPL_FOO is set to 'y',
|
||||
* 0 otherwise.
|
||||
*/
|
||||
#define CONFIG_IS_BUILTIN(option) config_enabled(CONFIG_VAL(option))
|
||||
|
||||
/*
|
||||
* CONFIG_IS_MODULE(FOO) evaluates to
|
||||
* 1 if CONFIG_SPL_BUILD is undefined and CONFIG_FOO is set to 'm',
|
||||
* 1 if CONFIG_SPL_BUILD is defined and CONFIG_SPL_FOO is set to 'm',
|
||||
* 0 otherwise.
|
||||
*/
|
||||
#define CONFIG_IS_MODULE(option) config_enabled(CONFIG_VAL(option##_MODULE))
|
||||
|
||||
#endif /* __LINUX_KCONFIG_H */
|
||||
@@ -0,0 +1,271 @@
|
||||
#ifndef _LINUX_KERNEL_H
|
||||
#define _LINUX_KERNEL_H
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/printk.h> /* for printf/pr_* utilities */
|
||||
|
||||
#define USHRT_MAX ((u16)(~0U))
|
||||
#define SHRT_MAX ((s16)(USHRT_MAX>>1))
|
||||
#define SHRT_MIN ((s16)(-SHRT_MAX - 1))
|
||||
#define INT_MAX ((int)(~0U>>1))
|
||||
#define INT_MIN (-INT_MAX - 1)
|
||||
#define UINT_MAX (~0U)
|
||||
#define LONG_MAX ((long)(~0UL>>1))
|
||||
#define LONG_MIN (-LONG_MAX - 1)
|
||||
#define ULONG_MAX (~0UL)
|
||||
#define LLONG_MAX ((long long)(~0ULL>>1))
|
||||
#define LLONG_MIN (-LLONG_MAX - 1)
|
||||
#define ULLONG_MAX (~0ULL)
|
||||
#ifndef SIZE_MAX
|
||||
#define SIZE_MAX (~(size_t)0)
|
||||
#endif
|
||||
|
||||
#define U8_MAX ((u8)~0U)
|
||||
#define S8_MAX ((s8)(U8_MAX>>1))
|
||||
#define S8_MIN ((s8)(-S8_MAX - 1))
|
||||
#define U16_MAX ((u16)~0U)
|
||||
#define S16_MAX ((s16)(U16_MAX>>1))
|
||||
#define S16_MIN ((s16)(-S16_MAX - 1))
|
||||
#define U32_MAX ((u32)~0U)
|
||||
#define S32_MAX ((s32)(U32_MAX>>1))
|
||||
#define S32_MIN ((s32)(-S32_MAX - 1))
|
||||
#define U64_MAX ((u64)~0ULL)
|
||||
#define S64_MAX ((s64)(U64_MAX>>1))
|
||||
#define S64_MIN ((s64)(-S64_MAX - 1))
|
||||
|
||||
/* Aliases defined by stdint.h */
|
||||
#define UINT32_MAX U32_MAX
|
||||
#define UINT64_MAX U64_MAX
|
||||
|
||||
#define INT32_MAX S32_MAX
|
||||
|
||||
#define STACK_MAGIC 0xdeadbeef
|
||||
|
||||
#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x))
|
||||
|
||||
#define ALIGN(x,a) __ALIGN_MASK((x),(typeof(x))(a)-1)
|
||||
#define ALIGN_DOWN(x, a) ALIGN((x) - ((a) - 1), (a))
|
||||
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
|
||||
#define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a)))
|
||||
#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
/*
|
||||
* This looks more complex than it should be. But we need to
|
||||
* get the type for the ~ right in round_down (it needs to be
|
||||
* as wide as the result!), and we want to evaluate the macro
|
||||
* arguments just once each.
|
||||
*/
|
||||
#define __round_mask(x, y) ((__typeof__(x))((y)-1))
|
||||
#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
|
||||
#define round_down(x, y) ((x) & ~__round_mask(x, y))
|
||||
|
||||
#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
|
||||
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
|
||||
|
||||
#define DIV_ROUND_DOWN_ULL(ll, d) \
|
||||
({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; })
|
||||
|
||||
#define DIV_ROUND_UP_ULL(ll, d) DIV_ROUND_DOWN_ULL((ll) + (d) - 1, (d))
|
||||
|
||||
#if BITS_PER_LONG == 32
|
||||
# define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d)
|
||||
#else
|
||||
# define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP(ll,d)
|
||||
#endif
|
||||
|
||||
/* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */
|
||||
#define roundup(x, y) ( \
|
||||
{ \
|
||||
const typeof(y) __y = y; \
|
||||
(((x) + (__y - 1)) / __y) * __y; \
|
||||
} \
|
||||
)
|
||||
#define rounddown(x, y) ( \
|
||||
{ \
|
||||
typeof(x) __x = (x); \
|
||||
__x - (__x % (y)); \
|
||||
} \
|
||||
)
|
||||
|
||||
/*
|
||||
* Divide positive or negative dividend by positive divisor and round
|
||||
* to closest integer. Result is undefined for negative divisors and
|
||||
* for negative dividends if the divisor variable type is unsigned.
|
||||
*/
|
||||
#define DIV_ROUND_CLOSEST(x, divisor)( \
|
||||
{ \
|
||||
typeof(x) __x = x; \
|
||||
typeof(divisor) __d = divisor; \
|
||||
(((typeof(x))-1) > 0 || \
|
||||
((typeof(divisor))-1) > 0 || (__x) > 0) ? \
|
||||
(((__x) + ((__d) / 2)) / (__d)) : \
|
||||
(((__x) - ((__d) / 2)) / (__d)); \
|
||||
} \
|
||||
)
|
||||
/*
|
||||
* Same as above but for u64 dividends. divisor must be a 32-bit
|
||||
* number.
|
||||
*/
|
||||
#define DIV_ROUND_CLOSEST_ULL(x, divisor)( \
|
||||
{ \
|
||||
typeof(divisor) __d = divisor; \
|
||||
unsigned long long _tmp = (x) + (__d) / 2; \
|
||||
do_div(_tmp, __d); \
|
||||
_tmp; \
|
||||
} \
|
||||
)
|
||||
|
||||
/*
|
||||
* Multiplies an integer by a fraction, while avoiding unnecessary
|
||||
* overflow or loss of precision.
|
||||
*/
|
||||
#define mult_frac(x, numer, denom)( \
|
||||
{ \
|
||||
typeof(x) quot = (x) / (denom); \
|
||||
typeof(x) rem = (x) % (denom); \
|
||||
(quot * (numer)) + ((rem * (numer)) / (denom)); \
|
||||
} \
|
||||
)
|
||||
|
||||
/**
|
||||
* upper_32_bits - return bits 32-63 of a number
|
||||
* @n: the number we're accessing
|
||||
*
|
||||
* A basic shift-right of a 64- or 32-bit quantity. Use this to suppress
|
||||
* the "right shift count >= width of type" warning when that quantity is
|
||||
* 32-bits.
|
||||
*/
|
||||
#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
|
||||
|
||||
/**
|
||||
* lower_32_bits - return bits 0-31 of a number
|
||||
* @n: the number we're accessing
|
||||
*/
|
||||
#define lower_32_bits(n) ((u32)(n))
|
||||
|
||||
/*
|
||||
* abs() handles unsigned and signed longs, ints, shorts and chars. For all
|
||||
* input types abs() returns a signed long.
|
||||
* abs() should not be used for 64-bit types (s64, u64, long long) - use abs64()
|
||||
* for those.
|
||||
*/
|
||||
#define abs(x) ({ \
|
||||
long ret; \
|
||||
if (sizeof(x) == sizeof(long)) { \
|
||||
long __x = (x); \
|
||||
ret = (__x < 0) ? -__x : __x; \
|
||||
} else { \
|
||||
int __x = (x); \
|
||||
ret = (__x < 0) ? -__x : __x; \
|
||||
} \
|
||||
ret; \
|
||||
})
|
||||
|
||||
#define abs64(x) ({ \
|
||||
s64 __x = (x); \
|
||||
(__x < 0) ? -__x : __x; \
|
||||
})
|
||||
|
||||
/*
|
||||
* min()/max()/clamp() macros that also do
|
||||
* strict type-checking.. See the
|
||||
* "unnecessary" pointer comparison.
|
||||
*/
|
||||
#define min(x, y) ({ \
|
||||
typeof(x) _min1 = (x); \
|
||||
typeof(y) _min2 = (y); \
|
||||
(void) (&_min1 == &_min2); \
|
||||
_min1 < _min2 ? _min1 : _min2; })
|
||||
|
||||
#define max(x, y) ({ \
|
||||
typeof(x) _max1 = (x); \
|
||||
typeof(y) _max2 = (y); \
|
||||
(void) (&_max1 == &_max2); \
|
||||
_max1 > _max2 ? _max1 : _max2; })
|
||||
|
||||
#define min3(x, y, z) min((typeof(x))min(x, y), z)
|
||||
#define max3(x, y, z) max((typeof(x))max(x, y), z)
|
||||
|
||||
/**
|
||||
* min_not_zero - return the minimum that is _not_ zero, unless both are zero
|
||||
* @x: value1
|
||||
* @y: value2
|
||||
*/
|
||||
#define min_not_zero(x, y) ({ \
|
||||
typeof(x) __x = (x); \
|
||||
typeof(y) __y = (y); \
|
||||
__x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
|
||||
|
||||
/**
|
||||
* clamp - return a value clamped to a given range with strict typechecking
|
||||
* @val: current value
|
||||
* @lo: lowest allowable value
|
||||
* @hi: highest allowable value
|
||||
*
|
||||
* This macro does strict typechecking of lo/hi to make sure they are of the
|
||||
* same type as val. See the unnecessary pointer comparisons.
|
||||
*/
|
||||
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
|
||||
|
||||
/*
|
||||
* ..and if you can't take the strict
|
||||
* types, you can specify one yourself.
|
||||
*
|
||||
* Or not use min/max/clamp at all, of course.
|
||||
*/
|
||||
#define min_t(type, x, y) ({ \
|
||||
type __min1 = (x); \
|
||||
type __min2 = (y); \
|
||||
__min1 < __min2 ? __min1: __min2; })
|
||||
|
||||
#define max_t(type, x, y) ({ \
|
||||
type __max1 = (x); \
|
||||
type __max2 = (y); \
|
||||
__max1 > __max2 ? __max1: __max2; })
|
||||
|
||||
/**
|
||||
* clamp_t - return a value clamped to a given range using a given type
|
||||
* @type: the type of variable to use
|
||||
* @val: current value
|
||||
* @lo: minimum allowable value
|
||||
* @hi: maximum allowable value
|
||||
*
|
||||
* This macro does no typechecking and uses temporary variables of type
|
||||
* 'type' to make all the comparisons.
|
||||
*/
|
||||
#define clamp_t(type, val, lo, hi) min_t(type, max_t(type, val, lo), hi)
|
||||
|
||||
/**
|
||||
* clamp_val - return a value clamped to a given range using val's type
|
||||
* @val: current value
|
||||
* @lo: minimum allowable value
|
||||
* @hi: maximum allowable value
|
||||
*
|
||||
* This macro does no typechecking and uses temporary variables of whatever
|
||||
* type the input argument 'val' is. This is useful when val is an unsigned
|
||||
* type and min and max are literals that will otherwise be assigned a signed
|
||||
* integer type.
|
||||
*/
|
||||
#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi)
|
||||
|
||||
|
||||
/*
|
||||
* swap - swap value of @a and @b
|
||||
*/
|
||||
#define swap(a, b) \
|
||||
do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
|
||||
|
||||
/**
|
||||
* container_of - cast a member of a structure out to the containing structure
|
||||
* @ptr: the pointer to the member.
|
||||
* @type: the type of the container struct this is embedded in.
|
||||
* @member: the name of the member within the struct.
|
||||
*
|
||||
*/
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,312 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef _INCLUDE_LIBFDT_H_
|
||||
#define _INCLUDE_LIBFDT_H_
|
||||
|
||||
#ifndef USE_HOSTCC
|
||||
#include <linux/libfdt_env.h>
|
||||
#endif
|
||||
#include "../../scripts/dtc/libfdt/libfdt.h"
|
||||
|
||||
/* U-Boot local hacks */
|
||||
|
||||
#ifndef SWIG /* Not available in Python */
|
||||
struct fdt_region {
|
||||
int offset;
|
||||
int size;
|
||||
};
|
||||
|
||||
/*
|
||||
* Flags for fdt_find_regions()
|
||||
*
|
||||
* Add a region for the string table (always the last region)
|
||||
*/
|
||||
#define FDT_REG_ADD_STRING_TAB (1 << 0)
|
||||
|
||||
/*
|
||||
* Add all supernodes of a matching node/property, useful for creating a
|
||||
* valid subset tree
|
||||
*/
|
||||
#define FDT_REG_SUPERNODES (1 << 1)
|
||||
|
||||
/* Add the FDT_BEGIN_NODE tags of subnodes, including their names */
|
||||
#define FDT_REG_DIRECT_SUBNODES (1 << 2)
|
||||
|
||||
/* Add all subnodes of a matching node */
|
||||
#define FDT_REG_ALL_SUBNODES (1 << 3)
|
||||
|
||||
/* Add a region for the mem_rsvmap table (always the first region) */
|
||||
#define FDT_REG_ADD_MEM_RSVMAP (1 << 4)
|
||||
|
||||
/* Indicates what an fdt part is (node, property, value) */
|
||||
#define FDT_IS_NODE (1 << 0)
|
||||
#define FDT_IS_PROP (1 << 1)
|
||||
#define FDT_IS_VALUE (1 << 2) /* not supported */
|
||||
#define FDT_IS_COMPAT (1 << 3) /* used internally */
|
||||
#define FDT_NODE_HAS_PROP (1 << 4) /* node contains prop */
|
||||
|
||||
#define FDT_ANY_GLOBAL (FDT_IS_NODE | FDT_IS_PROP | FDT_IS_VALUE | \
|
||||
FDT_IS_COMPAT)
|
||||
#define FDT_IS_ANY 0x1f /* all the above */
|
||||
|
||||
/* We set a reasonable limit on the number of nested nodes */
|
||||
#define FDT_MAX_DEPTH 32
|
||||
|
||||
/* Decribes what we want to include from the current tag */
|
||||
enum want_t {
|
||||
WANT_NOTHING,
|
||||
WANT_NODES_ONLY, /* No properties */
|
||||
WANT_NODES_AND_PROPS, /* Everything for one level */
|
||||
WANT_ALL_NODES_AND_PROPS /* Everything for all levels */
|
||||
};
|
||||
|
||||
/* Keeps track of the state at parent nodes */
|
||||
struct fdt_subnode_stack {
|
||||
int offset; /* Offset of node */
|
||||
enum want_t want; /* The 'want' value here */
|
||||
int included; /* 1 if we included this node, 0 if not */
|
||||
};
|
||||
|
||||
struct fdt_region_ptrs {
|
||||
int depth; /* Current tree depth */
|
||||
int done; /* What we have completed scanning */
|
||||
enum want_t want; /* What we are currently including */
|
||||
char *end; /* Pointer to end of full node path */
|
||||
int nextoffset; /* Next node offset to check */
|
||||
};
|
||||
|
||||
/* The state of our finding algortihm */
|
||||
struct fdt_region_state {
|
||||
struct fdt_subnode_stack stack[FDT_MAX_DEPTH]; /* node stack */
|
||||
struct fdt_region *region; /* Contains list of regions found */
|
||||
int count; /* Numnber of regions found */
|
||||
const void *fdt; /* FDT blob */
|
||||
int max_regions; /* Maximum regions to find */
|
||||
int can_merge; /* 1 if we can merge with previous region */
|
||||
int start; /* Start position of current region */
|
||||
struct fdt_region_ptrs ptrs; /* Pointers for what we are up to */
|
||||
};
|
||||
|
||||
/**
|
||||
* fdt_find_regions() - find regions in device tree
|
||||
*
|
||||
* Given a list of nodes to include and properties to exclude, find
|
||||
* the regions of the device tree which describe those included parts.
|
||||
*
|
||||
* The intent is to get a list of regions which will be invariant provided
|
||||
* those parts are invariant. For example, if you request a list of regions
|
||||
* for all nodes but exclude the property "data", then you will get the
|
||||
* same region contents regardless of any change to "data" properties.
|
||||
*
|
||||
* This function can be used to produce a byte-stream to send to a hashing
|
||||
* function to verify that critical parts of the FDT have not changed.
|
||||
*
|
||||
* Nodes which are given in 'inc' are included in the region list, as
|
||||
* are the names of the immediate subnodes nodes (but not the properties
|
||||
* or subnodes of those subnodes).
|
||||
*
|
||||
* For eaxample "/" means to include the root node, all root properties
|
||||
* and the FDT_BEGIN_NODE and FDT_END_NODE of all subnodes of /. The latter
|
||||
* ensures that we capture the names of the subnodes. In a hashing situation
|
||||
* it prevents the root node from changing at all Any change to non-excluded
|
||||
* properties, names of subnodes or number of subnodes would be detected.
|
||||
*
|
||||
* When used with FITs this provides the ability to hash and sign parts of
|
||||
* the FIT based on different configurations in the FIT. Then it is
|
||||
* impossible to change anything about that configuration (include images
|
||||
* attached to the configuration), but it may be possible to add new
|
||||
* configurations, new images or new signatures within the existing
|
||||
* framework.
|
||||
*
|
||||
* Adding new properties to a device tree may result in the string table
|
||||
* being extended (if the new property names are different from those
|
||||
* already added). This function can optionally include a region for
|
||||
* the string table so that this can be part of the hash too.
|
||||
*
|
||||
* The device tree header is not included in the list.
|
||||
*
|
||||
* @fdt: Device tree to check
|
||||
* @inc: List of node paths to included
|
||||
* @inc_count: Number of node paths in list
|
||||
* @exc_prop: List of properties names to exclude
|
||||
* @exc_prop_count: Number of properties in exclude list
|
||||
* @region: Returns list of regions
|
||||
* @max_region: Maximum length of region list
|
||||
* @path: Pointer to a temporary string for the function to use for
|
||||
* building path names
|
||||
* @path_len: Length of path, must be large enough to hold the longest
|
||||
* path in the tree
|
||||
* @add_string_tab: 1 to add a region for the string table
|
||||
* @return number of regions in list. If this is >max_regions then the
|
||||
* region array was exhausted. You should increase max_regions and try
|
||||
* the call again.
|
||||
*/
|
||||
int fdt_find_regions(const void *fdt, char * const inc[], int inc_count,
|
||||
char * const exc_prop[], int exc_prop_count,
|
||||
struct fdt_region region[], int max_regions,
|
||||
char *path, int path_len, int add_string_tab);
|
||||
|
||||
/**
|
||||
* fdt_first_region() - find regions in device tree
|
||||
*
|
||||
* Given a nodes and properties to include and properties to exclude, find
|
||||
* the regions of the device tree which describe those included parts.
|
||||
*
|
||||
* The use for this function is twofold. Firstly it provides a convenient
|
||||
* way of performing a structure-aware grep of the tree. For example it is
|
||||
* possible to grep for a node and get all the properties associated with
|
||||
* that node. Trees can be subsetted easily, by specifying the nodes that
|
||||
* are required, and then writing out the regions returned by this function.
|
||||
* This is useful for small resource-constrained systems, such as boot
|
||||
* loaders, which want to use an FDT but do not need to know about all of
|
||||
* it.
|
||||
*
|
||||
* Secondly it makes it easy to hash parts of the tree and detect changes.
|
||||
* The intent is to get a list of regions which will be invariant provided
|
||||
* those parts are invariant. For example, if you request a list of regions
|
||||
* for all nodes but exclude the property "data", then you will get the
|
||||
* same region contents regardless of any change to "data" properties.
|
||||
*
|
||||
* This function can be used to produce a byte-stream to send to a hashing
|
||||
* function to verify that critical parts of the FDT have not changed.
|
||||
* Note that semantically null changes in order could still cause false
|
||||
* hash misses. Such reordering might happen if the tree is regenerated
|
||||
* from source, and nodes are reordered (the bytes-stream will be emitted
|
||||
* in a different order and many hash functions will detect this). However
|
||||
* if an existing tree is modified using libfdt functions, such as
|
||||
* fdt_add_subnode() and fdt_setprop(), then this problem is avoided.
|
||||
*
|
||||
* The nodes/properties to include/exclude are defined by a function
|
||||
* provided by the caller. This function is called for each node and
|
||||
* property, and must return:
|
||||
*
|
||||
* 0 - to exclude this part
|
||||
* 1 - to include this part
|
||||
* -1 - for FDT_IS_PROP only: no information is available, so include
|
||||
* if its containing node is included
|
||||
*
|
||||
* The last case is only used to deal with properties. Often a property is
|
||||
* included if its containing node is included - this is the case where
|
||||
* -1 is returned.. However if the property is specifically required to be
|
||||
* included/excluded, then 0 or 1 can be returned. Note that including a
|
||||
* property when the FDT_REG_SUPERNODES flag is given will force its
|
||||
* containing node to be included since it is not valid to have a property
|
||||
* that is not in a node.
|
||||
*
|
||||
* Using the information provided, the inclusion of a node can be controlled
|
||||
* either by a node name or its compatible string, or any other property
|
||||
* that the function can determine.
|
||||
*
|
||||
* As an example, including node "/" means to include the root node and all
|
||||
* root properties. A flag provides a way of also including supernodes (of
|
||||
* which there is none for the root node), and another flag includes
|
||||
* immediate subnodes, so in this case we would get the FDT_BEGIN_NODE and
|
||||
* FDT_END_NODE of all subnodes of /.
|
||||
*
|
||||
* The subnode feature helps in a hashing situation since it prevents the
|
||||
* root node from changing at all. Any change to non-excluded properties,
|
||||
* names of subnodes or number of subnodes would be detected.
|
||||
*
|
||||
* When used with FITs this provides the ability to hash and sign parts of
|
||||
* the FIT based on different configurations in the FIT. Then it is
|
||||
* impossible to change anything about that configuration (include images
|
||||
* attached to the configuration), but it may be possible to add new
|
||||
* configurations, new images or new signatures within the existing
|
||||
* framework.
|
||||
*
|
||||
* Adding new properties to a device tree may result in the string table
|
||||
* being extended (if the new property names are different from those
|
||||
* already added). This function can optionally include a region for
|
||||
* the string table so that this can be part of the hash too. This is always
|
||||
* the last region.
|
||||
*
|
||||
* The FDT also has a mem_rsvmap table which can also be included, and is
|
||||
* always the first region if so.
|
||||
*
|
||||
* The device tree header is not included in the region list. Since the
|
||||
* contents of the FDT are changing (shrinking, often), the caller will need
|
||||
* to regenerate the header anyway.
|
||||
*
|
||||
* @fdt: Device tree to check
|
||||
* @h_include: Function to call to determine whether to include a part or
|
||||
* not:
|
||||
*
|
||||
* @priv: Private pointer as passed to fdt_find_regions()
|
||||
* @fdt: Pointer to FDT blob
|
||||
* @offset: Offset of this node / property
|
||||
* @type: Type of this part, FDT_IS_...
|
||||
* @data: Pointer to data (node name, property name, compatible
|
||||
* string, value (not yet supported)
|
||||
* @size: Size of data, or 0 if none
|
||||
* @return 0 to exclude, 1 to include, -1 if no information is
|
||||
* available
|
||||
* @priv: Private pointer passed to h_include
|
||||
* @region: Returns list of regions, sorted by offset
|
||||
* @max_regions: Maximum length of region list
|
||||
* @path: Pointer to a temporary string for the function to use for
|
||||
* building path names
|
||||
* @path_len: Length of path, must be large enough to hold the longest
|
||||
* path in the tree
|
||||
* @flags: Various flags that control the region algortihm, see
|
||||
* FDT_REG_...
|
||||
* @return number of regions in list. If this is >max_regions then the
|
||||
* region array was exhausted. You should increase max_regions and try
|
||||
* the call again. Only the first max_regions elements are available in the
|
||||
* array.
|
||||
*
|
||||
* On error a -ve value is return, which can be:
|
||||
*
|
||||
* -FDT_ERR_BADSTRUCTURE (too deep or more END tags than BEGIN tags
|
||||
* -FDT_ERR_BADLAYOUT
|
||||
* -FDT_ERR_NOSPACE (path area is too small)
|
||||
*/
|
||||
int fdt_first_region(const void *fdt,
|
||||
int (*h_include)(void *priv, const void *fdt, int offset,
|
||||
int type, const char *data, int size),
|
||||
void *priv, struct fdt_region *region,
|
||||
char *path, int path_len, int flags,
|
||||
struct fdt_region_state *info);
|
||||
|
||||
/** fdt_next_region() - find next region
|
||||
*
|
||||
* See fdt_first_region() for full description. This function finds the
|
||||
* next region according to the provided parameters, which must be the same
|
||||
* as passed to fdt_first_region().
|
||||
*
|
||||
* This function can additionally return -FDT_ERR_NOTFOUND when there are no
|
||||
* more regions
|
||||
*/
|
||||
int fdt_next_region(const void *fdt,
|
||||
int (*h_include)(void *priv, const void *fdt, int offset,
|
||||
int type, const char *data, int size),
|
||||
void *priv, struct fdt_region *region,
|
||||
char *path, int path_len, int flags,
|
||||
struct fdt_region_state *info);
|
||||
|
||||
/**
|
||||
* fdt_add_alias_regions() - find aliases that point to existing regions
|
||||
*
|
||||
* Once a device tree grep is complete some of the nodes will be present
|
||||
* and some will have been dropped. This function checks all the alias nodes
|
||||
* to figure out which points point to nodes which are still present. These
|
||||
* aliases need to be kept, along with the nodes they reference.
|
||||
*
|
||||
* Given a list of regions function finds the aliases that still apply and
|
||||
* adds more regions to the list for these. This function is called after
|
||||
* fdt_next_region() has finished returning regions and requires the same
|
||||
* state.
|
||||
*
|
||||
* @fdt: Device tree file to reference
|
||||
* @region: List of regions that will be kept
|
||||
* @count: Number of regions
|
||||
* @max_regions: Number of entries that can fit in @region
|
||||
* @info: Region state as returned from fdt_next_region()
|
||||
* @return new number of regions in @region (i.e. count + the number added)
|
||||
* or -FDT_ERR_NOSPACE if there was not enough space.
|
||||
*/
|
||||
int fdt_add_alias_regions(const void *fdt, struct fdt_region *region, int count,
|
||||
int max_regions, struct fdt_region_state *info);
|
||||
#endif /* SWIG */
|
||||
|
||||
extern struct fdt_header *working_fdt; /* Pointer to the working fdt */
|
||||
|
||||
#endif /* _INCLUDE_LIBFDT_H_ */
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifdef USE_HOSTCC
|
||||
#include "../scripts/dtc/libfdt/libfdt_env.h"
|
||||
#else
|
||||
/*
|
||||
* This position of the include guard is intentional.
|
||||
* Using the same guard name as that of scripts/dtc/libfdt/libfdt_env.h
|
||||
* prevents it from being included.
|
||||
*/
|
||||
#ifndef LIBFDT_ENV_H
|
||||
#define LIBFDT_ENV_H
|
||||
|
||||
#include <linux/string.h>
|
||||
#include <linux/kernel.h>
|
||||
|
||||
#include <asm/byteorder.h>
|
||||
|
||||
typedef __be16 fdt16_t;
|
||||
typedef __be32 fdt32_t;
|
||||
typedef __be64 fdt64_t;
|
||||
typedef __be64 unaligned_fdt64_t __aligned(4);
|
||||
|
||||
#define fdt32_to_cpu(x) be32_to_cpu(x)
|
||||
#define cpu_to_fdt32(x) cpu_to_be32(x)
|
||||
#define fdt64_to_cpu(x) be64_to_cpu(x)
|
||||
#define cpu_to_fdt64(x) cpu_to_be64(x)
|
||||
|
||||
/* U-Boot: for strtoul in fdt_overlay.c */
|
||||
#include <vsprintf.h>
|
||||
|
||||
#define strtoul(cp, endp, base) simple_strtoul(cp, endp, base)
|
||||
|
||||
#endif /* LIBFDT_ENV_H */
|
||||
#endif
|
||||
@@ -0,0 +1,74 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* U-Boot - linkage.h
|
||||
*
|
||||
* Copyright (c) 2005-2007 Analog Devices Inc.
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_LINKAGE_H
|
||||
#define _LINUX_LINKAGE_H
|
||||
|
||||
#include <asm/linkage.h>
|
||||
|
||||
/* Some toolchains use other characters (e.g. '`') to mark new line in macro */
|
||||
#ifndef ASM_NL
|
||||
#define ASM_NL ;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define CPP_ASMLINKAGE extern "C"
|
||||
#else
|
||||
#define CPP_ASMLINKAGE
|
||||
#endif
|
||||
|
||||
#ifndef asmlinkage
|
||||
#define asmlinkage CPP_ASMLINKAGE
|
||||
#endif
|
||||
|
||||
#define SYMBOL_NAME_STR(X) #X
|
||||
#define SYMBOL_NAME(X) X
|
||||
#ifdef __STDC__
|
||||
#define SYMBOL_NAME_LABEL(X) X##:
|
||||
#else
|
||||
#define SYMBOL_NAME_LABEL(X) X:
|
||||
#endif
|
||||
|
||||
#ifndef __ALIGN
|
||||
#define __ALIGN .align 4
|
||||
#endif
|
||||
|
||||
#ifndef __ALIGN_STR
|
||||
#define __ALIGN_STR ".align 4"
|
||||
#endif
|
||||
|
||||
#ifdef __ASSEMBLY__
|
||||
|
||||
#define ALIGN __ALIGN
|
||||
#define ALIGN_STR __ALIGN_STR
|
||||
|
||||
#define LENTRY(name) \
|
||||
ALIGN ASM_NL \
|
||||
SYMBOL_NAME_LABEL(name)
|
||||
|
||||
#define ENTRY(name) \
|
||||
.globl SYMBOL_NAME(name) ASM_NL \
|
||||
LENTRY(name)
|
||||
|
||||
#define WEAK(name) \
|
||||
.weak SYMBOL_NAME(name) ASM_NL \
|
||||
LENTRY(name)
|
||||
|
||||
#ifndef END
|
||||
#define END(name) \
|
||||
.size name, .-name
|
||||
#endif
|
||||
|
||||
#ifndef ENDPROC
|
||||
#define ENDPROC(name) \
|
||||
.type name STT_FUNC ASM_NL \
|
||||
END(name)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef _LINUX_LINUX_STRING_H_
|
||||
#define _LINUX_LINUX_STRING_H_
|
||||
|
||||
extern char * skip_spaces(const char *);
|
||||
|
||||
extern char *strim(char *);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,699 @@
|
||||
#ifndef _LINUX_LIST_H
|
||||
#define _LINUX_LIST_H
|
||||
|
||||
#include <linux/stddef.h>
|
||||
#include <linux/poison.h>
|
||||
|
||||
#ifndef ARCH_HAS_PREFETCH
|
||||
#define ARCH_HAS_PREFETCH
|
||||
static inline void prefetch(const void *x) {;}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Simple doubly linked list implementation.
|
||||
*
|
||||
* Some of the internal functions ("__xxx") are useful when
|
||||
* manipulating whole lists rather than single entries, as
|
||||
* sometimes we already know the next/prev entries and we can
|
||||
* generate better code by using them directly rather than
|
||||
* using the generic single-entry routines.
|
||||
*/
|
||||
|
||||
struct list_head {
|
||||
struct list_head *next, *prev;
|
||||
};
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
|
||||
#define LIST_HEAD(name) \
|
||||
struct list_head name = LIST_HEAD_INIT(name)
|
||||
|
||||
static inline void INIT_LIST_HEAD(struct list_head *list)
|
||||
{
|
||||
list->next = list;
|
||||
list->prev = list;
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert a new entry between two known consecutive entries.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_add(struct list_head *new,
|
||||
struct list_head *prev,
|
||||
struct list_head *next)
|
||||
{
|
||||
next->prev = new;
|
||||
new->next = next;
|
||||
new->prev = prev;
|
||||
prev->next = new;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it after
|
||||
*
|
||||
* Insert a new entry after the specified head.
|
||||
* This is good for implementing stacks.
|
||||
*/
|
||||
static inline void list_add(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head, head->next);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add_tail - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it before
|
||||
*
|
||||
* Insert a new entry before the specified head.
|
||||
* This is useful for implementing queues.
|
||||
*/
|
||||
static inline void list_add_tail(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head->prev, head);
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete a list entry by making the prev/next entries
|
||||
* point to each other.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_del(struct list_head *prev, struct list_head *next)
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del - deletes entry from list.
|
||||
* @entry: the element to delete from the list.
|
||||
* Note: list_empty() on entry does not return true after this, the entry is
|
||||
* in an undefined state.
|
||||
*/
|
||||
static inline void list_del(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
entry->next = LIST_POISON1;
|
||||
entry->prev = LIST_POISON2;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_replace - replace old entry by new one
|
||||
* @old : the element to be replaced
|
||||
* @new : the new element to insert
|
||||
*
|
||||
* If @old was empty, it will be overwritten.
|
||||
*/
|
||||
static inline void list_replace(struct list_head *old,
|
||||
struct list_head *new)
|
||||
{
|
||||
new->next = old->next;
|
||||
new->next->prev = new;
|
||||
new->prev = old->prev;
|
||||
new->prev->next = new;
|
||||
}
|
||||
|
||||
static inline void list_replace_init(struct list_head *old,
|
||||
struct list_head *new)
|
||||
{
|
||||
list_replace(old, new);
|
||||
INIT_LIST_HEAD(old);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del_init - deletes entry from list and reinitialize it.
|
||||
* @entry: the element to delete from the list.
|
||||
*/
|
||||
static inline void list_del_init(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
INIT_LIST_HEAD(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move - delete from one list and add as another's head
|
||||
* @list: the entry to move
|
||||
* @head: the head that will precede our entry
|
||||
*/
|
||||
static inline void list_move(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move_tail - delete from one list and add as another's tail
|
||||
* @list: the entry to move
|
||||
* @head: the head that will follow our entry
|
||||
*/
|
||||
static inline void list_move_tail(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add_tail(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_is_last - tests whether @list is the last entry in list @head
|
||||
* @list: the entry to test
|
||||
* @head: the head of the list
|
||||
*/
|
||||
static inline int list_is_last(const struct list_head *list,
|
||||
const struct list_head *head)
|
||||
{
|
||||
return list->next == head;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_empty - tests whether a list is empty
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static inline int list_empty(const struct list_head *head)
|
||||
{
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_empty_careful - tests whether a list is empty and not being modified
|
||||
* @head: the list to test
|
||||
*
|
||||
* Description:
|
||||
* tests whether a list is empty _and_ checks that no other CPU might be
|
||||
* in the process of modifying either member (next or prev)
|
||||
*
|
||||
* NOTE: using list_empty_careful() without synchronization
|
||||
* can only be safe if the only activity that can happen
|
||||
* to the list entry is list_del_init(). Eg. it cannot be used
|
||||
* if another CPU could re-list_add() it.
|
||||
*/
|
||||
static inline int list_empty_careful(const struct list_head *head)
|
||||
{
|
||||
struct list_head *next = head->next;
|
||||
return (next == head) && (next == head->prev);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_is_singular - tests whether a list has just one entry.
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static inline int list_is_singular(const struct list_head *head)
|
||||
{
|
||||
return !list_empty(head) && (head->next == head->prev);
|
||||
}
|
||||
|
||||
static inline void __list_cut_position(struct list_head *list,
|
||||
struct list_head *head, struct list_head *entry)
|
||||
{
|
||||
struct list_head *new_first = entry->next;
|
||||
list->next = head->next;
|
||||
list->next->prev = list;
|
||||
list->prev = entry;
|
||||
entry->next = list;
|
||||
head->next = new_first;
|
||||
new_first->prev = head;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_cut_position - cut a list into two
|
||||
* @list: a new list to add all removed entries
|
||||
* @head: a list with entries
|
||||
* @entry: an entry within head, could be the head itself
|
||||
* and if so we won't cut the list
|
||||
*
|
||||
* This helper moves the initial part of @head, up to and
|
||||
* including @entry, from @head to @list. You should
|
||||
* pass on @entry an element you know is on @head. @list
|
||||
* should be an empty list or a list you do not care about
|
||||
* losing its data.
|
||||
*
|
||||
*/
|
||||
static inline void list_cut_position(struct list_head *list,
|
||||
struct list_head *head, struct list_head *entry)
|
||||
{
|
||||
if (list_empty(head))
|
||||
return;
|
||||
if (list_is_singular(head) &&
|
||||
(head->next != entry && head != entry))
|
||||
return;
|
||||
if (entry == head)
|
||||
INIT_LIST_HEAD(list);
|
||||
else
|
||||
__list_cut_position(list, head, entry);
|
||||
}
|
||||
|
||||
static inline void __list_splice(const struct list_head *list,
|
||||
struct list_head *prev,
|
||||
struct list_head *next)
|
||||
{
|
||||
struct list_head *first = list->next;
|
||||
struct list_head *last = list->prev;
|
||||
|
||||
first->prev = prev;
|
||||
prev->next = first;
|
||||
|
||||
last->next = next;
|
||||
next->prev = last;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice - join two lists, this is designed for stacks
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*/
|
||||
static inline void list_splice(const struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list))
|
||||
__list_splice(list, head, head->next);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice_tail - join two lists, each list being a queue
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*/
|
||||
static inline void list_splice_tail(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list))
|
||||
__list_splice(list, head->prev, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice_init - join two lists and reinitialise the emptied list.
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*
|
||||
* The list at @list is reinitialised
|
||||
*/
|
||||
static inline void list_splice_init(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list)) {
|
||||
__list_splice(list, head, head->next);
|
||||
INIT_LIST_HEAD(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice_tail_init - join two lists and reinitialise the emptied list
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*
|
||||
* Each of the lists is a queue.
|
||||
* The list at @list is reinitialised
|
||||
*/
|
||||
static inline void list_splice_tail_init(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list)) {
|
||||
__list_splice(list, head->prev, head);
|
||||
INIT_LIST_HEAD(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* list_entry - get the struct for this entry
|
||||
* @ptr: the &struct list_head pointer.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_entry(ptr, type, member) \
|
||||
container_of(ptr, type, member)
|
||||
|
||||
/**
|
||||
* list_first_entry - get the first element from a list
|
||||
* @ptr: the list head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Note, that list is expected to be not empty.
|
||||
*/
|
||||
#define list_first_entry(ptr, type, member) \
|
||||
list_entry((ptr)->next, type, member)
|
||||
|
||||
/**
|
||||
* list_last_entry - get the last element from a list
|
||||
* @ptr: the list head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Note, that list is expected to be not empty.
|
||||
*/
|
||||
#define list_last_entry(ptr, type, member) \
|
||||
list_entry((ptr)->prev, type, member)
|
||||
|
||||
/**
|
||||
* list_first_entry_or_null - get the first element from a list
|
||||
* @ptr: the list head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_head within the struct.
|
||||
*
|
||||
* Note that if the list is empty, it returns NULL.
|
||||
*/
|
||||
#define list_first_entry_or_null(ptr, type, member) ({ \
|
||||
struct list_head *head__ = (ptr); \
|
||||
struct list_head *pos__ = READ_ONCE(head__->next); \
|
||||
pos__ != head__ ? list_entry(pos__, type, member) : NULL; \
|
||||
})
|
||||
|
||||
/**
|
||||
* list_for_each - iterate over a list
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; prefetch(pos->next), pos != (head); \
|
||||
pos = pos->next)
|
||||
|
||||
/**
|
||||
* __list_for_each - iterate over a list
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*
|
||||
* This variant differs from list_for_each() in that it's the
|
||||
* simplest possible list iteration code, no prefetching is done.
|
||||
* Use this for code that knows the list to be very short (empty
|
||||
* or 1 entry) most of the time.
|
||||
*/
|
||||
#define __list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); pos = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_prev - iterate over a list backwards
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_prev(pos, head) \
|
||||
for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
|
||||
pos = pos->prev)
|
||||
|
||||
/**
|
||||
* list_for_each_safe - iterate over a list safe against removal of list entry
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @n: another &struct list_head to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
||||
pos = n, n = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @n: another &struct list_head to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_prev_safe(pos, n, head) \
|
||||
for (pos = (head)->prev, n = pos->prev; \
|
||||
prefetch(pos->prev), pos != (head); \
|
||||
pos = n, n = pos->prev)
|
||||
|
||||
/**
|
||||
* list_for_each_entry - iterate over list of given type
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry(pos, head, member) \
|
||||
for (pos = list_entry((head)->next, typeof(*pos), member); \
|
||||
prefetch(pos->member.next), &pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_reverse - iterate backwards over list of given type.
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_reverse(pos, head, member) \
|
||||
for (pos = list_entry((head)->prev, typeof(*pos), member); \
|
||||
prefetch(pos->member.prev), &pos->member != (head); \
|
||||
pos = list_entry(pos->member.prev, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
|
||||
* @pos: the type * to use as a start point
|
||||
* @head: the head of the list
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Prepares a pos entry for use as a start point in list_for_each_entry_continue().
|
||||
*/
|
||||
#define list_prepare_entry(pos, head, member) \
|
||||
((pos) ? : list_entry(head, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_continue - continue iteration over list of given type
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Continue to iterate over list of given type, continuing after
|
||||
* the current position.
|
||||
*/
|
||||
#define list_for_each_entry_continue(pos, head, member) \
|
||||
for (pos = list_entry(pos->member.next, typeof(*pos), member); \
|
||||
prefetch(pos->member.next), &pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_continue_reverse - iterate backwards from the given point
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Start to iterate over list of given type backwards, continuing after
|
||||
* the current position.
|
||||
*/
|
||||
#define list_for_each_entry_continue_reverse(pos, head, member) \
|
||||
for (pos = list_entry(pos->member.prev, typeof(*pos), member); \
|
||||
prefetch(pos->member.prev), &pos->member != (head); \
|
||||
pos = list_entry(pos->member.prev, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_from - iterate over list of given type from the current point
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Iterate over list of given type, continuing from current position.
|
||||
*/
|
||||
#define list_for_each_entry_from(pos, head, member) \
|
||||
for (; prefetch(pos->member.next), &pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_safe(pos, n, head, member) \
|
||||
for (pos = list_entry((head)->next, typeof(*pos), member), \
|
||||
n = list_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, typeof(*n), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe_continue
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Iterate over list of given type, continuing after current point,
|
||||
* safe against removal of list entry.
|
||||
*/
|
||||
#define list_for_each_entry_safe_continue(pos, n, head, member) \
|
||||
for (pos = list_entry(pos->member.next, typeof(*pos), member), \
|
||||
n = list_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, typeof(*n), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe_from
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Iterate over list of given type from current point, safe against
|
||||
* removal of list entry.
|
||||
*/
|
||||
#define list_for_each_entry_safe_from(pos, n, head, member) \
|
||||
for (n = list_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, typeof(*n), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe_reverse
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Iterate backwards over list of given type, safe against removal
|
||||
* of list entry.
|
||||
*/
|
||||
#define list_for_each_entry_safe_reverse(pos, n, head, member) \
|
||||
for (pos = list_entry((head)->prev, typeof(*pos), member), \
|
||||
n = list_entry(pos->member.prev, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.prev, typeof(*n), member))
|
||||
|
||||
/*
|
||||
* Double linked lists with a single pointer list head.
|
||||
* Mostly useful for hash tables where the two pointer list head is
|
||||
* too wasteful.
|
||||
* You lose the ability to access the tail in O(1).
|
||||
*/
|
||||
|
||||
struct hlist_head {
|
||||
struct hlist_node *first;
|
||||
};
|
||||
|
||||
struct hlist_node {
|
||||
struct hlist_node *next, **pprev;
|
||||
};
|
||||
|
||||
#define HLIST_HEAD_INIT { .first = NULL }
|
||||
#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
|
||||
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
|
||||
static inline void INIT_HLIST_NODE(struct hlist_node *h)
|
||||
{
|
||||
h->next = NULL;
|
||||
h->pprev = NULL;
|
||||
}
|
||||
|
||||
static inline int hlist_unhashed(const struct hlist_node *h)
|
||||
{
|
||||
return !h->pprev;
|
||||
}
|
||||
|
||||
static inline int hlist_empty(const struct hlist_head *h)
|
||||
{
|
||||
return !h->first;
|
||||
}
|
||||
|
||||
static inline void __hlist_del(struct hlist_node *n)
|
||||
{
|
||||
struct hlist_node *next = n->next;
|
||||
struct hlist_node **pprev = n->pprev;
|
||||
*pprev = next;
|
||||
if (next)
|
||||
next->pprev = pprev;
|
||||
}
|
||||
|
||||
static inline void hlist_del(struct hlist_node *n)
|
||||
{
|
||||
__hlist_del(n);
|
||||
n->next = LIST_POISON1;
|
||||
n->pprev = LIST_POISON2;
|
||||
}
|
||||
|
||||
static inline void hlist_del_init(struct hlist_node *n)
|
||||
{
|
||||
if (!hlist_unhashed(n)) {
|
||||
__hlist_del(n);
|
||||
INIT_HLIST_NODE(n);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
|
||||
{
|
||||
struct hlist_node *first = h->first;
|
||||
n->next = first;
|
||||
if (first)
|
||||
first->pprev = &n->next;
|
||||
h->first = n;
|
||||
n->pprev = &h->first;
|
||||
}
|
||||
|
||||
/* next must be != NULL */
|
||||
static inline void hlist_add_before(struct hlist_node *n,
|
||||
struct hlist_node *next)
|
||||
{
|
||||
n->pprev = next->pprev;
|
||||
n->next = next;
|
||||
next->pprev = &n->next;
|
||||
*(n->pprev) = n;
|
||||
}
|
||||
|
||||
static inline void hlist_add_after(struct hlist_node *n,
|
||||
struct hlist_node *next)
|
||||
{
|
||||
next->next = n->next;
|
||||
n->next = next;
|
||||
next->pprev = &n->next;
|
||||
|
||||
if(next->next)
|
||||
next->next->pprev = &next->next;
|
||||
}
|
||||
|
||||
#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
|
||||
|
||||
#define hlist_for_each(pos, head) \
|
||||
for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
|
||||
pos = pos->next)
|
||||
|
||||
#define hlist_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
|
||||
pos = n)
|
||||
|
||||
/**
|
||||
* hlist_for_each_entry - iterate over list of given type
|
||||
* @tpos: the type * to use as a loop cursor.
|
||||
* @pos: the &struct hlist_node to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the hlist_node within the struct.
|
||||
*/
|
||||
#define hlist_for_each_entry(tpos, pos, head, member) \
|
||||
for (pos = (head)->first; \
|
||||
pos && ({ prefetch(pos->next); 1;}) && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = pos->next)
|
||||
|
||||
/**
|
||||
* hlist_for_each_entry_continue - iterate over a hlist continuing after current point
|
||||
* @tpos: the type * to use as a loop cursor.
|
||||
* @pos: the &struct hlist_node to use as a loop cursor.
|
||||
* @member: the name of the hlist_node within the struct.
|
||||
*/
|
||||
#define hlist_for_each_entry_continue(tpos, pos, member) \
|
||||
for (pos = (pos)->next; \
|
||||
pos && ({ prefetch(pos->next); 1;}) && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = pos->next)
|
||||
|
||||
/**
|
||||
* hlist_for_each_entry_from - iterate over a hlist continuing from current point
|
||||
* @tpos: the type * to use as a loop cursor.
|
||||
* @pos: the &struct hlist_node to use as a loop cursor.
|
||||
* @member: the name of the hlist_node within the struct.
|
||||
*/
|
||||
#define hlist_for_each_entry_from(tpos, pos, member) \
|
||||
for (; pos && ({ prefetch(pos->next); 1;}) && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = pos->next)
|
||||
|
||||
/**
|
||||
* hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
||||
* @tpos: the type * to use as a loop cursor.
|
||||
* @pos: the &struct hlist_node to use as a loop cursor.
|
||||
* @n: another &struct hlist_node to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the hlist_node within the struct.
|
||||
*/
|
||||
#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
|
||||
for (pos = (head)->first; \
|
||||
pos && ({ n = pos->next; 1; }) && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = n)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef _LINUX_LIST_SORT_H
|
||||
#define _LINUX_LIST_SORT_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
struct list_head;
|
||||
|
||||
void list_sort(void *priv, struct list_head *head,
|
||||
int (*cmp)(void *priv, struct list_head *a,
|
||||
struct list_head *b));
|
||||
#endif
|
||||
@@ -0,0 +1,215 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/* Integer base 2 logarithm calculation
|
||||
*
|
||||
* Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
|
||||
* Written by David Howells (dhowells@redhat.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version
|
||||
* 2 of the License, or (at your option) any later version.
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_LOG2_H
|
||||
#define _LINUX_LOG2_H
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/bitops.h>
|
||||
|
||||
/*
|
||||
* non-constant log of base 2 calculators
|
||||
* - the arch may override these in asm/bitops.h if they can be implemented
|
||||
* more efficiently than using fls() and fls64()
|
||||
* - the arch is not required to handle n==0 if implementing the fallback
|
||||
*/
|
||||
#ifndef CONFIG_ARCH_HAS_ILOG2_U32
|
||||
static inline __attribute__((const))
|
||||
int __ilog2_u32(u32 n)
|
||||
{
|
||||
return fls(n) - 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ARCH_HAS_ILOG2_U64
|
||||
static inline __attribute__((const))
|
||||
int __ilog2_u64(u64 n)
|
||||
{
|
||||
return fls64(n) - 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* is_power_of_2() - check if a value is a power of two
|
||||
* @n: the value to check
|
||||
*
|
||||
* Determine whether some value is a power of two, where zero is
|
||||
* *not* considered a power of two.
|
||||
* Return: true if @n is a power of 2, otherwise false.
|
||||
*/
|
||||
static inline __attribute__((const))
|
||||
bool is_power_of_2(unsigned long n)
|
||||
{
|
||||
return (n != 0 && ((n & (n - 1)) == 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* __roundup_pow_of_two() - round up to nearest power of two
|
||||
* @n: value to round up
|
||||
*/
|
||||
static inline __attribute__((const))
|
||||
unsigned long __roundup_pow_of_two(unsigned long n)
|
||||
{
|
||||
return 1UL << fls_long(n - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* __rounddown_pow_of_two() - round down to nearest power of two
|
||||
* @n: value to round down
|
||||
*/
|
||||
static inline __attribute__((const))
|
||||
unsigned long __rounddown_pow_of_two(unsigned long n)
|
||||
{
|
||||
return 1UL << (fls_long(n) - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* ilog2 - log base 2 of 32-bit or a 64-bit unsigned value
|
||||
* @n: parameter
|
||||
*
|
||||
* constant-capable log of base 2 calculation
|
||||
* - this can be used to initialise global variables from constant data, hence
|
||||
* the massive ternary operator construction
|
||||
*
|
||||
* selects the appropriately-sized optimised version depending on sizeof(n)
|
||||
*/
|
||||
#define ilog2(n) \
|
||||
( \
|
||||
__builtin_constant_p(n) ? ( \
|
||||
(n) < 2 ? 0 : \
|
||||
(n) & (1ULL << 63) ? 63 : \
|
||||
(n) & (1ULL << 62) ? 62 : \
|
||||
(n) & (1ULL << 61) ? 61 : \
|
||||
(n) & (1ULL << 60) ? 60 : \
|
||||
(n) & (1ULL << 59) ? 59 : \
|
||||
(n) & (1ULL << 58) ? 58 : \
|
||||
(n) & (1ULL << 57) ? 57 : \
|
||||
(n) & (1ULL << 56) ? 56 : \
|
||||
(n) & (1ULL << 55) ? 55 : \
|
||||
(n) & (1ULL << 54) ? 54 : \
|
||||
(n) & (1ULL << 53) ? 53 : \
|
||||
(n) & (1ULL << 52) ? 52 : \
|
||||
(n) & (1ULL << 51) ? 51 : \
|
||||
(n) & (1ULL << 50) ? 50 : \
|
||||
(n) & (1ULL << 49) ? 49 : \
|
||||
(n) & (1ULL << 48) ? 48 : \
|
||||
(n) & (1ULL << 47) ? 47 : \
|
||||
(n) & (1ULL << 46) ? 46 : \
|
||||
(n) & (1ULL << 45) ? 45 : \
|
||||
(n) & (1ULL << 44) ? 44 : \
|
||||
(n) & (1ULL << 43) ? 43 : \
|
||||
(n) & (1ULL << 42) ? 42 : \
|
||||
(n) & (1ULL << 41) ? 41 : \
|
||||
(n) & (1ULL << 40) ? 40 : \
|
||||
(n) & (1ULL << 39) ? 39 : \
|
||||
(n) & (1ULL << 38) ? 38 : \
|
||||
(n) & (1ULL << 37) ? 37 : \
|
||||
(n) & (1ULL << 36) ? 36 : \
|
||||
(n) & (1ULL << 35) ? 35 : \
|
||||
(n) & (1ULL << 34) ? 34 : \
|
||||
(n) & (1ULL << 33) ? 33 : \
|
||||
(n) & (1ULL << 32) ? 32 : \
|
||||
(n) & (1ULL << 31) ? 31 : \
|
||||
(n) & (1ULL << 30) ? 30 : \
|
||||
(n) & (1ULL << 29) ? 29 : \
|
||||
(n) & (1ULL << 28) ? 28 : \
|
||||
(n) & (1ULL << 27) ? 27 : \
|
||||
(n) & (1ULL << 26) ? 26 : \
|
||||
(n) & (1ULL << 25) ? 25 : \
|
||||
(n) & (1ULL << 24) ? 24 : \
|
||||
(n) & (1ULL << 23) ? 23 : \
|
||||
(n) & (1ULL << 22) ? 22 : \
|
||||
(n) & (1ULL << 21) ? 21 : \
|
||||
(n) & (1ULL << 20) ? 20 : \
|
||||
(n) & (1ULL << 19) ? 19 : \
|
||||
(n) & (1ULL << 18) ? 18 : \
|
||||
(n) & (1ULL << 17) ? 17 : \
|
||||
(n) & (1ULL << 16) ? 16 : \
|
||||
(n) & (1ULL << 15) ? 15 : \
|
||||
(n) & (1ULL << 14) ? 14 : \
|
||||
(n) & (1ULL << 13) ? 13 : \
|
||||
(n) & (1ULL << 12) ? 12 : \
|
||||
(n) & (1ULL << 11) ? 11 : \
|
||||
(n) & (1ULL << 10) ? 10 : \
|
||||
(n) & (1ULL << 9) ? 9 : \
|
||||
(n) & (1ULL << 8) ? 8 : \
|
||||
(n) & (1ULL << 7) ? 7 : \
|
||||
(n) & (1ULL << 6) ? 6 : \
|
||||
(n) & (1ULL << 5) ? 5 : \
|
||||
(n) & (1ULL << 4) ? 4 : \
|
||||
(n) & (1ULL << 3) ? 3 : \
|
||||
(n) & (1ULL << 2) ? 2 : \
|
||||
1) : \
|
||||
(sizeof(n) <= 4) ? \
|
||||
__ilog2_u32(n) : \
|
||||
__ilog2_u64(n) \
|
||||
)
|
||||
|
||||
/**
|
||||
* roundup_pow_of_two - round the given value up to nearest power of two
|
||||
* @n: parameter
|
||||
*
|
||||
* round the given value up to the nearest power of two
|
||||
* - the result is undefined when n == 0
|
||||
* - this can be used to initialise global variables from constant data
|
||||
*/
|
||||
#define roundup_pow_of_two(n) \
|
||||
( \
|
||||
__builtin_constant_p(n) ? ( \
|
||||
(n == 1) ? 1 : \
|
||||
(1UL << (ilog2((n) - 1) + 1)) \
|
||||
) : \
|
||||
__roundup_pow_of_two(n) \
|
||||
)
|
||||
|
||||
/**
|
||||
* rounddown_pow_of_two - round the given value down to nearest power of two
|
||||
* @n: parameter
|
||||
*
|
||||
* round the given value down to the nearest power of two
|
||||
* - the result is undefined when n == 0
|
||||
* - this can be used to initialise global variables from constant data
|
||||
*/
|
||||
#define rounddown_pow_of_two(n) \
|
||||
( \
|
||||
__builtin_constant_p(n) ? ( \
|
||||
(1UL << ilog2(n))) : \
|
||||
__rounddown_pow_of_two(n) \
|
||||
)
|
||||
|
||||
static inline __attribute_const__
|
||||
int __order_base_2(unsigned long n)
|
||||
{
|
||||
return n > 1 ? ilog2(n - 1) + 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* order_base_2 - calculate the (rounded up) base 2 order of the argument
|
||||
* @n: parameter
|
||||
*
|
||||
* The first few values calculated by this routine:
|
||||
* ob2(0) = 0
|
||||
* ob2(1) = 0
|
||||
* ob2(2) = 1
|
||||
* ob2(3) = 2
|
||||
* ob2(4) = 2
|
||||
* ob2(5) = 3
|
||||
* ... and so on.
|
||||
*/
|
||||
#define order_base_2(n) \
|
||||
( \
|
||||
__builtin_constant_p(n) ? ( \
|
||||
((n) == 0 || (n) == 1) ? 0 : \
|
||||
ilog2((n) - 1) + 1) : \
|
||||
__order_base_2(n) \
|
||||
)
|
||||
#endif /* _LINUX_LOG2_H */
|
||||
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __LOTUS_ATF_H__
|
||||
#define __LOTUS_ATF_H__
|
||||
|
||||
/**************************************************************/
|
||||
#define ARM_BOOT_SMC_CALL 0x8400ff02
|
||||
|
||||
#define SECURE 0x0
|
||||
#define NON_SECURE 0x1
|
||||
|
||||
#define EP_EE_MASK 0x2
|
||||
#define EP_EE_LITTLE 0x0
|
||||
#define EP_EE_BIG 0x2
|
||||
#define ep_get_ee(x) ((x) & EP_EE_MASK)
|
||||
#define ep_set_ee(x, ee) ((x) = ((x) & ~EP_EE_MASK) | (ee))
|
||||
|
||||
/* CPSR/SPSR definitions */
|
||||
#define DAIF_FIQ_BIT (1 << 0)
|
||||
#define DAIF_IRQ_BIT (1 << 1)
|
||||
#define DAIF_ABT_BIT (1 << 2)
|
||||
#define DAIF_DBG_BIT (1 << 3)
|
||||
#define SPSR_DAIF_SHIFT 6
|
||||
#define SPSR_DAIF_MASK 0xf
|
||||
|
||||
#define SPSR_AIF_SHIFT 6
|
||||
#define SPSR_AIF_MASK 0x7
|
||||
|
||||
#define SPSR_E_SHIFT 9
|
||||
#define SPSR_E_MASK 0x1
|
||||
#define SPSR_E_LITTLE 0x0
|
||||
#define SPSR_E_BIG 0x1
|
||||
|
||||
#define SPSR_T_SHIFT 5
|
||||
#define SPSR_T_MASK 0x1
|
||||
#define SPSR_T_ARM 0x0
|
||||
#define SPSR_T_THUMB 0x1
|
||||
|
||||
#define MODE_SP_SHIFT 0x0
|
||||
#define MODE_SP_MASK 0x1
|
||||
#define MODE_SP_EL0 0x0
|
||||
#define MODE_SP_ELX 0x1
|
||||
|
||||
#define MODE_RW_SHIFT 0x4
|
||||
#define MODE_RW_MASK 0x1
|
||||
#define MODE_RW_64 0x0
|
||||
#define MODE_RW_32 0x1
|
||||
|
||||
#define MODE_EL_SHIFT 0x2
|
||||
#define MODE_EL_MASK 0x3
|
||||
#define MODE_EL3 0x3
|
||||
#define MODE_EL2 0x2
|
||||
#define MODE_EL1 0x1
|
||||
#define MODE_EL0 0x0
|
||||
|
||||
#define MODE32_SHIFT 0
|
||||
#define MODE32_MASK 0xf
|
||||
#define MODE32_USR 0x0
|
||||
#define MODE32_FIQ 0x1
|
||||
#define MODE32_IRQ 0x2
|
||||
#define MODE32_SVC 0x3
|
||||
#define MODE32_MON 0x6
|
||||
#define MODE32_ABT 0x7
|
||||
#define MODE32_HYP 0xa
|
||||
#define MODE32_UND 0xb
|
||||
#define MODE32_SYS 0xf
|
||||
|
||||
/* Param header types */
|
||||
#define PARAM_EP 0x01UL
|
||||
#define PARAM_IMAGE_BINARY 0x02UL
|
||||
#define PARAM_BL31 0x03UL
|
||||
#define PARAM_BL_LOAD_INFO 0x04UL
|
||||
#define PARAM_BL_PARAMS 0x05UL
|
||||
#define PARAM_PSCI_LIB_ARGS 0x06UL
|
||||
#define PARAM_SP_IMAGE_BOOT_INFO 0x07UL
|
||||
|
||||
/* Param header version */
|
||||
#define VERSION_1 0x01UL
|
||||
#define VERSION_2 0x02UL
|
||||
|
||||
/* Firmware Image Package */
|
||||
#define FIP_IMAGE_ID 0UL
|
||||
|
||||
/* Trusted Boot Firmware BL2 */
|
||||
#define BL2_IMAGE_ID 1UL
|
||||
|
||||
/* SCP Firmware SCP_BL2 */
|
||||
#define SCP_BL2_IMAGE_ID 2UL
|
||||
|
||||
/* EL3 Runtime Firmware BL31 */
|
||||
#define BL31_IMAGE_ID 3UL
|
||||
|
||||
/* Secure Payload BL32 (Trusted OS) */
|
||||
#define BL32_IMAGE_ID 4UL
|
||||
|
||||
/* Non-Trusted Firmware BL33 */
|
||||
#define BL33_IMAGE_ID 5UL
|
||||
|
||||
|
||||
#define DISABLE_ALL_EXCEPTIONS \
|
||||
(DAIF_FIQ_BIT | DAIF_IRQ_BIT | DAIF_ABT_BIT | DAIF_DBG_BIT)
|
||||
|
||||
#define PARAM_EP_SECURITY_MASK 0x1
|
||||
#define get_security_state(x) ((x) & PARAM_EP_SECURITY_MASK)
|
||||
#define set_security_state(x, security) \
|
||||
((x) = ((x) & ~PARAM_EP_SECURITY_MASK) | (security))
|
||||
|
||||
#define spsr_64(el, sp, daif) \
|
||||
(MODE_RW_64 << MODE_RW_SHIFT | ((el) & MODE_EL_MASK) << MODE_EL_SHIFT | \
|
||||
((sp) & MODE_SP_MASK) << MODE_SP_SHIFT | ((daif) & SPSR_DAIF_MASK) << SPSR_DAIF_SHIFT)
|
||||
|
||||
#define spsr_mode32(mode, isa, endian, aif) (MODE_RW_32 << MODE_RW_SHIFT | \
|
||||
((mode) & MODE32_MASK) << MODE32_SHIFT | ((isa) & SPSR_T_MASK) << SPSR_T_SHIFT | \
|
||||
((endian) & SPSR_E_MASK) << SPSR_E_SHIFT | ((aif) & SPSR_AIF_MASK) << SPSR_AIF_SHIFT)
|
||||
|
||||
|
||||
/* Length of a node address (an IEEE 802 address). */
|
||||
#define _UUID_NODE_LEN 6
|
||||
|
||||
#define FIP_MAX_FILES 3
|
||||
|
||||
/* TODO: Update this number as required */
|
||||
#define TOC_HEADER_SERIAL_NUMBER 0x12345678
|
||||
|
||||
#define FLAG_FILENAME (1 << 0)
|
||||
|
||||
/* This is used as a signature to validate the blob header */
|
||||
#define TOC_HEADER_NAME 0xAA640001
|
||||
|
||||
/* ToC Entry UUIDs */
|
||||
#define UUID_TRUSTED_BOOT_FIRMWARE_BL2 \
|
||||
{0x0becf95f, 0x224d, 0x4d3e, 0xa5, 0x44, {0xc3, 0x9d, 0x81, 0xc7, 0x3f, 0x0a} }
|
||||
#define UUID_SCP_FIRMWARE_BL30 \
|
||||
{0x3dfd6697, 0xbe89, 0x49e8, 0xae, 0x5d, {0x78, 0xa1, 0x40, 0x60, 0x82, 0x13} }
|
||||
#define UUID_EL3_RUNTIME_FIRMWARE_BL31 \
|
||||
{0x6d08d447, 0xfe4c, 0x4698, 0x9b, 0x95, {0x29, 0x50, 0xcb, 0xbd, 0x5a, 0x00} }
|
||||
#define UUID_SECURE_PAYLOAD_BL32 \
|
||||
{0x89e1d005, 0xdc53, 0x4713, 0x8d, 0x2b, {0x50, 0x0a, 0x4b, 0x7a, 0x3e, 0x38} }
|
||||
#define UUID_NON_TRUSTED_FIRMWARE_BL33 \
|
||||
{0xa7eed0d6, 0xeafc, 0x4bd5, 0x97, 0x82, {0x99, 0x34, 0xf2, 0x34, 0xb6, 0xe4} }
|
||||
|
||||
/**************************************************************/
|
||||
/* XXX namespace pollution? */
|
||||
typedef struct uuuid uuid_t;
|
||||
|
||||
/**************************************************************/
|
||||
/*
|
||||
* See also:
|
||||
* http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt
|
||||
* http://www.opengroup.org/onlinepubs/009629399/apdxa.htm
|
||||
*
|
||||
* A DCE 1.1 compatible source representation of UUIDs.
|
||||
*/
|
||||
struct uuuid {
|
||||
uint32_t time_low;
|
||||
uint16_t time_mid;
|
||||
uint16_t time_hi_and_version;
|
||||
uint8_t clock_seq_hi_and_reserved;
|
||||
uint8_t clock_seq_low;
|
||||
uint8_t node[_UUID_NODE_LEN];
|
||||
};
|
||||
|
||||
typedef struct entry_lookup_list {
|
||||
const char *name;
|
||||
uuid_t name_uuid;
|
||||
const char *command_line_name;
|
||||
struct file_info *info;
|
||||
unsigned int flags;
|
||||
} entry_lookup_list_t;
|
||||
|
||||
typedef struct file_info {
|
||||
uuid_t name_uuid;
|
||||
const char *filename;
|
||||
unsigned int size;
|
||||
void *image_buffer;
|
||||
entry_lookup_list_t *entry;
|
||||
} file_info_t;
|
||||
|
||||
typedef struct fip_toc_header {
|
||||
uint32_t name;
|
||||
uint32_t serial_number;
|
||||
uint64_t flags;
|
||||
} fip_toc_header_t;
|
||||
|
||||
typedef struct fip_toc_entry {
|
||||
uuid_t uuid;
|
||||
uint64_t offset_address;
|
||||
uint64_t size;
|
||||
uint64_t flags;
|
||||
} fip_toc_entry_t;
|
||||
|
||||
typedef struct aapcs64_params {
|
||||
uint64_t arg0;
|
||||
uint64_t arg1;
|
||||
uint64_t arg2;
|
||||
uint64_t arg3;
|
||||
uint64_t arg4;
|
||||
uint64_t arg5;
|
||||
uint64_t arg6;
|
||||
uint64_t arg7;
|
||||
} aapcs64_params_t;
|
||||
|
||||
typedef struct aapcs32_params {
|
||||
uint64_t arg0;
|
||||
uint64_t arg1;
|
||||
uint64_t arg2;
|
||||
uint64_t arg3;
|
||||
} aapcs32_params_t;
|
||||
|
||||
/***************************************************************************
|
||||
* This structure provides version information and the size of the
|
||||
* structure, attributes for the structure it represents
|
||||
***************************************************************************/
|
||||
typedef struct param_header {
|
||||
uint8_t type; /* type of the structure */
|
||||
uint8_t version; /* version of this structure */
|
||||
uint16_t size; /* size of this structure in bytes */
|
||||
uint32_t attr; /* attributes: unused bits SBZ */
|
||||
} param_header_t;
|
||||
|
||||
/*****************************************************************************
|
||||
* This structure represents the superset of information needed while
|
||||
* switching exception levels. The only two mechanisms to do so are
|
||||
* ERET & SMC. Security state is indicated using bit zero of header
|
||||
* attribute
|
||||
* NOTE: BL1 expects entrypoint followed by spsr at an offset from the start
|
||||
* of this structure defined by the macro `ENTRY_POINT_INFO_PC_OFFSET` while
|
||||
* processing SMC to jump to BL31.
|
||||
*****************************************************************************/
|
||||
typedef struct entry_point_info {
|
||||
param_header_t h;
|
||||
uint64_t pc;
|
||||
uint32_t spsr;
|
||||
aapcs64_params_t args;
|
||||
} entry_point_info_t;
|
||||
|
||||
/*****************************************************************************
|
||||
* Image info binary provides information from the image loader that
|
||||
* can be used by the firmware to manage available trusted RAM.
|
||||
* More advanced firmware image formats can provide additional
|
||||
* information that enables optimization or greater flexibility in the
|
||||
* common firmware code
|
||||
*****************************************************************************/
|
||||
typedef struct bl_image_info {
|
||||
param_header_t h;
|
||||
uint64_t image_base; /* physical address of base of image */
|
||||
uint32_t image_size; /* bytes read from image file */
|
||||
uint32_t image_max_size;
|
||||
} bl_image_info_t;
|
||||
|
||||
/*****************************************************************************
|
||||
* The image descriptor struct definition.
|
||||
*****************************************************************************/
|
||||
/* BL image node in the BL image execution sequence */
|
||||
typedef struct bl_params_node {
|
||||
unsigned int image_id;
|
||||
bl_image_info_t *image_info __attribute((aligned (8)));
|
||||
entry_point_info_t *ep_info __attribute((aligned (8)));
|
||||
struct bl_params_node *next_params_info __attribute((aligned (8)));
|
||||
} bl_params_node_t;
|
||||
|
||||
/*
|
||||
* BL image head node in the BL image execution sequence
|
||||
* It is also used to pass information to next BL image.
|
||||
*/
|
||||
typedef struct bl_params {
|
||||
param_header_t h;
|
||||
bl_params_node_t *head __attribute((aligned (8)));
|
||||
} bl_params_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* This structure represents the superset of information that can be passed to
|
||||
* BL31 e.g. while passing control to it from BL2. The BL32 parameters will be
|
||||
* populated only if BL2 detects its presence. A pointer to a structure of this
|
||||
* type should be passed in X0 to BL31's cold boot entrypoint.
|
||||
*
|
||||
* Use of this structure and the X0 parameter is not mandatory: the BL31
|
||||
* platform code can use other mechanisms to provide the necessary information
|
||||
* about BL32 and BL33 to the common and SPD code.
|
||||
*
|
||||
* BL31 image information is mandatory if this structure is used. If either of
|
||||
* the optional BL32 and BL33 image information is not provided, this is
|
||||
* indicated by the respective image_info pointers being zero.
|
||||
******************************************************************************/
|
||||
typedef struct bl31_params {
|
||||
param_header_t h;
|
||||
uint64_t bl31_image_info;
|
||||
uint64_t bl32_ep_info;
|
||||
uint64_t bl32_image_info;
|
||||
uint64_t bl33_ep_info;
|
||||
uint64_t bl33_image_info;
|
||||
} bl31_params_t;
|
||||
|
||||
typedef struct smc_cmd_args {
|
||||
uint32_t arg1;
|
||||
uint32_t arg2;
|
||||
uint32_t arg3;
|
||||
uint32_t arg4;
|
||||
uint32_t arg5;
|
||||
}smc_cmd_args_t;
|
||||
|
||||
#define BL33_IMG_ARM32 32
|
||||
#define BL33_IMG_ARM64 64
|
||||
|
||||
#include <image.h>
|
||||
|
||||
void run_bl31(bootm_headers_t *images, uint32_t machid);
|
||||
|
||||
#endif /* __LOTUS_ATF_H__ */
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef LOTUS_CHIP_H
|
||||
#define LOTUS_CHIP_H
|
||||
|
||||
unsigned int get_chipid(void);
|
||||
|
||||
#endif /* LOTUS_CHIP_H */
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __CPU_COMMON_H__
|
||||
#define __CPU_COMMON_H__
|
||||
|
||||
#include <command.h>
|
||||
#include <linux/lotus/hw_decompress.h>
|
||||
|
||||
#ifdef CONFIG_EMMC
|
||||
extern int target_dev;
|
||||
extern int target_paratition;
|
||||
#endif
|
||||
|
||||
void reset_cpu(ulong addr);
|
||||
void uart_early_init(void);
|
||||
void uart_early_puts(const char *ss);
|
||||
|
||||
void download_boot(void);
|
||||
void show_boot_timestamp(void);
|
||||
|
||||
#ifdef CONFIG_BSP_NAND_SPL
|
||||
extern uint32_t crc32(uint32_t crc, const char *p, unsigned int len);
|
||||
|
||||
extern unsigned long __bss_start;
|
||||
extern unsigned char _blank_zone_end[];
|
||||
extern unsigned long _blank_crc_start;
|
||||
#endif
|
||||
extern unsigned char input_data[];
|
||||
extern unsigned char input_data_end[];
|
||||
extern unsigned long _armboot_start;
|
||||
extern int sdhci_add_port(int index, u32 regbase, u32 freq);
|
||||
extern int lotus_mmc_init(int index);
|
||||
|
||||
#if (CONFIG_AUTO_UPDATE == 1)
|
||||
extern int do_auto_update(void);
|
||||
extern int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
|
||||
#endif /* CONFIG_AUTO_UPDATE */
|
||||
|
||||
#ifdef CONFIG_GENERIC_MMC
|
||||
extern int mci_probe(int dev_num);
|
||||
#endif /* CONFIG_GENERIC_MMC */
|
||||
|
||||
#ifdef CONFIG_SUPPORT_EMMC_BOOT
|
||||
extern int mci_add_port(int index, u32 reg_base, u32 freq);
|
||||
#endif /* CONFIG_SUPPORT_EMMC_BOOT */
|
||||
|
||||
#ifdef CONFIG_AUTO_SD_UPDATE
|
||||
extern int mci_add_port(int index, u32 reg_base, u32 freq);
|
||||
#endif /* CONFIG_AUTO_SD_UPDATE */
|
||||
|
||||
extern int mmc_phy_init(void);
|
||||
|
||||
#ifdef CONFIG_CMD_NAND
|
||||
extern int nand_saveenv(void);
|
||||
extern void nand_env_relocate_spec(void);
|
||||
#endif /* CONFIG_CMD_NAND */
|
||||
|
||||
#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
|
||||
extern int sf_saveenv(void);
|
||||
extern void sf_env_relocate_spec(void);
|
||||
#endif /* CONFIG_ENV_IS_IN_SPI_FLASH */
|
||||
|
||||
#ifdef CONFIG_ENV_IS_IN_MMC
|
||||
extern int emmc_saveenv(void);
|
||||
extern void emmc_env_relocate_spec(void);
|
||||
#endif /* CONFIG_ENV_IS_IN_MMC */
|
||||
|
||||
#ifdef CONFIG_ENV_IS_IN_UFS
|
||||
extern int ufs_saveenv(void);
|
||||
extern void ufs_env_relocate_spec(void);
|
||||
#endif /* CONFIG_ENV_IS_IN_UFS */
|
||||
|
||||
#ifdef CONFIG_HWDEC
|
||||
extern unsigned int hw_dec_type;
|
||||
extern void hw_dec_init(void);
|
||||
extern void hw_dec_uinit(void);
|
||||
|
||||
#endif /* CONFIG_HWDEC */
|
||||
|
||||
#endif /* __CPU_COMMON_H__ */
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
#ifndef CYCLE_H
|
||||
#define CYCLE_H
|
||||
|
||||
#include <common.h>
|
||||
|
||||
int getcycledata(unsigned long src, unsigned long src_bak, unsigned int src_len,
|
||||
unsigned long dst);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __FLASH_READ_H
|
||||
#define __FLASH_READ_H
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/*
|
||||
* read flash into out_addr from offset.
|
||||
* note:
|
||||
* 1. offset should aligned with FLASH_ALIGNED_SIZE
|
||||
* 2. if size is not aligned with FLASH_ALIGNED_SIZE,
|
||||
* system will read (((size / FLASH_ALIGNED_SIZE) + 1) * FLASH_ALIGNED_SIZE) content to out_addr
|
||||
*/
|
||||
int flash_read(unsigned long offset, unsigned int size, unsigned char *out_addr);
|
||||
|
||||
/*
|
||||
* read flash into out_addr from offset.
|
||||
* note:
|
||||
* 1. offset and size should aligned with FLASH_ALIGNED_SIZE
|
||||
*/
|
||||
int flash_read_aligned(unsigned long offset, unsigned int size, unsigned char *out_addr);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
#ifndef __FMC_H__
|
||||
#define __FMC_H__
|
||||
|
||||
#include <spi_flash.h>
|
||||
#include <linux/mtd/mtd.h>
|
||||
|
||||
struct spi_flash *fmc100_spi_nor_probe(struct mtd_info_ex **);
|
||||
struct mtd_info_ex *fmc100_get_spi_nor_info(struct spi_flash *);
|
||||
|
||||
#endif /* End of __FMC_H__ */
|
||||
|
||||
@@ -0,0 +1,494 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
#ifndef __FMC_COMMON_H__
|
||||
#define __FMC_COMMON_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
#define _32B 32
|
||||
#define _64B 64
|
||||
#define _128B 128
|
||||
#define _218B 218
|
||||
#define _224B 224
|
||||
#define _232B 232
|
||||
#define _256B 256
|
||||
#define _448B 448
|
||||
#define _512B 512
|
||||
#define _640B 640
|
||||
#define _744B 744
|
||||
#define _1K 1024
|
||||
#define _1280B 1280
|
||||
#define _2K 2048
|
||||
#define _4K 4096
|
||||
#define _8K 8192
|
||||
#define _16K 16384
|
||||
#define _32K 32768
|
||||
#define _64K 0x10000UL
|
||||
#define _128K 0x20000UL
|
||||
#define _256K 0x40000UL
|
||||
#define _512K 0x80000UL
|
||||
#define _1M 0x100000UL
|
||||
#define _2M 0x200000UL
|
||||
#define _4M 0x400000UL
|
||||
#define _8M 0x800000UL
|
||||
#define _16M 0x1000000UL
|
||||
#define _32M 0x2000000UL
|
||||
#define _64M 0x4000000UL
|
||||
#define _128M 0x8000000UL
|
||||
#define _256M 0x10000000UL
|
||||
#define _512M 0x20000000UL
|
||||
#define _1G 0x40000000ULL
|
||||
#define _2G 0x80000000ULL
|
||||
#define _4G 0x100000000ULL
|
||||
#define _8G 0x200000000ULL
|
||||
#define _16G 0x400000000ULL
|
||||
#define _64G 0x1000000000ULL
|
||||
|
||||
#define ECC_TYPE_0BIT 0x0
|
||||
#define ECC_TYPE_8BIT 0x1
|
||||
#define ECC_TYPE_16BIT 0x2
|
||||
#define ECC_TYPE_24BIT 0x3
|
||||
#define ECC_TYPE_28BIT 0x4
|
||||
#define ECC_TYPE_40BIT 0x5
|
||||
#define ECC_TYPE_64BIT 0x6
|
||||
|
||||
#define PAGE_SIZE_2KB 0x0
|
||||
#define PAGE_SIZE_4KB 0x1
|
||||
#define PAGE_SIZE_8KB 0x2
|
||||
#define PAGE_SIZE_16KB 0x3
|
||||
|
||||
/* id len */
|
||||
#define _2B 2
|
||||
#define _3B 3
|
||||
#define _4B 4
|
||||
#define _5B 5
|
||||
#define _6B 6
|
||||
#define _7B 7
|
||||
#define _8B 8
|
||||
#define _9B 9
|
||||
#define _10B 10
|
||||
#define _11B 11
|
||||
#define _12B 12
|
||||
|
||||
#ifdef CONFIG_FMC
|
||||
|
||||
/* FMC REG */
|
||||
#define FMC_CFG 0x08
|
||||
#define fmc_cfg_spi_nand_sel(_type) (((_size) & 0x3) << 1)
|
||||
#define fmc_cfg_spi_nor_addr_mode(_mode) ((_mode) << 10)
|
||||
#define fmc_cfg_block_size(_size) (((_size) & 0x3) << 8)
|
||||
#define fmc_cfg_ecc_type(_type) (((_type) & 0x7) << 5)
|
||||
#define fmc_cfg_page_size(_size) (((_size) & 0x3) << 11)
|
||||
#define fmc_cfg_flash_sel(_type) (((_type) & 0x3) << 3)
|
||||
#define fmc_cfg_op_mode(_mode) ((_mode) & 0x1)
|
||||
|
||||
#define SPI_NAND_MFR_OTHER 0x0
|
||||
#define SPI_NAND_MFR_WINBOND 0x1
|
||||
#define SPI_NAND_MFR_ESMT 0x2
|
||||
#define SPI_NAND_MFR_MICRON 0x3
|
||||
|
||||
#define SPI_NAND_SEL_SHIFT 11
|
||||
#define SPI_NAND_SEL_MASK (0x3 << SPI_NAND_SEL_SHIFT)
|
||||
|
||||
#define SPI_NOR_ADDR_MODE_3_BYTES 0x0
|
||||
#define SPI_NOR_ADDR_MODE_4_BYTES 0x1
|
||||
|
||||
#define SPI_NOR_ADDR_MODE_SHIFT 10
|
||||
#define SPI_NOR_ADDR_MODE_MASK (0x1 << SPI_NOR_ADDR_MODE_SHIFT)
|
||||
|
||||
#define BLOCK_SIZE_64_PAGE 0x0
|
||||
#define BLOCK_SIZE_128_PAGE 0x1
|
||||
#define BLOCK_SIZE_256_PAGE 0x2
|
||||
#define BLOCK_SIZE_512_PAGE 0x3
|
||||
|
||||
#define _64_PAGES 64
|
||||
#define _128_PAGES 128
|
||||
#define _256_PAGES 256
|
||||
#define _512_PAGES 512
|
||||
|
||||
#define EB_NORMAL 28
|
||||
#define EB_2K_16_BIT 4
|
||||
#define EB_4K_16_BIT 12
|
||||
|
||||
#define BLOCK_SIZE_MASK (0x3 << 8)
|
||||
|
||||
#define ECC_TYPE_SHIFT 5
|
||||
#define ECC_TYPE_MASK (0x7 << ECC_TYPE_SHIFT)
|
||||
|
||||
#define PAGE_SIZE_SHIFT 11
|
||||
#define PAGE_SIZE_MASK (0x3 << PAGE_SIZE_SHIFT)
|
||||
|
||||
#define FLASH_TYPE_SPI_NOR 0x0
|
||||
#define FLASH_TYPE_SPI_NAND 0x1
|
||||
#define FLASH_TYPE_NAND 0x2
|
||||
#define FLASH_TYPE_DEFAULT 0x3
|
||||
|
||||
#define FLASH_SEL_SHIFT 3
|
||||
#define FLASH_SEL_MASK (0x3 << FLASH_SEL_SHIFT)
|
||||
|
||||
#define OP_MODE_BOOT 0x0
|
||||
#define OP_MODE_NORMAL 0x1
|
||||
|
||||
#define OP_MODE_MASK 0x1
|
||||
|
||||
#define FMC_GLOBAL_CFG 0x0c
|
||||
#define FMC_GLOBAL_CFG_WP_ENABLE (1 << 11)
|
||||
#define FMC_GLOBAL_CFG_RANDOMIZER_EN (1 << 24)
|
||||
|
||||
#define FMC_SPI_TIMING_CFG 0x00
|
||||
#define timing_cfg_tcsh(_n) (((_n) & 0xf) << 8)
|
||||
#define timing_cfg_tcss(_n) (((_n) & 0xf) << 0)
|
||||
#define timing_cfg_tshsl(_n) (((_n) & 0xf) << 4)
|
||||
|
||||
#define CS_HOLD_TIME 0x6
|
||||
#define CS_SETUP_TIME 0x6
|
||||
#define CS_DESELECT_TIME 0xf
|
||||
|
||||
#define FMC_PND_PWIDTH_CFG 0x04
|
||||
#define pwidth_cfg_rw_hcnt(_n) (((_n) & 0xf) << 8)
|
||||
#define pwidth_cfg_r_lcnt(_n) (((_n) & 0xf) << 4)
|
||||
#define pwidth_cfg_w_lcnt(_n) ((_n) & 0xf)
|
||||
|
||||
#ifdef CONFIG_NAND_EDO_MODE
|
||||
#define RW_H_WIDTH 0x3
|
||||
#define R_L_WIDTH 0x2
|
||||
#define W_L_WIDTH 0x2
|
||||
#define NAND_EDO_MODE_SHIFT 9
|
||||
#define NAND_EDO_MODE_MASK (1<<NAND_EDO_MODE_SHIFT)
|
||||
#define set_nand_edo_mode_en(reg) ((reg) | NAND_EDO_MODE_MASK)
|
||||
#else
|
||||
#define RW_H_WIDTH 0xa
|
||||
#define R_L_WIDTH 0xa
|
||||
#define W_L_WIDTH 0xa
|
||||
#endif
|
||||
|
||||
#define FMC_INT 0x10
|
||||
#define FMC_INT_AHB_OP (1 << 7)
|
||||
#define FMC_INT_WR_LOCK (1 << 6)
|
||||
#define FMC_INT_DMA_ERR (1 << 5)
|
||||
#define FMC_INT_ERR_ALARM (1 << 4)
|
||||
#define FMC_INT_ERR_INVALID (1 << 3)
|
||||
#define FMC_INT_ERR_VALID (1 << 2)
|
||||
#define FMC_INT_OP_FAIL (1 << 1)
|
||||
#define FMC_INT_OP_DONE (1 << 0)
|
||||
|
||||
#define FMC_INT_EN 0x14
|
||||
#define FMC_INT_EN_AHB_OP (1 << 7)
|
||||
#define FMC_INT_EN_WR_LOCK (1 << 6)
|
||||
#define FMC_INT_EN_DMA_ERR (1 << 5)
|
||||
#define FMC_INT_EN_ERR_ALARM (1 << 4)
|
||||
#define FMC_INT_EN_ERR_INVALID (1 << 3)
|
||||
#define FMC_INT_EN_ERR_VALID (1 << 2)
|
||||
#define FMC_INT_EN_OP_FAIL (1 << 1)
|
||||
#define FMC_INT_EN_OP_DONE (1 << 0)
|
||||
|
||||
#define FMC_INT_CLR 0x28
|
||||
#define FMC_INT_CLR_AHB_OP (1 << 7)
|
||||
#define FMC_INT_CLR_WR_LOCK (1 << 6)
|
||||
#define FMC_INT_CLR_DMA_ERR (1 << 5)
|
||||
#define FMC_INT_CLR_ERR_ALARM (1 << 4)
|
||||
#define FMC_INT_CLR_ERR_INVALID (1 << 3)
|
||||
#define FMC_INT_CLR_ERR_VALID (1 << 2)
|
||||
#define FMC_INT_CLR_OP_FAIL (1 << 1)
|
||||
#define FMC_INT_CLR_OP_DONE (1 << 0)
|
||||
|
||||
#define FMC_INT_CLR_ALL 0xff
|
||||
|
||||
#define FMC_CMD 0x2c
|
||||
#define fmc_cmd_cmd2(_cmd) (((_cmd) & 0xff) << 8)
|
||||
#define fmc_cmd_cmd1(_cmd) ((_cmd) & 0xff)
|
||||
|
||||
#define FMC_ADDRH 0x20
|
||||
#define fmc_addrh_set(_addr) ((_addr) & 0xff)
|
||||
|
||||
#define FMC_ADDRL 0x24
|
||||
#define fmc_addrl_block_h_mask(_page) (((_page) & 0xffff) << 16)
|
||||
#define fmc_addrl_block_l_mask(_page) ((_page) & 0xffc0)
|
||||
|
||||
#define READ_ID_ADDR 0x00
|
||||
#define PROTECT_ADDR 0xa0
|
||||
#define FEATURE_ADDR 0xb0
|
||||
#define STATUS_ADDR 0xc0
|
||||
|
||||
#define FMC_OP_CFG 0x38
|
||||
#define op_cfg_fm_cs(_cs) ((_cs) << 10)
|
||||
#define op_cfg_force_cs_en(_en) ((_en) << 11)
|
||||
#define op_cfg_mem_if_type(_type) (((_type) & 0x7) << 4)
|
||||
#define op_cfg_addr_num(_addr) (((_addr) & 0x7) << 7)
|
||||
#define op_cfg_dummy_num(_dummy) ((_dummy) & 0xf)
|
||||
#define OP_CFG_OEN_EN (0x1 << 13)
|
||||
|
||||
#define IF_TYPE_STD 0x0
|
||||
#define IF_TYPE_DUAL 0x1
|
||||
#define IF_TYPE_DIO 0x2
|
||||
#define IF_TYPE_QUAD 0x3
|
||||
#define IF_TYPE_QIO 0x4
|
||||
#define IF_TYPE_DTR 0x4
|
||||
|
||||
#define IF_TYPE_SHIFT 4
|
||||
#define IF_TYPE_MASK (0x7 << IF_TYPE_SHIFT)
|
||||
|
||||
#define READ_ID_ADDR_NUM 1
|
||||
#define FEATURES_OP_ADDR_NUM 1
|
||||
#define STD_OP_ADDR_NUM 3
|
||||
|
||||
#define FMC_SPI_OP_ADDR 0x3c
|
||||
|
||||
#define FMC_DATA_NUM 0x30
|
||||
#define fmc_data_num_cnt(_n) ((_n) & 0x3fff)
|
||||
|
||||
#define SPI_NOR_SR_LEN 1 /* Status Register length */
|
||||
#define SPI_NOR_CR_LEN 1 /* Config Register length */
|
||||
#define FEATURES_DATA_LEN 1
|
||||
#define READ_OOB_BB_LEN 1
|
||||
#define MAX_SPI_NOR_ID_LEN 8
|
||||
#define MAX_NAND_ID_LEN 8
|
||||
#define MAX_SPI_NAND_ID_LEN 3
|
||||
|
||||
#define PROTECT_BRWD_MASK (1 << 7)
|
||||
#define PROTECT_BP3_MASK (1 << 6)
|
||||
#define PROTECT_BP2_MASK (1 << 5)
|
||||
#define PROTECT_BP1_MASK (1 << 4)
|
||||
#define PROTECT_BP0_MASK (1 << 3)
|
||||
|
||||
#define any_bp_enable(_val) ((PROTECT_BP3_MASK & _val) || \
|
||||
(PROTECT_BP2_MASK & _val) || (PROTECT_BP1_MASK & _val) || \
|
||||
(PROTECT_BP0_MASK & _val))
|
||||
|
||||
#define ALL_BP_MASK (PROTECT_BP3_MASK \
|
||||
| PROTECT_BP2_MASK \
|
||||
| PROTECT_BP1_MASK \
|
||||
| PROTECT_BP0_MASK)
|
||||
|
||||
#define FEATURE_ECC_ENABLE (1 << 4)
|
||||
#define FEATURE_QE_ENABLE (1 << 0)
|
||||
|
||||
/* read nand id or nand status, return from nand data length */
|
||||
#define MAX_NANDINFO_LEN 0x10
|
||||
|
||||
#define FMC_OP 0x34
|
||||
#define fmc_op_dummy_en(_en) ((_en) << 8)
|
||||
#define fmc_op_cmd1_en(_en) ((_en) << 2)
|
||||
#define fmc_op_addr_en(_en) ((_en) << 1)
|
||||
#define fmc_op_write_data_en(_en) ((_en) << 5)
|
||||
#define fmc_op_cmd2_en(_en) ((_en) << 4)
|
||||
#define fmc_op_wait_ready_en(_en) ((_en) << 3)
|
||||
#define fmc_op_read_data_en(_en) ((_en) << 7)
|
||||
#define fmc_op_read_status_en(_en) ((_en) << 6)
|
||||
#define FMC_OP_REG_OP_START 1
|
||||
|
||||
#define FMC_DMA_LEN 0x48
|
||||
#define fmc_dma_len_set(_len) ((_len) & 0x0fffffff)
|
||||
#define byte_to_mb(_x) ((_x) >> 20)
|
||||
|
||||
#define FMC_DMA_AHB_CTRL 0x40
|
||||
#define FMC_DMA_AHB_CTRL_DMA_PP_EN (1 << 3)
|
||||
#define FMC_DMA_AHB_CTRL_BURST16_EN (1 << 2)
|
||||
#define FMC_DMA_AHB_CTRL_BURST8_EN (1 << 1)
|
||||
#define FMC_DMA_AHB_CTRL_BURST4_EN 1
|
||||
|
||||
#define ALL_BURST_ENABLE (FMC_DMA_AHB_CTRL_BURST16_EN \
|
||||
| FMC_DMA_AHB_CTRL_BURST8_EN \
|
||||
| FMC_DMA_AHB_CTRL_BURST4_EN)
|
||||
|
||||
#define FMC_DMA_ADDR_OFFSET 4096
|
||||
|
||||
#define FMC_DMA_SADDR_D0 0x44
|
||||
|
||||
#define FMC_DMA_SADDR_D1 0x58
|
||||
|
||||
#define FMC_DMA_SADDR_D2 0x5c
|
||||
|
||||
#define FMC_DMA_SADDR_D3 0x50
|
||||
|
||||
#define FMC_DMA_SADDR_OOB 0x54
|
||||
|
||||
#define FMC_DMA_SADDRH_D0 0x208
|
||||
#define FMC_DMA_SADDRH_SHIFT 0x3LL
|
||||
#define FMC_DMA_SADDRH_MASK (FMC_DMA_SADDRH_SHIFT << 32)
|
||||
|
||||
#define FMC_DMA_SADDRH_OOB 0x218
|
||||
|
||||
#define FMC_DMA_BLK_SADDR 0x68
|
||||
#define fmc_dma_blk_saddr_set(_addr) ((_addr) & 0xffffff)
|
||||
|
||||
#define FMC_DMA_BLK_LEN 0x6c
|
||||
#define fmc_dma_blk_len_set(_len) ((_len) & 0xffff)
|
||||
|
||||
#define FMC_OP_CTRL 0x60
|
||||
#define op_ctrl_rd_opcode(_code) (((_code) & 0xff) << 8)
|
||||
#define op_ctrl_wr_opcode(_code) (((_code) & 0xff) << 16)
|
||||
#define op_ctrl_rd_op_sel(_op) (((_op) & 0x3) << 4)
|
||||
#define op_ctrl_dma_op(_type) ((_type) << 2)
|
||||
#define op_ctrl_rw_op(_op) ((_op) << 1)
|
||||
#define OP_CTRL_DMA_OP_READY 1
|
||||
|
||||
#define RD_OP_READ_ALL_PAGE 0x0
|
||||
#define RD_OP_READ_OOB 0x1
|
||||
#define RD_OP_BLOCK_READ 0x2
|
||||
|
||||
#define RD_OP_SHIFT 4
|
||||
#define RD_OP_MASK (0x3 << RD_OP_SHIFT)
|
||||
|
||||
#define OP_TYPE_DMA 0x0
|
||||
#define OP_TYPE_REG 0x1
|
||||
|
||||
#define RW_OP_READ 0x0
|
||||
#define RW_OP_WRITE 0x1
|
||||
|
||||
#define FMC_OP_PARA 0x78
|
||||
#define FMC_OP_PARA_RD_OOB_ONLY (1 << 1)
|
||||
|
||||
#define FMC_BOOT_SET 0x7c
|
||||
#define FMC_BOOT_SET_DEVICE_ECC_EN (1 << 4)
|
||||
#define FMC_BOOT_SET_BOOT_QUAD_EN (1 << 0)
|
||||
|
||||
#define FMC_STATUS 0xa4
|
||||
|
||||
#define GET_OP 0
|
||||
#define SET_OP 1
|
||||
|
||||
#define STATUS_ECC_MASK (0x3 << 4)
|
||||
#define STATUS_P_FAIL_MASK (1 << 3)
|
||||
#define STATUS_E_FAIL_MASK (1 << 2)
|
||||
#define STATUS_WEL_MASK (1 << 1)
|
||||
#define STATUS_OIP_MASK (1 << 0)
|
||||
|
||||
#define FMC_VERSION 0xb4
|
||||
|
||||
/* FMC IP version */
|
||||
#define FMC_VER_100 0x200
|
||||
|
||||
#endif /* End of CONFIG_FMC */
|
||||
|
||||
#define DISABLE 0
|
||||
#define ENABLE 1
|
||||
|
||||
/* DMA address align with 32 bytes. */
|
||||
#define FMC_DMA_ALIGN 32
|
||||
|
||||
#define FMC_CHIP_DELAY 25
|
||||
|
||||
#define TMP_BUF_LEN 128
|
||||
|
||||
#define fmc_read(_host, _reg) \
|
||||
readl((uintptr_t)((char *)_host->regbase + (_reg)))
|
||||
|
||||
#define fmc_write(_host, _reg, _value) \
|
||||
writel((u_int)(_value), (uintptr_t)((char *)_host->regbase + (_reg)))
|
||||
|
||||
#define get_page_index(host) \
|
||||
((host->addr_value[0] >> 16) | (host->addr_value[1] << 16))
|
||||
|
||||
#define db_msg(_fmt, arg...) \
|
||||
printf("%s(%d): " _fmt, __func__, __LINE__, ##arg);
|
||||
|
||||
#define db_bug(fmt, args...) \
|
||||
do { \
|
||||
printf("%s(%d): BUG: " fmt, __FILE__, __LINE__, ##args); \
|
||||
while (1); \
|
||||
} while (0)
|
||||
|
||||
#define FMC_INFO 1
|
||||
|
||||
#define BT_DBG 0 /* Boot init debug print */
|
||||
#define ER_DBG 0 /* Erase debug print */
|
||||
#define WR_DBG 0 /* Write debug print */
|
||||
#define RD_DBG 0 /* Read debug print */
|
||||
#define QE_DBG 0 /* Quad Enable debug print */
|
||||
#define OP_DBG 0 /* OP command debug print */
|
||||
#define DMA_DB 0 /* DMA read or write debug print */
|
||||
#define AC_DBG 0 /* 3-4byte Address Cycle */
|
||||
#define SR_DBG 0 /* Status Register debug print */
|
||||
#define CR_DBG 0 /* Config Register debug print */
|
||||
#define FT_DBG 0 /* Features debug print */
|
||||
#define WE_DBG 0 /* Write Enable debug print */
|
||||
#define BP_DBG 0 /* Block Protection debug print */
|
||||
#define EC_DBG 0 /* enable/disable ecc0 and randomizer */
|
||||
#define DTR_DB 0 /* 4DTR debug print */
|
||||
#define RST_DB 0 /* enable/disable reset pin */
|
||||
#define REG_DB 0 /* operation debug print */
|
||||
|
||||
#define fmc_pr(_type, _fmt, arg...) \
|
||||
do { \
|
||||
if (_type) \
|
||||
db_msg(_fmt, ##arg) \
|
||||
} while (0)
|
||||
|
||||
#define FMC_WAIT_TIMEOUT 400000 /* 4s equals 400000*10us */
|
||||
|
||||
#define fmc_cmd_wait_cpu_finish(_host) \
|
||||
do { \
|
||||
unsigned regval, timeout = FMC_WAIT_TIMEOUT; \
|
||||
do { \
|
||||
udelay(10); \
|
||||
regval = fmc_read((_host), FMC_OP); \
|
||||
--timeout; \
|
||||
} while ((regval & FMC_OP_REG_OP_START) && timeout); \
|
||||
if (!timeout) \
|
||||
db_msg("Error: Wait cmd cpu finish timeout!\n"); \
|
||||
} while (0)
|
||||
|
||||
#define fmc_dma_wait_int_finish(_host) \
|
||||
do { \
|
||||
unsigned regval, timeout = FMC_WAIT_TIMEOUT; \
|
||||
do { \
|
||||
udelay(10); \
|
||||
regval = fmc_read((_host), FMC_INT); \
|
||||
--timeout; \
|
||||
} while ((!(regval & FMC_INT_OP_DONE) && timeout)); \
|
||||
if (!timeout) { \
|
||||
debug_register_dump(); \
|
||||
db_msg("Error: Wait dma int finish timeout!\n"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define fmc_dma_wait_cpu_finish(_host) \
|
||||
do { \
|
||||
unsigned regval, timeout = FMC_WAIT_TIMEOUT; \
|
||||
do { \
|
||||
udelay(10); \
|
||||
regval = fmc_read((_host), FMC_OP_CTRL); \
|
||||
--timeout; \
|
||||
} while ((regval & OP_CTRL_DMA_OP_READY) && timeout); \
|
||||
if (!timeout) { \
|
||||
debug_register_dump(); \
|
||||
db_msg("Error: Wait dma cpu finish timeout!\n"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define clk_2x(_clk) (((_clk) + 1) >> 1)
|
||||
#define clk_4x(_clk) (((_clk) + 1) >> 2)
|
||||
|
||||
enum OP {
|
||||
READ = 1,
|
||||
WRITE,
|
||||
ERASE,
|
||||
};
|
||||
|
||||
struct fmc_cmd_op {
|
||||
unsigned char cs;
|
||||
unsigned char cmd;
|
||||
unsigned char l_cmd;
|
||||
unsigned char addr_h;
|
||||
unsigned int addr_l;
|
||||
unsigned int data_no;
|
||||
unsigned short option;
|
||||
unsigned short op_cfg;
|
||||
};
|
||||
|
||||
char *ulltostr(unsigned long long size);
|
||||
|
||||
void debug_register_dump(void);
|
||||
|
||||
int fmc_ip_ver_check(void);
|
||||
|
||||
void fmc_dev_type_switch(unsigned char type);
|
||||
|
||||
void *get_fmc_ip(void);
|
||||
|
||||
unsigned char *get_cs_number(unsigned char cs);
|
||||
|
||||
unsigned int get_fmc_boot_mode (void);
|
||||
|
||||
#endif /* End of __FMC_COMMON_H__ */
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
#ifndef HW_DECOMPRESS_H
|
||||
#define HW_DECOMPRESS_H
|
||||
|
||||
#define GZIP_MAX_LEN 0xffffff /* (16MB - 1Byte) */
|
||||
|
||||
typedef enum {
|
||||
HW_DECOMPRESS_OP_START = 0, /* decompress operation start */
|
||||
HW_DECOMPRESS_OP_CONTINUE, /* decompress operation continue */
|
||||
HW_DECOMPRESS_OP_END, /* decompress operation end */
|
||||
HW_DECOMPRESS_OP_ONCE, /* decompress operation just once */
|
||||
} hw_decompress_op_type;
|
||||
|
||||
extern unsigned int hw_dec_type;
|
||||
void hw_dec_init(void);
|
||||
void hw_dec_uinit(void);
|
||||
|
||||
int hw_dec_decompress(const unsigned char *dst, int *dstlen,
|
||||
const unsigned char *src, int srclen, const void *unused);
|
||||
|
||||
/*
|
||||
* Support decompressing gzip file by sections
|
||||
* op_type: operation type
|
||||
* dst: addr of uncompressed file
|
||||
* dstlen: len of uncompressed file
|
||||
* src: addr of compressed file
|
||||
* srclen: len of compressed file
|
||||
*
|
||||
* note: only support v1 version now for sections feature
|
||||
*/
|
||||
int hw_dec_decompress_ex(hw_decompress_op_type op_type, const unsigned char *dst,
|
||||
unsigned int *dstlen, const unsigned char *src, unsigned int srclen);
|
||||
|
||||
int hw_gunzip(void *dst, unsigned int dst_len, void *src, unsigned int *src_len);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
#ifndef __LOTUS_IMAGE_H_
|
||||
#define __LOTUS_IMAGE_H_ 1
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* HW GZIP Image head */
|
||||
static inline bool check_hwzimage_header(unsigned char *header)
|
||||
{
|
||||
unsigned int magic_num0 = *((unsigned int *)(header + HEAD_MAGIC_NUM0_OFFSET));
|
||||
unsigned int magic_num1 = *((unsigned int *)(header + HEAD_MAGIC_NUM1_OFFSET));
|
||||
if ((magic_num0 != HEAD_MAGIC_NUM0) || (magic_num1 != HEAD_MAGIC_NUM1))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif /* __LOTUS_IMAGE_H_ */
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef LOTUS_I2C_H
|
||||
#define LOTUS_I2C_H
|
||||
|
||||
#include <compiler.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
struct i2c_client {
|
||||
unsigned char i2c_num;
|
||||
unsigned short dev_addr;
|
||||
unsigned long int reg_addr;
|
||||
unsigned int reg_width;
|
||||
};
|
||||
|
||||
int hal_i2c_init(unsigned char i2c_num);
|
||||
int hal_i2c_recv(const struct i2c_client *client, unsigned int *buf,
|
||||
unsigned int count);
|
||||
int hal_i2c_send(unsigned char i2c_num, unsigned short dev_addr, const char *buf,
|
||||
unsigned int count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HAL_I2C_H */
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
#ifndef _LOTUS_IMAGE_H_
|
||||
#define _LOTUS_IMAGE_H_
|
||||
|
||||
#include <config.h>
|
||||
#include <linux/lotus/hwzimage.h>
|
||||
|
||||
#define _MCU_HEAD_SIZE 64
|
||||
#define _MCU_FW_MAGIC 0x57465652
|
||||
|
||||
struct mcu_fw_head {
|
||||
u32 j_instruction; /* Jump to real excutable entry */
|
||||
u32 fw_magic; /* MCU Firmware magic */
|
||||
u32 fw_ver; /* MCU Firmware version */
|
||||
u32 fw_total_size; /* MCU Firmware total size */
|
||||
u32 fw_stage1_size; /* MCU Stage1 size */
|
||||
u8 resv[_MCU_HEAD_SIZE - 20]; /* Reserved */
|
||||
};
|
||||
|
||||
#endif /* ifndef _LOTUS_IMAGE_H_ */
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __MATCH_TABLE_H__
|
||||
#define __MATCH_TABLE_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
struct match_reg_type {
|
||||
int reg;
|
||||
int type;
|
||||
};
|
||||
|
||||
struct match_type_str {
|
||||
int type;
|
||||
const char *str;
|
||||
};
|
||||
|
||||
struct match_t {
|
||||
int type;
|
||||
int reg;
|
||||
void *data;
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
#define match_set_type_reg(_type, _reg) {(_type), (_reg), (void *)0}
|
||||
#define match_set_type_data(_type, _data) {(_type), 0, (void *)(_data)}
|
||||
#define match_set(_type, _reg, _data) {(_type), (_reg), (void *)(_data)}
|
||||
|
||||
int reg2type(const struct match_reg_type *table, int length, int reg, int def);
|
||||
|
||||
int type2reg(const struct match_reg_type *table, int length, int type, int def);
|
||||
|
||||
int str2type(const struct match_type_str *table, int length, const char *str,
|
||||
int size, int def);
|
||||
|
||||
const char *type2str(const struct match_type_str *table, int length, int type,
|
||||
const char *def);
|
||||
|
||||
int match_reg_to_type(const struct match_t *table, int nr_table, int reg, int def);
|
||||
|
||||
int match_type_to_reg(const struct match_t *table, int nr_table, int type, int def);
|
||||
|
||||
int match_data_to_type(const struct match_t *table, int nr_table, const char *data,
|
||||
int size, int def);
|
||||
|
||||
void *match_type_to_data(const struct match_t *table, int nr_table, int type,
|
||||
void *def);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif /* End of __MATCH_TABLE_H__ */
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __NFC_COMMON_H__
|
||||
#define __NFC_COMMON_H__
|
||||
|
||||
/*****************************************************************************/
|
||||
#include <asm/io.h>
|
||||
#include <common.h>
|
||||
#include <linux/mtd/rawnand.h>
|
||||
#include <linux/lotus/match_table.h>
|
||||
#include <linux/lotus/fmc_common.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
#define _512B 512
|
||||
#define _2K 2048
|
||||
#define _4K 4096
|
||||
#define _8K 8192
|
||||
#define _16K 16384
|
||||
|
||||
/*****************************************************************************/
|
||||
#define NAND_PAGE_512B 0
|
||||
#define NAND_PAGE_1K 1
|
||||
#define NAND_PAGE_2K 2
|
||||
#define NAND_PAGE_4K 3
|
||||
#define NAND_PAGE_8K 4
|
||||
#define NAND_PAGE_16K 5
|
||||
#define NAND_PAGE_32K 6
|
||||
|
||||
/*****************************************************************************/
|
||||
#define NAND_ECC_NONE 0
|
||||
#define NAND_ECC_0BIT 0
|
||||
#define NAND_ECC_1BIT 1
|
||||
#define NAND_ECC_1BIT_512 1
|
||||
#define NAND_ECC_4BIT 2
|
||||
#define NAND_ECC_4BIT_512 2
|
||||
#define NAND_ECC_4BYTE 2
|
||||
#define NAND_ECC_8BIT 2
|
||||
#define NAND_ECC_8BIT_512 3
|
||||
#define NAND_ECC_8BYTE 3
|
||||
#define NAND_ECC_13BIT 4
|
||||
#define NAND_ECC_16BIT 5
|
||||
#define NAND_ECC_18BIT 6
|
||||
#define NAND_ECC_24BIT 7
|
||||
#define NAND_ECC_27BIT 8
|
||||
#define NAND_ECC_28BIT 9
|
||||
#define NAND_ECC_32BIT 10
|
||||
#define NAND_ECC_40BIT 11
|
||||
#define NAND_ECC_41BIT 12
|
||||
#define NAND_ECC_42BIT 13
|
||||
#define NAND_ECC_48BIT 14
|
||||
#define NAND_ECC_60BIT 15
|
||||
#define NAND_ECC_64BIT 16
|
||||
#define NAND_ECC_72BIT 17
|
||||
#define NAND_ECC_80BIT 18
|
||||
|
||||
#define ERSTR_HARDWARE "Hardware configuration error."
|
||||
#define ERSTR_DRIVER "Driver does not support."
|
||||
|
||||
#define DISABLE 0
|
||||
#define ENABLE 1
|
||||
|
||||
#define is_randomizer(_dev) ((_dev)->flags & NAND_RANDOMIZER)
|
||||
#define is_hw_auto(_dev) ((_dev)->flags & NAND_HW_AUTO)
|
||||
#define is_synchronous(_dev) ((_dev)->flags & NAND_SYNCHRONOUS)
|
||||
#define is_config_done(_dev) ((_dev)->flags & NAND_CONFIG_DONE)
|
||||
#define is_synchronous_boot(_dev) ((_dev)->flags & NAND_SYNCHRONOUS_BOOT)
|
||||
|
||||
#define NAND_PAGE_SHIFT 9 /* 512 */
|
||||
|
||||
#if defined(CONFIG_FMC_SPI_NAND) || defined(CONFIG_FMC_NAND)
|
||||
/*****************************************************************************/
|
||||
enum ecc_type {
|
||||
ET_ECC_NONE = 0x00,
|
||||
ET_ECC_1BIT = 0x01,
|
||||
ET_ECC_4BIT = 0x02,
|
||||
ET_ECC_8BIT = 0x03,
|
||||
ET_ECC_24BIT1K = 0x04,
|
||||
ET_ECC_40BIT1K = 0x05,
|
||||
ET_ECC_64BIT1K = 0x06,
|
||||
};
|
||||
|
||||
enum page_type {
|
||||
PT_PAGESIZE_512 = 0x00,
|
||||
PT_PAGESIZE_2K = 0x01,
|
||||
PT_PAGESIZE_4K = 0x02,
|
||||
PT_PAGESIZE_8K = 0x03,
|
||||
PT_PAGESIZE_16K = 0x04,
|
||||
};
|
||||
|
||||
struct nand_config_info {
|
||||
unsigned int pagetype;
|
||||
unsigned int ecctype;
|
||||
unsigned int oobsize;
|
||||
struct nand_ecclayout *layout;
|
||||
};
|
||||
|
||||
struct nfc_host;
|
||||
|
||||
struct read_retry_t {
|
||||
int type;
|
||||
int count;
|
||||
int (*set_rr_param)(struct nfc_host *host, int param);
|
||||
int (*get_rr_param)(struct nfc_host *host);
|
||||
int (*reset_rr_param)(struct nfc_host *host);
|
||||
int (*enable_enhanced_slc)(struct nfc_host *host, int enable);
|
||||
};
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
struct nand_flash_dev_ex {
|
||||
struct nand_flash_dev flash_dev;
|
||||
|
||||
char *start_type;
|
||||
unsigned char ids[8]; /* 8Byte */
|
||||
int oobsize;
|
||||
int ecctype;
|
||||
|
||||
#define NAND_RANDOMIZER 0x01 /* nand chip need randomizer */
|
||||
#define NAND_HW_AUTO 0x02 /* controller support hardware auto config */
|
||||
#define NAND_SYNCHRONOUS 0x04 /* nand chip support synchronous */
|
||||
#define NAND_ASYNCHRONOUS 0x08 /* nand chip support asynchronous */
|
||||
#define NAND_SYNCHRONOUS_BOOT 0x10 /* nand boot from synchronous mode */
|
||||
#define NAND_CONFIG_DONE 0x20 /* current controller config finish */
|
||||
int flags;
|
||||
int is_randomizer;
|
||||
#define NAND_RR_NONE 0x00
|
||||
#define NAND_RR_HYNIX_BG_BDIE 0x10
|
||||
#define NAND_RR_HYNIX_BG_CDIE 0x11
|
||||
#define NAND_RR_HYNIX_CG_ADIE 0x12
|
||||
#define NAND_RR_MICRON 0x20
|
||||
#define NAND_RR_SAMSUNG 0x30
|
||||
#define NAND_RR_TOSHIBA_24NM 0x40
|
||||
#define NAND_RR_TOSHIBA_19NM 0x41
|
||||
#define NAND_RR_MASK 0xF0
|
||||
int read_retry_type;
|
||||
|
||||
int hostver; /* host controller version. */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
const char *nand_ecc_name(int type);
|
||||
|
||||
const char *nand_page_name(int type);
|
||||
|
||||
int nandpage_size2type(int size);
|
||||
|
||||
int nandpage_type2size(int size);
|
||||
|
||||
/*****************************************************************************/
|
||||
extern int nand_get_ecctype(void);
|
||||
|
||||
extern struct nand_flash_dev *(*get_flash_type)(struct mtd_info *mtd,
|
||||
struct nand_chip *chip, unsigned char *id);
|
||||
|
||||
extern int (*nand_oob_resize)(struct mtd_info *mtd);
|
||||
|
||||
/*****************************************************************************/
|
||||
extern unsigned char match_ecc_type_to_yaffs(unsigned char type);
|
||||
|
||||
extern unsigned char match_page_reg_to_type(unsigned char reg);
|
||||
|
||||
extern unsigned char match_page_type_to_reg(unsigned char type);
|
||||
|
||||
extern const char *match_page_type_to_str(unsigned char type);
|
||||
|
||||
/*****************************************************************************/
|
||||
extern unsigned char match_ecc_reg_to_type(unsigned char reg);
|
||||
|
||||
extern unsigned char match_ecc_type_to_reg(unsigned char type);
|
||||
|
||||
extern const char *match_ecc_type_to_str(unsigned char type);
|
||||
|
||||
/*****************************************************************************/
|
||||
extern unsigned char match_page_size_to_type(unsigned int size);
|
||||
|
||||
extern unsigned int match_page_type_to_size(unsigned char type);
|
||||
|
||||
#endif /* End of __NFC_COMMON_H__ */
|
||||
|
||||
@@ -0,0 +1,614 @@
|
||||
|
||||
#ifndef SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27
|
||||
#define SECUREC_H_5D13A042_DC3F_4ED9_A8D1_882811274C27
|
||||
|
||||
#include "linux/lotus/securectype.h"
|
||||
#ifndef SECUREC_HAVE_STDARG_H
|
||||
#define SECUREC_HAVE_STDARG_H 1
|
||||
#endif
|
||||
|
||||
#if SECUREC_HAVE_STDARG_H
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
|
||||
#ifndef SECUREC_HAVE_ERRNO_H
|
||||
#define SECUREC_HAVE_ERRNO_H 1
|
||||
#endif
|
||||
|
||||
/* EINVAL ERANGE may defined in errno.h */
|
||||
#if SECUREC_HAVE_ERRNO_H
|
||||
#if SECUREC_IN_KERNEL
|
||||
#include <linux/errno.h>
|
||||
#else
|
||||
#include <errno.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Define error code */
|
||||
#if defined(SECUREC_NEED_ERRNO_TYPE) || !defined(__STDC_WANT_LIB_EXT1__) || \
|
||||
(defined(__STDC_WANT_LIB_EXT1__) && (!__STDC_WANT_LIB_EXT1__))
|
||||
#ifndef SECUREC_DEFINED_ERRNO_TYPE
|
||||
#define SECUREC_DEFINED_ERRNO_TYPE
|
||||
/* Just check whether macrodefinition exists. */
|
||||
#ifndef errno_t
|
||||
typedef int errno_t;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Success */
|
||||
#ifndef EOK
|
||||
#define EOK 0
|
||||
#endif
|
||||
|
||||
#ifndef EINVAL
|
||||
/* The src buffer is not correct and destination buffer cant not be reset */
|
||||
#define EINVAL 22
|
||||
#endif
|
||||
|
||||
#ifndef EINVAL_AND_RESET
|
||||
/* Once the error is detected, the dest buffer must be reseted! Value is 22 xor 128 */
|
||||
#define EINVAL_AND_RESET 150
|
||||
#endif
|
||||
|
||||
#ifndef ERANGE
|
||||
/* The destination buffer is not long enough and destination buffer can not be reset */
|
||||
#define ERANGE 34
|
||||
#endif
|
||||
|
||||
#ifndef ERANGE_AND_RESET
|
||||
/* Once the error is detected, the dest buffer must be reseted! Value is 34 xor 128 */
|
||||
#define ERANGE_AND_RESET 162
|
||||
#endif
|
||||
|
||||
#ifndef EOVERLAP_AND_RESET
|
||||
/* Once the buffer overlap is detected, the dest buffer must be reseted! Value is 54 xor 128 */
|
||||
#define EOVERLAP_AND_RESET 182
|
||||
#endif
|
||||
|
||||
/* If you need export the function of this library in Win32 dll, use __declspec(dllexport) */
|
||||
#ifndef SECUREC_API
|
||||
#if defined(SECUREC_DLL_EXPORT)
|
||||
#define SECUREC_API __declspec(dllexport)
|
||||
#elif defined(SECUREC_DLL_IMPORT)
|
||||
#define SECUREC_API __declspec(dllimport)
|
||||
#else
|
||||
/*
|
||||
* Standardized function declaration. If a security function is declared in the your code,
|
||||
* it may cause a compilation alarm,Please delete the security function you declared.
|
||||
* Adding extern under windows will cause the system to have inline functions to expand,
|
||||
* so do not add the extern in default
|
||||
*/
|
||||
#if defined(_MSC_VER)
|
||||
#define SECUREC_API
|
||||
#else
|
||||
#define SECUREC_API extern
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Description: The GetHwSecureCVersion function get SecureC Version string and version number.
|
||||
* Parameter: verNumber - to store version number (for example value is 0x500 | 0xa)
|
||||
* Return: version string
|
||||
*/
|
||||
SECUREC_API const char *GetHwSecureCVersion(unsigned short *verNumber);
|
||||
|
||||
#if SECUREC_ENABLE_MEMSET
|
||||
/*
|
||||
* Description: The memset_s function copies the value of c (converted to an unsigned char) into each of
|
||||
* the first count characters of the object pointed to by dest.
|
||||
* Parameter: dest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer
|
||||
* Parameter: c - the value to be copied
|
||||
* Parameter: count - copies count bytes of value to dest
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t memset_s(void *dest, size_t destMax, int c, size_t count);
|
||||
#endif
|
||||
|
||||
#ifndef SECUREC_ONLY_DECLARE_MEMSET
|
||||
#define SECUREC_ONLY_DECLARE_MEMSET 0
|
||||
#endif
|
||||
|
||||
#if !SECUREC_ONLY_DECLARE_MEMSET
|
||||
|
||||
#if SECUREC_ENABLE_MEMMOVE
|
||||
/*
|
||||
* Description: The memmove_s function copies n characters from the object pointed to by src
|
||||
* into the object pointed to by dest.
|
||||
* Parameter: dest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer
|
||||
* Parameter: src - source address
|
||||
* Parameter: count - copies count bytes from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_MEMCPY
|
||||
/*
|
||||
* Description: The memcpy_s function copies n characters from the object pointed to
|
||||
* by src into the object pointed to by dest.
|
||||
* Parameter: dest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer
|
||||
* Parameter: src - source address
|
||||
* Parameter: count - copies count bytes from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRCPY
|
||||
/*
|
||||
* Description: The strcpy_s function copies the string pointed to by strSrc (including
|
||||
* the terminating null character) into the array pointed to by strDest
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
|
||||
* Parameter: strSrc - source address
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRNCPY
|
||||
/*
|
||||
* Description: The strncpy_s function copies not more than n successive characters (not including
|
||||
* the terminating null character) from the array pointed to by strSrc to the array pointed to by strDest.
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
|
||||
* Parameter: strSrc - source address
|
||||
* Parameter: count - copies count characters from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRCAT
|
||||
/*
|
||||
* Description: The strcat_s function appends a copy of the string pointed to by strSrc (including
|
||||
* the terminating null character) to the end of the string pointed to by strDest.
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null wide character)
|
||||
* Parameter: strSrc - source address
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRNCAT
|
||||
/*
|
||||
* Description: The strncat_s function appends not more than n successive characters (not including
|
||||
* the terminating null character)
|
||||
* from the array pointed to by strSrc to the end of the string pointed to by strDest.
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
|
||||
* Parameter: strSrc - source address
|
||||
* Parameter: count - copies count characters from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VSPRINTF
|
||||
/*
|
||||
* Description: The vsprintf_s function is equivalent to the vsprintf function except for the parameter destMax
|
||||
* and the explicit runtime-constraints violation
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null wide characte)
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of characters printed(not including the terminating null byte '\0'),
|
||||
* If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vsprintf_s(char *strDest, size_t destMax, const char *format,
|
||||
va_list argList) SECUREC_ATTRIBUTE(3, 0);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_SPRINTF
|
||||
/*
|
||||
* Description: The sprintf_s function is equivalent to the sprintf function except for the parameter destMax
|
||||
* and the explicit runtime-constraints violation
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of characters printed(not including the terminating null byte '\0'),
|
||||
* If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int sprintf_s(char *strDest, size_t destMax, const char *format, ...) SECUREC_ATTRIBUTE(3, 4);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VSNPRINTF
|
||||
/*
|
||||
* Description: The vsnprintf_s function is equivalent to the vsnprintf function except for
|
||||
* the parameter destMax/count and the explicit runtime-constraints violation
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
|
||||
* Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0')
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of characters printed(not including the terminating null byte '\0'),
|
||||
* If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs
|
||||
*/
|
||||
SECUREC_API int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
|
||||
va_list argList) SECUREC_ATTRIBUTE(4, 0);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_SNPRINTF
|
||||
/*
|
||||
* Description: The snprintf_s function is equivalent to the snprintf function except for
|
||||
* the parameter destMax/count and the explicit runtime-constraints violation
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
|
||||
* Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte '\0')
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of characters printed(not including the terminating null byte '\0'),
|
||||
* If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs
|
||||
*/
|
||||
SECUREC_API int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
|
||||
...) SECUREC_ATTRIBUTE(4, 5);
|
||||
#endif
|
||||
|
||||
#if SECUREC_SNPRINTF_TRUNCATED
|
||||
/*
|
||||
* Description: The vsnprintf_truncated_s function is equivalent to the vsnprintf_s function except
|
||||
* no count parameter and return value
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of characters printed(not including the terminating null byte '\0'),
|
||||
* If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs
|
||||
*/
|
||||
SECUREC_API int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format,
|
||||
va_list argList) SECUREC_ATTRIBUTE(3, 0);
|
||||
|
||||
/*
|
||||
* Description: The snprintf_truncated_s function is equivalent to the snprintf_2 function except
|
||||
* no count parameter and return value
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest.
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null byte '\0')
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of characters printed(not including the terminating null byte '\0'),
|
||||
* If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs
|
||||
*/
|
||||
SECUREC_API int snprintf_truncated_s(char *strDest, size_t destMax,
|
||||
const char *format, ...) SECUREC_ATTRIBUTE(3, 4);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_SCANF
|
||||
/*
|
||||
* Description: The scanf_s function is equivalent to fscanf_s with the argument stdin
|
||||
* interposed before the arguments to scanf_s
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int scanf_s(const char *format, ...);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VSCANF
|
||||
/*
|
||||
* Description: The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by argList
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vscanf_s(const char *format, va_list argList);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_SSCANF
|
||||
/*
|
||||
* Description: The sscanf_s function is equivalent to fscanf_s, except that input is obtained from a
|
||||
* string (specified by the argument buffer) rather than from a stream
|
||||
* Parameter: buffer - read character from buffer
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int sscanf_s(const char *buffer, const char *format, ...);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VSSCANF
|
||||
/*
|
||||
* Description: The vsscanf_s function is equivalent to sscanf_s, with the variable argument list
|
||||
* replaced by argList
|
||||
* Parameter: buffer - read character from buffer
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vsscanf_s(const char *buffer, const char *format, va_list argList);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_FSCANF
|
||||
/*
|
||||
* Description: The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion specifiers
|
||||
* apply to a pair of arguments (unless assignment suppression is indicated by a*)
|
||||
* Parameter: stream - stdio file stream
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int fscanf_s(FILE *stream, const char *format, ...);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VFSCANF
|
||||
/*
|
||||
* Description: The vfscanf_s function is equivalent to fscanf_s, with the variable argument list
|
||||
* replaced by argList
|
||||
* Parameter: stream - stdio file stream
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vfscanf_s(FILE *stream, const char *format, va_list argList);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRTOK
|
||||
/*
|
||||
* Description: The strtok_s function parses a string into a sequence of strToken,
|
||||
* replace all characters in strToken string that match to strDelimit set with 0.
|
||||
* On the first call to strtok_s the string to be parsed should be specified in strToken.
|
||||
* In each subsequent call that should parse the same string, strToken should be NULL
|
||||
* Parameter: strToken - the string to be delimited
|
||||
* Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string
|
||||
* Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function
|
||||
* Return: On the first call returns the address of the first non \0 character, otherwise NULL is returned.
|
||||
* In subsequent calls, the strtoken is set to NULL, and the context set is the same as the previous call,
|
||||
* return NULL if the *context string length is equal 0, otherwise return *context.
|
||||
*/
|
||||
SECUREC_API char *strtok_s(char *strToken, const char *strDelimit, char **context);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_GETS && !SECUREC_IN_KERNEL
|
||||
/*
|
||||
* Description: The gets_s function reads at most one less than the number of characters specified
|
||||
* by destMax from the stream pointed to by stdin, into the array pointed to by buffer
|
||||
* Parameter: buffer - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null character)
|
||||
* Return: buffer if there was no runtime-constraint violation,If an error occurred Return: NULL.
|
||||
*/
|
||||
SECUREC_API char *gets_s(char *buffer, size_t destMax);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_WCHAR_FUNC
|
||||
#if SECUREC_ENABLE_MEMCPY
|
||||
/*
|
||||
* Description: The wmemcpy_s function copies n successive wide characters from the object pointed to
|
||||
* by src into the object pointed to by dest.
|
||||
* Parameter: dest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer
|
||||
* Parameter: src - source address
|
||||
* Parameter: count - copies count wide characters from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_MEMMOVE
|
||||
/*
|
||||
* Description: The wmemmove_s function copies n successive wide characters from the object
|
||||
* pointed to by src into the object pointed to by dest.
|
||||
* Parameter: dest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer
|
||||
* Parameter: src - source address
|
||||
* Parameter: count - copies count wide characters from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRCPY
|
||||
/*
|
||||
* Description: The wcscpy_s function copies the wide string pointed to by strSrc (including theterminating
|
||||
* null wide character) into the array pointed to by strDest
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer
|
||||
* Parameter: strSrc - source address
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRNCPY
|
||||
/*
|
||||
* Description: The wcsncpy_s function copies not more than n successive wide characters (not including the
|
||||
* terminating null wide character) from the array pointed to by strSrc to the array pointed to by strDest
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating wide character)
|
||||
* Parameter: strSrc - source address
|
||||
* Parameter: count - copies count wide characters from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRCAT
|
||||
/*
|
||||
* Description: The wcscat_s function appends a copy of the wide string pointed to by strSrc (including the
|
||||
* terminating null wide character) to the end of the wide string pointed to by strDest
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating wide character)
|
||||
* Parameter: strSrc - source address
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRNCAT
|
||||
/*
|
||||
* Description: The wcsncat_s function appends not more than n successive wide characters (not including the
|
||||
* terminating null wide character) from the array pointed to by strSrc to the end of the wide string pointed to
|
||||
* by strDest.
|
||||
* Parameter: strDest - destination address
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating wide character)
|
||||
* Parameter: strSrc - source address
|
||||
* Parameter: count - copies count wide characters from the src
|
||||
* Return: EOK if there was no runtime-constraint violation
|
||||
*/
|
||||
SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_STRTOK
|
||||
/*
|
||||
* Description: The wcstok_s function is the wide-character equivalent of the strtok_s function
|
||||
* Parameter: strToken - the string to be delimited
|
||||
* Parameter: strDelimit - specifies a set of characters that delimit the tokens in the parsed string
|
||||
* Parameter: context - is a pointer to a char * variable that is used internally by strtok_s function
|
||||
* Return: a pointer to the first character of a token, or a null pointer if there is no token
|
||||
* or there is a runtime-constraint violation.
|
||||
*/
|
||||
SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VSPRINTF
|
||||
/*
|
||||
* Description: The vswprintf_s function is the wide-character equivalent of the vsprintf_s function
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null )
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of characters printed(not including the terminating null wide characte),
|
||||
* If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_SPRINTF
|
||||
|
||||
/*
|
||||
* Description: The swprintf_s function is the wide-character equivalent of the sprintf_s function
|
||||
* Parameter: strDest - produce output according to a format ,write to the character string strDest
|
||||
* Parameter: destMax - The maximum length of destination buffer(including the terminating null )
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of characters printed(not including the terminating null wide characte),
|
||||
* If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_FSCANF
|
||||
/*
|
||||
* Description: The fwscanf_s function is the wide-character equivalent of the fscanf_s function
|
||||
* Parameter: stream - stdio file stream
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int fwscanf_s(FILE *stream, const wchar_t *format, ...);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VFSCANF
|
||||
/*
|
||||
* Description: The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function
|
||||
* Parameter: stream - stdio file stream
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_SCANF
|
||||
/*
|
||||
* Description: The wscanf_s function is the wide-character equivalent of the scanf_s function
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int wscanf_s(const wchar_t *format, ...);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VSCANF
|
||||
/*
|
||||
* Description: The vwscanf_s function is the wide-character equivalent of the vscanf_s function
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vwscanf_s(const wchar_t *format, va_list argList);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_SSCANF
|
||||
/*
|
||||
* Description: The swscanf_s function is the wide-character equivalent of the sscanf_s function
|
||||
* Parameter: buffer - read character from buffer
|
||||
* Parameter: format - fromat string
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...);
|
||||
#endif
|
||||
|
||||
#if SECUREC_ENABLE_VSSCANF
|
||||
/*
|
||||
* Description: The vswscanf_s function is the wide-character equivalent of the vsscanf_s function
|
||||
* Parameter: buffer - read character from buffer
|
||||
* Parameter: format - fromat string
|
||||
* Parameter: argList - instead of a variable number of arguments
|
||||
* Return: the number of input items assigned, If an error occurred Return: -1.
|
||||
*/
|
||||
SECUREC_API int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList);
|
||||
#endif
|
||||
#endif /* SECUREC_ENABLE_WCHAR_FUNC */
|
||||
#endif
|
||||
|
||||
/* Those functions are used by macro ,must declare hare , also for without function declaration warning */
|
||||
extern errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count);
|
||||
extern errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc);
|
||||
|
||||
#if SECUREC_WITH_PERFORMANCE_ADDONS
|
||||
/* Those functions are used by macro */
|
||||
extern errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count);
|
||||
extern errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count);
|
||||
extern errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count);
|
||||
extern errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count);
|
||||
|
||||
/* The strcpy_sp is a macro, not a function in performance optimization mode. */
|
||||
#define strcpy_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \
|
||||
__builtin_constant_p((src))) ? \
|
||||
SECUREC_STRCPY_SM((dest), (destMax), (src)) : \
|
||||
strcpy_s((dest), (destMax), (src)))
|
||||
|
||||
/* The strncpy_sp is a macro, not a function in performance optimization mode. */
|
||||
#define strncpy_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \
|
||||
__builtin_constant_p((destMax)) && \
|
||||
__builtin_constant_p((src))) ? \
|
||||
SECUREC_STRNCPY_SM((dest), (destMax), (src), (count)) : \
|
||||
strncpy_s((dest), (destMax), (src), (count)))
|
||||
|
||||
/* The strcat_sp is a macro, not a function in performance optimization mode. */
|
||||
#define strcat_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \
|
||||
__builtin_constant_p((src))) ? \
|
||||
SECUREC_STRCAT_SM((dest), (destMax), (src)) : \
|
||||
strcat_s((dest), (destMax), (src)))
|
||||
|
||||
/* The strncat_sp is a macro, not a function in performance optimization mode. */
|
||||
#define strncat_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \
|
||||
__builtin_constant_p((destMax)) && \
|
||||
__builtin_constant_p((src))) ? \
|
||||
SECUREC_STRNCAT_SM((dest), (destMax), (src), (count)) : \
|
||||
strncat_s((dest), (destMax), (src), (count)))
|
||||
|
||||
/* The memcpy_sp is a macro, not a function in performance optimization mode. */
|
||||
#define memcpy_sp(dest, destMax, src, count) (__builtin_constant_p((count)) ? \
|
||||
(SECUREC_MEMCPY_SM((dest), (destMax), (src), (count))) : \
|
||||
(__builtin_constant_p((destMax)) ? \
|
||||
(((size_t)(destMax) > 0 && \
|
||||
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \
|
||||
memcpy_sOptTc((dest), (destMax), (src), (count)) : ERANGE) : \
|
||||
memcpy_sOptAsm((dest), (destMax), (src), (count))))
|
||||
|
||||
/* The memset_sp is a macro, not a function in performance optimization mode. */
|
||||
#define memset_sp(dest, destMax, c, count) (__builtin_constant_p((count)) ? \
|
||||
(SECUREC_MEMSET_SM((dest), (destMax), (c), (count))) : \
|
||||
(__builtin_constant_p((destMax)) ? \
|
||||
(((((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \
|
||||
memset_sOptTc((dest), (destMax), (c), (count)) : ERANGE) : \
|
||||
memset_sOptAsm((dest), (destMax), (c), (count))))
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,564 @@
|
||||
|
||||
#ifndef SECURECTYPE_H_A7BBB686_AADA_451B_B9F9_44DACDAE18A7
|
||||
#define SECURECTYPE_H_A7BBB686_AADA_451B_B9F9_44DACDAE18A7
|
||||
|
||||
#ifndef SECUREC_USING_STD_SECURE_LIB
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
#if defined(__STDC_WANT_SECURE_LIB__) && (!__STDC_WANT_SECURE_LIB__)
|
||||
/* Security functions have been provided since vs2005, default use of system library functions */
|
||||
#define SECUREC_USING_STD_SECURE_LIB 0
|
||||
#else
|
||||
#define SECUREC_USING_STD_SECURE_LIB 1
|
||||
#endif
|
||||
#else
|
||||
#define SECUREC_USING_STD_SECURE_LIB 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Compatibility with older Secure C versions, shielding VC symbol redefinition warning */
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && (!SECUREC_USING_STD_SECURE_LIB)
|
||||
#ifndef SECUREC_DISABLE_CRT_FUNC
|
||||
#define SECUREC_DISABLE_CRT_FUNC 1
|
||||
#endif
|
||||
#ifndef SECUREC_DISABLE_CRT_IMP
|
||||
#define SECUREC_DISABLE_CRT_IMP 1
|
||||
#endif
|
||||
#else /* MSC VER */
|
||||
#ifndef SECUREC_DISABLE_CRT_FUNC
|
||||
#define SECUREC_DISABLE_CRT_FUNC 0
|
||||
#endif
|
||||
#ifndef SECUREC_DISABLE_CRT_IMP
|
||||
#define SECUREC_DISABLE_CRT_IMP 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SECUREC_DISABLE_CRT_FUNC
|
||||
#ifdef __STDC_WANT_SECURE_LIB__
|
||||
#undef __STDC_WANT_SECURE_LIB__
|
||||
#endif
|
||||
#define __STDC_WANT_SECURE_LIB__ 0
|
||||
#endif
|
||||
|
||||
#if SECUREC_DISABLE_CRT_IMP
|
||||
#ifdef _CRTIMP_ALTERNATIVE
|
||||
#undef _CRTIMP_ALTERNATIVE
|
||||
#endif
|
||||
#define _CRTIMP_ALTERNATIVE /* Comment Microsoft *_s function */
|
||||
#endif
|
||||
|
||||
/* Compile in kernel under macro control */
|
||||
#ifndef SECUREC_IN_KERNEL
|
||||
#ifdef __KERNEL__
|
||||
#define SECUREC_IN_KERNEL 0
|
||||
#else
|
||||
#define SECUREC_IN_KERNEL 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* make kernel symbols of functions available to loadable modules */
|
||||
#ifndef SECUREC_EXPORT_KERNEL_SYMBOL
|
||||
#if SECUREC_IN_KERNEL
|
||||
#define SECUREC_EXPORT_KERNEL_SYMBOL 1
|
||||
#else
|
||||
#define SECUREC_EXPORT_KERNEL_SYMBOL 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SECUREC_IN_KERNEL
|
||||
#ifndef SECUREC_ENABLE_SCANF_FILE
|
||||
#define SECUREC_ENABLE_SCANF_FILE 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_WCHAR_FUNC
|
||||
#define SECUREC_ENABLE_WCHAR_FUNC 0
|
||||
#endif
|
||||
#else /* SECUREC_IN_KERNEL */
|
||||
#ifndef SECUREC_ENABLE_SCANF_FILE
|
||||
#define SECUREC_ENABLE_SCANF_FILE 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_WCHAR_FUNC
|
||||
#define SECUREC_ENABLE_WCHAR_FUNC 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Default secure function declaration, default declarations for non-standard functions */
|
||||
#ifndef SECUREC_SNPRINTF_TRUNCATED
|
||||
#define SECUREC_SNPRINTF_TRUNCATED 1
|
||||
#endif
|
||||
|
||||
#if SECUREC_USING_STD_SECURE_LIB
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
/* Declare secure functions that are not available in the VS compiler */
|
||||
#ifndef SECUREC_ENABLE_MEMSET
|
||||
#define SECUREC_ENABLE_MEMSET 1
|
||||
#endif
|
||||
/* VS 2005 have vsnprintf_s function */
|
||||
#ifndef SECUREC_ENABLE_VSNPRINTF
|
||||
#define SECUREC_ENABLE_VSNPRINTF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SNPRINTF
|
||||
/* VS 2005 have vsnprintf_s function Adapt the snprintf_s of the security function */
|
||||
#define snprintf_s _snprintf_s
|
||||
#define SECUREC_ENABLE_SNPRINTF 0
|
||||
#endif
|
||||
/* Before VS 2010 do not have v functions */
|
||||
#if _MSC_VER <= 1600 || defined(SECUREC_FOR_V_SCANFS)
|
||||
#ifndef SECUREC_ENABLE_VFSCANF
|
||||
#define SECUREC_ENABLE_VFSCANF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSCANF
|
||||
#define SECUREC_ENABLE_VSCANF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSSCANF
|
||||
#define SECUREC_ENABLE_VSSCANF 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#else /* MSC VER */
|
||||
#ifndef SECUREC_ENABLE_MEMSET
|
||||
#define SECUREC_ENABLE_MEMSET 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SNPRINTF
|
||||
#define SECUREC_ENABLE_SNPRINTF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSNPRINTF
|
||||
#define SECUREC_ENABLE_VSNPRINTF 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef SECUREC_ENABLE_MEMMOVE
|
||||
#define SECUREC_ENABLE_MEMMOVE 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_MEMCPY
|
||||
#define SECUREC_ENABLE_MEMCPY 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRCPY
|
||||
#define SECUREC_ENABLE_STRCPY 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRNCPY
|
||||
#define SECUREC_ENABLE_STRNCPY 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRCAT
|
||||
#define SECUREC_ENABLE_STRCAT 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRNCAT
|
||||
#define SECUREC_ENABLE_STRNCAT 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SPRINTF
|
||||
#define SECUREC_ENABLE_SPRINTF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSPRINTF
|
||||
#define SECUREC_ENABLE_VSPRINTF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SSCANF
|
||||
#define SECUREC_ENABLE_SSCANF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSSCANF
|
||||
#define SECUREC_ENABLE_VSSCANF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SCANF
|
||||
#define SECUREC_ENABLE_SCANF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSCANF
|
||||
#define SECUREC_ENABLE_VSCANF 0
|
||||
#endif
|
||||
|
||||
#ifndef SECUREC_ENABLE_FSCANF
|
||||
#define SECUREC_ENABLE_FSCANF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VFSCANF
|
||||
#define SECUREC_ENABLE_VFSCANF 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRTOK
|
||||
#define SECUREC_ENABLE_STRTOK 0
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_GETS
|
||||
#define SECUREC_ENABLE_GETS 0
|
||||
#endif
|
||||
|
||||
#else /* SECUREC USE STD SECURE LIB */
|
||||
|
||||
#ifndef SECUREC_ENABLE_MEMSET
|
||||
#define SECUREC_ENABLE_MEMSET 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_MEMMOVE
|
||||
#define SECUREC_ENABLE_MEMMOVE 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_MEMCPY
|
||||
#define SECUREC_ENABLE_MEMCPY 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRCPY
|
||||
#define SECUREC_ENABLE_STRCPY 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRNCPY
|
||||
#define SECUREC_ENABLE_STRNCPY 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRCAT
|
||||
#define SECUREC_ENABLE_STRCAT 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_STRNCAT
|
||||
#define SECUREC_ENABLE_STRNCAT 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SPRINTF
|
||||
#define SECUREC_ENABLE_SPRINTF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSPRINTF
|
||||
#define SECUREC_ENABLE_VSPRINTF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SNPRINTF
|
||||
#define SECUREC_ENABLE_SNPRINTF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSNPRINTF
|
||||
#define SECUREC_ENABLE_VSNPRINTF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SSCANF
|
||||
#define SECUREC_ENABLE_SSCANF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSSCANF
|
||||
#define SECUREC_ENABLE_VSSCANF 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_SCANF
|
||||
#if SECUREC_ENABLE_SCANF_FILE
|
||||
#define SECUREC_ENABLE_SCANF 1
|
||||
#else
|
||||
#define SECUREC_ENABLE_SCANF 0
|
||||
#endif
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VSCANF
|
||||
#if SECUREC_ENABLE_SCANF_FILE
|
||||
#define SECUREC_ENABLE_VSCANF 1
|
||||
#else
|
||||
#define SECUREC_ENABLE_VSCANF 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef SECUREC_ENABLE_FSCANF
|
||||
#if SECUREC_ENABLE_SCANF_FILE
|
||||
#define SECUREC_ENABLE_FSCANF 1
|
||||
#else
|
||||
#define SECUREC_ENABLE_FSCANF 0
|
||||
#endif
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_VFSCANF
|
||||
#if SECUREC_ENABLE_SCANF_FILE
|
||||
#define SECUREC_ENABLE_VFSCANF 1
|
||||
#else
|
||||
#define SECUREC_ENABLE_VFSCANF 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef SECUREC_ENABLE_STRTOK
|
||||
#define SECUREC_ENABLE_STRTOK 1
|
||||
#endif
|
||||
#ifndef SECUREC_ENABLE_GETS
|
||||
#define SECUREC_ENABLE_GETS 1
|
||||
#endif
|
||||
#endif /* SECUREC_USE_STD_SECURE_LIB */
|
||||
|
||||
#if !SECUREC_ENABLE_SCANF_FILE
|
||||
#if SECUREC_ENABLE_FSCANF
|
||||
#undef SECUREC_ENABLE_FSCANF
|
||||
#define SECUREC_ENABLE_FSCANF 0
|
||||
#endif
|
||||
#if SECUREC_ENABLE_VFSCANF
|
||||
#undef SECUREC_ENABLE_VFSCANF
|
||||
#define SECUREC_ENABLE_VFSCANF 0
|
||||
#endif
|
||||
#if SECUREC_ENABLE_SCANF
|
||||
#undef SECUREC_ENABLE_SCANF
|
||||
#define SECUREC_ENABLE_SCANF 0
|
||||
#endif
|
||||
#if SECUREC_ENABLE_FSCANF
|
||||
#undef SECUREC_ENABLE_FSCANF
|
||||
#define SECUREC_ENABLE_FSCANF 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if SECUREC_IN_KERNEL
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#else
|
||||
#ifndef SECUREC_HAVE_STDIO_H
|
||||
#define SECUREC_HAVE_STDIO_H 1
|
||||
#endif
|
||||
#ifndef SECUREC_HAVE_STRING_H
|
||||
#define SECUREC_HAVE_STRING_H 1
|
||||
#endif
|
||||
#ifndef SECUREC_HAVE_STDLIB_H
|
||||
#define SECUREC_HAVE_STDLIB_H 1
|
||||
#endif
|
||||
#if SECUREC_HAVE_STDIO_H
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#if SECUREC_HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#if SECUREC_HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If you need high performance, enable the SECUREC_WITH_PERFORMANCE_ADDONS macro, default is enable.
|
||||
* The macro is automatically closed on the windows platform and linux kernel
|
||||
*/
|
||||
#ifndef SECUREC_WITH_PERFORMANCE_ADDONS
|
||||
#if SECUREC_IN_KERNEL
|
||||
#define SECUREC_WITH_PERFORMANCE_ADDONS 0
|
||||
#else
|
||||
#define SECUREC_WITH_PERFORMANCE_ADDONS 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* If enable SECUREC_COMPATIBLE_WIN_FORMAT, the output format will be compatible to Windows. */
|
||||
#if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER)) && !defined(SECUREC_COMPATIBLE_LINUX_FORMAT)
|
||||
#ifndef SECUREC_COMPATIBLE_WIN_FORMAT
|
||||
#define SECUREC_COMPATIBLE_WIN_FORMAT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SECUREC_COMPATIBLE_WIN_FORMAT)
|
||||
/* On windows platform, can't use optimized function for there is no __builtin_constant_p like function */
|
||||
/* If need optimized macro, can define this: define __builtin_constant_p(x) 0 */
|
||||
#ifdef SECUREC_WITH_PERFORMANCE_ADDONS
|
||||
#undef SECUREC_WITH_PERFORMANCE_ADDONS
|
||||
#define SECUREC_WITH_PERFORMANCE_ADDONS 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__VXWORKS__) || defined(__vxworks) || defined(__VXWORKS) || defined(_VXWORKS_PLATFORM_) || \
|
||||
defined(SECUREC_VXWORKS_VERSION_5_4)
|
||||
#ifndef SECUREC_VXWORKS_PLATFORM
|
||||
#define SECUREC_VXWORKS_PLATFORM
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* If enable SECUREC_COMPATIBLE_LINUX_FORMAT, the output format will be compatible to Linux. */
|
||||
#if !defined(SECUREC_COMPATIBLE_WIN_FORMAT) && !defined(SECUREC_VXWORKS_PLATFORM)
|
||||
#ifndef SECUREC_COMPATIBLE_LINUX_FORMAT
|
||||
#define SECUREC_COMPATIBLE_LINUX_FORMAT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SECUREC_COMPATIBLE_LINUX_FORMAT
|
||||
#ifndef SECUREC_HAVE_STDDEF_H
|
||||
#define SECUREC_HAVE_STDDEF_H 1
|
||||
#endif
|
||||
/* Some system may no stddef.h */
|
||||
#if SECUREC_HAVE_STDDEF_H
|
||||
#if !SECUREC_IN_KERNEL
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Add the -DSECUREC_SUPPORT_FORMAT_WARNING=1 compiler option to supoort -Wformat=2.
|
||||
* Default does not check the format is that the same data type in the actual code.
|
||||
* In the product is different in the original data type definition of VxWorks and Linux.
|
||||
*/
|
||||
#ifndef SECUREC_SUPPORT_FORMAT_WARNING
|
||||
#define SECUREC_SUPPORT_FORMAT_WARNING 0
|
||||
#endif
|
||||
|
||||
#if SECUREC_SUPPORT_FORMAT_WARNING
|
||||
#define SECUREC_ATTRIBUTE(x, y) __attribute__((format(printf, (x), (y))))
|
||||
#else
|
||||
#define SECUREC_ATTRIBUTE(x, y)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Add the -DSECUREC_SUPPORT_BUILTIN_EXPECT=0 compiler option, if compiler can not support __builtin_expect.
|
||||
*/
|
||||
#ifndef SECUREC_SUPPORT_BUILTIN_EXPECT
|
||||
#define SECUREC_SUPPORT_BUILTIN_EXPECT 1
|
||||
#endif
|
||||
|
||||
#if SECUREC_SUPPORT_BUILTIN_EXPECT && defined(__GNUC__) && ((__GNUC__ > 3) || \
|
||||
(defined(__GNUC_MINOR__) && (__GNUC__ == 3 && __GNUC_MINOR__ > 3)))
|
||||
/*
|
||||
* This is a built-in function that can be used without a declaration, if warning for declaration not found occurred,
|
||||
* you can add -DSECUREC_NEED_BUILTIN_EXPECT_DECLARE to compiler options
|
||||
*/
|
||||
#ifdef SECUREC_NEED_BUILTIN_EXPECT_DECLARE
|
||||
long __builtin_expect(long exp, long c);
|
||||
#endif
|
||||
|
||||
#define SECUREC_LIKELY(x) __builtin_expect(!!(x), 1)
|
||||
#define SECUREC_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
#else
|
||||
#define SECUREC_LIKELY(x) (x)
|
||||
#define SECUREC_UNLIKELY(x) (x)
|
||||
#endif
|
||||
|
||||
/* Define the max length of the string */
|
||||
#ifndef SECUREC_STRING_MAX_LEN
|
||||
#define SECUREC_STRING_MAX_LEN 0x7fffffffUL
|
||||
#endif
|
||||
#define SECUREC_WCHAR_STRING_MAX_LEN (SECUREC_STRING_MAX_LEN / sizeof(wchar_t))
|
||||
|
||||
/* Add SECUREC_MEM_MAX_LEN for memcpy and memmove */
|
||||
#ifndef SECUREC_MEM_MAX_LEN
|
||||
#define SECUREC_MEM_MAX_LEN 0x7fffffffUL
|
||||
#endif
|
||||
#define SECUREC_WCHAR_MEM_MAX_LEN (SECUREC_MEM_MAX_LEN / sizeof(wchar_t))
|
||||
|
||||
#if SECUREC_STRING_MAX_LEN > 0x7fffffffUL
|
||||
#error "max string is 2G"
|
||||
#endif
|
||||
|
||||
#if (defined(__GNUC__) && defined(__SIZEOF_POINTER__))
|
||||
#if (__SIZEOF_POINTER__ != 4) && (__SIZEOF_POINTER__ != 8)
|
||||
#error "unsupported system"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_WIN64) || defined(WIN64) || defined(__LP64__) || defined(_LP64)
|
||||
#define SECUREC_ON_64BITS
|
||||
#endif
|
||||
|
||||
#if (!defined(SECUREC_ON_64BITS) && defined(__GNUC__) && defined(__SIZEOF_POINTER__))
|
||||
#if __SIZEOF_POINTER__ == 8
|
||||
#define SECUREC_ON_64BITS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__SVR4) || defined(__svr4__)
|
||||
#define SECUREC_ON_SOLARIS
|
||||
#endif
|
||||
|
||||
#if (defined(__hpux) || defined(_AIX) || defined(SECUREC_ON_SOLARIS))
|
||||
#define SECUREC_ON_UNIX
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Codes should run under the macro SECUREC_COMPATIBLE_LINUX_FORMAT in unknown system on default,
|
||||
* and strtold.
|
||||
* The function strtold is referenced first at ISO9899:1999(C99), and some old compilers can
|
||||
* not support these functions. Here provides a macro to open these functions:
|
||||
* SECUREC_SUPPORT_STRTOLD -- If defined, strtold will be used
|
||||
*/
|
||||
#ifndef SECUREC_SUPPORT_STRTOLD
|
||||
#define SECUREC_SUPPORT_STRTOLD 0
|
||||
#if (defined(SECUREC_COMPATIBLE_LINUX_FORMAT))
|
||||
#if defined(__USE_ISOC99) || \
|
||||
(defined(_AIX) && defined(_ISOC99_SOURCE)) || \
|
||||
(defined(__hpux) && defined(__ia64)) || \
|
||||
(defined(SECUREC_ON_SOLARIS) && (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
|
||||
defined(_STDC_C99) || defined(__EXTENSIONS__))
|
||||
#undef SECUREC_SUPPORT_STRTOLD
|
||||
#define SECUREC_SUPPORT_STRTOLD 1
|
||||
#endif
|
||||
#endif
|
||||
#if ((defined(SECUREC_WRLINUX_BELOW4) || defined(_WRLINUX_BELOW4_)))
|
||||
#undef SECUREC_SUPPORT_STRTOLD
|
||||
#define SECUREC_SUPPORT_STRTOLD 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SECUREC_WITH_PERFORMANCE_ADDONS
|
||||
|
||||
#ifndef SECUREC_TWO_MIN
|
||||
#define SECUREC_TWO_MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
/* For strncpy_s performance optimization */
|
||||
#define SECUREC_STRNCPY_SM(dest, destMax, src, count) \
|
||||
(((void *)(dest) != NULL && (const void *)(src) != NULL && (size_t)(destMax) > 0 && \
|
||||
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
|
||||
(SECUREC_TWO_MIN((size_t)(count), strlen(src)) + 1) <= (size_t)(destMax)) ? \
|
||||
(((size_t)(count) < strlen(src)) ? (memcpy((dest), (src), (count)), *((char *)(dest) + (count)) = '\0', EOK) : \
|
||||
(memcpy((dest), (src), strlen(src) + 1), EOK)) : (strncpy_error((dest), (destMax), (src), (count))))
|
||||
|
||||
#define SECUREC_STRCPY_SM(dest, destMax, src) \
|
||||
(((void *)(dest) != NULL && (const void *)(src) != NULL && (size_t)(destMax) > 0 && \
|
||||
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
|
||||
(strlen(src) + 1) <= (size_t)(destMax)) ? (memcpy((dest), (src), strlen(src) + 1), EOK) : \
|
||||
(strcpy_error((dest), (destMax), (src))))
|
||||
|
||||
/* For strcat_s performance optimization */
|
||||
#if defined(__GNUC__)
|
||||
#define SECUREC_STRCAT_SM(dest, destMax, src) ({ \
|
||||
int catRet_ = EOK; \
|
||||
if ((void *)(dest) != NULL && (const void *)(src) != NULL && (size_t)(destMax) > 0 && \
|
||||
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \
|
||||
char *catTmpDst_ = (char *)(dest); \
|
||||
size_t catRestSize_ = (destMax); \
|
||||
while (catRestSize_ > 0 && *catTmpDst_ != '\0') { \
|
||||
++catTmpDst_; \
|
||||
--catRestSize_; \
|
||||
} \
|
||||
if (catRestSize_ == 0) { \
|
||||
catRet_ = EINVAL; \
|
||||
} else if ((strlen(src) + 1) <= catRestSize_) { \
|
||||
memcpy(catTmpDst_, (src), strlen(src) + 1); \
|
||||
catRet_ = EOK; \
|
||||
} else { \
|
||||
catRet_ = ERANGE; \
|
||||
} \
|
||||
if (catRet_ != EOK) { \
|
||||
catRet_ = strcat_s((dest), (destMax), (src)); \
|
||||
} \
|
||||
} else { \
|
||||
catRet_ = strcat_s((dest), (destMax), (src)); \
|
||||
} \
|
||||
catRet_; \
|
||||
})
|
||||
#else
|
||||
#define SECUREC_STRCAT_SM(dest, destMax, src) strcat_s((dest), (destMax), (src))
|
||||
#endif
|
||||
|
||||
/* For strncat_s performance optimization */
|
||||
#if defined(__GNUC__)
|
||||
#define SECUREC_STRNCAT_SM(dest, destMax, src, count) ({ \
|
||||
int ncatRet_ = EOK; \
|
||||
if ((void *)(dest) != NULL && (const void *)(src) != NULL && (size_t)(destMax) > 0 && \
|
||||
(((unsigned long long)(destMax) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN) && \
|
||||
(((unsigned long long)(count) & (unsigned long long)(-2)) < SECUREC_STRING_MAX_LEN)) { \
|
||||
char *ncatTmpDest_ = (char *)(dest); \
|
||||
size_t ncatRestSize_ = (size_t)(destMax); \
|
||||
while (ncatRestSize_ > 0 && *ncatTmpDest_ != '\0') { \
|
||||
++ncatTmpDest_; \
|
||||
--ncatRestSize_; \
|
||||
} \
|
||||
if (ncatRestSize_ == 0) { \
|
||||
ncatRet_ = EINVAL; \
|
||||
} else if ((SECUREC_TWO_MIN((count), strlen(src)) + 1) <= ncatRestSize_) { \
|
||||
if ((size_t)(count) < strlen(src)) { \
|
||||
memcpy(ncatTmpDest_, (src), (count)); \
|
||||
*(ncatTmpDest_ + (count)) = '\0'; \
|
||||
} else { \
|
||||
memcpy(ncatTmpDest_, (src), strlen(src) + 1); \
|
||||
} \
|
||||
} else { \
|
||||
ncatRet_ = ERANGE; \
|
||||
} \
|
||||
if (ncatRet_ != EOK) { \
|
||||
ncatRet_ = strncat_s((dest), (destMax), (src), (count)); \
|
||||
} \
|
||||
} else { \
|
||||
ncatRet_ = strncat_s((dest), (destMax), (src), (count)); \
|
||||
} \
|
||||
ncatRet_; \
|
||||
})
|
||||
#else
|
||||
#define SECUREC_STRNCAT_SM(dest, destMax, src, count) strncat_s((dest), (destMax), (src), (count))
|
||||
#endif
|
||||
|
||||
/* This macro do not check buffer overlap by default */
|
||||
#define SECUREC_MEMCPY_SM(dest, destMax, src, count) \
|
||||
(!(((size_t)(destMax) == 0) || \
|
||||
(((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \
|
||||
((size_t)(count) > (size_t)(destMax)) || ((void *)(dest)) == NULL || ((const void *)(src) == NULL)) ? \
|
||||
(memcpy((dest), (src), (count)), EOK) : \
|
||||
(memcpy_s((dest), (destMax), (src), (count))))
|
||||
|
||||
#define SECUREC_MEMSET_SM(dest, destMax, c, count) \
|
||||
(!((((unsigned long long)(destMax) & (unsigned long long)(-2)) > SECUREC_MEM_MAX_LEN) || \
|
||||
((void *)(dest) == NULL) || ((size_t)(count) > (size_t)(destMax))) ? \
|
||||
(memset((dest), (c), (count)), EOK) : \
|
||||
(memset_s((dest), (destMax), (c), (count))))
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
|
||||
#ifndef __STEP_H_
|
||||
#define __STEP_H_
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ifdef CONFIG_LOTUS_EDA
|
||||
#ifdef __ASSEMBLY__
|
||||
|
||||
.macro step, num
|
||||
push {r11, r12}
|
||||
|
||||
ldr r11, = SYS_CTRL_REG_BASE
|
||||
mov r12, #\num
|
||||
str r12, [r11, #REG_SC_SYSBOOT2]
|
||||
|
||||
pop {r11, r12}
|
||||
.endm
|
||||
|
||||
.macro step_no_stack, num, tmp_reg1, tmp_reg2
|
||||
ldr \tmp_reg1, = SYS_CTRL_REG_BASE
|
||||
mov \tmp_reg2, #\num
|
||||
str \tmp_reg2, [\tmp_reg1, #REG_SC_SYSBOOT2]
|
||||
.endm
|
||||
|
||||
#else
|
||||
#define step(x) ((*(volatile u32 *) (SYS_CTRL_REG_BASE + REG_SC_SYSBOOT2)) = (x))
|
||||
#endif
|
||||
#else
|
||||
#ifdef __ASSEMBLY__
|
||||
.macro step, num
|
||||
.endm
|
||||
.macro step_no_stack, num, tmp_reg1, tmp_reg2
|
||||
.endm
|
||||
#else
|
||||
#define step(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /*__STEP_H_*/
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
/******************************************************************************
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*
|
||||
* File: param_atags.h
|
||||
*
|
||||
* Author: Lynn
|
||||
* Created: 12/07/22
|
||||
* Description: Param tag API and data structure
|
||||
*****************************************************************************/
|
||||
#ifndef _PARAM_ATAGS_H
|
||||
#define _PARAM_ATAGS_H
|
||||
|
||||
#include <asm/setup.h>
|
||||
|
||||
void set_param_data(const char *name, const char *buf, int buflen);
|
||||
int get_param_tag_data(char *tagbuf);
|
||||
|
||||
void setup_atags(char *fdt, int fdt_size);
|
||||
void setup_board_tags(struct tag **in_params);
|
||||
|
||||
#endif /* _PARAM_ATAGS_H */
|
||||
@@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
#ifndef __LOTUS_TIMESTAMP_H__
|
||||
#define __LOTUS_TIMESTAMP_H__
|
||||
|
||||
#include <config.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
|
||||
typedef u64 timestamp_type;
|
||||
|
||||
/*
|
||||
* timestamps storage arrangement
|
||||
* |-----Timestamp Item----|-----Timestamp Item----| ...
|
||||
* |stamp|func |line |type |stamp|func |line |type | ...
|
||||
*/
|
||||
#pragma pack(4)
|
||||
typedef struct {
|
||||
timestamp_type stamp;
|
||||
char *func;
|
||||
u32 line;
|
||||
u32 type;
|
||||
} timestamp_item;
|
||||
#pragma pack()
|
||||
|
||||
#define TIME_STAMP(type) timestamp_mark(__func__, __LINE__, type)
|
||||
|
||||
void timestamp_mark(const char *func, u32 line, u32 type);
|
||||
void timestamp_print(u32 type);
|
||||
void timestamp_clear(void);
|
||||
|
||||
void stopwatch_trigger(void);
|
||||
void stopwatch_clear(void);
|
||||
void stopwatch_print(void);
|
||||
#endif /* __LOTUS_TIMESTAMP_H__ */
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) LOTUS. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef USB_VENDOR_H
|
||||
#define USB_VENDOR_H
|
||||
|
||||
enum usb_init_types {
|
||||
LOTUS_DWC_U3 = 0, /* usb3 controller is default */
|
||||
LOTUS_DWC_U2 = 1, /* usb2 controller */
|
||||
LOTUS_USB_CTRL_UNKNOWN = 2, /* unknown controller */
|
||||
};
|
||||
|
||||
#ifdef CONFIG_USB_DUAL_PORT_SUPPORT
|
||||
void phy_usb_init(int index, int type);
|
||||
#else
|
||||
void phy_usb_init(int index);
|
||||
#endif
|
||||
void udc_connect(void);
|
||||
void udc_puts(const char *s);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef __LZO_H__
|
||||
#define __LZO_H__
|
||||
/*
|
||||
* LZO Public Kernel Interface
|
||||
* A mini subset of the LZO real-time data compression library
|
||||
*
|
||||
* Copyright (C) 1996-2005 Markus F.X.J. Oberhumer <markus@oberhumer.com>
|
||||
*
|
||||
* The full LZO package can be found at:
|
||||
* http://www.oberhumer.com/opensource/lzo/
|
||||
*
|
||||
* Changed for kernel use by:
|
||||
* Nitin Gupta <nitingupta910@gmail.com>
|
||||
* Richard Purdie <rpurdie@openedhand.com>
|
||||
*/
|
||||
|
||||
#define LZO1X_MEM_COMPRESS (16384 * sizeof(unsigned char *))
|
||||
#define LZO1X_1_MEM_COMPRESS LZO1X_MEM_COMPRESS
|
||||
|
||||
#define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)
|
||||
|
||||
/* This requires 'workmem' of size LZO1X_1_MEM_COMPRESS */
|
||||
int lzo1x_1_compress(const unsigned char *src, size_t src_len,
|
||||
unsigned char *dst, size_t *dst_len, void *wrkmem);
|
||||
|
||||
/* safe decompression with overrun testing */
|
||||
int lzo1x_decompress_safe(const unsigned char *src, size_t src_len,
|
||||
unsigned char *dst, size_t *dst_len);
|
||||
|
||||
/* decompress lzop format */
|
||||
int lzop_decompress(const unsigned char *src, size_t src_len,
|
||||
unsigned char *dst, size_t *dst_len);
|
||||
|
||||
/* check if the header is valid (based on magic numbers) */
|
||||
bool lzop_is_valid_header(const unsigned char *src);
|
||||
|
||||
/*
|
||||
* Return values (< 0 = Error)
|
||||
*/
|
||||
#define LZO_E_OK 0
|
||||
#define LZO_E_ERROR (-1)
|
||||
#define LZO_E_OUT_OF_MEMORY (-2)
|
||||
#define LZO_E_NOT_COMPRESSIBLE (-3)
|
||||
#define LZO_E_INPUT_OVERRUN (-4)
|
||||
#define LZO_E_OUTPUT_OVERRUN (-5)
|
||||
#define LZO_E_LOOKBEHIND_OVERRUN (-6)
|
||||
#define LZO_E_EOF_NOT_FOUND (-7)
|
||||
#define LZO_E_INPUT_NOT_CONSUMED (-8)
|
||||
#define LZO_E_NOT_YET_IMPLEMENTED (-9)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,257 @@
|
||||
#ifndef _LINUX_MATH64_H
|
||||
#define _LINUX_MATH64_H
|
||||
|
||||
#include <div64.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
#if BITS_PER_LONG == 64
|
||||
|
||||
#define div64_long(x, y) div64_s64((x), (y))
|
||||
#define div64_ul(x, y) div64_u64((x), (y))
|
||||
|
||||
/**
|
||||
* div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder
|
||||
*
|
||||
* This is commonly provided by 32bit archs to provide an optimized 64bit
|
||||
* divide.
|
||||
*/
|
||||
static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
|
||||
{
|
||||
*remainder = dividend % divisor;
|
||||
return dividend / divisor;
|
||||
}
|
||||
|
||||
/**
|
||||
* div_s64_rem - signed 64bit divide with 32bit divisor with remainder
|
||||
*/
|
||||
static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
|
||||
{
|
||||
*remainder = dividend % divisor;
|
||||
return dividend / divisor;
|
||||
}
|
||||
|
||||
/**
|
||||
* div64_u64_rem - unsigned 64bit divide with 64bit divisor and remainder
|
||||
*/
|
||||
static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
|
||||
{
|
||||
*remainder = dividend % divisor;
|
||||
return dividend / divisor;
|
||||
}
|
||||
|
||||
/**
|
||||
* div64_u64 - unsigned 64bit divide with 64bit divisor
|
||||
*/
|
||||
static inline u64 div64_u64(u64 dividend, u64 divisor)
|
||||
{
|
||||
return dividend / divisor;
|
||||
}
|
||||
|
||||
/**
|
||||
* div64_s64 - signed 64bit divide with 64bit divisor
|
||||
*/
|
||||
static inline s64 div64_s64(s64 dividend, s64 divisor)
|
||||
{
|
||||
return dividend / divisor;
|
||||
}
|
||||
|
||||
#elif BITS_PER_LONG == 32
|
||||
|
||||
#define div64_long(x, y) div_s64((x), (y))
|
||||
#define div64_ul(x, y) div_u64((x), (y))
|
||||
|
||||
#ifndef div_u64_rem
|
||||
static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
|
||||
{
|
||||
*remainder = do_div(dividend, divisor);
|
||||
return dividend;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef div_s64_rem
|
||||
extern s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder);
|
||||
#endif
|
||||
|
||||
#ifndef div64_u64_rem
|
||||
extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
|
||||
#endif
|
||||
|
||||
#ifndef div64_u64
|
||||
extern u64 div64_u64(u64 dividend, u64 divisor);
|
||||
#endif
|
||||
|
||||
#ifndef div64_s64
|
||||
extern s64 div64_s64(s64 dividend, s64 divisor);
|
||||
#endif
|
||||
|
||||
#endif /* BITS_PER_LONG */
|
||||
|
||||
/**
|
||||
* div_u64 - unsigned 64bit divide with 32bit divisor
|
||||
*
|
||||
* This is the most common 64bit divide and should be used if possible,
|
||||
* as many 32bit archs can optimize this variant better than a full 64bit
|
||||
* divide.
|
||||
*/
|
||||
#ifndef div_u64
|
||||
static inline u64 div_u64(u64 dividend, u32 divisor)
|
||||
{
|
||||
u32 remainder;
|
||||
return div_u64_rem(dividend, divisor, &remainder);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* div_s64 - signed 64bit divide with 32bit divisor
|
||||
*/
|
||||
#ifndef div_s64
|
||||
static inline s64 div_s64(s64 dividend, s32 divisor)
|
||||
{
|
||||
s32 remainder;
|
||||
return div_s64_rem(dividend, divisor, &remainder);
|
||||
}
|
||||
#endif
|
||||
|
||||
u32 iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder);
|
||||
|
||||
static __always_inline u32
|
||||
__iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder)
|
||||
{
|
||||
u32 ret = 0;
|
||||
|
||||
while (dividend >= divisor) {
|
||||
/* The following asm() prevents the compiler from
|
||||
optimising this loop into a modulo operation. */
|
||||
asm("" : "+rm"(dividend));
|
||||
|
||||
dividend -= divisor;
|
||||
ret++;
|
||||
}
|
||||
|
||||
*remainder = dividend;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef mul_u32_u32
|
||||
/*
|
||||
* Many a GCC version messes this up and generates a 64x64 mult :-(
|
||||
*/
|
||||
static inline u64 mul_u32_u32(u32 a, u32 b)
|
||||
{
|
||||
return (u64)a * b;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__)
|
||||
|
||||
#ifndef mul_u64_u32_shr
|
||||
static inline u64 mul_u64_u32_shr(u64 a, u32 mul, unsigned int shift)
|
||||
{
|
||||
return (u64)(((unsigned __int128)a * mul) >> shift);
|
||||
}
|
||||
#endif /* mul_u64_u32_shr */
|
||||
|
||||
#ifndef mul_u64_u64_shr
|
||||
static inline u64 mul_u64_u64_shr(u64 a, u64 mul, unsigned int shift)
|
||||
{
|
||||
return (u64)(((unsigned __int128)a * mul) >> shift);
|
||||
}
|
||||
#endif /* mul_u64_u64_shr */
|
||||
|
||||
#else
|
||||
|
||||
#ifndef mul_u64_u32_shr
|
||||
static inline u64 mul_u64_u32_shr(u64 a, u32 mul, unsigned int shift)
|
||||
{
|
||||
u32 ah, al;
|
||||
u64 ret;
|
||||
|
||||
al = a;
|
||||
ah = a >> 32;
|
||||
|
||||
ret = mul_u32_u32(al, mul) >> shift;
|
||||
if (ah)
|
||||
ret += mul_u32_u32(ah, mul) << (32 - shift);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* mul_u64_u32_shr */
|
||||
|
||||
#ifndef mul_u64_u64_shr
|
||||
static inline u64 mul_u64_u64_shr(u64 a, u64 b, unsigned int shift)
|
||||
{
|
||||
union {
|
||||
u64 ll;
|
||||
struct {
|
||||
#ifdef __BIG_ENDIAN
|
||||
u32 high, low;
|
||||
#else
|
||||
u32 low, high;
|
||||
#endif
|
||||
} l;
|
||||
} rl, rm, rn, rh, a0, b0;
|
||||
u64 c;
|
||||
|
||||
a0.ll = a;
|
||||
b0.ll = b;
|
||||
|
||||
rl.ll = mul_u32_u32(a0.l.low, b0.l.low);
|
||||
rm.ll = mul_u32_u32(a0.l.low, b0.l.high);
|
||||
rn.ll = mul_u32_u32(a0.l.high, b0.l.low);
|
||||
rh.ll = mul_u32_u32(a0.l.high, b0.l.high);
|
||||
|
||||
/*
|
||||
* Each of these lines computes a 64-bit intermediate result into "c",
|
||||
* starting at bits 32-95. The low 32-bits go into the result of the
|
||||
* multiplication, the high 32-bits are carried into the next step.
|
||||
*/
|
||||
rl.l.high = c = (u64)rl.l.high + rm.l.low + rn.l.low;
|
||||
rh.l.low = c = (c >> 32) + rm.l.high + rn.l.high + rh.l.low;
|
||||
rh.l.high = (c >> 32) + rh.l.high;
|
||||
|
||||
/*
|
||||
* The 128-bit result of the multiplication is in rl.ll and rh.ll,
|
||||
* shift it right and throw away the high part of the result.
|
||||
*/
|
||||
if (shift == 0)
|
||||
return rl.ll;
|
||||
if (shift < 64)
|
||||
return (rl.ll >> shift) | (rh.ll << (64 - shift));
|
||||
return rh.ll >> (shift & 63);
|
||||
}
|
||||
#endif /* mul_u64_u64_shr */
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef mul_u64_u32_div
|
||||
static inline u64 mul_u64_u32_div(u64 a, u32 mul, u32 divisor)
|
||||
{
|
||||
union {
|
||||
u64 ll;
|
||||
struct {
|
||||
#ifdef __BIG_ENDIAN
|
||||
u32 high, low;
|
||||
#else
|
||||
u32 low, high;
|
||||
#endif
|
||||
} l;
|
||||
} u, rl, rh;
|
||||
|
||||
u.ll = a;
|
||||
rl.ll = mul_u32_u32(u.l.low, mul);
|
||||
rh.ll = mul_u32_u32(u.l.high, mul) + rl.l.high;
|
||||
|
||||
/* Bits 32-63 of the result will be in rh.l.low. */
|
||||
rl.l.high = do_div(rh.ll, divisor);
|
||||
|
||||
/* Bits 0-31 of the result will be in rl.l.low. */
|
||||
do_div(rl.ll, divisor);
|
||||
|
||||
rl.l.high = rh.l.low;
|
||||
return rl.ll;
|
||||
}
|
||||
#endif /* mul_u64_u32_div */
|
||||
|
||||
#endif /* _LINUX_MATH64_H */
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Marvell MBUS common definitions.
|
||||
*
|
||||
* Copyright (C) 2008 Marvell Semiconductor
|
||||
*
|
||||
* This file is licensed under the terms of the GNU General Public
|
||||
* License version 2. This program is licensed "as is" without any
|
||||
* warranty of any kind, whether express or implied.
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_MBUS_H
|
||||
#define __LINUX_MBUS_H
|
||||
|
||||
struct resource;
|
||||
|
||||
struct mbus_dram_target_info {
|
||||
/*
|
||||
* The 4-bit MBUS target ID of the DRAM controller.
|
||||
*/
|
||||
u8 mbus_dram_target_id;
|
||||
|
||||
/*
|
||||
* The base address, size, and MBUS attribute ID for each
|
||||
* of the possible DRAM chip selects. Peripherals are
|
||||
* required to support at least 4 decode windows.
|
||||
*/
|
||||
int num_cs;
|
||||
struct mbus_dram_window {
|
||||
u8 cs_index;
|
||||
u8 mbus_attr;
|
||||
u32 base;
|
||||
u32 size;
|
||||
} cs[4];
|
||||
};
|
||||
|
||||
struct mvebu_mbus_state {
|
||||
void __iomem *mbuswins_base;
|
||||
void __iomem *sdramwins_base;
|
||||
struct dentry *debugfs_root;
|
||||
struct dentry *debugfs_sdram;
|
||||
struct dentry *debugfs_devs;
|
||||
const struct mvebu_mbus_soc_data *soc;
|
||||
int hw_io_coherency;
|
||||
};
|
||||
|
||||
/* Flags for PCI/PCIe address decoding regions */
|
||||
#define MVEBU_MBUS_PCI_IO 0x1
|
||||
#define MVEBU_MBUS_PCI_MEM 0x2
|
||||
#define MVEBU_MBUS_PCI_WA 0x3
|
||||
|
||||
/*
|
||||
* Magic value that explicits that we don't need a remapping-capable
|
||||
* address decoding window.
|
||||
*/
|
||||
#define MVEBU_MBUS_NO_REMAP (0xffffffff)
|
||||
|
||||
/* Maximum size of a mbus window name */
|
||||
#define MVEBU_MBUS_MAX_WINNAME_SZ 32
|
||||
|
||||
const struct mbus_dram_target_info *mvebu_mbus_dram_info(void);
|
||||
void mvebu_mbus_get_pcie_mem_aperture(struct resource *res);
|
||||
void mvebu_mbus_get_pcie_io_aperture(struct resource *res);
|
||||
int mvebu_mbus_add_window_remap_by_id(unsigned int target,
|
||||
unsigned int attribute,
|
||||
phys_addr_t base, size_t size,
|
||||
phys_addr_t remap);
|
||||
int mvebu_mbus_add_window_by_id(unsigned int target, unsigned int attribute,
|
||||
phys_addr_t base, size_t size);
|
||||
int mvebu_mbus_del_window(phys_addr_t base, size_t size);
|
||||
int mbus_dt_setup_win(struct mvebu_mbus_state *mbus,
|
||||
u32 base, u32 size, u8 target, u8 attr);
|
||||
|
||||
#endif /* __LINUX_MBUS_H */
|
||||
@@ -0,0 +1,86 @@
|
||||
/* mc146818rtc.h - register definitions for the Real-Time-Clock / CMOS RAM
|
||||
* Copyright Torsten Duwe <duwe@informatik.uni-erlangen.de> 1993
|
||||
* derived from Data Sheet, Copyright Motorola 1984 (!).
|
||||
* It was written to be part of the Linux operating system.
|
||||
*/
|
||||
/* permission is hereby granted to copy, modify and redistribute this code
|
||||
* in terms of the GNU Library General Public License, Version 2 or later,
|
||||
* at your option.
|
||||
*/
|
||||
|
||||
#ifndef _MC146818RTC_H
|
||||
#define _MC146818RTC_H
|
||||
|
||||
#include <asm/io.h>
|
||||
#include <linux/rtc.h> /* get the user-level API */
|
||||
#include <asm/mc146818rtc.h> /* register access macros */
|
||||
|
||||
/**********************************************************************
|
||||
* register summary
|
||||
**********************************************************************/
|
||||
#define RTC_SECONDS 0
|
||||
#define RTC_SECONDS_ALARM 1
|
||||
#define RTC_MINUTES 2
|
||||
#define RTC_MINUTES_ALARM 3
|
||||
#define RTC_HOURS 4
|
||||
#define RTC_HOURS_ALARM 5
|
||||
/* RTC_*_alarm is always true if 2 MSBs are set */
|
||||
# define RTC_ALARM_DONT_CARE 0xC0
|
||||
|
||||
#define RTC_DAY_OF_WEEK 6
|
||||
#define RTC_DAY_OF_MONTH 7
|
||||
#define RTC_MONTH 8
|
||||
#define RTC_YEAR 9
|
||||
|
||||
/* control registers - Moto names
|
||||
*/
|
||||
#define RTC_REG_A 10
|
||||
#define RTC_REG_B 11
|
||||
#define RTC_REG_C 12
|
||||
#define RTC_REG_D 13
|
||||
|
||||
/**********************************************************************
|
||||
* register details
|
||||
**********************************************************************/
|
||||
#define RTC_FREQ_SELECT RTC_REG_A
|
||||
|
||||
/* update-in-progress - set to "1" 244 microsecs before RTC goes off the bus,
|
||||
* reset after update (may take 1.984ms @ 32768Hz RefClock) is complete,
|
||||
* totalling to a max high interval of 2.228 ms.
|
||||
*/
|
||||
# define RTC_UIP 0x80
|
||||
# define RTC_DIV_CTL 0x70
|
||||
/* divider control: refclock values 4.194 / 1.049 MHz / 32.768 kHz */
|
||||
# define RTC_REF_CLCK_4MHZ 0x00
|
||||
# define RTC_REF_CLCK_1MHZ 0x10
|
||||
# define RTC_REF_CLCK_32KHZ 0x20
|
||||
/* 2 values for divider stage reset, others for "testing purposes only" */
|
||||
# define RTC_DIV_RESET1 0x60
|
||||
# define RTC_DIV_RESET2 0x70
|
||||
/* Periodic intr. / Square wave rate select. 0=none, 1=32.8kHz,... 15=2Hz */
|
||||
# define RTC_RATE_SELECT 0x0F
|
||||
|
||||
/**********************************************************************/
|
||||
#define RTC_CONTROL RTC_REG_B
|
||||
# define RTC_SET 0x80 /* disable updates for clock setting */
|
||||
# define RTC_PIE 0x40 /* periodic interrupt enable */
|
||||
# define RTC_AIE 0x20 /* alarm interrupt enable */
|
||||
# define RTC_UIE 0x10 /* update-finished interrupt enable */
|
||||
# define RTC_SQWE 0x08 /* enable square-wave output */
|
||||
# define RTC_DM_BINARY 0x04 /* all time/date values are BCD if clear */
|
||||
# define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */
|
||||
# define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */
|
||||
|
||||
/**********************************************************************/
|
||||
#define RTC_INTR_FLAGS RTC_REG_C
|
||||
/* caution - cleared by read */
|
||||
# define RTC_IRQF 0x80 /* any of the following 3 is active */
|
||||
# define RTC_PF 0x40
|
||||
# define RTC_AF 0x20
|
||||
# define RTC_UF 0x10
|
||||
|
||||
/**********************************************************************/
|
||||
#define RTC_VALID RTC_REG_D
|
||||
# define RTC_VRT 0x80 /* valid RAM and time */
|
||||
/**********************************************************************/
|
||||
#endif /* _MC146818RTC_H */
|
||||
@@ -0,0 +1,310 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
||||
/*
|
||||
* linux/mdio.h: definitions for MDIO (clause 45) transceivers
|
||||
* Copyright 2006-2009 Solarflare Communications Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 as published
|
||||
* by the Free Software Foundation, incorporated herein by reference.
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_MDIO_H__
|
||||
#define __LINUX_MDIO_H__
|
||||
|
||||
#include <linux/mii.h>
|
||||
|
||||
/* MDIO Manageable Devices (MMDs). */
|
||||
#define MDIO_MMD_PMAPMD 1 /* Physical Medium Attachment/
|
||||
* Physical Medium Dependent */
|
||||
#define MDIO_MMD_WIS 2 /* WAN Interface Sublayer */
|
||||
#define MDIO_MMD_PCS 3 /* Physical Coding Sublayer */
|
||||
#define MDIO_MMD_PHYXS 4 /* PHY Extender Sublayer */
|
||||
#define MDIO_MMD_DTEXS 5 /* DTE Extender Sublayer */
|
||||
#define MDIO_MMD_TC 6 /* Transmission Convergence */
|
||||
#define MDIO_MMD_AN 7 /* Auto-Negotiation */
|
||||
#define MDIO_MMD_C22EXT 29 /* Clause 22 extension */
|
||||
#define MDIO_MMD_VEND1 30 /* Vendor specific 1 */
|
||||
#define MDIO_MMD_VEND2 31 /* Vendor specific 2 */
|
||||
|
||||
/* Generic MDIO registers. */
|
||||
#define MDIO_CTRL1 MII_BMCR
|
||||
#define MDIO_STAT1 MII_BMSR
|
||||
#define MDIO_DEVID1 MII_PHYSID1
|
||||
#define MDIO_DEVID2 MII_PHYSID2
|
||||
#define MDIO_SPEED 4 /* Speed ability */
|
||||
#define MDIO_DEVS1 5 /* Devices in package */
|
||||
#define MDIO_DEVS2 6
|
||||
#define MDIO_CTRL2 7 /* 10G control 2 */
|
||||
#define MDIO_STAT2 8 /* 10G status 2 */
|
||||
#define MDIO_PMA_TXDIS 9 /* 10G PMA/PMD transmit disable */
|
||||
#define MDIO_PMA_RXDET 10 /* 10G PMA/PMD receive signal detect */
|
||||
#define MDIO_PMA_EXTABLE 11 /* 10G PMA/PMD extended ability */
|
||||
#define MDIO_PKGID1 14 /* Package identifier */
|
||||
#define MDIO_PKGID2 15
|
||||
#define MDIO_AN_ADVERTISE 16 /* AN advertising (base page) */
|
||||
#define MDIO_AN_LPA 19 /* AN LP abilities (base page) */
|
||||
#define MDIO_PCS_EEE_ABLE 20 /* EEE Capability register */
|
||||
#define MDIO_PCS_EEE_WK_ERR 22 /* EEE wake error counter */
|
||||
#define MDIO_PHYXS_LNSTAT 24 /* PHY XGXS lane state */
|
||||
#define MDIO_AN_EEE_ADV 60 /* EEE advertisement */
|
||||
#define MDIO_AN_EEE_LPABLE 61 /* EEE link partner ability */
|
||||
|
||||
/* Media-dependent registers. */
|
||||
#define MDIO_PMA_10GBT_SWAPPOL 130 /* 10GBASE-T pair swap & polarity */
|
||||
#define MDIO_PMA_10GBT_TXPWR 131 /* 10GBASE-T TX power control */
|
||||
#define MDIO_PMA_10GBT_SNR 133 /* 10GBASE-T SNR margin, lane A.
|
||||
* Lanes B-D are numbered 134-136. */
|
||||
#define MDIO_PMA_10GBR_FECABLE 170 /* 10GBASE-R FEC ability */
|
||||
#define MDIO_PCS_10GBX_STAT1 24 /* 10GBASE-X PCS status 1 */
|
||||
#define MDIO_PCS_10GBRT_STAT1 32 /* 10GBASE-R/-T PCS status 1 */
|
||||
#define MDIO_PCS_10GBRT_STAT2 33 /* 10GBASE-R/-T PCS status 2 */
|
||||
#define MDIO_AN_10GBT_CTRL 32 /* 10GBASE-T auto-negotiation control */
|
||||
#define MDIO_AN_10GBT_STAT 33 /* 10GBASE-T auto-negotiation status */
|
||||
|
||||
/* LASI (Link Alarm Status Interrupt) registers, defined by XENPAK MSA. */
|
||||
#define MDIO_PMA_LASI_RXCTRL 0x9000 /* RX_ALARM control */
|
||||
#define MDIO_PMA_LASI_TXCTRL 0x9001 /* TX_ALARM control */
|
||||
#define MDIO_PMA_LASI_CTRL 0x9002 /* LASI control */
|
||||
#define MDIO_PMA_LASI_RXSTAT 0x9003 /* RX_ALARM status */
|
||||
#define MDIO_PMA_LASI_TXSTAT 0x9004 /* TX_ALARM status */
|
||||
#define MDIO_PMA_LASI_STAT 0x9005 /* LASI status */
|
||||
|
||||
/* Control register 1. */
|
||||
/* Enable extended speed selection */
|
||||
#define MDIO_CTRL1_SPEEDSELEXT (BMCR_SPEED1000 | BMCR_SPEED100)
|
||||
/* All speed selection bits */
|
||||
#define MDIO_CTRL1_SPEEDSEL (MDIO_CTRL1_SPEEDSELEXT | 0x003c)
|
||||
#define MDIO_CTRL1_FULLDPLX BMCR_FULLDPLX
|
||||
#define MDIO_CTRL1_LPOWER BMCR_PDOWN
|
||||
#define MDIO_CTRL1_RESET BMCR_RESET
|
||||
#define MDIO_PMA_CTRL1_LOOPBACK 0x0001
|
||||
#define MDIO_PMA_CTRL1_SPEED1000 BMCR_SPEED1000
|
||||
#define MDIO_PMA_CTRL1_SPEED100 BMCR_SPEED100
|
||||
#define MDIO_PCS_CTRL1_LOOPBACK BMCR_LOOPBACK
|
||||
#define MDIO_PHYXS_CTRL1_LOOPBACK BMCR_LOOPBACK
|
||||
#define MDIO_AN_CTRL1_RESTART BMCR_ANRESTART
|
||||
#define MDIO_AN_CTRL1_ENABLE BMCR_ANENABLE
|
||||
#define MDIO_AN_CTRL1_XNP 0x2000 /* Enable extended next page */
|
||||
#define MDIO_PCS_CTRL1_CLKSTOP_EN 0x400 /* Stop the clock during LPI */
|
||||
|
||||
/* 10 Gb/s */
|
||||
#define MDIO_CTRL1_SPEED10G (MDIO_CTRL1_SPEEDSELEXT | 0x00)
|
||||
/* 10PASS-TS/2BASE-TL */
|
||||
#define MDIO_CTRL1_SPEED10P2B (MDIO_CTRL1_SPEEDSELEXT | 0x04)
|
||||
|
||||
/* Status register 1. */
|
||||
#define MDIO_STAT1_LPOWERABLE 0x0002 /* Low-power ability */
|
||||
#define MDIO_STAT1_LSTATUS BMSR_LSTATUS
|
||||
#define MDIO_STAT1_FAULT 0x0080 /* Fault */
|
||||
#define MDIO_AN_STAT1_LPABLE 0x0001 /* Link partner AN ability */
|
||||
#define MDIO_AN_STAT1_ABLE BMSR_ANEGCAPABLE
|
||||
#define MDIO_AN_STAT1_RFAULT BMSR_RFAULT
|
||||
#define MDIO_AN_STAT1_COMPLETE BMSR_ANEGCOMPLETE
|
||||
#define MDIO_AN_STAT1_PAGE 0x0040 /* Page received */
|
||||
#define MDIO_AN_STAT1_XNP 0x0080 /* Extended next page status */
|
||||
|
||||
/* Speed register. */
|
||||
#define MDIO_SPEED_10G 0x0001 /* 10G capable */
|
||||
#define MDIO_PMA_SPEED_2B 0x0002 /* 2BASE-TL capable */
|
||||
#define MDIO_PMA_SPEED_10P 0x0004 /* 10PASS-TS capable */
|
||||
#define MDIO_PMA_SPEED_1000 0x0010 /* 1000M capable */
|
||||
#define MDIO_PMA_SPEED_100 0x0020 /* 100M capable */
|
||||
#define MDIO_PMA_SPEED_10 0x0040 /* 10M capable */
|
||||
#define MDIO_PCS_SPEED_10P2B 0x0002 /* 10PASS-TS/2BASE-TL capable */
|
||||
|
||||
/* Device present registers. */
|
||||
#define MDIO_DEVS_PRESENT(devad) (1 << (devad))
|
||||
#define MDIO_DEVS_PMAPMD MDIO_DEVS_PRESENT(MDIO_MMD_PMAPMD)
|
||||
#define MDIO_DEVS_WIS MDIO_DEVS_PRESENT(MDIO_MMD_WIS)
|
||||
#define MDIO_DEVS_PCS MDIO_DEVS_PRESENT(MDIO_MMD_PCS)
|
||||
#define MDIO_DEVS_PHYXS MDIO_DEVS_PRESENT(MDIO_MMD_PHYXS)
|
||||
#define MDIO_DEVS_DTEXS MDIO_DEVS_PRESENT(MDIO_MMD_DTEXS)
|
||||
#define MDIO_DEVS_TC MDIO_DEVS_PRESENT(MDIO_MMD_TC)
|
||||
#define MDIO_DEVS_AN MDIO_DEVS_PRESENT(MDIO_MMD_AN)
|
||||
#define MDIO_DEVS_C22EXT MDIO_DEVS_PRESENT(MDIO_MMD_C22EXT)
|
||||
#define MDIO_DEVS_VEND1 MDIO_DEVS_PRESENT(MDIO_MMD_VEND1)
|
||||
#define MDIO_DEVS_VEND2 MDIO_DEVS_PRESENT(MDIO_MMD_VEND2)
|
||||
|
||||
#define MDIO_DEVS_LINK (MDIO_DEVS_PMAPMD | \
|
||||
MDIO_DEVS_WIS | \
|
||||
MDIO_DEVS_PCS | \
|
||||
MDIO_DEVS_PHYXS | \
|
||||
MDIO_DEVS_DTEXS | \
|
||||
MDIO_DEVS_AN)
|
||||
|
||||
/* Control register 2. */
|
||||
#define MDIO_PMA_CTRL2_TYPE 0x000f /* PMA/PMD type selection */
|
||||
#define MDIO_PMA_CTRL2_10GBCX4 0x0000 /* 10GBASE-CX4 type */
|
||||
#define MDIO_PMA_CTRL2_10GBEW 0x0001 /* 10GBASE-EW type */
|
||||
#define MDIO_PMA_CTRL2_10GBLW 0x0002 /* 10GBASE-LW type */
|
||||
#define MDIO_PMA_CTRL2_10GBSW 0x0003 /* 10GBASE-SW type */
|
||||
#define MDIO_PMA_CTRL2_10GBLX4 0x0004 /* 10GBASE-LX4 type */
|
||||
#define MDIO_PMA_CTRL2_10GBER 0x0005 /* 10GBASE-ER type */
|
||||
#define MDIO_PMA_CTRL2_10GBLR 0x0006 /* 10GBASE-LR type */
|
||||
#define MDIO_PMA_CTRL2_10GBSR 0x0007 /* 10GBASE-SR type */
|
||||
#define MDIO_PMA_CTRL2_10GBLRM 0x0008 /* 10GBASE-LRM type */
|
||||
#define MDIO_PMA_CTRL2_10GBT 0x0009 /* 10GBASE-T type */
|
||||
#define MDIO_PMA_CTRL2_10GBKX4 0x000a /* 10GBASE-KX4 type */
|
||||
#define MDIO_PMA_CTRL2_10GBKR 0x000b /* 10GBASE-KR type */
|
||||
#define MDIO_PMA_CTRL2_1000BT 0x000c /* 1000BASE-T type */
|
||||
#define MDIO_PMA_CTRL2_1000BKX 0x000d /* 1000BASE-KX type */
|
||||
#define MDIO_PMA_CTRL2_100BTX 0x000e /* 100BASE-TX type */
|
||||
#define MDIO_PMA_CTRL2_10BT 0x000f /* 10BASE-T type */
|
||||
#define MDIO_PCS_CTRL2_TYPE 0x0003 /* PCS type selection */
|
||||
#define MDIO_PCS_CTRL2_10GBR 0x0000 /* 10GBASE-R type */
|
||||
#define MDIO_PCS_CTRL2_10GBX 0x0001 /* 10GBASE-X type */
|
||||
#define MDIO_PCS_CTRL2_10GBW 0x0002 /* 10GBASE-W type */
|
||||
#define MDIO_PCS_CTRL2_10GBT 0x0003 /* 10GBASE-T type */
|
||||
|
||||
/* Status register 2. */
|
||||
#define MDIO_STAT2_RXFAULT 0x0400 /* Receive fault */
|
||||
#define MDIO_STAT2_TXFAULT 0x0800 /* Transmit fault */
|
||||
#define MDIO_STAT2_DEVPRST 0xc000 /* Device present */
|
||||
#define MDIO_STAT2_DEVPRST_VAL 0x8000 /* Device present value */
|
||||
#define MDIO_PMA_STAT2_LBABLE 0x0001 /* PMA loopback ability */
|
||||
#define MDIO_PMA_STAT2_10GBEW 0x0002 /* 10GBASE-EW ability */
|
||||
#define MDIO_PMA_STAT2_10GBLW 0x0004 /* 10GBASE-LW ability */
|
||||
#define MDIO_PMA_STAT2_10GBSW 0x0008 /* 10GBASE-SW ability */
|
||||
#define MDIO_PMA_STAT2_10GBLX4 0x0010 /* 10GBASE-LX4 ability */
|
||||
#define MDIO_PMA_STAT2_10GBER 0x0020 /* 10GBASE-ER ability */
|
||||
#define MDIO_PMA_STAT2_10GBLR 0x0040 /* 10GBASE-LR ability */
|
||||
#define MDIO_PMA_STAT2_10GBSR 0x0080 /* 10GBASE-SR ability */
|
||||
#define MDIO_PMD_STAT2_TXDISAB 0x0100 /* PMD TX disable ability */
|
||||
#define MDIO_PMA_STAT2_EXTABLE 0x0200 /* Extended abilities */
|
||||
#define MDIO_PMA_STAT2_RXFLTABLE 0x1000 /* Receive fault ability */
|
||||
#define MDIO_PMA_STAT2_TXFLTABLE 0x2000 /* Transmit fault ability */
|
||||
#define MDIO_PCS_STAT2_10GBR 0x0001 /* 10GBASE-R capable */
|
||||
#define MDIO_PCS_STAT2_10GBX 0x0002 /* 10GBASE-X capable */
|
||||
#define MDIO_PCS_STAT2_10GBW 0x0004 /* 10GBASE-W capable */
|
||||
#define MDIO_PCS_STAT2_RXFLTABLE 0x1000 /* Receive fault ability */
|
||||
#define MDIO_PCS_STAT2_TXFLTABLE 0x2000 /* Transmit fault ability */
|
||||
|
||||
/* Transmit disable register. */
|
||||
#define MDIO_PMD_TXDIS_GLOBAL 0x0001 /* Global PMD TX disable */
|
||||
#define MDIO_PMD_TXDIS_0 0x0002 /* PMD TX disable 0 */
|
||||
#define MDIO_PMD_TXDIS_1 0x0004 /* PMD TX disable 1 */
|
||||
#define MDIO_PMD_TXDIS_2 0x0008 /* PMD TX disable 2 */
|
||||
#define MDIO_PMD_TXDIS_3 0x0010 /* PMD TX disable 3 */
|
||||
|
||||
/* Receive signal detect register. */
|
||||
#define MDIO_PMD_RXDET_GLOBAL 0x0001 /* Global PMD RX signal detect */
|
||||
#define MDIO_PMD_RXDET_0 0x0002 /* PMD RX signal detect 0 */
|
||||
#define MDIO_PMD_RXDET_1 0x0004 /* PMD RX signal detect 1 */
|
||||
#define MDIO_PMD_RXDET_2 0x0008 /* PMD RX signal detect 2 */
|
||||
#define MDIO_PMD_RXDET_3 0x0010 /* PMD RX signal detect 3 */
|
||||
|
||||
/* Extended abilities register. */
|
||||
#define MDIO_PMA_EXTABLE_10GCX4 0x0001 /* 10GBASE-CX4 ability */
|
||||
#define MDIO_PMA_EXTABLE_10GBLRM 0x0002 /* 10GBASE-LRM ability */
|
||||
#define MDIO_PMA_EXTABLE_10GBT 0x0004 /* 10GBASE-T ability */
|
||||
#define MDIO_PMA_EXTABLE_10GBKX4 0x0008 /* 10GBASE-KX4 ability */
|
||||
#define MDIO_PMA_EXTABLE_10GBKR 0x0010 /* 10GBASE-KR ability */
|
||||
#define MDIO_PMA_EXTABLE_1000BT 0x0020 /* 1000BASE-T ability */
|
||||
#define MDIO_PMA_EXTABLE_1000BKX 0x0040 /* 1000BASE-KX ability */
|
||||
#define MDIO_PMA_EXTABLE_100BTX 0x0080 /* 100BASE-TX ability */
|
||||
#define MDIO_PMA_EXTABLE_10BT 0x0100 /* 10BASE-T ability */
|
||||
|
||||
/* PHY XGXS lane state register. */
|
||||
#define MDIO_PHYXS_LNSTAT_SYNC0 0x0001
|
||||
#define MDIO_PHYXS_LNSTAT_SYNC1 0x0002
|
||||
#define MDIO_PHYXS_LNSTAT_SYNC2 0x0004
|
||||
#define MDIO_PHYXS_LNSTAT_SYNC3 0x0008
|
||||
#define MDIO_PHYXS_LNSTAT_ALIGN 0x1000
|
||||
|
||||
/* PMA 10GBASE-T pair swap & polarity */
|
||||
#define MDIO_PMA_10GBT_SWAPPOL_ABNX 0x0001 /* Pair A/B uncrossed */
|
||||
#define MDIO_PMA_10GBT_SWAPPOL_CDNX 0x0002 /* Pair C/D uncrossed */
|
||||
#define MDIO_PMA_10GBT_SWAPPOL_AREV 0x0100 /* Pair A polarity reversed */
|
||||
#define MDIO_PMA_10GBT_SWAPPOL_BREV 0x0200 /* Pair B polarity reversed */
|
||||
#define MDIO_PMA_10GBT_SWAPPOL_CREV 0x0400 /* Pair C polarity reversed */
|
||||
#define MDIO_PMA_10GBT_SWAPPOL_DREV 0x0800 /* Pair D polarity reversed */
|
||||
|
||||
/* PMA 10GBASE-T TX power register. */
|
||||
#define MDIO_PMA_10GBT_TXPWR_SHORT 0x0001 /* Short-reach mode */
|
||||
|
||||
/* PMA 10GBASE-T SNR registers. */
|
||||
/* Value is SNR margin in dB, clamped to range [-127, 127], plus 0x8000. */
|
||||
#define MDIO_PMA_10GBT_SNR_BIAS 0x8000
|
||||
#define MDIO_PMA_10GBT_SNR_MAX 127
|
||||
|
||||
/* PMA 10GBASE-R FEC ability register. */
|
||||
#define MDIO_PMA_10GBR_FECABLE_ABLE 0x0001 /* FEC ability */
|
||||
#define MDIO_PMA_10GBR_FECABLE_ERRABLE 0x0002 /* FEC error indic. ability */
|
||||
|
||||
/* PCS 10GBASE-R/-T status register 1. */
|
||||
#define MDIO_PCS_10GBRT_STAT1_BLKLK 0x0001 /* Block lock attained */
|
||||
|
||||
/* PCS 10GBASE-R/-T status register 2. */
|
||||
#define MDIO_PCS_10GBRT_STAT2_ERR 0x00ff
|
||||
#define MDIO_PCS_10GBRT_STAT2_BER 0x3f00
|
||||
|
||||
/* AN 10GBASE-T control register. */
|
||||
#define MDIO_AN_10GBT_CTRL_ADV10G 0x1000 /* Advertise 10GBASE-T */
|
||||
|
||||
/* AN 10GBASE-T status register. */
|
||||
#define MDIO_AN_10GBT_STAT_LPTRR 0x0200 /* LP training reset req. */
|
||||
#define MDIO_AN_10GBT_STAT_LPLTABLE 0x0400 /* LP loop timing ability */
|
||||
#define MDIO_AN_10GBT_STAT_LP10G 0x0800 /* LP is 10GBT capable */
|
||||
#define MDIO_AN_10GBT_STAT_REMOK 0x1000 /* Remote OK */
|
||||
#define MDIO_AN_10GBT_STAT_LOCOK 0x2000 /* Local OK */
|
||||
#define MDIO_AN_10GBT_STAT_MS 0x4000 /* Master/slave config */
|
||||
#define MDIO_AN_10GBT_STAT_MSFLT 0x8000 /* Master/slave config fault */
|
||||
|
||||
/* EEE Supported/Advertisement/LP Advertisement registers.
|
||||
*
|
||||
* EEE capability Register (3.20), Advertisement (7.60) and
|
||||
* Link partner ability (7.61) registers have and can use the same identical
|
||||
* bit masks.
|
||||
*/
|
||||
#define MDIO_AN_EEE_ADV_100TX 0x0002 /* Advertise 100TX EEE cap */
|
||||
#define MDIO_AN_EEE_ADV_1000T 0x0004 /* Advertise 1000T EEE cap */
|
||||
/* Note: the two defines above can be potentially used by the user-land
|
||||
* and cannot remove them now.
|
||||
* So, we define the new generic MDIO_EEE_100TX and MDIO_EEE_1000T macros
|
||||
* using the previous ones (that can be considered obsolete).
|
||||
*/
|
||||
#define MDIO_EEE_100TX MDIO_AN_EEE_ADV_100TX /* 100TX EEE cap */
|
||||
#define MDIO_EEE_1000T MDIO_AN_EEE_ADV_1000T /* 1000T EEE cap */
|
||||
#define MDIO_EEE_10GT 0x0008 /* 10GT EEE cap */
|
||||
#define MDIO_EEE_1000KX 0x0010 /* 1000KX EEE cap */
|
||||
#define MDIO_EEE_10GKX4 0x0020 /* 10G KX4 EEE cap */
|
||||
#define MDIO_EEE_10GKR 0x0040 /* 10G KR EEE cap */
|
||||
|
||||
/* LASI RX_ALARM control/status registers. */
|
||||
#define MDIO_PMA_LASI_RX_PHYXSLFLT 0x0001 /* PHY XS RX local fault */
|
||||
#define MDIO_PMA_LASI_RX_PCSLFLT 0x0008 /* PCS RX local fault */
|
||||
#define MDIO_PMA_LASI_RX_PMALFLT 0x0010 /* PMA/PMD RX local fault */
|
||||
#define MDIO_PMA_LASI_RX_OPTICPOWERFLT 0x0020 /* RX optical power fault */
|
||||
#define MDIO_PMA_LASI_RX_WISLFLT 0x0200 /* WIS local fault */
|
||||
|
||||
/* LASI TX_ALARM control/status registers. */
|
||||
#define MDIO_PMA_LASI_TX_PHYXSLFLT 0x0001 /* PHY XS TX local fault */
|
||||
#define MDIO_PMA_LASI_TX_PCSLFLT 0x0008 /* PCS TX local fault */
|
||||
#define MDIO_PMA_LASI_TX_PMALFLT 0x0010 /* PMA/PMD TX local fault */
|
||||
#define MDIO_PMA_LASI_TX_LASERPOWERFLT 0x0080 /* Laser output power fault */
|
||||
#define MDIO_PMA_LASI_TX_LASERTEMPFLT 0x0100 /* Laser temperature fault */
|
||||
#define MDIO_PMA_LASI_TX_LASERBICURRFLT 0x0200 /* Laser bias current fault */
|
||||
|
||||
/* LASI control/status registers. */
|
||||
#define MDIO_PMA_LASI_LSALARM 0x0001 /* LS_ALARM enable/status */
|
||||
#define MDIO_PMA_LASI_TXALARM 0x0002 /* TX_ALARM enable/status */
|
||||
#define MDIO_PMA_LASI_RXALARM 0x0004 /* RX_ALARM enable/status */
|
||||
|
||||
/* Mapping between MDIO PRTAD/DEVAD and mii_ioctl_data::phy_id */
|
||||
|
||||
#define MDIO_PHY_ID_C45 0x8000
|
||||
#define MDIO_PHY_ID_PRTAD 0x03e0
|
||||
#define MDIO_PHY_ID_DEVAD 0x001f
|
||||
#define MDIO_PHY_ID_C45_MASK \
|
||||
(MDIO_PHY_ID_C45 | MDIO_PHY_ID_PRTAD | MDIO_PHY_ID_DEVAD)
|
||||
|
||||
#define MDIO_PRTAD_NONE (-1)
|
||||
#define MDIO_DEVAD_NONE (-1)
|
||||
#define MDIO_EMULATE_C22 4
|
||||
|
||||
static inline __u16 mdio_phy_id_c45(int prtad, int devad)
|
||||
{
|
||||
return MDIO_PHY_ID_C45 | (prtad << 5) | devad;
|
||||
}
|
||||
|
||||
#endif /* __LINUX_MDIO_H__ */
|
||||
@@ -0,0 +1,230 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
||||
/*
|
||||
* linux/mii.h: definitions for MII-compatible transceivers
|
||||
* Originally drivers/net/sunhme.h.
|
||||
*
|
||||
* Copyright (C) 1996, 1999, 2001 David S. Miller (davem@redhat.com)
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_MII_H__
|
||||
#define __LINUX_MII_H__
|
||||
|
||||
/* Generic MII registers. */
|
||||
#define MII_BMCR 0x00 /* Basic mode control register */
|
||||
#define MII_BMSR 0x01 /* Basic mode status register */
|
||||
#define MII_PHYSID1 0x02 /* PHYS ID 1 */
|
||||
#define MII_PHYSID2 0x03 /* PHYS ID 2 */
|
||||
#define MII_ADVERTISE 0x04 /* Advertisement control reg */
|
||||
#define MII_LPA 0x05 /* Link partner ability reg */
|
||||
#define MII_EXPANSION 0x06 /* Expansion register */
|
||||
#define MII_CTRL1000 0x09 /* 1000BASE-T control */
|
||||
#define MII_STAT1000 0x0a /* 1000BASE-T status */
|
||||
#define MII_MMD_CTRL 0x0d /* MMD Access Control Register */
|
||||
#define MII_MMD_DATA 0x0e /* MMD Access Data Register */
|
||||
#define MII_ESTATUS 0x0f /* Extended Status */
|
||||
#define MII_DCOUNTER 0x12 /* Disconnect counter */
|
||||
#define MII_FCSCOUNTER 0x13 /* False carrier counter */
|
||||
#define MII_NWAYTEST 0x14 /* N-way auto-neg test reg */
|
||||
#define MII_RERRCOUNTER 0x15 /* Receive error counter */
|
||||
#define MII_SREVISION 0x16 /* Silicon revision */
|
||||
#define MII_RESV1 0x17 /* Reserved... */
|
||||
#define MII_LBRERROR 0x18 /* Lpback, rx, bypass error */
|
||||
#define MII_PHYADDR 0x19 /* PHY address */
|
||||
#define MII_RESV2 0x1a /* Reserved... */
|
||||
#define MII_TPISTATUS 0x1b /* TPI status for 10mbps */
|
||||
#define MII_NCONFIG 0x1c /* Network interface config */
|
||||
|
||||
/* Basic mode control register. */
|
||||
#define BMCR_RESV 0x003f /* Unused... */
|
||||
#define BMCR_SPEED1000 0x0040 /* MSB of Speed (1000) */
|
||||
#define BMCR_CTST 0x0080 /* Collision test */
|
||||
#define BMCR_FULLDPLX 0x0100 /* Full duplex */
|
||||
#define BMCR_ANRESTART 0x0200 /* Auto negotiation restart */
|
||||
#define BMCR_ISOLATE 0x0400 /* Isolate data paths from MII */
|
||||
#define BMCR_PDOWN 0x0800 /* Enable low power state */
|
||||
#define BMCR_ANENABLE 0x1000 /* Enable auto negotiation */
|
||||
#define BMCR_SPEED100 0x2000 /* Select 100Mbps */
|
||||
#define BMCR_LOOPBACK 0x4000 /* TXD loopback bits */
|
||||
#define BMCR_RESET 0x8000 /* Reset to default state */
|
||||
#define BMCR_SPEED10 0x0000 /* Select 10Mbps */
|
||||
|
||||
/* Basic mode status register. */
|
||||
#define BMSR_ERCAP 0x0001 /* Ext-reg capability */
|
||||
#define BMSR_JCD 0x0002 /* Jabber detected */
|
||||
#define BMSR_LSTATUS 0x0004 /* Link status */
|
||||
#define BMSR_ANEGCAPABLE 0x0008 /* Able to do auto-negotiation */
|
||||
#define BMSR_RFAULT 0x0010 /* Remote fault detected */
|
||||
#define BMSR_ANEGCOMPLETE 0x0020 /* Auto-negotiation complete */
|
||||
#define BMSR_RESV 0x00c0 /* Unused... */
|
||||
#define BMSR_ESTATEN 0x0100 /* Extended Status in R15 */
|
||||
#define BMSR_100HALF2 0x0200 /* Can do 100BASE-T2 HDX */
|
||||
#define BMSR_100FULL2 0x0400 /* Can do 100BASE-T2 FDX */
|
||||
#define BMSR_10HALF 0x0800 /* Can do 10mbps, half-duplex */
|
||||
#define BMSR_10FULL 0x1000 /* Can do 10mbps, full-duplex */
|
||||
#define BMSR_100HALF 0x2000 /* Can do 100mbps, half-duplex */
|
||||
#define BMSR_100FULL 0x4000 /* Can do 100mbps, full-duplex */
|
||||
#define BMSR_100BASE4 0x8000 /* Can do 100mbps, 4k packets */
|
||||
|
||||
/* Advertisement control register. */
|
||||
#define ADVERTISE_SLCT 0x001f /* Selector bits */
|
||||
#define ADVERTISE_CSMA 0x0001 /* Only selector supported */
|
||||
#define ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */
|
||||
#define ADVERTISE_1000XFULL 0x0020 /* Try for 1000BASE-X full-duplex */
|
||||
#define ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */
|
||||
#define ADVERTISE_1000XHALF 0x0040 /* Try for 1000BASE-X half-duplex */
|
||||
#define ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */
|
||||
#define ADVERTISE_1000XPAUSE 0x0080 /* Try for 1000BASE-X pause */
|
||||
#define ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */
|
||||
#define ADVERTISE_1000XPSE_ASYM 0x0100 /* Try for 1000BASE-X asym pause */
|
||||
#define ADVERTISE_100BASE4 0x0200 /* Try for 100mbps 4k packets */
|
||||
#define ADVERTISE_PAUSE_CAP 0x0400 /* Try for pause */
|
||||
#define ADVERTISE_PAUSE_ASYM 0x0800 /* Try for asymetric pause */
|
||||
#define ADVERTISE_RESV 0x1000 /* Unused... */
|
||||
#define ADVERTISE_RFAULT 0x2000 /* Say we can detect faults */
|
||||
#define ADVERTISE_LPACK 0x4000 /* Ack link partners response */
|
||||
#define ADVERTISE_NPAGE 0x8000 /* Next page bit */
|
||||
|
||||
#define ADVERTISE_FULL (ADVERTISE_100FULL | ADVERTISE_10FULL | \
|
||||
ADVERTISE_CSMA)
|
||||
#define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \
|
||||
ADVERTISE_100HALF | ADVERTISE_100FULL)
|
||||
|
||||
/* Link partner ability register. */
|
||||
#define LPA_SLCT 0x001f /* Same as advertise selector */
|
||||
#define LPA_10HALF 0x0020 /* Can do 10mbps half-duplex */
|
||||
#define LPA_1000XFULL 0x0020 /* Can do 1000BASE-X full-duplex */
|
||||
#define LPA_10FULL 0x0040 /* Can do 10mbps full-duplex */
|
||||
#define LPA_1000XHALF 0x0040 /* Can do 1000BASE-X half-duplex */
|
||||
#define LPA_100HALF 0x0080 /* Can do 100mbps half-duplex */
|
||||
#define LPA_1000XPAUSE 0x0080 /* Can do 1000BASE-X pause */
|
||||
#define LPA_100FULL 0x0100 /* Can do 100mbps full-duplex */
|
||||
#define LPA_1000XPAUSE_ASYM 0x0100 /* Can do 1000BASE-X pause asym*/
|
||||
#define LPA_100BASE4 0x0200 /* Can do 100mbps 4k packets */
|
||||
#define LPA_PAUSE_CAP 0x0400 /* Can pause */
|
||||
#define LPA_PAUSE_ASYM 0x0800 /* Can pause asymetrically */
|
||||
#define LPA_RESV 0x1000 /* Unused... */
|
||||
#define LPA_RFAULT 0x2000 /* Link partner faulted */
|
||||
#define LPA_LPACK 0x4000 /* Link partner acked us */
|
||||
#define LPA_NPAGE 0x8000 /* Next page bit */
|
||||
|
||||
#define LPA_DUPLEX (LPA_10FULL | LPA_100FULL)
|
||||
#define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
|
||||
|
||||
/* Expansion register for auto-negotiation. */
|
||||
#define EXPANSION_NWAY 0x0001 /* Can do N-way auto-nego */
|
||||
#define EXPANSION_LCWP 0x0002 /* Got new RX page code word */
|
||||
#define EXPANSION_ENABLENPAGE 0x0004 /* This enables npage words */
|
||||
#define EXPANSION_NPCAPABLE 0x0008 /* Link partner supports npage */
|
||||
#define EXPANSION_MFAULTS 0x0010 /* Multiple faults detected */
|
||||
#define EXPANSION_RESV 0xffe0 /* Unused... */
|
||||
|
||||
#define ESTATUS_1000_XFULL 0x8000 /* Can do 1000BX Full */
|
||||
#define ESTATUS_1000_XHALF 0x4000 /* Can do 1000BX Half */
|
||||
#define ESTATUS_1000_TFULL 0x2000 /* Can do 1000BT Full */
|
||||
#define ESTATUS_1000_THALF 0x1000 /* Can do 1000BT Half */
|
||||
|
||||
/* N-way test register. */
|
||||
#define NWAYTEST_RESV1 0x00ff /* Unused... */
|
||||
#define NWAYTEST_LOOPBACK 0x0100 /* Enable loopback for N-way */
|
||||
#define NWAYTEST_RESV2 0xfe00 /* Unused... */
|
||||
|
||||
/* 1000BASE-T Control register */
|
||||
#define ADVERTISE_1000FULL 0x0200 /* Advertise 1000BASE-T full duplex */
|
||||
#define ADVERTISE_1000HALF 0x0100 /* Advertise 1000BASE-T half duplex */
|
||||
#define CTL1000_AS_MASTER 0x0800
|
||||
#define CTL1000_ENABLE_MASTER 0x1000
|
||||
|
||||
/* 1000BASE-T Status register */
|
||||
#define LPA_1000LOCALRXOK 0x2000 /* Link partner local receiver status */
|
||||
#define LPA_1000REMRXOK 0x1000 /* Link partner remote receiver status */
|
||||
#define LPA_1000FULL 0x0800 /* Link partner 1000BASE-T full duplex */
|
||||
#define LPA_1000HALF 0x0400 /* Link partner 1000BASE-T half duplex */
|
||||
|
||||
/* Flow control flags */
|
||||
#define FLOW_CTRL_TX 0x01
|
||||
#define FLOW_CTRL_RX 0x02
|
||||
|
||||
/* MMD Access Control register fields */
|
||||
#define MII_MMD_CTRL_DEVAD_MASK 0x1f /* Mask MMD DEVAD*/
|
||||
#define MII_MMD_CTRL_ADDR 0x0000 /* Address */
|
||||
#define MII_MMD_CTRL_NOINCR 0x4000 /* no post increment */
|
||||
#define MII_MMD_CTRL_INCR_RDWT 0x8000 /* post increment on reads & writes */
|
||||
#define MII_MMD_CTRL_INCR_ON_WT 0xC000 /* post increment on writes only */
|
||||
|
||||
/**
|
||||
* mii_nway_result
|
||||
* @negotiated: value of MII ANAR and'd with ANLPAR
|
||||
*
|
||||
* Given a set of MII abilities, check each bit and returns the
|
||||
* currently supported media, in the priority order defined by
|
||||
* IEEE 802.3u. We use LPA_xxx constants but note this is not the
|
||||
* value of LPA solely, as described above.
|
||||
*
|
||||
* The one exception to IEEE 802.3u is that 100baseT4 is placed
|
||||
* between 100T-full and 100T-half. If your phy does not support
|
||||
* 100T4 this is fine. If your phy places 100T4 elsewhere in the
|
||||
* priority order, you will need to roll your own function.
|
||||
*/
|
||||
static inline unsigned int mii_nway_result (unsigned int negotiated)
|
||||
{
|
||||
unsigned int ret;
|
||||
|
||||
if (negotiated & LPA_100FULL)
|
||||
ret = LPA_100FULL;
|
||||
else if (negotiated & LPA_100BASE4)
|
||||
ret = LPA_100BASE4;
|
||||
else if (negotiated & LPA_100HALF)
|
||||
ret = LPA_100HALF;
|
||||
else if (negotiated & LPA_10FULL)
|
||||
ret = LPA_10FULL;
|
||||
else
|
||||
ret = LPA_10HALF;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* mii_duplex
|
||||
* @duplex_lock: Non-zero if duplex is locked at full
|
||||
* @negotiated: value of MII ANAR and'd with ANLPAR
|
||||
*
|
||||
* A small helper function for a common case. Returns one
|
||||
* if the media is operating or locked at full duplex, and
|
||||
* returns zero otherwise.
|
||||
*/
|
||||
static inline unsigned int mii_duplex (unsigned int duplex_lock,
|
||||
unsigned int negotiated)
|
||||
{
|
||||
if (duplex_lock)
|
||||
return 1;
|
||||
if (mii_nway_result(negotiated) & LPA_DUPLEX)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* mii_resolve_flowctrl_fdx
|
||||
* @lcladv: value of MII ADVERTISE register
|
||||
* @rmtadv: value of MII LPA register
|
||||
*
|
||||
* Resolve full duplex flow control as per IEEE 802.3-2005 table 28B-3
|
||||
*/
|
||||
static inline u8 mii_resolve_flowctrl_fdx(u16 lcladv, u16 rmtadv)
|
||||
{
|
||||
u8 cap = 0;
|
||||
|
||||
if (lcladv & rmtadv & ADVERTISE_PAUSE_CAP) {
|
||||
cap = FLOW_CTRL_TX | FLOW_CTRL_RX;
|
||||
} else if (lcladv & rmtadv & ADVERTISE_PAUSE_ASYM) {
|
||||
if (lcladv & ADVERTISE_PAUSE_CAP)
|
||||
cap = FLOW_CTRL_RX;
|
||||
else if (rmtadv & ADVERTISE_PAUSE_CAP)
|
||||
cap = FLOW_CTRL_TX;
|
||||
}
|
||||
|
||||
return cap;
|
||||
}
|
||||
|
||||
void mii_init(void);
|
||||
|
||||
#endif /* __LINUX_MII_H__ */
|
||||
@@ -0,0 +1,161 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* linux/include/linux/mtd/bbm.h
|
||||
*
|
||||
* NAND family Bad Block Management (BBM) header file
|
||||
* - Bad Block Table (BBT) implementation
|
||||
*
|
||||
* Copyright © 2005 Samsung Electronics
|
||||
* Kyungmin Park <kyungmin.park@samsung.com>
|
||||
*
|
||||
* Copyright © 2000-2005
|
||||
* Thomas Gleixner <tglx@linuxtronix.de>
|
||||
*
|
||||
*/
|
||||
#ifndef __LINUX_MTD_BBM_H
|
||||
#define __LINUX_MTD_BBM_H
|
||||
|
||||
/* The maximum number of NAND chips in an array */
|
||||
#ifndef CONFIG_SYS_NAND_MAX_CHIPS
|
||||
#define CONFIG_SYS_NAND_MAX_CHIPS 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* struct nand_bbt_descr - bad block table descriptor
|
||||
* @options: options for this descriptor
|
||||
* @pages: the page(s) where we find the bbt, used with option BBT_ABSPAGE
|
||||
* when bbt is searched, then we store the found bbts pages here.
|
||||
* Its an array and supports up to 8 chips now
|
||||
* @offs: offset of the pattern in the oob area of the page
|
||||
* @veroffs: offset of the bbt version counter in the oob are of the page
|
||||
* @version: version read from the bbt page during scan
|
||||
* @len: length of the pattern, if 0 no pattern check is performed
|
||||
* @maxblocks: maximum number of blocks to search for a bbt. This number of
|
||||
* blocks is reserved at the end of the device where the tables are
|
||||
* written.
|
||||
* @reserved_block_code: if non-0, this pattern denotes a reserved (rather than
|
||||
* bad) block in the stored bbt
|
||||
* @pattern: pattern to identify bad block table or factory marked good /
|
||||
* bad blocks, can be NULL, if len = 0
|
||||
*
|
||||
* Descriptor for the bad block table marker and the descriptor for the
|
||||
* pattern which identifies good and bad blocks. The assumption is made
|
||||
* that the pattern and the version count are always located in the oob area
|
||||
* of the first block.
|
||||
*/
|
||||
struct nand_bbt_descr {
|
||||
int options;
|
||||
int pages[CONFIG_SYS_NAND_MAX_CHIPS];
|
||||
int offs;
|
||||
int veroffs;
|
||||
uint8_t version[CONFIG_SYS_NAND_MAX_CHIPS];
|
||||
int len;
|
||||
int maxblocks;
|
||||
int reserved_block_code;
|
||||
uint8_t *pattern;
|
||||
};
|
||||
|
||||
/* Options for the bad block table descriptors */
|
||||
|
||||
/* The number of bits used per block in the bbt on the device */
|
||||
#define NAND_BBT_NRBITS_MSK 0x0000000F
|
||||
#define NAND_BBT_1BIT 0x00000001
|
||||
#define NAND_BBT_2BIT 0x00000002
|
||||
#define NAND_BBT_4BIT 0x00000004
|
||||
#define NAND_BBT_8BIT 0x00000008
|
||||
/* The bad block table is in the last good block of the device */
|
||||
#define NAND_BBT_LASTBLOCK 0x00000010
|
||||
/* The bbt is at the given page, else we must scan for the bbt */
|
||||
#define NAND_BBT_ABSPAGE 0x00000020
|
||||
/* bbt is stored per chip on multichip devices */
|
||||
#define NAND_BBT_PERCHIP 0x00000080
|
||||
/* bbt has a version counter at offset veroffs */
|
||||
#define NAND_BBT_VERSION 0x00000100
|
||||
/* Create a bbt if none exists */
|
||||
#define NAND_BBT_CREATE 0x00000200
|
||||
/*
|
||||
* Create an empty BBT with no vendor information. Vendor's information may be
|
||||
* unavailable, for example, if the NAND controller has a different data and OOB
|
||||
* layout or if this information is already purged. Must be used in conjunction
|
||||
* with NAND_BBT_CREATE.
|
||||
*/
|
||||
#define NAND_BBT_CREATE_EMPTY 0x00000400
|
||||
/* Write bbt if neccecary */
|
||||
#define NAND_BBT_WRITE 0x00002000
|
||||
/* Read and write back block contents when writing bbt */
|
||||
#define NAND_BBT_SAVECONTENT 0x00004000
|
||||
/* Search good / bad pattern on the first and the second page */
|
||||
#define NAND_BBT_SCAN2NDPAGE 0x00008000
|
||||
/* Search good / bad pattern on the last page of the eraseblock */
|
||||
#define NAND_BBT_SCANLASTPAGE 0x00010000
|
||||
/*
|
||||
* Use a flash based bad block table. By default, OOB identifier is saved in
|
||||
* OOB area. This option is passed to the default bad block table function.
|
||||
*/
|
||||
#define NAND_BBT_USE_FLASH 0x00020000
|
||||
/*
|
||||
* Do not store flash based bad block table marker in the OOB area; store it
|
||||
* in-band.
|
||||
*/
|
||||
#define NAND_BBT_NO_OOB 0x00040000
|
||||
/*
|
||||
* Do not write new bad block markers to OOB; useful, e.g., when ECC covers
|
||||
* entire spare area. Must be used with NAND_BBT_USE_FLASH.
|
||||
*/
|
||||
#define NAND_BBT_NO_OOB_BBM 0x00080000
|
||||
|
||||
/*
|
||||
* Flag set by nand_create_default_bbt_descr(), marking that the nand_bbt_descr
|
||||
* was allocated dynamicaly and must be freed in nand_release(). Has no meaning
|
||||
* in nand_chip.bbt_options.
|
||||
*/
|
||||
#define NAND_BBT_DYNAMICSTRUCT 0x80000000
|
||||
|
||||
/* The maximum number of blocks to scan for a bbt */
|
||||
#define NAND_BBT_SCAN_MAXBLOCKS 4
|
||||
|
||||
/*
|
||||
* Constants for oob configuration
|
||||
*/
|
||||
#define NAND_SMALL_BADBLOCK_POS 5
|
||||
#define NAND_LARGE_BADBLOCK_POS 0
|
||||
#define ONENAND_BADBLOCK_POS 0
|
||||
|
||||
/*
|
||||
* Bad block scanning errors
|
||||
*/
|
||||
#define ONENAND_BBT_READ_ERROR 1
|
||||
#define ONENAND_BBT_READ_ECC_ERROR 2
|
||||
#define ONENAND_BBT_READ_FATAL_ERROR 4
|
||||
|
||||
/**
|
||||
* struct bbm_info - [GENERIC] Bad Block Table data structure
|
||||
* @bbt_erase_shift: [INTERN] number of address bits in a bbt entry
|
||||
* @badblockpos: [INTERN] position of the bad block marker in the oob area
|
||||
* @options: options for this descriptor
|
||||
* @bbt: [INTERN] bad block table pointer
|
||||
* @isbad_bbt: function to determine if a block is bad
|
||||
* @badblock_pattern: [REPLACEABLE] bad block scan pattern used for
|
||||
* initial bad block scan
|
||||
* @priv: [OPTIONAL] pointer to private bbm date
|
||||
*/
|
||||
struct bbm_info {
|
||||
int bbt_erase_shift;
|
||||
int badblockpos;
|
||||
int options;
|
||||
|
||||
uint8_t *bbt;
|
||||
|
||||
int (*isbad_bbt)(struct mtd_info *mtd, loff_t ofs, int allowbbt);
|
||||
|
||||
/* TODO Add more NAND specific fileds */
|
||||
struct nand_bbt_descr *badblock_pattern;
|
||||
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/* OneNAND BBT interface */
|
||||
extern int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd);
|
||||
extern int onenand_default_bbt(struct mtd_info *mtd);
|
||||
|
||||
#endif /* __LINUX_MTD_BBM_H */
|
||||
@@ -0,0 +1,32 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org> et al.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __MTD_CFI_H__
|
||||
#define __MTD_CFI_H__
|
||||
|
||||
#define CFI_MFR_ANY 0xFFFF
|
||||
#define CFI_ID_ANY 0xFFFF
|
||||
#define CFI_MFR_CONTINUATION 0x007F
|
||||
|
||||
#define CFI_MFR_AMD 0x0001
|
||||
#define CFI_MFR_AMIC 0x0037
|
||||
#define CFI_MFR_ATMEL 0x001F
|
||||
#define CFI_MFR_EON 0x001C
|
||||
#define CFI_MFR_FUJITSU 0x0004
|
||||
#define CFI_MFR_HYUNDAI 0x00AD
|
||||
#define CFI_MFR_INTEL 0x0089
|
||||
#define CFI_MFR_MACRONIX 0x00C2
|
||||
#define CFI_MFR_NEC 0x0010
|
||||
#define CFI_MFR_PMC 0x009D
|
||||
#define CFI_MFR_SAMSUNG 0x00EC
|
||||
#define CFI_MFR_SHARP 0x00B0
|
||||
#define CFI_MFR_SST 0x00BF
|
||||
#define CFI_MFR_ST 0x0020 /* STMicroelectronics */
|
||||
#define CFI_MFR_MICRON 0x002C /* Micron */
|
||||
#define CFI_MFR_TOSHIBA 0x0098
|
||||
#define CFI_MFR_WINBOND 0x00DA
|
||||
|
||||
#endif /* __MTD_CFI_H__ */
|
||||
@@ -0,0 +1,23 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* MTD device concatenation layer definitions
|
||||
*
|
||||
* Copyright © 2002 Robert Kaiser <rkaiser@sysgo.de>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MTD_CONCAT_H
|
||||
#define MTD_CONCAT_H
|
||||
|
||||
struct mtd_info *mtd_concat_create(
|
||||
struct mtd_info *subdev[], /* subdevices to concatenate */
|
||||
int num_devs, /* number of subdevices */
|
||||
#ifndef __UBOOT__
|
||||
const char *name); /* name for the new device */
|
||||
#else
|
||||
char *name); /* name for the new device */
|
||||
#endif
|
||||
|
||||
void mtd_concat_destroy(struct mtd_info *mtd);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,207 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* Linux driver for Disk-On-Chip devices
|
||||
*
|
||||
* Copyright © 1999 Machine Vision Holdings, Inc.
|
||||
* Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org>
|
||||
* Copyright © 2002-2003 Greg Ungerer <gerg@snapgear.com>
|
||||
* Copyright © 2002-2003 SnapGear Inc
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __MTD_DOC2000_H__
|
||||
#define __MTD_DOC2000_H__
|
||||
|
||||
#include <linux/mtd/mtd.h>
|
||||
#if 0
|
||||
#include <linux/mutex.h>
|
||||
#endif
|
||||
|
||||
#define DoC_Sig1 0
|
||||
#define DoC_Sig2 1
|
||||
|
||||
#define DoC_ChipID 0x1000
|
||||
#define DoC_DOCStatus 0x1001
|
||||
#define DoC_DOCControl 0x1002
|
||||
#define DoC_FloorSelect 0x1003
|
||||
#define DoC_CDSNControl 0x1004
|
||||
#define DoC_CDSNDeviceSelect 0x1005
|
||||
#define DoC_ECCConf 0x1006
|
||||
#define DoC_2k_ECCStatus 0x1007
|
||||
|
||||
#define DoC_CDSNSlowIO 0x100d
|
||||
#define DoC_ECCSyndrome0 0x1010
|
||||
#define DoC_ECCSyndrome1 0x1011
|
||||
#define DoC_ECCSyndrome2 0x1012
|
||||
#define DoC_ECCSyndrome3 0x1013
|
||||
#define DoC_ECCSyndrome4 0x1014
|
||||
#define DoC_ECCSyndrome5 0x1015
|
||||
#define DoC_AliasResolution 0x101b
|
||||
#define DoC_ConfigInput 0x101c
|
||||
#define DoC_ReadPipeInit 0x101d
|
||||
#define DoC_WritePipeTerm 0x101e
|
||||
#define DoC_LastDataRead 0x101f
|
||||
#define DoC_NOP 0x1020
|
||||
|
||||
#define DoC_Mil_CDSN_IO 0x0800
|
||||
#define DoC_2k_CDSN_IO 0x1800
|
||||
|
||||
#define DoC_Mplus_NOP 0x1002
|
||||
#define DoC_Mplus_AliasResolution 0x1004
|
||||
#define DoC_Mplus_DOCControl 0x1006
|
||||
#define DoC_Mplus_AccessStatus 0x1008
|
||||
#define DoC_Mplus_DeviceSelect 0x1008
|
||||
#define DoC_Mplus_Configuration 0x100a
|
||||
#define DoC_Mplus_OutputControl 0x100c
|
||||
#define DoC_Mplus_FlashControl 0x1020
|
||||
#define DoC_Mplus_FlashSelect 0x1022
|
||||
#define DoC_Mplus_FlashCmd 0x1024
|
||||
#define DoC_Mplus_FlashAddress 0x1026
|
||||
#define DoC_Mplus_FlashData0 0x1028
|
||||
#define DoC_Mplus_FlashData1 0x1029
|
||||
#define DoC_Mplus_ReadPipeInit 0x102a
|
||||
#define DoC_Mplus_LastDataRead 0x102c
|
||||
#define DoC_Mplus_LastDataRead1 0x102d
|
||||
#define DoC_Mplus_WritePipeTerm 0x102e
|
||||
#define DoC_Mplus_ECCSyndrome0 0x1040
|
||||
#define DoC_Mplus_ECCSyndrome1 0x1041
|
||||
#define DoC_Mplus_ECCSyndrome2 0x1042
|
||||
#define DoC_Mplus_ECCSyndrome3 0x1043
|
||||
#define DoC_Mplus_ECCSyndrome4 0x1044
|
||||
#define DoC_Mplus_ECCSyndrome5 0x1045
|
||||
#define DoC_Mplus_ECCConf 0x1046
|
||||
#define DoC_Mplus_Toggle 0x1046
|
||||
#define DoC_Mplus_DownloadStatus 0x1074
|
||||
#define DoC_Mplus_CtrlConfirm 0x1076
|
||||
#define DoC_Mplus_Power 0x1fff
|
||||
|
||||
/* How to access the device?
|
||||
* On ARM, it'll be mmap'd directly with 32-bit wide accesses.
|
||||
* On PPC, it's mmap'd and 16-bit wide.
|
||||
* Others use readb/writeb
|
||||
*/
|
||||
#if defined(__arm__)
|
||||
#define ReadDOC_(adr, reg) ((unsigned char)(*(volatile __u32 *)(((unsigned long)adr)+((reg)<<2))))
|
||||
#define WriteDOC_(d, adr, reg) do{ *(volatile __u32 *)(((unsigned long)adr)+((reg)<<2)) = (__u32)d; wmb();} while(0)
|
||||
#define DOC_IOREMAP_LEN 0x8000
|
||||
#elif defined(__ppc__)
|
||||
#define ReadDOC_(adr, reg) ((unsigned char)(*(volatile __u16 *)(((unsigned long)adr)+((reg)<<1))))
|
||||
#define WriteDOC_(d, adr, reg) do{ *(volatile __u16 *)(((unsigned long)adr)+((reg)<<1)) = (__u16)d; wmb();} while(0)
|
||||
#define DOC_IOREMAP_LEN 0x4000
|
||||
#else
|
||||
#define ReadDOC_(adr, reg) readb((void __iomem *)(adr) + (reg))
|
||||
#define WriteDOC_(d, adr, reg) writeb(d, (void __iomem *)(adr) + (reg))
|
||||
#define DOC_IOREMAP_LEN 0x2000
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
#define USE_MEMCPY
|
||||
#endif
|
||||
|
||||
/* These are provided to directly use the DoC_xxx defines */
|
||||
#define ReadDOC(adr, reg) ReadDOC_(adr,DoC_##reg)
|
||||
#define WriteDOC(d, adr, reg) WriteDOC_(d,adr,DoC_##reg)
|
||||
|
||||
#define DOC_MODE_RESET 0
|
||||
#define DOC_MODE_NORMAL 1
|
||||
#define DOC_MODE_RESERVED1 2
|
||||
#define DOC_MODE_RESERVED2 3
|
||||
|
||||
#define DOC_MODE_CLR_ERR 0x80
|
||||
#define DOC_MODE_RST_LAT 0x10
|
||||
#define DOC_MODE_BDECT 0x08
|
||||
#define DOC_MODE_MDWREN 0x04
|
||||
|
||||
#define DOC_ChipID_Doc2k 0x20
|
||||
#define DOC_ChipID_Doc2kTSOP 0x21 /* internal number for MTD */
|
||||
#define DOC_ChipID_DocMil 0x30
|
||||
#define DOC_ChipID_DocMilPlus32 0x40
|
||||
#define DOC_ChipID_DocMilPlus16 0x41
|
||||
|
||||
#define CDSN_CTRL_FR_B 0x80
|
||||
#define CDSN_CTRL_FR_B0 0x40
|
||||
#define CDSN_CTRL_FR_B1 0x80
|
||||
|
||||
#define CDSN_CTRL_ECC_IO 0x20
|
||||
#define CDSN_CTRL_FLASH_IO 0x10
|
||||
#define CDSN_CTRL_WP 0x08
|
||||
#define CDSN_CTRL_ALE 0x04
|
||||
#define CDSN_CTRL_CLE 0x02
|
||||
#define CDSN_CTRL_CE 0x01
|
||||
|
||||
#define DOC_ECC_RESET 0
|
||||
#define DOC_ECC_ERROR 0x80
|
||||
#define DOC_ECC_RW 0x20
|
||||
#define DOC_ECC__EN 0x08
|
||||
#define DOC_TOGGLE_BIT 0x04
|
||||
#define DOC_ECC_RESV 0x02
|
||||
#define DOC_ECC_IGNORE 0x01
|
||||
|
||||
#define DOC_FLASH_CE 0x80
|
||||
#define DOC_FLASH_WP 0x40
|
||||
#define DOC_FLASH_BANK 0x02
|
||||
|
||||
/* We have to also set the reserved bit 1 for enable */
|
||||
#define DOC_ECC_EN (DOC_ECC__EN | DOC_ECC_RESV)
|
||||
#define DOC_ECC_DIS (DOC_ECC_RESV)
|
||||
|
||||
struct Nand {
|
||||
char floor, chip;
|
||||
unsigned long curadr;
|
||||
unsigned char curmode;
|
||||
/* Also some erase/write/pipeline info when we get that far */
|
||||
};
|
||||
|
||||
#define MAX_FLOORS 4
|
||||
#define MAX_CHIPS 4
|
||||
|
||||
#define MAX_FLOORS_MIL 1
|
||||
#define MAX_CHIPS_MIL 1
|
||||
|
||||
#define MAX_FLOORS_MPLUS 2
|
||||
#define MAX_CHIPS_MPLUS 1
|
||||
|
||||
#define ADDR_COLUMN 1
|
||||
#define ADDR_PAGE 2
|
||||
#define ADDR_COLUMN_PAGE 3
|
||||
|
||||
struct DiskOnChip {
|
||||
unsigned long physadr;
|
||||
void __iomem *virtadr;
|
||||
unsigned long totlen;
|
||||
unsigned char ChipID; /* Type of DiskOnChip */
|
||||
int ioreg;
|
||||
|
||||
unsigned long mfr; /* Flash IDs - only one type of flash per device */
|
||||
unsigned long id;
|
||||
int chipshift;
|
||||
char page256;
|
||||
char pageadrlen;
|
||||
char interleave; /* Internal interleaving - Millennium Plus style */
|
||||
unsigned long erasesize;
|
||||
|
||||
int curfloor;
|
||||
int curchip;
|
||||
|
||||
int numchips;
|
||||
struct Nand *chips;
|
||||
struct mtd_info *nextdoc;
|
||||
/* XXX U-BOOT XXX */
|
||||
#if 0
|
||||
struct mutex lock;
|
||||
#endif
|
||||
};
|
||||
|
||||
int doc_decode_ecc(unsigned char sector[512], unsigned char ecc1[6]);
|
||||
|
||||
/* XXX U-BOOT XXX */
|
||||
#if 1
|
||||
/*
|
||||
* NAND Flash Manufacturer ID Codes
|
||||
*/
|
||||
#define NAND_MFR_TOSHIBA 0x98
|
||||
#define NAND_MFR_SAMSUNG 0xec
|
||||
#endif
|
||||
|
||||
#endif /* __MTD_DOC2000_H__ */
|
||||
@@ -0,0 +1,103 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* Copyright © 2000 Red Hat UK Limited
|
||||
* Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __MTD_FLASHCHIP_H__
|
||||
#define __MTD_FLASHCHIP_H__
|
||||
|
||||
#ifndef __UBOOT__
|
||||
/* For spinlocks. sched.h includes spinlock.h from whichever directory it
|
||||
* happens to be in - so we don't have to care whether we're on 2.2, which
|
||||
* has asm/spinlock.h, or 2.4, which has linux/spinlock.h
|
||||
*/
|
||||
#include <linux/sched.h>
|
||||
#include <linux/mutex.h>
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
FL_READY,
|
||||
FL_STATUS,
|
||||
FL_CFI_QUERY,
|
||||
FL_JEDEC_QUERY,
|
||||
FL_ERASING,
|
||||
FL_ERASE_SUSPENDING,
|
||||
FL_ERASE_SUSPENDED,
|
||||
FL_WRITING,
|
||||
FL_WRITING_TO_BUFFER,
|
||||
FL_OTP_WRITE,
|
||||
FL_WRITE_SUSPENDING,
|
||||
FL_WRITE_SUSPENDED,
|
||||
FL_PM_SUSPENDED,
|
||||
FL_SYNCING,
|
||||
FL_UNLOADING,
|
||||
FL_LOCKING,
|
||||
FL_UNLOCKING,
|
||||
FL_POINT,
|
||||
FL_XIP_WHILE_ERASING,
|
||||
FL_XIP_WHILE_WRITING,
|
||||
FL_SHUTDOWN,
|
||||
/* These 2 come from nand_state_t, which has been unified here */
|
||||
FL_READING,
|
||||
FL_CACHEDPRG,
|
||||
/* These 4 come from onenand_state_t, which has been unified here */
|
||||
FL_RESETING,
|
||||
FL_OTPING,
|
||||
FL_PREPARING_ERASE,
|
||||
FL_VERIFYING_ERASE,
|
||||
|
||||
FL_UNKNOWN
|
||||
} flstate_t;
|
||||
|
||||
|
||||
|
||||
/* NOTE: confusingly, this can be used to refer to more than one chip at a time,
|
||||
if they're interleaved. This can even refer to individual partitions on
|
||||
the same physical chip when present. */
|
||||
|
||||
struct flchip {
|
||||
unsigned long start; /* Offset within the map */
|
||||
// unsigned long len;
|
||||
/* We omit len for now, because when we group them together
|
||||
we insist that they're all of the same size, and the chip size
|
||||
is held in the next level up. If we get more versatile later,
|
||||
it'll make it a damn sight harder to find which chip we want from
|
||||
a given offset, and we'll want to add the per-chip length field
|
||||
back in.
|
||||
*/
|
||||
int ref_point_counter;
|
||||
flstate_t state;
|
||||
flstate_t oldstate;
|
||||
|
||||
unsigned int write_suspended:1;
|
||||
unsigned int erase_suspended:1;
|
||||
unsigned long in_progress_block_addr;
|
||||
|
||||
struct mutex mutex;
|
||||
#ifndef __UBOOT__
|
||||
wait_queue_head_t wq; /* Wait on here when we're waiting for the chip
|
||||
to be ready */
|
||||
#endif
|
||||
int word_write_time;
|
||||
int buffer_write_time;
|
||||
int erase_time;
|
||||
|
||||
int word_write_time_max;
|
||||
int buffer_write_time_max;
|
||||
int erase_time_max;
|
||||
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/* This is used to handle contention on write/erase operations
|
||||
between partitions of the same physical chip. */
|
||||
struct flchip_shared {
|
||||
struct mutex lock;
|
||||
struct flchip *writing;
|
||||
struct flchip *erasing;
|
||||
};
|
||||
|
||||
|
||||
#endif /* __MTD_FLASHCHIP_H__ */
|
||||
@@ -0,0 +1,44 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* FSL UPM NAND driver
|
||||
*
|
||||
* Copyright (C) 2007 MontaVista Software, Inc.
|
||||
* Anton Vorontsov <avorontsov@ru.mvista.com>
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_MTD_NAND_FSL_UPM
|
||||
#define __LINUX_MTD_NAND_FSL_UPM
|
||||
|
||||
#include <linux/mtd/rawnand.h>
|
||||
|
||||
#define FSL_UPM_WAIT_RUN_PATTERN 0x1
|
||||
#define FSL_UPM_WAIT_WRITE_BYTE 0x2
|
||||
#define FSL_UPM_WAIT_WRITE_BUFFER 0x4
|
||||
|
||||
struct fsl_upm {
|
||||
void __iomem *mdr;
|
||||
void __iomem *mxmr;
|
||||
void __iomem *mar;
|
||||
void __iomem *io_addr;
|
||||
};
|
||||
|
||||
struct fsl_upm_nand {
|
||||
struct fsl_upm upm;
|
||||
|
||||
int width;
|
||||
int upm_cmd_offset;
|
||||
int upm_addr_offset;
|
||||
int upm_mar_chip_offset;
|
||||
int wait_flags;
|
||||
int (*dev_ready)(int chip_nr);
|
||||
int chip_delay;
|
||||
int chip_offset;
|
||||
int chip_nr;
|
||||
|
||||
/* no need to fill */
|
||||
int last_ctrl;
|
||||
};
|
||||
|
||||
extern int fsl_upm_nand_init(struct nand_chip *chip, struct fsl_upm_nand *fun);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,84 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* (C) Copyright 2010
|
||||
* Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com.
|
||||
*/
|
||||
|
||||
#ifndef __FSMC_NAND_H__
|
||||
#define __FSMC_NAND_H__
|
||||
|
||||
#include <linux/mtd/rawnand.h>
|
||||
|
||||
struct fsmc_regs {
|
||||
u32 ctrl; /* 0x00 */
|
||||
u8 reserved_1[0x40 - 0x04];
|
||||
u32 pc; /* 0x40 */
|
||||
u32 sts; /* 0x44 */
|
||||
u32 comm; /* 0x48 */
|
||||
u32 attrib; /* 0x4c */
|
||||
u32 ioata; /* 0x50 */
|
||||
u32 ecc1; /* 0x54 */
|
||||
u32 ecc2; /* 0x58 */
|
||||
u32 ecc3; /* 0x5c */
|
||||
u8 reserved_2[0xfe0 - 0x60];
|
||||
u32 peripid0; /* 0xfe0 */
|
||||
u32 peripid1; /* 0xfe4 */
|
||||
u32 peripid2; /* 0xfe8 */
|
||||
u32 peripid3; /* 0xfec */
|
||||
u32 pcellid0; /* 0xff0 */
|
||||
u32 pcellid1; /* 0xff4 */
|
||||
u32 pcellid2; /* 0xff8 */
|
||||
u32 pcellid3; /* 0xffc */
|
||||
};
|
||||
|
||||
/* ctrl register definitions */
|
||||
#define FSMC_WP (1 << 7)
|
||||
|
||||
/* pc register definitions */
|
||||
#define FSMC_RESET (1 << 0)
|
||||
#define FSMC_WAITON (1 << 1)
|
||||
#define FSMC_ENABLE (1 << 2)
|
||||
#define FSMC_DEVTYPE_NAND (1 << 3)
|
||||
#define FSMC_DEVWID_8 (0 << 4)
|
||||
#define FSMC_DEVWID_16 (1 << 4)
|
||||
#define FSMC_ECCEN (1 << 6)
|
||||
#define FSMC_ECCPLEN_512 (0 << 7)
|
||||
#define FSMC_ECCPLEN_256 (1 << 7)
|
||||
#define FSMC_TCLR_1 (1 << 9)
|
||||
#define FSMC_TAR_1 (1 << 13)
|
||||
|
||||
/* sts register definitions */
|
||||
#define FSMC_CODE_RDY (1 << 15)
|
||||
|
||||
/* comm register definitions */
|
||||
#define FSMC_TSET_0 (0 << 0)
|
||||
#define FSMC_TWAIT_6 (6 << 8)
|
||||
#define FSMC_THOLD_4 (4 << 16)
|
||||
#define FSMC_THIZ_1 (1 << 24)
|
||||
|
||||
/* peripid2 register definitions */
|
||||
#define FSMC_REVISION_MSK (0xf)
|
||||
#define FSMC_REVISION_SHFT (0x4)
|
||||
|
||||
#define FSMC_VER8 0x8
|
||||
|
||||
/*
|
||||
* There are 13 bytes of ecc for every 512 byte block and it has to be read
|
||||
* consecutively and immediately after the 512 byte data block for hardware to
|
||||
* generate the error bit offsets
|
||||
* Managing the ecc bytes in the following way is easier. This way is similar to
|
||||
* oobfree structure maintained already in u-boot nand driver
|
||||
*/
|
||||
#define FSMC_MAX_ECCPLACE_ENTRIES 32
|
||||
|
||||
struct fsmc_nand_eccplace {
|
||||
u32 offset;
|
||||
u32 length;
|
||||
};
|
||||
|
||||
struct fsmc_eccplace {
|
||||
struct fsmc_nand_eccplace eccplace[FSMC_MAX_ECCPLACE_ENTRIES];
|
||||
};
|
||||
|
||||
extern int fsmc_nand_init(struct nand_chip *nand);
|
||||
#endif
|
||||
+625
@@ -0,0 +1,625 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org> et al.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __MTD_MTD_H__
|
||||
#define __MTD_MTD_H__
|
||||
|
||||
#ifndef __UBOOT__
|
||||
#include <linux/types.h>
|
||||
#include <linux/uio.h>
|
||||
#include <linux/notifier.h>
|
||||
#include <linux/device.h>
|
||||
|
||||
#include <mtd/mtd-abi.h>
|
||||
|
||||
#include <asm/div64.h>
|
||||
#else
|
||||
#include <linux/compat.h>
|
||||
#include <mtd/mtd-abi.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/list.h>
|
||||
#include <div64.h>
|
||||
#if IS_ENABLED(CONFIG_DM)
|
||||
#include <dm/device.h>
|
||||
#endif
|
||||
|
||||
#define MAX_MTD_DEVICES 32
|
||||
#endif
|
||||
|
||||
#define MTD_ERASE_PENDING 0x01
|
||||
#define MTD_ERASING 0x02
|
||||
#define MTD_ERASE_SUSPEND 0x04
|
||||
#define MTD_ERASE_DONE 0x08
|
||||
#define MTD_ERASE_FAILED 0x10
|
||||
|
||||
#define MTD_FAIL_ADDR_UNKNOWN -1LL
|
||||
|
||||
/*
|
||||
* If the erase fails, fail_addr might indicate exactly which block failed. If
|
||||
* fail_addr = MTD_FAIL_ADDR_UNKNOWN, the failure was not at the device level
|
||||
* or was not specific to any particular block.
|
||||
*/
|
||||
struct erase_info {
|
||||
struct mtd_info *mtd;
|
||||
uint64_t addr;
|
||||
uint64_t len;
|
||||
uint64_t fail_addr;
|
||||
u_long time;
|
||||
u_long retries;
|
||||
unsigned dev;
|
||||
unsigned cell;
|
||||
void (*callback) (struct erase_info *self);
|
||||
u_long priv;
|
||||
u_char state;
|
||||
struct erase_info *next;
|
||||
int scrub;
|
||||
};
|
||||
|
||||
struct mtd_erase_region_info {
|
||||
uint64_t offset; /* At which this region starts, from the beginning of the MTD */
|
||||
uint32_t erasesize; /* For this region */
|
||||
uint32_t numblocks; /* Number of blocks of erasesize in this region */
|
||||
unsigned long *lockmap; /* If keeping bitmap of locks */
|
||||
};
|
||||
|
||||
/**
|
||||
* struct mtd_oob_ops - oob operation operands
|
||||
* @mode: operation mode
|
||||
*
|
||||
* @len: number of data bytes to write/read
|
||||
*
|
||||
* @retlen: number of data bytes written/read
|
||||
*
|
||||
* @ooblen: number of oob bytes to write/read
|
||||
* @oobretlen: number of oob bytes written/read
|
||||
* @ooboffs: offset of oob data in the oob area (only relevant when
|
||||
* mode = MTD_OPS_PLACE_OOB or MTD_OPS_RAW)
|
||||
* @datbuf: data buffer - if NULL only oob data are read/written
|
||||
* @oobbuf: oob data buffer
|
||||
*/
|
||||
struct mtd_oob_ops {
|
||||
unsigned int mode;
|
||||
size_t len;
|
||||
size_t retlen;
|
||||
size_t ooblen;
|
||||
size_t oobretlen;
|
||||
uint32_t ooboffs;
|
||||
uint8_t *datbuf;
|
||||
uint8_t *oobbuf;
|
||||
};
|
||||
|
||||
#ifdef CONFIG_SYS_NAND_MAX_OOBFREE
|
||||
#define MTD_MAX_OOBFREE_ENTRIES_LARGE CONFIG_SYS_NAND_MAX_OOBFREE
|
||||
#else
|
||||
#define MTD_MAX_OOBFREE_ENTRIES_LARGE 32
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SYS_NAND_MAX_ECCPOS
|
||||
#define MTD_MAX_ECCPOS_ENTRIES_LARGE CONFIG_SYS_NAND_MAX_ECCPOS
|
||||
#else
|
||||
#define MTD_MAX_ECCPOS_ENTRIES_LARGE 680
|
||||
#endif
|
||||
/**
|
||||
* struct mtd_oob_region - oob region definition
|
||||
* @offset: region offset
|
||||
* @length: region length
|
||||
*
|
||||
* This structure describes a region of the OOB area, and is used
|
||||
* to retrieve ECC or free bytes sections.
|
||||
* Each section is defined by an offset within the OOB area and a
|
||||
* length.
|
||||
*/
|
||||
struct mtd_oob_region {
|
||||
u32 offset;
|
||||
u32 length;
|
||||
};
|
||||
|
||||
/*
|
||||
* struct mtd_ooblayout_ops - NAND OOB layout operations
|
||||
* @ecc: function returning an ECC region in the OOB area.
|
||||
* Should return -ERANGE if %section exceeds the total number of
|
||||
* ECC sections.
|
||||
* @free: function returning a free region in the OOB area.
|
||||
* Should return -ERANGE if %section exceeds the total number of
|
||||
* free sections.
|
||||
*/
|
||||
struct mtd_ooblayout_ops {
|
||||
int (*ecc)(struct mtd_info *mtd, int section,
|
||||
struct mtd_oob_region *oobecc);
|
||||
int (*free)(struct mtd_info *mtd, int section,
|
||||
struct mtd_oob_region *oobfree);
|
||||
};
|
||||
|
||||
/*
|
||||
* Internal ECC layout control structure. For historical reasons, there is a
|
||||
* similar, smaller struct nand_ecclayout_user (in mtd-abi.h) that is retained
|
||||
* for export to user-space via the ECCGETLAYOUT ioctl.
|
||||
* nand_ecclayout should be expandable in the future simply by the above macros.
|
||||
*/
|
||||
struct nand_ecclayout {
|
||||
__u32 eccbytes;
|
||||
__u32 eccpos[MTD_MAX_ECCPOS_ENTRIES_LARGE];
|
||||
__u32 oobavail;
|
||||
struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES_LARGE];
|
||||
};
|
||||
|
||||
struct module; /* only needed for owner field in mtd_info */
|
||||
|
||||
struct mtd_info {
|
||||
u_char type;
|
||||
uint32_t flags;
|
||||
uint64_t size; // Total size of the MTD
|
||||
|
||||
/* "Major" erase size for the device. Naïve users may take this
|
||||
* to be the only erase size available, or may use the more detailed
|
||||
* information below if they desire
|
||||
*/
|
||||
uint32_t erasesize;
|
||||
/* Minimal writable flash unit size. In case of NOR flash it is 1 (even
|
||||
* though individual bits can be cleared), in case of NAND flash it is
|
||||
* one NAND page (or half, or one-fourths of it), in case of ECC-ed NOR
|
||||
* it is of ECC block size, etc. It is illegal to have writesize = 0.
|
||||
* Any driver registering a struct mtd_info must ensure a writesize of
|
||||
* 1 or larger.
|
||||
*/
|
||||
uint32_t writesize;
|
||||
|
||||
/*
|
||||
* Size of the write buffer used by the MTD. MTD devices having a write
|
||||
* buffer can write multiple writesize chunks at a time. E.g. while
|
||||
* writing 4 * writesize bytes to a device with 2 * writesize bytes
|
||||
* buffer the MTD driver can (but doesn't have to) do 2 writesize
|
||||
* operations, but not 4. Currently, all NANDs have writebufsize
|
||||
* equivalent to writesize (NAND page size). Some NOR flashes do have
|
||||
* writebufsize greater than writesize.
|
||||
*/
|
||||
uint32_t writebufsize;
|
||||
|
||||
uint32_t oobsize; // Amount of OOB data per block (e.g. 16)
|
||||
uint32_t oobavail; // Available OOB bytes per block
|
||||
|
||||
/*
|
||||
* If erasesize is a power of 2 then the shift is stored in
|
||||
* erasesize_shift otherwise erasesize_shift is zero. Ditto writesize.
|
||||
*/
|
||||
unsigned int erasesize_shift;
|
||||
unsigned int writesize_shift;
|
||||
/* Masks based on erasesize_shift and writesize_shift */
|
||||
unsigned int erasesize_mask;
|
||||
unsigned int writesize_mask;
|
||||
|
||||
/*
|
||||
* read ops return -EUCLEAN if max number of bitflips corrected on any
|
||||
* one region comprising an ecc step equals or exceeds this value.
|
||||
* Settable by driver, else defaults to ecc_strength. User can override
|
||||
* in sysfs. N.B. The meaning of the -EUCLEAN return code has changed;
|
||||
* see Documentation/ABI/testing/sysfs-class-mtd for more detail.
|
||||
*/
|
||||
unsigned int bitflip_threshold;
|
||||
|
||||
// Kernel-only stuff starts here.
|
||||
#ifndef __UBOOT__
|
||||
const char *name;
|
||||
#else
|
||||
char *name;
|
||||
#endif
|
||||
int index;
|
||||
|
||||
/* OOB layout description */
|
||||
const struct mtd_ooblayout_ops *ooblayout;
|
||||
|
||||
/* ECC layout structure pointer - read only! */
|
||||
struct nand_ecclayout *ecclayout;
|
||||
|
||||
/* the ecc step size. */
|
||||
unsigned int ecc_step_size;
|
||||
|
||||
/* max number of correctible bit errors per ecc step */
|
||||
unsigned int ecc_strength;
|
||||
|
||||
/* Data for variable erase regions. If numeraseregions is zero,
|
||||
* it means that the whole device has erasesize as given above.
|
||||
*/
|
||||
int numeraseregions;
|
||||
struct mtd_erase_region_info *eraseregions;
|
||||
|
||||
/*
|
||||
* Do not call via these pointers, use corresponding mtd_*()
|
||||
* wrappers instead.
|
||||
*/
|
||||
int (*_erase) (struct mtd_info *mtd, struct erase_info *instr);
|
||||
#ifndef __UBOOT__
|
||||
int (*_point) (struct mtd_info *mtd, loff_t from, size_t len,
|
||||
size_t *retlen, void **virt, resource_size_t *phys);
|
||||
int (*_unpoint) (struct mtd_info *mtd, loff_t from, size_t len);
|
||||
#endif
|
||||
unsigned long (*_get_unmapped_area) (struct mtd_info *mtd,
|
||||
unsigned long len,
|
||||
unsigned long offset,
|
||||
unsigned long flags);
|
||||
int (*_read) (struct mtd_info *mtd, loff_t from, size_t len,
|
||||
size_t *retlen, u_char *buf);
|
||||
int (*_write) (struct mtd_info *mtd, loff_t to, size_t len,
|
||||
size_t *retlen, const u_char *buf);
|
||||
int (*_panic_write) (struct mtd_info *mtd, loff_t to, size_t len,
|
||||
size_t *retlen, const u_char *buf);
|
||||
int (*_read_oob) (struct mtd_info *mtd, loff_t from,
|
||||
struct mtd_oob_ops *ops);
|
||||
int (*_write_oob) (struct mtd_info *mtd, loff_t to,
|
||||
struct mtd_oob_ops *ops);
|
||||
int (*_get_fact_prot_info) (struct mtd_info *mtd, size_t len,
|
||||
size_t *retlen, struct otp_info *buf);
|
||||
int (*_read_fact_prot_reg) (struct mtd_info *mtd, loff_t from,
|
||||
size_t len, size_t *retlen, u_char *buf);
|
||||
int (*_get_user_prot_info) (struct mtd_info *mtd, size_t len,
|
||||
size_t *retlen, struct otp_info *buf);
|
||||
int (*_read_user_prot_reg) (struct mtd_info *mtd, loff_t from,
|
||||
size_t len, size_t *retlen, u_char *buf);
|
||||
int (*_write_user_prot_reg) (struct mtd_info *mtd, loff_t to,
|
||||
size_t len, size_t *retlen, u_char *buf);
|
||||
int (*_lock_user_prot_reg) (struct mtd_info *mtd, loff_t from,
|
||||
size_t len);
|
||||
#ifndef __UBOOT__
|
||||
int (*_writev) (struct mtd_info *mtd, const struct kvec *vecs,
|
||||
unsigned long count, loff_t to, size_t *retlen);
|
||||
#endif
|
||||
void (*_sync) (struct mtd_info *mtd);
|
||||
int (*_lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
|
||||
int (*_unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
|
||||
int (*_is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
|
||||
int (*_block_isreserved) (struct mtd_info *mtd, loff_t ofs);
|
||||
int (*_block_isbad) (struct mtd_info *mtd, loff_t ofs);
|
||||
int (*_block_markbad) (struct mtd_info *mtd, loff_t ofs);
|
||||
#ifndef __UBOOT__
|
||||
int (*_suspend) (struct mtd_info *mtd);
|
||||
void (*_resume) (struct mtd_info *mtd);
|
||||
void (*_reboot) (struct mtd_info *mtd);
|
||||
#endif
|
||||
/*
|
||||
* If the driver is something smart, like UBI, it may need to maintain
|
||||
* its own reference counting. The below functions are only for driver.
|
||||
*/
|
||||
int (*_get_device) (struct mtd_info *mtd);
|
||||
void (*_put_device) (struct mtd_info *mtd);
|
||||
|
||||
#ifndef __UBOOT__
|
||||
/* Backing device capabilities for this device
|
||||
* - provides mmap capabilities
|
||||
*/
|
||||
struct backing_dev_info *backing_dev_info;
|
||||
|
||||
struct notifier_block reboot_notifier; /* default mode before reboot */
|
||||
#endif
|
||||
|
||||
/* ECC status information */
|
||||
struct mtd_ecc_stats ecc_stats;
|
||||
/* Subpage shift (NAND) */
|
||||
int subpage_sft;
|
||||
|
||||
void *priv;
|
||||
|
||||
struct module *owner;
|
||||
#ifndef __UBOOT__
|
||||
struct device dev;
|
||||
#else
|
||||
struct udevice *dev;
|
||||
#endif
|
||||
int usecount;
|
||||
|
||||
/* MTD devices do not have any parent. MTD partitions do. */
|
||||
struct mtd_info *parent;
|
||||
|
||||
/*
|
||||
* Offset of the partition relatively to the parent offset.
|
||||
* Is 0 for real MTD devices (ie. not partitions).
|
||||
*/
|
||||
u64 offset;
|
||||
|
||||
/*
|
||||
* List node used to add an MTD partition to the parent
|
||||
* partition list.
|
||||
*/
|
||||
struct list_head node;
|
||||
|
||||
/*
|
||||
* List of partitions attached to this MTD device (the parent
|
||||
* MTD device can itself be a partition).
|
||||
*/
|
||||
struct list_head partitions;
|
||||
};
|
||||
|
||||
#if IS_ENABLED(CONFIG_DM)
|
||||
static inline void mtd_set_of_node(struct mtd_info *mtd,
|
||||
const struct device_node *np)
|
||||
{
|
||||
mtd->dev->node.np = np;
|
||||
}
|
||||
|
||||
static inline const struct device_node *mtd_get_of_node(struct mtd_info *mtd)
|
||||
{
|
||||
return mtd->dev->node.np;
|
||||
}
|
||||
#else
|
||||
struct device_node;
|
||||
|
||||
static inline void mtd_set_of_node(struct mtd_info *mtd,
|
||||
const struct device_node *np)
|
||||
{
|
||||
}
|
||||
|
||||
static inline const struct device_node *mtd_get_of_node(struct mtd_info *mtd)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline bool mtd_is_partition(const struct mtd_info *mtd)
|
||||
{
|
||||
return mtd->parent;
|
||||
}
|
||||
|
||||
static inline bool mtd_has_partitions(const struct mtd_info *mtd)
|
||||
{
|
||||
return !list_empty(&mtd->partitions);
|
||||
}
|
||||
|
||||
bool mtd_partitions_used(struct mtd_info *master);
|
||||
|
||||
int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,
|
||||
struct mtd_oob_region *oobecc);
|
||||
int mtd_ooblayout_find_eccregion(struct mtd_info *mtd, int eccbyte,
|
||||
int *section,
|
||||
struct mtd_oob_region *oobregion);
|
||||
int mtd_ooblayout_get_eccbytes(struct mtd_info *mtd, u8 *eccbuf,
|
||||
const u8 *oobbuf, int start, int nbytes);
|
||||
int mtd_ooblayout_set_eccbytes(struct mtd_info *mtd, const u8 *eccbuf,
|
||||
u8 *oobbuf, int start, int nbytes);
|
||||
int mtd_ooblayout_free(struct mtd_info *mtd, int section,
|
||||
struct mtd_oob_region *oobfree);
|
||||
int mtd_ooblayout_get_databytes(struct mtd_info *mtd, u8 *databuf,
|
||||
const u8 *oobbuf, int start, int nbytes);
|
||||
int mtd_ooblayout_set_databytes(struct mtd_info *mtd, const u8 *databuf,
|
||||
u8 *oobbuf, int start, int nbytes);
|
||||
int mtd_ooblayout_count_freebytes(struct mtd_info *mtd);
|
||||
int mtd_ooblayout_count_eccbytes(struct mtd_info *mtd);
|
||||
|
||||
static inline void mtd_set_ooblayout(struct mtd_info *mtd,
|
||||
const struct mtd_ooblayout_ops *ooblayout)
|
||||
{
|
||||
mtd->ooblayout = ooblayout;
|
||||
}
|
||||
|
||||
static inline u32 mtd_oobavail(struct mtd_info *mtd, struct mtd_oob_ops *ops)
|
||||
{
|
||||
return ops->mode == MTD_OPS_AUTO_OOB ? mtd->oobavail : mtd->oobsize;
|
||||
}
|
||||
|
||||
int mtd_erase(struct mtd_info *mtd, struct erase_info *instr);
|
||||
#ifndef __UBOOT__
|
||||
int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
|
||||
void **virt, resource_size_t *phys);
|
||||
int mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len);
|
||||
#endif
|
||||
unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, unsigned long len,
|
||||
unsigned long offset, unsigned long flags);
|
||||
int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
|
||||
u_char *buf);
|
||||
int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
|
||||
const u_char *buf);
|
||||
int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
|
||||
const u_char *buf);
|
||||
|
||||
int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops);
|
||||
int mtd_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops);
|
||||
|
||||
int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
|
||||
struct otp_info *buf);
|
||||
int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
|
||||
size_t *retlen, u_char *buf);
|
||||
int mtd_get_user_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
|
||||
struct otp_info *buf);
|
||||
int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len,
|
||||
size_t *retlen, u_char *buf);
|
||||
int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, size_t len,
|
||||
size_t *retlen, u_char *buf);
|
||||
int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len);
|
||||
|
||||
#ifndef __UBOOT__
|
||||
int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
|
||||
unsigned long count, loff_t to, size_t *retlen);
|
||||
#endif
|
||||
|
||||
static inline void mtd_sync(struct mtd_info *mtd)
|
||||
{
|
||||
if (mtd->_sync)
|
||||
mtd->_sync(mtd);
|
||||
}
|
||||
|
||||
int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
|
||||
int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
|
||||
int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len);
|
||||
int mtd_block_isreserved(struct mtd_info *mtd, loff_t ofs);
|
||||
int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs);
|
||||
int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs);
|
||||
|
||||
/*
|
||||
* this interface for iTools and application used.
|
||||
*/
|
||||
struct mtd_info_ex
|
||||
{
|
||||
u_char type; /* chip type MTD_NORFLASH / MTD_NANDFLASH */
|
||||
uint64_t chipsize; /* total size of the nand/spi chip */
|
||||
uint32_t erasesize;
|
||||
uint32_t pagesize;
|
||||
uint32_t numchips; /* number of nand chips */
|
||||
|
||||
uint32_t oobsize;
|
||||
uint32_t addrcycle;
|
||||
uint32_t ecctype;
|
||||
|
||||
u_char ids[8];
|
||||
uint32_t id_length;
|
||||
char name[16]; /* chip names */
|
||||
int hostver; /* host controller version */
|
||||
};
|
||||
|
||||
extern struct mtd_info_ex * get_nand_info(void);
|
||||
extern struct mtd_info_ex * get_spiflash_info(void);
|
||||
#ifndef __UBOOT__
|
||||
static inline int mtd_suspend(struct mtd_info *mtd)
|
||||
{
|
||||
return mtd->_suspend ? mtd->_suspend(mtd) : 0;
|
||||
}
|
||||
|
||||
static inline void mtd_resume(struct mtd_info *mtd)
|
||||
{
|
||||
if (mtd->_resume)
|
||||
mtd->_resume(mtd);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd)
|
||||
{
|
||||
if (mtd->erasesize_shift)
|
||||
return sz >> mtd->erasesize_shift;
|
||||
do_div(sz, mtd->erasesize);
|
||||
return sz;
|
||||
}
|
||||
|
||||
static inline uint32_t mtd_mod_by_eb(uint64_t sz, struct mtd_info *mtd)
|
||||
{
|
||||
if (mtd->erasesize_shift)
|
||||
return sz & mtd->erasesize_mask;
|
||||
return do_div(sz, mtd->erasesize);
|
||||
}
|
||||
|
||||
static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
|
||||
{
|
||||
if (mtd->writesize_shift)
|
||||
return sz >> mtd->writesize_shift;
|
||||
do_div(sz, mtd->writesize);
|
||||
return sz;
|
||||
}
|
||||
|
||||
static inline uint32_t mtd_mod_by_ws(uint64_t sz, struct mtd_info *mtd)
|
||||
{
|
||||
if (mtd->writesize_shift)
|
||||
return sz & mtd->writesize_mask;
|
||||
return do_div(sz, mtd->writesize);
|
||||
}
|
||||
|
||||
static inline int mtd_has_oob(const struct mtd_info *mtd)
|
||||
{
|
||||
return mtd->_read_oob && mtd->_write_oob;
|
||||
}
|
||||
|
||||
static inline int mtd_type_is_nand(const struct mtd_info *mtd)
|
||||
{
|
||||
return mtd->type == MTD_NANDFLASH || mtd->type == MTD_MLCNANDFLASH;
|
||||
}
|
||||
|
||||
static inline int mtd_can_have_bb(const struct mtd_info *mtd)
|
||||
{
|
||||
return !!mtd->_block_isbad;
|
||||
}
|
||||
|
||||
/* Kernel-side ioctl definitions */
|
||||
|
||||
struct mtd_partition;
|
||||
struct mtd_part_parser_data;
|
||||
|
||||
extern int mtd_device_parse_register(struct mtd_info *mtd,
|
||||
const char * const *part_probe_types,
|
||||
struct mtd_part_parser_data *parser_data,
|
||||
const struct mtd_partition *defparts,
|
||||
int defnr_parts);
|
||||
#define mtd_device_register(master, parts, nr_parts) \
|
||||
mtd_device_parse_register(master, NULL, NULL, parts, nr_parts)
|
||||
extern int mtd_device_unregister(struct mtd_info *master);
|
||||
extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
|
||||
extern int __get_mtd_device(struct mtd_info *mtd);
|
||||
extern void __put_mtd_device(struct mtd_info *mtd);
|
||||
extern struct mtd_info *get_mtd_device_nm(const char *name);
|
||||
extern void put_mtd_device(struct mtd_info *mtd);
|
||||
|
||||
|
||||
#ifndef __UBOOT__
|
||||
struct mtd_notifier {
|
||||
void (*add)(struct mtd_info *mtd);
|
||||
void (*remove)(struct mtd_info *mtd);
|
||||
struct list_head list;
|
||||
};
|
||||
|
||||
|
||||
extern void register_mtd_user (struct mtd_notifier *new);
|
||||
extern int unregister_mtd_user (struct mtd_notifier *old);
|
||||
#endif
|
||||
void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size);
|
||||
|
||||
#ifdef CONFIG_MTD_PARTITIONS
|
||||
void mtd_erase_callback(struct erase_info *instr);
|
||||
#else
|
||||
static inline void mtd_erase_callback(struct erase_info *instr)
|
||||
{
|
||||
if (instr->callback)
|
||||
instr->callback(instr);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline int mtd_is_bitflip(int err) {
|
||||
return err == -EUCLEAN;
|
||||
}
|
||||
|
||||
static inline int mtd_is_eccerr(int err) {
|
||||
return err == -EBADMSG;
|
||||
}
|
||||
|
||||
static inline int mtd_is_bitflip_or_eccerr(int err) {
|
||||
return mtd_is_bitflip(err) || mtd_is_eccerr(err);
|
||||
}
|
||||
|
||||
unsigned mtd_mmap_capabilities(struct mtd_info *mtd);
|
||||
|
||||
#ifdef __UBOOT__
|
||||
/* drivers/mtd/mtdcore.h */
|
||||
int add_mtd_device(struct mtd_info *mtd);
|
||||
int del_mtd_device(struct mtd_info *mtd);
|
||||
|
||||
#ifdef CONFIG_MTD_PARTITIONS
|
||||
int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
|
||||
int del_mtd_partitions(struct mtd_info *);
|
||||
#else
|
||||
static inline int add_mtd_partitions(struct mtd_info *mtd,
|
||||
const struct mtd_partition *parts,
|
||||
int nparts)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int del_mtd_partitions(struct mtd_info *mtd)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct mtd_info *__mtd_next_device(int i);
|
||||
#define mtd_for_each_device(mtd) \
|
||||
for ((mtd) = __mtd_next_device(0); \
|
||||
(mtd) != NULL; \
|
||||
(mtd) = __mtd_next_device(mtd->index + 1))
|
||||
|
||||
/* drivers/mtd/mtdcore.c */
|
||||
void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset,
|
||||
const uint64_t length, uint64_t *len_incl_bad,
|
||||
int *truncated);
|
||||
bool mtd_dev_list_updated(void);
|
||||
|
||||
/* drivers/mtd/mtd_uboot.c */
|
||||
int mtd_search_alternate_name(const char *mtdname, char *altname,
|
||||
unsigned int max_len);
|
||||
|
||||
#endif
|
||||
#endif /* __MTD_MTD_H__ */
|
||||
@@ -0,0 +1,734 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Copyright 2017 - Free Electrons
|
||||
*
|
||||
* Authors:
|
||||
* Boris Brezillon <boris.brezillon@free-electrons.com>
|
||||
* Peter Pan <peterpandong@micron.com>
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_MTD_NAND_H
|
||||
#define __LINUX_MTD_NAND_H
|
||||
|
||||
#include <linux/mtd/mtd.h>
|
||||
|
||||
/**
|
||||
* struct nand_memory_organization - Memory organization structure
|
||||
* @bits_per_cell: number of bits per NAND cell
|
||||
* @pagesize: page size
|
||||
* @oobsize: OOB area size
|
||||
* @pages_per_eraseblock: number of pages per eraseblock
|
||||
* @eraseblocks_per_lun: number of eraseblocks per LUN (Logical Unit Number)
|
||||
* @planes_per_lun: number of planes per LUN
|
||||
* @luns_per_target: number of LUN per target (target is a synonym for die)
|
||||
* @ntargets: total number of targets exposed by the NAND device
|
||||
*/
|
||||
struct nand_memory_organization {
|
||||
unsigned int bits_per_cell;
|
||||
unsigned int pagesize;
|
||||
unsigned int oobsize;
|
||||
unsigned int pages_per_eraseblock;
|
||||
unsigned int eraseblocks_per_lun;
|
||||
unsigned int planes_per_lun;
|
||||
unsigned int luns_per_target;
|
||||
unsigned int ntargets;
|
||||
};
|
||||
|
||||
#define NAND_MEMORG(bpc, ps, os, ppe, epl, ppl, lpt, nt) \
|
||||
{ \
|
||||
.bits_per_cell = (bpc), \
|
||||
.pagesize = (ps), \
|
||||
.oobsize = (os), \
|
||||
.pages_per_eraseblock = (ppe), \
|
||||
.eraseblocks_per_lun = (epl), \
|
||||
.planes_per_lun = (ppl), \
|
||||
.luns_per_target = (lpt), \
|
||||
.ntargets = (nt), \
|
||||
}
|
||||
|
||||
/**
|
||||
* struct nand_row_converter - Information needed to convert an absolute offset
|
||||
* into a row address
|
||||
* @lun_addr_shift: position of the LUN identifier in the row address
|
||||
* @eraseblock_addr_shift: position of the eraseblock identifier in the row
|
||||
* address
|
||||
*/
|
||||
struct nand_row_converter {
|
||||
unsigned int lun_addr_shift;
|
||||
unsigned int eraseblock_addr_shift;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct nand_pos - NAND position object
|
||||
* @target: the NAND target/die
|
||||
* @lun: the LUN identifier
|
||||
* @plane: the plane within the LUN
|
||||
* @eraseblock: the eraseblock within the LUN
|
||||
* @page: the page within the LUN
|
||||
*
|
||||
* These information are usually used by specific sub-layers to select the
|
||||
* appropriate target/die and generate a row address to pass to the device.
|
||||
*/
|
||||
struct nand_pos {
|
||||
unsigned int target;
|
||||
unsigned int lun;
|
||||
unsigned int plane;
|
||||
unsigned int eraseblock;
|
||||
unsigned int page;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct nand_page_io_req - NAND I/O request object
|
||||
* @pos: the position this I/O request is targeting
|
||||
* @dataoffs: the offset within the page
|
||||
* @datalen: number of data bytes to read from/write to this page
|
||||
* @databuf: buffer to store data in or get data from
|
||||
* @ooboffs: the OOB offset within the page
|
||||
* @ooblen: the number of OOB bytes to read from/write to this page
|
||||
* @oobbuf: buffer to store OOB data in or get OOB data from
|
||||
* @mode: one of the %MTD_OPS_XXX mode
|
||||
*
|
||||
* This object is used to pass per-page I/O requests to NAND sub-layers. This
|
||||
* way all useful information are already formatted in a useful way and
|
||||
* specific NAND layers can focus on translating these information into
|
||||
* specific commands/operations.
|
||||
*/
|
||||
struct nand_page_io_req {
|
||||
struct nand_pos pos;
|
||||
unsigned int dataoffs;
|
||||
unsigned int datalen;
|
||||
union {
|
||||
const void *out;
|
||||
void *in;
|
||||
} databuf;
|
||||
unsigned int ooboffs;
|
||||
unsigned int ooblen;
|
||||
union {
|
||||
const void *out;
|
||||
void *in;
|
||||
} oobbuf;
|
||||
int mode;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct nand_ecc_req - NAND ECC requirements
|
||||
* @strength: ECC strength
|
||||
* @step_size: ECC step/block size
|
||||
*/
|
||||
struct nand_ecc_req {
|
||||
unsigned int strength;
|
||||
unsigned int step_size;
|
||||
};
|
||||
|
||||
#define NAND_ECCREQ(str, stp) { .strength = (str), .step_size = (stp) }
|
||||
|
||||
/**
|
||||
* struct nand_bbt - bad block table object
|
||||
* @cache: in memory BBT cache
|
||||
*/
|
||||
struct nand_bbt {
|
||||
unsigned long *cache;
|
||||
};
|
||||
|
||||
struct nand_device;
|
||||
|
||||
/**
|
||||
* struct nand_ops - NAND operations
|
||||
* @erase: erase a specific block. No need to check if the block is bad before
|
||||
* erasing, this has been taken care of by the generic NAND layer
|
||||
* @markbad: mark a specific block bad. No need to check if the block is
|
||||
* already marked bad, this has been taken care of by the generic
|
||||
* NAND layer. This method should just write the BBM (Bad Block
|
||||
* Marker) so that future call to struct_nand_ops->isbad() return
|
||||
* true
|
||||
* @isbad: check whether a block is bad or not. This method should just read
|
||||
* the BBM and return whether the block is bad or not based on what it
|
||||
* reads
|
||||
*
|
||||
* These are all low level operations that should be implemented by specialized
|
||||
* NAND layers (SPI NAND, raw NAND, ...).
|
||||
*/
|
||||
struct nand_ops {
|
||||
int (*erase)(struct nand_device *nand, const struct nand_pos *pos);
|
||||
int (*markbad)(struct nand_device *nand, const struct nand_pos *pos);
|
||||
bool (*isbad)(struct nand_device *nand, const struct nand_pos *pos);
|
||||
};
|
||||
|
||||
/**
|
||||
* struct nand_device - NAND device
|
||||
* @mtd: MTD instance attached to the NAND device
|
||||
* @memorg: memory layout
|
||||
* @eccreq: ECC requirements
|
||||
* @rowconv: position to row address converter
|
||||
* @bbt: bad block table info
|
||||
* @ops: NAND operations attached to the NAND device
|
||||
*
|
||||
* Generic NAND object. Specialized NAND layers (raw NAND, SPI NAND, OneNAND)
|
||||
* should declare their own NAND object embedding a nand_device struct (that's
|
||||
* how inheritance is done).
|
||||
* struct_nand_device->memorg and struct_nand_device->eccreq should be filled
|
||||
* at device detection time to reflect the NAND device
|
||||
* capabilities/requirements. Once this is done nanddev_init() can be called.
|
||||
* It will take care of converting NAND information into MTD ones, which means
|
||||
* the specialized NAND layers should never manually tweak
|
||||
* struct_nand_device->mtd except for the ->_read/write() hooks.
|
||||
*/
|
||||
struct nand_device {
|
||||
struct mtd_info *mtd;
|
||||
struct nand_memory_organization memorg;
|
||||
struct nand_ecc_req eccreq;
|
||||
struct nand_row_converter rowconv;
|
||||
struct nand_bbt bbt;
|
||||
const struct nand_ops *ops;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct nand_io_iter - NAND I/O iterator
|
||||
* @req: current I/O request
|
||||
* @oobbytes_per_page: maximum number of OOB bytes per page
|
||||
* @dataleft: remaining number of data bytes to read/write
|
||||
* @oobleft: remaining number of OOB bytes to read/write
|
||||
*
|
||||
* Can be used by specialized NAND layers to iterate over all pages covered
|
||||
* by an MTD I/O request, which should greatly simplifies the boiler-plate
|
||||
* code needed to read/write data from/to a NAND device.
|
||||
*/
|
||||
struct nand_io_iter {
|
||||
struct nand_page_io_req req;
|
||||
unsigned int oobbytes_per_page;
|
||||
unsigned int dataleft;
|
||||
unsigned int oobleft;
|
||||
};
|
||||
|
||||
/**
|
||||
* mtd_to_nanddev() - Get the NAND device attached to the MTD instance
|
||||
* @mtd: MTD instance
|
||||
*
|
||||
* Return: the NAND device embedding @mtd.
|
||||
*/
|
||||
static inline struct nand_device *mtd_to_nanddev(struct mtd_info *mtd)
|
||||
{
|
||||
return mtd->priv;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_to_mtd() - Get the MTD device attached to a NAND device
|
||||
* @nand: NAND device
|
||||
*
|
||||
* Return: the MTD device embedded in @nand.
|
||||
*/
|
||||
static inline struct mtd_info *nanddev_to_mtd(struct nand_device *nand)
|
||||
{
|
||||
return nand->mtd;
|
||||
}
|
||||
|
||||
/*
|
||||
* nanddev_bits_per_cell() - Get the number of bits per cell
|
||||
* @nand: NAND device
|
||||
*
|
||||
* Return: the number of bits per cell.
|
||||
*/
|
||||
static inline unsigned int nanddev_bits_per_cell(const struct nand_device *nand)
|
||||
{
|
||||
return nand->memorg.bits_per_cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_page_size() - Get NAND page size
|
||||
* @nand: NAND device
|
||||
*
|
||||
* Return: the page size.
|
||||
*/
|
||||
static inline size_t nanddev_page_size(const struct nand_device *nand)
|
||||
{
|
||||
return nand->memorg.pagesize;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_per_page_oobsize() - Get NAND OOB size
|
||||
* @nand: NAND device
|
||||
*
|
||||
* Return: the OOB size.
|
||||
*/
|
||||
static inline unsigned int
|
||||
nanddev_per_page_oobsize(const struct nand_device *nand)
|
||||
{
|
||||
return nand->memorg.oobsize;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_pages_per_eraseblock() - Get the number of pages per eraseblock
|
||||
* @nand: NAND device
|
||||
*
|
||||
* Return: the number of pages per eraseblock.
|
||||
*/
|
||||
static inline unsigned int
|
||||
nanddev_pages_per_eraseblock(const struct nand_device *nand)
|
||||
{
|
||||
return nand->memorg.pages_per_eraseblock;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_per_page_oobsize() - Get NAND erase block size
|
||||
* @nand: NAND device
|
||||
*
|
||||
* Return: the eraseblock size.
|
||||
*/
|
||||
static inline size_t nanddev_eraseblock_size(const struct nand_device *nand)
|
||||
{
|
||||
return nand->memorg.pagesize * nand->memorg.pages_per_eraseblock;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_eraseblocks_per_lun() - Get the number of eraseblocks per LUN
|
||||
* @nand: NAND device
|
||||
*
|
||||
* Return: the number of eraseblocks per LUN.
|
||||
*/
|
||||
static inline unsigned int
|
||||
nanddev_eraseblocks_per_lun(const struct nand_device *nand)
|
||||
{
|
||||
return nand->memorg.eraseblocks_per_lun;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_target_size() - Get the total size provided by a single target/die
|
||||
* @nand: NAND device
|
||||
*
|
||||
* Return: the total size exposed by a single target/die in bytes.
|
||||
*/
|
||||
static inline u64 nanddev_target_size(const struct nand_device *nand)
|
||||
{
|
||||
return (u64)nand->memorg.luns_per_target *
|
||||
nand->memorg.eraseblocks_per_lun *
|
||||
nand->memorg.pages_per_eraseblock *
|
||||
nand->memorg.pagesize;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_ntarget() - Get the total of targets
|
||||
* @nand: NAND device
|
||||
*
|
||||
* Return: the number of targets/dies exposed by @nand.
|
||||
*/
|
||||
static inline unsigned int nanddev_ntargets(const struct nand_device *nand)
|
||||
{
|
||||
return nand->memorg.ntargets;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_neraseblocks() - Get the total number of erasablocks
|
||||
* @nand: NAND device
|
||||
*
|
||||
* Return: the total number of eraseblocks exposed by @nand.
|
||||
*/
|
||||
static inline unsigned int nanddev_neraseblocks(const struct nand_device *nand)
|
||||
{
|
||||
return (u64)nand->memorg.luns_per_target *
|
||||
nand->memorg.eraseblocks_per_lun *
|
||||
nand->memorg.pages_per_eraseblock;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_size() - Get NAND size
|
||||
* @nand: NAND device
|
||||
*
|
||||
* Return: the total size (in bytes) exposed by @nand.
|
||||
*/
|
||||
static inline u64 nanddev_size(const struct nand_device *nand)
|
||||
{
|
||||
return nanddev_target_size(nand) * nanddev_ntargets(nand);
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_get_memorg() - Extract memory organization info from a NAND device
|
||||
* @nand: NAND device
|
||||
*
|
||||
* This can be used by the upper layer to fill the memorg info before calling
|
||||
* nanddev_init().
|
||||
*
|
||||
* Return: the memorg object embedded in the NAND device.
|
||||
*/
|
||||
static inline struct nand_memory_organization *
|
||||
nanddev_get_memorg(struct nand_device *nand)
|
||||
{
|
||||
return &nand->memorg;
|
||||
}
|
||||
|
||||
int nanddev_init(struct nand_device *nand, const struct nand_ops *ops,
|
||||
struct module *owner);
|
||||
void nanddev_cleanup(struct nand_device *nand);
|
||||
|
||||
/**
|
||||
* nanddev_register() - Register a NAND device
|
||||
* @nand: NAND device
|
||||
*
|
||||
* Register a NAND device.
|
||||
* This function is just a wrapper around mtd_device_register()
|
||||
* registering the MTD device embedded in @nand.
|
||||
*
|
||||
* Return: 0 in case of success, a negative error code otherwise.
|
||||
*/
|
||||
static inline int nanddev_register(struct nand_device *nand)
|
||||
{
|
||||
return mtd_device_register(nand->mtd, NULL, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_unregister() - Unregister a NAND device
|
||||
* @nand: NAND device
|
||||
*
|
||||
* Unregister a NAND device.
|
||||
* This function is just a wrapper around mtd_device_unregister()
|
||||
* unregistering the MTD device embedded in @nand.
|
||||
*
|
||||
* Return: 0 in case of success, a negative error code otherwise.
|
||||
*/
|
||||
static inline int nanddev_unregister(struct nand_device *nand)
|
||||
{
|
||||
return mtd_device_unregister(nand->mtd);
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_set_of_node() - Attach a DT node to a NAND device
|
||||
* @nand: NAND device
|
||||
* @np: DT node
|
||||
*
|
||||
* Attach a DT node to a NAND device.
|
||||
*/
|
||||
static inline void nanddev_set_of_node(struct nand_device *nand,
|
||||
const struct device_node *np)
|
||||
{
|
||||
mtd_set_of_node(nand->mtd, np);
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_get_of_node() - Retrieve the DT node attached to a NAND device
|
||||
* @nand: NAND device
|
||||
*
|
||||
* Return: the DT node attached to @nand.
|
||||
*/
|
||||
static inline const struct device_node *nanddev_get_of_node(struct nand_device *nand)
|
||||
{
|
||||
return mtd_get_of_node(nand->mtd);
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_offs_to_pos() - Convert an absolute NAND offset into a NAND position
|
||||
* @nand: NAND device
|
||||
* @offs: absolute NAND offset (usually passed by the MTD layer)
|
||||
* @pos: a NAND position object to fill in
|
||||
*
|
||||
* Converts @offs into a nand_pos representation.
|
||||
*
|
||||
* Return: the offset within the NAND page pointed by @pos.
|
||||
*/
|
||||
static inline unsigned int nanddev_offs_to_pos(struct nand_device *nand,
|
||||
loff_t offs,
|
||||
struct nand_pos *pos)
|
||||
{
|
||||
unsigned int pageoffs;
|
||||
u64 tmp = offs;
|
||||
|
||||
pageoffs = do_div(tmp, nand->memorg.pagesize);
|
||||
pos->page = do_div(tmp, nand->memorg.pages_per_eraseblock);
|
||||
pos->eraseblock = do_div(tmp, nand->memorg.eraseblocks_per_lun);
|
||||
pos->plane = pos->eraseblock % nand->memorg.planes_per_lun;
|
||||
pos->lun = do_div(tmp, nand->memorg.luns_per_target);
|
||||
pos->target = tmp;
|
||||
|
||||
return pageoffs;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_pos_cmp() - Compare two NAND positions
|
||||
* @a: First NAND position
|
||||
* @b: Second NAND position
|
||||
*
|
||||
* Compares two NAND positions.
|
||||
*
|
||||
* Return: -1 if @a < @b, 0 if @a == @b and 1 if @a > @b.
|
||||
*/
|
||||
static inline int nanddev_pos_cmp(const struct nand_pos *a,
|
||||
const struct nand_pos *b)
|
||||
{
|
||||
if (a->target != b->target)
|
||||
return a->target < b->target ? -1 : 1;
|
||||
|
||||
if (a->lun != b->lun)
|
||||
return a->lun < b->lun ? -1 : 1;
|
||||
|
||||
if (a->eraseblock != b->eraseblock)
|
||||
return a->eraseblock < b->eraseblock ? -1 : 1;
|
||||
|
||||
if (a->page != b->page)
|
||||
return a->page < b->page ? -1 : 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_pos_to_offs() - Convert a NAND position into an absolute offset
|
||||
* @nand: NAND device
|
||||
* @pos: the NAND position to convert
|
||||
*
|
||||
* Converts @pos NAND position into an absolute offset.
|
||||
*
|
||||
* Return: the absolute offset. Note that @pos points to the beginning of a
|
||||
* page, if one wants to point to a specific offset within this page
|
||||
* the returned offset has to be adjusted manually.
|
||||
*/
|
||||
static inline loff_t nanddev_pos_to_offs(struct nand_device *nand,
|
||||
const struct nand_pos *pos)
|
||||
{
|
||||
unsigned int npages;
|
||||
|
||||
npages = pos->page +
|
||||
((pos->eraseblock +
|
||||
(pos->lun +
|
||||
(pos->target * nand->memorg.luns_per_target)) *
|
||||
nand->memorg.eraseblocks_per_lun) *
|
||||
nand->memorg.pages_per_eraseblock);
|
||||
|
||||
return (loff_t)npages * nand->memorg.pagesize;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_pos_to_row() - Extract a row address from a NAND position
|
||||
* @nand: NAND device
|
||||
* @pos: the position to convert
|
||||
*
|
||||
* Converts a NAND position into a row address that can then be passed to the
|
||||
* device.
|
||||
*
|
||||
* Return: the row address extracted from @pos.
|
||||
*/
|
||||
static inline unsigned int nanddev_pos_to_row(struct nand_device *nand,
|
||||
const struct nand_pos *pos)
|
||||
{
|
||||
return (pos->lun << nand->rowconv.lun_addr_shift) |
|
||||
(pos->eraseblock << nand->rowconv.eraseblock_addr_shift) |
|
||||
pos->page;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_pos_next_target() - Move a position to the next target/die
|
||||
* @nand: NAND device
|
||||
* @pos: the position to update
|
||||
*
|
||||
* Updates @pos to point to the start of the next target/die. Useful when you
|
||||
* want to iterate over all targets/dies of a NAND device.
|
||||
*/
|
||||
static inline void nanddev_pos_next_target(struct nand_device *nand,
|
||||
struct nand_pos *pos)
|
||||
{
|
||||
pos->page = 0;
|
||||
pos->plane = 0;
|
||||
pos->eraseblock = 0;
|
||||
pos->lun = 0;
|
||||
pos->target++;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_pos_next_lun() - Move a position to the next LUN
|
||||
* @nand: NAND device
|
||||
* @pos: the position to update
|
||||
*
|
||||
* Updates @pos to point to the start of the next LUN. Useful when you want to
|
||||
* iterate over all LUNs of a NAND device.
|
||||
*/
|
||||
static inline void nanddev_pos_next_lun(struct nand_device *nand,
|
||||
struct nand_pos *pos)
|
||||
{
|
||||
if (pos->lun >= nand->memorg.luns_per_target - 1)
|
||||
return nanddev_pos_next_target(nand, pos);
|
||||
|
||||
pos->lun++;
|
||||
pos->page = 0;
|
||||
pos->plane = 0;
|
||||
pos->eraseblock = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_pos_next_eraseblock() - Move a position to the next eraseblock
|
||||
* @nand: NAND device
|
||||
* @pos: the position to update
|
||||
*
|
||||
* Updates @pos to point to the start of the next eraseblock. Useful when you
|
||||
* want to iterate over all eraseblocks of a NAND device.
|
||||
*/
|
||||
static inline void nanddev_pos_next_eraseblock(struct nand_device *nand,
|
||||
struct nand_pos *pos)
|
||||
{
|
||||
if (pos->eraseblock >= nand->memorg.eraseblocks_per_lun - 1)
|
||||
return nanddev_pos_next_lun(nand, pos);
|
||||
|
||||
pos->eraseblock++;
|
||||
pos->page = 0;
|
||||
pos->plane = pos->eraseblock % nand->memorg.planes_per_lun;
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_pos_next_eraseblock() - Move a position to the next page
|
||||
* @nand: NAND device
|
||||
* @pos: the position to update
|
||||
*
|
||||
* Updates @pos to point to the start of the next page. Useful when you want to
|
||||
* iterate over all pages of a NAND device.
|
||||
*/
|
||||
static inline void nanddev_pos_next_page(struct nand_device *nand,
|
||||
struct nand_pos *pos)
|
||||
{
|
||||
if (pos->page >= nand->memorg.pages_per_eraseblock - 1)
|
||||
return nanddev_pos_next_eraseblock(nand, pos);
|
||||
|
||||
pos->page++;
|
||||
}
|
||||
|
||||
/**
|
||||
* nand_io_iter_init - Initialize a NAND I/O iterator
|
||||
* @nand: NAND device
|
||||
* @offs: absolute offset
|
||||
* @req: MTD request
|
||||
* @iter: NAND I/O iterator
|
||||
*
|
||||
* Initializes a NAND iterator based on the information passed by the MTD
|
||||
* layer.
|
||||
*/
|
||||
static inline void nanddev_io_iter_init(struct nand_device *nand,
|
||||
loff_t offs, struct mtd_oob_ops *req,
|
||||
struct nand_io_iter *iter)
|
||||
{
|
||||
struct mtd_info *mtd = nanddev_to_mtd(nand);
|
||||
|
||||
iter->req.mode = req->mode;
|
||||
iter->req.dataoffs = nanddev_offs_to_pos(nand, offs, &iter->req.pos);
|
||||
iter->req.ooboffs = req->ooboffs;
|
||||
iter->oobbytes_per_page = mtd_oobavail(mtd, req);
|
||||
iter->dataleft = req->len;
|
||||
iter->oobleft = req->ooblen;
|
||||
iter->req.databuf.in = req->datbuf;
|
||||
iter->req.datalen = min_t(unsigned int,
|
||||
nand->memorg.pagesize - iter->req.dataoffs,
|
||||
iter->dataleft);
|
||||
iter->req.oobbuf.in = req->oobbuf;
|
||||
iter->req.ooblen = min_t(unsigned int,
|
||||
iter->oobbytes_per_page - iter->req.ooboffs,
|
||||
iter->oobleft);
|
||||
}
|
||||
|
||||
/**
|
||||
* nand_io_iter_next_page - Move to the next page
|
||||
* @nand: NAND device
|
||||
* @iter: NAND I/O iterator
|
||||
*
|
||||
* Updates the @iter to point to the next page.
|
||||
*/
|
||||
static inline void nanddev_io_iter_next_page(struct nand_device *nand,
|
||||
struct nand_io_iter *iter)
|
||||
{
|
||||
nanddev_pos_next_page(nand, &iter->req.pos);
|
||||
iter->dataleft -= iter->req.datalen;
|
||||
iter->req.databuf.in += iter->req.datalen;
|
||||
iter->oobleft -= iter->req.ooblen;
|
||||
iter->req.oobbuf.in += iter->req.ooblen;
|
||||
iter->req.dataoffs = 0;
|
||||
iter->req.ooboffs = 0;
|
||||
iter->req.datalen = min_t(unsigned int, nand->memorg.pagesize,
|
||||
iter->dataleft);
|
||||
iter->req.ooblen = min_t(unsigned int, iter->oobbytes_per_page,
|
||||
iter->oobleft);
|
||||
}
|
||||
|
||||
/**
|
||||
* nand_io_iter_end - Should end iteration or not
|
||||
* @nand: NAND device
|
||||
* @iter: NAND I/O iterator
|
||||
*
|
||||
* Check whether @iter has reached the end of the NAND portion it was asked to
|
||||
* iterate on or not.
|
||||
*
|
||||
* Return: true if @iter has reached the end of the iteration request, false
|
||||
* otherwise.
|
||||
*/
|
||||
static inline bool nanddev_io_iter_end(struct nand_device *nand,
|
||||
const struct nand_io_iter *iter)
|
||||
{
|
||||
if (iter->dataleft || iter->oobleft)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* nand_io_for_each_page - Iterate over all NAND pages contained in an MTD I/O
|
||||
* request
|
||||
* @nand: NAND device
|
||||
* @start: start address to read/write from
|
||||
* @req: MTD I/O request
|
||||
* @iter: NAND I/O iterator
|
||||
*
|
||||
* Should be used for iterate over pages that are contained in an MTD request.
|
||||
*/
|
||||
#define nanddev_io_for_each_page(nand, start, req, iter) \
|
||||
for (nanddev_io_iter_init(nand, start, req, iter); \
|
||||
!nanddev_io_iter_end(nand, iter); \
|
||||
nanddev_io_iter_next_page(nand, iter))
|
||||
|
||||
bool nanddev_isbad(struct nand_device *nand, const struct nand_pos *pos);
|
||||
bool nanddev_isreserved(struct nand_device *nand, const struct nand_pos *pos);
|
||||
int nanddev_erase(struct nand_device *nand, const struct nand_pos *pos);
|
||||
int nanddev_markbad(struct nand_device *nand, const struct nand_pos *pos);
|
||||
|
||||
/* BBT related functions */
|
||||
enum nand_bbt_block_status {
|
||||
NAND_BBT_BLOCK_STATUS_UNKNOWN,
|
||||
NAND_BBT_BLOCK_GOOD,
|
||||
NAND_BBT_BLOCK_WORN,
|
||||
NAND_BBT_BLOCK_RESERVED,
|
||||
NAND_BBT_BLOCK_FACTORY_BAD,
|
||||
NAND_BBT_BLOCK_NUM_STATUS,
|
||||
};
|
||||
|
||||
int nanddev_bbt_init(struct nand_device *nand);
|
||||
void nanddev_bbt_cleanup(struct nand_device *nand);
|
||||
int nanddev_bbt_update(struct nand_device *nand);
|
||||
int nanddev_bbt_get_block_status(const struct nand_device *nand,
|
||||
unsigned int entry);
|
||||
int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,
|
||||
enum nand_bbt_block_status status);
|
||||
int nanddev_bbt_markbad(struct nand_device *nand, unsigned int block);
|
||||
|
||||
/**
|
||||
* nanddev_bbt_pos_to_entry() - Convert a NAND position into a BBT entry
|
||||
* @nand: NAND device
|
||||
* @pos: the NAND position we want to get BBT entry for
|
||||
*
|
||||
* Return the BBT entry used to store information about the eraseblock pointed
|
||||
* by @pos.
|
||||
*
|
||||
* Return: the BBT entry storing information about eraseblock pointed by @pos.
|
||||
*/
|
||||
static inline unsigned int nanddev_bbt_pos_to_entry(struct nand_device *nand,
|
||||
const struct nand_pos *pos)
|
||||
{
|
||||
return pos->eraseblock +
|
||||
((pos->lun + (pos->target * nand->memorg.luns_per_target)) *
|
||||
nand->memorg.eraseblocks_per_lun);
|
||||
}
|
||||
|
||||
/**
|
||||
* nanddev_bbt_is_initialized() - Check if the BBT has been initialized
|
||||
* @nand: NAND device
|
||||
*
|
||||
* Return: true if the BBT has been initialized, false otherwise.
|
||||
*/
|
||||
static inline bool nanddev_bbt_is_initialized(struct nand_device *nand)
|
||||
{
|
||||
return !!nand->bbt.cache;
|
||||
}
|
||||
|
||||
/* MTD -> NAND helper functions. */
|
||||
int nanddev_mtd_erase(struct mtd_info *mtd, struct erase_info *einfo);
|
||||
|
||||
#endif /* __LINUX_MTD_NAND_H */
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright © 2011 Ivan Djelic <ivan.djelic@parrot.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This file is the header for the NAND BCH ECC implementation.
|
||||
*/
|
||||
|
||||
#ifndef __MTD_NAND_BCH_H__
|
||||
#define __MTD_NAND_BCH_H__
|
||||
|
||||
struct mtd_info;
|
||||
struct nand_bch_control;
|
||||
|
||||
#if defined(CONFIG_NAND_ECC_BCH)
|
||||
|
||||
static inline int mtd_nand_has_bch(void) { return 1; }
|
||||
|
||||
/*
|
||||
* Calculate BCH ecc code
|
||||
*/
|
||||
int nand_bch_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
|
||||
u_char *ecc_code);
|
||||
|
||||
/*
|
||||
* Detect and correct bit errors
|
||||
*/
|
||||
int nand_bch_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc,
|
||||
u_char *calc_ecc);
|
||||
/*
|
||||
* Initialize BCH encoder/decoder
|
||||
*/
|
||||
struct nand_bch_control *nand_bch_init(struct mtd_info *mtd);
|
||||
/*
|
||||
* Release BCH encoder/decoder resources
|
||||
*/
|
||||
void nand_bch_free(struct nand_bch_control *nbc);
|
||||
|
||||
#else /* !CONFIG_NAND_ECC_BCH */
|
||||
|
||||
static inline int mtd_nand_has_bch(void) { return 0; }
|
||||
|
||||
static inline int
|
||||
nand_bch_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
|
||||
u_char *ecc_code)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int
|
||||
nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf,
|
||||
unsigned char *read_ecc, unsigned char *calc_ecc)
|
||||
{
|
||||
return -ENOTSUPP;
|
||||
}
|
||||
|
||||
static inline struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline void nand_bch_free(struct nand_bch_control *nbc) {}
|
||||
|
||||
#endif /* CONFIG_NAND_ECC_BCH */
|
||||
|
||||
#endif /* __MTD_NAND_BCH_H__ */
|
||||
@@ -0,0 +1,27 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* drivers/mtd/nand_ecc.h
|
||||
*
|
||||
* Copyright (C) 2000-2010 Steven J. Hill <sjhill@realitydiluted.com>
|
||||
* David Woodhouse <dwmw2@infradead.org>
|
||||
* Thomas Gleixner <tglx@linutronix.de>
|
||||
*
|
||||
* This file is the header for the ECC algorithm.
|
||||
*/
|
||||
|
||||
#ifndef __MTD_NAND_ECC_H__
|
||||
#define __MTD_NAND_ECC_H__
|
||||
|
||||
struct mtd_info;
|
||||
|
||||
/*
|
||||
* Calculate 3 byte ECC code for 256 byte block
|
||||
*/
|
||||
int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code);
|
||||
|
||||
/*
|
||||
* Detect and correct a 1 bit error for 256 byte block
|
||||
*/
|
||||
int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc);
|
||||
|
||||
#endif /* __MTD_NAND_ECC_H__ */
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* linux/include/linux/mtd/ndfc.h
|
||||
*
|
||||
* Copyright (c) 2006 Thomas Gleixner <tglx@linutronix.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Info:
|
||||
* Contains defines, datastructures for ndfc nand controller
|
||||
*
|
||||
*/
|
||||
#ifndef __LINUX_MTD_NDFC_H
|
||||
#define __LINUX_MTD_NDFC_H
|
||||
|
||||
/* NDFC Register definitions */
|
||||
#define NDFC_CMD 0x00
|
||||
#define NDFC_ALE 0x04
|
||||
#define NDFC_DATA 0x08
|
||||
#define NDFC_ECC 0x10
|
||||
#define NDFC_BCFG0 0x30
|
||||
#define NDFC_BCFG1 0x34
|
||||
#define NDFC_BCFG2 0x38
|
||||
#define NDFC_BCFG3 0x3c
|
||||
#define NDFC_CCR 0x40
|
||||
#define NDFC_STAT 0x44
|
||||
#define NDFC_HWCTL 0x48
|
||||
#define NDFC_REVID 0x50
|
||||
|
||||
#define NDFC_STAT_IS_READY 0x01000000
|
||||
|
||||
#define NDFC_CCR_RESET_CE 0x80000000 /* CE Reset */
|
||||
#define NDFC_CCR_RESET_ECC 0x40000000 /* ECC Reset */
|
||||
#define NDFC_CCR_RIE 0x20000000 /* Interrupt Enable on Device Rdy */
|
||||
#define NDFC_CCR_REN 0x10000000 /* Enable wait for Rdy in LinearR */
|
||||
#define NDFC_CCR_ROMEN 0x08000000 /* Enable ROM In LinearR */
|
||||
#define NDFC_CCR_ARE 0x04000000 /* Auto-Read Enable */
|
||||
#define NDFC_CCR_BS(x) (((x) & 0x3) << 24) /* Select Bank on CE[x] */
|
||||
#define NDFC_CCR_BS_MASK 0x03000000 /* Select Bank */
|
||||
#define NDFC_CCR_ARAC0 0x00000000 /* 3 Addr, 1 Col 2 Row 512b page */
|
||||
#define NDFC_CCR_ARAC1 0x00001000 /* 4 Addr, 1 Col 3 Row 512b page */
|
||||
#define NDFC_CCR_ARAC2 0x00002000 /* 4 Addr, 2 Col 2 Row 2K page */
|
||||
#define NDFC_CCR_ARAC3 0x00003000 /* 5 Addr, 2 Col 3 Row 2K page */
|
||||
#define NDFC_CCR_ARAC_MASK 0x00003000 /* Auto-Read mode Addr Cycles */
|
||||
#define NDFC_CCR_RPG 0x0000C000 /* Auto-Read Page */
|
||||
#define NDFC_CCR_EBCC 0x00000004 /* EBC Configuration Completed */
|
||||
#define NDFC_CCR_DHC 0x00000002 /* Direct Hardware Control Enable */
|
||||
|
||||
#define NDFC_BxCFG_EN 0x80000000 /* Bank Enable */
|
||||
#define NDFC_BxCFG_CED 0x40000000 /* nCE Style */
|
||||
#define NDFC_BxCFG_SZ_MASK 0x08000000 /* Bank Size */
|
||||
#define NDFC_BxCFG_SZ_8BIT 0x00000000 /* 8bit */
|
||||
#define NDFC_BxCFG_SZ_16BIT 0x08000000 /* 16bit */
|
||||
|
||||
#define NDFC_MAX_BANKS 4
|
||||
|
||||
struct ndfc_controller_settings {
|
||||
uint32_t ccr_settings;
|
||||
uint64_t ndfc_erpn;
|
||||
};
|
||||
|
||||
struct ndfc_chip_settings {
|
||||
uint32_t bank_settings;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,79 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* (C) Copyright 2010-2011 Texas Instruments, <www.ti.com>
|
||||
* Mansoor Ahamed <mansoor.ahamed@ti.com>
|
||||
*
|
||||
* Derived from work done by Rohit Choraria <rohitkc@ti.com> for omap3
|
||||
*/
|
||||
#ifndef __ASM_ARCH_ELM_H
|
||||
#define __ASM_ARCH_ELM_H
|
||||
/*
|
||||
* ELM Module Registers
|
||||
*/
|
||||
|
||||
/* ELM registers bit fields */
|
||||
#define ELM_SYSCONFIG_SOFTRESET_MASK (0x2)
|
||||
#define ELM_SYSCONFIG_SOFTRESET (0x2)
|
||||
#define ELM_SYSSTATUS_RESETDONE_MASK (0x1)
|
||||
#define ELM_SYSSTATUS_RESETDONE (0x1)
|
||||
#define ELM_LOCATION_CONFIG_ECC_BCH_LEVEL_MASK (0x3)
|
||||
#define ELM_LOCATION_CONFIG_ECC_SIZE_MASK (0x7FF0000)
|
||||
#define ELM_LOCATION_CONFIG_ECC_SIZE_POS (16)
|
||||
#define ELM_SYNDROME_FRAGMENT_6_SYNDROME_VALID (0x00010000)
|
||||
#define ELM_LOCATION_STATUS_ECC_CORRECTABLE_MASK (0x100)
|
||||
#define ELM_LOCATION_STATUS_ECC_NB_ERRORS_MASK (0x1F)
|
||||
|
||||
#define ELM_MAX_CHANNELS 8
|
||||
#define ELM_MAX_ERROR_COUNT 16
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
enum bch_level {
|
||||
BCH_4_BIT = 0,
|
||||
BCH_8_BIT,
|
||||
BCH_16_BIT
|
||||
};
|
||||
|
||||
|
||||
/* BCH syndrome registers */
|
||||
struct syndrome {
|
||||
u32 syndrome_fragment_x[7]; /* 0x400, 0x404.... 0x418 */
|
||||
u8 res1[36]; /* 0x41c */
|
||||
};
|
||||
|
||||
/* BCH error status & location register */
|
||||
struct location {
|
||||
u32 location_status; /* 0x800 */
|
||||
u8 res1[124]; /* 0x804 */
|
||||
u32 error_location_x[ELM_MAX_ERROR_COUNT]; /* 0x880, 0x980, .. */
|
||||
u8 res2[64]; /* 0x8c0 */
|
||||
};
|
||||
|
||||
/* BCH ELM register map - do not try to allocate memmory for this structure.
|
||||
* We have used plenty of reserved variables to fill the slots in the ELM
|
||||
* register memory map.
|
||||
* Directly initialize the struct pointer to ELM base address.
|
||||
*/
|
||||
struct elm {
|
||||
u32 rev; /* 0x000 */
|
||||
u8 res1[12]; /* 0x004 */
|
||||
u32 sysconfig; /* 0x010 */
|
||||
u32 sysstatus; /* 0x014 */
|
||||
u32 irqstatus; /* 0x018 */
|
||||
u32 irqenable; /* 0x01c */
|
||||
u32 location_config; /* 0x020 */
|
||||
u8 res2[92]; /* 0x024 */
|
||||
u32 page_ctrl; /* 0x080 */
|
||||
u8 res3[892]; /* 0x084 */
|
||||
struct syndrome syndrome_fragments[ELM_MAX_CHANNELS]; /* 0x400,0x420 */
|
||||
u8 res4[512]; /* 0x600 */
|
||||
struct location error_location[ELM_MAX_CHANNELS]; /* 0x800,0x900 ... */
|
||||
};
|
||||
|
||||
int elm_check_error(u8 *syndrome, enum bch_level bch_type, u32 *error_count,
|
||||
u32 *error_locations);
|
||||
int elm_config(enum bch_level level);
|
||||
void elm_reset(void);
|
||||
void elm_init(void);
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ASM_ARCH_ELM_H */
|
||||
@@ -0,0 +1,97 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* (C) Copyright 2004-2008 Texas Instruments, <www.ti.com>
|
||||
* Rohit Choraria <rohitkc@ti.com>
|
||||
*
|
||||
* (C) Copyright 2013 Andreas Bießmann <andreas@biessmann.org>
|
||||
*/
|
||||
#ifndef __ASM_OMAP_GPMC_H
|
||||
#define __ASM_OMAP_GPMC_H
|
||||
|
||||
#define GPMC_BUF_EMPTY 0
|
||||
#define GPMC_BUF_FULL 1
|
||||
#define GPMC_MAX_SECTORS 8
|
||||
|
||||
enum omap_ecc {
|
||||
/* 1-bit ECC calculation by Software, Error detection by Software */
|
||||
OMAP_ECC_HAM1_CODE_SW = 1, /* avoid un-initialized int can be 0x0 */
|
||||
/* 1-bit ECC calculation by GPMC, Error detection by Software */
|
||||
/* ECC layout compatible to legacy ROMCODE. */
|
||||
OMAP_ECC_HAM1_CODE_HW,
|
||||
/* 4-bit ECC calculation by GPMC, Error detection by Software */
|
||||
OMAP_ECC_BCH4_CODE_HW_DETECTION_SW,
|
||||
/* 4-bit ECC calculation by GPMC, Error detection by ELM */
|
||||
OMAP_ECC_BCH4_CODE_HW,
|
||||
/* 8-bit ECC calculation by GPMC, Error detection by Software */
|
||||
OMAP_ECC_BCH8_CODE_HW_DETECTION_SW,
|
||||
/* 8-bit ECC calculation by GPMC, Error detection by ELM */
|
||||
OMAP_ECC_BCH8_CODE_HW,
|
||||
/* 16-bit ECC calculation by GPMC, Error detection by ELM */
|
||||
OMAP_ECC_BCH16_CODE_HW,
|
||||
};
|
||||
|
||||
struct gpmc_cs {
|
||||
u32 config1; /* 0x00 */
|
||||
u32 config2; /* 0x04 */
|
||||
u32 config3; /* 0x08 */
|
||||
u32 config4; /* 0x0C */
|
||||
u32 config5; /* 0x10 */
|
||||
u32 config6; /* 0x14 */
|
||||
u32 config7; /* 0x18 */
|
||||
u32 nand_cmd; /* 0x1C */
|
||||
u32 nand_adr; /* 0x20 */
|
||||
u32 nand_dat; /* 0x24 */
|
||||
u8 res[8]; /* blow up to 0x30 byte */
|
||||
};
|
||||
|
||||
struct bch_res_0_3 {
|
||||
u32 bch_result_x[4];
|
||||
};
|
||||
|
||||
struct bch_res_4_6 {
|
||||
u32 bch_result_x[3];
|
||||
};
|
||||
|
||||
struct gpmc {
|
||||
u8 res1[0x10];
|
||||
u32 sysconfig; /* 0x10 */
|
||||
u8 res2[0x4];
|
||||
u32 irqstatus; /* 0x18 */
|
||||
u32 irqenable; /* 0x1C */
|
||||
u8 res3[0x20];
|
||||
u32 timeout_control; /* 0x40 */
|
||||
u8 res4[0xC];
|
||||
u32 config; /* 0x50 */
|
||||
u32 status; /* 0x54 */
|
||||
u8 res5[0x8]; /* 0x58 */
|
||||
struct gpmc_cs cs[8]; /* 0x60, 0x90, .. */
|
||||
u32 prefetch_config1; /* 0x1E0 */
|
||||
u32 prefetch_config2; /* 0x1E4 */
|
||||
u32 res6; /* 0x1E8 */
|
||||
u32 prefetch_control; /* 0x1EC */
|
||||
u32 prefetch_status; /* 0x1F0 */
|
||||
u32 ecc_config; /* 0x1F4 */
|
||||
u32 ecc_control; /* 0x1F8 */
|
||||
u32 ecc_size_config; /* 0x1FC */
|
||||
u32 ecc1_result; /* 0x200 */
|
||||
u32 ecc2_result; /* 0x204 */
|
||||
u32 ecc3_result; /* 0x208 */
|
||||
u32 ecc4_result; /* 0x20C */
|
||||
u32 ecc5_result; /* 0x210 */
|
||||
u32 ecc6_result; /* 0x214 */
|
||||
u32 ecc7_result; /* 0x218 */
|
||||
u32 ecc8_result; /* 0x21C */
|
||||
u32 ecc9_result; /* 0x220 */
|
||||
u8 res7[12]; /* 0x224 */
|
||||
u32 testmomde_ctrl; /* 0x230 */
|
||||
u8 res8[12]; /* 0x234 */
|
||||
struct bch_res_0_3 bch_result_0_3[GPMC_MAX_SECTORS]; /* 0x240,0x250, */
|
||||
u8 res9[16 * 4]; /* 0x2C0 - 0x2FF */
|
||||
struct bch_res_4_6 bch_result_4_6[GPMC_MAX_SECTORS]; /* 0x300,0x310, */
|
||||
};
|
||||
|
||||
/* Used for board specific gpmc initialization */
|
||||
extern const struct gpmc *gpmc_cfg;
|
||||
extern char gpmc_cs0_flash;
|
||||
|
||||
#endif /* __ASM_OMAP_GPMC_H */
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* linux/include/linux/mtd/onenand.h
|
||||
*
|
||||
* Copyright (C) 2005-2007 Samsung Electronics
|
||||
* Kyungmin Park <kyungmin.park@samsung.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_MTD_ONENAND_H
|
||||
#define __LINUX_MTD_ONENAND_H
|
||||
|
||||
#include <linux/mtd/onenand_regs.h>
|
||||
|
||||
/* Note: The header order is impoertant */
|
||||
#include <onenand_uboot.h>
|
||||
|
||||
#include <linux/compat.h>
|
||||
#include <linux/mtd/bbm.h>
|
||||
|
||||
#define MAX_DIES 2
|
||||
#define MAX_BUFFERRAM 2
|
||||
#define MAX_ONENAND_PAGESIZE (4096 + 128)
|
||||
|
||||
/* Scan and identify a OneNAND device */
|
||||
extern int onenand_scan (struct mtd_info *mtd, int max_chips);
|
||||
/* Free resources held by the OneNAND device */
|
||||
extern void onenand_release (struct mtd_info *mtd);
|
||||
|
||||
/**
|
||||
* struct onenand_bufferram - OneNAND BufferRAM Data
|
||||
* @param blockpage block & page address in BufferRAM
|
||||
*/
|
||||
struct onenand_bufferram {
|
||||
int blockpage;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct onenand_chip - OneNAND Private Flash Chip Data
|
||||
* @param base [BOARDSPECIFIC] address to access OneNAND
|
||||
* @dies: [INTERN][FLEXONENAND] number of dies on chip
|
||||
* @boundary: [INTERN][FLEXONENAND] Boundary of the dies
|
||||
* @diesize: [INTERN][FLEXONENAND] Size of the dies
|
||||
* @param chipsize [INTERN] the size of one chip for multichip arrays
|
||||
* @param device_id [INTERN] device ID
|
||||
* @param verstion_id [INTERN] version ID
|
||||
* @technology [INTERN] describes the internal NAND array technology such as SLC or MLC.
|
||||
* @density_mask: [INTERN] chip density, used for DDP devices
|
||||
* @param options [BOARDSPECIFIC] various chip options. They can partly be set to inform onenand_scan about
|
||||
* @param erase_shift [INTERN] number of address bits in a block
|
||||
* @param page_shift [INTERN] number of address bits in a page
|
||||
* @param ppb_shift [INTERN] number of address bits in a pages per block
|
||||
* @param page_mask [INTERN] a page per block mask
|
||||
* @param writesize [INTERN] a real page size
|
||||
* @param bufferam_index [INTERN] BufferRAM index
|
||||
* @param bufferam [INTERN] BufferRAM info
|
||||
* @param readw [REPLACEABLE] hardware specific function for read short
|
||||
* @param writew [REPLACEABLE] hardware specific function for write short
|
||||
* @param command [REPLACEABLE] hardware specific function for writing commands to the chip
|
||||
* @param wait [REPLACEABLE] hardware specific function for wait on ready
|
||||
* @param read_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area
|
||||
* @param write_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area
|
||||
* @param chip_lock [INTERN] spinlock used to protect access to this structure and the chip
|
||||
* @param wq [INTERN] wait queue to sleep on if a OneNAND operation is in progress
|
||||
* @param state [INTERN] the current state of the OneNAND device
|
||||
* @param autooob [REPLACEABLE] the default (auto)placement scheme
|
||||
* @param priv [OPTIONAL] pointer to private chip date
|
||||
*/
|
||||
struct onenand_chip {
|
||||
void __iomem *base;
|
||||
unsigned int dies;
|
||||
unsigned int boundary[MAX_DIES];
|
||||
unsigned int diesize[MAX_DIES];
|
||||
unsigned int chipsize;
|
||||
unsigned int device_id;
|
||||
unsigned int version_id;
|
||||
unsigned int technology;
|
||||
unsigned int density_mask;
|
||||
unsigned int options;
|
||||
|
||||
unsigned int erase_shift;
|
||||
unsigned int page_shift;
|
||||
unsigned int ppb_shift; /* Pages per block shift */
|
||||
unsigned int page_mask;
|
||||
unsigned int writesize;
|
||||
|
||||
unsigned int bufferram_index;
|
||||
struct onenand_bufferram bufferram[MAX_BUFFERRAM];
|
||||
|
||||
int (*command) (struct mtd_info *mtd, int cmd, loff_t address,
|
||||
size_t len);
|
||||
int (*wait) (struct mtd_info *mtd, int state);
|
||||
int (*bbt_wait) (struct mtd_info *mtd, int state);
|
||||
void (*unlock_all)(struct mtd_info *mtd);
|
||||
int (*read_bufferram) (struct mtd_info *mtd, loff_t addr, int area,
|
||||
unsigned char *buffer, int offset, size_t count);
|
||||
int (*write_bufferram) (struct mtd_info *mtd, loff_t addr, int area,
|
||||
const unsigned char *buffer, int offset,
|
||||
size_t count);
|
||||
unsigned short (*read_word) (void __iomem *addr);
|
||||
void (*write_word) (unsigned short value, void __iomem *addr);
|
||||
int (*chip_probe)(struct mtd_info *mtd);
|
||||
void (*mmcontrol) (struct mtd_info *mtd, int sync_read);
|
||||
int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
|
||||
int (*scan_bbt)(struct mtd_info *mtd);
|
||||
|
||||
unsigned char *main_buf;
|
||||
unsigned char *spare_buf;
|
||||
#ifdef DONT_USE_UBOOT
|
||||
spinlock_t chip_lock;
|
||||
wait_queue_head_t wq;
|
||||
#endif
|
||||
int state;
|
||||
unsigned char *page_buf;
|
||||
unsigned char *oob_buf;
|
||||
|
||||
struct nand_oobinfo *autooob;
|
||||
int subpagesize;
|
||||
struct nand_ecclayout *ecclayout;
|
||||
|
||||
void *bbm;
|
||||
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/*
|
||||
* Helper macros
|
||||
*/
|
||||
#define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
|
||||
#define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
|
||||
#define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
|
||||
#define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
|
||||
#define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0)
|
||||
#define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1)
|
||||
|
||||
#define FLEXONENAND(this) (this->device_id & DEVICE_IS_FLEXONENAND)
|
||||
#define ONENAND_IS_MLC(this) (this->technology & ONENAND_TECHNOLOGY_IS_MLC)
|
||||
#define ONENAND_IS_DDP(this) \
|
||||
(this->device_id & ONENAND_DEVICE_IS_DDP)
|
||||
|
||||
#define ONENAND_IS_4KB_PAGE(this) \
|
||||
(this->options & ONENAND_HAS_4KB_PAGE)
|
||||
|
||||
#define ONENAND_IS_2PLANE(this) (0)
|
||||
|
||||
/*
|
||||
* Options bits
|
||||
*/
|
||||
#define ONENAND_HAS_CONT_LOCK (0x0001)
|
||||
#define ONENAND_HAS_UNLOCK_ALL (0x0002)
|
||||
#define ONENAND_HAS_2PLANE (0x0004)
|
||||
#define ONENAND_HAS_4KB_PAGE (0x0008)
|
||||
#define ONENAND_RUNTIME_BADBLOCK_CHECK (0x0200)
|
||||
#define ONENAND_PAGEBUF_ALLOC (0x1000)
|
||||
#define ONENAND_OOBBUF_ALLOC (0x2000)
|
||||
|
||||
/*
|
||||
* OneNAND Flash Manufacturer ID Codes
|
||||
*/
|
||||
#define ONENAND_MFR_NUMONYX 0x20
|
||||
#define ONENAND_MFR_SAMSUNG 0xec
|
||||
|
||||
/**
|
||||
* struct nand_manufacturers - NAND Flash Manufacturer ID Structure
|
||||
* @param name: Manufacturer name
|
||||
* @param id: manufacturer ID code of device.
|
||||
*/
|
||||
struct onenand_manufacturers {
|
||||
int id;
|
||||
char *name;
|
||||
};
|
||||
|
||||
int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
|
||||
struct mtd_oob_ops *ops);
|
||||
|
||||
unsigned int onenand_block(struct onenand_chip *this, loff_t addr);
|
||||
int flexonenand_region(struct mtd_info *mtd, loff_t addr);
|
||||
#endif /* __LINUX_MTD_ONENAND_H */
|
||||
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* linux/include/linux/mtd/onenand_regs.h
|
||||
*
|
||||
* OneNAND Register header file
|
||||
*
|
||||
* Copyright (C) 2005-2007 Samsung Electronics
|
||||
* Kyungmin Park <kyungmin.park@samsung.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#ifndef __ONENAND_REG_H
|
||||
#define __ONENAND_REG_H
|
||||
|
||||
/* Memory Address Map Translation (Word order) */
|
||||
#define ONENAND_MEMORY_MAP(x) ((x) << 1)
|
||||
|
||||
/*
|
||||
* External BufferRAM area
|
||||
*/
|
||||
#define ONENAND_BOOTRAM ONENAND_MEMORY_MAP(0x0000)
|
||||
#define ONENAND_DATARAM ONENAND_MEMORY_MAP(0x0200)
|
||||
#define ONENAND_SPARERAM ONENAND_MEMORY_MAP(0x8010)
|
||||
|
||||
/*
|
||||
* OneNAND Registers
|
||||
*/
|
||||
#define ONENAND_REG_MANUFACTURER_ID ONENAND_MEMORY_MAP(0xF000)
|
||||
#define ONENAND_REG_DEVICE_ID ONENAND_MEMORY_MAP(0xF001)
|
||||
#define ONENAND_REG_VERSION_ID ONENAND_MEMORY_MAP(0xF002)
|
||||
#define ONENAND_REG_DATA_BUFFER_SIZE ONENAND_MEMORY_MAP(0xF003)
|
||||
#define ONENAND_REG_BOOT_BUFFER_SIZE ONENAND_MEMORY_MAP(0xF004)
|
||||
#define ONENAND_REG_NUM_BUFFERS ONENAND_MEMORY_MAP(0xF005)
|
||||
#define ONENAND_REG_TECHNOLOGY ONENAND_MEMORY_MAP(0xF006)
|
||||
|
||||
#define ONENAND_REG_START_ADDRESS1 ONENAND_MEMORY_MAP(0xF100)
|
||||
#define ONENAND_REG_START_ADDRESS2 ONENAND_MEMORY_MAP(0xF101)
|
||||
#define ONENAND_REG_START_ADDRESS3 ONENAND_MEMORY_MAP(0xF102)
|
||||
#define ONENAND_REG_START_ADDRESS4 ONENAND_MEMORY_MAP(0xF103)
|
||||
#define ONENAND_REG_START_ADDRESS5 ONENAND_MEMORY_MAP(0xF104)
|
||||
#define ONENAND_REG_START_ADDRESS6 ONENAND_MEMORY_MAP(0xF105)
|
||||
#define ONENAND_REG_START_ADDRESS7 ONENAND_MEMORY_MAP(0xF106)
|
||||
#define ONENAND_REG_START_ADDRESS8 ONENAND_MEMORY_MAP(0xF107)
|
||||
|
||||
#define ONENAND_REG_START_BUFFER ONENAND_MEMORY_MAP(0xF200)
|
||||
#define ONENAND_REG_COMMAND ONENAND_MEMORY_MAP(0xF220)
|
||||
#define ONENAND_REG_SYS_CFG1 ONENAND_MEMORY_MAP(0xF221)
|
||||
#define ONENAND_REG_SYS_CFG2 ONENAND_MEMORY_MAP(0xF222)
|
||||
#define ONENAND_REG_CTRL_STATUS ONENAND_MEMORY_MAP(0xF240)
|
||||
#define ONENAND_REG_INTERRUPT ONENAND_MEMORY_MAP(0xF241)
|
||||
#define ONENAND_REG_START_BLOCK_ADDRESS ONENAND_MEMORY_MAP(0xF24C)
|
||||
#define ONENAND_REG_END_BLOCK_ADDRESS ONENAND_MEMORY_MAP(0xF24D)
|
||||
#define ONENAND_REG_WP_STATUS ONENAND_MEMORY_MAP(0xF24E)
|
||||
|
||||
#define ONENAND_REG_ECC_STATUS ONENAND_MEMORY_MAP(0xFF00)
|
||||
#define ONENAND_REG_ECC_M0 ONENAND_MEMORY_MAP(0xFF01)
|
||||
#define ONENAND_REG_ECC_S0 ONENAND_MEMORY_MAP(0xFF02)
|
||||
#define ONENAND_REG_ECC_M1 ONENAND_MEMORY_MAP(0xFF03)
|
||||
#define ONENAND_REG_ECC_S1 ONENAND_MEMORY_MAP(0xFF04)
|
||||
#define ONENAND_REG_ECC_M2 ONENAND_MEMORY_MAP(0xFF05)
|
||||
#define ONENAND_REG_ECC_S2 ONENAND_MEMORY_MAP(0xFF06)
|
||||
#define ONENAND_REG_ECC_M3 ONENAND_MEMORY_MAP(0xFF07)
|
||||
#define ONENAND_REG_ECC_S3 ONENAND_MEMORY_MAP(0xFF08)
|
||||
|
||||
/*
|
||||
* Device ID Register F001h (R)
|
||||
*/
|
||||
#define DEVICE_IS_FLEXONENAND (1 << 9)
|
||||
#define FLEXONENAND_PI_MASK (0x3ff)
|
||||
#define FLEXONENAND_PI_UNLOCK_SHIFT (14)
|
||||
#define ONENAND_DEVICE_DENSITY_MASK (0xf)
|
||||
#define ONENAND_DEVICE_DENSITY_SHIFT (4)
|
||||
#define ONENAND_DEVICE_IS_DDP (1 << 3)
|
||||
#define ONENAND_DEVICE_IS_DEMUX (1 << 2)
|
||||
#define ONENAND_DEVICE_VCC_MASK (0x3)
|
||||
|
||||
#define ONENAND_DEVICE_DENSITY_512Mb (0x002)
|
||||
#define ONENAND_DEVICE_DENSITY_1Gb (0x003)
|
||||
#define ONENAND_DEVICE_DENSITY_2Gb (0x004)
|
||||
#define ONENAND_DEVICE_DENSITY_4Gb (0x005)
|
||||
|
||||
/*
|
||||
* Version ID Register F002h (R)
|
||||
*/
|
||||
#define ONENAND_VERSION_PROCESS_SHIFT (8)
|
||||
|
||||
/*
|
||||
* Technology Register F006h (R)
|
||||
*/
|
||||
#define ONENAND_TECHNOLOGY_IS_MLC (1 << 0)
|
||||
|
||||
/*
|
||||
* Start Address 1 F100h (R/W)
|
||||
*/
|
||||
#define ONENAND_DDP_SHIFT (15)
|
||||
#define ONENAND_DDP_CHIP0 (0)
|
||||
#define ONENAND_DDP_CHIP1 (1 << ONENAND_DDP_SHIFT)
|
||||
|
||||
/*
|
||||
* Start Address 8 F107h (R/W)
|
||||
*/
|
||||
#define ONENAND_FPA_MASK (0x7f)
|
||||
#define ONENAND_FPA_SHIFT (2)
|
||||
#define ONENAND_FSA_MASK (0x03)
|
||||
|
||||
/*
|
||||
* Start Buffer Register F200h (R/W)
|
||||
*/
|
||||
#define ONENAND_BSA_MASK (0x03)
|
||||
#define ONENAND_BSA_SHIFT (8)
|
||||
#define ONENAND_BSA_BOOTRAM (0 << 2)
|
||||
#define ONENAND_BSA_DATARAM0 (2 << 2)
|
||||
#define ONENAND_BSA_DATARAM1 (3 << 2)
|
||||
#define ONENAND_BSC_MASK (0x07)
|
||||
|
||||
/*
|
||||
* Command Register F220h (R/W)
|
||||
*/
|
||||
#define ONENAND_CMD_READ (0x00)
|
||||
#define ONENAND_CMD_READOOB (0x13)
|
||||
#define ONENAND_CMD_PROG (0x80)
|
||||
#define ONENAND_CMD_PROGOOB (0x1A)
|
||||
#define ONENAND_CMD_2X_PROG (0x7D)
|
||||
#define ONENAND_CMD_2X_CACHE_PROG (0x7F)
|
||||
#define ONENAND_CMD_UNLOCK (0x23)
|
||||
#define ONENAND_CMD_LOCK (0x2A)
|
||||
#define ONENAND_CMD_LOCK_TIGHT (0x2C)
|
||||
#define ONENAND_CMD_UNLOCK_ALL (0x27)
|
||||
#define ONENAND_CMD_ERASE (0x94)
|
||||
#define ONENAND_CMD_MULTIBLOCK_ERASE (0x95)
|
||||
#define ONENAND_CMD_ERASE_VERIFY (0x71)
|
||||
#define ONENAND_CMD_RESET (0xF0)
|
||||
#define ONENAND_CMD_READID (0x90)
|
||||
#define FLEXONENAND_CMD_RESET (0xF3)
|
||||
#define FLEXONENAND_CMD_PI_UPDATE (0x05)
|
||||
#define FLEXONENAND_CMD_PI_ACCESS (0x66)
|
||||
#define FLEXONENAND_CMD_RECOVER_LSB (0x05)
|
||||
|
||||
/* NOTE: Those are not *REAL* commands */
|
||||
#define ONENAND_CMD_BUFFERRAM (0x1978)
|
||||
#define FLEXONENAND_CMD_READ_PI (0x1985)
|
||||
|
||||
/*
|
||||
* System Configuration 1 Register F221h (R, R/W)
|
||||
*/
|
||||
#define ONENAND_SYS_CFG1_SYNC_READ (1 << 15)
|
||||
#define ONENAND_SYS_CFG1_BRL_7 (7 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_6 (6 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_5 (5 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_4 (4 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_3 (3 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_10 (2 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_9 (1 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_8 (0 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_SHIFT (12)
|
||||
#define ONENAND_SYS_CFG1_BL_32 (4 << 9)
|
||||
#define ONENAND_SYS_CFG1_BL_16 (3 << 9)
|
||||
#define ONENAND_SYS_CFG1_BL_8 (2 << 9)
|
||||
#define ONENAND_SYS_CFG1_BL_4 (1 << 9)
|
||||
#define ONENAND_SYS_CFG1_BL_CONT (0 << 9)
|
||||
#define ONENAND_SYS_CFG1_BL_SHIFT (9)
|
||||
#define ONENAND_SYS_CFG1_NO_ECC (1 << 8)
|
||||
#define ONENAND_SYS_CFG1_RDY (1 << 7)
|
||||
#define ONENAND_SYS_CFG1_INT (1 << 6)
|
||||
#define ONENAND_SYS_CFG1_IOBE (1 << 5)
|
||||
#define ONENAND_SYS_CFG1_RDY_CONF (1 << 4)
|
||||
|
||||
/*
|
||||
* Controller Status Register F240h (R)
|
||||
*/
|
||||
#define ONENAND_CTRL_ONGO (1 << 15)
|
||||
#define ONENAND_CTRL_LOCK (1 << 14)
|
||||
#define ONENAND_CTRL_LOAD (1 << 13)
|
||||
#define ONENAND_CTRL_PROGRAM (1 << 12)
|
||||
#define ONENAND_CTRL_ERASE (1 << 11)
|
||||
#define ONENAND_CTRL_ERROR (1 << 10)
|
||||
#define ONENAND_CTRL_RSTB (1 << 7)
|
||||
|
||||
/*
|
||||
* Interrupt Status Register F241h (R)
|
||||
*/
|
||||
#define ONENAND_INT_MASTER (1 << 15)
|
||||
#define ONENAND_INT_READ (1 << 7)
|
||||
#define ONENAND_INT_WRITE (1 << 6)
|
||||
#define ONENAND_INT_ERASE (1 << 5)
|
||||
#define ONENAND_INT_RESET (1 << 4)
|
||||
#define ONENAND_INT_CLEAR (0 << 0)
|
||||
|
||||
/*
|
||||
* NAND Flash Write Protection Status Register F24Eh (R)
|
||||
*/
|
||||
#define ONENAND_WP_US (1 << 2)
|
||||
#define ONENAND_WP_LS (1 << 1)
|
||||
#define ONENAND_WP_LTS (1 << 0)
|
||||
|
||||
/*
|
||||
* ECC Status Reigser FF00h (R)
|
||||
*/
|
||||
#define ONENAND_ECC_1BIT (1 << 0)
|
||||
#define ONENAND_ECC_1BIT_ALL (0x5555)
|
||||
#define ONENAND_ECC_2BIT (1 << 1)
|
||||
#define ONENAND_ECC_2BIT_ALL (0xAAAA)
|
||||
#define ONENAND_ECC_4BIT_UNCORRECTABLE (0x1010)
|
||||
#define FLEXONENAND_UNCORRECTABLE_ERROR (0x1010)
|
||||
|
||||
#endif /* __ONENAND_REG_H */
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* MTD partitioning layer definitions
|
||||
*
|
||||
* (C) 2000 Nicolas Pitre <nico@fluxnic.net>
|
||||
*
|
||||
* This code is GPL
|
||||
*/
|
||||
|
||||
#ifndef MTD_PARTITIONS_H
|
||||
#define MTD_PARTITIONS_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
|
||||
/*
|
||||
* Partition definition structure:
|
||||
*
|
||||
* An array of struct partition is passed along with a MTD object to
|
||||
* mtd_device_register() to create them.
|
||||
*
|
||||
* For each partition, these fields are available:
|
||||
* name: string that will be used to label the partition's MTD device.
|
||||
* size: the partition size; if defined as MTDPART_SIZ_FULL, the partition
|
||||
* will extend to the end of the master MTD device.
|
||||
* offset: absolute starting position within the master MTD device; if
|
||||
* defined as MTDPART_OFS_APPEND, the partition will start where the
|
||||
* previous one ended; if MTDPART_OFS_NXTBLK, at the next erase block;
|
||||
* if MTDPART_OFS_RETAIN, consume as much as possible, leaving size
|
||||
* after the end of partition.
|
||||
* mask_flags: contains flags that have to be masked (removed) from the
|
||||
* master MTD flag set for the corresponding MTD partition.
|
||||
* For example, to force a read-only partition, simply adding
|
||||
* MTD_WRITEABLE to the mask_flags will do the trick.
|
||||
*
|
||||
* Note: writeable partitions require their size and offset be
|
||||
* erasesize aligned (e.g. use MTDPART_OFS_NEXTBLK).
|
||||
*/
|
||||
|
||||
struct mtd_partition {
|
||||
const char *name; /* identifier string */
|
||||
uint64_t size; /* partition size */
|
||||
uint64_t offset; /* offset within the master MTD space */
|
||||
uint32_t mask_flags; /* master MTD flags to mask out for this partition */
|
||||
struct nand_ecclayout *ecclayout; /* out of band layout for this partition (NAND only) */
|
||||
};
|
||||
|
||||
#define MTDPART_OFS_RETAIN (-3)
|
||||
#define MTDPART_OFS_NXTBLK (-2)
|
||||
#define MTDPART_OFS_APPEND (-1)
|
||||
#define MTDPART_SIZ_FULL (0)
|
||||
|
||||
|
||||
struct mtd_info;
|
||||
struct device_node;
|
||||
|
||||
#ifndef __UBOOT__
|
||||
/**
|
||||
* struct mtd_part_parser_data - used to pass data to MTD partition parsers.
|
||||
* @origin: for RedBoot, start address of MTD device
|
||||
* @of_node: for OF parsers, device node containing partitioning information
|
||||
*/
|
||||
struct mtd_part_parser_data {
|
||||
unsigned long origin;
|
||||
struct device_node *of_node;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Functions dealing with the various ways of partitioning the space
|
||||
*/
|
||||
|
||||
struct mtd_part_parser {
|
||||
struct list_head list;
|
||||
struct module *owner;
|
||||
const char *name;
|
||||
int (*parse_fn)(struct mtd_info *, struct mtd_partition **,
|
||||
struct mtd_part_parser_data *);
|
||||
};
|
||||
|
||||
extern void register_mtd_parser(struct mtd_part_parser *parser);
|
||||
extern void deregister_mtd_parser(struct mtd_part_parser *parser);
|
||||
#endif
|
||||
|
||||
int mtd_add_partition(struct mtd_info *master, const char *name,
|
||||
long long offset, long long length);
|
||||
int mtd_del_partition(struct mtd_info *master, int partno);
|
||||
uint64_t mtd_get_device_size(const struct mtd_info *mtd);
|
||||
|
||||
#if defined(CONFIG_MTD_PARTITIONS)
|
||||
int mtd_parse_partitions(struct mtd_info *parent, const char **_mtdparts,
|
||||
struct mtd_partition **_parts, int *_nparts);
|
||||
void mtd_free_parsed_partitions(struct mtd_partition *parts,
|
||||
unsigned int nparts);
|
||||
#else
|
||||
static inline int
|
||||
mtd_parse_partitions(struct mtd_info *parent, const char **_mtdparts,
|
||||
struct mtd_partition **_parts, int *_nparts)
|
||||
{
|
||||
*_nparts = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
static inline void
|
||||
mtd_free_parsed_partitions(struct mtd_partition *parts, unsigned int nparts)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif /* defined(MTD_PARTITIONS) */
|
||||
|
||||
#endif
|
||||
+1351
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,116 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* Copyright (C) 2005-2009 Samsung Electronics
|
||||
* Minkyu Kang <mk7.kang@samsung.com>
|
||||
* Kyungmin Park <kyungmin.park@samsung.com>
|
||||
*/
|
||||
|
||||
#ifndef __SAMSUNG_ONENAND_H__
|
||||
#define __SAMSUNG_ONENAND_H__
|
||||
|
||||
/*
|
||||
* OneNAND Controller
|
||||
*/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
struct samsung_onenand {
|
||||
unsigned int mem_cfg; /* 0x0000 */
|
||||
unsigned char res1[0xc];
|
||||
unsigned int burst_len; /* 0x0010 */
|
||||
unsigned char res2[0xc];
|
||||
unsigned int mem_reset; /* 0x0020 */
|
||||
unsigned char res3[0xc];
|
||||
unsigned int int_err_stat; /* 0x0030 */
|
||||
unsigned char res4[0xc];
|
||||
unsigned int int_err_mask; /* 0x0040 */
|
||||
unsigned char res5[0xc];
|
||||
unsigned int int_err_ack; /* 0x0050 */
|
||||
unsigned char res6[0xc];
|
||||
unsigned int ecc_err_stat; /* 0x0060 */
|
||||
unsigned char res7[0xc];
|
||||
unsigned int manufact_id; /* 0x0070 */
|
||||
unsigned char res8[0xc];
|
||||
unsigned int device_id; /* 0x0080 */
|
||||
unsigned char res9[0xc];
|
||||
unsigned int data_buf_size; /* 0x0090 */
|
||||
unsigned char res10[0xc];
|
||||
unsigned int boot_buf_size; /* 0x00A0 */
|
||||
unsigned char res11[0xc];
|
||||
unsigned int buf_amount; /* 0x00B0 */
|
||||
unsigned char res12[0xc];
|
||||
unsigned int tech; /* 0x00C0 */
|
||||
unsigned char res13[0xc];
|
||||
unsigned int fba; /* 0x00D0 */
|
||||
unsigned char res14[0xc];
|
||||
unsigned int fpa; /* 0x00E0 */
|
||||
unsigned char res15[0xc];
|
||||
unsigned int fsa; /* 0x00F0 */
|
||||
unsigned char res16[0x3c];
|
||||
unsigned int sync_mode; /* 0x0130 */
|
||||
unsigned char res17[0xc];
|
||||
unsigned int trans_spare; /* 0x0140 */
|
||||
unsigned char res18[0x3c];
|
||||
unsigned int err_page_addr; /* 0x0180 */
|
||||
unsigned char res19[0x1c];
|
||||
unsigned int int_pin_en; /* 0x01A0 */
|
||||
unsigned char res20[0x1c];
|
||||
unsigned int acc_clock; /* 0x01C0 */
|
||||
unsigned char res21[0x1c];
|
||||
unsigned int err_blk_addr; /* 0x01E0 */
|
||||
unsigned char res22[0xc];
|
||||
unsigned int flash_ver_id; /* 0x01F0 */
|
||||
unsigned char res23[0x6c];
|
||||
unsigned int watchdog_cnt_low; /* 0x0260 */
|
||||
unsigned char res24[0xc];
|
||||
unsigned int watchdog_cnt_hi; /* 0x0270 */
|
||||
unsigned char res25[0xc];
|
||||
unsigned int sync_write; /* 0x0280 */
|
||||
unsigned char res26[0x1c];
|
||||
unsigned int cold_reset; /* 0x02A0 */
|
||||
unsigned char res27[0xc];
|
||||
unsigned int ddp_device; /* 0x02B0 */
|
||||
unsigned char res28[0xc];
|
||||
unsigned int multi_plane; /* 0x02C0 */
|
||||
unsigned char res29[0x1c];
|
||||
unsigned int trans_mode; /* 0x02E0 */
|
||||
unsigned char res30[0x1c];
|
||||
unsigned int ecc_err_stat2; /* 0x0300 */
|
||||
unsigned char res31[0xc];
|
||||
unsigned int ecc_err_stat3; /* 0x0310 */
|
||||
unsigned char res32[0xc];
|
||||
unsigned int ecc_err_stat4; /* 0x0320 */
|
||||
unsigned char res33[0x1c];
|
||||
unsigned int dev_page_size; /* 0x0340 */
|
||||
unsigned char res34[0x4c];
|
||||
unsigned int int_mon_status; /* 0x0390 */
|
||||
};
|
||||
#endif
|
||||
|
||||
#define ONENAND_MEM_RESET_HOT 0x3
|
||||
#define ONENAND_MEM_RESET_COLD 0x2
|
||||
#define ONENAND_MEM_RESET_WARM 0x1
|
||||
|
||||
#define INT_ERR_ALL 0x3fff
|
||||
#define CACHE_OP_ERR (1 << 13)
|
||||
#define RST_CMP (1 << 12)
|
||||
#define RDY_ACT (1 << 11)
|
||||
#define INT_ACT (1 << 10)
|
||||
#define UNSUP_CMD (1 << 9)
|
||||
#define LOCKED_BLK (1 << 8)
|
||||
#define BLK_RW_CMP (1 << 7)
|
||||
#define ERS_CMP (1 << 6)
|
||||
#define PGM_CMP (1 << 5)
|
||||
#define LOAD_CMP (1 << 4)
|
||||
#define ERS_FAIL (1 << 3)
|
||||
#define PGM_FAIL (1 << 2)
|
||||
#define INT_TO (1 << 1)
|
||||
#define LD_FAIL_ECC_ERR (1 << 0)
|
||||
|
||||
#define TSRF (1 << 0)
|
||||
|
||||
/* common initialize function */
|
||||
extern void s3c_onenand_init(struct mtd_info *);
|
||||
extern int s5pc110_chip_probe(struct mtd_info *);
|
||||
extern int s5pc210_chip_probe(struct mtd_info *);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,435 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Copyright (C) 2014 Freescale Semiconductor, Inc.
|
||||
* Synced from Linux v4.19
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_MTD_SPI_NOR_H
|
||||
#define __LINUX_MTD_SPI_NOR_H
|
||||
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/mtd/cfi.h>
|
||||
#include <linux/mtd/mtd.h>
|
||||
|
||||
/*
|
||||
* Manufacturer IDs
|
||||
*
|
||||
* The first byte returned from the flash after sending opcode SPINOR_OP_RDID.
|
||||
* Sometimes these are the same as CFI IDs, but sometimes they aren't.
|
||||
*/
|
||||
#define SNOR_MFR_ATMEL CFI_MFR_ATMEL
|
||||
#define SNOR_MFR_GIGADEVICE 0xc8
|
||||
#define SNOR_MFR_INTEL CFI_MFR_INTEL
|
||||
#define SNOR_MFR_ST CFI_MFR_ST /* ST Micro <--> Micron */
|
||||
#define SNOR_MFR_MICRON CFI_MFR_MICRON /* ST Micro <--> Micron */
|
||||
#define SNOR_MFR_MACRONIX CFI_MFR_MACRONIX
|
||||
#define SNOR_MFR_SPANSION CFI_MFR_AMD
|
||||
#define SNOR_MFR_SST CFI_MFR_SST
|
||||
#define SNOR_MFR_WINBOND 0xef /* Also used by some Spansion */
|
||||
|
||||
/*
|
||||
* Note on opcode nomenclature: some opcodes have a format like
|
||||
* SPINOR_OP_FUNCTION{4,}_x_y_z. The numbers x, y, and z stand for the number
|
||||
* of I/O lines used for the opcode, address, and data (respectively). The
|
||||
* FUNCTION has an optional suffix of '4', to represent an opcode which
|
||||
* requires a 4-byte (32-bit) address.
|
||||
*/
|
||||
|
||||
/* Flash opcodes. */
|
||||
#define SPINOR_OP_WREN 0x06 /* Write enable */
|
||||
#define SPINOR_OP_RDSR 0x05 /* Read status register */
|
||||
#define SPINOR_OP_WRSR 0x01 /* Write status register 1 byte */
|
||||
#define SPINOR_OP_RDSR2 0x3f /* Read status register 2 */
|
||||
#define SPINOR_OP_WRSR2 0x3e /* Write status register 2 */
|
||||
#define SPINOR_OP_READ 0x03 /* Read data bytes (low frequency) */
|
||||
#define SPINOR_OP_READ_FAST 0x0b /* Read data bytes (high frequency) */
|
||||
#define SPINOR_OP_READ_1_1_2 0x3b /* Read data bytes (Dual Output SPI) */
|
||||
#define SPINOR_OP_READ_1_2_2 0xbb /* Read data bytes (Dual I/O SPI) */
|
||||
#define SPINOR_OP_READ_1_1_4 0x6b /* Read data bytes (Quad Output SPI) */
|
||||
#define SPINOR_OP_READ_1_4_4 0xeb /* Read data bytes (Quad I/O SPI) */
|
||||
#define SPINOR_OP_PP 0x02 /* Page program (up to 256 bytes) */
|
||||
#define SPINOR_OP_PP_1_1_4 0x32 /* Quad page program */
|
||||
#define SPINOR_OP_PP_1_4_4 0x38 /* Quad page program */
|
||||
#define SPINOR_OP_BE_4K 0x20 /* Erase 4KiB block */
|
||||
#define SPINOR_OP_BE_4K_PMC 0xd7 /* Erase 4KiB block on PMC chips */
|
||||
#define SPINOR_OP_BE_32K 0x52 /* Erase 32KiB block */
|
||||
#define SPINOR_OP_CHIP_ERASE 0xc7 /* Erase whole flash chip */
|
||||
#define SPINOR_OP_SE 0xd8 /* Sector erase (usually 64KiB) */
|
||||
#define SPINOR_OP_RDID 0x9f /* Read JEDEC ID */
|
||||
#define SPINOR_OP_RDSFDP 0x5a /* Read SFDP */
|
||||
#define SPINOR_OP_RDCR 0x35 /* Read configuration register */
|
||||
#define SPINOR_OP_RDFSR 0x70 /* Read flag status register */
|
||||
#define SPINOR_OP_CLFSR 0x50 /* Clear flag status register */
|
||||
#define SPINOR_OP_RDEAR 0xc8 /* Read Extended Address Register */
|
||||
#define SPINOR_OP_WREAR 0xc5 /* Write Extended Address Register */
|
||||
|
||||
/* 4-byte address opcodes - used on Spansion and some Macronix flashes. */
|
||||
#define SPINOR_OP_READ_4B 0x13 /* Read data bytes (low frequency) */
|
||||
#define SPINOR_OP_READ_FAST_4B 0x0c /* Read data bytes (high frequency) */
|
||||
#define SPINOR_OP_READ_1_1_2_4B 0x3c /* Read data bytes (Dual Output SPI) */
|
||||
#define SPINOR_OP_READ_1_2_2_4B 0xbc /* Read data bytes (Dual I/O SPI) */
|
||||
#define SPINOR_OP_READ_1_1_4_4B 0x6c /* Read data bytes (Quad Output SPI) */
|
||||
#define SPINOR_OP_READ_1_4_4_4B 0xec /* Read data bytes (Quad I/O SPI) */
|
||||
#define SPINOR_OP_PP_4B 0x12 /* Page program (up to 256 bytes) */
|
||||
#define SPINOR_OP_PP_1_1_4_4B 0x34 /* Quad page program */
|
||||
#define SPINOR_OP_PP_1_4_4_4B 0x3e /* Quad page program */
|
||||
#define SPINOR_OP_BE_4K_4B 0x21 /* Erase 4KiB block */
|
||||
#define SPINOR_OP_BE_32K_4B 0x5c /* Erase 32KiB block */
|
||||
#define SPINOR_OP_SE_4B 0xdc /* Sector erase (usually 64KiB) */
|
||||
|
||||
/* Double Transfer Rate opcodes - defined in JEDEC JESD216B. */
|
||||
#define SPINOR_OP_READ_1_1_1_DTR 0x0d
|
||||
#define SPINOR_OP_READ_1_2_2_DTR 0xbd
|
||||
#define SPINOR_OP_READ_1_4_4_DTR 0xed
|
||||
|
||||
#define SPINOR_OP_READ_1_1_1_DTR_4B 0x0e
|
||||
#define SPINOR_OP_READ_1_2_2_DTR_4B 0xbe
|
||||
#define SPINOR_OP_READ_1_4_4_DTR_4B 0xee
|
||||
|
||||
/* Used for SST flashes only. */
|
||||
#define SPINOR_OP_BP 0x02 /* Byte program */
|
||||
#define SPINOR_OP_WRDI 0x04 /* Write disable */
|
||||
#define SPINOR_OP_AAI_WP 0xad /* Auto address increment word program */
|
||||
|
||||
/* Used for SST26* flashes only. */
|
||||
#define SPINOR_OP_READ_BPR 0x72 /* Read block protection register */
|
||||
#define SPINOR_OP_WRITE_BPR 0x42 /* Write block protection register */
|
||||
|
||||
/* Used for S3AN flashes only */
|
||||
#define SPINOR_OP_XSE 0x50 /* Sector erase */
|
||||
#define SPINOR_OP_XPP 0x82 /* Page program */
|
||||
#define SPINOR_OP_XRDSR 0xd7 /* Read status register */
|
||||
|
||||
#define XSR_PAGESIZE BIT(0) /* Page size in Po2 or Linear */
|
||||
#define XSR_RDY BIT(7) /* Ready */
|
||||
|
||||
/* Used for Macronix and Winbond flashes. */
|
||||
#define SPINOR_OP_EN4B 0xb7 /* Enter 4-byte mode */
|
||||
#define SPINOR_OP_EX4B 0xe9 /* Exit 4-byte mode */
|
||||
|
||||
/* Used for Spansion flashes only. */
|
||||
#define SPINOR_OP_BRWR 0x17 /* Bank register write */
|
||||
#define SPINOR_OP_BRRD 0x16 /* Bank register read */
|
||||
#define SPINOR_OP_CLSR 0x30 /* Clear status register 1 */
|
||||
|
||||
/* Used for Micron flashes only. */
|
||||
#define SPINOR_OP_RD_EVCR 0x65 /* Read EVCR register */
|
||||
#define SPINOR_OP_WD_EVCR 0x61 /* Write EVCR register */
|
||||
|
||||
/* Status Register bits. */
|
||||
#define SR_WIP BIT(0) /* Write in progress */
|
||||
#define SR_WEL BIT(1) /* Write enable latch */
|
||||
/* meaning of other SR_* bits may differ between vendors */
|
||||
#define SR_BP0 BIT(2) /* Block protect 0 */
|
||||
#define SR_BP1 BIT(3) /* Block protect 1 */
|
||||
#define SR_BP2 BIT(4) /* Block protect 2 */
|
||||
#define SR_TB BIT(5) /* Top/Bottom protect */
|
||||
#define SR_SRWD BIT(7) /* SR write protect */
|
||||
/* Spansion/Cypress specific status bits */
|
||||
#define SR_E_ERR BIT(5)
|
||||
#define SR_P_ERR BIT(6)
|
||||
|
||||
#define SR_QUAD_EN_MX BIT(6) /* Macronix Quad I/O */
|
||||
|
||||
/* Enhanced Volatile Configuration Register bits */
|
||||
#define EVCR_QUAD_EN_MICRON BIT(7) /* Micron Quad I/O */
|
||||
|
||||
/* Flag Status Register bits */
|
||||
#define FSR_READY BIT(7) /* Device status, 0 = Busy, 1 = Ready */
|
||||
#define FSR_E_ERR BIT(5) /* Erase operation status */
|
||||
#define FSR_P_ERR BIT(4) /* Program operation status */
|
||||
#define FSR_PT_ERR BIT(1) /* Protection error bit */
|
||||
|
||||
/* Configuration Register bits. */
|
||||
#define CR_QUAD_EN_SPAN BIT(1) /* Spansion Quad I/O */
|
||||
|
||||
/* Status Register 2 bits. */
|
||||
#define SR2_QUAD_EN_BIT7 BIT(7)
|
||||
|
||||
/* Supported SPI protocols */
|
||||
#define SNOR_PROTO_INST_MASK GENMASK(23, 16)
|
||||
#define SNOR_PROTO_INST_SHIFT 16
|
||||
#define SNOR_PROTO_INST(_nbits) \
|
||||
((((unsigned long)(_nbits)) << SNOR_PROTO_INST_SHIFT) & \
|
||||
SNOR_PROTO_INST_MASK)
|
||||
|
||||
#define SNOR_PROTO_ADDR_MASK GENMASK(15, 8)
|
||||
#define SNOR_PROTO_ADDR_SHIFT 8
|
||||
#define SNOR_PROTO_ADDR(_nbits) \
|
||||
((((unsigned long)(_nbits)) << SNOR_PROTO_ADDR_SHIFT) & \
|
||||
SNOR_PROTO_ADDR_MASK)
|
||||
|
||||
#define SNOR_PROTO_DATA_MASK GENMASK(7, 0)
|
||||
#define SNOR_PROTO_DATA_SHIFT 0
|
||||
#define SNOR_PROTO_DATA(_nbits) \
|
||||
((((unsigned long)(_nbits)) << SNOR_PROTO_DATA_SHIFT) & \
|
||||
SNOR_PROTO_DATA_MASK)
|
||||
|
||||
#define SNOR_PROTO_IS_DTR BIT(24) /* Double Transfer Rate */
|
||||
|
||||
#define SNOR_PROTO_STR(_inst_nbits, _addr_nbits, _data_nbits) \
|
||||
(SNOR_PROTO_INST(_inst_nbits) | \
|
||||
SNOR_PROTO_ADDR(_addr_nbits) | \
|
||||
SNOR_PROTO_DATA(_data_nbits))
|
||||
#define SNOR_PROTO_DTR(_inst_nbits, _addr_nbits, _data_nbits) \
|
||||
(SNOR_PROTO_IS_DTR | \
|
||||
SNOR_PROTO_STR(_inst_nbits, _addr_nbits, _data_nbits))
|
||||
|
||||
enum spi_nor_protocol {
|
||||
SNOR_PROTO_1_1_1 = SNOR_PROTO_STR(1, 1, 1),
|
||||
SNOR_PROTO_1_1_2 = SNOR_PROTO_STR(1, 1, 2),
|
||||
SNOR_PROTO_1_1_4 = SNOR_PROTO_STR(1, 1, 4),
|
||||
SNOR_PROTO_1_1_8 = SNOR_PROTO_STR(1, 1, 8),
|
||||
SNOR_PROTO_1_2_2 = SNOR_PROTO_STR(1, 2, 2),
|
||||
SNOR_PROTO_1_4_4 = SNOR_PROTO_STR(1, 4, 4),
|
||||
SNOR_PROTO_1_8_8 = SNOR_PROTO_STR(1, 8, 8),
|
||||
SNOR_PROTO_2_2_2 = SNOR_PROTO_STR(2, 2, 2),
|
||||
SNOR_PROTO_4_4_4 = SNOR_PROTO_STR(4, 4, 4),
|
||||
SNOR_PROTO_8_8_8 = SNOR_PROTO_STR(8, 8, 8),
|
||||
|
||||
SNOR_PROTO_1_1_1_DTR = SNOR_PROTO_DTR(1, 1, 1),
|
||||
SNOR_PROTO_1_2_2_DTR = SNOR_PROTO_DTR(1, 2, 2),
|
||||
SNOR_PROTO_1_4_4_DTR = SNOR_PROTO_DTR(1, 4, 4),
|
||||
SNOR_PROTO_1_8_8_DTR = SNOR_PROTO_DTR(1, 8, 8),
|
||||
};
|
||||
|
||||
static inline bool spi_nor_protocol_is_dtr(enum spi_nor_protocol proto)
|
||||
{
|
||||
return !!(proto & SNOR_PROTO_IS_DTR);
|
||||
}
|
||||
|
||||
static inline u8 spi_nor_get_protocol_inst_nbits(enum spi_nor_protocol proto)
|
||||
{
|
||||
return ((unsigned long)(proto & SNOR_PROTO_INST_MASK)) >>
|
||||
SNOR_PROTO_INST_SHIFT;
|
||||
}
|
||||
|
||||
static inline u8 spi_nor_get_protocol_addr_nbits(enum spi_nor_protocol proto)
|
||||
{
|
||||
return ((unsigned long)(proto & SNOR_PROTO_ADDR_MASK)) >>
|
||||
SNOR_PROTO_ADDR_SHIFT;
|
||||
}
|
||||
|
||||
static inline u8 spi_nor_get_protocol_data_nbits(enum spi_nor_protocol proto)
|
||||
{
|
||||
return ((unsigned long)(proto & SNOR_PROTO_DATA_MASK)) >>
|
||||
SNOR_PROTO_DATA_SHIFT;
|
||||
}
|
||||
|
||||
static inline u8 spi_nor_get_protocol_width(enum spi_nor_protocol proto)
|
||||
{
|
||||
return spi_nor_get_protocol_data_nbits(proto);
|
||||
}
|
||||
|
||||
#define SPI_NOR_MAX_CMD_SIZE 8
|
||||
enum spi_nor_ops {
|
||||
SPI_NOR_OPS_READ = 0,
|
||||
SPI_NOR_OPS_WRITE,
|
||||
SPI_NOR_OPS_ERASE,
|
||||
SPI_NOR_OPS_LOCK,
|
||||
SPI_NOR_OPS_UNLOCK,
|
||||
};
|
||||
|
||||
enum spi_nor_option_flags {
|
||||
SNOR_F_USE_FSR = BIT(0),
|
||||
SNOR_F_HAS_SR_TB = BIT(1),
|
||||
SNOR_F_NO_OP_CHIP_ERASE = BIT(2),
|
||||
SNOR_F_S3AN_ADDR_DEFAULT = BIT(3),
|
||||
SNOR_F_READY_XSR_RDY = BIT(4),
|
||||
SNOR_F_USE_CLSR = BIT(5),
|
||||
SNOR_F_BROKEN_RESET = BIT(6),
|
||||
};
|
||||
|
||||
/**
|
||||
* struct flash_info - Forward declaration of a structure used internally by
|
||||
* spi_nor_scan()
|
||||
*/
|
||||
struct flash_info;
|
||||
|
||||
/*
|
||||
* TODO: Remove, once all users of spi_flash interface are moved to MTD
|
||||
*
|
||||
* struct spi_flash {
|
||||
* Defined below (keep this text to enable searching for spi_flash decl)
|
||||
* }
|
||||
*/
|
||||
#define spi_flash spi_nor
|
||||
|
||||
/**
|
||||
* struct spi_nor - Structure for defining a the SPI NOR layer
|
||||
* @mtd: point to a mtd_info structure
|
||||
* @lock: the lock for the read/write/erase/lock/unlock operations
|
||||
* @dev: point to a spi device, or a spi nor controller device.
|
||||
* @info: spi-nor part JDEC MFR id and other info
|
||||
* @page_size: the page size of the SPI NOR
|
||||
* @addr_width: number of address bytes
|
||||
* @erase_opcode: the opcode for erasing a sector
|
||||
* @read_opcode: the read opcode
|
||||
* @read_dummy: the dummy needed by the read operation
|
||||
* @program_opcode: the program opcode
|
||||
* @bank_read_cmd: Bank read cmd
|
||||
* @bank_write_cmd: Bank write cmd
|
||||
* @bank_curr: Current flash bank
|
||||
* @sst_write_second: used by the SST write operation
|
||||
* @flags: flag options for the current SPI-NOR (SNOR_F_*)
|
||||
* @read_proto: the SPI protocol for read operations
|
||||
* @write_proto: the SPI protocol for write operations
|
||||
* @reg_proto the SPI protocol for read_reg/write_reg/erase operations
|
||||
* @cmd_buf: used by the write_reg
|
||||
* @prepare: [OPTIONAL] do some preparations for the
|
||||
* read/write/erase/lock/unlock operations
|
||||
* @unprepare: [OPTIONAL] do some post work after the
|
||||
* read/write/erase/lock/unlock operations
|
||||
* @read_reg: [DRIVER-SPECIFIC] read out the register
|
||||
* @write_reg: [DRIVER-SPECIFIC] write data to the register
|
||||
* @read: [DRIVER-SPECIFIC] read data from the SPI NOR
|
||||
* @write: [DRIVER-SPECIFIC] write data to the SPI NOR
|
||||
* @erase: [DRIVER-SPECIFIC] erase a sector of the SPI NOR
|
||||
* at the offset @offs; if not provided by the driver,
|
||||
* spi-nor will send the erase opcode via write_reg()
|
||||
* @flash_lock: [FLASH-SPECIFIC] lock a region of the SPI NOR
|
||||
* @flash_unlock: [FLASH-SPECIFIC] unlock a region of the SPI NOR
|
||||
* @flash_is_locked: [FLASH-SPECIFIC] check if a region of the SPI NOR is
|
||||
* @quad_enable: [FLASH-SPECIFIC] enables SPI NOR quad mode
|
||||
* completely locked
|
||||
* @priv: the private data
|
||||
*/
|
||||
struct spi_nor {
|
||||
struct mtd_info mtd;
|
||||
struct udevice *dev;
|
||||
struct spi_slave *spi;
|
||||
const struct flash_info *info;
|
||||
u32 page_size;
|
||||
u8 addr_width;
|
||||
u8 erase_opcode;
|
||||
u8 read_opcode;
|
||||
u8 read_dummy;
|
||||
u8 program_opcode;
|
||||
#ifdef CONFIG_SPI_FLASH_BAR
|
||||
u8 bank_read_cmd;
|
||||
u8 bank_write_cmd;
|
||||
u8 bank_curr;
|
||||
#endif
|
||||
enum spi_nor_protocol read_proto;
|
||||
enum spi_nor_protocol write_proto;
|
||||
enum spi_nor_protocol reg_proto;
|
||||
bool sst_write_second;
|
||||
u32 flags;
|
||||
u8 cmd_buf[SPI_NOR_MAX_CMD_SIZE];
|
||||
|
||||
int (*prepare)(struct spi_nor *nor, enum spi_nor_ops ops);
|
||||
void (*unprepare)(struct spi_nor *nor, enum spi_nor_ops ops);
|
||||
int (*read_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len);
|
||||
int (*write_reg)(struct spi_nor *nor, u8 opcode, u8 *buf, int len);
|
||||
|
||||
ssize_t (*read)(struct spi_nor *nor, loff_t from,
|
||||
size_t len, u_char *read_buf);
|
||||
ssize_t (*write)(struct spi_nor *nor, loff_t to,
|
||||
size_t len, const u_char *write_buf);
|
||||
int (*erase)(struct spi_nor *nor, loff_t offs);
|
||||
|
||||
#ifdef CONFIG_SPI_BLOCK_PROTECT
|
||||
unsigned int bp_level_max;
|
||||
|
||||
void (*lock)(unsigned char cmp, unsigned char level,
|
||||
unsigned char op);
|
||||
#endif
|
||||
int (*flash_lock)(struct spi_nor *nor, loff_t ofs, uint64_t len);
|
||||
int (*flash_unlock)(struct spi_nor *nor, loff_t ofs, uint64_t len);
|
||||
int (*flash_is_locked)(struct spi_nor *nor, loff_t ofs, uint64_t len);
|
||||
int (*quad_enable)(struct spi_nor *nor);
|
||||
|
||||
void *priv;
|
||||
/* Compatibility for spi_flash, remove once sf layer is merged with mtd */
|
||||
const char *name;
|
||||
u32 size;
|
||||
u32 sector_size;
|
||||
u32 erase_size;
|
||||
};
|
||||
|
||||
static inline void spi_nor_set_flash_node(struct spi_nor *nor,
|
||||
const struct device_node *np)
|
||||
{
|
||||
mtd_set_of_node(&nor->mtd, np);
|
||||
}
|
||||
|
||||
static inline const struct
|
||||
device_node *spi_nor_get_flash_node(struct spi_nor *nor)
|
||||
{
|
||||
return mtd_get_of_node(&nor->mtd);
|
||||
}
|
||||
|
||||
/**
|
||||
* struct spi_nor_hwcaps - Structure for describing the hardware capabilies
|
||||
* supported by the SPI controller (bus master).
|
||||
* @mask: the bitmask listing all the supported hw capabilies
|
||||
*/
|
||||
struct spi_nor_hwcaps {
|
||||
u32 mask;
|
||||
};
|
||||
|
||||
/*
|
||||
*(Fast) Read capabilities.
|
||||
* MUST be ordered by priority: the higher bit position, the higher priority.
|
||||
* As a matter of performances, it is relevant to use Octo SPI protocols first,
|
||||
* then Quad SPI protocols before Dual SPI protocols, Fast Read and lastly
|
||||
* (Slow) Read.
|
||||
*/
|
||||
#define SNOR_HWCAPS_READ_MASK GENMASK(14, 0)
|
||||
#define SNOR_HWCAPS_READ BIT(0)
|
||||
#define SNOR_HWCAPS_READ_FAST BIT(1)
|
||||
#define SNOR_HWCAPS_READ_1_1_1_DTR BIT(2)
|
||||
|
||||
#define SNOR_HWCAPS_READ_DUAL GENMASK(6, 3)
|
||||
#define SNOR_HWCAPS_READ_1_1_2 BIT(3)
|
||||
#define SNOR_HWCAPS_READ_1_2_2 BIT(4)
|
||||
#define SNOR_HWCAPS_READ_2_2_2 BIT(5)
|
||||
#define SNOR_HWCAPS_READ_1_2_2_DTR BIT(6)
|
||||
|
||||
#define SNOR_HWCAPS_READ_QUAD GENMASK(10, 7)
|
||||
#define SNOR_HWCAPS_READ_1_1_4 BIT(7)
|
||||
#define SNOR_HWCAPS_READ_1_4_4 BIT(8)
|
||||
#define SNOR_HWCAPS_READ_4_4_4 BIT(9)
|
||||
#define SNOR_HWCAPS_READ_1_4_4_DTR BIT(10)
|
||||
|
||||
#define SNOR_HWCPAS_READ_OCTO GENMASK(14, 11)
|
||||
#define SNOR_HWCAPS_READ_1_1_8 BIT(11)
|
||||
#define SNOR_HWCAPS_READ_1_8_8 BIT(12)
|
||||
#define SNOR_HWCAPS_READ_8_8_8 BIT(13)
|
||||
#define SNOR_HWCAPS_READ_1_8_8_DTR BIT(14)
|
||||
|
||||
/*
|
||||
* Page Program capabilities.
|
||||
* MUST be ordered by priority: the higher bit position, the higher priority.
|
||||
* Like (Fast) Read capabilities, Octo/Quad SPI protocols are preferred to the
|
||||
* legacy SPI 1-1-1 protocol.
|
||||
* Note that Dual Page Programs are not supported because there is no existing
|
||||
* JEDEC/SFDP standard to define them. Also at this moment no SPI flash memory
|
||||
* implements such commands.
|
||||
*/
|
||||
#define SNOR_HWCAPS_PP_MASK GENMASK(22, 16)
|
||||
#define SNOR_HWCAPS_PP BIT(16)
|
||||
|
||||
#define SNOR_HWCAPS_PP_QUAD GENMASK(19, 17)
|
||||
#define SNOR_HWCAPS_PP_1_1_4 BIT(17)
|
||||
#define SNOR_HWCAPS_PP_1_4_4 BIT(18)
|
||||
#define SNOR_HWCAPS_PP_4_4_4 BIT(19)
|
||||
|
||||
#define SNOR_HWCAPS_PP_OCTO GENMASK(22, 20)
|
||||
#define SNOR_HWCAPS_PP_1_1_8 BIT(20)
|
||||
#define SNOR_HWCAPS_PP_1_8_8 BIT(21)
|
||||
#define SNOR_HWCAPS_PP_8_8_8 BIT(22)
|
||||
|
||||
/**
|
||||
* spi_nor_scan() - scan the SPI NOR
|
||||
* @nor: the spi_nor structure
|
||||
*
|
||||
* The drivers can use this function to scan the SPI NOR.
|
||||
* In the scanning, it will try to get all the necessary information to
|
||||
* fill the mtd_info{} and the spi_nor{}.
|
||||
*
|
||||
* Return: 0 for success, others for failure.
|
||||
*/
|
||||
int spi_nor_scan(struct spi_nor *nor);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,433 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Copyright (c) 2016-2017 Micron Technology, Inc.
|
||||
*
|
||||
* Authors:
|
||||
* Peter Pan <peterpandong@micron.com>
|
||||
*/
|
||||
#ifndef __LINUX_MTD_SPINAND_H
|
||||
#define __LINUX_MTD_SPINAND_H
|
||||
|
||||
#ifndef __UBOOT__
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/mtd/mtd.h>
|
||||
#include <linux/mtd/nand.h>
|
||||
#include <linux/spi/spi.h>
|
||||
#include <linux/spi/spi-mem.h>
|
||||
#else
|
||||
#include <common.h>
|
||||
#include <spi.h>
|
||||
#include <spi-mem.h>
|
||||
#include <linux/mtd/nand.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Standard SPI NAND flash operations
|
||||
*/
|
||||
|
||||
#define SPINAND_RESET_OP \
|
||||
SPI_MEM_OP(SPI_MEM_OP_CMD(0xff, 1), \
|
||||
SPI_MEM_OP_NO_ADDR, \
|
||||
SPI_MEM_OP_NO_DUMMY, \
|
||||
SPI_MEM_OP_NO_DATA)
|
||||
|
||||
#define SPINAND_WR_EN_DIS_OP(enable) \
|
||||
SPI_MEM_OP(SPI_MEM_OP_CMD((enable) ? 0x06 : 0x04, 1), \
|
||||
SPI_MEM_OP_NO_ADDR, \
|
||||
SPI_MEM_OP_NO_DUMMY, \
|
||||
SPI_MEM_OP_NO_DATA)
|
||||
|
||||
#define SPINAND_READID_OP(ndummy, buf, len) \
|
||||
SPI_MEM_OP(SPI_MEM_OP_CMD(0x9f, 1), \
|
||||
SPI_MEM_OP_NO_ADDR, \
|
||||
SPI_MEM_OP_DUMMY(ndummy, 1), \
|
||||
SPI_MEM_OP_DATA_IN(len, buf, 1))
|
||||
|
||||
#define SPINAND_SET_FEATURE_OP(reg, valptr) \
|
||||
SPI_MEM_OP(SPI_MEM_OP_CMD(0x1f, 1), \
|
||||
SPI_MEM_OP_ADDR(1, reg, 1), \
|
||||
SPI_MEM_OP_NO_DUMMY, \
|
||||
SPI_MEM_OP_DATA_OUT(1, valptr, 1))
|
||||
|
||||
#define SPINAND_GET_FEATURE_OP(reg, valptr) \
|
||||
SPI_MEM_OP(SPI_MEM_OP_CMD(0x0f, 1), \
|
||||
SPI_MEM_OP_ADDR(1, reg, 1), \
|
||||
SPI_MEM_OP_NO_DUMMY, \
|
||||
SPI_MEM_OP_DATA_IN(1, valptr, 1))
|
||||
|
||||
#define SPINAND_BLK_ERASE_OP(addr) \
|
||||
SPI_MEM_OP(SPI_MEM_OP_CMD(0xd8, 1), \
|
||||
SPI_MEM_OP_ADDR(3, addr, 1), \
|
||||
SPI_MEM_OP_NO_DUMMY, \
|
||||
SPI_MEM_OP_NO_DATA)
|
||||
|
||||
#define SPINAND_PAGE_READ_OP(addr) \
|
||||
SPI_MEM_OP(SPI_MEM_OP_CMD(0x13, 1), \
|
||||
SPI_MEM_OP_ADDR(3, addr, 1), \
|
||||
SPI_MEM_OP_NO_DUMMY, \
|
||||
SPI_MEM_OP_NO_DATA)
|
||||
|
||||
#define SPINAND_PAGE_READ_FROM_CACHE_OP(fast, addr, ndummy, buf, len) \
|
||||
SPI_MEM_OP(SPI_MEM_OP_CMD(fast ? 0x0b : 0x03, 1), \
|
||||
SPI_MEM_OP_ADDR(2, addr, 1), \
|
||||
SPI_MEM_OP_DUMMY(ndummy, 1), \
|
||||
SPI_MEM_OP_DATA_IN(len, buf, 1))
|
||||
|
||||
#define SPINAND_PAGE_READ_FROM_CACHE_X2_OP(addr, ndummy, buf, len) \
|
||||
SPI_MEM_OP(SPI_MEM_OP_CMD(0x3b, 1), \
|
||||
SPI_MEM_OP_ADDR(2, addr, 1), \
|
||||
SPI_MEM_OP_DUMMY(ndummy, 1), \
|
||||
SPI_MEM_OP_DATA_IN(len, buf, 2))
|
||||
|
||||
#define SPINAND_PAGE_READ_FROM_CACHE_X4_OP(addr, ndummy, buf, len) \
|
||||
SPI_MEM_OP(SPI_MEM_OP_CMD(0x6b, 1), \
|
||||
SPI_MEM_OP_ADDR(2, addr, 1), \
|
||||
SPI_MEM_OP_DUMMY(ndummy, 1), \
|
||||
SPI_MEM_OP_DATA_IN(len, buf, 4))
|
||||
|
||||
#define SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(addr, ndummy, buf, len) \
|
||||
SPI_MEM_OP(SPI_MEM_OP_CMD(0xbb, 1), \
|
||||
SPI_MEM_OP_ADDR(2, addr, 2), \
|
||||
SPI_MEM_OP_DUMMY(ndummy, 2), \
|
||||
SPI_MEM_OP_DATA_IN(len, buf, 2))
|
||||
|
||||
#define SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(addr, ndummy, buf, len) \
|
||||
SPI_MEM_OP(SPI_MEM_OP_CMD(0xeb, 1), \
|
||||
SPI_MEM_OP_ADDR(2, addr, 4), \
|
||||
SPI_MEM_OP_DUMMY(ndummy, 4), \
|
||||
SPI_MEM_OP_DATA_IN(len, buf, 4))
|
||||
|
||||
#define SPINAND_PROG_EXEC_OP(addr) \
|
||||
SPI_MEM_OP(SPI_MEM_OP_CMD(0x10, 1), \
|
||||
SPI_MEM_OP_ADDR(3, addr, 1), \
|
||||
SPI_MEM_OP_NO_DUMMY, \
|
||||
SPI_MEM_OP_NO_DATA)
|
||||
|
||||
#define SPINAND_PROG_LOAD(reset, addr, buf, len) \
|
||||
SPI_MEM_OP(SPI_MEM_OP_CMD(reset ? 0x02 : 0x84, 1), \
|
||||
SPI_MEM_OP_ADDR(2, addr, 1), \
|
||||
SPI_MEM_OP_NO_DUMMY, \
|
||||
SPI_MEM_OP_DATA_OUT(len, buf, 1))
|
||||
|
||||
#define SPINAND_PROG_LOAD_X4(reset, addr, buf, len) \
|
||||
SPI_MEM_OP(SPI_MEM_OP_CMD(reset ? 0x32 : 0x34, 1), \
|
||||
SPI_MEM_OP_ADDR(2, addr, 1), \
|
||||
SPI_MEM_OP_NO_DUMMY, \
|
||||
SPI_MEM_OP_DATA_OUT(len, buf, 4))
|
||||
|
||||
/**
|
||||
* Standard SPI NAND flash commands
|
||||
*/
|
||||
#define SPINAND_CMD_PROG_LOAD_X4 0x32
|
||||
#define SPINAND_CMD_PROG_LOAD_RDM_DATA_X4 0x34
|
||||
|
||||
/* feature register */
|
||||
#define REG_BLOCK_LOCK 0xa0
|
||||
#define BL_ALL_UNLOCKED 0x00
|
||||
|
||||
/* configuration register */
|
||||
#define REG_CFG 0xb0
|
||||
#define CFG_OTP_ENABLE BIT(6)
|
||||
#define CFG_ECC_ENABLE BIT(4)
|
||||
#define CFG_QUAD_ENABLE BIT(0)
|
||||
|
||||
/* status register */
|
||||
#define REG_STATUS 0xc0
|
||||
#define STATUS_BUSY BIT(0)
|
||||
#define STATUS_ERASE_FAILED BIT(2)
|
||||
#define STATUS_PROG_FAILED BIT(3)
|
||||
#define STATUS_ECC_MASK GENMASK(5, 4)
|
||||
#define STATUS_ECC_NO_BITFLIPS (0 << 4)
|
||||
#define STATUS_ECC_HAS_BITFLIPS (1 << 4)
|
||||
#define STATUS_ECC_UNCOR_ERROR (2 << 4)
|
||||
|
||||
struct spinand_op;
|
||||
struct spinand_device;
|
||||
|
||||
#define SPINAND_MAX_ID_LEN 4
|
||||
|
||||
/**
|
||||
* struct spinand_id - SPI NAND id structure
|
||||
* @data: buffer containing the id bytes. Currently 4 bytes large, but can
|
||||
* be extended if required
|
||||
* @len: ID length
|
||||
*
|
||||
* struct_spinand_id->data contains all bytes returned after a READ_ID command,
|
||||
* including dummy bytes if the chip does not emit ID bytes right after the
|
||||
* READ_ID command. The responsibility to extract real ID bytes is left to
|
||||
* struct_manufacurer_ops->detect().
|
||||
*/
|
||||
struct spinand_id {
|
||||
u8 data[SPINAND_MAX_ID_LEN];
|
||||
int len;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct manufacurer_ops - SPI NAND manufacturer specific operations
|
||||
* @detect: detect a SPI NAND device. Every time a SPI NAND device is probed
|
||||
* the core calls the struct_manufacurer_ops->detect() hook of each
|
||||
* registered manufacturer until one of them return 1. Note that
|
||||
* the first thing to check in this hook is that the manufacturer ID
|
||||
* in struct_spinand_device->id matches the manufacturer whose
|
||||
* ->detect() hook has been called. Should return 1 if there's a
|
||||
* match, 0 if the manufacturer ID does not match and a negative
|
||||
* error code otherwise. When true is returned, the core assumes
|
||||
* that properties of the NAND chip (spinand->base.memorg and
|
||||
* spinand->base.eccreq) have been filled
|
||||
* @init: initialize a SPI NAND device
|
||||
* @cleanup: cleanup a SPI NAND device
|
||||
*
|
||||
* Each SPI NAND manufacturer driver should implement this interface so that
|
||||
* NAND chips coming from this vendor can be detected and initialized properly.
|
||||
*/
|
||||
struct spinand_manufacturer_ops {
|
||||
int (*detect)(struct spinand_device *spinand);
|
||||
int (*init)(struct spinand_device *spinand);
|
||||
void (*cleanup)(struct spinand_device *spinand);
|
||||
};
|
||||
|
||||
/**
|
||||
* struct spinand_manufacturer - SPI NAND manufacturer instance
|
||||
* @id: manufacturer ID
|
||||
* @name: manufacturer name
|
||||
* @ops: manufacturer operations
|
||||
*/
|
||||
struct spinand_manufacturer {
|
||||
u8 id;
|
||||
char *name;
|
||||
const struct spinand_manufacturer_ops *ops;
|
||||
};
|
||||
|
||||
/* SPI NAND manufacturers */
|
||||
extern const struct spinand_manufacturer gigadevice_spinand_manufacturer;
|
||||
extern const struct spinand_manufacturer macronix_spinand_manufacturer;
|
||||
extern const struct spinand_manufacturer micron_spinand_manufacturer;
|
||||
extern const struct spinand_manufacturer winbond_spinand_manufacturer;
|
||||
|
||||
/**
|
||||
* struct spinand_op_variants - SPI NAND operation variants
|
||||
* @ops: the list of variants for a given operation
|
||||
* @nops: the number of variants
|
||||
*
|
||||
* Some operations like read-from-cache/write-to-cache have several variants
|
||||
* depending on the number of IO lines you use to transfer data or address
|
||||
* cycles. This structure is a way to describe the different variants supported
|
||||
* by a chip and let the core pick the best one based on the SPI mem controller
|
||||
* capabilities.
|
||||
*/
|
||||
struct spinand_op_variants {
|
||||
const struct spi_mem_op *ops;
|
||||
unsigned int nops;
|
||||
};
|
||||
|
||||
#define SPINAND_OP_VARIANTS(name, ...) \
|
||||
const struct spinand_op_variants name = { \
|
||||
.ops = (struct spi_mem_op[]) { __VA_ARGS__ }, \
|
||||
.nops = sizeof((struct spi_mem_op[]){ __VA_ARGS__ }) / \
|
||||
sizeof(struct spi_mem_op), \
|
||||
}
|
||||
|
||||
/**
|
||||
* spinand_ecc_info - description of the on-die ECC implemented by a SPI NAND
|
||||
* chip
|
||||
* @get_status: get the ECC status. Should return a positive number encoding
|
||||
* the number of corrected bitflips if correction was possible or
|
||||
* -EBADMSG if there are uncorrectable errors. I can also return
|
||||
* other negative error codes if the error is not caused by
|
||||
* uncorrectable bitflips
|
||||
* @ooblayout: the OOB layout used by the on-die ECC implementation
|
||||
*/
|
||||
struct spinand_ecc_info {
|
||||
int (*get_status)(struct spinand_device *spinand, u8 status);
|
||||
const struct mtd_ooblayout_ops *ooblayout;
|
||||
};
|
||||
|
||||
#define SPINAND_HAS_QE_BIT BIT(0)
|
||||
|
||||
/**
|
||||
* struct spinand_info - Structure used to describe SPI NAND chips
|
||||
* @model: model name
|
||||
* @devid: device ID
|
||||
* @flags: OR-ing of the SPINAND_XXX flags
|
||||
* @memorg: memory organization
|
||||
* @eccreq: ECC requirements
|
||||
* @eccinfo: on-die ECC info
|
||||
* @op_variants: operations variants
|
||||
* @op_variants.read_cache: variants of the read-cache operation
|
||||
* @op_variants.write_cache: variants of the write-cache operation
|
||||
* @op_variants.update_cache: variants of the update-cache operation
|
||||
* @select_target: function used to select a target/die. Required only for
|
||||
* multi-die chips
|
||||
*
|
||||
* Each SPI NAND manufacturer driver should have a spinand_info table
|
||||
* describing all the chips supported by the driver.
|
||||
*/
|
||||
struct spinand_info {
|
||||
const char *model;
|
||||
u8 devid;
|
||||
u32 flags;
|
||||
struct nand_memory_organization memorg;
|
||||
struct nand_ecc_req eccreq;
|
||||
struct spinand_ecc_info eccinfo;
|
||||
struct {
|
||||
const struct spinand_op_variants *read_cache;
|
||||
const struct spinand_op_variants *write_cache;
|
||||
const struct spinand_op_variants *update_cache;
|
||||
} op_variants;
|
||||
int (*select_target)(struct spinand_device *spinand,
|
||||
unsigned int target);
|
||||
};
|
||||
|
||||
#define SPINAND_INFO_OP_VARIANTS(__read, __write, __update) \
|
||||
{ \
|
||||
.read_cache = __read, \
|
||||
.write_cache = __write, \
|
||||
.update_cache = __update, \
|
||||
}
|
||||
|
||||
#define SPINAND_ECCINFO(__ooblayout, __get_status) \
|
||||
.eccinfo = { \
|
||||
.ooblayout = __ooblayout, \
|
||||
.get_status = __get_status, \
|
||||
}
|
||||
|
||||
#define SPINAND_SELECT_TARGET(__func) \
|
||||
.select_target = __func,
|
||||
|
||||
#define SPINAND_INFO(__model, __id, __memorg, __eccreq, __op_variants, \
|
||||
__flags, ...) \
|
||||
{ \
|
||||
.model = __model, \
|
||||
.devid = __id, \
|
||||
.memorg = __memorg, \
|
||||
.eccreq = __eccreq, \
|
||||
.op_variants = __op_variants, \
|
||||
.flags = __flags, \
|
||||
__VA_ARGS__ \
|
||||
}
|
||||
|
||||
/**
|
||||
* struct spinand_device - SPI NAND device instance
|
||||
* @base: NAND device instance
|
||||
* @slave: pointer to the SPI slave object
|
||||
* @lock: lock used to serialize accesses to the NAND
|
||||
* @id: NAND ID as returned by READ_ID
|
||||
* @flags: NAND flags
|
||||
* @op_templates: various SPI mem op templates
|
||||
* @op_templates.read_cache: read cache op template
|
||||
* @op_templates.write_cache: write cache op template
|
||||
* @op_templates.update_cache: update cache op template
|
||||
* @select_target: select a specific target/die. Usually called before sending
|
||||
* a command addressing a page or an eraseblock embedded in
|
||||
* this die. Only required if your chip exposes several dies
|
||||
* @cur_target: currently selected target/die
|
||||
* @eccinfo: on-die ECC information
|
||||
* @cfg_cache: config register cache. One entry per die
|
||||
* @databuf: bounce buffer for data
|
||||
* @oobbuf: bounce buffer for OOB data
|
||||
* @scratchbuf: buffer used for everything but page accesses. This is needed
|
||||
* because the spi-mem interface explicitly requests that buffers
|
||||
* passed in spi_mem_op be DMA-able, so we can't based the bufs on
|
||||
* the stack
|
||||
* @manufacturer: SPI NAND manufacturer information
|
||||
* @priv: manufacturer private data
|
||||
*/
|
||||
struct spinand_device {
|
||||
struct nand_device base;
|
||||
#ifndef __UBOOT__
|
||||
struct spi_mem *spimem;
|
||||
struct mutex lock;
|
||||
#else
|
||||
struct spi_slave *slave;
|
||||
#endif
|
||||
struct spinand_id id;
|
||||
u32 flags;
|
||||
|
||||
struct {
|
||||
const struct spi_mem_op *read_cache;
|
||||
const struct spi_mem_op *write_cache;
|
||||
const struct spi_mem_op *update_cache;
|
||||
} op_templates;
|
||||
|
||||
int (*select_target)(struct spinand_device *spinand,
|
||||
unsigned int target);
|
||||
unsigned int cur_target;
|
||||
|
||||
struct spinand_ecc_info eccinfo;
|
||||
|
||||
u8 *cfg_cache;
|
||||
u8 *databuf;
|
||||
u8 *oobbuf;
|
||||
u8 *scratchbuf;
|
||||
const struct spinand_manufacturer *manufacturer;
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* mtd_to_spinand() - Get the SPI NAND device attached to an MTD instance
|
||||
* @mtd: MTD instance
|
||||
*
|
||||
* Return: the SPI NAND device attached to @mtd.
|
||||
*/
|
||||
static inline struct spinand_device *mtd_to_spinand(struct mtd_info *mtd)
|
||||
{
|
||||
return container_of(mtd_to_nanddev(mtd), struct spinand_device, base);
|
||||
}
|
||||
|
||||
/**
|
||||
* spinand_to_mtd() - Get the MTD device embedded in a SPI NAND device
|
||||
* @spinand: SPI NAND device
|
||||
*
|
||||
* Return: the MTD device embedded in @spinand.
|
||||
*/
|
||||
static inline struct mtd_info *spinand_to_mtd(struct spinand_device *spinand)
|
||||
{
|
||||
return nanddev_to_mtd(&spinand->base);
|
||||
}
|
||||
|
||||
/**
|
||||
* nand_to_spinand() - Get the SPI NAND device embedding an NAND object
|
||||
* @nand: NAND object
|
||||
*
|
||||
* Return: the SPI NAND device embedding @nand.
|
||||
*/
|
||||
static inline struct spinand_device *nand_to_spinand(struct nand_device *nand)
|
||||
{
|
||||
return container_of(nand, struct spinand_device, base);
|
||||
}
|
||||
|
||||
/**
|
||||
* spinand_to_nand() - Get the NAND device embedded in a SPI NAND object
|
||||
* @spinand: SPI NAND device
|
||||
*
|
||||
* Return: the NAND device embedded in @spinand.
|
||||
*/
|
||||
static inline struct nand_device *
|
||||
spinand_to_nand(struct spinand_device *spinand)
|
||||
{
|
||||
return &spinand->base;
|
||||
}
|
||||
|
||||
/**
|
||||
* spinand_set_of_node - Attach a DT node to a SPI NAND device
|
||||
* @spinand: SPI NAND device
|
||||
* @np: DT node
|
||||
*
|
||||
* Attach a DT node to a SPI NAND device.
|
||||
*/
|
||||
static inline void spinand_set_of_node(struct spinand_device *spinand,
|
||||
const struct device_node *np)
|
||||
{
|
||||
nanddev_set_of_node(&spinand->base, np);
|
||||
}
|
||||
|
||||
int spinand_match_and_init(struct spinand_device *dev,
|
||||
const struct spinand_info *table,
|
||||
unsigned int table_size, u8 devid);
|
||||
|
||||
int spinand_upd_cfg(struct spinand_device *spinand, u8 mask, u8 val);
|
||||
int spinand_select_target(struct spinand_device *spinand, unsigned int target);
|
||||
|
||||
#endif /* __LINUX_MTD_SPINAND_H */
|
||||
@@ -0,0 +1,100 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* (C) Copyright 2009
|
||||
* Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com.
|
||||
*/
|
||||
|
||||
#ifndef ST_SMI_H
|
||||
#define ST_SMI_H
|
||||
|
||||
/* 0xF800.0000 . 0xFBFF.FFFF 64MB SMI (Serial Flash Mem) */
|
||||
/* 0xFC00.0000 . 0xFC1F.FFFF 2MB SMI (Serial Flash Reg.) */
|
||||
|
||||
#define FLASH_START_ADDRESS CONFIG_SYS_FLASH_BASE
|
||||
#define FLASH_BANK_SIZE CONFIG_SYS_FLASH_BANK_SIZE
|
||||
|
||||
#define SMIBANK0_BASE (FLASH_START_ADDRESS)
|
||||
#define SMIBANK1_BASE (SMIBANK0_BASE + FLASH_BANK_SIZE)
|
||||
#define SMIBANK2_BASE (SMIBANK1_BASE + FLASH_BANK_SIZE)
|
||||
#define SMIBANK3_BASE (SMIBANK2_BASE + FLASH_BANK_SIZE)
|
||||
|
||||
#define BANK0 0
|
||||
#define BANK1 1
|
||||
#define BANK2 2
|
||||
#define BANK3 3
|
||||
|
||||
struct smi_regs {
|
||||
u32 smi_cr1;
|
||||
u32 smi_cr2;
|
||||
u32 smi_sr;
|
||||
u32 smi_tr;
|
||||
u32 smi_rr;
|
||||
};
|
||||
|
||||
/* CONTROL REG 1 */
|
||||
#define BANK_EN 0x0000000F /* enables all banks */
|
||||
#define DSEL_TIME 0x00000060 /* Deselect time */
|
||||
#define PRESCAL5 0x00000500 /* AHB_CK prescaling value */
|
||||
#define PRESCALA 0x00000A00 /* AHB_CK prescaling value */
|
||||
#define PRESCAL3 0x00000300 /* AHB_CK prescaling value */
|
||||
#define PRESCAL4 0x00000400 /* AHB_CK prescaling value */
|
||||
#define SW_MODE 0x10000000 /* enables SW Mode */
|
||||
#define WB_MODE 0x20000000 /* Write Burst Mode */
|
||||
#define FAST_MODE 0x00008000 /* Fast Mode */
|
||||
#define HOLD1 0x00010000
|
||||
|
||||
/* CONTROL REG 2 */
|
||||
#define RD_STATUS_REG 0x00000400 /* reads status reg */
|
||||
#define WE 0x00000800 /* Write Enable */
|
||||
#define BANK0_SEL 0x00000000 /* Select Banck0 */
|
||||
#define BANK1_SEL 0x00001000 /* Select Banck1 */
|
||||
#define BANK2_SEL 0x00002000 /* Select Banck2 */
|
||||
#define BANK3_SEL 0x00003000 /* Select Banck3 */
|
||||
#define BANKSEL_SHIFT 12
|
||||
#define SEND 0x00000080 /* Send data */
|
||||
#define TX_LEN_1 0x00000001 /* data length = 1 byte */
|
||||
#define TX_LEN_2 0x00000002 /* data length = 2 byte */
|
||||
#define TX_LEN_3 0x00000003 /* data length = 3 byte */
|
||||
#define TX_LEN_4 0x00000004 /* data length = 4 byte */
|
||||
#define RX_LEN_1 0x00000010 /* data length = 1 byte */
|
||||
#define RX_LEN_2 0x00000020 /* data length = 2 byte */
|
||||
#define RX_LEN_3 0x00000030 /* data length = 3 byte */
|
||||
#define RX_LEN_4 0x00000040 /* data length = 4 byte */
|
||||
#define TFIE 0x00000100 /* Tx Flag Interrupt Enable */
|
||||
#define WCIE 0x00000200 /* WCF Interrupt Enable */
|
||||
|
||||
/* STATUS_REG */
|
||||
#define INT_WCF_CLR 0xFFFFFDFF /* clear: WCF clear */
|
||||
#define INT_TFF_CLR 0xFFFFFEFF /* clear: TFF clear */
|
||||
#define WIP_BIT 0x00000001 /* WIP Bit of SPI SR */
|
||||
#define WEL_BIT 0x00000002 /* WEL Bit of SPI SR */
|
||||
#define RSR 0x00000005 /* Read Status regiser */
|
||||
#define TFF 0x00000100 /* Transfer Finished FLag */
|
||||
#define WCF 0x00000200 /* Transfer Finished FLag */
|
||||
#define ERF1 0x00000400 /* Error Flag 1 */
|
||||
#define ERF2 0x00000800 /* Error Flag 2 */
|
||||
#define WM0 0x00001000 /* WM Bank 0 */
|
||||
#define WM1 0x00002000 /* WM Bank 1 */
|
||||
#define WM2 0x00004000 /* WM Bank 2 */
|
||||
#define WM3 0x00008000 /* WM Bank 3 */
|
||||
#define WM_SHIFT 12
|
||||
|
||||
/* TR REG */
|
||||
#define READ_ID 0x0000009F /* Read Identification */
|
||||
#define BULK_ERASE 0x000000C7 /* BULK erase */
|
||||
#define SECTOR_ERASE 0x000000D8 /* SECTOR erase */
|
||||
#define WRITE_ENABLE 0x00000006 /* Wenable command to FLASH */
|
||||
|
||||
struct flash_dev {
|
||||
u32 density;
|
||||
ulong size;
|
||||
ushort sector_count;
|
||||
};
|
||||
|
||||
#define SFLASH_PAGE_SIZE 0x100 /* flash page size */
|
||||
#define XFER_FINISH_TOUT 15 /* xfer finish timeout(in ms) */
|
||||
#define WMODE_TOUT 15 /* write enable timeout(in ms) */
|
||||
|
||||
extern void smi_init(void);
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user