arch/sim: Make up_internal.h includable in host environment

to avoid the declaration repetition

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2020-07-26 18:06:26 +08:00
committed by liuguo09
parent 3543950766
commit 8ce0ff5ce4
15 changed files with 47 additions and 132 deletions
+3 -4
View File
@@ -41,7 +41,6 @@
****************************************************************************/
#include <stdint.h>
#include <stdbool.h>
/****************************************************************************
* Pre-processor Definitions
@@ -49,15 +48,15 @@
/* Must match definitions in up_testset.c */
#define SP_UNLOCKED false /* The Un-locked state */
#define SP_LOCKED true /* The Locked state */
#define SP_UNLOCKED 0 /* The Un-locked state */
#define SP_LOCKED 1 /* The Locked state */
/****************************************************************************
* Public Types
****************************************************************************/
/* Must match definitions in up_testset.c */
typedef bool spinlock_t;
typedef uint8_t spinlock_t;
/****************************************************************************
* Public Functions
-4
View File
@@ -48,10 +48,6 @@
#include "up_internal.h"
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
-13
View File
@@ -63,14 +63,6 @@
# define kmm_free(mem) free(mem)
#endif
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
@@ -188,11 +180,6 @@ static const unsigned char g_vfatdata[] =
0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x77, 0x7d, 0x06
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
+4
View File
@@ -95,4 +95,8 @@ void up_exit(int status)
/* Then switch contexts */
up_longjmp(tcb->xcp.regs, 1);
/* The function does not return */
for (; ; );
}
+1 -2
View File
@@ -89,11 +89,10 @@ int main(int argc, char **argv, char **envp)
/* Start the CPU0 emulation. This should not return. */
sim_cpu0_start();
#else
#endif
/* Start the Nuttx emulation. This should not return. */
nx_start();
#endif
}
return g_exitcode;
+1 -3
View File
@@ -37,8 +37,6 @@
* Included Files
****************************************************************************/
#define _GNU_SOURCE 1
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
@@ -55,7 +53,7 @@
#include "hostfs.h"
/****************************************************************************
* Public Functions
* Private Functions
****************************************************************************/
/****************************************************************************
+20 -26
View File
@@ -41,20 +41,12 @@
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#ifndef __ASSEMBLY__
#ifdef __ASSEMBLY__
# include <nuttx/config.h>
#else
# include <sys/types.h>
# include <stdbool.h>
# include <netinet/in.h>
# include <nuttx/irq.h>
# include <arch/irq.h>
# ifdef CONFIG_SMP
# include <nuttx/sched.h>
# include <nuttx/spinlock.h>
# endif
#endif
/****************************************************************************
@@ -186,16 +178,21 @@
#define STACK_COLOR 0xdeadbeef
#ifndef __ASSEMBLY__
/****************************************************************************
* Public Types
* Public Type Definitions
****************************************************************************/
struct tcb_s;
struct spi_dev_s;
struct qspi_dev_s;
struct ioexpander_dev_s;
/****************************************************************************
* Public Data
****************************************************************************/
#ifndef __ASSEMBLY__
#ifdef CONFIG_SMP
/* These spinlocks are used in the SMP configuration in order to implement
* up_cpu_pause(). The protocol for CPUn to pause CPUm is as follows
@@ -211,8 +208,8 @@
* so that it will be ready for the next pause operation.
*/
extern volatile spinlock_t g_cpu_wait[CONFIG_SMP_NCPUS] SP_SECTION;
extern volatile spinlock_t g_cpu_paused[CONFIG_SMP_NCPUS] SP_SECTION;
extern volatile uint8_t g_cpu_wait[CONFIG_SMP_NCPUS];
extern volatile uint8_t g_cpu_paused[CONFIG_SMP_NCPUS];
#endif
/****************************************************************************
@@ -221,8 +218,8 @@ extern volatile spinlock_t g_cpu_paused[CONFIG_SMP_NCPUS] SP_SECTION;
/* up_setjmp32.S ************************************************************/
int up_setjmp(xcpt_reg_t *jb);
void up_longjmp(xcpt_reg_t *jb, int val) noreturn_function;
int up_setjmp(void *jb);
void up_longjmp(void *jb, int val);
/* up_hostmemory.c **********************************************************/
@@ -246,6 +243,8 @@ void sim_cpu0_start(void);
#ifdef CONFIG_SMP
void up_cpu_started(void);
int up_cpu_paused(int cpu);
struct tcb_s *up_this_task(void);
#endif
/* up_oneshot.c *************************************************************/
@@ -315,8 +314,7 @@ int sim_ajoy_initialize(void);
/* up_ioexpander.c **********************************************************/
#ifdef CONFIG_SIM_IOEXPANDER
struct ioexpander_dev_s;
FAR struct ioexpander_dev_s *sim_ioexpander_initialize(void);
struct ioexpander_dev_s *sim_ioexpander_initialize(void);
#endif
/* up_tapdev.c **************************************************************/
@@ -372,12 +370,10 @@ void vpnkit_ifdown(void);
/* up_netdriver.c ***********************************************************/
#ifdef CONFIG_SIM_NETDEV
int netdriver_init(void);
void netdriver_setmacaddr(unsigned char *macaddr);
void netdriver_setmtu(int mtu);
void netdriver_loop(void);
#endif
/* up_rptun.c ***************************************************************/
@@ -387,19 +383,17 @@ void up_rptun_loop(void);
#endif
#ifdef CONFIG_SIM_SPIFLASH
struct spi_dev_s;
struct spi_dev_s *up_spiflashinitialize(FAR const char *name);
struct spi_dev_s *up_spiflashinitialize(const char *name);
#endif
#ifdef CONFIG_SIM_QSPIFLASH
struct qspi_dev_s;
struct qspi_dev_s *up_qspiflashinitialize(void);
#endif
/* Debug ********************************************************************/
#ifdef CONFIG_STACK_COLORATION
void up_stack_color(FAR void *stackbase, size_t nbytes);
void up_stack_color(void *stackbase, size_t nbytes);
#endif
#endif /* __ASSEMBLY__ */
+6 -29
View File
@@ -44,25 +44,12 @@
#include <sched.h>
#include <errno.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Must match definitions in arch/sim/include/spinlock.h */
#define SP_UNLOCKED 0 /* The Un-locked state */
#define SP_LOCKED 1 /* The Locked state */
#include "up_internal.h"
/****************************************************************************
* Private Types
****************************************************************************/
/* Must match definitions in arch/sim/include/spinlock.h. Assuming that
* bool and unsigned char are equivalent.
*/
typedef unsigned char spinlock_t;
struct sim_cpuinfo_s
{
int cpu; /* CPU number */
@@ -90,20 +77,14 @@ static pthread_t g_cpu_thread[CONFIG_SMP_NCPUS];
* so that it will be ready for the next pause operation.
*/
volatile spinlock_t g_cpu_wait[CONFIG_SMP_NCPUS];
volatile spinlock_t g_cpu_paused[CONFIG_SMP_NCPUS];
volatile uint8_t g_cpu_wait[CONFIG_SMP_NCPUS];
volatile uint8_t g_cpu_paused[CONFIG_SMP_NCPUS];
/****************************************************************************
* NuttX domain function prototypes
****************************************************************************/
void nx_start(void);
void up_cpu_started(void);
int up_cpu_paused(int cpu);
void host_sleepuntil(uint64_t nsec);
#ifdef CONFIG_SCHED_INSTRUMENTATION
struct tcb_s *up_this_task(void);
void sched_note_cpu_start(struct tcb_s *tcb, int cpu);
void sched_note_cpu_pause(struct tcb_s *tcb, int cpu);
void sched_note_cpu_resume(struct tcb_s *tcb, int cpu);
@@ -278,10 +259,6 @@ void sim_cpu0_start(void)
{
return;
}
/* Give control to nx_start() */
nx_start();
}
/****************************************************************************
@@ -408,8 +385,8 @@ int up_cpu_pause(int cpu)
/* Take the spinlock that will prevent the CPU thread from running */
g_cpu_wait[cpu] = SP_LOCKED;
g_cpu_paused[cpu] = SP_LOCKED;
g_cpu_wait[cpu] = 1;
g_cpu_paused[cpu] = 1;
/* Signal the CPU thread */
@@ -454,6 +431,6 @@ int up_cpu_resume(int cpu)
/* Release the spinlock that will alloc the CPU thread to continue */
g_cpu_wait[cpu] = SP_UNLOCKED;
g_cpu_wait[cpu] = 0;
return 0;
}
-4
View File
@@ -327,10 +327,6 @@ struct sim_spiflashdev_s *gp_spidev[] =
NULL
};
/************************************************************************************
* Public Data
************************************************************************************/
/************************************************************************************
* Private Functions
************************************************************************************/
+2 -7
View File
@@ -66,6 +66,8 @@
#include <linux/net.h>
#include <netinet/in.h>
#include "up_internal.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -87,13 +89,6 @@ struct sel_arg_struct
struct timeval *tvp;
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
void netdriver_setmacaddr(unsigned char *macaddr);
void netdriver_setmtu(int mtu);
/****************************************************************************
* Private Data
****************************************************************************/
+4 -21
View File
@@ -43,23 +43,6 @@
# include <stdatomic.h>
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Must match definitions in arch/sim/include/spinlock.h */
#define SP_UNLOCKED 0 /* The Un-locked state */
#define SP_LOCKED 1 /* The Locked state */
/****************************************************************************
* Private Types
****************************************************************************/
/* Must match definitions in arch/sim/include/spinlock.h */
typedef uint8_t spinlock_t;
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -84,22 +67,22 @@ typedef uint8_t spinlock_t;
*
****************************************************************************/
spinlock_t up_testset(volatile spinlock_t *lock)
uint8_t up_testset(volatile uint8_t *lock)
{
#ifdef CONFIG_SMP
/* In the multi-CPU SMP case, we use atomic operation to assure that the
* following test and set is atomic.
*/
return atomic_exchange(lock, SP_LOCKED);
return atomic_exchange(lock, 1);
#else
/* In the non-SMP case, the simulation is implemented with a single thread
* the test-and-set operation is inherently atomic.
*/
spinlock_t ret = *lock;
*lock = SP_LOCKED;
uint8_t ret = *lock;
*lock = 1;
return ret;
#endif
}
+1 -7
View File
@@ -35,6 +35,7 @@
#include <string.h>
#include <unistd.h>
#include "up_internal.h"
#include "vpnkit/protocol.h"
/****************************************************************************
@@ -47,10 +48,6 @@
fprintf(stderr, "up_vpnkit: " fmt "\r\n", ##__VA_ARGS__)
#define DEBUG(fmt, ...)
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
@@ -64,9 +61,6 @@ static bool g_connect_warned;
* Private Functions
****************************************************************************/
int negotiate(int fd, struct vif_info *vif);
void netdriver_setmacaddr(unsigned char *macaddr);
static int vpnkit_connect(void)
{
struct sockaddr_un sun;
+2 -6
View File
@@ -55,6 +55,8 @@
#include <netinet/in.h>
#include "up_internal.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -114,12 +116,6 @@ static pcap_open_live_t pcap_open_live;
static pcap_next_ex_t pcap_next_ex;
static pcap_sendpacket_t pcap_sendpacket;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
void netdriver_setmacaddr(unsigned char *macaddr);
/****************************************************************************
* Private Functions
****************************************************************************/
+1 -6
View File
@@ -38,14 +38,9 @@
****************************************************************************/
#include <stdio.h>
#include <X11/Xlib.h>
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
extern void up_buttonevent(int x, int y, int buttons);
#include "up_internal.h"
/****************************************************************************
* Public Data
+2
View File
@@ -140,6 +140,8 @@ extern char expected_hello_old[5];
* Public Function Prototypes
****************************************************************************/
int negotiate(int fd, struct vif_info *vif);
extern struct init_message *create_init_message(void);
extern int read_init_message(int fd, struct init_message *ci);
extern int write_init_message(int fd, struct init_message *ci);