GK SDK 源码库: XMIPCLinuxV100R005C00SPC030 (kernel/tools/open_source excluded)
This commit is contained in:
@@ -0,0 +1,608 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
#ifndef __OSAL__
|
||||
#define __OSAL__
|
||||
|
||||
#define OSAL_VERSION "1.0"
|
||||
|
||||
#include "osal_list.h"
|
||||
#include "osal_devfreq.h"
|
||||
|
||||
#define osal_gfp_kernel 0
|
||||
#define osal_gfp_atomic 1
|
||||
extern void *osal_vmalloc(unsigned long size);
|
||||
extern void osal_vfree(const void *addr);
|
||||
extern void *osal_kmalloc(unsigned long size, unsigned int osal_gfp_flag);
|
||||
extern void osal_kfree(const void *addr);
|
||||
|
||||
// atomic api
|
||||
typedef struct {
|
||||
void *atomic;
|
||||
} osal_atomic_t;
|
||||
|
||||
#define OSAL_ATOMIC_INIT(i) { (i) }
|
||||
|
||||
extern int osal_atomic_init(osal_atomic_t *atomic);
|
||||
extern void osal_atomic_destory(osal_atomic_t *atomic);
|
||||
extern void osal_atomic_destroy(osal_atomic_t *atomic);
|
||||
extern int osal_atomic_read(osal_atomic_t *v);
|
||||
extern void osal_atomic_set(osal_atomic_t *v, int i);
|
||||
extern int osal_atomic_inc_return(osal_atomic_t *v);
|
||||
extern int osal_atomic_dec_return(osal_atomic_t *v);
|
||||
|
||||
// semaphore api
|
||||
#define EINTR 4
|
||||
typedef struct osal_semaphore {
|
||||
void *sem;
|
||||
} osal_semaphore_t;
|
||||
extern int osal_sema_init(osal_semaphore_t *sem, int val);
|
||||
extern int osal_down(osal_semaphore_t *sem);
|
||||
extern int osal_down_interruptible(osal_semaphore_t *sem);
|
||||
extern int osal_down_trylock(osal_semaphore_t *sem);
|
||||
extern void osal_up(osal_semaphore_t *sem);
|
||||
// notice:must be called when kmod exit, other wise will lead to memory leak;
|
||||
extern void osal_sema_destory(osal_semaphore_t *sem);
|
||||
extern void osal_sema_destroy(osal_semaphore_t *sem);
|
||||
|
||||
// mutex api
|
||||
typedef struct osal_mutex {
|
||||
void *mutex;
|
||||
} osal_mutex_t;
|
||||
extern int osal_mutex_init(osal_mutex_t *mutex);
|
||||
extern int osal_mutex_lock(osal_mutex_t *mutex);
|
||||
extern int osal_mutex_lock_interruptible(osal_mutex_t *mutex);
|
||||
extern int osal_mutex_trylock(osal_mutex_t *mutex);
|
||||
extern void osal_mutex_unlock(osal_mutex_t *mutex);
|
||||
// notice:must be called when kmod exit, other wise will lead to memory leak;
|
||||
extern void osal_mutex_destroy(osal_mutex_t *mutex);
|
||||
|
||||
// spin lock api
|
||||
typedef struct osal_spinlock {
|
||||
void *lock;
|
||||
} osal_spinlock_t;
|
||||
extern int osal_spin_lock_init(osal_spinlock_t *lock);
|
||||
extern void osal_spin_lock(osal_spinlock_t *lock);
|
||||
extern int osal_spin_trylock(osal_spinlock_t *lock);
|
||||
extern void osal_spin_unlock(osal_spinlock_t *lock);
|
||||
extern void osal_spin_lock_irqsave(osal_spinlock_t *lock, unsigned long *flags);
|
||||
extern void osal_spin_unlock_irqrestore(osal_spinlock_t *lock, unsigned long *flags);
|
||||
// notice:must be called when kmod exit, other wise will lead to memory leak;
|
||||
extern void osal_spin_lock_destory(osal_spinlock_t *lock);
|
||||
extern void osal_spin_lock_destroy(osal_spinlock_t *lock);
|
||||
|
||||
// wait api
|
||||
typedef int (*osal_wait_cond_func_t)(const void *param);
|
||||
|
||||
typedef struct osal_wait {
|
||||
void *wait;
|
||||
} osal_wait_t;
|
||||
#define ERESTARTSYS 512
|
||||
|
||||
extern unsigned long osal_msecs_to_jiffies(const unsigned int m);
|
||||
extern int osal_wait_init(osal_wait_t *wait);
|
||||
extern int osal_wait_interruptible(osal_wait_t *wait, osal_wait_cond_func_t func, void *param);
|
||||
extern int osal_wait_uninterruptible(osal_wait_t *wait, osal_wait_cond_func_t func, void *param);
|
||||
extern int osal_wait_timeout_interruptible(osal_wait_t *wait, osal_wait_cond_func_t func, void *param,
|
||||
unsigned long ms);
|
||||
extern int osal_wait_timeout_uninterruptible(osal_wait_t *wait, osal_wait_cond_func_t func, void *param,
|
||||
unsigned long ms);
|
||||
|
||||
#define osal_wait_event_interruptible(wait, func, param) \
|
||||
({ \
|
||||
int __ret = 0; \
|
||||
\
|
||||
for (;;) { \
|
||||
if (func(param)) { \
|
||||
__ret = 0; \
|
||||
break; \
|
||||
} \
|
||||
__ret = osal_wait_timeout_interruptible(wait, (func), param, 100); \
|
||||
if (__ret < 0) \
|
||||
break; \
|
||||
} \
|
||||
__ret; \
|
||||
})
|
||||
|
||||
#define osal_wait_event_uninterruptible(wait, func, param) \
|
||||
({ \
|
||||
int __ret = 0; \
|
||||
\
|
||||
for (;;) { \
|
||||
if (func(param)) { \
|
||||
__ret = 0; \
|
||||
break; \
|
||||
} \
|
||||
__ret = osal_wait_uninterruptible(wait, (func), param); \
|
||||
if (__ret < 0) \
|
||||
break; \
|
||||
} \
|
||||
__ret; \
|
||||
})
|
||||
|
||||
#define osal_wait_event_timeout_interruptible(wait, func, param, timeout) \
|
||||
({ \
|
||||
int __ret = timeout; \
|
||||
\
|
||||
if ((func(param)) && !timeout) { \
|
||||
__ret = 1; \
|
||||
} \
|
||||
\
|
||||
for (;;) { \
|
||||
if (func(param)) { \
|
||||
__ret = osal_msecs_to_jiffies(__ret); \
|
||||
break; \
|
||||
} \
|
||||
__ret = osal_wait_timeout_interruptible(wait, (func), param, __ret); \
|
||||
if (!__ret || __ret == -ERESTARTSYS) \
|
||||
break; \
|
||||
} \
|
||||
__ret; \
|
||||
})
|
||||
|
||||
#define osal_wait_event_timeout_uninterruptible(wait, func, param, timeout) \
|
||||
({ \
|
||||
int __ret = timeout; \
|
||||
\
|
||||
if ((func(param)) && !timeout) { \
|
||||
__ret = 1; \
|
||||
} \
|
||||
\
|
||||
for (;;) { \
|
||||
if (func(param)) { \
|
||||
__ret = osal_msecs_to_jiffies(__ret); \
|
||||
break; \
|
||||
} \
|
||||
__ret = osal_wait_timeout_uninterruptible(wait, (func), param, __ret); \
|
||||
if (!__ret || __ret == -ERESTARTSYS) \
|
||||
break; \
|
||||
} \
|
||||
__ret; \
|
||||
})
|
||||
|
||||
extern void osal_wakeup(osal_wait_t *wait); // same as wake_up_all
|
||||
extern void osal_wait_destory(osal_wait_t *wait);
|
||||
extern void osal_wait_destroy(osal_wait_t *wait);
|
||||
|
||||
// workqueue api
|
||||
typedef struct osal_work_struct {
|
||||
void *work;
|
||||
void (*func)(struct osal_work_struct *work);
|
||||
} osal_work_struct_t;
|
||||
typedef void (*osal_work_func_t)(struct osal_work_struct *work);
|
||||
|
||||
extern int osal_init_work(struct osal_work_struct *work, osal_work_func_t func);
|
||||
|
||||
#define OSAL_INIT_WORK(_work, _func) \
|
||||
do { \
|
||||
osal_init_work((_work), (_func)); \
|
||||
} while (0)
|
||||
|
||||
extern int osal_schedule_work(struct osal_work_struct *work);
|
||||
extern void osal_destroy_work(struct osal_work_struct *work);
|
||||
|
||||
// shedule
|
||||
extern void osal_yield(void);
|
||||
|
||||
// interrupt api
|
||||
enum osal_irqreturn {
|
||||
OSAL_IRQ_NONE = (0 << 0),
|
||||
OSAL_IRQ_HANDLED = (1 << 0),
|
||||
OSAL_IRQ_WAKE_THREAD = (1 << 1),
|
||||
};
|
||||
|
||||
typedef int (*osal_irq_handler_t)(int, void *);
|
||||
extern int osal_request_irq(unsigned int irq, osal_irq_handler_t handler, osal_irq_handler_t thread_fn,
|
||||
const char *name, void *dev);
|
||||
extern void osal_free_irq(unsigned int irq, void *dev);
|
||||
extern int osal_in_interrupt(void);
|
||||
|
||||
#define OSAL_DIS_IRQ_CNT 2
|
||||
typedef void (*osal_gic_handle_t)(unsigned int, unsigned int, void *);
|
||||
extern int osal_register_gic_handle(unsigned int index, unsigned int irq, osal_gic_handle_t handle, const char *name,
|
||||
void *dev);
|
||||
extern int osal_unregister_gic_handle(unsigned int index, unsigned int irq, void *dev);
|
||||
|
||||
// task api
|
||||
typedef struct osal_task {
|
||||
void *task_struct;
|
||||
} osal_task_t;
|
||||
typedef int (*threadfn_t)(void *data);
|
||||
extern osal_task_t *osal_kthread_create(threadfn_t thread, void *data, const char *name);
|
||||
extern void osal_kthread_destory(osal_task_t *task, unsigned int stop_flag);
|
||||
extern void osal_kthread_destroy(osal_task_t *task, unsigned int stop_flag);
|
||||
int osal_kthread_should_stop(void);
|
||||
|
||||
// string api
|
||||
extern char *osal_strcpy(char *s1, const char *s2);
|
||||
extern char *osal_strncpy(char *s1, const char *s2, int size);
|
||||
extern int osal_strlcpy(char *s1, const char *s2, int size);
|
||||
extern char *osal_strcat(char *s1, const char *s2);
|
||||
extern char *osal_strncat(char *s1, const char *s2, int size);
|
||||
extern int osal_strlcat(char *s1, const char *s2, int size);
|
||||
extern int osal_strcmp(const char *s1, const char *s2);
|
||||
extern int osal_strncmp(const char *s1, const char *s2, int size);
|
||||
extern int osal_strnicmp(const char *s1, const char *s2, int size);
|
||||
extern int osal_strcasecmp(const char *s1, const char *s2);
|
||||
extern int osal_strncasecmp(const char *s1, const char *s2, int n);
|
||||
extern char *osal_strchr(const char *s, int n);
|
||||
extern char *osal_strnchr(const char *s, int count, int c);
|
||||
extern char *osal_strrchr(const char *s, int c);
|
||||
extern char *osal_strstr(const char *s1, const char *s2);
|
||||
extern char *osal_strnstr(const char *s1, const char *s2, int n);
|
||||
extern int osal_strlen(const char *s);
|
||||
extern int osal_strnlen(const char *s, int size);
|
||||
extern char *osal_strpbrk(const char *s1, const char *s2);
|
||||
extern char *osal_strsep(char **s, const char *ct);
|
||||
extern int osal_strspn(const char *s, const char *accept);
|
||||
extern int osal_strcspn(const char *s, const char *reject);
|
||||
extern void *osal_memset(void *str, int c, int count);
|
||||
extern void *osal_memcpy(void *s1, const void *s2, int count);
|
||||
extern void *osal_memmove(void *s1, const void *s2, int count);
|
||||
extern void *osal_memscan(void *addr, int c, int size);
|
||||
extern int osal_memcmp(const void *cs, const void *ct, int count);
|
||||
extern void *osal_memchr(const void *s, int c, int n);
|
||||
extern void *osal_memchr_inv(const void *s, int c, int n);
|
||||
|
||||
extern unsigned long long osal_strtoull(const char *cp, char **endp, unsigned int base);
|
||||
extern unsigned long osal_strtoul(const char *cp, char **endp, unsigned int base);
|
||||
extern long osal_strtol(const char *cp, char **endp, unsigned int base);
|
||||
extern long long osal_strtoll(const char *cp, char **endp, unsigned int base);
|
||||
extern int osal_snprintf(char *buf, int size, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
|
||||
extern int osal_scnprintf(char *buf, int size, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
|
||||
extern int osal_sprintf(char *buf, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
|
||||
extern int osal_sscanf(const char *buf, const char *fmt, ...);
|
||||
|
||||
// addr translate
|
||||
extern void *osal_ioremap(unsigned long phys_addr, unsigned long size);
|
||||
extern void *osal_ioremap_nocache(unsigned long phys_addr, unsigned long size);
|
||||
extern void *osal_ioremap_cached(unsigned long phys_addr, unsigned long size);
|
||||
extern void *osal_ioremap_wc(unsigned long phys_addr, unsigned long size);
|
||||
extern void osal_iounmap(void *addr);
|
||||
|
||||
#define osal_readl(x) (*((volatile int *)(x)))
|
||||
#define osal_writel(v, x) (*((volatile int *)(x)) = (v))
|
||||
|
||||
extern unsigned long osal_copy_from_user(void *to, const void *from, unsigned long n);
|
||||
extern unsigned long osal_copy_to_user(void *to, const void *from, unsigned long n);
|
||||
|
||||
#define OSAL_VERIFY_READ 0
|
||||
#define OSAL_VERIFY_WRITE 1
|
||||
extern int osal_access_ok(int type, const void *addr, unsigned long size);
|
||||
|
||||
// cache api
|
||||
extern void osal_flush_cache_all(void);
|
||||
extern void osal_cpuc_flush_dcache_area(void *addr, int size);
|
||||
|
||||
extern void osal_flush_dcache_area(void *kvirt, unsigned long phys_addr, unsigned long length);
|
||||
extern int osal_flush_dcache_all(void);
|
||||
|
||||
// math
|
||||
extern int osal_isdigit(int c);
|
||||
extern void osal_kernel_neon_end(void);
|
||||
extern void osal_kernel_neon_begin(void);
|
||||
extern unsigned long long osal_div_u64(unsigned long long dividend, unsigned int divisor);
|
||||
extern long long osal_div_s64(long long dividend, int divisor);
|
||||
extern unsigned long long osal_div64_u64(unsigned long long dividend, unsigned long long divisor);
|
||||
extern long long osal_div64_s64(long long dividend, long long divisor);
|
||||
extern unsigned long long osal_div_u64_rem(unsigned long long dividend, unsigned int divisor);
|
||||
extern long long osal_div_s64_rem(long long dividend, int divisor);
|
||||
extern unsigned long long osal_div64_u64_rem(unsigned long long dividend, unsigned long long divisor);
|
||||
extern unsigned int osal_random(void);
|
||||
|
||||
#define osal_max(x, y) ({ \
|
||||
__typeof__(x) _max1 = (x); \
|
||||
__typeof__(y) _max2 = (y); \
|
||||
(void) (&_max1 == &_max2); \
|
||||
_max1 > _max2 ? _max1 : _max2; })
|
||||
|
||||
#define osal_min(x, y) ({ \
|
||||
__typeof__(x) _min1 = (x); \
|
||||
__typeof__(y) _min2 = (y); \
|
||||
(void) (&_min1 == &_min2); \
|
||||
_min1 < _min2 ? _min1 : _min2; })
|
||||
|
||||
#define osal_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; \
|
||||
})
|
||||
|
||||
// barrier
|
||||
extern void osal_mb(void);
|
||||
extern void osal_rmb(void);
|
||||
extern void osal_wmb(void);
|
||||
extern void osal_smp_mb(void);
|
||||
extern void osal_smp_rmb(void);
|
||||
extern void osal_smp_wmb(void);
|
||||
extern void osal_isb(void);
|
||||
extern void osal_dsb(void);
|
||||
extern void osal_dmb(void);
|
||||
|
||||
// debug
|
||||
extern int osal_printk(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
extern void osal_panic(const char *fmt, const char *fun, int line, const char *);
|
||||
#define OSAL_BUG() \
|
||||
do { \
|
||||
} while (1)
|
||||
|
||||
#define OSAL_ASSERT(expr) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
osal_printk("\nASSERT failed at:\n" \
|
||||
" >Condition: %s\n", \
|
||||
#expr); \
|
||||
OSAL_BUG(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define OSAL_BUG_ON(expr) \
|
||||
do { \
|
||||
if (expr) { \
|
||||
osal_printk("BUG: failure at %d/%s()!\n", __LINE__, __func__); \
|
||||
OSAL_BUG(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// proc
|
||||
typedef struct osal_proc_dir_entry {
|
||||
char name[50];
|
||||
void *proc_dir_entry;
|
||||
int (*open)(struct osal_proc_dir_entry *entry);
|
||||
int (*read)(struct osal_proc_dir_entry *entry);
|
||||
int (*write)(struct osal_proc_dir_entry *entry, const char *buf, int count, long long *);
|
||||
void *private;
|
||||
void *seqfile;
|
||||
struct osal_list_head node;
|
||||
} osal_proc_entry_t;
|
||||
extern osal_proc_entry_t *osal_create_proc_entry(const char *name, osal_proc_entry_t *parent);
|
||||
extern osal_proc_entry_t *osal_proc_mkdir(const char *name, osal_proc_entry_t *parent);
|
||||
extern void osal_remove_proc_entry(const char *name, osal_proc_entry_t *parent);
|
||||
extern void osal_seq_printf(osal_proc_entry_t *entry, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
|
||||
|
||||
// device api
|
||||
#ifndef _IOC_TYPECHECK
|
||||
#ifdef __KERNEL__
|
||||
#include "osal_ioctl.h"
|
||||
#endif
|
||||
#endif
|
||||
typedef struct osal_dev {
|
||||
char name[48];
|
||||
void *dev;
|
||||
int minor;
|
||||
struct osal_fileops *fops;
|
||||
struct osal_pmops *osal_pmops;
|
||||
struct osal_devfreq_dev_profile *osal_profile;
|
||||
} osal_dev_t;
|
||||
|
||||
typedef struct osal_devfreq_dev_profile {
|
||||
unsigned long initial_freq;
|
||||
unsigned int polling_ms;
|
||||
|
||||
int (*target)(osal_dev_t *dev, unsigned long *freq, unsigned int flags);
|
||||
int (*get_dev_status)(osal_dev_t *dev, struct osal_devfreq_dev_status *stat);
|
||||
int (*get_cur_freq)(osal_dev_t *dev, unsigned long *freq);
|
||||
void (*exit)(osal_dev_t *dev);
|
||||
|
||||
unsigned long *freq_table;
|
||||
unsigned int max_state;
|
||||
} osal_devfreq_dev_profile_t;
|
||||
|
||||
typedef struct osal_vm {
|
||||
void *vm;
|
||||
} osal_vm_t;
|
||||
|
||||
#define OSAL_POLLIN 0x0001
|
||||
#define OSAL_POLLPRI 0x0002
|
||||
#define OSAL_POLLOUT 0x0004
|
||||
#define OSAL_POLLERR 0x0008
|
||||
#define OSAL_POLLHUP 0x0010
|
||||
#define OSAL_POLLNVAL 0x0020
|
||||
#define OSAL_POLLRDNORM 0x0040
|
||||
#define OSAL_POLLRDBAND 0x0080
|
||||
#define OSAL_POLLWRNORM 0x0100
|
||||
|
||||
typedef struct osal_poll {
|
||||
void *poll_table;
|
||||
void *data;
|
||||
} osal_poll_t;
|
||||
|
||||
typedef struct osal_fileops {
|
||||
int (*open)(void *private_data);
|
||||
int (*read)(char *buf, int size, long *offset, void *private_data);
|
||||
int (*write)(const char *buf, int size, long *offset, void *private_data);
|
||||
long (*llseek)(long offset, int whence, void *private_data);
|
||||
int (*release)(void *private_data);
|
||||
long (*unlocked_ioctl)(unsigned int cmd, unsigned long arg, void *private_data);
|
||||
unsigned int (*poll)(osal_poll_t *osal_poll, void *private_data);
|
||||
int (*mmap)(osal_vm_t *vm, unsigned long start, unsigned long end, unsigned long vm_pgoff, void *private_data);
|
||||
#ifdef CONFIG_COMPAT
|
||||
long (*compat_ioctl)(unsigned int cmd, unsigned long arg, void *private_data);
|
||||
#endif
|
||||
} osal_fileops_t;
|
||||
|
||||
typedef struct osal_pmops {
|
||||
int (*pm_prepare)(osal_dev_t *dev);
|
||||
void (*pm_complete)(osal_dev_t *dev);
|
||||
int (*pm_suspend)(osal_dev_t *dev);
|
||||
int (*pm_resume)(osal_dev_t *dev);
|
||||
int (*pm_freeze)(osal_dev_t *dev);
|
||||
int (*pm_thaw)(osal_dev_t *dev);
|
||||
int (*pm_poweroff)(osal_dev_t *dev);
|
||||
int (*pm_restore)(osal_dev_t *dev);
|
||||
int (*pm_suspend_late)(osal_dev_t *dev);
|
||||
int (*pm_resume_early)(osal_dev_t *dev);
|
||||
int (*pm_freeze_late)(osal_dev_t *dev);
|
||||
int (*pm_thaw_early)(osal_dev_t *dev);
|
||||
int (*pm_poweroff_late)(osal_dev_t *dev);
|
||||
int (*pm_restore_early)(osal_dev_t *dev);
|
||||
int (*pm_suspend_noirq)(osal_dev_t *dev);
|
||||
int (*pm_resume_noirq)(osal_dev_t *dev);
|
||||
int (*pm_freeze_noirq)(osal_dev_t *dev);
|
||||
int (*pm_thaw_noirq)(osal_dev_t *dev);
|
||||
int (*pm_poweroff_noirq)(osal_dev_t *dev);
|
||||
int (*pm_restore_noirq)(osal_dev_t *dev);
|
||||
} osal_pmops_t;
|
||||
|
||||
#define OSAL_SEEK_SET 0
|
||||
#define OSAL_SEEK_CUR 1
|
||||
#define OSAL_SEEK_END 2
|
||||
|
||||
// #define PAGE_SHIFT 12
|
||||
|
||||
extern osal_dev_t *osal_createdev(const char *name);
|
||||
extern int osal_destroydev(osal_dev_t *pdev);
|
||||
extern int osal_registerdevice(osal_dev_t *pdev);
|
||||
extern void osal_deregisterdevice(osal_dev_t *pdev);
|
||||
extern void osal_poll_wait(osal_poll_t *table, osal_wait_t *wait);
|
||||
extern void osal_pgprot_noncached(osal_vm_t *vm);
|
||||
extern void osal_pgprot_cached(osal_vm_t *vm);
|
||||
extern void osal_pgprot_writecombine(osal_vm_t *vm);
|
||||
extern void osal_pgprot_stronglyordered(osal_vm_t *vm);
|
||||
extern int osal_remap_pfn_range(osal_vm_t *vm, unsigned long addr, unsigned long pfn, unsigned long size);
|
||||
extern int osal_io_remap_pfn_range(osal_vm_t *vm, unsigned long addr, unsigned long pfn, unsigned long size);
|
||||
extern int osal_devfreq_register(osal_dev_t *osal_dev, struct osal_devfreq_dev_profile *osal_profile,
|
||||
const char *governor, void *data);
|
||||
extern void osal_devfreq_unregister(osal_dev_t *osal_dev);
|
||||
|
||||
|
||||
// timer
|
||||
typedef struct osal_timer {
|
||||
void *timer;
|
||||
void (*function)(unsigned long);
|
||||
unsigned long data;
|
||||
} osal_timer_t;
|
||||
|
||||
typedef struct osal_timeval {
|
||||
long tv_sec;
|
||||
long tv_usec;
|
||||
} osal_timeval_t;
|
||||
|
||||
typedef struct osal_rtc_time {
|
||||
int tm_sec;
|
||||
int tm_min;
|
||||
int tm_hour;
|
||||
int tm_mday;
|
||||
int tm_mon;
|
||||
int tm_year;
|
||||
int tm_wday;
|
||||
int tm_yday;
|
||||
int tm_isdst;
|
||||
} osal_rtc_time_t;
|
||||
|
||||
/* Return values for the timer callback function */
|
||||
typedef enum OSAL_HRTIMER_RESTART_E {
|
||||
OSAL_HRTIMER_NORESTART, /* < The timer will not be restarted. */
|
||||
OSAL_HRTIMER_RESTART /* < The timer must be restarted. */
|
||||
} OSAL_HRTIMER_RESTART_E;
|
||||
|
||||
/* hrtimer struct */
|
||||
typedef struct osal_hrtimer {
|
||||
void *timer;
|
||||
OSAL_HRTIMER_RESTART_E (*function)(void *timer);
|
||||
unsigned long interval; /* Unit ms */
|
||||
} osal_hrtimer_t;
|
||||
|
||||
extern int osal_hrtimer_create(osal_hrtimer_t *phrtimer);
|
||||
extern int osal_hrtimer_start(osal_hrtimer_t *phrtimer);
|
||||
extern int osal_hrtimer_destroy(osal_hrtimer_t *phrtimer);
|
||||
|
||||
extern int osal_timer_init(osal_timer_t *timer);
|
||||
extern int osal_set_timer(osal_timer_t *timer, unsigned long interval); /* ms */
|
||||
extern unsigned long osal_timer_get_private_data(void *data);
|
||||
extern int osal_del_timer(osal_timer_t *timer);
|
||||
extern int osal_timer_destory(osal_timer_t *timer);
|
||||
extern int osal_timer_destroy(osal_timer_t *timer);
|
||||
|
||||
extern unsigned long osal_msleep(unsigned int msecs);
|
||||
extern void osal_udelay(unsigned int usecs);
|
||||
extern void osal_mdelay(unsigned int msecs);
|
||||
|
||||
extern unsigned int osal_get_tickcount(void);
|
||||
extern unsigned long long osal_sched_clock(void);
|
||||
extern void osal_gettimeofday(osal_timeval_t *tv);
|
||||
|
||||
/* unit is ns */
|
||||
extern unsigned long long osal_get_boottime(void);
|
||||
extern void osal_rtc_time_to_tm(unsigned long time, osal_rtc_time_t *tm);
|
||||
extern void osal_rtc_tm_to_time(osal_rtc_time_t *tm, unsigned long *time);
|
||||
extern int osal_rtc_valid_tm(struct osal_rtc_time *tm);
|
||||
extern void osal_getjiffies(unsigned long long *pjiffies);
|
||||
|
||||
#define OSAL_O_ACCMODE 00000003
|
||||
#define OSAL_O_RDONLY 00000000
|
||||
#define OSAL_O_WRONLY 00000001
|
||||
#define OSAL_O_RDWR 00000002
|
||||
#define OSAL_O_CREAT 00000100
|
||||
|
||||
extern void *osal_klib_fopen(const char *filename, int flags, int mode);
|
||||
extern void osal_klib_fclose(void *filp);
|
||||
extern int osal_klib_fwrite(const char *buf, int len, void *filp);
|
||||
extern int osal_klib_fread(char *buf, unsigned int len, void *filp);
|
||||
|
||||
// reboot
|
||||
struct osal_notifier_block {
|
||||
int (*notifier_call)(struct osal_notifier_block *nb, unsigned long action, void *data);
|
||||
void *notifier_block;
|
||||
};
|
||||
typedef int (*osal_notifier_fn_t)(struct osal_notifier_block *nb, unsigned long action, void *data);
|
||||
|
||||
extern int osal_register_reboot_notifier(struct osal_notifier_block *nb);
|
||||
extern int osal_unregister_reboot_notifier(struct osal_notifier_block *nb);
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifndef _OSAL_VA_LIST
|
||||
|
||||
#define _OSAL_VA_LIST
|
||||
#define osal_va_list va_list
|
||||
#define osal_va_arg(ap, T) va_arg(ap, T)
|
||||
#define osal_va_end(ap) va_end(ap)
|
||||
#define osal_va_start(ap, A) va_start(ap, A)
|
||||
|
||||
#endif /* va_arg */
|
||||
|
||||
#define NULL_STRING "NULL"
|
||||
|
||||
extern void osal_vprintk(const char *fmt, osal_va_list args);
|
||||
extern int osal_vsnprintf(char *str, int size, const char *fmt, osal_va_list args);
|
||||
|
||||
#ifdef CONFIG_SNAPSHOT_BOOT
|
||||
|
||||
#ifndef OSAL_UMH_WAIT_PROC
|
||||
#define OSAL_UMH_WAIT_PROC 2 /* wait for the process to complete */
|
||||
#endif
|
||||
|
||||
extern int osal_call_usermodehelper_force(char *path, char **argv, char **envp, int wait);
|
||||
#endif
|
||||
|
||||
int osal_platform_driver_register(void *drv);
|
||||
void osal_platform_driver_unregister(void *drv);
|
||||
void *osal_platform_get_resource_byname(void *dev, unsigned int type, const char *name);
|
||||
void *osal_platform_get_resource(void *dev, unsigned int type, unsigned int num);
|
||||
int osal_platform_get_irq(void *dev, unsigned int num);
|
||||
int osal_platform_get_irq_byname(void *dev, const char *name);
|
||||
|
||||
#define osal_module_driver(osal_driver, osal_register, osal_unregister, ...) \
|
||||
static int __init osal_driver##_init(void) \
|
||||
{ \
|
||||
return osal_register(&(osal_driver)); \
|
||||
} \
|
||||
module_init(osal_driver##_init); \
|
||||
static void __exit osal_driver##_exit(void) \
|
||||
{ \
|
||||
osal_unregister(&(osal_driver)); \
|
||||
} \
|
||||
module_exit(osal_driver##_exit);
|
||||
|
||||
#define osal_module_platform_driver(platform_driver) \
|
||||
osal_module_driver(platform_driver, osal_platform_driver_register, \
|
||||
osal_platform_driver_unregister)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
#ifndef __OSAL_DEVFREQ__H
|
||||
#define __OSAL_DEVFREQ__H
|
||||
|
||||
typedef struct osal_devfreq_dev_status {
|
||||
/* both since the last measure */
|
||||
unsigned long total_time;
|
||||
unsigned long busy_time;
|
||||
unsigned long current_frequency;
|
||||
void *private_data;
|
||||
} osal_devfreq_dev_status_t;
|
||||
|
||||
typedef struct osal_devfreq_para {
|
||||
unsigned long initial_freq;
|
||||
unsigned int polling_ms;
|
||||
unsigned long *freq_table;
|
||||
unsigned int max_state;
|
||||
} osal_devfreq_para_t;
|
||||
|
||||
#endif /* __OSAL_DEVFREQ__H */
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
#ifndef _DRV_IOCTL_H
|
||||
#define _DRV_IOCTL_H
|
||||
|
||||
/* ioctl command encoding: 32 bits total, command in lower 16 bits,
|
||||
* size of the parameter structure in the lower 14 bits of the
|
||||
* upper 16 bits.
|
||||
* Encoding the size of the parameter structure in the ioctl request
|
||||
* is useful for catching programs compiled with old versions
|
||||
* and to avoid overwriting user space outside the user buffer area.
|
||||
* The highest 2 bits are reserved for indicating the ``access mode''.
|
||||
* NOTE: This limits the max parameter size to 16kB -1 !
|
||||
*/
|
||||
|
||||
/*
|
||||
* The following is for compatibility across the various Linux
|
||||
* platforms. The generic ioctl numbering scheme doesn't really enforce
|
||||
* a type field. De facto, however, the top 8 bits of the lower 16
|
||||
* bits are indeed used as a type field, so we might just as well make
|
||||
* this explicit here. Please be sure to use the decoding macros
|
||||
* below from now on.
|
||||
*/
|
||||
#define _IOC_NRBITS 8
|
||||
#define _IOC_TYPEBITS 8
|
||||
|
||||
/*
|
||||
* Let any architecture override either of the following before
|
||||
* including this file.
|
||||
*/
|
||||
|
||||
#ifndef _IOC_SIZEBITS
|
||||
#define _IOC_SIZEBITS 14
|
||||
#endif
|
||||
|
||||
#ifndef _IOC_DIRBITS
|
||||
#define _IOC_DIRBITS 2
|
||||
#endif
|
||||
|
||||
#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
|
||||
#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
|
||||
#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
|
||||
#define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
|
||||
|
||||
#define _IOC_NRSHIFT 0
|
||||
#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
|
||||
#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
|
||||
#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
|
||||
|
||||
/*
|
||||
* Direction bits, which any architecture can choose to override
|
||||
* before including this file.
|
||||
*/
|
||||
|
||||
#ifndef _IOC_NONE
|
||||
#define _IOC_NONE 0U
|
||||
#endif
|
||||
|
||||
#ifndef _IOC_WRITE
|
||||
#define _IOC_WRITE 1U
|
||||
#endif
|
||||
|
||||
#ifndef _IOC_READ
|
||||
#define _IOC_READ 2U
|
||||
#endif
|
||||
|
||||
#define _IOC(dir, type, nr, size) \
|
||||
(((dir) << _IOC_DIRSHIFT) | \
|
||||
((type) << _IOC_TYPESHIFT) | \
|
||||
((nr) << _IOC_NRSHIFT) | \
|
||||
((size) << _IOC_SIZESHIFT))
|
||||
|
||||
// #define _IOC_TYPECHECK(t) (sizeof(t))
|
||||
|
||||
#ifdef __CHECKER__
|
||||
#define _IOC_TYPECHECK(t) (sizeof(t))
|
||||
#else
|
||||
/* provoke compile error for invalid uses of size argument */
|
||||
extern unsigned int __invalid_size_argument_for_IOC;
|
||||
#define _IOC_TYPECHECK(t) \
|
||||
((sizeof(t) == sizeof(t[1]) && \
|
||||
sizeof(t) < (1 << _IOC_SIZEBITS)) \
|
||||
? sizeof(t) \
|
||||
: __invalid_size_argument_for_IOC)
|
||||
#endif
|
||||
|
||||
/* used to create numbers */
|
||||
#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
|
||||
#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),(_IOC_TYPECHECK(size)))
|
||||
#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
|
||||
#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
|
||||
#define _IOR_BAD(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
|
||||
#define _IOW_BAD(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
|
||||
#define _IOWR_BAD(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
|
||||
|
||||
/* used to decode ioctl numbers.. */
|
||||
#define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
|
||||
#define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
|
||||
#define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
|
||||
#define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
|
||||
|
||||
#define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT)
|
||||
#define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT)
|
||||
#define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
|
||||
#define IOCSIZE_MASK (_IOC_SIZEMASK << _IOC_SIZESHIFT)
|
||||
#define IOCSIZE_SHIFT (_IOC_SIZESHIFT)
|
||||
|
||||
#endif /* _DRV_IOCTL_H */
|
||||
@@ -0,0 +1,745 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
#ifndef _OSAL_LIST_H
|
||||
#define _OSAL_LIST_H
|
||||
|
||||
#define OSAL_NULL (0)
|
||||
|
||||
/*
|
||||
* 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 osal_list_head {
|
||||
struct osal_list_head *next, *prev;
|
||||
};
|
||||
#define OSAL_LIST_HEAD_INIT(name) \
|
||||
{ \
|
||||
&(name), &(name) \
|
||||
}
|
||||
|
||||
#define OSAL_LIST_HEAD(name) \
|
||||
struct osal_list_head name = OSAL_LIST_HEAD_INIT(name)
|
||||
|
||||
static inline void OSAL_INIT_LIST_HEAD(struct osal_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 osal___list_add(struct osal_list_head *new,
|
||||
struct osal_list_head *prev,
|
||||
struct osal_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 osal_list_add(struct osal_list_head *new, struct osal_list_head *head)
|
||||
{
|
||||
osal___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 osal_list_add_tail(struct osal_list_head *new, struct osal_list_head *head)
|
||||
{
|
||||
osal___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 osal___list_del(struct osal_list_head *prev, struct osal_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 osal___list_del_entry(struct osal_list_head *entry)
|
||||
{
|
||||
osal___list_del(entry->prev, entry->next);
|
||||
}
|
||||
|
||||
#define OSAL_LIST_POISON1 ((void *)0x00100100)
|
||||
#define OSAL_LIST_POISON2 ((void *)0x00200200)
|
||||
|
||||
static inline void osal_list_del(struct osal_list_head *entry)
|
||||
{
|
||||
osal___list_del(entry->prev, entry->next);
|
||||
entry->next = OSAL_LIST_POISON1;
|
||||
entry->prev = OSAL_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 osal_list_replace(struct osal_list_head *old,
|
||||
struct osal_list_head *new)
|
||||
{
|
||||
new->next = old->next;
|
||||
new->next->prev = new;
|
||||
new->prev = old->prev;
|
||||
new->prev->next = new;
|
||||
}
|
||||
|
||||
static inline void osal_list_replace_init(struct osal_list_head *old,
|
||||
struct osal_list_head *new)
|
||||
{
|
||||
osal_list_replace(old, new);
|
||||
OSAL_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 osal_list_del_init(struct osal_list_head *entry)
|
||||
{
|
||||
osal___list_del_entry(entry);
|
||||
OSAL_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 osal_list_move(struct osal_list_head *list, struct osal_list_head *head)
|
||||
{
|
||||
osal___list_del_entry(list);
|
||||
osal_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 osal_list_move_tail(struct osal_list_head *list,
|
||||
struct osal_list_head *head)
|
||||
{
|
||||
osal___list_del_entry(list);
|
||||
osal_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 osal_list_is_last(const struct osal_list_head *list,
|
||||
const struct osal_list_head *head)
|
||||
{
|
||||
return list->next == head;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_empty - tests whether a list is empty
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static inline int osal_list_empty(const struct osal_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 osal_list_empty_careful(const struct osal_list_head *head)
|
||||
{
|
||||
struct osal_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 osal_list_rotate_left(struct osal_list_head *head)
|
||||
{
|
||||
struct osal_list_head *first;
|
||||
|
||||
if (!osal_list_empty(head)) {
|
||||
first = head->next;
|
||||
osal_list_move_tail(first, head);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* list_is_singular - tests whether a list has just one entry.
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static inline int osal_list_is_singular(const struct osal_list_head *head)
|
||||
{
|
||||
return !osal_list_empty(head) && (head->next == head->prev);
|
||||
}
|
||||
|
||||
static inline void osal___list_cut_position(struct osal_list_head *list,
|
||||
struct osal_list_head *head, struct osal_list_head *entry)
|
||||
{
|
||||
struct osal_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 osal_list_cut_position(struct osal_list_head *list,
|
||||
struct osal_list_head *head, struct osal_list_head *entry)
|
||||
{
|
||||
if (osal_list_empty(head)) {
|
||||
return;
|
||||
}
|
||||
if (osal_list_is_singular(head) &&
|
||||
((head->next != entry) && (head != entry))) {
|
||||
return;
|
||||
}
|
||||
if (entry == head) {
|
||||
OSAL_INIT_LIST_HEAD(list);
|
||||
} else {
|
||||
osal___list_cut_position(list, head, entry);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void osal___list_splice(const struct osal_list_head *list,
|
||||
struct osal_list_head *prev,
|
||||
struct osal_list_head *next)
|
||||
{
|
||||
struct osal_list_head *first = list->next;
|
||||
struct osal_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 osal_list_splice(const struct osal_list_head *list,
|
||||
struct osal_list_head *head)
|
||||
{
|
||||
if (!osal_list_empty(list)) {
|
||||
osal___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 osal_list_splice_tail(struct osal_list_head *list,
|
||||
struct osal_list_head *head)
|
||||
{
|
||||
if (!osal_list_empty(list)) {
|
||||
osal___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 osal_list_splice_init(struct osal_list_head *list,
|
||||
struct osal_list_head *head)
|
||||
{
|
||||
if (!osal_list_empty(list)) {
|
||||
osal___list_splice(list, head, head->next);
|
||||
OSAL_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 osal_list_splice_tail_init(struct osal_list_head *list,
|
||||
struct osal_list_head *head)
|
||||
{
|
||||
if (!osal_list_empty(list)) {
|
||||
osal___list_splice(list, head->prev, head);
|
||||
OSAL_INIT_LIST_HEAD(list);
|
||||
}
|
||||
}
|
||||
|
||||
#undef osal_offsetof
|
||||
#ifdef __compiler_offsetof
|
||||
#define osal_offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER)
|
||||
#else
|
||||
#define osal_offsetof(TYPE, MEMBER) ((int)(unsigned long)&((TYPE *)0)->MEMBER)
|
||||
#endif
|
||||
|
||||
#define osal_container_of(ptr, type, member) ({ \
|
||||
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
|
||||
(type *)( (char *)__mptr - osal_offsetof(type,member) ); })
|
||||
|
||||
/**
|
||||
* 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 osal_list_entry(ptr, type, member) \
|
||||
osal_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 osal_list_first_entry(ptr, type, member) \
|
||||
osal_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 osal_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 osal___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 osal_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 osal_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 osal_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 osal_list_for_each_entry(pos, head, member) \
|
||||
for (pos = osal_list_entry((head)->next, __typeof__(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = osal_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 osal_list_for_each_entry_reverse(pos, head, member) \
|
||||
for (pos = osal_list_entry((head)->prev, __typeof__(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = osal_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 osal_list_prepare_entry(pos, head, member) \
|
||||
((pos) ?: osal_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 osal_list_for_each_entry_continue(pos, head, member) \
|
||||
for (pos = osal_list_entry(pos->member.next, __typeof__(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = osal_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 osal_list_for_each_entry_continue_reverse(pos, head, member) \
|
||||
for (pos = osal_list_entry(pos->member.prev, __typeof__(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = osal_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 osal_list_for_each_entry_from(pos, head, member) \
|
||||
for (; &pos->member != (head); \
|
||||
pos = osal_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 osal_list_for_each_entry_safe(pos, n, head, member) \
|
||||
for (pos = osal_list_entry((head)->next, __typeof__(*pos), member), \
|
||||
n = osal_list_entry(pos->member.next, __typeof__(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = osal_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 osal_list_for_each_entry_safe_continue(pos, n, head, member) \
|
||||
for (pos = osal_list_entry(pos->member.next, __typeof__(*pos), member), \
|
||||
n = osal_list_entry(pos->member.next, __typeof__(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = osal_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 osal_list_for_each_entry_safe_from(pos, n, head, member) \
|
||||
for (n = osal_list_entry(pos->member.next, __typeof__(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = osal_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 osal_list_for_each_entry_safe_reverse(pos, n, head, member) \
|
||||
for (pos = osal_list_entry((head)->prev, __typeof__(*pos), member), \
|
||||
n = osal_list_entry(pos->member.prev, __typeof__(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = osal_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 osal_list_safe_reset_next(pos, n, member) \
|
||||
n = osal_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).
|
||||
*/
|
||||
struct osal_hlist_node {
|
||||
struct osal_hlist_node *next, **pprev;
|
||||
};
|
||||
struct osal_hlist_head {
|
||||
struct osal_hlist_node *first;
|
||||
};
|
||||
|
||||
#define OSAL_HLIST_HEAD_INIT \
|
||||
{ \
|
||||
.first = OSAL_NULL \
|
||||
}
|
||||
#define OSAL_HLIST_HEAD(name) struct osal_hlist_head name = { .first = OSAL_NULL }
|
||||
#define INIT_OSAL_HLIST_HEAD(ptr) ((ptr)->first = OSAL_NULL)
|
||||
static inline void INIT_OSAL_HLIST_NODE(struct osal_hlist_node *h)
|
||||
{
|
||||
h->next = OSAL_NULL;
|
||||
h->pprev = OSAL_NULL;
|
||||
}
|
||||
|
||||
static inline int osal_hlist_unhashed(const struct osal_hlist_node *h)
|
||||
{
|
||||
return !h->pprev;
|
||||
}
|
||||
|
||||
static inline int osal_hlist_empty(const struct osal_hlist_head *h)
|
||||
{
|
||||
return !h->first;
|
||||
}
|
||||
|
||||
static inline void osal___hlist_del(struct osal_hlist_node *n)
|
||||
{
|
||||
struct osal_hlist_node *next = n->next;
|
||||
struct osal_hlist_node **pprev = n->pprev;
|
||||
*pprev = next;
|
||||
if (next) {
|
||||
next->pprev = pprev;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void osal_hlist_del(struct osal_hlist_node *n)
|
||||
{
|
||||
osal___hlist_del(n);
|
||||
n->next = OSAL_LIST_POISON1;
|
||||
n->pprev = OSAL_LIST_POISON2;
|
||||
}
|
||||
|
||||
static inline void osal_hlist_del_init(struct osal_hlist_node *n)
|
||||
{
|
||||
if (!osal_hlist_unhashed(n)) {
|
||||
osal___hlist_del(n);
|
||||
INIT_OSAL_HLIST_NODE(n);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void osal_hlist_add_head(struct osal_hlist_node *n, struct osal_hlist_head *h)
|
||||
{
|
||||
struct osal_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 osal_hlist_add_before(struct osal_hlist_node *n,
|
||||
struct osal_hlist_node *next)
|
||||
{
|
||||
n->pprev = next->pprev;
|
||||
n->next = next;
|
||||
next->pprev = &n->next;
|
||||
*(n->pprev) = n;
|
||||
}
|
||||
|
||||
static inline void osal_hlist_add_after(struct osal_hlist_node *n,
|
||||
struct osal_hlist_node *next)
|
||||
{
|
||||
next->next = n->next;
|
||||
n->next = next;
|
||||
next->pprev = &n->next;
|
||||
|
||||
if (next->next) {
|
||||
next->next->pprev = &next->next;
|
||||
}
|
||||
}
|
||||
|
||||
/* after that we'll appear to be on some hlist and hlist_del will work */
|
||||
static inline void osal_hlist_add_fake(struct osal_hlist_node *n)
|
||||
{
|
||||
n->pprev = &n->next;
|
||||
}
|
||||
|
||||
/*
|
||||
* Move a list from one list head to another. Fixup the pprev
|
||||
* reference of the first entry if it exists.
|
||||
*/
|
||||
static inline void osal_hlist_move_list(struct osal_hlist_head *old,
|
||||
struct osal_hlist_head *new)
|
||||
{
|
||||
new->first = old->first;
|
||||
if (new->first) {
|
||||
new->first->pprev = &new->first;
|
||||
}
|
||||
old->first = OSAL_NULL;
|
||||
}
|
||||
|
||||
#define osal_hlist_entry(ptr, type, member) osal_container_of(ptr, type, member)
|
||||
|
||||
#define osal_hlist_for_each(pos, head) \
|
||||
for (pos = (head)->first; pos; pos = pos->next)
|
||||
|
||||
#define osal_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 osal_hlist_for_each_entry(tpos, pos, head, member) \
|
||||
for (pos = (head)->first; \
|
||||
pos && \
|
||||
({ tpos = osal_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 osal_hlist_for_each_entry_continue(tpos, pos, member) \
|
||||
for (pos = (pos)->next; \
|
||||
pos && \
|
||||
({ tpos = osal_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 osal_hlist_for_each_entry_from(tpos, pos, member) \
|
||||
for (; pos && \
|
||||
({ tpos = osal_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 osal_hlist_for_each_entry_safe(tpos, pos, n, head, member) \
|
||||
for (pos = (head)->first; \
|
||||
pos && ({ n = pos->next; 1; }) && \
|
||||
({ tpos = osal_hlist_entry(pos, __typeof__(*tpos), member); 1; }); \
|
||||
pos = n)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
#ifndef _OSAL_MMZ_H
|
||||
#define _OSAL_MMZ_H
|
||||
|
||||
#include "osal.h"
|
||||
|
||||
#define CACHE_LINE_SIZE (0x40)
|
||||
#define MMZ_MMZ_NAME_LEN 32
|
||||
#define MMZ_MMB_NAME_LEN 16
|
||||
|
||||
struct mmz_media_memory_zone {
|
||||
char name[MMZ_MMZ_NAME_LEN];
|
||||
|
||||
unsigned long gfp;
|
||||
|
||||
unsigned long phys_start;
|
||||
unsigned long nbytes;
|
||||
|
||||
struct osal_list_head list;
|
||||
union {
|
||||
struct device *cma_dev;
|
||||
unsigned char *bitmap;
|
||||
};
|
||||
struct osal_list_head mmb_list;
|
||||
|
||||
unsigned int alloc_type;
|
||||
unsigned long block_align;
|
||||
|
||||
void (*destructor)(const void *);
|
||||
};
|
||||
typedef struct mmz_media_memory_zone mmz_mmz_t;
|
||||
|
||||
#define MMZ_MMZ_FMT_S "PHYS(0x%08lX, 0x%08lX), GFP=%lu, nBYTES=%luKB, NAME=\"%s\""
|
||||
#define mmz_mmz_fmt_arg(p) (p)->phys_start, (p)->phys_start + (p)->nbytes - 1, (p)->gfp, (p)->nbytes / SZ_1K, (p)->name
|
||||
|
||||
#define MMZ_MMB_NAME_LEN 16
|
||||
struct mmz_media_memory_block {
|
||||
#ifndef MMZ_V2_SUPPORT
|
||||
unsigned int id;
|
||||
#endif
|
||||
char name[MMZ_MMB_NAME_LEN];
|
||||
struct mmz_media_memory_zone *zone;
|
||||
struct osal_list_head list;
|
||||
|
||||
unsigned long phys_addr;
|
||||
void *kvirt;
|
||||
unsigned long length;
|
||||
|
||||
unsigned long flags;
|
||||
|
||||
unsigned int order;
|
||||
|
||||
int phy_ref;
|
||||
int map_ref;
|
||||
};
|
||||
typedef struct mmz_media_memory_block mmz_mmb_t;
|
||||
|
||||
#define mmz_mmb_kvirt(p) ({mmz_mmb_t *__mmb=(p); OSAL_BUG_ON(__mmb==NULL); __mmb->kvirt; })
|
||||
#define mmz_mmb_phys(p) ({mmz_mmb_t *__mmb=(p); OSAL_BUG_ON(__mmb==NULL); __mmb->phys_addr; })
|
||||
#define mmz_mmb_length(p) ({mmz_mmb_t *__mmb=(p); OSAL_BUG_ON(__mmb==NULL); __mmb->length; })
|
||||
#define mmz_mmb_name(p) ({mmz_mmb_t *__mmb=(p); OSAL_BUG_ON(__mmb==NULL); __mmb->name; })
|
||||
#define mmz_mmb_zone(p) ({mmz_mmb_t *__mmb=(p); OSAL_BUG_ON(__mmb==NULL); __mmb->zone; })
|
||||
|
||||
#define MMZ_MMB_MAP2KERN (1 << 0)
|
||||
#define MMZ_MMB_MAP2KERN_CACHED (1 << 1)
|
||||
#define MMZ_MMB_RELEASED (1 << 2)
|
||||
|
||||
#define MMZ_MMB_FMT_S "phys(0x%08lX, 0x%08lX), kvirt=0x%08lX, flags=0x%08lX, length=%luKB, name=\"%s\""
|
||||
#define mmz_mmb_fmt_arg(p) (p)->phys_addr, mmz_grain_align((p)->phys_addr + (p)->length) - 1, (unsigned long)(uintptr_t)((p)->kvirt), (p)->flags, (p)->length / SZ_1K, (p)->name
|
||||
|
||||
#define DEFAULT_ALLOC 0
|
||||
#define SLAB_ALLOC 1
|
||||
#define EQ_BLOCK_ALLOC 2
|
||||
|
||||
#define LOW_TO_HIGH 0
|
||||
#define HIGH_TO_LOW 1
|
||||
|
||||
#define MMZ_DBG_LEVEL 0x0
|
||||
#define mmz_trace(level, s, params...) \
|
||||
do { \
|
||||
if (level & MMZ_DBG_LEVEL) \
|
||||
printk(KERN_INFO "[%s, %d]: " s "\n", __FUNCTION__, __LINE__, params); \
|
||||
} while (0)
|
||||
|
||||
#define mmz_trace_func() mmz_trace(0x02, "%s", __FUNCTION__)
|
||||
|
||||
#define MMZ_GRAIN PAGE_SIZE
|
||||
#define mmz_bitmap_size(p) (mmz_align2(mmz_length2grain((p)->nbytes), 8) / 8)
|
||||
|
||||
#define mmz_get_bit(p, n) (((p)->bitmap[(n) / 8] >> ((n)&0x7)) & 0x1)
|
||||
#define mmz_set_bit(p, n) (p)->bitmap[(n) / 8] |= 1 << ((n)&0x7)
|
||||
#define mmz_clr_bit(p, n) (p)->bitmap[(n) / 8] &= ~(1 << ((n)&0x7))
|
||||
|
||||
#define mmz_pos2phy_addr(p, n) ((p)->phys_start + (n)*MMZ_GRAIN)
|
||||
#define mmz_phy_addr2pos(p, a) (((a) - (p)->phys_start) / MMZ_GRAIN)
|
||||
|
||||
#define mmz_align2low(x, g) (((x) / (g)) * (g))
|
||||
#define mmz_align2(x, g) ((((x) + (g)-1) / (g)) * (g))
|
||||
#define mmz_grain_align(x) mmz_align2(x, MMZ_GRAIN)
|
||||
#define mmz_length2grain(len) (mmz_grain_align(len) / MMZ_GRAIN)
|
||||
|
||||
#define begin_list_for_each_mmz(p, gfp, mmz_name) \
|
||||
list_for_each_entry(p, &mmz_list, list) \
|
||||
{ \
|
||||
if (gfp == 0 ? 0 : (p)->gfp != (gfp)) \
|
||||
continue; \
|
||||
if ((mmz_name == NULL) || (*mmz_name == '\0')) { \
|
||||
if (strcmp("anonymous", p->name)) \
|
||||
continue; \
|
||||
} else { \
|
||||
if (strcmp(mmz_name, p->name)) \
|
||||
continue; \
|
||||
} \
|
||||
mmz_trace(1, MMZ_MMZ_FMT_S, mmz_mmz_fmt_arg(p));
|
||||
#define end_list_for_each_mmz() }
|
||||
|
||||
#if defined(KERNEL_BIT_64) && defined(USER_BIT_32)
|
||||
#define __phys_addr_type__ unsigned long long
|
||||
#define __phys_len_type__ unsigned long long
|
||||
#define __phys_addr_align__ __attribute__((aligned(8)))
|
||||
#else
|
||||
#define __phys_addr_type__ unsigned long
|
||||
#define __phys_len_type__ unsigned long
|
||||
#define __phys_addr_align__ __attribute__((aligned(sizeof(long))))
|
||||
#endif
|
||||
|
||||
struct mmb_info {
|
||||
__phys_addr_type__ phys_addr; /* phys-memory address */
|
||||
__phys_addr_type__ __phys_addr_align__ align; /* if you need your phys-memory have special align size */
|
||||
__phys_len_type__ __phys_addr_align__ size; /* length of memory you need, in bytes */
|
||||
unsigned int __phys_addr_align__ order;
|
||||
|
||||
void *__phys_addr_align__ mapped; /* userspace mapped ptr */
|
||||
|
||||
union {
|
||||
struct
|
||||
{
|
||||
unsigned long prot : 8; /* PROT_READ or PROT_WRITE */
|
||||
unsigned long flags : 12; /* MAP_SHARED or MAP_PRIVATE */
|
||||
|
||||
#ifdef __KERNEL__
|
||||
unsigned long reserved : 7;/* reserved, do not use */
|
||||
unsigned long kernel_mmb :1;
|
||||
unsigned long delayed_free : 1;
|
||||
unsigned long map_cached : 1;
|
||||
#endif
|
||||
};
|
||||
unsigned long w32_stuf;
|
||||
} __phys_addr_align__;
|
||||
|
||||
char mmb_name[MMZ_MMB_NAME_LEN];
|
||||
char mmz_name[MMZ_MMZ_NAME_LEN];
|
||||
unsigned long __phys_addr_align__ gfp; /* reserved, do set to 0 */
|
||||
|
||||
#ifdef __KERNEL__
|
||||
int map_ref;
|
||||
int mmb_ref;
|
||||
|
||||
struct osal_list_head list;
|
||||
mmz_mmb_t *mmb;
|
||||
#endif
|
||||
} __attribute__((aligned(8)));
|
||||
|
||||
struct dirty_area {
|
||||
__phys_addr_type__ dirty_phys_start; /* dirty physical address */
|
||||
void *__phys_addr_align__ dirty_virt_start; /* dirty virtual address,
|
||||
must be coherent with dirty_phys_addr */
|
||||
__phys_len_type__ __phys_addr_align__ dirty_size;
|
||||
} __phys_addr_align__;
|
||||
|
||||
#define IOC_MMB_ALLOC _IOWR('m', 10, struct mmb_info)
|
||||
#define IOC_MMB_ATTR _IOR('m', 11, struct mmb_info)
|
||||
#define IOC_MMB_FREE _IOW('m', 12, struct mmb_info)
|
||||
|
||||
#define IOC_MMB_USER_REMAP _IOWR('m', 20, struct mmb_info)
|
||||
#define IOC_MMB_USER_REMAP_CACHED _IOWR('m', 21, struct mmb_info)
|
||||
#define IOC_MMB_USER_UNMAP _IOWR('m', 22, struct mmb_info)
|
||||
|
||||
#define IOC_MMB_VIRT_GET_PHYS _IOWR('m', 23, struct mmb_info)
|
||||
|
||||
#define IOC_MMB_ADD_REF _IO('r', 30) /* ioctl(file, cmd, arg), arg is mmb_addr */
|
||||
#define IOC_MMB_DEC_REF _IO('r', 31) /* ioctl(file, cmd, arg), arg is mmb_addr */
|
||||
|
||||
#define IOC_MMB_FLUSH_DCACHE _IO('c', 40)
|
||||
|
||||
#define IOC_MMB_FLUSH_DCACHE_DIRTY _IOW('d', 50, struct dirty_area)
|
||||
#define IOC_MMB_TEST_CACHE _IOW('t', 11, struct mmb_info)
|
||||
|
||||
#define MMZ_SETUP_CMDLINE_LEN 256
|
||||
|
||||
/*
|
||||
* APIs
|
||||
*/
|
||||
extern mmz_mmz_t *mmz_mmz_create(const char *name, unsigned long gfp, unsigned long phys_start,
|
||||
unsigned long nbytes);
|
||||
|
||||
extern int mmz_mmz_destroy(mmz_mmz_t *zone);
|
||||
|
||||
extern int mmz_mmz_register(mmz_mmz_t *zone);
|
||||
extern int mmz_mmz_unregister(mmz_mmz_t *zone);
|
||||
extern mmz_mmz_t *mmz_mmz_find(unsigned long gfp, const char *mmz_name);
|
||||
|
||||
extern mmz_mmb_t *mmz_mmb_alloc(const char *name, unsigned long size, unsigned long align,
|
||||
unsigned long gfp, const char *mmz_name);
|
||||
extern int mmz_mmb_free(mmz_mmb_t *mmb);
|
||||
extern mmz_mmb_t *mmz_mmb_getby_phys(unsigned long addr);
|
||||
extern mmz_mmb_t *mmz_mmb_getby_phys_2(unsigned long addr, unsigned long *Outoffset); // used in cipher
|
||||
extern mmz_mmb_t *mmz_mmb_getby_kvirt(void *virt);
|
||||
extern unsigned long usr_virt_to_phys(unsigned long virt);
|
||||
|
||||
extern int mmz_is_phys_in_mmz(unsigned long addr_start, unsigned long addr_len);
|
||||
|
||||
extern int mmz_vma_check(unsigned long vm_start, unsigned long vm_end);
|
||||
extern int mmz_mmb_flush_dcache_byaddr_safe(void *kvirt, unsigned long phys_addr, unsigned long length);
|
||||
|
||||
extern unsigned long mmz_mmz_get_phys(const char *zone_name);
|
||||
|
||||
#define mmz_mmb_freeby_phys(phys_addr) mmz_mmb_free(mmz_mmb_getby_phys(phys_addr))
|
||||
|
||||
extern void *mmz_mmb_map2kern(mmz_mmb_t *mmb);
|
||||
extern void *mmz_mmb_map2kern_cached(mmz_mmb_t *mmb);
|
||||
|
||||
extern int mmz_mmb_flush_dcache_byaddr(void *kvirt, unsigned long phys_addr, unsigned long length);
|
||||
extern int mmz_mmb_invalid_cache_byaddr(void *kvirt, unsigned long phys_addr, unsigned long length);
|
||||
|
||||
extern int mmz_mmb_unmap(mmz_mmb_t *mmb);
|
||||
extern int mmz_mmb_get(mmz_mmb_t *mmb);
|
||||
extern int mmz_mmb_put(mmz_mmb_t *mmb);
|
||||
|
||||
extern void *mmz_mmf_map2kern_nocache(unsigned long phys, int len);
|
||||
extern void *mmz_mmf_map2kern_cache(unsigned long phys, int len);
|
||||
extern void mmz_mmf_unmap(void *virt);
|
||||
|
||||
/* for mmz userdev */
|
||||
int mmz_userdev_init(void);
|
||||
void mmz_userdev_exit(void);
|
||||
int mmz_flush_dcache_all(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) XMEDIA. All rights reserved.
|
||||
*/
|
||||
#ifndef __OSAL_USER__
|
||||
#define __OSAL_USER__
|
||||
|
||||
#ifndef PROT_READ
|
||||
#define PROT_READ
|
||||
#endif
|
||||
#ifndef PROT_WRITE
|
||||
#define PROT_WRITE
|
||||
#endif
|
||||
#ifndef MAP_SHARED
|
||||
#define MAP_SHARED
|
||||
#endif
|
||||
#ifndef MAP_FAILED
|
||||
#define MAP_FAILED (NULL)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user