modify file names and create directories
This commit is contained in:
21
lib/abort.c
Normal file
21
lib/abort.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <aal/debug.h>
|
||||
#include <aal/cpu.h>
|
||||
|
||||
void panic(const char *msg)
|
||||
{
|
||||
cpu_disable_interrupt();
|
||||
|
||||
kprintf(msg);
|
||||
|
||||
while (1) {
|
||||
cpu_halt();
|
||||
}
|
||||
}
|
||||
|
||||
extern void arch_show_interrupt_context(const void*);
|
||||
|
||||
void aal_mc_debug_show_interrupt_context(const void *reg)
|
||||
{
|
||||
arch_show_interrupt_context(reg);
|
||||
}
|
||||
|
||||
54
lib/include/ctype.h
Normal file
54
lib/include/ctype.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#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 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)
|
||||
|
||||
#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
|
||||
169
lib/include/errno.h
Normal file
169
lib/include/errno.h
Normal file
@@ -0,0 +1,169 @@
|
||||
#ifndef _ASM_GENERIC_ERRNO_BASE_H
|
||||
#define _ASM_GENERIC_ERRNO_BASE_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 /* Function not implemented */
|
||||
#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 NFS 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 */
|
||||
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
/* Should never be seen by user programs */
|
||||
#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 */
|
||||
|
||||
/* 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 EIOCBRETRY 530 /* iocb queued, will trigger a retry */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
81
lib/include/ihk/cpu.h
Normal file
81
lib/include/ihk/cpu.h
Normal file
@@ -0,0 +1,81 @@
|
||||
#ifndef AAL_CPU_H
|
||||
#define AAL_CPU_H
|
||||
|
||||
#include <list.h>
|
||||
#include <aal/context.h>
|
||||
|
||||
void cpu_enable_interrupt(void);
|
||||
void cpu_disable_interrupt(void);
|
||||
void cpu_halt(void);
|
||||
void cpu_restore_interrupt(unsigned long);
|
||||
void cpu_pause(void);
|
||||
|
||||
#define barrier() asm volatile("" : : : "memory")
|
||||
|
||||
unsigned long cpu_disable_interrupt_save(void);
|
||||
|
||||
struct aal_mc_interrupt_handler {
|
||||
struct list_head list;
|
||||
void (*func)(void *);
|
||||
void *priv;
|
||||
};
|
||||
int aal_mc_register_interrupt_handler(int vector,
|
||||
struct aal_mc_interrupt_handler *h);
|
||||
int aal_mc_unregister_interrupt_handler(int vector,
|
||||
struct aal_mc_interrupt_handler *h);
|
||||
|
||||
enum aal_mc_gv_type {
|
||||
AAL_GV_IKC = 1,
|
||||
};
|
||||
|
||||
int aal_mc_get_vector(enum aal_mc_gv_type type);
|
||||
int aal_mc_interrupt_host(int cpu, int vector);
|
||||
|
||||
struct aal_mc_cpu_info {
|
||||
int ncpus;
|
||||
int *hw_ids;
|
||||
int *nodes;
|
||||
};
|
||||
|
||||
struct aal_mc_cpu_info *aal_mc_get_cpu_info(void);
|
||||
void aal_mc_boot_cpu(int cpuid, unsigned long pc);
|
||||
int aal_mc_get_processor_id(void);
|
||||
int aal_mc_get_hardware_processor_id(void);
|
||||
|
||||
void aal_mc_delay_us(int us);
|
||||
void aal_mc_set_syscall_handler(long (*handler)(int, aal_mc_user_context_t *));
|
||||
|
||||
void aal_mc_init_ap(void);
|
||||
|
||||
void aal_mc_init_context(aal_mc_kernel_context_t *new_ctx,
|
||||
void *stack_pointer,
|
||||
void (*next_function)(void));
|
||||
void aal_mc_switch_context(aal_mc_kernel_context_t *old_ctx,
|
||||
aal_mc_kernel_context_t *new_ctx);
|
||||
int aal_mc_interrupt_cpu(int cpu, int vector);
|
||||
|
||||
void aal_mc_init_user_process(aal_mc_kernel_context_t *ctx,
|
||||
aal_mc_user_context_t **puctx,
|
||||
void *stack_pointer, unsigned long user_pc,
|
||||
unsigned long user_sp);
|
||||
|
||||
enum aal_mc_user_context_regtype {
|
||||
AAL_UCR_STACK_POINTER = 1,
|
||||
AAL_UCR_PROGRAM_COUNTER = 2,
|
||||
};
|
||||
|
||||
void aal_mc_modify_user_context(aal_mc_user_context_t *uctx,
|
||||
enum aal_mc_user_context_regtype reg,
|
||||
unsigned long value);
|
||||
|
||||
void aal_mc_debug_show_interrupt_context(const void *reg);
|
||||
|
||||
enum aal_asr_type {
|
||||
AAL_ASR_X86_FS,
|
||||
AAL_ASR_X86_GS,
|
||||
};
|
||||
|
||||
int aal_mc_arch_set_special_register(enum aal_asr_type, unsigned long value);
|
||||
int aal_mc_arch_get_special_register(enum aal_asr_type, unsigned long *value);
|
||||
|
||||
#endif
|
||||
19
lib/include/ihk/debug.h
Normal file
19
lib/include/ihk/debug.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef AAL_DEBUG_H
|
||||
#define AAL_DEBUG_H
|
||||
|
||||
#include <aal/memconst.h>
|
||||
|
||||
struct aal_kmsg_buf {
|
||||
int tail;
|
||||
int len;
|
||||
char str[AAL_KMSG_SIZE - sizeof(int) * 2];
|
||||
};
|
||||
|
||||
extern int kprintf(const char *format, ...);
|
||||
extern int kprintf_lock();
|
||||
extern void kprintf_unlock(int irqflags);
|
||||
extern int __kprintf(const char *format, ...);
|
||||
|
||||
extern void panic(const char *msg);
|
||||
|
||||
#endif
|
||||
21
lib/include/ihk/dma.h
Normal file
21
lib/include/ihk/dma.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef __HEADER_GENERIC_INCLUDE_DMA_H
|
||||
#define __HEADER_GENERIC_INCLUDE_DMA_H
|
||||
|
||||
#include <aal/ikc.h>
|
||||
|
||||
struct aal_dma_request {
|
||||
aal_os_t src_os;
|
||||
unsigned long src_phys;
|
||||
aal_os_t dest_os;
|
||||
unsigned long dest_phys;
|
||||
unsigned long size;
|
||||
|
||||
void (*callback)(void *);
|
||||
void *priv;
|
||||
aal_os_t notify_os;
|
||||
unsigned long *notify;
|
||||
};
|
||||
|
||||
int aal_mc_dma_request(int channel, struct aal_dma_request *req);
|
||||
|
||||
#endif
|
||||
13
lib/include/ihk/lock.h
Normal file
13
lib/include/ihk/lock.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef __HEADER_GENERIC_AAL_LOCK
|
||||
#define __HEADER_GENERIC_AAL_LOCK
|
||||
|
||||
#include <arch-lock.h>
|
||||
|
||||
#ifndef AAL_STATIC_SPINLOCK_FUNCS
|
||||
void aal_mc_spinlock_init(aal_spinlock_t *);
|
||||
void aal_mc_spinlock_lock(aal_spinlock_t *, unsigned long *);
|
||||
void aal_mc_spinlock_unlock(aal_spinlock_t *, unsigned long *);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
99
lib/include/ihk/mm.h
Normal file
99
lib/include/ihk/mm.h
Normal file
@@ -0,0 +1,99 @@
|
||||
#ifndef __HEADER_GENERIC_AAL_MM_H
|
||||
#define __HEADER_GENERIC_AAL_MM_H
|
||||
|
||||
#include <memory.h>
|
||||
|
||||
enum aal_mc_gma_type {
|
||||
AAL_MC_GMA_MAP_START,
|
||||
AAL_MC_GMA_MAP_END,
|
||||
AAL_MC_GMA_AVAIL_START,
|
||||
AAL_MC_GMA_AVAIL_END,
|
||||
AAL_MC_GMA_HEAP_START,
|
||||
AAL_MC_NR_RESERVED_AREAS,
|
||||
AAL_MC_RESERVED_AREA_START,
|
||||
AAL_MC_RESERVED_AREA_END,
|
||||
};
|
||||
|
||||
enum aal_mc_ma_type {
|
||||
AAL_MC_MA_AVAILABLE,
|
||||
AAL_MC_MA_RESERVED,
|
||||
AAL_MC_MA_SPECIAL,
|
||||
};
|
||||
|
||||
enum aal_mc_ap_flag {
|
||||
AAL_MC_AP_FLAG,
|
||||
};
|
||||
|
||||
enum aal_mc_pt_prepare_flag {
|
||||
AAL_MC_PT_FIRST_LEVEL,
|
||||
AAL_MC_PT_LAST_LEVEL,
|
||||
};
|
||||
|
||||
struct aal_mc_memory_area {
|
||||
unsigned long start;
|
||||
unsigned long size;
|
||||
enum aal_mc_ma_type type;
|
||||
};
|
||||
|
||||
struct aal_mc_memory_node {
|
||||
int node;
|
||||
int nareas;
|
||||
struct aal_mc_memory_area *areas;
|
||||
};
|
||||
|
||||
unsigned long aal_mc_get_memory_address(enum aal_mc_gma_type, int);
|
||||
|
||||
void aal_mc_reserve_arch_pages(unsigned long start, unsigned long end,
|
||||
void (*cb)(unsigned long, unsigned long, int));
|
||||
|
||||
struct aal_mc_pa_ops {
|
||||
void *(*alloc_page)(int, enum aal_mc_ap_flag);
|
||||
void (*free_page)(void *, int);
|
||||
|
||||
void *(*alloc)(int, enum aal_mc_ap_flag);
|
||||
void (*free)(void *);
|
||||
};
|
||||
|
||||
void aal_mc_set_page_allocator(struct aal_mc_pa_ops *);
|
||||
void aal_mc_set_page_fault_handler(void (*h)(unsigned long, void *, unsigned long));
|
||||
|
||||
unsigned long aal_mc_map_memory(void *os, unsigned long phys,
|
||||
unsigned long size);
|
||||
void aal_mc_unmap_memory(void *os, unsigned long phys, unsigned long size);
|
||||
|
||||
void *aal_mc_map_virtual(unsigned long phys, int npages,
|
||||
enum aal_mc_pt_attribute attr);
|
||||
void aal_mc_unmap_virtual(void *va, int npages, int free_physical);
|
||||
|
||||
extern void *sbox_base;
|
||||
extern unsigned int free_bitmap_micpa;
|
||||
void aal_mc_map_micpa(unsigned long host_pa, unsigned long* mic_pa);
|
||||
int aal_mc_free_micpa(unsigned long mic_pa);
|
||||
void aal_mc_clean_micpa(void);
|
||||
|
||||
void *aal_mc_alloc_pages(int npages, enum aal_mc_ap_flag flag);
|
||||
void aal_mc_free_pages(void *p, int npages);
|
||||
void *aal_mc_allocate(int size, enum aal_mc_ap_flag flag);
|
||||
void aal_mc_free(void *p);
|
||||
|
||||
void *arch_alloc_page(enum aal_mc_ap_flag flag);
|
||||
void arch_free_page(void *ptr);
|
||||
|
||||
typedef void *page_table_t;
|
||||
|
||||
int aal_mc_pt_set_page(page_table_t pt, void *virt, unsigned long phys,
|
||||
enum aal_mc_pt_attribute attr);
|
||||
int aal_mc_pt_set_large_page(page_table_t pt, void *virt,
|
||||
unsigned long phys, enum aal_mc_pt_attribute attr);
|
||||
int aal_mc_pt_change_page(page_table_t pt, void *virt,
|
||||
enum aal_mc_pt_attribute);
|
||||
int aal_mc_pt_clear_page(page_table_t pt, void *virt);
|
||||
int aal_mc_pt_prepare_map(page_table_t pt, void *virt, unsigned long size,
|
||||
enum aal_mc_pt_prepare_flag);
|
||||
|
||||
struct page_table *aal_mc_pt_create(void);
|
||||
void aal_mc_load_page_table(struct page_table *pt);
|
||||
int aal_mc_pt_virt_to_phys(struct page_table *pt,
|
||||
void *virt, unsigned long *phys);
|
||||
|
||||
#endif
|
||||
28
lib/include/ihk/page_alloc.h
Normal file
28
lib/include/ihk/page_alloc.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef __HEADER_GENERIC_AAL_PAGE_ALLOC
|
||||
#define __HEADER_GENERIC_AAL_PAGE_ALLOC
|
||||
|
||||
struct aal_page_allocator_desc {
|
||||
unsigned long start;
|
||||
unsigned int last;
|
||||
unsigned int count;
|
||||
unsigned int flag;
|
||||
unsigned int shift;
|
||||
aal_spinlock_t lock;
|
||||
unsigned int pad;
|
||||
|
||||
unsigned long map[0];
|
||||
};
|
||||
|
||||
unsigned long aal_pagealloc_count(void *__desc);
|
||||
void *__aal_pagealloc_init(unsigned long start, unsigned long size,
|
||||
unsigned long unit, void *initial,
|
||||
unsigned long *pdescsize);
|
||||
void *aal_pagealloc_init(unsigned long start, unsigned long size,
|
||||
unsigned long unit);
|
||||
void aal_pagealloc_destroy(void *__desc);
|
||||
unsigned long aal_pagealloc_alloc(void *__desc, int npages);
|
||||
void aal_pagealloc_reserve(void *desc, unsigned long start, unsigned long end);
|
||||
void aal_pagealloc_free(void *__desc, unsigned long address, int npages);
|
||||
unsigned long aal_pagealloc_count(void *__desc);
|
||||
|
||||
#endif
|
||||
41
lib/include/ihk/perfctr.h
Normal file
41
lib/include/ihk/perfctr.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef HEADER_GENERIC_AAL_PERFCTR_H
|
||||
#define HEADER_GENERIC_AAL_PERFCTR_H
|
||||
|
||||
#define PERFCTR_USER_MODE 0x01
|
||||
#define PERFCTR_KERNEL_MODE 0x02
|
||||
|
||||
enum aal_perfctr_type {
|
||||
APT_TYPE_DATA_PAGE_WALK,
|
||||
APT_TYPE_DATA_READ_MISS,
|
||||
APT_TYPE_DATA_WRITE_MISS,
|
||||
APT_TYPE_BANK_CONFLICTS,
|
||||
APT_TYPE_CODE_CACHE_MISS,
|
||||
APT_TYPE_INSTRUCTIONS_EXECUTED,
|
||||
APT_TYPE_INSTRUCTIONS_EXECUTED_V_PIPE,
|
||||
|
||||
APT_TYPE_L2_READ_MISS,
|
||||
APT_TYPE_L2_CODE_READ_MISS_CACHE_FILL,
|
||||
APT_TYPE_L2_DATA_READ_MISS_CACHE_FILL,
|
||||
APT_TYPE_L2_CODE_READ_MISS_MEM_FILL,
|
||||
APT_TYPE_L2_DATA_READ_MISS_MEM_FILL,
|
||||
|
||||
APT_TYPE_L1D_REQUEST,
|
||||
APT_TYPE_L1I_REQUEST,
|
||||
APT_TYPE_L1_MISS,
|
||||
APT_TYPE_LLC_MISS,
|
||||
APT_TYPE_DTLB_MISS,
|
||||
APT_TYPE_ITLB_MISS,
|
||||
APT_TYPE_STALL,
|
||||
APT_TYPE_CYCLE,
|
||||
PERFCTR_MAX_TYPE,
|
||||
};
|
||||
|
||||
int aal_mc_perfctr_init(int counter, enum aal_perfctr_type type, int mode);
|
||||
int aal_mc_perfctr_start(unsigned long counter_mask);
|
||||
int aal_mc_perfctr_stop(unsigned long counter_mask);
|
||||
int aal_mc_perfctr_reset(int counter);
|
||||
int aal_mc_perfctr_read_mask(unsigned long counter_mask, unsigned long *value);
|
||||
unsigned long aal_mc_perfctr_read(int counter);
|
||||
|
||||
#endif
|
||||
|
||||
7
lib/include/limits.h
Normal file
7
lib/include/limits.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef __HEADER_LIMITS
|
||||
#define __HEADER_LIMITS
|
||||
|
||||
#define INT_MAX 0x7fffffff
|
||||
#define INT_MIN -0x80000000
|
||||
|
||||
#endif
|
||||
581
lib/include/list.h
Normal file
581
lib/include/list.h
Normal file
@@ -0,0 +1,581 @@
|
||||
#ifndef _LINUX_LIST_H
|
||||
#define _LINUX_LIST_H
|
||||
|
||||
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
||||
/**
|
||||
* 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) );})
|
||||
|
||||
struct list_head {
|
||||
struct list_head *next, *prev;
|
||||
};
|
||||
|
||||
#define LIST_POISON1 ((void *)0x00100129)
|
||||
#define LIST_POISON2 ((void *)0x00200229)
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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!
|
||||
*/
|
||||
#ifndef CONFIG_DEBUG_LIST
|
||||
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;
|
||||
}
|
||||
#else
|
||||
extern void __list_add(struct list_head *new,
|
||||
struct list_head *prev,
|
||||
struct list_head *next);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
#ifndef CONFIG_DEBUG_LIST
|
||||
static inline void __list_del_entry(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
}
|
||||
|
||||
static inline void list_del(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
entry->next = LIST_POISON1;
|
||||
entry->prev = LIST_POISON2;
|
||||
}
|
||||
#else
|
||||
extern void __list_del_entry(struct list_head *entry);
|
||||
extern void list_del(struct list_head *entry);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 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(entry);
|
||||
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_entry(list);
|
||||
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_entry(list);
|
||||
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_rotate_left - rotate the list to the left
|
||||
* @head: the head of the list
|
||||
*/
|
||||
static inline void list_rotate_left(struct list_head *head)
|
||||
{
|
||||
struct list_head *first;
|
||||
|
||||
if (!list_empty(head)) {
|
||||
first = head->next;
|
||||
list_move_tail(first, head);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_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; 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 doesn't differ from list_for_each() any more.
|
||||
* We don't do prefetching in either case.
|
||||
*/
|
||||
#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; 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; \
|
||||
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); \
|
||||
&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); \
|
||||
&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); \
|
||||
&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); \
|
||||
&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 (; &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 - continue list iteration safe against removal
|
||||
* @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 - iterate over list from current point safe against removal
|
||||
* @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 - iterate backwards over list safe against removal
|
||||
* @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))
|
||||
|
||||
/**
|
||||
* list_safe_reset_next - reset a stale list_for_each_entry_safe loop
|
||||
* @pos: the loop cursor used in the list_for_each_entry_safe loop
|
||||
* @n: temporary storage used in list_for_each_entry_safe
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* list_safe_reset_next is not safe to use in general if the list may be
|
||||
* modified concurrently (eg. the lock is dropped in the loop body). An
|
||||
* exception to this is if the cursor element (pos) is pinned in the list,
|
||||
* and list_safe_reset_next is called after re-taking the lock and before
|
||||
* completing the current iteration of the loop body.
|
||||
*/
|
||||
#define list_safe_reset_next(pos, n, member) \
|
||||
n = list_entry(pos->member.next, typeof(*pos), 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).
|
||||
*/
|
||||
|
||||
#endif
|
||||
23
lib/include/memory.h
Normal file
23
lib/include/memory.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef __HEADER_GENERIC_MEMORY_H
|
||||
#define __HEADER_GENERIC_MEMORY_H
|
||||
|
||||
#include <arch-memory.h>
|
||||
|
||||
#ifndef KERNEL_PHYS_OFFSET
|
||||
#define KERNEL_PHYS_OFFSET 0
|
||||
|
||||
static unsigned long virt_to_phys(void *v)
|
||||
{
|
||||
return (unsigned long)v - KERNEL_PHYS_OFFSET;
|
||||
}
|
||||
static void *phys_to_virt(unsigned long p)
|
||||
{
|
||||
return (void *)(p + KERNEL_PHYS_OFFSET);
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned long virt_to_phys(void *v);
|
||||
void *phys_to_virt(unsigned long p);
|
||||
|
||||
#endif
|
||||
|
||||
20
lib/include/string.h
Normal file
20
lib/include/string.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef __STRING_H
|
||||
#define __STRING_H
|
||||
|
||||
#include <types.h>
|
||||
|
||||
size_t strlen(const char *p);
|
||||
size_t strnlen(const char *p, size_t maxlen);
|
||||
char *strcpy(char *dest, const char *src);
|
||||
char *strncpy(char *dest, const char *src, size_t maxlen);
|
||||
int strcmp(const char *s1, const char *s2);
|
||||
int strncmp(const char *s1, const char *s2, size_t n);
|
||||
char *strstr(const char *haystack, const char *needle);
|
||||
void *memcpy(void *dest, const void *src, size_t n);
|
||||
void *memcpy_long(void *dest, const void *src, size_t n);
|
||||
int memcmp(const void *s1, const void *s2, size_t n);
|
||||
void *memset(void *s, int n, size_t l);
|
||||
|
||||
unsigned long strtol(const char *cp, char **endp, unsigned int base);
|
||||
|
||||
#endif
|
||||
7
lib/include/types.h
Normal file
7
lib/include/types.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
#include <aal/types.h>
|
||||
|
||||
#endif
|
||||
|
||||
253
lib/page_alloc.c
Normal file
253
lib/page_alloc.c
Normal file
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
* AAL - Generic page allocator (manycore version)
|
||||
* (C) Copyright 2011 Taku Shimosawa.
|
||||
*/
|
||||
#include <types.h>
|
||||
#include <string.h>
|
||||
#include <aal/debug.h>
|
||||
#include <aal/lock.h>
|
||||
#include <aal/mm.h>
|
||||
#include <aal/page_alloc.h>
|
||||
#include <memory.h>
|
||||
#include <bitops.h>
|
||||
|
||||
void *allocate_pages(int npages, enum aal_mc_ap_flag flag);
|
||||
void free_pages(void *, int npages);
|
||||
|
||||
#define MAP_INDEX(n) ((n) >> 6)
|
||||
#define MAP_BIT(n) ((n) & 0x3f)
|
||||
#define ADDRESS(desc, index, bit) \
|
||||
((desc)->start + (((index) * 64 + (bit)) << ((desc)->shift)))
|
||||
|
||||
void *__aal_pagealloc_init(unsigned long start, unsigned long size,
|
||||
unsigned long unit, void *initial,
|
||||
unsigned long *pdescsize)
|
||||
{
|
||||
/* Unit must be power of 2, and size and start must be unit-aligned */
|
||||
struct aal_page_allocator_desc *desc;
|
||||
int i, page_shift, descsize, mapsize, mapaligned;
|
||||
int flag = 0;
|
||||
|
||||
if (!unit) {
|
||||
return NULL;
|
||||
}
|
||||
page_shift = fls(unit) - 1;
|
||||
|
||||
/* round up to 64-bit */
|
||||
mapsize = (size >> page_shift);
|
||||
mapaligned = ((mapsize + 63) >> 6) << 3;
|
||||
descsize = sizeof(*desc) + mapaligned;
|
||||
|
||||
descsize = (descsize + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
||||
|
||||
if (initial) {
|
||||
desc = initial;
|
||||
*pdescsize = descsize;
|
||||
} else {
|
||||
desc = (void *)allocate_pages(descsize, 0);
|
||||
}
|
||||
flag = descsize;
|
||||
memset(desc, 0, descsize * PAGE_SIZE);
|
||||
|
||||
if (!desc) {
|
||||
kprintf("AAL: failed to allocate page-allocator-desc "\
|
||||
"(%lx, %lx, %lx)\n", start, size, unit);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
desc->start = start;
|
||||
desc->last = 0;
|
||||
desc->count = mapaligned >> 3;
|
||||
desc->shift = page_shift;
|
||||
desc->flag = flag;
|
||||
|
||||
kprintf("Page allocator: %lx - %lx (%d)\n", start, start + size,
|
||||
page_shift);
|
||||
|
||||
aal_mc_spinlock_init(&desc->lock);
|
||||
|
||||
/* Reserve align padding area */
|
||||
for (i = mapsize; i < mapaligned * 8; i++) {
|
||||
desc->map[MAP_INDEX(i)] |= (1UL << MAP_BIT(i));
|
||||
}
|
||||
|
||||
return desc;
|
||||
}
|
||||
|
||||
void *aal_pagealloc_init(unsigned long start, unsigned long size,
|
||||
unsigned long unit)
|
||||
{
|
||||
return __aal_pagealloc_init(start, size, unit, NULL, NULL);
|
||||
}
|
||||
|
||||
void aal_pagealloc_destroy(void *__desc)
|
||||
{
|
||||
struct aal_page_allocator_desc *desc = __desc;
|
||||
|
||||
free_pages(desc, desc->flag);
|
||||
}
|
||||
|
||||
static unsigned long __aal_pagealloc_large(struct aal_page_allocator_desc *desc,
|
||||
int nblocks)
|
||||
{
|
||||
unsigned long flags;
|
||||
unsigned int i, j, mi;
|
||||
|
||||
flags = aal_mc_spinlock_lock(&desc->lock);
|
||||
for (i = 0, mi = desc->last; i < desc->count; i++, mi++) {
|
||||
if (mi >= desc->count) {
|
||||
mi = 0;
|
||||
}
|
||||
if (mi + nblocks >= desc->count) {
|
||||
continue;
|
||||
}
|
||||
for (j = mi; j < mi + nblocks; j++) {
|
||||
if (desc->map[j]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == mi + nblocks) {
|
||||
for (j = mi; j < mi + nblocks; j++) {
|
||||
desc->map[j] = (unsigned long)-1;
|
||||
}
|
||||
aal_mc_spinlock_unlock(&desc->lock, flags);
|
||||
return ADDRESS(desc, mi, 0);
|
||||
}
|
||||
}
|
||||
aal_mc_spinlock_unlock(&desc->lock, flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long aal_pagealloc_alloc(void *__desc, int npages)
|
||||
{
|
||||
struct aal_page_allocator_desc *desc = __desc;
|
||||
unsigned int i, mi;
|
||||
int j;
|
||||
unsigned long v, mask, flags;
|
||||
|
||||
/* If requested page is more than the half of the element,
|
||||
* we allocate the whole element (ulong) */
|
||||
if (npages >= 32) {
|
||||
return __aal_pagealloc_large(desc, (npages + 63) >> 6);
|
||||
}
|
||||
|
||||
mask = (1UL << npages) - 1;
|
||||
|
||||
flags = aal_mc_spinlock_lock(&desc->lock);
|
||||
for (i = 0, mi = desc->last; i < desc->count; i++, mi++) {
|
||||
if (mi >= desc->count) {
|
||||
mi = 0;
|
||||
}
|
||||
|
||||
v = desc->map[mi];
|
||||
if (v == (unsigned long)-1)
|
||||
continue;
|
||||
|
||||
for (j = 0; j <= 64 - npages; j++) {
|
||||
if (!(v & (mask << j))) { /* free */
|
||||
desc->map[mi] |= (mask << j);
|
||||
|
||||
aal_mc_spinlock_unlock(&desc->lock, flags);
|
||||
return ADDRESS(desc, mi, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
aal_mc_spinlock_unlock(&desc->lock, flags);
|
||||
|
||||
/* We use null pointer for failure */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void aal_pagealloc_reserve(void *__desc, unsigned long start, unsigned long end)
|
||||
{
|
||||
int i, n;
|
||||
struct aal_page_allocator_desc *desc = __desc;
|
||||
unsigned long flags;
|
||||
|
||||
n = (end + (1 << desc->shift) - 1 - desc->start) >> desc->shift;
|
||||
i = ((start - desc->start) >> desc->shift);
|
||||
if (i < 0 || n < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
flags = aal_mc_spinlock_lock(&desc->lock);
|
||||
for (; i < n; i++) {
|
||||
if (!(i & 63) && i + 63 < n) {
|
||||
desc->map[MAP_INDEX(i)] = (unsigned long)-1L;
|
||||
i += 63;
|
||||
} else {
|
||||
desc->map[MAP_INDEX(i)] |= (1UL << MAP_BIT(i));
|
||||
}
|
||||
}
|
||||
aal_mc_spinlock_unlock(&desc->lock, flags);
|
||||
}
|
||||
|
||||
void aal_pagealloc_free(void *__desc, unsigned long address, int npages)
|
||||
{
|
||||
struct aal_page_allocator_desc *desc = __desc;
|
||||
int i;
|
||||
unsigned mi;
|
||||
unsigned long flags;
|
||||
|
||||
/* XXX: Parameter check */
|
||||
if (npages >= 32) {
|
||||
npages = (npages + 63) & ~63;
|
||||
}
|
||||
flags = aal_mc_spinlock_lock(&desc->lock);
|
||||
mi = (address - desc->start) >> desc->shift;
|
||||
for (i = 0; i < npages; i++, mi++) {
|
||||
desc->map[MAP_INDEX(mi)] &= ~(1UL << MAP_BIT(mi));
|
||||
}
|
||||
aal_mc_spinlock_unlock(&desc->lock, flags);
|
||||
}
|
||||
|
||||
unsigned long aal_pagealloc_count(void *__desc)
|
||||
{
|
||||
struct aal_page_allocator_desc *desc = __desc;
|
||||
unsigned long i, j, n = 0;
|
||||
unsigned long flags;
|
||||
|
||||
flags = aal_mc_spinlock_lock(&desc->lock);
|
||||
/* XXX: Very silly counting */
|
||||
for (i = 0; i < desc->count; i++) {
|
||||
for (j = 0; j < 64; j++) {
|
||||
if (!(desc->map[i] & (1UL << j))) {
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
aal_mc_spinlock_unlock(&desc->lock, flags);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void __aal_pagealloc_zero_free_pages(void *__desc)
|
||||
{
|
||||
struct aal_page_allocator_desc *desc = __desc;
|
||||
unsigned int mi;
|
||||
int j;
|
||||
unsigned long v, flags;
|
||||
|
||||
kprintf("zeroing free memory... ");
|
||||
|
||||
flags = aal_mc_spinlock_lock(&desc->lock);
|
||||
for (mi = 0; mi < desc->count; mi++) {
|
||||
|
||||
v = desc->map[mi];
|
||||
if (v == (unsigned long)-1)
|
||||
continue;
|
||||
|
||||
for (j = 0; j < 64; j++) {
|
||||
if (!(v & ((unsigned long)1 << j))) { /* free */
|
||||
|
||||
memset(phys_to_virt(ADDRESS(desc, mi, j)), 0, PAGE_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
aal_mc_spinlock_unlock(&desc->lock, flags);
|
||||
|
||||
kprintf("\nzeroing done\n");
|
||||
}
|
||||
|
||||
|
||||
158
lib/string.c
Normal file
158
lib/string.c
Normal file
@@ -0,0 +1,158 @@
|
||||
#include <string.h>
|
||||
|
||||
size_t strlen(const char *p)
|
||||
{
|
||||
const char *head = p;
|
||||
|
||||
while(*p){
|
||||
p++;
|
||||
}
|
||||
|
||||
return p - head;
|
||||
}
|
||||
|
||||
size_t strnlen(const char *p, size_t maxlen)
|
||||
{
|
||||
const char *head = p;
|
||||
|
||||
while(*p && maxlen > 0){
|
||||
p++;
|
||||
maxlen--;
|
||||
}
|
||||
|
||||
return p - head;
|
||||
}
|
||||
|
||||
char *strcpy(char *dest, const char *src)
|
||||
{
|
||||
char *head = dest;
|
||||
|
||||
while((*(dest++) = *(src++)));
|
||||
|
||||
return head;
|
||||
}
|
||||
|
||||
char *strncpy(char *dest, const char *src, size_t maxlen)
|
||||
{
|
||||
char *head = dest;
|
||||
ssize_t len = maxlen;
|
||||
|
||||
while((*(dest++) = *(src++)) && --len);
|
||||
if(len > 0){
|
||||
while(len--){
|
||||
*(dest++) = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return head;
|
||||
}
|
||||
|
||||
int strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
while(*s1 && *s1 == *s2){
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return *s1 - *s2;
|
||||
}
|
||||
|
||||
int strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
while(*s1 && *s1 == *s2 && n > 1){
|
||||
s1++;
|
||||
s2++;
|
||||
n--;
|
||||
}
|
||||
return *s1 - *s2;
|
||||
}
|
||||
|
||||
char *strstr(const char *haystack, const char *needle)
|
||||
{
|
||||
int len = strlen(needle);
|
||||
|
||||
while(*haystack){
|
||||
if(!strncmp(haystack, needle, len)){
|
||||
return (char *)haystack;
|
||||
}
|
||||
haystack++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
const char *p1 = src;
|
||||
char *p2 = dest;
|
||||
|
||||
while(n > 0){
|
||||
*p2 = *p1;
|
||||
p1++;
|
||||
p2++;
|
||||
n--;
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
void *memcpy_long(void *dest, const void *src, size_t n)
|
||||
{
|
||||
const unsigned long *p1 = src;
|
||||
unsigned long *p2 = dest;
|
||||
|
||||
n /= sizeof(unsigned long);
|
||||
while (n > 0) {
|
||||
*(p2++) = *(p1++);
|
||||
n--;
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
void *memset(void *s, int c, size_t n)
|
||||
{
|
||||
char *s_aligned = (void *)(((unsigned long)s + 7) & ~7);
|
||||
char *e_aligned = (void *)(((unsigned long)s + n) & ~7);
|
||||
char *e = ((char *)s + n);
|
||||
char *p;
|
||||
unsigned long *l;
|
||||
#define C ((unsigned long)(c & 0xff))
|
||||
unsigned long pat = C | C << 8 | C << 16 | C << 24 | C << 32 |
|
||||
C << 40 | C << 48 | C << 56;
|
||||
#undef C
|
||||
|
||||
if(s_aligned < e_aligned){
|
||||
p = s;
|
||||
while(p < s_aligned){
|
||||
*(p++) = (char)c;
|
||||
}
|
||||
l = (unsigned long *)s_aligned;
|
||||
while((char *)l < e_aligned){
|
||||
*(l++) = pat;
|
||||
}
|
||||
p = e_aligned;
|
||||
while(p < e){
|
||||
*(p++) = (char)c;
|
||||
}
|
||||
}else{
|
||||
p = s;
|
||||
while(p < e){
|
||||
*(p++) = (char)c;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
const char *p1 = s1;
|
||||
const char *p2 = s2;
|
||||
|
||||
while(*p1 == *p2 && n > 1){
|
||||
p1++;
|
||||
p2++;
|
||||
n--;
|
||||
}
|
||||
return *p1 - *p2;
|
||||
}
|
||||
1440
lib/vsprintf.c
Normal file
1440
lib/vsprintf.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user