| /* |
| */ |
| |
| #ifndef __HDA_WRAPPER_H |
| #define __HDA_WRAPPER_H |
| |
| #include <stdarg.h> |
| #include <linux/delay.h> |
| #include <linux/stddef.h> |
| |
| #define min(x, y) ({ \ |
| typeof(x) _min1 = (x); \ |
| typeof(y) _min2 = (y); \ |
| (void) (&_min1 == &_min2); \ |
| _min1 < _min2 ? _min1 : _min2; }) |
| |
| #define max(x, y) ({ \ |
| typeof(x) _max1 = (x); \ |
| typeof(y) _max2 = (y); \ |
| (void) (&_max1 == &_max2); \ |
| _max1 > _max2 ? _max1 : _max2; }) |
| |
| #define clamp(val, min, max) ({ \ |
| typeof(val) __val = (val); \ |
| typeof(min) __min = (min); \ |
| typeof(max) __max = (max); \ |
| (void) (&__val == &__min); \ |
| (void) (&__val == &__max); \ |
| __val = __val < __min ? __min: __val; \ |
| __val > __max ? __max: __val; }) |
| |
| #define min_t(type, x, y) ({ \ |
| type __min1 = (x); \ |
| type __min2 = (y); \ |
| __min1 < __min2 ? __min1: __min2; }) |
| |
| #define max_t(type, x, y) ({ \ |
| type __max1 = (x); \ |
| type __max2 = (y); \ |
| __max1 > __max2 ? __max1: __max2; }) |
| |
| #define clamp_t(type, val, min, max) ({ \ |
| type __val = (val); \ |
| type __min = (min); \ |
| type __max = (max); \ |
| __val = __val < __min ? __min: __val; \ |
| __val > __max ? __max: __val; }) |
| |
| #define clamp_val(val, min, max) ({ \ |
| typeof(val) __val = (val); \ |
| typeof(val) __min = (min); \ |
| typeof(val) __max = (max); \ |
| __val = __val < __min ? __min: __val; \ |
| __val > __max ? __max: __val; }) |
| |
| #define swap(a, b) \ |
| do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) |
| |
| #define container_of(ptr, type, member) ({ \ |
| const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
| (type *)( (char *)__mptr - offsetof(type,member) );}) |
| #define prefetch(x) (x) |
| |
| #define struct_size(p, member, n) \ |
| (((n) * sizeof(*(p)->member)) + sizeof(*p)) |
| |
| #include <stdio.h> |
| #include <stdint.h> |
| #include <errno.h> |
| #include <string.h> |
| #include <stdlib.h> |
| |
| #include "hda-log.h" |
| /* #define printk printf */ |
| #define printk hda_log_printk |
| #define KERN_DEBUG "<7>" |
| #define KERN_INFO "<6>" |
| #define KERN_NOTICE "<5>" |
| #define KERN_WARNING "<4>" |
| #define KERN_ERR "<3>" |
| |
| #undef HZ |
| #define HZ 250 |
| |
| #define pr_fmt(fmt) fmt |
| #define pr_emerg(fmt, ...) \ |
| printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) |
| #define pr_alert(fmt, ...) \ |
| printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) |
| #define pr_crit(fmt, ...) \ |
| printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) |
| #define pr_err(fmt, ...) \ |
| printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) |
| #define pr_warning(fmt, ...) \ |
| printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
| #define pr_warn pr_warning |
| #define pr_notice(fmt, ...) \ |
| printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
| #define pr_info(fmt, ...) \ |
| printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) |
| #define pr_cont(fmt, ...) \ |
| printk(KERN_CONT fmt, ##__VA_ARGS__) |
| #define pr_debug(fmt, ...) \ |
| printk(KERN_DEBUG fmt, ##__VA_ARGS__) |
| |
| /* FIXME */ |
| #define scnprintf snprintf |
| |
| #if 0 |
| typedef uint64_t u64; |
| typedef uint64_t __u64; |
| typedef int64_t s64; |
| typedef int64_t __s64; |
| typedef uint32_t u32; |
| typedef uint32_t __u32; |
| typedef int32_t s32; |
| typedef int32_t __s32; |
| typedef uint16_t u16; |
| typedef uint16_t __u16; |
| typedef int16_t s16; |
| typedef int16_t __s16; |
| typedef uint8_t u8; |
| typedef uint8_t __u8; |
| typedef int8_t s8; |
| typedef int8_t __s8; |
| #else |
| #include <asm-generic/int-ll64.h> |
| #endif |
| |
| #define USHRT_MAX ((u16)(~0U)) |
| #define SHRT_MAX ((s16)(USHRT_MAX>>1)) |
| #define SHRT_MIN ((s16)(-SHRT_MAX - 1)) |
| #define INT_MAX ((int)(~0U>>1)) |
| #define INT_MIN (-INT_MAX - 1) |
| #define UINT_MAX (~0U) |
| #define LONG_MAX ((long)(~0UL>>1)) |
| #define LONG_MIN (-LONG_MAX - 1) |
| #define ULONG_MAX (~0UL) |
| #define LLONG_MAX ((long long)(~0ULL>>1)) |
| #define LLONG_MIN (-LLONG_MAX - 1) |
| #define ULLONG_MAX (~0ULL) |
| |
| typedef u16 __le16; |
| typedef u16 __be16; |
| typedef u32 __le32; |
| typedef u32 __be32; |
| typedef u64 __le64; |
| typedef u64 __be64; |
| |
| #define le32_to_cpu(x) (x) |
| #define cpu_to_le32(x) (x) |
| #define upper_32_bits(x) ((u32)((x) >> 32)) |
| |
| typedef unsigned long cycle_t; |
| |
| typedef _Bool bool; |
| |
| typedef unsigned long dma_addr_t; |
| |
| typedef unsigned long kernel_ulong_t; |
| typedef unsigned int uuid_le; |
| |
| typedef long __kernel_long_t; |
| typedef unsigned long __kernel_ulong_t; |
| typedef long long __kernel_time64_t; |
| typedef long __kernel_old_time_t; |
| typedef long __kernel_suseconds_t; |
| |
| #define PAGE_SIZE 4096 |
| |
| #ifndef __user |
| #define __user |
| #endif |
| #ifndef __bitwise |
| #define __bitwise |
| #endif |
| #ifndef __iomem |
| #define __iomem |
| #endif |
| #ifndef __must_check |
| #define __must_check |
| #endif |
| #define __force |
| #define unlikely(x) x |
| |
| #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
| |
| #define cond_resched() |
| #define schedule_timeout(x) |
| |
| #undef abs |
| #define abs(x) ({ \ |
| int __x = (x); \ |
| (__x < 0) ? -__x : __x; \ |
| }) |
| |
| #undef offsetof |
| #ifdef __compiler_offsetof |
| #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER) |
| #else |
| #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) |
| #endif |
| |
| #define put_user(a,b) ({*(b) = (a); 0;}) |
| |
| #define __round_mask(x, y) ((__typeof__(x))((y)-1)) |
| #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) |
| #define round_down(x, y) ((x) & ~__round_mask(x, y)) |
| |
| #define jiffies 0 |
| static inline bool time_after_eq(unsigned long a, unsigned long b) |
| { return 1; } |
| |
| static inline bool time_after(unsigned long a, unsigned long b) |
| { return 1; } |
| |
| static inline bool time_before(unsigned long a, unsigned long b) |
| { return 0; } |
| |
| #define BUG_ON(x) do { \ |
| if (x) { fprintf(stderr, "ERROR! (%s:%d)\n", __func__, __LINE__); } \ |
| } while (0) |
| |
| #define BUILD_BUG_ON(x) do {} while (0) |
| |
| static inline int _WARN_ON(int cond, const char *func, int line) |
| { |
| if (cond) |
| printk(KERN_ERR "WARNING! (%s:%d)\n", func, line); |
| return cond; |
| } |
| |
| #define WARN_ON(cond) _WARN_ON(!!(cond), __func__, __LINE__) |
| |
| #define WARN_ON_ONCE(cond) WARN_ON(cond) |
| |
| static inline void WARN(int cond, const char *str) |
| { |
| if (cond) |
| printk(KERN_ERR "WARNING! %s\n", str); |
| } |
| |
| #define simple_strtoul strtoul |
| #define simple_strtol strtol |
| |
| static inline int strict_strtoul(const char *str, unsigned int base, unsigned long *val) |
| { |
| *val = strtoul(str, NULL, base); |
| return 0; |
| } |
| |
| static inline int strict_strtol(const char *str, unsigned int base, long *val) |
| { |
| *val = strtol(str, NULL, base); |
| return 0; |
| } |
| |
| static inline int kstrtoint(const char *s, unsigned int base, int *res) |
| { |
| *res = strtol(s, NULL, base); |
| return 0; |
| } |
| |
| #ifndef __USE_MISC |
| static inline size_t strlcat(char *dest, const char *src, size_t count) |
| { |
| size_t dsize = strlen(dest); |
| size_t len = strlen(src); |
| size_t res = dsize + len; |
| |
| dest += dsize; |
| count -= dsize; |
| if (len >= count) |
| len = count-1; |
| memcpy(dest, src, len); |
| dest[len] = 0; |
| return res; |
| } |
| #endif |
| |
| #ifdef __USE_MISC |
| #define strlcpy strlcpy_linux |
| #endif |
| |
| void *__hda_malloc(size_t size, const char *file, int line, int gfp); |
| void __hda_free(void *ptr, const char *file, int line); |
| void *__hda_realloc(const void *p, size_t new_size, const char *file, int line, int gfp); |
| void *__hda_strdup(const char *str, const char *file, int line, int gfp); |
| |
| /* |
| * lock debug |
| */ |
| enum { |
| MYLOCK_UNINIT, |
| MYLOCK_UNLOCKED, |
| MYLOCK_LOCKED, |
| }; |
| |
| void mylock_init(int *lock); |
| void mylock_lock(int *lock, const char *file, int line); |
| void mylock_unlock(int *lock, const char *file, int line); |
| void mylock_read_lock(int *lock, const char *file, int line); |
| void mylock_read_unlock(int *lock, const char *file, int line); |
| void mylock_write_lock(int *lock, const char *file, int line); |
| void mylock_write_unlock(int *lock, const char *file, int line); |
| |
| #include "linux/atomic.h" |
| #include "linux/spinlock.h" |
| #include "linux/pci_ids.h" |
| #include "linux/workqueue.h" |
| #include "linux/bitmap.h" |
| #include "linux/module.h" |
| #include "linux/log2.h" |
| |
| /* FIXME */ |
| #define IS_ENABLED(x) 1 |
| #define IS_BUILTIN(x) 1 |
| #define IS_REACHABLE(x) 1 |
| #define IS_MODULE(x) 0 |
| |
| #define symbol_request(x) x |
| #define symbol_put(x) |
| #define symbol_put_addr(x) |
| |
| static inline long copy_from_user(void *to, const void __user *from, unsigned long n) |
| { |
| memcpy(to, from, n); |
| return 0; |
| } |
| |
| static inline long copy_to_user(void __user *to, const void *from, unsigned long n) |
| { |
| memcpy(to, from, n); |
| return 0; |
| } |
| |
| |
| static inline char *kvasprintf(int gfp, const char *fmt, va_list ap) |
| { |
| char tmp; |
| va_list app; |
| int len; |
| char *buf; |
| |
| va_copy(app, ap); |
| len = vsnprintf(&tmp, 1, fmt, app); |
| va_end(app); |
| if (len < 0) |
| return NULL; |
| buf = __hda_malloc(len + 1, __FILE__, __LINE__, 0); |
| if (!buf) |
| return NULL; |
| vsnprintf(buf, len + 1, fmt, ap); |
| return buf; |
| } |
| |
| static inline char *kasprintf(int gfp, const char *fmt, ...) |
| { |
| va_list ap; |
| char *ret; |
| |
| va_start(ap, fmt); |
| ret = kvasprintf(gfp, fmt, ap); |
| va_end(ap); |
| return ret; |
| } |
| |
| #define KBUILD_MODNAME __FILE__ |
| |
| #define module_driver(__driver, __register, __unregister, ...) \ |
| static int __init __driver##_init(void) \ |
| { \ |
| return __register(&(__driver) , ##__VA_ARGS__); \ |
| } \ |
| module_init(__driver##_init); \ |
| static void __exit __driver##_exit(void) \ |
| { \ |
| __unregister(&(__driver) , ##__VA_ARGS__); \ |
| } \ |
| module_exit(__driver##_exit); |
| |
| /* attributes */ |
| #define __printf(a, b) __attribute__((format(printf, a, b))) |
| |
| #define __packed __attribute__((packed)) |
| |
| #define cpu_relax() |
| #define wmb() |
| |
| typedef int wait_queue_head_t; // just a hack, no real meaning |
| #define init_waitqueue_head(x) // we don't care for now |
| |
| typedef int irqreturn_t; // just a hack |
| |
| struct vm_area_struct; |
| |
| // UUID |
| typedef struct { |
| __u8 b[16]; |
| } guid_t; |
| |
| #define fallthrough /**/ |
| |
| struct completion { |
| int dummy; |
| }; |
| |
| #define DIV_ROUND_UP(a, b) (((a) + (b) - 1) / (b)) |
| #define roundup(a, b) (DIV_ROUND_UP(a, b) * (b)) |
| |
| |
| /* XXX just for hdac_controller.c */ |
| typedef int wait_queue_entry_t; |
| #define waitqueue_active(x) false |
| #define wake_up(x) do {} while (0) |
| #define init_wait_entry(x,y) do {} while (0) |
| #define prepare_to_wait(x,y,z) do {} while (0) |
| #define finish_wait(x,y) do {} while (0) |
| #define wait_event(x,y) do {} while (0) |
| |
| #define snd_dma_alloc_pages(type, dev, size, dp) 0 |
| #define snd_dma_free_pages(dp) |
| |
| # define do_div(n,base) ({ \ |
| uint32_t __base = (base); \ |
| uint32_t __rem; \ |
| __rem = ((uint64_t)(n)) % __base; \ |
| (n) = ((uint64_t)(n)) / __base; \ |
| __rem; \ |
| }) |
| |
| #define might_sleep_if(cond) |
| |
| /* |
| * hackish workaround; not really used, so let's define dummies |
| */ |
| struct snd_pcm_hw_params { int foo; }; |
| #define params_set_format(x, y) |
| #define hw_param_mask(x, y) NULL |
| #define snd_mask_set(x, y) |
| #define snd_pcm_hw_params_bits(x) 0 |
| |
| #define GENMASK(h, l) \ |
| (((~0UL) - (1UL << (l)) + 1) & \ |
| (~0UL >> (BITS_PER_LONG - 1 - (h)))) |
| |
| #define fwnode_handle_get(f) NULL |
| #define device_property_count_u32(dev, p) 0 |
| #define fwnode_property_count_u32(fw, p) 0 |
| |
| #define str_yes_no(x) ((x) ? "yes" : "no") |
| |
| #endif /* __HDA_WRAPPER_H */ |