Ignore:
Timestamp:
Jan 1, 2021, 5:31:48 AM (5 years ago)
Author:
Paul Smedley
Message:

Add source for uniaud32 based on code from linux kernel 5.4.86

Location:
GPL/branches/uniaud32-next
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • GPL/branches/uniaud32-next/lib32/misc.c

    r614 r615  
    2929#include <linux/fs.h>
    3030#include <linux/poll.h>
    31 #define CONFIG_PROC_FS
     31#define CONFIG_PROC_FS 1
    3232#include <linux/proc_fs.h>
    3333#include <asm/uaccess.h>
     
    3838#include <linux/workqueue.h>
    3939#include <linux/firmware.h>
     40#include <linux/ctype.h>
    4041#include <dbgos2.h>
    4142
     
    8485    return 0;
    8586}
     87
     88//******************************************************************************
     89//Save error message in szLastALSAError; if card init failed, then we will
     90//print it in drv32\init.cpp
     91//******************************************************************************
     92int dev_dbg(const struct device *dev, const char * fmt, ...)
     93{
     94    va_list argptr;                /* -> variable argument list */
     95
     96    char *pszLastALSAError;
     97
     98    pszLastALSAError= iLastError ? szLastALSAError2 : szLastALSAError1;
     99
     100    va_start(argptr, fmt);           /* get pointer to argument list */
     101    vsprintf(pszLastALSAError, fmt, argptr);
     102//    strcat(pszLastALSAError, "\r");
     103    va_end(argptr);                /* done with variable arguments */
     104
     105    if(szOverrunTest1 != 0xCC || szOverrunTest2 != 0xCC) {
     106        DebugInt3();
     107    }
     108
     109        StringOut(pszLastALSAError);
     110//    rprintf( (pszLastALSAError) );
     111    if(++iLastError > 1) {
     112        iLastError = 0;
     113    }
     114    return 0;
     115}
     116//******************************************************************************
     117int pcm_dbg(struct snd_pcm *dev, const char * fmt, ...)
     118{
     119    va_list argptr;                /* -> variable argument list */
     120
     121    char *pszLastALSAError;
     122
     123    pszLastALSAError= iLastError ? szLastALSAError2 : szLastALSAError1;
     124
     125    va_start(argptr, fmt);           /* get pointer to argument list */
     126    vsprintf(pszLastALSAError, fmt, argptr);
     127//    strcat(pszLastALSAError, "\r");
     128    va_end(argptr);                /* done with variable arguments */
     129
     130    if(szOverrunTest1 != 0xCC || szOverrunTest2 != 0xCC) {
     131        DebugInt3();
     132    }
     133
     134        StringOut(pszLastALSAError);
     135//    rprintf( (pszLastALSAError) );
     136    if(++iLastError > 1) {
     137        iLastError = 0;
     138    }
     139    return 0;
     140}
     141//******************************************************************************
     142int codec_dbg(struct hda_codec *dev, const char * fmt, ...)
     143{
     144    va_list argptr;                /* -> variable argument list */
     145
     146    char *pszLastALSAError;
     147
     148    pszLastALSAError= iLastError ? szLastALSAError2 : szLastALSAError1;
     149
     150    va_start(argptr, fmt);           /* get pointer to argument list */
     151    vsprintf(pszLastALSAError, fmt, argptr);
     152//    strcat(pszLastALSAError, "\r");
     153    va_end(argptr);                /* done with variable arguments */
     154
     155    if(szOverrunTest1 != 0xCC || szOverrunTest2 != 0xCC) {
     156        DebugInt3();
     157    }
     158
     159        StringOut(pszLastALSAError);
     160//    rprintf( (pszLastALSAError) );
     161    if(++iLastError > 1) {
     162        iLastError = 0;
     163    }
     164    return 0;
     165}
    86166//******************************************************************************
    87167//******************************************************************************
     
    175255//******************************************************************************
    176256//******************************************************************************
    177 void kill_fasync(struct fasync_struct *a, int b, int c)
     257void kill_fasync(struct fasync_struct **a, int b, int c)
    178258{
    179259}
     
    273353                run_workqueue(wq);
    274354        } else {
    275                 wait_queue_t wait;
     355                struct wait_queue_entry wait;
    276356
    277357                init_waitqueue_entry(&wait, current);
     
    425505//******************************************************************************
    426506//******************************************************************************
    427 int schedule_work(struct work_struct *works)
    428 {
    429 #ifndef TARGET_OS2
    430         return kernel_thread(work_caller, works, 0) >= 0;
    431 #else
    432         return 1;
     507struct workqueue_struct *system_wq;
     508
     509int schedule_work(struct work_struct *work)
     510{
     511#ifndef TARGET_OS2 // crashes
     512        return queue_work(system_wq, work);
    433513#endif
    434 }
     514        return 0;
     515}
     516
    435517//******************************************************************************
    436518//******************************************************************************
     
    517599        return -EINVAL;
    518600}
     601//******************************************************************************
     602//******************************************************************************
     603
     604static void u32_swap(void *a, void *b, int size)
     605{
     606        u32 t = *(u32 *)a;
     607        *(u32 *)a = *(u32 *)b;
     608        *(u32 *)b = t;
     609}
     610
     611static void generic_swap(void *a, void *b, int size)
     612{
     613        char t;
     614
     615        do {
     616                t = *(char *)a;
     617                *(char *)a++ = *(char *)b;
     618                *(char *)b++ = t;
     619        } while (--size > 0);
     620}
     621
     622/**
     623 * sort - sort an array of elements
     624 * @base: pointer to data to sort
     625 * @num: number of elements
     626 * @size: size of each element
     627 * @cmp_func: pointer to comparison function
     628 * @swap_func: pointer to swap function or NULL
     629 *
     630 * This function does a heapsort on the given array. You may provide a
     631 * swap_func function optimized to your element type.
     632 *
     633 * Sorting time is O(n log n) both on average and worst-case. While
     634 * qsort is about 20% faster on average, it suffers from exploitable
     635 * O(n*n) worst-case behavior and extra memory requirements that make
     636 * it less suitable for kernel use.
     637 */
     638
     639void sort(void *base, size_t num, size_t size,
     640          int (*cmp_func)(const void *, const void *),
     641          void (*swap_func)(void *, void *, int size))
     642{
     643        /* pre-scale counters for performance */
     644        int i = (num/2 - 1) * size, n = num * size, c, r;
     645
     646        if (!swap_func)
     647                swap_func = (size == 4 ? u32_swap : generic_swap);
     648
     649        /* heapify */
     650        for ( ; i >= 0; i -= size) {
     651                for (r = i; r * 2 + size < n; r  = c) {
     652                        c = r * 2 + size;
     653                        if (c < n - size &&
     654                                        cmp_func(base + c, base + c + size) < 0)
     655                                c += size;
     656                        if (cmp_func(base + r, base + c) >= 0)
     657                                break;
     658                        swap_func(base + r, base + c, size);
     659                }
     660        }
     661
     662        /* sort */
     663        for (i = n - size; i > 0; i -= size) {
     664                swap_func(base, base + i, size);
     665                for (r = 0; r * 2 + size < i; r = c) {
     666                        c = r * 2 + size;
     667                        if (c < i - size &&
     668                                        cmp_func(base + c, base + c + size) < 0)
     669                                c += size;
     670                        if (cmp_func(base + r, base + c) >= 0)
     671                                break;
     672                        swap_func(base + r, base + c, size);
     673                }
     674        }
     675}
     676//******************************************************************************
     677//******************************************************************************
     678
     679/**
     680 * hex_to_bin - convert a hex digit to its real value
     681 * @ch: ascii character represents hex digit
     682 *
     683 * hex_to_bin() converts one hex digit to its actual value or -1 in case of bad
     684 * input.
     685 */
     686int hex_to_bin(char ch)
     687{
     688        if ((ch >= '0') && (ch <= '9'))
     689                return ch - '0';
     690        ch = tolower(ch);
     691        if ((ch >= 'a') && (ch <= 'f'))
     692                return ch - 'a' + 10;
     693        return -1;
     694}
     695//******************************************************************************
     696
     697
     698/*
     699 * stream_open is used by subsystems that want stream-like file descriptors.
     700 * Such file descriptors are not seekable and don't have notion of position
     701 * (file.f_pos is always 0). Contrary to file descriptors of other regular
     702 * files, .read() and .write() can run simultaneously.
     703 *
     704 * stream_open never fails and is marked to return int so that it could be
     705 * directly used as file_operations.open .
     706 */
     707int stream_open(struct inode *inode, struct file *filp)
     708{
     709        filp->f_mode &= ~(FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE | FMODE_ATOMIC_POS);
     710        filp->f_mode |= FMODE_STREAM;
     711        return 0;
     712}
     713
     714/**
     715 * alloc_pages_exact - allocate pages with the given size
     716 * @size: the size to allocate in bytes
     717 * @gfp_flags: the allocation conditions, GFP_XXX
     718 *
     719 * Allocates the physically contiguous pages with the given size.
     720 *
     721 * Return: The pointer of the buffer, or %NULL if no enough memory.
     722 */
     723void *alloc_pages_exact(size_t size, gfp_t gfp_flags)
     724{
     725        int pg;
     726
     727        if (WARN_ON(!size))
     728                return NULL;
     729        if (WARN_ON(!gfp_flags))
     730                return NULL;
     731        gfp_flags |= __GFP_COMP;        /* compound page lets parts be mapped */
     732        pg = get_order(size);
     733        return (void *) __get_free_pages(gfp_flags, pg);
     734}
     735
     736/**
     737 * free_pages_exact - release the pages
     738 * @ptr: the buffer pointer to release
     739 * @size: the allocated buffer size
     740 *
     741 * Releases the buffer allocated via snd_malloc_pages().
     742 */
     743void free_pages_exact(void *ptr, size_t size)
     744{
     745        int pg;
     746
     747        if (ptr == NULL)
     748                return;
     749        pg = get_order(size);
     750        free_pages((unsigned long) ptr, pg);
     751}
Note: See TracChangeset for help on using the changeset viewer.